Skip to content

Commit 9e5d25e

Browse files
committed
Merge tag 'trace-v4.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: "I found two minor bugs while doing development on the ring buffer code. The first is something that's been there since its creation. If a reader reads a page out of the ring buffer before there's any events on it, it can get an out of date timestamp for that event. It may be off by a few microseconds, more if the first event gets discarded. The fix was to only update the reader time stamp when it actually sees an event on the page, instead of just reading the timestamp from the page even if it has no events on it. That timestamp is still volatile until an event is present. The second bug is more recent. Instead of passing around parameters a descriptor was made and the parameters are passed via a single descriptor. This simplified the code a bit. But there was one place that expected the parameter to be passed by value not reference (which a descriptor now does). And it added to the length of the event, which may be ignored later, but the length should not have been increased. The only real problem with this bug is that it may allocate more than was needed for the event" * tag 'trace-v4.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: ring-buffer: Put back the length if crossed page with add_timestamp ring-buffer: Update read stamp with first real commit on page
2 parents 31ade3b + bd1b7cd commit 9e5d25e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/trace/ring_buffer.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,12 +1887,6 @@ rb_event_index(struct ring_buffer_event *event)
18871887
return (addr & ~PAGE_MASK) - BUF_PAGE_HDR_SIZE;
18881888
}
18891889

1890-
static void rb_reset_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
1891-
{
1892-
cpu_buffer->read_stamp = cpu_buffer->reader_page->page->time_stamp;
1893-
cpu_buffer->reader_page->read = 0;
1894-
}
1895-
18961890
static void rb_inc_iter(struct ring_buffer_iter *iter)
18971891
{
18981892
struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
@@ -2803,8 +2797,11 @@ rb_reserve_next_event(struct ring_buffer *buffer,
28032797

28042798
event = __rb_reserve_next(cpu_buffer, &info);
28052799

2806-
if (unlikely(PTR_ERR(event) == -EAGAIN))
2800+
if (unlikely(PTR_ERR(event) == -EAGAIN)) {
2801+
if (info.add_timestamp)
2802+
info.length -= RB_LEN_TIME_EXTEND;
28072803
goto again;
2804+
}
28082805

28092806
if (!event)
28102807
goto out_fail;
@@ -3626,7 +3623,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
36263623

36273624
/* Finally update the reader page to the new head */
36283625
cpu_buffer->reader_page = reader;
3629-
rb_reset_reader_page(cpu_buffer);
3626+
cpu_buffer->reader_page->read = 0;
36303627

36313628
if (overwrite != cpu_buffer->last_overrun) {
36323629
cpu_buffer->lost_events = overwrite - cpu_buffer->last_overrun;
@@ -3636,6 +3633,10 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
36363633
goto again;
36373634

36383635
out:
3636+
/* Update the read_stamp on the first event */
3637+
if (reader && reader->read == 0)
3638+
cpu_buffer->read_stamp = reader->page->time_stamp;
3639+
36393640
arch_spin_unlock(&cpu_buffer->lock);
36403641
local_irq_restore(flags);
36413642

0 commit comments

Comments
 (0)