Skip to contentSkip to conversation

rcu: avoid unnecessary thread wakeup

PATCH In review Shaohua Li 2 participants 3 messages Jun 10, 2011 – Jun 13, 2011

lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 rcu: avoid unnecessary thread wakeup

invoke_rcu_cpu_kthread could be called in the thread itself. In this case, we don't need call wakeup, which is just wasting CPU.

kernel/rcutree.c +2 -1
index 89419ff..f9bd051 100644
@@ -1475,7 +1475,8 @@ static void invoke_rcu_cpu_kthread(void)
 		local_irq_restore(flags);
 		return;
 	}
-	wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
+	if (current != __this_cpu_read(rcu_cpu_kthread_task))
+		wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
 	local_irq_restore(flags);
 }
 
#1 lore raw
Quoted 10 lines · Shaohua Li

invoke_rcu_cpu_kthread could be called in the thread itself. In this case, we don't need call wakeup, which is just wasting CPU.

kernel/rcutree.c +0 -0
index 89419ff..f9bd051 100644

kernel/rcutree.c static void invoke_rcu_cpu_kthread(void) · line 1481

Quoted 8 lines
kernel/rcutree.c +2 -1
@@ -1475,7 +1475,8 @@ static void invoke_rcu_cpu_kthread(void)
 		local_irq_restore(flags);
 		return;
 	}
-	wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
+	if (current != __this_cpu_read(rcu_cpu_kthread_task))
+		wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
 	local_irq_restore(flags);
 }

Excellent point, thank you!

But how about combining the tests, perhaps something like the following?

Unless you have objections or spot problems with it (or it breaks during testing), I will queue the patch below with your SOB, since I derived it from your patch.

Thanx, Paul

------------------------------------------------------------------------

kernel/rcutree.c +3 -5
index b4b254d..eda3986 100644
@@ -1523,11 +1523,9 @@ static void invoke_rcu_cpu_kthread(void)
 
 	local_irq_save(flags);
 	__this_cpu_write(rcu_cpu_has_work, 1);
-	if (__this_cpu_read(rcu_cpu_kthread_task) == NULL) {
-		local_irq_restore(flags);
-		return;
-	}
-	wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
+	if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
+	    current != __this_cpu_read(rcu_cpu_kthread_task))
+		wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
 	local_irq_restore(flags);
 }
 
author
#2 lore raw
Quoted 22 lines · Paul E. McKenney
Quoted 10 lines · Shaohua Li

invoke_rcu_cpu_kthread could be called in the thread itself. In this case, we don't need call wakeup, which is just wasting CPU.

kernel/rcutree.c +0 -0
index 89419ff..f9bd051 100644

kernel/rcutree.c static void invoke_rcu_cpu_kthread(void) · line 1481

Quoted 8 lines
kernel/rcutree.c +2 -1
@@ -1475,7 +1475,8 @@ static void invoke_rcu_cpu_kthread(void)
 		local_irq_restore(flags);
 		return;
 	}
-	wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
+	if (current != __this_cpu_read(rcu_cpu_kthread_task))
+		wake_up_process(__this_cpu_read(rcu_cpu_kthread_task));
 	local_irq_restore(flags);
 }

Excellent point, thank you!

Quoted 6 lines

But how about combining the tests, perhaps something like the following?

Unless you have objections or spot problems with it (or it breaks during testing), I will queue the patch below with your SOB, since I derived it from your patch.

that's better, thanks.

Thanks,
Shaohua