Commit d4788207 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt

ring-buffer: add locks around rb_per_cpu_empty

The checking of whether the buffer is empty or not needs to be serialized
among the readers. Add the reader spin lock around it.
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 5f78abee
...@@ -2756,12 +2756,17 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset); ...@@ -2756,12 +2756,17 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset);
int ring_buffer_empty(struct ring_buffer *buffer) int ring_buffer_empty(struct ring_buffer *buffer)
{ {
struct ring_buffer_per_cpu *cpu_buffer; struct ring_buffer_per_cpu *cpu_buffer;
unsigned long flags;
int cpu; int cpu;
int ret;
/* yes this is racy, but if you don't like the race, lock the buffer */ /* yes this is racy, but if you don't like the race, lock the buffer */
for_each_buffer_cpu(buffer, cpu) { for_each_buffer_cpu(buffer, cpu) {
cpu_buffer = buffer->buffers[cpu]; cpu_buffer = buffer->buffers[cpu];
if (!rb_per_cpu_empty(cpu_buffer)) spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
ret = rb_per_cpu_empty(cpu_buffer);
spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
if (!ret)
return 0; return 0;
} }
...@@ -2777,14 +2782,16 @@ EXPORT_SYMBOL_GPL(ring_buffer_empty); ...@@ -2777,14 +2782,16 @@ EXPORT_SYMBOL_GPL(ring_buffer_empty);
int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu) int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu)
{ {
struct ring_buffer_per_cpu *cpu_buffer; struct ring_buffer_per_cpu *cpu_buffer;
unsigned long flags;
int ret; int ret;
if (!cpumask_test_cpu(cpu, buffer->cpumask)) if (!cpumask_test_cpu(cpu, buffer->cpumask))
return 1; return 1;
cpu_buffer = buffer->buffers[cpu]; cpu_buffer = buffer->buffers[cpu];
spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
ret = rb_per_cpu_empty(cpu_buffer); ret = rb_per_cpu_empty(cpu_buffer);
spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment