mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>
Cc: sched-ext@lists.linux.dev, David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	David Dai <david.dai@linux.dev>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] sched_ext: scx_qmap: Also re-enqueue stranded tasks with scx_bpf_dsq_reenq_task()
Date: Sun, 18 Oct 2026 01:06:39 +0200	[thread overview]
Message-ID: <atP_f5S5v_1V06L2@gpd4> (raw)
In-Reply-To: <20261017223738.993262-4-tj@kernel.org>

On Sat, Oct 17, 2026 at 12:37:38PM -1000, Tejun Heo wrote:
> scan_shared_dsq() rescues a task stranded on SHARED_DSQ or HIGHPRI_DSQ by
> moving it to the rescue path with scx_bpf_dsq_move(). For a task with an odd
> pid, mark it with scx_bpf_dsq_reenq_task() instead, which sends it back
> through qmap_enqueue() and its rescue, so that both kfuncs are exercised.
> 
> scan_shared_dsq() runs from qmap_dispatch() and from the monitor timer, so
> the kfunc can be called both with the dispatch rq locked and with no rq lock
> held.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
>  tools/sched_ext/scx_qmap.bpf.c | 50 +++++++++++++++++++++-------------
>  1 file changed, 31 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
> index 61143a2d79f8..e8e451be862d 100644
> --- a/tools/sched_ext/scx_qmap.bpf.c
> +++ b/tools/sched_ext/scx_qmap.bpf.c
> @@ -651,10 +651,35 @@ static void update_core_sched_head_seq(struct task_struct *p)
>  		qa.core_sched_head_seqs[idx] = taskc->core_sched_seq;
>  }
>  
> +/*
> + * Send @p, stranded on the DSQ @it iterates, to the kernel rescue path. To
> + * exercise both kfuncs, move tasks with an even pid there with
> + * scx_bpf_dsq_move() and re-enqueue the others with scx_bpf_dsq_reenq_task(),
> + * which takes them through qmap_enqueue()'s rescue. The choice is per task so
> + * that a marked task isn't moved by another scan before the re-enqueue reaches
> + * it.
> + */
> +static __always_inline void rescue_stranded(struct bpf_iter_scx_dsq *it,
> +					    struct task_struct *p, task_ctx_t *taskc)
> +{
> +	s32 c;
> +
> +	if (p->pid & 1) {

nit: if ((p->pid & 1) && __COMPAT_has_dsq_reenq_task())

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

Thanks,
-Andrea

> +		scx_bpf_dsq_reenq_task(it, p);
> +		return;
> +	}
> +
> +	c = cmask_next_set_wrap(&taskc->cpus_allowed, 0);
> +	if (c >= 0 && c < scx_bpf_nr_cids()) {
> +		__sync_fetch_and_add(&qa.nr_rescue_dsp, 1);
> +		scx_bpf_dsq_move(it, p, SCX_DSQ_LOCAL_ON | c, SCX_ENQ_RESCUE);
> +	}
> +}
> +
>  /*
>   * One pass over SHARED_DSQ: rescue stranded tasks and boost highpri ones. A
>   * task whose cids were lost while it was queued in the fifos would strand on
> - * SHARED_DSQ, which is consumed only on self cids it can't run on - move it to
> + * SHARED_DSQ, which is consumed only on self cids it can't run on - send it to
>   * the kernel rescue path. One whose cids were lost after the highpri cull is
>   * likewise rescued out of HIGHPRI_DSQ below.
>   *
> @@ -663,9 +688,9 @@ static void update_core_sched_head_seq(struct task_struct *p)
>   * consuming them first. This makes minor difference only when dsp_batch is
>   * larger than 1.
>   *
> - * scx_bpf_dsq_move[_vtime]() are allowed both from ops.dispatch() and
> - * non-rq-lock holding BPF programs. As demonstration, this function is called
> - * from qmap_dispatch() and monitor_timerfn().
> + * scx_bpf_dsq_move[_vtime]() and scx_bpf_dsq_reenq_task() are allowed both from
> + * ops.dispatch() and non-rq-lock holding BPF programs. As demonstration, this
> + * function is called from qmap_dispatch() and monitor_timerfn().
>   */
>  static bool scan_shared_dsq(bool from_timer)
>  {
> @@ -677,19 +702,13 @@ static bool scan_shared_dsq(bool from_timer)
>  	bpf_for_each(scx_dsq, p, SHARED_DSQ, 0) {
>  		static u64 highpri_seq;
>  		task_ctx_t *taskc;
> -		s32 c;
>  
>  		if (!(taskc = lookup_task_ctx(p)))
>  			return false;
>  
>  		/* stranded? rescue - it can't be dispatched here either way */
>  		if (!cmask_intersects(&taskc->cpus_allowed, &qa.self_cids.mask)) {
> -			c = cmask_next_set_wrap(&taskc->cpus_allowed, 0);
> -			if (c >= 0 && c < scx_bpf_nr_cids()) {
> -				__sync_fetch_and_add(&qa.nr_rescue_dsp, 1);
> -				scx_bpf_dsq_move(BPF_FOR_EACH_ITER, p, SCX_DSQ_LOCAL_ON | c,
> -						 SCX_ENQ_RESCUE);
> -			}
> +			rescue_stranded(BPF_FOR_EACH_ITER, p, taskc);
>  			continue;
>  		}
>  
> @@ -723,19 +742,12 @@ static bool scan_shared_dsq(bool from_timer)
>  						      &qa.usable_cids.mask,
>  						      this_cid + 1);
>  		if (cid >= nr_cids) {
> -			s32 c;
> -
>  			/* self cids lack caps in effect yet, leave it queued */
>  			if (cmask_intersects(&taskc->cpus_allowed, &qa.self_cids.mask))
>  				continue;
>  
>  			/* stranded after the cull - rescue it from here */
> -			c = cmask_next_set_wrap(&taskc->cpus_allowed, 0);
> -			if (c >= 0 && c < nr_cids) {
> -				__sync_fetch_and_add(&qa.nr_rescue_dsp, 1);
> -				scx_bpf_dsq_move(BPF_FOR_EACH_ITER, p, SCX_DSQ_LOCAL_ON | c,
> -						 SCX_ENQ_RESCUE);
> -			}
> +			rescue_stranded(BPF_FOR_EACH_ITER, p, taskc);
>  			continue;
>  		}
>  
> -- 
> 2.56.0
> 

  reply	other threads:[~2026-10-17 23:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 22:37 [PATCHSET sched_ext/for-7.4] sched_ext: Add scx_bpf_dsq_reenq_task() Tejun Heo
2026-10-17 22:37 ` [PATCH 1/3] sched_ext: Factor out the rq lock switch of scx_dsq_move() Tejun Heo
2026-10-17 22:52   ` Andrea Righi
2026-10-17 22:37 ` [PATCH 2/3] sched_ext: Add scx_bpf_dsq_reenq_task() to re-enqueue single tasks from a DSQ iteration Tejun Heo
2026-10-17 23:01   ` Andrea Righi
2026-10-17 23:35   ` [PATCH v2 " Tejun Heo
2026-10-17 22:37 ` [PATCH 3/3] sched_ext: scx_qmap: Also re-enqueue stranded tasks with scx_bpf_dsq_reenq_task() Tejun Heo
2026-10-17 23:06   ` Andrea Righi [this message]
2026-10-17 23:35     ` Tejun Heo
2026-10-18  6:14       ` Andrea Righi
2026-10-17 23:43 ` [PATCHSET sched_ext/for-7.4] sched_ext: Add scx_bpf_dsq_reenq_task() Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=atP_f5S5v_1V06L2@gpd4 \
    --to=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=david.dai@linux.dev \
    --cc=emil@etsalapatis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®