Fix: ensure all probe providers have their symbols
[lttng-ust.git] / libringbuffer / frontend_types.h
CommitLineData
e92f3e28
MD
1#ifndef _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
2#define _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
852c2936
MD
3
4/*
e92f3e28 5 * libringbuffer/frontend_types.h
852c2936
MD
6 *
7 * Ring Buffer Library Synchronization Header (types).
8 *
e92f3e28
MD
9 * Copyright (C) 2005-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 *
852c2936
MD
25 * Author:
26 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
27 *
28 * See ring_buffer_frontend.c for more information on wait-free algorithms.
852c2936
MD
29 */
30
a6352fd4
MD
31#include <string.h>
32
14641deb
MD
33#include <urcu/list.h>
34#include <urcu/uatomic.h>
14641deb 35
4318ae1b 36#include <lttng/ringbuffer-config.h>
44c72f10 37#include <usterr-signal-safe.h>
4931a13e 38#include "backend_types.h"
1d498196 39#include "shm_internal.h"
a3bb4b27 40#include "vatomic.h"
852c2936
MD
41
42/*
43 * A switch is done during tracing or as a final flush after tracing (so it
44 * won't write in the new sub-buffer).
45 */
46enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH };
47
852c2936 48/* channel: collection of per-cpu ring buffers. */
74d81a6c 49#define RB_CHANNEL_PADDING 32
852c2936 50struct channel {
14641deb 51 int record_disabled;
852c2936
MD
52 unsigned long commit_count_mask; /*
53 * Commit count mask, removing
54 * the MSBs corresponding to
55 * bits used to represent the
56 * subbuffer index.
57 */
58
852c2936
MD
59 unsigned long switch_timer_interval; /* Buffer flush (jiffies) */
60 unsigned long read_timer_interval; /* Reader wakeup (jiffies) */
14641deb 61 //wait_queue_head_t read_wait; /* reader wait queue */
852c2936 62 int finalized; /* Has channel been finalized */
a3f61e7f 63 size_t priv_data_offset;
74d81a6c
MD
64 unsigned int nr_streams; /* Number of streams */
65 char padding[RB_CHANNEL_PADDING];
de85e7c3
MD
66 /*
67 * Associated backend contains a variable-length array. Needs to
68 * be last member.
69 */
70 struct channel_backend backend; /* Associated backend */
b728d87e 71} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
852c2936
MD
72
73/* Per-subbuffer commit counters used on the hot path */
3c8964ba 74#define RB_COMMIT_COUNT_HOT_PADDING 16
852c2936
MD
75struct commit_counters_hot {
76 union v_atomic cc; /* Commit counter */
77 union v_atomic seq; /* Consecutive commits */
3c8964ba 78 char padding[RB_COMMIT_COUNT_HOT_PADDING];
b728d87e 79} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
852c2936
MD
80
81/* Per-subbuffer commit counters used only on cold paths */
3c8964ba 82#define RB_COMMIT_COUNT_COLD_PADDING 24
852c2936
MD
83struct commit_counters_cold {
84 union v_atomic cc_sb; /* Incremented _once_ at sb switch */
3c8964ba 85 char padding[RB_COMMIT_COUNT_COLD_PADDING];
b728d87e 86} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
852c2936 87
852c2936 88/* ring buffer state */
3c8964ba 89#define RB_RING_BUFFER_PADDING 64
4cfec15c 90struct lttng_ust_lib_ring_buffer {
852c2936
MD
91 /* First 32 bytes cache-hot cacheline */
92 union v_atomic offset; /* Current offset in the buffer */
a6352fd4 93 DECLARE_SHMP(struct commit_counters_hot, commit_hot);
852c2936 94 /* Commit count per sub-buffer */
14641deb 95 long consumed; /*
852c2936
MD
96 * Current offset in the buffer
97 * standard atomic access (shared)
98 */
14641deb 99 int record_disabled;
852c2936
MD
100 /* End of first 32 bytes cacheline */
101 union v_atomic last_tsc; /*
102 * Last timestamp written in the buffer.
103 */
104
4cfec15c 105 struct lttng_ust_lib_ring_buffer_backend backend; /* Associated backend */
852c2936 106
a6352fd4 107 DECLARE_SHMP(struct commit_counters_cold, commit_cold);
852c2936 108 /* Commit count per sub-buffer */
14641deb 109 long active_readers; /*
852c2936
MD
110 * Active readers count
111 * standard atomic access (shared)
112 */
113 /* Dropped records */
114 union v_atomic records_lost_full; /* Buffer full */
115 union v_atomic records_lost_wrap; /* Nested wrap-around */
116 union v_atomic records_lost_big; /* Events too big */
117 union v_atomic records_count; /* Number of records written */
118 union v_atomic records_overrun; /* Number of overwritten records */
14641deb 119 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
852c2936 120 int finalized; /* buffer has been finalized */
14641deb
MD
121 //struct timer_list switch_timer; /* timer for periodical switch */
122 //struct timer_list read_timer; /* timer for read poll */
852c2936
MD
123 unsigned long get_subbuf_consumed; /* Read-side consumed */
124 unsigned long prod_snapshot; /* Producer count snapshot */
125 unsigned long cons_snapshot; /* Consumer count snapshot */
7c2caf2b
MD
126 unsigned int get_subbuf:1, /* Sub-buffer being held by reader */
127 switch_timer_enabled:1, /* Protected by ring_buffer_nohz_lock */
128 read_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */
5d61a504 129 /* shmp pointer to self */
4cfec15c 130 DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self);
3c8964ba 131 char padding[RB_RING_BUFFER_PADDING];
b728d87e 132} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
852c2936
MD
133
134static inline
135void *channel_get_private(struct channel *chan)
136{
a3f61e7f 137 return ((char *) chan) + chan->priv_data_offset;
852c2936
MD
138}
139
0d4aa2df
MD
140#ifndef __rb_same_type
141#define __rb_same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
142#endif
143
852c2936
MD
144/*
145 * Issue warnings and disable channels upon internal error.
4cfec15c 146 * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend
852c2936
MD
147 * parameters.
148 */
149#define CHAN_WARN_ON(c, cond) \
150 ({ \
151 struct channel *__chan; \
b5a3dfa5 152 int _____ret = caa_unlikely(cond); \
852c2936 153 if (_____ret) { \
0d4aa2df 154 if (__rb_same_type(*(c), struct channel_backend)) \
14641deb 155 __chan = caa_container_of((void *) (c), \
852c2936
MD
156 struct channel, \
157 backend); \
0d4aa2df 158 else if (__rb_same_type(*(c), struct channel)) \
852c2936
MD
159 __chan = (void *) (c); \
160 else \
161 BUG_ON(1); \
14641deb 162 uatomic_inc(&__chan->record_disabled); \
852c2936
MD
163 WARN_ON(1); \
164 } \
165 _____ret; \
166 })
167
e92f3e28 168#endif /* _LTTNG_RING_BUFFER_FRONTEND_TYPES_H */
This page took 0.032248 seconds and 4 git commands to generate.