Commit 884bfe89a462fcc85c8abd96171519cf2fe70929

Authored by Slava Pestov
Committed by Steven Rostedt
1 parent f43c738bfa

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>

Showing 3 changed files with 39 additions and 6 deletions Side-by-side Diff

include/linux/ring_buffer.h
... ... @@ -166,6 +166,7 @@
166 166 unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
167 167 unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
168 168 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);
169 170  
170 171 u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu);
171 172 void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
kernel/trace/ring_buffer.c
... ... @@ -460,9 +460,10 @@
460 460 unsigned long lost_events;
461 461 unsigned long last_overrun;
462 462 local_t entries_bytes;
463   - local_t commit_overrun;
464   - local_t overrun;
465 463 local_t entries;
  464 + local_t overrun;
  465 + local_t commit_overrun;
  466 + local_t dropped_events;
466 467 local_t committing;
467 468 local_t commits;
468 469 unsigned long read;
469 470  
... ... @@ -2155,8 +2156,10 @@
2155 2156 * If we are not in overwrite mode,
2156 2157 * this is easy, just stop here.
2157 2158 */
2158   - if (!(buffer->flags & RB_FL_OVERWRITE))
  2159 + if (!(buffer->flags & RB_FL_OVERWRITE)) {
  2160 + local_inc(&cpu_buffer->dropped_events);
2159 2161 goto out_reset;
  2162 + }
2160 2163  
2161 2164 ret = rb_handle_head_page(cpu_buffer,
2162 2165 tail_page,
... ... @@ -2995,7 +2998,8 @@
2995 2998 EXPORT_SYMBOL_GPL(ring_buffer_entries_cpu);
2996 2999  
2997 3000 /**
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).
2999 3003 * @buffer: The ring buffer
3000 3004 * @cpu: The per CPU buffer to get the number of overruns from
3001 3005 */
... ... @@ -3015,7 +3019,9 @@
3015 3019 EXPORT_SYMBOL_GPL(ring_buffer_overrun_cpu);
3016 3020  
3017 3021 /**
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.
3019 3025 * @buffer: The ring buffer
3020 3026 * @cpu: The per CPU buffer to get the number of overruns from
3021 3027 */
... ... @@ -3036,6 +3042,28 @@
3036 3042 EXPORT_SYMBOL_GPL(ring_buffer_commit_overrun_cpu);
3037 3043  
3038 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 +
  3066 +/**
3039 3067 * ring_buffer_entries - get the number of entries in a buffer
3040 3068 * @buffer: The ring buffer
3041 3069 *
3042 3070  
... ... @@ -3864,9 +3892,10 @@
3864 3892 local_set(&cpu_buffer->reader_page->page->commit, 0);
3865 3893 cpu_buffer->reader_page->read = 0;
3866 3894  
3867   - local_set(&cpu_buffer->commit_overrun, 0);
3868 3895 local_set(&cpu_buffer->entries_bytes, 0);
3869 3896 local_set(&cpu_buffer->overrun, 0);
  3897 + local_set(&cpu_buffer->commit_overrun, 0);
  3898 + local_set(&cpu_buffer->dropped_events, 0);
3870 3899 local_set(&cpu_buffer->entries, 0);
3871 3900 local_set(&cpu_buffer->committing, 0);
3872 3901 local_set(&cpu_buffer->commits, 0);
kernel/trace/trace.c
... ... @@ -4385,6 +4385,9 @@
4385 4385 usec_rem = do_div(t, USEC_PER_SEC);
4386 4386 trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
4387 4387  
  4388 + cnt = ring_buffer_dropped_events_cpu(tr->buffer, cpu);
  4389 + trace_seq_printf(s, "dropped events: %ld\n", cnt);
  4390 +
4388 4391 count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
4389 4392  
4390 4393 kfree(s);