1 #ifndef _LINUX_RING_BUFFER_FRONTEND_TYPES_H
2 #define _LINUX_RING_BUFFER_FRONTEND_TYPES_H
5 * linux/ringbuffer/frontend_types.h
7 * (C) Copyright 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Ring Buffer Library Synchronization Header (types).
12 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 * See ring_buffer_frontend.c for more information on wait-free algorithms.
16 * Dual LGPL v2.1/GPL v2 license.
19 #include <linux/kref.h>
20 #include "../../wrapper/ringbuffer/config.h"
21 #include "../../wrapper/ringbuffer/backend_types.h"
22 #include "../../lib/prio_heap/lttng_prio_heap.h" /* For per-CPU read-side iterator */
25 * A switch is done during tracing or as a final flush after tracing (so it
26 * won't write in the new sub-buffer).
28 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
30 /* channel-level read-side iterator */
32 /* Prio heap of buffers. Lowest timestamps at the top. */
33 struct lttng_ptr_heap heap
; /* Heap of struct lib_ring_buffer ptrs */
34 struct list_head empty_head
; /* Empty buffers linked-list head */
35 int read_open
; /* Opened for reading ? */
36 u64 last_qs
; /* Last quiescent state timestamp */
37 u64 last_timestamp
; /* Last timestamp (for WARN_ON) */
38 int last_cpu
; /* Last timestamp cpu */
40 * read() file operation state.
42 unsigned long len_left
;
45 /* channel: collection of per-cpu ring buffers. */
47 atomic_t record_disabled
;
48 unsigned long commit_count_mask
; /*
49 * Commit count mask, removing
50 * the MSBs corresponding to
51 * bits used to represent the
55 struct channel_backend backend
; /* Associated backend */
57 unsigned long switch_timer_interval
; /* Buffer flush (jiffies) */
58 unsigned long read_timer_interval
; /* Reader wakeup (jiffies) */
59 struct notifier_block cpu_hp_notifier
; /* CPU hotplug notifier */
60 struct notifier_block tick_nohz_notifier
; /* CPU nohz notifier */
61 struct notifier_block hp_iter_notifier
; /* hotplug iterator notifier */
62 int cpu_hp_enable
:1; /* Enable CPU hotplug notif. */
63 int hp_iter_enable
:1; /* Enable hp iter notif. */
64 wait_queue_head_t read_wait
; /* reader wait queue */
65 wait_queue_head_t hp_wait
; /* CPU hotplug wait queue */
66 int finalized
; /* Has channel been finalized */
67 struct channel_iter iter
; /* Channel read-side iterator */
68 struct kref ref
; /* Reference count */
71 /* Per-subbuffer commit counters used on the hot path */
72 struct commit_counters_hot
{
73 union v_atomic cc
; /* Commit counter */
74 union v_atomic seq
; /* Consecutive commits */
77 /* Per-subbuffer commit counters used only on cold paths */
78 struct commit_counters_cold
{
79 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
82 /* Per-buffer read iterator */
83 struct lib_ring_buffer_iter
{
84 u64 timestamp
; /* Current record timestamp */
85 size_t header_len
; /* Current record header length */
86 size_t payload_len
; /* Current record payload length */
88 struct list_head empty_node
; /* Linked list of empty buffers */
89 unsigned long consumed
, read_offset
, data_size
;
97 int read_open
:1; /* Opened for reading ? */
100 /* ring buffer state */
101 struct lib_ring_buffer
{
102 /* First 32 bytes cache-hot cacheline */
103 union v_atomic offset
; /* Current offset in the buffer */
104 struct commit_counters_hot
*commit_hot
;
105 /* Commit count per sub-buffer */
106 atomic_long_t consumed
; /*
107 * Current offset in the buffer
108 * standard atomic access (shared)
110 atomic_t record_disabled
;
111 /* End of first 32 bytes cacheline */
112 union v_atomic last_tsc
; /*
113 * Last timestamp written in the buffer.
116 struct lib_ring_buffer_backend backend
; /* Associated backend */
118 struct commit_counters_cold
*commit_cold
;
119 /* Commit count per sub-buffer */
120 atomic_long_t active_readers
; /*
121 * Active readers count
122 * standard atomic access (shared)
124 /* Dropped records */
125 union v_atomic records_lost_full
; /* Buffer full */
126 union v_atomic records_lost_wrap
; /* Nested wrap-around */
127 union v_atomic records_lost_big
; /* Events too big */
128 union v_atomic records_count
; /* Number of records written */
129 union v_atomic records_overrun
; /* Number of overwritten records */
130 wait_queue_head_t read_wait
; /* reader buffer-level wait queue */
131 int finalized
; /* buffer has been finalized */
132 struct timer_list switch_timer
; /* timer for periodical switch */
133 struct timer_list read_timer
; /* timer for read poll */
134 raw_spinlock_t raw_tick_nohz_spinlock
; /* nohz entry lock/trylock */
135 struct lib_ring_buffer_iter iter
; /* read-side iterator */
136 unsigned long get_subbuf_consumed
; /* Read-side consumed */
137 unsigned long prod_snapshot
; /* Producer count snapshot */
138 unsigned long cons_snapshot
; /* Consumer count snapshot */
139 int get_subbuf
:1; /* Sub-buffer being held by reader */
140 int switch_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
141 int read_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
145 void *channel_get_private(struct channel
*chan
)
147 return chan
->backend
.priv
;
151 * Issue warnings and disable channels upon internal error.
152 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
155 #define CHAN_WARN_ON(c, cond) \
157 struct channel *__chan; \
158 int _____ret = unlikely(cond); \
160 if (__same_type(*(c), struct channel_backend)) \
161 __chan = container_of((void *) (c), \
164 else if (__same_type(*(c), struct channel)) \
165 __chan = (void *) (c); \
168 atomic_inc(&__chan->record_disabled); \
174 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */