diff mbox series

libtracefs: Force off trace mmapping

Message ID 20240108131903.52b02897@gandalf.local.home (mailing list archive)
State Accepted
Commit 585ec77727e0b5f908792b87d4f736e553433f9f
Headers show
Series libtracefs: Force off trace mmapping | expand

Commit Message

Steven Rostedt Jan. 8, 2024, 6:19 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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 tha 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

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.

The memory mapping can still be complied in by doing:

  make EXTRA_CFLAGS=-DFORCE_MMAP_ENABLE

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 Makefile           | 12 +++++++++---
 src/tracefs-mmap.c |  4 ++++
 2 files changed, 13 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index e915e14..7a5b0c4 100644
--- a/Makefile
+++ b/Makefile
@@ -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)