]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/2.6.35.8/ring-buffer-fix-typo-of-time-extends-per-page.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.35.8 / ring-buffer-fix-typo-of-time-extends-per-page.patch
CommitLineData
7691b2d1
GKH
1From d01343244abdedd18303d0323b518ed9cdcb1988 Mon Sep 17 00:00:00 2001
2From: Steven Rostedt <srostedt@redhat.com>
3Date: Tue, 12 Oct 2010 12:06:43 -0400
4Subject: ring-buffer: Fix typo of time extends per page
5
6From: Steven Rostedt <srostedt@redhat.com>
7
8commit d01343244abdedd18303d0323b518ed9cdcb1988 upstream.
9
10Time stamps for the ring buffer are created by the difference between
11two events. Each page of the ring buffer holds a full 64 bit timestamp.
12Each event has a 27 bit delta stamp from the last event. The unit of time
13is nanoseconds, so 27 bits can hold ~134 milliseconds. If two events
14happen more than 134 milliseconds apart, a time extend is inserted
15to add more bits for the delta. The time extend has 59 bits, which
16is good for ~18 years.
17
18Currently the time extend is committed separately from the event.
19If an event is discarded before it is committed, due to filtering,
20the time extend still exists. If all events are being filtered, then
21after ~134 milliseconds a new time extend will be added to the buffer.
22
23This can only happen till the end of the page. Since each page holds
24a full timestamp, there is no reason to add a time extend to the
25beginning of a page. Time extends can only fill a page that has actual
26data at the beginning, so there is no fear that time extends will fill
27more than a page without any data.
28
29When reading an event, a loop is made to skip over time extends
30since they are only used to maintain the time stamp and are never
31given to the caller. As a paranoid check to prevent the loop running
32forever, with the knowledge that time extends may only fill a page,
33a check is made that tests the iteration of the loop, and if the
34iteration is more than the number of time extends that can fit in a page
35a warning is printed and the ring buffer is disabled (all of ftrace
36is also disabled with it).
37
38There is another event type that is called a TIMESTAMP which can
39hold 64 bits of data in the theoretical case that two events happen
4018 years apart. This code has not been implemented, but the name
41of this event exists, as well as the structure for it. The
42size of a TIMESTAMP is 16 bytes, where as a time extend is only
438 bytes. The macro used to calculate how many time extends can fit on
44a page used the TIMESTAMP size instead of the time extend size
45cutting the amount in half.
46
47The following test case can easily trigger the warning since we only
48need to have half the page filled with time extends to trigger the
49warning:
50
51 # cd /sys/kernel/debug/tracing/
52 # echo function > current_tracer
53 # echo 'common_pid < 0' > events/ftrace/function/filter
54 # echo > trace
55 # echo 1 > trace_marker
56 # sleep 120
57 # cat trace
58
59Enabling the function tracer and then setting the filter to only trace
60functions where the process id is negative (no events), then clearing
61the trace buffer to ensure that we have nothing in the buffer,
62then write to trace_marker to add an event to the beginning of a page,
63sleep for 2 minutes (only 35 seconds is probably needed, but this
64guarantees the bug), and then finally reading the trace which will
65trigger the bug.
66
67This patch fixes the typo and prevents the false positive of that warning.
68
69Reported-by: Hans J. Koch <hjk@linutronix.de>
70Tested-by: Hans J. Koch <hjk@linutronix.de>
71Cc: Thomas Gleixner <tglx@linutronix.de>
72Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
73Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
74
75---
76 kernel/trace/ring_buffer.c | 2 +-
77 1 file changed, 1 insertion(+), 1 deletion(-)
78
79--- a/kernel/trace/ring_buffer.c
80+++ b/kernel/trace/ring_buffer.c
81@@ -405,7 +405,7 @@ static inline int test_time_stamp(u64 de
82 #define BUF_MAX_DATA_SIZE (BUF_PAGE_SIZE - (sizeof(u32) * 2))
83
84 /* Max number of timestamps that can fit on a page */
85-#define RB_TIMESTAMPS_PER_PAGE (BUF_PAGE_SIZE / RB_LEN_TIME_STAMP)
86+#define RB_TIMESTAMPS_PER_PAGE (BUF_PAGE_SIZE / RB_LEN_TIME_EXTEND)
87
88 int ring_buffer_print_page_header(struct trace_seq *s)
89 {