Skip to contentSkip to conversation

sched: Remove pointless preemption disable in sched_submit_work()

PATCH Applied Thomas Gleixner 4 participants 6 messages Sep 28, 2021 – Oct 5, 2021 Scheduler

lore
Share & tools
lore
#0 lore raw

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it.

---
 kernel/sched/core.c |    2 --
 1 file changed, 2 deletions(-)
kernel/sched/core.c +0 -2
@@ -6327,12 +6327,10 @@ static inline void sched_submit_work(str
 	 * requires it.
 	 */
 	if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
-		preempt_disable();
 		if (task_flags & PF_WQ_WORKER)
 			wq_worker_sleeping(tsk);
 		else
 			io_wq_worker_sleeping(tsk);
-		preempt_enable_no_resched();
 	}
 
 	if (tsk_is_pi_blocked(tsk))
Reviewed-by
#1 lore raw
Quoted 10 lines · Thomas Gleixner

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it.

Signature · 1 line
Jens Axboe
Reviewed-by
#2 lore raw
In reply to Thomas Gleixner
Quoted 20 lines · Thomas Gleixner

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it.

---
 kernel/sched/core.c |    2 --
 1 file changed, 2 deletions(-)

kernel/sched/core.c static inline void sched_submit_work(str · line 6329

Quoted 3 lines
kernel/sched/core.c +0 -0
@@ -6327,12 +6327,10 @@ static inline void sched_submit_work(str
         * requires it.
         */
        if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {

Hello

The comment about preemption above this if branch and wq_worker_sleeping() needs to be removed.

Thanks
Lai

Quoted 9 lines
kernel/sched/core.c +0 -2
-               preempt_disable();
                if (task_flags & PF_WQ_WORKER)
                        wq_worker_sleeping(tsk);
                else
                        io_wq_worker_sleeping(tsk);
-               preempt_enable_no_resched();
        }
 
        if (tsk_is_pi_blocked(tsk))
#3 lore raw

PATCH v2 1/1 sched: Remove pointless preemption disable in sched_submit_work()

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it and update the stale comment.

---
V2: Update comment as pointed out by Lai

---
 kernel/sched/core.c |   13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
kernel/sched/core.c +2 -8
@@ -6319,20 +6319,14 @@ static inline void sched_submit_work(str
 
 	task_flags = tsk->flags;
 	/*
-	 * If a worker went to sleep, notify and ask workqueue whether
-	 * it wants to wake up a task to maintain concurrency.
-	 * As this function is called inside the schedule() context,
-	 * we disable preemption to avoid it calling schedule() again
-	 * in the possible wakeup of a kworker and because wq_worker_sleeping()
-	 * requires it.
+	 * If a worker goes to sleep, notify and ask workqueue whether it
+	 * wants to wake up a task to maintain concurrency.
 	 */
 	if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
-		preempt_disable();
 		if (task_flags & PF_WQ_WORKER)
 			wq_worker_sleeping(tsk);
 		else
 			io_wq_worker_sleeping(tsk);
-		preempt_enable_no_resched();
 	}
 
 	if (tsk_is_pi_blocked(tsk))
#4 lore raw
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     579df3f2325191322b96906a5898462253a45ede
Gitweb:        https://git.kernel.org/tip/579df3f2325191322b96906a5898462253a45ede
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Wed, 29 Sep 2021 11:37:32 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 01 Oct 2021 13:58:07 +02:00

sched: Remove pointless preemption disable in sched_submit_work()

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it and update the stale comment.

---
 kernel/sched/core.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/sched/core.c +2 -8
index 8e49b17..d469c7b 100644
@@ -6097,20 +6097,14 @@ static inline void sched_submit_work(struct task_struct *tsk)
 
 	task_flags = tsk->flags;
 	/*
-	 * If a worker went to sleep, notify and ask workqueue whether
-	 * it wants to wake up a task to maintain concurrency.
-	 * As this function is called inside the schedule() context,
-	 * we disable preemption to avoid it calling schedule() again
-	 * in the possible wakeup of a kworker and because wq_worker_sleeping()
-	 * requires it.
+	 * If a worker goes to sleep, notify and ask workqueue whether it
+	 * wants to wake up a task to maintain concurrency.
 	 */
 	if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
-		preempt_disable();
 		if (task_flags & PF_WQ_WORKER)
 			wq_worker_sleeping(tsk);
 		else
 			io_wq_worker_sleeping(tsk);
-		preempt_enable_no_resched();
 	}
 
 	if (tsk_is_pi_blocked(tsk))
#5 lore raw
In reply to Thomas Gleixner
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     b945efcdd07d86cece1cce68503aae91f107eacb
Gitweb:        https://git.kernel.org/tip/b945efcdd07d86cece1cce68503aae91f107eacb
Author:        Thomas Gleixner <[email protected]>
AuthorDate:    Wed, 29 Sep 2021 11:37:32 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 05 Oct 2021 15:52:15 +02:00

sched: Remove pointless preemption disable in sched_submit_work()

Neither wq_worker_sleeping() nor io_wq_worker_sleeping() require to be invoked with preemption disabled:

- The worker flag checks operations only need to be serialized against the worker thread itself.

- The accounting and worker pool operations are serialized with locks.

which means that disabling preemption has neither a reason nor a value. Remove it and update the stale comment.

---
 kernel/sched/core.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
kernel/sched/core.c +2 -8
index e33b03c..e47d7e5 100644
@@ -6251,20 +6251,14 @@ static inline void sched_submit_work(struct task_struct *tsk)
 
 	task_flags = tsk->flags;
 	/*
-	 * If a worker went to sleep, notify and ask workqueue whether
-	 * it wants to wake up a task to maintain concurrency.
-	 * As this function is called inside the schedule() context,
-	 * we disable preemption to avoid it calling schedule() again
-	 * in the possible wakeup of a kworker and because wq_worker_sleeping()
-	 * requires it.
+	 * If a worker goes to sleep, notify and ask workqueue whether it
+	 * wants to wake up a task to maintain concurrency.
 	 */
 	if (task_flags & (PF_WQ_WORKER | PF_IO_WORKER)) {
-		preempt_disable();
 		if (task_flags & PF_WQ_WORKER)
 			wq_worker_sleeping(tsk);
 		else
 			io_wq_worker_sleeping(tsk);
-		preempt_enable_no_resched();
 	}
 
 	if (tsk_is_pi_blocked(tsk))