File: 0113-sched-workqueue-Only-wake-up-idle-workers-if-not-blo.patch

package info (click to toggle)
linux 4.19.194-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 967,940 kB
  • sloc: ansic: 16,799,826; asm: 272,028; makefile: 38,421; sh: 33,838; perl: 27,701; python: 21,148; cpp: 5,066; yacc: 4,650; lex: 2,584; awk: 1,385; ruby: 25; sed: 5
file content (45 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 909f8288829d620b516ea8b42d33f72df3d54157 Mon Sep 17 00:00:00 2001
From: Steven Rostedt <rostedt@goodmis.org>
Date: Mon, 18 Mar 2013 15:12:49 -0400
Subject: [PATCH 113/338] sched/workqueue: Only wake up idle workers if not
 blocked on sleeping spin lock
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patches-4.19.193-rt81.tar.xz

In -rt, most spin_locks() turn into mutexes. One of these spin_lock
conversions is performed on the workqueue gcwq->lock. When the idle
worker is worken, the first thing it will do is grab that same lock and
it too will block, possibly jumping into the same code, but because
nr_running would already be decremented it prevents an infinite loop.

But this is still a waste of CPU cycles, and it doesn't follow the method
of mainline, as new workers should only be woken when a worker thread is
truly going to sleep, and not just blocked on a spin_lock().

Check the saved_state too before waking up new workers.


Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index d90e666c991a..0915e400eff8 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3541,8 +3541,10 @@ static void __sched notrace __schedule(bool preempt)
 			 * If a worker went to sleep, notify and ask workqueue
 			 * whether it wants to wake up a task to maintain
 			 * concurrency.
+			 * Only call wake up if prev isn't blocked on a sleeping
+			 * spin lock.
 			 */
-			if (prev->flags & PF_WQ_WORKER) {
+			if (prev->flags & PF_WQ_WORKER && !prev->saved_state) {
 				struct task_struct *to_wakeup;
 
 				to_wakeup = wq_worker_sleeping(prev);
-- 
2.31.1