5 * Copyright (C) 2010 Pierre-Marc Fournier
6 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; version 2.1 of
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
24 #include <lttng/config.h>
25 #include <urcu/arch.h>
26 #include <urcu/compiler.h>
30 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
33 /* ALIGNMENT SHORTCUTS */
37 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
38 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
39 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
40 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
41 #define PAGE_MASK (~(PAGE_SIZE-1))
44 #define MAX_ERRNO 4095
46 #define IS_ERR_VALUE(x) caa_unlikely((x) >= (unsigned long)-MAX_ERRNO)
48 static inline void *ERR_PTR(long error
)
50 return (void *) error
;
53 static inline long PTR_ERR(const void *ptr
)
58 static inline long IS_ERR(const void *ptr
)
60 return IS_ERR_VALUE((unsigned long)ptr
);
66 #define min_t(type, x, y) ({ \
69 __min1 < __min2 ? __min1: __min2; })
71 #define max_t(type, x, y) ({ \
74 __max1 > __max2 ? __max1: __max2; })
81 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
82 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
89 void *zmalloc(size_t len
)
91 return calloc(1, len
);
95 void *malloc_align(size_t len
)
97 return malloc(ALIGN(len
, CAA_CACHE_LINE_SIZE
));
101 void *zmalloc_align(size_t len
)
103 return calloc(1, ALIGN(len
, CAA_CACHE_LINE_SIZE
));
108 #include <lttng/processor.h>
109 static inline unsigned int hweight32(unsigned int w
)
111 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
112 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
113 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
114 res
= res
+ (res
>> 8);
115 return (res
+ (res
>> 16)) & 0x000000FF;
118 static __inline__
int get_count_order(unsigned int count
)
122 order
= fls(count
) - 1;
123 if (count
& (count
- 1))
128 #define _ust_container_of(ptr, type, member) ({ \
129 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
130 (type *)( (char *)__mptr - offsetof(type,member) );})
132 #ifndef inline_memcpy
133 #define inline_memcpy memcpy
137 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
142 static __inline__
int ust_get_cpu(void)
146 cpu
= sched_getcpu();
147 if (caa_likely(cpu
>= 0))
150 * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback.
155 #else /* #else #ifndef UST_VALGRIND */
157 static __inline__
int ust_get_cpu(void)
160 * Valgrind does not support the sched_getcpu() vsyscall.
161 * It causes it to detect a segfault in the program and stop it.
162 * So if we want to check libust with valgrind, we have to refrain
163 * from using this call. TODO: it would probably be better to return
164 * other values too, to better test it.
169 #endif /* #else #ifndef UST_VALGRIND */
171 #endif /* UST_CORE_H */
This page took 0.036516 seconds and 4 git commands to generate.