|
Packit |
c04fcb |
#ifndef _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
|
|
Packit |
c04fcb |
#define _LTTNG_RING_BUFFER_FRONTEND_TYPES_H
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* libringbuffer/frontend_types.h
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* Ring Buffer Library Synchronization Header (types).
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* This library is free software; you can redistribute it and/or
|
|
Packit |
c04fcb |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
c04fcb |
* License as published by the Free Software Foundation; only
|
|
Packit |
c04fcb |
* version 2.1 of the License.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
c04fcb |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
c04fcb |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
c04fcb |
* Lesser General Public License for more details.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
c04fcb |
* License along with this library; if not, write to the Free Software
|
|
Packit |
c04fcb |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* Author:
|
|
Packit |
c04fcb |
* Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* See ring_buffer_frontend.c for more information on wait-free algorithms.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#include <string.h>
|
|
Packit |
c04fcb |
#include <time.h> /* for timer_t */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#include <urcu/list.h>
|
|
Packit |
c04fcb |
#include <urcu/uatomic.h>
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#include <lttng/ringbuffer-config.h>
|
|
Packit |
c04fcb |
#include <usterr-signal-safe.h>
|
|
Packit |
c04fcb |
#include "backend_types.h"
|
|
Packit |
c04fcb |
#include "shm_internal.h"
|
|
Packit |
c04fcb |
#include "shm_types.h"
|
|
Packit |
c04fcb |
#include "vatomic.h"
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* A switch is done during tracing or as a final flush after tracing (so it
|
|
Packit |
c04fcb |
* won't write in the new sub-buffer).
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
enum switch_mode { SWITCH_ACTIVE, SWITCH_FLUSH };
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* channel: collection of per-cpu ring buffers. */
|
|
Packit |
c04fcb |
#define RB_CHANNEL_PADDING 32
|
|
Packit |
c04fcb |
struct channel {
|
|
Packit |
c04fcb |
int record_disabled;
|
|
Packit |
c04fcb |
unsigned long commit_count_mask; /*
|
|
Packit |
c04fcb |
* Commit count mask, removing
|
|
Packit |
c04fcb |
* the MSBs corresponding to
|
|
Packit |
c04fcb |
* bits used to represent the
|
|
Packit |
c04fcb |
* subbuffer index.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
unsigned long switch_timer_interval; /* Buffer flush (us) */
|
|
Packit |
c04fcb |
timer_t switch_timer;
|
|
Packit |
c04fcb |
int switch_timer_enabled;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
unsigned long read_timer_interval; /* Reader wakeup (us) */
|
|
Packit |
c04fcb |
timer_t read_timer;
|
|
Packit |
c04fcb |
int read_timer_enabled;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
int finalized; /* Has channel been finalized */
|
|
Packit |
c04fcb |
size_t priv_data_offset;
|
|
Packit |
c04fcb |
unsigned int nr_streams; /* Number of streams */
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle;
|
|
Packit |
c04fcb |
char padding[RB_CHANNEL_PADDING];
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Associated backend contains a variable-length array. Needs to
|
|
Packit |
c04fcb |
* be last member.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
struct channel_backend backend; /* Associated backend */
|
|
Packit |
c04fcb |
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* Per-subbuffer commit counters used on the hot path */
|
|
Packit |
c04fcb |
#define RB_COMMIT_COUNT_HOT_PADDING 16
|
|
Packit |
c04fcb |
struct commit_counters_hot {
|
|
Packit |
c04fcb |
union v_atomic cc; /* Commit counter */
|
|
Packit |
c04fcb |
union v_atomic seq; /* Consecutive commits */
|
|
Packit |
c04fcb |
char padding[RB_COMMIT_COUNT_HOT_PADDING];
|
|
Packit |
c04fcb |
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* Per-subbuffer commit counters used only on cold paths */
|
|
Packit |
c04fcb |
#define RB_COMMIT_COUNT_COLD_PADDING 24
|
|
Packit |
c04fcb |
struct commit_counters_cold {
|
|
Packit |
c04fcb |
union v_atomic cc_sb; /* Incremented _once_ at sb switch */
|
|
Packit |
c04fcb |
char padding[RB_COMMIT_COUNT_COLD_PADDING];
|
|
Packit |
c04fcb |
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* ring buffer state */
|
|
Packit |
c04fcb |
#define RB_CRASH_DUMP_ABI_LEN 256
|
|
Packit |
c04fcb |
#define RB_RING_BUFFER_PADDING 60
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#define RB_CRASH_DUMP_ABI_MAGIC_LEN 16
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* The 128-bit magic number is xor'd in the process data so it does not
|
|
Packit |
c04fcb |
* cause a false positive when searching for buffers by scanning memory.
|
|
Packit |
c04fcb |
* The actual magic number is:
|
|
Packit |
c04fcb |
* 0x17, 0x7B, 0xF1, 0x77, 0xBF, 0x17, 0x7B, 0xF1,
|
|
Packit |
c04fcb |
* 0x77, 0xBF, 0x17, 0x7B, 0xF1, 0x77, 0xBF, 0x17,
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
#define RB_CRASH_DUMP_ABI_MAGIC_XOR \
|
|
Packit |
c04fcb |
{ \
|
|
Packit |
c04fcb |
0x17 ^ 0xFF, 0x7B ^ 0xFF, 0xF1 ^ 0xFF, 0x77 ^ 0xFF, \
|
|
Packit |
c04fcb |
0xBF ^ 0xFF, 0x17 ^ 0xFF, 0x7B ^ 0xFF, 0xF1 ^ 0xFF, \
|
|
Packit |
c04fcb |
0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, 0x7B ^ 0xFF, \
|
|
Packit |
c04fcb |
0xF1 ^ 0xFF, 0x77 ^ 0xFF, 0xBF ^ 0xFF, 0x17 ^ 0xFF, \
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#define RB_CRASH_ENDIAN 0x1234
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#define RB_CRASH_DUMP_ABI_MAJOR 0
|
|
Packit |
c04fcb |
#define RB_CRASH_DUMP_ABI_MINOR 0
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
enum lttng_crash_type {
|
|
Packit |
c04fcb |
LTTNG_CRASH_TYPE_UST = 0,
|
|
Packit |
c04fcb |
LTTNG_CRASH_TYPE_KERNEL = 1,
|
|
Packit |
c04fcb |
};
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
struct lttng_crash_abi {
|
|
Packit |
c04fcb |
uint8_t magic[RB_CRASH_DUMP_ABI_MAGIC_LEN];
|
|
Packit |
c04fcb |
uint64_t mmap_length; /* Overall lenght of crash record */
|
|
Packit |
c04fcb |
uint16_t endian; /*
|
|
Packit |
c04fcb |
* { 0x12, 0x34 }: big endian
|
|
Packit |
c04fcb |
* { 0x34, 0x12 }: little endian
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
uint16_t major; /* Major number. */
|
|
Packit |
c04fcb |
uint16_t minor; /* Minor number. */
|
|
Packit |
c04fcb |
uint8_t word_size; /* Word size (bytes). */
|
|
Packit |
c04fcb |
uint8_t layout_type; /* enum lttng_crash_type */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
struct {
|
|
Packit |
c04fcb |
uint32_t prod_offset;
|
|
Packit |
c04fcb |
uint32_t consumed_offset;
|
|
Packit |
c04fcb |
uint32_t commit_hot_array;
|
|
Packit |
c04fcb |
uint32_t commit_hot_seq;
|
|
Packit |
c04fcb |
uint32_t buf_wsb_array;
|
|
Packit |
c04fcb |
uint32_t buf_wsb_id;
|
|
Packit |
c04fcb |
uint32_t sb_array;
|
|
Packit |
c04fcb |
uint32_t sb_array_shmp_offset;
|
|
Packit |
c04fcb |
uint32_t sb_backend_p_offset;
|
|
Packit |
c04fcb |
uint32_t content_size;
|
|
Packit |
c04fcb |
uint32_t packet_size;
|
|
Packit |
c04fcb |
} __attribute__((packed)) offset;
|
|
Packit |
c04fcb |
struct {
|
|
Packit |
c04fcb |
uint8_t prod_offset;
|
|
Packit |
c04fcb |
uint8_t consumed_offset;
|
|
Packit |
c04fcb |
uint8_t commit_hot_seq;
|
|
Packit |
c04fcb |
uint8_t buf_wsb_id;
|
|
Packit |
c04fcb |
uint8_t sb_array_shmp_offset;
|
|
Packit |
c04fcb |
uint8_t sb_backend_p_offset;
|
|
Packit |
c04fcb |
uint8_t content_size;
|
|
Packit |
c04fcb |
uint8_t packet_size;
|
|
Packit |
c04fcb |
} __attribute__((packed)) length;
|
|
Packit |
c04fcb |
struct {
|
|
Packit |
c04fcb |
uint32_t commit_hot_array;
|
|
Packit |
c04fcb |
uint32_t buf_wsb_array;
|
|
Packit |
c04fcb |
uint32_t sb_array;
|
|
Packit |
c04fcb |
} __attribute__((packed)) stride;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
uint64_t buf_size; /* Size of the buffer */
|
|
Packit |
c04fcb |
uint64_t subbuf_size; /* Sub-buffer size */
|
|
Packit |
c04fcb |
uint64_t num_subbuf; /* Number of sub-buffers for writer */
|
|
Packit |
c04fcb |
uint32_t mode; /* Buffer mode: 0: overwrite, 1: discard */
|
|
Packit |
c04fcb |
} __attribute__((packed));
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer {
|
|
Packit |
c04fcb |
/* First 32 bytes are for the buffer crash dump ABI */
|
|
Packit |
c04fcb |
struct lttng_crash_abi crash_abi;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* 32 bytes cache-hot cacheline */
|
|
Packit |
c04fcb |
union v_atomic __attribute__((aligned(32))) offset;
|
|
Packit |
c04fcb |
/* Current offset in the buffer */
|
|
Packit |
c04fcb |
DECLARE_SHMP(struct commit_counters_hot, commit_hot);
|
|
Packit |
c04fcb |
/* Commit count per sub-buffer */
|
|
Packit |
c04fcb |
long consumed; /*
|
|
Packit |
c04fcb |
* Current offset in the buffer
|
|
Packit |
c04fcb |
* standard atomic access (shared)
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
int record_disabled;
|
|
Packit |
c04fcb |
/* End of cache-hot 32 bytes cacheline */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
union v_atomic last_tsc; /*
|
|
Packit |
c04fcb |
* Last timestamp written in the buffer.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer_backend backend;
|
|
Packit |
c04fcb |
/* Associated backend */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
DECLARE_SHMP(struct commit_counters_cold, commit_cold);
|
|
Packit |
c04fcb |
/* Commit count per sub-buffer */
|
|
Packit |
c04fcb |
long active_readers; /*
|
|
Packit |
c04fcb |
* Active readers count
|
|
Packit |
c04fcb |
* standard atomic access (shared)
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
/* Dropped records */
|
|
Packit |
c04fcb |
union v_atomic records_lost_full; /* Buffer full */
|
|
Packit |
c04fcb |
union v_atomic records_lost_wrap; /* Nested wrap-around */
|
|
Packit |
c04fcb |
union v_atomic records_lost_big; /* Events too big */
|
|
Packit |
c04fcb |
union v_atomic records_count; /* Number of records written */
|
|
Packit |
c04fcb |
union v_atomic records_overrun; /* Number of overwritten records */
|
|
Packit |
c04fcb |
//wait_queue_head_t read_wait; /* reader buffer-level wait queue */
|
|
Packit |
c04fcb |
int finalized; /* buffer has been finalized */
|
|
Packit |
c04fcb |
unsigned long get_subbuf_consumed; /* Read-side consumed */
|
|
Packit |
c04fcb |
unsigned long prod_snapshot; /* Producer count snapshot */
|
|
Packit |
c04fcb |
unsigned long cons_snapshot; /* Consumer count snapshot */
|
|
Packit |
c04fcb |
unsigned int get_subbuf:1; /* Sub-buffer being held by reader */
|
|
Packit |
c04fcb |
/* shmp pointer to self */
|
|
Packit |
c04fcb |
DECLARE_SHMP(struct lttng_ust_lib_ring_buffer, self);
|
|
Packit |
c04fcb |
char padding[RB_RING_BUFFER_PADDING];
|
|
Packit |
c04fcb |
} __attribute__((aligned(CAA_CACHE_LINE_SIZE)));
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
void *channel_get_private(struct channel *chan)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return ((char *) chan) + chan->priv_data_offset;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#ifndef __rb_same_type
|
|
Packit |
c04fcb |
#define __rb_same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
|
Packit |
c04fcb |
#endif
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Issue warnings and disable channels upon internal error.
|
|
Packit |
c04fcb |
* Can receive struct lttng_ust_lib_ring_buffer or struct lttng_ust_lib_ring_buffer_backend
|
|
Packit |
c04fcb |
* parameters.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
#define CHAN_WARN_ON(c, cond) \
|
|
Packit |
c04fcb |
({ \
|
|
Packit |
c04fcb |
struct channel *__chan; \
|
|
Packit |
c04fcb |
int _____ret = caa_unlikely(cond); \
|
|
Packit |
c04fcb |
if (_____ret) { \
|
|
Packit |
c04fcb |
if (__rb_same_type(*(c), struct channel_backend)) \
|
|
Packit |
c04fcb |
__chan = caa_container_of((void *) (c), \
|
|
Packit |
c04fcb |
struct channel, \
|
|
Packit |
c04fcb |
backend); \
|
|
Packit |
c04fcb |
else if (__rb_same_type(*(c), struct channel)) \
|
|
Packit |
c04fcb |
__chan = (void *) (c); \
|
|
Packit |
c04fcb |
else \
|
|
Packit |
c04fcb |
BUG_ON(1); \
|
|
Packit |
c04fcb |
uatomic_inc(&__chan->record_disabled); \
|
|
Packit |
c04fcb |
WARN_ON(1); \
|
|
Packit |
c04fcb |
} \
|
|
Packit |
c04fcb |
_____ret = _____ret; /* For clang "unused result". */ \
|
|
Packit |
c04fcb |
})
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#endif /* _LTTNG_RING_BUFFER_FRONTEND_TYPES_H */
|