rcu: Fix the (t=0 jiffies) false positive
authorZhaolong Zhang <zhangzl2013@126.com>
Thu, 5 Mar 2020 22:56:11 +0000 (14:56 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 27 Apr 2020 18:01:16 +0000 (11:01 -0700)
It is possible that an over-long grace period will end while the RCU
CPU stall warning message is printing.  In this case, the estimate of
the offending grace period's duration can be erroneous due to refetching
of rcu_state.gp_start, which will now be the time of the newly started
grace period.  Computation of this duration clearly needs to use the
start time for the old over-long grace period, not the fresh new one.
This commit avoids such errors by causing both print_other_cpu_stall() and
print_cpu_stall() to reuse the value previously fetched by their caller.

Signed-off-by: Zhaolong Zhang <zhangzl2013@126.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree_stall.h

index e7da1111ab0c8fa872a11d7d7131acb3efe19440..3a7bc99e78e384dbe1e2d1da9c0aa0fa7c94ac0c 100644 (file)
@@ -371,7 +371,7 @@ static void rcu_check_gp_kthread_starvation(void)
        }
 }
 
-static void print_other_cpu_stall(unsigned long gp_seq)
+static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
 {
        int cpu;
        unsigned long flags;
@@ -408,7 +408,7 @@ static void print_other_cpu_stall(unsigned long gp_seq)
        for_each_possible_cpu(cpu)
                totqlen += rcu_get_n_cbs_cpu(cpu);
        pr_cont("\t(detected by %d, t=%ld jiffies, g=%ld, q=%lu)\n",
-              smp_processor_id(), (long)(jiffies - rcu_state.gp_start),
+              smp_processor_id(), (long)(jiffies - gps),
               (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
        if (ndetected) {
                rcu_dump_cpu_stacks();
@@ -442,7 +442,7 @@ static void print_other_cpu_stall(unsigned long gp_seq)
        rcu_force_quiescent_state();  /* Kick them all. */
 }
 
-static void print_cpu_stall(void)
+static void print_cpu_stall(unsigned long gps)
 {
        int cpu;
        unsigned long flags;
@@ -467,7 +467,7 @@ static void print_cpu_stall(void)
        for_each_possible_cpu(cpu)
                totqlen += rcu_get_n_cbs_cpu(cpu);
        pr_cont("\t(t=%lu jiffies g=%ld q=%lu)\n",
-               jiffies - rcu_state.gp_start,
+               jiffies - gps,
                (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
 
        rcu_check_gp_kthread_starvation();
@@ -546,7 +546,7 @@ static void check_cpu_stall(struct rcu_data *rdp)
            cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
 
                /* We haven't checked in, so go dump stack. */
-               print_cpu_stall();
+               print_cpu_stall(gps);
                if (rcu_cpu_stall_ftrace_dump)
                        rcu_ftrace_dump(DUMP_ALL);
 
@@ -555,7 +555,7 @@ static void check_cpu_stall(struct rcu_data *rdp)
                   cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
 
                /* They had a few time units to dump stack, so complain. */
-               print_other_cpu_stall(gs2);
+               print_other_cpu_stall(gs2, gps);
                if (rcu_cpu_stall_ftrace_dump)
                        rcu_ftrace_dump(DUMP_ALL);
        }