Skip to contentSkip to conversation

softirq: Don't skip softirq execution when softirq thread is parking

PATCH New Matthias Kaehlcke 2 participants 5 messages Jan 28, 2019 – Feb 10, 2019

lore
Share & tools
lore
#0 lore raw

cover softirq: Don't skip softirq execution when softirq thread is parking

Matthias Kaehlcke (2):
kthread: Add __kthread_should_park()
softirq: Don't skip softirq execution when softirq thread is parking

 include/linux/kthread.h | 1 +
 kernel/kthread.c        | 8 +++++++-
 kernel/softirq.c        | 3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1.495.gaa96b0ce6b-goog
#1 lore raw

PATCH 1/2 kthread: Add __kthread_should_park()

The existing kthread_should_park() is used to check if the calling kthread ('current') should park. The new __kthread_should_park() receives a task_struct as parameter to check if the corresponding kernel thread should be parked. Call __kthread_should_park() from kthread_should_park() to avoid code duplication.

---
I'm not overly happy about the function name with the double underscore prefix, but couldn't come up with anything better. I'm open to suggestions :)

---
 include/linux/kthread.h | 1 +
 kernel/kthread.c        | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
include/linux/kthread.h +1 -0
index c1961761311db..1577a2d56e9d4 100644
@@ -56,6 +56,7 @@ void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
 int kthread_stop(struct task_struct *k);
 bool kthread_should_stop(void);
 bool kthread_should_park(void);
+bool __kthread_should_park(struct task_struct *k);
 bool kthread_freezable_should_stop(bool *was_frozen);
 void *kthread_data(struct task_struct *k);
 void *kthread_probe_data(struct task_struct *k);
kernel/kthread.c +7 -1
index 087d18d771b53..65234c89d85b4 100644
@@ -101,6 +101,12 @@ bool kthread_should_stop(void)
 }
 EXPORT_SYMBOL(kthread_should_stop);
 
+bool __kthread_should_park(struct task_struct *k)
+{
+	return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(k)->flags);
+}
+EXPORT_SYMBOL_GPL(__kthread_should_park);
+
 /**
  * kthread_should_park - should this kthread park now?
  *
@@ -114,7 +120,7 @@ EXPORT_SYMBOL(kthread_should_stop);
  */
 bool kthread_should_park(void)
 {
-	return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(current)->flags);
+	return __kthread_should_park(current);
 }
 EXPORT_SYMBOL_GPL(kthread_should_park);
 
Signature · 1 line
2.20.1.495.gaa96b0ce6b-goog
#2 lore raw

[tip:irq/core] kthread: Add __kthread_should_park()

kthread: Add __kthread_should_park()
Commit-ID:  0121805d9d2b1fff371e195c28e9b86ae38b5e47
Gitweb:     https://git.kernel.org/tip/0121805d9d2b1fff371e195c28e9b86ae38b5e47
Author:     Matthias Kaehlcke <[email protected]>
AuthorDate: Mon, 28 Jan 2019 15:46:24 -0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 10 Feb 2019 21:51:39 +0100

kthread: Add __kthread_should_park()

kthread_should_park() is used to check if the calling kthread ('current') should park, but there is no function to check whether an arbitrary kthread should be parked. The latter is required to plug a CPU hotplug race vs. a parking ksoftirqd thread.

The new __kthread_should_park() receives a task_struct as parameter to check if the corresponding kernel thread should be parked.

Call __kthread_should_park() from kthread_should_park() to avoid code duplication.

Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc "Paul E . McKenney" <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Stephen Boyd <[email protected]>
---
 include/linux/kthread.h | 1 +
 kernel/kthread.c        | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
include/linux/kthread.h +1 -0
index c1961761311d..1577a2d56e9d 100644
@@ -56,6 +56,7 @@ void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask);
 int kthread_stop(struct task_struct *k);
 bool kthread_should_stop(void);
 bool kthread_should_park(void);
+bool __kthread_should_park(struct task_struct *k);
 bool kthread_freezable_should_stop(bool *was_frozen);
 void *kthread_data(struct task_struct *k);
 void *kthread_probe_data(struct task_struct *k);
kernel/kthread.c +7 -1
index 087d18d771b5..65234c89d85b 100644
@@ -101,6 +101,12 @@ bool kthread_should_stop(void)
 }
 EXPORT_SYMBOL(kthread_should_stop);
 
+bool __kthread_should_park(struct task_struct *k)
+{
+	return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(k)->flags);
+}
+EXPORT_SYMBOL_GPL(__kthread_should_park);
+
 /**
  * kthread_should_park - should this kthread park now?
  *
@@ -114,7 +120,7 @@ EXPORT_SYMBOL(kthread_should_stop);
  */
 bool kthread_should_park(void)
 {
-	return test_bit(KTHREAD_SHOULD_PARK, &to_kthread(current)->flags);
+	return __kthread_should_park(current);
 }
 EXPORT_SYMBOL_GPL(kthread_should_park);
 
#3 lore raw

PATCH 2/2 softirq: Don't skip softirq execution when softirq thread is parking

In reply to Matthias Kaehlcke

When a CPU is unplugged the kernel threads of this CPU are parked (see smpboot_park_threads()). kthread_park() is used to mark each thread as parked and wake it up, so it can complete the process of parking itselfs (see smpboot_thread_fn()).

If local softirqs are pending on interrupt exit invoke_softirq() is called to process the softirqs, however it skips processing when the softirq kernel thread of the local CPU is scheduled to run. The softirq kthread is one of the threads that is parked when a CPU is unplugged. Parking the kthread wakes it up, however only to complete the parking process, not to process the pending softirqs. Hence processing of softirqs at the end of an interrupt is skipped, but not done elsewhere, which can result in warnings about pending softirqs when a CPU is unplugged:

/sys/devices/system/cpu # echo 0 > cpu4/online
[ ... ] NOHZ: local_softirq_pending 02
[ ... ] NOHZ: local_softirq_pending 202
[ ... ] CPU4: shutdown
[ ... ] psci: CPU4 killed.

Don't skip processing of softirqs at the end of an interrupt when the softirq thread of the CPU is parking.

---
 kernel/softirq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/softirq.c +2 -1
index d28813306b2c2..10277429ed84f 100644
@@ -89,7 +89,8 @@ static bool ksoftirqd_running(unsigned long pending)
 
 	if (pending & SOFTIRQ_NOW_MASK)
 		return false;
-	return tsk && (tsk->state == TASK_RUNNING);
+	return tsk && (tsk->state == TASK_RUNNING) &&
+		!__kthread_should_park(tsk);
 }
 
 /*
Signature · 1 line
2.20.1.495.gaa96b0ce6b-goog
#4 lore raw
softirq: Don't skip softirq execution when softirq thread is parking
Commit-ID:  1342d8080f6183b0419a9246c6e6545e21fa1e05
Gitweb:     https://git.kernel.org/tip/1342d8080f6183b0419a9246c6e6545e21fa1e05
Author:     Matthias Kaehlcke <[email protected]>
AuthorDate: Mon, 28 Jan 2019 15:46:25 -0800
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sun, 10 Feb 2019 21:51:39 +0100

softirq: Don't skip softirq execution when softirq thread is parking

When a CPU is unplugged the kernel threads of this CPU are parked (see smpboot_park_threads()). kthread_park() is used to mark each thread as parked and wake it up, so it can complete the process of parking itselfs (see smpboot_thread_fn()).

If local softirqs are pending on interrupt exit invoke_softirq() is called to process the softirqs, however it skips processing when the softirq kernel thread of the local CPU is scheduled to run. The softirq kthread is one of the threads that is parked when a CPU is unplugged. Parking the kthread wakes it up, however only to complete the parking process, not to process the pending softirqs. Hence processing of softirqs at the end of an interrupt is skipped, but not done elsewhere, which can result in warnings about pending softirqs when a CPU is unplugged:

/sys/devices/system/cpu # echo 0 > cpu4/online
[ ... ] NOHZ: local_softirq_pending 02
[ ... ] NOHZ: local_softirq_pending 202
[ ... ] CPU4: shutdown
[ ... ] psci: CPU4 killed.

Don't skip processing of softirqs at the end of an interrupt when the softirq thread of the CPU is parking.

Cc Peter Zijlstra <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc "Paul E . McKenney" <[email protected]>
Cc Sebastian Andrzej Siewior <[email protected]>
Cc Douglas Anderson <[email protected]>
Cc Stephen Boyd <[email protected]>
---
 kernel/softirq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/softirq.c +2 -1
index d28813306b2c..10277429ed84 100644
@@ -89,7 +89,8 @@ static bool ksoftirqd_running(unsigned long pending)
 
 	if (pending & SOFTIRQ_NOW_MASK)
 		return false;
-	return tsk && (tsk->state == TASK_RUNNING);
+	return tsk && (tsk->state == TASK_RUNNING) &&
+		!__kthread_should_park(tsk);
 }
 
 /*