ring_buffer.h 4.6 KB
Newer Older
S
Steven Rostedt 已提交
1 2 3 4 5 6 7 8 9 10
#ifndef _LINUX_RING_BUFFER_H
#define _LINUX_RING_BUFFER_H

#include <linux/mm.h>
#include <linux/seq_file.h>

struct ring_buffer;
struct ring_buffer_iter;

/*
W
Wenji Huang 已提交
11
 * Don't refer to this struct directly, use functions below.
S
Steven Rostedt 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 */
struct ring_buffer_event {
	u32		type:2, len:3, time_delta:27;
	u32		array[];
};

/**
 * enum ring_buffer_type - internal ring buffer types
 *
 * @RINGBUF_TYPE_PADDING:	Left over page padding
 *				 array is ignored
 *				 size is variable depending on how much
 *				  padding is needed
 *
 * @RINGBUF_TYPE_TIME_EXTEND:	Extend the time delta
 *				 array[0] = time delta (28 .. 59)
 *				 size = 8 bytes
 *
 * @RINGBUF_TYPE_TIME_STAMP:	Sync time stamp with external clock
L
Lai Jiangshan 已提交
31 32
 *				 array[0]    = tv_nsec
 *				 array[1..2] = tv_sec
S
Steven Rostedt 已提交
33 34 35 36 37
 *				 size = 16 bytes
 *
 * @RINGBUF_TYPE_DATA:		Data record
 *				 If len is zero:
 *				  array[0] holds the actual length
L
Lai Jiangshan 已提交
38 39
 *				  array[1..(length+3)/4] holds data
 *				  size = 4 + 4 + length (bytes)
S
Steven Rostedt 已提交
40 41
 *				 else
 *				  length = len << 2
L
Lai Jiangshan 已提交
42 43
 *				  array[0..(length+3)/4-1] holds data
 *				  size = 4 + length (bytes)
S
Steven Rostedt 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
 */
enum ring_buffer_type {
	RINGBUF_TYPE_PADDING,
	RINGBUF_TYPE_TIME_EXTEND,
	/* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
	RINGBUF_TYPE_TIME_STAMP,
	RINGBUF_TYPE_DATA,
};

unsigned ring_buffer_event_length(struct ring_buffer_event *event);
void *ring_buffer_event_data(struct ring_buffer_event *event);

/**
 * ring_buffer_event_time_delta - return the delta timestamp of the event
 * @event: the event to get the delta timestamp of
 *
 * The delta timestamp is the 27 bit timestamp since the last event.
 */
static inline unsigned
ring_buffer_event_time_delta(struct ring_buffer_event *event)
{
	return event->time_delta;
}

/*
 * size is in bytes for each per CPU buffer.
 */
struct ring_buffer *
ring_buffer_alloc(unsigned long size, unsigned flags);
void ring_buffer_free(struct ring_buffer *buffer);

int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size);

77 78
struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer,
						   unsigned long length);
S
Steven Rostedt 已提交
79
int ring_buffer_unlock_commit(struct ring_buffer *buffer,
80
			      struct ring_buffer_event *event);
S
Steven Rostedt 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
int ring_buffer_write(struct ring_buffer *buffer,
		      unsigned long length, void *data);

struct ring_buffer_event *
ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts);
struct ring_buffer_event *
ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts);

struct ring_buffer_iter *
ring_buffer_read_start(struct ring_buffer *buffer, int cpu);
void ring_buffer_read_finish(struct ring_buffer_iter *iter);

struct ring_buffer_event *
ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts);
struct ring_buffer_event *
ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts);
void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
int ring_buffer_iter_empty(struct ring_buffer_iter *iter);

unsigned long ring_buffer_size(struct ring_buffer *buffer);

void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu);
void ring_buffer_reset(struct ring_buffer *buffer);

int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
			 struct ring_buffer *buffer_b, int cpu);

int ring_buffer_empty(struct ring_buffer *buffer);
int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu);

void ring_buffer_record_disable(struct ring_buffer *buffer);
void ring_buffer_record_enable(struct ring_buffer *buffer);
void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu);
void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu);

unsigned long ring_buffer_entries(struct ring_buffer *buffer);
unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
118 119
unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
S
Steven Rostedt 已提交
120 121 122 123

u64 ring_buffer_time_stamp(int cpu);
void ring_buffer_normalize_time_stamp(int cpu, u64 *ts);

124 125 126 127
/*
 * The below functions are fine to use outside the tracing facility.
 */
#ifdef CONFIG_RING_BUFFER
128 129
void tracing_on(void);
void tracing_off(void);
130
void tracing_off_permanent(void);
131
int tracing_is_on(void);
132 133 134 135
#else
static inline void tracing_on(void) { }
static inline void tracing_off(void) { }
static inline void tracing_off_permanent(void) { }
136
static inline int tracing_is_on(void) { return 0; }
137
#endif
138

S
Steven Rostedt 已提交
139 140 141 142 143
void *ring_buffer_alloc_read_page(struct ring_buffer *buffer);
void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data);
int ring_buffer_read_page(struct ring_buffer *buffer,
			  void **data_page, int cpu, int full);

S
Steven Rostedt 已提交
144 145 146 147 148
enum ring_buffer_flags {
	RB_FL_OVERWRITE		= 1 << 0,
};

#endif /* _LINUX_RING_BUFFER_H */