From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by sourceware.org (Postfix) with ESMTPS id 5F03D3858CD1; Sun, 10 Dec 2023 03:25:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F03D3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F03D3858CD1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=192.198.163.9 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1702178710; cv=pass; b=DAniXVb9rBD33icx8g6j56Yfjdf43w693yQCxjJ/SIn9AUWr+Nk0g+wQRbLOM4CRXaK1ARcQi78K/5uTJ8gXGuejfhl7+AzX6jZvNcnf2+oUDHj0HBU7HvvcLJr9HQlPyr1EILlS0k0yQyvG3ePFS7vjTQZYLEddluzrfgO3Jbk= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1702178710; c=relaxed/simple; bh=Ce8rugXmrwRdZXP7QXPETohFg/QB8+NUuEgmiKHXIS8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JZ2darLjpIswwrJDyCCCoNVT+dk9MdvyoBpgiOXM9ZJ3R+FTzF/m7rViX3fKqiS3fRItEgH7cPj9gOr8z9pvoOJxSMpBEVqI+CdAlRKTfXPdk2bAcToQp9kqjR2Qrv2drPxF249B90sLBS6fJBOGtWpzLd/WZWoVJp3CxiB4NWc= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702178709; x=1733714709; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Ce8rugXmrwRdZXP7QXPETohFg/QB8+NUuEgmiKHXIS8=; b=Aw/HHBVJWHzUCLjl9F5k9cK0GXzLelOYEonqM3iNPXTLx4sVAET8v69l iurKCB2Qw+Llbc2BFDGBbJB684z7+t3OrZnQhnPxWNU00vwmbYwTpioHd Q1pQon0bE8/OtMcTQk9pxcfj5cXvqHGAUpElT83st7FKuJbwQMFHi0yz1 AQ15z8ac/uDb9bQRQhPJxxJ3Q3ufv51IxdwlMxyMAVwFX0RsF6B/dGI1b HcIEipvcWCY640+0A6WIH7Tb6egOgg+6gs2379IqDtap6vjem7ze7lJ0h ITIhvEiffBsO4oe59uqm0NOiO0Ahd2O4nQIkCz/oJT1/0pM8lDaRyQKz1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10919"; a="1408392" X-IronPort-AV: E=Sophos;i="6.04,264,1695711600"; d="scan'208";a="1408392" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2023 19:25:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10919"; a="863327492" X-IronPort-AV: E=Sophos;i="6.04,264,1695711600"; d="scan'208";a="863327492" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by FMSMGA003.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 09 Dec 2023 19:25:06 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sat, 9 Dec 2023 19:25:06 -0800 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Sat, 9 Dec 2023 19:25:06 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sat, 9 Dec 2023 19:25:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cRKXIp+pUqPOmCXRv7wybGlEF4QEmNGJaey58Ul64isUxSyGaBChXuNbXv1tIxsv5veLEsDzIunyLyZOsSrzna/9tbI8qx1WYZz4bJBHxanPZZxyd1Bhgosy1EopFj3g06y3V7x9JQb5YKwQJetorbSp3gXBaY1AqVcLa1MKlLi2Z6F1eg+ZlyDbL8JJahI47cRo/mSRs9sXIkQ2Tg2V2gGTehFSbzJBn2y3Y7khEXFFwRV0MFHNda5pRFhUO7aJTezcN1Mfj1fJLFT6ztWL7JGqIAPMHzoNua+ZZ9o4IuGlu4nL8RgD5/vgkqrC3o7fFl9yb7zukjbhDfrJtaaPLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lYDpeTYjraLSL6E85Yv91iL6xiw6uyJlIyiHAE90dd0=; b=Y0XoOYrO89kBOev0bwaR8DKXsfmnzzMAIz9jt8IoTqxm12Myag/gc4uQAI8hz8rX1H8NKl8FDGY9dqOrTdkfthFxHeSkn75vluJkqXX9vgAxBV1pkNfm/9agzoN1RkGm1h5dNPgAAOwQRoe6L4s8THObRxwf3E0tkTlBB//dvn8RK1QFpVK+k8HacHfZ1TrasDCCaniGqPVSy46C/6Yyf67XlRRoX1qy/GU8p06DIPnRkbIRjJ7NZcz/TmmwWpQ00s9iKYKBOoOYrJcQSO0AkL5X1KQyCRdqDnDZ4EWlLu7taxHInfSw2ttuMDjaqVPARQqFnynPTq+Gu0l837qyKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from PH7PR11MB6056.namprd11.prod.outlook.com (2603:10b6:510:1d4::20) by DS7PR11MB7808.namprd11.prod.outlook.com (2603:10b6:8:ee::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.31; Sun, 10 Dec 2023 03:25:02 +0000 Received: from PH7PR11MB6056.namprd11.prod.outlook.com ([fe80::a74b:825d:7dc3:67]) by PH7PR11MB6056.namprd11.prod.outlook.com ([fe80::a74b:825d:7dc3:67%3]) with mapi id 15.20.7068.029; Sun, 10 Dec 2023 03:25:02 +0000 From: "Zhu, Lipeng" To: Jakub Jelinek CC: "fortran@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" , "Lu, Hongjiu" , "Deng, Pan" , "rep.dot.nop@gmail.com" , "Li, Tianyou" , "tkoenig@netcologne.de" , "Guo, Wangyang" Subject: RE: [PATCH v7] libgfortran: Replace mutex with rwlock Thread-Topic: [PATCH v7] libgfortran: Replace mutex with rwlock Thread-Index: AQHaKrM4g1HI51TEIEqlNeu1d35e0bChEeeAgADG/tA= Date: Sun, 10 Dec 2023 03:25:02 +0000 Message-ID: References: <20231209153944.3746165-1-lipeng.zhu@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR11MB6056:EE_|DS7PR11MB7808:EE_ x-ms-office365-filtering-correlation-id: e68d202a-5ac1-4fb6-ccb3-08dbf92f9896 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OdUQlPSt9CO0JwLqCEwd4y2mqF+M7AIoPg7Y5Uia79SpZzJ9b+XJiPkgraSFBTTaStZ5lrzPrnnpWdkyH0dIXjJQhFtucjClJN+yT1Qe+o2X09Lw1yZGzjoLl8QH+V+NTY5NVo1dYOmxkMey5hlpe7Itc0AhMRFaKyXB429cet6SRdwwzrge3PAM1e7b9GQlkV7rx7LNuZCprqpGR7tjzDLnSyxd4FBZOZqFqKkO2MaVpGEcCL3BidKO3zLcVLPUoDTueIETnCYif/1zxJTzixF4xFkeUu4dsodVPsH9nlwHiC+hLd/X8MOo4AlyHc42ENmipIu6HegL+hh/uDwsMhb32FviK33XrNp/+yQC4oRDkP6uDKzeQhehLCk3Z26Es1BFcBXQu82Vqt0hzGlaXSU0ELVye0Xqs1ToLhu8WkyCr5x7lyeGxL2jX0HOLoYx3x1EXaxT8uDbMjPPNfBnDdvXrj5Qo3I3t6YQCWHJsPdrwy5JZSnNniYgznX5uUi3bcXli0z64ApVIogz4teqPj6nr/RGb4Vwds04I4DAb0aXvTuvxigItCa6Lj/AZhOPSvEl50DDYDV7wIhGh89U7d7pucHX/M/YLxaFh6AMYNM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR11MB6056.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(136003)(39860400002)(346002)(376002)(366004)(396003)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(41300700001)(107886003)(26005)(83380400001)(82960400001)(38070700009)(33656002)(86362001)(38100700002)(122000001)(5660300002)(316002)(8936002)(8676002)(4326008)(52536014)(2906002)(7696005)(6506007)(9686003)(71200400001)(53546011)(66946007)(66556008)(66476007)(66446008)(64756008)(54906003)(6916009)(76116006)(478600001)(966005)(55016003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?uRbQbLYodjFmBRpC9CaaUNWgfkyr0mxzWhKq9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JQO2+tdxjY4ywZuyQoZVXCQeGs91BkaAu+fjIgN?= =?us-ascii?Q?K04Bd/8ViQupDHPXPnwsX8Tk+PBD8jZJCAEAMKuBLI56l9X2kYg4eQt4E9Wj?= =?us-ascii?Q?qq7HWPXdHswlGaipoFetxvafwjusygxDnTrxKceAgufp95FeK4r2ya9V/KT2?= =?us-ascii?Q?YOBLXsVx1kEAxnXtchDsuyktAnjbyv+b5wrKIEHaLNtmYfLD3VUzE9xjti7p?= =?us-ascii?Q?c305LSq+Xn8m7+H6/4r5a+WryQh8YngkH9JN1KF6YsWKDyMieAJ1fWQY6tYh?= =?us-ascii?Q?npWWS3oMb8OS7nQDgrzBhmPrMqfAIIjFtYzwwZzTl/oJiQOEiHTMPt0mzKD+?= =?us-ascii?Q?1f/MT7shH7hihb0Cvy4Y2xr9ksyLtIR+505a+V1El7y1AErgZ2AwXRIQ2ZCc?= =?us-ascii?Q?Jj7STP5omSFTYDNkAKrNSq7ZYOdnGQzD6PVZlivuE2wxPbwZTsdrn1yQXUus?= =?us-ascii?Q?5I78QKTD6Aap5C7+p8oqC2yxmRe6rtU7+gBiwSG2vD/zyzDtfX006KvZf07m?= =?us-ascii?Q?qpuBDIAGfkoetjJEl0ltH7qNHupKihJJJH3Yu31SsljXJLzpTngWmakMNkgb?= =?us-ascii?Q?zsDLbdNvoE/qSGQdBbP9IPh9+PaEkKavh6VMfFfT8IerkzWW/boNGVvsKNZa?= =?us-ascii?Q?t+1FKOHzGJwVNwdLiK+/FPZjKQCCiZMguONvH7Ak?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR11MB6056.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e68d202a-5ac1-4fb6-ccb3-08dbf92f9896 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Dec 2023 03:25:02.1485 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ZsAKcMMV/xRyJ6emk570tUq/ks5oby9aZnbXkNfh9DIYuxqumZsB3Y9qwtXmJpfrjpfBOcFhq0QXoxoUDqldgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB7808 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023/12/9 23:23, Jakub Jelinek wrote: > On Sat, Dec 09, 2023 at 10:39:45AM -0500, Lipeng Zhu wrote: > > This patch try to introduce the rwlock and split the read/write to > > unit_root tree and unit_cache with rwlock instead of the mutex to > > increase CPU efficiency. In the get_gfc_unit function, the percentage > > to step into the insert_unit function is around 30%, in most > > instances, we can get the unit in the phase of reading the unit_cache > > or unit_root tree. So split the read/write phase by rwlock would be an > > approach to make it more parallel. > > > > BTW, the IPC metrics can gain around 9x in our test server with 220 > > cores. The benchmark we used is https://github.com/rwesson/NEAT > > > > libgcc/ChangeLog: > > > > * gthr-posix.h (__GTHREAD_RWLOCK_INIT): New macro. > > (__gthrw): New function. > > (__gthread_rwlock_rdlock): New function. > > (__gthread_rwlock_tryrdlock): New function. > > (__gthread_rwlock_wrlock): New function. > > (__gthread_rwlock_trywrlock): New function. > > (__gthread_rwlock_unlock): New function. > > > > libgfortran/ChangeLog: > > > > * io/async.c (DEBUG_LINE): New macro. > > * io/async.h (RWLOCK_DEBUG_ADD): New macro. > > (CHECK_RDLOCK): New macro. > > (CHECK_WRLOCK): New macro. > > (TAIL_RWLOCK_DEBUG_QUEUE): New macro. > > (IN_RWLOCK_DEBUG_QUEUE): New macro. > > (RDLOCK): New macro. > > (WRLOCK): New macro. > > (RWUNLOCK): New macro. > > (RD_TO_WRLOCK): New macro. > > (INTERN_RDLOCK): New macro. > > (INTERN_WRLOCK): New macro. > > (INTERN_RWUNLOCK): New macro. > > * io/io.h (struct gfc_unit): Change UNIT_LOCK to UNIT_RWLOCK in > > a comment. > > (unit_lock): Remove including associated internal_proto. > > (unit_rwlock): New declarations including associated internal_proto. > > (dec_waiting_unlocked): Use WRLOCK and RWUNLOCK on unit_rwlock > > instead of __gthread_mutex_lock and __gthread_mutex_unlock on > > unit_lock. > > * io/transfer.c (st_read_done_worker): Use WRLOCK and RWUNLOCK > on > > unit_rwlock instead of LOCK and UNLOCK on unit_lock. > > (st_write_done_worker): Likewise. > > * io/unit.c: Change UNIT_LOCK to UNIT_RWLOCK in 'IO locking rules' > > comment. Use unit_rwlock variable instead of unit_lock variable. > > (get_gfc_unit_from_unit_root): New function. > > (get_gfc_unit): Use RDLOCK, WRLOCK and RWUNLOCK on unit_rwlock > > instead of LOCK and UNLOCK on unit_lock. > > (close_unit_1): Use WRLOCK and RWUNLOCK on unit_rwlock instead > of > > LOCK and UNLOCK on unit_lock. > > (close_units): Likewise. > > (newunit_alloc): Use RWUNLOCK on unit_rwlock instead of UNLOCK on > > unit_lock. > > * io/unix.c (find_file): Use RDLOCK and RWUNLOCK on unit_rwlock > > instead of LOCK and UNLOCK on unit_lock. > > (flush_all_units): Use WRLOCK and RWUNLOCK on unit_rwlock instead > > of LOCK and UNLOCK on unit_lock. >=20 > Ok for trunk, thanks. >=20 > Jakub Thanks! Looking forward to landing to trunk. Lipeng Zhu