From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 87116385DC14 for ; Mon, 22 Feb 2021 18:15:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87116385DC14 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-vwLjNRLdOaeJFjiWUbq5-A-1; Mon, 22 Feb 2021 13:14:59 -0500 X-MC-Unique: vwLjNRLdOaeJFjiWUbq5-A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 176761074CC1; Mon, 22 Feb 2021 18:14:58 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-197.ams2.redhat.com [10.36.112.197]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92FE56B8DA; Mon, 22 Feb 2021 18:14:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 11MIEsF01551693 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 22 Feb 2021 19:14:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 11MIErW31551692; Mon, 22 Feb 2021 19:14:53 +0100 Date: Mon, 22 Feb 2021 19:14:53 +0100 From: Jakub Jelinek To: Kwok Cheung Yeung Cc: GCC Patches Subject: Re: [WIP] Re: [PATCH] openmp: Fix intermittent hanging of task-detach-6 libgomp tests [PR98738] Message-ID: <20210222181453.GM3748@tucnak> Reply-To: Jakub Jelinek References: <20210129150317.GN4020736@tucnak> <0aca6daf-356a-7b03-c007-e33c35114356@codesourcery.com> <20210222134943.GA1837485@tucnak> MIME-Version: 1.0 In-Reply-To: <20210222134943.GA1837485@tucnak> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-List-Received-Date: Mon, 22 Feb 2021 18:15:05 -0000 On Mon, Feb 22, 2021 at 02:49:44PM +0100, Jakub Jelinek wrote: > So, I think for the team != gomp_thread ()->ts.team > && !do_wake > && gomp_team_barrier_waiting_for_tasks (&team->barrier) > && team->task_detach_count == 0 > case, we need to wake up 1 thread anyway and arrange for it to do: > gomp_team_barrier_done (&team->barrier, state); > gomp_mutex_unlock (&team->task_lock); > gomp_team_barrier_wake (&team->barrier, 0); > Possibly in > if (!priority_queue_empty_p (&team->task_queue, MEMMODEL_RELAXED)) > add > else if (team->task_count == 0 > && gomp_team_barrier_waiting_for_tasks (&team->barrier)) > { > gomp_team_barrier_done (&team->barrier, state); > gomp_mutex_unlock (&team->task_lock); > gomp_team_barrier_wake (&team->barrier, 0); > if (to_free) > { > gomp_finish_task (to_free); > free (to_free); > } > return; > } > but the: > if (--team->task_count == 0 > && gomp_team_barrier_waiting_for_tasks (&team->barrier)) > { > gomp_team_barrier_done (&team->barrier, state); > gomp_mutex_unlock (&team->task_lock); > gomp_team_barrier_wake (&team->barrier, 0); > gomp_mutex_lock (&team->task_lock); > } > in that case would then be incorrect, we don't want to do that twice. > So, either that second if would need to do the to_free handling > and return instead of taking the lock again and looping, or > perhaps we can just do > --team->task_count; > there instead and let the above added else if handle that? FYI, I've just tested that part of change alone whether it doesn't break anything else and it worked fine: diff --git a/libgomp/task.c b/libgomp/task.c index b242e7c8d20..9c27c3b5148 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -1405,6 +1405,19 @@ gomp_barrier_handle_tasks (gomp_barrier_state_t state) team->task_running_count++; child_task->in_tied_task = true; } + else if (team->task_count == 0 + && gomp_team_barrier_waiting_for_tasks (&team->barrier)) + { + gomp_team_barrier_done (&team->barrier, state); + gomp_mutex_unlock (&team->task_lock); + gomp_team_barrier_wake (&team->barrier, 0); + if (to_free) + { + gomp_finish_task (to_free); + free (to_free); + } + return; + } gomp_mutex_unlock (&team->task_lock); if (do_wake) { @@ -1479,14 +1492,7 @@ gomp_barrier_handle_tasks (gomp_barrier_state_t state) if (do_wake > new_tasks) do_wake = new_tasks; } - if (--team->task_count == 0 - && gomp_team_barrier_waiting_for_tasks (&team->barrier)) - { - gomp_team_barrier_done (&team->barrier, state); - gomp_mutex_unlock (&team->task_lock); - gomp_team_barrier_wake (&team->barrier, 0); - gomp_mutex_lock (&team->task_lock); - } + --team->task_count; } } } Jakub