From a954495245c4f9054bf5ed7ab64b555e2e102c19 Mon Sep 17 00:00:00 2001 From: Kuba Kozak Date: Thu, 13 Apr 2017 16:59:25 +0200 Subject: [PATCH] ethdev: get xstats ID by name Introduced new function: rte_eth_xstats_get_id_by_name to retrieve xstats ids by its names. doc: added release note Signed-off-by: Kuba Kozak Acked-by: Harry van Haaren --- doc/guides/rel_notes/release_17_05.rst | 2 ++ lib/librte_ether/rte_ethdev.c | 44 ++++++++++++++++++++++++++ lib/librte_ether/rte_ethdev.h | 21 ++++++++++++ lib/librte_ether/rte_ether_version.map | 1 + 4 files changed, 68 insertions(+) diff --git a/doc/guides/rel_notes/release_17_05.rst b/doc/guides/rel_notes/release_17_05.rst index 96118e8252..ad20e86084 100644 --- a/doc/guides/rel_notes/release_17_05.rst +++ b/doc/guides/rel_notes/release_17_05.rst @@ -457,6 +457,8 @@ API Changes * Added new functions ``rte_eth_xstats_get_all`` and ``rte_eth_xstats_get_names_all to provide backward compatibility for ``rte_eth_xstats_get`` and ``rte_eth_xstats_get_names`` + * Added new function ``rte_eth_xstats_get_id_by_name`` + ABI Changes ----------- diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index fe56f65821..85b173944c 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1378,6 +1378,50 @@ get_xstats_count(uint8_t port_id) return count; } +int +rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name, + uint64_t *id) +{ + int cnt_xstats, idx_xstat; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + + if (!id) { + RTE_PMD_DEBUG_TRACE("Error: id pointer is NULL\n"); + return -1; + } + + if (!xstat_name) { + RTE_PMD_DEBUG_TRACE("Error: xstat_name pointer is NULL\n"); + return -1; + } + + /* Get count */ + cnt_xstats = rte_eth_xstats_get_names(port_id, NULL, 0, NULL); + if (cnt_xstats < 0) { + RTE_PMD_DEBUG_TRACE("Error: Cannot get count of xstats\n"); + return -1; + } + + /* Get id-name lookup table */ + struct rte_eth_xstat_name xstats_names[cnt_xstats]; + + if (cnt_xstats != rte_eth_xstats_get_names( + port_id, xstats_names, cnt_xstats, NULL)) { + RTE_PMD_DEBUG_TRACE("Error: Cannot get xstats lookup\n"); + return -1; + } + + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { + if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) { + *id = idx_xstat; + return 0; + }; + } + + return -EINVAL; +} + int rte_eth_xstats_get_names_v1607(uint8_t port_id, struct rte_eth_xstat_name *xstats_names, diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 21b41e93a5..2f4d2a80cf 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -2287,6 +2287,27 @@ int rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats); */ void rte_eth_stats_reset(uint8_t port_id); + +/** + * Gets the ID of a statistic from its name. + * + * This function searches for the statistics using string compares, and + * as such should not be used on the fast-path. For fast-path retrieval of + * specific statistics, store the ID as provided in *id* from this function, + * and pass the ID to rte_eth_xstats_get() + * + * @param port_id The port to look up statistics from + * @param xstat_name The name of the statistic to return + * @param[out] id A pointer to an app-supplied uint64_t which should be + * set to the ID of the stat if the stat exists. + * @return + * 0 on success + * -ENODEV for invalid port_id, + * -EINVAL if the xstat_name doesn't exist in port_id + */ +int rte_eth_xstats_get_id_by_name(uint8_t port_id, const char *xstat_name, + uint64_t *id); + /** * Retrieve all extended statistics of an Ethernet device. * diff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map index 64e8840f47..6e118c4816 100644 --- a/lib/librte_ether/rte_ether_version.map +++ b/lib/librte_ether/rte_ether_version.map @@ -153,6 +153,7 @@ DPDK_17.05 { rte_eth_find_next; rte_eth_xstats_get; rte_eth_xstats_get_all; + rte_eth_xstats_get_id_by_name; rte_eth_xstats_get_names; rte_eth_xstats_get_names_all; -- 2.20.1