ethdev: remove redundant id field in xstats name lookup
authorRemy Horton <remy.horton@intel.com>
Fri, 1 Jul 2016 13:16:45 +0000 (14:16 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 1 Jul 2016 14:09:06 +0000 (16:09 +0200)
For all drivers that currently implement xstats, the id field in the
rte_eth_stats_name structure equals the entry's array index. This
patch eliminates the redundant id field as a direct index lookup is
faster than a search for the matching id field.

Suggested-by: Olivier Matz <olivier.matz@6wind.com>
Signed-off-by: Remy Horton <remy.horton@intel.com>
app/proc_info/main.c
app/test-pmd/config.c
doc/guides/prog_guide/poll_mode_drv.rst
drivers/net/e1000/igb_ethdev.c
drivers/net/fm10k/fm10k_ethdev.c
drivers/net/i40e/i40e_ethdev.c
drivers/net/i40e/i40e_ethdev_vf.c
drivers/net/ixgbe/ixgbe_ethdev.c
drivers/net/virtio/virtio_ethdev.c
lib/librte_ether/rte_ethdev.c
lib/librte_ether/rte_ethdev.h

index f2063fa..6dc0bbb 100644 (file)
@@ -246,7 +246,6 @@ nic_xstats_display(uint8_t port_id)
        struct rte_eth_xstat_name *xstats_names;
        struct rte_eth_xstat *xstats;
        int len, ret, i;
-       int idx_name;
        static const char *nic_stats_border = "########################";
 
        len = rte_eth_xstats_get_names(port_id, NULL, 0);
@@ -284,13 +283,9 @@ nic_xstats_display(uint8_t port_id)
        }
 
        for (i = 0; i < len; i++)
-               for (idx_name = 0; idx_name < len; idx_name++)
-                       if (xstats_names[idx_name].id == xstats[i].id) {
-                               printf("%s: %"PRIu64"\n",
-                                       xstats_names[idx_name].name,
-                                       xstats[i].value);
-                               break;
-                       }
+               printf("%s: %"PRIu64"\n",
+                       xstats_names[i].name,
+                       xstats[i].value);
 
        printf("%s############################\n",
                           nic_stats_border);
index de60284..c5865f9 100644 (file)
@@ -261,7 +261,7 @@ void
 nic_xstats_display(portid_t port_id)
 {
        struct rte_eth_xstat *xstats;
-       int cnt_xstats, idx_xstat, idx_name;
+       int cnt_xstats, idx_xstat;
        struct rte_eth_xstat_name *xstats_names;
 
        printf("###### NIC extended statistics for port %-2d\n", port_id);
@@ -306,13 +306,9 @@ nic_xstats_display(portid_t port_id)
 
        /* Display xstats */
        for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++)
-               for (idx_name = 0; idx_name < cnt_xstats; idx_name++)
-                       if (xstats_names[idx_name].id == xstats[idx_xstat].id) {
-                               printf("%s: %"PRIu64"\n",
-                                       xstats_names[idx_name].name,
-                                       xstats[idx_xstat].value);
-                               break;
-                       }
+               printf("%s: %"PRIu64"\n",
+                       xstats_names[idx_xstat].name,
+                       xstats[idx_xstat].value);
        free(xstats_names);
        free(xstats);
 }
index 802fb8f..bf3ea9f 100644 (file)
@@ -309,17 +309,13 @@ functions:
   information.
 
 Each ``struct rte_eth_xstat`` contains an identifier and value pair, and
-each ``struct rte_eth_xstat_name`` contains an identifier and string pair.
-Each identifier within ``struct rte_eth_xstat`` must have a corresponding
-entry in ``struct rte_eth_xstat_name`` with a matching identifier. These
-identifiers, as well as the number of extended statistic exposed, must
-remain constant during runtime.
-
-Note that extended statistic identifiers are driver-specific, and hence
-might not be the same for different ports. Although it is expected that
-drivers will make the identifiers used within ``struct rte_eth_xstat`` and
-``struct rte_eth_xstat_name`` entries match the entries' array index, this
-property should not be relied on by applications for lookups.
+each ``struct rte_eth_xstat_name`` contains a string. Each identifier
+within the ``struct rte_eth_xstat`` lookup array must have a corresponding
+entry in the ``struct rte_eth_xstat_name`` lookup array. Within the latter
+the index of the entry is the identifier the string is associated with.
+These identifiers, as well as the number of extended statistic exposed, must
+remain constant during runtime. Note that extended statistic identifiers are
+driver-specific, and hence might not be the same for different ports.
 
 A naming scheme exists for the strings exposed to clients of the API. This is
 to allow scraping of the API for statistics of interest. The naming scheme uses
