* [PATCH v3 0/2] tick/nohz: avoid showing '(null)' if nohz_full= not set
@ 2025-10-11 1:18 Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 1/2] sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 2/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
0 siblings, 2 replies; 3+ messages in thread
From: Aaron Tomlin @ 2025-10-11 1:18 UTC (permalink / raw)
To: gregkh, nathan, rafael, dakr; +Cc: riel, frederic, atomlin, linux-kernel
Hi Nathan, Greg,
Thank you for your feedback so far.
Changes since v2 [1]
- Removed unnecessary else statement (Nathan Chancellor)
- Used cpumask_available() instead (Nathan Chancellor)
- Used DEVICE_ATTR_RO for nohz_full attribute
Changes since v1 [2]
- Refactor to use an if statement (Greg KH)
[1]: https://lore.kernel.org/lkml/20251007012504.16118-2-atomlin@atomlin.com/
[2]: https://lore.kernel.org/lkml/20251007012504.16118-1-atomlin@atomlin.com/
Aaron Tomlin (2):
sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute
tick/nohz: avoid showing '(null)' if nohz_full= not set
drivers/base/cpu.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/2] sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute
2025-10-11 1:18 [PATCH v3 0/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
@ 2025-10-11 1:18 ` Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 2/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
1 sibling, 0 replies; 3+ messages in thread
From: Aaron Tomlin @ 2025-10-11 1:18 UTC (permalink / raw)
To: gregkh, nathan, rafael, dakr; +Cc: riel, frederic, atomlin, linux-kernel
The /sys/devices/system/cpu/nohz_full file is a read-only attribute that
reports the CPUs configured for tickless operation (CONFIG_NO_HZ_FULL=y).
The current definition uses the generic DEVICE_ATTR macro, which
unnecessarily requires specifying the file mode (0444) and a NULL
store operation pointer.
This patch converts the definition to use the dedicated DEVICE_ATTR_RO
macro. This correctly expresses the read-only nature of the attribute,
removes the redundant mode field, and simplifies the code. As a related
cleanup, rename the show function from print_cpus_nohz_full() to the
standard nohz_full_show() for consistency with common sysfs attribute
naming conventions.
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
drivers/base/cpu.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index fa0a2eef93ac..c792ec66462d 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -301,12 +301,13 @@ static ssize_t print_cpus_isolated(struct device *dev,
static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
#ifdef CONFIG_NO_HZ_FULL
-static ssize_t print_cpus_nohz_full(struct device *dev,
- struct device_attribute *attr, char *buf)
+static ssize_t nohz_full_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
{
return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
}
-static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
+static DEVICE_ATTR_RO(nohz_full);
#endif
#ifdef CONFIG_CRASH_HOTPLUG
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 2/2] tick/nohz: avoid showing '(null)' if nohz_full= not set
2025-10-11 1:18 [PATCH v3 0/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 1/2] sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute Aaron Tomlin
@ 2025-10-11 1:18 ` Aaron Tomlin
1 sibling, 0 replies; 3+ messages in thread
From: Aaron Tomlin @ 2025-10-11 1:18 UTC (permalink / raw)
To: gregkh, nathan, rafael, dakr; +Cc: riel, frederic, atomlin, linux-kernel
In the context of CONFIG_NO_HZ_FULL=y, tick_nohz_full_mask (of type
cpumask_var_t) is initialised to 0. Memory is only allocated to the cpumask
data structure, in tick_nohz_full_setup(), when Linux kernel boot-time
parameter "nohz_full=" is correctly specified (see housekeeping_setup()).
If "nohz_full=" is not set and an attempt is made to read
/sys/devices/system/cpu/nohz_full, '(null)' can be displayed:
❯ cat /sys/devices/system/cpu/nohz_full
(null)
This patch changes the output to print a newline (or 0x0A) instead of
'(null)', making it consistent with print_cpus_isolated() behaviour.
Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
drivers/base/cpu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index c792ec66462d..e3cb47eae982 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -305,7 +305,10 @@ static ssize_t nohz_full_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
- return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(tick_nohz_full_mask));
+ if (cpumask_available(tick_nohz_full_mask))
+ return sysfs_emit(buf, "%*pbl\n",
+ cpumask_pr_args(tick_nohz_full_mask));
+ return sysfs_emit(buf, "\n");
}
static DEVICE_ATTR_RO(nohz_full);
#endif
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-11 1:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-11 1:18 [PATCH v3 0/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 1/2] sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute Aaron Tomlin
2025-10-11 1:18 ` [PATCH v3 2/2] tick/nohz: avoid showing '(null)' if nohz_full= not set Aaron Tomlin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox