6 /* FIXME: libkcompat must not define arch-specific local ops, as ust *must*
7 * fallback to the normal atomic ops. Fix things so we don't add them and
8 * break things accidentally.
11 #define container_of(ptr, type, member) ({ \
12 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
13 (type *)( (char *)__mptr - offsetof(type,member) );})
16 #define MAX_ERRNO 4095
18 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
20 static inline void *ERR_PTR(long error
)
22 return (void *) error
;
25 static inline long PTR_ERR(const void *ptr
)
30 static inline long IS_ERR(const void *ptr
)
32 return IS_ERR_VALUE((unsigned long)ptr
);
38 #define min_t(type, x, y) ({ \
41 __min1 < __min2 ? __min1: __min2; })
43 #define max_t(type, x, y) ({ \
46 __max1 > __max2 ? __max1: __max2; })
53 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
54 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
56 #define mutex_lock(m) pthread_mutex_lock(m)
58 #define mutex_unlock(m) pthread_mutex_unlock(m)
63 #define zmalloc(s) calloc(1, s)
67 /* FIXME: define this */
68 #define ____cacheline_aligned
72 static inline unsigned int hweight32(unsigned int w
)
74 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
75 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
76 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
77 res
= res
+ (res
>> 8);
78 return (res
+ (res
>> 16)) & 0x000000FF;
81 static inline int fls(int x
)
84 //ust// #ifdef CONFIG_X86_CMOV
87 : "=&r" (r
) : "rm" (x
), "rm" (-1));
89 //ust// asm("bsrl %1,%0\n\t"
91 //ust// "movl $-1,%0\n"
92 //ust// "1:" : "=r" (r) : "rm" (x));
97 static __inline__
int get_count_order(unsigned int count
)
101 order
= fls(count
) - 1;
102 if (count
& (count
- 1))
112 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
113 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
114 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
115 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
116 #define PAGE_MASK (~(PAGE_SIZE-1))
123 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
127 /* There are two types of clocks that can be used.
129 - gettimeofday() clock
131 Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are inlined):
132 Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
133 Calls (100000000) to gettimeofday(): 9723158352 cycles or 97 cycles/call
135 For merging traces with the kernel, a time source compatible with that of
136 the kernel is necessary.
141 /* WARNING: Make sure to set frequency and scaling functions that will not
142 * result in lttv timestamps (sec.nsec) with seconds greater than 2**32-1.
144 static inline u64
trace_clock_read64(void)
149 __asm__
volatile ("rdtsc\n" : "=a" (low
), "=d" (high
));
157 #include <sys/time.h>
159 static inline u64
trace_clock_read64(void)
164 gettimeofday(&tv
, NULL
);
167 retval
+= tv
.tv_usec
;
172 static inline u64
trace_clock_frequency(void)
177 static inline u32
trace_clock_freq_scale(void)
182 #endif /* KERNELCOMPAT_H */
This page took 0.034319 seconds and 4 git commands to generate.