From 5f796aec4e514c556b20454a58c6ca9b4f3128a9 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Tue, 23 Mar 2021 16:56:21 -0400 Subject: [PATCH] Namespace RING_BUFFER_ALIGN macros Also add comments to clarify why efficient memory access impacts the layout of the ringbuffer. Change-Id: I752f8b6dec6b00b8222500194cd53428db7d0da5 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- include/lttng/ringbuffer-context.h | 25 ++++++++++++++++--------- include/lttng/ust-tracer.h | 11 +++++++---- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/lttng/ringbuffer-context.h b/include/lttng/ringbuffer-context.h index 1b200f7c..0092a0f1 100644 --- a/include/lttng/ringbuffer-context.h +++ b/include/lttng/ringbuffer-context.h @@ -101,18 +101,20 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, } /* - * We need to define RING_BUFFER_ALIGN_ATTR so it is known early at + * We need to define LTTNG_UST_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. + * paths, but LTTNG_UST_RING_BUFFER_ALIGN_ATTR is only available for the client + * code. */ -#ifdef RING_BUFFER_ALIGN +#ifdef LTTNG_UST_RING_BUFFER_NATURAL_ALIGN -# define RING_BUFFER_ALIGN_ATTR /* Default arch alignment */ +# define LTTNG_UST_RING_BUFFER_ALIGN_ATTR /* Default arch alignment */ /* - * Calculate the offset needed to align the type. - * size_of_type must be non-zero. + * lib_ring_buffer_align - Calculate the offset needed to align the type. + * @align_drift: object offset from an "alignment"-aligned address. + * @size_of_type: Must be non-zero, power of 2. */ static inline lttng_ust_notrace unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type); @@ -124,17 +126,22 @@ unsigned int lib_ring_buffer_align(size_t align_drift, size_t size_of_type) #else -# define RING_BUFFER_ALIGN_ATTR __attribute__((packed)) +# define LTTNG_UST_RING_BUFFER_ALIGN_ATTR __attribute__((packed)) /* - * Calculate the offset needed to align the type. - * size_of_type must be non-zero. + * lib_ring_buffer_align - Calculate the offset needed to align the type. + * @align_drift: object offset from an "alignment"-aligned address. + * @size_of_type: Must be non-zero, power of 2. */ 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) { + /* + * On architectures with efficient unaligned memory access, the content + * of the ringbuffer is packed and so the offset is always zero. + */ return 0; } diff --git a/include/lttng/ust-tracer.h b/include/lttng/ust-tracer.h index b451eae6..3a771e9b 100644 --- a/include/lttng/ust-tracer.h +++ b/include/lttng/ust-tracer.h @@ -11,16 +11,19 @@ #include #include -#include #include #include +/* + * Default to having the content of the ringbuffer respect the natural + * alignment of the system. Only pack its content on architectures we know + * have efficient unaligned memory access. + */ #ifndef LTTNG_UST_ARCH_HAS_EFFICIENT_UNALIGNED_ACCESS -/* Align data on its natural alignment */ -#define RING_BUFFER_ALIGN +#define LTTNG_UST_RING_BUFFER_NATURAL_ALIGN #endif -#ifdef RING_BUFFER_ALIGN +#ifdef LTTNG_UST_RING_BUFFER_NATURAL_ALIGN #define lttng_alignof(type) __alignof__(type) #else #define lttng_alignof(type) 1 -- 2.34.1