From patchwork Thu Nov 21 16:28:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13882134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FEDDD7878B for ; Thu, 21 Nov 2024 16:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F48B6B0085; Thu, 21 Nov 2024 11:28:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A52D6B0088; Thu, 21 Nov 2024 11:28:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 893666B0089; Thu, 21 Nov 2024 11:28:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6B41B6B0085 for ; Thu, 21 Nov 2024 11:28:33 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E92C11C7F97 for ; Thu, 21 Nov 2024 16:28:32 +0000 (UTC) X-FDA: 82810634760.28.4BAEE30 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf25.hostedemail.com (Postfix) with ESMTP id EBF92A0012 for ; Thu, 21 Nov 2024 16:27:51 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=HTvI9Mxk; spf=pass (imf25.hostedemail.com: domain of 3rV8_ZwYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3rV8_ZwYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732206359; h=from:from:sender: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:in-reply-to: references:dkim-signature; bh=DzshYmtDI4/275THI8fMkxHrRvuypnNNcYPdRzlGWBM=; b=BC39tFWa1Wn/sirPTqK6wCCbQM4gXWkeVlmU/npVIWOf6e98esL0sRTglxpgDU+Z4MNOWx eUArwV/RAu6rT8fVNs4yMBbWz/myHrzo6l3MuQb4tALNXx1MPrnD8j4RVtG8nBnZNtmtsi GTvCSVLwO8NF39VPBDy5pT5IxQ7L5CI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732206359; a=rsa-sha256; cv=none; b=iEICqlkao75jromvs+4RbdxcqitGESs2QUvEbwzUvEzJIsuFPapcj8C7PLOj0Ao9sowlXU 8Ai+VcEvk9vldG8Um4koM6MfjRkBtS/ZwPSGMBOei3SGUr9cFyEzDFcTDb4WQVIGq/1YFX eMsm3PFb5IaldVsnTw8n0T+4WOH90m0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=HTvI9Mxk; spf=pass (imf25.hostedemail.com: domain of 3rV8_ZwYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3rV8_ZwYKCKocebOXLQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e388c4bd92bso1895733276.1 for ; Thu, 21 Nov 2024 08:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732206509; x=1732811309; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DzshYmtDI4/275THI8fMkxHrRvuypnNNcYPdRzlGWBM=; b=HTvI9MxkQipHfOdel/Ws277grJ5TPKoKt7DLXRndWAOhEa4sFf/KreBNj1CuGJT2H5 82rnZpoi+nirIWB8lgoMkm9msI7ey1FlXpPiEIcbzlV6ZtJPtI5g52oJyYgMGFKeFOXh 5+ZVLjczA1GnylzUtJ/nmdAZEr/KSfO6o3IxiMG/Rdy2yiIIhyxS9Nf1CmwceDiEzvv+ aWNS0zV54QwYqUqtNhPI+ONefPVoufF0ofkUDsjlRnEQUtYFmuwjzfkm3M7GwBRZWOVd IjtjKD0EeffBjpKZdwud/MN3/7VwF35aMs94iE9y0Bi+Wlinc96cD0+Z2SP5wyssNE4Q J6TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732206509; x=1732811309; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DzshYmtDI4/275THI8fMkxHrRvuypnNNcYPdRzlGWBM=; b=KA3GkY/6ExeHPPt1Iaf0xOCmHFsorRWVbjFO/uLk3VKZE3Uam4XNCkY8Ggv+X3Ia1e CYI9IFF1Qxk4VCSoUiiW66rRoVOmwzXJ0YkvqoKzV9YdGFusU46rLW4Z3TDS7wrbM9jz PMLDL0zYe2dQin9Z6AvwMpQbI/5msabVUxouHtcZqP7smHV84Lh7AG7u8UOuFeV6keR/ SNW/Z+wx0rhB30X1lk1ILLgZxfiQ94B3JUvRNDU8ce/1f5owVEJVbVNv05d/SDw4iiFZ 9CDII3zMcmfnNGj3BqLVhoXsHsTAOFfIiTIN8LBSuJPF1ORtduGi6pUskXZjTwq4Qvew PYfg== X-Forwarded-Encrypted: i=1; AJvYcCWKMN8fT/rRGdynPNNG5uCUJPxNmLdXmpK+KDTyCGsuZjZr/3qzOKiC32IrfPAXXPmJH1LmiIabgw==@kvack.org X-Gm-Message-State: AOJu0YzbT+fQddpOzEdHECPIM73EUa0/pc4ekxQdc1Q7d4vU49xBZP6x djjLQJOhu0Hfv5mWFZh8gUGEpTnd/Y3btELI4GiB3g3oxw+2NCkPZFpoCVZL0839lUR4Ss94NcV A3w== X-Google-Smtp-Source: AGHT+IE33qxVBVPbXuIrP36mPBIu7ro+9/sXMzayf2Pcl9WA+DZzBVqH09gzO70e2f7gvoUxthb+t2JPckY= X-Received: from surenb-desktop.mtv.corp.google.com ([2a00:79e0:2e3f:8:ab6:ec44:b69c:2388]) (user=surenb job=sendgmr) by 2002:a05:6902:1b04:b0:e38:840d:3a9e with SMTP id 3f1490d57ef6-e38cb60a27fmr47366276.7.1732206509139; Thu, 21 Nov 2024 08:28:29 -0800 (PST) Date: Thu, 21 Nov 2024 08:28:24 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241121162826.987947-1-surenb@google.com> Subject: [PATCH v2 1/3] seqlock: add raw_seqcount_try_begin From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: peterz@infradead.org, andrii@kernel.org, jannh@google.com, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, mhocko@kernel.org, shakeel.butt@linux.dev, hannes@cmpxchg.org, david@redhat.com, willy@infradead.org, brauner@kernel.org, oleg@redhat.com, arnd@arndb.de, richard.weiyang@gmail.com, zhangpeng.00@bytedance.com, linmiaohe@huawei.com, viro@zeniv.linux.org.uk, hca@linux.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EBF92A0012 X-Stat-Signature: ybwkhzfm4hnnbdj3onw6zukqrx5uh87i X-HE-Tag: 1732206471-685468 X-HE-Meta: U2FsdGVkX19K4zj5KfcmB/zUf4TUplMmHl4E31BN38EK2nxd5xrKII+ct6gygevaL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JvQxPRxaGRm6PTscuI/BsUvn1mtik4TFft9Dyfc6IxLRVcqcEUwvoOXrDojuhcQumyt/al4Cx++HkQtQwsAry66CJnrqQWhbAiuNvU68rrr/+lFkCqZwCvprVYLdxpf9MnMaGSbYjnRUgLBM6R4Bj/McjhLbljja2waaXvfB72YLgr22vls3y6wWC24pP1HlfulORiIggICk7CyG+hGiEp452/dhV63v3ozddRyEXliH6JGaOmAAAVpzEnN6Nv8O3cA7ShwFH4DZbTXXwMBk+WigX/0jBcftlqHdn2A+bx8cdlC0UfIM28187sJlCU+U1L78pKCWkNVHpjzKaMim+8I4IAADu+HJBOIeRe3jH9/5Qix5V8aoIy6PA83BQwcaEdbqOkXpDQoW9vPf/nYVH5Znn+D3IXsqsQljTMC/r9BpLzCqlVPK7D8otPjDT568ctEvlxcDzka5fhimN4oP4Gdk6MNM1XDgaQwPNb4Z5Y3O97OE8/ndaCUS9jWtNgjnUkEyUQ8tlcA0dx6SSYFuBz/bMADCBtkbeIxko50DLqm5y25ooIbSqouL3YXM8N9Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000678, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add raw_seqcount_try_begin() to opens a read critical section of the given seqcount_t if the counter is even. This enables eliding the critical section entirely if the counter is odd, instead of doing the speculation knowing it will fail. Suggested-by: Peter Zijlstra Signed-off-by: Suren Baghdasaryan Reviewed-by: David Hildenbrand Reviewed-by: Liam R. Howlett --- Applies over Linus' ToT include/linux/seqlock.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) base-commit: 43fb83c17ba2d63dfb798f0be7453ed55ca3f9c2 diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 5298765d6ca4..22c2c48b4265 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -318,6 +318,28 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) __seq; \ }) +/** + * raw_seqcount_try_begin() - begin a seqcount_t read critical section + * w/o lockdep and w/o counter stabilization + * @s: Pointer to seqcount_t or any of the seqcount_LOCKNAME_t variants + * + * Similar to raw_seqcount_begin(), except it enables eliding the critical + * section entirely if odd, instead of doing the speculation knowing it will + * fail. + * + * Useful when counter stabilization is more or less equivalent to taking + * the lock and there is a slowpath that does that. + * + * If true, start will be set to the (even) sequence count read. + * + * Return: true when a read critical section is started. + */ +#define raw_seqcount_try_begin(s, start) \ +({ \ + start = raw_read_seqcount(s); \ + !(start & 1); \ +}) + /** * raw_seqcount_begin() - begin a seqcount_t read critical section w/o * lockdep and w/o counter stabilization