[URGENT] trace-cmd: Fix for all stable versions for up coming fix in Linux v3.10

Steven Rostedt rostedt at goodmis.org
Sat Mar 2 00:32:17 UTC 2013

I recently fixed a long standing bug in the splice code for ftrace. This
was something that I wanted fixed so that trace-cmd would work better.
The fix is to finally have the splice system call block until data is
available, instead of having trace-cmd poll reading the trace_pipe_raw
data file.

This fix is queued to go in to mainline for v3.10. Unfortunately, even
though I've wanted this for trace-cmd since day one, my trace-cmd
implementation to use this had a bug in it, that the kernel fix now
triggers. Basically, when tracing is finished (when the command that is
being recorded is done), trace-cmd stops tracing, signals the recording
threads to finish and then waits for the recording threads to exit.

Well, there's a race where the recording threads may make one last read
of the splice system call. The problem is that this read is blocking.
Now that tracing has been disabled by the main thread, this read will
block indefinitely as there is no more data to read. The main thread
waiting for the recorder threads to finish will continue to wait.
Hitting Ctrl-C kicks it and the threads all finish, but that's not what
should happen. The threads should finish when tracing is done, and not
require input from the user.

The fix is quite simple, and has been included in the latest trace-cmd
repo. I back ported the fix to the following versions, and tested all of
them running on a kernel with the splice fix. Without this update, all
the versions can end up blocked on splice and require user input to
continue. With the fix, they all work fine.

Here's the new stable trace-cmd versions that contain the fix:


and the main repo has it as well.

-- Steve

>From 4b04db879a99d600988bc302e7ac88e8c012f98f Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (Red Hat)" <rostedt at goodmis.org>
Date: Thu, 28 Feb 2013 11:29:43 -0500
Subject: [PATCH] trace-cmd: Do not block on reads when record is finished

Starting with Linux v3.10, trace_pipe_raw will block on reads.
We need to make sure that when the trace is done, the reads do
not block, and flushing finishes reading the ring buffer.

Signed-off-by: Steven Rostedt <rostedt at goodmis.org>
 trace-recorder.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/trace-recorder.c b/trace-recorder.c
index 1b9723d..4e15b86 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -249,9 +249,15 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s
 void tracecmd_stop_recording(struct tracecmd_recorder *recorder)
+	long flags;
 	if (!recorder)
+	/* Do not block on reads for flushing */
+	flags = fcntl(recorder->trace_fd, F_GETFL);
+	fcntl(recorder->trace_fd, F_SETFL, flags | O_NONBLOCK);
 	recorder->stop = 1;

More information about the Ubuntu-motu mailing list