From patchwork Sat Jan 3 20:04:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1244 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470831; bh=yysf9I36JlwMV6vigd/BBd9aBZ5RfLymmfeMshvVCsc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hlXGNkoMZzVU1qpg4h6dy37NDr96aP3pQcAWWRFmdtj9AMhjIv3HgRqaUOS/nNFbA +YiZc9F3XOudPTG8wL3kqtPUecfi7pG6p7FdHw4hFNhpuZDqCRrmCmCGx1zgKAnaBN sY4gCN65LDHxWdrqnaZNZhGpujLWP3ufDNK94JXbMnLINfXGP6tXV0AAQkrTh3aPs9 sMkJq1pY37TmKX+uQ7OucVUD1euup0QSFhNwLuN+E0/a84FP1xr68QMl6XcXPqX0XG Fij9fU5k4kfEiGOoE5utbsJ7uFoFdEdzFs8MEs/eNR9dXgA23dmbOBsXWssapi4ZIL rdSHNy0OUYnEQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2838269095 for ; Sat, 3 Jan 2026 13:07:11 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id f8aGZfN6dugT for ; Sat, 3 Jan 2026 13:07:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470831; bh=yysf9I36JlwMV6vigd/BBd9aBZ5RfLymmfeMshvVCsc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hlXGNkoMZzVU1qpg4h6dy37NDr96aP3pQcAWWRFmdtj9AMhjIv3HgRqaUOS/nNFbA +YiZc9F3XOudPTG8wL3kqtPUecfi7pG6p7FdHw4hFNhpuZDqCRrmCmCGx1zgKAnaBN sY4gCN65LDHxWdrqnaZNZhGpujLWP3ufDNK94JXbMnLINfXGP6tXV0AAQkrTh3aPs9 sMkJq1pY37TmKX+uQ7OucVUD1euup0QSFhNwLuN+E0/a84FP1xr68QMl6XcXPqX0XG Fij9fU5k4kfEiGOoE5utbsJ7uFoFdEdzFs8MEs/eNR9dXgA23dmbOBsXWssapi4ZIL rdSHNy0OUYnEQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1763E68FD2 for ; Sat, 3 Jan 2026 13:07:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470828; bh=W6HPVerUpqgQPLe5iG/UrJR3Rd1IJTQJ4+CcCNwhBSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WGKwidcwe8tt0wQhTTCyo4AxXemiJuVpJS07aOWsnjiy5pqIB+lgfL2S/738Hbefj K1jQdqJOgzMcpjG5SWfGjMLCvDiZVeXxd0fIJG/LKs3Ra9zq6zVP4Qi8oYqT8cPorN YDUOh6ATAonoY7lJAwpHfPj6us+BAdzq/uGahjKkYC3HhJrxJvNhj5Quv/eBcH/l2C 2j9H1jzVGkZKwf8zNPF9RER2vRHMhX4ANIOvEOdQXKOPZ7wLipayMKcUOzqPOHbFhB 2qiT69yrxsRyzEluEXpG4r7yUL5hqLcs5GJTxRT77u+0kyVAJWzD1FhrSEZr4uNjZo sQVcFSHUBvF5A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AE39768FD2; Sat, 3 Jan 2026 13:07:08 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id dvovJGjpWoRL; Sat, 3 Jan 2026 13:07:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470824; bh=HD64RQJBO4lXmuRfZPJ9p3h6M2hLAuzSMFrpCFxDoWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NnFRQR0pFvHs1/6Ptxjrv1UAaO4XO1Sgz+JINit5DkRCYP8negMXVhskIbZMQL6Ke FBcwj86Ctib8MgwGdjRuSnZ4TqFIj5lfWB5ayErJM9pc1QT7OorzPZWpWUJRybFQhN da4VOp1PHiZRCnhmKK8O0mlyXyFkfL0bIPWZ+BhBdpLR7NAkpnmyC+5o2OG/PA8AOq T2ZAB0MBMHo2HKCol4gjX+/989sCI5WHYGNJFi1hWJ4PUcw36IsLUvcu/0yBS1eAQg DFIBBJxYMlF9STZ4O4hvuEYd4q58h9mFBekuIm9Who4yz2KQs4MgWdAERnk35vHioG oA4XB2BSeGdmQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 621E469085; Sat, 3 Jan 2026 13:07:04 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:57 -0700 Message-ID: <20260103200510.3605009-27-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OII56MIZEPL4TNYOSEVRT2O7ZRYU2KPH X-Message-ID-Hash: OII56MIZEPL4TNYOSEVRT2O7ZRYU2KPH X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 26/29] test/py: Reduce CPU usage when waiting for console output List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass 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 Signed-off-by: Simon Glass --- (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