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
20 #ifndef _XENO_ASM_NIOS2_TSC_H
21 #define _XENO_ASM_NIOS2_TSC_H
25 extern volatile void *xeno_nios2_hrclock
;
27 static inline unsigned long long __xn_rdtsc(void)
29 volatile unsigned short *hrclock
;
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() \
43 __snap = hrclock_rdsnap(3) | hrclock_rdsnap(2) | \
44 hrclock_rdsnap(1) | hrclock_rdsnap(0); \
48 #define hrclock_getsnap() \
50 hrclock_wrsnap(0, 0); \
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.
65 t0
= hrclock_getsnap(); /* Request snapshot and read it */
66 __asm__
__volatile__("": : :"memory");
67 t1
= hrclock_peeksnap(); /* Confirm first reading */
70 #undef hrclock_getsnap
77 #endif /* __KERNEL__ */
79 #endif /* _XENO_ASM_NIOS2_TSC_H */