mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue
@ 2026-10-17 23:58 Tejun Heo
  2026-10-18  6:07 ` Andrea Righi
  2026-10-18  6:24 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Tejun Heo @ 2026-10-17 23:58 UTC (permalink / raw)
  To: sched-ext
  Cc: David Vernet, Andrea Righi, Changwoo Min, Emil Tsalapatis,
	David Dai, linux-kernel, Tejun Heo

reenq_user() drops dsq->lock around each re-enqueue and its rq lock every
SCX_TASK_ITER_BATCH re-enqueues. A walk filtered by SCX_REENQ_MARKED skips
unmarked tasks without dropping either, so a long run of unmarked tasks is
walked in one hold of both locks.

Count the visited tasks instead of the re-enqueued ones and drop both locks
every SCX_TASK_ITER_BATCH visits. An unfiltered walk drops the locks as
often as before.

Suggested-by: Andrea Righi <arighi@nvidia.com>
Link: https://lore.kernel.org/all/atP-LIKpxPhR-Nuc@gpd4/
Signed-off-by: Tejun Heo <tj@kernel.org>
---
 kernel/sched/ext/ext.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 14fe63428036..07857039aee6 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -5111,7 +5111,7 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
 	struct scx_sched *sch = dsq->sched;
 	struct scx_dsq_list_node cursor = INIT_DSQ_LIST_CURSOR(cursor, dsq, 0);
 	struct task_struct *p;
-	s32 nr_enqueued = 0;
+	s32 nr_visited = 0;
 
 	lockdep_assert_rq_held(rq);
 
@@ -5121,6 +5121,21 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
 		struct rq *task_rq;
 		u32 reason;
 
+		/*
+		 * Count skipped tasks too so that a long walk doesn't hold the
+		 * locks throughout. The cursor keeps the position.
+		 */
+		if (!(++nr_visited % SCX_TASK_ITER_BATCH)) {
+			raw_spin_unlock(&dsq->lock);
+			if (locked_rq) {
+				scx_rq_lock_drop(locked_rq);
+				raw_spin_rq_unlock(locked_rq);
+				locked_rq = NULL;
+			}
+			cpu_relax();
+			raw_spin_lock(&dsq->lock);
+		}
+
 		p = nldsq_cursor_next_task(&cursor, dsq);
 		if (!p)
 			break;
@@ -5157,13 +5172,6 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
 
 		scx_do_enqueue_task(task_rq, p, SCX_ENQ_REENQ, -1);
 
-		if (!(++nr_enqueued % SCX_TASK_ITER_BATCH)) {
-			scx_rq_lock_drop(locked_rq);
-			raw_spin_rq_unlock(locked_rq);
-			locked_rq = NULL;
-			cpu_relax();
-		}
-
 		raw_spin_lock(&dsq->lock);
 	}
 
-- 
2.56.0


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

* Re: [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue
  2026-10-17 23:58 [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue Tejun Heo
@ 2026-10-18  6:07 ` Andrea Righi
  2026-10-18  6:24 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Righi @ 2026-10-18  6:07 UTC (permalink / raw)
  To: Tejun Heo
  Cc: sched-ext, David Vernet, Changwoo Min, Emil Tsalapatis,
	David Dai, linux-kernel

On Sat, Oct 17, 2026 at 01:58:40PM -1000, Tejun Heo wrote:
> reenq_user() drops dsq->lock around each re-enqueue and its rq lock every
> SCX_TASK_ITER_BATCH re-enqueues. A walk filtered by SCX_REENQ_MARKED skips
> unmarked tasks without dropping either, so a long run of unmarked tasks is
> walked in one hold of both locks.
> 
> Count the visited tasks instead of the re-enqueued ones and drop both locks
> every SCX_TASK_ITER_BATCH visits. An unfiltered walk drops the locks as
> often as before.
> 
> Suggested-by: Andrea Righi <arighi@nvidia.com>
> Link: https://lore.kernel.org/all/atP-LIKpxPhR-Nuc@gpd4/
> Signed-off-by: Tejun Heo <tj@kernel.org>

Looks good!

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> ---
>  kernel/sched/ext/ext.c | 24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 14fe63428036..07857039aee6 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -5111,7 +5111,7 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
>  	struct scx_sched *sch = dsq->sched;
>  	struct scx_dsq_list_node cursor = INIT_DSQ_LIST_CURSOR(cursor, dsq, 0);
>  	struct task_struct *p;
> -	s32 nr_enqueued = 0;
> +	s32 nr_visited = 0;
>  
>  	lockdep_assert_rq_held(rq);
>  
> @@ -5121,6 +5121,21 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
>  		struct rq *task_rq;
>  		u32 reason;
>  
> +		/*
> +		 * Count skipped tasks too so that a long walk doesn't hold the
> +		 * locks throughout. The cursor keeps the position.
> +		 */
> +		if (!(++nr_visited % SCX_TASK_ITER_BATCH)) {
> +			raw_spin_unlock(&dsq->lock);
> +			if (locked_rq) {
> +				scx_rq_lock_drop(locked_rq);
> +				raw_spin_rq_unlock(locked_rq);
> +				locked_rq = NULL;
> +			}
> +			cpu_relax();
> +			raw_spin_lock(&dsq->lock);
> +		}
> +
>  		p = nldsq_cursor_next_task(&cursor, dsq);
>  		if (!p)
>  			break;
> @@ -5157,13 +5172,6 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
>  
>  		scx_do_enqueue_task(task_rq, p, SCX_ENQ_REENQ, -1);
>  
> -		if (!(++nr_enqueued % SCX_TASK_ITER_BATCH)) {
> -			scx_rq_lock_drop(locked_rq);
> -			raw_spin_rq_unlock(locked_rq);
> -			locked_rq = NULL;
> -			cpu_relax();
> -		}
> -
>  		raw_spin_lock(&dsq->lock);
>  	}
>  
> -- 
> 2.56.0
> 

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

* Re: [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue
  2026-10-17 23:58 [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue Tejun Heo
  2026-10-18  6:07 ` Andrea Righi
@ 2026-10-18  6:24 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2026-10-18  6:24 UTC (permalink / raw)
  To: sched-ext
  Cc: David Vernet, Andrea Righi, Changwoo Min, Emil Tsalapatis,
	David Dai, linux-kernel

Applied to sched_ext/for-7.4 with the following tag added:

 Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks.

--
tejun

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

end of thread, other threads:[~2026-10-18  6:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17 23:58 [PATCH sched_ext/for-7.4] sched_ext: Drop the locks periodically while walking a user DSQ for re-enqueue Tejun Heo
2026-10-18  6:07 ` Andrea Righi
2026-10-18  6:24 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®