From: Peter Zijlstra <peterz@infradead.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.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>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Imran Khan <imran.f.khan@oracle.com>,
Leonardo Bras <leobras@redhat.com>, Guo Ren <guoren@kernel.org>,
Rik van Riel <riel@surriel.com>, Tejun Heo <tj@kernel.org>,
Cruz Zhao <CruzZhao@linux.alibaba.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
Zqiang <qiang.zhang1211@gmail.com>,
Julia Lawall <julia.lawall@inria.fr>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>
Subject: Re: [PATCH 2/3] sched/core: Introduce SM_IDLE and an idle re-entry fast-path in __schedule()
Date: Thu, 11 Jul 2024 11:19:36 +0200 [thread overview]
Message-ID: <20240711091936.GJ4587@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAKfTPtCNJUC-gNNPkEBRT5a2UVcPUHLdzUJ+-egZGQ5ihnU0Kw@mail.gmail.com>
On Thu, Jul 11, 2024 at 10:00:15AM +0200, Vincent Guittot wrote:
> On Wed, 10 Jul 2024 at 11:03, K Prateek Nayak <kprateek.nayak@amd.com> wrote:
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 1e0c77eac65a..417d3ebbdf60 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -6343,19 +6343,12 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
> > * Constants for the sched_mode argument of __schedule().
> > *
> > * The mode argument allows RT enabled kernels to differentiate a
> > - * preemption from blocking on an 'sleeping' spin/rwlock. Note that
> > - * SM_MASK_PREEMPT for !RT has all bits set, which allows the compiler to
> > - * optimize the AND operation out and just check for zero.
> > + * preemption from blocking on an 'sleeping' spin/rwlock.
> > */
> > -#define SM_NONE 0x0
> > -#define SM_PREEMPT 0x1
> > -#define SM_RTLOCK_WAIT 0x2
> > -
> > -#ifndef CONFIG_PREEMPT_RT
> > -# define SM_MASK_PREEMPT (~0U)
> > -#else
> > -# define SM_MASK_PREEMPT SM_PREEMPT
> > -#endif
> > +#define SM_IDLE (-1)
> > +#define SM_NONE 0
> > +#define SM_PREEMPT 1
> > +#define SM_RTLOCK_WAIT 2
> >
> > /*
> > * __schedule() is the main scheduler function.
> > @@ -6396,11 +6389,12 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
> > *
> > * WARNING: must be called with preemption disabled!
> > */
> > -static void __sched notrace __schedule(unsigned int sched_mode)
> > +static void __sched notrace __schedule(int sched_mode)
> > {
> > struct task_struct *prev, *next;
> > unsigned long *switch_count;
> > unsigned long prev_state;
> > + bool preempt = sched_mode > 0;
> > struct rq_flags rf;
> > struct rq *rq;
> > int cpu;
> > @@ -6409,13 +6403,13 @@ static void __sched notrace __schedule(unsigned int sched_mode)
> > rq = cpu_rq(cpu);
> > prev = rq->curr;
> >
> > - schedule_debug(prev, !!sched_mode);
> > + schedule_debug(prev, preempt);
> >
> > if (sched_feat(HRTICK) || sched_feat(HRTICK_DL))
> > hrtick_clear(rq);
> >
> > local_irq_disable();
> > - rcu_note_context_switch(!!sched_mode);
> > + rcu_note_context_switch(preempt);
> >
> > /*
> > * Make sure that signal_pending_state()->signal_pending() below
> > @@ -6449,7 +6443,12 @@ static void __sched notrace __schedule(unsigned int sched_mode)
> > * that we form a control dependency vs deactivate_task() below.
> > */
> > prev_state = READ_ONCE(prev->__state);
> > - if (!(sched_mode & SM_MASK_PREEMPT) && prev_state) {
> > + if (sched_mode == SM_IDLE) {
> > + if (!rq->nr_running) {
> > + next = prev;
> > + goto picked;
> > + }
> > + } else if (!preempt && prev_state) {
>
> With CONFIG_PREEMPT_RT, it was only for SM_PREEMPT but not for SM_RTLOCK_WAIT
Bah, yes. But then schedule_debug() and rcu_note_context_switch() have
an argument that is called 'preempt' but is set for SM_RTLOCK_WAIT.
Now, I think the RCU think is actually correct here, it doesn't want to
consider SM_RTLOCK_WAIT as a voluntary schedule point, because spinlocks
don't either. But it is confusing as heck.
We can either write things like:
} else if (sched_mode != SM_PREEMPT && prev_state) {
or do silly things like:
#define SM_IDLE (-16)
keep the SM_MASK_PREEMPT trickery and do:
} else if (!(sched_mode & SM_MASK_PREEMPT) && prev_state) {
Not sure that is actually going to matter at this point though.
next prev parent reply other threads:[~2024-07-11 9:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 9:02 [PATCH 0/3] sched/core: Fixes and enhancements around spurious need_resched() and idle load balancing K Prateek Nayak
2024-07-10 9:02 ` [PATCH 1/3] sched/core: Remove the unnecessary need_resched() check in nohz_csd_func() K Prateek Nayak
2024-07-10 14:53 ` Peter Zijlstra
2024-07-10 17:57 ` K Prateek Nayak
2024-07-23 6:46 ` K Prateek Nayak
2024-07-10 9:02 ` [PATCH 2/3] sched/core: Introduce SM_IDLE and an idle re-entry fast-path in __schedule() K Prateek Nayak
2024-07-11 8:00 ` Vincent Guittot
2024-07-11 9:19 ` Peter Zijlstra [this message]
2024-07-11 13:14 ` Vincent Guittot
2024-07-12 6:40 ` K Prateek Nayak
2024-07-30 16:13 ` Chen Yu
2024-08-04 4:05 ` Chen Yu
2024-08-05 4:03 ` K Prateek Nayak
2024-07-10 9:02 ` [RFC PATCH 3/3] softirq: Avoid waking up ksoftirqd from flush_smp_call_function_queue() K Prateek Nayak
2024-07-10 15:05 ` Peter Zijlstra
2024-07-10 18:20 ` K Prateek Nayak
2024-07-23 4:50 ` K Prateek Nayak
2024-07-29 2:42 ` [PATCH 0/3] sched/core: Fixes and enhancements around spurious need_resched() and idle load balancing Chen Yu
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=20240711091936.GJ4587@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=CruzZhao@linux.alibaba.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gautham.shenoy@amd.com \
--cc=guoren@kernel.org \
--cc=imran.f.khan@oracle.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=julia.lawall@inria.fr \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=leobras@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=qiang.zhang1211@gmail.com \
--cc=riel@surriel.com \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--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