Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_RING_BUFFER_H |
| 2 | #define _LINUX_RING_BUFFER_H |
| 3 | |
| 4 | #include <linux/mm.h> |
| 5 | #include <linux/seq_file.h> |
| 6 | |
| 7 | struct ring_buffer; |
| 8 | struct ring_buffer_iter; |
| 9 | |
| 10 | /* |
| 11 | * Don't reference this struct directly, use functions below. |
| 12 | */ |
| 13 | struct ring_buffer_event { |
| 14 | u32 type:2, len:3, time_delta:27; |
| 15 | u32 array[]; |
| 16 | }; |
| 17 | |
| 18 | /** |
| 19 | * enum ring_buffer_type - internal ring buffer types |
| 20 | * |
| 21 | * @RINGBUF_TYPE_PADDING: Left over page padding |
| 22 | * array is ignored |
| 23 | * size is variable depending on how much |
| 24 | * padding is needed |
| 25 | * |
| 26 | * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta |
| 27 | * array[0] = time delta (28 .. 59) |
| 28 | * size = 8 bytes |
| 29 | * |
| 30 | * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock |
Lai Jiangshan | 361b73d | 2008-12-08 10:58:08 +0800 | [diff] [blame] | 31 | * array[0] = tv_nsec |
| 32 | * array[1..2] = tv_sec |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 33 | * size = 16 bytes |
| 34 | * |
| 35 | * @RINGBUF_TYPE_DATA: Data record |
| 36 | * If len is zero: |
| 37 | * array[0] holds the actual length |
Lai Jiangshan | 361b73d | 2008-12-08 10:58:08 +0800 | [diff] [blame] | 38 | * array[1..(length+3)/4] holds data |
| 39 | * size = 4 + 4 + length (bytes) |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 40 | * else |
| 41 | * length = len << 2 |
Lai Jiangshan | 361b73d | 2008-12-08 10:58:08 +0800 | [diff] [blame] | 42 | * array[0..(length+3)/4-1] holds data |
| 43 | * size = 4 + length (bytes) |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 44 | */ |
| 45 | enum ring_buffer_type { |
| 46 | RINGBUF_TYPE_PADDING, |
| 47 | RINGBUF_TYPE_TIME_EXTEND, |
| 48 | /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */ |
| 49 | RINGBUF_TYPE_TIME_STAMP, |
| 50 | RINGBUF_TYPE_DATA, |
| 51 | }; |
| 52 | |
| 53 | unsigned ring_buffer_event_length(struct ring_buffer_event *event); |
| 54 | void *ring_buffer_event_data(struct ring_buffer_event *event); |
| 55 | |
| 56 | /** |
| 57 | * ring_buffer_event_time_delta - return the delta timestamp of the event |
| 58 | * @event: the event to get the delta timestamp of |
| 59 | * |
| 60 | * The delta timestamp is the 27 bit timestamp since the last event. |
| 61 | */ |
| 62 | static inline unsigned |
| 63 | ring_buffer_event_time_delta(struct ring_buffer_event *event) |
| 64 | { |
| 65 | return event->time_delta; |
| 66 | } |
| 67 | |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 68 | /* |
| 69 | * size is in bytes for each per CPU buffer. |
| 70 | */ |
| 71 | struct ring_buffer * |
| 72 | ring_buffer_alloc(unsigned long size, unsigned flags); |
| 73 | void ring_buffer_free(struct ring_buffer *buffer); |
| 74 | |
| 75 | int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size); |
| 76 | |
| 77 | struct ring_buffer_event * |
| 78 | ring_buffer_lock_reserve(struct ring_buffer *buffer, |
| 79 | unsigned long length, |
| 80 | unsigned long *flags); |
| 81 | int ring_buffer_unlock_commit(struct ring_buffer *buffer, |
| 82 | struct ring_buffer_event *event, |
| 83 | unsigned long flags); |
| 84 | int ring_buffer_write(struct ring_buffer *buffer, |
| 85 | unsigned long length, void *data); |
| 86 | |
| 87 | struct ring_buffer_event * |
| 88 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts); |
| 89 | struct ring_buffer_event * |
| 90 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts); |
| 91 | |
| 92 | struct ring_buffer_iter * |
| 93 | ring_buffer_read_start(struct ring_buffer *buffer, int cpu); |
| 94 | void ring_buffer_read_finish(struct ring_buffer_iter *iter); |
| 95 | |
| 96 | struct ring_buffer_event * |
| 97 | ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts); |
| 98 | struct ring_buffer_event * |
| 99 | ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts); |
| 100 | void ring_buffer_iter_reset(struct ring_buffer_iter *iter); |
| 101 | int ring_buffer_iter_empty(struct ring_buffer_iter *iter); |
| 102 | |
| 103 | unsigned long ring_buffer_size(struct ring_buffer *buffer); |
| 104 | |
| 105 | void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu); |
| 106 | void ring_buffer_reset(struct ring_buffer *buffer); |
| 107 | |
| 108 | int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, |
| 109 | struct ring_buffer *buffer_b, int cpu); |
| 110 | |
| 111 | int ring_buffer_empty(struct ring_buffer *buffer); |
| 112 | int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu); |
| 113 | |
| 114 | void ring_buffer_record_disable(struct ring_buffer *buffer); |
| 115 | void ring_buffer_record_enable(struct ring_buffer *buffer); |
| 116 | void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu); |
| 117 | void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); |
| 118 | |
| 119 | unsigned long ring_buffer_entries(struct ring_buffer *buffer); |
| 120 | unsigned long ring_buffer_overruns(struct ring_buffer *buffer); |
Robert Richter | e09373f | 2008-11-26 14:04:19 +0100 | [diff] [blame] | 121 | unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); |
| 122 | unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 123 | |
| 124 | u64 ring_buffer_time_stamp(int cpu); |
| 125 | void ring_buffer_normalize_time_stamp(int cpu, u64 *ts); |
| 126 | |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 127 | void tracing_on(void); |
| 128 | void tracing_off(void); |
Steven Rostedt | 033601a | 2008-11-21 12:41:55 -0500 | [diff] [blame] | 129 | void tracing_off_permanent(void); |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 130 | |
Steven Rostedt | 8789a9e | 2008-12-02 15:34:07 -0500 | [diff] [blame] | 131 | void *ring_buffer_alloc_read_page(struct ring_buffer *buffer); |
| 132 | void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data); |
| 133 | int ring_buffer_read_page(struct ring_buffer *buffer, |
| 134 | void **data_page, int cpu, int full); |
| 135 | |
Steven Rostedt | 7a8e76a | 2008-09-29 23:02:38 -0400 | [diff] [blame] | 136 | enum ring_buffer_flags { |
| 137 | RB_FL_OVERWRITE = 1 << 0, |
| 138 | }; |
| 139 | |
| 140 | #endif /* _LINUX_RING_BUFFER_H */ |