From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id g4FPMikg7mrDuSkAWB0awg (envelope-from ) for ; Fri, 06 Nov 2026 13:44:57 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wNfLYOD8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B88A91E09A; Fri, 06 Nov 2026 13:44:57 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8E0E11E043 for ; Fri, 06 Nov 2026 13:44:56 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 835234BA2E31 for ; Fri, 6 Nov 2026 18:44:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 835234BA2E31 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wNfLYOD8 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 4E2D14BA2E06 for ; Fri, 6 Nov 2026 18:44:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E2D14BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4E2D14BA2E06 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793990668; cv=none; b=ibxvVz2sps4Pw84xOi0zTzxcm8+oKEDnBLNcLUgNP4C8wQ7gP5PFM16fSaMxOHPQXBRBcjJwuAoIGIkfgmxSzC0zJmrj3ymJNE0I0F5DQEjy8PbE7sy2DQBKHZlBNglsK1GptkzLumiAojMf1HCK3XyathiXX7Hup69STd82rz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793990668; c=relaxed/simple; bh=KJ0pHszt6atmtVL2u0UOH9TNA3waHN2L8xIpEyRAVjE=; h=DKIM-Signature:To:Date:Message-ID:MIME-Version:From:Subject; b=aMX0QPro4HRWbWzCQTA511QV+UcFgxl3Uda1y5uHdFj5IAAxVqo0pLSAUaRjuYq8hZyhPFmJz1WXdsJ44RHkU05HM4rlpbU5YUCRGSbleAPj0O37R4Tp6PutOVT/kcmIMAZIqwe5q+BW3sYT4LLOyHzIIvD31LrHu6ovjwq6Kek= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wNfLYOD8 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E2D14BA2E06 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4a140e7405dso9866855e9.3 for ; Fri, 06 Nov 2026 10:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793990667; x=1794595467; darn=sourceware.org; h=subject:from:content-transfer-encoding:content-type:mime-version :references:in-reply-to:message-id:date:cc:to:from:to:cc:subject :date:message-id:reply-to:content-type; bh=sWqWl1mHFbzjteYw9iLywHBNZCa0OeDmJDsryeBdKKk=; b=wNfLYOD8wSfoUxvBahe5PUTDd5W1OoDTDKksyZzJuxafnQIbmDe533DOp0faVrey4u ThFqwtLZ9c1ByRXOaUjd78MX6W5+8CKH3qTzI5O8xG1I/Cab8QN/rsF8xxn8feuy9fZV 123pgXkJ1uypwAVSS59yhvFg1Iq9HWlRfjypS3GB5r9loWFAWBjfn3nbsB1s/5miB+zC QF1ZuGPtQSNtoLv9VVIGpcRaHMyMgBlA87RMq2XxPKJUyMPrrmReQx+ZnfkLH0vYnr1V so1E7VQJ3QKV/9fIn1KWDWHR8/qJ+IZ4fm42VRFj711VfOuMP69nVP5IkB2+Cc/Y90Xi jIKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793990667; x=1794595467; h=subject:from:content-transfer-encoding:content-type:mime-version :references:in-reply-to:message-id:date:cc:to:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sWqWl1mHFbzjteYw9iLywHBNZCa0OeDmJDsryeBdKKk=; b=loEvTSc7GJ665fZOWcszXrPYQKz4Qwo01UJMkCt8Yopc0bBZ2D8XXw1+WVyQb2oI9f Txb8r+ooWfmyIHvwFI+Y984GqB9PQ7x61b8Se1Ms+gRAcmr4E7zmuMT+YfYjWTcT2Utx BW5F2abKQyWoYfpP7WN4JVW1sgTajrOqVytr/ZRvNKddcdOAYImoUQy6OMebihG94F+J kQcOMxaEKENoFUOtrDw/htztp/JtyH8aJFbNQBM6CcO65tyTmDsz0p09H/PpYPOZq2Cv rtrpzT5ukfIkBvZU0oYPbLkDn1r4O1ilRljqp/zIicUW4uqYoa5/9ilDMOHBPqcJ5qRN N1dg== X-Gm-Message-State: APuU4Z8o8kpTUWJwrYDwEml6qg+KD/xNC1bOv0n/mKD3C5KMirA7gz3k C5yaOvQyedW+y4CwoSAHnCSVE9tUz5LO68rIhx/I0AlsP6vbnVq543OyvWJFNw== X-Gm-Gg: AYBFou2ZWlGrMPFBgsIVWbZ3ewbXuwEFtYvK+fgR6UcpbSIrwB5wfJ88PxTr+MdT04e Lj3rtLXOSuJt3F2UVQdDAVOvW/iiewrc2J1bXfkqBj34sQ546epFhsyH93IW+drNrU5FGD+91Jl zYpQQNIWY6GfO9UR3OcUisPT18z8lPzMz+UB/qUHzdiq2UFPShMBNbLcOf1ZQso+PJqs1O3tHhH ua+NXujif4a3KkQdAwzYVfSXNkOqtk9+iKqWx3jwq1FSkVGhacF3bwjhqxnvoefbMBl/Bh5cjTo +BRAJ2OjbPp8uCGGv9+Td+U9jwmA2zG6sBcn1VnuCRFm4Sr6aUv+q8Q7BKipqdmKEfiUesjz7ro ow/5WLvTtXuZbhRIN0KIkQ7VqT5/E3C7jr/uXSmoKTsLtMLfHTVJ8dmsndYid9VE0z958dXp2Wk PV58gk3OPFWprpG21XKDaC5Pwe+xnEj6bd6V7ZlSbLr2yvREieMu6wLEC8i4IqbgA3g8jpqg8HK gxIi/l8wEUfPnKqpuLinr4JWyzvMGctB3yZZSaeYY8mijy8NUL1f3UC01mfGNVDN0Vrk6RhxvMb mSyo/2mw5XfbMh2wTZcpn8Ty2d4tVN9ZlWRo8GlVz5DBHyjsC5O1sYvPFmgChQ+A9d1+xadCig= = X-Received: by 2002:a05:600c:8b6a:b0:4a2:74f:46c1 with SMTP id 5b1f17b1804b1-4b6de78895dmr59700095e9.8.1793990666887; Fri, 06 Nov 2026 10:44:26 -0800 (PST) Received: from [127.0.1.1] ([212.23.215.93]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-492d6d6391dsm5141387f8f.14.2026.11.06.10.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 10:44:26 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Date: Fri, 06 Nov 2026 18:44:11 +0000 Message-ID: In-Reply-To: <87pkwjxcwe.fsf@tromey.com> References: <179373584304.213326.6133225504256345073@gmail.com> <87pkwjxcwe.fsf@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Josip Seketa Subject: [PATCH v2 0/2] gdb: read a pipe command's stderr while waiting, not per character X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi Tom, Thank you for the review. It was very welcome, and it sent me down the rabbit hole, well past the surface. First a correction: the numbers in my v1 were wrong, and you quoted them, so I would like to fix that before anything else. "1.86 s against 0.034 s" was timed with GDB running under strace, which makes every read far slower, so it inflated the very cost I was measuring. The test program was also mostly one repeated byte, which the protocol compresses, so little of it crossed the pipe. And the read calls were counted for the whole session, not the dump. Without strace, that same test takes 0.04-0.07 s on master and 0.02-0.03 s with the patch: about 2x, not 55x. The real gain is in the tables below. You were right to ask about draining. v1 never deadlocked, because the wait in do_ser_base_readchar drains the error fd every second, and v1 did not touch that. But the read per character also drained it while GDB worked through a chunk, so v1 could be slower when a stub blocks on stderr in the middle of a reply. To measure it, a fake stub wrote 300 KiB to stderr, more than the socket holds, with each of 13 memory replies (3 rounds, alternated; all output arrived every time): master v1 v2 before each reply 10.4-13.5 s 8.4-13.3 s 0.20-0.21 s in the middle of it 1.3-2.3 s 1.2-4.2 s 0.19-0.20 s The first row is master's one-second wait, once per reply. So patch 1 goes one step further than your idea of reading the error fd when the read fails: GDB waits for the input and the error fd together, and prints error output as it arrives. Why generic_readchar and not do_ser_base_readchar: only the former runs for every character. The other one runs once per second of waiting. On your two cases, I think the split is whether the event loop runs, not the mode. While GDB is blocked in remote.c's readchar the serial may be async, but handle_error_fd cannot fire, so the wait itself has to watch the error fd. The reads in ser_base_wait_for, do_ser_base_readchar and generic_readchar are now commented where they are used, and ser_base_read_error_fd lists every place that reads the error fd and why. The per-byte cost is still gone. Without strace, with memory that does not compress, over "target remote | exec gdbserver - prog", the bytes identical, 6 rounds, alternated: master v2 dump 2 MiB 0.75-0.77 s 0.05-0.09 s read calls 2,130,240 576 connect, run, kill 0.94-0.97 s 0.15-0.19 s read calls 2,373,809 1,607 The second row needs no dump: GDB reads the shared libraries through the same pipe when it connects. All times here are from one laptop with CPU boost on. With boost off they are 1.9x longer, and the read calls do not change. So the ratio is what to compare, about 10x for the dump and 5x for connecting. The program, if you want to repeat it: static unsigned char big[2 << 20]; void stop (void) {} int main (void) { unsigned x = 2463534242u; for (unsigned i = 0; i < sizeof big; i++) { x ^= x << 13; x ^= x >> 17; x ^= x << 5; big[i] = x; } stop (); return big[0]; } About ssh: it depends on how you connect. The same 2 MiB, gdbserver on the same machine, 5 rounds each, alternated: master v2 "| ssh localhost" 0.769-0.797 s 0.055-0.118 s "| gdbserver" 0.744-0.762 s 0.051-0.081 s TCP port 0.051-0.065 s 0.060-0.078 s So with "target remote | ssh" this could be what you noticed: v2 is about as fast as a socket, and master is not. Localhost has no network delay, so a real link will look different. If ssh only starts gdbserver and GDB connects over TCP, this will not help. How do you connect? This applies on top of my other patch, which also updates a test that this series needs: https://inbox.sourceware.org/gdb-patches/179382821911.358872.8271312658591136533@gmail.com/ Tested on x86-64 GNU/Linux, on top of that patch and the two fixes I am sending separately: gdb.base, gdb.server, gdb.threads, gdb.mi, gdb.multi and gdb.python, on native-stdio-gdbserver, native-gdbserver and native-extended-gdbserver, compared with master test by test. No new failures, apart from the finish_step_over assertion (bug 26284), which shows up under CPU load on master as well, at the same rate. A stub with random stderr bursts, split replies and pauses, 1500 runs on pipes and 300 on TCP, Unix sockets and a pty, plus 330 under ASan and UBSan: memory identical, all stderr lines there, one run with one line out of order that did not come back (GDB's own output can fall inside a partly read line, on master too). Also checked by hand: stderr closed mid-session, Ctrl-C, MI, a stub writing stderr without pause (GDB still retries every 2 seconds), and an error fd above FD_SETSIZE. Not tested on Windows. Serials with "avail" keep the old wait there, but patch 2 and the limit in patch 1 do apply. This series is larger than v1, so it no longer counts as a tiny change, and I have no FSF copyright assignment. This is my own work, not my employer's. What do you need from me? Josip Seketa (2): gdb: watch a serial's error fd while waiting for input gdb: read a serial's error fd once per input chunk, not per character gdb/ser-base.c | 87 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 9 deletions(-) -- 2.56.0