Fix: wrapper random documentation
[lttng-modules.git] / lib / ringbuffer / frontend_types.h
1 /* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only)
2 *
3 * lib/ringbuffer/frontend_types.h
4 *
5 * Ring Buffer Library Synchronization Header (types).
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * See ring_buffer_frontend.c for more information on wait-free algorithms.
10 */
11
12 #ifndef _LIB_RING_BUFFER_FRONTEND_TYPES_H
13 #define _LIB_RING_BUFFER_FRONTEND_TYPES_H
14
15 #include <linux/kref.h>
16 #include <wrapper/ringbuffer/config.h>
17 #include <wrapper/ringbuffer/backend_types.h>
18 #include <lib/prio_heap/lttng_prio_heap.h> /* For per-CPU read-side iterator */
19 #include <lttng-cpuhotplug.h>
20
21 /*
22 * A switch is done during tracing or as a final flush after tracing (so it
23 * won't write in the new sub-buffer).
24 */
25 enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH };
26
27 /* channel-level read-side iterator */
28 struct channel_iter {
29 /* Prio heap of buffers. Lowest timestamps at the top. */
30 struct lttng_ptr_heap heap; /* Heap of struct lib_ring_buffer ptrs */
31 struct list_head empty_head; /* Empty buffers linked-list head */
32 int read_open; /* Opened for reading ? */
33 u64 last_qs; /* Last quiescent state timestamp */
34 u64 last_timestamp; /* Last timestamp (for WARN_ON) */
35 int last_cpu; /* Last timestamp cpu */
36 /*
37 * read() file operation state.
38 */
39 unsigned long len_left;
40 };
41
42 /* channel: collection of per-cpu ring buffers. */
43 struct channel {
44 atomic_t record_disabled;
45 unsigned long commit_count_mask; /*
46 * Commit count mask, removing
47 * the MSBs corresponding to
48 * bits used to represent the
49 * subbuffer index.
50 */
51
52 struct channel_backend backend; /* Associated backend */
53
54 unsigned long switch_timer_interval; /* Buffer flush (jiffies) */
55 unsigned long read_timer_interval; /* Reader wakeup (jiffies) */
56 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
57 struct lttng_cpuhp_node cpuhp_prepare;
58 struct lttng_cpuhp_node cpuhp_online;
59 struct lttng_cpuhp_node cpuhp_iter_online;
60 #else
61 struct notifier_block cpu_hp_notifier; /* CPU hotplug notifier */
62 struct notifier_block hp_iter_notifier; /* hotplug iterator notifier */
63 unsigned int cpu_hp_enable:1; /* Enable CPU hotplug notif. */
64 unsigned int hp_iter_enable:1; /* Enable hp iter notif. */
65 #endif
66 struct notifier_block tick_nohz_notifier; /* CPU nohz notifier */
67 wait_queue_head_t read_wait; /* reader wait queue */
68 wait_queue_head_t hp_wait; /* CPU hotplug wait queue */
69 int finalized; /* Has channel been finalized */
70 struct channel_iter iter; /* Channel read-side iterator */
71 struct kref ref; /* Reference count */
72 };
73
74 /* Per-subbuffer commit counters used on the hot path */
75 struct commit_counters_hot {
76 union v_atomic cc; /* Commit counter */
77 union v_atomic seq; /* Consecutive commits */
78 };
79
80 /* Per-subbuffer commit counters used only on cold paths */
81 struct commit_counters_cold {
82 union v_atomic cc_sb; /* Incremented _once_ at sb switch */
83 };
84
85 /* Per-buffer read iterator */
86 struct lib_ring_buffer_iter {
87 u64 timestamp; /* Current record timestamp */
88 size_t header_len; /* Current record header length */
89 size_t payload_len; /* Current record payload length */
90
91 struct list_head empty_node; /* Linked list of empty buffers */
92 unsigned long consumed, read_offset, data_size;
93 enum {
94 ITER_GET_SUBBUF = 0,
95 ITER_TEST_RECORD,
96 ITER_NEXT_RECORD,
97 ITER_PUT_SUBBUF,
98 } state;
99 unsigned int allocated:1;
100 unsigned int read_open:1; /* Opened for reading ? */
101 };
102
103 /* ring buffer state */
104 struct lib_ring_buffer {
105 /* First 32 bytes cache-hot cacheline */
106 union v_atomic offset; /* Current offset in the buffer */
107 struct commit_counters_hot *commit_hot;
108 /* Commit count per sub-buffer */
109 atomic_long_t consumed; /*
110 * Current offset in the buffer
111 * standard atomic access (shared)
112 */
113 atomic_t record_disabled;
114 /* End of first 32 bytes cacheline */
115 union v_atomic last_tsc; /*
116 * Last timestamp written in the buffer.
117 */
118
119 struct lib_ring_buffer_backend backend; /* Associated backend */
120
121 struct commit_counters_cold *commit_cold;
122 /* Commit count per sub-buffer */
123 u64 *ts_end; /*
124 * timestamp_end per sub-buffer.
125 * Time is sampled by the
126 * switch_*_end() callbacks which
127 * are the last space reservation
128 * performed in the sub-buffer
129 * before it can be fully
130 * committed and delivered. This
131 * time value is then read by
132 * the deliver callback,
133 * performed by the last commit
134 * before the buffer becomes
135 * readable.
136 */
137 atomic_long_t active_readers; /*
138 * Active readers count
139 * standard atomic access (shared)
140 */
141 /* Dropped records */
142 union v_atomic records_lost_full; /* Buffer full */
143 union v_atomic records_lost_wrap; /* Nested wrap-around */
144 union v_atomic records_lost_big; /* Events too big */
145 union v_atomic records_count; /* Number of records written */
146 union v_atomic records_overrun; /* Number of overwritten records */
147 wait_queue_head_t read_wait; /* reader buffer-level wait queue */
148 wait_queue_head_t write_wait; /* writer buffer-level wait queue (for metadata only) */
149 int finalized; /* buffer has been finalized */
150 struct timer_list switch_timer; /* timer for periodical switch */
151 struct timer_list read_timer; /* timer for read poll */
152 raw_spinlock_t raw_tick_nohz_spinlock; /* nohz entry lock/trylock */
153 struct lib_ring_buffer_iter iter; /* read-side iterator */
154 unsigned long get_subbuf_consumed; /* Read-side consumed */
155 unsigned long prod_snapshot; /* Producer count snapshot */
156 unsigned long cons_snapshot; /* Consumer count snapshot */
157 unsigned int get_subbuf:1, /* Sub-buffer being held by reader */
158 switch_timer_enabled:1, /* Protected by ring_buffer_nohz_lock */
159 read_timer_enabled:1, /* Protected by ring_buffer_nohz_lock */
160 quiescent:1;
161 };
162
163 static inline
164 void *channel_get_private(struct channel *chan)
165 {
166 return chan->backend.priv;
167 }
168
169 void lib_ring_buffer_lost_event_too_big(struct channel *chan);
170
171 /*
172 * Issue warnings and disable channels upon internal error.
173 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
174 * parameters.
175 */
176 #define CHAN_WARN_ON(c, cond) \
177 ({ \
178 struct channel *__chan; \
179 int _____ret = unlikely(cond); \
180 if (_____ret) { \
181 if (__same_type(*(c), struct channel_backend)) \
182 __chan = container_of((void *) (c), \
183 struct channel, \
184 backend); \
185 else if (__same_type(*(c), struct channel)) \
186 __chan = (void *) (c); \
187 else \
188 BUG_ON(1); \
189 atomic_inc(&__chan->record_disabled); \
190 WARN_ON(1); \
191 } \
192 _____ret; \
193 })
194
195 #endif /* _LIB_RING_BUFFER_FRONTEND_TYPES_H */
This page took 0.032687 seconds and 4 git commands to generate.