From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964889AbbI2MzX (ORCPT ); Tue, 29 Sep 2015 08:55:23 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:36587 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964790AbbI2MzQ (ORCPT ); Tue, 29 Sep 2015 08:55:16 -0400 Date: Tue, 29 Sep 2015 14:55:13 +0200 From: Frederic Weisbecker To: Peter Zijlstra Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, oleg@redhat.com, umgwanakikbuti@gmail.com, tglx@linutronix.de, rostedt@goodmis.org Subject: Re: [RFC][PATCH 02/11] sched: Create preempt_count invariant Message-ID: <20150929125512.GB31582@lerouge> References: <20150929092825.540553633@infradead.org> <20150929093519.817299442@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150929093519.817299442@infradead.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2015 at 11:28:27AM +0200, Peter Zijlstra wrote: > Ensure that upon scheduling preempt_count == 2; although currently an > additional PREEMPT_ACTIVE is still possible. > > Signed-off-by: Peter Zijlstra (Intel) > --- > arch/x86/include/asm/preempt.h | 3 ++- > include/asm-generic/preempt.h | 2 +- > kernel/sched/core.c | 14 ++++++++++---- > 3 files changed, 13 insertions(+), 6 deletions(-) > > --- a/arch/x86/include/asm/preempt.h > +++ b/arch/x86/include/asm/preempt.h > @@ -31,7 +31,8 @@ static __always_inline void preempt_coun > * must be macros to avoid header recursion hell > */ > #define init_task_preempt_count(p) do { \ > - task_thread_info(p)->saved_preempt_count = PREEMPT_DISABLED; \ > + task_thread_info(p)->saved_preempt_count = \ > + 2*PREEMPT_DISABLE_OFFSET + PREEMPT_NEED_RESCHED; \ > } while (0) > > #define init_idle_preempt_count(p, cpu) do { \ > --- a/include/asm-generic/preempt.h > +++ b/include/asm-generic/preempt.h > @@ -24,7 +24,7 @@ static __always_inline void preempt_coun > * must be macros to avoid header recursion hell > */ > #define init_task_preempt_count(p) do { \ > - task_thread_info(p)->preempt_count = PREEMPT_DISABLED; \ > + task_thread_info(p)->preempt_count = 2*PREEMPT_DISABLED; \ Since it's not quite obvious why we use this magic value without looking at schedule_tail() details, maybe add a little comment? (Just "/* see schedule_tail() */"). > } while (0) > > #define init_idle_preempt_count(p, cpu) do { \ > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -2588,11 +2588,17 @@ asmlinkage __visible void schedule_tail( > { > struct rq *rq; > > - /* finish_task_switch() drops rq->lock and enables preemtion */ > - preempt_disable(); > - rq = finish_task_switch(prev); > + /* > + * Still have preempt_count() == 2, from: > + * > + * schedule() > + * preempt_disable(); // 1 > + * __schedule() > + * raw_spin_lock_irq(&rq->lock) // 2 > + */ I found that a bit confusing first, because that's a preempt_count() we actually emulate for a new task. Maybe something like: + /* + * New task is init with preempt_count() == 2 because prev task left + * us after: + * + * schedule() + * preempt_disable(); // 1 + * __schedule() + * raw_spin_lock_irq(&rq->lock) // 2 + */ > + rq = finish_task_switch(prev); /* drops rq->lock, preempt_count() == 1 */ > balance_callback(rq); > - preempt_enable(); > + preempt_enable(); /* preempt_count() == 0 */ Thanks!