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