Implement lttng_ust_get_cpu()
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 18 Nov 2011 18:15:56 +0000 (13:15 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 18 Nov 2011 18:15:56 +0000 (13:15 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/core.h
liblttng-ust/ltt-events.c
libringbuffer/Makefile.am
libringbuffer/frontend_api.h
libringbuffer/getcpu.h [new file with mode: 0644]
libringbuffer/smp.h

index 086d50d32d73387654691717b727430377074809..0c483e8847e4fe0be3cd4e6c3b69997586d32a0c 100644 (file)
@@ -74,13 +74,6 @@ static inline long IS_ERR(const void *ptr)
        __max1 > __max2 ? __max1: __max2; })
 
 
-/* MUTEXES */
-
-#include <pthread.h>
-
-#define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
-#define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
-
 /* MALLOCATION */
 
 #include <stdlib.h>
@@ -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 */
index 477db76f53222d149e1788d14e0b9aa81c7349dc..27f24d982ef59926997e511a822c3ff8d070110c 100644 (file)
@@ -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)
 {
index 74a9b0dcfae240c0b32370c8c00db0bc42552d10..f1d7ade37aa9efd95a379851d3246cc4858c1426 100644 (file)
@@ -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 \
index 24f94acf110b5f663443207d3711e3bbe323fa39..d644a65b89ac5f63a2122c4e6198fd99d1827616 100644 (file)
@@ -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 (file)
index 0000000..f5f2f67
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef _LTTNG_GETCPU_H
+#define _LTTNG_GETCPU_H
+
+/*
+ * Copyright (c) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <urcu/compiler.h>
+#include <sched.h>
+
+#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 */
index 755c65fc52fb53e91ee59ddbd415cc0468cec2bf..bef3e0ef7ff467c01e6937b70bcf3608eb9f51ac 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <lttng/core.h>
+#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)++)
 
This page took 0.028769 seconds and 4 git commands to generate.