X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=include%2Fust%2Fcore.h;h=10e864f18b22a25493b5aa13f6faa3590768724c;hb=1ea172a1367c416716fa046289d25694f53ce599;hp=e781a3a6c5542e85f98898ee8beb3314be8869a8;hpb=1e4b909b682cc34aaa51ee13432c1c23f7e70bab;p=lttng-ust.git diff --git a/include/ust/core.h b/include/ust/core.h index e781a3a6..10e864f1 100644 --- a/include/ust/core.h +++ b/include/ust/core.h @@ -1,9 +1,14 @@ -/* Copyright (C) 2010 Pierre-Marc Fournier +#ifndef UST_CORE_H +#define UST_CORE_H + +/* + * Copyright (C) 2010 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * License as published by the Free Software Foundation; version 2.1 of + * the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,50 +20,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef UST_CORE_H -#define UST_CORE_H - #include +#include +#include #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) -#if defined(CONFIG_LTT) && defined(CONFIG_LTT_ALIGNMENT) - -/* - * Calculate the offset needed to align the type. - * size_of_type must be non-zero. - */ -static inline unsigned int ltt_align(size_t align_drift, size_t size_of_type) -{ - size_t alignment = min(sizeof(void *), size_of_type); - return (alignment - align_drift) & (alignment - 1); -} -/* Default arch alignment */ -#define LTT_ALIGN - -static inline int ltt_get_alignment(void) -{ - return sizeof(void *); -} - -#else - -static inline unsigned int ltt_align(size_t align_drift, - size_t size_of_type) -{ - return 0; -} - -#define LTT_ALIGN __attribute__((packed)) - -static inline int ltt_get_alignment(void) -{ - return 0; -} -#endif /* defined(CONFIG_LTT) && defined(CONFIG_LTT_ALIGNMENT) */ - - /* ARRAYS */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -117,7 +85,25 @@ static inline long IS_ERR(const void *ptr) /* MALLOCATION */ -#define zmalloc(s) calloc(1, s) +#include + +static inline +void *zmalloc(size_t len) +{ + return calloc(1, len); +} + +static inline +void *malloc_align(size_t len) +{ + return malloc(ALIGN(len, CAA_CACHE_LINE_SIZE)); +} + +static inline +void *zmalloc_align(size_t len) +{ + return calloc(1, ALIGN(len, CAA_CACHE_LINE_SIZE)); +} /* MATH */ @@ -145,4 +131,43 @@ static __inline__ int get_count_order(unsigned int count) const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#ifndef inline_memcpy +#define inline_memcpy memcpy +#endif + +#ifndef __same_type +#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) +#endif + +#ifndef UST_VALGRIND + +static __inline__ int ust_get_cpu(void) +{ + int cpu; + + cpu = sched_getcpu(); + if (likely(cpu >= 0)) + return cpu; + /* + * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback. + */ + return 0; +} + +#else /* #else #ifndef UST_VALGRIND */ + +static __inline__ int ust_get_cpu(void) +{ + /* + * Valgrind does not support the sched_getcpu() vsyscall. + * It causes it to detect a segfault in the program and stop it. + * So if we want to check libust with valgrind, we have to refrain + * from using this call. TODO: it would probably be better to return + * other values too, to better test it. + */ + return 0; +} + +#endif /* #else #ifndef UST_VALGRIND */ + #endif /* UST_CORE_H */