libnvme: add support for retrieving additional NVMe stat
v2 cover libnvme: add support for retrieving additional NVMe stat
Hi,
Certain NVMe attributes and statistics can change dynamically at runtime. However, the current libnvme implementation caches attribute values while scanning and building the topology. Subsequent libnvme API calls return these cached values.
While this approach works well for one-shot nvme-cli commands, it is not suitable for use cases that require upto date information. In particular, real-time monitoring tools such as nvme-top require access to the latest (non-cached) values of such attributes.
To address this, this patchset introduces support for retrieving non-cached values for selected attributes whose values may change dynamically. The first three patches disable auto-generated accessors for ana_state, numa_nodes, and iopolicy using "!accessors:none", and provide custom implementations that always return the latest values.
In addition, libnvme lacks support for retrieving gendisk statistics, which provide useful insight into disk activity (e.g., number of I/Os processed, time spent servicing I/O, and in-flight I/O counts). This patchset adds support for retrieving gendisk I/O statistics for both per-path and namespace gendisks.
Finally, this series adds support for retrieving diagnostic counters at different levels, including per-path, namespace, nshead, and controller. These counters should improve visibility into NVMe native multipath behavior.
All of the above statistics and counters can be leveraged by tools such as nvme-top to provide real-time monitoring and analysis.
As usual, feedback and suggestions are welcome!
Changes from v1:
- Avoid exposing internal state of libnvme to its users
while exporting the nvme stat; add a switch while updating
nvme stat which determines whether getters shall return the
nvme diffstat or absolute stat (Daniel Wagner)
- If libnvme API fails then return appropriate error code
instead of -1 (Daniel Wagner)
Link to v1: https://lore.kernel.org/all/[email protected]/
Nilay Shroff (9):
libnvme: annotate nvme_path::ana_state with !accessors:none
libnvme: annotate nvme_path::numa_nodes with !accessors:none
libnvme: annotate nvme_subsystem::iopolicy with !accessors:none
libnvme: add support for retrieving per-path gendisk I/O statistics
libnvme: add support for retrieving namespace gendisk I/O statistics
libnvme: add support for per-path diagnostic counters
libnvme: add support for namespace diagnostic counters
libnvme: add support for nshead diagnostic counters
libnvme: add support for ctrl diagnostic counters
libnvme/src/accessors.ld | 6 - libnvme/src/libnvme.ld | 36 +++ libnvme/src/nvme/accessors.c | 39 --- libnvme/src/nvme/accessors.h | 47 --- libnvme/src/nvme/private.h | 51 +++- libnvme/src/nvme/tree.c | 563 +++++++++++++++++++++++++++++++++++ libnvme/src/nvme/tree.h | 297 ++++++++++++++++++ 7 files changed, 944 insertions(+), 95 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/9 libnvme: annotate nvme_path::ana_state with !accessors:none
The default accessor generation creates getters that return cached attribute values. However, for nvme_path::ana_state, a real-time (non-cached) value is required.
This is particularly useful for tools such as nvme-top, which rely on up-to-date information for displaying a real-time dashboard.
Annotate nvme_path::ana_state with "!accessors:none" to disable the auto-generated accessor, and provide a custom implementation of nvme_path_get_ana_state() that returns the current value.
--- libnvme/src/accessors.ld | 2 -- libnvme/src/libnvme.ld | 1 + libnvme/src/nvme/accessors.c | 13 ------------- libnvme/src/nvme/accessors.h | 15 --------------- libnvme/src/nvme/private.h | 2 +- libnvme/src/nvme/tree.c | 15 +++++++++++++++ libnvme/src/nvme/tree.h | 8 ++++++++ 7 files changed, 25 insertions(+), 31 deletions(-)
libnvme/src/accessors.ld +0 -2
@@ -14,8 +14,6 @@ LIBNVME_ACCESSORS_3 { nvme_path_set_name; nvme_path_get_sysfs_dir; nvme_path_set_sysfs_dir; - nvme_path_get_ana_state; - nvme_path_set_ana_state; nvme_path_get_numa_nodes; nvme_path_set_numa_nodes; nvme_path_get_grpid;
libnvme/src/libnvme.ld +1 -0
@@ -142,6 +142,7 @@ LIBNVME_3 { nvme_path_get_ctrl; nvme_path_get_ns; nvme_path_get_queue_depth; + nvme_path_get_ana_state; nvme_random_uuid; nvme_read_config; nvme_read_hostid;
libnvme/src/nvme/accessors.c +0 -13
@@ -52,19 +52,6 @@ __public const char *nvme_path_get_sysfs_dir(const struct nvme_path *p)return p->sysfs_dir; } -__public void nvme_path_set_ana_state( -struct nvme_path *p, -const char *ana_state) -{ -free (p->ana_state); - p->ana_state = ana_state ?strdup (ana_state) :NULL ; -} - -__public const char *nvme_path_get_ana_state(const struct nvme_path *p) -{ -return p->ana_state; -} - __public void nvme_path_set_numa_nodes(struct nvme_path *p,const char *numa_nodes)
libnvme/src/nvme/accessors.h +0 -15
@@ -68,21 +68,6 @@ void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir);*/ const char *nvme_path_get_sysfs_dir (const struct nvme_path *p); -/** -* nvme_path_set_ana_state() - Set ana_state. -* @p: The &struct nvme_path instance to update. -* @ana_state: New string; a copy is stored. Pass NULL to clear. -*/ -void nvme_path_set_ana_state (struct nvme_path *p,const char *ana_state); - -/** -* nvme_path_get_ana_state() - Get ana_state. -* @p: The &struct nvme_path instance to query. -* -* Return: The value of the ana_state field, or NULL if not set. -*/ -const char *nvme_path_get_ana_state (const struct nvme_path *p); -/** * nvme_path_set_numa_nodes() - Set numa_nodes. * @p: The &struct nvme_path instance to update.
libnvme/src/nvme/private.h +1 -1
@@ -137,8 +137,8 @@ struct nvme_path { /*!generate-accessors*/char *name;char *sysfs_dir; -char *ana_state;char *numa_nodes; +char *ana_state;//!accessors:none int grpid;int queue_depth;//!accessors:none };
libnvme/src/nvme/tree.c +15 -0
@@ -806,6 +806,21 @@ __public int nvme_path_get_queue_depth(nvme_path_t p)return p->queue_depth; } +__public char *nvme_path_get_ana_state(nvme_path_t p) +{ + _cleanup_free_ char *ana_state = NULL; + + ana_state =nvme_get_path_attr (p,"ana_state" ); +if (ana_state) { +if (!p->ana_state ||strcmp (ana_state, p->ana_state)) { +free (p->ana_state); + p->ana_state =strdup (ana_state); + } + } + +return p->ana_state; +} +void nvme_free_path (struct nvme_path *p) {list_del_init (&p->entry);
libnvme/src/nvme/tree.h +8 -0
@@ -679,6 +679,14 @@ int nvme_ns_identify_descs(nvme_ns_t n, struct nvme_ns_id_desc *descs);*/ int nvme_path_get_queue_depth (nvme_path_t p); +/** +* nvme_path_get_ana_state() - ANA state of an nvme_path_t object +* @p: &nvme_path_t object +* +* Return: ANA state of @p +*/ +char *nvme_path_get_ana_state (nvme_path_t p); +/** * nvme_path_get_ctrl() - Parent controller of an nvme_path_t object * @p: &nvme_path_t object
Signature · 1 line
2.53.0
PATCH v2 2/9 libnvme: annotate nvme_path::numa_nodes with !accessors:none
In reply to Nilay ShroffThe default accessor generation creates getters that return cached attribute values. However, for nvme_path::numa_nodes, a real-time (non-cached) value is required.
This is particularly useful for tools such as nvme-top, which rely on up-to-date information for displaying a real-time dashboard.
Annotate nvme_path::numa_nodes with "!accessors:none" to disable the auto-generated accessor, and provide a custom implementation of nvme_path_get_numa_nodes() that returns the current value.
--- libnvme/src/accessors.ld | 2 -- libnvme/src/libnvme.ld | 1 + libnvme/src/nvme/accessors.c | 13 ------------- libnvme/src/nvme/accessors.h | 15 --------------- libnvme/src/nvme/private.h | 2 +- libnvme/src/nvme/tree.c | 15 +++++++++++++++ libnvme/src/nvme/tree.h | 8 ++++++++ 7 files changed, 25 insertions(+), 31 deletions(-)
libnvme/src/accessors.ld +0 -2
@@ -14,8 +14,6 @@ LIBNVME_ACCESSORS_3 { nvme_path_set_name; nvme_path_get_sysfs_dir; nvme_path_set_sysfs_dir; - nvme_path_get_numa_nodes; - nvme_path_set_numa_nodes; nvme_path_get_grpid; nvme_path_set_grpid; nvme_ns_get_nsid;
libnvme/src/libnvme.ld +1 -0
@@ -143,6 +143,7 @@ LIBNVME_3 { nvme_path_get_ns; nvme_path_get_queue_depth; nvme_path_get_ana_state; + nvme_path_get_numa_nodes; nvme_random_uuid; nvme_read_config; nvme_read_hostid;
libnvme/src/nvme/accessors.c +0 -13
@@ -52,19 +52,6 @@ __public const char *nvme_path_get_sysfs_dir(const struct nvme_path *p)return p->sysfs_dir; } -__public void nvme_path_set_numa_nodes( -struct nvme_path *p, -const char *numa_nodes) -{ -free (p->numa_nodes); - p->numa_nodes = numa_nodes ?strdup (numa_nodes) :NULL ; -} - -__public const char *nvme_path_get_numa_nodes(const struct nvme_path *p) -{ -return p->numa_nodes; -} - __public void nvme_path_set_grpid(struct nvme_path *p, int grpid) { p->grpid = grpid;
libnvme/src/nvme/accessors.h +0 -15
@@ -68,21 +68,6 @@ void nvme_path_set_sysfs_dir(struct nvme_path *p, const char *sysfs_dir);*/ const char *nvme_path_get_sysfs_dir (const struct nvme_path *p); -/** -* nvme_path_set_numa_nodes() - Set numa_nodes. -* @p: The &struct nvme_path instance to update. -* @numa_nodes: New string; a copy is stored. Pass NULL to clear. -*/ -void nvme_path_set_numa_nodes (struct nvme_path *p,const char *numa_nodes); - -/** -* nvme_path_get_numa_nodes() - Get numa_nodes. -* @p: The &struct nvme_path instance to query. -* -* Return: The value of the numa_nodes field, or NULL if not set. -*/ -const char *nvme_path_get_numa_nodes (const struct nvme_path *p); -/** * nvme_path_set_grpid() - Set grpid. * @p: The &struct nvme_path instance to update.
libnvme/src/nvme/private.h +1 -1
@@ -137,8 +137,8 @@ struct nvme_path { /*!generate-accessors*/char *name;char *sysfs_dir; -char *numa_nodes;char *ana_state;//!accessors:none +char *numa_nodes;//!accessors:none int grpid;int queue_depth;//!accessors:none };
libnvme/src/nvme/tree.c +15 -0
@@ -821,6 +821,21 @@ __public char *nvme_path_get_ana_state(nvme_path_t p)return p->ana_state; } +__public char *nvme_path_get_numa_nodes(nvme_path_t p) +{ + _cleanup_free_ char *numa_nodes = NULL; + + numa_nodes =nvme_get_path_attr (p,"numa_nodes" ); +if (numa_nodes) { +if (!p->numa_nodes ||strcmp (numa_nodes, p->numa_nodes)) { +free (p->numa_nodes); + p->numa_nodes =strdup (numa_nodes); + } + } + +return p->numa_nodes; +} +void nvme_free_path (struct nvme_path *p) {list_del_init (&p->entry);
libnvme/src/nvme/tree.h +8 -0
@@ -687,6 +687,14 @@ int nvme_path_get_queue_depth(nvme_path_t p);*/ char *nvme_path_get_ana_state (nvme_path_t p); +/** +* nvme_path_get_numa_nodes() - Numa nodes of an nvme_path_t object +* @p: &nvme_path_t object +* +* Return: Numa nodes of @p +*/ +char *nvme_path_get_numa_nodes (nvme_path_t p); +/** * nvme_path_get_ctrl() - Parent controller of an nvme_path_t object * @p: &nvme_path_t object
Signature · 1 line
2.53.0
PATCH v2 3/9 libnvme: annotate nvme_subsystem::iopolicy with !accessors:none
In reply to Nilay ShroffThe default accessor generation creates getters that return cached attribute values. However, for nvme_subsystem::iopolicy, a real-time (non-cached) value is required.
This is particularly useful for tools such as nvme-top, which rely on up-to-date information for displaying a real-time dashboard.
Annotate nvme_subsystem::iopolicy with "!accessors:none" to disable the auto-generated accessor, and provide a custom implementation of nvme_subsystem_get_iopolicy() that returns the current value.
--- libnvme/src/accessors.ld | 2 -- libnvme/src/libnvme.ld | 1 + libnvme/src/nvme/accessors.c | 13 ------------- libnvme/src/nvme/accessors.h | 17 ----------------- libnvme/src/nvme/private.h | 2 +- libnvme/src/nvme/tree.c | 15 +++++++++++++++ libnvme/src/nvme/tree.h | 8 ++++++++ 7 files changed, 25 insertions(+), 33 deletions(-)
libnvme/src/accessors.ld +0 -2
@@ -77,8 +77,6 @@ LIBNVME_ACCESSORS_3 { nvme_subsystem_get_subsystype; nvme_subsystem_get_application; nvme_subsystem_set_application; - nvme_subsystem_get_iopolicy; - nvme_subsystem_set_iopolicy; nvme_host_get_hostnqn; nvme_host_get_hostid; nvme_host_get_dhchap_host_key;
libnvme/src/libnvme.ld +1 -0
@@ -180,6 +180,7 @@ LIBNVME_3 { nvme_subsystem_first_ctrl; nvme_subsystem_first_ns; nvme_subsystem_get_host; + nvme_subsystem_get_iopolicy; nvme_subsystem_lookup_namespace; nvme_subsystem_next_ctrl; nvme_subsystem_next_ns;
libnvme/src/nvme/accessors.c +0 -13
@@ -404,19 +404,6 @@ __public const char *nvme_subsystem_get_application(return p->application; } -__public void nvme_subsystem_set_iopolicy( -struct nvme_subsystem *p, -const char *iopolicy) -{ -free (p->iopolicy); - p->iopolicy = iopolicy ?strdup (iopolicy) :NULL ; -} - -__public const char *nvme_subsystem_get_iopolicy(const struct nvme_subsystem *p) -{ -return p->iopolicy; -} -/**************************************************************************** * Accessors for: struct nvme_host ****************************************************************************/
libnvme/src/nvme/accessors.h +0 -17
@@ -575,23 +575,6 @@ void nvme_subsystem_set_application(*/ const char *nvme_subsystem_get_application (const struct nvme_subsystem *p); -/** -* nvme_subsystem_set_iopolicy() - Set iopolicy. -* @p: The &struct nvme_subsystem instance to update. -* @iopolicy: New string; a copy is stored. Pass NULL to clear. -*/ -void nvme_subsystem_set_iopolicy ( -struct nvme_subsystem *p, -const char *iopolicy); - -/** -* nvme_subsystem_get_iopolicy() - Get iopolicy. -* @p: The &struct nvme_subsystem instance to query. -* -* Return: The value of the iopolicy field, or NULL if not set. -*/ -const char *nvme_subsystem_get_iopolicy (const struct nvme_subsystem *p); -/**************************************************************************** * Accessors for: struct nvme_host ****************************************************************************/
libnvme/src/nvme/private.h +1 -1
@@ -230,7 +230,7 @@ struct nvme_subsystem { /*!generate-accessors*/char *firmware;/*!accessors:readonly*/ char *subsystype;/*!accessors:readonly*/ char *application; -char *iopolicy; +char *iopolicy;//!accessors:none };struct nvme_host {/*!generate-accessors*/
libnvme/src/nvme/tree.c +15 -0
@@ -445,6 +445,21 @@ __public nvme_host_t nvme_subsystem_get_host(nvme_subsystem_t s)return s->h; } +__public char *nvme_subsystem_get_iopolicy(nvme_subsystem_t s) +{ + _cleanup_free_ char *iopolicy = NULL; + + iopolicy =nvme_get_subsys_attr (s,"iopolicy" ); +if (iopolicy) { +if (!s->iopolicy ||strcmp (iopolicy, s->iopolicy)) { +free (s->iopolicy); + s->iopolicy =strdup (iopolicy); + } + } + +return s->iopolicy; +} + __public nvme_ns_t nvme_subsystem_first_ns(nvme_subsystem_t s) { return list_top(&s->namespaces, struct nvme_ns, entry);
libnvme/src/nvme/tree.h +8 -0
@@ -212,6 +212,14 @@ void nvme_free_subsystem(struct nvme_subsystem *s);*/ nvme_host_t nvme_subsystem_get_host (nvme_subsystem_t s); +/** +* nvme_subsystem_get_iopolicy() - Get subsystem iopolicy name +* @s: subsystem +* +* Return: The iopolicy configured in subsystem @s +*/ +char *nvme_subsystem_get_iopolicy (nvme_subsystem_t s); +/** * nvme_ctrl_first_ns() - Start namespace iterator * @c: Controller instance
Signature · 1 line
2.53.0
PATCH v2 4/9 libnvme: add support for retrieving per-path gendisk I/O statistics
In reply to Nilay ShroffGendisk I/O statistics provide useful insight into disk activity, including read/write/discard/flush operations, as well as information about in-flight I/Os and I/O timing.
Parsing these statistics allows users to determine the number of I/Os processed, time spent servicing I/O, number of sectors accessed, and the count of in-flight requests.
Add support for retrieving per-path gendisk I/O statistics. Also add support for computing deltas of these statistics between samples, such as I/O ticks, number of sectors, and number of serviced I/Os.
These metrics can be used by tools such as nvme-top to display real-time disk activity. Per-path metrics are particularly useful when NVMe native multipath is enabled.
--- libnvme/src/libnvme.ld | 12 ++ libnvme/src/nvme/private.h | 29 ++++ libnvme/src/nvme/tree.c | 268 +++++++++++++++++++++++++++++++++++++ libnvme/src/nvme/tree.h | 93 +++++++++++++ 4 files changed, 402 insertions(+)
libnvme/src/libnvme.ld +12 -0
@@ -144,6 +144,18 @@ LIBNVME_3 { nvme_path_get_queue_depth; nvme_path_get_ana_state; nvme_path_get_numa_nodes; + nvme_path_get_stat; + nvme_path_get_read_ios; + nvme_path_get_write_ios; + nvme_path_get_inflights; + nvme_path_get_stat_interval; + nvme_path_get_io_ticks; + nvme_path_get_read_ticks; + nvme_path_get_write_ticks; + nvme_path_get_read_sectors; + nvme_path_get_write_sectors; + nvme_path_reset_stat; + nvme_path_update_stat; nvme_random_uuid; nvme_read_config; nvme_read_hostid;
libnvme/src/nvme/private.h +29 -0
@@ -20,6 +20,7 @@#include <nvme/fabrics.h> #include <nvme/mi.h> +#include <nvme/tree.h> const char *nvme_subsys_sysfs_dir (void );const char *nvme_ctrl_sysfs_dir (void );
@@ -128,10 +129,38 @@ struct nvme_transport_handle {struct nvme_log *log; }; +enum stat_group { +READ =0 , +WRITE , +DISCARD , +FLUSH , + +NR_STAT_GROUPS +}; + +struct nvme_stat { +struct { +unsigned long ios; +unsigned long merges; +unsigned long long sectors; +unsigned int ticks;/* in milliseconds */ + } group[NR_STAT_GROUPS ]; + +unsigned int inflights; +unsigned int io_ticks;/* in milliseconds */ +unsigned int tot_ticks;/* in milliseconds */ + +double ts_ms;/* timestamp when the stat is updated */ +}; +struct nvme_path {/*!generate-accessors*/ struct list_node entry;struct list_node nentry; +struct nvme_stat stat[2 ];/* gendisk I/O stat */ +unsigned int curr_idx;/* current index into the stat[] */ +bool diffstat; +struct nvme_ctrl *c;struct nvme_ns *n;
libnvme/src/nvme/tree.c +268 -0
280 lines not on this page · raw message
libnvme/src/nvme/tree.h +93 -0
105 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 5/9 libnvme: add support for retrieving namespace gendisk I/O statistics
In reply to Nilay ShroffGendisk I/O statistics provide useful insight into disk activity, including read/write/discard/flush operations, as well as information about in-flight I/Os and I/O timing.
Parsing these statistics allows users to determine the number of I/Os processed, time spent servicing I/O, number of sectors accessed, and the count of in-flight requests.
Add support for retrieving namespace gendisk I/O statistics. Also add support for computing deltas of these statistics between samples, such as I/O ticks, number of sectors, and number of serviced I/Os.
These metrics can be used by tools such as nvme-top to display real-time disk activity.
--- libnvme/src/libnvme.ld | 11 +++ libnvme/src/nvme/private.h | 5 ++ libnvme/src/nvme/tree.c | 140 +++++++++++++++++++++++++++++++++++++ libnvme/src/nvme/tree.h | 94 +++++++++++++++++++++++++ 4 files changed, 250 insertions(+)
libnvme/src/libnvme.ld +11 -0
@@ -131,6 +131,17 @@ LIBNVME_3 { nvme_ns_get_serial; nvme_ns_get_subsystem; nvme_ns_get_uuid; + nvme_ns_reset_stat; + nvme_ns_update_stat; + nvme_ns_get_stat_interval; + nvme_ns_get_read_ios; + nvme_ns_get_write_ios; + nvme_ns_get_read_ticks; + nvme_ns_get_write_ticks; + nvme_ns_get_read_sectors; + nvme_ns_get_write_sectors; + nvme_ns_get_inflights; + nvme_ns_get_io_ticks; nvme_ns_identify; nvme_ns_read; nvme_ns_verify;
libnvme/src/nvme/private.h +5 -0
@@ -187,6 +187,11 @@ struct nvme_ns { /*!generate-accessors*/struct nvme_ns_head *head;struct nvme_global_ctx *ctx; + +struct nvme_stat stat[2 ];/* gendisk I/O stat */ +unsigned int curr_idx;/* current index into the stat[] */ +bool diffstat; +struct nvme_transport_handle *hdl;__u32 nsid;char *name;
libnvme/src/nvme/tree.c +140 -0
188 lines not on this page · raw message
libnvme/src/nvme/tree.h +94 -0
100 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 6/9 libnvme: add support for per-path diagnostic counters
In reply to Nilay ShroffAdd support for retrieving per-path diagnostic counters such as command_retry_count, command_error_count, and multipath_failover_count. These counters improve visibility into NVMe native multipath behavior and can be useful for tools such as nvme-top to display real-time statistics.
Unlike other sysfs attributes, these counters can change dynamically. Annotate them with "!accessors:none" and provide custom implementations to always retrieve the latest (non-cached) values.
--- libnvme/src/libnvme.ld | 3 +++ libnvme/src/nvme/private.h | 3 +++ libnvme/src/nvme/tree.c | 33 +++++++++++++++++++++++++++++++++ libnvme/src/nvme/tree.h | 27 +++++++++++++++++++++++++++ 4 files changed, 66 insertions(+)
libnvme/src/libnvme.ld +3 -0
@@ -167,6 +167,9 @@ LIBNVME_3 { nvme_path_get_write_sectors; nvme_path_reset_stat; nvme_path_update_stat; + nvme_path_get_command_retry_count; + nvme_path_get_command_error_count; + nvme_path_get_multipath_failover_count; nvme_random_uuid; nvme_read_config; nvme_read_hostid;
libnvme/src/nvme/private.h +3 -0
@@ -170,6 +170,9 @@ struct nvme_path { /*!generate-accessors*/char *numa_nodes;//!accessors:none int grpid;int queue_depth;//!accessors:none +long multipath_failover_count;//!accessors:none +long command_retry_count;//!accessors:none +long command_error_count;//!accessors:none };struct nvme_ns_head {
libnvme/src/nvme/tree.c +33 -0
@@ -852,6 +852,39 @@ __public char *nvme_path_get_numa_nodes(nvme_path_t p)return p->numa_nodes; } +__public long nvme_path_get_multipath_failover_count (nvme_path_t p) +{ + _cleanup_free_ char *failover_count = NULL; + + failover_count =nvme_get_path_attr (p,"multipath_failover_count" ); +if (failover_count) +sscanf (failover_count,"%ld" , &p->multipath_failover_count); + +return p->multipath_failover_count; +} + +__public long nvme_path_get_command_retry_count (nvme_path_t p) +{ + _cleanup_free_ char *retry_count = NULL; + + retry_count =nvme_get_path_attr (p,"command_retry_count" ); +if (retry_count) +sscanf (retry_count,"%ld" , &p->command_retry_count); + +return p->command_retry_count; +} + +__public long nvme_path_get_command_error_count (nvme_path_t p) +{ + _cleanup_free_ char *error_count = NULL; + + error_count =nvme_get_path_attr (p,"command_error_count" ); +if (error_count) +sscanf (error_count,"%ld" , &p->command_error_count); + +return p->command_error_count; +} +static nvme_stat_t nvme_path_get_stat (nvme_path_t p,unsigned int idx) {if (idx >1 )
libnvme/src/nvme/tree.h +27 -0
@@ -704,6 +704,33 @@ char *nvme_path_get_ana_state(nvme_path_t p);*/ char *nvme_path_get_numa_nodes (nvme_path_t p); +/** +* nvme_path_get_multipath_failover_count() - Get multipath failover count +* @p: &nvme_path_t object +* +* Return: Number of times I/Os have to be failed over to another active path +* from path @p maybe due to any transient error observed on path @p +*/ +long nvme_path_get_multipath_failover_count (nvme_path_t p); + +/** +* nvme_path_get_command_retry_count() - Get command retry count +* @p: &nvme_path_t object +* +* Return: Number of times any command issued to the namespace represented by +* path @p has to be retried +*/ +long nvme_path_get_command_retry_count (nvme_path_t p); + +/** +* nvme_path_get_command_error_count() - Get command error count +* @p: &nvme_path_t object +* +* Return: Number of times command issued to the namespace represented by path +* @p returns non-zero status or error +*/ +long nvme_path_get_command_error_count (nvme_path_t p); +/** * nvme_path_get_ctrl() - Parent controller of an nvme_path_t object * @p: &nvme_path_t object
Signature · 1 line
2.53.0
PATCH v2 7/9 libnvme: add support for namespace diagnostic counters
In reply to Nilay ShroffAdd support for retrieving namespace diagnostic counters such as command_retry_count and command_error_count. These counters improve visibility and can be useful for tools such as nvme-top to display real-time statistics.
Unlike other sysfs attributes, these counters can change dynamically. Annotate them with "!accessors:none" and provide custom implementations to always retrieve the latest (non-cached) values.
--- libnvme/src/libnvme.ld | 2 ++ libnvme/src/nvme/private.h | 3 +++ libnvme/src/nvme/tree.c | 22 ++++++++++++++++++++++ libnvme/src/nvme/tree.h | 17 +++++++++++++++++ 4 files changed, 44 insertions(+)
libnvme/src/libnvme.ld +2 -0
@@ -142,6 +142,8 @@ LIBNVME_3 { nvme_ns_get_write_sectors; nvme_ns_get_inflights; nvme_ns_get_io_ticks; + nvme_ns_get_command_retry_count; + nvme_ns_get_command_error_count; nvme_ns_identify; nvme_ns_read; nvme_ns_verify;
libnvme/src/nvme/private.h +3 -0
@@ -211,6 +211,9 @@ struct nvme_ns { /*!generate-accessors*/uint8_t nguid[16 ];unsigned char uuid[NVME_UUID_LEN ];enum nvme_csi csi; + +long command_retry_count;//!accessors:none +long command_error_count;//!accessors:none };struct nvme_ctrl {/*!generate-accessors*/
libnvme/src/nvme/tree.c +22 -0
@@ -2592,6 +2592,28 @@ __public void nvme_ns_get_uuid(nvme_ns_t n, unsigned char out[NVME_UUID_LEN])memcpy (out, n->uuid,NVME_UUID_LEN ); } +__public long nvme_ns_get_command_retry_count (nvme_ns_t n) +{ + _cleanup_free_ char *retry_count = NULL; + + retry_count =nvme_get_ns_attr (n,"command_retry_count" ); +if (retry_count) +sscanf (retry_count,"%ld" , &n->command_retry_count); + +return n->command_retry_count; +} + +__public long nvme_ns_get_command_error_count (nvme_ns_t n) +{ + _cleanup_free_ char *error_count = NULL; + + error_count =nvme_get_ns_attr (n,"command_error_count" ); +if (error_count) +sscanf (error_count,"%ld" , &n->command_error_count); + +return n->command_error_count; +} + __public int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) {struct nvme_transport_handle *hdl;
libnvme/src/nvme/tree.h +17 -0
@@ -529,6 +529,23 @@ const uint8_t *nvme_ns_get_nguid(nvme_ns_t n);*/ void nvme_ns_get_uuid (nvme_ns_t n,unsigned char out[NVME_UUID_LEN ]); +/** +* nvme_ns_get_command_retry_count() - Get command retry count +* @n: &nvme_ns_t object +* +* Return: Number of times any command issued to namespace @n has to be retried +*/ +long nvme_ns_get_command_retry_count (nvme_ns_t n); + +/** +* nvme_ns_get_command_error_count() - Get command error count +* @n: &nvme_ns_t object +* +* Return: Number of times command issued to namespace @n returns non-zero +* status or error +*/ +long nvme_ns_get_command_error_count (nvme_ns_t n); +/** * nvme_ns_get_generic_name() - Returns name of generic namespace chardev. * @n: Namespace instance
Signature · 1 line
2.53.0
PATCH v2 8/9 libnvme: add support for nshead diagnostic counters
In reply to Nilay ShroffAdd support for retrieving nshead diagnostic counters such as requeue_ no_usable_path_count and fail_no_available_path_count.
The requeue_no_usable_path_count counter represents the number of I/Os requeued to the namespace head when no usable path is available (for example, due to transient link issues). The fail_no_available_path_count counter represents the number of I/Os failed when no I/O path is available (for example, when all paths are removed).
These counters improve visibility into NVMe native multipath behavior and can be useful for tools such as nvme-top to display real-time statistics.
Unlike other sysfs attributes, these counters can change dynamically. Annotate them with "!accessors:none" and provide custom implementations to always retrieve the latest (non-cached) values.
--- libnvme/src/libnvme.ld | 2 ++ libnvme/src/nvme/private.h | 2 ++ libnvme/src/nvme/tree.c | 22 ++++++++++++++++++++++ libnvme/src/nvme/tree.h | 17 +++++++++++++++++ 4 files changed, 43 insertions(+)
libnvme/src/libnvme.ld +2 -0
@@ -144,6 +144,8 @@ LIBNVME_3 { nvme_ns_get_io_ticks; nvme_ns_get_command_retry_count; nvme_ns_get_command_error_count; + nvme_ns_get_requeue_no_usable_path_count; + nvme_ns_get_fail_no_available_path_count; nvme_ns_identify; nvme_ns_read; nvme_ns_verify;
libnvme/src/nvme/private.h +2 -0
@@ -214,6 +214,8 @@ struct nvme_ns { /*!generate-accessors*/long command_retry_count;//!accessors:none long command_error_count;//!accessors:none +long requeue_no_usable_path_count;//!accessors:none +long fail_no_available_path_count;//!accessors:none };struct nvme_ctrl {/*!generate-accessors*/
libnvme/src/nvme/tree.c +22 -0
@@ -2614,6 +2614,28 @@ __public long nvme_ns_get_command_error_count(nvme_ns_t n)return n->command_error_count; } +__public long nvme_ns_get_requeue_no_usable_path_count (nvme_ns_t n) +{ + _cleanup_free_ char *requeue_count = NULL; + + requeue_count =nvme_get_ns_attr (n,"requeue_no_usable_path_count" ); +if (requeue_count) +sscanf (requeue_count,"%ld" , &n->requeue_no_usable_path_count); + +return n->requeue_no_usable_path_count; +} + +__public long nvme_ns_get_fail_no_available_path_count (nvme_ns_t n) +{ + _cleanup_free_ char *fail_count = NULL; + + fail_count =nvme_get_ns_attr (n,"fail_no_available_path_count" ); +if (fail_count) +sscanf (fail_count,"%ld" , &n->fail_no_available_path_count); + +return n->fail_no_available_path_count; +} + __public int nvme_ns_identify(nvme_ns_t n, struct nvme_id_ns *ns) {struct nvme_transport_handle *hdl;
libnvme/src/nvme/tree.h +17 -0
@@ -546,6 +546,23 @@ long nvme_ns_get_command_retry_count(nvme_ns_t n);*/ long nvme_ns_get_command_error_count (nvme_ns_t n); +/** +* nvme_ns_get_requeue_no_usable_path_count() - Get num of I/O requeue count +* @n: &nvme_ns_t object +* +* Return: Number of I/Os which are re-queued due to the unavalibility of +* any usable path (maybe path is currently experiencing transinet link failure) +*/ +long nvme_ns_get_requeue_no_usable_path_count (nvme_ns_t n); + +/** +* nvme_ns_get_fail_no_available_path_count() - Get num of I/Os forced to fail +* @n: &nvme_ns_t object +* +* Return: Number of I/Os which are forced to fail due to no path available +*/ +long nvme_ns_get_fail_no_available_path_count (nvme_ns_t n); +/** * nvme_ns_get_generic_name() - Returns name of generic namespace chardev. * @n: Namespace instance
Signature · 1 line
2.53.0
PATCH v2 9/9 libnvme: add support for ctrl diagnostic counters
In reply to Nilay ShroffAdd support for retrieving ctrl diagnostic counters such as command_ error_count, reset_count and reconnect_count. These counters improve visibility and can be useful for tools such as nvme-top to display real-time statistics.
Unlike other sysfs attributes, these counters can change dynamically. Annotate them with "!accessors:none" and provide custom implementations to always retrieve the latest (non-cached) values.
--- libnvme/src/libnvme.ld | 3 +++ libnvme/src/nvme/private.h | 3 +++ libnvme/src/nvme/tree.c | 33 +++++++++++++++++++++++++++++++++ libnvme/src/nvme/tree.h | 25 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+)
libnvme/src/libnvme.ld +3 -0
@@ -16,6 +16,9 @@ LIBNVME_3 { nvme_ctrl_get_subsysnqn; nvme_ctrl_get_subsystem; nvme_ctrl_get_transport_handle; + nvme_ctrl_get_command_error_count; + nvme_ctrl_get_reset_count; + nvme_ctrl_get_reconnect_count; nvme_ctrl_identify; nvme_ctrl_match_config; nvme_ctrl_next_ns;
libnvme/src/nvme/private.h +3 -0
@@ -255,6 +255,9 @@ struct nvme_ctrl { /*!generate-accessors*/bool unique_discovery_ctrl;bool discovered;bool persistent; +long command_error_count;//!accessors:none +long reset_count;//!accessors:none +long reconnect_count;//!accessors:none struct nvme_fabrics_config cfg; };
libnvme/src/nvme/tree.c +33 -0
@@ -1414,6 +1414,39 @@ __public const char *nvme_ctrl_get_state(nvme_ctrl_t c)return c->state; } +__public long nvme_ctrl_get_command_error_count (nvme_ctrl_t c) +{ + _cleanup_free_ char *error_count = NULL; + + error_count =nvme_get_ctrl_attr (c,"command_error_count" ); +if (error_count) +sscanf (error_count,"%ld" , &c->command_error_count); + +return c->command_error_count; +} + +__public long nvme_ctrl_get_reset_count (nvme_ctrl_t c) +{ + _cleanup_free_ char *reset_count = NULL; + + reset_count =nvme_get_ctrl_attr (c,"reset_count" ); +if (reset_count) +sscanf (reset_count,"%ld" , &c->reset_count); + +return c->reset_count; +} + +__public long nvme_ctrl_get_reconnect_count (nvme_ctrl_t c) +{ + _cleanup_free_ char *reconnect_count = NULL; + + reconnect_count =nvme_get_ctrl_attr (c,"reconnect_count" ); +if (reconnect_count) +sscanf (reconnect_count,"%ld" , &c->reconnect_count); + +return c->reconnect_count; +} + __public struct nvme_fabrics_config *nvme_ctrl_get_config(nvme_ctrl_t c) {return &c->cfg;
libnvme/src/nvme/tree.h +25 -0
@@ -1030,6 +1030,31 @@ unsigned long long nvme_ns_get_write_sectors(nvme_ns_t n);*/ struct nvme_fabrics_config *nvme_ctrl_get_config (nvme_ctrl_t c); +/** +* nvme_ctrl_get_command_error_count() - Get admin command error count +* @c: Controller instance +* +* Return: Number of times admin command issued to controller @c failed or +* returned error status +*/ +long nvme_ctrl_get_command_error_count (nvme_ctrl_t c); + +/** +* nvme_ctrl_get_reset_count() - Get controller reset count +* @c: Controller instance +* +* Return: Number of timer controller @c is reset +*/ +long nvme_ctrl_get_reset_count (nvme_ctrl_t c); + +/** +* nvme_ctrl_get_reconnect_count() - Get controller reconnect count +* @c: Controller instance +* +* Return: Number of times controller has to reconnect to the target +*/ +long nvme_ctrl_get_reconnect_count (nvme_ctrl_t c); +/** * nvme_ctrl_identify() - Issues an 'identify controller' command * @c: Controller instance
Signature · 1 line
2.53.0
Hi Nilay,
Quoted 22 lines · Nilay Shroff
Certain NVMe attributes and statistics can change dynamically at runtime. However, the current libnvme implementation caches attribute values while scanning and building the topology. Subsequent libnvme API calls return these cached values.
While this approach works well for one-shot nvme-cli commands, it is not suitable for use cases that require upto date information. In particular, real-time monitoring tools such as nvme-top require access to the latest (non-cached) values of such attributes.
To address this, this patchset introduces support for retrieving non-cached values for selected attributes whose values may change dynamically. The first three patches disable auto-generated accessors for
ana_state,numa_nodes, and iopolicy using "!accessors:none", and provide custom implementations that always return the latest values.In addition, libnvme lacks support for retrieving gendisk statistics, which provide useful insight into disk activity (e.g., number of I/Os processed, time spent servicing I/O, and in-flight I/O counts). This patchset adds support for retrieving gendisk I/O statistics for both per-path and namespace gendisks.
Quoted 8 lines
Finally, this series adds support for retrieving diagnostic counters at different levels, including per-path, namespace, nshead, and controller. These counters should improve visibility into NVMe native multipath behavior.
All of the above statistics and counters can be leveraged by tools such as nvme-top to provide real-time monitoring and analysis.
As usual, feedback and suggestions are welcome!
Looks way better. Thanks!
Unfortunately, the big renaming of the API has happened, thus could I ask to rebase (and rename the symbols accordingly)?
One thing I notices, is the first set of statistic getters have the 'bool diffstat' argument, the second one not. To make this a bit more consistent I'd say it would be great to have it on all functions. WDYT?
Thanks,
Daniel
Quoted 32 lines · Daniel Wagner
Hi Nilay,
Quoted 29 lines · Nilay Shroff
Certain NVMe attributes and statistics can change dynamically at runtime. However, the current libnvme implementation caches attribute values while scanning and building the topology. Subsequent libnvme API calls return these cached values.
While this approach works well for one-shot nvme-cli commands, it is not suitable for use cases that require upto date information. In particular, real-time monitoring tools such as nvme-top require access to the latest (non-cached) values of such attributes.
To address this, this patchset introduces support for retrieving non-cached values for selected attributes whose values may change dynamically. The first three patches disable auto-generated accessors for
ana_state,numa_nodes, and iopolicy using "!accessors:none", and provide custom implementations that always return the latest values.In addition, libnvme lacks support for retrieving gendisk statistics, which provide useful insight into disk activity (e.g., number of I/Os processed, time spent servicing I/O, and in-flight I/O counts). This patchset adds support for retrieving gendisk I/O statistics for both per-path and namespace gendisks.
Finally, this series adds support for retrieving diagnostic counters at different levels, including per-path, namespace, nshead, and controller. These counters should improve visibility into NVMe native multipath behavior.
All of the above statistics and counters can be leveraged by tools such as nvme-top to provide real-time monitoring and analysis.
Quoted 7 lines
Quoted 1 line
As usual, feedback and suggestions are welcome!
Looks way better. Thanks!
Unfortunately, the big renaming of the API has happened, thus could I ask to rebase (and rename the symbols accordingly)?
Yes sure, I will rebase the code and spin a new revision.
Quoted 4 lines
One thing I notices, is the first set of statistic getters have the 'bool diffstat' argument, the second one not. To make this a bit more consistent I'd say it would be great to have it on all functions. WDYT?
The diffstat value is only set during the refresh/update phase (i.e., nvme_ns_update_stat() or nvme_path_update_stat()). These refresh APIs take the diffstat argument so that the caller can specify whether they want absolute statistics or differential statistics for getters.
In practice, the caller indicates this preference at refresh time—for
example: nvme_path_update_stat(p, diffstat);
After that, the getter APIs rely on the state established during the refresh. Based on the diffstat setting, they will either:
- return the current absolute values, or
- compute and return the difference between the current and previous statistics.
For example, the following getters:
- nvme_path_get_io_ticks
- nvme_path_get_read_ticks
- nvme_path_get_write_ticks
- nvme_path_get_read_ios
- nvme_path_get_write_ios
- nvme_path_get_read_sectors
- nvme_path_get_write_sectors
Will return differential values if diffstat was set to true during the refresh. Otherwise, they return absolute values. Does this make sense?
Thanks,
--Nilay