diff mbox series

[v9,02/10] eal: move OS common options functions

Message ID 20200624082847.21344-3-talshn@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series Windows bus/pci support | expand

Checks

Context Check Description
ci/Intel-compilation fail apply issues
ci/checkpatch success coding style OK

Commit Message

Tal Shnaiderman June 24, 2020, 8:28 a.m. UTC
From: Tal Shnaiderman <talshn@mellanox.com>

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 <talshn@mellanox.com>
---
 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(-)

Comments

Thomas Monjalon June 25, 2020, 2:29 p.m. UTC | #1
24/06/2020 10:28, talshn@mellanox.com:
> From: Tal Shnaiderman <talshn@mellanox.com>
> 
> Move common functions between Unix and Windows to eal_common_options.c.
> 
> Those functions are getter functions for rte_application_usage_hook.
[...]
> +/* Return a pointer to rte_usage_hook_t */
> +rte_usage_hook_t *

Why not returning rte_usage_hook_t directly?

> +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;

A single space is enough to declare the variable.

> +
> +	/* 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;
> +}

[...]
>  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) {

Explicit test is better: if (*hook != NULL)
It could even be if (hook != NULL && *hook != NULL),
which asks the question why returning the pointer of the pointer?

>  		printf("===== Application Usage =====\n\n");
> -		rte_application_usage_hook(prgname);
> +		(*hook)(prgname);
>  	}
>  }
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index f480f6f99b..51ee3a0a7e 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;
+
+/* Return a pointer to 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 21a6ee7e85..99eb7dccbe 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -698,4 +698,13 @@  eal_config_remap(void *mem_cfg_addr);
 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 d79e6c1665..f6c7158d14 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;
@@ -412,28 +410,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 faad7e096e..f20d1dd698 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;
@@ -524,6 +521,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"
@@ -538,25 +537,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 72630f1f21..7ab52cdb7c 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);
 	}
 }