Re: [PATCH perf-tools-next v12 01/10] perf ftrace: Handle signals, non-blocking reads and pager exits in __cmd_ftrace()

From: Aaron Tomlin

Date: Sat Oct 31 2026 - 18:29:51 EST


On Sat, Oct 31, 2026 at 12:12:32AM -0700, Namhyung Kim wrote:
> On Sun, Oct 25, 2026 at 10:57:26PM -0400, Aaron Tomlin wrote:
> > In __cmd_ftrace(), trace_fd is configured for non-blocking I/O via
> > fcntl(trace_fd, F_SETFL, O_NONBLOCK) and polled using poll(). However,
> > the polling loop previously treated any negative return code from poll()
> > or read() as an unrecoverable failure.
> >
> > If poll() or read() is interrupted by a non-fatal signal (i.e. SIGWINCH
> > upon terminal resizing), errno is set to EINTR. Furthermore, read() on
> > trace_pipe can return EAGAIN/EWOULDBLOCK even after poll() indicates
> > POLLIN (for instance, under concurrent readers, spurious wakeups, or
> > block-mode trace iterator options). In all such cases, breaking from the
> > loop causes perf ftrace to terminate tracing prematurely.
> >
> > Additionally, output errors on stdout (i.e. when a pager or consumer
> > process exits, closing the downstream pipe) were ignored by fflush(),
> > leaving __cmd_ftrace() polling indefinitely until the workload
> > completes.
> >
> > Resolve these concerns by retrying poll() upon receiving EINTR, retrying
> > read() on EAGAIN, EWOULDBLOCK, and EINTR, and breaking on EOF (n == 0).
> > Furthermore, detect stdout errors and broken pipes via fflush() and
> > ferror() to exit immediately when the downstream output sink closes, and
> > handle EINTR and ferror(stdout) cleanly in the subsequent buffer
> > draining loop.
> >
> > Fixes: d01f4e8db22c ("perf ftrace: Introduce new 'ftrace' tool")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Tested-by: Ian Rogers <irogers@xxxxxxxxxx>
> > Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
> > Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
>
> Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>
>
> Thanks,
> Namhyung


Thank you,
--
Aaron Tomlin