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