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: 106300 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1233479qgd; Sun, 25 Jun 2017 17:51:16 -0700 (PDT) X-Received: by 10.84.216.70 with SMTP id f6mr20579833plj.79.1498438276460; Sun, 25 Jun 2017 17:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498438276; cv=none; d=google.com; s=arc-20160816; b=nMYHa3PbLzRMRRtxrH5METXJ2sTXGI5h/xU423TR5zLpZUkcKfmNSAzOgDfRjNNoKX Yb7zsAd6RwnZ8P2UOm9L0oIYgWwlbqiKKxCNGH+WnZpI1R9odzDq2/vfSvCAe5h0qMW3 oc7DRf4Hyzw5WA26KKV7HJzSXUloYWOqf3AnExELUfvNbtGNvrqXDTelPgU3LMXWIClb qQhqz3t6lY/0owSf59oL/siDqSRxbqIDWEibiAzVNu96mJxU59SypeVUYV6L+FUXaz8/ U7SLJVhN7nRd+WxLO0YkuEVlyimj7t9sejDisYeBm7gJyCAhuwcXGpAw4uuhomYpKn04 Mzbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=//gDgTkp9DVe75wnHC5WPRhLrqML8JVHyiA7Q178VUQ=; b=lWxFvwnoIrnw+jpATNNnNYT0WgDzWDc6OFpYz9B0iPjLtOZ0RH5KXsUh8F7TJ/n3Wk rXgRHX82Ui/QPUobbh7DNQVt4fp9gyj4yzqVeH8HUD2n+c/66x4SF/qudyi+nTg606Rl iptN9Mmv70TH6JumYGLh8QtK3xVVqQ8GqBfjEl44P4VNaLpE+s0yoRE1vNTjMxymUu+x Rwqt44DZbXwrK3diJAMS6xY0nLJG817iB3K2gGTDjg1soB2FWaxX38EHoW25Aewxjbt0 tVbSNdL0bX+nivA05TKrZTJYKIkEBCLHKp+dUVtkOeRYI61EMBnbA+BPCjuszGhnNNoV v55g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=v/G27vOi; spf=pass (google.com: domain of gcc-patches-return-456781-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-456781-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e1si7663037pgc.311.2017.06.25.17.51.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Jun 2017 17:51:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-456781-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=v/G27vOi; spf=pass (google.com: domain of gcc-patches-return-456781-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-456781-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=BMoWTmN+yLVn0I8O8R4zTUSpzJmgkJCTlyGraMLhGneF2O ibiAgBoFWY6Vn+UIeGrtsQPFG33UBM+ek8g88+kI2JEX8dDwz7ZADZQyGV4j829I 6Qmi44ZWEj4FiyPc9aj+KWLGiiMOErTwffnfgSzxfqq5yRJcZ9Ht5eJf2mqCU= 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=v/G27vOiDSS/cx3/c04Q H5MngnqhnFZl753OsbK15MDedhFkhlJ2KxmmE4P9asqtm396B33bi5y0BbmC+4vs cdS7GBel4Nsiv4Rdjnzp827T0QF8R1yUR1oLR1XLp7BGpSV6qZ6+y+d7FSusTjTO Fh0u71wh2Gh5EGXb9d+2s+k= 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;