1 #ifndef _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
2 #define _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
5 * libringbuffer/frontend_types.h
7 * Ring Buffer Library Synchronization Header (types).
9 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
26 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
28 * See ring_buffer_frontend.c for more information on wait-free algorithms.
33 #include <urcu/list.h>
34 #include <urcu/uatomic.h>
36 #include <lttng/ringbuffer-config.h>
37 #include <usterr-signal-safe.h>
38 #include "backend_types.h"
39 #include "shm_internal.h"
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).
46 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
48 /* channel: collection of per-cpu ring buffers. */
49 #define RB_CHANNEL_PADDING 64
52 unsigned long commit_count_mask
; /*
53 * Commit count mask, removing
54 * the MSBs corresponding to
55 * bits used to represent the
59 unsigned long switch_timer_interval
; /* Buffer flush (jiffies) */
60 unsigned long read_timer_interval
; /* Reader wakeup (jiffies) */
61 //wait_queue_head_t read_wait; /* reader wait queue */
62 int finalized
; /* Has channel been finalized */
63 size_t priv_data_offset
;
65 * Associated backend contains a variable-length array. Needs to
68 struct channel_backend backend
; /* Associated backend */
69 char padding
[RB_CHANNEL_PADDING
];
70 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
72 /* Per-subbuffer commit counters used on the hot path */
73 #define RB_COMMIT_COUNT_HOT_PADDING 16
74 struct commit_counters_hot
{
75 union v_atomic cc
; /* Commit counter */
76 union v_atomic seq
; /* Consecutive commits */
77 char padding
[RB_COMMIT_COUNT_HOT_PADDING
];
78 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
80 /* Per-subbuffer commit counters used only on cold paths */
81 #define RB_COMMIT_COUNT_COLD_PADDING 24
82 struct commit_counters_cold
{
83 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
84 char padding
[RB_COMMIT_COUNT_COLD_PADDING
];
85 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
87 /* ring buffer state */
88 #define RB_RING_BUFFER_PADDING 64
89 struct lttng_ust_lib_ring_buffer
{
90 /* First 32 bytes cache-hot cacheline */
91 union v_atomic offset
; /* Current offset in the buffer */
92 DECLARE_SHMP(struct commit_counters_hot
, commit_hot
);
93 /* Commit count per sub-buffer */
95 * Current offset in the buffer
96 * standard atomic access (shared)
99 /* End of first 32 bytes cacheline */
100 union v_atomic last_tsc
; /*
101 * Last timestamp written in the buffer.
104 struct lttng_ust_lib_ring_buffer_backend backend
; /* Associated backend */
106 DECLARE_SHMP(struct commit_counters_cold
, commit_cold
);
107 /* Commit count per sub-buffer */
108 long active_readers
; /*
109 * Active readers count
110 * standard atomic access (shared)
112 long active_shadow_readers
;
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 */
119 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
120 int finalized
; /* buffer has been finalized */
121 //struct timer_list switch_timer; /* timer for periodical switch */
122 //struct timer_list read_timer; /* timer for read poll */
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 */
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 */
129 /* shmp pointer to self */
130 DECLARE_SHMP(struct lttng_ust_lib_ring_buffer
, self
);
131 char padding
[RB_RING_BUFFER_PADDING
];
132 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
135 void *channel_get_private(struct channel
*chan
)
137 return ((char *) chan
) + chan
->priv_data_offset
;
140 #ifndef __rb_same_type
141 #define __rb_same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
145 * Issue warnings and disable channels upon internal error.
146 * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend
149 #define CHAN_WARN_ON(c, cond) \
151 struct channel *__chan; \
152 int _____ret = caa_unlikely(cond); \
154 if (__rb_same_type(*(c), struct channel_backend)) \
155 __chan = caa_container_of((void *) (c), \
158 else if (__rb_same_type(*(c), struct channel)) \
159 __chan = (void *) (c); \
162 uatomic_inc(&__chan->record_disabled); \
168 #endif /* _LTTNG_RING_BUFFER_FRONTEND_TYPES_H */