Commit | Line | Data |
---|---|---|
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/core.h" |
14641deb | 25 | |
4318ae1b MD |
26 | #include <lttng/usterr-signal-safe.h> |
27 | #include <lttng/ringbuffer-config.h> | |
4931a13e | 28 | #include "backend_types.h" |
1d498196 | 29 | #include "shm_internal.h" |
852c2936 MD |
30 | |
31 | /* | |
32 | * A switch is done during tracing or as a final flush after tracing (so it | |
33 | * won't write in the new sub-buffer). | |
34 | */ | |
35 | enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH }; | |
36 | ||
852c2936 MD |
37 | /* channel: collection of per-cpu ring buffers. */ |
38 | struct 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 */ | |
b728d87e | 57 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
58 | |
59 | /* Per-subbuffer commit counters used on the hot path */ | |
60 | struct commit_counters_hot { | |
61 | union v_atomic cc; /* Commit counter */ | |
62 | union v_atomic seq; /* Consecutive commits */ | |
b728d87e | 63 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
64 | |
65 | /* Per-subbuffer commit counters used only on cold paths */ | |
66 | struct commit_counters_cold { | |
67 | union v_atomic cc_sb; /* Incremented _once_ at sb switch */ | |
b728d87e | 68 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 | 69 | |
852c2936 | 70 | /* ring buffer state */ |
4cfec15c | 71 | struct lttng_ust_lib_ring_buffer { |
852c2936 MD |
72 | /* First 32 bytes cache-hot cacheline */ |
73 | union v_atomic offset; /* Current offset in the buffer */ | |
a6352fd4 | 74 | DECLARE_SHMP(struct commit_counters_hot, commit_hot); |
852c2936 | 75 | /* Commit count per sub-buffer */ |
14641deb | 76 | long consumed; /* |
852c2936 MD |
77 | * Current offset in the buffer |
78 | * standard atomic access (shared) | |
79 | */ | |
14641deb | 80 | int record_disabled; |
852c2936 MD |
81 | /* End of first 32 bytes cacheline */ |
82 | union v_atomic last_tsc; /* | |
83 | * Last timestamp written in the buffer. | |
84 | */ | |
85 | ||
4cfec15c | 86 | struct lttng_ust_lib_ring_buffer_backend backend; /* Associated backend */ |
852c2936 | 87 | |
a6352fd4 | 88 | DECLARE_SHMP(struct commit_counters_cold, commit_cold); |
852c2936 | 89 | /* Commit count per sub-buffer */ |
14641deb | 90 | long active_readers; /* |
852c2936 MD |
91 | * Active readers count |
92 | * standard atomic access (shared) | |
93 | */ | |
824f40b8 | 94 | long active_shadow_readers; |
852c2936 MD |
95 | /* Dropped records */ |
96 | union v_atomic records_lost_full; /* Buffer full */ | |
97 | union v_atomic records_lost_wrap; /* Nested wrap-around */ | |
98 | union v_atomic records_lost_big; /* Events too big */ | |
99 | union v_atomic records_count; /* Number of records written */ | |
100 | union v_atomic records_overrun; /* Number of overwritten records */ | |
14641deb | 101 | //wait_queue_head_t read_wait; /* reader buffer-level wait queue */ |
852c2936 | 102 | int finalized; /* buffer has been finalized */ |
14641deb MD |
103 | //struct timer_list switch_timer; /* timer for periodical switch */ |
104 | //struct timer_list read_timer; /* timer for read poll */ | |
852c2936 MD |
105 | unsigned long get_subbuf_consumed; /* Read-side consumed */ |
106 | unsigned long prod_snapshot; /* Producer count snapshot */ | |
107 | unsigned long cons_snapshot; /* Consumer count snapshot */ | |
108 | int get_subbuf:1; /* Sub-buffer being held by reader */ | |
109 | int switch_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */ | |
110 | int read_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */ | |
5d61a504 | 111 | /* shmp pointer to self */ |
4cfec15c | 112 | DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self); |
b728d87e | 113 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
114 | |
115 | static inline | |
116 | void *channel_get_private(struct channel *chan) | |
117 | { | |
a3f61e7f | 118 | return ((char *) chan) + chan->priv_data_offset; |
852c2936 MD |
119 | } |
120 | ||
121 | /* | |
122 | * Issue warnings and disable channels upon internal error. | |
4cfec15c | 123 | * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend |
852c2936 MD |
124 | * parameters. |
125 | */ | |
126 | #define CHAN_WARN_ON(c, cond) \ | |
127 | ({ \ | |
128 | struct channel *__chan; \ | |
b5a3dfa5 | 129 | int _____ret = caa_unlikely(cond); \ |
852c2936 MD |
130 | if (_____ret) { \ |
131 | if (__same_type(*(c), struct channel_backend)) \ | |
14641deb | 132 | __chan = caa_container_of((void *) (c), \ |
852c2936 MD |
133 | struct channel, \ |
134 | backend); \ | |
135 | else if (__same_type(*(c), struct channel)) \ | |
136 | __chan = (void *) (c); \ | |
137 | else \ | |
138 | BUG_ON(1); \ | |
14641deb | 139 | uatomic_inc(&__chan->record_disabled); \ |
852c2936 MD |
140 | WARN_ON(1); \ |
141 | } \ | |
142 | _____ret; \ | |
143 | }) | |
144 | ||
145 | #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */ |