From: Michael Jeanson Date: Tue, 23 Mar 2021 20:56:21 +0000 (-0400) Subject: Namespace RING_BUFFER_ALIGN macros X-Git-Tag: v2.13.0-rc1~195 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=5f796aec4e514c556b20454a58c6ca9b4f3128a9;p=lttng-ust.git 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 --- 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