Skip to contentSkip to conversation

rcu: Dump all rcuc kthreads status for CPUs that not report quiescent state

PATCH Superseded Zqiang 2 participants 4 messages Apr 13, 2022 – Apr 19, 2022 RCU

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 rcu: Dump all rcuc kthreads status for CPUs that not report quiescent state

If the rcutree.use_softirq is configured, when RCU Stall event happened, dump status of all rcuc kthreads who due to starvation prevented grace period ends on CPUs that not report quiescent state.

---
 kernel/rcu/tree_stall.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/rcu/tree_stall.h +5 -3
index d7956c03edbd..e6ecc32cfe23 100644
@@ -348,6 +348,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
 }
 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
 
+static void rcuc_kthread_dump(struct rcu_data *rdp);
 /*
  * Dump stacks of all tasks running on stalled CPUs.  First try using
  * NMIs, but fall back to manual remote stack tracing on architectures
@@ -368,6 +369,7 @@ static void rcu_dump_cpu_stacks(void)
 					pr_err("Offline CPU %d blocking current GP.\n", cpu);
 				else if (!trigger_single_cpu_backtrace(cpu))
 					dump_cpu_task(cpu);
+				rcuc_kthread_dump(per_cpu_ptr(&rcu_data, cpu));
 			}
 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	}
@@ -471,6 +473,9 @@ static void rcuc_kthread_dump(struct rcu_data *rdp)
 	unsigned long j;
 	struct task_struct *rcuc;
 
+	if (use_softirq)
+		return;
+
 	rcuc = rdp->rcu_cpu_kthread_task;
 	if (!rcuc)
 		return;
@@ -659,9 +664,6 @@ static void print_cpu_stall(unsigned long gps)
 	rcu_check_gp_kthread_expired_fqs_timer();
 	rcu_check_gp_kthread_starvation();
 
-	if (!use_softirq)
-		rcuc_kthread_dump(rdp);
-
 	rcu_dump_cpu_stacks();
 
 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · Zqiang

If the rcutree.use_softirq is configured, when RCU Stall event happened, dump status of all rcuc kthreads who due to starvation prevented grace period ends on CPUs that not report quiescent state.

This could be a good improvement! But a few questions and comments below.

Thanx, Paul

Quoted 17 lines
---
 kernel/rcu/tree_stall.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/rcu/tree_stall.h +1 -0
index d7956c03edbd..e6ecc32cfe23 100644
@@ -348,6 +348,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
 }
 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
 
+static void rcuc_kthread_dump(struct rcu_data *rdp);
 /*
  * Dump stacks of all tasks running on stalled CPUs.  First try using
  * NMIs, but fall back to manual remote stack tracing on architectures

kernel/rcu/tree_stall.h static void rcu_dump_cpu_stacks(void) · line 372

Quoted 4 lines
kernel/rcu/tree_stall.h +1 -0
@@ -368,6 +369,7 @@ static void rcu_dump_cpu_stacks(void)
 					pr_err("Offline CPU %d blocking current GP.\n", cpu);
 				else if (!trigger_single_cpu_backtrace(cpu))
 					dump_cpu_task(cpu);
+				rcuc_kthread_dump(per_cpu_ptr(&rcu_data, cpu));

Was this addition inspired by the chasing of a bug? If so, please let me know exactly what information was (or would have been) the most helpful.

For example, the starvation information might be more compactly represented in the information printed by print_cpu_stall_info(). Unless the stack trace was quite valuable, it might be best to omit it. After all, RCU CPU stall warnings are already infamously heavy on the text output.

kernel/rcu/tree_stall.h static void rcuc_kthread_dump(struct rcu_data *rdp) · line 480

Quoted 12 lines
kernel/rcu/tree_stall.h +3 -0
 			}
 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	}
@@ -471,6 +473,9 @@ static void rcuc_kthread_dump(struct rcu_data *rdp)
 	unsigned long j;
 	struct task_struct *rcuc;
 
+	if (use_softirq)
+		return;
+
 	rcuc = rdp->rcu_cpu_kthread_task;
 	if (!rcuc)

The checks for use_softirq on the one hand and the checks for non-NULL rdp->rcu_cpu_kthread_task are a bit "interesting". Not your fault or problem, of course!

kernel/rcu/tree_stall.h static void print_cpu_stall(unsigned long gps) · line 662

Quoted 6 lines
kernel/rcu/tree_stall.h +0 -1
 		return;
@@ -659,9 +664,6 @@ static void print_cpu_stall(unsigned long gps)
 	rcu_check_gp_kthread_expired_fqs_timer();
 	rcu_check_gp_kthread_starvation();
 
-	if (!use_softirq)

In particular, I am wondering if this "if" is redundant.

Quoted 8 lines
kernel/rcu/tree_stall.h +0 -2
-		rcuc_kthread_dump(rdp);
-
 	rcu_dump_cpu_stacks();
 
 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
Signature · 1 line
2.25.1
#2 lore raw
Quoted 32 lines · Zqiang

If the rcutree.use_softirq is configured, when RCU Stall event happened, dump status of all rcuc kthreads who due to starvation prevented grace period ends on CPUs that not report quiescent state.

This could be a good improvement! But a few questions and comments below.

Thanx, Paul

---
 kernel/rcu/tree_stall.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/rcu/tree_stall.h index renamed from kernel/rcu/tree_stall.h +0 -0

d7956c03edbd..e6ecc32cfe23 100644

kernel/rcu/tree_stall.h +0 -0
@@ -348,6 +348,7 @@ static int rcu_print_task_stall(struct rcu_node 
 *rnp, unsigned long flags)  }  #endif /* #else #ifdef 

CONFIG_PREEMPT_RCU */

