tick/nohz: avoid showing '(null)' if nohz_full= not set
v3 cover tick/nohz: avoid showing '(null)' if nohz_full= not set
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/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
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(-)
Signature · 1 line
2.49.0
PATCH v3 1/2 sysfs/cpu: Use DEVICE_ATTR_RO for nohz_full attribute
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.
--- drivers/base/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/base/cpu.c +4 -3
@@ -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
Signature · 1 line
2.49.0
PATCH v3 2/2 tick/nohz: avoid showing '(null)' if nohz_full= not set
In reply to Aaron TomlinIn 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.
--- drivers/base/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/base/cpu.c +4 -1
@@ -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
Signature · 1 line
2.49.0