ring_buffer.c (10464b4aa605ef93c937452f442e74cc0a4a6ceb) ring_buffer.c (b23d7a5f4a07af02343cdd28fe1f7488bac3afda)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Generic ring buffer
4 *
5 * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com>
6 */
7#include <linux/trace_events.h>
8#include <linux/ring_buffer.h>

--- 256 unchanged lines hidden (view full) ---

265{
266 return rb_event_data(event);
267}
268EXPORT_SYMBOL_GPL(ring_buffer_event_data);
269
270#define for_each_buffer_cpu(buffer, cpu) \
271 for_each_cpu(cpu, buffer->cpumask)
272
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Generic ring buffer
4 *
5 * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com>
6 */
7#include <linux/trace_events.h>
8#include <linux/ring_buffer.h>

--- 256 unchanged lines hidden (view full) ---

265{
266 return rb_event_data(event);
267}
268EXPORT_SYMBOL_GPL(ring_buffer_event_data);
269
270#define for_each_buffer_cpu(buffer, cpu) \
271 for_each_cpu(cpu, buffer->cpumask)
272
273#define for_each_online_buffer_cpu(buffer, cpu) \
274 for_each_cpu_and(cpu, buffer->cpumask, cpu_online_mask)
275
273#define TS_SHIFT 27
274#define TS_MASK ((1ULL << TS_SHIFT) - 1)
275#define TS_DELTA_TEST (~TS_MASK)
276
277/**
278 * ring_buffer_event_time_stamp - return the event's extended timestamp
279 * @event: the event to get the timestamp of
280 *

--- 4504 unchanged lines hidden (view full) ---

4785 rb_time_set(&cpu_buffer->before_stamp, 0);
4786
4787 cpu_buffer->lost_events = 0;
4788 cpu_buffer->last_overrun = 0;
4789
4790 rb_head_page_activate(cpu_buffer);
4791}
4792
276#define TS_SHIFT 27
277#define TS_MASK ((1ULL << TS_SHIFT) - 1)
278#define TS_DELTA_TEST (~TS_MASK)
279
280/**
281 * ring_buffer_event_time_stamp - return the event's extended timestamp
282 * @event: the event to get the timestamp of
283 *

--- 4504 unchanged lines hidden (view full) ---

4788 rb_time_set(&cpu_buffer->before_stamp, 0);
4789
4790 cpu_buffer->lost_events = 0;
4791 cpu_buffer->last_overrun = 0;
4792
4793 rb_head_page_activate(cpu_buffer);
4794}
4795
4796/* Must have disabled the cpu buffer then done a synchronize_rcu */
4797static void reset_disabled_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
4798{
4799 unsigned long flags;
4800
4801 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
4802
4803 if (RB_WARN_ON(cpu_buffer, local_read(&cpu_buffer->committing)))
4804 goto out;
4805
4806 arch_spin_lock(&cpu_buffer->lock);
4807
4808 rb_reset_cpu(cpu_buffer);
4809
4810 arch_spin_unlock(&cpu_buffer->lock);
4811
4812 out:
4813 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
4814}
4815
4793/**
4794 * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
4795 * @buffer: The ring buffer to reset a per cpu buffer of
4796 * @cpu: The CPU buffer to be reset
4797 */
4798void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
4799{
4800 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
4816/**
4817 * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
4818 * @buffer: The ring buffer to reset a per cpu buffer of
4819 * @cpu: The CPU buffer to be reset
4820 */
4821void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)
4822{
4823 struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
4801 unsigned long flags;
4802
4803 if (!cpumask_test_cpu(cpu, buffer->cpumask))
4804 return;
4805
4806 atomic_inc(&cpu_buffer->resize_disabled);
4807 atomic_inc(&cpu_buffer->record_disabled);
4808
4809 /* Make sure all commits have finished */
4810 synchronize_rcu();
4811
4824
4825 if (!cpumask_test_cpu(cpu, buffer->cpumask))
4826 return;
4827
4828 atomic_inc(&cpu_buffer->resize_disabled);
4829 atomic_inc(&cpu_buffer->record_disabled);
4830
4831 /* Make sure all commits have finished */
4832 synchronize_rcu();
4833
4812 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
4834 reset_disabled_cpu_buffer(cpu_buffer);
4813
4835
4814 if (RB_WARN_ON(cpu_buffer, local_read(&cpu_buffer->committing)))
4815 goto out;
4836 atomic_dec(&cpu_buffer->record_disabled);
4837 atomic_dec(&cpu_buffer->resize_disabled);
4838}
4839EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
4816
4840
4817 arch_spin_lock(&cpu_buffer->lock);
4841/**
4842 * ring_buffer_reset_cpu - reset a ring buffer per CPU buffer
4843 * @buffer: The ring buffer to reset a per cpu buffer of
4844 * @cpu: The CPU buffer to be reset
4845 */
4846void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)
4847{
4848 struct ring_buffer_per_cpu *cpu_buffer;
4849 int cpu;
4818
4850
4819 rb_reset_cpu(cpu_buffer);
4851 for_each_online_buffer_cpu(buffer, cpu) {
4852 cpu_buffer = buffer->buffers[cpu];
4820
4853
4821 arch_spin_unlock(&cpu_buffer->lock);
4854 atomic_inc(&cpu_buffer->resize_disabled);
4855 atomic_inc(&cpu_buffer->record_disabled);
4856 }
4822
4857
4823 out:
4824 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
4858 /* Make sure all commits have finished */
4859 synchronize_rcu();
4825
4860
4826 atomic_dec(&cpu_buffer->record_disabled);
4827 atomic_dec(&cpu_buffer->resize_disabled);
4861 for_each_online_buffer_cpu(buffer, cpu) {
4862 cpu_buffer = buffer->buffers[cpu];
4863
4864 reset_disabled_cpu_buffer(cpu_buffer);
4865
4866 atomic_dec(&cpu_buffer->record_disabled);
4867 atomic_dec(&cpu_buffer->resize_disabled);
4868 }
4828}
4869}
4829EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
4830
4831/**
4832 * ring_buffer_reset - reset a ring buffer
4833 * @buffer: The ring buffer to reset all cpu buffers
4834 */
4835void ring_buffer_reset(struct trace_buffer *buffer)
4836{
4870
4871/**
4872 * ring_buffer_reset - reset a ring buffer
4873 * @buffer: The ring buffer to reset all cpu buffers
4874 */
4875void ring_buffer_reset(struct trace_buffer *buffer)
4876{
4877 struct ring_buffer_per_cpu *cpu_buffer;
4837 int cpu;
4838
4878 int cpu;
4879
4839 for_each_buffer_cpu(buffer, cpu)
4840 ring_buffer_reset_cpu(buffer, cpu);
4880 for_each_buffer_cpu(buffer, cpu) {
4881 cpu_buffer = buffer->buffers[cpu];
4882
4883 atomic_inc(&cpu_buffer->resize_disabled);
4884 atomic_inc(&cpu_buffer->record_disabled);
4885 }
4886
4887 /* Make sure all commits have finished */
4888 synchronize_rcu();
4889
4890 for_each_buffer_cpu(buffer, cpu) {
4891 cpu_buffer = buffer->buffers[cpu];
4892
4893 reset_disabled_cpu_buffer(cpu_buffer);
4894
4895 atomic_dec(&cpu_buffer->record_disabled);
4896 atomic_dec(&cpu_buffer->resize_disabled);
4897 }
4841}
4842EXPORT_SYMBOL_GPL(ring_buffer_reset);
4843
4844/**
4845 * rind_buffer_empty - is the ring buffer empty?
4846 * @buffer: The ring buffer to test
4847 */
4848bool ring_buffer_empty(struct trace_buffer *buffer)

--- 777 unchanged lines hidden ---
4898}
4899EXPORT_SYMBOL_GPL(ring_buffer_reset);
4900
4901/**
4902 * rind_buffer_empty - is the ring buffer empty?
4903 * @buffer: The ring buffer to test
4904 */
4905bool ring_buffer_empty(struct trace_buffer *buffer)

--- 777 unchanged lines hidden ---