From patchwork Wed Oct 11 08:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Zhang X-Patchwork-Id: 151208 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp387135vqb; Wed, 11 Oct 2023 01:40:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxR0yIpqojdXSySh6cqHUvvsWOG9nM8XTJ7sxAWH9H0rgtHrzRFLcFSMGJomTx9YgQLux1 X-Received: by 2002:a17:907:7713:b0:9b9:f46f:8925 with SMTP id kw19-20020a170907771300b009b9f46f8925mr13415375ejc.48.1697013612385; Wed, 11 Oct 2023 01:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697013612; cv=none; d=google.com; s=arc-20160816; b=o511tmuNvgN2XlxpPCBBk/bdtjkV/DhGVjMLTowBUr5xTrIhOcrTDTYX88xTIcPKWG nNtiP0D8J0QCy1A8ClCfu7I0MzerxFSQ6h5LK48scjCfyslo1GGPQ3egkiuxmpyKmkkK SS1Q500n/FdSyDO9EgDD4YmpG6X5fwIa4sa3hE+gYe9zoym5jgo63mcewdRQV/SFH3eL FNk1IaR8zz7eWi8vEBE0qD8CenZWjDrJzMqtKwM+/K5+V4FCwCc6Ik3gfdQTFovCB9jh 2bOWI73GUYohdlJI/qg8OMZXXOp9ZLEr6FY8PKuewoPk8Y6EDst40XE7xBGrYIyTseEa HDuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=o6e95t/4tNQ4fGzT3ZIuquIw1TX+fe+ZXHFJl3R7EA8=; fh=tRraQiMPPSfUMuclBPtL0PLljw3MIu49oXKhKrffu4o=; b=wAiQjlMLz9dURy6dY+c/R04RguAAHFN5SIz4IqzK05uyLjftoZJnK9boTh5WwnIvJY WNN7UgCDMjrxi9+FeRnFJ/xjVKMHS2RK6X6RAiOP6pLUQdiUB+siA8Bt2TXI9C94Ij6F N6OGV5GdnmDEk0xi/wEOomVW8SO+gjmlGlGUNulzX3I4T6x4CpYoffyGbO5o9DOn6Lgm BHLjneTzoO937ak1y9sRP2nsssrFYcMP3gynJ/bMosUfd8z1WbAwuZ5qcMWbGoaDzJG0 vCIHAYL8ZQ6TTNYYtjzRyCm+jBqcXekw7oE8gzycm1ZgTr6fsfcBwXTkE+ZHVNzoU7m2 /zIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RdlBJ5a2; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y25-20020a170906471900b009a190ce8502si6174151ejq.120.2023.10.11.01.40.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 01:40:12 -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=@intel.com header.s=Intel header.b=RdlBJ5a2; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 942883857700 for ; Wed, 11 Oct 2023 08:40:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by sourceware.org (Postfix) with ESMTPS id 0A0903858D3C for ; Wed, 11 Oct 2023 08:39:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A0903858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697013574; x=1728549574; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=y5bfgrwGExN5IIZdH+DY+BQfh0UOKemC88V1ilSf490=; b=RdlBJ5a2sKERAd+ezBkPwDiNqdBO9Vo4caSAnFJNcpWpn7qLnYHX8FYI 0PNKmQzWnnaR4DFaXnSCqh1Ohts0fBZxsn/QCCjzUTYRMPf9dwuL5LPic t4HgWe9VG6ERsPqUXhhb9h3MCkSg0a/9jrMRiyh0VmltmI9d5weldHazt Ju/REDKfHRO1WY2g7febTBb54b3RUyHtdKr+4RWc/2Ly7r+EBqvnVtm57 thh8C04PX8chl4d1jBs5oDULkBihHu0iXv+cSse0Uu0aqBeS+avp2Zu/3 Etw3qsHF9Giv+P8J0Hu7RrB0yrggPL78EoULv+m2+gOFg7+uVtmqR0DC8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="383473477" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="383473477" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2023 01:39:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10859"; a="783171966" X-IronPort-AV: E=Sophos;i="6.03,214,1694761200"; d="scan'208";a="783171966" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga008.jf.intel.com with ESMTP; 11 Oct 2023 01:39:29 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id EAA6F100571C; Wed, 11 Oct 2023 16:39:28 +0800 (CST) From: Jun Zhang To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, jakub@redhat.com, hongtao.liu@intel.com, jun.zhang@intel.com Subject: [PATCH v2] x86: set spincount 1 for x86 hybrid platform Date: Wed, 11 Oct 2023 16:39:28 +0800 Message-Id: <20231011083928.2535012-1-jun.zhang@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779447745318709963 X-GMAIL-MSGID: 1779447745318709963 From: "Zhang, Jun" By test, we find in hybrid platform spincount 1 is better. Use '-march=native -Ofast -funroll-loops -flto', results as follows: spec2017 speed RPL ADL 657.xz_s 0.00% 0.50% 603.bwaves_s 10.90% 26.20% 607.cactuBSSN_s 5.50% 72.50% 619.lbm_s 2.40% 2.50% 621.wrf_s -7.70% 2.40% 627.cam4_s 0.50% 0.70% 628.pop2_s 48.20% 153.00% 638.imagick_s -0.10% 0.20% 644.nab_s 2.30% 1.40% 649.fotonik3d_s 8.00% 13.80% 654.roms_s 1.20% 1.10% Geomean-int 0.00% 0.50% Geomean-fp 6.30% 21.10% Geomean-all 5.70% 19.10% omp2012 RPL ADL 350.md -1.81% -1.75% 351.bwaves 7.72% 12.50% 352.nab 14.63% 19.71% 357.bt331 -0.20% 1.77% 358.botsalgn 0.00% 0.00% 359.botsspar 0.00% 0.65% 360.ilbdc 0.00% 0.25% 362.fma3d 2.66% -0.51% 363.swim 10.44% 0.00% 367.imagick 0.00% 0.12% 370.mgrid331 2.49% 25.56% 371.applu331 1.06% 4.22% 372.smithwa 0.74% 3.34% 376.kdtree 10.67% 16.03% GEOMEAN 3.34% 5.53% include/ChangeLog: * spincount.h: New file. libgomp/ChangeLog: * env.c (initialize_env): Use do_adjust_default_spincount. * config/linux/x86/spincount.h: New file. --- include/spincount.h | 33 +++++++++++++++++++ libgomp/config/linux/x86/spincount.h | 49 ++++++++++++++++++++++++++++ libgomp/env.c | 6 +++- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 include/spincount.h create mode 100644 libgomp/config/linux/x86/spincount.h diff --git a/include/spincount.h b/include/spincount.h new file mode 100644 index 00000000000..9eecfff198d --- /dev/null +++ b/include/spincount.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2023-2023 Free Software Foundation, Inc. + Contributed by Jun Zhang . + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#ifndef GOMP_SPINCOUNT_H +#define GOMP_SPINCOUNT_H 1 + +static inline void do_adjust_default_spincount (void) +{ +} + +#endif /* GOMP_SPINCOUNT_H */ diff --git a/libgomp/config/linux/x86/spincount.h b/libgomp/config/linux/x86/spincount.h new file mode 100644 index 00000000000..9d2624fd457 --- /dev/null +++ b/libgomp/config/linux/x86/spincount.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2023-2023 Free Software Foundation, Inc. + Contributed by Jun Zhang . + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#ifndef GOMP_SPINCOUNT_H +#define GOMP_SPINCOUNT_H 1 + +#ifdef __x86_64__ +#include "cpuid.h" +#include "libgomp.h" + +/* Only for x86 hybrid platform */ +static inline void do_adjust_default_spincount (void) +{ + unsigned int eax, ebx, ecx, edx; + if (__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx) + /* CPUID.07H.0H:EDX[15] Hybrid. */ + && ((edx >> 15) & 1)) + gomp_spin_count_var = 1LL; +} +#else + +static inline void do_adjust_default_spincount (void) +{ +} +#endif + +#endif /* GOMP_SPINCOUNT_H */ diff --git a/libgomp/env.c b/libgomp/env.c index a21adb3fd4b..d058043b06c 100644 --- a/libgomp/env.c +++ b/libgomp/env.c @@ -61,6 +61,7 @@ #include "secure_getenv.h" #include "environ.h" +#include "spincount.h" /* Default values of ICVs according to the OpenMP standard, except for default-device-var. */ @@ -2431,7 +2432,10 @@ initialize_env (void) if (wait_policy > 0) gomp_spin_count_var = 30000000000LL; else if (wait_policy < 0) - gomp_spin_count_var = 300000LL; + { + gomp_spin_count_var = 300000LL; + do_adjust_default_spincount (); + } } /* gomp_throttled_spin_count_var is used when there are more libgomp managed threads than available CPUs. Use very short spinning. */