Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp30853ybh; Mon, 20 Jul 2020 09:35:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRjMJbv3o0fErnV3MebBnwejPN1GLRIoWSkxFJHfP+fsrLfuhsxqnXpSslwJ/I/dRAf2FX X-Received: by 2002:a05:6402:1250:: with SMTP id l16mr22798293edw.362.1595262916494; Mon, 20 Jul 2020 09:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262916; cv=none; d=google.com; s=arc-20160816; b=yIeigrr4FAz5isxRId5yszckL+OGqjb5OKq5Z+ZAmtuU+RF7KugKJ4C36Z1UU//a3u SQUke8Lr1XEXmr+x3Ka80raSPXpXOtQSqeqVhcI6MOw3yQUPmxMR9Xw4dTu44vxZQ8tb VrV9/wB/QjKUV+PBsFLVJu9NTQF9NcGg6yUpDtVG4I3quLfuB36zaslR7MN8scEPuRxn l0y9DcwxBrCcfPFe8L82zrO06JZBUgQBM/tRqjOp+x3rZMt8tkdW/fHIvUtIRMYTCTjI QMjqfADyPBDjXMeKFilc5S89uEp3j+P8bYAyM82cayGnHQNjEzb7DSzqqEz+eC2ToRDv k/Ew== 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=hTejVaczVZ4+w4L8i2iPGvYmmuPlo78b2DCMDOKBNPE=; b=UvogHxpsftX+mXBVeOxXwRzQluhqNjNWDUMnrOR0YA4USeS+OM+79ycJFrKFtK0tYC tWAyOBRziDYR/JoRX4/SXsdDdTcHOMFbsaDMD6yZJdEzaz+u0vFtw0zjM7rKzm+He40+ 9LlCjsELbGVPOezVS9dmlAwHw0krjY3WVVIO0Xgd74hh2y7Flo0GLwrr69JyHMtprMvQ VSSvGoZGWA/12Pm7Fo+i8AYozqA2rXTzcwrj0hPSeibW01sTGclW4N9PQjPLJ63VmKEn O0B363YH7d6dk62xaChZHwtIXqmSZ/lCZ+PCuc/mwo0dBW9taUvoaFvy4MPM4yM6cEjo 6A3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lYFPP3k4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=EjEp3oh2; 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 pk22si10340599ejb.235.2020.07.20.09.34.51; Mon, 20 Jul 2020 09:35:16 -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=lYFPP3k4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=EjEp3oh2; 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 S1731775AbgGTP4Q (ORCPT + 99 others); Mon, 20 Jul 2020 11:56:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731531AbgGTP4C (ORCPT ); Mon, 20 Jul 2020 11:56:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A695C061794 for ; Mon, 20 Jul 2020 08:56:02 -0700 (PDT) From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595260560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hTejVaczVZ4+w4L8i2iPGvYmmuPlo78b2DCMDOKBNPE=; b=lYFPP3k4u36S1kCMfdfAvF++/+hiaSOdrK/t1OyZ+qd5hUVxBN3r3Ni0d6pqH6I3LgqXYd UAiuisMsTooKVUdFRPQiAQ+sz0ip/Wepb0oKk1c2TPwqBdPuK32DgeUDv5UUNNfTeAcPij 9TPrxqnSI9EyL8iecLZjacul0aLJdW0rwnM4LTNxSUEZ9+X9MXinObmFOUbDbk6GyueI3G Gu/51NmnMnjeZExiUeHwTmgcSf0Ed96FViVkU0b6IFio52eOQmtKJ+OlOR3jhgFkql88eW 3Ft1hsSqHCHHzPJ+0hOX214kfxPNoF1/7EX4gN3PLYUKUEjACzKpp+Lk6PkJEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595260560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hTejVaczVZ4+w4L8i2iPGvYmmuPlo78b2DCMDOKBNPE=; b=EjEp3oh2PwsfLThRtM9JrTA+oJeXpqs2Pjua5FH30R18ERPFNmxB2sDq8lLDNvL/L+0Rbi 5C65eXeBUguf7oDw== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" Subject: [PATCH v4 06/24] seqlock: Implement raw_seqcount_begin() in terms of raw_read_seqcount() Date: Mon, 20 Jul 2020 17:55:12 +0200 Message-Id: <20200720155530.1173732-7-a.darwish@linutronix.de> In-Reply-To: <20200720155530.1173732-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200720155530.1173732-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org raw_seqcount_begin() has the same code as raw_read_seqcount(), with the exception of masking the sequence counter's LSB before returning it to the caller. Note, raw_seqcount_begin() masks the counter's LSB before returning it to the caller so that read_seqcount_retry() can fail if the counter is odd -- without the overhead of an extra branching instruction. Signed-off-by: Ahmed S. Darwish --- include/linux/seqlock.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 85fb3ac93ffb..e885702d8b82 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -199,10 +199,11 @@ static inline unsigned raw_read_seqcount(const seqcount_t *s) */ static inline unsigned raw_seqcount_begin(const seqcount_t *s) { - unsigned ret = READ_ONCE(s->sequence); - smp_rmb(); - kcsan_atomic_next(KCSAN_SEQLOCK_REGION_MAX); - return ret & ~1; + /* + * If the counter is odd, let read_seqcount_retry() fail + * by decrementing the counter. + */ + return raw_read_seqcount(s) & ~1; } /** -- 2.20.1