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