~ubuntu-branches/ubuntu/wily/ust/wily-proposed

« back to all changes in this revision

Viewing changes to libringbuffer/frontend_types.h

  • Committer: Package Import Robot
  • Author(s): Jon Bernard
  • Date: 2012-06-29 16:47:49 UTC
  • mto: (11.2.1 sid) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20120629164749-mcca8f7w9ovcktj2
Tags: upstream-2.0.4
ImportĀ upstreamĀ versionĀ 2.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
 
2
#define _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
 
3
 
 
4
/*
 
5
 * libringbuffer/frontend_types.h
 
6
 *
 
7
 * Ring Buffer Library Synchronization Header (types).
 
8
 *
 
9
 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 
10
 *
 
11
 * This library is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU Lesser General Public
 
13
 * License as published by the Free Software Foundation; only
 
14
 * version 2.1 of the License.
 
15
 *
 
16
 * This library is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
19
 * Lesser General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU Lesser General Public
 
22
 * License along with this library; if not, write to the Free Software
 
23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
24
 *
 
25
 * Author:
 
26
 *      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 
27
 *
 
28
 * See ring_buffer_frontend.c for more information on wait-free algorithms.
 
29
 */
 
30
 
 
31
#include <string.h>
 
32
 
 
33
#include <urcu/list.h>
 
34
#include <urcu/uatomic.h>
 
35
 
 
36
#include <lttng/ringbuffer-config.h>
 
37
#include <usterr-signal-safe.h>
 
38
#include "backend_types.h"
 
39
#include "shm_internal.h"
 
40
#include "vatomic.h"
 
41
 
 
42
/*
 
43
 * A switch is done during tracing or as a final flush after tracing (so it
 
44
 * won't write in the new sub-buffer).
 
45
 */
 
46
enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH };
 
47
 
 
48
/* channel: collection of per-cpu ring buffers. */
 
