Skip to content

Commit 884bfe8

Browse files
Slava Pestovrostedt
authored andcommitted
ring-buffer: Add a 'dropped events' counter
The existing 'overrun' counter is incremented when the ring buffer wraps around, with overflow on (the default). We wanted a way to count requests lost from the buffer filling up with overflow off, too. I decided to add a new counter instead of retro-fitting the existing one because it seems like a different statistic to count conceptually, and also because of how the code was structured. Link: http://lkml.kernel.org/r/1310765038-26399-1-git-send-email-slavapestov@google.com Signed-off-by: Slava Pestov <slavapestov@google.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent f43c738 commit 884bfe8

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎include/linux/ring_buffer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
166166
unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
167167
unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
168168
unsigned long ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu);
169+
unsigned long ring_buffer_dropped_events_cpu(struct ring_buffer *buffer, int cpu);
169170

170171
u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu);
171172
void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,

‎kernel/trace/ring_buffer.c‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ struct ring_buffer_per_cpu {
460460
unsigned long lost_events;
461461
unsigned long last_overrun;
462462
local_t entries_bytes;
463-
local_t commit_overrun;
464-
local_t overrun;
465463
local_t entries;
464+
local_t overrun;
465+
local_t commit_overrun;
466+
local_t dropped_events;
466467
local_t committing;
467468
local_t commits;
468469
unsigned long read;
@@ -2155,8 +2156,10 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
21552156
* If we are not in overwrite mode,
21562157
* this is easy, just stop here.
21572158
*/
2158-
if (!(buffer->flags & RB_FL_OVERWRITE))
2159+
if (!(buffer->flags & RB_FL_OVERWRITE)) {
2160+
local_inc(&cpu_buffer->dropped_events);
21592161
goto out_reset;
2162+
}
21602163

21612164
ret = rb_handle_head_page(cpu_buffer,
21622165
tail_page,
@@ -2995,7 +2998,8 @@ unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu)
29952998
EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu);
29962999

29973000
/**
2998-
* ring_buffer_overrun_cpu - get the number of overruns in a cpu_buffer
3001+
* ring_buffer_overrun_cpu - get the number of overruns caused by the ring
3002+
* buffer wrapping around (only if RB_FL_OVERWRITE is on).
29993003
* @buffer: The ring buffer
30003004
* @cpu: The per CPU buffer to get the number of overruns from
30013005
*/
@@ -3015,7 +3019,9 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
30153019
EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu);
30163020

30173021
/**
3018-
* ring_buffer_commit_overrun_cpu - get the number of overruns caused by commits
3022+
* ring_buffer_commit_overrun_cpu - get the number of overruns caused by
3023+
* commits failing due to the buffer wrapping around while there are uncommitted
3024+
* events, such as during an interrupt storm.
30193025
* @buffer: The ring buffer
30203026
* @cpu: The per CPU buffer to get the number of overruns from
30213027
*/
@@ -3035,6 +3041,28 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
30353041
}
30363042
EXPORT_SYMBOL_GPL(ring_buffer_commit_overrun_cpu);
30373043

3044+
/**
3045+
* ring_buffer_dropped_events_cpu - get the number of dropped events caused by
3046+
* the ring buffer filling up (only if RB_FL_OVERWRITE is off).
3047+
* @buffer: The ring buffer
3048+
* @cpu: The per CPU buffer to get the number of overruns from
3049+
*/
3050+
unsigned long
3051+
ring_buffer_dropped_events_cpu(struct ring_buffer *buffer, int cpu)
3052+
{
3053+
struct ring_buffer_per_cpu *cpu_buffer;
3054+
unsigned long ret;
3055+
3056+
if (!cpumask_test_cpu(cpu, buffer->cpumask))
3057+
return 0;
3058+
3059+
cpu_buffer = buffer->buffers[cpu];
3060+
ret = local_read(&cpu_buffer->dropped_events);
3061+
3062+
return ret;
3063+
}
3064+
EXPORT_SYMBOL_GPL(ring_buffer_dropped_events_cpu);
3065+
30383066
/**
30393067
* ring_buffer_entries - get the number of entries in a buffer
30403068
* @buffer: The ring buffer
@@ -3864,9 +3892,10 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
38643892
local_set(&cpu_buffer->reader_page->page->commit, 0);
38653893
cpu_buffer->reader_page->read = 0;
38663894

3867-
local_set(&cpu_buffer->commit_overrun, 0);
38683895
local_set(&cpu_buffer->entries_bytes, 0);
38693896
local_set(&cpu_buffer->overrun, 0);
3897+
local_set(&cpu_buffer->commit_overrun, 0);
3898+
local_set(&cpu_buffer->dropped_events, 0);
38703899
local_set(&cpu_buffer->entries, 0);
38713900
local_set(&cpu_buffer->committing, 0);
38723901
local_set(&cpu_buffer->commits, 0);

‎kernel/trace/trace.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,9 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
43854385
usec_rem = do_div(t, USEC_PER_SEC);
43864386
trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
43874387

4388+
cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu);
4389+
trace_seq_printf(s, "dropped events: %ld\n", cnt);
4390+
43884391
count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
43894392

43904393
kfree(s);

0 commit comments

Comments
 (0)