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.
20 #include "backend_types.h"
21 #include "../lib_prio_heap/lttng_prio_heap.h" /* For per-CPU read-side iterator */
24 * A switch is done during tracing or as a final flush after tracing (so it
25 * won't write in the new sub-buffer).
27 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
29 /* channel-level read-side iterator */
31 /* Prio heap of buffers. Lowest timestamps at the top. */
32 struct lttng_ptr_heap heap
; /* Heap of struct lib_ring_buffer ptrs */
33 struct list_head empty_head
; /* Empty buffers linked-list head */
34 int read_open
; /* Opened for reading ? */
35 u64 last_qs
; /* Last quiescent state timestamp */
36 u64 last_timestamp
; /* Last timestamp (for WARN_ON) */
37 int last_cpu
; /* Last timestamp cpu */
39 * read() file operation state.
41 unsigned long len_left
;
44 /* channel: collection of per-cpu ring buffers. */
46 atomic_t record_disabled
;
47 unsigned long commit_count_mask
; /*
48 * Commit count mask, removing
49 * the MSBs corresponding to
50 * bits used to represent the
54 struct channel_backend backend
; /* Associated backend */
56 unsigned long switch_timer_interval
; /* Buffer flush (jiffies) */
57 unsigned long read_timer_interval
; /* Reader wakeup (jiffies) */
58 struct notifier_block cpu_hp_notifier
; /* CPU hotplug notifier */
59 struct notifier_block tick_nohz_notifier
; /* CPU nohz notifier */
60 struct notifier_block hp_iter_notifier
; /* hotplug iterator notifier */
61 int cpu_hp_enable
:1; /* Enable CPU hotplug notif. */
62 int hp_iter_enable
:1; /* Enable hp iter notif. */
63 wait_queue_head_t read_wait
; /* reader wait queue */
64 wait_queue_head_t hp_wait
; /* CPU hotplug wait queue */
65 int finalized
; /* Has channel been finalized */
66 struct channel_iter iter
; /* Channel read-side iterator */
67 struct kref ref
; /* Reference count */
70 /* Per-subbuffer commit counters used on the hot path */
71 struct commit_counters_hot
{
72 union v_atomic cc
; /* Commit counter */
73 union v_atomic seq
; /* Consecutive commits */
76 /* Per-subbuffer commit counters used only on cold paths */
77 struct commit_counters_cold
{
78 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
81 /* Per-buffer read iterator */
82 struct lib_ring_buffer_iter
{
83 u64 timestamp
; /* Current record timestamp */
84 size_t header_len
; /* Current record header length */
85 size_t payload_len
; /* Current record payload length */
87 struct list_head empty_node
; /* Linked list of empty buffers */
88 unsigned long consumed
, read_offset
, data_size
;
96 int read_open
:1; /* Opened for reading ? */
99 /* ring buffer state */
100 struct lib_ring_buffer
{
101 /* First 32 bytes cache-hot cacheline */
102 union v_atomic offset
; /* Current offset in the buffer */
103 struct commit_counters_hot
*commit_hot
;
104 /* Commit count per sub-buffer */
105 atomic_long_t consumed
; /*
106 * Current offset in the buffer
107 * standard atomic access (shared)
109 atomic_t record_disabled
;
110 /* End of first 32 bytes cacheline */
111 union v_atomic last_tsc
; /*
112 * Last timestamp written in the buffer.
115 struct lib_ring_buffer_backend backend
; /* Associated backend */
117 struct commit_counters_cold
*commit_cold
;
118 /* Commit count per sub-buffer */
119 atomic_long_t active_readers
; /*
120 * Active readers count
121 * standard atomic access (shared)
123 /* Dropped records */
124 union v_atomic records_lost_full
; /* Buffer full */
125 union v_atomic records_lost_wrap
; /* Nested wrap-around */
126 union v_atomic records_lost_big
; /* Events too big */
127 union v_atomic records_count
; /* Number of records written */
128 union v_atomic records_overrun
; /* Number of overwritten records */
129 wait_queue_head_t read_wait
; /* reader buffer-level wait queue */
130 int finalized
; /* buffer has been finalized */
131 struct timer_list switch_timer
; /* timer for periodical switch */
132 struct timer_list read_timer
; /* timer for read poll */
133 raw_spinlock_t raw_tick_nohz_spinlock
; /* nohz entry lock/trylock */
134 struct lib_ring_buffer_iter iter
; /* read-side iterator */
135 unsigned long get_subbuf_consumed
; /* Read-side consumed */
136 unsigned long prod_snapshot
; /* Producer count snapshot */
137 unsigned long cons_snapshot
; /* Consumer count snapshot */
138 int get_subbuf
:1; /* Sub-buffer being held by reader */
139 int switch_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
140 int read_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
144 void *channel_get_private(struct channel
*chan
)
146 return chan
->backend
.priv
;
150 * Issue warnings and disable channels upon internal error.
151 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
154 #define CHAN_WARN_ON(c, cond) \
156 struct channel *__chan; \
157 int _____ret = unlikely(cond); \
159 if (__same_type(*(c), struct channel_backend)) \
160 __chan = container_of((void *) (c), \
163 else if (__same_type(*(c), struct channel)) \
164 __chan = (void *) (c); \
167 atomic_inc(&__chan->record_disabled); \
173 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */