From: Remy Horton Date: Fri, 1 Jul 2016 13:16:45 +0000 (+0100) Subject: ethdev: remove redundant id field in xstats name lookup X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=d085232a14bc40451aecdcf490abedcb85b438b7;p=dpdk.git ethdev: remove redundant id field in xstats name lookup 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 Signed-off-by: Remy Horton --- diff --git a/app/proc_info/main.c b/app/proc_info/main.c index f2063fa3c9..6dc0bbb8bd 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -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); diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index de60284da4..c5865f953c 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -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); } diff --git a/doc/guides/prog_guide/poll_mode_drv.rst b/doc/guides/prog_guide/poll_mode_drv.rst index 802fb8f888..bf3ea9fde2 100644 --- a/doc/guides/prog_guide/poll_mode_drv.rst +++ b/doc/guides/prog_guide/poll_mode_drv.rst @@ -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 diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c index dea50f3766..5067d208a6 100644 --- a/drivers/net/e1000/igb_ethdev.c +++ b/drivers/net/e1000/igb_ethdev.c @@ -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; } diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c index 6d6bbe3fe5..eb77705e3b 100644 --- a/drivers/net/fm10k/fm10k_ethdev.c +++ b/drivers/net/fm10k/fm10k_ethdev.c @@ -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++; } } diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c index c07da1bbed..f414d9386b 100644 --- a/drivers/net/i40e/i40e_ethdev.c +++ b/drivers/net/i40e/i40e_ethdev.c @@ -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 + diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c index f1079b7f6b..7b6df1d846 100644 --- a/drivers/net/i40e/i40e_ethdev_vf.c +++ b/drivers/net/i40e/i40e_ethdev_vf.c @@ -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; } diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c index d61af376ff..0629b426e6 100644 --- a/drivers/net/ixgbe/ixgbe_ethdev.c +++ b/drivers/net/ixgbe/ixgbe_ethdev.c @@ -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); } diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index c89fa9f6b8..480daa37b6 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -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++; diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 42aaef72dd..eac260f15f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -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", diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 54c1a7575e..da7902ff12 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -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