From: Simon Glass <simon.glass@canonical.com> In some cases the target sends a lot of data. This is typically limited to 4K on Linux (PTY size), but when (say) 100K of console output is sent, pytest uses all available CPU, often only reading 50 bytes at a time. Add a 1ms delay before polling, to help with this. Increase the read-buffer size from 1KB to 4KB to reduce the number of system calls. To test this change, dm_test_host() was modified to do 10 malloc_dump() calls, thus producing a lot of output. The impact of this patch is: total time 17s -> 6s total CPU 40s -> 18s Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- (no changes since v1) test/py/console_base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/py/console_base.py b/test/py/console_base.py index 86b6da1f5b0..6d117413aa3 100644 --- a/test/py/console_base.py +++ b/test/py/console_base.py @@ -32,6 +32,10 @@ pattern_lab_mode = re.compile('{lab mode.*}') TIMEOUT_MS = 30000 # Standard timeout TIMEOUT_CMD_MS = 10000 # Command-echo timeout +# Maximum bytes to read at once from the console. 4KB matches the typical +# Linux PTY buffer size (N_TTY_BUF_SIZE), so there's no benefit to larger. +RECV_BUF_SIZE = 4096 + # Timeout for board preparation in lab mode. This needs to be enough to build # U-Boot, write it to the board and then boot the board. Since this process is # under the control of another program (e.g. Labgrid), it will failure sooner @@ -803,7 +807,10 @@ class ConsoleBase(): events = self.p.poll.poll(poll_maxwait) if not events: raise Timeout() - c = self.p.receive(1024) + # Small delay to let more data accumulate in PTY buffer, to + # reduce CPU usage for test.py from 100% + time.sleep(0.001) + c = self.p.receive(RECV_BUF_SIZE) if self.logfile_read: self.logfile_read.write(c) self.buf += c -- 2.43.0