From: K Prateek Nayak <kprateek.nayak@amd.com>
To: John Stultz <jstultz@google.com>
Cc: Suleiman Souhlal <suleiman@google.com>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Will Deacon <will@kernel.org>, Boqun Feng <boqun@kernel.org>,
Andrea Righi <arighi@nvidia.com>, <linux-kernel@vger.kernel.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>,
"Waiman Long" <longman@redhat.com>
Subject: Re: [RFC PATCH 04/16] sched/core: Activate blocked donor when no owner is found
Date: Wed, 16 Sep 2026 09:46:40 +0530 [thread overview]
Message-ID: <d0d2b334-d7e2-4a4e-87e3-d24e6f3afbc2@amd.com> (raw)
In-Reply-To: <CANDhNCrgA4FtvybSaigh1nfDr2r+xz5FDrhpWHnD3FS3FD2tWA@mail.gmail.com>
Hello John,
On 9/16/2026 8:59 AM, John Stultz wrote:
> On Tue, Aug 25, 2026 at 11:30 PM K Prateek Nayak <kprateek.nayak@amd.com> wrote:
>>
>> mutex_unlock_slowpath() follows:
>>
>> if (owner & MUTEX_FLAG_HANDOFF)
>> break /* ... and do __mutex_handoff() */
>>
>> if (atomic_long_try_cmpxchg_release(&lock->owner, &owner, __owner_flags(owner))) {
>> if (owner & MUTEX_FLAG_WAITERS)
>> break; /* ... and wake up the forst waiter. */
>>
>> MUTEX_FLAG_HANDOFF is only set by first-waiter after it has been woken
>> up and in absence of MUTEX_FLAG_HANDOFF, the owner clears itself from
>> the lock_word and wakes up the first waiter to try a
>> __mutex_trylock_or_handoff().
>
> We also set it when there is a blocked_donor, to ensure the task
> donating its time to the owner gets the lock next.
Ack! I just considered that to be the same as a MUTEX_FLAG_HANDOFF ;-)
>
>> MUTEX_FLAG_HANDOFF exists to prevent new optimistic spinners from
>> trying to hijack the lock from waiter all the time and potentially
>> starving them but it is not necessary for MUTEX_FLAG_HANDOFF to be
>> always set in presence of a waiter.
>>
>> If a blocked donor is deactivated when no owner is observed, it may not
>> be woken up until it becomes the first waiter and is naturally woken up
>> which breaks proxy in the interim.
>
> Hrm. So in older versions of the proxy-migration/return-migration
> logic, if the owner was NULL we'd clear the donor's blocked_on and
> either run it or do return migration, which I guess wouldn't see this
> issue.
>
> I'm curious, is this behavior something you've observed directly or
> did you just find it through code inspection?
I was testing chain migration and I would see some task just block and
stop proxy.
It basically led to an observation where I would see most tasks, which
are being proxied, finish quickly, and the ones that were fully blocked
would wake last one by one and finish slowly.
> I'm wondering as in playing with Suleiman's proxy-futex work I've seen
> a few traces that had some unexpected behavior and I'm wondering if
> this might be the cause.
>
>> Wake up the blocked donor and allow it to grab the lock when no owner is
>> observed. If the task manages to grab the lock, the block chain will
>> follow at the next proxy migration. If the task fails to grab the lock,
>> same situation is restored and everyone migrated to the CPU of new
>> owner.
>
> This seems reasonable to me. For the situation to occcur, we'd need
> the task A to be deep on the waiter list, and be in blocked_on chain
> from a selected donor, and the lock its blocked on to be unlocked and
> ownerlist before the woken top waiter is able to take it.
>
> If the task is important enough to be in a donor chain, then we might
> as well wake it and let it try to steal the lock. That seems better
> than deactivating it and the whole chain until it rises to the top of
> the lock waiter-list. Especaially as if we came in a moment later and
> found it owned, we'd be potentially migrating the whole chain to a
> different runqueue just to boost it. So yeah, making the most of the
> opportunity and trying to grab it makes sense to me.
>
>>
>> Fixes: f13beb010e4a ("sched: Have try_to_wake_up() handle return-migration for PROXY_WAKING case")
>> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
>> ---
>> XXX: Is there a better way to handle this? If we can confirm a owner in
>> find_proxy_task(), we don't need to do a spurious wakeup of every task
>> observing !owner.
>
> I guess I'd want to get some metrics to see how common spurious
> wakeups are and how problematic they might be.
I think it is rare with proxy - if there is an active donor, we do a
handoff and we don't have a problem. The only way we have wasteful
wakeups is if many CPUs have a blocked donor that see the same lock
having !owner and all decide to wakeup at the same time.
>
>> proxy_resched_idle() until owner appears in an option but it will spin
>> until next owner appears.
>
> Eh, that feels wasteful (especially if the top waiter unlock woke up
> ends up deep in the runqueue and doesn't run for awhile - I see Andrea
> raised this point).
Yes, and I had weird (borderline criminal) ways to get around that in
https://lore.kernel.org/lkml/fe1bef59-e047-4008-b498-0c0d49a2be76@amd.com/
> I've lightly tested with this and it seemed ok. Though I want to do
> some more runs with it applied along with the proxy-futex code to
> understand if it helps.
Ack! As mentioned in the cover letter, I have only tried this in
middle of your pile where futex bits hadn't come yet and similar
to chain wakeup, my head started spinning after reaching the
cpupri bits.
One of these days I'll be able to push through :-)
>
> Acked-by: John Stultz <jstultz@google.com>
Thanks a ton.
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-09-16 4:16 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 6:28 [RFC PATCH 00/16][PoC] sched/core: Alternate approach to sleeping-owner handling in PROXY_EXEC K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 01/16] sched/core: Break activation of blocked task into a separate helper K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 02/16] sched/core: Use enqueue/dequeue flags instead of task_on_rq_migrating() K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 03/16] sched/fair: Use enqueue flags for DO_ATTACH in update_load_avg() K Prateek Nayak
2026-08-26 15:36 ` Andrea Righi
2026-08-26 6:28 ` [RFC PATCH 04/16] sched/core: Activate blocked donor when no owner is found K Prateek Nayak
2026-08-26 15:56 ` Andrea Righi
2026-08-26 17:20 ` K Prateek Nayak
2026-08-28 6:04 ` K Prateek Nayak
2026-08-31 15:07 ` Andrea Righi
2026-09-16 4:16 ` K Prateek Nayak
2026-09-16 3:29 ` John Stultz
2026-09-16 4:16 ` K Prateek Nayak [this message]
2026-08-26 6:28 ` [RFC PATCH 05/16] sched/core: Do not queue blocked donor on a delayed owner K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 06/16] sched/core: Queue blocked donor onto sleeping owner for chain-wakeup K Prateek Nayak
2026-08-26 16:20 ` Andrea Righi
2026-08-27 3:51 ` K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 07/16] sched/core: Avoid delaying blocked donors queued on sleeping owner K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 08/16] sched/deadline: Prepare for blocking and proxy activation with MIGRATING flag K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 09/16] sched/core: Track CPU where the task was blocked on K Prateek Nayak
2026-09-16 5:52 ` John Stultz
2026-09-16 6:29 ` K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 10/16] sched/core: Introduce p->is_linked to track if task is queued on sleeping owner K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 11/16] sched/core: Prepare to inspect ->is_linked alongside ->on_rq during wakeup K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 12/16] sched:core: Add MIGRATING flags when blocking and activating linked donors K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 13/16] sched/core: Use p->is_linked state to unlink from sleeping owner early K Prateek Nayak
2026-08-26 6:28 ` [RFC PATCH 14/16] sched/core: Introduce chain-wakeup to activate blocked donors K Prateek Nayak
2026-09-15 5:48 ` John Stultz
2026-08-26 6:28 ` [RFC PATCH 15/16] locking/mutex: Track locks owned by a task in a per-task counter K Prateek Nayak
2026-08-26 6:29 ` [RFC PATCH 16/16] sched/core: Set activation of non lock-holders to fast-path K Prateek Nayak
2026-09-16 5:22 ` [RFC PATCH 00/16][PoC] sched/core: Alternate approach to sleeping-owner handling in PROXY_EXEC John Stultz
2026-09-16 6:10 ` K Prateek Nayak
2026-09-16 6:23 ` John Stultz
2026-09-16 6:59 ` K Prateek Nayak
2026-09-16 17:57 ` John Stultz
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=d0d2b334-d7e2-4a4e-87e3-d24e6f3afbc2@amd.com \
--to=kprateek.nayak@amd.com \
--cc=arighi@nvidia.com \
--cc=boqun@kernel.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=suleiman@google.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.org \
/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®