From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 47509361641 for ; Fri, 10 Jul 2026 03:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783654169; cv=none; b=QuhClYhSNU4nCdEXod4SDWJuEiCVO0EnAk4eFbpvRncQZ2OjQr28WY4tYa+sRF/+WZCBQbLfNjzcJvy5UnMC5crApYRgDESERrfH6HJW9KHZ5w0Ba6G+zXP3RSgillBX8JhtCRbr9r9+ZaT+Dw68+i3urrpyIfwzR1gPwl/Ob7I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783654169; c=relaxed/simple; bh=Gwt0vIVRdUfUurXNz0U9um8/c6hFVw+sQjNLaLm168U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qQ7xR6ip1SJMJa0B+G1pZiEQQyENoPFv/4yws5tGyzRdmv6Pa3fqsix3gVAr3lACg3p/uL3oZI1qTEdXdLlR/n6wa0Q7OjUES5aFH7K4KtoEQvdFYtdpym2HapTEpXI6A6+tICZ218lH5RRzkgTas9OOKugBmlPbJhkHpBt2B68= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jfRS0gus; arc=none smtp.client-ip=209.85.214.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jfRS0gus" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2cc61541f8cso21629805ad.0 for ; Thu, 09 Jul 2026 20:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783654168; x=1784258968; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6HyVQ93m8I4DnhXDv5rSatBwFHcjRnR8kBcgkmMTv+c=; b=jfRS0gusrHnEQMRd1dhgGrBgdfHybLeQ9ECOlV9GUjmEr3cT0oYfIiX3gea9Wmf2Uy U7pHaSzygXfxwMA6JX/+Mp2DF3Yat95RQu4rTarDlE0EK1twr6zceJfVlxYP0uTJ3BkS SiHdPXVaYYEiNN4bMvZVAie3epJWEdtHrUeQyOQBhS1VAn2dYrKlniXvb92s62idar3y NaUCEvTYX4Exl0JQ0NMe8FyrHge9eGJ97kfDoHmbQf4Vxe7wzgs0O69fEqwSVDXtzwYx c0/2doFPj7ukUyNyPBYqzLiamn4Qi37xwr1FRlVN+SE6QEfeei6IP2wcvIqmVYFSIti8 hXZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783654168; x=1784258968; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6HyVQ93m8I4DnhXDv5rSatBwFHcjRnR8kBcgkmMTv+c=; b=oRdwOaU3Ry+SBPrlM/OzE49Dr1KEnGkFBPKypEYxCAIFK7bbEGWHmR0nc14QGkuPJW cjZUcgVye7IM2LWoeX+wnVafYCQvWclqkEoNKgIIuUN+hp9UgHRVf5Jv+z6d6c/ieGGy vAJMaKU9JYIXyerq9an86Zb5MOD290iVWim64wYjgkOa9MhgL3B5p2x1cbkztmdcz0Ni J9dJ7eOPH4ut1rucgDI+Wp2o9FwIuUFpDMoVKP69QG2rOeN50m5s/ykfJdiRFM377xB6 daDCgWThzIr6WjIBD6czm4BT7nEd4wXKwNazZDMgQBFzb1AIxe0eIEBDVcV7jjeFfDpi Dl9g== X-Forwarded-Encrypted: i=1; AHgh+Rrz6HY8ZqXgzrMRSZwW1UVoYPNik0WTEmnZEefIcRjeppEkCbc55+VwciOxysADePA+eOBoKeRKh2S5nVdr6rY=@vger.kernel.org X-Gm-Message-State: AOJu0YxL3cvbrnrrGqPNlctZgr362LwfcOhY6MrDO1A6ifKBjZL1KonS sNybKR7JG4xAjQI/uyTH99uewCmYB9Va0J3cAiEUmlfOEUd7f9ZEk/dA X-Gm-Gg: AfdE7cmIFmOo0kHWZK1zgK7d3UqSSUpZUE1laWcgnXhu7RL8N0C+D1ISEFLEj1MHobK 2ybcu6pnfj+PswI8SkZtgLM4Nox25/m6uQSJHxRNG4qav/9f0GIkjB8X3Zj/u1KQXnAvoEd1MEF lo+tJ4migLvkCaY2pM/6genJASZbICeVa6RLnUDVQaqdiAVSRsNhOVSyVCcRvEZodE2thGScdc4 jE3GRotofyKA8ijVX+nhpZLT2AXkJwUjUvmzxxA1uUkXI3Gs+EhUusg+xt0PlUqOnuEcnAzRc1a 3mp3nW6EapfvfMN5qKwuPRlsFiAjPW4a7sKocnnxSlrN9/2SqbCpD0GXEj/iofol4Nw4bG6ZYFm IsDOS/y8Hdvnvm2a25e+CX6AX0nAe+X074fs6Xj5bSHT8zQcDjwyKLnr3fkxSXjhzAK/4zPCJQF r5iiSvl+fhmro= X-Received: by 2002:a17:902:d98b:b0:2c6:8d95:fd7e with SMTP id d9443c01a7336-2ce8285abefmr20003265ad.6.1783654167651; Thu, 09 Jul 2026 20:29:27 -0700 (PDT) Received: from [127.0.1.1] ([138.199.21.246]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9bdb56fsm53436465ad.15.2026.07.09.20.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 20:29:27 -0700 (PDT) From: Jing Wu Date: Fri, 10 Jul 2026 11:28:18 +0800 Subject: [PATCH v4 07/11] tick/nohz: add runtime tick_nohz_full_mask update for CPU isolation Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260710-wujing-dhm-v4-7-2e912e5d9645@gmail.com> References: <20260710-wujing-dhm-v4-0-2e912e5d9645@gmail.com> In-Reply-To: <20260710-wujing-dhm-v4-0-2e912e5d9645@gmail.com> To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Uladzislau Rezki , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Anna-Maria Behnsen , Tejun Heo , Jonathan Corbet , Shuah Khan , Shuah Khan , Thomas Gleixner Cc: Waiman Long , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Jing Wu , Qiliang Yuan X-Mailer: b4 0.13.0 When kernel-noise isolation is requested for a CPU at runtime via a cpuset isolated partition, tick suppression must be activated on the affected CPU without requiring nohz_full= at boot. tick_nohz_full_mask and tick_nohz_full_running are currently set only during boot by tick_nohz_full_setup(). There is no runtime path to add or remove CPUs from the full-dynticks set. Add tick_nohz_cpu_isolate() and tick_nohz_cpu_deisolate(), both called with the target CPU offline (between remove_cpu and add_cpu in the hotplug cycling path): tick_nohz_cpu_isolate(cpu) - lazily allocates tick_nohz_full_mask if it was never set up at boot, sets the CPU's bit in the mask, sets tick_nohz_full_running, and calls ct_cpu_track_user() to activate per-CPU context tracking so kernel/user transitions suppress the scheduler tick. tick_nohz_cpu_deisolate(cpu) - reverses the above: deactivates context tracking via ct_cpu_untrack_user(), clears the CPU's bit, and clears tick_nohz_full_running when the mask becomes empty. A per-function mutex guards the lazy allocation and running flag updates against concurrent isolation requests. Co-developed-by: Qiliang Yuan Signed-off-by: Qiliang Yuan Signed-off-by: Jing Wu --- include/linux/tick.h | 4 ++++ kernel/time/tick-sched.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/tick.h b/include/linux/tick.h index 738007d6f577f..c4038e62533ba 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -210,6 +210,8 @@ extern void tick_nohz_dep_set_signal(struct task_struct *tsk, extern void tick_nohz_dep_clear_signal(struct signal_struct *signal, enum tick_dep_bits bit); extern bool tick_nohz_cpu_hotpluggable(unsigned int cpu); +extern int tick_nohz_cpu_isolate(int cpu); +extern void tick_nohz_cpu_deisolate(int cpu); /* * The below are tick_nohz_[set,clear]_dep() wrappers that optimize off-cases @@ -281,6 +283,8 @@ static inline bool tick_nohz_full_cpu(int cpu) { return false; } static inline void tick_nohz_dep_set_cpu(int cpu, enum tick_dep_bits bit) { } static inline void tick_nohz_dep_clear_cpu(int cpu, enum tick_dep_bits bit) { } static inline bool tick_nohz_cpu_hotpluggable(unsigned int cpu) { return true; } +static inline int tick_nohz_cpu_isolate(int cpu) { return -EINVAL; } +static inline void tick_nohz_cpu_deisolate(int cpu) { } static inline void tick_dep_set(enum tick_dep_bits bit) { } static inline void tick_dep_clear(enum tick_dep_bits bit) { } diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index ba7adc671c580..1bc01e2ab525b 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -621,6 +621,51 @@ void __tick_nohz_task_switch(void) } } +static DEFINE_MUTEX(tick_nohz_cpu_isolate_mutex); + +/* + * tick_nohz_cpu_isolate - Add a CPU to the full-dynticks set at runtime. + * @cpu: the CPU to isolate; must be offline. + * + * Lazily allocates tick_nohz_full_mask on the first call so that no + * nohz_full= boot parameter is required. Activates per-CPU context + * tracking so that kernel/user transitions suppress the scheduler tick. + */ +int tick_nohz_cpu_isolate(int cpu) +{ + mutex_lock(&tick_nohz_cpu_isolate_mutex); + if (!cpumask_available(tick_nohz_full_mask)) { + if (!zalloc_cpumask_var(&tick_nohz_full_mask, GFP_KERNEL)) { + mutex_unlock(&tick_nohz_cpu_isolate_mutex); + return -ENOMEM; + } + } + cpumask_set_cpu(cpu, tick_nohz_full_mask); + if (!tick_nohz_full_running) + tick_nohz_full_running = true; + mutex_unlock(&tick_nohz_cpu_isolate_mutex); + + ct_cpu_track_user(cpu); + return 0; +} +EXPORT_SYMBOL_GPL(tick_nohz_cpu_isolate); + +/* + * tick_nohz_cpu_deisolate - Remove a CPU from the full-dynticks set. + * @cpu: the CPU to de-isolate; must be offline. + */ +void tick_nohz_cpu_deisolate(int cpu) +{ + ct_cpu_untrack_user(cpu); + + mutex_lock(&tick_nohz_cpu_isolate_mutex); + cpumask_clear_cpu(cpu, tick_nohz_full_mask); + if (cpumask_empty(tick_nohz_full_mask)) + tick_nohz_full_running = false; + mutex_unlock(&tick_nohz_cpu_isolate_mutex); +} +EXPORT_SYMBOL_GPL(tick_nohz_cpu_deisolate); + /* Get the boot-time nohz CPU list from the kernel parameters. */ void __init tick_nohz_full_setup(cpumask_var_t cpumask) { -- 2.43.0