index dea50f3..5067d20 100644 (file)
@@ -1802,7 +1802,6 @@ static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
        for (i = 0; i < IGB_NB_XSTATS; i++) {
                snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
                         "%s", rte_igb_stats_strings[i].name);
-               xstats_names[i].id = i;
        }
 
        return IGB_NB_XSTATS;
@@ -1889,7 +1888,6 @@ static int eth_igbvf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                        snprintf(xstats_names[i].name,
                                sizeof(xstats_names[i].name), "%s",
                                rte_igbvf_stats_strings[i].name);
-                       xstats_names[i].id = i;
                }
        return IGBVF_NB_XSTATS;
 }
index 6d6bbe3..eb77705 100644 (file)
@@ -1270,7 +1270,6 @@ static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                        snprintf(xstats_names[count].name,
                                sizeof(xstats_names[count].name),
                                "%s", fm10k_hw_stats_strings[count].name);
-                       xstats_names[count].id = count;
                        count++;
                }
 
@@ -1281,7 +1280,6 @@ static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "rx_q%u_%s", q,
                                        fm10k_hw_stats_rx_q_strings[i].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                        for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
@@ -1289,7 +1287,6 @@ static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "tx_q%u_%s", q,
                                        fm10k_hw_stats_tx_q_strings[i].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                }
index c07da1b..f414d93 100644 (file)
@@ -2431,7 +2431,6 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                snprintf(xstats_names[count].name,
                         sizeof(xstats_names[count].name),
                         "%s", rte_i40e_stats_strings[i].name);
-               xstats_names[count].id = count;
                count++;
        }
 
@@ -2440,7 +2439,6 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                snprintf(xstats_names[count].name,
                        sizeof(xstats_names[count].name),
                         "%s", rte_i40e_hw_port_strings[i].name);
-               xstats_names[count].id = count;
                count++;
        }
 
@@ -2450,7 +2448,6 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                                 sizeof(xstats_names[count].name),
                                 "rx_priority%u_%s", prio,
                                 rte_i40e_rxq_prio_strings[i].name);
-                       xstats_names[count].id = count;
                        count++;
                }
        }
@@ -2461,7 +2458,6 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                                 sizeof(xstats_names[count].name),
                                 "tx_priority%u_%s", prio,
                                 rte_i40e_txq_prio_strings[i].name);
-                       xstats_names[count].id = count;
                        count++;
                }
        }
@@ -2490,7 +2486,6 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 
        /* Get stats from i40e_eth_stats struct */
        for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
-               xstats[count].id = count;
                xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
                        rte_i40e_stats_strings[i].offset);
                count++;
@@ -2498,7 +2493,6 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 
        /* Get individiual stats from i40e_hw_port struct */
        for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
-               xstats[count].id = count;
                xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
                        rte_i40e_hw_port_strings[i].offset);
                count++;
