driver core: platform: expose numa_node to users in sysfs
authorBarry Song <song.bao.hua@hisilicon.com>
Fri, 19 Jun 2020 03:00:45 +0000 (15:00 +1200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jul 2020 12:14:37 +0000 (14:14 +0200)
Some platform devices like ARM SMMU are memory-mapped and populated by ACPI/IORT.
In this case, NUMA topology of those platform devices are exported by firmware as
well. Software might care about the numa_node of those devices in order to achieve
NUMA locality.
This patch will show the numa_node for this kind of devices in sysfs. For those
platform devices without numa, numa_node won't be visible.

Cc: Prime Zeng <prime.zeng@hisilicon.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
Link: https://lore.kernel.org/r/20200619030045.81956-1-song.bao.hua@hisilicon.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/ABI/testing/sysfs-bus-platform
drivers/base/platform.c

index 5172a6124b27f8c1e406a610c794611ee5998a90..194ca700e96297823ecb74db46b621e4636c42a4 100644 (file)
@@ -18,3 +18,13 @@ Description:
                devices to opt-out of driver binding using a driver_override
                name such as "none".  Only a single driver may be specified in
                the override, there is no support for parsing delimiters.
+
+What:          /sys/bus/platform/devices/.../numa_node
+Date:          June 2020
+Contact:       Barry Song <song.bao.hua@hisilicon.com>
+Description:
+               This file contains the NUMA node to which the platform device
+               is attached. It won't be visible if the node is unknown. The
+               value comes from an ACPI _PXM method or a similar firmware
+               source. Initial users for this file would be devices like
+               arm smmu which are populated by arm64 acpi_iort.
index 3273a2fad4ad9103eeee319b00fa71f78a4f9c8d..e5d8a0503b4f796fb455a0e58db2750ce865b3c8 100644 (file)
@@ -1076,13 +1076,37 @@ static ssize_t driver_override_show(struct device *dev,
 }
 static DEVICE_ATTR_RW(driver_override);
 
+static ssize_t numa_node_show(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", dev_to_node(dev));
+}
+static DEVICE_ATTR_RO(numa_node);
+
+static umode_t platform_dev_attrs_visible(struct kobject *kobj, struct attribute *a,
+               int n)
+{
+       struct device *dev = container_of(kobj, typeof(*dev), kobj);
+
+       if (a == &dev_attr_numa_node.attr &&
+                       dev_to_node(dev) == NUMA_NO_NODE)
+               return 0;
+
+       return a->mode;
+}
 
 static struct attribute *platform_dev_attrs[] = {
        &dev_attr_modalias.attr,
+       &dev_attr_numa_node.attr,
        &dev_attr_driver_override.attr,
        NULL,
 };
-ATTRIBUTE_GROUPS(platform_dev);
+
+static struct attribute_group platform_dev_group = {
+       .attrs = platform_dev_attrs,
+       .is_visible = platform_dev_attrs_visible,
+};
+__ATTRIBUTE_GROUPS(platform_dev);
 
 static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
 {