From: Mathieu Desnoyers Date: Wed, 17 Mar 2021 18:18:28 +0000 (-0400) Subject: Add missing ringbuffer-context.h X-Git-Tag: v2.13.0-rc1~261 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=0f3a182fa713ddeb6dad104e8f0ee187f8edf529;p=lttng-ust.git Add missing ringbuffer-context.h Signed-off-by: Mathieu Desnoyers Change-Id: I3dcf5b2c12c88570b9089b187d7e560af26e96af --- diff --git a/include/lttng/ringbuffer-context.h b/include/lttng/ringbuffer-context.h new file mode 100644 index 00000000..614150da --- /dev/null +++ b/include/lttng/ringbuffer-context.h @@ -0,0 +1,162 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2010-2021 Mathieu Desnoyers + * + * Ring buffer context header. + */ + +#ifndef _LTTNG_RING_BUFFER_CONTEXT_H +#define _LTTNG_RING_BUFFER_CONTEXT_H + +#include +#include +#include +#include +#include +#include +#include +#include + +struct lttng_ust_lib_ring_buffer; +struct lttng_ust_lib_ring_buffer_channel; +struct lttng_ust_lib_ring_buffer_ctx; +struct lttng_ust_shm_handle; + +/* + * ring buffer context + * + * Context passed to lib_ring_buffer_reserve(), lib_ring_buffer_commit(), + * lib_ring_buffer_try_discard_reserve(), lib_ring_buffer_align_ctx() and + * lib_ring_buffer_write(). + * + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Fields need to be only added at the end, never reordered, never + * removed. + * + * The field @struct_size should be used to determine the size of the + * structure. It should be queried before using additional fields added + * at the end of the structure. + */ +struct lttng_ust_lib_ring_buffer_ctx { + uint32_t struct_size; /* Size of this structure. */ + + /* input received by lib_ring_buffer_reserve(), saved here. */ + struct lttng_ust_lib_ring_buffer_channel *chan; /* channel */ + void *priv; /* client private data */ + struct lttng_ust_shm_handle *handle; /* shared-memory handle */ + size_t data_size; /* size of payload */ + int largest_align; /* + * alignment of the largest element + * in the payload + */ + int cpu; /* processor id */ + + /* output from lib_ring_buffer_reserve() */ + struct lttng_ust_lib_ring_buffer *buf; /* + * buffer corresponding to processor id + * for this channel + */ + size_t slot_size; /* size of the reserved slot */ + unsigned long buf_offset; /* offset following the record header */ + unsigned long pre_offset; /* + * Initial offset position _before_ + * the record is written. Positioned + * prior to record header alignment + * padding. + */ + uint64_t tsc; /* time-stamp counter value */ + unsigned int rflags; /* reservation flags */ + void *ip; /* caller ip address */ + struct lttng_ust_lib_ring_buffer_backend_pages *backend_pages; + + /* End of base ABI. Fields below should be used after checking struct_size. */ +}; + +/** + * lib_ring_buffer_ctx_init - initialize ring buffer context + * @ctx: ring buffer context to initialize + * @chan: channel + * @priv: client private data + * @data_size: size of record data payload + * @largest_align: largest alignment within data payload types + * @cpu: processor id + */ +static inline lttng_ust_notrace +void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_ust_lib_ring_buffer_channel *chan, + void *priv, size_t data_size, int largest_align, + int cpu, struct lttng_ust_shm_handle *handle); +static inline +void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, + struct lttng_ust_lib_ring_buffer_channel *chan, + void *priv, size_t data_size, int largest_align, + int cpu, struct lttng_ust_shm_handle *handle) +{ + ctx->struct_size = sizeof(struct lttng_ust_lib_ring_buffer_ctx); + ctx->chan = chan; + ctx->priv = priv; + ctx->data_size = data_size; + ctx->largest_align = largest_align; + ctx->cpu = cpu; + ctx->rflags = 0; + ctx->handle = handle; + ctx->ip = 0; +} + +/* + * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at + * compile-time. We have to duplicate the "config->align" information and the + * definition here because config->align is used both in the slow and fast + * paths, but RING_BUFFER_ALIGN_ATTR is only available for the client code. + */ +#ifdef RING_BUFFER_ALIGN + +# define RING_BUFFER_ALIGN_ATTR /* Default arch alignment */ + +/* + * Calculate the offset needed to align the type. + * size_of_type must be non-zero. + */ +static inline lttng_ust_notrace +unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type); +static inline +unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type) +{ + return lttng_ust_offset_align(align_drift, size_of_type); +} + +#else + +# define RING_BUFFER_ALIGN_ATTR __attribute__((packed)) + +/* + * Calculate the offset needed to align the type. + * size_of_type must be non-zero. + */ +static inline lttng_ust_notrace +unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type); +static inline +unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type) +{ + return 0; +} + +#endif + +/** + * lib_ring_buffer_align_ctx - Align context offset on "alignment" + * @ctx: ring buffer context. + */ +static inline lttng_ust_notrace +void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx, + size_t alignment); +static inline +void lib_ring_buffer_align_ctx(struct lttng_ust_lib_ring_buffer_ctx *ctx, + size_t alignment) +{ + ctx->buf_offset += lib_ring_buffer_align(ctx->buf_offset, + alignment); +} + +#endif /* _LTTNG_RING_BUFFER_CONTEXT_H */