From: Mathieu Desnoyers Date: Wed, 24 Dec 2014 17:24:04 +0000 (-0500) Subject: Fix: lttng_this_cpu_ptr wrapper for kernel 3.19+ X-Git-Tag: v2.6.0~9 X-Git-Url: https://git.lttng.org/?p=lttng-modules.git;a=commitdiff_plain;h=1816623505f9a0111fa5041da63f8e1099b6ffcc Fix: lttng_this_cpu_ptr wrapper for kernel 3.19+ 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 --- diff --git a/lib/ringbuffer/frontend_api.h b/lib/ringbuffer/frontend_api.h index ff6abce9..b622bd7e 100644 --- a/lib/ringbuffer/frontend_api.h +++ b/lib/ringbuffer/frontend_api.h @@ -30,6 +30,7 @@ */ #include "../../wrapper/ringbuffer/frontend.h" +#include "../../wrapper/percpu-defs.h" #include #include @@ -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(); } diff --git a/lib/ringbuffer/ring_buffer_frontend.c b/lib/ringbuffer/ring_buffer_frontend.c index ae0b9e39..c4b797ce 100644 --- a/lib/ringbuffer/ring_buffer_frontend.c +++ b/lib/ringbuffer/ring_buffer_frontend.c @@ -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 index 00000000..bba1bcea --- /dev/null +++ b/wrapper/percpu-defs.h @@ -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 + * + * 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 + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) + +#include + +#define lttng_this_cpu_ptr(ptr) this_cpu_ptr(ptr) + +#else /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0) */ + +#include + +#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 */ diff --git a/wrapper/trace-clock.h b/wrapper/trace-clock.h index 5705d0c2..1b2821a1 100644 --- a/wrapper/trace-clock.h +++ b/wrapper/trace-clock.h @@ -36,6 +36,7 @@ #include #include #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(<tng_last_tsc); last = local_read(last_tsc); /* * Read "last" before "now". It is not strictly required, but it ensures