|
Packit |
c04fcb |
#ifndef _LTTNG_RING_BUFFER_FRONTEND_H
|
|
Packit |
c04fcb |
#define _LTTNG_RING_BUFFER_FRONTEND_H
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* libringbuffer/frontend.h
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* Ring Buffer Library Synchronization Header (API).
|
|
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 |
*
|
|
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 <urcu/compiler.h>
|
|
Packit |
c04fcb |
#include <urcu/uatomic.h>
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#include "smp.h"
|
|
Packit |
c04fcb |
/* Internal helpers */
|
|
Packit |
c04fcb |
#include "frontend_internal.h"
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* Buffer creation/removal and setup operations */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* switch_timer_interval is the time interval (in us) to fill sub-buffers with
|
|
Packit |
c04fcb |
* padding to let readers get those sub-buffers. Used for live streaming.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* read_timer_interval is the time interval (in us) to wake up pending readers.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* buf_addr is a pointer the the beginning of the preallocated buffer contiguous
|
|
Packit |
c04fcb |
* address mapping. It is used only by RING_BUFFER_STATIC configuration. It can
|
|
Packit |
c04fcb |
* be set to NULL for other backends.
|
|
Packit |
c04fcb |
*
|
|
Packit |
c04fcb |
* priv_data (output) is set to a pointer into a "priv_data_len"-sized
|
|
Packit |
c04fcb |
* memory area for client-specific data. This memory is managed by lib
|
|
Packit |
c04fcb |
* ring buffer. priv_data_align is the alignment required for the
|
|
Packit |
c04fcb |
* private data area.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
const char *name,
|
|
Packit |
c04fcb |
void **priv_data,
|
|
Packit |
c04fcb |
size_t priv_data_align,
|
|
Packit |
c04fcb |
size_t priv_data_size,
|
|
Packit |
c04fcb |
void *priv_data_init,
|
|
Packit |
c04fcb |
void *buf_addr,
|
|
Packit |
c04fcb |
size_t subbuf_size, size_t num_subbuf,
|
|
Packit |
c04fcb |
unsigned int switch_timer_interval,
|
|
Packit |
c04fcb |
unsigned int read_timer_interval,
|
|
Packit |
c04fcb |
const int *stream_fds, int nr_stream_fds);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* channel_destroy finalizes all channel's buffers, waits for readers to
|
|
Packit |
c04fcb |
* release all references, and destroys the channel.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
void channel_destroy(struct channel *chan, struct lttng_ust_shm_handle *handle,
|
|
Packit |
c04fcb |
int consumer);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/* Buffer read operations */
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Iteration on channel cpumask needs to issue a read barrier to match the write
|
|
Packit |
c04fcb |
* barrier in cpu hotplug. It orders the cpumask read before read of per-cpu
|
|
Packit |
c04fcb |
* buffer data. The per-cpu buffer is never removed by cpu hotplug; teardown is
|
|
Packit |
c04fcb |
* only performed at channel destruction.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
#define for_each_channel_cpu(cpu, chan) \
|
|
Packit |
c04fcb |
for_each_possible_cpu(cpu)
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
extern struct lttng_ust_lib_ring_buffer *channel_get_ring_buffer(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct channel *chan, int cpu,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle,
|
|
Packit |
c04fcb |
int *shm_fd, int *wait_fd,
|
|
Packit |
c04fcb |
int *wakeup_fd,
|
|
Packit |
c04fcb |
uint64_t *memory_map_size);
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
int ring_buffer_channel_close_wait_fd(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct channel *chan,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
int ring_buffer_channel_close_wakeup_fd(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct channel *chan,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
int ring_buffer_stream_close_wait_fd(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct channel *chan,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle,
|
|
Packit |
c04fcb |
int cpu);
|
|
Packit |
c04fcb |
extern
|
|
Packit |
c04fcb |
int ring_buffer_stream_close_wakeup_fd(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct channel *chan,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle,
|
|
Packit |
c04fcb |
int cpu);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
extern int lib_ring_buffer_open_read(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
extern void lib_ring_buffer_release_read(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Initialize signals for ring buffer. Should be called early e.g. by
|
|
Packit |
c04fcb |
* main() in the program to affect all threads.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
void lib_ringbuffer_signal_init(void);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Read sequence: snapshot, many get_subbuf/put_subbuf, move_consumer.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
extern int lib_ring_buffer_snapshot(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
unsigned long *consumed,
|
|
Packit |
c04fcb |
unsigned long *produced,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
extern void lib_ring_buffer_move_consumer(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
unsigned long consumed_new,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
extern int lib_ring_buffer_get_subbuf(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
unsigned long consumed,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
extern void lib_ring_buffer_put_subbuf(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* lib_ring_buffer_get_next_subbuf/lib_ring_buffer_put_next_subbuf are helpers
|
|
Packit |
c04fcb |
* to read sub-buffers sequentially.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
static inline int lib_ring_buffer_get_next_subbuf(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
int ret;
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
ret = lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
|
|
Packit |
c04fcb |
&buf->prod_snapshot, handle);
|
|
Packit |
c04fcb |
if (ret)
|
|
Packit |
c04fcb |
return ret;
|
|
Packit |
c04fcb |
ret = lib_ring_buffer_get_subbuf(buf, buf->cons_snapshot, handle);
|
|
Packit |
c04fcb |
return ret;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
void lib_ring_buffer_put_next_subbuf(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
lib_ring_buffer_put_subbuf(buf, handle);
|
|
Packit |
c04fcb |
lib_ring_buffer_move_consumer(buf, subbuf_align(buf->cons_snapshot,
|
|
Packit |
c04fcb |
shmp(handle, buf->backend.chan)), handle);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
extern void channel_reset(struct channel *chan);
|
|
Packit |
c04fcb |
extern void lib_ring_buffer_reset(struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle);
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_offset(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->offset);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_consumed(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return uatomic_read(&buf->consumed);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Must call lib_ring_buffer_is_finalized before reading counters (memory
|
|
Packit |
c04fcb |
* ordering enforced with respect to trace teardown).
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
int lib_ring_buffer_is_finalized(const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
int finalized = CMM_ACCESS_ONCE(buf->finalized);
|
|
Packit |
c04fcb |
/*
|
|
Packit |
c04fcb |
* Read finalized before counters.
|
|
Packit |
c04fcb |
*/
|
|
Packit |
c04fcb |
cmm_smp_rmb();
|
|
Packit |
c04fcb |
return finalized;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
int lib_ring_buffer_channel_is_finalized(const struct channel *chan)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return chan->finalized;
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
int lib_ring_buffer_channel_is_disabled(const struct channel *chan)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return uatomic_read(&chan->record_disabled);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_read_data_size(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf,
|
|
Packit |
c04fcb |
struct lttng_ust_shm_handle *handle)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return subbuffer_get_read_data_size(config, &buf->backend, handle);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_count(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->records_count);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_overrun(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->records_overrun);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_lost_full(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->records_lost_full);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_lost_wrap(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->records_lost_wrap);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_lost_big(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->records_lost_big);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
static inline
|
|
Packit |
c04fcb |
unsigned long lib_ring_buffer_get_records_read(
|
|
Packit |
c04fcb |
const struct lttng_ust_lib_ring_buffer_config *config,
|
|
Packit |
c04fcb |
struct lttng_ust_lib_ring_buffer *buf)
|
|
Packit |
c04fcb |
{
|
|
Packit |
c04fcb |
return v_read(config, &buf->backend.records_read);
|
|
Packit |
c04fcb |
}
|
|
Packit |
c04fcb |
|
|
Packit |
c04fcb |
#endif /* _LTTNG_RING_BUFFER_FRONTEND_H */
|