+static void rcuc_kthread_dump(struct rcu_data *rdp);
/*
* Dump stacks of all tasks running on stalled CPUs. First try using
* NMIs, but fall back to manual remote stack tracing on
architectures @@ -368,6 +369,7 @@ static void rcu_dump_cpu_stacks(void)

kernel/rcu/tree_stall.h +1 -0
 					pr_err("Offline CPU %d blocking current GP.\n", cpu);
 				else if (!trigger_single_cpu_backtrace(cpu))
 					dump_cpu_task(cpu);
+				rcuc_kthread_dump(per_cpu_ptr(&rcu_data, cpu));
Quoted 5 lines

Was this addition inspired by the chasing of a bug? If so, please let me know exactly what information was (or would have been) the most helpful.

For example, the starvation information might be more compactly represented in the information printed by print_cpu_stall_info(). Unless the stack trace was quite valuable, it might be best to omit it.
After all, RCU CPU stall warnings are already infamously heavy on the text output.

Is it better to modify it like this?

kernel/rcu/tree_stall.h +24 -13
index d7956c03edbd..37444ff00787 100644
@@ -465,27 +465,38 @@ static void print_cpu_stall_info(int cpu)
               falsepositive ? " (false positive?)" : "");
 }
 
-static void rcuc_kthread_dump(struct rcu_data *rdp)
+static void rcuc_kthread_dump(void)
 {
        int cpu;
        unsigned long j;
+       unsigned long flags
+       struct rcu_node *rnp;
        struct task_struct *rcuc;
+       struct rcu_data *rdp;
 
-       rcuc = rdp->rcu_cpu_kthread_task;
-       if (!rcuc)
-               return;
+       rcu_for_each_leaf_node(rnp) {
+               raw_spin_lock_irqsave_rcu_node(rnp, flags);
+               for_each_leaf_node_possible_cpu(rnp, cpu)
+                       if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
+                               rdp = per_cpu_ptr(&rcu_data, cpu);
+                               rcuc = rdp->rcu_cpu_kthread_task;
+                               if (!rcuc)
+                                       return;
 
-       cpu = task_cpu(rcuc);
-       if (cpu_is_offline(cpu) || idle_cpu(cpu))
-               return;
+                               cpu = task_cpu(rcuc);
+                               if (cpu_is_offline(cpu) || idle_cpu(cpu))
+                                       return;
 
-       if (!rcu_is_rcuc_kthread_starving(rdp, &j))
-               return;
+                               if (!rcu_is_rcuc_kthread_starving(rdp, &j))
+                                       return;
 
-       pr_err("%s kthread starved for %ld jiffies\n", rcuc->comm, j);
-       sched_show_task(rcuc);
-       if (!trigger_single_cpu_backtrace(cpu))
-               dump_cpu_task(cpu);
+                               pr_err("%s kthread starved for %ld jiffies\n", rcuc->comm, j);
+                               sched_show_task(rcuc);
+                               if (!trigger_single_cpu_backtrace(cpu))
+                                       dump_cpu_task(cpu);
+                       }
+               raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+       }
 }
 

/* Complain about starvation of grace-period kthread. */
@@ -595,6 +606,9 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)

               smp_processor_id(), (long)(jiffies - gps),
               (long)rcu_seq_current(&rcu_state.gp_seq), totqlen, rcu_state.n_online_cpus);
        if (ndetected) {
+               if (!use_softirq)
+                       rcuc_kthread_dump();
+
                rcu_dump_cpu_stacks();

                /* Complain about tasks blocking the grace period. */
@@ -660,7 +674,7 @@ static void print_cpu_stall(unsigned long gps)
        rcu_check_gp_kthread_starvation();

        if (!use_softirq)

- rcuc_kthread_dump(rdp);
+ rcuc_kthread_dump();

        rcu_dump_cpu_stacks();

Thanks
Zqiang

Quoted 13 lines
kernel/rcu/tree_stall.h +3 -0
 			}
 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	}
