2 * ring_buffer_frontend.c
4 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Ring buffer wait-free buffer synchronization. Producer-consumer and flight
22 * recorder (overwrite) modes. See thesis:
24 * Desnoyers, Mathieu (2009), "Low-Impact Operating System Tracing", Ph.D.
25 * dissertation, Ecole Polytechnique de Montreal.
26 * http://www.lttng.org/pub/thesis/desnoyers-dissertation-2009-12.pdf
28 * - Algorithm presentation in Chapter 5:
29 * "Lockless Multi-Core High-Throughput Buffering".
30 * - Algorithm formal verification in Section 8.6:
31 * "Formal verification of LTTng"
34 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
36 * Inspired from LTT and RelayFS:
37 * Karim Yaghmour <karim@opersys.com>
38 * Tom Zanussi <zanussi@us.ibm.com>
39 * Bob Wisniewski <bob@watson.ibm.com>
41 * Bob Wisniewski <bob@watson.ibm.com>
43 * Buffer reader semantic :
46 * while buffer is not finalized and empty
48 * - if return value != 0, continue
49 * - splice one subbuffer worth of data to a pipe
50 * - splice the data from pipe to disk/network
54 #include <linux/delay.h>
55 #include <linux/module.h>
56 #include <linux/percpu.h>
58 #include <wrapper/ringbuffer/config.h>
59 #include <wrapper/ringbuffer/backend.h>
60 #include <wrapper/ringbuffer/frontend.h>
61 #include <wrapper/ringbuffer/iterator.h>
62 #include <wrapper/ringbuffer/nohz.h>
63 #include <wrapper/atomic.h>
64 #include <wrapper/kref.h>
65 #include <wrapper/percpu-defs.h>
66 #include <wrapper/timer.h>
69 * Internal structure representing offsets to use at a sub-buffer switch.
71 struct switch_offsets
{
72 unsigned long begin
, end
, old
;
73 size_t pre_header_padding
, size
;
74 unsigned int switch_new_start
:1, switch_new_end
:1, switch_old_start
:1,
85 static ATOMIC_NOTIFIER_HEAD(tick_nohz_notifier
);
86 #endif /* CONFIG_NO_HZ */
88 static DEFINE_PER_CPU(spinlock_t
, ring_buffer_nohz_lock
);
90 DEFINE_PER_CPU(unsigned int, lib_ring_buffer_nesting
);
91 EXPORT_PER_CPU_SYMBOL(lib_ring_buffer_nesting
);
94 void lib_ring_buffer_print_errors(struct channel
*chan
,
95 struct lib_ring_buffer
*buf
, int cpu
);
97 void _lib_ring_buffer_switch_remote(struct lib_ring_buffer
*buf
,
98 enum switch_mode mode
);
101 int lib_ring_buffer_poll_deliver(const struct lib_ring_buffer_config
*config
,
102 struct lib_ring_buffer
*buf
,
103 struct channel
*chan
)
105 unsigned long consumed_old
, consumed_idx
, commit_count
, write_offset
;
107 consumed_old
= atomic_long_read(&buf
->consumed
);
108 consumed_idx
= subbuf_index(consumed_old
, chan
);
109 commit_count
= v_read(config
, &buf
->commit_cold
[consumed_idx
].cc_sb
);
111 * No memory barrier here, since we are only interested
112 * in a statistically correct polling result. The next poll will
113 * get the data is we are racing. The mb() that ensures correct
114 * memory order is in get_subbuf.
116 write_offset
= v_read(config
, &buf
->offset
);
119 * Check that the subbuffer we are trying to consume has been
120 * already fully committed.
123 if (((commit_count
- chan
->backend
.subbuf_size
)
124 & chan
->commit_count_mask
)
125 - (buf_trunc(consumed_old
, chan
)
126 >> chan
->backend
.num_subbuf_order
)
131 * Check that we are not about to read the same subbuffer in
132 * which the writer head is.
134 if (subbuf_trunc(write_offset
, chan
) - subbuf_trunc(consumed_old
, chan
)
142 * Must be called under cpu hotplug protection.
144 void lib_ring_buffer_free(struct lib_ring_buffer
*buf
)
146 struct channel
*chan
= buf
->backend
.chan
;
148 lib_ring_buffer_print_errors(chan
, buf
, buf
->backend
.cpu
);
149 kfree(buf
->commit_hot
);
150 kfree(buf
->commit_cold
);
152 lib_ring_buffer_backend_free(&buf
->backend
);
156 * lib_ring_buffer_reset - Reset ring buffer to initial values.
159 * Effectively empty the ring buffer. Should be called when the buffer is not
160 * used for writing. The ring buffer can be opened for reading, but the reader
161 * should not be using the iterator concurrently with reset. The previous
162 * current iterator record is reset.
164 void lib_ring_buffer_reset(struct lib_ring_buffer
*buf
)
166 struct channel
*chan
= buf
->backend
.chan
;
167 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
171 * Reset iterator first. It will put the subbuffer if it currently holds
174 lib_ring_buffer_iterator_reset(buf
);
175 v_set(config
, &buf
->offset
, 0);
176 for (i
= 0; i
< chan
->backend
.num_subbuf
; i
++) {
177 v_set(config
, &buf
->commit_hot
[i
].cc
, 0);
178 v_set(config
, &buf
->commit_hot
[i
].seq
, 0);
179 v_set(config
, &buf
->commit_cold
[i
].cc_sb
, 0);
181 atomic_long_set(&buf
->consumed
, 0);
182 atomic_set(&buf
->record_disabled
, 0);
183 v_set(config
, &buf
->last_tsc
, 0);
184 lib_ring_buffer_backend_reset(&buf
->backend
);
185 /* Don't reset number of active readers */
186 v_set(config
, &buf
->records_lost_full
, 0);
187 v_set(config
, &buf
->records_lost_wrap
, 0);
188 v_set(config
, &buf
->records_lost_big
, 0);
189 v_set(config
, &buf
->records_count
, 0);
190 v_set(config
, &buf
->records_overrun
, 0);
193 EXPORT_SYMBOL_GPL(lib_ring_buffer_reset
);
196 * channel_reset - Reset channel to initial values.
199 * Effectively empty the channel. Should be called when the channel is not used
200 * for writing. The channel can be opened for reading, but the reader should not
201 * be using the iterator concurrently with reset. The previous current iterator
204 void channel_reset(struct channel
*chan
)
207 * Reset iterators first. Will put the subbuffer if held for reading.
209 channel_iterator_reset(chan
);
210 atomic_set(&chan
->record_disabled
, 0);
211 /* Don't reset commit_count_mask, still valid */
212 channel_backend_reset(&chan
->backend
);
213 /* Don't reset switch/read timer interval */
214 /* Don't reset notifiers and notifier enable bits */
215 /* Don't reset reader reference count */
217 EXPORT_SYMBOL_GPL(channel_reset
);
220 * Must be called under cpu hotplug protection.
222 int lib_ring_buffer_create(struct lib_ring_buffer
*buf
,
223 struct channel_backend
*chanb
, int cpu
)
225 const struct lib_ring_buffer_config
*config
= &chanb
->config
;
226 struct channel
*chan
= container_of(chanb
, struct channel
, backend
);
227 void *priv
= chanb
->priv
;
228 size_t subbuf_header_size
;
232 /* Test for cpu hotplug */
233 if (buf
->backend
.allocated
)
237 * Paranoia: per cpu dynamic allocation is not officially documented as
238 * zeroing the memory, so let's do it here too, just in case.
240 memset(buf
, 0, sizeof(*buf
));
242 ret
= lib_ring_buffer_backend_create(&buf
->backend
, &chan
->backend
, cpu
);
247 kzalloc_node(ALIGN(sizeof(*buf
->commit_hot
)
248 * chan
->backend
.num_subbuf
,
249 1 << INTERNODE_CACHE_SHIFT
),
250 GFP_KERNEL
, cpu_to_node(max(cpu
, 0)));
251 if (!buf
->commit_hot
) {
257 kzalloc_node(ALIGN(sizeof(*buf
->commit_cold
)
258 * chan
->backend
.num_subbuf
,
259 1 << INTERNODE_CACHE_SHIFT
),
260 GFP_KERNEL
, cpu_to_node(max(cpu
, 0)));
261 if (!buf
->commit_cold
) {
266 init_waitqueue_head(&buf
->read_wait
);
267 init_waitqueue_head(&buf
->write_wait
);
268 raw_spin_lock_init(&buf
->raw_tick_nohz_spinlock
);
271 * Write the subbuffer header for first subbuffer so we know the total
272 * duration of data gathering.
274 subbuf_header_size
= config
->cb
.subbuffer_header_size();
275 v_set(config
, &buf
->offset
, subbuf_header_size
);
276 subbuffer_id_clear_noref(config
, &buf
->backend
.buf_wsb
[0].id
);
277 tsc
= config
->cb
.ring_buffer_clock_read(buf
->backend
.chan
);
278 config
->cb
.buffer_begin(buf
, tsc
, 0);
279 v_add(config
, subbuf_header_size
, &buf
->commit_hot
[0].cc
);
281 if (config
->cb
.buffer_create
) {
282 ret
= config
->cb
.buffer_create(buf
, priv
, cpu
, chanb
->name
);
288 * Ensure the buffer is ready before setting it to allocated and setting
290 * Used for cpu hotplug vs cpumask iteration.
293 buf
->backend
.allocated
= 1;
295 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
296 CHAN_WARN_ON(chan
, cpumask_test_cpu(cpu
,
297 chan
->backend
.cpumask
));
298 cpumask_set_cpu(cpu
, chan
->backend
.cpumask
);
305 kfree(buf
->commit_cold
);
307 kfree(buf
->commit_hot
);
309 lib_ring_buffer_backend_free(&buf
->backend
);
313 static void switch_buffer_timer(unsigned long data
)
315 struct lib_ring_buffer
*buf
= (struct lib_ring_buffer
*)data
;
316 struct channel
*chan
= buf
->backend
.chan
;
317 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
320 * Only flush buffers periodically if readers are active.
322 if (atomic_long_read(&buf
->active_readers
))
323 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
325 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
326 lttng_mod_timer_pinned(&buf
->switch_timer
,
327 jiffies
+ chan
->switch_timer_interval
);
329 mod_timer(&buf
->switch_timer
,
330 jiffies
+ chan
->switch_timer_interval
);
334 * Called with ring_buffer_nohz_lock held for per-cpu buffers.
336 static void lib_ring_buffer_start_switch_timer(struct lib_ring_buffer
*buf
)
338 struct channel
*chan
= buf
->backend
.chan
;
339 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
341 if (!chan
->switch_timer_interval
|| buf
->switch_timer_enabled
)
344 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
345 lttng_init_timer_pinned(&buf
->switch_timer
);
347 init_timer(&buf
->switch_timer
);
349 buf
->switch_timer
.function
= switch_buffer_timer
;
350 buf
->switch_timer
.expires
= jiffies
+ chan
->switch_timer_interval
;
351 buf
->switch_timer
.data
= (unsigned long)buf
;
352 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
353 add_timer_on(&buf
->switch_timer
, buf
->backend
.cpu
);
355 add_timer(&buf
->switch_timer
);
356 buf
->switch_timer_enabled
= 1;
360 * Called with ring_buffer_nohz_lock held for per-cpu buffers.
362 static void lib_ring_buffer_stop_switch_timer(struct lib_ring_buffer
*buf
)
364 struct channel
*chan
= buf
->backend
.chan
;
366 if (!chan
->switch_timer_interval
|| !buf
->switch_timer_enabled
)
369 del_timer_sync(&buf
->switch_timer
);
370 buf
->switch_timer_enabled
= 0;
374 * Polling timer to check the channels for data.
376 static void read_buffer_timer(unsigned long data
)
378 struct lib_ring_buffer
*buf
= (struct lib_ring_buffer
*)data
;
379 struct channel
*chan
= buf
->backend
.chan
;
380 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
382 CHAN_WARN_ON(chan
, !buf
->backend
.allocated
);
384 if (atomic_long_read(&buf
->active_readers
)
385 && lib_ring_buffer_poll_deliver(config
, buf
, chan
)) {
386 wake_up_interruptible(&buf
->read_wait
);
387 wake_up_interruptible(&chan
->read_wait
);
390 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
391 lttng_mod_timer_pinned(&buf
->read_timer
,
392 jiffies
+ chan
->read_timer_interval
);
394 mod_timer(&buf
->read_timer
,
395 jiffies
+ chan
->read_timer_interval
);
399 * Called with ring_buffer_nohz_lock held for per-cpu buffers.
401 static void lib_ring_buffer_start_read_timer(struct lib_ring_buffer
*buf
)
403 struct channel
*chan
= buf
->backend
.chan
;
404 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
406 if (config
->wakeup
!= RING_BUFFER_WAKEUP_BY_TIMER
407 || !chan
->read_timer_interval
408 || buf
->read_timer_enabled
)
411 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
412 lttng_init_timer_pinned(&buf
->read_timer
);
414 init_timer(&buf
->read_timer
);
416 buf
->read_timer
.function
= read_buffer_timer
;
417 buf
->read_timer
.expires
= jiffies
+ chan
->read_timer_interval
;
418 buf
->read_timer
.data
= (unsigned long)buf
;
420 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
421 add_timer_on(&buf
->read_timer
, buf
->backend
.cpu
);
423 add_timer(&buf
->read_timer
);
424 buf
->read_timer_enabled
= 1;
428 * Called with ring_buffer_nohz_lock held for per-cpu buffers.
430 static void lib_ring_buffer_stop_read_timer(struct lib_ring_buffer
*buf
)
432 struct channel
*chan
= buf
->backend
.chan
;
433 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
435 if (config
->wakeup
!= RING_BUFFER_WAKEUP_BY_TIMER
436 || !chan
->read_timer_interval
437 || !buf
->read_timer_enabled
)
440 del_timer_sync(&buf
->read_timer
);
442 * do one more check to catch data that has been written in the last
445 if (lib_ring_buffer_poll_deliver(config
, buf
, chan
)) {
446 wake_up_interruptible(&buf
->read_wait
);
447 wake_up_interruptible(&chan
->read_wait
);
449 buf
->read_timer_enabled
= 0;
452 #ifdef CONFIG_HOTPLUG_CPU
454 * lib_ring_buffer_cpu_hp_callback - CPU hotplug callback
455 * @nb: notifier block
456 * @action: hotplug action to take
459 * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
462 int lib_ring_buffer_cpu_hp_callback(struct notifier_block
*nb
,
463 unsigned long action
,
466 unsigned int cpu
= (unsigned long)hcpu
;
467 struct channel
*chan
= container_of(nb
, struct channel
,
469 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
, cpu
);
470 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
472 if (!chan
->cpu_hp_enable
)
475 CHAN_WARN_ON(chan
, config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
);
478 case CPU_DOWN_FAILED
:
479 case CPU_DOWN_FAILED_FROZEN
:
481 case CPU_ONLINE_FROZEN
:
482 wake_up_interruptible(&chan
->hp_wait
);
483 lib_ring_buffer_start_switch_timer(buf
);
484 lib_ring_buffer_start_read_timer(buf
);
487 case CPU_DOWN_PREPARE
:
488 case CPU_DOWN_PREPARE_FROZEN
:
489 lib_ring_buffer_stop_switch_timer(buf
);
490 lib_ring_buffer_stop_read_timer(buf
);
494 case CPU_DEAD_FROZEN
:
496 * Performing a buffer switch on a remote CPU. Performed by
497 * the CPU responsible for doing the hotunplug after the target
498 * CPU stopped running completely. Ensures that all data
499 * from that remote CPU is flushed.
501 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
510 #if defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER)
512 * For per-cpu buffers, call the reader wakeups before switching the buffer, so
513 * that wake-up-tracing generated events are flushed before going idle (in
514 * tick_nohz). We test if the spinlock is locked to deal with the race where
515 * readers try to sample the ring buffer before we perform the switch. We let
516 * the readers retry in that case. If there is data in the buffer, the wake up
517 * is going to forbid the CPU running the reader thread from going idle.
519 static int notrace
ring_buffer_tick_nohz_callback(struct notifier_block
*nb
,
523 struct channel
*chan
= container_of(nb
, struct channel
,
525 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
526 struct lib_ring_buffer
*buf
;
527 int cpu
= smp_processor_id();
529 if (config
->alloc
!= RING_BUFFER_ALLOC_PER_CPU
) {
531 * We don't support keeping the system idle with global buffers
532 * and streaming active. In order to do so, we would need to
533 * sample a non-nohz-cpumask racelessly with the nohz updates
534 * without adding synchronization overhead to nohz. Leave this
535 * use-case out for now.
540 buf
= channel_get_ring_buffer(config
, chan
, cpu
);
542 case TICK_NOHZ_FLUSH
:
543 raw_spin_lock(&buf
->raw_tick_nohz_spinlock
);
544 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_TIMER
545 && chan
->read_timer_interval
546 && atomic_long_read(&buf
->active_readers
)
547 && (lib_ring_buffer_poll_deliver(config
, buf
, chan
)
548 || lib_ring_buffer_pending_data(config
, buf
, chan
))) {
549 wake_up_interruptible(&buf
->read_wait
);
550 wake_up_interruptible(&chan
->read_wait
);
552 if (chan
->switch_timer_interval
)
553 lib_ring_buffer_switch_slow(buf
, SWITCH_ACTIVE
);
554 raw_spin_unlock(&buf
->raw_tick_nohz_spinlock
);
557 spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock
));
558 lib_ring_buffer_stop_switch_timer(buf
);
559 lib_ring_buffer_stop_read_timer(buf
);
560 spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock
));
562 case TICK_NOHZ_RESTART
:
563 spin_lock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock
));
564 lib_ring_buffer_start_read_timer(buf
);
565 lib_ring_buffer_start_switch_timer(buf
);
566 spin_unlock(lttng_this_cpu_ptr(&ring_buffer_nohz_lock
));
573 void notrace
lib_ring_buffer_tick_nohz_flush(void)
575 atomic_notifier_call_chain(&tick_nohz_notifier
, TICK_NOHZ_FLUSH
,
579 void notrace
lib_ring_buffer_tick_nohz_stop(void)
581 atomic_notifier_call_chain(&tick_nohz_notifier
, TICK_NOHZ_STOP
,
585 void notrace
lib_ring_buffer_tick_nohz_restart(void)
587 atomic_notifier_call_chain(&tick_nohz_notifier
, TICK_NOHZ_RESTART
,
590 #endif /* defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER) */
595 static void channel_unregister_notifiers(struct channel
*chan
)
597 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
600 channel_iterator_unregister_notifiers(chan
);
601 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
604 * Remove the nohz notifier first, so we are certain we stop
607 atomic_notifier_chain_unregister(&tick_nohz_notifier
,
608 &chan
->tick_nohz_notifier
);
610 * ring_buffer_nohz_lock will not be needed below, because
611 * we just removed the notifiers, which were the only source of
614 #endif /* CONFIG_NO_HZ */
615 #ifdef CONFIG_HOTPLUG_CPU
617 chan
->cpu_hp_enable
= 0;
618 for_each_online_cpu(cpu
) {
619 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
621 lib_ring_buffer_stop_switch_timer(buf
);
622 lib_ring_buffer_stop_read_timer(buf
);
625 unregister_cpu_notifier(&chan
->cpu_hp_notifier
);
627 for_each_possible_cpu(cpu
) {
628 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
630 lib_ring_buffer_stop_switch_timer(buf
);
631 lib_ring_buffer_stop_read_timer(buf
);
635 struct lib_ring_buffer
*buf
= chan
->backend
.buf
;
637 lib_ring_buffer_stop_switch_timer(buf
);
638 lib_ring_buffer_stop_read_timer(buf
);
640 channel_backend_unregister_notifiers(&chan
->backend
);
643 static void lib_ring_buffer_set_quiescent(struct lib_ring_buffer
*buf
)
645 if (!buf
->quiescent
) {
646 buf
->quiescent
= true;
647 _lib_ring_buffer_switch_remote(buf
, SWITCH_FLUSH
);
651 static void lib_ring_buffer_clear_quiescent(struct lib_ring_buffer
*buf
)
653 buf
->quiescent
= false;
656 void lib_ring_buffer_set_quiescent_channel(struct channel
*chan
)
659 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
661 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
663 for_each_channel_cpu(cpu
, chan
) {
664 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
667 lib_ring_buffer_set_quiescent(buf
);
671 struct lib_ring_buffer
*buf
= chan
->backend
.buf
;
673 lib_ring_buffer_set_quiescent(buf
);
676 EXPORT_SYMBOL_GPL(lib_ring_buffer_set_quiescent_channel
);
678 void lib_ring_buffer_clear_quiescent_channel(struct channel
*chan
)
681 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
683 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
685 for_each_channel_cpu(cpu
, chan
) {
686 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
689 lib_ring_buffer_clear_quiescent(buf
);
693 struct lib_ring_buffer
*buf
= chan
->backend
.buf
;
695 lib_ring_buffer_clear_quiescent(buf
);
698 EXPORT_SYMBOL_GPL(lib_ring_buffer_clear_quiescent_channel
);
700 static void channel_free(struct channel
*chan
)
702 if (chan
->backend
.release_priv_ops
) {
703 chan
->backend
.release_priv_ops(chan
->backend
.priv_ops
);
705 channel_iterator_free(chan
);
706 channel_backend_free(&chan
->backend
);
711 * channel_create - Create channel.
712 * @config: ring buffer instance configuration
713 * @name: name of the channel
714 * @priv: ring buffer client private data
715 * @buf_addr: pointer the the beginning of the preallocated buffer contiguous
716 * address mapping. It is used only by RING_BUFFER_STATIC
717 * configuration. It can be set to NULL for other backends.
718 * @subbuf_size: subbuffer size
719 * @num_subbuf: number of subbuffers
720 * @switch_timer_interval: Time interval (in us) to fill sub-buffers with
721 * padding to let readers get those sub-buffers.
722 * Used for live streaming.
723 * @read_timer_interval: Time interval (in us) to wake up pending readers.
726 * Returns NULL on failure.
728 struct channel
*channel_create(const struct lib_ring_buffer_config
*config
,
729 const char *name
, void *priv
, void *buf_addr
,
731 size_t num_subbuf
, unsigned int switch_timer_interval
,
732 unsigned int read_timer_interval
)
735 struct channel
*chan
;
737 if (lib_ring_buffer_check_config(config
, switch_timer_interval
,
738 read_timer_interval
))
741 chan
= kzalloc(sizeof(struct channel
), GFP_KERNEL
);
745 ret
= channel_backend_init(&chan
->backend
, name
, config
, priv
,
746 subbuf_size
, num_subbuf
);
750 ret
= channel_iterator_init(chan
);
752 goto error_free_backend
;
754 chan
->commit_count_mask
= (~0UL >> chan
->backend
.num_subbuf_order
);
755 chan
->switch_timer_interval
= usecs_to_jiffies(switch_timer_interval
);
756 chan
->read_timer_interval
= usecs_to_jiffies(read_timer_interval
);
757 kref_init(&chan
->ref
);
758 init_waitqueue_head(&chan
->read_wait
);
759 init_waitqueue_head(&chan
->hp_wait
);
761 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
762 #if defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER)
763 /* Only benefit from NO_HZ idle with per-cpu buffers for now. */
764 chan
->tick_nohz_notifier
.notifier_call
=
765 ring_buffer_tick_nohz_callback
;
766 chan
->tick_nohz_notifier
.priority
= ~0U;
767 atomic_notifier_chain_register(&tick_nohz_notifier
,
768 &chan
->tick_nohz_notifier
);
769 #endif /* defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER) */
772 * In case of non-hotplug cpu, if the ring-buffer is allocated
773 * in early initcall, it will not be notified of secondary cpus.
774 * In that off case, we need to allocate for all possible cpus.
776 #ifdef CONFIG_HOTPLUG_CPU
777 chan
->cpu_hp_notifier
.notifier_call
=
778 lib_ring_buffer_cpu_hp_callback
;
779 chan
->cpu_hp_notifier
.priority
= 6;
780 register_cpu_notifier(&chan
->cpu_hp_notifier
);
783 for_each_online_cpu(cpu
) {
784 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
786 spin_lock(&per_cpu(ring_buffer_nohz_lock
, cpu
));
787 lib_ring_buffer_start_switch_timer(buf
);
788 lib_ring_buffer_start_read_timer(buf
);
789 spin_unlock(&per_cpu(ring_buffer_nohz_lock
, cpu
));
791 chan
->cpu_hp_enable
= 1;
794 for_each_possible_cpu(cpu
) {
795 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
797 spin_lock(&per_cpu(ring_buffer_nohz_lock
, cpu
));
798 lib_ring_buffer_start_switch_timer(buf
);
799 lib_ring_buffer_start_read_timer(buf
);
800 spin_unlock(&per_cpu(ring_buffer_nohz_lock
, cpu
));
804 struct lib_ring_buffer
*buf
= chan
->backend
.buf
;
806 lib_ring_buffer_start_switch_timer(buf
);
807 lib_ring_buffer_start_read_timer(buf
);
813 channel_backend_free(&chan
->backend
);
818 EXPORT_SYMBOL_GPL(channel_create
);
821 void channel_release(struct kref
*kref
)
823 struct channel
*chan
= container_of(kref
, struct channel
, ref
);
828 * channel_destroy - Finalize, wait for q.s. and destroy channel.
829 * @chan: channel to destroy
832 * Call "destroy" callback, finalize channels, and then decrement the
833 * channel reference count. Note that when readers have completed data
834 * consumption of finalized channels, get_subbuf() will return -ENODATA.
835 * They should release their handle at that point. Returns the private
838 void *channel_destroy(struct channel
*chan
)
841 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
844 channel_unregister_notifiers(chan
);
846 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
848 * No need to hold cpu hotplug, because all notifiers have been
851 for_each_channel_cpu(cpu
, chan
) {
852 struct lib_ring_buffer
*buf
= per_cpu_ptr(chan
->backend
.buf
,
855 if (config
->cb
.buffer_finalize
)
856 config
->cb
.buffer_finalize(buf
,
859 if (buf
->backend
.allocated
)
860 lib_ring_buffer_set_quiescent(buf
);
862 * Perform flush before writing to finalized.
865 ACCESS_ONCE(buf
->finalized
) = 1;
866 wake_up_interruptible(&buf
->read_wait
);
869 struct lib_ring_buffer
*buf
= chan
->backend
.buf
;
871 if (config
->cb
.buffer_finalize
)
872 config
->cb
.buffer_finalize(buf
, chan
->backend
.priv
, -1);
873 if (buf
->backend
.allocated
)
874 lib_ring_buffer_set_quiescent(buf
);
876 * Perform flush before writing to finalized.
879 ACCESS_ONCE(buf
->finalized
) = 1;
880 wake_up_interruptible(&buf
->read_wait
);
882 ACCESS_ONCE(chan
->finalized
) = 1;
883 wake_up_interruptible(&chan
->hp_wait
);
884 wake_up_interruptible(&chan
->read_wait
);
885 priv
= chan
->backend
.priv
;
886 kref_put(&chan
->ref
, channel_release
);
889 EXPORT_SYMBOL_GPL(channel_destroy
);
891 struct lib_ring_buffer
*channel_get_ring_buffer(
892 const struct lib_ring_buffer_config
*config
,
893 struct channel
*chan
, int cpu
)
895 if (config
->alloc
== RING_BUFFER_ALLOC_GLOBAL
)
896 return chan
->backend
.buf
;
898 return per_cpu_ptr(chan
->backend
.buf
, cpu
);
900 EXPORT_SYMBOL_GPL(channel_get_ring_buffer
);
902 int lib_ring_buffer_open_read(struct lib_ring_buffer
*buf
)
904 struct channel
*chan
= buf
->backend
.chan
;
906 if (!atomic_long_add_unless(&buf
->active_readers
, 1, 1))
908 if (!lttng_kref_get(&chan
->ref
)) {
909 atomic_long_dec(&buf
->active_readers
);
912 lttng_smp_mb__after_atomic();
915 EXPORT_SYMBOL_GPL(lib_ring_buffer_open_read
);
917 void lib_ring_buffer_release_read(struct lib_ring_buffer
*buf
)
919 struct channel
*chan
= buf
->backend
.chan
;
921 CHAN_WARN_ON(chan
, atomic_long_read(&buf
->active_readers
) != 1);
922 lttng_smp_mb__before_atomic();
923 atomic_long_dec(&buf
->active_readers
);
924 kref_put(&chan
->ref
, channel_release
);
926 EXPORT_SYMBOL_GPL(lib_ring_buffer_release_read
);
929 * Promote compiler barrier to a smp_mb().
930 * For the specific ring buffer case, this IPI call should be removed if the
931 * architecture does not reorder writes. This should eventually be provided by
932 * a separate architecture-specific infrastructure.
934 static void remote_mb(void *info
)
940 * lib_ring_buffer_snapshot - save subbuffer position snapshot (for read)
942 * @consumed: consumed count indicating the position where to read
943 * @produced: produced count, indicates position when to stop reading
945 * Returns -ENODATA if buffer is finalized, -EAGAIN if there is currently no
946 * data to read at consumed position, or 0 if the get operation succeeds.
947 * Busy-loop trying to get data if the tick_nohz sequence lock is held.
950 int lib_ring_buffer_snapshot(struct lib_ring_buffer
*buf
,
951 unsigned long *consumed
, unsigned long *produced
)
953 struct channel
*chan
= buf
->backend
.chan
;
954 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
955 unsigned long consumed_cur
, write_offset
;
959 finalized
= ACCESS_ONCE(buf
->finalized
);
961 * Read finalized before counters.
964 consumed_cur
= atomic_long_read(&buf
->consumed
);
966 * No need to issue a memory barrier between consumed count read and
967 * write offset read, because consumed count can only change
968 * concurrently in overwrite mode, and we keep a sequence counter
969 * identifier derived from the write offset to check we are getting
970 * the same sub-buffer we are expecting (the sub-buffers are atomically
971 * "tagged" upon writes, tags are checked upon read).
973 write_offset
= v_read(config
, &buf
->offset
);
976 * Check that we are not about to read the same subbuffer in
977 * which the writer head is.
979 if (subbuf_trunc(write_offset
, chan
) - subbuf_trunc(consumed_cur
, chan
)
983 *consumed
= consumed_cur
;
984 *produced
= subbuf_trunc(write_offset
, chan
);
990 * The memory barriers __wait_event()/wake_up_interruptible() take care
991 * of "raw_spin_is_locked" memory ordering.
995 else if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1000 EXPORT_SYMBOL_GPL(lib_ring_buffer_snapshot
);
1003 * lib_ring_buffer_put_snapshot - move consumed counter forward
1005 * Should only be called from consumer context.
1007 * @consumed_new: new consumed count value
1009 void lib_ring_buffer_move_consumer(struct lib_ring_buffer
*buf
,
1010 unsigned long consumed_new
)
1012 struct lib_ring_buffer_backend
*bufb
= &buf
->backend
;
1013 struct channel
*chan
= bufb
->chan
;
1014 unsigned long consumed
;
1016 CHAN_WARN_ON(chan
, atomic_long_read(&buf
->active_readers
) != 1);
1019 * Only push the consumed value forward.
1020 * If the consumed cmpxchg fails, this is because we have been pushed by
1021 * the writer in flight recorder mode.
1023 consumed
= atomic_long_read(&buf
->consumed
);
1024 while ((long) consumed
- (long) consumed_new
< 0)
1025 consumed
= atomic_long_cmpxchg(&buf
->consumed
, consumed
,
1027 /* Wake-up the metadata producer */
1028 wake_up_interruptible(&buf
->write_wait
);
1030 EXPORT_SYMBOL_GPL(lib_ring_buffer_move_consumer
);
1033 * lib_ring_buffer_get_subbuf - get exclusive access to subbuffer for reading
1035 * @consumed: consumed count indicating the position where to read
1037 * Returns -ENODATA if buffer is finalized, -EAGAIN if there is currently no
1038 * data to read at consumed position, or 0 if the get operation succeeds.
1039 * Busy-loop trying to get data if the tick_nohz sequence lock is held.
1041 int lib_ring_buffer_get_subbuf(struct lib_ring_buffer
*buf
,
1042 unsigned long consumed
)
1044 struct channel
*chan
= buf
->backend
.chan
;
1045 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1046 unsigned long consumed_cur
, consumed_idx
, commit_count
, write_offset
;
1050 if (buf
->get_subbuf
) {
1052 * Reader is trying to get a subbuffer twice.
1054 CHAN_WARN_ON(chan
, 1);
1058 finalized
= ACCESS_ONCE(buf
->finalized
);
1060 * Read finalized before counters.
1063 consumed_cur
= atomic_long_read(&buf
->consumed
);
1064 consumed_idx
= subbuf_index(consumed
, chan
);
1065 commit_count
= v_read(config
, &buf
->commit_cold
[consumed_idx
].cc_sb
);
1067 * Make sure we read the commit count before reading the buffer
1068 * data and the write offset. Correct consumed offset ordering
1069 * wrt commit count is insured by the use of cmpxchg to update
1070 * the consumed offset.
1071 * smp_call_function_single can fail if the remote CPU is offline,
1072 * this is OK because then there is no wmb to execute there.
1073 * If our thread is executing on the same CPU as the on the buffers
1074 * belongs to, we don't have to synchronize it at all. If we are
1075 * migrated, the scheduler will take care of the memory barriers.
1076 * Normally, smp_call_function_single() should ensure program order when
1077 * executing the remote function, which implies that it surrounds the
1078 * function execution with :
1089 * However, smp_call_function_single() does not seem to clearly execute
1090 * such barriers. It depends on spinlock semantic to provide the barrier
1091 * before executing the IPI and, when busy-looping, csd_lock_wait only
1092 * executes smp_mb() when it has to wait for the other CPU.
1094 * I don't trust this code. Therefore, let's add the smp_mb() sequence
1095 * required ourself, even if duplicated. It has no performance impact
1098 * smp_mb() is needed because smp_rmb() and smp_wmb() only order read vs
1099 * read and write vs write. They do not ensure core synchronization. We
1100 * really have to ensure total order between the 3 barriers running on
1103 if (config
->ipi
== RING_BUFFER_IPI_BARRIER
) {
1104 if (config
->sync
== RING_BUFFER_SYNC_PER_CPU
1105 && config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
) {
1106 if (raw_smp_processor_id() != buf
->backend
.cpu
) {
1107 /* Total order with IPI handler smp_mb() */
1109 smp_call_function_single(buf
->backend
.cpu
,
1110 remote_mb
, NULL
, 1);
1111 /* Total order with IPI handler smp_mb() */
1115 /* Total order with IPI handler smp_mb() */
1117 smp_call_function(remote_mb
, NULL
, 1);
1118 /* Total order with IPI handler smp_mb() */
1123 * Local rmb to match the remote wmb to read the commit count
1124 * before the buffer data and the write offset.
1129 write_offset
= v_read(config
, &buf
->offset
);
1132 * Check that the buffer we are getting is after or at consumed_cur
1135 if ((long) subbuf_trunc(consumed
, chan
)
1136 - (long) subbuf_trunc(consumed_cur
, chan
) < 0)
1140 * Check that the subbuffer we are trying to consume has been
1141 * already fully committed.
1143 if (((commit_count
- chan
->backend
.subbuf_size
)
1144 & chan
->commit_count_mask
)
1145 - (buf_trunc(consumed
, chan
)
1146 >> chan
->backend
.num_subbuf_order
)
1151 * Check that we are not about to read the same subbuffer in
1152 * which the writer head is.
1154 if (subbuf_trunc(write_offset
, chan
) - subbuf_trunc(consumed
, chan
)
1159 * Failure to get the subbuffer causes a busy-loop retry without going
1160 * to a wait queue. These are caused by short-lived race windows where
1161 * the writer is getting access to a subbuffer we were trying to get
1162 * access to. Also checks that the "consumed" buffer count we are
1163 * looking for matches the one contained in the subbuffer id.
1165 ret
= update_read_sb_index(config
, &buf
->backend
, &chan
->backend
,
1166 consumed_idx
, buf_trunc_val(consumed
, chan
));
1169 subbuffer_id_clear_noref(config
, &buf
->backend
.buf_rsb
.id
);
1171 buf
->get_subbuf_consumed
= consumed
;
1172 buf
->get_subbuf
= 1;
1178 * The memory barriers __wait_event()/wake_up_interruptible() take care
1179 * of "raw_spin_is_locked" memory ordering.
1183 else if (raw_spin_is_locked(&buf
->raw_tick_nohz_spinlock
))
1188 EXPORT_SYMBOL_GPL(lib_ring_buffer_get_subbuf
);
1191 * lib_ring_buffer_put_subbuf - release exclusive subbuffer access
1194 void lib_ring_buffer_put_subbuf(struct lib_ring_buffer
*buf
)
1196 struct lib_ring_buffer_backend
*bufb
= &buf
->backend
;
1197 struct channel
*chan
= bufb
->chan
;
1198 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1199 unsigned long read_sb_bindex
, consumed_idx
, consumed
;
1201 CHAN_WARN_ON(chan
, atomic_long_read(&buf
->active_readers
) != 1);
1203 if (!buf
->get_subbuf
) {
1205 * Reader puts a subbuffer it did not get.
1207 CHAN_WARN_ON(chan
, 1);
1210 consumed
= buf
->get_subbuf_consumed
;
1211 buf
->get_subbuf
= 0;
1214 * Clear the records_unread counter. (overruns counter)
1215 * Can still be non-zero if a file reader simply grabbed the data
1216 * without using iterators.
1217 * Can be below zero if an iterator is used on a snapshot more than
1220 read_sb_bindex
= subbuffer_id_get_index(config
, bufb
->buf_rsb
.id
);
1221 v_add(config
, v_read(config
,
1222 &bufb
->array
[read_sb_bindex
]->records_unread
),
1223 &bufb
->records_read
);
1224 v_set(config
, &bufb
->array
[read_sb_bindex
]->records_unread
, 0);
1225 CHAN_WARN_ON(chan
, config
->mode
== RING_BUFFER_OVERWRITE
1226 && subbuffer_id_is_noref(config
, bufb
->buf_rsb
.id
));
1227 subbuffer_id_set_noref(config
, &bufb
->buf_rsb
.id
);
1230 * Exchange the reader subbuffer with the one we put in its place in the
1231 * writer subbuffer table. Expect the original consumed count. If
1232 * update_read_sb_index fails, this is because the writer updated the
1233 * subbuffer concurrently. We should therefore keep the subbuffer we
1234 * currently have: it has become invalid to try reading this sub-buffer
1235 * consumed count value anyway.
1237 consumed_idx
= subbuf_index(consumed
, chan
);
1238 update_read_sb_index(config
, &buf
->backend
, &chan
->backend
,
1239 consumed_idx
, buf_trunc_val(consumed
, chan
));
1241 * update_read_sb_index return value ignored. Don't exchange sub-buffer
1242 * if the writer concurrently updated it.
1245 EXPORT_SYMBOL_GPL(lib_ring_buffer_put_subbuf
);
1248 * cons_offset is an iterator on all subbuffer offsets between the reader
1249 * position and the writer position. (inclusive)
1252 void lib_ring_buffer_print_subbuffer_errors(struct lib_ring_buffer
*buf
,
1253 struct channel
*chan
,
1254 unsigned long cons_offset
,
1257 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1258 unsigned long cons_idx
, commit_count
, commit_count_sb
;
1260 cons_idx
= subbuf_index(cons_offset
, chan
);
1261 commit_count
= v_read(config
, &buf
->commit_hot
[cons_idx
].cc
);
1262 commit_count_sb
= v_read(config
, &buf
->commit_cold
[cons_idx
].cc_sb
);
1264 if (subbuf_offset(commit_count
, chan
) != 0)
1266 "ring buffer %s, cpu %d: "
1267 "commit count in subbuffer %lu,\n"
1268 "expecting multiples of %lu bytes\n"
1269 " [ %lu bytes committed, %lu bytes reader-visible ]\n",
1270 chan
->backend
.name
, cpu
, cons_idx
,
1271 chan
->backend
.subbuf_size
,
1272 commit_count
, commit_count_sb
);
1274 printk(KERN_DEBUG
"ring buffer: %s, cpu %d: %lu bytes committed\n",
1275 chan
->backend
.name
, cpu
, commit_count
);
1279 void lib_ring_buffer_print_buffer_errors(struct lib_ring_buffer
*buf
,
1280 struct channel
*chan
,
1281 void *priv
, int cpu
)
1283 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1284 unsigned long write_offset
, cons_offset
;
1287 * No need to order commit_count, write_offset and cons_offset reads
1288 * because we execute at teardown when no more writer nor reader
1289 * references are left.
1291 write_offset
= v_read(config
, &buf
->offset
);
1292 cons_offset
= atomic_long_read(&buf
->consumed
);
1293 if (write_offset
!= cons_offset
)
1295 "ring buffer %s, cpu %d: "
1296 "non-consumed data\n"
1297 " [ %lu bytes written, %lu bytes read ]\n",
1298 chan
->backend
.name
, cpu
, write_offset
, cons_offset
);
1300 for (cons_offset
= atomic_long_read(&buf
->consumed
);
1301 (long) (subbuf_trunc((unsigned long) v_read(config
, &buf
->offset
),
1304 cons_offset
= subbuf_align(cons_offset
, chan
))
1305 lib_ring_buffer_print_subbuffer_errors(buf
, chan
, cons_offset
,
1310 void lib_ring_buffer_print_errors(struct channel
*chan
,
1311 struct lib_ring_buffer
*buf
, int cpu
)
1313 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1314 void *priv
= chan
->backend
.priv
;
1316 if (!strcmp(chan
->backend
.name
, "relay-metadata")) {
1317 printk(KERN_DEBUG
"ring buffer %s: %lu records written, "
1318 "%lu records overrun\n",
1320 v_read(config
, &buf
->records_count
),
1321 v_read(config
, &buf
->records_overrun
));
1323 printk(KERN_DEBUG
"ring buffer %s, cpu %d: %lu records written, "
1324 "%lu records overrun\n",
1325 chan
->backend
.name
, cpu
,
1326 v_read(config
, &buf
->records_count
),
1327 v_read(config
, &buf
->records_overrun
));
1329 if (v_read(config
, &buf
->records_lost_full
)
1330 || v_read(config
, &buf
->records_lost_wrap
)
1331 || v_read(config
, &buf
->records_lost_big
))
1333 "ring buffer %s, cpu %d: records were lost. Caused by:\n"
1334 " [ %lu buffer full, %lu nest buffer wrap-around, "
1335 "%lu event too big ]\n",
1336 chan
->backend
.name
, cpu
,
1337 v_read(config
, &buf
->records_lost_full
),
1338 v_read(config
, &buf
->records_lost_wrap
),
1339 v_read(config
, &buf
->records_lost_big
));
1341 lib_ring_buffer_print_buffer_errors(buf
, chan
, priv
, cpu
);
1345 * lib_ring_buffer_switch_old_start: Populate old subbuffer header.
1347 * Only executed by SWITCH_FLUSH, which can be issued while tracing is active
1348 * or at buffer finalization (destroy).
1351 void lib_ring_buffer_switch_old_start(struct lib_ring_buffer
*buf
,
1352 struct channel
*chan
,
1353 struct switch_offsets
*offsets
,
1356 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1357 unsigned long oldidx
= subbuf_index(offsets
->old
, chan
);
1358 unsigned long commit_count
;
1360 config
->cb
.buffer_begin(buf
, tsc
, oldidx
);
1363 * Order all writes to buffer before the commit count update that will
1364 * determine that the subbuffer is full.
1366 if (config
->ipi
== RING_BUFFER_IPI_BARRIER
) {
1368 * Must write slot data before incrementing commit count. This
1369 * compiler barrier is upgraded into a smp_mb() by the IPI sent
1375 v_add(config
, config
->cb
.subbuffer_header_size(),
1376 &buf
->commit_hot
[oldidx
].cc
);
1377 commit_count
= v_read(config
, &buf
->commit_hot
[oldidx
].cc
);
1378 /* Check if the written buffer has to be delivered */
1379 lib_ring_buffer_check_deliver(config
, buf
, chan
, offsets
->old
,
1380 commit_count
, oldidx
, tsc
);
1381 lib_ring_buffer_write_commit_counter(config
, buf
, chan
, oldidx
,
1382 offsets
->old
+ config
->cb
.subbuffer_header_size(),
1387 * lib_ring_buffer_switch_old_end: switch old subbuffer
1389 * Note : offset_old should never be 0 here. It is ok, because we never perform
1390 * buffer switch on an empty subbuffer in SWITCH_ACTIVE mode. The caller
1391 * increments the offset_old value when doing a SWITCH_FLUSH on an empty
1395 void lib_ring_buffer_switch_old_end(struct lib_ring_buffer
*buf
,
1396 struct channel
*chan
,
1397 struct switch_offsets
*offsets
,
1400 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1401 unsigned long oldidx
= subbuf_index(offsets
->old
- 1, chan
);
1402 unsigned long commit_count
, padding_size
, data_size
;
1404 data_size
= subbuf_offset(offsets
->old
- 1, chan
) + 1;
1405 padding_size
= chan
->backend
.subbuf_size
- data_size
;
1406 subbuffer_set_data_size(config
, &buf
->backend
, oldidx
, data_size
);
1409 * Order all writes to buffer before the commit count update that will
1410 * determine that the subbuffer is full.
1412 if (config
->ipi
== RING_BUFFER_IPI_BARRIER
) {
1414 * Must write slot data before incrementing commit count. This
1415 * compiler barrier is upgraded into a smp_mb() by the IPI sent
1421 v_add(config
, padding_size
, &buf
->commit_hot
[oldidx
].cc
);
1422 commit_count
= v_read(config
, &buf
->commit_hot
[oldidx
].cc
);
1423 lib_ring_buffer_check_deliver(config
, buf
, chan
, offsets
->old
- 1,
1424 commit_count
, oldidx
, tsc
);
1425 lib_ring_buffer_write_commit_counter(config
, buf
, chan
, oldidx
,
1426 offsets
->old
+ padding_size
, commit_count
);
1430 * lib_ring_buffer_switch_new_start: Populate new subbuffer.
1432 * This code can be executed unordered : writers may already have written to the
1433 * sub-buffer before this code gets executed, caution. The commit makes sure
1434 * that this code is executed before the deliver of this sub-buffer.
1437 void lib_ring_buffer_switch_new_start(struct lib_ring_buffer
*buf
,
1438 struct channel
*chan
,
1439 struct switch_offsets
*offsets
,
1442 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1443 unsigned long beginidx
= subbuf_index(offsets
->begin
, chan
);
1444 unsigned long commit_count
;
1446 config
->cb
.buffer_begin(buf
, tsc
, beginidx
);
1449 * Order all writes to buffer before the commit count update that will
1450 * determine that the subbuffer is full.
1452 if (config
->ipi
== RING_BUFFER_IPI_BARRIER
) {
1454 * Must write slot data before incrementing commit count. This
1455 * compiler barrier is upgraded into a smp_mb() by the IPI sent
1461 v_add(config
, config
->cb
.subbuffer_header_size(),
1462 &buf
->commit_hot
[beginidx
].cc
);
1463 commit_count
= v_read(config
, &buf
->commit_hot
[beginidx
].cc
);
1464 /* Check if the written buffer has to be delivered */
1465 lib_ring_buffer_check_deliver(config
, buf
, chan
, offsets
->begin
,
1466 commit_count
, beginidx
, tsc
);
1467 lib_ring_buffer_write_commit_counter(config
, buf
, chan
, beginidx
,
1468 offsets
->begin
+ config
->cb
.subbuffer_header_size(),
1473 * lib_ring_buffer_switch_new_end: finish switching current subbuffer
1475 * Calls subbuffer_set_data_size() to set the data size of the current
1476 * sub-buffer. We do not need to perform check_deliver nor commit here,
1477 * since this task will be done by the "commit" of the event for which
1478 * we are currently doing the space reservation.
1481 void lib_ring_buffer_switch_new_end(struct lib_ring_buffer
*buf
,
1482 struct channel
*chan
,
1483 struct switch_offsets
*offsets
,
1486 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1487 unsigned long endidx
, data_size
;
1489 endidx
= subbuf_index(offsets
->end
- 1, chan
);
1490 data_size
= subbuf_offset(offsets
->end
- 1, chan
) + 1;
1491 subbuffer_set_data_size(config
, &buf
->backend
, endidx
, data_size
);
1497 * !0 if execution must be aborted.
1500 int lib_ring_buffer_try_switch_slow(enum switch_mode mode
,
1501 struct lib_ring_buffer
*buf
,
1502 struct channel
*chan
,
1503 struct switch_offsets
*offsets
,
1506 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1507 unsigned long off
, reserve_commit_diff
;
1509 offsets
->begin
= v_read(config
, &buf
->offset
);
1510 offsets
->old
= offsets
->begin
;
1511 offsets
->switch_old_start
= 0;
1512 off
= subbuf_offset(offsets
->begin
, chan
);
1514 *tsc
= config
->cb
.ring_buffer_clock_read(chan
);
1517 * Ensure we flush the header of an empty subbuffer when doing the
1518 * finalize (SWITCH_FLUSH). This ensures that we end up knowing the
1519 * total data gathering duration even if there were no records saved
1520 * after the last buffer switch.
1521 * In SWITCH_ACTIVE mode, switch the buffer when it contains events.
1522 * SWITCH_ACTIVE only flushes the current subbuffer, dealing with end of
1523 * subbuffer header as appropriate.
1524 * The next record that reserves space will be responsible for
1525 * populating the following subbuffer header. We choose not to populate
1526 * the next subbuffer header here because we want to be able to use
1527 * SWITCH_ACTIVE for periodical buffer flush and CPU tick_nohz stop
1528 * buffer flush, which must guarantee that all the buffer content
1529 * (records and header timestamps) are visible to the reader. This is
1530 * required for quiescence guarantees for the fusion merge.
1532 if (mode
!= SWITCH_FLUSH
&& !off
)
1533 return -1; /* we do not have to switch : buffer is empty */
1535 if (unlikely(off
== 0)) {
1536 unsigned long sb_index
, commit_count
;
1539 * We are performing a SWITCH_FLUSH. There may be concurrent
1540 * writes into the buffer if e.g. invoked while performing a
1541 * snapshot on an active trace.
1543 * If the client does not save any header information (sub-buffer
1544 * header size == 0), don't switch empty subbuffer on finalize,
1545 * because it is invalid to deliver a completely empty
1548 if (!config
->cb
.subbuffer_header_size())
1551 /* Test new buffer integrity */
1552 sb_index
= subbuf_index(offsets
->begin
, chan
);
1553 commit_count
= v_read(config
,
1554 &buf
->commit_cold
[sb_index
].cc_sb
);
1555 reserve_commit_diff
=
1556 (buf_trunc(offsets
->begin
, chan
)
1557 >> chan
->backend
.num_subbuf_order
)
1558 - (commit_count
& chan
->commit_count_mask
);
1559 if (likely(reserve_commit_diff
== 0)) {
1560 /* Next subbuffer not being written to. */
1561 if (unlikely(config
->mode
!= RING_BUFFER_OVERWRITE
&&
1562 subbuf_trunc(offsets
->begin
, chan
)
1563 - subbuf_trunc((unsigned long)
1564 atomic_long_read(&buf
->consumed
), chan
)
1565 >= chan
->backend
.buf_size
)) {
1567 * We do not overwrite non consumed buffers
1568 * and we are full : don't switch.
1573 * Next subbuffer not being written to, and we
1574 * are either in overwrite mode or the buffer is
1575 * not full. It's safe to write in this new
1581 * Next subbuffer reserve offset does not match the
1582 * commit offset. Don't perform switch in
1583 * producer-consumer and overwrite mode. Caused by
1584 * either a writer OOPS or too many nested writes over a
1585 * reserve/commit pair.
1591 * Need to write the subbuffer start header on finalize.
1593 offsets
->switch_old_start
= 1;
1595 offsets
->begin
= subbuf_align(offsets
->begin
, chan
);
1596 /* Note: old points to the next subbuf at offset 0 */
1597 offsets
->end
= offsets
->begin
;
1602 * Force a sub-buffer switch. This operation is completely reentrant : can be
1603 * called while tracing is active with absolutely no lock held.
1605 * Note, however, that as a v_cmpxchg is used for some atomic
1606 * operations, this function must be called from the CPU which owns the buffer
1607 * for a ACTIVE flush.
1609 void lib_ring_buffer_switch_slow(struct lib_ring_buffer
*buf
, enum switch_mode mode
)
1611 struct channel
*chan
= buf
->backend
.chan
;
1612 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1613 struct switch_offsets offsets
;
1614 unsigned long oldidx
;
1620 * Perform retryable operations.
1623 if (lib_ring_buffer_try_switch_slow(mode
, buf
, chan
, &offsets
,
1625 return; /* Switch not needed */
1626 } while (v_cmpxchg(config
, &buf
->offset
, offsets
.old
, offsets
.end
)
1630 * Atomically update last_tsc. This update races against concurrent
1631 * atomic updates, but the race will always cause supplementary full TSC
1632 * records, never the opposite (missing a full TSC record when it would
1635 save_last_tsc(config
, buf
, tsc
);
1638 * Push the reader if necessary
1640 lib_ring_buffer_reserve_push_reader(buf
, chan
, offsets
.old
);
1642 oldidx
= subbuf_index(offsets
.old
, chan
);
1643 lib_ring_buffer_clear_noref(config
, &buf
->backend
, oldidx
);
1646 * May need to populate header start on SWITCH_FLUSH.
1648 if (offsets
.switch_old_start
) {
1649 lib_ring_buffer_switch_old_start(buf
, chan
, &offsets
, tsc
);
1650 offsets
.old
+= config
->cb
.subbuffer_header_size();
1654 * Switch old subbuffer.
1656 lib_ring_buffer_switch_old_end(buf
, chan
, &offsets
, tsc
);
1658 EXPORT_SYMBOL_GPL(lib_ring_buffer_switch_slow
);
1660 struct switch_param
{
1661 struct lib_ring_buffer
*buf
;
1662 enum switch_mode mode
;
1665 static void remote_switch(void *info
)
1667 struct switch_param
*param
= info
;
1668 struct lib_ring_buffer
*buf
= param
->buf
;
1670 lib_ring_buffer_switch_slow(buf
, param
->mode
);
1673 static void _lib_ring_buffer_switch_remote(struct lib_ring_buffer
*buf
,
1674 enum switch_mode mode
)
1676 struct channel
*chan
= buf
->backend
.chan
;
1677 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1679 struct switch_param param
;
1682 * With global synchronization we don't need to use the IPI scheme.
1684 if (config
->sync
== RING_BUFFER_SYNC_GLOBAL
) {
1685 lib_ring_buffer_switch_slow(buf
, mode
);
1690 * Taking lock on CPU hotplug to ensure two things: first, that the
1691 * target cpu is not taken concurrently offline while we are within
1692 * smp_call_function_single() (I don't trust that get_cpu() on the
1693 * _local_ CPU actually inhibit CPU hotplug for the _remote_ CPU (to be
1694 * confirmed)). Secondly, if it happens that the CPU is not online, our
1695 * own call to lib_ring_buffer_switch_slow() needs to be protected from
1696 * CPU hotplug handlers, which can also perform a remote subbuffer
1702 ret
= smp_call_function_single(buf
->backend
.cpu
,
1703 remote_switch
, ¶m
, 1);
1705 /* Remote CPU is offline, do it ourself. */
1706 lib_ring_buffer_switch_slow(buf
, mode
);
1711 void lib_ring_buffer_switch_remote(struct lib_ring_buffer
*buf
)
1713 _lib_ring_buffer_switch_remote(buf
, SWITCH_ACTIVE
);
1715 EXPORT_SYMBOL_GPL(lib_ring_buffer_switch_remote
);
1717 /* Switch sub-buffer even if current sub-buffer is empty. */
1718 void lib_ring_buffer_switch_remote_empty(struct lib_ring_buffer
*buf
)
1720 _lib_ring_buffer_switch_remote(buf
, SWITCH_FLUSH
);
1722 EXPORT_SYMBOL_GPL(lib_ring_buffer_switch_remote_empty
);
1727 * -ENOSPC if event size is too large for packet.
1728 * -ENOBUFS if there is currently not enough space in buffer for the event.
1729 * -EIO if data cannot be written into the buffer for any other reason.
1732 int lib_ring_buffer_try_reserve_slow(struct lib_ring_buffer
*buf
,
1733 struct channel
*chan
,
1734 struct switch_offsets
*offsets
,
1735 struct lib_ring_buffer_ctx
*ctx
)
1737 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1738 unsigned long reserve_commit_diff
, offset_cmp
;
1741 offsets
->begin
= offset_cmp
= v_read(config
, &buf
->offset
);
1742 offsets
->old
= offsets
->begin
;
1743 offsets
->switch_new_start
= 0;
1744 offsets
->switch_new_end
= 0;
1745 offsets
->switch_old_end
= 0;
1746 offsets
->pre_header_padding
= 0;
1748 ctx
->tsc
= config
->cb
.ring_buffer_clock_read(chan
);
1749 if ((int64_t) ctx
->tsc
== -EIO
)
1752 if (last_tsc_overflow(config
, buf
, ctx
->tsc
))
1753 ctx
->rflags
|= RING_BUFFER_RFLAG_FULL_TSC
;
1755 if (unlikely(subbuf_offset(offsets
->begin
, ctx
->chan
) == 0)) {
1756 offsets
->switch_new_start
= 1; /* For offsets->begin */
1758 offsets
->size
= config
->cb
.record_header_size(config
, chan
,
1760 &offsets
->pre_header_padding
,
1763 lib_ring_buffer_align(offsets
->begin
+ offsets
->size
,
1766 if (unlikely(subbuf_offset(offsets
->begin
, chan
) +
1767 offsets
->size
> chan
->backend
.subbuf_size
)) {
1768 offsets
->switch_old_end
= 1; /* For offsets->old */
1769 offsets
->switch_new_start
= 1; /* For offsets->begin */
1772 if (unlikely(offsets
->switch_new_start
)) {
1773 unsigned long sb_index
, commit_count
;
1776 * We are typically not filling the previous buffer completely.
1778 if (likely(offsets
->switch_old_end
))
1779 offsets
->begin
= subbuf_align(offsets
->begin
, chan
);
1780 offsets
->begin
= offsets
->begin
1781 + config
->cb
.subbuffer_header_size();
1782 /* Test new buffer integrity */
1783 sb_index
= subbuf_index(offsets
->begin
, chan
);
1785 * Read buf->offset before buf->commit_cold[sb_index].cc_sb.
1786 * lib_ring_buffer_check_deliver() has the matching
1787 * memory barriers required around commit_cold cc_sb
1788 * updates to ensure reserve and commit counter updates
1789 * are not seen reordered when updated by another CPU.
1792 commit_count
= v_read(config
,
1793 &buf
->commit_cold
[sb_index
].cc_sb
);
1794 /* Read buf->commit_cold[sb_index].cc_sb before buf->offset. */
1796 if (unlikely(offset_cmp
!= v_read(config
, &buf
->offset
))) {
1798 * The reserve counter have been concurrently updated
1799 * while we read the commit counter. This means the
1800 * commit counter we read might not match buf->offset
1801 * due to concurrent update. We therefore need to retry.
1805 reserve_commit_diff
=
1806 (buf_trunc(offsets
->begin
, chan
)
1807 >> chan
->backend
.num_subbuf_order
)
1808 - (commit_count
& chan
->commit_count_mask
);
1809 if (likely(reserve_commit_diff
== 0)) {
1810 /* Next subbuffer not being written to. */
1811 if (unlikely(config
->mode
!= RING_BUFFER_OVERWRITE
&&
1812 subbuf_trunc(offsets
->begin
, chan
)
1813 - subbuf_trunc((unsigned long)
1814 atomic_long_read(&buf
->consumed
), chan
)
1815 >= chan
->backend
.buf_size
)) {
1817 * We do not overwrite non consumed buffers
1818 * and we are full : record is lost.
1820 v_inc(config
, &buf
->records_lost_full
);
1824 * Next subbuffer not being written to, and we
1825 * are either in overwrite mode or the buffer is
1826 * not full. It's safe to write in this new
1832 * Next subbuffer reserve offset does not match the
1833 * commit offset, and this did not involve update to the
1834 * reserve counter. Drop record in producer-consumer and
1835 * overwrite mode. Caused by either a writer OOPS or
1836 * too many nested writes over a reserve/commit pair.
1838 v_inc(config
, &buf
->records_lost_wrap
);
1842 config
->cb
.record_header_size(config
, chan
,
1844 &offsets
->pre_header_padding
,
1847 lib_ring_buffer_align(offsets
->begin
+ offsets
->size
,
1850 if (unlikely(subbuf_offset(offsets
->begin
, chan
)
1851 + offsets
->size
> chan
->backend
.subbuf_size
)) {
1853 * Record too big for subbuffers, report error, don't
1854 * complete the sub-buffer switch.
1856 v_inc(config
, &buf
->records_lost_big
);
1860 * We just made a successful buffer switch and the
1861 * record fits in the new subbuffer. Let's write.
1866 * Record fits in the current buffer and we are not on a switch
1867 * boundary. It's safe to write.
1870 offsets
->end
= offsets
->begin
+ offsets
->size
;
1872 if (unlikely(subbuf_offset(offsets
->end
, chan
) == 0)) {
1874 * The offset_end will fall at the very beginning of the next
1877 offsets
->switch_new_end
= 1; /* For offsets->begin */
1882 static struct lib_ring_buffer
*get_current_buf(struct channel
*chan
, int cpu
)
1884 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1886 if (config
->alloc
== RING_BUFFER_ALLOC_PER_CPU
)
1887 return per_cpu_ptr(chan
->backend
.buf
, cpu
);
1889 return chan
->backend
.buf
;
1892 void lib_ring_buffer_lost_event_too_big(struct channel
*chan
)
1894 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1895 struct lib_ring_buffer
*buf
= get_current_buf(chan
, smp_processor_id());
1897 v_inc(config
, &buf
->records_lost_big
);
1899 EXPORT_SYMBOL_GPL(lib_ring_buffer_lost_event_too_big
);
1902 * lib_ring_buffer_reserve_slow - Atomic slot reservation in a buffer.
1903 * @ctx: ring buffer context.
1905 * Return : -NOBUFS if not enough space, -ENOSPC if event size too large,
1906 * -EIO for other errors, else returns 0.
1907 * It will take care of sub-buffer switching.
1909 int lib_ring_buffer_reserve_slow(struct lib_ring_buffer_ctx
*ctx
)
1911 struct channel
*chan
= ctx
->chan
;
1912 const struct lib_ring_buffer_config
*config
= &chan
->backend
.config
;
1913 struct lib_ring_buffer
*buf
;
1914 struct switch_offsets offsets
;
1917 ctx
->buf
= buf
= get_current_buf(chan
, ctx
->cpu
);
1921 ret
= lib_ring_buffer_try_reserve_slow(buf
, chan
, &offsets
,
1925 } while (unlikely(v_cmpxchg(config
, &buf
->offset
, offsets
.old
,
1930 * Atomically update last_tsc. This update races against concurrent
1931 * atomic updates, but the race will always cause supplementary full TSC
1932 * records, never the opposite (missing a full TSC record when it would
1935 save_last_tsc(config
, buf
, ctx
->tsc
);
1938 * Push the reader if necessary
1940 lib_ring_buffer_reserve_push_reader(buf
, chan
, offsets
.end
- 1);
1943 * Clear noref flag for this subbuffer.
1945 lib_ring_buffer_clear_noref(config
, &buf
->backend
,
1946 subbuf_index(offsets
.end
- 1, chan
));
1949 * Switch old subbuffer if needed.
1951 if (unlikely(offsets
.switch_old_end
)) {
1952 lib_ring_buffer_clear_noref(config
, &buf
->backend
,
1953 subbuf_index(offsets
.old
- 1, chan
));
1954 lib_ring_buffer_switch_old_end(buf
, chan
, &offsets
, ctx
->tsc
);
1958 * Populate new subbuffer.
1960 if (unlikely(offsets
.switch_new_start
))
1961 lib_ring_buffer_switch_new_start(buf
, chan
, &offsets
, ctx
->tsc
);
1963 if (unlikely(offsets
.switch_new_end
))
1964 lib_ring_buffer_switch_new_end(buf
, chan
, &offsets
, ctx
->tsc
);
1966 ctx
->slot_size
= offsets
.size
;
1967 ctx
->pre_offset
= offsets
.begin
;
1968 ctx
->buf_offset
= offsets
.begin
+ offsets
.pre_header_padding
;
1971 EXPORT_SYMBOL_GPL(lib_ring_buffer_reserve_slow
);
1974 void lib_ring_buffer_vmcore_check_deliver(const struct lib_ring_buffer_config
*config
,
1975 struct lib_ring_buffer
*buf
,
1976 unsigned long commit_count
,
1979 if (config
->oops
== RING_BUFFER_OOPS_CONSISTENCY
)
1980 v_set(config
, &buf
->commit_hot
[idx
].seq
, commit_count
);
1983 void lib_ring_buffer_check_deliver_slow(const struct lib_ring_buffer_config
*config
,
1984 struct lib_ring_buffer
*buf
,
1985 struct channel
*chan
,
1986 unsigned long offset
,
1987 unsigned long commit_count
,
1991 unsigned long old_commit_count
= commit_count
1992 - chan
->backend
.subbuf_size
;
1995 * If we succeeded at updating cc_sb below, we are the subbuffer
1996 * writer delivering the subbuffer. Deals with concurrent
1997 * updates of the "cc" value without adding a add_return atomic
1998 * operation to the fast path.
2000 * We are doing the delivery in two steps:
2001 * - First, we cmpxchg() cc_sb to the new value
2002 * old_commit_count + 1. This ensures that we are the only
2003 * subbuffer user successfully filling the subbuffer, but we
2004 * do _not_ set the cc_sb value to "commit_count" yet.
2005 * Therefore, other writers that would wrap around the ring
2006 * buffer and try to start writing to our subbuffer would
2007 * have to drop records, because it would appear as
2009 * We therefore have exclusive access to the subbuffer control
2010 * structures. This mutual exclusion with other writers is
2011 * crucially important to perform record overruns count in
2012 * flight recorder mode locklessly.
2013 * - When we are ready to release the subbuffer (either for
2014 * reading or for overrun by other writers), we simply set the
2015 * cc_sb value to "commit_count" and perform delivery.
2017 * The subbuffer size is least 2 bytes (minimum size: 1 page).
2018 * This guarantees that old_commit_count + 1 != commit_count.
2022 * Order prior updates to reserve count prior to the
2023 * commit_cold cc_sb update.
2026 if (likely(v_cmpxchg(config
, &buf
->commit_cold
[idx
].cc_sb
,
2027 old_commit_count
, old_commit_count
+ 1)
2028 == old_commit_count
)) {
2030 * Start of exclusive subbuffer access. We are
2031 * guaranteed to be the last writer in this subbuffer
2032 * and any other writer trying to access this subbuffer
2033 * in this state is required to drop records.
2036 subbuffer_get_records_count(config
,
2037 &buf
->backend
, idx
),
2038 &buf
->records_count
);
2040 subbuffer_count_records_overrun(config
,
2043 &buf
->records_overrun
);
2044 config
->cb
.buffer_end(buf
, tsc
, idx
,
2045 lib_ring_buffer_get_data_size(config
,
2050 * Increment the packet counter while we have exclusive
2053 subbuffer_inc_packet_count(config
, &buf
->backend
, idx
);
2056 * Set noref flag and offset for this subbuffer id.
2057 * Contains a memory barrier that ensures counter stores
2058 * are ordered before set noref and offset.
2060 lib_ring_buffer_set_noref_offset(config
, &buf
->backend
, idx
,
2061 buf_trunc_val(offset
, chan
));
2064 * Order set_noref and record counter updates before the
2065 * end of subbuffer exclusive access. Orders with
2066 * respect to writers coming into the subbuffer after
2067 * wrap around, and also order wrt concurrent readers.
2070 /* End of exclusive subbuffer access */
2071 v_set(config
, &buf
->commit_cold
[idx
].cc_sb
,
2074 * Order later updates to reserve count after
2075 * the commit_cold cc_sb update.
2078 lib_ring_buffer_vmcore_check_deliver(config
, buf
,
2082 * RING_BUFFER_WAKEUP_BY_WRITER wakeup is not lock-free.
2084 if (config
->wakeup
== RING_BUFFER_WAKEUP_BY_WRITER
2085 && atomic_long_read(&buf
->active_readers
)
2086 && lib_ring_buffer_poll_deliver(config
, buf
, chan
)) {
2087 wake_up_interruptible(&buf
->read_wait
);
2088 wake_up_interruptible(&chan
->read_wait
);
2093 EXPORT_SYMBOL_GPL(lib_ring_buffer_check_deliver_slow
);
2095 int __init
init_lib_ring_buffer_frontend(void)
2099 for_each_possible_cpu(cpu
)
2100 spin_lock_init(&per_cpu(ring_buffer_nohz_lock
, cpu
));
2104 module_init(init_lib_ring_buffer_frontend
);
2106 void __exit
exit_lib_ring_buffer_frontend(void)
2110 module_exit(exit_lib_ring_buffer_frontend
);