* [PATCH 1/3] libtracefs utest: Scale trace cpu pipe test to the sub-buffer size
2026-11-18 13:30 [PATCH 0/3] libtracefs utest: Fix trace cpu pipe and test_mem failures Frank Heimes
@ 2026-11-18 13:30 ` Frank Heimes
2026-11-18 13:30 ` [PATCH 2/3] libtracefs utest: Run valgrind memory test with fair scheduling Frank Heimes
2026-11-18 13:30 ` [PATCH 3/3] libtracefs utest: Account for overruns in the trace cpu pipe test Frank Heimes
2 siblings, 0 replies; 4+ messages in thread
From: Frank Heimes @ 2026-11-18 13:30 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt, Benjamin Drung, Jamie Dolan
The last step of the "trace cpu pipe" test writes events_per_buf * 1000
events, i.e. the equivalent of 1000 sub-buffers, while a reader thread
copies the ring buffer with tracefs_cpu_write() into a temporary file
in /tmp.
When the ring buffer is memory mapped, tracefs_cpu_write() writes a full
sub-buffer, padded with zeros, for every read that returns data. As the
reader thread polls continuously, most reads only return a few events,
so the amount of data written is roughly the number of reads times the
sub-buffer size.
On architectures with a 64K PAGE_SIZE like ppc64el the sub-buffers are
16 times larger than on x86 and events_per_buf is about 3276 instead of
about 200, so the test generates 3.3 million events and writes more
than 13 GB into the temporary file. With /tmp being a tmpfs (as on several
distributions) this fails with ENOSPC:
Test: trace cpu pipe ...FAILED
1. tracefs-utest.c:1966 - ret >= 0
2. tracefs-utest.c:1970 - cnt == expect
3. tracefs-utest.c:1966 - ret >= 0
4. tracefs-utest.c:1970 - cnt == expect
Scale the number of sub-buffers to the sub-buffer size, using 1000
sub-buffers of 4K as reference. This keeps the test unchanged for 4K
sub-buffers (1000) and uses 62 sub-buffers for 64K sub-buffers, which
still is a multiple of the ring buffer size.
Link: https://bugs.launchpad.net/bugs/2062119
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
---
utest/tracefs-utest.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index e48232c..44e8fb4 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -1973,15 +1973,27 @@ static void test_cpu_pipe(struct test_cpu_data *data, int expect)
static void test_instance_trace_cpu_pipe(struct tracefs_instance *instance, bool map)
{
struct test_cpu_data data;
+ int big_num;
if (setup_trace_cpu(instance, &data, true, map))
return;
+ /*
+ * Scale the number of sub-buffers to write to the sub-buffer size,
+ * using 1000 sub-buffers of 4K as reference. With the memory mapped
+ * buffer every read writes a full (zero padded) sub-buffer, which on
+ * architectures with large sub-buffers (64K PAGE_SIZE) can easily
+ * fill the file system holding the temporary file.
+ */
+ big_num = 1000 * 4096 / data.bufsize;
+ if (big_num < 1)
+ big_num = 1;
+
test_cpu_pipe(&data, 1);
test_cpu_pipe(&data, data.events_per_buf / 2);
test_cpu_pipe(&data, data.events_per_buf);
test_cpu_pipe(&data, data.events_per_buf + 1);
- test_cpu_pipe(&data, data.events_per_buf * 1000);
+ test_cpu_pipe(&data, data.events_per_buf * big_num);
shutdown_trace_cpu(&data);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/3] libtracefs utest: Run valgrind memory test with fair scheduling
2026-11-18 13:30 [PATCH 0/3] libtracefs utest: Fix trace cpu pipe and test_mem failures Frank Heimes
2026-11-18 13:30 ` [PATCH 1/3] libtracefs utest: Scale trace cpu pipe test to the sub-buffer size Frank Heimes
@ 2026-11-18 13:30 ` Frank Heimes
2026-11-18 13:30 ` [PATCH 3/3] libtracefs utest: Account for overruns in the trace cpu pipe test Frank Heimes
2 siblings, 0 replies; 4+ messages in thread
From: Frank Heimes @ 2026-11-18 13:30 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt, Benjamin Drung, Jamie Dolan
valgrind serializes the threads of the program under test with a lock
that, by default, is not handed out fairly. A thread that never blocks
can therefore get the lock again and again, starving the other threads.
The "trace pid events filter" and "trace pid function filter" tests
start two threads that spin calling getppid() until the main thread
sets data->stop after msleep(100). Under valgrind the spinning threads
can starve the main thread, so data->stop is never set and the test
hangs until the test runner times out. This is reproducible on ppc64el
where make test_mem hangs in "trace pid events filter" for hours.
Run valgrind with --fair-sched=yes, which makes valgrind schedule the
threads in a round-robin fashion.
Link: https://bugs.launchpad.net/bugs/2172071
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
---
Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile
index 20ae41f..b9f3853 100644
--- a/Makefile
+++ b/Makefile
@@ -217,6 +217,7 @@ ifneq ($(shell id -u), 0)
$(error "The unit test should be run as root, as it reuqires full access to tracefs")
endif
CK_FORK=no LD_LIBRARY_PATH=$(bdir) $(VALGRIND) \
+ --fair-sched=yes \
--show-leak-kinds=all --leak-resolution=high \
--leak-check=full --show-possibly-lost=yes \
--track-origins=yes -s \
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] libtracefs utest: Account for overruns in the trace cpu pipe test
2026-11-18 13:30 [PATCH 0/3] libtracefs utest: Fix trace cpu pipe and test_mem failures Frank Heimes
2026-11-18 13:30 ` [PATCH 1/3] libtracefs utest: Scale trace cpu pipe test to the sub-buffer size Frank Heimes
2026-11-18 13:30 ` [PATCH 2/3] libtracefs utest: Run valgrind memory test with fair scheduling Frank Heimes
@ 2026-11-18 13:30 ` Frank Heimes
2 siblings, 0 replies; 4+ messages in thread
From: Frank Heimes @ 2026-11-18 13:30 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt, Benjamin Drung, Jamie Dolan
The "trace cpu pipe" test generates events on CPU 0 while a reader
thread copies the ring buffer with tracefs_cpu_write() into a file, and
then expects all events in the file. For the large step of the test the
number of events is about three times what the ring buffer can hold, so
the test only passes if the reader thread keeps up with the writer.
That is not the case when running under valgrind with the memory mapped
ring buffer, where the reader walks every event in user space. The ring
buffer then overwrites the oldest events, and the test fails in
"make test_mem" on all architectures (amd64, ppc64el, ...):
Test: trace cpu pipe ...missed events -1
FAILED
1. tracefs-utest.c:1970 - cnt == expect
2. tracefs-utest.c:1970 - cnt == expect
The kernel accounts for every overwritten event in the overrun counter
of the per CPU stats. For example on ppc64el:
map=1 expect=203112 cnt=85176 overrun=117936
Check that every event was either read or accounted for as overrun by
the kernel. If no events are overwritten, which is the normal case
without valgrind, the test is as strict as before.
Link: https://bugs.launchpad.net/bugs/2172071
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
---
utest/tracefs-utest.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c
index 44e8fb4..877f09f 100644
--- a/utest/tracefs-utest.c
+++ b/utest/tracefs-utest.c
@@ -1942,9 +1942,24 @@ static void *trace_cpu_thread(void *arg)
return (void *)ret;
}
+static ssize_t get_cpu_overrun(struct tracefs_instance *instance, int cpu)
+{
+ struct tracefs_buffer_stat *tstat;
+ ssize_t overrun;
+
+ tstat = tracefs_instance_get_stat(instance, cpu);
+ if (!tstat)
+ return -1;
+ overrun = tracefs_buffer_stat_overrun(tstat);
+ tracefs_instance_put_stat(tstat);
+
+ return overrun;
+}
+
static void test_cpu_pipe(struct test_cpu_data *data, int expect)
{
pthread_t thread;
+ ssize_t overrun;
void *retval;
long ret;
int cnt;
@@ -1952,6 +1967,10 @@ static void test_cpu_pipe(struct test_cpu_data *data, int expect)
tracefs_instance_file_clear(data->instance, "trace");
ftruncate(data->fd, 0);
+ /* The events are generated on CPU 0, see setup_trace_cpu() */
+ overrun = get_cpu_overrun(data->instance, 0);
+ CU_TEST(overrun >= 0);
+
data->done = false;
pthread_create(&thread, NULL, trace_cpu_thread, data);
@@ -1967,7 +1986,14 @@ static void test_cpu_pipe(struct test_cpu_data *data, int expect)
cnt = read_trace_cpu_file(data);
- CU_TEST(cnt == expect);
+ /*
+ * If the reader can not keep up with the writer (for example
+ * when running under valgrind), the ring buffer overwrites the
+ * oldest events. Those events are lost, but accounted for by
+ * the kernel in the overrun counter.
+ */
+ overrun = get_cpu_overrun(data->instance, 0) - overrun;
+ CU_TEST(cnt + overrun == expect);
}
static void test_instance_trace_cpu_pipe(struct tracefs_instance *instance, bool map)
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread