[dpdk-dev] [PATCH] app/testpmd: change log level at run time
Introduced a run time command to change the log level for a given log type. Added the necessary documentation. Signed-off-by: Elza Mathew --- app/test-pmd/cmdline.c | 53 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 19 +++ 2 files changed, 72 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index f7d5bb0..56b2fb6 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -274,6 +274,9 @@ static void cmd_help_long_parsed(void *parsed_result, "set verbose (level)\n" "Set the debug verbosity level X.\n\n" + "set log global|(type) (level)\n" + "Set the log level.\n\n" + "set nbport (num)\n" "Set number of ports.\n\n" @@ -3055,6 +3058,55 @@ static void cmd_set_parsed(void *parsed_result, }, }; +/* *** SET LOG LEVEL CONFIGURATION *** */ + +struct cmd_set_log_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t log; + cmdline_fixed_string_t type; + uint32_t level; +}; + +static void +cmd_set_log_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_log_result *res; + int ret; + + res = parsed_result; + if (!strcmp(res->type, "global")) + rte_log_set_global_level(res->level); + else { + ret = rte_log_set_level_regexp(res->type, res->level); + if (ret < 0) + printf("Unable to set log level\n"); + } +} + +cmdline_parse_token_string_t cmd_set_log_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set"); +cmdline_parse_token_string_t cmd_set_log_log = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log"); +cmdline_parse_token_string_t cmd_set_log_type = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL); +cmdline_parse_token_num_t cmd_set_log_level = + TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32); + +cmdline_parse_inst_t cmd_set_log = { + .f = cmd_set_log_parsed, + .data = NULL, + .help_str = "set log global| ", + .tokens = { + (void *)&cmd_set_log_set, + (void *)&cmd_set_log_log, + (void *)&cmd_set_log_type, + (void *)&cmd_set_log_level, + NULL, + }, +}; + /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ struct cmd_set_txpkts_result { @@ -16026,6 +16078,7 @@ struct cmd_cmdfile_result { (cmdline_parse_inst_t *)&cmd_set_link_down, (cmdline_parse_inst_t *)&cmd_reset, (cmdline_parse_inst_t *)&cmd_set_numbers, + (cmdline_parse_inst_t *)&cmd_set_log, (cmdline_parse_inst_t *)&cmd_set_txpkts, (cmdline_parse_inst_t *)&cmd_set_txsplit, (cmdline_parse_inst_t *)&cmd_set_fwd_list, diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index d8c9ef0..3c55eb6 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -505,6 +505,25 @@ When retry is enabled, the transmit delay time and number of retries can also be testpmd> set burst tx delay (microseconds) retry (num) +set log +~~~ + +Set the log level for a log type:: + + testpmd> set log global|(type) (level) + +Where: + +* ``type`` is the log name. + +* ``level`` is the log level. + +For example, to change the global log level:: + testpmd> set log global (level) + +Regexes can also be used for type. To change log level of user1, user2 and user3:: + testpmd> set log user[1-3] (level) + set txpkts ~~ -- 1.9.1
[dpdk-dev] [PATCH v2] app/testpmd: change log level at run time
Introduced a run time command to change the log level for a given log type. Added the necessary documentation. V2: Changed the position of the command in the documentation since generic commands are placed at the beginning. Signed-off-by: Elza Mathew --- app/test-pmd/cmdline.c | 53 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 19 +++ 2 files changed, 72 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 9f12c0f..c9b2b57 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -274,6 +274,9 @@ static void cmd_help_long_parsed(void *parsed_result, "set verbose (level)\n" "Set the debug verbosity level X.\n\n" + "set log global|(type) (level)\n" + "Set the log level.\n\n" + "set nbport (num)\n" "Set number of ports.\n\n" @@ -3055,6 +3058,55 @@ static void cmd_set_parsed(void *parsed_result, }, }; +/* *** SET LOG LEVEL CONFIGURATION *** */ + +struct cmd_set_log_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t log; + cmdline_fixed_string_t type; + uint32_t level; +}; + +static void +cmd_set_log_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_log_result *res; + int ret; + + res = parsed_result; + if (!strcmp(res->type, "global")) + rte_log_set_global_level(res->level); + else { + ret = rte_log_set_level_regexp(res->type, res->level); + if (ret < 0) + printf("Unable to set log level\n"); + } +} + +cmdline_parse_token_string_t cmd_set_log_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, set, "set"); +cmdline_parse_token_string_t cmd_set_log_log = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, log, "log"); +cmdline_parse_token_string_t cmd_set_log_type = + TOKEN_STRING_INITIALIZER(struct cmd_set_log_result, type, NULL); +cmdline_parse_token_num_t cmd_set_log_level = + TOKEN_NUM_INITIALIZER(struct cmd_set_log_result, level, UINT32); + +cmdline_parse_inst_t cmd_set_log = { + .f = cmd_set_log_parsed, + .data = NULL, + .help_str = "set log global| ", + .tokens = { + (void *)&cmd_set_log_set, + (void *)&cmd_set_log_log, + (void *)&cmd_set_log_type, + (void *)&cmd_set_log_level, + NULL, + }, +}; + /* *** SET SEGMENT LENGTHS OF TXONLY PACKETS *** */ struct cmd_set_txpkts_result { @@ -16026,6 +16078,7 @@ struct cmd_cmdfile_result { (cmdline_parse_inst_t *)&cmd_set_link_down, (cmdline_parse_inst_t *)&cmd_reset, (cmdline_parse_inst_t *)&cmd_set_numbers, + (cmdline_parse_inst_t *)&cmd_set_log, (cmdline_parse_inst_t *)&cmd_set_txpkts, (cmdline_parse_inst_t *)&cmd_set_txsplit, (cmdline_parse_inst_t *)&cmd_set_fwd_list, diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index d8c9ef0..f7a709f 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -448,6 +448,25 @@ Set the debug verbosity level:: Currently the only available levels are 0 (silent except for error) and 1 (fully verbose). +set log +~~~ + +Set the log level for a log type:: + + testpmd> set log global|(type) (level) + +Where: + +* ``type`` is the log name. + +* ``level`` is the log level. + +For example, to change the global log level:: + testpmd> set log global (level) + +Regexes can also be used for type. To change log level of user1, user2 and user3:: + testpmd> set log user[1-3] (level) + set nbport ~~ -- 1.9.1
[dpdk-dev] [PATCH] app/testpmd: refine xstats show
When using "show port xstats all" command to show xstats, the output is usually too long to obtain what you really want, especially when multi-queue is enabled. Added an option to set whether zero values should be displayed or not for xstats. The "set xstats-hide-zero on|off" command enables the user to decide if the zero values should be shown while displaying xstats. Signed-off-by: Jianfeng Tan Signed-off-by: Elza Mathew --- app/test-pmd/cmdline.c | 47 + app/test-pmd/config.c | 11 ++- app/test-pmd/testpmd.c | 5 +++ app/test-pmd/testpmd.h | 4 +++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 11 +++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index bb01e98..c631dc0 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -507,6 +507,10 @@ static void cmd_help_long_parsed(void *parsed_result, "e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" " on port 0 to mapping 5.\n\n" + "set xstats-hide-zero on|off\n" + "Set the option to hide the zero values" + " for xstats display.\n" + "set port (port_id) vf (vf_id) rx|tx on|off\n" "Enable/Disable a VF receive/tranmit from a port\n\n" @@ -7078,6 +7082,48 @@ struct cmd_set_qmap_result { }, }; +/* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS DISPLAY *** */ +struct cmd_set_xstats_hide_zero_result { + cmdline_fixed_string_t keyword; + cmdline_fixed_string_t name; + cmdline_fixed_string_t on_off; +}; + +static void +cmd_set_xstats_hide_zero_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_xstats_hide_zero_result *res; + uint16_t on_off = 0; + + res = parsed_result; + on_off = !strcmp(res->on_off, "on") ? 1 : 0; + set_xstats_hide_zero(on_off); +} + +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, +keyword, "set"); +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, +name, "xstats-hide-zero"); +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, +on_off, "on#off"); + +cmdline_parse_inst_t cmd_set_xstats_hide_zero = { + .f = cmd_set_xstats_hide_zero_parsed, + .data = NULL, + .help_str = "set xstats-hide-zero on|off", + .tokens = { + (void *)&cmd_set_xstats_hide_zero_keyword, + (void *)&cmd_set_xstats_hide_zero_name, + (void *)&cmd_set_xstats_hide_zero_on_off, + NULL, + }, +}; + /* *** CONFIGURE UNICAST HASH TABLE *** */ struct cmd_set_uc_hash_table { cmdline_fixed_string_t set; @@ -15482,6 +15528,7 @@ struct cmd_cmdfile_result { (cmdline_parse_inst_t *)&cmd_stop, (cmdline_parse_inst_t *)&cmd_mac_addr, (cmdline_parse_inst_t *)&cmd_set_qmap, + (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero, (cmdline_parse_inst_t *)&cmd_operate_port, (cmdline_parse_inst_t *)&cmd_operate_specific_port, (cmdline_parse_inst_t *)&cmd_operate_attach_port, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index bafe76c..1c8f542 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -292,10 +292,13 @@ struct rss_type_info { } /* Display xstats */ - for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { + if (xstats_hide_zero && !xstats[idx_xstat].value) + continue; printf("%s: %"PRIu64"\n", xstats_names[idx_xstat].name, xstats[idx_xstat].value); + } free(xstats_names); free(xstats); } @@ -2866,6 +2869,12 @@ struct igb_ring_desc_16_bytes { } } +void +set_xstats_hide_zero(uint8_t on_off) +{ + xstats_hide_zero = on_off; +} + static inline void print_fdir_mask(struct rte_eth_fdir_masks *mask) { diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index a4d4a86..8b57aaf 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -384,6 +384,11 @@ struct
[dpdk-dev] [PATCH 2/3] hash: run-time function selection
Compile-time function selection can potentially lead to lower performance on generic builds done by distros. Replaced compile time flag checks with run-time function selection. Signed-off-by: Elza Mathew --- lib/librte_hash/rte_fbk_hash.c | 11 ++- lib/librte_hash/rte_fbk_hash.h | 8 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 55c9f35..7c4e194 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -114,6 +114,7 @@ struct rte_fbk_hash_table * sizeof(*ht) + (sizeof(ht->t[0]) * params->entries); uint32_t i; struct rte_fbk_hash_list *fbk_hash_list; + rte_fbk_hash_fn default_hash_func = (rte_fbk_hash_fn)rte_jhash_1word; fbk_hash_list = RTE_TAILQ_CAST(rte_fbk_hash_tailq.head, rte_fbk_hash_list); @@ -161,6 +162,14 @@ struct rte_fbk_hash_table * goto exit; } + /* Default hash function */ +#if defined(RTE_ARCH_X86) + default_hash_func = (rte_fbk_hash_fn)rte_hash_crc_4byte; +#elif defined(RTE_ARCH_ARM64) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + default_hash_func = (rte_fbk_hash_fn)rte_hash_crc_4byte; +#endif + /* Set up hash table context. */ snprintf(ht->name, sizeof(ht->name), "%s", params->name); ht->entries = params->entries; @@ -177,7 +186,7 @@ struct rte_fbk_hash_table * ht->init_val = params->init_val; } else { - ht->hash_func = RTE_FBK_HASH_FUNC_DEFAULT; + ht->hash_func = default_hash_func; ht->init_val = RTE_FBK_HASH_INIT_VAL_DEFAULT; } diff --git a/lib/librte_hash/rte_fbk_hash.h b/lib/librte_hash/rte_fbk_hash.h index c39c097..1b1b7df 100644 --- a/lib/librte_hash/rte_fbk_hash.h +++ b/lib/librte_hash/rte_fbk_hash.h @@ -54,16 +54,8 @@ #include -#ifndef RTE_FBK_HASH_FUNC_DEFAULT -#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32) #include -/** Default four-byte key hash function if none is specified. */ -#define RTE_FBK_HASH_FUNC_DEFAULT rte_hash_crc_4byte -#else #include -#define RTE_FBK_HASH_FUNC_DEFAULT rte_jhash_1word -#endif -#endif #ifndef RTE_FBK_HASH_INIT_VAL_DEFAULT /** Initialising value used when calculating hash. */ -- 1.9.1
[dpdk-dev] [PATCH 1/3] hash: run-time function selection
Compile-time function selection can potentially lead to lower performance on generic builds done by distros. Replaced compile time flag checks with run-time function selection. Signed-off-by: Elza Mathew --- lib/librte_hash/rte_cuckoo_hash.c | 10 +- lib/librte_hash/rte_cuckoo_hash.h | 6 -- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index e69b911..078d9c8 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -125,6 +125,7 @@ struct rte_hash * unsigned num_key_slots; unsigned hw_trans_mem_support = 0; unsigned i; + rte_hash_function default_hash_func = (rte_hash_function)rte_jhash; hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list); @@ -268,6 +269,13 @@ struct rte_hash * RTE_CACHE_LINE_SIZE, params->socket_id); } + /* Default hash function */ +#if defined(RTE_ARCH_X86) + default_hash_func = (rte_hash_function)rte_hash_crc; +#elif defined(RTE_ARCH_ARM64) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + default_hash_func = (rte_hash_function)rte_hash_crc; +#endif /* Setup hash context */ snprintf(h->name, sizeof(h->name), "%s", params->name); h->entries = params->entries; @@ -279,7 +287,7 @@ struct rte_hash * h->bucket_bitmask = h->num_buckets - 1; h->buckets = buckets; h->hash_func = (params->hash_func == NULL) ? - DEFAULT_HASH_FUNC : params->hash_func; + default_hash_func : params->hash_func; h->key_store = k; h->free_slots = r; h->hw_trans_mem_support = hw_trans_mem_support; diff --git a/lib/librte_hash/rte_cuckoo_hash.h b/lib/librte_hash/rte_cuckoo_hash.h index f75392d..b4fd9b1 100644 --- a/lib/librte_hash/rte_cuckoo_hash.h +++ b/lib/librte_hash/rte_cuckoo_hash.h @@ -57,14 +57,8 @@ #define RETURN_IF_TRUE(cond, retval) #endif -/* Hash function used if none is specified */ -#if defined(RTE_ARCH_X86) || defined(RTE_MACHINE_CPUFLAG_CRC32) #include -#define DEFAULT_HASH_FUNC rte_hash_crc -#else #include -#define DEFAULT_HASH_FUNC rte_jhash -#endif #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64) /* -- 1.9.1
[dpdk-dev] [PATCH 3/3] net: run-time function selection
Compile-time function selection can potentially lead to lower performance on generic builds done by distros. Replaced compile time flag checks with run-time function selection. Signed-off-by: Elza Mathew --- lib/librte_net/rte_net_crc.c | 22 +- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c index 661fe32..8f6a0e7 100644 --- a/lib/librte_net/rte_net_crc.c +++ b/lib/librte_net/rte_net_crc.c @@ -39,8 +39,8 @@ #include #include -#if defined(RTE_ARCH_X86_64) && defined(RTE_MACHINE_CPUFLAG_PCLMULQDQ) -#define X86_64_SSE42_PCLMULQDQ 1 +#ifdef RTE_ARCH_X86_64 +#include #elif defined(RTE_ARCH_ARM64) && defined(RTE_MACHINE_CPUFLAG_PMULL) #define ARM64_NEON_PMULL 1 #endif @@ -71,7 +71,7 @@ [RTE_NET_CRC32_ETH] = rte_crc32_eth_handler, }; -#ifdef X86_64_SSE42_PCLMULQDQ +#ifdef RTE_ARCH_X86_64 static rte_net_crc_handler handlers_sse42[] = { [RTE_NET_CRC16_CCITT] = rte_crc16_ccitt_sse42_handler, [RTE_NET_CRC32_ETH] = rte_crc32_eth_sse42_handler, @@ -169,10 +169,12 @@ rte_net_crc_set_alg(enum rte_net_crc_alg alg) { switch (alg) { -#ifdef X86_64_SSE42_PCLMULQDQ +#ifdef RTE_ARCH_X86_64 case RTE_NET_CRC_SSE42: - handlers = handlers_sse42; - break; + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PCLMULQDQ)) { + handlers = handlers_sse42; + break; + } #elif defined ARM64_NEON_PMULL /* fall-through */ case RTE_NET_CRC_NEON: @@ -212,9 +214,11 @@ static inline void __attribute__((constructor)) rte_net_crc_scalar_init(); -#ifdef X86_64_SSE42_PCLMULQDQ - alg = RTE_NET_CRC_SSE42; - rte_net_crc_sse42_init(); +#ifdef RTE_ARCH_X86_64 + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PCLMULQDQ)) { + alg = RTE_NET_CRC_SSE42; + rte_net_crc_sse42_init(); + } #elif defined ARM64_NEON_PMULL if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { alg = RTE_NET_CRC_NEON; -- 1.9.1
[dpdk-dev] [PATCH 2/2] lib: optimize _xstats_by_ids APIs
Introduced a check to detect if the stats IDs being requested are all basic stats IDs. In that case, ensured that only the basic stats would be retrieved. Previously, both basic stats and xstats were being retrieved even if all the IDs were basic stats IDs. Signed-off-by: Elza Mathew --- lib/librte_ether/rte_ethdev.c | 38 +++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index dfe8e65..210600d 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1688,7 +1688,9 @@ struct rte_eth_dev * { struct rte_eth_xstat_name *xstats_names_copy; unsigned int no_basic_stat_requested = 1; + unsigned int no_ext_stat_requested = 1; unsigned int expected_entries; + unsigned int basic_count; struct rte_eth_dev *dev; unsigned int i; int ret; @@ -1696,6 +1698,7 @@ struct rte_eth_dev * RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; + basic_count = get_xstats_basic_count(dev); ret = get_xstats_count(port_id); if (ret < 0) return ret; @@ -1713,7 +1716,6 @@ struct rte_eth_dev * return -EINVAL; if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) { - unsigned int basic_count = get_xstats_basic_count(dev); uint64_t ids_copy[size]; for (i = 0; i < size; i++) { @@ -1752,8 +1754,22 @@ struct rte_eth_dev * return -ENOMEM; } + if (ids) { + for (i = 0; i < size; i++) { + if (ids[i] > basic_count) { + no_ext_stat_requested = 0; + break; + } + } + } + /* Fill xstats_names_copy structure */ - rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries); + if (ids && no_ext_stat_requested) { + rte_eth_basic_stats_get_names(dev, xstats_names_copy); + } else { + rte_eth_xstats_get_names(port_id, xstats_names_copy, + expected_entries); + } /* Filter stats */ for (i = 0; i < size; i++) { @@ -1860,7 +1876,9 @@ struct rte_eth_dev * uint64_t *values, unsigned int size) { unsigned int no_basic_stat_requested = 1; + unsigned int no_ext_stat_requested = 1; unsigned int num_xstats_filled; + unsigned int basic_count; uint16_t expected_entries; struct rte_eth_dev *dev; unsigned int i; @@ -1870,6 +1888,7 @@ struct rte_eth_dev * expected_entries = get_xstats_count(port_id); struct rte_eth_xstat xstats[expected_entries]; dev = &rte_eth_devices[port_id]; + basic_count = get_xstats_basic_count(dev); /* Return max number of stats if no ids given */ if (!ids) { @@ -1904,8 +1923,21 @@ struct rte_eth_dev * values, size); } + if (ids) { + for (i = 0; i < size; i++) { + if (ids[i] > basic_count) { + no_ext_stat_requested = 0; + break; + } + } + } + /* Fill the xstats structure */ - ret = rte_eth_xstats_get(port_id, xstats, expected_entries); + if (ids && no_ext_stat_requested) + ret = rte_eth_basic_stats_get(port_id, xstats); + else + ret = rte_eth_xstats_get(port_id, xstats, expected_entries); + if (ret < 0) return ret; num_xstats_filled = (unsigned int)ret; -- 1.9.1
[dpdk-dev] [PATCH 1/2] lib: refactor basic stats code
Moved the code to get the basic stats names and values into static functions. Signed-off-by: Elza Mathew --- lib/librte_ether/rte_ethdev.c | 156 -- 1 file changed, 91 insertions(+), 65 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 318af28..dfe8e65 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1641,6 +1641,45 @@ struct rte_eth_dev * return -EINVAL; } +/* retrieve basic stats names */ +static int +rte_eth_basic_stats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names) +{ + int cnt_used_entries = 0; + uint32_t idx, id_queue; + uint16_t num_q; + + for (idx = 0; idx < RTE_NB_STATS; idx++) { + snprintf(xstats_names[cnt_used_entries].name, + sizeof(xstats_names[0].name), + "%s", rte_stats_strings[idx].name); + cnt_used_entries++; + } + num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); + for (id_queue = 0; id_queue < num_q; id_queue++) { + for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) { + snprintf(xstats_names[cnt_used_entries].name, + sizeof(xstats_names[0].name), + "rx_q%u%s", + id_queue, rte_rxq_stats_strings[idx].name); + cnt_used_entries++; + } + + } + num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); + for (id_queue = 0; id_queue < num_q; id_queue++) { + for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) { + snprintf(xstats_names[cnt_used_entries].name, + sizeof(xstats_names[0].name), + "tx_q%u%s", + id_queue, rte_txq_stats_strings[idx].name); + cnt_used_entries++; + } + } + return cnt_used_entries; +} + /* retrieve ethdev extended statistics names */ int rte_eth_xstats_get_names_by_id(uint16_t port_id, @@ -1739,8 +1778,6 @@ struct rte_eth_dev * int cnt_used_entries; int cnt_expected_entries; int cnt_driver_entries; - uint32_t idx, id_queue; - uint16_t num_q; cnt_expected_entries = get_xstats_count(port_id); if (xstats_names == NULL || cnt_expected_entries < 0 || @@ -1749,35 +1786,9 @@ struct rte_eth_dev * /* port_id checked in get_xstats_count() */ dev = &rte_eth_devices[port_id]; - cnt_used_entries = 0; - for (idx = 0; idx < RTE_NB_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "%s", rte_stats_strings[idx].name); - cnt_used_entries++; - } - num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (id_queue = 0; id_queue < num_q; id_queue++) { - for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "rx_q%u%s", - id_queue, rte_rxq_stats_strings[idx].name); - cnt_used_entries++; - } - - } - num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); - for (id_queue = 0; id_queue < num_q; id_queue++) { - for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "tx_q%u%s", - id_queue, rte_txq_stats_strings[idx].name); - cnt_used_entries++; - } - } + cnt_used_entries = rte_eth_basic_stats_get_names( + dev, xstats_names); if (dev->dev_ops->xstats_get_names != NULL) { /* If there are any driver-specific xstats, append them @@ -1795,6 +1806,54 @@ struct rte_eth_dev * return cnt_used_entries; } + +static int +rte_eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats) +{ + struct rte_eth_dev *dev; + struct rte_eth_stats eth_stats; + unsigned int count = 0, i, q; + uint64_t val, *stats_ptr; + uint16_t nb_rxqs, nb_txqs; + + rte_eth_stats_get(port_id, ð_stats); + dev = &rte_eth_devices[port_id]; + + nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); + nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHD