From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GDK7EpDh7GqTpCIAWB0awg (envelope-from ) for ; Thu, 05 Nov 2026 15:05:36 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=GgE0oC0O; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 39BBB1E09A; Thu, 05 Nov 2026 15:05:36 -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,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 5B23D1E043 for ; Thu, 05 Nov 2026 15:05:35 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79ADA4BA23C0 for ; Thu, 5 Nov 2026 20:05:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79ADA4BA23C0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=GgE0oC0O Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id A873A4BA2E1B for ; Thu, 5 Nov 2026 20:05:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A873A4BA2E1B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A873A4BA2E1B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793909108; cv=none; b=H0smQjf4JNS42cV01EOIONBwLX1mssDWjWTJLWgt6KkM0ZMmx4lM73IjY2aqHVWQth9U5In3ukPsQfb3JLZMYzPNdNTitQUeZGInRlTEW7HvyV2lKDS0vNUtv33zVyZaOA7N0ZDv8NYJmQpyyASsVeoVLmhcMkqqS9D8Ee8Xtmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793909108; c=relaxed/simple; bh=vRN5XQIpyxndR1tFEUAfW6KMDZbwnmwUrFpGzomtr3k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q2oZg9wJQ731ix4gVN5yv7eTJG31dz1D7iQ5sZYwqtZmEcgA/h/QD+FZ2jWGiRLFtXZwWi4IZkIXrpp7lcYK6VoPQck5CpkLx5wfLlA43QZwxc9E+0Ebsph4lrY+rBqHvJ5sG2XJ1ZVNvwArm3I4M23jZKCxomaM4gXfGhwlWFg= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=GgE0oC0O DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A873A4BA2E1B Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-85ac281604dso1257391a34.0 for ; Thu, 05 Nov 2026 12:05:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1793909108; x=1794513908; darn=sourceware.org; h=content-type:mime-version:user-agent:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=mj8n0v4FRSOHjAN6qIthmKxyBzZbpaYmljAMKJnsZwQ=; b=GgE0oC0OHpqV83EKq7w4CV48VDcHc0X9dEPMyWljaH9ieCe5upV5q2kM0TuAi+4okh GKTMkWKbr0kFsJYihCu5bLBBELP05Q0knM2VWoTQu7DWrl2wsB0hVlMO8fQNCP3VY/9P /YIc7iNh4vMeYT4d71lhvCGiVu1Dc5b1iMPnhiriS5GTMD1Zz1vPd1n5Of2xnNlJnSxx SFrOTZ+N3JI1kiUWZd2m3xE2UyU3MNdIBlrNQk7hgoe5FnLMxmWiAuxhL8VPzcQOCpkh nJuqDuTasiZ1Qvfi3JQiTCMDc3xMGHUD58goJIo1ZcNWopF0MWDS0iSmTKIxot5eLFuD AGVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793909108; x=1794513908; h=content-type:mime-version:user-agent:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=mj8n0v4FRSOHjAN6qIthmKxyBzZbpaYmljAMKJnsZwQ=; b=nG5qUFTYc7O4IBIVpYr2w75ouhpBQkzOmCqe0iuUtOI989L6eCsjXglMTtW2sUutdO z/rGfzj62lgCf5amcMfRfE8reoQYbnSxwU86DQFOK0RiV/rdjUW6jO6Dq7CY11SPlxAU 7DAv5Drgg6FhZtGQ7tdhW/M37pv5vhScgvkEepYFrn8kn909ygmdb9pov/zm2CRnk7eo L8JDsmsLlbYpdt7OzuclznSTpERx4diAeGpy1DqMqMkWJACg6+NqZtyuvUs9uEo089IB dLBrF8SvUvKBiObZ4eH3eaHzPyP8GeDsx0h3UBWwN9XS7MMj6R+dlclwk33pXQyaeSGI acrw== X-Gm-Message-State: APuU4Z8qaS/pbgBjEZiuIVZgVR8CONU/8jL4bUjzk/Xj/dHS/VXDrfqT SFINf5+Z6WIs+HiSg+j8ZFe5J1OrOMBnBNyXPY5zwPdmUmRf5Syt11I64EQ4yY1CQg== X-Gm-Gg: AYBFou38NVKPSxMLJ/QdfEY3utG0l8pG0pwo4+2bjN8gfHuKEePn0/WGbHnRcBc54jB OrJxdYfuGZJEaHsMbVPESvf0M2yZ6Sh+pnl7aUZw9/4XsCNhzvOhC+KU5T+qJLWg7lBvMXitfNU WzgQCAFI3zoybY+TS0qTXoEjhNOXHnz8XvWJA4asathBpHNyVPE9dOlC1QttcKzN2FtITaxKXV5 oBvvB0kB4k2mlfgXbZN4ghb6vGOS2mBcJlxTRo0jlSEdn2WSx7noEyHrUWq6brYSek3MjQL1E0C 1T5b5I+GtGGfePuQ416mC2sFil3dC3fwXgzg+NcdxCU1aLcWGqloVeJy84vfuf0lFVvbCIk+Q/b e1nrr7rHOdFMG596nnUrv8qXe+OjXfxzl4tVaOLNhIck1nhqkvu4v67m9ocpW7p4Ax6veVdQxyW mG74D5lxRTneTYljpHf+1y55Q+X/864tR5LXA7vIgQeOE0/Zcub7gaRi0IVnWOZtm514v1wHkuJ N9Bx9lUBVhhDJ3ojrOsNM4uFXbIwIetIrHWiipTPYrnwhN9uDpIjuLifUG4BLjgV2zJ9gZTco62 Z9PsjMereHycoqM4+8cV410jusnlgqBKntnYS1wQcMZuWNYb3Yv9OJ2Dsyk1nY5jLOOh8gfo X-Received: by 2002:a05:6830:2682:b0:815:cdb4:4a7 with SMTP id 46e09a7af769-85f1cd8d7bemr443384a34.3.1793909107918; Thu, 05 Nov 2026 12:05:07 -0800 (PST) Received: from bapiya (97-122-110-129.hlrn.qwest.net. [97.122.110.129]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-85f1d6a4cd8sm254243a34.0.2026.11.05.12.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2026 12:05:07 -0800 (PST) From: Tom Tromey To: Josip Seketa Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb: read a serial's error fd once per input chunk, not per character In-Reply-To: <179373584304.213326.6133225504256345073@gmail.com> (Josip Seketa's message of "Tue, 03 Nov 2026 19:57:23 +0000") References: <179373584304.213326.6133225504256345073@gmail.com> X-Attribution: Tom Date: Thu, 05 Nov 2026 13:05:05 -0700 Message-ID: <87pkwjxcwe.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain 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 >>>>> Josip Seketa writes: > generic_readchar reads the error fd after every character it returns. > For a pipe target ("target remote | command"), that fd is the > command's stderr. > ser-pipe.c has no "avail" method, so each of these reads is a read(2) > on a non-blocking socket, which nearly always fails with EAGAIN. > Reading memory therefore costs one extra system call per byte. Thank you for the patch. I hadn't previously taken any notice of this code. Ugly stuff :-( > Read the error fd only when the character is the first one of a chunk > read from the device, or is an error or end of file. I find it a bit hard to untangle all this but I think there are two cases here: 1. In async mode, the error fd is handled via the main select/poll loop. 2. In sync mode, the error fd is handled when reading from the main serial fd as well. And (again IIUC) your patch addresses an issue with scenario 2. And I guess this makes sense. We can't always handle the error fd via the poll loop, because in sync mode gdb will be blocked in some read() in remote.c. Ok so far. But then, consider this comment from ser-base.c: /* We also need to check and consume the stderr because it could come before the stdout for some stubs. If we just sit and wait for stdout, we would hit a deadlock for that case. */ >From this I think the idea is to consider a remote that's writing to both its stdout and stderr. And, if the stderr pipe fills up, then a read attempt by gdb on the remote's stdout will never finish -- because the remote will be blocked while writing. So, gdb has to be sure to drain the error output while reading. And so my question is whether your patch preserves this. I somewhat suspect it does not. Also I was wondering why you changed the call in generic_readchar (which passes "1" as the close_fd parameter) and not the call in do_ser_base_readchar. I didn't dig much deeper than this. The code here is a bit confusing I think. Anyway, I do think some kind of change here would be good. I'm just not sure exactly what. Maybe one idea would be if the read from the remote's stdout fails (like if we're doing a non-blocking read, which I didn't look into), then that might be a good time to read from the error fd? I also have a crazier idea involving threads but TBH I'm not sure that is sensible at all. Finally I wanted to say: > Before: 1.86 to 1.89 s, 2,689,827 read calls. > After: 0.034 to 0.035 s, 1,793 read calls. This is a nice find, thank you. Here at AdaCore, we've noticed that remote testing over ssh is noticeably slower than remote testing over a socket. Investigating this has never gotten to the top of my to-do list -- but I wonder if you've found the problem. Tom