-#ifdef CONFIG_HOTPLUG_CPU
-/**
- * lib_ring_buffer_cpu_hp_callback - CPU hotplug callback
- * @nb: notifier block
- * @action: hotplug action to take
- * @hcpu: CPU number
- *
- * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
- */
-static
-int __cpuinit lib_ring_buffer_cpu_hp_callback(struct notifier_block *nb,
- unsigned long action,
- void *hcpu)
-{
- unsigned int cpu = (unsigned long)hcpu;
- struct channel *chan = caa_container_of(nb, struct channel,
- cpu_hp_notifier);
- struct lib_ring_buffer *buf = per_cpu_ptr(chan->backend.buf, cpu);
- const struct lib_ring_buffer_config *config = chan->backend.config;
-
- if (!chan->cpu_hp_enable)
- return NOTIFY_DONE;
-
- CHAN_WARN_ON(chan, config->alloc == RING_BUFFER_ALLOC_GLOBAL);
-
- switch (action) {
- case CPU_DOWN_FAILED:
- case CPU_DOWN_FAILED_FROZEN:
- case CPU_ONLINE:
- case CPU_ONLINE_FROZEN:
- wake_up_interruptible(&chan->hp_wait);
- lib_ring_buffer_start_switch_timer(buf);
- lib_ring_buffer_start_read_timer(buf);
- return NOTIFY_OK;
-
- case CPU_DOWN_PREPARE:
- case CPU_DOWN_PREPARE_FROZEN:
- lib_ring_buffer_stop_switch_timer(buf);
- lib_ring_buffer_stop_read_timer(buf);
- return NOTIFY_OK;
-
- case CPU_DEAD:
- case CPU_DEAD_FROZEN:
- /*
- * Performing a buffer switch on a remote CPU. Performed by
- * the CPU responsible for doing the hotunplug after the target
- * CPU stopped running completely. Ensures that all data
- * from that remote CPU is flushed.
- */
- lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
- return NOTIFY_OK;
-
- default:
- return NOTIFY_DONE;
- }
-}
-#endif
-
-#if defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER)
-/*
- * For per-cpu buffers, call the reader wakeups before switching the buffer, so
- * that wake-up-tracing generated events are flushed before going idle (in
- * tick_nohz). We test if the spinlock is locked to deal with the race where
- * readers try to sample the ring buffer before we perform the switch. We let
- * the readers retry in that case. If there is data in the buffer, the wake up
- * is going to forbid the CPU running the reader thread from going idle.
- */
-static int notrace ring_buffer_tick_nohz_callback(struct notifier_block *nb,
- unsigned long val,
- void *data)
-{
- struct channel *chan = caa_container_of(nb, struct channel,
- tick_nohz_notifier);
- const struct lib_ring_buffer_config *config = chan->backend.config;
- struct lib_ring_buffer *buf;
- int cpu = smp_processor_id();
-
- if (config->alloc != RING_BUFFER_ALLOC_PER_CPU) {
- /*
- * We don't support keeping the system idle with global buffers
- * and streaming active. In order to do so, we would need to
- * sample a non-nohz-cpumask racelessly with the nohz updates
- * without adding synchronization overhead to nohz. Leave this
- * use-case out for now.
- */
- return 0;
- }
-
- buf = channel_get_ring_buffer(config, chan, cpu);
- switch (val) {
- case TICK_NOHZ_FLUSH:
- raw_spin_lock(&buf->raw_tick_nohz_spinlock);
- if (config->wakeup == RING_BUFFER_WAKEUP_BY_TIMER
- && chan->read_timer_interval
- && atomic_long_read(&buf->active_readers)
- && (lib_ring_buffer_poll_deliver(config, buf, chan)
- || lib_ring_buffer_pending_data(config, buf, chan))) {
- wake_up_interruptible(&buf->read_wait);
- wake_up_interruptible(&chan->read_wait);
- }
- if (chan->switch_timer_interval)
- lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE);
- raw_spin_unlock(&buf->raw_tick_nohz_spinlock);
- break;
- case TICK_NOHZ_STOP:
- spin_lock(&__get_cpu_var(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));
- break;
- case TICK_NOHZ_RESTART:
- spin_lock(&__get_cpu_var(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));
- break;
- }
-
- return 0;
-}
-
-void notrace lib_ring_buffer_tick_nohz_flush(void)
-{
- atomic_notifier_call_chain(&tick_nohz_notifier, TICK_NOHZ_FLUSH,
- NULL);
-}
-
-void notrace lib_ring_buffer_tick_nohz_stop(void)
-{
- atomic_notifier_call_chain(&tick_nohz_notifier, TICK_NOHZ_STOP,
- NULL);
-}
-
-void notrace lib_ring_buffer_tick_nohz_restart(void)
-{
- atomic_notifier_call_chain(&tick_nohz_notifier, TICK_NOHZ_RESTART,
- NULL);
-}
-#endif /* defined(CONFIG_NO_HZ) && defined(CONFIG_LIB_RING_BUFFER) */
-
-/*
- * Holds CPU hotplug.
- */
-static void channel_unregister_notifiers(struct channel *chan)