[PATCH] nvme-pci: add NVMe controller statistics

Keith Busch kbusch at kernel.org
Wed May 28 13:35:07 PDT 2025


On Thu, May 29, 2025 at 02:02:56AM +0900, Tokunori Ikegami wrote:
> +static ssize_t stats_show(struct device *dev, struct device_attribute *attr,
> +			  char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	struct nvme_stats *stats = &ctrl->stats;
> +
> +	return sysfs_emit(buf,
> +			  "timeouts: %lu, aborts: %lu, resets: %lu, disables: %lu\n",
> +			  stats->timeouts, stats->aborts, stats->resets,
> +			  stats->disables);
> +}

Specifically on sysfs attributes, the intended use was one file, one
attribute, one value. That makes programatically parsing these much
easier. So what you'd do instead is create 4 new files called
"timeouts", "aborts", "resets", and "disables", and each just print out
a sinlge number instead of this more complex output. If you're concerned
with polluting the nvme device's sysfs directory, you can also make a
sub-directory called "stats" to collect such things.

That principle hasn't always been strictly followed, but let's not
introduce new deviants.

As to what you're tracking and reporting here, I'm not convinced it's
useful. It's just a snapshot of what's happened for the lifetime of that
instance, which may not be very long.



More information about the Linux-nvme mailing list