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/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 | */ | |
34 | enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH }; | |
35 | ||
852c2936 MD |
36 | /* channel: collection of per-cpu ring buffers. */ |
37 | struct channel { | |
14641deb | 38 | int record_disabled; |
852c2936 MD |
39 | unsigned long commit_count_mask; /* |
40 | * Commit count mask, removing | |
41 | * the MSBs corresponding to | |
42 | * bits used to represent the | |
43 | * subbuffer index. | |
44 | */ | |
45 | ||
852c2936 MD |
46 | unsigned long switch_timer_interval; /* Buffer flush (jiffies) */ |
47 | unsigned long read_timer_interval; /* Reader wakeup (jiffies) */ | |
14641deb | 48 | //wait_queue_head_t read_wait; /* reader wait queue */ |
852c2936 | 49 | int finalized; /* Has channel been finalized */ |
a3f61e7f | 50 | size_t priv_data_offset; |
de85e7c3 MD |
51 | /* |
52 | * Associated backend contains a variable-length array. Needs to | |
53 | * be last member. | |
54 | */ | |
55 | struct channel_backend backend; /* Associated backend */ | |
b728d87e | 56 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
57 | |
58 | /* Per-subbuffer commit counters used on the hot path */ | |
59 | struct commit_counters_hot { | |
60 | union v_atomic cc; /* Commit counter */ | |
61 | union v_atomic seq; /* Consecutive commits */ | |
b728d87e | 62 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
63 | |
64 | /* Per-subbuffer commit counters used only on cold paths */ | |
65 | struct commit_counters_cold { | |
66 | union v_atomic cc_sb; /* Incremented _once_ at sb switch */ | |
b728d87e | 67 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 | 68 | |
852c2936 | 69 | /* ring buffer state */ |
4cfec15c | 70 | struct lttng_ust_lib_ring_buffer { |
852c2936 MD |
71 | /* First 32 bytes cache-hot cacheline */ |
72 | union v_atomic offset; /* Current offset in the buffer */ | |
a6352fd4 | 73 | DECLARE_SHMP(struct commit_counters_hot, commit_hot); |
852c2936 | 74 | /* Commit count per sub-buffer */ |
14641deb | 75 | long consumed; /* |
852c2936 MD |
76 | * Current offset in the buffer |
77 | * standard atomic access (shared) | |
78 | */ | |
14641deb | 79 | int record_disabled; |
852c2936 MD |
80 | /* End of first 32 bytes cacheline */ |
81 | union v_atomic last_tsc; /* | |
82 | * Last timestamp written in the buffer. | |
83 | */ | |
84 | ||
4cfec15c | 85 | struct lttng_ust_lib_ring_buffer_backend backend; /* Associated backend */ |
852c2936 | 86 | |
a6352fd4 | 87 | DECLARE_SHMP(struct commit_counters_cold, commit_cold); |
852c2936 | 88 | /* Commit count per sub-buffer */ |
14641deb | 89 | long active_readers; /* |
852c2936 MD |
90 | * Active readers count |
91 | * standard atomic access (shared) | |
92 | */ | |
824f40b8 | 93 | long active_shadow_readers; |
852c2936 MD |
94 | /* Dropped records */ |
95 | union v_atomic records_lost_full; /* Buffer full */ | |
96 | union v_atomic records_lost_wrap; /* Nested wrap-around */ | |
97 | union v_atomic records_lost_big; /* Events too big */ | |
98 | union v_atomic records_count; /* Number of records written */ | |
99 | union v_atomic records_overrun; /* Number of overwritten records */ | |
14641deb | 100 | //wait_queue_head_t read_wait; /* reader buffer-level wait queue */ |
852c2936 | 101 | int finalized; /* buffer has been finalized */ |
14641deb MD |
102 | //struct timer_list switch_timer; /* timer for periodical switch */ |
103 | //struct timer_list read_timer; /* timer for read poll */ | |
852c2936 MD |
104 | unsigned long get_subbuf_consumed; /* Read-side consumed */ |
105 | unsigned long prod_snapshot; /* Producer count snapshot */ | |
106 | unsigned long cons_snapshot; /* Consumer count snapshot */ | |
7c2caf2b MD |
107 | unsigned int get_subbuf:1, /* Sub-buffer being held by reader */ |
108 | switch_timer_enabled:1, /* Protected by ring_buffer_nohz_lock */ | |
109 | read_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */ | |
5d61a504 | 110 | /* shmp pointer to self */ |
4cfec15c | 111 | DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self); |
b728d87e | 112 | } __attribute__((aligned(CAA_CACHE_LINE_SIZE))); |
852c2936 MD |
113 | |
114 | static inline | |
115 | void *channel_get_private(struct channel *chan) | |
116 | { | |
a3f61e7f | 117 | return ((char *) chan) + chan->priv_data_offset; |
852c2936 MD |
118 | } |
119 | ||
0d4aa2df MD |
120 | #ifndef __rb_same_type |
121 | #define __rb_same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) | |
122 | #endif | |
123 | ||
852c2936 MD |
124 | /* |
125 | * Issue warnings and disable channels upon internal error. | |
4cfec15c | 126 | * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend |
852c2936 MD |
127 | * parameters. |
128 | */ | |
129 | #define CHAN_WARN_ON(c, cond) \ | |
130 | ({ \ | |
131 | struct channel *__chan; \ | |
b5a3dfa5 | 132 | int _____ret = caa_unlikely(cond); \ |
852c2936 | 133 | if (_____ret) { \ |
0d4aa2df | 134 | if (__rb_same_type(*(c), struct channel_backend)) \ |
14641deb | 135 | __chan = caa_container_of((void *) (c), \ |
852c2936 MD |
136 | struct channel, \ |
137 | backend); \ | |
0d4aa2df | 138 | else if (__rb_same_type(*(c), struct channel)) \ |
852c2936 MD |
139 | __chan = (void *) (c); \ |
140 | else \ | |
141 | BUG_ON(1); \ | |
14641deb | 142 | uatomic_inc(&__chan->record_disabled); \ |
852c2936 MD |
143 | WARN_ON(1); \ |
144 | } \ | |
145 | _____ret; \ | |
146 | }) | |
147 | ||
148 | #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */ |