From patchwork Thu Aug 18 12:42:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp250926pxh; Thu, 18 Aug 2022 05:43:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR6IJgy51HJUNVzQxIEHN1+OwA8eFEpbyEK23Mjf51illwnrDlanTAoORynDNkxrQLpNyTvc X-Received: by 2002:a17:907:75e8:b0:730:ccd3:2683 with SMTP id jz8-20020a17090775e800b00730ccd32683mr1770203ejc.329.1660826610555; Thu, 18 Aug 2022 05:43:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660826610; cv=none; d=google.com; s=arc-20160816; b=dj2rVoOxfjYY3wos/dPqKGIVOkqfjMDvwJSp6X5EbCY08ycM7Uf+FxrR3a6B0E7is5 kxPLXM8Giv+k6EUyJcsSpPuhSlRXT1j0iZraFmP5KzRt7u8c6BhxhsmugQ4R23lHjhHE wEW2bZ1Tx/L3TB0rpONuNb0ivhyn9RYlV7hgA1XpBOigC1Le+MiANiRbtaa+UG/OkIXn Pmp4J8SOTFjkqAFWjvKjhCPdX/m51ItrKtHt5urAN6SlZPlebZLd1G3tzLt03UDqtQ59 oftm1c8uzihB1NUX2QllzRsXRIS7q9j85x7zPQQL7a0nkYykKrMyd9WVpPWe65h8rDys 8bSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=UOkCvT7G3C//2o1dgZRPSgOr8GyusQFi0vAKr+wh7RI=; b=Ildd/g+RpceAwa/voOT+QK4YXN7tss4rmjQgH63Y9QnnayYyypPUATUlUjF0FFkdN2 yLWlFl4NZ/re3UB45MpsAWyHWs4NzsfMu4FOugGS2X5uCQPINkZ0mimvUkipYvD7gA5T 6fZbf5z4ZAoiOsoV0QTMNokGWCdb0+aypp+rUlSpVpP09XpQJMpHdECAZKtiuVD0h19j dNNaFb4l9V3uc97qD0fR/ptqPTto1VIFcuOAdbhpUHYDL9xwZByFFpKq7U2j8kYVu2z/ TvUkoyy254WHTz0mP21vNjGHY+8cLujUCPiTVMnocjLdxh90dcxI+O2357rv1vldzPa2 neeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lvLwySz8; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=b7xbipsX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id mp41-20020a1709071b2900b0073063cbab03si999787ejc.655.2022.08.18.05.43.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 05:43:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=lvLwySz8; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=b7xbipsX; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 578953858D28 for ; Thu, 18 Aug 2022 12:43:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 4C8703858D28 for ; Thu, 18 Aug 2022 12:42:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C8703858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 356833EFCE for ; Thu, 18 Aug 2022 12:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1660826577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UOkCvT7G3C//2o1dgZRPSgOr8GyusQFi0vAKr+wh7RI=; b=lvLwySz84cbmJJ+IBBZIM1qTBJsvComoCB4raKRdxQ3YtMXRp0eO8IPlgUeRhrS8rogZ3F RlveO1vNzqyn8O3DCAmK5gsV8IpCgZQlSeWT6VbQP5ieLupuXdKK/EH9yMdP+gMOd9TB03 h+gXCPVz8iCJRVYqx2OOnqFCR2jAOTU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1660826577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UOkCvT7G3C//2o1dgZRPSgOr8GyusQFi0vAKr+wh7RI=; b=b7xbipsX5Wa2sIwtVg1MNkVlnQc8E+J8RBUiwDsxjwIR51wfRRDhsL1wfrVvU/pcHuKUHu 54zLDCJIKcJRJ+DA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 104EC133B5 for ; Thu, 18 Aug 2022 12:42:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 1OF4AtEz/mIaSwAAMHmgww (envelope-from ) for ; Thu, 18 Aug 2022 12:42:57 +0000 Message-ID: Date: Thu, 18 Aug 2022 14:42:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] jobserver: detect properly O_NONBLOCK To: GCC Patches Content-Language: en-US X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741502923874334116?= X-GMAIL-MSGID: =?utf-8?q?1741502923874334116?= That handles systems that don't have O_NONBLOCK, in that case WPA streaming is not using jobserver if --jobserver-auth uses 'fifo'. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Tested with mingw cross compiler as well. Ready to be installed? Thanks, Martin gcc/ChangeLog: * configure.ac: Detect O_NONBLOCK flag for open. * config.in: Regenerate. * configure: Regenerate. * opts-common.cc (jobserver_info::connect): Set is_connected properly based on O_NONBLOCK. * opts-jobserver.h (struct jobserver_info): Add is_connected member variable. gcc/lto/ChangeLog: * lto.cc (wait_for_child): Ask if we are connected to jobserver. (stream_out_partitions): Likewise. --- gcc/config.in | 6 ++++++ gcc/configure | 39 +++++++++++++++++++++++++++++++++++++-- gcc/configure.ac | 11 +++++++++++ gcc/lto/lto.cc | 12 ++++++------ gcc/opts-common.cc | 11 ++++++++++- gcc/opts-jobserver.h | 2 ++ 6 files changed, 72 insertions(+), 9 deletions(-) diff --git a/gcc/config.in b/gcc/config.in index 413b2bd36cb..abab9bf5024 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -2148,6 +2148,12 @@ #endif +/* Define if O_NONBLOCK supported by fcntl. */ +#ifndef USED_FOR_TARGET +#undef HOST_HAS_O_NONBLOCK +#endif + + /* Define which stat syscall is able to handle 64bit indodes. */ #ifndef USED_FOR_TARGET #undef HOST_STAT_FOR_64BIT_INODES diff --git a/gcc/configure b/gcc/configure index da7a45066b5..8b416c1a142 100755 --- a/gcc/configure +++ b/gcc/configure @@ -12460,6 +12460,41 @@ $as_echo "#define HOST_HAS_O_CLOEXEC 1" >>confdefs.h fi +# Check if O_NONBLOCK is defined by fcntl +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for O_NONBLOCK" >&5 +$as_echo_n "checking for O_NONBLOCK... " >&6; } +if ${ac_cv_o_nonblock+:} false; then : + $as_echo_n "(cached) " >&6 +else + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +int +main () +{ + +return open ("/dev/null", O_RDONLY | O_NONBLOCK); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_cv_o_nonblock=yes +else + ac_cv_o_nonblock=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_o_nonblock" >&5 +$as_echo "$ac_cv_o_nonblock" >&6; } +if test $ac_cv_o_nonblock = yes; then + +$as_echo "#define HOST_HAS_O_NONBLOCK 1" >>confdefs.h + +fi + # C++ Modules would like some networking features to provide the mapping # server. You can still use modules without them though. # The following network-related checks could probably do with some @@ -19678,7 +19713,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19681 "configure" +#line 19716 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -19784,7 +19819,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 19787 "configure" +#line 19822 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/gcc/configure.ac b/gcc/configure.ac index f70b6c24fda..4ebdad38b9b 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1707,6 +1707,17 @@ if test $ac_cv_o_cloexec = yes; then [Define if O_CLOEXEC supported by fcntl.]) fi +# Check if O_NONBLOCK is defined by fcntl +AC_CACHE_CHECK(for O_NONBLOCK, ac_cv_o_nonblock, [ +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include ]], [[ +return open ("/dev/null", O_RDONLY | O_NONBLOCK);]])], +[ac_cv_o_nonblock=yes],[ac_cv_o_nonblock=no])]) +if test $ac_cv_o_nonblock = yes; then + AC_DEFINE(HOST_HAS_O_NONBLOCK, 1, + [Define if O_NONBLOCK supported by fcntl.]) +fi + # C++ Modules would like some networking features to provide the mapping # server. You can still use modules without them though. # The following network-related checks could probably do with some diff --git a/gcc/lto/lto.cc b/gcc/lto/lto.cc index c82307f4f7e..3a9147b01b5 100644 --- a/gcc/lto/lto.cc +++ b/gcc/lto/lto.cc @@ -213,11 +213,11 @@ wait_for_child () } while (!WIFEXITED (status) && !WIFSIGNALED (status)); - --nruns; + --nruns; - /* Return token to the jobserver if active. */ - if (jinfo != NULL && jinfo->is_active) - jinfo->return_token (); + /* Return token to the jobserver if active. */ + if (jinfo != NULL && jinfo->is_connected) + jinfo->return_token (); } #endif @@ -254,7 +254,7 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, streaming process. */ if (!last) { - if (jinfo != NULL && jinfo->is_active) + if (jinfo != NULL && jinfo->is_connected) while (true) { if (jinfo->get_token ()) @@ -291,7 +291,7 @@ stream_out_partitions (char *temp_filename, int blen, int min, int max, while (nruns > 0) wait_for_child (); - if (jinfo != NULL && jinfo->is_active) + if (jinfo != NULL && jinfo->is_connected) jinfo->disconnect (); } asm_nodes_output = true; diff --git a/gcc/opts-common.cc b/gcc/opts-common.cc index 4dec9f94447..bff2be02d38 100644 --- a/gcc/opts-common.cc +++ b/gcc/opts-common.cc @@ -2064,7 +2064,16 @@ void jobserver_info::connect () { if (!pipe_path.empty ()) - pipefd = open (pipe_path.c_str (), O_RDWR | O_NONBLOCK); + { +#if HOST_HAS_O_NONBLOCK + pipefd = open (pipe_path.c_str (), O_RDWR | O_NONBLOCK); + is_connected = true; +#else + is_connected = false; +#endif + } + else + is_connected = true; } void diff --git a/gcc/opts-jobserver.h b/gcc/opts-jobserver.h index 76c1d9b2882..284b2417837 100644 --- a/gcc/opts-jobserver.h +++ b/gcc/opts-jobserver.h @@ -55,6 +55,8 @@ struct jobserver_info int pipefd = -1; /* Return true if jobserver is active. */ bool is_active = false; + /* Return true if communication with jobserver is working. */ + bool is_connected = false; }; #endif /* GCC_JOBSERVER_H */