Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2597662rdd; Fri, 12 Jan 2024 15:10:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOthzEjdFy9lKUZoEuHL2//i1BZIBaDIKsP+o6lTsWzv/8MmnJRNUrt91ATwulRW02ugHm X-Received: by 2002:a17:902:e541:b0:1d0:c6fd:316c with SMTP id n1-20020a170902e54100b001d0c6fd316cmr2214777plf.72.1705101016091; Fri, 12 Jan 2024 15:10:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705101016; cv=none; d=google.com; s=arc-20160816; b=ey0kPq2Bagp5cE6Pa2x2L/rmmBpD2MjAv6MMfdK2aKTqOs3IP5B4LKjcr9Wlv4Y4IV NQOeydRvi0edbPT2TTW/o2dFSFy25WTdnX13GmZ2Fqzd7yvNdnIUfKKC5GYGpFPRIcGX Ne5vFsdMrNnXUMEOzO9+CGY3a9Ng8BL0wbGvC/WMHfnCSCzWroxt5CMpZQND4y56Ara0 Bt1YZQc3AILwgNyLFYYrsZ8Xz9qfkUEh0BNV8JzybcY58PX5V/DFcNmOHO8wqRJpMw1y /zAEpzl8huWb92UhUtzzPXc1pIg9wNCeqwrf7Sglzb74qlR1vnS+se/eqBFWAgDGb7Rh XJJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=K5YzpHp8wmJwgwCbchTLQxuOcI6+3FrPIEoAwLdO9bo=; fh=pLqVG82dKEKtwR79WearxyXqSZsjaM8zMdYHPaxw/bE=; b=x+nfwpu+OdxpQGQgXECinL63czjWkCQdSO3qrNJ8BCERssjLOGA9INFqZj6ocpUJBh 7IOG4lSr+uRAPP2lFMYZbGANuomZzYG5GZYQ0sLmj6Z0njqPN5RKqQO77j+Q0KjwvYVi knXYW7k0BYRh8i7hiWNGqjrkWh410LZacSL1ikdz18wgxECaj2BM5T5hWtFx8+I0UaID lzFTPgOXMIqfFZH/SPTNBpxFJzAJbDpMverrOt2vpa534reKdtK+robOrgUgFSGV9y62 eDfKUYs6eljL+dKt7H7LvUnxkidRsPBnLQYWabRE7rYu3bv5xaP1fW1mfyzoInax8c3C B+hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JWyfoPNX; spf=pass (google.com: domain of linux-kernel+bounces-25090-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id kj16-20020a17090306d000b001d4322ed670si4199050plb.456.2024.01.12.15.10.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 15:10:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25090-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JWyfoPNX; spf=pass (google.com: domain of linux-kernel+bounces-25090-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25090-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7A5DCB22E13 for ; Fri, 12 Jan 2024 23:10:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11F7018E34; Fri, 12 Jan 2024 23:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JWyfoPNX" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FDC618C2F; Fri, 12 Jan 2024 23:09:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39D34C433F1; Fri, 12 Jan 2024 23:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705100994; bh=efTI8B5muEIKqGCBPUBKmsADMSjVD/REEPOCMdTkE/g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JWyfoPNXyKJEhKGXUj7KSKllQ6JLPm2xKqjl7YpSLMHORqfS9ohgTqHH1poT1/M0C LN/hbtbQx6cFrr++HvCe8PEA5iyevhrVAH5TslsOzL88xFLeLKyANgYidtBlIALNXg Q2+rZcnccRmqFeodEIh63X3ZJXz5POndb0ZXChM/uR/pIgtHscbWd+pYHSKgenBbJ3 w38WIPRYVW5wCJVA5tGkmk6yDmogJZv57sv9SYBxDK2HygvnO/PBfRLSGZygEHmjmj Y4KcuWyRfn5JaJEYbVDAPTsXbhUw6svq0ZW8vfVtcUlO3vFX10CJs8aLRRGomMkq8z KXSIjJfGOS02Q== Date: Sat, 13 Jan 2024 00:09:51 +0100 From: Frederic Weisbecker To: "Uladzislau Rezki (Sony)" Cc: "Paul E . McKenney" , RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko Subject: Re: [PATCH v4 1/4] rcu: Reduce synchronize_rcu() latency Message-ID: References: <20240104162510.72773-1-urezki@gmail.com> <20240104162510.72773-2-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240104162510.72773-2-urezki@gmail.com> Le Thu, Jan 04, 2024 at 05:25:07PM +0100, Uladzislau Rezki (Sony) a ?crit : > diff --git a/kernel/rcu/Kconfig.debug b/kernel/rcu/Kconfig.debug > index 9b0b52e1836f..4812c6249185 100644 > --- a/kernel/rcu/Kconfig.debug > +++ b/kernel/rcu/Kconfig.debug > @@ -168,4 +168,16 @@ config RCU_STRICT_GRACE_PERIOD > when looking for certain types of RCU usage bugs, for example, > too-short RCU read-side critical sections. > > +config RCU_SR_NORMAL_DEBUG_GP > + bool "Debug synchronize_rcu() callers for a grace period completion" > + depends on DEBUG_KERNEL && RCU_EXPERT > + default n > + help > + This option enables additional debugging for detecting a grace > + period incompletion for synchronize_rcu() users. If a GP is not > + fully passed for any user, the warning message is emitted. > + > + Say Y here if you want to enable such debugging > + Say N if you are unsure. How about just reuse CONFIG_PROVE_RCU instead? > + > endmenu # "RCU Debugging" > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index 499803234176..b756c40e4960 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -1422,6 +1422,106 @@ static void rcu_poll_gp_seq_end_unlocked(unsigned long *snap) > raw_spin_unlock_irqrestore_rcu_node(rnp, flags); > } > > +/* > + * There are three lists for handling synchronize_rcu() users. > + * A first list corresponds to new coming users, second for users > + * which wait for a grace period and third is for which a grace > + * period is passed. > + */ > +static struct sr_normal_state { > + struct llist_head srs_next; /* request a GP users. */ > + struct llist_head srs_wait; /* wait for GP users. */ > + struct llist_head srs_done; /* ready for GP users. */ > + > + /* > + * In order to add a batch of nodes to already > + * existing srs-done-list, a tail of srs-wait-list > + * is maintained. > + */ > + struct llist_node *srs_wait_tail; > +} sr; "sr" is good enough for a function scope variable but not for a file scope one. At least "sr_state" would be better. Or maybe you don't even need to name that struct and make instead: struct { ... ... } sr_normal_state; > + > +/* Disabled by default. */ > +static int rcu_normal_wake_from_gp; > +module_param(rcu_normal_wake_from_gp, int, 0644); > + > +static void rcu_sr_normal_complete(struct llist_node *node) > +{ > + struct rcu_synchronize *rs = container_of( > + (struct rcu_head *) node, struct rcu_synchronize, head); Should there be some union in struct rcu_synchronize between struct rcu_head and struct llist_node? Anyway it's stack allocated, they could even be separate fields. > + unsigned long oldstate = (unsigned long) rs->head.func; Luckily struct callback_head layout allows such magic but if rcu_head and llist_node were separate, reviewers would be less hurt. If stack space really matters, something like the below? struct rcu_synchronize { union { struct rcu_head head; struct { struct llist_node node; unsigned long seq; } } struct completion completion; }; > + > + WARN_ONCE(IS_ENABLED(CONFIG_RCU_SR_NORMAL_DEBUG_GP) && > + !poll_state_synchronize_rcu(oldstate), > + "A full grace period is not passed yet: %lu", > + rcu_seq_diff(get_state_synchronize_rcu(), oldstate)); > + > + /* Finally. */ > + complete(&rs->completion); > +} > + [...] > + > +/* > + * Helper function for rcu_gp_cleanup(). > + */ > +static void rcu_sr_normal_gp_cleanup(void) > +{ > + struct llist_node *head, *tail; > + > + if (llist_empty(&sr.srs_wait)) > + return; > + > + tail = READ_ONCE(sr.srs_wait_tail); Is the READ_ONCE() needed? A part from those boring details: Reviewed-by: Frederic Weisbecker