Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161329AbbBDRcH (ORCPT ); Wed, 4 Feb 2015 12:32:07 -0500 Received: from mail-wg0-f45.google.com ([74.125.82.45]:49650 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161298AbbBDRcC (ORCPT ); Wed, 4 Feb 2015 12:32:02 -0500 Date: Wed, 4 Feb 2015 18:31:57 +0100 From: Frederic Weisbecker To: Peter Zijlstra Cc: Ingo Molnar , LKML , Steven Rostedt , Linus Torvalds Subject: Re: [PATCH 3/4] sched: Pull preemption disablement to __schedule() caller Message-ID: <20150204173152.GA24000@lerouge> References: <1422404652-29067-1-git-send-email-fweisbec@gmail.com> <1422404652-29067-4-git-send-email-fweisbec@gmail.com> <20150128155044.GJ23038@twins.programming.kicks-ass.net> <20150202175343.GD11054@lerouge> <20150203105303.GI26304@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150203105303.GI26304@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3052 Lines: 66 On Tue, Feb 03, 2015 at 11:53:03AM +0100, Peter Zijlstra wrote: > 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/ Ok, ok then. > 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. Right, although relying only on __schedule() as a function call is perhaps error-prone in case we add things in preempt_schedule*() APIs later, before the call to __schedule(), that need the preempt count to be visible. I can create preempt_active_enter() / preempt_active_exit() that take care of the preempt op and the barrier() for example. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/