From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f44.google.com (mail-pb0-f44.google.com [209.85.160.44]) by kanga.kvack.org (Postfix) with ESMTP id F3B536B0031 for ; Tue, 1 Oct 2013 16:01:22 -0400 (EDT) Received: by mail-pb0-f44.google.com with SMTP id xa7so7633105pbc.17 for ; Tue, 01 Oct 2013 13:01:22 -0700 (PDT) Message-ID: <524B2A01.4080403@hp.com> Date: Tue, 01 Oct 2013 16:01:05 -0400 From: Waiman Long MIME-Version: 1.0 Subject: Re: [PATCH v6 5/6] MCS Lock: Restructure the MCS lock defines and locking code into its own file References: <1380147049.3467.67.camel@schen9-DESK> <20130927152953.GA4464@linux.vnet.ibm.com> <1380310733.3467.118.camel@schen9-DESK> <20130927203858.GB9093@linux.vnet.ibm.com> <1380322005.3467.186.camel@schen9-DESK> <20130927230137.GE9093@linux.vnet.ibm.com> <20130928021947.GF9093@linux.vnet.ibm.com> <52499E13.8050109@hp.com> <1380557440.14213.6.camel@j-VirtualBox> <5249A8A4.9060400@hp.com> <1380646092.11046.6.camel@schen9-DESK> In-Reply-To: <1380646092.11046.6.camel@schen9-DESK> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Tim Chen Cc: Jason Low , Paul McKenney , Ingo Molnar , Andrew Morton , Andrea Arcangeli , Alex Shi , Andi Kleen , Michel Lespinasse , Davidlohr Bueso , Matthew R Wilcox , Dave Hansen , Peter Zijlstra , Rik van Riel , Peter Hurley , linux-kernel@vger.kernel.org, linux-mm On 10/01/2013 12:48 PM, Tim Chen wrote: > On Mon, 2013-09-30 at 12:36 -0400, Waiman Long wrote: >> On 09/30/2013 12:10 PM, Jason Low wrote: >>> On Mon, 2013-09-30 at 11:51 -0400, Waiman Long wrote: >>>> On 09/28/2013 12:34 AM, Jason Low wrote: >>>>>> Also, below is what the mcs_spin_lock() and mcs_spin_unlock() >>>>>> functions would look like after applying the proposed changes. >>>>>> >>>>>> static noinline >>>>>> void mcs_spin_lock(struct mcs_spin_node **lock, struct mcs_spin_node *node) >>>>>> { >>>>>> struct mcs_spin_node *prev; >>>>>> >>>>>> /* Init node */ >>>>>> node->locked = 0; >>>>>> node->next = NULL; >>>>>> >>>>>> prev = xchg(lock, node); >>>>>> if (likely(prev == NULL)) { >>>>>> /* Lock acquired. No need to set node->locked since it >>>>>> won't be used */ >>>>>> return; >>>>>> } >>>>>> ACCESS_ONCE(prev->next) = node; >>>>>> /* Wait until the lock holder passes the lock down */ >>>>>> while (!ACCESS_ONCE(node->locked)) >>>>>> arch_mutex_cpu_relax(); >>>>>> smp_mb(); >>>> I wonder if a memory barrier is really needed here. >>> If the compiler can reorder the while (!ACCESS_ONCE(node->locked)) check >>> so that the check occurs after an instruction in the critical section, >>> then the barrier may be necessary. >>> >> In that case, just a barrier() call should be enough. > The cpu could still be executing out of order load instruction from the > critical section before checking node->locked? Probably smp_mb() is > still needed. > > Tim But this is the lock function, a barrier() call should be enough to prevent the critical section from creeping up there. We certainly need some kind of memory barrier at the end of the unlock function. -Longman -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org