bfin: remove inline keyword
[xenomai-head.git] / include / asm-nios2 / tsc.h
blob90be757da8e734d7561ccb469055944c8e06dfe1
1 /*
2 * Copyright (C) 2009 Philippe Gerum <rpm@xenomai.org>.
4 * Xenomai is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * Xenomai is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Xenomai; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 * 02111-1307, USA.
20 #ifndef _XENO_ASM_NIOS2_TSC_H
21 #define _XENO_ASM_NIOS2_TSC_H
23 #ifndef __KERNEL__
25 extern volatile void *xeno_nios2_hrclock;
27 static inline unsigned long long __xn_rdtsc(void)
29 volatile unsigned short *hrclock;
30 int64_t t0, t1;
32 hrclock = xeno_nios2_hrclock;
34 #define hrclock_wrsnap(reg, val) \
35 (*(hrclock + (12 + ((reg) * 2)))) = (val)
37 #define hrclock_rdsnap(reg) \
38 (int64_t)(*(hrclock + (12 + ((reg) * 2)))) << (reg * 16)
40 #define hrclock_peeksnap() \
41 ({ \
42 int64_t __snap; \
43 __snap = hrclock_rdsnap(3) | hrclock_rdsnap(2) | \
44 hrclock_rdsnap(1) | hrclock_rdsnap(0); \
45 __snap; \
48 #define hrclock_getsnap() \
49 ({ \
50 hrclock_wrsnap(0, 0); \
51 hrclock_peeksnap(); \
55 * We compete with both the kernel and userland applications
56 * which may request a snapshot as well, but we don't have any
57 * simple mutual exclusion mechanism at hand to avoid
58 * races. In order to keep the overhead of reading the hrclock
59 * from userland low, we make sure to read two consecutive
60 * coherent snapshots. In case both readings do not match, we
61 * have to request a fresh snapshot anew, since it means that
62 * we have been preempted in the middle of the operation.
64 do {
65 t0 = hrclock_getsnap(); /* Request snapshot and read it */
66 __asm__ __volatile__("": : :"memory");
67 t1 = hrclock_peeksnap(); /* Confirm first reading */
68 } while (t0 != t1);
70 #undef hrclock_getsnap
71 #undef hrclock_rdsnap
72 #undef hrclock_wrsnap
74 return ~t0;
77 #endif /* __KERNEL__ */
79 #endif /* _XENO_ASM_NIOS2_TSC_H */