diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-08 13:19:03 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-08 14:50:28 -0500 |
commit | 585ec77727e0b5f908792b87d4f736e553433f9f (patch) | |
tree | 6df002fedd66e0220cc63ffb1dfc6003c8b4d5fe | |
parent | 2ed14b594f669fe5228d19e032467405b764833a (diff) | |
download | libtracefs-585ec77727e0b5f908792b87d4f736e553433f9f.tar.gz |
libtracefs: Force off trace mmapping
The libtracefs API for trace buffer memory mapping should be stable. But the
Linux kernel has not yet accepted the changes. There's a chance that the kernel
API may change. In order to add the libtracefs API without depending on the API
being stable, add it but always have it fail unless the code is built with:
make EXTRA_FLAGS=-DFORCE_MMAP_ENBALE # For debugging purposes only!
Applications can start using the API and when it becomes available in the
kernel, force disabling will be removed in a "fix" update to libtracefs. This
way if the Linux kernel API changes before it gets in, an application using an
older libtracefs will not break, as the mapping code will still silently fail
like it always has. For an application to work with the buffer mmap after it is
in the Linux kernel with a stable API, all it will need to do is update the
libtracefs to a version that has it enabled.
That is, the libtracefs API of:
tracefs_cpu_open_mapped()
tracefs_cpu_is_mapped()
tracefs_cpu_map()
tracefs_cpu_unmap()
Will still be applicable even if the Linux kernel changes how it does the
memory mapping when it is finally upstream.
Link: https://lore.kernel.org/linux-trace-devel/20240108131903.52b02897@gandalf.local.home
Cc: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | src/tracefs-mmap.c | 4 |
2 files changed, 13 insertions, 3 deletions
@@ -165,6 +165,12 @@ INCLUDES += -I$(src)/include/tracefs include $(src)/scripts/features.mk # Set compile option CFLAGS if not set elsewhere +ifdef EXTRA_CFLAGS + CFLAGS ?= $(EXTRA_CFLAGS) +else + CFLAGS ?= -g -Wall +endif + CFLAGS ?= -g -Wall CPPFLAGS ?= LDFLAGS ?= @@ -172,15 +178,15 @@ LDFLAGS ?= CUNIT_INSTALLED := $(shell if (printf "$(pound)include <CUnit/Basic.h>\n void main(){CU_initialize_registry();}" | $(CC) -x c - -lcunit -o /dev/null >/dev/null 2>&1) ; then echo 1; else echo 0 ; fi) export CUNIT_INSTALLED -export CFLAGS -export INCLUDES - # Append required CFLAGS override CFLAGS += -D_GNU_SOURCE $(LIBTRACEEVENT_INCLUDES) $(INCLUDES) # Make sure 32 bit stat() works on large file systems override CFLAGS += -D_FILE_OFFSET_BITS=64 +export CFLAGS +export INCLUDES + all: all_cmd LIB_TARGET = libtracefs.a libtracefs.so.$(TRACEFS_VERSION) diff --git a/src/tracefs-mmap.c b/src/tracefs-mmap.c index 5807453..0f90f51 100644 --- a/src/tracefs-mmap.c +++ b/src/tracefs-mmap.c @@ -61,6 +61,10 @@ __hidden void *trace_mmap(int fd, struct kbuffer *kbuf) void *meta; void *data; +#ifndef FORCE_MMAP_ENABLE + return NULL; +#endif + page_size = getpagesize(); meta = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); if (meta == MAP_FAILED) |