17a8e76a3SSteven Rostedt #ifndef _LINUX_RING_BUFFER_H 27a8e76a3SSteven Rostedt #define _LINUX_RING_BUFFER_H 37a8e76a3SSteven Rostedt 47a8e76a3SSteven Rostedt #include <linux/mm.h> 57a8e76a3SSteven Rostedt #include <linux/seq_file.h> 67a8e76a3SSteven Rostedt 77a8e76a3SSteven Rostedt struct ring_buffer; 87a8e76a3SSteven Rostedt struct ring_buffer_iter; 97a8e76a3SSteven Rostedt 107a8e76a3SSteven Rostedt /* 117a8e76a3SSteven Rostedt * Don't reference this struct directly, use functions below. 127a8e76a3SSteven Rostedt */ 137a8e76a3SSteven Rostedt struct ring_buffer_event { 147a8e76a3SSteven Rostedt u32 type:2, len:3, time_delta:27; 157a8e76a3SSteven Rostedt u32 array[]; 167a8e76a3SSteven Rostedt }; 177a8e76a3SSteven Rostedt 187a8e76a3SSteven Rostedt /** 197a8e76a3SSteven Rostedt * enum ring_buffer_type - internal ring buffer types 207a8e76a3SSteven Rostedt * 217a8e76a3SSteven Rostedt * @RINGBUF_TYPE_PADDING: Left over page padding 227a8e76a3SSteven Rostedt * array is ignored 237a8e76a3SSteven Rostedt * size is variable depending on how much 247a8e76a3SSteven Rostedt * padding is needed 257a8e76a3SSteven Rostedt * 267a8e76a3SSteven Rostedt * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta 277a8e76a3SSteven Rostedt * array[0] = time delta (28 .. 59) 287a8e76a3SSteven Rostedt * size = 8 bytes 297a8e76a3SSteven Rostedt * 307a8e76a3SSteven Rostedt * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock 317a8e76a3SSteven Rostedt * array[0] = tv_nsec 32361b73d5SLai Jiangshan * array[1..2] = tv_sec 337a8e76a3SSteven Rostedt * size = 16 bytes 347a8e76a3SSteven Rostedt * 357a8e76a3SSteven Rostedt * @RINGBUF_TYPE_DATA: Data record 367a8e76a3SSteven Rostedt * If len is zero: 377a8e76a3SSteven Rostedt * array[0] holds the actual length 38361b73d5SLai Jiangshan * array[1..(length+3)/4] holds data 39361b73d5SLai Jiangshan * size = 4 + 4 + length (bytes) 407a8e76a3SSteven Rostedt * else 417a8e76a3SSteven Rostedt * length = len << 2 42361b73d5SLai Jiangshan * array[0..(length+3)/4-1] holds data 43361b73d5SLai Jiangshan * size = 4 + length (bytes) 447a8e76a3SSteven Rostedt */ 457a8e76a3SSteven Rostedt enum ring_buffer_type { 467a8e76a3SSteven Rostedt RINGBUF_TYPE_PADDING, 477a8e76a3SSteven Rostedt RINGBUF_TYPE_TIME_EXTEND, 487a8e76a3SSteven Rostedt /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */ 497a8e76a3SSteven Rostedt RINGBUF_TYPE_TIME_STAMP, 507a8e76a3SSteven Rostedt RINGBUF_TYPE_DATA, 517a8e76a3SSteven Rostedt }; 527a8e76a3SSteven Rostedt 537a8e76a3SSteven Rostedt unsigned ring_buffer_event_length(struct ring_buffer_event *event); 547a8e76a3SSteven Rostedt void *ring_buffer_event_data(struct ring_buffer_event *event); 557a8e76a3SSteven Rostedt 567a8e76a3SSteven Rostedt /** 577a8e76a3SSteven Rostedt * ring_buffer_event_time_delta - return the delta timestamp of the event 587a8e76a3SSteven Rostedt * @event: the event to get the delta timestamp of 597a8e76a3SSteven Rostedt * 607a8e76a3SSteven Rostedt * The delta timestamp is the 27 bit timestamp since the last event. 617a8e76a3SSteven Rostedt */ 627a8e76a3SSteven Rostedt static inline unsigned 637a8e76a3SSteven Rostedt ring_buffer_event_time_delta(struct ring_buffer_event *event) 647a8e76a3SSteven Rostedt { 657a8e76a3SSteven Rostedt return event->time_delta; 667a8e76a3SSteven Rostedt } 677a8e76a3SSteven Rostedt 687a8e76a3SSteven Rostedt /* 697a8e76a3SSteven Rostedt * size is in bytes for each per CPU buffer. 707a8e76a3SSteven Rostedt */ 717a8e76a3SSteven Rostedt struct ring_buffer * 727a8e76a3SSteven Rostedt ring_buffer_alloc(unsigned long size, unsigned flags); 737a8e76a3SSteven Rostedt void ring_buffer_free(struct ring_buffer *buffer); 747a8e76a3SSteven Rostedt 757a8e76a3SSteven Rostedt int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size); 767a8e76a3SSteven Rostedt 77*0a987751SArnaldo Carvalho de Melo struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer, 78*0a987751SArnaldo Carvalho de Melo unsigned long length); 797a8e76a3SSteven Rostedt int ring_buffer_unlock_commit(struct ring_buffer *buffer, 80*0a987751SArnaldo Carvalho de Melo struct ring_buffer_event *event); 817a8e76a3SSteven Rostedt int ring_buffer_write(struct ring_buffer *buffer, 827a8e76a3SSteven Rostedt unsigned long length, void *data); 837a8e76a3SSteven Rostedt 847a8e76a3SSteven Rostedt struct ring_buffer_event * 857a8e76a3SSteven Rostedt ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts); 867a8e76a3SSteven Rostedt struct ring_buffer_event * 877a8e76a3SSteven Rostedt ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts); 887a8e76a3SSteven Rostedt 897a8e76a3SSteven Rostedt struct ring_buffer_iter * 907a8e76a3SSteven Rostedt ring_buffer_read_start(struct ring_buffer *buffer, int cpu); 917a8e76a3SSteven Rostedt void ring_buffer_read_finish(struct ring_buffer_iter *iter); 927a8e76a3SSteven Rostedt 937a8e76a3SSteven Rostedt struct ring_buffer_event * 947a8e76a3SSteven Rostedt ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts); 957a8e76a3SSteven Rostedt struct ring_buffer_event * 967a8e76a3SSteven Rostedt ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts); 977a8e76a3SSteven Rostedt void ring_buffer_iter_reset(struct ring_buffer_iter *iter); 987a8e76a3SSteven Rostedt int ring_buffer_iter_empty(struct ring_buffer_iter *iter); 997a8e76a3SSteven Rostedt 1007a8e76a3SSteven Rostedt unsigned long ring_buffer_size(struct ring_buffer *buffer); 1017a8e76a3SSteven Rostedt 1027a8e76a3SSteven Rostedt void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu); 1037a8e76a3SSteven Rostedt void ring_buffer_reset(struct ring_buffer *buffer); 1047a8e76a3SSteven Rostedt 1057a8e76a3SSteven Rostedt int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, 1067a8e76a3SSteven Rostedt struct ring_buffer *buffer_b, int cpu); 1077a8e76a3SSteven Rostedt 1087a8e76a3SSteven Rostedt int ring_buffer_empty(struct ring_buffer *buffer); 1097a8e76a3SSteven Rostedt int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu); 1107a8e76a3SSteven Rostedt 1117a8e76a3SSteven Rostedt void ring_buffer_record_disable(struct ring_buffer *buffer); 1127a8e76a3SSteven Rostedt void ring_buffer_record_enable(struct ring_buffer *buffer); 1137a8e76a3SSteven Rostedt void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu); 1147a8e76a3SSteven Rostedt void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); 1157a8e76a3SSteven Rostedt 1167a8e76a3SSteven Rostedt unsigned long ring_buffer_entries(struct ring_buffer *buffer); 1177a8e76a3SSteven Rostedt unsigned long ring_buffer_overruns(struct ring_buffer *buffer); 118e09373f2SRobert Richter unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); 119e09373f2SRobert Richter unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); 1207a8e76a3SSteven Rostedt 1217a8e76a3SSteven Rostedt u64 ring_buffer_time_stamp(int cpu); 1227a8e76a3SSteven Rostedt void ring_buffer_normalize_time_stamp(int cpu, u64 *ts); 1237a8e76a3SSteven Rostedt 124a3583244SSteven Rostedt void tracing_on(void); 125a3583244SSteven Rostedt void tracing_off(void); 126033601a3SSteven Rostedt void tracing_off_permanent(void); 127a3583244SSteven Rostedt 1288789a9e7SSteven Rostedt void *ring_buffer_alloc_read_page(struct ring_buffer *buffer); 1298789a9e7SSteven Rostedt void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data); 1308789a9e7SSteven Rostedt int ring_buffer_read_page(struct ring_buffer *buffer, 1318789a9e7SSteven Rostedt void **data_page, int cpu, int full); 1328789a9e7SSteven Rostedt 1337a8e76a3SSteven Rostedt enum ring_buffer_flags { 1347a8e76a3SSteven Rostedt RB_FL_OVERWRITE = 1 << 0, 1357a8e76a3SSteven Rostedt }; 1367a8e76a3SSteven Rostedt 1377a8e76a3SSteven Rostedt #endif /* _LINUX_RING_BUFFER_H */ 138