From: Mathieu Desnoyers Date: Fri, 18 Nov 2011 18:15:56 +0000 (-0500) Subject: Implement lttng_ust_get_cpu() X-Git-Tag: v1.9.1~74 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2b2d6ff75efc17aa74ea9b0a7f8c756d812804bb;p=lttng-ust.git Implement lttng_ust_get_cpu() Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/core.h b/include/lttng/core.h index 086d50d3..0c483e88 100644 --- a/include/lttng/core.h +++ b/include/lttng/core.h @@ -74,13 +74,6 @@ static inline long IS_ERR(const void *ptr) __max1 > __max2 ? __max1: __max2; }) -/* MUTEXES */ - -#include - -#define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER; -#define DECLARE_MUTEX(m) extern pthread_mutex_t (m); - /* MALLOCATION */ #include @@ -122,34 +115,4 @@ static inline unsigned int hweight32(unsigned int w) #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) #endif -#ifndef UST_VALGRIND - -/* - * If getcpu(2) is not implemented in the Kernel use CPU 0 as fallback. - */ -static __inline__ int ust_get_cpu(void) -{ - int cpu = sched_getcpu(); - - if (caa_likely(cpu >= 0)) - return cpu; - return 0; -} - -#else /* #else #ifndef UST_VALGRIND */ - -/* - * 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. - */ -static __inline__ int ust_get_cpu(void) -{ - return 0; -} - -#endif /* #else #ifndef UST_VALGRIND */ - #endif /* UST_CORE_H */ diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 477db76f..27f24d98 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -39,7 +39,7 @@ * control and probe registration. All operations within this file are * called by the communication thread, under ust_lock protection. */ -static DEFINE_MUTEX(sessions_mutex); +static pthread_mutex_t sessions_mutex = PTHREAD_MUTEX_INITIALIZER; void ust_lock(void) { diff --git a/libringbuffer/Makefile.am b/libringbuffer/Makefile.am index 74a9b0dc..f1d7ade3 100644 --- a/libringbuffer/Makefile.am +++ b/libringbuffer/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = -fno-strict-aliasing noinst_LTLIBRARIES = libringbuffer.la libringbuffer_la_SOURCES = \ - smp.h smp.c \ + smp.h smp.c getcpu.h \ shm.c shm.h shm_types.h shm_internal.h \ ring_buffer_backend.c \ ring_buffer_frontend.c \ diff --git a/libringbuffer/frontend_api.h b/libringbuffer/frontend_api.h index 24f94acf..d644a65b 100644 --- a/libringbuffer/frontend_api.h +++ b/libringbuffer/frontend_api.h @@ -42,7 +42,7 @@ int lib_ring_buffer_get_cpu(const struct lttng_ust_lib_ring_buffer_config *confi int cpu, nesting; rcu_read_lock(); - cpu = ust_get_cpu(); + cpu = lttng_ust_get_cpu(); nesting = ++lib_ring_buffer_nesting; /* TLS */ cmm_barrier(); diff --git a/libringbuffer/getcpu.h b/libringbuffer/getcpu.h new file mode 100644 index 00000000..f5f2f675 --- /dev/null +++ b/libringbuffer/getcpu.h @@ -0,0 +1,57 @@ +#ifndef _LTTNG_GETCPU_H +#define _LTTNG_GETCPU_H + +/* + * 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; only + * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define _GNU_SOURCE +#include +#include + +#ifdef UST_VALGRIND + +/* + * Fallback on cpu 0 if liblttng-ust is build with Valgrind support. + * get_cpu() returns the current CPU number. It may change due to + * migration, so it is only statistically accurate. + */ +static inline +int lttng_ust_get_cpu(void) +{ + return 0; +} + +#else + +/* + * If getcpu is not implemented in the kernel, use cpu 0 as fallback. + */ +static inline +int lttng_ust_get_cpu(void) +{ + int cpu; + + cpu = sched_getcpu(); + if (caa_unlikely(cpu < 0)) + return 0; + return cpu; +} + +#endif + +#endif /* _LTTNG_GETCPU_H */ diff --git a/libringbuffer/smp.h b/libringbuffer/smp.h index 755c65fc..bef3e0ef 100644 --- a/libringbuffer/smp.h +++ b/libringbuffer/smp.h @@ -10,6 +10,7 @@ */ #include +#include "getcpu.h" /* * 4kB of per-cpu data available. Enough to hold the control structures, @@ -28,45 +29,6 @@ int num_possible_cpus(void) return __num_possible_cpus; } -/* - * get_cpu() returns the current CPU number. It may change due to - * migration, so it is only statistically accurate. - */ -#ifndef UST_VALGRIND -static inline -int get_cpu(void) -{ - int cpu; - - cpu = sched_getcpu(); - if (caa_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 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 */ - -static inline -void put_cpu(void) -{ -} - #define for_each_possible_cpu(cpu) \ for ((cpu) = 0; (cpu) < num_possible_cpus(); (cpu)++)