blob: 4e52e5f122307ed621e44c0cce066575d468c770 [file] [log] [blame]
Patrick Williams93c203f2021-10-06 16:15:23 -05001From 8be4c8a38ee1e297578e094a6e4c143ec5259aba Mon Sep 17 00:00:00 2001
2From: Michael Jeanson <mjeanson@efficios.com>
3Date: Mon, 13 Sep 2021 12:00:38 -0400
4Subject: [PATCH 1/2] fix: cpu/hotplug: Remove deprecated CPU-hotplug
5 functions. (v5.15)
6
7The CPU-hotplug functions get|put_online_cpus() were deprecated in v4.13
8and removed in v5.15.
9
10See upstream commits :
11
12commit 8c854303ce0e38e5bbedd725ff39da7e235865d8
13Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
14Date: Tue Aug 3 16:16:21 2021 +0200
15
16 cpu/hotplug: Remove deprecated CPU-hotplug functions.
17
18 No users in tree use the deprecated CPU-hotplug functions anymore.
19
20 Remove them.
21
22Introduced in v4.13 :
23
24 commit 8f553c498e1772cccb39a114da4a498d22992758
25 Author: Thomas Gleixner <tglx@linutronix.de>
26 Date: Wed May 24 10:15:12 2017 +0200
27
28 cpu/hotplug: Provide cpus_read|write_[un]lock()
29
30 The counting 'rwsem' hackery of get|put_online_cpus() is going to be
31 replaced by percpu rwsem.
32
33 Rename the functions to make it clear that it's locking and not some
34 refcount style interface. These new functions will be used for the
35 preparatory patches which make the code ready for the percpu rwsem
36 conversion.
37
38 Rename all instances in the cpu hotplug code while at it.
39
40Upstream-Status: backport [https://git.lttng.org/?p=lttng-modules.git;a=commit;h=ffcc873470121ef1ebb110df3d9038a38d9cb7cb]
41
42Change-Id: I5a37cf5afc075a402b7347989fac637dfa60a1ed
43Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
44Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
45---
46 include/wrapper/cpu.h | 44 +++++++++++++++++++++++
47 src/lib/ringbuffer/ring_buffer_backend.c | 8 ++---
48 src/lib/ringbuffer/ring_buffer_frontend.c | 17 ++++-----
49 src/lib/ringbuffer/ring_buffer_iterator.c | 15 ++++----
50 src/lttng-context-perf-counters.c | 11 +++---
51 src/lttng-statedump-impl.c | 6 ++--
52 6 files changed, 74 insertions(+), 27 deletions(-)
53 create mode 100644 include/wrapper/cpu.h
54
55diff --git a/include/wrapper/cpu.h b/include/wrapper/cpu.h
56new file mode 100644
57index 00000000..cbee1962
58--- /dev/null
59+++ b/include/wrapper/cpu.h
60@@ -0,0 +1,44 @@
61+/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
62+ *
63+ * wrapper/cpu.h
64+ *
65+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
66+ */
67+
68+#ifndef _LTTNG_WRAPPER_CPU_H
69+#define _LTTNG_WRAPPER_CPU_H
70+
71+#include <linux/cpu.h>
72+#include <lttng/kernel-version.h>
73+
74+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,13,0))
75+
76+static inline
77+void lttng_cpus_read_lock(void)
78+{
79+ cpus_read_lock();
80+}
81+
82+static inline
83+void lttng_cpus_read_unlock(void)
84+{
85+ cpus_read_unlock();
86+}
87+
88+#else /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,13,0) */
89+
90+static inline
91+void lttng_cpus_read_lock(void)
92+{
93+ get_online_cpus();
94+}
95+
96+static inline
97+void lttng_cpus_read_unlock(void)
98+{
99+ put_online_cpus();
100+}
101+
102+#endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,13,0) */
103+
104+#endif /* _LTTNG_WRAPPER_CPU_H */
105diff --git a/src/lib/ringbuffer/ring_buffer_backend.c b/src/lib/ringbuffer/ring_buffer_backend.c
106index 26efb2bc..9a339be0 100644
107--- a/src/lib/ringbuffer/ring_buffer_backend.c
108+++ b/src/lib/ringbuffer/ring_buffer_backend.c
109@@ -12,10 +12,10 @@
110 #include <linux/delay.h>
111 #include <linux/errno.h>
112 #include <linux/slab.h>
113-#include <linux/cpu.h>
114 #include <linux/mm.h>
115 #include <linux/vmalloc.h>
116
117+#include <wrapper/cpu.h>
118 #include <wrapper/mm.h>
119 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
120 #include <ringbuffer/config.h>
121@@ -445,14 +445,14 @@ int channel_backend_init(struct channel_backend *chanb,
122 chanb->cpu_hp_notifier.priority = 5;
123 register_hotcpu_notifier(&chanb->cpu_hp_notifier);
124
125- get_online_cpus();
126+ lttng_cpus_read_lock();
127 for_each_online_cpu(i) {
128 ret = lib_ring_buffer_create(per_cpu_ptr(chanb->buf, i),
129 chanb, i);
130 if (ret)
131 goto free_bufs; /* cpu hotplug locked */
132 }
133- put_online_cpus();
134+ lttng_cpus_read_unlock();
135 #else
136 for_each_possible_cpu(i) {
137 ret = lib_ring_buffer_create(per_cpu_ptr(chanb->buf, i),
138@@ -485,7 +485,7 @@ free_bufs:
139 */
140 #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
141 #ifdef CONFIG_HOTPLUG_CPU
142- put_online_cpus();
143+ lttng_cpus_read_unlock();
144 unregister_hotcpu_notifier(&chanb->cpu_hp_notifier);
145 #endif
146 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
147diff --git a/src/lib/ringbuffer/ring_buffer_frontend.c b/src/lib/ringbuffer/ring_buffer_frontend.c
148index e9056118..87a575d0 100644
149--- a/src/lib/ringbuffer/ring_buffer_frontend.c
150+++ b/src/lib/ringbuffer/ring_buffer_frontend.c
151@@ -48,6 +48,7 @@
152 #include <ringbuffer/iterator.h>
153 #include <ringbuffer/nohz.h>
154 #include <wrapper/atomic.h>
155+#include <wrapper/cpu.h>
156 #include <wrapper/kref.h>
157 #include <wrapper/percpu-defs.h>
158 #include <wrapper/timer.h>
159@@ -724,7 +725,7 @@ static void channel_unregister_notifiers(struct lttng_kernel_ring_buffer_channel
160 int cpu;
161
162 #ifdef CONFIG_HOTPLUG_CPU
163- get_online_cpus();
164+ lttng_cpus_read_lock();
165 chan->cpu_hp_enable = 0;
166 for_each_online_cpu(cpu) {
167 struct lttng_kernel_ring_buffer *buf = per_cpu_ptr(chan->backend.buf,
168@@ -732,7 +733,7 @@ static void channel_unregister_notifiers(struct lttng_kernel_ring_buffer_channel
169 lib_ring_buffer_stop_switch_timer(buf);
170 lib_ring_buffer_stop_read_timer(buf);
171 }
172- put_online_cpus();
173+ lttng_cpus_read_unlock();
174 unregister_cpu_notifier(&chan->cpu_hp_notifier);
175 #else
176 for_each_possible_cpu(cpu) {
177@@ -772,14 +773,14 @@ void lib_ring_buffer_set_quiescent_channel(struct lttng_kernel_ring_buffer_chann
178 const struct lttng_kernel_ring_buffer_config *config = &chan->backend.config;
179
180 if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
181- get_online_cpus();
182+ lttng_cpus_read_lock();
183 for_each_channel_cpu(cpu, chan) {
184 struct lttng_kernel_ring_buffer *buf = per_cpu_ptr(chan->backend.buf,
185 cpu);
186
187 lib_ring_buffer_set_quiescent(buf);
188 }
189- put_online_cpus();
190+ lttng_cpus_read_unlock();
191 } else {
192 struct lttng_kernel_ring_buffer *buf = chan->backend.buf;
193
194@@ -794,14 +795,14 @@ void lib_ring_buffer_clear_quiescent_channel(struct lttng_kernel_ring_buffer_cha
195 const struct lttng_kernel_ring_buffer_config *config = &chan->backend.config;
196
197 if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
198- get_online_cpus();
199+ lttng_cpus_read_lock();
200 for_each_channel_cpu(cpu, chan) {
201 struct lttng_kernel_ring_buffer *buf = per_cpu_ptr(chan->backend.buf,
202 cpu);
203
204 lib_ring_buffer_clear_quiescent(buf);
205 }
206- put_online_cpus();
207+ lttng_cpus_read_unlock();
208 } else {
209 struct lttng_kernel_ring_buffer *buf = chan->backend.buf;
210
211@@ -899,7 +900,7 @@ struct lttng_kernel_ring_buffer_channel *channel_create(const struct lttng_kerne
212 chan->cpu_hp_notifier.priority = 6;
213 register_cpu_notifier(&chan->cpu_hp_notifier);
214
215- get_online_cpus();
216+ lttng_cpus_read_lock();
217 for_each_online_cpu(cpu) {
218 struct lttng_kernel_ring_buffer *buf = per_cpu_ptr(chan->backend.buf,
219 cpu);
220@@ -909,7 +910,7 @@ struct lttng_kernel_ring_buffer_channel *channel_create(const struct lttng_kerne
221 spin_unlock(&per_cpu(ring_buffer_nohz_lock, cpu));
222 }
223 chan->cpu_hp_enable = 1;
224- put_online_cpus();
225+ lttng_cpus_read_unlock();
226 #else
227 for_each_possible_cpu(cpu) {
228 struct lttng_kernel_ring_buffer *buf = per_cpu_ptr(chan->backend.buf,
229diff --git a/src/lib/ringbuffer/ring_buffer_iterator.c b/src/lib/ringbuffer/ring_buffer_iterator.c
230index 25839af6..60c95ca6 100644
231--- a/src/lib/ringbuffer/ring_buffer_iterator.c
232+++ b/src/lib/ringbuffer/ring_buffer_iterator.c
233@@ -10,6 +10,7 @@
234 */
235
236 #include <ringbuffer/iterator.h>
237+#include <wrapper/cpu.h>
238 #include <wrapper/file.h>
239 #include <wrapper/uaccess.h>
240 #include <linux/jiffies.h>
241@@ -440,13 +441,13 @@ int channel_iterator_init(struct lttng_kernel_ring_buffer_channel *chan)
242 chan->hp_iter_notifier.priority = 10;
243 register_cpu_notifier(&chan->hp_iter_notifier);
244
245- get_online_cpus();
246+ lttng_cpus_read_lock();
247 for_each_online_cpu(cpu) {
248 buf = per_cpu_ptr(chan->backend.buf, cpu);
249 lib_ring_buffer_iterator_init(chan, buf);
250 }
251 chan->hp_iter_enable = 1;
252- put_online_cpus();
253+ lttng_cpus_read_unlock();
254 #else
255 for_each_possible_cpu(cpu) {
256 buf = per_cpu_ptr(chan->backend.buf, cpu);
257@@ -519,7 +520,7 @@ int channel_iterator_open(struct lttng_kernel_ring_buffer_channel *chan)
258 CHAN_WARN_ON(chan, config->output != RING_BUFFER_ITERATOR);
259
260 if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
261- get_online_cpus();
262+ lttng_cpus_read_lock();
263 /* Allow CPU hotplug to keep track of opened reader */
264 chan->iter.read_open = 1;
265 for_each_channel_cpu(cpu, chan) {
266@@ -529,7 +530,7 @@ int channel_iterator_open(struct lttng_kernel_ring_buffer_channel *chan)
267 goto error;
268 buf->iter.read_open = 1;
269 }
270- put_online_cpus();
271+ lttng_cpus_read_unlock();
272 } else {
273 buf = channel_get_ring_buffer(config, chan, 0);
274 ret = lib_ring_buffer_iterator_open(buf);
275@@ -538,7 +539,7 @@ int channel_iterator_open(struct lttng_kernel_ring_buffer_channel *chan)
276 error:
277 /* Error should always happen on CPU 0, hence no close is required. */
278 CHAN_WARN_ON(chan, cpu != 0);
279- put_online_cpus();
280+ lttng_cpus_read_unlock();
281 return ret;
282 }
283 EXPORT_SYMBOL_GPL(channel_iterator_open);
284@@ -550,7 +551,7 @@ void channel_iterator_release(struct lttng_kernel_ring_buffer_channel *chan)
285 int cpu;
286
287 if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
288- get_online_cpus();
289+ lttng_cpus_read_lock();
290 for_each_channel_cpu(cpu, chan) {
291 buf = channel_get_ring_buffer(config, chan, cpu);
292 if (buf->iter.read_open) {
293@@ -559,7 +560,7 @@ void channel_iterator_release(struct lttng_kernel_ring_buffer_channel *chan)
294 }
295 }
296 chan->iter.read_open = 0;
297- put_online_cpus();
298+ lttng_cpus_read_unlock();
299 } else {
300 buf = channel_get_ring_buffer(config, chan, 0);
301 lib_ring_buffer_iterator_release(buf);
302diff --git a/src/lttng-context-perf-counters.c b/src/lttng-context-perf-counters.c
303index b0227d47..372f05e0 100644
304--- a/src/lttng-context-perf-counters.c
305+++ b/src/lttng-context-perf-counters.c
306@@ -16,6 +16,7 @@
307 #include <lttng/events.h>
308 #include <lttng/events-internal.h>
309 #include <ringbuffer/frontend_types.h>
310+#include <wrapper/cpu.h>
311 #include <wrapper/vmalloc.h>
312 #include <wrapper/perf.h>
313 #include <lttng/tracer.h>
314@@ -97,10 +98,10 @@ void lttng_destroy_perf_counter_ctx_field(void *priv)
315 {
316 int cpu;
317
318- get_online_cpus();
319+ lttng_cpus_read_lock();
320 for_each_online_cpu(cpu)
321 perf_event_release_kernel(events[cpu]);
322- put_online_cpus();
323+ lttng_cpus_read_unlock();
324 #ifdef CONFIG_HOTPLUG_CPU
325 unregister_cpu_notifier(&perf_field->nb);
326 #endif
327@@ -304,7 +305,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
328 perf_field->nb.priority = 0;
329 register_cpu_notifier(&perf_field->nb);
330 #endif
331- get_online_cpus();
332+ lttng_cpus_read_lock();
333 for_each_online_cpu(cpu) {
334 events[cpu] = wrapper_perf_event_create_kernel_counter(attr,
335 cpu, NULL, overflow_callback);
336@@ -317,7 +318,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
337 goto counter_busy;
338 }
339 }
340- put_online_cpus();
341+ lttng_cpus_read_unlock();
342 perf_field->hp_enable = 1;
343 }
344 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
345@@ -351,7 +352,7 @@ counter_error:
346 if (events[cpu] && !IS_ERR(events[cpu]))
347 perf_event_release_kernel(events[cpu]);
348 }
349- put_online_cpus();
350+ lttng_cpus_read_unlock();
351 #ifdef CONFIG_HOTPLUG_CPU
352 unregister_cpu_notifier(&perf_field->nb);
353 #endif
354diff --git a/src/lttng-statedump-impl.c b/src/lttng-statedump-impl.c
355index 4dfbca0b..2b42783a 100644
356--- a/src/lttng-statedump-impl.c
357+++ b/src/lttng-statedump-impl.c
358@@ -23,7 +23,6 @@
359 #include <linux/file.h>
360 #include <linux/interrupt.h>
361 #include <linux/irqnr.h>
362-#include <linux/cpu.h>
363 #include <linux/netdevice.h>
364 #include <linux/inetdevice.h>
365 #include <linux/mm.h>
366@@ -34,6 +33,7 @@
367
368 #include <lttng/events.h>
369 #include <lttng/tracer.h>
370+#include <wrapper/cpu.h>
371 #include <wrapper/irqdesc.h>
372 #include <wrapper/fdtable.h>
373 #include <wrapper/namespace.h>
374@@ -770,7 +770,7 @@ int do_lttng_statedump(struct lttng_kernel_session *session)
375 * is to guarantee that each CPU has been in a state where is was in
376 * syscall mode (i.e. not in a trap, an IRQ or a soft IRQ).
377 */
378- get_online_cpus();
379+ lttng_cpus_read_lock();
380 atomic_set(&kernel_threads_to_run, num_online_cpus());
381 for_each_online_cpu(cpu) {
382 INIT_DELAYED_WORK(&cpu_work[cpu], lttng_statedump_work_func);
383@@ -778,7 +778,7 @@ int do_lttng_statedump(struct lttng_kernel_session *session)
384 }
385 /* Wait for all threads to run */
386 __wait_event(statedump_wq, (atomic_read(&kernel_threads_to_run) == 0));
387- put_online_cpus();
388+ lttng_cpus_read_unlock();
389 /* Our work is done */
390 trace_lttng_statedump_end(session);
391 return 0;
392--
3932.19.1
394