@@ -2506,7 +2500,6 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 
        for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
                for (prio = 0; prio < 8; prio++) {
-                       xstats[count].id = count;
                        xstats[count].value =
                                *(uint64_t *)(((char *)hw_stats) +
                                rte_i40e_rxq_prio_strings[i].offset +
@@ -2517,7 +2510,6 @@ i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 
        for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
                for (prio = 0; prio < 8; prio++) {
-                       xstats[count].id = count;
                        xstats[count].value =
                                *(uint64_t *)(((char *)hw_stats) +
                                rte_i40e_txq_prio_strings[i].offset +
index f1079b7..7b6df1d 100644 (file)
@@ -999,7 +999,6 @@ static int i40evf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                        snprintf(xstats_names[i].name,
                                sizeof(xstats_names[i].name),
                                "%s", rte_i40evf_stats_strings[i].name);
-                       xstats_names[i].id = i;
                }
        return I40EVF_NB_XSTATS;
 }
index d61af37..0629b42 100644 (file)
@@ -2784,7 +2784,6 @@ static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
                /* Extended stats from ixgbe_hw_stats */
                for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
-                       xstats_names[count].id = count;
                        snprintf(xstats_names[count].name,
                                sizeof(xstats_names[count].name),
                                "%s",
@@ -2795,7 +2794,6 @@ static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                /* RX Priority Stats */
                for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
                        for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
-                               xstats_names[count].id = count;
                                snprintf(xstats_names[count].name,
                                        sizeof(xstats_names[count].name),
                                        "rx_priority%u_%s", i,
@@ -2807,7 +2805,6 @@ static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                /* TX Priority Stats */
                for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
                        for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
-                               xstats_names[count].id = count;
                                snprintf(xstats_names[count].name,
                                        sizeof(xstats_names[count].name),
                                        "tx_priority%u_%s", i,
@@ -2868,7 +2865,6 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
        /* Extended stats from ixgbe_hw_stats */
        count = 0;
        for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
-               xstats[count].id = count;
                xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
                                rte_ixgbe_stats_strings[i].offset);
                count++;
@@ -2877,7 +2873,6 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
        /* RX Priority Stats */
        for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
                for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
                                        rte_ixgbe_rxq_strings[stat].offset +
                                        (sizeof(uint64_t) * i));
@@ -2888,7 +2883,6 @@ ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
        /* TX Priority Stats */
        for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
                for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
                                        rte_ixgbe_txq_strings[stat].offset +
                                        (sizeof(uint64_t) * i));
@@ -2959,7 +2953,6 @@ ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 
        /* Extended stats */
        for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
-               xstats[i].id = i;
                xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
                        rte_ixgbevf_stats_strings[i].offset);
        }
index c89fa9f..480daa3 100644 (file)
@@ -788,7 +788,6 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "rx_q%u_%s", i,
                                        rte_virtio_rxq_stat_strings[t].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                }
@@ -802,7 +801,6 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "tx_q%u_%s", i,
                                        rte_virtio_txq_stat_strings[t].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                }
@@ -833,7 +831,6 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                unsigned t;
 
                for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)rxvq) +
                                rte_virtio_rxq_stat_strings[t].offset);
                        count++;
@@ -849,7 +846,6 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                unsigned t;
 
                for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)txvq) +
                                rte_virtio_txq_stat_strings[t].offset);
                        count++;
index 42aaef7..eac260f 100644 (file)
@@ -1557,7 +1557,6 @@ rte_eth_xstats_get_names(uint8_t port_id,
                cnt_used_entries = 0;
 
        for (idx = 0; idx < RTE_NB_STATS; idx++) {
-               xstats_names[cnt_used_entries].id = cnt_used_entries;
                snprintf(xstats_names[cnt_used_entries].name,
                        sizeof(xstats_names[0].name),
                        "%s", rte_stats_strings[idx].name);
@@ -1565,7 +1564,6 @@ rte_eth_xstats_get_names(uint8_t port_id,
        }
        for (id_queue = 0; id_queue < dev->data->nb_rx_queues; id_queue++) {
                for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
-                       xstats_names[cnt_used_entries].id = cnt_used_entries;
                        snprintf(xstats_names[cnt_used_entries].name,
                                sizeof(xstats_names[0].name),
                                "rx_q%u%s",
@@ -1576,7 +1574,6 @@ rte_eth_xstats_get_names(uint8_t port_id,
        }
        for (id_queue = 0; id_queue < dev->data->nb_tx_queues; id_queue++) {
                for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
-                       xstats_names[cnt_used_entries].id = cnt_used_entries;
                        snprintf(xstats_names[cnt_used_entries].name,
                                sizeof(xstats_names[0].name),
                                "tx_q%u%s",
index 54c1a75..da7902f 100644 (file)
@@ -945,7 +945,6 @@ struct rte_eth_xstat {
  */
 struct rte_eth_xstat_name {
        char name[RTE_ETH_XSTATS_NAME_SIZE];
-       uint64_t id;
 };
 
 #define ETH_DCB_NUM_TCS    8