Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2891094ybk; Mon, 18 May 2020 10:24:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/wxx7BYAuk6tY+4ElWplLgv309ddL5Di9aGkIR048h2koGxoBjXH7kQTEr/36NTYylsu0 X-Received: by 2002:a50:bb6b:: with SMTP id y98mr14247829ede.296.1589822694575; Mon, 18 May 2020 10:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589822694; cv=none; d=google.com; s=arc-20160816; b=HBJMbj6XpMXCLhfVA/c1KOv3SUbhEJ2m4ZiZThSCtszTOK+e6SVNBm/A7xU2437aqO cbMv2Yv5e3Gux3YxXz68oo5TpYi3uG8tuxWd53G8SZBTCIze2c35BEFX/AQr4fp2DfOO gIKnFpj94unDVzhYPxsX5Zg076awXO4VxX/CYhVnz3d/V6KuJhHNHg5OP2yud7NQyYEu HNR0XS4vVkQm5LoSaBFTKb70PyVYT+ydrw2QYp63ipHFYiWH7ZxLIl5ofUqQuVVtoZN2 IV9A4F8hWOXKhph6WKHwZSxumS0jXW+FaZAAKoVjbwYT5HGjiaijuy13xK3qaVkxtZ7c d3yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qu8M66lDUKLK1WzpQWJe9igp01pFB46NWxsyvCKG6oY=; b=ykVZ9wrLNHt8sS3STnWzpZQe3l6/rREp0oP7ELO5Msa1WDzW/uzRD/kJQ5aGOmMUwh woNkgmGj6yjOVVMp44rB+ORuL80SOWv+sju6CiP5xIuCprBNMZEqQhT9WPH5KSUVUhoF uttz7ihgtO5OT8x8MRwu9tERuhn7ye0GQwW9u4bU0gvz0v+VsZuxLeO+yZZju09cqmFj ygwEy70C10foYie8AcTZwDYDNG1WEvfbb0KBd5U2pph2HuKsZCBoweXbPItSeOPaFojj uVg2J2X7BGCHJjgC8OyYYzZI9N8aNDqaUJE8f4WnH81v+aIs15AxWSV/CoSCov0h+Msn YmsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WAxyrolK; 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 f3si6038345edv.335.2020.05.18.10.24.31; Mon, 18 May 2020 10:24:54 -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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=WAxyrolK; 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 S1728280AbgERRWv (ORCPT + 99 others); Mon, 18 May 2020 13:22:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726958AbgERRWv (ORCPT ); Mon, 18 May 2020 13:22:51 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AEF0C061A0C for ; Mon, 18 May 2020 10:22:50 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id g1so10718432ljk.7 for ; Mon, 18 May 2020 10:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qu8M66lDUKLK1WzpQWJe9igp01pFB46NWxsyvCKG6oY=; b=WAxyrolK30XZ/8MijRphoQ1WbKWVbqxz0H4gA/Jy0pDcY9RRDe21Oan+4qDj9RDWUv LcWGp75Zyqhpcfrh+DYhLDfC9L9hFBI3p+iU/zxywhL1G6tidYQ6GLIuGqXlUMc5RKDx 2NX8Xzg6Xu2UUpMC93lzFHkjXofk5Qof537hs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qu8M66lDUKLK1WzpQWJe9igp01pFB46NWxsyvCKG6oY=; b=QgJT0+COzxQwr3uWPV4+f2iHO02dYKVPmBKOVSShVjlqK8reDyDjJiqeRHL731sGU5 2R2qRdan/L2x37IdSCNbiTKaz4HRHrRhDXNiDGcsA+wp2zIXlJjJHMRnjlksPZ9J0K/S y3U9GrCB2s4r9YJOWg6J/x9WiBZoFclfqqIbYS16wlTgIYhn75RMrIEJhsPwN+SHkMTM eHgvEFTkTi44+DLaDfvVOhi0zgDDGSlrmXAM+k/6y28y7yU0hw7wiVMJbZgXPcoCtBTG QGa5fbgW55DRAQNRWiulG1dpAUe4Lzi6Ae+4mFQNWqvnuWoGaFP6HIPgq15sCM122p71 Ze6w== X-Gm-Message-State: AOAM5306mlIFyqRIMo/k33JwT0CdeF6Iya+SpT8VdCsmyCFHf/uP1lp7 ySUUHUJteNYkAkdlBCkC6F6uiCLLN/4= X-Received: by 2002:a2e:9743:: with SMTP id f3mr4459056ljj.205.1589822568390; Mon, 18 May 2020 10:22:48 -0700 (PDT) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id g6sm5982657ljj.78.2020.05.18.10.22.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 May 2020 10:22:47 -0700 (PDT) Received: by mail-lf1-f50.google.com with SMTP id 82so8792000lfh.2 for ; Mon, 18 May 2020 10:22:46 -0700 (PDT) X-Received: by 2002:a05:6512:62:: with SMTP id i2mr3417039lfo.152.1589822566461; Mon, 18 May 2020 10:22:46 -0700 (PDT) MIME-Version: 1.0 References: <20200501094010.17694-1-john.ogness@linutronix.de> <20200501094010.17694-3-john.ogness@linutronix.de> <87v9ktcs3q.fsf@vostro.fn.ogness.net> In-Reply-To: <87v9ktcs3q.fsf@vostro.fn.ogness.net> From: Linus Torvalds Date: Mon, 18 May 2020 10:22:30 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 2/3] printk: add lockless buffer To: John Ogness 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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 18, 2020 at 6:04 AM John Ogness wrote: > > The cmpxchg() needs to be moved out of the while condition so that a > continue can be used as intended. Patch below. This seems pointless and wrong (patch edited to remove the '-' lines so that you see the end result): > 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. Linus