From patchwork Mon Jun 26 00:50:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 780572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wwr8Y2wNCz9ryT for ; Mon, 26 Jun 2017 10:51:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="oD0GrtBZ"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=iKBvvi+maaEQe2OLw0FxjLCwGYVGHodeH2JYx8ANLm80/8 4E9GTXLu8NwZZxjYYyff14KR5JF5FjA2WeBXvBr+VsRZKAj93+o90lpcUt52zwj4 DIq24kkm3L2A7Vfy/bz64Tb9ilH10Wu1xtrp110D6xDrnSMAbv1oCGnzed810= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=jl6jpTASExwU3Hv1BimE1fJeBAQ=; b=oD0GrtBZnQe3N+tHwiM6 zYdAJGY9nvij0Y256R7PwSqA4Okk7k4igaQYP7xWoe+l13EOILRjVme7VhvtbW7a nTLU2Ii1LOG//lclE6oEuXuLZdYdJosqNOx8Df7tE8kICCeiF8ckksUPk5hoVbTf RDevYFHVU+3ihIV3IZDMJn0= Received: (qmail 119341 invoked by alias); 26 Jun 2017 00:50:54 -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 119261 invoked by uid 89); 26 Jun 2017 00:50:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=afterward, act X-HELO: mail-lf0-f46.google.com Received: from mail-lf0-f46.google.com (HELO mail-lf0-f46.google.com) (209.85.215.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Jun 2017 00:50:51 +0000 Received: by mail-lf0-f46.google.com with SMTP id l13so52821175lfl.1 for ; Sun, 25 Jun 2017 17:50:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=JuuhrtpplzEOu4w8BlPUMKJ2TMKtHBSdfB8ydFi+/j0=; b=H4kN2avVAMp8oEJhQGgVcEXE/8BJb0JPcIz9J7Gw5cpJUNk7ixdS5KRuScg1EP9vca qET+jR+PLtUHWZRSMMG8vHcLqWVRazvzheJrkmYA5ENZZHR8AQ+9J8oFotRVutJm/CFD np7jb26eZvqKQGUr39mC55HzKvcR4j1z5BgXSlkNH/vqL6EFYgRLHRAHCtWWI9iAJSar 9BreHTIlTB0jdQbrXtmPEgtD4qgi2HylerB4oAJpPnYLBn0vu9bYjWB3GDZ83DEI6qTf 8PNCeRi34RXYV2EGVCX7anbh/IciRJ2d0sdMsD7xAg26PP4yabCpd91xNZRjXPO+yfoK kqYQ== X-Gm-Message-State: AKS2vOzIdAMiQjmO4uqX0he+6B58WNoRemtntNWaP0ElmjNhdyxSaP5J Cv4It6NUGoIFiE1uuEg0wOwOEFonb9CRV5Q= X-Received: by 10.46.88.86 with SMTP id x22mr5281688ljd.106.1498438249030; Sun, 25 Jun 2017 17:50:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.158.3 with HTTP; Sun, 25 Jun 2017 17:50:48 -0700 (PDT) From: Jim Wilson Date: Sun, 25 Jun 2017 17:50:48 -0700 Message-ID: Subject: [PATCH, libgfortran] proposed fix for SPEC CPU2017 621.wrf_s failures To: "gcc-patches@gcc.gnu.org" , fortran@gcc.gnu.org As mentioned in bug 81195, I see openmp related failures due to a lack of locking of the newunit_stack and newunit_tos variables. The code locks when pushing onto the stack, but does not lock when popping from the stack. This can cause multiple threads to pop the same structure, which then eventually leads to an error. This patch was tested with an aarch64 bootstrap and make check. There were no regressions. It was also tested with a SPEC CPU2017 run, and solves the 621.wrf_s failure I get without the patch. gcc 7 has the same problem. gcc 6 is OK. Jim libgfortran/ PR libfortran/81195 * io/unit.c (get_unit): Call __gthread_mutex_lock before newunit_stack and newunit_tos references. Call __gthread_mutex_unlock afterward. Index: libgfortran/io/unit.c =================================================================== --- libgfortran/io/unit.c (revision 249613) +++ libgfortran/io/unit.c (working copy) @@ -583,14 +583,17 @@ } else { + __gthread_mutex_lock (&unit_lock); if (newunit_tos) { dtp->common.unit = newunit_stack[newunit_tos].unit_number; unit = newunit_stack[newunit_tos--].unit; + __gthread_mutex_unlock (&unit_lock); unit->fbuf->act = unit->fbuf->pos = 0; } else { + __gthread_mutex_unlock (&unit_lock); dtp->common.unit = newunit_alloc (); unit = xcalloc (1, sizeof (gfc_unit)); fbuf_init (unit, 128); @@ -603,12 +606,15 @@ /* If an internal unit number is passed from the parent to the child it should have been stashed on the newunit_stack ready to be used. Check for it now and return the internal unit if found. */ + __gthread_mutex_lock (&unit_lock); if (newunit_tos && (dtp->common.unit <= NEWUNIT_START) && (dtp->common.unit == newunit_stack[newunit_tos].unit_number)) { unit = newunit_stack[newunit_tos--].unit; + __gthread_mutex_unlock (&unit_lock); return unit; } + __gthread_mutex_unlock (&unit_lock); /* Has to be an external unit. */ dtp->u.p.unit_is_internal = 0;