From b8fe14b7cf81d9019b2b4851c8f84e5a64b9a41f Mon Sep 17 00:00:00 2001 From: Gaetan Rivet Date: Thu, 20 Dec 2018 18:06:42 +0100 Subject: [PATCH] eal: add option usage string Add a usage string field in rte_option, allowing to display help to the user and describe which options are currently available. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_options.c | 1 + lib/librte_eal/common/eal_private.h | 7 +++++++ lib/librte_eal/common/include/rte_option.h | 1 + lib/librte_eal/common/rte_option.c | 17 +++++++++++++++++ lib/librte_telemetry/rte_telemetry.c | 1 + 5 files changed, 27 insertions(+) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index a2d862b5f9..3796dbf48f 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -1515,4 +1515,5 @@ eal_common_usage(void) " --"OPT_NO_HPET" Disable HPET\n" " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n" "\n", RTE_MAX_LCORE); + rte_option_usage(); } diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 4f483833db..798ede553b 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -374,4 +374,11 @@ rte_option_parse(const char *opt); void rte_option_init(void); +/** + * Iterate through the registered options and show the associated + * usage string. + */ +void +rte_option_usage(void); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/common/include/rte_option.h b/lib/librte_eal/common/include/rte_option.h index 8957b970cd..bbcc6cec9e 100644 --- a/lib/librte_eal/common/include/rte_option.h +++ b/lib/librte_eal/common/include/rte_option.h @@ -35,6 +35,7 @@ typedef int (*rte_option_cb)(void); struct rte_option { TAILQ_ENTRY(rte_option) next; /**< Next entry in the list. */ char *opt_str; /**< The option name. */ + const char *usage; /**< Option summary string. */ rte_option_cb cb; /**< Function called when option is used. */ int enabled; /**< Set when the option is used. */ }; diff --git a/lib/librte_eal/common/rte_option.c b/lib/librte_eal/common/rte_option.c index 9e233f7d2f..2ed74873b4 100644 --- a/lib/librte_eal/common/rte_option.c +++ b/lib/librte_eal/common/rte_option.c @@ -61,3 +61,20 @@ rte_option_init(void) option->cb(); } } + +void +rte_option_usage(void) +{ + struct rte_option *option; + int opt_count = 0; + + TAILQ_FOREACH(option, &rte_option_list, next) + opt_count += 1; + if (opt_count == 0) + return; + + printf("EAL dynamic options:\n"); + TAILQ_FOREACH(option, &rte_option_list, next) + printf(" --%-*s %s\n", 17, option->opt_str, option->usage); + printf("\n"); +} diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c index b2972d7336..2e808cd7aa 100644 --- a/lib/librte_telemetry/rte_telemetry.c +++ b/lib/librte_telemetry/rte_telemetry.c @@ -1821,6 +1821,7 @@ int telemetry_log_level; static struct rte_option option = { .opt_str = "telemetry", + .usage = "Enable telemetry backend", .cb = &rte_telemetry_init, .enabled = 0 }; -- 2.20.1