From patchwork Wed Jul 15 20:45:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11666267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4D271392 for ; Wed, 15 Jul 2020 20:46:46 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE6602065F for ; Wed, 15 Jul 2020 20:46:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE6602065F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 9BCA321F6BA; Wed, 15 Jul 2020 13:46:10 -0700 (PDT) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 5ADF321F7F9 for ; Wed, 15 Jul 2020 13:45:34 -0700 (PDT) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id D11AB5E7; Wed, 15 Jul 2020 16:45:20 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id CFD4A2BB; Wed, 15 Jul 2020 16:45:20 -0400 (EDT) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Wed, 15 Jul 2020 16:45:17 -0400 Message-Id: <1594845918-29027-37-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1594845918-29027-1-git-send-email-jsimmons@infradead.org> References: <1594845918-29027-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 36/37] lnet: socklnd: change ksnd_nthreads to atomic_t X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: Mr NeilBrown This variable is treated like an atomic_t, but a global spinlock is used to protect updates - and also unnecessarily to protect reads. Change to atomic_t and avoid using the spinlock. WC-bug-id: https://jira.whamcloud.com/browse/LU-12678 Lustre-commit: 4b0d3c0e41201 ("LU-12678 socklnd: change ksnd_nthreads to atomic_t") Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/39121 Reviewed-by: James Simmons Reviewed-by: Chris Horn Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- net/lnet/klnds/socklnd/socklnd.c | 4 ++-- net/lnet/klnds/socklnd/socklnd.h | 2 +- net/lnet/klnds/socklnd/socklnd_cb.c | 8 ++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/net/lnet/klnds/socklnd/socklnd.c b/net/lnet/klnds/socklnd/socklnd.c index 22a73c3..91925475 100644 --- a/net/lnet/klnds/socklnd/socklnd.c +++ b/net/lnet/klnds/socklnd/socklnd.c @@ -2260,9 +2260,9 @@ static int ksocknal_push(struct lnet_ni *ni, struct lnet_process_id id) } wait_var_event_warning(&ksocknal_data.ksnd_nthreads, - ksocknal_data.ksnd_nthreads == 0, + atomic_read(&ksocknal_data.ksnd_nthreads) == 0, "waiting for %d threads to terminate\n", - ksocknal_data.ksnd_nthreads); + atomic_read(&ksocknal_data.ksnd_nthreads)); ksocknal_free_buffers(); diff --git a/net/lnet/klnds/socklnd/socklnd.h b/net/lnet/klnds/socklnd/socklnd.h index df863f2..350f2c8 100644 --- a/net/lnet/klnds/socklnd/socklnd.h +++ b/net/lnet/klnds/socklnd/socklnd.h @@ -196,7 +196,7 @@ struct ksock_nal_data { * known peers */ - int ksnd_nthreads; /* # live threads */ + atomic_t ksnd_nthreads; /* # live threads */ int ksnd_shuttingdown; /* tell threads to exit */ struct ksock_sched **ksnd_schedulers; /* schedulers info */ diff --git a/net/lnet/klnds/socklnd/socklnd_cb.c b/net/lnet/klnds/socklnd/socklnd_cb.c index 9b3b604..a1c0c3d 100644 --- a/net/lnet/klnds/socklnd/socklnd_cb.c +++ b/net/lnet/klnds/socklnd/socklnd_cb.c @@ -976,19 +976,15 @@ struct ksock_route * if (IS_ERR(task)) return PTR_ERR(task); - write_lock_bh(&ksocknal_data.ksnd_global_lock); - ksocknal_data.ksnd_nthreads++; - write_unlock_bh(&ksocknal_data.ksnd_global_lock); + atomic_inc(&ksocknal_data.ksnd_nthreads); return 0; } void ksocknal_thread_fini(void) { - write_lock_bh(&ksocknal_data.ksnd_global_lock); - if (--ksocknal_data.ksnd_nthreads == 0) + if (atomic_dec_and_test(&ksocknal_data.ksnd_nthreads)) wake_up_var(&ksocknal_data.ksnd_nthreads); - write_unlock_bh(&ksocknal_data.ksnd_global_lock); } int