From patchwork Sat Jan 3 01:18: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: 1215 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=1767403236; bh=4ALHTAbTMDCebzs12K5qB3JLQtHEm1w6ErHC/wJNuI0=; 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=mKMT2/NOwTFcTIiHeFfAW4xBuo6wMk1JfuChab95VshTDMwDaZGdoMiA5U5WR576i nfBCOcddZI7Wy/4rRn0ICVXaqrLsYJ1muBC0+NImsWM0+2wny5Gq2dqlIf6I9+VYLX NRYHC1jjwze22mxG9kur6iWUXskKRvVOc5Y/OVWuqWz3ciC5pbT5TXkzTFio8qh+LC sG3ku3oEwajwQqqfcQ/s9HbTASE1U7wpUukMvud9njYJIno8x+X+5tIfNyQb3JKPa1 /gViZokpKnJTzn7bLvBLXANaNl1dZ9/d1X13bQh97HuqrpnskjkgVPn6rY1mXS9/eD eWJmX2KZ7uX7A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D510368F87 for ; Fri, 2 Jan 2026 18:20:36 -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 pG9WvogTVyNu for ; Fri, 2 Jan 2026 18:20:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403236; bh=4ALHTAbTMDCebzs12K5qB3JLQtHEm1w6ErHC/wJNuI0=; 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=mKMT2/NOwTFcTIiHeFfAW4xBuo6wMk1JfuChab95VshTDMwDaZGdoMiA5U5WR576i nfBCOcddZI7Wy/4rRn0ICVXaqrLsYJ1muBC0+NImsWM0+2wny5Gq2dqlIf6I9+VYLX NRYHC1jjwze22mxG9kur6iWUXskKRvVOc5Y/OVWuqWz3ciC5pbT5TXkzTFio8qh+LC sG3ku3oEwajwQqqfcQ/s9HbTASE1U7wpUukMvud9njYJIno8x+X+5tIfNyQb3JKPa1 /gViZokpKnJTzn7bLvBLXANaNl1dZ9/d1X13bQh97HuqrpnskjkgVPn6rY1mXS9/eD eWJmX2KZ7uX7A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4E5168FAF for ; Fri, 2 Jan 2026 18:20:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403234; bh=ed8wmOV6yKM0UZKnBIzZbmJ0M5n8Lu48IH0b3MxA0eg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DCz+amCf9OQtxnjBnWHtIMdVIPpidWq2m88zAqvKggaNE47xIRv+Yi19Kxp0wIrHh Vv5Zixz/BQ9XkucItq1M1XnA0M/DV0JvNZk6vMAJD+UOS1C0kGw27HfSrm61yUZAxw I9X5FGWUkBIqAdYp/BhWyV8cuzA21cMHxqIbZpvnIdjwlwGhrbD9pLFsnRGXluS9kb 2pM8dIrVOFK8CUz5JqQrJDt0FTqu++j5aynU+vvWYSc+6x3L6VSGVfef5ejyl1nCou OxYlEc/W5YR89t7NBd7CpeX0HgB0EY3UBkoEJ0laWpTJ9CyUqWTh9jKr0J8e0uZOFO j72rONzDQAjBA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2D2B86904D; Fri, 2 Jan 2026 18:20:34 -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 Roz-Be8ADXIT; Fri, 2 Jan 2026 18:20:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403232; bh=UO4Omr2/1SwuEMVX9eAJk/+/2EJZcjhJpPyLV7zmS/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wLhqo2jiBnbk0zJR2mgI524wsjWVotykFRuO6D2850OKCwW+l7E5urc78PvUUHCnS EQmpR7z8iRSrGeV7A5LZrCEBWyAKKVqsL+LUxGqJmpkrnMJ3e3cSHi6Ln+Vi2dz8AP VgZ5XfzxyfKs2tPiMUoM3RZNX5E9PdaH4FGqxtPNN9VXYVQNHSM1WrmA6BjA6NHeK5 ZSalkenZUX9LKMjNUGZJyv+Pi9FUF5oliOR/md0ZKotJ1w4Nld0GZG0nZmluN0p2zC qcz4jDC1ly4WuX5/8M9fxoBW+W6COkIZqowxkK/kxcghw8r28D0qS/J1v4Y7eDZVTp kMO4wDySiVv1g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3C68568F8A; Fri, 2 Jan 2026 18:20:32 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:57 -0700 Message-ID: <20260103011908.149445-22-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: INKRLEYCHLYKCTTOVOTFFQMHIBJOUS2Z X-Message-ID-Hash: INKRLEYCHLYKCTTOVOTFFQMHIBJOUS2Z 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 21/24] 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 --- 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