From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 9BF363858D38 for ; Sun, 25 Jun 2023 11:32:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BF363858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-30fcda210cfso2678733f8f.3 for ; Sun, 25 Jun 2023 04:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687692751; x=1690284751; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=MAsBglIHkuWzY04ORPWZYLtbaaLYbj4nRUtGi0vSqtE=; b=T0zBPTCv1AKzMNHvKSBSy0fwbXn8Wzr4DhmcCfAN1Szki5kU8svb8kTHIsYRDYx0Wd MEJ4PKfZDRPOuRSJHB5qh4pmG9sLJib0A1CcINCrcJ61ZirPcDQnuycugpXqN5u94EwK oqvBg4ItxKv9mYwZjnx97rVffJem8NIjElQL4/qv8dPZk6vX+bIZqCaiqCMPsOTiV3gD /nqFvHB09mmqxDaeqekR9u1srGRXuSonssX4arfcTnDoDWysxH3ryKh7n631Hmf0GTB+ 5VWYLH/Gp1BIjICBOLP6Bv7vtiRiPPoQ/U7HWZtJo7VDVOORhUYfbB0ho13N7e+eQ5O0 cR9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687692751; x=1690284751; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MAsBglIHkuWzY04ORPWZYLtbaaLYbj4nRUtGi0vSqtE=; b=A5GqZFzTNuoJsZtPGh/qtOs6kb+nvfgJK4n+6up0jA4CQHSrXN+CgFUf90HasBJdXu anJDg3EYeE3oJuHA7nGeNH69YhK13uL0+HI+gOD5T344uuE4dWHJHjGpr8czsP3ODI5v niUvfOybadUFXz2RqYp9Uq9e207C8tB54YN1r0P/G/gkWr3LR3mBQ1v20f9vQ10mDKFM hcPbBQkzqgiNgddk1uurEMXqWcRrwmoR1AjdIRzNPz8f6gklvHQdMjKhDptqASpkopqP Q20qrnD7jFIT7SYq7uSo7ldiB36fq8+bV/WMIh2Yc80C4dhIWFXzWt+w7uH44/Rd306F 0+MQ== X-Gm-Message-State: AC+VfDyu2T+UQanUH7DJdmbEenl4bPt+QyImaXmgjrCWPq7bbJNzpIh7 yzzRFv8OdBQTSiUWOKnRVGU6jNUeYYfZxg== X-Google-Smtp-Source: ACHHUZ65vMmgNjnR6nqDBx/9vOE+JcTYbuePgxAT1u3z3HhTKkiJWRsXlHHcwm/cg/RXyAIkqmzPCg== X-Received: by 2002:a5d:4e8f:0:b0:30f:c703:8be3 with SMTP id e15-20020a5d4e8f000000b0030fc7038be3mr19524612wru.42.1687692751010; Sun, 25 Jun 2023 04:32:31 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id s7-20020adfeb07000000b0030ae901bc54sm4345265wrn.62.2023.06.25.04.32.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 25 Jun 2023 04:32:30 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: gaiusmod2@gmail.com Subject: [PATCH] modula-2: Amend the handling of failed select() calls in RTint [PR108835]. Date: Sun, 25 Jun 2023 12:32:29 +0100 Message-Id: <20230625113229.79338-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) Reply-To: iain@sandoe.co.uk MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested on various affected Darwin versions and on x86_64-linux-gnu OK for trunk? OK for 13.2? thanks Iain --- 8< --- When we make a select() that fails, there is an attempt to (a) diagnose why and (b) make a fallback. These actions are causing some tests to hang on some Darwin versions, this is because the first action that is tried to assist in diagnosis/fallback handling is to replace the set timeout with NIL (which causes select to wait forever, modulo other reasons it might complete). To fix this, call select with a zero timeout when checking for error conditions. Also, as we check the possible failure conditions, if we find a change that succeeds, then stop looking for errors. Signed-off-by: Iain Sandoe PR testsuite/108835 gcc/m2/ChangeLog: * gm2-libs/RTint.mod: Do not use NIL timeout setting on select, test failures sequentially, finishing on the first success. --- gcc/m2/gm2-libs/RTint.mod | 70 ++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/gcc/m2/gm2-libs/RTint.mod b/gcc/m2/gm2-libs/RTint.mod index b3b8737a9f5..8b967b553ff 100644 --- a/gcc/m2/gm2-libs/RTint.mod +++ b/gcc/m2/gm2-libs/RTint.mod @@ -441,6 +441,10 @@ END ExcludeVector ; PROCEDURE AddFd (VAR set: SetOfFd; VAR max: INTEGER; fd: INTEGER) ; BEGIN + IF (fd<0) + THEN + RETURN + END ; max := Max (fd, max) ; IF set = NIL THEN @@ -667,6 +671,7 @@ PROCEDURE Listen (untilInterrupt: BOOLEAN; VAR found : BOOLEAN ; result : INTEGER ; + zero, after, b4, timeval: Timeval ; @@ -722,14 +727,14 @@ BEGIN THEN SetTime (timeval, 0, 0) END ; - IF untilInterrupt AND (inSet=NIL) AND (outSet=NIL) AND (NOT found) + IF untilInterrupt AND (((inSet=NIL) AND (outSet=NIL)) OR (maxFd=-1)) AND (NOT found) THEN Halt ('deadlock found, no more processes to run and no interrupts active', __FILE__, __FUNCTION__, __LINE__) END ; (* printf('timeval = 0x%x\n', timeval) ; *) (* printf('}\n') ; *) - IF (NOT found) AND (maxFd=-1) AND (inSet=NIL) AND (outSet=NIL) + IF (NOT found) AND (maxFd=-1) THEN (* no file descriptors to be selected upon. *) timeval := KillTime (timeval) ; @@ -738,6 +743,7 @@ BEGIN ELSE GetTime (timeval, sec, micro) ; Assert (micro < Microseconds) ; + zero := InitTime (0, 0) ; b4 := InitTime (0, 0) ; after := InitTime (0, 0) ; result := GetTimeOfDay (b4) ; @@ -754,26 +760,54 @@ BEGIN THEN printf ("select (.., .., .., %u.%06u)\n", sec, micro) END ; - result := select (maxFd+1, inSet, outSet, NIL, timeval) ; + IF maxFd<0 + THEN + result := select (0, NIL, NIL, NIL, timeval) + ELSE + result := select (maxFd+1, inSet, outSet, NIL, timeval) + END ; IF result=-1 THEN - perror ("select") ; - result := select (maxFd+1, inSet, outSet, NIL, NIL) ; - IF result=-1 + IF Debugging THEN - perror ("select timeout argument is faulty") + perror ("select failed : ") ; END ; - result := select (maxFd+1, inSet, NIL, NIL, timeval) ; - IF result=-1 + result := select (maxFd+1, inSet, outSet, NIL, zero) ; + IF result#-1 THEN - perror ("select output fd argument is faulty") - END ; - result := select (maxFd+1, NIL, outSet, NIL, timeval) ; - IF result=-1 - THEN - perror ("select input fd argument is faulty") + GetTime (timeval, sec, micro) ; + IF Debugging + THEN + printf ("(nfds : %d timeval: %u.%06u) : \n", maxFd, sec, micro) ; + END ; + perror ("select timeout argument was faulty : ") ELSE - perror ("select maxFD+1 argument is faulty") + result := select (maxFd+1, inSet, NIL, NIL, timeval) ; + IF result#-1 + THEN + perror ("select output fd argument was faulty : ") + ELSE + result := select (maxFd+1, NIL, outSet, NIL, timeval) ; + IF result#-1 + THEN + perror ("select input fd argument was faulty : ") + ELSE + IF maxFd=-1 + THEN + result := select (0, NIL, NIL, NIL, timeval) ; + IF result=-1 + THEN + IF Debugging + THEN + perror ("select does not accept nfds == 0 ") ; + END ; + result := 0 + END + ELSE + perror ("select maxFD+1 argument was faulty : ") ; + END + END + END END END UNTIL result#-1 @@ -785,6 +819,10 @@ BEGIN THEN timeval := KillTime (timeval) END ; + IF zero#NIL + THEN + zero := KillTime (zero) + END ; IF after#NIL THEN after := KillTime (after) -- 2.39.2 (Apple Git-143)