linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Gurtovoy <mgurtovoy@nvidia.com>
To: <mst@redhat.com>, <virtualization@lists.linux-foundation.org>,
	<kvm@vger.kernel.org>, <stefanha@redhat.com>
Cc: <oren@nvidia.com>, <nitzanc@nvidia.com>, <israelr@nvidia.com>,
	<hch@infradead.org>, <linux-block@vger.kernel.org>,
	<axboe@kernel.dk>, "Max Gurtovoy" <mgurtovoy@nvidia.com>
Subject: [PATCH 1/2] virtio: introduce virtio_dev_to_node helper
Date: Sun, 26 Sep 2021 17:55:17 +0300	[thread overview]
Message-ID: <20210926145518.64164-1-mgurtovoy@nvidia.com> (raw)

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


             reply	other threads:[~2021-09-26 14:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-26 14:55 Max Gurtovoy [this message]
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 17:39     ` Max Gurtovoy
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:24             ` Max Gurtovoy
2021-09-27 11:34   ` Leon Romanovsky
2021-09-27 17:25     ` Max Gurtovoy
2021-09-27 18:23       ` Leon Romanovsky
2021-09-28 15:59         ` Max Gurtovoy
2021-09-28 16:27           ` Leon Romanovsky
2021-09-28 23:28             ` Max Gurtovoy
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  9:31 ` Michael S. Tsirkin
2021-09-28 16:14   ` Max Gurtovoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210926145518.64164-1-mgurtovoy@nvidia.com \
    --to=mgurtovoy@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=israelr@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nitzanc@nvidia.com \
    --cc=oren@nvidia.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).