Linux cgroups development
 help / color / mirror / Atom feed
From: Peng Wang <peng_wang@linux.alibaba.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@kernel.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: Re: [RFC PATCH 2/2] cpu: Add sysfs control of full dynticks policy
Date: Sat, 17 Oct 2026 01:27:07 +0800	[thread overview]
Message-ID: <atJea4b6VvYlAvbD@MacBook-Pro.local> (raw)
In-Reply-To: <2026101646-speller-gutter-c184@gregkh>

On Fri, Oct 16, 2026 at 06:25:26PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Oct 15, 2026 at 08:43:09PM +0800, Peng Wang wrote:
> > Expose nohz_full_allowed under /sys/devices/system/cpu/ as the subset of
> > nohz_full CPUs permitted to suppress their non-idle scheduler tick.
> > 
> > Writes replace the entire list; reads report policy, not current tick
> > state. Reject invalid input before updating policy. Document asynchronous
> > revocation, offline CPU configuration and persistence across hotplug.
> > The existing nohz_full attribute continues to report membership.
> > 
> > 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      | 40 ++++++++++++++++
> >  drivers/base/cpu.c                            | 46 +++++++++++++++++++
> >  2 files changed, 86 insertions(+)
> > 
> > diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
> > index 82d10d556cc89..edf3408fd84c8 100644
> > --- a/Documentation/ABI/testing/sysfs-devices-system-cpu
> > +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
> > @@ -767,6 +767,46 @@ Description:	Preferred MTE tag checking mode
> >  
> >  		See also: Documentation/arch/arm64/memory-tagging-extension.rst
> >  
> > +What:		/sys/devices/system/cpu/nohz_full_allowed
> > +Date:		October 2026
> > +Contact:	Linux kernel mailing list <linux-kernel@vger.kernel.org>
> > +Description:
> > +		(RW) CPUs permitted to stop the scheduler tick while non-idle.
> > +		Available with CONFIG_NO_HZ_FULL. The default is the complete
> > +		nohz_full CPU list. Readback reports permission, not the current
> > +		tick state: all the usual tick dependencies still apply.
> > +
> > +		A write replaces the entire list, using CPU-list syntax (for
> > +		example, "1-3,5"). An empty line revokes permission from all
> > +		nohz_full CPUs. Invalid input is rejected without changing
> > +		policy. A parsed list containing CPUs outside nohz_full fails
> > +		with EINVAL. CPU numbers beyond the mask range and numeric
> > +		overflows are rejected by the CPU-list parser with ERANGE and
> > +		EOVERFLOW, respectively. Input must be shorter than PAGE_SIZE
> > +		bytes, otherwise E2BIG is returned. Embedded NULs and newlines
> > +		other than a trailing newline are rejected with EINVAL. Valid
> > +		writes without an active nohz_full configuration fail with
> > +		EOPNOTSUPP.
> > +
> > +		Reads fail with EOVERFLOW if the formatted output reaches
> > +		PAGE_SIZE - 1 bytes, rather than returning a potentially
> > +		truncated CPU list.
> > +
> > +		Revoking permission adds a per-CPU tick dependency. Online CPUs
> > +		are notified through the existing asynchronous kick mechanism
> > +		to restart a stopped non-idle tick. A successful write means
> > +		the policy is updated and any needed notification is queued;
> > +		it does not wait for tick restart. Changes to multiple CPUs
> > +		are not simultaneous. Granting permission only removes this
> > +		dependency and does not force the tick to stop.
> > +
> > +		Offline CPUs may be configured without sending notifications.
> > +		Policy persists across CPU offline/online. Idle tick suppression
> > +		is unchanged; the policy applies when a CPU leaves idle.
> > +
> > +		This interface 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..299ce61cef895 100644
> > --- a/drivers/base/cpu.c
> > +++ b/drivers/base/cpu.c
> > @@ -324,6 +324,51 @@ static ssize_t nohz_full_show(struct device *dev,
> >  	return sysfs_emit(buf, "\n");
> >  }
> >  static DEVICE_ATTR_RO(nohz_full);
> > +
> > +static ssize_t nohz_full_allowed_show(struct device *dev,
> > +				      struct device_attribute *attr, char *buf)
> > +{
> > +	cpumask_var_t mask;
> > +	ssize_t ret;
> > +
> > +	if (!alloc_cpumask_var(&mask, GFP_KERNEL))
> > +		return -ENOMEM;
> > +
> > +	tick_nohz_full_get_allowed(mask);
> > +	ret = sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(mask));
> > +
> > +	free_cpumask_var(mask);
> > +
> > +	/* Never present a truncated CPU list as the complete policy. */
> > +	return ret == PAGE_SIZE - 1 ? -EOVERFLOW : ret;
> 
> Why not?  What will userspace do then if it gets -EOVERFLOW as it can
> not get the full list?

Hi Greg,

There is no way to retrieve the full list through this attribute.
The intent was to avoid returning a truncated list that userspace
could write back, unintentionally revoking permission for the omitted
CPUs. Returning an error does not solve that interface limitation.

> 
> > +}
> > +
> > +static ssize_t nohz_full_allowed_store(struct device *dev,
> > +				       struct device_attribute *attr,
> > +				       const char *buf, size_t count)
> > +{
> > +	cpumask_var_t mask;
> > +	int ret;
> > +
> > +	/* kernfs may truncate an oversized write to PAGE_SIZE. */
> > +	if (count >= PAGE_SIZE)
> > +		return -E2BIG;
> 
> How are you getting a larger than PAGE_SIZE value here?

I cannot; kernfs caps count at PAGE_SIZE. The check is intended for
count == PAGE_SIZE, to avoid applying a potentially truncated prefix
as a complete list. It also rejects an exactly page-sized input.

> 
> > +	if (memchr(buf, '\0', count) ||
> > +	    (count > 1 && memchr(buf, '\n', count - 1)))
> > +		return -EINVAL;
> 
> What are you testing for here, sorry, I can't easily figure it out.

The checks reject user-supplied NULs and non-final newlines.
For example, cpulist_parse() accepts "1\n2\n" as CPU 1 only, while
store() would report the full input as consumed. The NUL appended
by kernfs is at buf[count], outside the checked range.

I propose replacing the global attribute with
/sys/devices/system/cpu/cpuN/nohz_tick_allowed, available only on
nohz_full CPUs. Writing 0 would prevent non-idle tick suppression,
using the existing asynchronous kick when needed. Writing 1 would
allow suppression, subject to the existing tick dependencies.
Readback would report policy, not the current tick state.

Each write would affect only that CPU, without changing nohz_full
membership or other isolation settings. This would give up the
single-write whole-list replacement. Would that be a better fit?

Thanks,
Peng

> 
> thanks,
> 
> greg k-h

  reply	other threads:[~2026-10-16 17:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 12:43 [RFC PATCH 0/2] tick/nohz: Add runtime control of non-idle tick suppression Peng Wang
2026-10-15 12:43 ` [RFC PATCH 1/2] tick/nohz: Add a policy dependency for full dynticks Peng Wang
2026-10-15 12:43 ` [RFC PATCH 2/2] cpu: Add sysfs control of full dynticks policy Peng Wang
2026-10-15 16:07   ` Waiman Long
2026-10-15 17:50     ` Peng Wang
2026-10-16 16:25   ` Greg Kroah-Hartman
2026-10-16 17:27     ` Peng Wang [this message]
2026-10-15 16:00 ` [RFC PATCH 0/2] tick/nohz: Add runtime control of non-idle tick suppression Waiman Long
2026-10-15 17:48   ` Peng Wang
2026-10-15 20:13     ` Waiman Long
2026-10-16  2:33       ` Peng Wang

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=atJea4b6VvYlAvbD@MacBook-Pro.local \
    --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