[RFC v2 8/9] sysfs: Add cpu_avoid file

Shrikanth Hegde posted 9 patches 7 months, 2 weeks ago
[RFC v2 8/9] sysfs: Add cpu_avoid file
Posted by Shrikanth Hegde 7 months, 2 weeks ago
Add a sysfs file called "avoid" which prints the current CPUs 
makred as avoid. 

This could be used by userspace components or tools such as irqbalance. 

/sys/devices/system/cpu # cat avoid 
70-479

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 drivers/base/cpu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 7779ab0ca7ce..51c1207f6f33 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -300,6 +300,13 @@ static ssize_t print_cpus_isolated(struct device *dev,
 }
 static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);
 
+static ssize_t print_cpus_avoid(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_avoid_mask));
+}
+static DEVICE_ATTR(avoid, 0444, print_cpus_avoid, NULL);
+
 #ifdef CONFIG_NO_HZ_FULL
 static ssize_t print_cpus_nohz_full(struct device *dev,
 				    struct device_attribute *attr, char *buf)
@@ -505,6 +512,7 @@ static struct attribute *cpu_root_attrs[] = {
 	&dev_attr_offline.attr,
 	&dev_attr_enabled.attr,
 	&dev_attr_isolated.attr,
+	&dev_attr_avoid.attr,
 #ifdef CONFIG_NO_HZ_FULL
 	&dev_attr_nohz_full.attr,
 #endif
-- 
2.43.0
Re: [RFC v2 8/9] sysfs: Add cpu_avoid file
Posted by Greg KH 7 months, 1 week ago
On Thu, Jun 26, 2025 at 12:41:07AM +0530, Shrikanth Hegde wrote:
> Add a sysfs file called "avoid" which prints the current CPUs 
> makred as avoid. 
> 
> This could be used by userspace components or tools such as irqbalance. 
> 
> /sys/devices/system/cpu # cat avoid 
> 70-479

You forgot to document the new sysfs file in Documentation/ABI/ :(

Also, you have trailing whitespace in your changelog here, was that
intentional?

thanks,

greg k-h
Re: [RFC v2 8/9] sysfs: Add cpu_avoid file
Posted by Shrikanth Hegde 7 months, 1 week ago

Hi Greg, Thanks for looking into the patches.

> On Thu, Jun 26, 2025 at 12:41:07AM +0530, Shrikanth Hegde wrote:
>> Add a sysfs file called "avoid" which prints the current CPUs
>> makred as avoid.
>>
>> This could be used by userspace components or tools such as irqbalance.
>>
>> /sys/devices/system/cpu # cat avoid
>> 70-479
> 
> You forgot to document the new sysfs file in Documentation/ABI/ :( 

Sorry, didn't realize that. Will fix it in v2.

> 
> Also, you have trailing whitespace in your changelog here, was that
> intentional?
> 

My bad, didn't realize it while editing. Will fix it too.


Also checkpatch --strict doesn't complain if there is a trailing whitespace
in changelog.

> thanks,
> 
> greg k-h