From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: hare@suse.de, dwagner@suse.de, kbusch@kernel.org, gjoyce@ibm.com
Subject: [PATCHv3 2/4] tree: add queue-depth attribute for nvme path object
Date: Sat, 26 Apr 2025 00:26:07 +0530 [thread overview]
Message-ID: <20250425185617.1242994-3-nilay@linux.ibm.com> (raw)
In-Reply-To: <20250425185617.1242994-1-nilay@linux.ibm.com>
Introduce a new sysfs attribute, queue_depth, under the NVMe path object.
This attribute is used by the queue-depth I/O policy introduced in kernel
v6.11, but the sysfs interface for this attribute was only added later in
kernel v6.15.
The queue_depth value is useful for observing which paths are selected
for I/O forwarding based on their current queue depths. To make this
information available to user space tools such as nvme-cli, the attribute
is now exported in libnvme.map.
As queue_depth value could change frequently, nvme_path_get_queue_depth()
is implemented to always fetch the latest queue_depth value, rather than
relying solely on a cached version. If fetching the latest value fails,
the function gracefully falls back to the cached value.
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
src/libnvme.map | 1 +
src/nvme/private.h | 1 +
src/nvme/tree.c | 19 ++++++++++++++++++-
src/nvme/tree.h | 8 ++++++++
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/libnvme.map b/src/libnvme.map
index 4314705f..e53fad6b 100644
--- a/src/libnvme.map
+++ b/src/libnvme.map
@@ -317,6 +317,7 @@ LIBNVME_1_0 {
nvme_path_get_ctrl;
nvme_path_get_name;
nvme_path_get_ns;
+ nvme_path_get_queue_depth;
nvme_path_get_sysfs_dir;
nvme_paths_filter;
nvme_read_config;
diff --git a/src/nvme/private.h b/src/nvme/private.h
index f45c5823..f94276e2 100644
--- a/src/nvme/private.h
+++ b/src/nvme/private.h
@@ -34,6 +34,7 @@ struct nvme_path {
char *sysfs_dir;
char *ana_state;
int grpid;
+ int queue_depth;
};
struct nvme_ns_head {
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 2f82fd77..20d4c2e2 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -903,6 +903,18 @@ const char *nvme_path_get_name(nvme_path_t p)
return p->name;
}
+int nvme_path_get_queue_depth(nvme_path_t p)
+{
+ _cleanup_free_ char *queue_depth = NULL;
+
+ queue_depth = nvme_get_path_attr(p, "queue_depth");
+ if (queue_depth) {
+ sscanf(queue_depth, "%d", &p->queue_depth);
+ }
+
+ return p->queue_depth;
+}
+
const char *nvme_path_get_ana_state(nvme_path_t p)
{
return p->ana_state;
@@ -921,7 +933,7 @@ void nvme_free_path(struct nvme_path *p)
static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name)
{
struct nvme_path *p;
- _cleanup_free_ char *path = NULL, *grpid = NULL;
+ _cleanup_free_ char *path = NULL, *grpid = NULL, *queue_depth = NULL;
int ret;
nvme_msg(r, LOG_DEBUG, "scan controller %s path %s\n",
@@ -955,6 +967,11 @@ static int nvme_ctrl_scan_path(nvme_root_t r, struct nvme_ctrl *c, char *name)
sscanf(grpid, "%d", &p->grpid);
}
+ queue_depth = nvme_get_path_attr(p, "queue_depth");
+ if (queue_depth) {
+ sscanf(queue_depth, "%d", &p->queue_depth);
+ }
+
list_node_init(&p->nentry);
list_node_init(&p->entry);
list_add_tail(&c->paths, &p->entry);
diff --git a/src/nvme/tree.h b/src/nvme/tree.h
index 9f382e9c..a9082f8e 100644
--- a/src/nvme/tree.h
+++ b/src/nvme/tree.h
@@ -867,6 +867,14 @@ const char *nvme_path_get_sysfs_dir(nvme_path_t p);
*/
const char *nvme_path_get_ana_state(nvme_path_t p);
+/**
+ * nvme_path_get_queue_depth() - Queue depth of an nvme_path_t object
+ * @p: &nvme_path_t object
+ *
+ * Return: Queue depth of @p
+ */
+int nvme_path_get_queue_depth(nvme_path_t p);
+
/**
* nvme_path_get_ctrl() - Parent controller of an nvme_path_t object
* @p: &nvme_path_t object
--
2.49.0
next prev parent reply other threads:[~2025-04-25 18:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 18:56 [PATCHv3 0/4] libnvme: add support for discovering multipath of a shared ns Nilay Shroff
2025-04-25 18:56 ` [PATCHv3 1/4] tree: add support for discovering nvme paths using sysfs multipath link Nilay Shroff
2025-04-25 18:56 ` Nilay Shroff [this message]
2025-04-25 18:56 ` [PATCHv3 3/4] tree: add attribute numa_nodes for NVMe path object Nilay Shroff
2025-04-25 18:56 ` [PATCHv3 4/4] test: extend sysfs tree dump test Nilay Shroff
2025-05-13 11:28 ` [PATCHv3 0/4] libnvme: add support for discovering multipath of a shared ns Nilay Shroff
2025-06-04 14:47 ` Daniel Wagner
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=20250425185617.1242994-3-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@ibm.com \
--cc=hare@suse.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.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