From 0466ac28c41336fd6d373cc8b0b26ef132225b9f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 17 Mar 2021 14:10:38 -0400 Subject: [PATCH] Refactoring: Privatize ring buffer config header The public header ringbuffer-config.h contains two distinct sets of APIs and structure declarations: - Ring buffer configuration, which should become private (moved to libringbuffer/ringbuffer-config.h), - Ring buffer context for use when writing an event record into the ring buffer. This part is moved to a new "ringbuffer-context.h" public header. Signed-off-by: Mathieu Desnoyers Change-Id: I07dae33ab5e3925dea0158058d484c49292a0bb0 --- include/Makefile.am | 2 +- include/lttng/ust-tracepoint-event.h | 2 +- liblttng-ust/lttng-context-cgroup-ns.c | 2 +- liblttng-ust/lttng-context-cpu-id.c | 2 +- liblttng-ust/lttng-context-ip.c | 2 +- liblttng-ust/lttng-context-ipc-ns.c | 2 +- liblttng-ust/lttng-context-mnt-ns.c | 2 +- liblttng-ust/lttng-context-net-ns.c | 2 +- liblttng-ust/lttng-context-perf-counters.c | 2 +- liblttng-ust/lttng-context-pid-ns.c | 2 +- liblttng-ust/lttng-context-procname.c | 2 +- liblttng-ust/lttng-context-pthread-id.c | 2 +- liblttng-ust/lttng-context-time-ns.c | 2 +- liblttng-ust/lttng-context-user-ns.c | 2 +- liblttng-ust/lttng-context-uts-ns.c | 2 +- liblttng-ust/lttng-context-vegid.c | 2 +- liblttng-ust/lttng-context-veuid.c | 2 +- liblttng-ust/lttng-context-vgid.c | 2 +- liblttng-ust/lttng-context-vpid.c | 2 +- liblttng-ust/lttng-context-vsgid.c | 2 +- liblttng-ust/lttng-context-vsuid.c | 2 +- liblttng-ust/lttng-context-vtid.c | 2 +- liblttng-ust/lttng-context-vuid.c | 2 +- liblttng-ust/lttng-tracer-core.h | 2 +- libringbuffer/Makefile.am | 2 +- libringbuffer/backend_internal.h | 3 +- libringbuffer/frontend_internal.h | 3 +- libringbuffer/frontend_types.h | 3 +- libringbuffer/ring_buffer_backend.c | 3 +- libringbuffer/ring_buffer_frontend.c | 3 +- .../ringbuffer-config.h | 137 +----------------- tests/compile/test-app-ctx/hello.c | 4 +- 32 files changed, 40 insertions(+), 166 deletions(-) rename {include/lttng => libringbuffer}/ringbuffer-config.h (65%) diff --git a/include/Makefile.am b/include/Makefile.am index 0dd7cf39..8c741b06 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -21,7 +21,7 @@ nobase_include_HEADERS = \ lttng/ust-compiler.h \ lttng/ust.h \ lttng/ust-endian.h \ - lttng/ringbuffer-config.h \ + lttng/ringbuffer-context.h \ lttng/align.h \ lttng/bug.h \ lttng/ust-error.h \ diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 5d84e0b2..50cbfbbc 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/liblttng-ust/lttng-context-cgroup-ns.c b/liblttng-ust/lttng-context-cgroup-ns.c index a6741fb1..65c5306c 100644 --- a/liblttng-ust/lttng-context-cgroup-ns.c +++ b/liblttng-ust/lttng-context-cgroup-ns.c @@ -14,9 +14,9 @@ #include #include #include -#include #include #include +#include #include "context-internal.h" #include "lttng-tracer-core.h" diff --git a/liblttng-ust/lttng-context-cpu-id.c b/liblttng-ust/lttng-context-cpu-id.c index cdcfe1a1..9c553828 100644 --- a/liblttng-ust/lttng-context-cpu-id.c +++ b/liblttng-ust/lttng-context-cpu-id.c @@ -18,8 +18,8 @@ #include #include #include -#include #include "../libringbuffer/getcpu.h" +#include #include "context-internal.h" diff --git a/liblttng-ust/lttng-context-ip.c b/liblttng-ust/lttng-context-ip.c index 4b32dc39..d7a65905 100644 --- a/liblttng-ust/lttng-context-ip.c +++ b/liblttng-ust/lttng-context-ip.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include "context-internal.h" diff --git a/liblttng-ust/lttng-context-ipc-ns.c b/liblttng-ust/lttng-context-ipc-ns.c index d0c4ecd6..b2c5e27d 100644 --- a/liblttng-ust/lttng-context-ipc-ns.c +++ b/liblttng-ust/lttng-context-ipc-ns.c @@ -14,9 +14,9 @@ #include #include #include -#include #include #include +#include #include "context-internal.h" #include "lttng-tracer-core.h" diff --git a/liblttng-ust/lttng-context-mnt-ns.c b/liblttng-ust/lttng-context-mnt-ns.c index 3535aacb..2606ff3c 100644 --- a/liblttng-ust/lttng-context-mnt-ns.c +++ b/liblttng-ust/lttng-context-mnt-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "ns.h" diff --git a/liblttng-ust/lttng-context-net-ns.c b/liblttng-ust/lttng-context-net-ns.c index 415c8ac3..1512fc27 100644 --- a/liblttng-ust/lttng-context-net-ns.c +++ b/liblttng-ust/lttng-context-net-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/liblttng-ust/lttng-context-perf-counters.c b/liblttng-ust/lttng-context-perf-counters.c index 725f4cf1..53ff3cbc 100644 --- a/liblttng-ust/lttng-context-perf-counters.c +++ b/liblttng-ust/lttng-context-perf-counters.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/liblttng-ust/lttng-context-pid-ns.c b/liblttng-ust/lttng-context-pid-ns.c index d5c731c8..1c45d7f2 100644 --- a/liblttng-ust/lttng-context-pid-ns.c +++ b/liblttng-ust/lttng-context-pid-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "ns.h" diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index 5e3f9f8a..1221298e 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include "compat.h" diff --git a/liblttng-ust/lttng-context-pthread-id.c b/liblttng-ust/lttng-context-pthread-id.c index d113f595..b25dc7ae 100644 --- a/liblttng-ust/lttng-context-pthread-id.c +++ b/liblttng-ust/lttng-context-pthread-id.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "context-internal.h" diff --git a/liblttng-ust/lttng-context-time-ns.c b/liblttng-ust/lttng-context-time-ns.c index dda556c6..6534ce72 100644 --- a/liblttng-ust/lttng-context-time-ns.c +++ b/liblttng-ust/lttng-context-time-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include "lttng-tracer-core.h" diff --git a/liblttng-ust/lttng-context-user-ns.c b/liblttng-ust/lttng-context-user-ns.c index 925b77b6..ee1cf739 100644 --- a/liblttng-ust/lttng-context-user-ns.c +++ b/liblttng-ust/lttng-context-user-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "ns.h" diff --git a/liblttng-ust/lttng-context-uts-ns.c b/liblttng-ust/lttng-context-uts-ns.c index 55a22899..e22011c9 100644 --- a/liblttng-ust/lttng-context-uts-ns.c +++ b/liblttng-ust/lttng-context-uts-ns.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/liblttng-ust/lttng-context-vegid.c b/liblttng-ust/lttng-context-vegid.c index d1a21a6e..488bfdd8 100644 --- a/liblttng-ust/lttng-context-vegid.c +++ b/liblttng-ust/lttng-context-vegid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-context-veuid.c b/liblttng-ust/lttng-context-veuid.c index 159eb420..22c09c82 100644 --- a/liblttng-ust/lttng-context-veuid.c +++ b/liblttng-ust/lttng-context-veuid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-context-vgid.c b/liblttng-ust/lttng-context-vgid.c index 5bfcd22e..a7b5dbfd 100644 --- a/liblttng-ust/lttng-context-vgid.c +++ b/liblttng-ust/lttng-context-vgid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-context-vpid.c b/liblttng-ust/lttng-context-vpid.c index 78e1f0ce..3594e529 100644 --- a/liblttng-ust/lttng-context-vpid.c +++ b/liblttng-ust/lttng-context-vpid.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include "context-internal.h" diff --git a/liblttng-ust/lttng-context-vsgid.c b/liblttng-ust/lttng-context-vsgid.c index 16a68a5c..f49d7f79 100644 --- a/liblttng-ust/lttng-context-vsgid.c +++ b/liblttng-ust/lttng-context-vsgid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-context-vsuid.c b/liblttng-ust/lttng-context-vsuid.c index c7d08151..aa8f755e 100644 --- a/liblttng-ust/lttng-context-vsuid.c +++ b/liblttng-ust/lttng-context-vsuid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index 432b8b0d..543e0498 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/liblttng-ust/lttng-context-vuid.c b/liblttng-ust/lttng-context-vuid.c index e6f57e71..438b4222 100644 --- a/liblttng-ust/lttng-context-vuid.c +++ b/liblttng-ust/lttng-context-vuid.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "context-internal.h" #include "creds.h" diff --git a/liblttng-ust/lttng-tracer-core.h b/liblttng-ust/lttng-tracer-core.h index 3216cdc1..2ab8bc7c 100644 --- a/liblttng-ust/lttng-tracer-core.h +++ b/liblttng-ust/lttng-tracer-core.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include /* diff --git a/libringbuffer/Makefile.am b/libringbuffer/Makefile.am index 631a3568..46c720a5 100644 --- a/libringbuffer/Makefile.am +++ b/libringbuffer/Makefile.am @@ -12,7 +12,7 @@ libringbuffer_la_SOURCES = \ api.h mmap.h \ backend.h backend_internal.h backend_types.h \ frontend_api.h frontend.h frontend_internal.h frontend_types.h \ - nohz.h vatomic.h rb-init.h + nohz.h vatomic.h rb-init.h ringbuffer-config.h libringbuffer_la_LIBADD = \ -lrt diff --git a/libringbuffer/backend_internal.h b/libringbuffer/backend_internal.h index 60c97d42..766fde2d 100644 --- a/libringbuffer/backend_internal.h +++ b/libringbuffer/backend_internal.h @@ -14,7 +14,8 @@ #include #include -#include +#include +#include "ringbuffer-config.h" #include "backend_types.h" #include "frontend_types.h" #include "shm.h" diff --git a/libringbuffer/frontend_internal.h b/libringbuffer/frontend_internal.h index e6569b28..6e9d8be2 100644 --- a/libringbuffer/frontend_internal.h +++ b/libringbuffer/frontend_internal.h @@ -17,7 +17,8 @@ #include #include -#include +#include +#include "ringbuffer-config.h" #include "backend_types.h" #include "frontend_types.h" #include "shm.h" diff --git a/libringbuffer/frontend_types.h b/libringbuffer/frontend_types.h index 851c8da9..01fdaccf 100644 --- a/libringbuffer/frontend_types.h +++ b/libringbuffer/frontend_types.h @@ -18,7 +18,8 @@ #include #include -#include +#include +#include "ringbuffer-config.h" #include #include "backend_types.h" #include "shm_internal.h" diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index 3202e8d9..f1f34898 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -12,7 +12,8 @@ #include #include -#include +#include +#include "ringbuffer-config.h" #include "vatomic.h" #include "backend.h" #include "frontend.h" diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index bc680100..45ff7dee 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -54,7 +54,8 @@ #include #include "smp.h" -#include +#include +#include "ringbuffer-config.h" #include "vatomic.h" #include "backend.h" #include "frontend.h" diff --git a/include/lttng/ringbuffer-config.h b/libringbuffer/ringbuffer-config.h similarity index 65% rename from include/lttng/ringbuffer-config.h rename to libringbuffer/ringbuffer-config.h index 00f655e5..1052ed6f 100644 --- a/include/lttng/ringbuffer-config.h +++ b/libringbuffer/ringbuffer-config.h @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: MIT * - * Copyright (C) 2010 Mathieu Desnoyers + * Copyright (C) 2010-2021 Mathieu Desnoyers * * Ring buffer configuration header. Note: after declaring the standard inline * functions, clients should also include linux/ringbuffer/api.h. @@ -11,12 +11,12 @@ #define _LTTNG_RING_BUFFER_CONFIG_H #include -#include "lttng/ust-tracer.h" +#include #include #include #include #include -#include "lttng/align.h" +#include #include struct lttng_ust_lib_ring_buffer; @@ -201,82 +201,6 @@ struct lttng_ust_lib_ring_buffer_config { char padding[LTTNG_UST_RING_BUFFER_CONFIG_PADDING]; }; -/* - * 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. - */ -#define LTTNG_UST_RING_BUFFER_CTX_PADDING 64 -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; -}; - -/** - * 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; -} - /* * Reservation flags. * @@ -294,61 +218,6 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx, #define RING_BUFFER_RFLAG_FULL_TSC (1U << 0) #define RING_BUFFER_RFLAG_END (1U << 1) -/* - * 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); -} - /* * lib_ring_buffer_check_config() returns 0 on success. * Used internally to check for valid configurations at channel creation. diff --git a/tests/compile/test-app-ctx/hello.c b/tests/compile/test-app-ctx/hello.c index 20df12db..19901c7c 100644 --- a/tests/compile/test-app-ctx/hello.c +++ b/tests/compile/test-app-ctx/hello.c @@ -28,9 +28,9 @@ struct mmsghdr; #define TRACEPOINT_DEFINE #include "ust_tests_hello.h" -/* Internal header. */ #include -#include +#include +/* Internal header. */ #include static __thread unsigned int test_count; -- 2.34.1