linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] rt-tests: Remove debugfs usage
@ 2025-09-03 11:17 Sebastian Andrzej Siewior
  2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
                   ` (9 more replies)
  0 siblings, 10 replies; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

v6.17 starts to complain if /sys/kernel/debug/tracing is used instead of
the "official" directory. Official as "it is in use since v4.1" which
was released over 10 years ago.
All the "I need to mount it here" kind of workarounds are also outdated
and not needed since distros mount it properly.
There is no need of a "special work around" for this since other tools
such as trace-cmd expect that these folder exist.

Anyway. Started a small clean up, diffstat looks nice.

Sebastian Andrzej Siewior (10):
  README: Drop "debug" from the tracing path
  rt-utils: Remove mount_debugfs()
  rt-utils: Rename get_debugfileprefix() and let it look for tracefs
  queuelat, rt-migrate-test: Use tracefs for tracing
  rt-utils: Remove fileprefix.
  rt-utils: Simplify trace_file_exists()
  rt-utils: Decouple writting trace-marks with trace stopping
  sched_deadline: Use tracemark() from rt-utils instead cusstom
    implementation
  sched_deadline: Check the resulting size returned from snprintf()
  cyclicdeadline: Don't test for /sys/kernel/debug/sched_features

 README.markdown                       |  13 +--
 src/backfire/sendme.c                 |   2 +-
 src/cyclictest/cyclictest.c           |   1 +
 src/include/rt-utils.h                |   4 +-
 src/lib/rt-utils.c                    | 105 +++++++--------------
 src/oslat/oslat.c                     |   1 +
 src/pmqtest/pmqtest.c                 |   2 +-
 src/ptsematest/ptsematest.c           |   2 +-
 src/queuelat/queuelat.c               |   2 +-
 src/rt-migrate-test/rt-migrate-test.c |   4 +-
 src/sched_deadline/cyclicdeadline.c   | 128 ++------------------------
 src/sigwaittest/sigwaittest.c         |   2 +-
 src/svsematest/svsematest.c           |   2 +-
 13 files changed, 61 insertions(+), 207 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 01/10] README: Drop "debug" from the tracing path
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:18   ` John Kacur
  2025-09-03 11:17 ` [PATCH 02/10] rt-utils: Remove mount_debugfs() Sebastian Andrzej Siewior
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

The tracing interface moved away from debug/ configfs. It moved one
level up and the debug sub folder has a compatibility mount which will be
removed.
While at it I noticed that the -f option is long gone. Take the
opportunity to update this, too.

Update the docs accordingly.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 README.markdown | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/README.markdown b/README.markdown
index 3ab6ddf53c7ed..617b57e88614f 100644
--- a/README.markdown
+++ b/README.markdown
@@ -57,15 +57,16 @@ then probably be regarded as real-time capable.
 
 What, however, if the latency is higher than acceptable? Then, the famous
 "*latency fighting*" begins. For this purpose, the cyclictest tool provides the
-`-b` option that causes a function tracing to be written to
-`/sys/kernel/debug/tracing/trace`, if a specified latency threshold was
-exceeded, for example:
+`--breaktrace` option to halt tracing if the specified latency was exceeded. A
+tracer must be configured upfront. The resulting trace can be invastigated in
+`/sys/kernel/tracing/trace`, for example:
 
-    ./cyclictest -a -t -n -p99 -f -b100
+    echo function > /sys/kernel/tracing/current_tracer
+    cyclictest -a -t -n -p99 --tracemark --breaktrace 100
 
 This causes the program to abort execution, if the latency value exceeds 100
 microseconds; the culprit can then be found in the trace output at
-`/sys/kernel/debug/tracing/trace`.
+`/sys/kernel/tracing/trace`.
 The kernel function that was executed just before a latency of more than 100
 microseconds was detected is marked with an exclamation mark such as
 
@@ -80,7 +81,7 @@ latency.
 If the trace output is not obvious, it can be submitted to the OSADL Latency
 Fight Support Service at
 [latency-fighters@osadl.org](mailto:latency-fighters@osadl.org).
-In addition to the output of `cat /sys/kernel/debug/tracing/trace`, the output
+In addition to the output of `cat /sys/kernel/tracing/trace`, the output
 of `lspci` and the `.config` file that was used to build the kernel in question
 must be submitted. We are sure you understand that OSADL members will be served
 first, but we promise to do our best to help everybody to successfully fight
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 02/10] rt-utils: Remove mount_debugfs()
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
  2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:20   ` John Kacur
  2025-09-03 11:17 ` [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs Sebastian Andrzej Siewior
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

The requirement to mount debugfs is very old. It originated from a time
where it was "fairly new" and was not mounted by distros at the time.
These days debugfs gets mounted during boot and more importantly the
tracing directory moved out over 10years ago.

Don't try to mount debugfs anymore.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/include/rt-utils.h |  1 -
 src/lib/rt-utils.c     | 29 -----------------------------
 2 files changed, 30 deletions(-)

diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index f6b3fede06f7b..95964f70a6310 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -12,7 +12,6 @@
 
 int check_privs(void);
 char *get_debugfileprefix(void);
-int mount_debugfs(char *);
 int get_tracers(char ***);
 int valid_tracer(char *);
 
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 6bbd25a8ba53f..7e96950ef9887 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -99,32 +99,6 @@ char *get_debugfileprefix(void)
 	return debugfileprefix;
 }
 
-int mount_debugfs(char *path)
-{
-	char *mountpoint = path;
-	char cmd[MAX_PATH];
-	char *prefix;
-	int ret;
-
-	/* if it's already mounted just return */
-	prefix = get_debugfileprefix();
-	if (strlen(prefix) != 0) {
-		info(1, "debugfs mountpoint: %s\n", prefix);
-		return 0;
-	}
-	if (!mountpoint)
-		mountpoint = "/sys/kernel/debug";
-
-	sprintf(cmd, "mount -t debugfs debugfs %s", mountpoint);
-	ret = system(cmd);
-	if (ret != 0) {
-		fprintf(stderr, "Error mounting debugfs at %s: %s\n",
-			mountpoint, strerror(errno));
-		return -1;
-	}
-	return 0;
-}
-
 static char **tracer_list;
 static char *tracer_buffer;
 static int num_tracers;
@@ -451,9 +425,6 @@ static int trace_file_exists(char *name)
 
 static void debugfs_prepare(void)
 {
-	if (mount_debugfs(NULL))
-		fatal("could not mount debugfs");
-
 	fileprefix = get_debugfileprefix();
 	if (!trace_file_exists("tracing_enabled") &&
 	    !trace_file_exists("tracing_on"))
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
  2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
  2025-09-03 11:17 ` [PATCH 02/10] rt-utils: Remove mount_debugfs() Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:29   ` John Kacur
  2025-09-03 11:17 ` [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing Sebastian Andrzej Siewior
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

get_debugfileprefix() used to look for debugfs and added the tracing
suffix to it. In the early days it it was not always monted at the same
destination. Later, that function got a fastpath to look directly at
"/sys/kernel/debug/tracing". This avoids parsing the mounted filesystem
and looking for debugfs.

Since about v4.1 (released over 10 years ago) that tracing folder moved
out debugfs and got its own filesystem (tracefs) and is mounted at
/sys/kernel/tracing. Since then that /sys/kernel/debug/tracing folder is
just an automount/ alias to /sys/kernel/tracing.
Since v6.17 that automount can be disabled and is schedulued for
removal.
Strart using tracefs directly instead that alias:
- Replace that "debug" prefix with tracefs since debugfs is no longer
  the thing that is used
- Look directy for /sys/kernel/tracing
- If it is not there, look for tracefs filesystem in case it is mounted
  at an unusual spot.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/backfire/sendme.c         |  2 +-
 src/include/rt-utils.h        |  2 +-
 src/lib/rt-utils.c            | 51 ++++++++++++-----------------------
 src/pmqtest/pmqtest.c         |  2 +-
 src/ptsematest/ptsematest.c   |  2 +-
 src/sigwaittest/sigwaittest.c |  2 +-
 src/svsematest/svsematest.c   |  2 +-
 7 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/src/backfire/sendme.c b/src/backfire/sendme.c
index da10397846f79..1c3e8b0c4c1b9 100644
--- a/src/backfire/sendme.c
+++ b/src/backfire/sendme.c
@@ -45,7 +45,7 @@ static int interval = 1000;
 static int kernvar(int mode, const char *name, char *value, size_t sizeofvalue)
 {
 	char filename[128];
-	char *fileprefix = get_debugfileprefix();
+	char *fileprefix = get_tracefs_prefix();
 	int retval = 1;
 	int path;
 	size_t len_prefix = strlen(fileprefix), len_name = strlen(name);
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index 95964f70a6310..569023c5d3051 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -11,7 +11,7 @@
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 int check_privs(void);
-char *get_debugfileprefix(void);
+char *get_tracefs_prefix(void);
 int get_tracers(char ***);
 int valid_tracer(char *);
 
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 7e96950ef9887..696bca2657d18 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -32,7 +32,7 @@
 #define  MAX_COMMAND_LINE 4096
 #define  MAX_TS_SIZE 64
 
-static char debugfileprefix[MAX_PATH];
+static char tracefs_prefix[MAX_PATH];
 static char *fileprefix;
 static int trace_fd = -1;
 static int tracemark_fd = -1;
@@ -41,28 +41,21 @@ static char test_cmdline[MAX_COMMAND_LINE];
 static char ts_start[MAX_TS_SIZE];
 
 /*
- * Finds the tracing directory in a mounted debugfs
+ * Finds the tracing directory
  */
-char *get_debugfileprefix(void)
+char *get_tracefs_prefix(void)
 {
 	char type[100];
 	FILE *fp;
-	int size;
 	int found = 0;
 	struct stat s;
 
-	if (debugfileprefix[0] != '\0')
+	if (tracefs_prefix[0] != '\0')
 		goto out;
 
 	/* look in the "standard" mount point first */
-	if ((stat("/sys/kernel/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
-		strcpy(debugfileprefix, "/sys/kernel/debug/tracing/");
-		goto out;
-	}
-
-	/* now look in the "other standard" place */
-	if ((stat("/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
-		strcpy(debugfileprefix, "/debug/tracing/");
+	if ((stat("/sys/kernel/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
+		strcpy(tracefs_prefix, "/sys/kernel/tracing/");
 		goto out;
 	}
 
@@ -73,14 +66,8 @@ char *get_debugfileprefix(void)
 	while (fscanf(fp, "%*s %"
 		      STR(MAX_PATH)
 		      "s %99s %*s %*d %*d\n",
-		      debugfileprefix, type) == 2) {
-		if (strcmp(type, "debugfs") == 0) {
-			found = 1;
-			break;
-		}
-		/* stupid check for systemd-style autofs mount */
-		if ((strcmp(debugfileprefix, "/sys/kernel/debug") == 0) &&
-		    (strcmp(type, "systemd") == 0)) {
+		      tracefs_prefix, type) == 2) {
+		if (strcmp(type, "tracefs") == 0) {
 			found = 1;
 			break;
 		}
@@ -88,15 +75,11 @@ char *get_debugfileprefix(void)
 	fclose(fp);
 
 	if (!found) {
-		debugfileprefix[0] = '\0';
+		tracefs_prefix[0] = '\0';
 		goto out;
 	}
-
-	size = sizeof(debugfileprefix) - strlen(debugfileprefix);
-	strncat(debugfileprefix, "/tracing/", size);
-
 out:
-	return debugfileprefix;
+	return tracefs_prefix;
 }
 
 static char **tracer_list;
@@ -113,7 +96,7 @@ int get_tracers(char ***list)
 	int ret;
 	FILE *fp;
 	char buffer[CHUNKSZ];
-	char *prefix = get_debugfileprefix();
+	char *prefix = get_tracefs_prefix();
 	char *tmpbuf = NULL;
 	char *ptr;
 	int tmpsz = 0;
@@ -193,7 +176,7 @@ int valid_tracer(char *tracername)
  */
 int setevent(char *event, char *val)
 {
-	char *prefix = get_debugfileprefix();
+	char *prefix = get_tracefs_prefix();
 	char buffer[MAX_PATH];
 	int fd;
 	int ret;
@@ -417,19 +400,19 @@ static void close_tracemark_fd(void)
 static int trace_file_exists(char *name)
 {
 	struct stat sbuf;
-	char *tracing_prefix = get_debugfileprefix();
+	char *tracing_prefix = get_tracefs_prefix();
 	char path[MAX_PATH];
 	strcat(strcpy(path, tracing_prefix), name);
 	return stat(path, &sbuf) ? 0 : 1;
 }
 
-static void debugfs_prepare(void)
+static void tracefs_prepare(void)
 {
-	fileprefix = get_debugfileprefix();
+	fileprefix = get_tracefs_prefix();
 	if (!trace_file_exists("tracing_enabled") &&
 	    !trace_file_exists("tracing_on"))
 		warn("tracing_enabled or tracing_on not found\n"
-		     "debug fs not mounted");
+		     "tracefs not found");
 }
 
 void tracemark(char *fmt, ...)
@@ -455,7 +438,7 @@ void tracemark(char *fmt, ...)
 
 void enable_trace_mark(void)
 {
-	debugfs_prepare();
+	tracefs_prepare();
 	open_tracemark_fd();
 }
 
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index 04e36a1ad9795..a25b5cd2c24a1 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -184,7 +184,7 @@ void *pmqthread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index d21166946f6ac..00871d08df3a8 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -107,7 +107,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 026cc81510157..e55f7fd2411f6 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -163,7 +163,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index f3cddf8545757..093f3c473f0a1 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -170,7 +170,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (2 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:39   ` John Kacur
  2025-09-03 11:17 ` [PATCH 05/10] rt-utils: Remove fileprefix Sebastian Andrzej Siewior
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

Instead of looking at all possible folders underneath debugfs for
tracing, look directly at /sys/kernel/tracing/. It no longer lives
underneath debugfs.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/queuelat/queuelat.c               | 2 +-
 src/rt-migrate-test/rt-migrate-test.c | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/queuelat/queuelat.c b/src/queuelat/queuelat.c
index 28cf7abe83ae6..5a3d0c61a3fc4 100644
--- a/src/queuelat/queuelat.c
+++ b/src/queuelat/queuelat.c
@@ -331,7 +331,7 @@ static void trace_open(void)
 {
 	int fd;
 
-	fd = open("/sys/kernel/debug/tracing/trace_marker", O_RDWR);
+	fd = open("/sys/kernel/tracing/trace_marker", O_RDWR);
 
 	if (fd == -1) {
 		perror("open");
diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
index 8afe0834905bd..ccc2caf77d735 100644
--- a/src/rt-migrate-test/rt-migrate-test.c
+++ b/src/rt-migrate-test/rt-migrate-test.c
@@ -39,9 +39,7 @@ static void setup_ftrace_marker(void)
 {
 	struct stat st;
 	char *files[] = {
-		"/sys/kernel/debug/tracing/trace_marker",
-		"/debug/tracing/trace_marker",
-		"/debugfs/tracing/trace_marker",
+		"/sys/kernel/tracing/trace_marker",
 	};
 	int ret;
 	unsigned int i;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 05/10] rt-utils: Remove fileprefix.
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (3 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:41   ` John Kacur
  2025-09-03 11:17 ` [PATCH 06/10] rt-utils: Simplify trace_file_exists() Sebastian Andrzej Siewior
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

Remove fileprefix and use tracefs_prefix directly.
There is no need for having both.
Since sprintf() will complain that output buffer has the same size as
the first input buffer so it could write more bytes use snprintf() and
catch that possible overflow.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/lib/rt-utils.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 696bca2657d18..0e6e6056a4392 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -33,7 +33,6 @@
 #define  MAX_TS_SIZE 64
 
 static char tracefs_prefix[MAX_PATH];
-static char *fileprefix;
 static int trace_fd = -1;
 static int tracemark_fd = -1;
 static __thread char tracebuf[TRACEBUFSIZ];
@@ -363,12 +362,17 @@ int parse_mem_string(char *str, uint64_t *val)
 static void open_tracemark_fd(void)
 {
 	char path[MAX_PATH];
+	int n;
 
 	/*
 	 * open the tracemark file if it's not already open
 	 */
 	if (tracemark_fd < 0) {
-		sprintf(path, "%s/%s", fileprefix, "trace_marker");
+		n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "trace_marker");
+		if (n >= sizeof(path)) {
+			warn("tracefs path too long\n");
+			return;
+		}
 		tracemark_fd = open(path, O_WRONLY);
 		if (tracemark_fd < 0) {
 			warn("unable to open trace_marker file: %s\n", path);
@@ -382,7 +386,11 @@ static void open_tracemark_fd(void)
 	 * if we hit a breaktrace threshold
 	 */
 	if (trace_fd < 0) {
-		sprintf(path, "%s/%s", fileprefix, "tracing_on");
+		n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "tracing_on");
+		if (n >= sizeof(path)) {
+			warn("tracefs path too long\n");
+			return;
+		}
 		if ((trace_fd = open(path, O_WRONLY)) < 0)
 			warn("unable to open tracing_on file: %s\n", path);
 	}
@@ -408,7 +416,7 @@ static int trace_file_exists(char *name)
 
 static void tracefs_prepare(void)
 {
-	fileprefix = get_tracefs_prefix();
+	get_tracefs_prefix();
 	if (!trace_file_exists("tracing_enabled") &&
 	    !trace_file_exists("tracing_on"))
 		warn("tracing_enabled or tracing_on not found\n"
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 06/10] rt-utils: Simplify trace_file_exists()
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (4 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 05/10] rt-utils: Remove fileprefix Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:42   ` John Kacur
  2025-09-03 11:17 ` [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping Sebastian Andrzej Siewior
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

Pass the tracefs folder prefix directly to stat instead making a copy of
it. stat() is defined as not altering the path argument.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/lib/rt-utils.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 0e6e6056a4392..294fc9683a122 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -408,10 +408,7 @@ static void close_tracemark_fd(void)
 static int trace_file_exists(char *name)
 {
 	struct stat sbuf;
-	char *tracing_prefix = get_tracefs_prefix();
-	char path[MAX_PATH];
-	strcat(strcpy(path, tracing_prefix), name);
-	return stat(path, &sbuf) ? 0 : 1;
+	return stat(tracefs_prefix, &sbuf) ? 0 : 1;
 }
 
 static void tracefs_prepare(void)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (5 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 06/10] rt-utils: Simplify trace_file_exists() Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:49   ` John Kacur
  2025-09-03 11:17 ` [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation Sebastian Andrzej Siewior
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

Most users write a trace mark and expect that the trace stops afterwads.
Decoupling writting and stopping the trace so it can be used in context
where trace stopping is not needed.

Make tracemark() writting just to the tracemark file.
Add tracing_stop() which stops tracing and let current users of
tracemark() use it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/cyclictest/cyclictest.c         | 1 +
 src/include/rt-utils.h              | 1 +
 src/lib/rt-utils.c                  | 8 ++++++--
 src/oslat/oslat.c                   | 1 +
 src/sched_deadline/cyclicdeadline.c | 1 +
 5 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index 890da5d869c92..b4bce8915b432 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -852,6 +852,7 @@ static void *timerthread(void *param)
 				break_thread_id = stat->tid;
 				tracemark("hit latency threshold (%llu > %d)",
 					  (unsigned long long) diff, tracelimit);
+				tracing_stop();
 				break_thread_value = diff;
 			}
 			pthread_mutex_unlock(&break_thread_id_lock);
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index 569023c5d3051..e148dd77fd7d8 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -31,6 +31,7 @@ int parse_mem_string(char *str, uint64_t *val);
 
 void enable_trace_mark(void);
 void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
+void tracing_stop(void);
 void disable_trace_mark(void);
 
 #define MSEC_PER_SEC		1000
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 294fc9683a122..e504b17738411 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -427,7 +427,7 @@ void tracemark(char *fmt, ...)
 
 	/* bail out if we're not tracing */
 	/* or if the kernel doesn't support trace_mark */
-	if (tracemark_fd < 0 || trace_fd < 0)
+	if (tracemark_fd < 0)
 		return;
 
 	va_start(ap, fmt);
@@ -436,8 +436,12 @@ void tracemark(char *fmt, ...)
 
 	/* write the tracemark message */
 	write(tracemark_fd, tracebuf, len);
+}
 
-	/* now stop any trace */
+void tracing_stop(void)
+{
+	if (trace_fd < 0)
+		return;
 	write(trace_fd, "0\n", 2);
 }
 
diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
index 9e5a08a2fbd92..4291221dc6521 100644
--- a/src/oslat/oslat.c
+++ b/src/oslat/oslat.c
@@ -340,6 +340,7 @@ static void insert_bucket(struct thread *t, stamp_t value)
 		char *line = "%s: Trace threshold (%d us) triggered on cpu %d with %.*f us!\n";
 		tracemark(line, g.app_name, g.trace_threshold, t->core_i,
 			  g.precision, us);
+		tracing_stop();
 		err_quit(line, g.app_name, g.trace_threshold, t->core_i,
 			 g.precision, us);
 	}
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 04e61edc68d83..e2f827deb275a 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -885,6 +885,7 @@ void *run_deadline(void *data)
 				break_thread_value = stat->max;
 				tracemark("hit latency threshold (%lld > %d)",
 						 (unsigned long long) stat->max, tracelimit);
+				tracing_stop();
 			}
 			pthread_mutex_unlock(&break_thread_id_lock);
 			break;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (6 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:52   ` John Kacur
  2025-09-03 11:17 ` [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf() Sebastian Andrzej Siewior
  2025-09-03 11:17 ` [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features Sebastian Andrzej Siewior
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

Somehow cyclicdeadline has its implementation to write to the
trace_marker and it also uses tracemark() from rt-utils.
Since now tracemark() is not stopping the trace anymore it can be used
as-is.
This has the advantage of removing some code and automaticly using
trace_marker from tracefs :)

Remove ftrace_write(), setup_ftrace_marker() and use tracemark()
instead.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/sched_deadline/cyclicdeadline.c | 116 ++--------------------------
 1 file changed, 5 insertions(+), 111 deletions(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index e2f827deb275a..82e640409ecef 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -72,8 +72,6 @@ struct sched_data {
 	int bufmsk;
 
 	struct thread_stat stat;
-
-	char buff[BUFSIZ+1];
 };
 
 static int shutdown;
@@ -92,7 +90,6 @@ static int cpu_count;
 static int all_cpus;
 static int nr_threads;
 static int use_nsecs;
-static int mark_fd;
 static int quiet;
 static char jsonfile[MAX_PATH];
 
@@ -136,107 +133,6 @@ static const char *find_debugfs(void)
 	return debugfs;
 }
 
-static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
-{
-	const char *p;
-	char tmp[100];
-	char *s = buf;
-	char *end = buf + size;
-	char *str;
-	long long lng;
-	int l;
-	int i;
-
-	end[-1] = 0;
-
-	for (p = fmt; *p && s < end; p++) {
-		if (*p == '%') {
-			l = 0;
- again:
-			p++;
-			switch (*p) {
-			case 's':
-				if (l)
-					fatal("Illegal print format l used with %%s\n");
-				str = va_arg(ap, char *);
-				l = strlen(str);
-				strncpy(s, str, end - s);
-				s += l;
-				break;
-			case 'l':
-				l++;
-				goto again;
-			case 'd':
-				if (l == 1) {
-					if (sizeof(long) == 8)
-						l = 2;
-				}
-				if (l == 2)
-					lng = va_arg(ap, long long);
-				else if (l > 2)
-					fatal("Illegal print format l=%d\n", l);
-				else
-					lng = va_arg(ap, int);
-				i = 0;
-				while (lng > 0) {
-					tmp[i++] = (lng % 10) + '0';
-					lng /= 10;
-				}
-				tmp[i] = 0;
-				l = strlen(tmp);
-				if (!l) {
-					*s++ = '0';
-				} else {
-					while (l)
-						*s++ = tmp[--l];
-				}
-				break;
-			default:
-				fatal("Illegal print format '%c'\n", *p);
-			}
-			continue;
-		}
-		*s++ = *p;
-	}
-
-	return s - buf;
-}
-
-static void ftrace_write(char *buf, const char *fmt, ...)
-{
-	va_list ap;
-	int n;
-
-	if (mark_fd < 0)
-		return;
-
-	va_start(ap, fmt);
-	n = my_vsprintf(buf, BUFSIZ, fmt, ap);
-	va_end(ap);
-
-	write(mark_fd, buf, n);
-}
-
-static void setup_ftrace_marker(void)
-{
-	struct stat st;
-	const char *debugfs = find_debugfs();
-	char files[strlen(debugfs) + strlen("/tracing/trace_marker") + 1];
-	int ret;
-
-	if (strlen(debugfs) == 0)
-		return;
-
-	sprintf(files, "%s/tracing/trace_marker", debugfs);
-	ret = stat(files, &st);
-	if (ret >= 0)
-		goto found;
-	/* Do nothing if not mounted */
-	return;
-found:
-	mark_fd = open(files, O_WRONLY);
-}
-
 /*
  * Return true if file exists
  */
@@ -804,16 +700,15 @@ static u64 do_runtime(struct sched_data *sd, u64 period)
 		 * preempting us when we started. If that's the case then
 		 * adjust the current period.
 		 */
-		ftrace_write(sd->buff,
-			     "Adjusting period: now: %lld period: %lld delta:%lld%s\n",
-			     now, period, delta, delta > sd->deadline_us / 2 ?
-			     " HUGE ADJUSTMENT" : "");
+		tracemark("Adjusting period: now: %lld period: %lld delta:%lld%s\n",
+			  now, period, delta, delta > sd->deadline_us / 2 ?
+			  " HUGE ADJUSTMENT" : "");
 		period = now;
 		next_period = period + sd->deadline_us;
 	}
 
-	ftrace_write(sd->buff, "start at %lld off=%lld (period=%lld next=%lld)\n",
-		     now, now - period, period, next_period);
+	tracemark("start at %lld off=%lld (period=%lld next=%lld)\n",
+		  now, now - period, period, next_period);
 
 
 	diff = now - period;
@@ -1293,7 +1188,6 @@ int main(int argc, char **argv)
 	if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1)
 		warn("mlockall");
 
-	setup_ftrace_marker();
 	if (tracelimit && trace_marker)
 		enable_trace_mark();
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf()
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (7 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:54   ` John Kacur
  2025-09-03 11:17 ` [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features Sebastian Andrzej Siewior
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

The code simply assumes that the built path does not exceed MAX_PATH.
Since the previous change the compiler started to complain but I don't
see a connection other than the removal of one find_debugfs() user.

Make sure the resulting path is not truncated.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/sched_deadline/cyclicdeadline.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 82e640409ecef..89b7c0b8deb21 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -160,12 +160,16 @@ static int fill_sched_features(char *path)
 	if (strlen(debugfs) == 0)
 		return -1;
 
-	snprintf(path, MAX_PATH, "%s/sched/features", debugfs);
+	ret = snprintf(path, MAX_PATH, "%s/sched/features", debugfs);
+	if (ret >= MAX_PATH)
+		return -1;
 	ret = check_file_exists(path);
 	if (ret)
 		return 0;
 
-	snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
+	ret = snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
+	if (ret >= MAX_PATH)
+		return -1;
 	ret = check_file_exists(path);
 	if (ret)
 		return 0;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features
  2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
                   ` (8 preceding siblings ...)
  2025-09-03 11:17 ` [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf() Sebastian Andrzej Siewior
@ 2025-09-03 11:17 ` Sebastian Andrzej Siewior
  2025-09-19 18:55   ` John Kacur
  9 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-09-03 11:17 UTC (permalink / raw)
  To: linux-rt-users
  Cc: John Kacur, Clark Williams, Steven Rostedt,
	Sebastian Andrzej Siewior

sched_features was renamed to sched/features in commit 8a99b6833c884
("sched: Move SCHED_DEBUG sysctl to debugfs") which was merged in v5.13.

It is probably okay to remove it from the fallback list.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 src/sched_deadline/cyclicdeadline.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 89b7c0b8deb21..4ee3717a767e9 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -167,17 +167,8 @@ static int fill_sched_features(char *path)
 	if (ret)
 		return 0;
 
-	ret = snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
-	if (ret >= MAX_PATH)
-		return -1;
-	ret = check_file_exists(path);
-	if (ret)
-		return 0;
-
 	memset(path, 0, MAX_PATH);
-
 	return ret;
-
 }
 
 static int setup_hr_tick(void)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH 01/10] README: Drop "debug" from the tracing path
  2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
@ 2025-09-19 18:18   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:18 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> The tracing interface moved away from debug/ configfs. It moved one
> level up and the debug sub folder has a compatibility mount which will be
> removed.
> While at it I noticed that the -f option is long gone. Take the
> opportunity to update this, too.
> 
> Update the docs accordingly.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  README.markdown | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/README.markdown b/README.markdown
> index 3ab6ddf53c7ed..617b57e88614f 100644
> --- a/README.markdown
> +++ b/README.markdown
> @@ -57,15 +57,16 @@ then probably be regarded as real-time capable.
>  
>  What, however, if the latency is higher than acceptable? Then, the famous
>  "*latency fighting*" begins. For this purpose, the cyclictest tool provides the
> -`-b` option that causes a function tracing to be written to
> -`/sys/kernel/debug/tracing/trace`, if a specified latency threshold was
> -exceeded, for example:
> +`--breaktrace` option to halt tracing if the specified latency was exceeded. A
> +tracer must be configured upfront. The resulting trace can be invastigated in
> +`/sys/kernel/tracing/trace`, for example:
>  
> -    ./cyclictest -a -t -n -p99 -f -b100
> +    echo function > /sys/kernel/tracing/current_tracer
> +    cyclictest -a -t -n -p99 --tracemark --breaktrace 100
>  
>  This causes the program to abort execution, if the latency value exceeds 100
>  microseconds; the culprit can then be found in the trace output at
> -`/sys/kernel/debug/tracing/trace`.
> +`/sys/kernel/tracing/trace`.
>  The kernel function that was executed just before a latency of more than 100
>  microseconds was detected is marked with an exclamation mark such as
>  
> @@ -80,7 +81,7 @@ latency.
>  If the trace output is not obvious, it can be submitted to the OSADL Latency
>  Fight Support Service at
>  [latency-fighters@osadl.org](mailto:latency-fighters@osadl.org).
> -In addition to the output of `cat /sys/kernel/debug/tracing/trace`, the output
> +In addition to the output of `cat /sys/kernel/tracing/trace`, the output
>  of `lspci` and the `.config` file that was used to build the kernel in question
>  must be submitted. We are sure you understand that OSADL members will be served
>  first, but we promise to do our best to help everybody to successfully fight
> -- 
> 2.51.0
> 
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 02/10] rt-utils: Remove mount_debugfs()
  2025-09-03 11:17 ` [PATCH 02/10] rt-utils: Remove mount_debugfs() Sebastian Andrzej Siewior
@ 2025-09-19 18:20   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:20 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> The requirement to mount debugfs is very old. It originated from a time
> where it was "fairly new" and was not mounted by distros at the time.
> These days debugfs gets mounted during boot and more importantly the
> tracing directory moved out over 10years ago.
> 
> Don't try to mount debugfs anymore.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/include/rt-utils.h |  1 -
>  src/lib/rt-utils.c     | 29 -----------------------------
>  2 files changed, 30 deletions(-)
> 
> diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
> index f6b3fede06f7b..95964f70a6310 100644
> --- a/src/include/rt-utils.h
> +++ b/src/include/rt-utils.h
> @@ -12,7 +12,6 @@
>  
>  int check_privs(void);
>  char *get_debugfileprefix(void);
> -int mount_debugfs(char *);
>  int get_tracers(char ***);
>  int valid_tracer(char *);
>  
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 6bbd25a8ba53f..7e96950ef9887 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -99,32 +99,6 @@ char *get_debugfileprefix(void)
>  	return debugfileprefix;
>  }
>  
> -int mount_debugfs(char *path)
> -{
> -	char *mountpoint = path;
> -	char cmd[MAX_PATH];
> -	char *prefix;
> -	int ret;
> -
> -	/* if it's already mounted just return */
> -	prefix = get_debugfileprefix();
> -	if (strlen(prefix) != 0) {
> -		info(1, "debugfs mountpoint: %s\n", prefix);
> -		return 0;
> -	}
> -	if (!mountpoint)
> -		mountpoint = "/sys/kernel/debug";
> -
> -	sprintf(cmd, "mount -t debugfs debugfs %s", mountpoint);
> -	ret = system(cmd);
> -	if (ret != 0) {
> -		fprintf(stderr, "Error mounting debugfs at %s: %s\n",
> -			mountpoint, strerror(errno));
> -		return -1;
> -	}
> -	return 0;
> -}
> -
>  static char **tracer_list;
>  static char *tracer_buffer;
>  static int num_tracers;
> @@ -451,9 +425,6 @@ static int trace_file_exists(char *name)
>  
>  static void debugfs_prepare(void)
>  {
> -	if (mount_debugfs(NULL))
> -		fatal("could not mount debugfs");
> -
>  	fileprefix = get_debugfileprefix();
>  	if (!trace_file_exists("tracing_enabled") &&
>  	    !trace_file_exists("tracing_on"))
> -- 
> 2.51.0
> 
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs
  2025-09-03 11:17 ` [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs Sebastian Andrzej Siewior
@ 2025-09-19 18:29   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:29 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> get_debugfileprefix() used to look for debugfs and added the tracing
> suffix to it. In the early days it it was not always monted at the same
> destination. Later, that function got a fastpath to look directly at
> "/sys/kernel/debug/tracing". This avoids parsing the mounted filesystem
> and looking for debugfs.
> 
> Since about v4.1 (released over 10 years ago) that tracing folder moved
> out debugfs and got its own filesystem (tracefs) and is mounted at
> /sys/kernel/tracing. Since then that /sys/kernel/debug/tracing folder is
> just an automount/ alias to /sys/kernel/tracing.
> Since v6.17 that automount can be disabled and is schedulued for
> removal.
> Strart using tracefs directly instead that alias:
> - Replace that "debug" prefix with tracefs since debugfs is no longer
>   the thing that is used
> - Look directy for /sys/kernel/tracing
> - If it is not there, look for tracefs filesystem in case it is mounted
>   at an unusual spot.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/backfire/sendme.c         |  2 +-
>  src/include/rt-utils.h        |  2 +-
>  src/lib/rt-utils.c            | 51 ++++++++++++-----------------------
>  src/pmqtest/pmqtest.c         |  2 +-
>  src/ptsematest/ptsematest.c   |  2 +-
>  src/sigwaittest/sigwaittest.c |  2 +-
>  src/svsematest/svsematest.c   |  2 +-
>  7 files changed, 23 insertions(+), 40 deletions(-)
> 
> diff --git a/src/backfire/sendme.c b/src/backfire/sendme.c
> index da10397846f79..1c3e8b0c4c1b9 100644
> --- a/src/backfire/sendme.c
> +++ b/src/backfire/sendme.c
> @@ -45,7 +45,7 @@ static int interval = 1000;
>  static int kernvar(int mode, const char *name, char *value, size_t sizeofvalue)
>  {
>  	char filename[128];
> -	char *fileprefix = get_debugfileprefix();
> +	char *fileprefix = get_tracefs_prefix();
>  	int retval = 1;
>  	int path;
>  	size_t len_prefix = strlen(fileprefix), len_name = strlen(name);
> diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
> index 95964f70a6310..569023c5d3051 100644
> --- a/src/include/rt-utils.h
> +++ b/src/include/rt-utils.h
> @@ -11,7 +11,7 @@
>  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
>  
>  int check_privs(void);
> -char *get_debugfileprefix(void);
> +char *get_tracefs_prefix(void);
>  int get_tracers(char ***);
>  int valid_tracer(char *);
>  
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 7e96950ef9887..696bca2657d18 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -32,7 +32,7 @@
>  #define  MAX_COMMAND_LINE 4096
>  #define  MAX_TS_SIZE 64
>  
> -static char debugfileprefix[MAX_PATH];
> +static char tracefs_prefix[MAX_PATH];
>  static char *fileprefix;
>  static int trace_fd = -1;
>  static int tracemark_fd = -1;
> @@ -41,28 +41,21 @@ static char test_cmdline[MAX_COMMAND_LINE];
>  static char ts_start[MAX_TS_SIZE];
>  
>  /*
> - * Finds the tracing directory in a mounted debugfs
> + * Finds the tracing directory
>   */
> -char *get_debugfileprefix(void)
> +char *get_tracefs_prefix(void)
>  {
>  	char type[100];
>  	FILE *fp;
> -	int size;
>  	int found = 0;
>  	struct stat s;
>  
> -	if (debugfileprefix[0] != '\0')
> +	if (tracefs_prefix[0] != '\0')
>  		goto out;
>  
>  	/* look in the "standard" mount point first */
> -	if ((stat("/sys/kernel/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
> -		strcpy(debugfileprefix, "/sys/kernel/debug/tracing/");
> -		goto out;
> -	}
> -
> -	/* now look in the "other standard" place */
> -	if ((stat("/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
> -		strcpy(debugfileprefix, "/debug/tracing/");
> +	if ((stat("/sys/kernel/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
> +		strcpy(tracefs_prefix, "/sys/kernel/tracing/");
>  		goto out;
>  	}
>  
> @@ -73,14 +66,8 @@ char *get_debugfileprefix(void)
>  	while (fscanf(fp, "%*s %"
>  		      STR(MAX_PATH)
>  		      "s %99s %*s %*d %*d\n",
> -		      debugfileprefix, type) == 2) {
> -		if (strcmp(type, "debugfs") == 0) {
> -			found = 1;
> -			break;
> -		}
> -		/* stupid check for systemd-style autofs mount */
> -		if ((strcmp(debugfileprefix, "/sys/kernel/debug") == 0) &&
> -		    (strcmp(type, "systemd") == 0)) {
> +		      tracefs_prefix, type) == 2) {
> +		if (strcmp(type, "tracefs") == 0) {
>  			found = 1;
>  			break;
>  		}
> @@ -88,15 +75,11 @@ char *get_debugfileprefix(void)
>  	fclose(fp);
>  
>  	if (!found) {
> -		debugfileprefix[0] = '\0';
> +		tracefs_prefix[0] = '\0';
>  		goto out;
>  	}
> -
> -	size = sizeof(debugfileprefix) - strlen(debugfileprefix);
> -	strncat(debugfileprefix, "/tracing/", size);
> -
>  out:
> -	return debugfileprefix;
> +	return tracefs_prefix;
>  }
>  
>  static char **tracer_list;
> @@ -113,7 +96,7 @@ int get_tracers(char ***list)
>  	int ret;
>  	FILE *fp;
>  	char buffer[CHUNKSZ];
> -	char *prefix = get_debugfileprefix();
> +	char *prefix = get_tracefs_prefix();
>  	char *tmpbuf = NULL;
>  	char *ptr;
>  	int tmpsz = 0;
> @@ -193,7 +176,7 @@ int valid_tracer(char *tracername)
>   */
>  int setevent(char *event, char *val)
>  {
> -	char *prefix = get_debugfileprefix();
> +	char *prefix = get_tracefs_prefix();
>  	char buffer[MAX_PATH];
>  	int fd;
>  	int ret;
> @@ -417,19 +400,19 @@ static void close_tracemark_fd(void)
>  static int trace_file_exists(char *name)
>  {
>  	struct stat sbuf;
> -	char *tracing_prefix = get_debugfileprefix();
> +	char *tracing_prefix = get_tracefs_prefix();
>  	char path[MAX_PATH];
>  	strcat(strcpy(path, tracing_prefix), name);
>  	return stat(path, &sbuf) ? 0 : 1;
>  }
>  
> -static void debugfs_prepare(void)
> +static void tracefs_prepare(void)
>  {
> -	fileprefix = get_debugfileprefix();
> +	fileprefix = get_tracefs_prefix();
>  	if (!trace_file_exists("tracing_enabled") &&
>  	    !trace_file_exists("tracing_on"))
>  		warn("tracing_enabled or tracing_on not found\n"
> -		     "debug fs not mounted");
> +		     "tracefs not found");
>  }
>  
>  void tracemark(char *fmt, ...)
> @@ -455,7 +438,7 @@ void tracemark(char *fmt, ...)
>  
>  void enable_trace_mark(void)
>  {
> -	debugfs_prepare();
> +	tracefs_prepare();
>  	open_tracemark_fd();
>  }
>  
> diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
> index 04e36a1ad9795..a25b5cd2c24a1 100644
> --- a/src/pmqtest/pmqtest.c
> +++ b/src/pmqtest/pmqtest.c
> @@ -184,7 +184,7 @@ void *pmqthread(void *param)
>  			if (par->tracelimit && par->maxdiff > par->tracelimit) {
>  				char tracing_enabled_file[MAX_PATH];
>  
> -				strcpy(tracing_enabled_file, get_debugfileprefix());
> +				strcpy(tracing_enabled_file, get_tracefs_prefix());
>  				strcat(tracing_enabled_file, "tracing_on");
>  				int tracing_enabled =
>  				    open(tracing_enabled_file, O_WRONLY);
> diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
> index d21166946f6ac..00871d08df3a8 100644
> --- a/src/ptsematest/ptsematest.c
> +++ b/src/ptsematest/ptsematest.c
> @@ -107,7 +107,7 @@ void *semathread(void *param)
>  			if (par->tracelimit && par->maxdiff > par->tracelimit) {
>  				char tracing_enabled_file[MAX_PATH];
>  
> -				strcpy(tracing_enabled_file, get_debugfileprefix());
> +				strcpy(tracing_enabled_file, get_tracefs_prefix());
>  				strcat(tracing_enabled_file, "tracing_on");
>  				int tracing_enabled =
>  				    open(tracing_enabled_file, O_WRONLY);
> diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
> index 026cc81510157..e55f7fd2411f6 100644
> --- a/src/sigwaittest/sigwaittest.c
> +++ b/src/sigwaittest/sigwaittest.c
> @@ -163,7 +163,7 @@ void *semathread(void *param)
>  			if (par->tracelimit && par->maxdiff > par->tracelimit) {
>  				char tracing_enabled_file[MAX_PATH];
>  
> -				strcpy(tracing_enabled_file, get_debugfileprefix());
> +				strcpy(tracing_enabled_file, get_tracefs_prefix());
>  				strcat(tracing_enabled_file, "tracing_on");
>  				int tracing_enabled =
>  				    open(tracing_enabled_file, O_WRONLY);
> diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
> index f3cddf8545757..093f3c473f0a1 100644
> --- a/src/svsematest/svsematest.c
> +++ b/src/svsematest/svsematest.c
> @@ -170,7 +170,7 @@ void *semathread(void *param)
>  			if (par->tracelimit && par->maxdiff > par->tracelimit) {
>  				char tracing_enabled_file[MAX_PATH];
>  
> -				strcpy(tracing_enabled_file, get_debugfileprefix());
> +				strcpy(tracing_enabled_file, get_tracefs_prefix());
>  				strcat(tracing_enabled_file, "tracing_on");
>  				int tracing_enabled =
>  				    open(tracing_enabled_file, O_WRONLY);
> -- 
> 2.51.0
> 
> 
> 

   - a few quick spelling and grammar fixes
    Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing
  2025-09-03 11:17 ` [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing Sebastian Andrzej Siewior
@ 2025-09-19 18:39   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:39 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> Instead of looking at all possible folders underneath debugfs for
> tracing, look directly at /sys/kernel/tracing/. It no longer lives
> underneath debugfs.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/queuelat/queuelat.c               | 2 +-
>  src/rt-migrate-test/rt-migrate-test.c | 4 +---
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/src/queuelat/queuelat.c b/src/queuelat/queuelat.c
> index 28cf7abe83ae6..5a3d0c61a3fc4 100644
> --- a/src/queuelat/queuelat.c
> +++ b/src/queuelat/queuelat.c
> @@ -331,7 +331,7 @@ static void trace_open(void)
>  {
>  	int fd;
>  
> -	fd = open("/sys/kernel/debug/tracing/trace_marker", O_RDWR);
> +	fd = open("/sys/kernel/tracing/trace_marker", O_RDWR);
>  
>  	if (fd == -1) {
>  		perror("open");
> diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
> index 8afe0834905bd..ccc2caf77d735 100644
> --- a/src/rt-migrate-test/rt-migrate-test.c
> +++ b/src/rt-migrate-test/rt-migrate-test.c
> @@ -39,9 +39,7 @@ static void setup_ftrace_marker(void)
>  {
>  	struct stat st;
>  	char *files[] = {
> -		"/sys/kernel/debug/tracing/trace_marker",
> -		"/debug/tracing/trace_marker",
> -		"/debugfs/tracing/trace_marker",
> +		"/sys/kernel/tracing/trace_marker",
>  	};
>  	int ret;
>  	unsigned int i;
> -- 
> 2.51.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 05/10] rt-utils: Remove fileprefix.
  2025-09-03 11:17 ` [PATCH 05/10] rt-utils: Remove fileprefix Sebastian Andrzej Siewior
@ 2025-09-19 18:41   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:41 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> Remove fileprefix and use tracefs_prefix directly.
> There is no need for having both.
> Since sprintf() will complain that output buffer has the same size as
> the first input buffer so it could write more bytes use snprintf() and
> catch that possible overflow.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/lib/rt-utils.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 696bca2657d18..0e6e6056a4392 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -33,7 +33,6 @@
>  #define  MAX_TS_SIZE 64
>  
>  static char tracefs_prefix[MAX_PATH];
> -static char *fileprefix;
>  static int trace_fd = -1;
>  static int tracemark_fd = -1;
>  static __thread char tracebuf[TRACEBUFSIZ];
> @@ -363,12 +362,17 @@ int parse_mem_string(char *str, uint64_t *val)
>  static void open_tracemark_fd(void)
>  {
>  	char path[MAX_PATH];
> +	int n;
>  
>  	/*
>  	 * open the tracemark file if it's not already open
>  	 */
>  	if (tracemark_fd < 0) {
> -		sprintf(path, "%s/%s", fileprefix, "trace_marker");
> +		n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "trace_marker");
> +		if (n >= sizeof(path)) {
> +			warn("tracefs path too long\n");
> +			return;
> +		}
>  		tracemark_fd = open(path, O_WRONLY);
>  		if (tracemark_fd < 0) {
>  			warn("unable to open trace_marker file: %s\n", path);
> @@ -382,7 +386,11 @@ static void open_tracemark_fd(void)
>  	 * if we hit a breaktrace threshold
>  	 */
>  	if (trace_fd < 0) {
> -		sprintf(path, "%s/%s", fileprefix, "tracing_on");
> +		n = snprintf(path, sizeof(path), "%s/%s", tracefs_prefix, "tracing_on");
> +		if (n >= sizeof(path)) {
> +			warn("tracefs path too long\n");
> +			return;
> +		}
>  		if ((trace_fd = open(path, O_WRONLY)) < 0)
>  			warn("unable to open tracing_on file: %s\n", path);
>  	}
> @@ -408,7 +416,7 @@ static int trace_file_exists(char *name)
>  
>  static void tracefs_prepare(void)
>  {
> -	fileprefix = get_tracefs_prefix();
> +	get_tracefs_prefix();
>  	if (!trace_file_exists("tracing_enabled") &&
>  	    !trace_file_exists("tracing_on"))
>  		warn("tracing_enabled or tracing_on not found\n"
> -- 
> 2.51.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 06/10] rt-utils: Simplify trace_file_exists()
  2025-09-03 11:17 ` [PATCH 06/10] rt-utils: Simplify trace_file_exists() Sebastian Andrzej Siewior
@ 2025-09-19 18:42   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:42 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> Pass the tracefs folder prefix directly to stat instead making a copy of
> it. stat() is defined as not altering the path argument.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/lib/rt-utils.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 0e6e6056a4392..294fc9683a122 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -408,10 +408,7 @@ static void close_tracemark_fd(void)
>  static int trace_file_exists(char *name)
>  {
>  	struct stat sbuf;
> -	char *tracing_prefix = get_tracefs_prefix();
> -	char path[MAX_PATH];
> -	strcat(strcpy(path, tracing_prefix), name);
> -	return stat(path, &sbuf) ? 0 : 1;
> +	return stat(tracefs_prefix, &sbuf) ? 0 : 1;
>  }
>  
>  static void tracefs_prepare(void)
> -- 
> 2.51.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping
  2025-09-03 11:17 ` [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping Sebastian Andrzej Siewior
@ 2025-09-19 18:49   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:49 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> Most users write a trace mark and expect that the trace stops afterwads.
> Decoupling writting and stopping the trace so it can be used in context
> where trace stopping is not needed.
> 
> Make tracemark() writting just to the tracemark file.
> Add tracing_stop() which stops tracing and let current users of
> tracemark() use it.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/cyclictest/cyclictest.c         | 1 +
>  src/include/rt-utils.h              | 1 +
>  src/lib/rt-utils.c                  | 8 ++++++--
>  src/oslat/oslat.c                   | 1 +
>  src/sched_deadline/cyclicdeadline.c | 1 +
>  5 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index 890da5d869c92..b4bce8915b432 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -852,6 +852,7 @@ static void *timerthread(void *param)
>  				break_thread_id = stat->tid;
>  				tracemark("hit latency threshold (%llu > %d)",
>  					  (unsigned long long) diff, tracelimit);
> +				tracing_stop();
>  				break_thread_value = diff;
>  			}
>  			pthread_mutex_unlock(&break_thread_id_lock);
> diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
> index 569023c5d3051..e148dd77fd7d8 100644
> --- a/src/include/rt-utils.h
> +++ b/src/include/rt-utils.h
> @@ -31,6 +31,7 @@ int parse_mem_string(char *str, uint64_t *val);
>  
>  void enable_trace_mark(void);
>  void tracemark(char *fmt, ...) __attribute__((format(printf, 1, 2)));
> +void tracing_stop(void);
>  void disable_trace_mark(void);
>  
>  #define MSEC_PER_SEC		1000
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 294fc9683a122..e504b17738411 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -427,7 +427,7 @@ void tracemark(char *fmt, ...)
>  
>  	/* bail out if we're not tracing */
>  	/* or if the kernel doesn't support trace_mark */
> -	if (tracemark_fd < 0 || trace_fd < 0)
> +	if (tracemark_fd < 0)
>  		return;
>  
>  	va_start(ap, fmt);
> @@ -436,8 +436,12 @@ void tracemark(char *fmt, ...)
>  
>  	/* write the tracemark message */
>  	write(tracemark_fd, tracebuf, len);
> +}
>  
> -	/* now stop any trace */
> +void tracing_stop(void)
> +{
> +	if (trace_fd < 0)
> +		return;
>  	write(trace_fd, "0\n", 2);
>  }
>  
> diff --git a/src/oslat/oslat.c b/src/oslat/oslat.c
> index 9e5a08a2fbd92..4291221dc6521 100644
> --- a/src/oslat/oslat.c
> +++ b/src/oslat/oslat.c
> @@ -340,6 +340,7 @@ static void insert_bucket(struct thread *t, stamp_t value)
>  		char *line = "%s: Trace threshold (%d us) triggered on cpu %d with %.*f us!\n";
>  		tracemark(line, g.app_name, g.trace_threshold, t->core_i,
>  			  g.precision, us);
> +		tracing_stop();
>  		err_quit(line, g.app_name, g.trace_threshold, t->core_i,
>  			 g.precision, us);
>  	}
> diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
> index 04e61edc68d83..e2f827deb275a 100644
> --- a/src/sched_deadline/cyclicdeadline.c
> +++ b/src/sched_deadline/cyclicdeadline.c
> @@ -885,6 +885,7 @@ void *run_deadline(void *data)
>  				break_thread_value = stat->max;
>  				tracemark("hit latency threshold (%lld > %d)",
>  						 (unsigned long long) stat->max, tracelimit);
> +				tracing_stop();
>  			}
>  			pthread_mutex_unlock(&break_thread_id_lock);
>  			break;
> -- 
> 2.51.0
> 
> 
    - Fixed spelling of "writing" and "afterwards"
    Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation
  2025-09-03 11:17 ` [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation Sebastian Andrzej Siewior
@ 2025-09-19 18:52   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:52 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> Somehow cyclicdeadline has its implementation to write to the
> trace_marker and it also uses tracemark() from rt-utils.
> Since now tracemark() is not stopping the trace anymore it can be used
> as-is.
> This has the advantage of removing some code and automaticly using
> trace_marker from tracefs :)
> 
> Remove ftrace_write(), setup_ftrace_marker() and use tracemark()
> instead.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/sched_deadline/cyclicdeadline.c | 116 ++--------------------------
>  1 file changed, 5 insertions(+), 111 deletions(-)
> 
> diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
> index e2f827deb275a..82e640409ecef 100644
> --- a/src/sched_deadline/cyclicdeadline.c
> +++ b/src/sched_deadline/cyclicdeadline.c
> @@ -72,8 +72,6 @@ struct sched_data {
>  	int bufmsk;
>  
>  	struct thread_stat stat;
> -
> -	char buff[BUFSIZ+1];
>  };
>  
>  static int shutdown;
> @@ -92,7 +90,6 @@ static int cpu_count;
>  static int all_cpus;
>  static int nr_threads;
>  static int use_nsecs;
> -static int mark_fd;
>  static int quiet;
>  static char jsonfile[MAX_PATH];
>  
> @@ -136,107 +133,6 @@ static const char *find_debugfs(void)
>  	return debugfs;
>  }
>  
> -static int my_vsprintf(char *buf, int size, const char *fmt, va_list ap)
> -{
> -	const char *p;
> -	char tmp[100];
> -	char *s = buf;
> -	char *end = buf + size;
> -	char *str;
> -	long long lng;
> -	int l;
> -	int i;
> -
> -	end[-1] = 0;
> -
> -	for (p = fmt; *p && s < end; p++) {
> -		if (*p == '%') {
> -			l = 0;
> - again:
> -			p++;
> -			switch (*p) {
> -			case 's':
> -				if (l)
> -					fatal("Illegal print format l used with %%s\n");
> -				str = va_arg(ap, char *);
> -				l = strlen(str);
> -				strncpy(s, str, end - s);
> -				s += l;
> -				break;
> -			case 'l':
> -				l++;
> -				goto again;
> -			case 'd':
> -				if (l == 1) {
> -					if (sizeof(long) == 8)
> -						l = 2;
> -				}
> -				if (l == 2)
> -					lng = va_arg(ap, long long);
> -				else if (l > 2)
> -					fatal("Illegal print format l=%d\n", l);
> -				else
> -					lng = va_arg(ap, int);
> -				i = 0;
> -				while (lng > 0) {
> -					tmp[i++] = (lng % 10) + '0';
> -					lng /= 10;
> -				}
> -				tmp[i] = 0;
> -				l = strlen(tmp);
> -				if (!l) {
> -					*s++ = '0';
> -				} else {
> -					while (l)
> -						*s++ = tmp[--l];
> -				}
> -				break;
> -			default:
> -				fatal("Illegal print format '%c'\n", *p);
> -			}
> -			continue;
> -		}
> -		*s++ = *p;
> -	}
> -
> -	return s - buf;
> -}
> -
> -static void ftrace_write(char *buf, const char *fmt, ...)
> -{
> -	va_list ap;
> -	int n;
> -
> -	if (mark_fd < 0)
> -		return;
> -
> -	va_start(ap, fmt);
> -	n = my_vsprintf(buf, BUFSIZ, fmt, ap);
> -	va_end(ap);
> -
> -	write(mark_fd, buf, n);
> -}
> -
> -static void setup_ftrace_marker(void)
> -{
> -	struct stat st;
> -	const char *debugfs = find_debugfs();
> -	char files[strlen(debugfs) + strlen("/tracing/trace_marker") + 1];
> -	int ret;
> -
> -	if (strlen(debugfs) == 0)
> -		return;
> -
> -	sprintf(files, "%s/tracing/trace_marker", debugfs);
> -	ret = stat(files, &st);
> -	if (ret >= 0)
> -		goto found;
> -	/* Do nothing if not mounted */
> -	return;
> -found:
> -	mark_fd = open(files, O_WRONLY);
> -}
> -
>  /*
>   * Return true if file exists
>   */
> @@ -804,16 +700,15 @@ static u64 do_runtime(struct sched_data *sd, u64 period)
>  		 * preempting us when we started. If that's the case then
>  		 * adjust the current period.
>  		 */
> -		ftrace_write(sd->buff,
> -			     "Adjusting period: now: %lld period: %lld delta:%lld%s\n",
> -			     now, period, delta, delta > sd->deadline_us / 2 ?
> -			     " HUGE ADJUSTMENT" : "");
> +		tracemark("Adjusting period: now: %lld period: %lld delta:%lld%s\n",
> +			  now, period, delta, delta > sd->deadline_us / 2 ?
> +			  " HUGE ADJUSTMENT" : "");
>  		period = now;
>  		next_period = period + sd->deadline_us;
>  	}
>  
> -	ftrace_write(sd->buff, "start at %lld off=%lld (period=%lld next=%lld)\n",
> -		     now, now - period, period, next_period);
> +	tracemark("start at %lld off=%lld (period=%lld next=%lld)\n",
> +		  now, now - period, period, next_period);
>  
>  
>  	diff = now - period;
> @@ -1293,7 +1188,6 @@ int main(int argc, char **argv)
>  	if (mlockall(MCL_CURRENT|MCL_FUTURE) == -1)
>  		warn("mlockall");
>  
> -	setup_ftrace_marker();
>  	if (tracelimit && trace_marker)
>  		enable_trace_mark();
>  
> -- 
> 2.51.0
> 
> 
    - fixed spelling of automatically
    Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf()
  2025-09-03 11:17 ` [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf() Sebastian Andrzej Siewior
@ 2025-09-19 18:54   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:54 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> The code simply assumes that the built path does not exceed MAX_PATH.
> Since the previous change the compiler started to complain but I don't
> see a connection other than the removal of one find_debugfs() user.
> 
> Make sure the resulting path is not truncated.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/sched_deadline/cyclicdeadline.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
> index 82e640409ecef..89b7c0b8deb21 100644
> --- a/src/sched_deadline/cyclicdeadline.c
> +++ b/src/sched_deadline/cyclicdeadline.c
> @@ -160,12 +160,16 @@ static int fill_sched_features(char *path)
>  	if (strlen(debugfs) == 0)
>  		return -1;
>  
> -	snprintf(path, MAX_PATH, "%s/sched/features", debugfs);
> +	ret = snprintf(path, MAX_PATH, "%s/sched/features", debugfs);
> +	if (ret >= MAX_PATH)
> +		return -1;
>  	ret = check_file_exists(path);
>  	if (ret)
>  		return 0;
>  
> -	snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
> +	ret = snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
> +	if (ret >= MAX_PATH)
> +		return -1;
>  	ret = check_file_exists(path);
>  	if (ret)
>  		return 0;
> -- 
> 2.51.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features
  2025-09-03 11:17 ` [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features Sebastian Andrzej Siewior
@ 2025-09-19 18:55   ` John Kacur
  0 siblings, 0 replies; 21+ messages in thread
From: John Kacur @ 2025-09-19 18:55 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-rt-users, Clark Williams, Steven Rostedt



On Wed, 3 Sep 2025, Sebastian Andrzej Siewior wrote:

> sched_features was renamed to sched/features in commit 8a99b6833c884
> ("sched: Move SCHED_DEBUG sysctl to debugfs") which was merged in v5.13.
> 
> It is probably okay to remove it from the fallback list.
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  src/sched_deadline/cyclicdeadline.c | 9 ---------
>  1 file changed, 9 deletions(-)
> 
> diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
> index 89b7c0b8deb21..4ee3717a767e9 100644
> --- a/src/sched_deadline/cyclicdeadline.c
> +++ b/src/sched_deadline/cyclicdeadline.c
> @@ -167,17 +167,8 @@ static int fill_sched_features(char *path)
>  	if (ret)
>  		return 0;
>  
> -	ret = snprintf(path, MAX_PATH, "%s/sched_features", debugfs);
> -	if (ret >= MAX_PATH)
> -		return -1;
> -	ret = check_file_exists(path);
> -	if (ret)
> -		return 0;
> -
>  	memset(path, 0, MAX_PATH);
> -
>  	return ret;
> -
>  }
>  
>  static int setup_hr_tick(void)
> -- 
> 2.51.0
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-09-19 18:55 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 11:17 [PATCH 00/10] rt-tests: Remove debugfs usage Sebastian Andrzej Siewior
2025-09-03 11:17 ` [PATCH 01/10] README: Drop "debug" from the tracing path Sebastian Andrzej Siewior
2025-09-19 18:18   ` John Kacur
2025-09-03 11:17 ` [PATCH 02/10] rt-utils: Remove mount_debugfs() Sebastian Andrzej Siewior
2025-09-19 18:20   ` John Kacur
2025-09-03 11:17 ` [PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs Sebastian Andrzej Siewior
2025-09-19 18:29   ` John Kacur
2025-09-03 11:17 ` [PATCH 04/10] queuelat, rt-migrate-test: Use tracefs for tracing Sebastian Andrzej Siewior
2025-09-19 18:39   ` John Kacur
2025-09-03 11:17 ` [PATCH 05/10] rt-utils: Remove fileprefix Sebastian Andrzej Siewior
2025-09-19 18:41   ` John Kacur
2025-09-03 11:17 ` [PATCH 06/10] rt-utils: Simplify trace_file_exists() Sebastian Andrzej Siewior
2025-09-19 18:42   ` John Kacur
2025-09-03 11:17 ` [PATCH 07/10] rt-utils: Decouple writting trace-marks with trace stopping Sebastian Andrzej Siewior
2025-09-19 18:49   ` John Kacur
2025-09-03 11:17 ` [PATCH 08/10] sched_deadline: Use tracemark() from rt-utils instead cusstom implementation Sebastian Andrzej Siewior
2025-09-19 18:52   ` John Kacur
2025-09-03 11:17 ` [PATCH 09/10] sched_deadline: Check the resulting size returned from snprintf() Sebastian Andrzej Siewior
2025-09-19 18:54   ` John Kacur
2025-09-03 11:17 ` [PATCH 10/10] cyclicdeadline: Don't test for /sys/kernel/debug/sched_features Sebastian Andrzej Siewior
2025-09-19 18:55   ` John Kacur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).