[v2,08/10] dma/ioat: add statistics

Message ID 20210903111734.2734545-9-conor.walsh@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series dma: add dmadev driver for ioat devices |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Conor Walsh Sept. 3, 2021, 11:17 a.m. UTC
Add statistic tracking for operations in IOAT.

Signed-off-by: Conor Walsh <conor.walsh@intel.com>
---
 doc/guides/dmadevs/ioat.rst    | 23 +++++++++++++++++++
 drivers/dma/ioat/ioat_dmadev.c | 40 ++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
  

Comments

Kevin Laatz Sept. 7, 2021, 10:12 a.m. UTC | #1
On 03/09/2021 12:17, Conor Walsh wrote:
> Add statistic tracking for operations in IOAT.
>
> Signed-off-by: Conor Walsh <conor.walsh@intel.com>
> ---
>   doc/guides/dmadevs/ioat.rst    | 23 +++++++++++++++++++
>   drivers/dma/ioat/ioat_dmadev.c | 40 ++++++++++++++++++++++++++++++++++
>   2 files changed, 63 insertions(+)
>
Reviewed-by: Kevin Laatz <kevin.laatz@intel.com>
  

Patch

diff --git a/doc/guides/dmadevs/ioat.rst b/doc/guides/dmadevs/ioat.rst
index 9ea5708090..620b676718 100644
--- a/doc/guides/dmadevs/ioat.rst
+++ b/doc/guides/dmadevs/ioat.rst
@@ -189,3 +189,26 @@  of memory is overwritten, or filled, with a short pattern of data.
 Fill operations can be performed in much the same was as copy operations
 described above, just using the ``rte_dmadev_fill()`` function rather
 than the ``rte_dmadev_copy()`` function.
+
+Querying Device Statistics
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The statistics from the IOAT dmadev device can be got via the
+``rte_dmadev_stats_get()`` API in the ``rte_dmadev`` library.
+
+The statistics returned for each IOAT device are:
+
+* ``submitted``: The number of operations submitted to the device.
+* ``completed``: The number of operations successfully completed by the device.
+* ``errors``: The number of operations that failed.
+
+The stats function can be used as follows:
+
+.. code-block:: C
+
+   struct rte_dmadev_stats stats;
+   if (rte_dmadev_stats_get(dmadev_id, vchan, &stats) >= 0) {
+      printf("Total submitted ops: %lu", stats.submitted);
+      printf("Total completed ops: %lu", stats.completed);
+      printf("Total failed ops: %lu", stats.errors);
+   }
diff --git a/drivers/dma/ioat/ioat_dmadev.c b/drivers/dma/ioat/ioat_dmadev.c
index 715beb3b7e..743fb2f558 100644
--- a/drivers/dma/ioat/ioat_dmadev.c
+++ b/drivers/dma/ioat/ioat_dmadev.c
@@ -198,6 +198,8 @@  __submit(struct ioat_dmadev *ioat)
 {
 	*ioat->doorbell = ioat->next_write - ioat->offset;
 
+	ioat->stats.submitted += (uint16_t)(ioat->next_write - ioat->last_write);
+
 	ioat->last_write = ioat->next_write;
 }
 
@@ -326,6 +328,10 @@  ioat_dev_dump(const struct rte_dmadev *dev, FILE *f)
 	fprintf(f, "    Dest: %#lx\n", ioat->desc_ring[ioat->next_read & mask].dest_addr);
 	fprintf(f, "    Next: %#lx\n", ioat->desc_ring[ioat->next_read & mask].next);
 	fprintf(f, "  }\n");
+	fprintf(f, "  Key Stats { submitted: %"PRIu64", comp: %"PRIu64", failed: %"PRIu64" }\n",
+			ioat->stats.submitted,
+			ioat->stats.completed,
+			ioat->stats.errors);
 
 	return 0;
 }
@@ -415,6 +421,9 @@  ioat_completed(struct rte_dmadev *dev, uint16_t qid __rte_unused, const uint16_t
 		*last_idx = ioat->next_read - 2;
 	}
 
+	ioat->stats.completed += count;
+	ioat->stats.errors += fails;
+
 	return count;
 }
 
@@ -465,9 +474,38 @@  ioat_completed_status(struct rte_dmadev *dev, uint16_t qid __rte_unused,
 
 	*last_idx = ioat->next_read - 1;
 
+	ioat->stats.completed += count;
+	ioat->stats.errors += fails;
+
 	return count;
 }
 
+/* Retrieve the generic stats of a DMA device. */
+static int
+ioat_stats_get(const struct rte_dmadev *dev, uint16_t vchan __rte_unused,
+		struct rte_dmadev_stats *rte_stats, uint32_t size)
+{
+	struct rte_dmadev_stats *stats = (&((struct ioat_dmadev *)dev->dev_private)->stats);
+
+	if (size < sizeof(rte_stats))
+		return -EINVAL;
+	if (rte_stats == NULL)
+		return -EINVAL;
+
+	*rte_stats = *stats;
+	return 0;
+}
+
+/* Reset the generic stat counters for the DMA device. */
+static int
+ioat_stats_reset(struct rte_dmadev *dev, uint16_t vchan __rte_unused)
+{
+	struct ioat_dmadev *ioat = dev->dev_private;
+
+	memset(&ioat->stats, 0, sizeof(ioat->stats));
+	return 0;
+}
+
 /* Create a DMA device. */
 static int
 ioat_dmadev_create(const char *name, struct rte_pci_device *dev)
@@ -479,6 +517,8 @@  ioat_dmadev_create(const char *name, struct rte_pci_device *dev)
 		.dev_info_get = ioat_dev_info_get,
 		.dev_start = ioat_dev_start,
 		.dev_stop = ioat_dev_stop,
+		.stats_get = ioat_stats_get,
+		.stats_reset = ioat_stats_reset,
 		.vchan_setup = ioat_vchan_setup,
 	};