mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
	rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>,
	Saravanan D <sarvanand@fb.com>
Subject: [PATCH rcu 03/11] rcu: Check for jiffies going backwards
Date: Mon, 18 Apr 2022 15:53:51 -0700	[thread overview]
Message-ID: <20220418225359.3945217-3-paulmck@kernel.org> (raw)
In-Reply-To: <20220418225345.GA3945110@paulmck-ThinkPad-P17-Gen-1>

A report of a 12-jiffy normal RCU CPU stall warning raises interesting
questions about the nature of time on the offending system.  This commit
instruments rcu_sched_clock_irq(), which is RCU's hook into the
scheduling-clock interrupt, checking for the jiffies counter going
backwards.

Reported-by: Saravanan D <sarvanand@fb.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
 kernel/rcu/tree.c | 10 ++++++++++
 kernel/rcu/tree.h |  1 +
 2 files changed, 11 insertions(+)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index a4b8189455d5..a5ea67454640 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1679,6 +1679,8 @@ static bool __note_gp_changes(struct rcu_node *rnp, struct rcu_data *rdp)
 	rdp->gp_seq = rnp->gp_seq;  /* Remember new grace-period state. */
 	if (ULONG_CMP_LT(rdp->gp_seq_needed, rnp->gp_seq_needed) || rdp->gpwrap)
 		WRITE_ONCE(rdp->gp_seq_needed, rnp->gp_seq_needed);
+	if (IS_ENABLED(CONFIG_PROVE_RCU) && READ_ONCE(rdp->gpwrap))
+		WRITE_ONCE(rdp->last_sched_clock, jiffies);
 	WRITE_ONCE(rdp->gpwrap, false);
 	rcu_gpnum_ovf(rnp, rdp);
 	return ret;
@@ -2609,6 +2611,13 @@ static void rcu_do_batch(struct rcu_data *rdp)
  */
 void rcu_sched_clock_irq(int user)
 {
+	unsigned long j;
+
+	if (IS_ENABLED(CONFIG_PROVE_RCU)) {
+		j = jiffies;
+		WARN_ON_ONCE(time_before(j, __this_cpu_read(rcu_data.last_sched_clock)));
+		__this_cpu_write(rcu_data.last_sched_clock, j);
+	}
 	trace_rcu_utilization(TPS("Start scheduler-tick"));
 	lockdep_assert_irqs_disabled();
 	raw_cpu_inc(rcu_data.ticks_this_gp);
@@ -4179,6 +4188,7 @@ rcu_boot_init_percpu_data(int cpu)
 	rdp->rcu_ofl_gp_flags = RCU_GP_CLEANED;
 	rdp->rcu_onl_gp_seq = rcu_state.gp_seq;
 	rdp->rcu_onl_gp_flags = RCU_GP_CLEANED;
+	rdp->last_sched_clock = jiffies;
 	rdp->cpu = cpu;
 	rcu_boot_init_nocb_percpu_data(rdp);
 }
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 926673ebe355..94b55f669915 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -254,6 +254,7 @@ struct rcu_data {
 	unsigned long rcu_onl_gp_seq;	/* ->gp_seq at last online. */
 	short rcu_onl_gp_flags;		/* ->gp_flags at last online. */
 	unsigned long last_fqs_resched;	/* Time of last rcu_resched(). */
+	unsigned long last_sched_clock;	/* Jiffies of last rcu_sched_clock_irq(). */
 
 	int cpu;
 };
-- 
2.31.1.189.g2e36527f23


  parent reply	other threads:[~2022-04-18 22:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 22:53 [PATCH rcu 0/11] Miscellaneous fixes for v5.19 Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 01/11] rcu: Clarify fill-the-gap comment in rcu_segcblist_advance() Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 02/11] rcu: Fix rcu_preempt_deferred_qs_irqrestore() strict QS reporting Paul E. McKenney
2022-04-18 22:53 ` Paul E. McKenney [this message]
2022-04-18 22:53 ` [PATCH rcu 04/11] kernel/smp: Provide boot-time timeout for CSD lock diagnostics Paul E. McKenney
2022-04-19  7:11   ` Juergen Gross
2022-04-19 16:44     ` Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 05/11] rcu: Add comments to final rcu_gp_cleanup() "if" statement Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 06/11] rcu: Print number of online CPUs in RCU CPU stall-warning messages Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 07/11] rcu: Fix preemption mode check on synchronize_rcu[_expedited]() Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 08/11] srcu: Drop needless initialization of sdp in srcu_gp_start() Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 09/11] rcu: Check for successful spawn of ->boost_kthread_task Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 10/11] rcu_sync: Fix comment to properly reflect rcu_sync_exit() behavior Paul E. McKenney
2022-04-18 22:53 ` [PATCH rcu 11/11] rcu: Use IRQ_WORK_INIT_HARD() to avoid rcu_read_unlock() hangs Paul E. McKenney
     [not found] ` <20220419085607.2014-1-hdanton@sina.com>
2022-04-19 13:46   ` [PATCH rcu 04/11] kernel/smp: Provide boot-time timeout for CSD lock diagnostics Paul E. McKenney
2022-04-19 14:11     ` Dmitry Vyukov
2022-04-19 16:49       ` Paul E. McKenney
     [not found]         ` <20220419231820.2089-1-hdanton@sina.com>
2022-04-20 12:17           ` Dmitry Vyukov
2022-04-20 13:41             ` Paul E. McKenney
2022-04-20 14:00               ` Dmitry Vyukov
2022-04-20 14:12                 ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220418225359.3945217-3-paulmck@kernel.org \
    --to=paulmck@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sarvanand@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®