Message ID | 20231101033507.21651-1-qiang.zhang1211@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp168348vqx; Tue, 31 Oct 2023 20:37:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGeT/UZxFxEFigNNdhBQRFAYAXr6/EOLHe3I69lLUdVzMJdOwpC+43et4YwRty22oNDag34 X-Received: by 2002:a17:902:d50d:b0:1cc:4596:841f with SMTP id b13-20020a170902d50d00b001cc4596841fmr2125990plg.31.1698809833410; Tue, 31 Oct 2023 20:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698809833; cv=none; d=google.com; s=arc-20160816; b=hFeTyh+AcUaMXqer1JrpSQod+uO/ejuya74Oe8ZlpbCUB8r/OAK3Y4nPteuJavSnQt 5nsCVkRtuj7ug9fNMkc+ohN/xqdmabTJGQCvXlaOBwoIJlM/LOVJr4mqowW348pzJwEc wcqH+2SZWt22apEM40o1uaTGKhMh3yzcTWS6sm/M1wc+DGJpW5+Qu800ZJ9zOAU0Y7r/ xWAumBZBo0cRoAOtQoXz84CUzjJkLsoH1b7u3/cVbL7LWXdEndV0JZi1B6Z2OIpwAJQz 63Z24M7nVzIWy12ba8rZZfe+Oy+8dJfhZdq9/B2Zh+LmsErHeL9vCD7AjCiEUMbOwszu VyTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=4AYaAfrBQMEF3rm9agZrtQ/weHtjQJC7TH+07CV4Lio=; fh=gwiqvfVgKJz0dErjXj6/k92xBhYgRbUDUBlJIm9YqFs=; b=H0hQTiisqFYPC1nbZyW7De94ht3lhgZV68SQ5jWjuwL9XBqinziUq2MIU82zFHpOGc MfOh28El+efewSID27YtzirTnWHNAbQbQfDhCL2j18q/OklZQqQiQYnhGtgnQXL2m7fM cJpXeiGR6nrY4KplTPK1D/kUVTyvRTaLK1RBIhwAjN/pCPoqQk94es2J8CjUnPIZLMo3 xr625CvNFkU2gJEW8IQDWQgTLPWByQFYvV4k5scCBcvmYmc90gVx4eJmbWAaxo9j3FBe 8M7YWLFMNWlM6/JgFmFsyatmpZHscN7JhiytU0tou2EXv1CdxkgkDIhEdE3d86kcMmg8 tsgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hNiJFe2h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id b68-20020a633447000000b005ab7b51ab5bsi2062895pga.110.2023.10.31.20.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 20:37:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hNiJFe2h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 5FEFE807D9BB; Tue, 31 Oct 2023 20:35:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232599AbjKADfX (ORCPT <rfc822;rbbytesnap@gmail.com> + 35 others); Tue, 31 Oct 2023 23:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231924AbjKADfV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Oct 2023 23:35:21 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B63E7A4; Tue, 31 Oct 2023 20:35:19 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6b77ab73c6fso369224b3a.1; Tue, 31 Oct 2023 20:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698809719; x=1699414519; darn=vger.kernel.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4AYaAfrBQMEF3rm9agZrtQ/weHtjQJC7TH+07CV4Lio=; b=hNiJFe2hWRWqcT8E4Pfk7GdFEFHdYU9ZVQqN5thpreM9DQsxXGBilzSmRdaTaFtnnp MHCTyw0fptKGNQVvDeq0PbLyMldSduERS2vOgptZ2GitMcle0rFisJOnhP2pdlXDgnPt 74OpzzvWEi5akJyJd4uuXixsGiChIsdQI/IuLanuZ8f+OByL1068QwH6iiJD5qAxJ1fR pIqbCa9F7yUk1SZ3mYgxOmYCavPEn5pOOCDZnE7Er+325fsHXobORPekHooW/MUK5mZq E4nIl3w9HxNWylXZT82DYc8nbw5SI4jffYKzmFJWJsvwoy0NGO+PUhFdK2l7N2RgXWWG LCwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698809719; x=1699414519; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4AYaAfrBQMEF3rm9agZrtQ/weHtjQJC7TH+07CV4Lio=; b=Piy4V/ZkZ1TlVkDW0SrEXunr/nJM226/wBalUgkPhHWF8UaXLjcY6GSeEMHnU1o+eU nhwVyWyl9kiBCvyaShGJRKcXfn3GxEwPVJlB0URwyQSncBXlKZEC9QU5m9NwBJpa0Q+M EzrYFYbgSNdw2tObT8XTq27MaQ0Rmv0QQW9D5pYa7cD6HSoTVEAD8yK8V503IJMKN/8S Ggp3avSnacxgI5nlvGuBstct0477HYJ2fYwbETXkEx3F1oa+PbpBSSQaZ402auiuyhYN Io0iY446j3q2n90744x4payvPqyg3Qcuwpr7ZTmkSMVyTGwM+kIND55JOGCzgn4IonZL IwVA== X-Gm-Message-State: AOJu0YysQ9FF2aNMbMWvnJB0FPck91kcGRNcW6IVx7Mf2SZLkHECtkj6 M6pQUmVDzM1FVHQSh15bdaM= X-Received: by 2002:a05:6a00:6ca1:b0:6c2:e263:5c3d with SMTP id jc33-20020a056a006ca100b006c2e2635c3dmr1528475pfb.0.1698809719082; Tue, 31 Oct 2023 20:35:19 -0700 (PDT) Received: from MSCND1355B05.fareast.nevint.com ([183.242.39.186]) by smtp.gmail.com with ESMTPSA id z3-20020aa785c3000000b0069ea08a2a99sm318749pfn.211.2023.10.31.20.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 20:35:18 -0700 (PDT) From: Zqiang <qiang.zhang1211@gmail.com> To: paulmck@kernel.org, frederic@kernel.org, joel@joelfernandes.org, boqun.feng@gmail.com Cc: qiang.zhang1211@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu: Force quiescent states only for ongoing grace period Date: Wed, 1 Nov 2023 11:35:07 +0800 Message-Id: <20231101033507.21651-1-qiang.zhang1211@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 20:35:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781331219738062888 X-GMAIL-MSGID: 1781331219738062888 |
Series |
rcu: Force quiescent states only for ongoing grace period
|
|
Commit Message
Z qiang
Nov. 1, 2023, 3:35 a.m. UTC
Currently, when running the rcutorture testing, if the fqs_task
kthread was created, the periodic fqs operations will be performed,
regardless of whether the grace-period is ongoing. however, if there
is no ongoing grace-period, invoke the rcu_force_quiescent_state() has
no effect, because when the new grace-period starting, will clear all
flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add
rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is
no ongoing grace-period, return directly.
Signed-off-by: Zqiang <qiang.zhang1211@gmail.com>
---
kernel/rcu/tree.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Wed, Nov 01, 2023 at 11:35:07AM +0800, Zqiang wrote: > Currently, when running the rcutorture testing, if the fqs_task > kthread was created, the periodic fqs operations will be performed, > regardless of whether the grace-period is ongoing. however, if there > is no ongoing grace-period, invoke the rcu_force_quiescent_state() has > no effect, because when the new grace-period starting, will clear all > flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add > rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is > no ongoing grace-period, return directly. > > Signed-off-by: Zqiang <qiang.zhang1211@gmail.com> Nice optimization, but one question below. Thanx, Paul > --- > kernel/rcu/tree.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index aa4c808978b8..5b4279ef66da 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) > struct rcu_node *rnp; > struct rcu_node *rnp_old = NULL; > > + if (!rcu_gp_in_progress()) > + return; Suppose that the grace period that was in progress above ends right at this point in the code. We will still do the useless grace forcing of quiescent states. Which means that this code path does need to be tested. So, when you run rcutorture with this change, how often has the grace period ended before this function returns? If that happens reasonably often, say more than once per minute or so, then this works nicely. If not, we do need to do something to make sure that that code path gets tested. Thoughts? > /* Funnel through hierarchy to reduce memory contention. */ > rnp = raw_cpu_read(rcu_data.mynode); > for (; rnp != NULL; rnp = rnp->parent) { > -- > 2.17.1 >
> > On Wed, Nov 01, 2023 at 11:35:07AM +0800, Zqiang wrote: > > Currently, when running the rcutorture testing, if the fqs_task > > kthread was created, the periodic fqs operations will be performed, > > regardless of whether the grace-period is ongoing. however, if there > > is no ongoing grace-period, invoke the rcu_force_quiescent_state() has > > no effect, because when the new grace-period starting, will clear all > > flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add > > rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is > > no ongoing grace-period, return directly. > > > > Signed-off-by: Zqiang <qiang.zhang1211@gmail.com> > > Nice optimization, but one question below. > > Thanx, Paul > > > --- > > kernel/rcu/tree.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index aa4c808978b8..5b4279ef66da 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) > > struct rcu_node *rnp; > > struct rcu_node *rnp_old = NULL; > > > > + if (!rcu_gp_in_progress()) > > + return; > > Suppose that the grace period that was in progress above ends right > at this point in the code. We will still do the useless grace > forcing of quiescent states. Which means that this code path > does need to be tested. > > So, when you run rcutorture with this change, how often has the > grace period ended before this function returns? If that happens > reasonably often, say more than once per minute or so, then this > works nicely. If not, we do need to do something to make sure > that that code path gets tested. > > Thoughts? Thanks for the suggestion, I will add some debug information to test again. Thanks Zqiang > > > /* Funnel through hierarchy to reduce memory contention. */ > > rnp = raw_cpu_read(rcu_data.mynode); > > for (; rnp != NULL; rnp = rnp->parent) { > > -- > > 2.17.1 > >
On Fri, Nov 03, 2023 at 03:14:11PM +0800, Z qiang wrote: > > > > On Wed, Nov 01, 2023 at 11:35:07AM +0800, Zqiang wrote: > > > Currently, when running the rcutorture testing, if the fqs_task > > > kthread was created, the periodic fqs operations will be performed, > > > regardless of whether the grace-period is ongoing. however, if there > > > is no ongoing grace-period, invoke the rcu_force_quiescent_state() has > > > no effect, because when the new grace-period starting, will clear all > > > flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add > > > rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is > > > no ongoing grace-period, return directly. > > > > > > Signed-off-by: Zqiang <qiang.zhang1211@gmail.com> > > > > Nice optimization, but one question below. > > > > Thanx, Paul > > > > > --- > > > kernel/rcu/tree.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > index aa4c808978b8..5b4279ef66da 100644 > > > --- a/kernel/rcu/tree.c > > > +++ b/kernel/rcu/tree.c > > > @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) > > > struct rcu_node *rnp; > > > struct rcu_node *rnp_old = NULL; > > > > > > + if (!rcu_gp_in_progress()) > > > + return; > > > > Suppose that the grace period that was in progress above ends right > > at this point in the code. We will still do the useless grace > > forcing of quiescent states. Which means that this code path > > does need to be tested. > > > > So, when you run rcutorture with this change, how often has the > > grace period ended before this function returns? If that happens > > reasonably often, say more than once per minute or so, then this > > works nicely. If not, we do need to do something to make sure > > that that code path gets tested. > > > > Thoughts? > > Thanks for the suggestion, I will add some debug information to test again. Very good, and I look forward to seeing what you come up with! Thanx, Paul > Thanks > Zqiang > > > > > > /* Funnel through hierarchy to reduce memory contention. */ > > > rnp = raw_cpu_read(rcu_data.mynode); > > > for (; rnp != NULL; rnp = rnp->parent) { > > > -- > > > 2.17.1 > > >
> > On Fri, Nov 03, 2023 at 03:14:11PM +0800, Z qiang wrote: > > > > > > On Wed, Nov 01, 2023 at 11:35:07AM +0800, Zqiang wrote: > > > > Currently, when running the rcutorture testing, if the fqs_task > > > > kthread was created, the periodic fqs operations will be performed, > > > > regardless of whether the grace-period is ongoing. however, if there > > > > is no ongoing grace-period, invoke the rcu_force_quiescent_state() has > > > > no effect, because when the new grace-period starting, will clear all > > > > flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add > > > > rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is > > > > no ongoing grace-period, return directly. > > > > > > > > Signed-off-by: Zqiang <qiang.zhang1211@gmail.com> > > > > > > Nice optimization, but one question below. > > > > > > Thanx, Paul > > > > > > > --- > > > > kernel/rcu/tree.c | 2 ++ > > > > 1 file changed, 2 insertions(+) > > > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > > index aa4c808978b8..5b4279ef66da 100644 > > > > --- a/kernel/rcu/tree.c > > > > +++ b/kernel/rcu/tree.c > > > > @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) > > > > struct rcu_node *rnp; > > > > struct rcu_node *rnp_old = NULL; > > > > > > > > + if (!rcu_gp_in_progress()) > > > > + return; > > > > > > Suppose that the grace period that was in progress above ends right > > > at this point in the code. We will still do the useless grace > > > forcing of quiescent states. Which means that this code path > > > does need to be tested. > > > > > > So, when you run rcutorture with this change, how often has the > > > grace period ended before this function returns? If that happens > > > reasonably often, say more than once per minute or so, then this > > > works nicely. If not, we do need to do something to make sure > > > that that code path gets tested. > > > > > > Thoughts? > > > > Thanks for the suggestion, I will add some debug information to test again. > > Very good, and I look forward to seeing what you come up with! > Hi, Paul I added some debug code to run rcu torture tests: diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h index 98e13be411af..248e13e1ccd6 100644 --- a/kernel/rcu/rcu.h +++ b/kernel/rcu/rcu.h @@ -548,6 +548,9 @@ void do_trace_rcu_torture_read(const char *rcutorturename, unsigned long c_old, unsigned long c); void rcu_gp_set_torture_wait(int duration); +void rcutorture_fqs_set(bool on); +unsigned long rcutorture_fqs_nr(void); +unsigned long rcutorture_fqs_valid_nr(void); #else static inline void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags, unsigned long *gp_seq) diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index 9bd6856135d7..15f506c26df3 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -1179,6 +1179,7 @@ rcu_torture_fqs(void *arg) int oldnice = task_nice(current); VERBOSE_TOROUT_STRING("rcu_torture_fqs task started"); + rcutorture_fqs_set(true); do { fqs_resume_time = jiffies + fqs_stutter * HZ; while (time_before(jiffies, fqs_resume_time) && @@ -1195,6 +1196,7 @@ rcu_torture_fqs(void *arg) if (stutter_wait("rcu_torture_fqs")) sched_set_normal(current, oldnice); } while (!torture_must_stop()); + rcutorture_fqs_set(false); torture_kthread_stopping("rcu_torture_fqs"); return 0; } @@ -2213,6 +2215,7 @@ rcu_torture_stats_print(void) pr_cont("read-exits: %ld ", data_race(n_read_exits)); // Statistic. pr_cont("nocb-toggles: %ld:%ld\n", atomic_long_read(&n_nocb_offload), atomic_long_read(&n_nocb_deoffload)); + pr_cont("nr_fqs: %ld:%ld\n", rcutorture_fqs_valid_nr(), rcutorture_fqs_nr()); pr_alert("%s%s ", torture_type, TORTURE_FLAG); if (atomic_read(&n_rcu_torture_mberror) || diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..9ae0c442e552 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2299,6 +2299,38 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp)) } } +static bool rcu_fqs_enable; +static unsigned long fqs_valid_nr; +static unsigned long fqs_nr; + +void rcutorture_fqs_set(bool on) +{ + WRITE_ONCE(rcu_fqs_enable, on); +} +EXPORT_SYMBOL_GPL(rcutorture_fqs_set); + +unsigned long rcutorture_fqs_nr(void) +{ + return READ_ONCE(fqs_nr); +} +EXPORT_SYMBOL_GPL(rcutorture_fqs_nr); + +unsigned long rcutorture_fqs_valid_nr(void) +{ + return READ_ONCE(fqs_valid_nr); +} +EXPORT_SYMBOL_GPL(rcutorture_fqs_valid_nr); + +void rcutorture_fqs_account(void) +{ + if (rcu_fqs_enable) { + if (READ_ONCE(rcu_state.gp_state) == RCU_GP_WAIT_FQS || + READ_ONCE(rcu_state.gp_state) == RCU_GP_DOING_FQS) + WRITE_ONCE(fqs_valid_nr, fqs_valid_nr + 1); + WRITE_ONCE(fqs_nr, fqs_nr + 1); + } +} + /* * Force quiescent states on reluctant CPUs, and also detect which * CPUs are in dyntick-idle mode. @@ -2333,6 +2365,7 @@ void rcu_force_quiescent_state(void) WRITE_ONCE(rcu_state.gp_flags, READ_ONCE(rcu_state.gp_flags) | RCU_GP_FLAG_FQS); raw_spin_unlock_irqrestore_rcu_node(rnp_old, flags); + rcutorture_fqs_account(); rcu_gp_kthread_wake(); } EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); runqemu kvm nographic slirp qemuparams="-smp 4 -m 1024" bootparams="rcutorture.fqs_duration=6 rcutorture.fqs_holdoff=1 rcutorture.shutdown_secs=3600" -d original [ 3603.574361] nr_fqs: 1635:1723 apply this patch [ 3603.990193] nr_fqs: 1787:1795 Thanks Zqiang > > Thanx, Paul > > > Thanks > > Zqiang > > > > > > > > > /* Funnel through hierarchy to reduce memory contention. */ > > > > rnp = raw_cpu_read(rcu_data.mynode); > > > > for (; rnp != NULL; rnp = rnp->parent) { > > > > -- > > > > 2.17.1 > > > >
On Tue, Nov 07, 2023 at 02:30:57PM +0800, Z qiang wrote: > > > > On Fri, Nov 03, 2023 at 03:14:11PM +0800, Z qiang wrote: > > > > > > > > On Wed, Nov 01, 2023 at 11:35:07AM +0800, Zqiang wrote: > > > > > Currently, when running the rcutorture testing, if the fqs_task > > > > > kthread was created, the periodic fqs operations will be performed, > > > > > regardless of whether the grace-period is ongoing. however, if there > > > > > is no ongoing grace-period, invoke the rcu_force_quiescent_state() has > > > > > no effect, because when the new grace-period starting, will clear all > > > > > flags int rcu_state.gp_flags in rcu_gp_init(). this commit therefore add > > > > > rcu_gp_in_progress() check in rcu_force_quiescent_state(), if there is > > > > > no ongoing grace-period, return directly. > > > > > > > > > > Signed-off-by: Zqiang <qiang.zhang1211@gmail.com> > > > > > > > > Nice optimization, but one question below. > > > > > > > > Thanx, Paul > > > > > > > > > --- > > > > > kernel/rcu/tree.c | 2 ++ > > > > > 1 file changed, 2 insertions(+) > > > > > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > > > index aa4c808978b8..5b4279ef66da 100644 > > > > > --- a/kernel/rcu/tree.c > > > > > +++ b/kernel/rcu/tree.c > > > > > @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) > > > > > struct rcu_node *rnp; > > > > > struct rcu_node *rnp_old = NULL; > > > > > > > > > > + if (!rcu_gp_in_progress()) > > > > > + return; > > > > > > > > Suppose that the grace period that was in progress above ends right > > > > at this point in the code. We will still do the useless grace > > > > forcing of quiescent states. Which means that this code path > > > > does need to be tested. > > > > > > > > So, when you run rcutorture with this change, how often has the > > > > grace period ended before this function returns? If that happens > > > > reasonably often, say more than once per minute or so, then this > > > > works nicely. If not, we do need to do something to make sure > > > > that that code path gets tested. > > > > > > > > Thoughts? > > > > > > Thanks for the suggestion, I will add some debug information to test again. > > > > Very good, and I look forward to seeing what you come up with! > > > > Hi, Paul > > I added some debug code to run rcu torture tests: > > diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h > index 98e13be411af..248e13e1ccd6 100644 > --- a/kernel/rcu/rcu.h > +++ b/kernel/rcu/rcu.h > @@ -548,6 +548,9 @@ void do_trace_rcu_torture_read(const char *rcutorturename, > unsigned long c_old, > unsigned long c); > void rcu_gp_set_torture_wait(int duration); > +void rcutorture_fqs_set(bool on); > +unsigned long rcutorture_fqs_nr(void); > +unsigned long rcutorture_fqs_valid_nr(void); > #else > static inline void rcutorture_get_gp_data(enum rcutorture_type test_type, > int *flags, unsigned long *gp_seq) > diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c > index 9bd6856135d7..15f506c26df3 100644 > --- a/kernel/rcu/rcutorture.c > +++ b/kernel/rcu/rcutorture.c > @@ -1179,6 +1179,7 @@ rcu_torture_fqs(void *arg) > int oldnice = task_nice(current); > > VERBOSE_TOROUT_STRING("rcu_torture_fqs task started"); > + rcutorture_fqs_set(true); > do { > fqs_resume_time = jiffies + fqs_stutter * HZ; > while (time_before(jiffies, fqs_resume_time) && > @@ -1195,6 +1196,7 @@ rcu_torture_fqs(void *arg) > if (stutter_wait("rcu_torture_fqs")) > sched_set_normal(current, oldnice); > } while (!torture_must_stop()); > + rcutorture_fqs_set(false); > torture_kthread_stopping("rcu_torture_fqs"); > return 0; > } > @@ -2213,6 +2215,7 @@ rcu_torture_stats_print(void) > pr_cont("read-exits: %ld ", data_race(n_read_exits)); // Statistic. > pr_cont("nocb-toggles: %ld:%ld\n", > atomic_long_read(&n_nocb_offload), > atomic_long_read(&n_nocb_deoffload)); > + pr_cont("nr_fqs: %ld:%ld\n", rcutorture_fqs_valid_nr(), > rcutorture_fqs_nr()); > > pr_alert("%s%s ", torture_type, TORTURE_FLAG); > if (atomic_read(&n_rcu_torture_mberror) || > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index cb1caefa8bd0..9ae0c442e552 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -2299,6 +2299,38 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp)) > } > } > > +static bool rcu_fqs_enable; > +static unsigned long fqs_valid_nr; > +static unsigned long fqs_nr; > + > +void rcutorture_fqs_set(bool on) > +{ > + WRITE_ONCE(rcu_fqs_enable, on); > +} > +EXPORT_SYMBOL_GPL(rcutorture_fqs_set); > + > +unsigned long rcutorture_fqs_nr(void) > +{ > + return READ_ONCE(fqs_nr); > +} > +EXPORT_SYMBOL_GPL(rcutorture_fqs_nr); > + > +unsigned long rcutorture_fqs_valid_nr(void) > +{ > + return READ_ONCE(fqs_valid_nr); > +} > +EXPORT_SYMBOL_GPL(rcutorture_fqs_valid_nr); > + > +void rcutorture_fqs_account(void) > +{ > + if (rcu_fqs_enable) { > + if (READ_ONCE(rcu_state.gp_state) == RCU_GP_WAIT_FQS || > + READ_ONCE(rcu_state.gp_state) == > RCU_GP_DOING_FQS) > + WRITE_ONCE(fqs_valid_nr, fqs_valid_nr + 1); > + WRITE_ONCE(fqs_nr, fqs_nr + 1); > + } > +} > + > /* > * Force quiescent states on reluctant CPUs, and also detect which > * CPUs are in dyntick-idle mode. > @@ -2333,6 +2365,7 @@ void rcu_force_quiescent_state(void) > WRITE_ONCE(rcu_state.gp_flags, > READ_ONCE(rcu_state.gp_flags) | RCU_GP_FLAG_FQS); > raw_spin_unlock_irqrestore_rcu_node(rnp_old, flags); > + rcutorture_fqs_account(); > rcu_gp_kthread_wake(); > } > EXPORT_SYMBOL_GPL(rcu_force_quiescent_state); > > runqemu kvm nographic slirp qemuparams="-smp 4 -m 1024" > bootparams="rcutorture.fqs_duration=6 rcutorture.fqs_holdoff=1 > rcutorture.shutdown_secs=3600" -d > > original > [ 3603.574361] nr_fqs: 1635:1723 > apply this patch > [ 3603.990193] nr_fqs: 1787:1795 Very good, then it does appear that we are exercising the code, thank you for checking! Let me go find that commit again... Thanx, Paul > Thanks > Zqiang > > > > > > > Thanx, Paul > > > > > Thanks > > > Zqiang > > > > > > > > > > > > /* Funnel through hierarchy to reduce memory contention. */ > > > > > rnp = raw_cpu_read(rcu_data.mynode); > > > > > for (; rnp != NULL; rnp = rnp->parent) { > > > > > -- > > > > > 2.17.1 > > > > >
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index aa4c808978b8..5b4279ef66da 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2338,6 +2338,8 @@ void rcu_force_quiescent_state(void) struct rcu_node *rnp; struct rcu_node *rnp_old = NULL; + if (!rcu_gp_in_progress()) + return; /* Funnel through hierarchy to reduce memory contention. */ rnp = raw_cpu_read(rcu_data.mynode); for (; rnp != NULL; rnp = rnp->parent) {