Fix: lttng_this_cpu_ptr wrapper for kernel 3.19+
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Dec 2014 17:24:04 +0000 (12:24 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Dec 2014 17:24:04 +0000 (12:24 -0500)
Starting from kernel 3.19-rc1, __get_cpu_var() disappears, replaced by
this_cpu_ptr(). Introduce a wrapper using either depending on the kernel
version. Older kernels did not expose a this_cpu_ptr(), so keep on using
__get_cpu_var() on old kernels.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lib/ringbuffer/frontend_api.h
lib/ringbuffer/ring_buffer_frontend.c
wrapper/percpu-defs.h [new file with mode: 0644]
wrapper/trace-clock.h

index ff6abce93d684a86e48066ed7fc537a2516fe9b4..b622bd7e865cae4079a4a91c2bab87eed34ebb32 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include "../../wrapper/ringbuffer/frontend.h"
+#include "../../wrapper/percpu-defs.h"
 #include <linux/errno.h>
 #include <linux/prefetch.h>
 
@@ -73,7 +74,7 @@ static inline
 void lib_ring_buffer_put_cpu(const struct lib_ring_buffer_config *config)
 {
        barrier();
-       __get_cpu_var(lib_ring_buffer_nesting)--;
+       (*lttng_this_cpu_ptr(&lib_ring_buffer_nesting))--;
        rcu_read_unlock_sched_notrace();
 }
 
index ae0b9e3986267a8b79e8395d13cd23d55cc357c7..c4b797ce8af76faf9ba5209d054b89fb42326656 100644 (file)
@@ -61,6 +61,7 @@
 #include "../../wrapper/ringbuffer/iterator.h"
 #include "../../wrapper/ringbuffer/nohz.h"
 #include "../../wrapper/atomic.h"
+#include "../../wrapper/percpu-defs.h"
 
 /*
  * Internal structure representing offsets to use at a sub-buffer switch.
@@ -498,16 +499,16 @@ static int notrace ring_buffer_tick_nohz_callback(struct notifier_block *nb,
                raw_spin_unlock(&buf->raw_tick_nohz_spinlock);
                break;
        case TICK_NOHZ_STOP:
-               spin_lock(&__get_cpu_var(ring_buffer_nohz_lock));
+               spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
                lib_ring_buffer_stop_switch_timer(buf);
                lib_ring_buffer_stop_read_timer(buf);
-               spin_unlock(&__get_cpu_var(ring_buffer_nohz_lock));
+               spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
                break;
        case TICK_NOHZ_RESTART:
-               spin_lock(&__get_cpu_var(ring_buffer_nohz_lock));
+               spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
                lib_ring_buffer_start_read_timer(buf);
                lib_ring_buffer_start_switch_timer(buf);
-               spin_unlock(&__get_cpu_var(ring_buffer_nohz_lock));
+               spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock));
                break;
        }
 
diff --git a/wrapper/percpu-defs.h b/wrapper/percpu-defs.h
new file mode 100644 (file)
index 0000000..bba1bce
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef _LTTNG_WRAPPER_PERCPU_DEFS_H
+#define _LTTNG_WRAPPER_PERCPU_DEFS_H
+
+/*
+ * wrapper/percpu-defs.h
+ *
+ * wrapper around linux/percpu-defs.h.
+ *
+ * Copyright (C) 2014 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
+ */
+
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0)
+
+#include <linux/percpu-defs.h>
+
+#define lttng_this_cpu_ptr(ptr)                this_cpu_ptr(ptr)
+
+#else /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) */
+
+#include <linux/percpu.h>
+
+#define lttng_this_cpu_ptr(ptr)                (&__get_cpu_var(*(ptr)))
+
+#endif /* #else #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) */
+
+#endif /* _LTTNG_WRAPPER_PERCPU_DEFS_H */
index 5705d0c25a9477fe3b80710fb97ef0ad66ab2261..1b2821a19a8b7fde4a315721944d0d66405062bb 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/version.h>
 #include <asm/local.h>
 #include "../lttng-kernel-version.h"
+#include "percpu-defs.h"
 #include "random.h"
 
 #if LTTNG_KERNEL_RANGE(3,10,0, 3,10,14) || LTTNG_KERNEL_RANGE(3,11,0, 3,11,3)
@@ -97,7 +98,7 @@ static inline u64 trace_clock_monotonic_wrapper(void)
        local_t *last_tsc;
 
        /* Use fast nmi-safe monotonic clock provided by the Linux kernel. */
-       last_tsc = &__get_cpu_var(lttng_last_tsc);
+       last_tsc = lttng_this_cpu_ptr(&lttng_last_tsc);
        last = local_read(last_tsc);
        /*
         * Read "last" before "now". It is not strictly required, but it ensures
This page took 0.030008 seconds and 4 git commands to generate.