1 /* Copyright (C) 2009 Pierre-Marc Fournier
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef KERNELCOMPAT_H
19 #define KERNELCOMPAT_H
21 #include <ust/kcompat/kcompat.h>
22 #include <urcu/list.h>
24 /* FIXME: libkcompat must not define arch-specific local ops, as ust *must*
25 * fallback to the normal atomic ops. Fix things so we don't add them and
26 * break things accidentally.
29 #define container_of(ptr, type, member) ({ \
30 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
31 (type *)( (char *)__mptr - offsetof(type,member) );})
34 #define MAX_ERRNO 4095
36 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
38 static inline void *ERR_PTR(long error
)
40 return (void *) error
;
43 static inline long PTR_ERR(const void *ptr
)
48 static inline long IS_ERR(const void *ptr
)
50 return IS_ERR_VALUE((unsigned long)ptr
);
56 #define min_t(type, x, y) ({ \
59 __min1 < __min2 ? __min1: __min2; })
61 #define max_t(type, x, y) ({ \
64 __max1 > __max2 ? __max1: __max2; })
71 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
72 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
74 #define mutex_lock(m) pthread_mutex_lock(m)
76 #define mutex_unlock(m) pthread_mutex_unlock(m)
81 #define zmalloc(s) calloc(1, s)
85 /* FIXME: define this */
86 #define ____cacheline_aligned
90 #include <ust/processor.h>
91 static inline unsigned int hweight32(unsigned int w
)
93 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
94 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
95 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
96 res
= res
+ (res
>> 8);
97 return (res
+ (res
>> 16)) & 0x000000FF;
100 static __inline__
int get_count_order(unsigned int count
)
104 order
= fls(count
) - 1;
105 if (count
& (count
- 1))
115 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
116 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
117 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
118 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
119 #define PAGE_MASK (~(PAGE_SIZE-1))
126 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
130 /* There are two types of clocks that can be used.
132 - gettimeofday() clock
134 Microbenchmarks on Linux 2.6.30 on Core2 Duo 3GHz (functions are inlined):
135 Calls (100000000) to tsc(): 4004035641 cycles or 40 cycles/call
136 Calls (100000000) to gettimeofday(): 9723158352 cycles or 97 cycles/call
138 For merging traces with the kernel, a time source compatible with that of
139 the kernel is necessary.
144 /* WARNING: Make sure to set frequency and scaling functions that will not
145 * result in lttv timestamps (sec.nsec) with seconds greater than 2**32-1.
147 static inline u64
trace_clock_read64(void)
152 __asm__
volatile ("rdtsc\n" : "=a" (low
), "=d" (high
));
160 #include <sys/time.h>
162 static inline u64
trace_clock_read64(void)
167 gettimeofday(&tv
, NULL
);
170 retval
+= tv
.tv_usec
;
175 static inline u64
trace_clock_frequency(void)
180 static inline u32
trace_clock_freq_scale(void)
185 #endif /* KERNELCOMPAT_H */
This page took 0.033857 seconds and 5 git commands to generate.