Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753995Ab3I0UQW (ORCPT ); Fri, 27 Sep 2013 16:16:22 -0400 Received: from mail-bk0-f51.google.com ([209.85.214.51]:57908 "EHLO mail-bk0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752941Ab3I0UQU (ORCPT ); Fri, 27 Sep 2013 16:16:20 -0400 MIME-Version: 1.0 In-Reply-To: <1380310733.3467.118.camel@schen9-DESK> References: <1380147049.3467.67.camel@schen9-DESK> <20130927152953.GA4464@linux.vnet.ibm.com> <1380310733.3467.118.camel@schen9-DESK> Date: Fri, 27 Sep 2013 13:16:16 -0700 X-Google-Sender-Auth: XwuijNV90NKB3-X_OL6kp2JxvjU Message-ID: Subject: Re: [PATCH v6 5/6] MCS Lock: Restructure the MCS lock defines and locking code into its own file From: Jason Low To: Tim Chen Cc: Paul McKenney , Waiman Long , 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 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1311 Lines: 35 On Fri, Sep 27, 2013 at 12:38 PM, Tim Chen wrote: > BTW, is the above memory barrier necessary? It seems like the xchg > instruction already provided a memory barrier. > > Now if we made the changes that Jason suggested: > > > /* Init node */ > - node->locked = 0; > node->next = NULL; > > prev = xchg(lock, node); > if (likely(prev == NULL)) { > /* Lock acquired */ > - node->locked = 1; > return; > } > + node->locked = 0; > ACCESS_ONCE(prev->next) = node; > smp_wmb(); > > We are probably still okay as other cpus do not read the value of > node->locked, which is a local variable. Similarly, I was wondering if we should also move smp_wmb() so that it is before the ACCESS_ONCE(prev->next) = node and after the node->locked = 0. Would we want to guarantee that the node->locked gets set before it is added to the linked list where a previous thread calling mcs_spin_unlock() would potentially modify node->locked? -- 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/