From patchwork Thu Jan 4 16:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 185057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5716263dyb; Thu, 4 Jan 2024 08:26:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJF+4X4lczXy5NrV3rGYeKRB2okKf4sTw9RYaoUxw1oKP8lLK+kqBfjsuXiKsRZ6KeBzeK X-Received: by 2002:a17:907:789:b0:a28:4bf8:a16f with SMTP id xd9-20020a170907078900b00a284bf8a16fmr620281ejb.136.1704385580328; Thu, 04 Jan 2024 08:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385580; cv=none; d=google.com; s=arc-20160816; b=klcYj/YiqsFJ2IQmrfUJFcM5zag/FhbENzztmJUheXUjU0EAqrYUXmkmaT2V33MKun BcfjT/2j7zz+QXWYtLa+p9E3dRsv8UP/oNyyvwl4oa7HOrPEdTIvvaDQTIfjWH8OHKG9 D26pjc2tM6QNEz7aiwLKYM3psQvZ2iFSFvRn7y6OvaNsvLVoiFnS6yQxkM+k9dpwJszv GUkGkvjiG1IQgfJZqtO726QCOxvAmkCfvEzPDdU2HNiq+N8ovTqgOfaOFGOAiUOf2A6f 6FyLGJoJQeQkU0rJq9nZdEKkXB1JduB0VPCa6Eu4vAVuxGLPB112j2awP36r9MJ+8iN3 KWiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VUeBeX6rjtlK/bjhBpn7IZ69YLqQmCPOhVA274t93sE=; fh=4iZcRCmzpaCZKgp7nvxh/m3AX3kfm//yPbGO/jIXleI=; b=zZOd2eds+Pcoq0kpfbevyKgtTDRRQnwDaFi1W5oUur4+fyANvMhIO6zxwhy9KsGR/f uz5iEYRj2z2wd1BQfHrxV57eLJfHMp0Rdw3lOVg9bm2X+hAoyYfr619jM4L1vsT2WnbP Bo+bt9vnpnI8Svj4tjJgOQ6Nr2Xzyr1v8unvRpWGoB/IbLYISenfHkpp2yl9+/XllHN/ pCc6eOIBOHwX1fA2q02fVMeZXnu7wDwnuyL4VBD2lnsJsCuKXd+if/XNwvvtpFXkEJu7 u6kxdM02p4HgOr9xOuPre3ZDriVCBqivyL+mRtdvhhHqI2NU6pf3DTFG//ZyUgnpEouc QUnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZgBfArE7; spf=pass (google.com: domain of linux-kernel+bounces-16917-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16917-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id su14-20020a17090703ce00b00a23634b1ebdsi12044980ejb.253.2024.01.04.08.26.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:26:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16917-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZgBfArE7; spf=pass (google.com: domain of linux-kernel+bounces-16917-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16917-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id BF4031F218B1 for ; Thu, 4 Jan 2024 16:26:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16E7125571; Thu, 4 Jan 2024 16:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZgBfArE7" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8899924B23; Thu, 4 Jan 2024 16:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2cc9fa5e8e1so8654581fa.3; Thu, 04 Jan 2024 08:25:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704385514; x=1704990314; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VUeBeX6rjtlK/bjhBpn7IZ69YLqQmCPOhVA274t93sE=; b=ZgBfArE7AD86xlClSkgVUKq5iyu9eFdQENC7awlW5eXImLMsGQ+CfqjRktR7Y0wgg1 vnz+v9A/ijBT3nLjpnO6oweOSYeUBKcG1EKjVriha6r49fDIiL5b3MQ/OnmcT7dm2jr9 5XYJZW/hLE+ABmGCRWLIsuh0eNh3gjEGaepP/OvL1nynBYfoB5MdkufvRFn11ZOs2zoh mz7id7HoUk38cQxYFjX0zWtDNVElYL4mfUeIqTn9UmNQmIz5VVxuYDHTFJ+DlVI4P6qR x6skKR2wr8w+RBsjPhyBfz8JGotQW7E8pNwOQ5MW5ZFx4gJVATtdcQh7xfOzxBsMUWz8 FRaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704385514; x=1704990314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VUeBeX6rjtlK/bjhBpn7IZ69YLqQmCPOhVA274t93sE=; b=cbhnqIzJcYfztpTmfLbpa9iApRIU3SUT2ZkHqv94MzOpCZwypuj46W07SRwkSwfpYv KpgP4moWxBjX5H2K11TlFZ71mp+A3atkUa5Cra6kg4mvcfTrXf6qU/pclIMj7bffO8X7 yxGCWY9MfEjMscEyoOnrWSWRvMhqcdo2Ci8stHclc+wHUoKIPLbfTlMNn5lgstkt6KjH rrGqEvSw6RAjuMa323S8mXecJpCWOoj0jrmrWnQO5f0Bfksfl2JKUal2HXaJ1ERyAAMx 0qDfrRqIk9QNmRt9cFX0/A2Wa4TL2qmcPFNq2FlVGu4VeIVO9remEk6p870MGFboyta3 iw1Q== X-Gm-Message-State: AOJu0Yx+MnagP0ay1yfUOJwOVJDj4IjAx0iZANboVK9HbAQnuqEQV2Uj EC2QWghYG8xT7KipQ3JqBQA= X-Received: by 2002:ac2:5b84:0:b0:50e:6d96:4b32 with SMTP id o4-20020ac25b84000000b0050e6d964b32mr410302lfn.71.1704385514347; Thu, 04 Jan 2024 08:25:14 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id i5-20020a0565123e0500b0050e80d1e142sm2789252lfv.170.2024.01.04.08.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:25:13 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: "Paul E . McKenney" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Uladzislau Rezki , Oleksiy Avramchenko , Frederic Weisbecker Subject: [PATCH v4 1/4] rcu: Reduce synchronize_rcu() latency Date: Thu, 4 Jan 2024 17:25:07 +0100 Message-Id: <20240104162510.72773-2-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104162510.72773-1-urezki@gmail.com> References: <20240104162510.72773-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787177813983184683 X-GMAIL-MSGID: 1787177813983184683 A call to a synchronize_rcu() can be optimized from a latency point of view. Workloads which depend on this can benefit of it. The delay of wakeme_after_rcu() callback, which unblocks a waiter, depends on several factors: - how fast a process of offloading is started. Combination of: - !CONFIG_RCU_NOCB_CPU/CONFIG_RCU_NOCB_CPU; - !CONFIG_RCU_LAZY/CONFIG_RCU_LAZY; - other. - when started, invoking path is interrupted due to: - time limit; - need_resched(); - if limit is reached. - where in a nocb list it is located; - how fast previous callbacks completed; Example: 1. On our embedded devices i can easily trigger the scenario when it is a last in the list out of ~3600 callbacks: <...>-29 [001] d..1. 21950.145313: rcu_batch_start: rcu_preempt CBs=3613 bl=28 ... <...>-29 [001] ..... 21950.152578: rcu_invoke_callback: rcu_preempt rhp=00000000b2d6dee8 func=__free_vm_area_struct.cfi_jt <...>-29 [001] ..... 21950.152579: rcu_invoke_callback: rcu_preempt rhp=00000000a446f607 func=__free_vm_area_struct.cfi_jt <...>-29 [001] ..... 21950.152580: rcu_invoke_callback: rcu_preempt rhp=00000000a5cab03b func=__free_vm_area_struct.cfi_jt <...>-29 [001] ..... 21950.152581: rcu_invoke_callback: rcu_preempt rhp=0000000013b7e5ee func=__free_vm_area_struct.cfi_jt <...>-29 [001] ..... 21950.152582: rcu_invoke_callback: rcu_preempt rhp=000000000a8ca6f9 func=__free_vm_area_struct.cfi_jt <...>-29 [001] ..... 21950.152583: rcu_invoke_callback: rcu_preempt rhp=000000008f162ca8 func=wakeme_after_rcu.cfi_jt <...>-29 [001] d..1. 21950.152625: rcu_batch_end: rcu_preempt CBs-invoked=3612 idle=.... 2. We use cpuset/cgroup to classify tasks and assign them into different cgroups. For example "backgrond" group which binds tasks only to little CPUs or "foreground" which makes use of all CPUs. Tasks can be migrated between groups by a request if an acceleration is needed. See below an example how "surfaceflinger" task gets migrated. Initially it is located in the "system-background" cgroup which allows to run only on little cores. In order to speed it up it can be temporary moved into "foreground" cgroup which allows to use big/all CPUs: cgroup_attach_task(): -> cgroup_migrate_execute() -> cpuset_can_attach() -> percpu_down_write() -> rcu_sync_enter() -> synchronize_rcu() -> now move tasks to the new cgroup. -> cgroup_migrate_finish() rcuop/1-29 [000] ..... 7030.528570: rcu_invoke_callback: rcu_preempt rhp=00000000461605e0 func=wakeme_after_rcu.cfi_jt PERFD-SERVER-1855 [000] d..1. 7030.530293: cgroup_attach_task: dst_root=3 dst_id=22 dst_level=1 dst_path=/foreground pid=1900 comm=surfaceflinger TimerDispatch-2768 [002] d..5. 7030.537542: sched_migrate_task: comm=surfaceflinger pid=1900 prio=98 orig_cpu=0 dest_cpu=4 "Boosting a task" depends on synchronize_rcu() latency: - first trace shows a completion of synchronize_rcu(); - second shows attaching a task to a new group; - last shows a final step when migration occurs. 3. To address this drawback, maintain a separate track that consists of synchronize_rcu() callers only. After completion of a grace period users are deferred to a dedicated worker to process requests. 4. This patch reduces the latency of synchronize_rcu() approximately by ~30-40% on synthetic tests. The real test case, camera launch time, shows(time is in milliseconds): 1-run 542 vs 489 improvement 9% 2-run 540 vs 466 improvement 13% 3-run 518 vs 468 improvement 9% 4-run 531 vs 457 improvement 13% 5-run 548 vs 475 improvement 13% 6-run 509 vs 484 improvement 4% Synthetic test(no "noise" from other callbacks): Hardware: x86_64 64 CPUs, 64GB of memory Linux-6.6 - 10K tasks(simultaneous); - each task does(1000 loops) synchronize_rcu(); kfree(p); default: CONFIG_RCU_NOCB_CPU: takes 54 seconds to complete all users; patch: CONFIG_RCU_NOCB_CPU: takes 35 seconds to complete all users. Running 60K gives approximately same results on my setup. Please note it is without any interaction with another type of callbacks, otherwise it will impact a lot a default case. 5. An extra CONFIG_RCU_SR_NORMAL_DEBUG_GP kernel option is added which 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. 6. By default it is disabled. To enable this perform one of the below sequence: echo 1 > /sys/module/rcutree/parameters/rcu_normal_wake_from_gp or pass a boot parameter "rcutree.rcu_normal_wake_from_gp=1" Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Frederic Weisbecker --- .../admin-guide/kernel-parameters.txt | 14 ++ kernel/rcu/Kconfig.debug | 12 ++ kernel/rcu/tree.c | 138 +++++++++++++++++- kernel/rcu/tree_exp.h | 2 +- 4 files changed, 164 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 17a454909ab4..2cca75e4f0c6 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5047,6 +5047,20 @@ delay, memory pressure or callback list growing too big. + rcutree.rcu_normal_wake_from_gp= [KNL] + Reduces a latency of synchronize_rcu() call. This approach + maintains its own track of synchronize_rcu() callers, so it + does not interact with regular callbacks because it does not + use a call_rcu[_hurry]() path. Please note, this is for a + normal grace period. + + How to enable it: + + echo 1 > /sys/module/rcutree/parameters/rcu_normal_wake_from_gp + or pass a boot parameter "rcutree.rcu_normal_wake_from_gp=1" + + Default is 0. + rcuscale.gp_async= [KNL] Measure performance of asynchronous grace-period primitives such as call_rcu(). 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. + 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; + +/* 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); + unsigned long oldstate = (unsigned long) rs->head.func; + + 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); +} + +static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) +{ + struct llist_node *done, *rcu, *next; + + done = llist_del_all(&sr.srs_done); + if (!done) + return; + + llist_for_each_safe(rcu, next, done) + rcu_sr_normal_complete(rcu); +} +static DECLARE_WORK(sr_normal_gp_cleanup, rcu_sr_normal_gp_cleanup_work); + +/* + * 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); + head = __llist_del_all(&sr.srs_wait); + + if (head) { + /* Can be not empty. */ + llist_add_batch(head, tail, &sr.srs_done); + queue_work(system_highpri_wq, &sr_normal_gp_cleanup); + } +} + +/* + * Helper function for rcu_gp_init(). + */ +static void rcu_sr_normal_gp_init(void) +{ + struct llist_node *head, *tail; + + if (llist_empty(&sr.srs_next)) + return; + + tail = llist_del_all(&sr.srs_next); + head = llist_reverse_order(tail); + + /* + * A waiting list of GP should be empty on this step, + * since a GP-kthread, rcu_gp_init() -> gp_cleanup(), + * rolls it over. If not, it is a BUG, warn a user. + */ + WARN_ON_ONCE(!llist_empty(&sr.srs_wait)); + + WRITE_ONCE(sr.srs_wait_tail, tail); + __llist_add_batch(head, tail, &sr.srs_wait); +} + +static void rcu_sr_normal_add_req(struct rcu_synchronize *rs) +{ + llist_add((struct llist_node *) &rs->head, &sr.srs_next); +} + /* * Initialize a new grace period. Return false if no grace period required. */ @@ -1456,6 +1556,7 @@ static noinline_for_stack bool rcu_gp_init(void) /* Record GP times before starting GP, hence rcu_seq_start(). */ rcu_seq_start(&rcu_state.gp_seq); ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq); + rcu_sr_normal_gp_init(); trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("start")); rcu_poll_gp_seq_start(&rcu_state.gp_seq_polled_snap); raw_spin_unlock_irq_rcu_node(rnp); @@ -1825,6 +1926,9 @@ static noinline void rcu_gp_cleanup(void) } raw_spin_unlock_irq_rcu_node(rnp); + // Make synchronize_rcu() users aware of the end of old grace period. + rcu_sr_normal_gp_cleanup(); + // If strict, make all CPUs aware of the end of the old grace period. if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD)) on_each_cpu(rcu_strict_gp_boundary, NULL, 0); @@ -3561,6 +3665,38 @@ static int rcu_blocking_is_gp(void) return true; } +/* + * Helper function for the synchronize_rcu() API. + */ +static void synchronize_rcu_normal(void) +{ + struct rcu_synchronize rs; + + if (!READ_ONCE(rcu_normal_wake_from_gp)) { + wait_rcu_gp(call_rcu_hurry); + return; + } + + init_rcu_head_on_stack(&rs.head); + init_completion(&rs.completion); + + /* + * This code might be preempted, therefore take a GP + * snapshot before adding a request. + */ + if (IS_ENABLED(CONFIG_RCU_SR_NORMAL_DEBUG_GP)) + rs.head.func = (void *) get_state_synchronize_rcu(); + + rcu_sr_normal_add_req(&rs); + + /* Kick a GP and start waiting. */ + (void) start_poll_synchronize_rcu(); + + /* Now we can wait. */ + wait_for_completion(&rs.completion); + destroy_rcu_head_on_stack(&rs.head); +} + /** * synchronize_rcu - wait until a grace period has elapsed. * @@ -3612,7 +3748,7 @@ void synchronize_rcu(void) if (rcu_gp_is_expedited()) synchronize_rcu_expedited(); else - wait_rcu_gp(call_rcu_hurry); + synchronize_rcu_normal(); return; } diff --git a/kernel/rcu/tree_exp.h b/kernel/rcu/tree_exp.h index 014ddf672165..bdc30d972d32 100644 --- a/kernel/rcu/tree_exp.h +++ b/kernel/rcu/tree_exp.h @@ -985,7 +985,7 @@ void synchronize_rcu_expedited(void) /* If expedited grace periods are prohibited, fall back to normal. */ if (rcu_gp_is_normal()) { - wait_rcu_gp(call_rcu_hurry); + synchronize_rcu_normal(); return; } From patchwork Thu Jan 4 16:25:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 185059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5716681dyb; Thu, 4 Jan 2024 08:27:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMDc4z03VKVJlrzGCKRdIl5lk1DK/r04J1sRuGyIS8Ar//zIlJjw+xIktC5O7jR3u+gtWs X-Received: by 2002:a17:90a:94ca:b0:28c:f623:5f40 with SMTP id j10-20020a17090a94ca00b0028cf6235f40mr888753pjw.14.1704385627770; Thu, 04 Jan 2024 08:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385627; cv=none; d=google.com; s=arc-20160816; b=AaomYRBzl1xoFO2gOp/kDVSlE6uFRcSirpmzy4buDq88u3PNMuMuScJpYi4ouIKlT3 8MCLiy4dcIsaYqKhP2SFGd6CHCoH9uAxQyAhZpb/zo5MLiTyBdkeN0D/agIZjFDDw+8b jPKlShgVdAuhLl8lDLo75Eb2wViojQUUVB6cooez4tnBm+a3JjyhCdUlV8q3k4+8FkXA ocasbZVNjXhurSvaDT59Y/UoZ8HdOOCz8G9G6ZnIqf6dvPOoP8aZ0w5XSdXwhsV792n2 tMSvmIUU1EhzSYpW0sUT7gIDGtM33gBfGBNAZxFkLNOVPgMZ53vR9qpqtolQx8G4S7N8 DgRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=brIJ2euFOpiSQ53pXAG7v0znGgtL9iaFEsHcomev58o=; fh=4iZcRCmzpaCZKgp7nvxh/m3AX3kfm//yPbGO/jIXleI=; b=z8IF4S+fOQtHMoQgjWoyyZ43X/0tZEIren09q5+jKGVm7j78dwcDUKZY1NdSlSM4k2 Sq3tBAfynhsWMhHxedKNTi/btyHQ61t10LD3W5gQJ6OrGLRkb86WotKTB6yutitESv2r LbD2eoT41B0gSb715X2hINaE05gFYVplwqAm0JuKCVabaaKLtF26VAQiyS2+JO3a0U+2 2StRuHhwFFYVNguwNZinnKOFArXwAF2UTC9/acXiUlPba1pMgvtu3JDL/Fe0sLJuxL1h Djd7BzNRQzGt4cVm5saee+jBpRS200VFpEE+WFDse6SFqlMBYMiI49hxd9+2T4GVI9Hn mRdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LCQ2PdEw; spf=pass (google.com: domain of linux-kernel+bounces-16918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16918-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z3-20020a656103000000b005cddfe4eb92si23341594pgu.883.2024.01.04.08.27.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:27:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16918-ouuuleilei=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=@gmail.com header.s=20230601 header.b=LCQ2PdEw; spf=pass (google.com: domain of linux-kernel+bounces-16918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16918-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 2B881B238F6 for ; Thu, 4 Jan 2024 16:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8594128694; Thu, 4 Jan 2024 16:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LCQ2PdEw" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71BA824B54; Thu, 4 Jan 2024 16:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50e4e3323a6so1567496e87.0; Thu, 04 Jan 2024 08:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704385515; x=1704990315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=brIJ2euFOpiSQ53pXAG7v0znGgtL9iaFEsHcomev58o=; b=LCQ2PdEws9a5KKhcAQjH0211pS3ANlyR4YfklMLtH5ljGJq0Xl+o1jxNgwAn/qDV+F HfkFJ2gfUh+0sWEpf20ZGNtmeZAFgiJ3nbfTDcT7BmI0e4kIN+ktEqcOqOj9Q+qjBwUA wL8JaJqQsp3W2I8nLcYkPZTYneUZ4JQW/xia0Yj5wh5k1We0+S10On+NbdqUoNG0Dhel fU2WdTiF06K5A2P4eBkKa3I9Bcgel8XDh23UQXzLlR1Cg3+zK+9w/NGkww2LnejV4hau LuaYd1+JuAIs0kx0da8YryzGTvXovh/hegAoI6DqbUCFg+BcTwGggXqSt+bzr2W0V42Y 9iZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704385515; x=1704990315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=brIJ2euFOpiSQ53pXAG7v0znGgtL9iaFEsHcomev58o=; b=Zhwp3c9/aa5psiemoh+WDMTckoM3tSeMVskfgM0Yb24D8dKf8SNjSu2roorAF1gGs3 ojOYZpkViYB7on32FDjG5Py9wk9sMAPeCHIvH4lBOTU1dC26AU97oR2ceU5uAkqnk73J gB5iGHmLWnRVlu/z/iE+aROGMfafzqjwQWQ0/o1L1Mh6RLzuDJj1Ua+TYom4ePiFQDCS RZT8Da0Fgue832U92DHonvSNmnnmkdnoHbMoUXU7W1fO+2Aju6oJr23LkO91Qbu7ru2H 9hbmIDAI2s9dlK++35rFnVdWIZbv+nj0xWdufF6bOtyR78Bc01YkUR9zNw9muo6v+Df2 PIaA== X-Gm-Message-State: AOJu0YxAUHFt4e9RwUJFJQayo8f+vR/4kCmwJB7bkkDuWf4U6QZOhKum JcTOdR7UCrc8ZzAZfQPIrQI= X-Received: by 2002:a05:6512:20c6:b0:50e:7b9c:4d97 with SMTP id u6-20020a05651220c600b0050e7b9c4d97mr455431lfr.8.1704385515198; Thu, 04 Jan 2024 08:25:15 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id i5-20020a0565123e0500b0050e80d1e142sm2789252lfv.170.2024.01.04.08.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:25:14 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: "Paul E . McKenney" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Uladzislau Rezki , Oleksiy Avramchenko , Frederic Weisbecker Subject: [PATCH v4 2/4] rcu: Add a trace event for synchronize_rcu_normal() Date: Thu, 4 Jan 2024 17:25:08 +0100 Message-Id: <20240104162510.72773-3-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104162510.72773-1-urezki@gmail.com> References: <20240104162510.72773-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787177864168134555 X-GMAIL-MSGID: 1787177864168134555 Add an rcu_sr_normal() trace event. It takes three arguments first one is the name of RCU flavour, second one is a user id which triggeres synchronize_rcu_normal() and last one is an event. There are two traces in the synchronize_rcu_normal(). On entry, when a new request is registered and on exit point when request is completed. Please note, CONFIG_RCU_TRACE=y is required to activate traces. Signed-off-by: Uladzislau Rezki (Sony) --- include/trace/events/rcu.h | 27 +++++++++++++++++++++++++++ kernel/rcu/tree.c | 7 ++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/trace/events/rcu.h b/include/trace/events/rcu.h index 2ef9c719772a..31b3e0d3e65f 100644 --- a/include/trace/events/rcu.h +++ b/include/trace/events/rcu.h @@ -707,6 +707,33 @@ TRACE_EVENT_RCU(rcu_invoke_kfree_bulk_callback, __entry->rcuname, __entry->p, __entry->nr_records) ); +/* + * Tracepoint for a normal synchronize_rcu() states. The first argument + * is the RCU flavor, the second argument is a pointer to rcu_head the + * last one is an event. + */ +TRACE_EVENT_RCU(rcu_sr_normal, + + TP_PROTO(const char *rcuname, struct rcu_head *rhp, const char *srevent), + + TP_ARGS(rcuname, rhp, srevent), + + TP_STRUCT__entry( + __field(const char *, rcuname) + __field(void *, rhp) + __field(const char *, srevent) + ), + + TP_fast_assign( + __entry->rcuname = rcuname; + __entry->rhp = rhp; + __entry->srevent = srevent; + ), + + TP_printk("%s rhp=0x%p event=%s", + __entry->rcuname, __entry->rhp, __entry->srevent) +); + /* * Tracepoint for exiting rcu_do_batch after RCU callbacks have been * invoked. The first argument is the name of the RCU flavor, diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index b756c40e4960..7d2ed89efcb3 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3672,9 +3672,11 @@ static void synchronize_rcu_normal(void) { struct rcu_synchronize rs; + trace_rcu_sr_normal(rcu_state.name, &rs.head, TPS("request")); + if (!READ_ONCE(rcu_normal_wake_from_gp)) { wait_rcu_gp(call_rcu_hurry); - return; + goto trace_complete_out; } init_rcu_head_on_stack(&rs.head); @@ -3695,6 +3697,9 @@ static void synchronize_rcu_normal(void) /* Now we can wait. */ wait_for_completion(&rs.completion); destroy_rcu_head_on_stack(&rs.head); + +trace_complete_out: + trace_rcu_sr_normal(rcu_state.name, &rs.head, TPS("complete")); } /** From patchwork Thu Jan 4 16:25:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 185060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5716868dyb; Thu, 4 Jan 2024 08:27:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMeTuHBe57NyhgBtPAhl0kJ1+kGYZBBc3U1eSkgxY6DGrhYZ4hEp41RG01dkBGdCxyUdfU X-Received: by 2002:a17:902:e889:b0:1d4:1f0d:6785 with SMTP id w9-20020a170902e88900b001d41f0d6785mr925859plg.20.1704385643630; Thu, 04 Jan 2024 08:27:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385643; cv=none; d=google.com; s=arc-20160816; b=kmg78H+xPzikzQofU+O4OU8LwGnmRzGlHrxm6lct/Mq3/tAwUTzqtSlNeTjwRvYpTB XDYaAzVEvLYa4TXMCf/7/gOrzQnZSclzsiefUwA1tnf/XaowmN0HYxYtFSgO7161SYmI 40Qn5XKdH4l05h6I4uH0wJdrLwBEv8JN2BB4xmrFH0HmsvDcxI0rqvF9+0T+dIDniESv NVspdCnN3K1tayZ84o2eOwEX8WreZZSoYmX7F7y9TV59k1K7uEiimS6LTJ54J2UbDgYO O31fiUL3WUMsfDL8u5AImgX/4Ig21tMsVq856UY1JFG6dEuV6Ovt4T6+UToTi4OH2vLl osJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JwvcJwxDzv91yZ88lkQTn+Y5ddJXcrq/Xx7SY1QWYMU=; fh=4iZcRCmzpaCZKgp7nvxh/m3AX3kfm//yPbGO/jIXleI=; b=gnBfYvnUS/WcBekqrW0ByAAJ4nw2JBqMScMV2guKNfGxQDYPoIMDEH2uQ3wUDqg7V9 6SrHvuqD4d5Bog3OmtQkz8kdtzR3BYkss2K6MpOArfA4jET5G/G6AOVoosa7r746jsgx MFLvFXx9+xuWcs3yZFLF9VwCY8Mrc95h/4eIL3eQmOUflK8D9+t6Zdqj9B0e/9PlfoqO dxIGGEECGpU89guDyRbiza2XnlM0F4XrxiQoE2yVAiEVLQiucPm85IeI0zM8SKy4yz+M F2dNKrAsFp8B4sVL460h4sYZivFt8ZsZEwaracCSYxQheX5wrCil8ODKpafr/oP/nhXZ 3M2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="azoFA/Wi"; spf=pass (google.com: domain of linux-kernel+bounces-16919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16919-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x9-20020a654149000000b005b96c2ab110si23161009pgp.131.2024.01.04.08.27.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:27:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16919-ouuuleilei=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=@gmail.com header.s=20230601 header.b="azoFA/Wi"; spf=pass (google.com: domain of linux-kernel+bounces-16919-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16919-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 E4DEDB237D9 for ; Thu, 4 Jan 2024 16:26:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8574F24B2C; Thu, 4 Jan 2024 16:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="azoFA/Wi" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0747324B5E; Thu, 4 Jan 2024 16:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50eaa8b447bso746984e87.1; Thu, 04 Jan 2024 08:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704385516; x=1704990316; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JwvcJwxDzv91yZ88lkQTn+Y5ddJXcrq/Xx7SY1QWYMU=; b=azoFA/WiRQeOBH4U02NMV/f0Ko2tIQjO5U+euysu6ovgDJaadpF53nPBoiLKNWulWa jQlcrm9caJKSvcSIHC1wlPSj0Nk4sCg89B7ugQhMvj7wgF6vjYYlDmbOM28dT1kFt8/t hvLk1EF1esR9bBmii2O2503cUTrVi626koiUdo42ZZkCGYo8nCoMD+8h8j4BkNM0DdlW 3YHECVwlXUQfa8LPqlax15VYPChWAzoyjtoiaw4HtRrqUnnsPJ1gUTQJ6X8bjfxvZFu0 JCBDuxQv/762gws0ucSGaV5ifgmWHW2EIWZOU2cKd31IXxVcv/tRSi7jWjNUTMz7H+0x 0iSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704385516; x=1704990316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JwvcJwxDzv91yZ88lkQTn+Y5ddJXcrq/Xx7SY1QWYMU=; b=R3JOWETAezCxB8dWeqDvK8pqtB6PqOrbanX+dMggFmBz2yAoltpFSGaAIPwAIM/bR7 Q+eV4h0LJZMbfsYlPcUnPVWE0MHT//AEDlp391nxqFumig/qw/cOLfcY1TUojEDbxDaK TX3SoRXZvnxM7PxdGM/0EYymEHEw42EVepEEv2wDBLUnc+bI3xcwqsocVyx6pwQ2Cphe Uow10TPWgvEQuQADlWXUdvhsF7jZdR+nj8OcGEedc6ShJMEWYTOrlUR87CV6hEYcgdfZ gG01VkO9AD4dkGMrz4zkLQEbL1V1r0oOB3ssQkfe/nQl+nMpUdJYFrJD+ET78x8RWj+H ntSA== X-Gm-Message-State: AOJu0YwIH91Fowdmk++B731S9vWI4dUbMc/+Yz0YnI98cwHeG20c+8iU 60z8UWjq1r1+jqiuM11qDUc= X-Received: by 2002:a05:6512:3da2:b0:50e:76a4:4e13 with SMTP id k34-20020a0565123da200b0050e76a44e13mr255906lfv.119.1704385516013; Thu, 04 Jan 2024 08:25:16 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id i5-20020a0565123e0500b0050e80d1e142sm2789252lfv.170.2024.01.04.08.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:25:15 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: "Paul E . McKenney" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Uladzislau Rezki , Oleksiy Avramchenko , Frederic Weisbecker Subject: [PATCH v4 3/4] rcu: Improve handling of synchronize_rcu() users Date: Thu, 4 Jan 2024 17:25:09 +0100 Message-Id: <20240104162510.72773-4-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104162510.72773-1-urezki@gmail.com> References: <20240104162510.72773-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787177880698443191 X-GMAIL-MSGID: 1787177880698443191 From: Neeraj Upadhyay Currently, processing of the next batch of rcu_synchronize nodes for the new grace period, requires doing a llist reversal operation to find the tail element of the list. This can be a very costly operation (high number of cache misses) for a long list. To address this, this patch introduces a "dummy-wait-node" entity. At every grace period init, a new wait node is added to the llist. This wait node is used as wait tail for this new grace period. This allows lockless additions of new rcu_synchronize nodes in the rcu_sr_normal_add_req(), while the cleanup work executes and does the progress. The dummy nodes are removed on next round of cleanup work execution. Co-developed-by: Uladzislau Rezki (Sony) Signed-off-by: Neeraj Upadhyay Signed-off-by: Uladzislau Rezki (Sony) --- kernel/rcu/tree.c | 271 +++++++++++++++++++++++++++++++++++++++------- kernel/rcu/tree.h | 13 +++ 2 files changed, 244 insertions(+), 40 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 7d2ed89efcb3..88a47a6a658e 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1423,23 +1423,157 @@ static void rcu_poll_gp_seq_end_unlocked(unsigned long *snap) } /* - * 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. + * There is a single llist, which is used for handling + * synchronize_rcu() users' enqueued rcu_synchronize nodes. + * Within this llist, there are two tail pointers: + * + * wait tail: Tracks the set of nodes, which need to + * wait for the current GP to complete. + * done tail: Tracks the set of nodes, for which grace + * period has elapsed. These nodes processing + * will be done as part of the cleanup work + * execution by a kworker. + * + * At every grace period init, a new wait node is added + * to the llist. This wait node is used as wait tail + * for this new grace period. Given that there are a fixed + * number of wait nodes, if all wait nodes are in use + * (which can happen when kworker callback processing + * is delayed) and additional grace period is requested. + * This means, a system is slow in processing callbacks. + * + * TODO: If a slow processing is detected, a first node + * in the llist should be used as a wait-tail for this + * grace period, therefore users which should wait due + * to a slow process are handled by _this_ grace period + * and not next. + * + * Below is an illustration of how the done and wait + * tail pointers move from one set of rcu_synchronize nodes + * to the other, as grace periods start and finish and + * nodes are processed by kworker. + * + * + * a. Initial llist callbacks list: + * + * +----------+ +--------+ +-------+ + * | | | | | | + * | head |---------> | cb2 |--------->| cb1 | + * | | | | | | + * +----------+ +--------+ +-------+ + * + * + * + * b. New GP1 Start: + * + * WAIT TAIL + * | + * | + * v + * +----------+ +--------+ +--------+ +-------+ + * | | | | | | | | + * | head ------> wait |------> cb2 |------> | cb1 | + * | | | head1 | | | | | + * +----------+ +--------+ +--------+ +-------+ + * + * + * + * c. GP completion: + * + * WAIT_TAIL == DONE_TAIL + * + * DONE TAIL + * | + * | + * v + * +----------+ +--------+ +--------+ +-------+ + * | | | | | | | | + * | head ------> wait |------> cb2 |------> | cb1 | + * | | | head1 | | | | | + * +----------+ +--------+ +--------+ +-------+ + * + * + * + * d. New callbacks and GP2 start: + * + * WAIT TAIL DONE TAIL + * | | + * | | + * v v + * +----------+ +------+ +------+ +------+ +-----+ +-----+ +-----+ + * | | | | | | | | | | | | | | + * | head ------> wait |--->| cb4 |--->| cb3 |--->|wait |--->| cb2 |--->| cb1 | + * | | | head2| | | | | |head1| | | | | + * +----------+ +------+ +------+ +------+ +-----+ +-----+ +-----+ + * + * + * + * e. GP2 completion: + * + * WAIT_TAIL == DONE_TAIL + * DONE TAIL + * | + * | + * v + * +----------+ +------+ +------+ +------+ +-----+ +-----+ +-----+ + * | | | | | | | | | | | | | | + * | head ------> wait |--->| cb4 |--->| cb3 |--->|wait |--->| cb2 |--->| cb1 | + * | | | head2| | | | | |head1| | | | | + * +----------+ +------+ +------+ +------+ +-----+ +-----+ +-----+ + * + * + * While the llist state transitions from d to e, a kworker + * can start executing rcu_sr_normal_gp_cleanup_work() and + * can observe either the old done tail (@c) or the new + * done tail (@e). So, done tail updates and reads need + * to use the rel-acq semantics. If the concurrent kworker + * observes the old done tail, the newly queued work + * execution will process the updated done tail. If the + * concurrent kworker observes the new done tail, then + * the newly queued work will skip processing the done + * tail, as workqueue semantics guarantees that the new + * work is executed only after the previous one completes. + * + * f. kworker callbacks processing complete: + * + * + * DONE TAIL + * | + * | + * v + * +----------+ +--------+ + * | | | | + * | head ------> wait | + * | | | head2 | + * +----------+ +--------+ + * */ -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. */ +static bool rcu_sr_is_wait_head(struct llist_node *node) +{ + return &(rcu_state.srs_wait_nodes)[0].node <= node && + node <= &(rcu_state.srs_wait_nodes)[SR_NORMAL_GP_WAIT_HEAD_MAX - 1].node; +} - /* - * 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; +static struct llist_node *rcu_sr_get_wait_head(void) +{ + struct sr_wait_node *sr_wn; + int i; + + for (i = 0; i < SR_NORMAL_GP_WAIT_HEAD_MAX; i++) { + sr_wn = &(rcu_state.srs_wait_nodes)[i]; + + if (!atomic_cmpxchg_acquire(&sr_wn->inuse, 0, 1)) + return &sr_wn->node; + } + + return NULL; +} + +static void rcu_sr_put_wait_head(struct llist_node *node) +{ + struct sr_wait_node *sr_wn = container_of(node, struct sr_wait_node, node); + atomic_set_release(&sr_wn->inuse, 0); +} /* Disabled by default. */ static int rcu_normal_wake_from_gp; @@ -1462,14 +1596,44 @@ static void rcu_sr_normal_complete(struct llist_node *node) static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) { - struct llist_node *done, *rcu, *next; + struct llist_node *done, *rcu, *next, *head; - done = llist_del_all(&sr.srs_done); + /* + * This work execution can potentially execute + * while a new done tail is being updated by + * grace period kthread in rcu_sr_normal_gp_cleanup(). + * So, read and updates of done tail need to + * follow acq-rel semantics. + * + * Given that wq semantics guarantees that a single work + * cannot execute concurrently by multiple kworkers, + * the done tail list manipulations are protected here. + */ + done = smp_load_acquire(&rcu_state.srs_done_tail); if (!done) return; - llist_for_each_safe(rcu, next, done) - rcu_sr_normal_complete(rcu); + WARN_ON_ONCE(!rcu_sr_is_wait_head(done)); + head = done->next; + done->next = NULL; + + /* + * The dummy node, which is pointed to by the + * done tail which is acq-read above is not removed + * here. This allows lockless additions of new + * rcu_synchronize nodes in rcu_sr_normal_add_req(), + * while the cleanup work executes. The dummy + * nodes is removed, in next round of cleanup + * work execution. + */ + llist_for_each_safe(rcu, next, head) { + if (!rcu_sr_is_wait_head(rcu)) { + rcu_sr_normal_complete(rcu); + continue; + } + + rcu_sr_put_wait_head(rcu); + } } static DECLARE_WORK(sr_normal_gp_cleanup, rcu_sr_normal_gp_cleanup_work); @@ -1478,48 +1642,61 @@ static DECLARE_WORK(sr_normal_gp_cleanup, rcu_sr_normal_gp_cleanup_work); */ static void rcu_sr_normal_gp_cleanup(void) { - struct llist_node *head, *tail; + struct llist_node *wait_tail; - if (llist_empty(&sr.srs_wait)) + wait_tail = rcu_state.srs_wait_tail; + if (wait_tail == NULL) return; - tail = READ_ONCE(sr.srs_wait_tail); - head = __llist_del_all(&sr.srs_wait); + rcu_state.srs_wait_tail = NULL; + ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_wait_tail); - if (head) { - /* Can be not empty. */ - llist_add_batch(head, tail, &sr.srs_done); + // concurrent sr_normal_gp_cleanup work might observe this update. + smp_store_release(&rcu_state.srs_done_tail, wait_tail); + ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail); + + if (wait_tail) queue_work(system_highpri_wq, &sr_normal_gp_cleanup); - } } /* * Helper function for rcu_gp_init(). */ -static void rcu_sr_normal_gp_init(void) +static bool rcu_sr_normal_gp_init(void) { - struct llist_node *head, *tail; + struct llist_node *first; + struct llist_node *wait_head; + bool start_new_poll = false; - if (llist_empty(&sr.srs_next)) - return; + first = READ_ONCE(rcu_state.srs_next.first); + if (!first || rcu_sr_is_wait_head(first)) + return start_new_poll; + + wait_head = rcu_sr_get_wait_head(); + if (!wait_head) { + // Kick another GP to retry. + start_new_poll = true; + return start_new_poll; + } - tail = llist_del_all(&sr.srs_next); - head = llist_reverse_order(tail); + /* Inject a wait-dummy-node. */ + llist_add(wait_head, &rcu_state.srs_next); /* - * A waiting list of GP should be empty on this step, - * since a GP-kthread, rcu_gp_init() -> gp_cleanup(), + * A waiting list of rcu_synchronize nodes should be empty on + * this step, since a GP-kthread, rcu_gp_init() -> gp_cleanup(), * rolls it over. If not, it is a BUG, warn a user. */ - WARN_ON_ONCE(!llist_empty(&sr.srs_wait)); + WARN_ON_ONCE(rcu_state.srs_wait_tail != NULL); + rcu_state.srs_wait_tail = wait_head; + ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_wait_tail); - WRITE_ONCE(sr.srs_wait_tail, tail); - __llist_add_batch(head, tail, &sr.srs_wait); + return start_new_poll; } static void rcu_sr_normal_add_req(struct rcu_synchronize *rs) { - llist_add((struct llist_node *) &rs->head, &sr.srs_next); + llist_add((struct llist_node *) &rs->head, &rcu_state.srs_next); } /* @@ -1532,6 +1709,7 @@ static noinline_for_stack bool rcu_gp_init(void) unsigned long mask; struct rcu_data *rdp; struct rcu_node *rnp = rcu_get_root(); + bool start_new_poll; WRITE_ONCE(rcu_state.gp_activity, jiffies); raw_spin_lock_irq_rcu_node(rnp); @@ -1556,11 +1734,24 @@ static noinline_for_stack bool rcu_gp_init(void) /* Record GP times before starting GP, hence rcu_seq_start(). */ rcu_seq_start(&rcu_state.gp_seq); ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq); - rcu_sr_normal_gp_init(); + start_new_poll = rcu_sr_normal_gp_init(); trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("start")); rcu_poll_gp_seq_start(&rcu_state.gp_seq_polled_snap); raw_spin_unlock_irq_rcu_node(rnp); + /* + * The "start_new_poll" is set to true, only when this GP is not able + * to handle anything and there are outstanding users. It happens when + * the rcu_sr_normal_gp_init() function was not able to insert a dummy + * separator to the llist, because there were no left any dummy-nodes. + * + * Number of dummy-nodes is fixed, it could be that we are run out of + * them, if so we start a new pool request to repeat a try. It is rare + * and it means that a system is doing a slow processing of callbacks. + */ + if (start_new_poll) + (void) start_poll_synchronize_rcu(); + /* * Apply per-leaf buffered online and offline operations to * the rcu_node tree. Note that this new grace period need not diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index e9821a8422db..4c35d7d37647 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -316,6 +316,13 @@ do { \ __set_current_state(TASK_RUNNING); \ } while (0) +#define SR_NORMAL_GP_WAIT_HEAD_MAX 5 + +struct sr_wait_node { + atomic_t inuse; + struct llist_node node; +}; + /* * RCU global state, including node hierarchy. This hierarchy is * represented in "heap" form in a dense array. The root (first level) @@ -401,6 +408,12 @@ struct rcu_state { /* Synchronize offline with */ /* GP pre-initialization. */ int nocb_is_setup; /* nocb is setup from boot */ + + /* synchronize_rcu() part. */ + struct llist_head srs_next; /* request a GP users. */ + struct llist_node *srs_wait_tail; /* wait for GP users. */ + struct llist_node *srs_done_tail; /* ready for GP users. */ + struct sr_wait_node srs_wait_nodes[SR_NORMAL_GP_WAIT_HEAD_MAX]; }; /* Values for rcu_state structure's gp_flags field. */ From patchwork Thu Jan 4 16:25:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 185058 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5716457dyb; Thu, 4 Jan 2024 08:26:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAiaCR8iat5KcKW2cHwOgMrt9vvZn93EvE6BJWPIoZIVOVraxoTmNfRmGwbdIzM831fV33 X-Received: by 2002:ac8:5a91:0:b0:421:b13a:3af with SMTP id c17-20020ac85a91000000b00421b13a03afmr839802qtc.40.1704385604785; Thu, 04 Jan 2024 08:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385604; cv=none; d=google.com; s=arc-20160816; b=BwxQCfX1JIaW70rfjjEddejsS8bWd5B7C9UF+92marDXtQdCYg1OoPyLxVRwa+0jMy dOPTlpkPDQ9LWi/93VOZk0N6xKHoT4MdfiSve5EMmQYvuvHl1QzixnygD/hnP+8sGDZr bFBtE2aWO6wdXfjKG3AjNMIlczao8kh+Cov7ynmV5Vr16RIzi6jg9DNZLR1xvI6t02eY 9LIGZyaMz0mAcbJklQwRDsBtf5ubcejvIrVzn3Tv93w0o/2wb9Wm5Npp3B4J5V1zDVv8 +ulRJhExOw+NSDuOd8XhAtffLUyNwmIe0oCTuDnsbiPe/bqhnGdh9bVQkRQ985NujZOO c7hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ptdvZP3gB3Tmhzg2S9uP54DorDCDKViWWNLgg+oxUJQ=; fh=4iZcRCmzpaCZKgp7nvxh/m3AX3kfm//yPbGO/jIXleI=; b=IPJ68JOrLrzR1c+l+YUfVTlsu+j9RNsCbBV+3e8q42aXUv3DkAGx/AqMEk8oNU3BC2 ZIRobSXpBCahF1is9/FptX6eV+dmSJL6ynEAsH52KII2BFo2++F4WMaFqey0WSHqHOrz qHEXobntliKEn6qjVQsmlHF1H22qmQxhTo4CHjY6MqjPnjGjPLSjkRlbvDdXTdSPUPtS Sm35mSakeGHaZRVGz+1dy6jbk1gyLUu8VVglzomvtT4SDlCF9uF6q7VvSwDJqlBggd58 zXzXGg2C5FieOXuELUZjnT+3/gpxDLyUBiHo1qtTkxolOQUYwdgVRDHklXX+fsAZBwEB Qedg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BLgQR20n; spf=pass (google.com: domain of linux-kernel+bounces-16920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16920-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u20-20020a05622a011400b004281496315dsi11578501qtw.526.2024.01.04.08.26.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:26:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BLgQR20n; spf=pass (google.com: domain of linux-kernel+bounces-16920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16920-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7FE1B1C216A9 for ; Thu, 4 Jan 2024 16:26:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A67028DA2; Thu, 4 Jan 2024 16:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BLgQR20n" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F418250F2; Thu, 4 Jan 2024 16:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50eaa8b447bso747006e87.1; Thu, 04 Jan 2024 08:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704385517; x=1704990317; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ptdvZP3gB3Tmhzg2S9uP54DorDCDKViWWNLgg+oxUJQ=; b=BLgQR20nGKaLqBvls9aiIl50RDRq+NwTlGEwI8O2O6vpRWb/xjlHaF8y41Hz/H4h1c G8HuxtimpIvJTD8Q1IgGr2yamF1T6L+TKmbgf9Y+hKBytbX56i7gkWLzt2ikZLs5EJZQ 5gXdb4ckoCfSweaNcXmu+iTorj5gxyi5ivlzurerjF5VesGsrcWWYuaTLUa5bRgNWbZa s1FBF5Z4juEEoGIhO+gd8VFj3lAeihBkn9QXRFfKyLP2NXb8utJJTnrnj3rr+EVeXdJh 7fTN0SZnTo9yYSPsfu+hKMfbaZl0fmXL8KwSLtUY0qRvj8i+ufhEzWshFuVd0t9WoHMu xnsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704385517; x=1704990317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptdvZP3gB3Tmhzg2S9uP54DorDCDKViWWNLgg+oxUJQ=; b=cFXL/9aUTBeAEXdvb5Tb2i6Ick5uFwNMmYq1fRjEGATWg2LKhn7ZL/ZKQeVoxS6KTt NcD6lv+I8nu63a4VzHAXyGtoo03QBi1TXzNA7IbaxDfj+PCMqApPbbVrtQJPbkNEVVQL YG+/LFuCJAYvwIeAHO1y7a/BaOqSJDngib1lVYrGypPtZZ00FjVIM+bX6B4DOG7zXZ2k U2s6Y3Aswb2OSG/fPn1swd+zvkqYBAyvja3f2JfoQNfGk1/rwexDDy5SG+VJEYBHAZUF yOfTMtLjp93FvHnNHmj8GDn6z0t5KTlHL9mKakAQ30+aafsmCjHOND6vdgDKH8Fp3ncS l0fg== X-Gm-Message-State: AOJu0YztXmRpiDAIE+UYpAUkwBcPXHxkS1EwUU9Dpmw+/4m/BFFdfuZM p8o+FMyIUXxX3h1AbmgbRrY= X-Received: by 2002:ac2:5fad:0:b0:50e:6b54:6a61 with SMTP id s13-20020ac25fad000000b0050e6b546a61mr222086lfe.118.1704385516810; Thu, 04 Jan 2024 08:25:16 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id i5-20020a0565123e0500b0050e80d1e142sm2789252lfv.170.2024.01.04.08.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:25:16 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: "Paul E . McKenney" Cc: RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Uladzislau Rezki , Oleksiy Avramchenko , Frederic Weisbecker Subject: [PATCH v4 4/4] rcu: Support direct wake-up of synchronize_rcu() users Date: Thu, 4 Jan 2024 17:25:10 +0100 Message-Id: <20240104162510.72773-5-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240104162510.72773-1-urezki@gmail.com> References: <20240104162510.72773-1-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787177839879986662 X-GMAIL-MSGID: 1787177839879986662 This patch introduces a small enhancement which allows to do a direct wake-up of synchronize_rcu() callers. It occurs after a completion of grace period, thus by the gp-kthread. Number of clients is limited by the hard-coded maximum allowed threshold. The remaining part, if still exists is deferred to a main worker. Signed-off-by: Uladzislau Rezki (Sony) --- kernel/rcu/tree.c | 31 +++++++++++++++++++++++++++++-- kernel/rcu/tree.h | 6 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 88a47a6a658e..96fe9cc122ca 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1642,7 +1642,8 @@ static DECLARE_WORK(sr_normal_gp_cleanup, rcu_sr_normal_gp_cleanup_work); */ static void rcu_sr_normal_gp_cleanup(void) { - struct llist_node *wait_tail; + struct llist_node *wait_tail, *next, *rcu; + int done = 0; wait_tail = rcu_state.srs_wait_tail; if (wait_tail == NULL) @@ -1650,12 +1651,38 @@ static void rcu_sr_normal_gp_cleanup(void) rcu_state.srs_wait_tail = NULL; ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_wait_tail); + WARN_ON_ONCE(!rcu_sr_is_wait_head(wait_tail)); + + /* + * Process (a) and (d) cases. See an illustration. Apart of + * that it handles the scenario when all clients are done, + * wait-head is released if last. The worker is not kicked. + */ + llist_for_each_safe(rcu, next, wait_tail->next) { + if (rcu_sr_is_wait_head(rcu)) { + if (!rcu->next) { + rcu_sr_put_wait_head(rcu); + wait_tail->next = NULL; + } else { + wait_tail->next = rcu; + } + + break; + } + + rcu_sr_normal_complete(rcu); + // It can be last, update a next on this step. + wait_tail->next = next; + + if (++done == SR_MAX_USERS_WAKE_FROM_GP) + break; + } // concurrent sr_normal_gp_cleanup work might observe this update. smp_store_release(&rcu_state.srs_done_tail, wait_tail); ASSERT_EXCLUSIVE_WRITER(rcu_state.srs_done_tail); - if (wait_tail) + if (wait_tail->next) queue_work(system_highpri_wq, &sr_normal_gp_cleanup); } diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index 4c35d7d37647..5d8b71a1caec 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -316,6 +316,12 @@ do { \ __set_current_state(TASK_RUNNING); \ } while (0) +/* + * A max threshold for synchronize_rcu() users which are + * awaken directly by the rcu_gp_kthread(). Left part is + * deferred to the main worker. + */ +#define SR_MAX_USERS_WAKE_FROM_GP 5 #define SR_NORMAL_GP_WAIT_HEAD_MAX 5 struct sr_wait_node {