diff options
Diffstat (limited to 'kernel/trace/ring_buffer.c')
| -rw-r--r-- | kernel/trace/ring_buffer.c | 693 |
1 files changed, 529 insertions, 164 deletions
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index bd38c5cfd8a..960cbf44c84 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c | |||
| @@ -4,21 +4,92 @@ | |||
| 4 | * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com> | 4 | * Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com> |
| 5 | */ | 5 | */ |
| 6 | #include <linux/ring_buffer.h> | 6 | #include <linux/ring_buffer.h> |
| 7 | #include <linux/trace_clock.h> | ||
| 8 | #include <linux/ftrace_irq.h> | ||
| 7 | #include <linux/spinlock.h> | 9 | #include <linux/spinlock.h> |
| 8 | #include <linux/debugfs.h> | 10 | #include <linux/debugfs.h> |
| 9 | #include <linux/uaccess.h> | 11 | #include <linux/uaccess.h> |
| 12 | #include <linux/hardirq.h> | ||
| 10 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 11 | #include <linux/percpu.h> | 14 | #include <linux/percpu.h> |
| 12 | #include <linux/mutex.h> | 15 | #include <linux/mutex.h> |
| 13 | #include <linux/sched.h> /* used for sched_clock() (for now) */ | ||
| 14 | #include <linux/init.h> | 16 | #include <linux/init.h> |
| 15 | #include <linux/hash.h> | 17 | #include <linux/hash.h> |
| 16 | #include <linux/list.h> | 18 | #include <linux/list.h> |
| 19 | #include <linux/cpu.h> | ||
| 17 | #include <linux/fs.h> | 20 | #include <linux/fs.h> |
| 18 | 21 | ||
| 19 | #include "trace.h" | 22 | #include "trace.h" |
| 20 | 23 | ||
| 21 | /* | 24 | /* |
| 25 | * The ring buffer is made up of a list of pages. A separate list of pages is | ||
| 26 | * allocated for each CPU. A writer may only write to a buffer that is | ||
| 27 | * associated with the CPU it is currently executing on. A reader may read | ||
| 28 | * from any per cpu buffer. | ||
| 29 | * | ||
| 30 | * The reader is special. For each per cpu buffer, the reader has its own | ||
| 31 | * reader page. When a reader has read the entire reader page, this reader | ||
| 32 | * page is swapped with another page in the ring buffer. | ||
| 33 | * | ||
| 34 | * Now, as long as the writer is off the reader page, the reader can do what | ||
| 35 | * ever it wants with that page. The writer will never write to that page | ||
| 36 | * again (as long as it is out of the ring buffer). | ||
| 37 | * | ||
| 38 | * Here's some silly ASCII art. | ||
| 39 | * | ||
| 40 | * +------+ | ||
| 41 | * |reader| RING BUFFER | ||
| 42 | * |page | | ||
| 43 | * +------+ +---+ +---+ +---+ | ||
| 44 | * | |-->| |-->| | | ||
| 45 | * +---+ +---+ +---+ | ||
| 46 | * ^ | | ||
| 47 | * | | | ||
| 48 | * +---------------+ | ||
| 49 | * | ||
| 50 | * | ||
| 51 | * +------+ | ||
| 52 | * |reader| RING BUFFER | ||
| 53 | * |page |------------------v | ||
| 54 | * +------+ +---+ +---+ +---+ | ||
| 55 | * | |-->| |-->| | | ||
| 56 | * +---+ +---+ +---+ | ||
| 57 | * ^ | | ||
| 58 | * | | | ||
| 59 | * +---------------+ | ||
| 60 | * | ||
| 61 | * | ||
| 62 | * +------+ | ||
| 63 | * |reader| RING BUFFER | ||
| 64 | * |page |------------------v | ||
| 65 | * +------+ +---+ +---+ +---+ | ||
| 66 | * ^ | |-->| |-->| | | ||
| 67 | * | +---+ +---+ +---+ | ||
| 68 | * | | | ||
| 69 | * | | | ||
| 70 | * +------------------------------+ | ||
| 71 | * | ||
| 72 | * | ||
| 73 | * +------+ | ||
| 74 | * |buffer| RING BUFFER | ||
| 75 | * |page |------------------v | ||
| 76 | * +------+ +---+ +---+ +---+ | ||
| 77 | * ^ | | | |-->| | | ||
| 78 | * | New +---+ +---+ +---+ | ||
| 79 | * | Reader------^ | | ||
| 80 | * | page | | ||
| 81 | * +------------------------------+ | ||
| 82 | * | ||
| 83 | * | ||
| 84 | * After we make this swap, the reader can hand this page off to the splice | ||
| 85 | * code and be done with it. It can even allocate a new page if it needs to | ||
| 86 | * and swap that into the ring buffer. | ||
| 87 | * | ||
| 88 | * We will be using cmpxchg soon to make all this lockless. | ||
| 89 | * | ||
| 90 | */ | ||
| 91 | |||
| 92 | /* | ||
| 22 | * A fast way to enable or disable all ring buffers is to | 93 | * A fast way to enable or disable all ring buffers is to |
| 23 | * call tracing_on or tracing_off. Turning off the ring buffers | 94 | * call tracing_on or tracing_off. Turning off the ring buffers |
| 24 | * prevents all ring buffers from being recorded to. | 95 | * prevents all ring buffers from being recorded to. |
| @@ -57,7 +128,9 @@ enum { | |||
| 57 | RB_BUFFERS_DISABLED = 1 << RB_BUFFERS_DISABLED_BIT, | 128 | RB_BUFFERS_DISABLED = 1 << RB_BUFFERS_DISABLED_BIT, |
| 58 | }; | 129 | }; |
| 59 | 130 | ||
| 60 | static long ring_buffer_flags __read_mostly = RB_BUFFERS_ON; | 131 | static unsigned long ring_buffer_flags __read_mostly = RB_BUFFERS_ON; |
| 132 | |||
| 133 | #define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) | ||
| 61 | 134 | ||
| 62 | /** | 135 | /** |
| 63 | * tracing_on - enable all tracing buffers | 136 | * tracing_on - enable all tracing buffers |
| @@ -89,59 +162,92 @@ EXPORT_SYMBOL_GPL(tracing_off); | |||
| 89 | * tracing_off_permanent - permanently disable ring buffers | 162 | * tracing_off_permanent - permanently disable ring buffers |
| 90 | * | 163 | * |
| 91 | * This function, once called, will disable all ring buffers | 164 | * This function, once called, will disable all ring buffers |
| 92 | * permanenty. | 165 | * permanently. |
| 93 | */ | 166 | */ |
| 94 | void tracing_off_permanent(void) | 167 | void tracing_off_permanent(void) |
| 95 | { | 168 | { |
| 96 | set_bit(RB_BUFFERS_DISABLED_BIT, &ring_buffer_flags); | 169 | set_bit(RB_BUFFERS_DISABLED_BIT, &ring_buffer_flags); |
| 97 | } | 170 | } |
| 98 | 171 | ||
| 172 | /** | ||
| 173 | * tracing_is_on - show state of ring buffers enabled | ||
| 174 | */ | ||
| 175 | int tracing_is_on(void) | ||
| 176 | { | ||
| 177 | return ring_buffer_flags == RB_BUFFERS_ON; | ||
| 178 | } | ||
| 179 | EXPORT_SYMBOL_GPL(tracing_is_on); | ||
| 180 | |||
| 99 | #include "trace.h" | 181 | #include "trace.h" |
| 100 | 182 | ||
| 101 | /* Up this if you want to test the TIME_EXTENTS and normalization */ | 183 | #define RB_EVNT_HDR_SIZE (offsetof(struct ring_buffer_event, array)) |
| 102 | #define DEBUG_SHIFT 0 | 184 | #define RB_ALIGNMENT 4U |
| 185 | #define RB_MAX_SMALL_DATA 28 | ||
| 186 | |||
| 187 | enum { | ||
| 188 | RB_LEN_TIME_EXTEND = 8, | ||
| 189 | RB_LEN_TIME_STAMP = 16, | ||
| 190 | }; | ||
| 103 | 191 | ||
| 104 | /* FIXME!!! */ | 192 | static inline int rb_null_event(struct ring_buffer_event *event) |
| 105 | u64 ring_buffer_time_stamp(int cpu) | ||
| 106 | { | 193 | { |
| 107 | u64 time; | 194 | return event->type == RINGBUF_TYPE_PADDING && event->time_delta == 0; |
| 195 | } | ||
| 108 | 196 | ||
| 109 | preempt_disable_notrace(); | 197 | static inline int rb_discarded_event(struct ring_buffer_event *event) |
| 110 | /* shift to debug/test normalization and TIME_EXTENTS */ | 198 | { |
| 111 | time = sched_clock() << DEBUG_SHIFT; | 199 | return event->type == RINGBUF_TYPE_PADDING && event->time_delta; |
| 112 | preempt_enable_no_resched_notrace(); | 200 | } |
| 113 | 201 | ||
| 114 | return time; | 202 | static void rb_event_set_padding(struct ring_buffer_event *event) |
| 203 | { | ||
| 204 | event->type = RINGBUF_TYPE_PADDING; | ||
| 205 | event->time_delta = 0; | ||
| 115 | } | 206 | } |
| 116 | EXPORT_SYMBOL_GPL(ring_buffer_time_stamp); | ||
| 117 | 207 | ||
| 118 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts) | 208 | /** |
| 209 | * ring_buffer_event_discard - discard an event in the ring buffer | ||
| 210 | * @buffer: the ring buffer | ||
| 211 | * @event: the event to discard | ||
| 212 | * | ||
| 213 | * Sometimes a event that is in the ring buffer needs to be ignored. | ||
| 214 | * This function lets the user discard an event in the ring buffer | ||
| 215 | * and then that event will not be read later. | ||
| 216 | * | ||
| 217 | * Note, it is up to the user to be careful with this, and protect | ||
| 218 | * against races. If the user discards an event that has been consumed | ||
| 219 | * it is possible that it could corrupt the ring buffer. | ||
| 220 | */ | ||
| 221 | void ring_buffer_event_discard(struct ring_buffer_event *event) | ||
| 119 | { | 222 | { |
| 120 | /* Just stupid testing the normalize function and deltas */ | 223 | event->type = RINGBUF_TYPE_PADDING; |
| 121 | *ts >>= DEBUG_SHIFT; | 224 | /* time delta must be non zero */ |
| 225 | if (!event->time_delta) | ||
| 226 | event->time_delta = 1; | ||
| 122 | } | 227 | } |
| 123 | EXPORT_SYMBOL_GPL(ring_buffer_normalize_time_stamp); | ||
| 124 | 228 | ||
| 125 | #define RB_EVNT_HDR_SIZE (sizeof(struct ring_buffer_event)) | 229 | static unsigned |
| 126 | #define RB_ | ||
