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 <urcu/list.h>
20 #include <urcu/uatomic.h>
25 #include "usterr_signal_safe.h"
27 #include "backend_types.h"
30 * A switch is done during tracing or as a final flush after tracing (so it
31 * won't write in the new sub-buffer).
33 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
35 /* channel: collection of per-cpu ring buffers. */
38 unsigned long commit_count_mask
; /*
39 * Commit count mask, removing
40 * the MSBs corresponding to
41 * bits used to represent the
45 struct channel_backend backend
; /* Associated backend */
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 struct urcu_ref ref
; /* Reference count */
54 /* Per-subbuffer commit counters used on the hot path */
55 struct commit_counters_hot
{
56 union v_atomic cc
; /* Commit counter */
57 union v_atomic seq
; /* Consecutive commits */
60 /* Per-subbuffer commit counters used only on cold paths */
61 struct commit_counters_cold
{
62 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
65 /* ring buffer state */
66 struct lib_ring_buffer
{
67 /* First 32 bytes cache-hot cacheline */
68 union v_atomic offset
; /* Current offset in the buffer */
69 struct commit_counters_hot
*commit_hot
;
70 /* Commit count per sub-buffer */
72 * Current offset in the buffer
73 * standard atomic access (shared)
76 /* End of first 32 bytes cacheline */
77 union v_atomic last_tsc
; /*
78 * Last timestamp written in the buffer.
81 struct lib_ring_buffer_backend backend
; /* Associated backend */
83 struct commit_counters_cold
*commit_cold
;
84 /* Commit count per sub-buffer */
85 long active_readers
; /*
86 * Active readers count
87 * standard atomic access (shared)
90 union v_atomic records_lost_full
; /* Buffer full */
91 union v_atomic records_lost_wrap
; /* Nested wrap-around */
92 union v_atomic records_lost_big
; /* Events too big */
93 union v_atomic records_count
; /* Number of records written */
94 union v_atomic records_overrun
; /* Number of overwritten records */
95 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
96 int finalized
; /* buffer has been finalized */
97 //struct timer_list switch_timer; /* timer for periodical switch */
98 //struct timer_list read_timer; /* timer for read poll */
99 unsigned long get_subbuf_consumed
; /* Read-side consumed */
100 unsigned long prod_snapshot
; /* Producer count snapshot */
101 unsigned long cons_snapshot
; /* Consumer count snapshot */
102 int get_subbuf
:1; /* Sub-buffer being held by reader */
103 int switch_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
104 int read_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
108 void *channel_get_private(struct channel
*chan
)
110 return chan
->backend
.priv
;
114 * Issue warnings and disable channels upon internal error.
115 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
118 #define CHAN_WARN_ON(c, cond) \
120 struct channel *__chan; \
121 int _____ret = unlikely(cond); \
123 if (__same_type(*(c), struct channel_backend)) \
124 __chan = caa_container_of((void *) (c), \
127 else if (__same_type(*(c), struct channel)) \
128 __chan = (void *) (c); \
131 uatomic_inc(&__chan->record_disabled); \
137 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */