From mboxrd@z Thu Jan 1 00:00:00 1970 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 D1B7A375AD3; Tue, 3 Mar 2026 23:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772581839; cv=none; b=lIdLUKtigvBlQZGoRaugDWc2Vu18sSGVQAs92llJzoMjKsqFVFEh3i8+39/X/y3T78A7TmfpNWTbQknk463bkQ2q/y/xPaG0xT7XrA42hVbbcrdRVp8diurzhsQZ5ZnmjJJ9PsR12L2UIXKxWT9WfaXwEhx7BwOULjOSBylrH2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772581839; c=relaxed/simple; bh=UolUOkfqiM0WjO3JAkjDbdkps04/fjY11ex6OnmY59o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fritnCXEtKOiGKKMo7iGyZhoVRZ9D7WJd5DIjztVGXqHvGfrxxa8h8fdjfpGlD/F8F7gd4KLmBJzw0tt9XqMdYrgs0ypwZL4UM6Iduu4ogXFlPmkHCwmAYNyhPbHTP1qfMLAbrkRVl3YmfpIMRzawAFhh36L+/ZeQCJ1M+aKQwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g+Xq0Lmg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g+Xq0Lmg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0476C2BCB0; Tue, 3 Mar 2026 23:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772581839; bh=UolUOkfqiM0WjO3JAkjDbdkps04/fjY11ex6OnmY59o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+Xq0LmgqodyBcvWXatMM0zB09VVF0KV1PwIQy7aMQA106lB2w1XKnV9CBc8nwSU2 rsM/iPgJd2wkY+hGaDadtmPmfncXRuIw7ulh3+FZEZnABNRtCF8Fg3nXDKhomThFlr 66v/aOttZRFF11zb1QS7x3KnSQxq6aYOCVh6jmIQb4fQ7ohiThalJLJxu7IOtcU2Lc 7PpNWVMzVTRfTUsRP8vjHp0/QLwDukpVY6snKhZXb6WKVFjZI7M5It0pGmlYYLYgR+ zXBW2SenOhMZAzllYQIX6nApNL02E7enHSiJDD+hwcianFtQAmICF4HGO0N2mNMcFe 77v/peM6NB32w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F16DDCE0F1B; Tue, 3 Mar 2026 15:50:38 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Paul E. McKenney" Subject: [PATCH 07/11] refscale: Ditch ref_scale_shutdown in favor of torture_shutdown_init() Date: Tue, 3 Mar 2026 15:50:33 -0800 Message-Id: <20260303235037.1967017-7-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <50d2bb98-c912-4ba6-a723-4a4aed506fdf@paulmck-laptop> References: <50d2bb98-c912-4ba6-a723-4a4aed506fdf@paulmck-laptop> Precedence: bulk X-Mailing-List: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The torture_shutdown_init() function spawns a shutdown kthread in a manner very similar to that implemented by ref_scale_shutdown(). This commit therefore re-implements ref_scale_shutdown in terms of torture_shutdown_init(). The initial draft of this patch was generated by version 2.1.16 of the Claude AI/LLM, but trained and configured for use by my employer, and prompted to refer to Linux-kernel source code. This initial draft failed to provide a forward reference to ref_scale_cleanup(), passed zero to torture_shutdown_init() for an unwelcome insta-shutdown, and failed to pass the kvm.sh --duration argument in as a refscale module parameter. On the other hand, it did catch the need to NULL main_task on the post-test self-shutdown code path, which I might well have forgotten to do. This version of the patch fixes those problems, and in fact very little of the initial draft remains. Signed-off-by: Paul E. McKenney [outline more of development process] Signed-off-by: Paul E. McKenney --- kernel/rcu/refscale.c | 51 +++++-------------- .../configs/refscale/ver_functions.sh | 2 +- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index c158b6a947cde..a2d9d75d88a10 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -92,15 +92,9 @@ torture_param(int, nreaders, -1, "Number of readers, -1 for 75% of CPUs."); torture_param(int, nruns, 30, "Number of experiments to run."); // Reader delay in nanoseconds, 0 for no delay. torture_param(int, readdelay, 0, "Read-side delay in nanoseconds."); - -#ifdef MODULE -# define REFSCALE_SHUTDOWN 0 -#else -# define REFSCALE_SHUTDOWN 1 -#endif - -torture_param(bool, shutdown, REFSCALE_SHUTDOWN, - "Shutdown at end of scalability tests."); +// Maximum shutdown delay in seconds, or zero for no shutdown. +torture_param(int, shutdown_secs, !IS_MODULE(CONFIG_REPRO_TEST) * 300, + "Shutdown at end of scalability tests or at specified timeout (s)."); struct reader_task { struct task_struct *task; @@ -109,12 +103,8 @@ struct reader_task { u64 last_duration_ns; }; -static struct task_struct *shutdown_task; -static wait_queue_head_t shutdown_wq; - static struct task_struct *main_task; static wait_queue_head_t main_wq; -static int shutdown_start; static struct reader_task *reader_tasks; @@ -1357,6 +1347,8 @@ static u64 process_durations(int n) return sum; } +static void ref_scale_cleanup(void); + // The main_func is the main orchestrator, it performs a bunch of // experiments. For every experiment, it orders all the readers // involved to start and waits for them to finish the experiment. It @@ -1443,9 +1435,10 @@ static int main_func(void *arg) oom_exit: // This will shutdown everything including us. - if (shutdown) { - shutdown_start = 1; - wake_up(&shutdown_wq); + if (shutdown_secs) { + main_task = NULL; // Avoid self-kill deadlock. + ref_scale_cleanup(); + kernel_power_off(); } // Wait for torture to stop us @@ -1463,8 +1456,8 @@ static void ref_scale_print_module_parms(const struct ref_scale_ops *cur_ops, const char *tag) { pr_alert("%s" SCALE_FLAG - "--- %s: verbose=%d verbose_batched=%d shutdown=%d holdoff=%d lookup_instances=%ld loops=%d nreaders=%d nruns=%d readdelay=%d\n", scale_type, tag, - verbose, verbose_batched, shutdown, holdoff, lookup_instances, loops, nreaders, nruns, readdelay); + "--- %s: verbose=%d verbose_batched=%d shutdown_secs=%d holdoff=%d lookup_instances=%ld loops=%d nreaders=%d nruns=%d readdelay=%d\n", scale_type, tag, + verbose, verbose_batched, shutdown_secs, holdoff, lookup_instances, loops, nreaders, nruns, readdelay); } static void @@ -1497,19 +1490,6 @@ ref_scale_cleanup(void) torture_cleanup_end(); } -// Shutdown kthread. Just waits to be awakened, then shuts down system. -static int -ref_scale_shutdown(void *arg) -{ - wait_event_idle(shutdown_wq, shutdown_start); - - smp_mb(); // Wake before output. - ref_scale_cleanup(); - kernel_power_off(); - - return -EINVAL; -} - static int __init ref_scale_init(void) { @@ -1553,13 +1533,10 @@ ref_scale_init(void) ref_scale_print_module_parms(cur_ops, "Start of test"); // Shutdown task - if (shutdown) { - init_waitqueue_head(&shutdown_wq); - firsterr = torture_create_kthread(ref_scale_shutdown, NULL, - shutdown_task); + if (shutdown_secs) { + firsterr = torture_shutdown_init(shutdown_secs, ref_scale_cleanup); if (torture_init_error(firsterr)) goto unwind; - schedule_timeout_uninterruptible(1); } // Reader tasks (default to ~75% of online CPUs). @@ -1604,7 +1581,7 @@ ref_scale_init(void) unwind: torture_init_end(); ref_scale_cleanup(); - if (shutdown) { + if (shutdown_secs) { WARN_ON(!IS_MODULE(CONFIG_RCU_REF_SCALE_TEST)); kernel_power_off(); } diff --git a/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh b/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh index 7484656276012..219fac070af28 100644 --- a/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh +++ b/tools/testing/selftests/rcutorture/configs/refscale/ver_functions.sh @@ -11,7 +11,7 @@ # # Adds per-version torture-module parameters to kernels supporting them. per_version_boot_params () { - echo refscale.shutdown=1 \ + echo refscale.shutdown_secs=$3 \ refscale.verbose=0 \ $1 } -- 2.40.1