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: 13112020 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3B16C38142 for ; Mon, 23 Jan 2023 12:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjAWM01 (ORCPT ); Mon, 23 Jan 2023 07:26:27 -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: Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org 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