The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: John Stultz <jstultz@google.com>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Christian Loehle <christian.loehle@arm.com>,
	David Dai <david.dai@linux.dev>, Koba Ko <kobak@nvidia.com>,
	Aiqun Yu <aiqun.yu@oss.qualcomm.com>,
	Shuah Khan <shuah@kernel.org>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 01/10] sched/core: Drop mutex locks before proxy rescheduling
Date: Sat, 11 Jul 2026 11:04:37 +0200	[thread overview]
Message-ID: <alIHJf72RhxOn40c@gpd4> (raw)
In-Reply-To: <CANDhNCoyO=KaOhQZDy4drXpyeCbwt9src3cpXe+1EFJgEpPN2w@mail.gmail.com>

On Fri, Jul 10, 2026 at 05:21:45PM -0700, John Stultz wrote:
> On Fri, Jul 10, 2026 at 1:47 PM Andrea Righi <arighi@nvidia.com> wrote:
> > Inspecting the proxy chain is not strictly required. A BPF scheduler can just
> > accept a blocked donor, enqueue it on its current CPU and let the core
> > proxy-exec path resolve and "virtually" migrate it as needed to the owner's CPU.
> >
> > The motivation for providing a scx_bpf_task_proxy_cpu() kfunc is purely for
> > optimization reasons. By knowing the owner's CPU, a scheduler could make more
> > informed admission decisions. For example, it can inspect the task currently
> > running on the target CPU, determine whether the donor should take precedence
> > over the running task and kick that CPU to trigger a preemption. Without this
> > information, the scheduler can only enqueue the donor and wait until the task
> > running on the owner's CPU releases it (potentially adding up to one time slice
> > of latency).
> 
> So... I suspect I'm missing a subtlety of scx, but in the non-scx
> case, if a blocked task is important enough to be selected on the
> current cpu, the find_proxy_task() logic will walk the chain and do
> the proxy-migration if needed and mark resched, so then that cpu can
> evaluate which of the currently running task or the migrated donor is
> important enough to run.

With scx if a resched is triggered balance_one() does this:

if (prev is runnable and prev->scx.slice > 0)
    keep running prev;

We need to set the prev->scx.slice to 0 to select the new task. That means, if
the donor is "more important" than the task running in the owner's CPU we need
to zero it's time slice. And This can be done via
scx_bpf_kick_cpu(cpu, SCX_KICK_PREEMPT).

That's the reason why I was considering introducing the
scx_bpf_task_proxy_cpu() kfunc.

However, I agree that this is adding too much complexity and we can ignore this
for now.

Moreover, let's also consider the following:
 - if donor and owner are on the same CPU everything is already working as
   intended without scx_bpf_task_proxy_cpu()
 - if donor and owner are on different CPUs, something like this should happen
   (D = donor, O = owner, C = contending task):

  CPU0                              CPU1
  ----                              ----
  D blocks                          C runs
  ops.enqueue(D, SCX_ENQ_BLOCKED)
    [D inserted into CPU0 local DSQ]
  D briefly yields to idle
  D selected from local DSQ
  D migrates ---------------------> ops.enqueue(D, SCX_ENQ_BLOCKED)
                                      [D enters CPU1 local DSQ]
                                    resched, but C retains its slice
                                    C continues
                                    C's slice expires
				    ops.enqueue(C, 0)
				      [C is returned to the BPF policy]
                                    D selected as donor
                                    O proxy-runs using D's slice
                                    O releases mutex

If we want to handle the preemption when the donor's CPU != owner's CPU we can
just use SCX_ENQ_PREEMPT when scx_bpf_cpu_curr(scx_bpf_task_cpu(p)) is an SCX
task.

So the BPF scheduler could do something like this:

ops.enqueue(p, enq_flags) {
  if (enq_flags & SCX_ENQ_BLOCKED) { // p is a donor
      struct task_struct *curr = scx_bpf_cpu_curr(cpu);

      if ((curr && task_is_scx(curr) && is_more_important(p, curr))
          enq_flags |= SCX_ENQ_PREEMPT; // curr->scx.slice to 0 + resched

      scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL_ON | cpu, 0, flags);
}

Therefore we don't really need scx_bpf_task_proxy_cpu().

> 
> I worry the difficulty (with my poor understanding of the
> optimization) is that it seems like its evaluting the preemption on
> admission (I assume this means the point when we keep the blocked_on
> task on the rq? I may be totally off base here), is that if a very
> important task was breifly running at that moment, you might not allow
> the blocked_on task to be enqueued. And at that point the donor is
> effectively sleeping and no proxying can happen until it wakes (which
> may be only when the lock owner eventually runs and releases the
> lock).  In this way the optimization might make a call in that instant
> that results in *many* time slices of latency (particularly if there
> are lots other unimportant tasks on that cpu).
> 
> By letting the proxy logic handle the proxy migration and
> rescheduling, the blocked_on tasks are just in the same pool of
> selectable tasks on that cpu and the scheduler on that cpu gets to
> decide what is the most important thing to run next.
> 
> Now, I can see the benefit of potentially saving the resched kick on
> the target cpu when we do a proxy-migration - it is an interesting
> idea I should think more on to see how we might do that better in the
> core logic.
> 
> > That said, I don't see a correctness dependency on exposing this information.
> > If the latency-policy use case is not strong enough to justify the API, I'm
> > happy to drop the query kfuncs and this preparatory lock-scope change for now,
> > the blocked-donor admission support can stand on its own.
> 
> Yeah. If that's the case I wonder if it might be worth waiting a bit
> on these optimizations until after the rest of the core proxy logic
> makes it upstream and settles a bit?

Agreed. I've already dropped that in my local tree. Let's keep it simple for
now. :)

> 
> It might also help make sure the demand for this
> optimization/interface is strong before we start adding interfaces
> prematurely.
> 
> Really, I'd like it to all be transparent to the class schedulers, but
> given the complexities, just having the ability for the scx bpf
> schedulers to disable keeping blocked_on tasks on the rq (effectively
> disabling scx proxy donation) seems like a good initial step.
> 
> Again, I am really excited about your work here! I've sadly really not
> had any time since Dec to look into sched_ext details, and I've had to
> tell a few folks who are interested in both sched_ext and proxy_exec
> that they should turn proxy_exec off if they want to use sched_ext.
> So I'm very eager to have a better answer there!
> 
> Thanks for all your great work here!
> -john

Thank you!
-Andrea

  reply	other threads:[~2026-07-11  9:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  8:36 [PATCHSET v4 sched_ext/for-7.3] sched: Make proxy execution compatible with sched_ext Andrea Righi
2026-07-10  8:36 ` [PATCH 01/10] sched/core: Drop mutex locks before proxy rescheduling Andrea Righi
2026-07-10 18:56   ` John Stultz
2026-07-10 20:47     ` Andrea Righi
2026-07-11  0:21       ` John Stultz
2026-07-11  9:04         ` Andrea Righi [this message]
2026-07-10  8:36 ` [PATCH 02/10] sched_ext: Fix ops.running/stopping() pairing for proxy-exec donors Andrea Righi
2026-07-10 21:33   ` John Stultz
2026-07-11  9:37     ` Andrea Righi
2026-07-10  8:36 ` [PATCH 03/10] sched_ext: Split curr|donor references properly Andrea Righi
2026-07-10  8:36 ` [PATCH 04/10] sched_ext: Fix TOCTOU race in consume_remote_task() Andrea Righi
2026-07-10  8:36 ` [PATCH 05/10] sched_ext: Handle blocked donor migration with proxy execution Andrea Righi
2026-07-10  8:36 ` [PATCH 06/10] sched_ext: Delegate proxy donor admission to BPF schedulers Andrea Righi
2026-07-11  1:43   ` John Stultz
2026-07-11  8:24     ` Andrea Righi
2026-07-10  8:36 ` [PATCH 07/10] sched_ext: Add proxy destination query kfuncs Andrea Righi
2026-07-10 21:54   ` John Stultz
2026-07-11  9:07     ` Andrea Righi
2026-07-10  8:36 ` [PATCH 08/10] sched_ext: Add selftest for blocked donor admission Andrea Righi
2026-07-10  8:36 ` [PATCH 09/10] sched_ext: scx_qmap: Add proxy execution support Andrea Righi
2026-07-10  8:36 ` [PATCH 10/10] sched: Allow enabling proxy exec with sched_ext Andrea Righi

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=alIHJf72RhxOn40c@gpd4 \
    --to=arighi@nvidia.com \
    --cc=aiqun.yu@oss.qualcomm.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=christian.loehle@arm.com \
    --cc=david.dai@linux.dev \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kobak@nvidia.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.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