Update to use caa_likely/caa_unlikely from urcu 0.6.6
[lttng-ust.git] / libringbuffer / frontend_types.h
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
19 #include <string.h>
20
21 #include <urcu/list.h>
22 #include <urcu/uatomic.h>
23
24 #include "ust/core.h"
25
26 #include <ust/usterr-signal-safe.h>
27 #include <ust/ringbuffer-config.h>
28 #include "backend_types.h"
29 #include "shm_internal.h"
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
37 /* channel: collection of per-cpu ring buffers. */
38 struct channel {
39 int record_disabled;
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
47 unsigned long switch_timer_interval; /* Buffer flush (jiffies) */
48 unsigned long read_timer_interval; /* Reader wakeup (jiffies) */
49 //wait_queue_head_t read_wait; /* reader wait queue */
50 int finalized; /* Has channel been finalized */
51 /*
52 * Associated backend contains a variable-length array. Needs to
53 * be last member.
54 */
55 struct channel_backend backend; /* Associated backend */
56 } ____cacheline_aligned;
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 */
62 } ____cacheline_aligned;
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 */
67 } ____cacheline_aligned;
68
69 /* ring buffer state */
70 struct lttng_ust_lib_ring_buffer {
71 /* First 32 bytes cache-hot cacheline */
72 union v_atomic offset; /* Current offset in the buffer */
73 DECLARE_SHMP(struct commit_counters_hot, commit_hot);
74 /* Commit count per sub-buffer */
75 long consumed; /*
76 * Current offset in the buffer
77 * standard atomic access (shared)
78 */
79 int record_disabled;
80 /* End of first 32 bytes cacheline */
81 union v_atomic last_tsc; /*
82 * Last timestamp written in the buffer.
83 */
84
85 struct lttng_ust_lib_ring_buffer_backend backend; /* Associated backend */
86
87 DECLARE_SHMP(struct commit_counters_cold, commit_cold);
88 /* Commit count per sub-buffer */
89 long active_readers; /*
90 * Active readers count
91 * standard atomic access (shared)
92 */
93 long active_shadow_readers;
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 */
100 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
101 int finalized; /* buffer has been finalized */
102 //struct timer_list switch_timer; /* timer for periodical switch */
103 //struct timer_list read_timer; /* timer for read poll */
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 */
107 int get_subbuf:1; /* Sub-buffer being held by reader */
108 int switch_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */
109 int read_timer_enabled:1; /* Protected by ring_buffer_nohz_lock */
110 /* shmp pointer to self */
111 DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self);
112 } ____cacheline_aligned;
113
114 static inline
115 void *channel_get_private(struct channel *chan)
116 {
117 return chan->backend.priv;
118 }
119
120 /*
121 * Issue warnings and disable channels upon internal error.
122 * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend
123 * parameters.
124 */
125 #define CHAN_WARN_ON(c, cond) \
126 ({ \
127 struct channel *__chan; \
128 int _____ret = caa_unlikely(cond); \
129 if (_____ret) { \
130 if (__same_type(*(c), struct channel_backend)) \
131 __chan = caa_container_of((void *) (c), \
132 struct channel, \
133 backend); \
134 else if (__same_type(*(c), struct channel)) \
135 __chan = (void *) (c); \
136 else \
137 BUG_ON(1); \
138 uatomic_inc(&__chan->record_disabled); \
139 WARN_ON(1); \
140 } \
141 _____ret; \
142 })
143
144 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */
This page took 0.03336 seconds and 5 git commands to generate.