From patchwork Fri Nov 15 21:44:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1195868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513692-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YfD4Ca0V"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47FBhv2PTCz9s4Y for ; Sat, 16 Nov 2019 08:45:03 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; q=dns; s= default; b=Q2ti6Hsih0+MUma5YC6x1vppwa0G2NXHH3vgurID+uSykfakO2eCu 49P2EhWWaMYdU058jpjpz7odyNx6fvU3+hZFnWZK3PAAyqCJ61O9QR59MI0YbTmm 55hidYyJDhHvd2ZhoR70aEgHmoSGO4N6eIxv5CBupjlganwmvUEorw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=VzTtuROnDz8GhbY2hozaBgOwbO0=; b=YfD4Ca0V5iBkYnMZxdmLzWopZZ3k MLiXnaE/rmHlaDJdZS1f08TVLNgLeLyy/HbNyO1/XdhfjnKTpcV8K/t/AncfzOon UcmJQn8+uacxi8WTqlz0GFn8Yp0pAB4tD41wju2NCTjlJwHWqeaovIHD4mD7OpAw b8Y5aH/8MLuONTc= Received: (qmail 51005 invoked by alias); 15 Nov 2019 21:44:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 50954 invoked by uid 89); 15 Nov 2019 21:44:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=corrects, agent, HContent-Transfer-Encoding:8bit X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Nov 2019 21:44:28 +0000 IronPort-SDR: nmOea+ouTE5vO4Ap5afPoJKi3NdGKOJv2vB1PhX6QUZEi5BWXKMtfrkFSn70w/deRxYSufpbJg xBijUDbLaC/f8tinIozdLOks2RSi2QBhGKmtwEYRtiePOe/j3HQAP2epw9pGg+Os+0owdpxq9v Fe+vUaTyk/lo+88uYVNZIjnC8AEtUAj1uS4hX8Gs2kg9M+X7wt12I70kUutBdpIPFZLfjuTkMv rJoUXJ5O6+x4TVe3ubyUi69ArSF9BvoC6WgMKqvu0YYeNDLD0Espa5phCXZAGHddh8tv+p7Tio yBo= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 15 Nov 2019 13:44:27 -0800 IronPort-SDR: 8Q2P750qLu5SdxGoPm4SPUm9VFHadmS+VQM/8hqsKH/75Iho/K8PRQS1gGAWTImA/3iiBLrbS0 0X64i1pMFbhlWwzaPj0f+vbr9MEFS1qTOyAAxDEe88JDr1OAuDY6vPob4ntJMiI1bmLZ6r68mm nlmwsvjyrk+WTEQ100qZObQuDmthlm9pnmELHs1ZYH1hKSpUvqu0MWRTBwCvnhl/9tX1CZEoxP J2uOqbCTcUXXW2o74SEfggkDqvI5klEeQJZItpywXiVWKzoqFRTP0PouVmvCPvCg2l5UWg0CGZ 4BU= From: Julian Brown To: CC: , , , Andrew Stubbs Subject: [PATCH 09/13] AMD GCN libgomp plugin queue-full condition locking fix Date: Fri, 15 Nov 2019 13:44:02 -0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes This patch corrects a possible race condition in locking for the asynchronous queue-full condition check in the AMD GCN libgomp plugin. OK? Julian ChangeLog libgomp/ * plugin/plugin-gcn.c (wait_for_queue_nonfull): Don't lock/unlock aq->mutex here. (queue_push_launch): Lock aq->mutex before calling wait_for_queue_nonfull. (queue_push_callback): Likewise. (queue_push_asyncwait): Likewise. (queue_push_placeholder): Likewise. --- libgomp/plugin/plugin-gcn.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index eb016e3fcd6..c4347dfa45d 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -2732,13 +2732,9 @@ wait_for_queue_nonfull (struct goacc_asyncqueue *aq) { if (aq->queue_n == ASYNC_QUEUE_SIZE) { - pthread_mutex_lock (&aq->mutex); - /* Queue is full. Wait for it to not be full. */ while (aq->queue_n == ASYNC_QUEUE_SIZE) pthread_cond_wait (&aq->queue_cond_out, &aq->mutex); - - pthread_mutex_unlock (&aq->mutex); } } @@ -2752,10 +2748,10 @@ queue_push_launch (struct goacc_asyncqueue *aq, struct kernel_info *kernel, { assert (aq->agent == kernel->agent); - wait_for_queue_nonfull (aq); - pthread_mutex_lock (&aq->mutex); + wait_for_queue_nonfull (aq); + int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE); if (DEBUG_QUEUES) @@ -2785,10 +2781,10 @@ static void queue_push_callback (struct goacc_asyncqueue *aq, void (*fn)(void *), void *data) { - wait_for_queue_nonfull (aq); - pthread_mutex_lock (&aq->mutex); + wait_for_queue_nonfull (aq); + int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE); if (DEBUG_QUEUES) @@ -2818,10 +2814,10 @@ static void queue_push_asyncwait (struct goacc_asyncqueue *aq, struct placeholder *placeholderp) { - wait_for_queue_nonfull (aq); - pthread_mutex_lock (&aq->mutex); + wait_for_queue_nonfull (aq); + int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE); if (DEBUG_QUEUES) GCN_DEBUG ("queue_push_asyncwait %d:%d: at %i\n", aq->agent->device_id, @@ -2849,10 +2845,10 @@ queue_push_placeholder (struct goacc_asyncqueue *aq) { struct placeholder *placeholderp; - wait_for_queue_nonfull (aq); - pthread_mutex_lock (&aq->mutex); + wait_for_queue_nonfull (aq); + int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE); if (DEBUG_QUEUES) GCN_DEBUG ("queue_push_placeholder %d:%d: at %i\n", aq->agent->device_id,