@@ -471,6 +473,9 @@ static void rcuc_kthread_dump(struct rcu_data *rdp)
 	unsigned long j;
 	struct task_struct *rcuc;
 
+	if (use_softirq)
+		return;
+
 	rcuc = rdp->rcu_cpu_kthread_task;
 	if (!rcuc)
 
Quoted 3 lines

The checks for use_softirq on the one hand and the checks for non-NULL rdp->rcu_cpu_kthread_task are a bit "interesting". Not your fault or problem, of course!

Yes the ' if (!use_softirq)' is redundant, the if rcu_cpu_kthread_task Is completely enough

Quoted 9 lines
kernel/rcu/tree_stall.h +0 -1
 		return;
@@ -659,9 +664,6 @@ static void print_cpu_stall(unsigned long gps)
 	rcu_check_gp_kthread_expired_fqs_timer();
 	rcu_check_gp_kthread_starvation();
 
-	if (!use_softirq)
 

In particular, I am wondering if this "if" is redundant.

Yes the ' if (!use_softirq)' is also redundant

Quoted 9 lines
kernel/rcu/tree_stall.h +0 -3
-		rcuc_kthread_dump(rdp);
-
 	rcu_dump_cpu_stacks();
 
 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
--

2.25.1

#3 lore raw
Quoted 32 lines · Zqiang

If the rcutree.use_softirq is configured, when RCU Stall event happened, dump status of all rcuc kthreads who due to starvation prevented grace period ends on CPUs that not report quiescent state.

This could be a good improvement! But a few questions and comments below.

Thanx, Paul

---
 kernel/rcu/tree_stall.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/rcu/tree_stall.h index renamed from kernel/rcu/tree_stall.h +0 -0

d7956c03edbd..e6ecc32cfe23 100644

kernel/rcu/tree_stall.h +0 -0
@@ -348,6 +348,7 @@ static int rcu_print_task_stall(struct rcu_node 
 *rnp, unsigned long flags)  }  #endif /* #else #ifdef 

CONFIG_PREEMPT_RCU */

