diff mbox series

[v2,1/2] rcu: Delete a redundant check in rcu_check_gp_kthread_starvation()

Message ID 20230712151557.760-2-thunder.leizhen@huawei.com (mailing list archive)
State Accepted
Commit 4e9939c3b46a4163c48393eaa210df39b7282797
Headers show
Series rcu: Don't dump the stalled CPU on where RCU GP kthread last ran twice | expand

Commit Message

Leizhen (ThunderTown) July 12, 2023, 3:15 p.m. UTC
The kernel provides the only legal way, that is, function set_task_cpu(),
to dynamically change the value of task_cpu(p). And in which the validity
of the CPU ID is checked.
set_task_cpu():
	WARN_ON_ONCE(!cpu_online(new_cpu));
	__set_task_cpu(p, new_cpu);

Therefore, in normal cases, the value of task_cpu(gpk) is always valid.
Then for the following snippet in rcu_check_gp_kthread_starvation():
	cpu = gpk ? task_cpu(gpk) : -1;
	if (gpk) {
		if (cpu >= 0) {

The above condition "if (gpk)" already ensures that gp_kthread is created,
so the local variable 'cpu' cannot be negative here.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
 kernel/rcu/tree_stall.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index b10b8349bb2a48b..dcfaa3d5db2cbc7 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -537,13 +537,11 @@  static void rcu_check_gp_kthread_starvation(void)
 			pr_err("\tUnless %s kthread gets sufficient CPU time, OOM is now expected behavior.\n", rcu_state.name);
 			pr_err("RCU grace-period kthread stack dump:\n");
 			sched_show_task(gpk);
-			if (cpu >= 0) {
-				if (cpu_is_offline(cpu)) {
-					pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
-				} else  {
-					pr_err("Stack dump where RCU GP kthread last ran:\n");
-					dump_cpu_task(cpu);
-				}
+			if (cpu_is_offline(cpu)) {
+				pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
+			} else  {
+				pr_err("Stack dump where RCU GP kthread last ran:\n");
+				dump_cpu_task(cpu);
 			}
 			wake_up_process(gpk);
 		}