49
struct channel {
 
50
        int record_disabled;
 
51
        unsigned long commit_count_mask;        /*
 
52
                                                 * Commit count mask, removing
 
53
                                                 * the MSBs corresponding to
 
54
                                                 * bits used to represent the
 
55
                                                 * subbuffer index.
 
56
                                                 */
 
57
 
 
58
        unsigned long switch_timer_interval;    /* Buffer flush (jiffies) */
 
59
        unsigned long read_timer_interval;      /* Reader wakeup (jiffies) */
 
60
        //wait_queue_head_t read_wait;          /* reader wait queue */
 
61
        int finalized;                          /* Has channel been finalized */
 
62
        size_t priv_data_offset;
 
63
        /* Note: padding field is missing */
 
64
        /*
 
65
         * Associated backend contains a variable-length array. Needs to
 
66
         * be last member.
 
67
         */
 
68
        struct channel_backend backend;         /* Associated backend */
 
69
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
70
 
 
71
/* Per-subbuffer commit counters used on the hot path */
 
72
#define RB_COMMIT_COUNT_HOT_PADDING     16
 
73
struct commit_counters_hot {
 
74
        union v_atomic cc;              /* Commit counter */
 
75
        union v_atomic seq;             /* Consecutive commits */
 
76
        char padding[RB_COMMIT_COUNT_HOT_PADDING];
 
77
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
78
 
 
79
/* Per-subbuffer commit counters used only on cold paths */
 
80
#define RB_COMMIT_COUNT_COLD_PADDING    24
 
81
struct commit_counters_cold {
 
82
        union v_atomic cc_sb;           /* Incremented _once_ at sb switch */
 
83
        char padding[RB_COMMIT_COUNT_COLD_PADDING];
 
84
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
85
 
 
86
/* ring buffer state */
 
87
#define RB_RING_BUFFER_PADDING          64
 
88
struct lttng_ust_lib_ring_buffer {
 
89
        /* First 32 bytes cache-hot cacheline */
 
90
        union v_atomic offset;          /* Current offset in the buffer */
 
91
        DECLARE_SHMP(struct commit_counters_hot, commit_hot);
 
92
                                        /* Commit count per sub-buffer */
 
93
        long consumed;                  /*
 
94
                                         * Current offset in the buffer
 
95
                                         * standard atomic access (shared)
 
96
                                         */
 
97
        int record_disabled;
 
98
        /* End of first 32 bytes cacheline */
 
99
        union v_atomic last_tsc;        /*
 
100
                                         * Last timestamp written in the buffer.
 
101
                                         */
 
102
 
 
103
        struct lttng_ust_lib_ring_buffer_backend backend;       /* Associated backend */
 
104
 
 
105
        DECLARE_SHMP(struct commit_counters_cold, commit_cold);
 
106
                                        /* Commit count per sub-buffer */
 
107
        long active_readers;            /*
 
108
                                         * Active readers count
 
109
                                         * standard atomic access (shared)
 
110
                                         */
 
111
        long active_shadow_readers;
 
112
                                        /* Dropped records */
 
113
        union v_atomic records_lost_full;       /* Buffer full */
 
114
        union v_atomic records_lost_wrap;       /* Nested wrap-around */
 
115
        union v_atomic records_lost_big;        /* Events too big */
 
116
        union v_atomic records_count;   /* Number of records written */
 
117
        union v_atomic records_overrun; /* Number of overwritten records */
 
118
        //wait_queue_head_t read_wait;  /* reader buffer-level wait queue */
 
119
        int finalized;                  /* buffer has been finalized */
 
120
        //struct timer_list switch_timer;       /* timer for periodical switch */
 
121
        //struct timer_list read_timer; /* timer for read poll */
 
122
        unsigned long get_subbuf_consumed;      /* Read-side consumed */
 
123
        unsigned long prod_snapshot;    /* Producer count snapshot */
 
124
        unsigned long cons_snapshot;    /* Consumer count snapshot */
 
125
        unsigned int get_subbuf:1,      /* Sub-buffer being held by reader */
 
126
                switch_timer_enabled:1, /* Protected by ring_buffer_nohz_lock */
 
127
                read_timer_enabled:1;   /* Protected by ring_buffer_nohz_lock */
 
128
        /* shmp pointer to self */
 
129
        DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self);
 
130
        char padding[RB_RING_BUFFER_PADDING];
 
131
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
 
132
 
 
133
static inline
 
134
void *channel_get_private(struct channel *chan)
 
135
{
 
136
        return ((char *) chan) + chan->priv_data_offset;
 
137
}
 
138
 
 
139
#ifndef __rb_same_type
 
140
#define __rb_same_type(a, b)    __builtin_types_compatible_p(typeof(a), typeof(b))
 
141
#endif
 
142
 
 
143
/*
 
144
 * Issue warnings and disable channels upon internal error.
 
145
 * Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend
 
146
 * parameters.
 
147
 */
 
148
#define CHAN_WARN_ON(c, cond)                                           \
 
149
        ({                                                              \
 
150
                struct channel *__chan;                                 \
 
151
                int _____ret = caa_unlikely(cond);                              \
 
152
                if (_____ret) {                                         \
 
153
                        if (__rb_same_type(*(c), struct channel_backend))       \
 
154
                                __chan = caa_container_of((void *) (c), \
 
155
                                                        struct channel, \
 
156
                                                        backend);       \
 
157
                        else if (__rb_same_type(*(c), struct channel))  \
 
158
                                __chan = (void *) (c);                  \
 
159
                        else                                            \
 
160
                                BUG_ON(1);                              \
 
161
                        uatomic_inc(&__chan->record_disabled);          \
 
162
                        WARN_ON(1);                                     \
 
163
                }                                                       \
 
164
                _____ret;                                               \
 
165
        })
 
166
 
 
167
#endif /* _LTTNG_RING_BUFFER_FRONTEND_TYPES_H */