Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3813476ybk; Tue, 19 May 2020 13:36:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfR1YQbcb9q/93Z6+Y5YeD9dcM10PTDF92t1biPYlEYSCrEEGPhAxGHKS7hpXm3T/1AFCR X-Received: by 2002:a50:fa8d:: with SMTP id w13mr560248edr.280.1589920582156; Tue, 19 May 2020 13:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589920582; cv=none; d=google.com; s=arc-20160816; b=P2cubdHpAcKF4qNLGSTsTCBEzC4AtgDJ9u6LXFtAERJMH33H0TNYDN15WsSk0QVB6b ie87iFKgdwB4Wq6/ucCnx5wXidB8C3uzO1LAkQTrtsI3BGA+U+Zji8UXgZvvUoMH84IV +y3nXpXX6fvNvC6SzQfb0A8tMdHEHFVtmECseGdZnTIZM49TjUjXS8YMM+9HK0tL8o/p UMYYTnVkG8Gng0RWhF9ctW6HDWapmlWs+s3x+fUOumN4h7fKNego2vIlgnk3Ui8rKVok ygEh5koyNMl5hIoh38/1YHs+ht2OROEMEr3aB9r7TRSPvYImTon+fuxPs/hApRoG2SXe 0/7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=09vI0CsgaxplihQPIL3k5EMR2EFkBWk2NjpyKMYvK0U=; b=Furia2JOk1z3LGOY2AZ6xn9cbTdPQZJcZzpZlZtDW6nuZdnzrC5O9ktN7NpCLOEU99 hD1JPvqDo1hmB3OQyCERDqpnPuY4qeNWh2hsPHA0mfVzzTGwBkg3xfcFiroeXAwPc2O9 3/ucSz4NacfiB5tzXR+1V5aBJKmqXojgciP7MT2wckpHUwSlX9eWKCJct/ZEGW4i54QP p9mkzQiiWq4KhIZlXAcAIWP8NhUyHIhKwtXLbDJUOUJIDZJ8bxA28BTOeO6Wr2O+Obj9 agVCI2v8841cgih+jyCaD+GweAs4eK3mtWf9vX67bkkSZWv3BKca3Nxqh/UxrO1BON5k 4NAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr16si733780ejc.320.2020.05.19.13.35.53; Tue, 19 May 2020 13:36:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726199AbgESUeZ (ORCPT + 99 others); Tue, 19 May 2020 16:34:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725885AbgESUeY (ORCPT ); Tue, 19 May 2020 16:34:24 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE1DC08C5C0 for ; Tue, 19 May 2020 13:34:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=vostro) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1jb8wP-0001Ip-0I; Tue, 19 May 2020 22:34:21 +0200 From: John Ogness To: Linus Torvalds Cc: Petr Mladek , Peter Zijlstra , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , kexec@lists.infradead.org, Linux Kernel Mailing List , "Paul E. McKenney" Subject: Re: [PATCH v2 2/3] printk: add lockless buffer References: <20200501094010.17694-1-john.ogness@linutronix.de> <20200501094010.17694-3-john.ogness@linutronix.de> <87v9ktcs3q.fsf@vostro.fn.ogness.net> Date: Tue, 19 May 2020 22:34:19 +0200 In-Reply-To: (Linus Torvalds's message of "Mon, 18 May 2020 10:22:30 -0700") Message-ID: <87tv0bhdf8.fsf@vostro.fn.ogness.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-18, Linus Torvalds wrote: >> smp_mb(); /* LMM(data_push_tail:C) */ >> >> + if (atomic_long_try_cmpxchg_relaxed(&data_ring->tail_lpos, >> + &tail_lpos, >> + next_lpos)) { /* LMM(data_push_tail:D) */ >> + break; >> + } > > Doing an "smp_mb()" followed by a "cmpxchg_relaxed" seems all kinds of > odd and pointless, and is very much non-optimal on x86 for example., > > Just remove the smp_mb(), and use the non-relaxed form of cmpxchg. > It's defined to be fully ordered if it succeeds (and if the cmpxchg > doesn't succeed, it's a no-op and the memory barrier shouldn't make > any difference). > > Otherwise you'll do two memory ordering operations on x86 (and > probably some other architectures), since the cmpxchg is always > ordered on x86 and there exists no "relaxed" form of it. ACK. All three smp_mb()'s and both smp_wmb()'s sit directly next to cmpxchg_relaxed() calls. Having explicit memory barriers was helpful for identifying, proving, and testing a minimal set of pairs (on arm64), but all will be folded into full cmpxchg()'s for the next version. John Ogness