From patchwork Mon Jun 29 12:37:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 72408 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD2B3A0350; Mon, 29 Jun 2020 14:38:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0FA901BEBF; Mon, 29 Jun 2020 14:38:00 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 0D4B61BEA8 for ; Mon, 29 Jun 2020 14:37:55 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from talshn@mellanox.com) with SMTP; 29 Jun 2020 15:37:55 +0300 Received: from l-wincomp04-vm.labs.mlnx (l-wincomp04-vm.mtl.labs.mlnx [10.237.1.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 05TCbrhN016264; Mon, 29 Jun 2020 15:37:54 +0300 From: talshn@mellanox.com To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, david.marchand@redhat.com, grive@u256.net, ranjit.menon@intel.com, navasile@linux.microsoft.com, harini.ramakrishnan@microsoft.com, ocardona@microsoft.com, anatoly.burakov@intel.com, fady@mellanox.com, bruce.richardson@intel.com, Tal Shnaiderman Date: Mon, 29 Jun 2020 15:37:33 +0300 Message-Id: <20200629123741.20716-3-talshn@mellanox.com> X-Mailer: git-send-email 2.16.1.windows.4 In-Reply-To: <20200629123741.20716-1-talshn@mellanox.com> References: <20200624082847.21344-1-talshn@mellanox.com> <20200629123741.20716-1-talshn@mellanox.com> Subject: [dpdk-dev] [PATCH v10 02/10] eal: move OS common options functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Tal Shnaiderman Move common functions between Unix and Windows to eal_common_options.c. Those functions are getter functions for rte_application_usage_hook. Signed-off-by: Tal Shnaiderman --- lib/librte_eal/common/eal_common_options.c | 23 +++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 9 +++++++++ lib/librte_eal/freebsd/eal.c | 21 ++++----------------- lib/librte_eal/linux/eal.c | 22 ++++------------------ lib/librte_eal/windows/eal.c | 9 ++++----- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 6b909ce914..24b223ebfd 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -146,6 +146,29 @@ static int master_lcore_parsed; static int mem_parsed; static int core_parsed; +/* Allow the application to print its usage message too if set */ +static rte_usage_hook_t rte_application_usage_hook; + +/* Returns rte_usage_hook_t */ +rte_usage_hook_t +eal_get_application_usage_hook(void) +{ + return rte_application_usage_hook; +} + +/* Set a per-application usage message */ +rte_usage_hook_t +rte_set_application_usage_hook(rte_usage_hook_t usage_func) +{ + rte_usage_hook_t old_func; + + /* Will be NULL on the first call to denote the last usage routine. */ + old_func = rte_application_usage_hook; + rte_application_usage_hook = usage_func; + + return old_func; +} + #ifndef RTE_EXEC_ENV_WINDOWS static char **eal_args; static char **eal_app_args; diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index be4d0a8dbc..46bcae9305 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -690,4 +690,13 @@ eal_set_runtime_dir(char *run_dir, size_t size); struct internal_config * eal_get_internal_configuration(void); +/** + * Get the current value of the rte_application_usage pointer + * + * @return + * Pointer to the current value of rte_application_usage . + */ +rte_usage_hook_t +eal_get_application_usage_hook(void); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c index 766a52b76c..9326c8270a 100644 --- a/lib/librte_eal/freebsd/eal.c +++ b/lib/librte_eal/freebsd/eal.c @@ -56,8 +56,6 @@ #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) -/* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook = NULL; /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; @@ -418,28 +416,17 @@ rte_config_init(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t hook = eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); /* Allow the application to print its usage message too if hook is set */ - if ( rte_application_usage_hook ) { + if (hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (hook)(prgname); } } -/* Set a per-application usage message */ -rte_usage_hook_t -rte_set_application_usage_hook( rte_usage_hook_t usage_func ) -{ - rte_usage_hook_t old_func; - - /* Will be NULL on the first call to denote the last usage routine. */ - old_func = rte_application_usage_hook; - rte_application_usage_hook = usage_func; - - return old_func; -} - static inline size_t eal_get_hugepage_mem_size(void) { diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index e7068f198b..3b56d14da1 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -69,9 +69,6 @@ #define KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups" -/* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook = NULL; - /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; @@ -532,6 +529,8 @@ eal_hugedirs_unlock(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t hook = eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); printf("EAL Linux options:\n" @@ -546,25 +545,12 @@ eal_usage(const char *prgname) " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n" "\n"); /* Allow the application to print its usage message too if hook is set */ - if ( rte_application_usage_hook ) { + if (hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (hook)(prgname); } } -/* Set a per-application usage message */ -rte_usage_hook_t -rte_set_application_usage_hook( rte_usage_hook_t usage_func ) -{ - rte_usage_hook_t old_func; - - /* Will be NULL on the first call to denote the last usage routine. */ - old_func = rte_application_usage_hook; - rte_application_usage_hook = usage_func; - - return old_func; -} - static int eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg) { diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 11801e6093..8333d5977e 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -24,9 +24,6 @@ #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) - /* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook; - /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ @@ -72,14 +69,16 @@ eal_proc_type_detect(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t hook = eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); /* Allow the application to print its usage message too * if hook is set */ - if (rte_application_usage_hook) { + if (hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (hook)(prgname); } }