From patchwork Mon Jan 23 12:26:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 47124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1579418wrn; Mon, 23 Jan 2023 04:29:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJuOi/4rGPbAIhEzu2uIgYrNNCoFwNoLwl5r/tinLvICcJr5FOEM7HaKHag8+dErqUu6WR X-Received: by 2002:a05:6a21:1507:b0:af:98cd:7df1 with SMTP id nq7-20020a056a21150700b000af98cd7df1mr26086268pzb.24.1674476954192; Mon, 23 Jan 2023 04:29:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674476954; cv=none; d=google.com; s=arc-20160816; b=ZSW6a4tirsT1o9rRyABelRXBXZUPEnt33fWOkqLCYMnamZEPk8Ub2DUQM2ouqnOCWF df/1Jy9aqA7wgdw9Se/EN5MhnzZg2jCGb3oGq9Xi6HwkGZsYsrMrOTWJEYTowebzsvAV vCXvlb2A+bi0kNlrRZmgcSSOcY0unfRwOVupaI5LSLrjjNMXmDsZbtuaSaTck9JsYvZJ sqlSeZzuZurC5umgNR5kkgzmzBWApRiuk8Xm1QTrr9qvrsFDqcazcSJUmWPmPPlKFDbb LTy/gDFb8flE1KVEAdDltKEgJn8FmXFL1FnjgA+ddJ+givCqPEBakUShREYj7AaB/s5g m3Gg== 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=ENpitKhW0QSSU1jDp8xy1OQN+BDqrLYGi+fPlyA0aPE=; b=ZhqehBfP/T9d5SMJBdfc4lBDpojxHrJvrQcs5rh9zfrglAltuD2vovbVpMMPtT0vWJ xdCD1AP/8Z2IYFxCiXDD1U0If1D1DrT+nIm2gXjEI4396Se64ZRED+7vs6NmVO356JcY 3qa2UrcxOCqM9SQetXletlpuuc+7+1UDrFI9WsyCW6wfwBVl32LWLILNp4SeRdkg7Fmk xtzO8TMEl5rRiVFo4tIRV3WLmnbZL2q4usBfq/ecNED1zY2GnCpR39Z2/M9OMZlgym+g +aKhh9fy84+eORTwozeJc8JRXewIj1bo3C2Ui88GXxUr3wlLC+P4d8ZtfgqrSKSZfi1y mwOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LHsq9/Pk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 195-20020a6302cc000000b004ce0ead7aabsi22110573pgc.302.2023.01.23.04.29.02; Mon, 23 Jan 2023 04:29:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LHsq9/Pk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbjAWM02 (ORCPT + 99 others); Mon, 23 Jan 2023 07:26:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjAWM00 (ORCPT ); Mon, 23 Jan 2023 07:26:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E4D67ED5; Mon, 23 Jan 2023 04:26:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0027BB80D6F; Mon, 23 Jan 2023 12:26:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FE4CC433EF; Mon, 23 Jan 2023 12:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674476782; bh=REoMVUQMRQ2NqLzeaiL5wyh/jcsd+1lc+rqBF3lyNhI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LHsq9/PkpIkw75FgfUuG1EIIdCoJVjwC39dTgrQRU3/1NLhnsJZHSG+zO6YdI5J6J 2R3NtqhZBQFcQux1h/PCdWFkEcR7U4DBQZzwKuhA2ifHp2TUi+zJZp4VqO29Wvg6cN CyWlyusH99nGl0q8d82hvSaFo22bTWXVMFW8KY3ewVdbiOGWQtJspAeTXmr9IvkXGx HBObGWRU+KXeCE6+56CsCcSwCpt2ULoWSwvLvo25xnaUwUkA5QHwJClRaB6tE07zNp 1cIt/k3PJl9leiuJe33HEalzElpZDu7WnTmDtekmK3XbZWy/RYQAn4kgItXePvM4x/ TLU5aEbLTqbpw== Date: Mon, 23 Jan 2023 13:26:19 +0100 From: Frederic Weisbecker To: Joel Fernandes Cc: "Paul E . McKenney" , LKML , rcu , quic_neeraju@quicinc.com, Uladzislau Rezki Subject: [PATCH v3] rcu: Further comment and explain the state space of GP sequences Message-ID: References: <20230119141134.686626-1-frederic@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755460612975298358?= X-GMAIL-MSGID: =?utf-8?q?1755816347074599604?= On Thu, Jan 19, 2023 at 05:06:27PM +0000, Joel Fernandes wrote: > On Thu, Jan 19, 2023 at 2:15 PM Frederic Weisbecker wrote: > > > > On Thu, Jan 19, 2023 at 03:11:35PM +0100, Frederic Weisbecker wrote: > > > The state space of the GP sequence number isn't documented and the > > > definitions of its special values are scattered. Try to gather some > > > common knowledge near the GP seq headers. > > > > > > Signed-off-by: Frederic Weisbecker > > > --- > > > kernel/rcu/rcu.h | 33 +++++++++++++++++++++++++++++++++ > > > 1 file changed, 33 insertions(+) > > > > > > diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h > > > index 115616ac3bfa..fb95de039596 100644 > > > --- a/kernel/rcu/rcu.h > > > +++ b/kernel/rcu/rcu.h > > > @@ -14,6 +14,39 @@ > > > > > > /* > > > * Grace-period counter management. > > > + * > > > + * The two lowest significant bits gather the control flags. > > > + * The higher bits form the RCU sequence counter. > > > + * > > > + * About the control flags, a common value of 0 means that no GP is in progress. > > > + * A value of 1 means that a grace period has started and is in progress. When > > > + * the grace period completes, the control flags are reset to 0 and the sequence > > > + * counter is incremented. > > > + * > > > + * However some specific RCU usages make use of custom values. > > > + * > > > + * SRCU special control values: > > > + * > > > + * SRCU_SNP_INIT_SEQ : Invalid/init value set when SRCU node > > > + * is initialized. > > > + * > > > + * SRCU_STATE_IDLE : No SRCU gp is in progress > > > + * > > > + * SRCU_STATE_SCAN1 : State set by rcu_seq_start(). Indicates > > > + * we are scanning the inactive readers > > > + * index. > > The term "inactive reader" is confusing. The readers can very much be > active during scans. During a scan stage, there might be a reader on > any of the 2 indexes that can be right in the middle of their critical > section (and we don't know which index because they could have got > preempted, right after sampling idx). Maybe "inactive slot" is a > better term? And define "inactive slot" as the slot which is no longer > going to be sampled by new readers. That's why I used "inactive readers index". I guess I should have written "inactive readers' index" to disambiguate the fact that inactive refers to "index" and not "readers" but I almost never observe plural genitive written that way these days. As for the gory details of "inactive" being actually "bound to become inactive", I'm not sure that belongs here but here is what I can do: Reviewed-by: Joel Fernandes (Google) --- From: Frederic Weisbecker Date: Thu, 19 Jan 2023 14:29:34 +0100 Subject: [PATCH] rcu: Further comment and explain the state space of GP sequences The state space of the GP sequence number isn't documented and the definitions of its special values are scattered. Try to gather some common knowledge near the GP seq headers. Signed-off-by: Frederic Weisbecker --- kernel/rcu/rcu.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h index 115616ac3bfa..5be983598b5a 100644 --- a/kernel/rcu/rcu.h +++ b/kernel/rcu/rcu.h @@ -14,6 +14,43 @@ /* * Grace-period counter management. + * + * The two lowest significant bits gather the control flags. + * The higher bits form the RCU sequence counter. + * + * About the control flags, a common value of 0 means that no GP is in progress. + * A value of 1 means that a grace period has started and is in progress. When + * the grace period completes, the control flags are reset to 0 and the sequence + * counter is incremented. + * + * However some specific RCU usages make use of custom values. + * + * SRCU special control values: + * + * SRCU_SNP_INIT_SEQ : Invalid/init value set when SRCU node + * is initialized. + * + * SRCU_STATE_IDLE : No SRCU gp is in progress + * + * SRCU_STATE_SCAN1 : State set by rcu_seq_start(). Indicates + * we are scanning the readers on the slot + * defined as inactive (though there might + * be pending readers there but their number + * is bound). + * + * SRCU_STATE_SCAN2 : State set manually via rcu_seq_set_state() + * Indicates we are flipping the readers + * index and then scanning the readers on the + * slot newly set as inactive (again there + * might remain a bound amount of pending + * readers there). + * + * RCU polled GP special control value: + * + * RCU_GET_STATE_COMPLETED : State value indicating that a polled GP + * has completed. It's an absolute value + * covering both the state and the counter of + * the GP sequence. */ #define RCU_SEQ_CTR_SHIFT 2