df7e695d21c9919fe3ca69976da4762fd47178db
1 /*****************************************************************************
4 * This file holds the code needed by LTT usertrace that comes from the
5 * kernel headers. Since including kernel headers is not recommended in
6 * userspace programs/libraries, we rewrote implementations HIGHLY INSPIRED
7 * (i.e. copied/pasted) from the original kernel headers (2.6.17).
9 * Martin Bisson, July 2006
10 * Mathieu Desnoyers, August 2006
13 #ifndef _KERNELUTILS_I386_H
14 #define _KERNELUTILS_I386_H
16 // We are careful, so we assume a possibly SMP machine
17 #define LOCK "lock ; "
18 #define LOCK_PREFIX "lock ; "
27 * Make sure gcc doesn't try to be clever and move things around
28 * on us. We need to use _exactly_ the address the user gave us,
29 * not some alias that contains the same information.
31 typedef struct { volatile int counter
; } atomic_t
;
35 * atomic_read - read atomic variable
36 * @v: pointer of type atomic_t
38 * Atomically reads the value of @v.
40 #define atomic_read(v) ((v)->counter)
43 * atomic_add - add integer to atomic variable
44 * @i: integer value to add
45 * @v: pointer of type atomic_t
47 * Atomically adds @i to @v.
49 static __inline__
void atomic_add(int i
, atomic_t
*v
)
54 :"ir" (i
), "m" (v
->counter
));
58 * atomic_inc - increment atomic variable
59 * @v: pointer of type atomic_t
61 * Atomically increments @v by 1.
63 static __inline__
void atomic_inc(atomic_t
*v
)
72 * atomic_add_return - add and return
73 * @i: integer value to add
74 * @v: pointer of type atomic_t
76 * Atomically adds @i to @v and returns @i + @v
78 static __inline__
int atomic_add_return(int i
, atomic_t
*v
)
84 :"m"(v
->counter
), "0"(i
));
93 struct __xchg_dummy
{ unsigned long a
[100]; };
94 #define __xg(x) ((struct __xchg_dummy *)(x))
98 * Atomic compare and exchange. Compare OLD with MEM, if identical,
99 * store NEW in MEM. Return the initial value in MEM. Success is
100 * indicated by comparing RETURN with OLD.
103 #define __HAVE_ARCH_CMPXCHG 1
104 #define cmpxchg(ptr,o,n)\
105 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
106 (unsigned long)(n),sizeof(*(ptr))))
108 static inline unsigned long __cmpxchg(volatile void *ptr
, unsigned long old
,
109 unsigned long new, int size
)
114 __asm__
__volatile__(LOCK_PREFIX
"cmpxchgb %b1,%2"
116 : "q"(new), "m"(*__xg(ptr
)), "0"(old
)
120 __asm__
__volatile__(LOCK_PREFIX
"cmpxchgw %w1,%2"
122 : "r"(new), "m"(*__xg(ptr
)), "0"(old
)
126 __asm__
__volatile__(LOCK_PREFIX
"cmpxchgl %1,%2"
128 : "r"(new), "m"(*__xg(ptr
)), "0"(old
)
138 #define rdtscll(val) \
139 __asm__ __volatile__("rdtsc" : "=A" (val))
143 typedef unsigned long long cycles_t
;
145 static inline cycles_t
get_cycles (void)
147 unsigned long long ret
;
154 #endif // _KERNELUTILS_I386_H
This page took 0.045029 seconds and 4 git commands to generate.