netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Fabian Frederick <fabf@skynet.be>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Jan \"Yenya\" Kasprzak" <kas@fi.muni.cz>,
	netdev@vger.kernel.org
Subject: Re: [PATCH 6/7 linux-next] wan: cosa: replace current->state by set_current_state()
Date: Fri, 20 Feb 2015 19:58:00 +0100	[thread overview]
Message-ID: <20150220185800.GR2896@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <54E77E34.6050909@cogentembedded.com>

On Fri, Feb 20, 2015 at 09:34:28PM +0300, Sergei Shtylyov wrote:
> Hello.
> 
> On 02/20/2015 09:12 PM, Fabian Frederick wrote:
> 
> >Use helper functions to access current->state.
> >Direct assignments are prone to races and therefore buggy.
> 
> >current->state = TASK_RUNNING is replaced by __set_current_state()
> 
>    You sometimes use __set_current_state() and sometimes set_current_state().

It depends on which state; setting yourself TASK_RUNNING is free of
wakeup races -- you're already running after all, so it can safely use
__set_current_state().

Setting a blocking state otoh needs set_current_state() which issues a
full memory barriers with the store (critically in this case,
effectively after the store) such that it orders the state store with a
subsequent load in the condition check if it really needs to go to
sleep.


In full:

	current->state = TASK_UNINTERRUPTIBLE;		wait = false;
	smp_mb();					smp_wmb();
	if (wait)					p->state = TASK_RUNNING;
		schedule();

Without that smp_mb(); the following order is possible:

	if (wait)
							wait = false;
							smp_wmb();
							p->state = TASK_RUNNING;
	current->state = TASK_UNINTERRUPTIBLE;
		schedule();

And we'll wait forever more..

  parent reply	other threads:[~2015-02-20 18:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1424455977-21903-1-git-send-email-fabf@skynet.be>
2015-02-20 18:12 ` [PATCH 2/7 linux-next] mISDN: replace current->state by set_current_state() Fabian Frederick
2015-02-22 20:24   ` David Miller
2015-02-20 18:12 ` [PATCH 5/7 linux-next] hso: replace current->state by __set_current_state() Fabian Frederick
2015-02-22 20:25   ` David Miller
2015-02-20 18:12 ` [PATCH 6/7 linux-next] wan: cosa: replace current->state by set_current_state() Fabian Frederick
2015-02-20 18:26   ` Jan Yenya Kasprzak
2015-02-20 18:34   ` Sergei Shtylyov
2015-02-20 18:51     ` Fabian Frederick
2015-02-20 19:15       ` Sergei Shtylyov
2015-02-20 18:58     ` Peter Zijlstra [this message]
2015-02-20 19:31       ` Eric Dumazet
2015-02-20 19:44         ` Eric Dumazet
2015-02-20 20:02         ` Peter Zijlstra
2015-02-21  7:42       ` Fabian Frederick
2015-02-22 20:25   ` David Miller

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=20150220185800.GR2896@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=fabf@skynet.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=kas@fi.muni.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=sergei.shtylyov@cogentembedded.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;
as well as URLs for NNTP newsgroup(s).