mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peng Wang <peng_wang@linux.alibaba.com>
To: Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@kernel.org>
Cc: Peng Wang <peng_wang@linux.alibaba.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Waiman Long <longman@redhat.com>, Tejun Heo <tj@kernel.org>,
	He Rongguang <herongguang@linux.alibaba.com>,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	driver-core@lists.linux.dev, linux-trace-kernel@vger.kernel.org,
	cgroups@vger.kernel.org
Subject: [RFC PATCH v2 2/2] cpu: Add per-CPU control of non-idle tick suppression
Date: Sat, 17 Oct 2026 21:13:42 +0800	[thread overview]
Message-ID: <224314ef5ad5c3c7634f73efad433616eb1d68ca.1792242566.git.peng_wang@linux.alibaba.com> (raw)
In-Reply-To: <cover.1792242566.git.peng_wang@linux.alibaba.com>

Expose cpuN/nohz_tick_allowed on CPUs in the boot-time nohz_full set.
The boolean defaults to 1: allow non-idle tick suppression, subject to
existing dependencies. Writing 0 prevents suppression through POLICY.
Readback reports permission, not the current tick state.

Each write affects only that CPU. Registered offline CPUs remain
configurable, and policy persists across offline/online transitions.
Retry writes when CPU hotplug is in progress so CPU device removal
can drain active sysfs callbacks without a lock dependency cycle.

Co-developed-by: He Rongguang <herongguang@linux.alibaba.com>
Signed-off-by: He Rongguang <herongguang@linux.alibaba.com>
Signed-off-by: Peng Wang <peng_wang@linux.alibaba.com>
---
 .../ABI/testing/sysfs-devices-system-cpu      | 27 ++++++++++
 drivers/base/cpu.c                            | 53 +++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index 82d10d556cc89..4f6ac6b41e2b6 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -767,6 +767,33 @@ Description:	Preferred MTE tag checking mode
 
 		See also: Documentation/arch/arm64/memory-tagging-extension.rst
 
+What:		/sys/devices/system/cpu/cpuX/nohz_tick_allowed
+Date:		October 2026
+Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
+Description:
+		(RW) Boolean allowing this CPU to stop its non-idle scheduler
+		tick. Present only for registered CPUs in the boot-time
+		nohz_full set, with CONFIG_NO_HZ_FULL.
+
+		The default is 1 (allowed), subject to existing tick
+		dependencies. Writing 0 prevents non-idle tick suppression;
+		writing 1 allows it without forcing the tick to stop. Each
+		write affects one CPU. Readback reports permission, not the
+		current tick state.
+
+		Revoking permission requests an asynchronous restart of a
+		stopped non-idle tick on an online CPU. The write does not wait
+		for restart. Idle tick suppression is unchanged; the policy
+		applies when the CPU leaves idle.
+
+		Registered offline CPUs may be configured. Policy is retained
+		per logical CPU across offline/online and CPU device removal
+		and re-addition. CPUs without a registered cpuN device cannot
+		be configured through this interface.
+
+		This does not change nohz_full membership, context tracking,
+		RCU offloading or housekeeping configuration.
+
 What:		/sys/devices/system/cpu/nohz_full
 Date:		Apr 2015
 Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 69e52fed42415..6fad1b0227dac 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -7,6 +7,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/sched.h>
+#include <linux/sched/signal.h>
 #include <linux/cpu.h>
 #include <linux/topology.h>
 #include <linux/device.h>
@@ -189,7 +190,56 @@ static const struct attribute_group crash_note_cpu_attr_group = {
 };
 #endif
 
+#ifdef CONFIG_NO_HZ_FULL
+static ssize_t nohz_tick_allowed_show(struct device *dev,
+				     struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%u\n", tick_nohz_full_get_allowed(dev->id));
+}
+
+static ssize_t nohz_tick_allowed_store(struct device *dev,
+				      struct device_attribute *attr,
+				      const char *buf, size_t count)
+{
+	bool allowed;
+	int ret;
+
+	ret = kstrtobool(buf, &allowed);
+	if (ret)
+		return ret;
+
+	ret = tick_nohz_full_set_allowed(dev->id, allowed);
+	if (ret == -EBUSY) {
+		/* Retry after releasing the sysfs active reference. */
+		fsleep(5000);
+		return restart_syscall();
+	}
+
+	return ret ? ret : count;
+}
+static DEVICE_ATTR_RW(nohz_tick_allowed);
+
+static umode_t nohz_tick_is_visible(struct kobject *kobj,
+				   struct attribute *attr, int unused)
+{
+	return tick_nohz_full_cpu(kobj_to_dev(kobj)->id) ? attr->mode : 0;
+}
+
+static struct attribute *nohz_tick_cpu_attrs[] = {
+	&dev_attr_nohz_tick_allowed.attr,
+	NULL
+};
+
+static const struct attribute_group nohz_tick_cpu_attr_group = {
+	.attrs = nohz_tick_cpu_attrs,
+	.is_visible = nohz_tick_is_visible,
+};
+#endif
+
 static const struct attribute_group *common_cpu_attr_groups[] = {
+#ifdef CONFIG_NO_HZ_FULL
+	&nohz_tick_cpu_attr_group,
+#endif
 #ifdef CONFIG_CRASH_DUMP
 	&crash_note_cpu_attr_group,
 #endif
@@ -197,6 +247,9 @@ static const struct attribute_group *common_cpu_attr_groups[] = {
 };
 
 static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
+#ifdef CONFIG_NO_HZ_FULL
+	&nohz_tick_cpu_attr_group,
+#endif
 #ifdef CONFIG_CRASH_DUMP
 	&crash_note_cpu_attr_group,
 #endif
-- 
2.47.0


      parent reply	other threads:[~2026-10-17 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 13:13 [RFC PATCH v2 0/2] tick/nohz: " Peng Wang
2026-10-17 13:13 ` [RFC PATCH v2 1/2] tick/nohz: Add a policy dependency for full dynticks Peng Wang
2026-10-17 13:13 ` Peng Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=224314ef5ad5c3c7634f73efad433616eb1d68ca.1792242566.git.peng_wang@linux.alibaba.com \
    --to=peng_wang@linux.alibaba.com \
    --cc=anna-maria@linutronix.de \
    --cc=cgroups@vger.kernel.org \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=frederic@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=herongguang@linux.alibaba.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®