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.
21 #include <urcu/list.h>
22 #include <urcu/uatomic.h>
26 #include "usterr_signal_safe.h"
28 #include "backend_types.h"
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).
35 enum switch_mode
{ SWITCH_ACTIVE
, SWITCH_FLUSH
};
37 /* channel: collection of per-cpu ring buffers. */
40 unsigned long commit_count_mask
; /*
41 * Commit count mask, removing
42 * the MSBs corresponding to
43 * bits used to represent the
47 struct channel_backend backend
; /* Associated backend */
49 unsigned long switch_timer_interval
; /* Buffer flush (jiffies) */
50 unsigned long read_timer_interval
; /* Reader wakeup (jiffies) */
51 //wait_queue_head_t read_wait; /* reader wait queue */
52 int finalized
; /* Has channel been finalized */
53 DECLARE_SHMP(struct shm_header
, shm_header
);
54 } ____cacheline_aligned
;
56 /* Per-subbuffer commit counters used on the hot path */
57 struct commit_counters_hot
{
58 union v_atomic cc
; /* Commit counter */
59 union v_atomic seq
; /* Consecutive commits */
60 } ____cacheline_aligned
;
62 /* Per-subbuffer commit counters used only on cold paths */
63 struct commit_counters_cold
{
64 union v_atomic cc_sb
; /* Incremented _once_ at sb switch */
65 } ____cacheline_aligned
;
67 /* ring buffer state */
68 struct lib_ring_buffer
{
69 /* First 32 bytes cache-hot cacheline */
70 union v_atomic offset
; /* Current offset in the buffer */
71 DECLARE_SHMP(struct commit_counters_hot
, commit_hot
);
72 /* Commit count per sub-buffer */
74 * Current offset in the buffer
75 * standard atomic access (shared)
78 /* End of first 32 bytes cacheline */
79 union v_atomic last_tsc
; /*
80 * Last timestamp written in the buffer.
83 struct lib_ring_buffer_backend backend
; /* Associated backend */
85 DECLARE_SHMP(struct commit_counters_cold
, commit_cold
);
86 /* Commit count per sub-buffer */
87 long active_readers
; /*
88 * Active readers count
89 * standard atomic access (shared)
92 union v_atomic records_lost_full
; /* Buffer full */
93 union v_atomic records_lost_wrap
; /* Nested wrap-around */
94 union v_atomic records_lost_big
; /* Events too big */
95 union v_atomic records_count
; /* Number of records written */
96 union v_atomic records_overrun
; /* Number of overwritten records */
97 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
98 int finalized
; /* buffer has been finalized */
99 //struct timer_list switch_timer; /* timer for periodical switch */
100 //struct timer_list read_timer; /* timer for read poll */
101 unsigned long get_subbuf_consumed
; /* Read-side consumed */
102 unsigned long prod_snapshot
; /* Producer count snapshot */
103 unsigned long cons_snapshot
; /* Consumer count snapshot */
104 int get_subbuf
:1; /* Sub-buffer being held by reader */
105 int switch_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
106 int read_timer_enabled
:1; /* Protected by ring_buffer_nohz_lock */
107 } ____cacheline_aligned
;
110 void *channel_get_private(struct channel
*chan
)
112 return chan
->backend
.priv
;
116 * Issue warnings and disable channels upon internal error.
117 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
120 #define CHAN_WARN_ON(c, cond) \
122 struct channel *__chan; \
123 int _____ret = unlikely(cond); \
125 if (__same_type(*(c), struct channel_backend)) \
126 __chan = caa_container_of((void *) (c), \
129 else if (__same_type(*(c), struct channel)) \
130 __chan = (void *) (c); \
133 uatomic_inc(&__chan->record_disabled); \
139 #endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */