The current extended ethernet statistics fetching involve doing several
string operations, which causes performance issues if there are lots of
statistics and/or network interfaces. This patch changes the i40e driver
to use the new API that seperates name string and value queries.

Signed-off-by: Remy Horton <remy.horton at intel.com>
---
 drivers/net/i40e/i40e_ethdev.c    | 81 ++++++++++++++++++++++++++++++++-------
 drivers/net/i40e/i40e_ethdev_vf.c | 25 ++++++++++--
 2 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 24777d5..e0ce695 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -306,6 +306,9 @@ static void i40e_dev_stats_get(struct rte_eth_dev *dev,
                               struct rte_eth_stats *stats);
 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
                               struct rte_eth_xstats *xstats, unsigned n);
+static int i40e_dev_xstats_names(struct rte_eth_dev *dev,
+                                struct rte_eth_xstats_name *ptr_names,
+                                unsigned limit);
 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
                                            uint16_t queue_id,
@@ -467,6 +470,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
        .link_update                  = i40e_dev_link_update,
        .stats_get                    = i40e_dev_stats_get,
        .xstats_get                   = i40e_dev_xstats_get,
+       .xstats_names                 = i40e_dev_xstats_names,
        .stats_reset                  = i40e_dev_stats_reset,
        .xstats_reset                 = i40e_dev_stats_reset,
        .queue_stats_mapping_set      = i40e_dev_queue_stats_mapping_set,
@@ -2205,6 +2209,59 @@ i40e_xstats_calc_num(void)
                (I40E_NB_TXQ_PRIO_XSTATS * 8);
 }

+static int i40e_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+                                struct rte_eth_xstats_name *ptr_names,
+                                __rte_unused unsigned limit)
+{
+       unsigned count = 0;
+       unsigned i, prio;
+
+       if (ptr_names == NULL)
+               return i40e_xstats_calc_num();
+
+       /* Note: limit checked in rte_eth_xstats_names() */
+
+       /* Get stats from i40e_eth_stats struct */
+       for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
+               snprintf(ptr_names[count].name, sizeof(ptr_names[count].name),
+                        "%s", rte_i40e_stats_strings[i].name);
+               ptr_names[count].id = count;
+               count++;
+       }
+
+       /* Get individiual stats from i40e_hw_port struct */
+       for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
+               snprintf(ptr_names[count].name,
+                       sizeof(ptr_names[count].name),
+                        "%s", rte_i40e_hw_port_strings[i].name);
+               ptr_names[count].id = count;
+               count++;
+       }
+
+       for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
+               for (prio = 0; prio < 8; prio++) {
+                       snprintf(ptr_names[count].name,
+                                sizeof(ptr_names[count].name),
+                                "rx_priority%u_%s", prio,
+                                rte_i40e_rxq_prio_strings[i].name);
+                       ptr_names[count].id = count;
+                       count++;
+               }
+       }
+
+       for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
+               for (prio = 0; prio < 8; prio++) {
+                       snprintf(ptr_names[count].name,
+                                sizeof(ptr_names[count].name),
+                                "tx_priority%u_%s", prio,
+                                rte_i40e_txq_prio_strings[i].name);
+                       ptr_names[count].id = count;
+                       count++;
+               }
+       }
+       return count;
+}
+
 static int
 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
                    unsigned n)
@@ -2227,8 +2284,8 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct 
rte_eth_xstats *xstats,

        /* Get stats from i40e_eth_stats struct */
        for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
-               snprintf(xstats[count].name, sizeof(xstats[count].name),
-                        "%s", rte_i40e_stats_strings[i].name);
+               xstats[count].name[0] = '\0';
+               xstats[count].id = count;
                xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
                        rte_i40e_stats_strings[i].offset);
                count++;
@@ -2236,19 +2293,17 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct 
rte_eth_xstats *xstats,

        /* Get individiual stats from i40e_hw_port struct */
        for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
-               snprintf(xstats[count].name, sizeof(xstats[count].name),
-                        "%s", rte_i40e_hw_port_strings[i].name);
+               xstats[count].name[0] = '\0';
+               xstats[count].id = count;
                xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
-                               rte_i40e_hw_port_strings[i].offset);
+                       rte_i40e_hw_port_strings[i].offset);
                count++;
        }

        for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
                for (prio = 0; prio < 8; prio++) {
-                       snprintf(xstats[count].name,
-                                sizeof(xstats[count].name),
-                                "rx_priority%u_%s", prio,
-                                rte_i40e_rxq_prio_strings[i].name);
+                       xstats[count].name[0] = '\0';
+                       xstats[count].id = count;
                        xstats[count].value =
                                *(uint64_t *)(((char *)hw_stats) +
                                rte_i40e_rxq_prio_strings[i].offset +
@@ -2259,10 +2314,8 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct 
rte_eth_xstats *xstats,

        for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
                for (prio = 0; prio < 8; prio++) {
-                       snprintf(xstats[count].name,
-                                sizeof(xstats[count].name),
-                                "tx_priority%u_%s", prio,
-                                rte_i40e_txq_prio_strings[i].name);
+                       xstats[count].name[0] = '\0';
+                       xstats[count].id = count;
                        xstats[count].value =
                                *(uint64_t *)(((char *)hw_stats) +
                                rte_i40e_txq_prio_strings[i].offset +
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c 
b/drivers/net/i40e/i40e_ethdev_vf.c
index 90682ac..c3301c5 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -112,6 +112,9 @@ static void i40evf_dev_stats_get(struct rte_eth_dev *dev,
                                struct rte_eth_stats *stats);
 static int i40evf_dev_xstats_get(struct rte_eth_dev *dev,
                                 struct rte_eth_xstats *xstats, unsigned n);
+static int i40evf_dev_xstats_names(struct rte_eth_dev *dev,
+                                  struct rte_eth_xstats_name *ptr_names,
+                                  unsigned limit);
 static void i40evf_dev_xstats_reset(struct rte_eth_dev *dev);
 static int i40evf_vlan_filter_set(struct rte_eth_dev *dev,
                                  uint16_t vlan_id, int on);
@@ -196,6 +199,7 @@ static const struct eth_dev_ops i40evf_eth_dev_ops = {
        .link_update          = i40evf_dev_link_update,
        .stats_get            = i40evf_dev_stats_get,
        .xstats_get           = i40evf_dev_xstats_get,
+       .xstats_names         = i40evf_dev_xstats_names,
        .xstats_reset         = i40evf_dev_xstats_reset,
        .dev_close            = i40evf_dev_close,
        .dev_infos_get        = i40evf_dev_info_get,
@@ -984,6 +988,21 @@ i40evf_dev_xstats_reset(struct rte_eth_dev *dev)
        vf->vsi.eth_stats_offset = vf->vsi.eth_stats;
 }

+static int i40evf_dev_xstats_names(__rte_unused struct rte_eth_dev *dev,
+                                  struct rte_eth_xstats_name *ptr_names,
+                                  __rte_unused unsigned limit)
+{
+       unsigned i;
+
+       if (ptr_names != NULL)
+               for (i = 0; i < I40EVF_NB_XSTATS; i++) {
+                       snprintf(ptr_names[i].name, sizeof(ptr_names[i].name),
+                               "%s", rte_i40evf_stats_strings[i].name);
+                       ptr_names[i].id = i;
+               }
+       return I40EVF_NB_XSTATS;
+}
+
 static int i40evf_dev_xstats_get(struct rte_eth_dev *dev,
                                 struct rte_eth_xstats *xstats, unsigned n)
 {
@@ -1003,8 +1022,8 @@ static int i40evf_dev_xstats_get(struct rte_eth_dev *dev,

        /* loop over xstats array and values from pstats */
        for (i = 0; i < I40EVF_NB_XSTATS; i++) {
-               snprintf(xstats[i].name, sizeof(xstats[i].name),
-                        "%s", rte_i40evf_stats_strings[i].name);
+               xstats[i].name[0] = '\0';
+               xstats[i].id = i;
                xstats[i].value = *(uint64_t *)(((char *)pstats) +
                        rte_i40evf_stats_strings[i].offset);
        }
-- 
2.5.5

Reply via email to