raw/ioat: add statistics functions
authorBruce Richardson <bruce.richardson@intel.com>
Tue, 2 Jul 2019 14:12:29 +0000 (15:12 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 4 Jul 2019 07:44:35 +0000 (09:44 +0200)
Add stats functions to track what is happening in the driver, and put
unit tests to check those.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Jiayu Hu <jiayu.hu@intel.com>
Tested-by: Harry van Haaren <harry.van.haaren@intel.com>
doc/guides/rawdevs/ioat_rawdev.rst
drivers/raw/ioat/ioat_rawdev.c
drivers/raw/ioat/ioat_rawdev_test.c
drivers/raw/ioat/rte_ioat_rawdev.h

index a0594d2..40210b3 100644 (file)
@@ -149,3 +149,17 @@ The following code shows how the device is configured in
 
 Once configured, the device can then be made ready for use by calling the
 ``rte_rawdev_start()`` API.
+
+Querying Device Statistics
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The statistics from the IOAT rawdev device can be got via the xstats
+functions in the ``rte_rawdev`` library, i.e.
+``rte_rawdev_xstats_names_get()``, ``rte_rawdev_xstats_get()`` and
+``rte_rawdev_xstats_by_name_get``. The statistics returned for each device
+instance are:
+
+* ``failed_enqueues``
+* ``successful_enqueues``
+* ``copies_started``
+* ``copies_completed``
index 0c91b35..d509b66 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <rte_cycles.h>
 #include <rte_bus_pci.h>
+#include <rte_string_fns.h>
 #include <rte_rawdev_pmd.h>
 
 #include "rte_ioat_rawdev.h"
@@ -119,6 +120,47 @@ ioat_dev_info_get(struct rte_rawdev *dev, rte_rawdev_obj_t dev_info)
                cfg->ring_size = ioat->ring_size;
 }
 
+static const char * const xstat_names[] = {
+               "failed_enqueues", "successful_enqueues",
+               "copies_started", "copies_completed"
+};
+
+static int
+ioat_xstats_get(const struct rte_rawdev *dev, const unsigned int ids[],
+               uint64_t values[], unsigned int n)
+{
+       const struct rte_ioat_rawdev *ioat = dev->dev_private;
+       unsigned int i;
+
+       for (i = 0; i < n; i++) {
+               switch (ids[i]) {
+               case 0: values[i] = ioat->enqueue_failed; break;
+               case 1: values[i] = ioat->enqueued; break;
+               case 2: values[i] = ioat->started; break;
+               case 3: values[i] = ioat->completed; break;
+               default: values[i] = 0; break;
+               }
+       }
+       return n;
+}
+
+static int
+ioat_xstats_get_names(const struct rte_rawdev *dev,
+               struct rte_rawdev_xstats_name *names,
+               unsigned int size)
+{
+       unsigned int i;
+
+       RTE_SET_USED(dev);
+       if (size < RTE_DIM(xstat_names))
+               return RTE_DIM(xstat_names);
+
+       for (i = 0; i < RTE_DIM(xstat_names); i++)
+               strlcpy(names[i].name, xstat_names[i], sizeof(names[i]));
+
+       return RTE_DIM(xstat_names);
+}
+
 extern int ioat_rawdev_test(uint16_t dev_id);
 
 static int
@@ -129,6 +171,8 @@ ioat_rawdev_create(const char *name, struct rte_pci_device *dev)
                        .dev_start = ioat_dev_start,
                        .dev_stop = ioat_dev_stop,
                        .dev_info_get = ioat_dev_info_get,
+                       .xstats_get = ioat_xstats_get,
+                       .xstats_get_names = ioat_xstats_get_names,
                        .dev_selftest = ioat_rawdev_test,
        };
 
index 5375da2..ab67181 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <inttypes.h>
 #include "rte_rawdev.h"
 #include "rte_ioat_rawdev.h"
 
@@ -13,6 +14,11 @@ ioat_rawdev_test(uint16_t dev_id)
 #define IOAT_TEST_RINGSIZE 512
        struct rte_ioat_rawdev_config p = { .ring_size = -1 };
        struct rte_rawdev_info info = { .dev_private = &p };
+       struct rte_rawdev_xstats_name *snames = NULL;
+       uint64_t *stats = NULL;
+       unsigned int *ids = NULL;
+       unsigned int nb_xstats;
+       unsigned int i;
 
        rte_rawdev_info_get(dev_id, &info);
        if (p.ring_size != 0) {
@@ -37,5 +43,44 @@ ioat_rawdev_test(uint16_t dev_id)
                printf("Error with rte_rawdev_start()\n");
                return -1;
        }
+
+       /* allocate memory for xstats names and values */
+       nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
+
+       snames = malloc(sizeof(*snames) * nb_xstats);
+       if (snames == NULL) {
+               printf("Error allocating xstat names memory\n");
+               goto err;
+       }
+       rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
+
+       ids = malloc(sizeof(*ids) * nb_xstats);
+       if (ids == NULL) {
+               printf("Error allocating xstat ids memory\n");
+               goto err;
+       }
+       for (i = 0; i < nb_xstats; i++)
+               ids[i] = i;
+
+       stats = malloc(sizeof(*stats) * nb_xstats);
+       if (stats == NULL) {
+               printf("Error allocating xstat memory\n");
+               goto err;
+       }
+
+       rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
+       for (i = 0; i < nb_xstats; i++)
+               printf("%s: %"PRIu64"   ", snames[i].name, stats[i]);
+       printf("\n");
+
+       free(snames);
+       free(stats);
+       free(ids);
        return 0;
+
+err:
+       free(snames);
+       free(stats);
+       free(ids);
+       return -1;
 }
index f2cf98c..d532681 100644 (file)
@@ -54,6 +54,12 @@ struct rte_ioat_rawdev {
        struct rte_ioat_generic_hw_desc *desc_ring;
        __m128i *hdls; /* completion handles for returning to user */
 
+       /* some statistics for tracking, if added/changed update xstats fns*/
+       uint64_t enqueue_failed __rte_cache_aligned;
+       uint64_t enqueued;
+       uint64_t started;
+       uint64_t completed;
+
        /* to report completions, the device will write status back here */
        volatile uint64_t status __rte_cache_aligned;
 };