All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] virtio: introduce virtio_dev_to_node helper
@ 2021-09-26 14:55 Max Gurtovoy
  2021-09-26 14:55 ` [PATCH 2/2] virtio-blk: set NUMA affinity for a tagset Max Gurtovoy
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Max Gurtovoy @ 2021-09-26 14:55 UTC (permalink / raw)
  To: mst, virtualization, kvm, stefanha
  Cc: oren, nitzanc, israelr, hch, linux-block, axboe, Max Gurtovoy

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@nvidia.com>
---
 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


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-09-30 13:25 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 14:55 [PATCH 1/2] virtio: introduce virtio_dev_to_node helper Max Gurtovoy
2021-09-26 14:55 ` [PATCH 2/2] virtio-blk: set NUMA affinity for a tagset Max Gurtovoy
2021-09-27  8:09   ` Stefan Hajnoczi
2021-09-27  8:09     ` Stefan Hajnoczi
2021-09-27 17:39     ` Max Gurtovoy
2021-09-28  6:47       ` Stefan Hajnoczi
2021-09-28  6:47         ` Stefan Hajnoczi
2021-09-29 15:07         ` Max Gurtovoy
2021-09-30 13:16           ` Stefan Hajnoczi
2021-09-30 13:16             ` Stefan Hajnoczi
2021-09-30 13:24             ` Max Gurtovoy
2021-09-27 11:34   ` Leon Romanovsky
2021-09-27 11:34     ` Leon Romanovsky
2021-09-27 17:25     ` Max Gurtovoy
2021-09-27 18:23       ` Leon Romanovsky
2021-09-27 18:23         ` Leon Romanovsky
2021-09-28 15:59         ` Max Gurtovoy
2021-09-28 16:27           ` Leon Romanovsky
2021-09-28 16:27             ` Leon Romanovsky
2021-09-28 23:28             ` Max Gurtovoy
2021-09-29  6:50               ` Leon Romanovsky
2021-09-29  6:50                 ` Leon Romanovsky
2021-09-29  9:48                 ` Max Gurtovoy
2021-09-27  8:02 ` [PATCH 1/2] virtio: introduce virtio_dev_to_node helper Stefan Hajnoczi
2021-09-27  8:02   ` Stefan Hajnoczi
2021-09-27  9:31 ` Michael S. Tsirkin
2021-09-27  9:31   ` Michael S. Tsirkin
2021-09-28 16:14   ` Max Gurtovoy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.