All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] softirq: Don't skip softirq execution when softirq thread is parking
@ 2019-01-28 23:46 Matthias Kaehlcke
  2019-01-28 23:46 ` [PATCH 1/2] kthread: Add __kthread_should_park() Matthias Kaehlcke
  2019-01-28 23:46 ` [PATCH 2/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
  0 siblings, 2 replies; 5+ messages in thread
From: Matthias Kaehlcke @ 2019-01-28 23:46 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, Steven Rostedt,
	Paul E . McKenney, Sebastian Andrzej Siewior
  Cc: linux-kernel, Douglas Anderson, Stephen Boyd, Matthias Kaehlcke

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(-)

-- 
2.20.1.495.gaa96b0ce6b-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] kthread: Add __kthread_should_park()
  2019-01-28 23:46 [PATCH 0/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
@ 2019-01-28 23:46 ` Matthias Kaehlcke
  2019-02-10 20:56   ` [tip:irq/core] " tip-bot for Matthias Kaehlcke
  2019-01-28 23:46 ` [PATCH 2/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
  1 sibling, 1 reply; 5+ messages in thread
From: Matthias Kaehlcke @ 2019-01-28 23:46 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, Steven Rostedt,
	Paul E . McKenney, Sebastian Andrzej Siewior
  Cc: linux-kernel, Douglas Anderson, Stephen Boyd, Matthias Kaehlcke

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.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
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(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index c1961761311db..1577a2d56e9d4 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -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);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 087d18d771b53..65234c89d85b4 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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);
 
-- 
2.20.1.495.gaa96b0ce6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] softirq: Don't skip softirq execution when softirq thread is parking
  2019-01-28 23:46 [PATCH 0/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
  2019-01-28 23:46 ` [PATCH 1/2] kthread: Add __kthread_should_park() Matthias Kaehlcke
@ 2019-01-28 23:46 ` Matthias Kaehlcke
  2019-02-10 20:57   ` [tip:irq/core] " tip-bot for Matthias Kaehlcke
  1 sibling, 1 reply; 5+ messages in thread
From: Matthias Kaehlcke @ 2019-01-28 23:46 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, Steven Rostedt,
	Paul E . McKenney, Sebastian Andrzej Siewior
  Cc: linux-kernel, Douglas Anderson, Stephen Boyd, 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.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 kernel/softirq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index d28813306b2c2..10277429ed84f 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -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);
 }
 
 /*
-- 
2.20.1.495.gaa96b0ce6b-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip:irq/core] kthread: Add __kthread_should_park()
  2019-01-28 23:46 ` [PATCH 1/2] kthread: Add __kthread_should_park() Matthias Kaehlcke
@ 2019-02-10 20:56   ` tip-bot for Matthias Kaehlcke
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Matthias Kaehlcke @ 2019-02-10 20:56 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, hpa, linux-kernel, paulmck, rostedt, mka, mingo, tglx,
	bigeasy, dianders, swboyd

Commit-ID:  0121805d9d2b1fff371e195c28e9b86ae38b5e47
Gitweb:     https://git.kernel.org/tip/0121805d9d2b1fff371e195c28e9b86ae38b5e47
Author:     Matthias Kaehlcke <mka@chromium.org>
AuthorDate: Mon, 28 Jan 2019 15:46:24 -0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
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.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Douglas Anderson <dianders@chromium.org>
Cc: Stephen Boyd <swboyd@chromium.org>
Link: https://lkml.kernel.org/r/20190128234625.78241-2-mka@chromium.org

---
 include/linux/kthread.h | 1 +
 kernel/kthread.c        | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index c1961761311d..1577a2d56e9d 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -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);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 087d18d771b5..65234c89d85b 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -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);
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip:irq/core] softirq: Don't skip softirq execution when softirq thread is parking
  2019-01-28 23:46 ` [PATCH 2/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
@ 2019-02-10 20:57   ` tip-bot for Matthias Kaehlcke
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Matthias Kaehlcke @ 2019-02-10 20:57 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, paulmck, dianders, swboyd, bigeasy, mingo, peterz, tglx,
	linux-kernel, mka, rostedt

Commit-ID:  1342d8080f6183b0419a9246c6e6545e21fa1e05
Gitweb:     https://git.kernel.org/tip/1342d8080f6183b0419a9246c6e6545e21fa1e05
Author:     Matthias Kaehlcke <mka@chromium.org>
AuthorDate: Mon, 28 Jan 2019 15:46:25 -0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
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.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Douglas Anderson <dianders@chromium.org>
Cc: Stephen Boyd <swboyd@chromium.org>
Link: https://lkml.kernel.org/r/20190128234625.78241-3-mka@chromium.org

---
 kernel/softirq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index d28813306b2c..10277429ed84 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -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);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-10 20:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 23:46 [PATCH 0/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
2019-01-28 23:46 ` [PATCH 1/2] kthread: Add __kthread_should_park() Matthias Kaehlcke
2019-02-10 20:56   ` [tip:irq/core] " tip-bot for Matthias Kaehlcke
2019-01-28 23:46 ` [PATCH 2/2] softirq: Don't skip softirq execution when softirq thread is parking Matthias Kaehlcke
2019-02-10 20:57   ` [tip:irq/core] " tip-bot for Matthias Kaehlcke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.