From: Peter Zijlstra <peterz@infradead.org>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 3/4] sched: Pull preemption disablement to __schedule() caller
Date: Tue, 3 Feb 2015 11:53:03 +0100 [thread overview]
Message-ID: <20150203105303.GI26304@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150202175343.GD11054@lerouge>
On Mon, Feb 02, 2015 at 06:53:45PM +0100, Frederic Weisbecker wrote:
> It looks like preempt_count_add/inc() mostly imply entering a context that we want
> to be seen right away (thus want barrier() after) and preempt_count_sub/dec() mostly
> want previous work to be visible before re-enabling interrupt, preemption, etc...
> (thus want barrier() before).
>
> So maybe these functions (the non-underscored ones) should imply a barrier() rather
> than their callers (preempt_disable() and others). Inline functions instead of macros
> would do the trick (if the headers hell let us do that).
>
> Note the underscored implementations are all inline currently so this happens to
> work by chance for direct calls to preempt_count_add/sub() outside preempt_disable().
> If the non-underscored caller is turned into inline too I don't expect performance issues.
>
> What do you think, does it make sense?
AFAIK inline does _not_ guarantee a compiler barrier, only an actual
function call does.
When inlining the compiler creates visibility into the 'call' and can
avoid the constraint -- teh interweb seems to agree and also pointed out
that 'pure' function calls, even when actual function calls, can avoid
being a compiler barrier.
The below blog seems to do a fair job of explaining things; in
particular the 'implied compiler barriers' section is relevant here:
http://preshing.com/20120625/memory-ordering-at-compile-time/
As it stands the difference between the non underscore and the
underscore version is debug/tracing muck. The underscore ops are the raw
operations without fancy bits on.
I think I would prefer keeping it that way; this means that
preempt_count_$op() is a pure op and when we want to build stuff with it
like preempt_{en,dis}able() they add the extra semantics on top.
In any case; if we make __schedule() noinline (I think that might make
sense) that function call would itself imply the compiler barrier and
something like:
__preempt_count_add(PREEMPT_ACTIVE + PREEMPT_CHECK_OFFSET);
__schedule();
__preempt_count_sub(PREEMPT_ACTIVE + PREEMPT_CHECK_OFFSET);
Would actually be safe/correct.
As it stands I think __schedule() would fail the GCC inline static
criteria for being too large, but you never know, noinline guarantees it
will not.
next prev parent reply other threads:[~2015-02-03 10:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-28 0:24 [PATCH 0/4] sched: schedule/preempt optimizations and cleanups Frederic Weisbecker
2015-01-28 0:24 ` [PATCH 1/4] sched: Pull resched loop to __schedule() callers Frederic Weisbecker
2015-02-04 14:36 ` [tip:sched/core] " tip-bot for Frederic Weisbecker
2015-01-28 0:24 ` [RFC PATCH 2/4] sched: Use traced preempt count operations to toggle PREEMPT_ACTIVE Frederic Weisbecker
2015-01-28 1:42 ` Steven Rostedt
2015-01-28 13:59 ` Frederic Weisbecker
2015-01-28 15:04 ` Steven Rostedt
2015-01-28 15:42 ` Peter Zijlstra
2015-02-02 17:22 ` Frederic Weisbecker
2015-01-28 0:24 ` [PATCH 3/4] sched: Pull preemption disablement to __schedule() caller Frederic Weisbecker
2015-01-28 15:50 ` Peter Zijlstra
2015-02-02 17:53 ` Frederic Weisbecker
2015-02-03 10:53 ` Peter Zijlstra [this message]
2015-02-04 17:31 ` Frederic Weisbecker
2015-02-04 17:48 ` Peter Zijlstra
2015-01-28 0:24 ` [RFC PATCH 4/4] sched: Account PREEMPT_ACTIVE context as atomic Frederic Weisbecker
2015-01-28 15:46 ` Peter Zijlstra
2015-02-02 17:29 ` Frederic Weisbecker
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=20150203105303.GI26304@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).