1 #ifndef _LINUX_RING_BUFFER_FRONTEND_H
2 #define _LINUX_RING_BUFFER_FRONTEND_H
5 * linux/ringbuffer/frontend.h
7 * (C) Copyright 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Ring Buffer Library Synchronization Header (API).
12 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 * See ring_buffer_frontend.c for more information on wait-free algorithms.
16 * Dual LGPL v2.1/GPL v2 license.
19 #include <linux/pipe_fs_i.h>
20 #include <linux/rcupdate.h>
21 #include <linux/cpumask.h>
22 #include <linux/module.h>
23 #include <linux/bitops.h>
24 #include <linux/splice.h>
25 #include <linux/string.h>
26 #include <linux/timer.h>
27 #include <linux/sched.h>
28 #include <linux/cache.h>
29 #include <linux/time.h>
30 #include <linux/slab.h>
31 #include <linux/init.h>
32 #include <linux/stat.h>
33 #include <linux/cpu.h>
36 #include <asm/atomic.h>
37 #include <asm/local.h>
39 /* Internal helpers */
40 #include "../../wrapper/ringbuffer/frontend_internal.h"
42 /* Buffer creation/removal and setup operations */
45 * switch_timer_interval is the time interval (in us) to fill sub-buffers with
46 * padding to let readers get those sub-buffers. Used for live streaming.
48 * read_timer_interval is the time interval (in us) to wake up pending readers.
50 * buf_addr is a pointer the the beginning of the preallocated buffer contiguous
51 * address mapping. It is used only by RING_BUFFER_STATIC configuration. It can
52 * be set to NULL for other backends.
56 struct channel
*channel_create(const struct lib_ring_buffer_config
*config
,
57 const char *name
, void *priv
,
59 size_t subbuf_size
, size_t num_subbuf
,
60 unsigned int switch_timer_interval
,
61 unsigned int read_timer_interval
);
64 * channel_destroy returns the private data pointer. It finalizes all channel's
65 * buffers, waits for readers to release all references, and destroys the
69 void *channel_destroy(struct channel
*chan
);
72 /* Buffer read operations */
75 * Iteration on channel cpumask needs to issue a read barrier to match the write
76 * barrier in cpu hotplug. It orders the cpumask read before read of per-cpu
77 * buffer data. The per-cpu buffer is never removed by cpu hotplug; teardown is
78 * only performed at channel destruction.
80 #define for_each_channel_cpu(cpu, chan) \
82 ({ (cpu) = cpumask_next(cpu, (chan)->backend.cpumask); \
83 smp_read_barrier_depends(); (cpu) < nr_cpu_ids; });)
85 extern struct lib_ring_buffer
*channel_get_ring_buffer(
86 const struct lib_ring_buffer_config
*config
,
87 struct channel
*chan
, int cpu
);
88 extern int lib_ring_buffer_open_read(struct lib_ring_buffer
*buf
);
89 extern void lib_ring_buffer_release_read(struct lib_ring_buffer
*buf
);
92 * Read sequence: snapshot, many get_subbuf/put_subbuf, move_consumer.
94 extern int lib_ring_buffer_snapshot(struct lib_ring_buffer
*buf
,
95 unsigned long *consumed
,
96 unsigned long *produced
);
97 extern void lib_ring_buffer_move_consumer(struct lib_ring_buffer
*buf
,
98 unsigned long consumed_new
);
100 extern int lib_ring_buffer_get_subbuf(struct lib_ring_buffer
*buf
,
101 unsigned long consumed
);
102 extern void lib_ring_buffer_put_subbuf(struct lib_ring_buffer
*buf
);
105 * lib_ring_buffer_get_next_subbuf/lib_ring_buffer_put_next_subbuf are helpers
106 * to read sub-buffers sequentially.
108 static inline int lib_ring_buffer_get_next_subbuf(struct lib_ring_buffer
*buf
)
112 ret
= lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
113 &buf
->prod_snapshot
);
116 ret
= lib_ring_buffer_get_subbuf(buf
, buf
->cons_snapshot
);
120 static inline void lib_ring_buffer_put_next_subbuf(struct lib_ring_buffer
*buf
)
122 lib_ring_buffer_put_subbuf(buf
);
123 lib_ring_buffer_move_consumer(buf
, subbuf_align(buf
->cons_snapshot
,
127 extern void channel_reset(struct channel
*chan
);
128 extern void lib_ring_buffer_reset(struct lib_ring_buffer
*buf
);
131 unsigned long lib_ring_buffer_get_offset(const struct lib_ring_buffer_config
*config
,
132 struct lib_ring_buffer
*buf
)
134 return v_read(config
, &buf
->offset
);
138 unsigned long lib_ring_buffer_get_consumed(const struct lib_ring_buffer_config
*config
,
139 struct lib_ring_buffer
*buf
)
141 return atomic_long_read(&buf
->consumed
);
145 * Must call lib_ring_buffer_is_finalized before reading counters (memory
146 * ordering enforced with respect to trace teardown).
149 int lib_ring_buffer_is_finalized(const struct lib_ring_buffer_config
*config
,
150 struct lib_ring_buffer
*buf
)
152 int finalized
= ACCESS_ONCE(buf
->finalized
);
154 * Read finalized before counters.
161 int lib_ring_buffer_channel_is_finalized(const struct channel
*chan
)
163 return chan
->finalized
;
167 int lib_ring_buffer_channel_is_disabled(const struct channel
*chan
)
169 return atomic_read(&chan
->record_disabled
);
173 unsigned long lib_ring_buffer_get_read_data_size(
174 const struct lib_ring_buffer_config
*config
,
175 struct lib_ring_buffer
*buf
)
177 return subbuffer_get_read_data_size(config
, &buf
->backend
);
181 unsigned long lib_ring_buffer_get_records_count(
182 const struct lib_ring_buffer_config
*config
,
183 struct lib_ring_buffer
*buf
)
185 return v_read(config
, &buf
->records_count
);
189 unsigned long lib_ring_buffer_get_records_overrun(
190 const struct lib_ring_buffer_config
*config
,
191 struct lib_ring_buffer
*buf
)
193 return v_read(config
, &buf
->records_overrun
);
197 unsigned long lib_ring_buffer_get_records_lost_full(
198 const struct lib_ring_buffer_config
*config
,
199 struct lib_ring_buffer
*buf
)
201 return v_read(config
, &buf
->records_lost_full
);
205 unsigned long lib_ring_buffer_get_records_lost_wrap(
206 const struct lib_ring_buffer_config
*config
,
207 struct lib_ring_buffer
*buf
)
209 return v_read(config
, &buf
->records_lost_wrap
);
213 unsigned long lib_ring_buffer_get_records_lost_big(
214 const struct lib_ring_buffer_config
*config
,
215 struct lib_ring_buffer
*buf
)
217 return v_read(config
, &buf
->records_lost_big
);
221 unsigned long lib_ring_buffer_get_records_read(
222 const struct lib_ring_buffer_config
*config
,
223 struct lib_ring_buffer
*buf
)
225 return v_read(config
, &buf
->backend
.records_read
);
228 #endif /* _LINUX_RING_BUFFER_FRONTEND_H */
This page took 0.034592 seconds and 4 git commands to generate.