Port ring buffer to userspace, part 1
[lttng-ust.git] / libringbuffer / frontend_types.h
CommitLineData
852c2936
MD
1#ifndef _LINUX_RING_BUFFER_FRONTEND_TYPES_H
2#define _LINUX_RING_BUFFER_FRONTEND_TYPES_H
3
4/*
5 * linux/ringbuffer/frontend_types.h
6 *
7 * (C) Copyright 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Ring Buffer Library Synchronization Header (types).
10 *
11 * Author:
12 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 *
14 * See ring_buffer_frontend.c for more information on wait-free algorithms.
15 *
16 * Dual LGPL v2.1/GPL v2 license.
17 */
18
14641deb
MD
19#include <urcu/list.h>
20#include <urcu/uatomic.h>
21#include <urcu/ref.h>
22
23#include "ust/core.h"
24
25#include "usterr_signal_safe.h"
4931a13e
MD
26#include "config.h"
27#include "backend_types.h"
852c2936
MD
28
29/*
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).
32 */
33enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH };
34
852c2936
MD
35/* channel: collection of per-cpu ring buffers. */
36struct channel {
14641deb 37 int record_disabled;
852c2936
MD
38 unsigned long commit_count_mask; /*
39 * Commit count mask, removing
40 * the MSBs corresponding to
41 * bits used to represent the
42 * subbuffer index.
43 */
44
45 struct channel_backend backend; /* Associated backend */
46
47 unsigned long switch_timer_interval; /* Buffer flush (jiffies) */
48 unsigned long read_timer_interval; /* Reader wakeup (jiffies) */
14641deb 49 //wait_queue_head_t read_wait; /* reader wait queue */
852c2936 50 int finalized; /* Has channel been finalized */
14641deb 51 struct urcu_ref ref; /* Reference count */
852c2936
MD
52};
53
54/* Per-subbuffer commit counters used on the hot path */
55struct commit_counters_hot {
56 union v_atomic cc; /* Commit counter */
57 union v_atomic seq; /* Consecutive commits */
58};
59
60/* Per-subbuffer commit counters used only on cold paths */
61struct commit_counters_cold {
62 union v_atomic cc_sb; /* Incremented _once_ at sb switch */
63};
64
852c2936
MD
65/* ring buffer state */
66struct 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 */
14641deb 71 long consumed; /*
852c2936
MD
72 * Current offset in the buffer
73 * standard atomic access (shared)
74 */
14641deb 75 int record_disabled;
852c2936
MD
76 /* End of first 32 bytes cacheline */
77 union v_atomic last_tsc; /*
78 * Last timestamp written in the buffer.
79 */
80
81 struct lib_ring_buffer_backend backend; /* Associated backend */
82
83 struct commit_counters_cold *commit_cold;
84 /* Commit count per sub-buffer */
14641deb 85 long active_readers; /*
852c2936
MD
86 * Active readers count
87 * standard atomic access (shared)
88 */
89 /* Dropped records */
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 */
14641deb 95 //wait_queue_head_t read_wait; /* reader buffer-level wait queue */
852c2936 96 int finalized; /* buffer has been finalized */
14641deb
MD
97 //struct timer_list switch_timer; /* timer for periodical switch */
98 //struct timer_list read_timer; /* timer for read poll */
852c2936
MD
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 */
105};
106
107static inline
108void *channel_get_private(struct channel *chan)
109{
110 return chan->backend.priv;
111}
112
113/*
114 * Issue warnings and disable channels upon internal error.
115 * Can receive struct lib_ring_buffer or struct lib_ring_buffer_backend
116 * parameters.
117 */
118#define CHAN_WARN_ON(c, cond) \
119 ({ \
120 struct channel *__chan; \
121 int _____ret = unlikely(cond); \
122 if (_____ret) { \
123 if (__same_type(*(c), struct channel_backend)) \
14641deb 124 __chan = caa_container_of((void *) (c), \
852c2936
MD
125 struct channel, \
126 backend); \
127 else if (__same_type(*(c), struct channel)) \
128 __chan = (void *) (c); \
129 else \
130 BUG_ON(1); \
14641deb 131 uatomic_inc(&__chan->record_disabled); \
852c2936
MD
132 WARN_ON(1); \
133 } \
134 _____ret; \
135 })
136
137#endif /* _LINUX_RING_BUFFER_FRONTEND_TYPES_H */
This page took 0.035884 seconds and 4 git commands to generate.