+static void rcuc_kthread_dump(struct rcu_data *rdp);
/*
* Dump stacks of all tasks running on stalled CPUs. First try using
* NMIs, but fall back to manual remote stack tracing on
architectures @@ -368,6 +369,7 @@ static void rcu_dump_cpu_stacks(void)

kernel/rcu/tree_stall.h +1 -0
 					pr_err("Offline CPU %d blocking current GP.\n", cpu);
 				else if (!trigger_single_cpu_backtrace(cpu))
 					dump_cpu_task(cpu);
+				rcuc_kthread_dump(per_cpu_ptr(&rcu_data, cpu));
Quoted 7 lines

Was this addition inspired by the chasing of a bug? If so, please let me know exactly what information was (or would have been) the most helpful.

For example, the starvation information might be more compactly represented in the information printed by print_cpu_stall_info(). Unless the stack trace was quite valuable, it might be best to omit it.
After all, RCU CPU stall warnings are already infamously heavy on the text output.

Is it better to modify it like this?

I'm so sorry, the following modifications are problematic, I'll resend v2

Thanks
Zqiang

Quoted 115 lines
kernel/rcu/tree_stall.h +24 -13
@@ -465,27 +465,38 @@ static void print_cpu_stall_info(int cpu)
              falsepositive ? " (false positive?)" : "");  }
 
-static void rcuc_kthread_dump(struct rcu_data *rdp)
+static void rcuc_kthread_dump(void)
 {
       int cpu;
       unsigned long j;
+       unsigned long flags
+       struct rcu_node *rnp;
       struct task_struct *rcuc;
+       struct rcu_data *rdp;
 
-       rcuc = rdp->rcu_cpu_kthread_task;
-       if (!rcuc)
-               return;
+       rcu_for_each_leaf_node(rnp) {
+               raw_spin_lock_irqsave_rcu_node(rnp, flags);
+               for_each_leaf_node_possible_cpu(rnp, cpu)
+                       if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
+                               rdp = per_cpu_ptr(&rcu_data, cpu);
+                               rcuc = rdp->rcu_cpu_kthread_task;
+                               if (!rcuc)
+                                       return;
 
-       cpu = task_cpu(rcuc);
-       if (cpu_is_offline(cpu) || idle_cpu(cpu))
-               return;
+                               cpu = task_cpu(rcuc);
+                               if (cpu_is_offline(cpu) || idle_cpu(cpu))
+                                       return;
 
-       if (!rcu_is_rcuc_kthread_starving(rdp, &j))
-               return;
+                               if (!rcu_is_rcuc_kthread_starving(rdp, &j))
+                                       return;
 
-       pr_err("%s kthread starved for %ld jiffies\n", rcuc->comm, j);
-       sched_show_task(rcuc);
-       if (!trigger_single_cpu_backtrace(cpu))
-               dump_cpu_task(cpu);
+                               pr_err("%s kthread starved for %ld jiffies\n", rcuc->comm, j);
+                               sched_show_task(rcuc);
+                               if (!trigger_single_cpu_backtrace(cpu))
+                                       dump_cpu_task(cpu);
+                       }
+               raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+       }
 }
 
 /* Complain about starvation of grace-period kthread.  */ @@ -595,6 +606,9 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
             smp_processor_id(), (long)(jiffies - gps),
              (long)rcu_seq_current(&rcu_state.gp_seq), totqlen, rcu_state.n_online_cpus);
       if (ndetected) {
kernel/rcu/tree_stall.h +4 -1
+               if (!use_softirq)
+                       rcuc_kthread_dump();
+
               rcu_dump_cpu_stacks();
 
               /* Complain about tasks blocking the grace period. */ @@ -660,7 +674,7 @@ static void print_cpu_stall(unsigned long gps)
       rcu_check_gp_kthread_starvation();
 
       if (!use_softirq)
-               rcuc_kthread_dump(rdp);
+               rcuc_kthread_dump();
 
       rcu_dump_cpu_stacks();

Thanks
Zqiang

kernel/rcu/tree_stall.h +3 -0
 			}
 		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	}
@@ -471,6 +473,9 @@ static void rcuc_kthread_dump(struct rcu_data *rdp)
 	unsigned long j;
 	struct task_struct *rcuc;
 
+	if (use_softirq)
+		return;
+
 	rcuc = rdp->rcu_cpu_kthread_task;
 	if (!rcuc)
 

The checks for use_softirq on the one hand and the checks for non-NULL rdp->rcu_cpu_kthread_task are a bit "interesting". Not your fault or problem, of course!

Yes the ' if (!use_softirq)' is redundant, the if rcu_cpu_kthread_task Is completely enough

kernel/rcu/tree_stall.h +0 -1
 		return;
@@ -659,9 +664,6 @@ static void print_cpu_stall(unsigned long gps)
 	rcu_check_gp_kthread_expired_fqs_timer();
 	rcu_check_gp_kthread_starvation();
 
-	if (!use_softirq)
 

In particular, I am wondering if this "if" is redundant.

Yes the ' if (!use_softirq)' is also redundant

kernel/rcu/tree_stall.h +0 -3
-		rcuc_kthread_dump(rdp);
-
 	rcu_dump_cpu_stacks();
 
 	raw_spin_lock_irqsave_rcu_node(rnp, flags);
--

2.25.1