b0c77e0972a66f8d03235494f4e5be72fcbc281a
10 /* FIXME: libkcompat must not define arch-specific local ops, as ust *must*
11 * fallback to the normal atomic ops. Fix things so we don't add them and
12 * break things accidentally.
15 #define container_of(ptr, type, member) ({ \
16 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
17 (type *)( (char *)__mptr - offsetof(type,member) );})
20 #define KERN_NOTICE ""
24 #define KERN_WARNING ""
28 #define MAX_ERRNO 4095
30 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
32 static inline void *ERR_PTR(long error
)
34 return (void *) error
;
37 static inline long PTR_ERR(const void *ptr
)
42 static inline long IS_ERR(const void *ptr
)
44 return IS_ERR_VALUE((unsigned long)ptr
);
50 #define min_t(type, x, y) ({ \
53 __min1 < __min2 ? __min1: __min2; })
55 #define max_t(type, x, y) ({ \
58 __max1 > __max2 ? __max1: __max2; })
65 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
66 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
68 #define mutex_lock(m) pthread_mutex_lock(m)
70 #define mutex_unlock(m) pthread_mutex_unlock(m)
77 #define kmalloc(s, t) malloc(s)
78 #define kzalloc(s, t) zmalloc(s)
79 #define kfree(p) free((void *)p)
80 #define kstrdup(s, t) strdup(s)
82 #define zmalloc(s) calloc(1, s)
89 #define printk(fmt, args...) printf(fmt, ## args)
94 #define ____cacheline_aligned
98 static inline unsigned int hweight32(unsigned int w
)
100 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
101 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
102 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
103 res
= res
+ (res
>> 8);
104 return (res
+ (res
>> 16)) & 0x000000FF;
107 static inline int fls(int x
)
110 //ust// #ifdef CONFIG_X86_CMOV
113 : "=&r" (r
) : "rm" (x
), "rm" (-1));
115 //ust// asm("bsrl %1,%0\n\t"
117 //ust// "movl $-1,%0\n"
118 //ust// "1:" : "=r" (r) : "rm" (x));
123 static __inline__
int get_count_order(unsigned int count
)
127 order
= fls(count
) - 1;
128 if (count
& (count
- 1))
138 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
139 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
140 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
141 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
142 #define PAGE_MASK (~(PAGE_SIZE-1))
149 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
153 static inline u64
trace_clock_read64(void)
158 __asm__
volatile ("rdtsc\n" : "=a" (low
), "=d" (high
));
165 //static inline u64 trace_clock_read64(void)
167 // struct timeval tv;
170 // gettimeofday(&tv, NULL);
171 // retval = tv.tv_sec;
172 // retval *= 1000000;
173 // retval += tv.tv_usec;
178 static inline u64
trace_clock_frequency(void)
183 static inline u32
trace_clock_freq_scale(void)
189 #endif /* KERNELCOMPAT_H */
This page took 0.033304 seconds and 4 git commands to generate.