From: Frederic Weisbecker <fweisbec@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 2/2] sched: Pull resched loop to __schedule() callers
Date: Mon, 15 Dec 2014 17:32:36 +0100 [thread overview]
Message-ID: <20141215163232.GA21962@lerouge> (raw)
In-Reply-To: <CA+55aFwhEkBc899yMY3KugwF0QGF8r7iM_6+DoYa0RgtApv5aw@mail.gmail.com>
On Sun, Dec 14, 2014 at 06:46:27PM -0800, Linus Torvalds wrote:
> On Sun, Dec 14, 2014 at 6:24 PM, Frederic Weisbecker <fweisbec@gmail.com> wrote:
> > -need_resched:
> > preempt_disable();
> > cpu = smp_processor_id();
> > rq = cpu_rq(cpu);
> > @@ -2821,8 +2824,6 @@ need_resched:
> > post_schedule(rq);
> >
> > sched_preempt_enable_no_resched();
> > - if (need_resched())
> > - goto need_resched;
>
>
> So my suggestion was to move the
> "preempt_disable()/enable_no_resched()" into the callers too.
>
> Everybody already does that - except for "schedule()" itself. So that
> would involve adding it here too:
>
> > @@ -2842,7 +2843,9 @@ asmlinkage __visible void __sched schedule(void)
> > struct task_struct *tsk = current;
> >
> > sched_submit_work(tsk);
> > - __schedule();
> > + do {
> preempt_disable();
> > + __schedule();
> sched_preempt_enable_no_resched();
> > + } while (need_resched());
> > }
>
> Hmm?
Indeed!
>
> That would mean that we have one less preempt update in the
> __sched_preempt() cases. If somebody cares about the preempt counter
> value, we'd have to increemnt the preempt count add values too, ie do
>
> __preempt_count_add(PREEMPT_ACTIVE+1);
>
> there, but I'm not convicned anybody cares about the exact count.
It _looks_ fine to only add PREEMPT_ACTIVE without PREEMPT_OFFSET. I guess
we are only interested in avoiding preemption.
But it may have an impact on some context checkers that rely on in_atomic*()
which ignore the PREEMPT_ACTIVE value. It shouldn't ignore that though but I
guess it's a hack for some specific situation. Now if we do what we plan,
PREEMPT_ACTIVE won't involve PREEMPT_OFFSET anymore, so in_atomic() should
handle PREEMPT_ACTIVE.
schedule_debug() for example relies on in_atomic_preempt_off() which wants
preemption disabled through PREEMPT_OFFSET. But we can tweak that.
This is the only context check I know of, lets hope there are no others lurking.
Ah and there is also the preempt off tracer which ignores the PREEMPT_ACTIVE
counts because they use __preempt_count_add/sub() and they use to be immediately
followed by preempt disable. So we need to use the non-underscored version of
preempt_count_add/sub() on preempt_schedule*() to trace correctly (note though
that ftrace only records preempt_count() & PREEMPT_MASK. So it's going to record
preemption disabled area with a 0 pc.
> As it is, you end up doing the preempt count things twice in the
> __sched_preempt() case: first the PREEMPT_ACTIVE count, and then the
> count inside __schedule().
Indeed so I'm going to split the changes in two steps:
1) disable preemption from schedule(), add PREEMPT_ACTIVE + PREEMPT_OFFSET from
preempt_schedule*() callers, make them use non-underscored preempt_count_add()
and remove the preempt_disable() from __schedule(). That change should be safe
and we remove the overhead of the double preempt_disable.
2) Optional change: remove the PREEMPT_OFFSET from the preempt_schedule*() callers
and tweak schedule_bug(). Having that as a seperate patch so it's easier to ignore,
drop or revert as it looks like a sensitive change.
next prev parent reply other threads:[~2014-12-15 16:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-15 2:24 [PATCH 0/2] sched: Preemption fixlet and cleanup Frederic Weisbecker
2014-12-15 2:24 ` [PATCH 1/2] sched: Fix missing preemption check in cond_resched() Frederic Weisbecker
2014-12-15 2:24 ` [PATCH 2/2] sched: Pull resched loop to __schedule() callers Frederic Weisbecker
2014-12-15 2:46 ` Linus Torvalds
2014-12-15 16:32 ` Frederic Weisbecker [this message]
2014-12-15 19:16 ` Linus Torvalds
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=20141215163232.GA21962@lerouge \
--to=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.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