From: Peter Zijlstra <peterz@infradead.org>
To: Tejun Heo <tj@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, David Vernet <void@manifault.com>,
Ingo Molnar <mingo@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [GIT PULL] sched_ext: Initial pull request for v6.11
Date: Tue, 6 Aug 2024 10:27:16 +0200 [thread overview]
Message-ID: <20240806082716.GP37996@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Zq0p154ndOtU9Ypu@slm.duckdns.org>
On Fri, Aug 02, 2024 at 08:47:51AM -1000, Tejun Heo wrote:
> > > +static bool consume_remote_task(struct rq *rq, struct scx_dispatch_q *dsq,
> > > + struct task_struct *p, struct rq *task_rq)
> > > +{
> > > + bool moved = false;
> > > +
> > > + lockdep_assert_held(&dsq->lock); /* released on return */
> > > +
> > > + /*
> > > + * @dsq is locked and @p is on a remote rq. @p is currently protected by
> > > + * @dsq->lock. We want to pull @p to @rq but may deadlock if we grab
> > > + * @task_rq while holding @dsq and @rq locks. As dequeue can't drop the
> > > + * rq lock or fail, do a little dancing from our side. See
> > > + * move_task_to_local_dsq().
> > > + */
> > > + WARN_ON_ONCE(p->scx.holding_cpu >= 0);
> > > + task_unlink_from_dsq(p, dsq);
> > > + dsq_mod_nr(dsq, -1);
> > > + p->scx.holding_cpu = raw_smp_processor_id();
> > > + raw_spin_unlock(&dsq->lock);
> > > +
> > > + double_lock_balance(rq, task_rq);
> > > +
> > > + moved = move_task_to_local_dsq(rq, p, 0);
> > > +
> > > + double_unlock_balance(rq, task_rq);
> > > +
> > > + return moved;
> > > +}
> >
> > I've gotta ask, why are you using the double_lock_balance() pattern
> > instead of the one in move_queued_task() that does:
> >
> > lock src
> > dequeue src, task
> > set_task_cpu task, dst
> > unlock src
> >
> > lock dst
> > enqueue dst, task
> > unlock dst
>
> When !CONFIG_PREEMPTION, double_lock_balance() seems cheaper than unlocking
> and locking unconditionally. Because SCX schedulers can do a lot more hot
> migrations, I thought it'd be better to go that way. I haven't actually
> measured anything tho, so I could be wrong.
So I think the theory is something like this.
If you take a spinlock, you wait-time W is N times the hold-time H,
where the hold-time is avg/max (depending on your analysis goals) time
you hold the lock for, and N is the contention level or number of
waiters etc.
Now, when you go nest locks, your hold-time increases with the wait-time
of the nested lock. In this case, since it's the 'same' lock, your
hold-time gets a recursive wait-time term, that is: H'=H+N*H.
This blows up your wait-time, which makes contention worse. Because what
was W=N*H then becomes W=N*(N*H).
Anyway, at the time we saw great benefits from moving away from the
double-lock thing, it might be worth looking into when/if you see
significant lock contention; because obviously if the locks are not
contended it all doesn't matter.
next prev parent reply other threads:[~2024-08-06 8:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 22:32 [GIT PULL] sched_ext: Initial pull request for v6.11 Tejun Heo
2024-07-23 16:33 ` Peter Zijlstra
2024-07-23 19:34 ` Tejun Heo
2024-07-24 8:52 ` Peter Zijlstra
2024-07-24 17:38 ` David Vernet
2024-07-31 1:36 ` Tejun Heo
2024-08-02 11:10 ` Peter Zijlstra
2024-08-02 16:09 ` Tejun Heo
2024-08-02 17:37 ` Peter Zijlstra
2024-08-06 21:10 ` Peter Zijlstra
2024-08-06 21:34 ` Tejun Heo
2024-08-06 21:55 ` Peter Zijlstra
2024-08-06 22:09 ` Tejun Heo
2024-08-10 20:45 ` Peter Zijlstra
2024-08-13 19:14 ` Tejun Heo
2024-08-13 22:53 ` Peter Zijlstra
2024-08-21 23:08 ` Tejun Heo
2024-08-06 19:56 ` Tejun Heo
2024-08-06 20:18 ` Peter Zijlstra
2024-08-06 20:20 ` Tejun Heo
2024-08-02 12:20 ` Peter Zijlstra
2024-08-02 18:47 ` Tejun Heo
2024-08-06 8:27 ` Peter Zijlstra [this message]
2024-08-06 19:17 ` Tejun Heo
2024-07-25 1:19 ` Qais Yousef
2024-07-30 9:04 ` Peter Zijlstra
2024-07-31 1:11 ` Tejun Heo
2024-07-31 1:22 ` Tejun Heo
2024-08-01 13:17 ` Qais Yousef
2024-08-01 16:36 ` Tejun Heo
2024-08-05 1:44 ` Qais Yousef
2024-08-01 2:50 ` Russell Haley
2024-08-01 15:52 ` Qais Yousef
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=20240806082716.GP37996@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ast@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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