1 #ifndef _LINUX_RING_BUFFER_FRONTEND_TYPES_H
2 #define _LINUX_RING_BUFFER_FRONTEND_TYPES_H
5 * linux/ringbuffer/frontend_types.h
7 * (C) Copyright 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Ring Buffer Library Synchronization Header (types).
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/kref.h>
20 #include "../../wrapper/ringbuffer/config.h"
21 #include "../../wrapper/ringbuffer/backend_types.h"
22 #include "../../wrapper/prio_heap.h" /* For per-CPU read-side iterator */
25 * A switch is done during tracing or as a final flush after tracing (so it
26 * won't write in the new sub-buffer).
28 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
30 /* channel-level read-side iterator */
32 /* Prio heap of buffers. Lowest timestamps at the top. */
33 struct ptr_heap heap
; /* Heap of struct lib_ring_buffer ptrs */
34 struct list_head empty_head
; /* Empty buffers linked-list head */
35 int read_open
; /* Opened for reading ? */
36 u64 last_qs
; /* Last quiescent state timestamp */
37 u64 last_timestamp
; /* Last timestamp (for WARN_ON) */
38 int last_cpu
; /* Last timestamp cpu */
40 * read() file operation state.
42 unsigned long len_left
;
45 /* channel: collection of per-cpu ring buffers. */
47 atomic_t record_disabled
;
48 unsigned long commit_count_mask
; /*
49 * Commit count mask, removing
50 * the MSBs corresponding to
51 * bits used to represent the
55 struct channel_backend backend
; /* Associated backend */
57 unsigned long switch_timer_interval
; /* Buffer flush (jiffies) */
58 unsigned long read_timer_interval
; /* Reader wakeup (jiffies) */
59 struct notifier_block cpu_hp_notifier
; /* CPU hotplug notifier */
60 struct notifier_block tick_nohz_notifier
; /* CPU nohz notifier */
61 struct notifier_block hp_iter_notifier
; /* hotplug iterator notifier */
62 int cpu_hp_enable
:1; /* Enable CPU hotplug notif. */
63 int hp_iter_enable
:1; /* Enable hp iter notif. */
64 wait_queue_head_t read_wait
; /* reader wait queue */
65 struct channel_iter iter
; /* Channel read-side iterator */
66 struct kref ref
; /* Reference count */
69 /* Per-subbuffer commit counters used on the hot path */
70 struct commit_counters_hot
{
71 union v_atomic cc
; /* Commit counter */
72 union v_atomic seq
; /* Consecutive commits */
75 /* Per-subbuffer commit counters used only on cold paths */
76 struct commit_counters_cold
{
77 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
80 /* Per-buffer read iterator */
81 struct lib_ring_buffer_iter
{
82 u64 timestamp
; /* Current record timestamp */
83 size_t header_len
; /* Current record header length */
84 size_t payload_len
; /* Current record payload length */
86 struct list_head empty_node
; /* Linked list of empty buffers */
87 unsigned long consumed
, read_offset
, data_size
;
95 int read_open
:1; /* Opened for reading ? */
98 /* ring buffer state */
99 struct lib_ring_buffer
{
100 /* First 32 bytes cache-hot cacheline */
101 union v_atomic offset
; /* Current offset in the buffer */
102 struct commit_counters_hot
*commit_hot
;
103 /* Commit count per sub-buffer */
104 atomic_long_t consumed
; /*
105 * Current offset in the buffer
106 * standard atomic access (shared)
108 atomic_t record_disabled
;
109 /* End of first 32 bytes cacheline */
110 union v_atomic last_tsc
; /*
111 * Last timestamp written in the buffer.
114 struct lib_ring_buffer_backend backend
; /* Associated backend */
116 struct commit_counters_cold
*commit_cold
;
117 /* Commit count per sub-buffer */
118 atomic_long_t active_readers
; /*
119 * Active readers count
120 * standard atomic access (shared)
122 /* Dropped records */
123 union v_atomic records_lost_full
; /* Buffer full */
124 union v_atomic records_lost_wrap
; /* Nested wrap-around */
125 union v_atomic records_lost_big
; /* Events too big */
126 union v_atomic records_count
; /* Number of records written */
127 union v_atomic records_overrun
; /* Number of overwritten records */
128 wait_queue_head_t read_wait
; /* reader buffer-level wait queue */
129 int finalized
; /* buffer has been finalized */
130 struct timer_list switch_timer
; /* timer for periodical switch */
131 struct timer_list read_timer
; /* timer for read poll */
132 raw_spinlock_t raw_tick_nohz_spinlock
; /* nohz entry lock/trylock */
133 struct lib_ring_buffer_iter iter
; /* read-side iterator */
134 unsigned long get_subbuf_consumed
; /* Read-side consumed */
135 unsigned long prod_snapshot
; /* Producer count snapshot */
136 unsigned long cons_snapshot
; /* Consumer count snapshot */
137 int get_subbuf
:1; /* Sub-buffer being held by reader */
138 int switch_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
139 int read_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
143 * Issue warnings and disable channels upon internal error.
144 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
147 #define CHAN_WARN_ON(c, cond) \
149 struct channel *__chan; \
150 int _____ret = unlikely(cond); \
152 if (__same_type(*(c), struct channel_backend)) \
153 __chan = container_of((void *) (c), \
156 else if (__same_type(*(c), struct channel)) \
157 __chan = (void *) (c); \
160 atomic_inc(&__chan->record_disabled); \
166 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */