Re: [PATCH 12/14] sched: Add shared runqueue locking to __task_rq_lock()

Peter Zijlstra
2025-09-12T14:12:09Z

On Fri, Sep 12, 2025 at 01:54:59PM +0200, Peter Zijlstra wrote:
> On Thu, Sep 11, 2025 at 02:19:57PM -1000, Tejun Heo wrote:
> > Hello,
> >
> > On Wed, Sep 10, 2025 at 05:44:21PM +0200, Peter Zijlstra wrote:
> > > @@ -703,17 +703,24 @@ void double_rq_lock(struct rq *rq1, stru
> > > struct rq *__task_rq_lock(struct task_struct *p, struct rq_flags *rf)
> > > __acquires(rq->lock)
> > > {
> > > + raw_spinlock_t *slock;
> > > struct rq *rq;
> > >
> > > lockdep_assert_held(&p->pi_lock);
> > >
> > > for (;;) {
> > > rq = task_rq(p);
> > > + slock = p->srq_lock;
> > > raw_spin_rq_lock(rq);
> > > - if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) {
> > > + if (slock)
> > > + raw_spin_lock(slock);
> > > + if (likely(rq == task_rq(p) && !task_on_rq_migrating(p) &&
> > > + (!slock || p->srq_lock == slock))) {
> > > rq_pin_lock(rq, rf);
> > > return rq;
> > > }
>
> Yeah, I think that needs to change a little. Perhaps something like:
>
> slock2 = p->srq_lock;
> if (... && (!slock2 || slock2 == slock))

I'm being stupid, all that wants is: && (p->srq_lock == slock). If there
is a mis-match, unlock and re-try.