Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757655AbcDHGly (ORCPT ); Fri, 8 Apr 2016 02:41:54 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:36351 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751957AbcDHGlx (ORCPT ); Fri, 8 Apr 2016 02:41:53 -0400 Date: Fri, 8 Apr 2016 08:41:36 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Mathieu Desnoyers , "Paul E. McKenney" , Ingo Molnar , Paul Turner , Andi Kleen , Chris Lameter , Dave Watson , Josh Triplett , Linux API , "linux-kernel@vger.kernel.org" , Andrew Hunter , Linus Torvalds Subject: Re: [RFC PATCH 0/3] restartable sequences v2: fast user-space percpu critical sections Message-ID: <20160408064136.GJ3448@twins.programming.kicks-ass.net> References: <20151027235635.16059.11630.stgit@pjt-glaptop.roam.corp.google.com> <20160407120254.GY3448@twins.programming.kicks-ass.net> <20160407152432.GZ3448@twins.programming.kicks-ass.net> <20160407155312.GA3448@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 633 Lines: 20 On Thu, Apr 07, 2016 at 09:43:33AM -0700, Andy Lutomirski wrote: > enter the critical section: > 1: > movq %[cpu], %%r12 > movq {address of counter for our cpu}, %%r13 > movq {some fresh value}, (%%r13) > cmpq %[cpu], %%r12 > jne 1b This is inherently racy; your forgot the detail of 'some fresh value', but since you want to avoid collisions you really want an increment. But load-store archs cannot do that. Or rather, they need to do: load Rn, $event add Rn, Rn, 1 store $event, Rn But if they're preempted in the middle, two threads will collide and generate the _same_ increment. Comparing CPU numbers will not fix that.