[PATCH 1/2] virtio: introduce virtio_dev_to_node helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also expose numa_node field as a sysfs attribute. Now virtio device
drivers will be able to allocate memory that is node-local to the
device. This significantly helps performance and it's oftenly used in
other drivers such as NVMe, for example.

Signed-off-by: Max Gurtovoy <mgurtovoy@xxxxxxxxxx>
---
 drivers/virtio/virtio.c | 10 ++++++++++
 include/linux/virtio.h  | 13 +++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 588e02fb91d3..bdbd76c5c58c 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -60,12 +60,22 @@ static ssize_t features_show(struct device *_d,
 }
 static DEVICE_ATTR_RO(features);
 
+static ssize_t numa_node_show(struct device *_d,
+			      struct device_attribute *attr, char *buf)
+{
+	struct virtio_device *vdev = dev_to_virtio(_d);
+
+	return sysfs_emit(buf, "%d\n", virtio_dev_to_node(vdev));
+}
+static DEVICE_ATTR_RO(numa_node);
+
 static struct attribute *virtio_dev_attrs[] = {
 	&dev_attr_device.attr,
 	&dev_attr_vendor.attr,
 	&dev_attr_status.attr,
 	&dev_attr_modalias.attr,
 	&dev_attr_features.attr,
+	&dev_attr_numa_node.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(virtio_dev);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 41edbc01ffa4..05b586ac71d1 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -125,6 +125,19 @@ static inline struct virtio_device *dev_to_virtio(struct device *_dev)
 	return container_of(_dev, struct virtio_device, dev);
 }
 
+/**
+ * virtio_dev_to_node - return the NUMA node for a given virtio device
+ * @vdev:	device to get the NUMA node for.
+ */
+static inline int virtio_dev_to_node(struct virtio_device *vdev)
+{
+	struct device *parent = vdev->dev.parent;
+
+	if (!parent)
+		return NUMA_NO_NODE;
+	return dev_to_node(parent);
+}
+
 void virtio_add_status(struct virtio_device *dev, unsigned int status);
 int register_virtio_device(struct virtio_device *dev);
 void unregister_virtio_device(struct virtio_device *dev);
-- 
2.18.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux