Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2261797pxu; Mon, 7 Dec 2020 01:38:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwT6FjaJIqH76mQoYdwcTgdvVZpyfZFmjBmQzC0VSeS7N0xB87BE+PcS9i9SwZafBEpoeJd X-Received: by 2002:a50:fc8b:: with SMTP id f11mr19298642edq.11.1607333929288; Mon, 07 Dec 2020 01:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607333929; cv=none; d=google.com; s=arc-20160816; b=H3HJEZrMxOA5Di3sDDg8tfgH6U8qgxkQv96Ax2auItnS55oNBfI/VMVNKW46bQ+HHy 784UBHSYmX3luPepYeG1V4+mz3RjXSxwJvuaqjowgzzEJvWw8H+cORZKnyF2o29YT+9e YHS6qrqlqC3rMsQOZZAXwUyr/zHk4BN7fVOTWJC9IkPi3AD59aUM+F9EA+BBNu2V+F5x DKVFi9z39Qx7qGxneSf+/nnUUpPzQxIRhxYLcilZkGODBdRYn0EtKf9go1isyk8XBvO8 bGXY5TaxUKbi9wpAHIgJ463sg8Tk65V1cfEi11v6pc6D1d80LQztBZ8EvWBqePbOfrTN sXDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=b1j1H8XecQrBVNudhF5CzRVkTselpA16gsYa3scFeZw=; b=sz74dRrM2A+zwqa8lg7TmfWO365ydXtx8tIRFkaRGaI5l0Tqt4UADXR4Mt8i23aPxJ jTQBSJ366RtKXAX+VqTCsZbJcz/Sg/ftWcgEvPwxdC5pFKPRQ/EZ86ad0TUuKkM/1naD gU4BbIua3n/cihseEllzwalxiu8aZhTFXnDDS2c89Vj7h9SJyjQy5DZ/eTVB9O+tGkmc 07qNTOT/iW1cIL1uUpmkavOob8lRMo4lVgsw/YffgO3k+tx1t69/1pdr4C4D5udcntMa ifr1mQVKUiZUfhP3dcwwjKdCmMI9nrPaoTvUWX45x4YssHWlb21T7LIkSUnT5y1Xz88U 1RqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=uWCrzYW5; 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 k9si7864175edv.493.2020.12.07.01.38.27; Mon, 07 Dec 2020 01:38:49 -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=@infradead.org header.s=casper.20170209 header.b=uWCrzYW5; 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 S1726452AbgLGJfO (ORCPT + 99 others); Mon, 7 Dec 2020 04:35:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbgLGJfN (ORCPT ); Mon, 7 Dec 2020 04:35:13 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35A9BC0613D0 for ; Mon, 7 Dec 2020 01:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=b1j1H8XecQrBVNudhF5CzRVkTselpA16gsYa3scFeZw=; b=uWCrzYW5xhcvC1/HYehJsuLddK WYw/tPoSFVZ+GRu3XVNWbfnJaUNFnkq5EcKSntpifvfRuQPJc5ei/zQmErrZNFs3+vRdICRvk+OT8 FxHPnqWxs5Re8ypT4DRc5ZNtPFq8pSWAZuxgaRupBMPlfkmUs6aMOVGWFERhiDLhBe4/UHlSOE0Vi Eppyz9e/PdzJmEvKUd0o985bckVOQYluMF3k8YGf3h2Xmlu1wGRIZgzEri7cIcJduGsea2SegmUK4 AnLRFQy0F+yK63q644D5ReQ11tzeMvf4A6duCII1Lyo11ZshnC5c1La3muhGWQB92cUcv8u51mqsn /gndXO7w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmCuS-0007I0-ST; Mon, 07 Dec 2020 09:34:21 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B59D6304D28; Mon, 7 Dec 2020 10:34:19 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A49CB20E02217; Mon, 7 Dec 2020 10:34:19 +0100 (CET) Date: Mon, 7 Dec 2020 10:34:19 +0100 From: Peter Zijlstra To: John Ogness 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 Message-ID: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875z5eof8g.fsf@jogness.linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Dec 06, 2020 at 09:29:59PM +0106, John Ogness 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); Also look for CONFIG_64_BIT in kernel/sched/fair.c.