9 /* FIXME: libkcompat must not define arch-specific local ops, as ust *must*
10 * fallback to the normal atomic ops. Fix things so we don't add them and
11 * break things accidentally.
14 #define container_of(ptr, type, member) ({ \
15 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
16 (type *)( (char *)__mptr - offsetof(type,member) );})
19 #define KERN_NOTICE ""
23 #define KERN_WARNING ""
27 #define MAX_ERRNO 4095
29 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
31 static inline void *ERR_PTR(long error
)
33 return (void *) error
;
36 static inline long PTR_ERR(const void *ptr
)
41 static inline long IS_ERR(const void *ptr
)
43 return IS_ERR_VALUE((unsigned long)ptr
);
49 #define min_t(type, x, y) ({ \
52 __min1 < __min2 ? __min1: __min2; })
54 #define max_t(type, x, y) ({ \
57 __max1 > __max2 ? __max1: __max2; })
64 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
65 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
67 #define mutex_lock(m) pthread_mutex_lock(m)
69 #define mutex_unlock(m) pthread_mutex_unlock(m)
76 #define kmalloc(s, t) malloc(s)
77 #define kzalloc(s, t) zmalloc(s)
78 #define kfree(p) free((void *)p)
79 #define kstrdup(s, t) strdup(s)
81 #define zmalloc(s) calloc(1, s)
88 #define printk(fmt, args...) printf(fmt, ## args)
93 #define ____cacheline_aligned
97 static inline unsigned int hweight32(unsigned int w
)
99 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
100 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
101 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
102 res
= res
+ (res
>> 8);
103 return (res
+ (res
>> 16)) & 0x000000FF;
106 static inline int fls(int x
)
109 //ust// #ifdef CONFIG_X86_CMOV
112 : "=&r" (r
) : "rm" (x
), "rm" (-1));
114 //ust// asm("bsrl %1,%0\n\t"
116 //ust// "movl $-1,%0\n"
117 //ust// "1:" : "=r" (r) : "rm" (x));
122 static __inline__
int get_count_order(unsigned int count
)
126 order
= fls(count
) - 1;
127 if (count
& (count
- 1))
137 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
138 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
139 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
140 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
141 #define PAGE_MASK (~(PAGE_SIZE-1))
148 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
152 /* There are two types of clocks that can be used.
154 - gettimeofday() clock
156 Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are inlined):
157 Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
158 Calls (100000000) to gettimeofday(): 9723158352 cycles or 97 cycles/call
160 For merging traces with the kernel, a time source compatible with that of
161 the kernel is necessary.
166 /* WARNING: Make sure to set frequency and scaling functions that will not
167 * result in lttv timestamps (sec.nsec) with seconds greater than 2**32-1.
169 static inline u64
trace_clock_read64(void)
174 __asm__
volatile ("rdtsc\n" : "=a" (low
), "=d" (high
));
182 static inline u64
trace_clock_read64(void)
187 gettimeofday(&tv
, NULL
);
190 retval
+= tv
.tv_usec
;
195 static inline u64
trace_clock_frequency(void)
200 static inline u32
trace_clock_freq_scale(void)
206 #endif /* KERNELCOMPAT_H */
This page took 0.056559 seconds and 4 git commands to generate.