Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752280AbbBUHmj (ORCPT ); Sat, 21 Feb 2015 02:42:39 -0500 Received: from mailsec108.isp.belgacom.be ([195.238.20.104]:38650 "EHLO mailsec108.isp.belgacom.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750746AbbBUHmg convert rfc822-to-8bit (ORCPT ); Sat, 21 Feb 2015 02:42:36 -0500 X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=M25fSHNwW0AVyF8PBjdaZiLQS1FBtLFJFIDkHdlBKq0= c=1 sm=2 a=IkcTkHD0fZMA:10 a=JfrnYn6hAAAA:8 a=EQ45Dt1ACSX7UY4GR-QA:9 a=QEXdDO2ut3YA:10 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2AQBgBdNuhU/9EU7sNbgwaBLIMIrSkBAQEBAQEGmEQCgRlDAQEBAQEBfIQPAQEBAwEjBFIFCwUEAhgCAhgOAgJXBgESEYgWDJ4TnGyGU5FxAQEBAQYBAQEBHoEhhGOFC4Q7MweCaIFDBZVAjjuIRCKCMoE9PTGCQwEBAQ Date: Sat, 21 Feb 2015 08:42:23 +0100 (CET) From: Fabian Frederick Reply-To: Fabian Frederick To: Peter Zijlstra , Sergei Shtylyov Cc: Ingo Molnar , Greg Kroah-Hartman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Jan \"Yenya\" Kasprzak" Message-ID: <970522031.62268.1424504543731.open-xchange@webmail.nmp.proximus.be> In-Reply-To: <20150220185800.GR2896@worktop.programming.kicks-ass.net> References: <1424455977-21903-1-git-send-email-fabf@skynet.be> <1424455977-21903-6-git-send-email-fabf@skynet.be> <54E77E34.6050909@cogentembedded.com> <20150220185800.GR2896@worktop.programming.kicks-ass.net> Subject: Re: [PATCH 6/7 linux-next] wan: cosa: replace current->state by set_current_state() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v7.2.2-Rev27 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2345 Lines: 62 > On 20 February 2015 at 19:58 Peter Zijlstra wrote: > > > 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.. Do I have to add more comments in changelogs or is it OK for you ? Maybe something like: " current->state = TASK_RUNNING can safely be converted to __set_current_state() as we're already in that state. Other assignments are converted to set_current_state() (which uses set_mb()). " Regards, Fabian > -- 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/