ftrace: add a new 'tail drops' counter for overflow events
Subsystems (2)
PATCH 1/1 ftrace: add a new 'tail drops' counter for overflow events
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.
--- include/linux/ring_buffer.h | 1 + kernel/trace/ring_buffer.c | 43 ++++++++++++++++++++++++++++++++++++------- kernel/trace/trace.c | 3 +++ 3 files changed, 40 insertions(+), 7 deletions(-)
include/linux/ring_buffer.h +1 -0
@@ -157,6 +157,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer);unsigned long ring_buffer_entries_cpu (struct ring_buffer *buffer,int cpu);unsigned long ring_buffer_overrun_cpu (struct ring_buffer *buffer,int cpu);unsigned long ring_buffer_commit_overrun_cpu (struct ring_buffer *buffer,int cpu); +unsigned long ring_buffer_tail_drops_cpu (struct ring_buffer *buffer,int cpu);u64 ring_buffer_time_stamp (struct ring_buffer *buffer,int cpu); void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
kernel/trace/ring_buffer.c +36 -7
81 lines not on this page · raw message
kernel/trace/trace.c +3 -0
@@ -3916,6 +3916,9 @@ tracing_stats_read(struct file *filp, char __user *ubuf, cnt =ring_buffer_commit_overrun_cpu (tr->buffer, cpu);trace_seq_printf (s,"commit overrun: %ld\n" , cnt); + cnt =ring_buffer_tail_drops_cpu (tr->buffer, cpu); +trace_seq_printf (s,"tail drops: %ld\n" , cnt); + count =simple_read_from_buffer (ubuf, count, ppos, s->buffer, s->len);kfree (s);
Signature · 1 line
1.7.3.1
Steven Rostedt
maintainerQuoted 7 lines · Slava Pestov
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.
So this is when we are in producer/consumer mode and the ring buffer fills up and events are dropped.
For this we could just add a new ring buffer type. We could use the RINGBUF_TYPE_TIME_STAMP as and call it RINGBUF_TYPE_LOST_EVENTS instead. I never implemented the TIME_STAMP as I never found a need to ;)
As we currently have a TIME_EXTEND that is still relative from the last event but has a total of 59 bits for time. That being nanoseconds we can handle events that are 18 years apart. That far apart and never being read.
The LOST_EVENTS could store the number of events lost when it starts reading again. This way raw readers will know that events were lost and how many.
-- Steve
Quoted 2 lines
Signed-off-by Slava Pestov <[email protected]>
Quoted 16 lines · Steven Rostedt
Quoted 7 lines · Slava Pestov
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.
So this is when we are in producer/consumer mode and the ring buffer fills up and events are dropped.
For this we could just add a new ring buffer type. We could use the
RINGBUF_TYPE_TIME_STAMPas and call itRINGBUF_TYPE_LOST_EVENTSinstead. I never implemented theTIME_STAMPas I never found a need to ;)
Quoted 8 lines
As we currently have a
TIME_EXTENDthat is still relative from the last event but has a total of 59 bits for time. That being nanoseconds we can handle events that are 18 years apart. That far apart and never being read.The
LOST_EVENTScould store the number of events lost when it starts reading again. This way raw readers will know that events were lost and how many.
s/reading/writing ? ie, the next time enough space is available, it would first write a LOST_EVENTS event before returning space for the next event?
Regardless of whether or not you want to put this info in the trace itself (I agree it would be very useful to know where events were dropped), I think it's useful for a user to be able to quickly see the total number of events that were lost without grepping the trace.
Quoted 9 lines
-- Steve
Quoted 2 lines
Signed-off-by Slava Pestov <[email protected]>