Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp508770pxa; Thu, 27 Aug 2020 08:13:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrhN6kC+rCfSliPkWjE0Oa6I2hsIdVragDujBPR9qMsFRhkCBEI9NAs5ZgfKmJ639z/V6s X-Received: by 2002:a17:906:1513:: with SMTP id b19mr3814570ejd.537.1598541204574; Thu, 27 Aug 2020 08:13:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598541204; cv=none; d=google.com; s=arc-20160816; b=ZwMabWuuvpOJhmA+XNL9UiNp8ul7pjXi6Zu3Dehn3ASpEvMSHydiR1rBLCU6IiWQYc 8SS90kpsS7miurSIZB6t3Ky3qnvFQEdqfwutmkUdMt+n1ixHko2Y9zpg9+gWO5+afroa 9+dIwCHwV0Z5aiV84qdSjp5ed0Sw3r490eylRilIvgKu34QRcaWC81UKB8MrjV1gQlKo Na0CABBods3IpVBXoA8vBMvU9FWPlvNR9EmjDKL5NVSstcQDOt9ER1XMjf0eL2bBq1S/ CNvSf/CnYB0WeHdHljxJqlTbduC9Gwg2TTYVFn1fkskXkIhf9mWiHPIYInSvrwfn/QYg hDgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=26R9zahhoyqsZTU4t3ThQWnrhdQZn+07MTILm+kfM9s=; b=hYpXtrCbCcKG11JFjW5tAvgdmyuiSXO0cMHe5iIHxbw+LGuDXUka76RngQkAAzaZkr saEe4m4Ceu4ERf/A3+LTEczhFI4Q5WzEBoGWZIrZfTUlTuiQq01PX4Xf/cdpt9nqJCMp 1VeqG0kbVxyQj8uAt06TmxPLRN4F858pRKdSCxWUwk+m4teyZ9po5uLInUS6J/51t8IE REoVd/a86jZFEMeooj69cEJ3xngyDHUSC7H4GxXzXPVbq69tXDEPdvYDXw+ZyBAct5Ss 0neLa/uK7PwWWGkzE/SMsAkMRlhGqnuIu+kWgluuUE+2Zk3gEjmE+zNEZtiRPCHzu+v4 wPrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TX1+1wja; 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 f21si1832924edq.106.2020.08.27.08.13.01; Thu, 27 Aug 2020 08:13:24 -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=@linutronix.de header.s=2020 header.b=TX1+1wja; 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 S1727997AbgH0PMU (ORCPT + 99 others); Thu, 27 Aug 2020 11:12:20 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38220 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728766AbgH0Lkv (ORCPT ); Thu, 27 Aug 2020 07:40:51 -0400 From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1598528448; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=26R9zahhoyqsZTU4t3ThQWnrhdQZn+07MTILm+kfM9s=; b=TX1+1wjanjrE/bOMnAQJie2vzXwTv8I0mkZYGbi/xU31jqm7ZFLfRE5JIId1euJZdx1fBC 6D3SFXifQe3Ah1JhIdhmk7X43ZLaC5aYb8qe4sqHU/Uwg/IiMPlNn/1B4OoxerZuP8VlO5 EoFwQ9a7hRIF5bvQTQ9ciobIPaIS2QKmB3VTNcgzlxlKr/QZu/bY4ILbzmRXydf+vsAAeo tJWMORL7SJlZyv4VAHjp5Lx/jcd/DbBO/Z4jF5zAA6kp6A+sj2M60omDGkj4T7dILH/5Th rh/2ZCngAaSjLIMxKU0XoB1k0A99UCf46JEUMj5Pc+zqzvLgGAwPkvu+67ApdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1598528448; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=26R9zahhoyqsZTU4t3ThQWnrhdQZn+07MTILm+kfM9s=; b=FXAOT/ODjYG0Jo2PimtDdINR90AKk8xVV8aVgquY793/G71eFay0QrpsWD+Oi8gUZDP9xw I9O81Vd9Q6hGHOAw== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Sebastian A. Siewior" , LKML , "Ahmed S. Darwish" Subject: [PATCH v1 5/8] timekeeping: Use seqcount_latch_t Date: Thu, 27 Aug 2020 13:40:41 +0200 Message-Id: <20200827114044.11173-6-a.darwish@linutronix.de> In-Reply-To: <20200827114044.11173-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200827114044.11173-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Latch sequence counters are a multiversion concurrency control mechanism where the seqcount_t counter even/odd value is used to switch between two data storage copies. This allows the seqcount_t read path to safely interrupt its write side critical section (e.g. from NMIs). Initially, latch sequence counters were implemented as a single write function, raw_write_seqcount_latch(), above plain seqcount_t. The read path was expected to use plain seqcount_t raw_read_seqcount(). A specialized read function was later added, raw_read_seqcount_latch(), and became the standardized way for latch read paths. Having unique read and write APIs meant that latch sequence counters are basically a data type of their own -- just inappropriately overloading plain seqcount_t. The seqcount_latch_t data type was thus introduced at seqlock.h. Use that new data type instead of seqcount_raw_spinlock_t. This ensures that only latch-safe APIs are to be used with the sequence counter. Note that the use of seqcount_raw_spinlock_t was not very useful in the first place. Only the "raw_" subset of seqcount_t APIs were used at timekeeping.c. This subset was created for contexts where lockdep cannot be used. seqcount_LOCKTYPE_t's raison d'ĂȘtre -- verifying that the seqcount_t writer serialization lock is held -- cannot thus be done. References: 0c3351d451ae ("seqlock: Use raw_ prefix instead of _no_lockdep") References: 55f3560df975 ("seqlock: Extend seqcount API with associated locks") Signed-off-by: Ahmed S. Darwish --- kernel/time/timekeeping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 4c47f388a83f..999c981ae766 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -64,7 +64,7 @@ static struct timekeeper shadow_timekeeper; * See @update_fast_timekeeper() below. */ struct tk_fast { - seqcount_raw_spinlock_t seq; + seqcount_latch_t seq; struct tk_read_base base[2]; }; @@ -81,13 +81,13 @@ static struct clocksource dummy_clock = { }; static struct tk_fast tk_fast_mono ____cacheline_aligned = { - .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_fast_mono.seq, &timekeeper_lock), + .seq = SEQCNT_LATCH_ZERO(tk_fast_mono.seq), .base[0] = { .clock = &dummy_clock, }, .base[1] = { .clock = &dummy_clock, }, }; static struct tk_fast tk_fast_raw ____cacheline_aligned = { - .seq = SEQCNT_RAW_SPINLOCK_ZERO(tk_fast_raw.seq, &timekeeper_lock), + .seq = SEQCNT_LATCH_ZERO(tk_fast_raw.seq), .base[0] = { .clock = &dummy_clock, }, .base[1] = { .clock = &dummy_clock, }, }; @@ -467,7 +467,7 @@ static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf) tk_clock_read(tkr), tkr->cycle_last, tkr->mask)); - } while (read_seqcount_retry(&tkf->seq, seq)); + } while (read_seqcount_latch_retry(&tkf->seq, seq)); return now; } @@ -533,7 +533,7 @@ static __always_inline u64 __ktime_get_real_fast_ns(struct tk_fast *tkf) tk_clock_read(tkr), tkr->cycle_last, tkr->mask)); - } while (read_seqcount_retry(&tkf->seq, seq)); + } while (read_seqcount_latch_retry(&tkf->seq, seq)); return now; } -- 2.28.0