Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1327849rwb; Thu, 19 Jan 2023 09:14:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXtvlfBenSBk4xQbw9elurt9T6HHImxAeyGYDVy/e2SGULy0tAZb6K7DV52ayEv2TTYObx9U X-Received: by 2002:a17:90a:604e:b0:223:4bfe:f215 with SMTP id h14-20020a17090a604e00b002234bfef215mr12490716pjm.15.1674148440094; Thu, 19 Jan 2023 09:14:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674148440; cv=none; d=google.com; s=arc-20160816; b=kcIxoF2ba+OpUOq9WB8L2BKg6FNeYwjEsLzEhg8sme2JnxTO4XSeAWuVVD0VRHnLPd dIry/DseJeR5loQgeZn1C2I/Z9rBRCqJnFuj8DJ7Ot81vPNBRyXP6WgNN6wWnoEsAGEe 4yfB/3cp42wQyy8SefUil5BIeDW0yL9XcqMkSuewHT0RevIvNausdSYPBhefTp6fBsBD MdS2JaB6zS4OQAMdbHvZyZLLjF/x61ohac+UXPvkqQYsFHXM9VkUPHDdko4GOhnwUqce QVqN+IxyIFAHBFkDcWafm0gttKDRJ6Op3oo/mPb1tJs80sGpDrPGqzx2kYO5i5jNl8v4 0GHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=bZgElKE+M6zPeGQ50PJSNi64y0Huvpk+yfU5mO8GMQ8=; b=ive+GrDYSxblLFEBPi3PUj+P3Q7a+Soi/yktQIdNXeKgJq982IUXwrTqBAObEgR5fM 9U+tWU13R8OnQDn/EiTgnlbotr8TxHy1gfiKI6J35BOJxpCN75W/T63GLc/z6Mn3FSnA O3xXnJmbMi7BFbGPShSMdSQfqcTvxSAJGhg+Lvm3E0rkPvw5KRvntouZd/JOHZCUeC2z +JZfCBwPVzGkLcm/1JAe858//ToxxzopJ30U6sP3bKIAiRmUIiVkqdMhAZ7rgiZ3ni0L gZqavuHbn1VkQyy7BszrTZPrlxmqQKttNVjPHPDzGw/CwmaQeg2Ig2HPk6gyP7rG5W56 saRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Z1+X5u73; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv5-20020a17090b1b4500b002296a8ff568si6253636pjb.152.2023.01.19.09.13.54; Thu, 19 Jan 2023 09:14:00 -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=@joelfernandes.org header.s=google header.b=Z1+X5u73; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230414AbjASRGp (ORCPT + 45 others); Thu, 19 Jan 2023 12:06:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbjASRGm (ORCPT ); Thu, 19 Jan 2023 12:06:42 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5ABEA5CB for ; Thu, 19 Jan 2023 09:06:40 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id bf43so4163379lfb.6 for ; Thu, 19 Jan 2023 09:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bZgElKE+M6zPeGQ50PJSNi64y0Huvpk+yfU5mO8GMQ8=; b=Z1+X5u73zLWbRJIlRmxmmrKkFNMZ6vs8cT1hYVwktFOrR9+fiBm0Csn7zhfgjskvzr gC/w0L4J1BAzFHnK/wBhirlzFK+c2HXh7eTWLBfxXm43KxHIb8j9Pwl0RfEQ/7GAoayv 8ZuGAD254vZYE3R8UK2aeR0hUsQiqLzeKAQqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bZgElKE+M6zPeGQ50PJSNi64y0Huvpk+yfU5mO8GMQ8=; b=F6CwZVpiVkfZPJ8X8KiodQXGK2jYjAMZsarE/DflceUIJFABmWcq7uQVfvD1eCfN69 FiH8YVcSQQVGuqC4ZqDPhLNtVPvz9+gPEkazzYKqTgHhdn/jvVeVir3Pn0Lm0vV+d+zq iRrOZpJTdWIhz4kHQuolz45Bh2qpcKAHV2iF4n4T85DoI3xZ/qIf3cc97ilomCAd9dtj W+GCxmugGyOMVzwzbgVjbEE6bPLargg9gXdPQnwq5WCUAalGUTF/IsfS9zTC6TbnOUiQ /zdNDgh7aXiomrkSKkOiJpeyK898ZGWfnKuREiipZZwiRQ6ZAcsEVzzBUsDft7GRWyfD rukw== X-Gm-Message-State: AFqh2ko94wGgK4OjWHbZepfX9EmmPODSV/9Ic5JfDWrUDqQet93kL50r 4v87gpn2XBANIB+xqP2iquOv5adH1bukTUchVl3jnUm4MzO9a4RL X-Received: by 2002:ac2:4856:0:b0:4d1:afe6:423c with SMTP id 22-20020ac24856000000b004d1afe6423cmr878254lfy.84.1674147999189; Thu, 19 Jan 2023 09:06:39 -0800 (PST) MIME-Version: 1.0 References: <20230119141134.686626-1-frederic@kernel.org> In-Reply-To: From: Joel Fernandes Date: Thu, 19 Jan 2023 17:06:27 +0000 Message-ID: Subject: Re: [PATCH] rcu: Further comment and explain the state space of GP sequences To: Frederic Weisbecker Cc: "Paul E . McKenney" , LKML , rcu , quic_neeraju@quicinc.com, Uladzislau Rezki Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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. > > + * > > + * SRCU_STATE_SCAN2 : State set manually via rcu_seq_set_state() > > + * Indicates we are flipping the readers > > + * index and then scanning the newly inactive > > + * readers index. > > + * > > + * 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. This part I still have to learn (polling) so I'll go do that. But otherwise your patch LGTM and thanks for doing it. - Joel > > */ > > > > #define RCU_SEQ_CTR_SHIFT 2 > > -- > > 2.34.1 > > > > Ok perhaps this one got the tabs right: > > --- > From: Frederic Weisbecker > Date: Thu, 19 Jan 2023 14:29:34 +0100 > Subject: [PATCH v2] 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 | 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. > + * > + * SRCU_STATE_SCAN2 : State set manually via rcu_seq_set_state() > + * Indicates we are flipping the readers > + * index and then scanning the newly inactive > + * readers index. > + * > + * 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 > -- > 2.34.1 >