Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18443373ybl; Fri, 3 Jan 2020 02:26:57 -0800 (PST) X-Google-Smtp-Source: APXvYqy7zWFRjU8iZPn4wpJ++BgmChayULIjCeleqLteWEMs3os4clg+7dZMcbQ14c3GTO4Vt9i2 X-Received: by 2002:a9d:6f11:: with SMTP id n17mr82794504otq.126.1578047217810; Fri, 03 Jan 2020 02:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578047217; cv=none; d=google.com; s=arc-20160816; b=UgeU6MVDXdMNliv1Ui+BNEYSNptaAm7Aj9XosCDJi6RdiR5LvQcbSLlh7/pj7RwkWY dHne0Zq3KHybBVwlXctyICtrjL8joMyykZXK7Fz4TW9oAYNiBlhpuuhd5vu7C4KGtpYp 0jFM+Dv/ipDTQM5dLVEuCKwlyiavDBJ9x7WCgGD+F2nHKw1j247G5k2ZcWsRQ+bntZC3 uyirQSRABa11FFciFyrnJKC5RRiHF5kBQKrHQa9mkgGh/15X0Arq+dvTyIZwkJOFrs9i UWjZ5EUCvpATcbc3nsBMA870Htx0J0RjQibtW3Blv/WWHMDcduV+SWCr4EdedNkBGAXM qd9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xVxjhuumobDKYQtEkIzABm6kHBJCSd1kVjGm8tVKMwY=; b=vQgxGwHJG+V6gDavyeivCxz1bPsVj24dpL0+neS3JyCB+bExmfVzCAoAXTsbQj9Hat eUgr8YKUdVrYHj0MaKTNOOxPK0znf0LE1K9Ai8XYr0dYg3QeAODXmREJW/XeNJgYWUP5 nQquRkP6aX1jholDgJKSEsLrF80KMDj8vwE5Fv9WwfZ02CPnfSSXqTHvYqpA8H//q3Vz I6H9iIuDgiAKxfJa7+60exOCvd/0ZJ/n9Rb0UPz1xGTf9HTeH2a6Sr862CUjTzXqYxCT wJMDULcYa3Bsa+J87hIdkooTCYxotyOSPNhMMKzgDKra+w8oaiPiPmexx7nl7snW+lm6 9WCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l131si28997009oig.120.2020.01.03.02.26.45; Fri, 03 Jan 2020 02:26:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727498AbgACKY0 (ORCPT + 99 others); Fri, 3 Jan 2020 05:24:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:47864 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbgACKYZ (ORCPT ); Fri, 3 Jan 2020 05:24:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C2B03B266; Fri, 3 Jan 2020 10:24:22 +0000 (UTC) Date: Fri, 3 Jan 2020 11:24:20 +0100 From: Petr Mladek To: John Ogness Cc: Andrea Parri , linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , Sergey Senozhatsky , Brendan Higgins , kexec@lists.infradead.org Subject: Re: [RFC PATCH v5 1/3] printk-rb: new printk ringbuffer implementation (writer) Message-ID: <20200103102420.n6i5chgxaygfvx5h@pathway.suse.cz> References: <20191128015235.12940-1-john.ogness@linutronix.de> <20191128015235.12940-2-john.ogness@linutronix.de> <20191221142235.GA7824@andrea> <87imm7820z.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87imm7820z.fsf@linutronix.de> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2019-12-23 17:01:00, John Ogness wrote: > Hi Andrea, > > On 2019-12-21, Andrea Parri wrote: > >> + *desc_out = READ_ONCE(*desc); > >> + > >> + /* Load data before re-checking state. */ > >> + smp_rmb(); /* matches LMM_REF(desc_reserve:A) */ > > > > I looked for a matching WRITE_ONCE() or some other type of marked write, > > but I could not find it. What is the rationale? Or what did I miss? Good question. READ_ONCE() looks superfluous here because it is surrounded by two read barriers. In each case, there is no corresponding WRITE_ONCE(). Note that we are copying the entire struct prb_desc here. All values are written only when state_val is in desc_reserved state. It happens between two full write barriers: + A writer is allowed to modify the descriptor after successful cmpxchg in desc_reserve(), see LMM_TAG(desc_reserve:A). + The writer must not touch the descriptor after changing state_var to committed state, see LMM_TAG(prb_commit:A) in prb_commit(). These barriers are mentioned in the comments for the two read barriers here. > >> + do { > >> + next_lpos = get_next_lpos(data_ring, begin_lpos, size); > >> + > >> + if (!data_push_tail(rb, data_ring, > >> + next_lpos - DATA_SIZE(data_ring))) { > >> + /* Failed to allocate, specify a data-less block. */ > >> + blk_lpos->begin = INVALID_LPOS; > >> + blk_lpos->next = INVALID_LPOS; > >> + return NULL; > >> + } > >> + } while (!atomic_long_try_cmpxchg(&data_ring->head_lpos, &begin_lpos, > >> + next_lpos)); > >> + > >> + /* > >> + * No barrier is needed here. The data validity is defined by > >> + * the state of the associated descriptor. They are marked as > >> + * invalid at the moment. And only the winner of the above > >> + * cmpxchg() could write here. > >> + */ > > > > The (successful) CMPXCHG provides a full barrier. This comment suggests > > that that could be somehow relaxed? Or the comment could be improved? > > You are correct. There is no need for the full barrier here. This code > is based on Petr's POC. I focussed on making sure needed barriers are in > place, but did not try to eliminate excessive barriers. I hope that I'll get better understanding of the guarantees of different atomic operations one day. There are so many variants now. BTW: Documentation/memory-barriers.txt describes various aspects of the memory barriers. It describes implicit barriers provided by spin locks, mutexes, semaphores, and various scheduler-related operations. But I can't find any explanation of the various variants of the atomic operations: acquire, release, fetch, return, try, relaxed. I can find some clues here and there but it is hard to get the picture. Best Regards, Petr