Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2274292pxu; Mon, 7 Dec 2020 02:08:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWx8MtoehRgMdHa3TgaWs1iXU23w5Rhh9FrUImwClbUV7PK4jdw17DSpkAzV8VjZtq+iLZ X-Received: by 2002:aa7:d6c9:: with SMTP id x9mr18613521edr.96.1607335688360; Mon, 07 Dec 2020 02:08:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607335688; cv=none; d=google.com; s=arc-20160816; b=Syhkf26O7VtHamO3NVo1QqatS/9B61wnekTyGUUOhq+CfIlBRIlrgpGfTat30Oks5i EGVVQ5t+wb/Q/fU9vMvc31QZa6XJCZuup5e8w2HEXXQ7qN2GnFtfaJeQ6OzTfVQ4oc/c Ms1OnSLRWSaYiKjyL42rGezNUWDfA3pToXPzAwcGNpDCPCCjftPsV/L7a1xuEcJtVZdA M3jH1TACDU6t1UCGOefy1ybGcmPxVUQvRiebF5d/x8igtTB7mCPwNRfXt5crYsEOEnAp Py3nGnkQXuoml/58tb/LBfQ9iTMf/aL9iClPjtAWFtLJDk7GSD8V/m9r+zkGWtCjHjp3 YbvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=t4Jhtz8veRXymryz0xKab9TlQ3baLQoL7wNE/fpuipU=; b=tfm/XgHvNhPvxmZzy5GfE589UsXp01yaWzeM66AeD6k3nX/gQDd6EMMH3IUcjBaSGc FWc8bxhx9t4Old8JTTl229HGLqLygoW4tRJrcAx7h3g7BfwgSJyT8sLCcQPD1E4vDdBt URtIG9JfMF8FQZbZVJt9WG0AJPllzBmO6GTicdxPKpq4Kffg90NsfGfK8KjbyLWX1lXT V3p3Js21QWFDIi7I+MXXej6zXD/e5BAfzIFUpCpDbR8DnAOW+nRRzQrx/5RPJNBq+KU2 dKOdFIR8eK0fY+x2CJC+9ilY+Iu93tMDDRiO4hcByq3R8EwmbmdqAcC15J8uLbjDRH5B l+1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MW4i1KXM; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si6118877eje.628.2020.12.07.02.07.45; Mon, 07 Dec 2020 02:08:08 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=MW4i1KXM; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726276AbgLGKEW (ORCPT + 99 others); Mon, 7 Dec 2020 05:04:22 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:35322 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726076AbgLGKEW (ORCPT ); Mon, 7 Dec 2020 05:04:22 -0500 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607335420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=t4Jhtz8veRXymryz0xKab9TlQ3baLQoL7wNE/fpuipU=; b=MW4i1KXMb7DEMR3VrxXrhEtSLAsORfekNssZsz9I9bzJTKtqWFkiNiUSkfx1YSjbT0+60o nKkyiMPLFvK3TkuKMrIv81Br8rUBO/BXDxCajwvvfIClmAfjKur4VUfalc9uFlsksX30JI hglHrmn2goj9UBT1Lajx7ti+9uc+2wDf8qXY3i00QKAFRNtPfKr1LvX1D1eR4mJL0hB9VC 2egTD53Os2zb1zLb1NOByD578XNcsbrPVBPERorikxY1G2/IOaKVBaZjZW2uRdmDhM3ooO 5RVgSyzXpEFLe8k0+rxFF13HSZVEDLQjbSGSa+XZR86gFhCiQ0wvO+UWEgY+ug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607335420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=t4Jhtz8veRXymryz0xKab9TlQ3baLQoL7wNE/fpuipU=; b=AzFFebzy8Ardd0tIVtCVgtMMQMG69P11Xn6Pc9Bq0FHdevwLe3Y34MjxAyBwJAjrlwHCeq MMhaE1dWr7UZr4Bw== To: Peter Zijlstra Cc: Petr Mladek , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH next v2 2/3] printk: change @clear_seq to atomic64_t In-Reply-To: <20201207093419.GH3040@hirez.programming.kicks-ass.net> References: <20201201205341.3871-1-john.ogness@linutronix.de> <20201201205341.3871-3-john.ogness@linutronix.de> <875z5eof8g.fsf@jogness.linutronix.de> <20201207093419.GH3040@hirez.programming.kicks-ass.net> Date: Mon, 07 Dec 2020 11:09:39 +0106 Message-ID: <87mtyq9blw.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-12-07, Peter Zijlstra wrote: >> Yes, and it is read-only access. Perhaps atomic64_t is the wrong thing >> to use here. We could use a seqcount_latch and a shadow variable so that >> if a writer has been preempted, we can use the previous value. (Only >> kmsg_dump would need to use the lockless variant to read the value.) >> >> void clear_seq_set(u64 val) >> { >> spin_lock_irq(&clear_lock); >> raw_write_seqcount_latch(&clear_latch); >> clear_seq[0] = val; >> raw_write_seqcount_latch(&clear_latch); >> clear_seq[1] = val; >> spin_unlock_irq(&clear_lock); >> } >> >> u64 clear_seq_get_nolock(void) >> { >> unsigned int seq, idx; >> u64 val; >> >> do { >> seq = raw_read_seqcount_latch(&clear_latch); >> idx = seq & 0x1; >> val = clear_seq[idx]; >> } while (read_seqcount_latch_retry(&clear_latch, seq)); >> >> return val; >> } > > That's overly complicated. > > If you're going to double the storage you can simply do: > > > seq = val > smp_wmb(); > seq_copy = val; > > vs > > do { > tmp = seq_copy; > smp_rmb(); > val = seq; > } while (val != tmp); That will not work. We are talking about a situation where the writer is preempted. So seq will never equal seq_copy in that situation. I expect that the seqcount_latch is necessary. John Ogness