Skip to contentSkip to conversation

utils: Ensure output buffers are always line based

PATCH Applied Richard Purdie 2 participants 2 messages Mar 7 – Mar 8

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: Ensure output buffers are always line based

When running slow ptests, we can see an issue where the tests are writing output but it doesn't make it to the process (e.g. ssh connection) running ptest-runner.

The issue is that the standard buffering for non-interactive terminals is 8kb and some ptests don't output enough data to trigger a write. This can lead to the controlling connection timing out.

This change forces the output streams to be line buffered in all cases. Most ptest output would contain newlines so this should work well. stderr can be unbuffered by default but making it consistent here seems the best approach.

Testing with this change on slow ptest runs (e.g. qemu emulated) showed much more consistent data with this change.

---
 utils.c | 2 ++
 1 file changed, 2 insertions(+)
utils.c +2 -0
index 6cfa26f..192d3d0 100644
@@ -434,11 +434,13 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
 				set_nonblocking(pipefd_stdout[PIPE_READ]);
 				pfds[0].fd = pipefd_stdout[PIPE_READ];
 				pfds[0].events = POLLIN;
+				setlinebuf(fp);
 				dest_fps[0] = fp;
 
 				set_nonblocking(pipefd_stderr[PIPE_READ]);
 				pfds[1].fd = pipefd_stderr[PIPE_READ];
 				pfds[1].events = POLLIN;
+				setlinebuf(fp_stderr);
 				dest_fps[1] = fp_stderr;
 
 				while (true) {
Applied
#1 lore raw

Applied!, Thanks!

Quoted 45 lines · Richard Purdie

When running slow ptests, we can see an issue where the tests are writing output
but it doesn't make it to the process (e.g. ssh connection) running ptest-runner.

The issue is that the standard buffering for non-interactive terminals is 8kb and
some ptests don't output enough data to trigger a write. This can lead to the controlling connection timing out.

This change forces the output streams to be line buffered in all cases. Most
ptest output would contain newlines so this should work well. stderr can be unbuffered by default but making it consistent here seems the best approach.

Testing with this change on slow ptest runs (e.g. qemu emulated) showed much
more consistent data with this change.

---
 utils.c | 2 ++
 1 file changed, 2 insertions(+)
utils.c +2 -0
index 6cfa26f..192d3d0 100644
@@ -434,11 +434,13 @@ run_ptests(struct ptest_list *head, const struct
 ptest_options opts,
                                set_nonblocking(pipefd_stdout[PIPE_READ]);
                                pfds[0].fd = pipefd_stdout[PIPE_READ];
                                pfds[0].events = POLLIN;
+                               setlinebuf(fp);
                                dest_fps[0] = fp;
 
                                set_nonblocking(pipefd_stderr[PIPE_READ]);
                                pfds[1].fd = pipefd_stderr[PIPE_READ];
                                pfds[1].events = POLLIN;
+                               setlinebuf(fp_stderr);
                                dest_fps[1] = fp_stderr;
 
                                while (true) {