From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by sourceware.org (Postfix) with ESMTPS id 266033858C56; Mon, 11 Dec 2023 17:46:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 266033858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 266033858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702316792; cv=none; b=PRfFfjEJmKcE/F3yRPGT38kTKFnCM+20FMxvCXztCHlK9uFvl9L2DQCsC6IJbUZEQOIbsUJhh/GzrUAN7mDGADfF2inV5RzrDYjY8mFxqANhNKO/n5ynTk+cCbbHlN06ZjjkXe3UUkl2Asv4scB+EpCaQRu7yJeb1V2gSoBEBAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702316792; c=relaxed/simple; bh=3sXDsIGgbKF1zthM740KAx07kZ20zPUV/Jjl/xcT9M0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KQOKNclgS/iux8VMKmS/L/VcIt0ZQFBE2sd35eMmbofvazEe10GeerhxZULoTwcb2zcl0vv4CtSEY7Q88szlAYLmYnY0BIgAsi562qyTlWEZr43VWrLlotxmqp/OAGSVqtn7ZFb03oVamhn6TtBT1F0mMfhk7EZXnrt8vwL9CgA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-5d3644ca426so45213927b3.1; Mon, 11 Dec 2023 09:46:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702316790; x=1702921590; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7TWzWoC7GYi2tinYIdOt0x1NGwTF9ABnbpvWFdoqe0Y=; b=m+RxlJbMH9AROffae1aRMziB/u9ki5203wiyPwaMLkMEhhoXWJj1oaVVw2UWi1c5oJ kj7y6NAroQtXQRdnurnLDtcW/nGdS+TuSqMieK+TDtekx6PrvwB09Pv2Oi9M2QnHM7/H 3GvLK2e2QOtqNQG012zRav4bqY4Bo5bVMCIsF0iBKx6uCycrXv05mcQBnhAPRyPsZTff nr1tdSb77vef2aGYsW3TvtyMT7MZovUKxKs/6wZ8Y79K7Y+2ExiVT2vOLjUPHAmZKC9+ CmdxeHzEONjmGiZKsXk34vtlh1Na3BG9eOHnuMBzVMQWpgN2QVNYfjA/roWiwfCjTzVk S2uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702316790; x=1702921590; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7TWzWoC7GYi2tinYIdOt0x1NGwTF9ABnbpvWFdoqe0Y=; b=a05DO0b4HRCGj/lPdtX2AgHidcpz/daOf8CniQdoPU8qeK9FoevHCQcZc3qq6SD+6l loXRJ0W8l65W3tCPALfLlNXIotME9kzI9FRClfuQe6kit+Kql/LiOi1LHeEsO3lNyHP8 W/Grro0aR/nj1QZvFxmU5SzEnEIjEgmYNSIOT1oUShgdiagoMadVJ62ebb/TFPK0sUgB 0zLIlshoNu9YdvqSwsqjyqYpYfqBoKCqi9rDshPJ+fmPoABd7QIcSUOngwaGe1oZgfDU c8ub4JjdTzZB6RzjmdDzD7SNYmlJYDUJnFSniZay/QVtY+52zg7MEJGKXBVST39zEQWo 0UIw== X-Gm-Message-State: AOJu0YytqSCGqn4I6jMMF7HRJMAmBJ2B5kiAPFuSkKBdjOeMMSGWZ2bj 8AxNjKwMdil7yuAmzkyg0K0saln38Wbrw53NBnc= X-Google-Smtp-Source: AGHT+IFGCJmjYhlIhWOZE5tWTC9WPr0ebur75Z3rZoIThmQ1P2n8kdzUIqmYNufSjdBxQNhnwtXBVRJ8EI4jlieP070= X-Received: by 2002:a81:924b:0:b0:5cc:1e61:5f67 with SMTP id j72-20020a81924b000000b005cc1e615f67mr3068558ywg.48.1702316790524; Mon, 11 Dec 2023 09:46:30 -0800 (PST) MIME-Version: 1.0 References: <20231209153944.3746165-1-lipeng.zhu@intel.com> In-Reply-To: From: "H.J. Lu" Date: Mon, 11 Dec 2023 09:45:54 -0800 Message-ID: Subject: Re: [PATCH v7] libgfortran: Replace mutex with rwlock To: "Zhu, Lipeng" Cc: Jakub Jelinek , "fortran@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" , "Deng, Pan" , "rep.dot.nop@gmail.com" , "Li, Tianyou" , "tkoenig@netcologne.de" , "Guo, Wangyang" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3015.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Sat, Dec 9, 2023 at 7:25=E2=80=AFPM Zhu, Lipeng w= rote: > > 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 a= n > > > 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_pro= to. > > > (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. > > > > Ok for trunk, thanks. > > > > Jakub > > Thanks! Looking forward to landing to trunk. > > Lipeng Zhu Pushed for you. Thanks. --=20 H.J.