DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/7] Move EAL common functions
@ 2014-12-25 15:33 Ravi Kerur
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2 Ravi Kerur
                   ` (7 more replies)
  0 siblings, 8 replies; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

Common functions in linuxapp and bsdapp are moved into
librte_eal/common directory.
New files added follow _common_ naming conventions.
Tested against ubuntu and FreeBSD.

*** BLURB HERE ***

Ravi Kerur (7):
  Fix rte_is_power_of_2
  Move EAL common functions
  Move EAL common functions
  Move EAL common functions
  Move EAL common functions
  Move EAL common functions
  Move EAL common functions

 lib/librte_eal/bsdapp/eal/Makefile         |  11 +-
 lib/librte_eal/bsdapp/eal/eal.c            | 233 +-------------------
 lib/librte_eal/bsdapp/eal/eal_debug.c      | 113 ----------
 lib/librte_eal/bsdapp/eal/eal_lcore.c      |  62 ++----
 lib/librte_eal/bsdapp/eal/eal_memory.c     |  36 +---
 lib/librte_eal/bsdapp/eal/eal_thread.c     | 233 --------------------
 lib/librte_eal/bsdapp/eal/eal_timer.c      |  50 +----
 lib/librte_eal/common/eal_common.c         | 328 +++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_debug.c   | 112 ++++++++++
 lib/librte_eal/common/eal_common_lcore.c   | 106 ++++++++++
 lib/librte_eal/common/eal_common_memory.c  |  43 +++-
 lib/librte_eal/common/eal_common_thread.c  | 248 ++++++++++++++++++++++
 lib/librte_eal/common/eal_common_timer.c   |  99 +++++++++
 lib/librte_eal/common/eal_externs.h        |  45 ++++
 lib/librte_eal/common/eal_hugepages.h      |   1 +
 lib/librte_eal/common/eal_private.h        | 128 +++++++++++
 lib/librte_eal/common/include/rte_common.h |   2 +-
 lib/librte_eal/linuxapp/eal/Makefile       |  11 +-
 lib/librte_eal/linuxapp/eal/eal.c          | 246 +---------------------
 lib/librte_eal/linuxapp/eal/eal_debug.c    | 113 ----------
 lib/librte_eal/linuxapp/eal/eal_lcore.c    |  55 +----
 lib/librte_eal/linuxapp/eal/eal_memory.c   |  36 +---
 lib/librte_eal/linuxapp/eal/eal_thread.c   | 233 --------------------
 lib/librte_eal/linuxapp/eal/eal_timer.c    |  52 +----
 24 files changed, 1165 insertions(+), 1431 deletions(-)
 delete mode 100644 lib/librte_eal/bsdapp/eal/eal_debug.c
 delete mode 100644 lib/librte_eal/bsdapp/eal/eal_thread.c
 create mode 100644 lib/librte_eal/common/eal_common.c
 create mode 100644 lib/librte_eal/common/eal_common_debug.c
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
 create mode 100644 lib/librte_eal/common/eal_common_thread.c
 create mode 100644 lib/librte_eal/common/eal_common_timer.c
 create mode 100644 lib/librte_eal/common/eal_externs.h
 delete mode 100644 lib/librte_eal/linuxapp/eal/eal_debug.c
 delete mode 100644 lib/librte_eal/linuxapp/eal/eal_thread.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2014-12-25 17:21   ` Neil Horman
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 2/7] Move EAL common functions Ravi Kerur
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
by checking for n.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/common/include/rte_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 921b91f..8ac940c 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;
 static inline int
 rte_is_power_of_2(uint32_t n)
 {
-	return ((n-1) & n) == 0;
+	return n && !(n & (n - 1));
 }
 
 /**
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2 Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2014-12-25 17:30   ` Neil Horman
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 3/7] " Ravi Kerur
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

eal_debug.c has no difference between Linux and BSD, move
into common directory.
Rename eal_debug.c to eal_common_debug.c
Makefile changes to reflect file move and name change.
Fix checkpatch warnings.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile       |   2 +-
 lib/librte_eal/bsdapp/eal/eal_debug.c    | 113 -------------------------------
 lib/librte_eal/common/eal_common_debug.c | 112 ++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile     |   2 +-
 lib/librte_eal/linuxapp/eal/eal_debug.c  | 113 -------------------------------
 5 files changed, 114 insertions(+), 228 deletions(-)
 delete mode 100644 lib/librte_eal/bsdapp/eal/eal_debug.c
 create mode 100644 lib/librte_eal/common/eal_common_debug.c
 delete mode 100644 lib/librte_eal/linuxapp/eal/eal_debug.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index d434882..9b83e11 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -53,7 +53,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_hugepage_info.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_pci.c
-SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c
@@ -73,6 +72,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_hexdump.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_debug.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
deleted file mode 100644
index 44fc4f3..0000000
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <execinfo.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#include <rte_log.h>
-#include <rte_debug.h>
-#include <rte_common.h>
-
-#define BACKTRACE_SIZE 256
-
-/* dump the stack of the calling core */
-void rte_dump_stack(void)
-{
-	void *func[BACKTRACE_SIZE];
-	char **symb = NULL;
-	int size;
-
-	size = backtrace(func, BACKTRACE_SIZE);
-	symb = backtrace_symbols(func, size);
-	while (size > 0) {
-		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
-			"%d: [%s]\n", size, symb[size - 1]);
-		size --;
-	}
-}
-
-/* not implemented in this environment */
-void rte_dump_registers(void)
-{
-	return;
-}
-
-/* call abort(), it will generate a coredump if enabled */
-void __rte_panic(const char *funcname, const char *format, ...)
-{
-	va_list ap;
-
-	/* disable history */
-	rte_log_set_history(0);
-
-	rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "PANIC in %s():\n", funcname);
-	va_start(ap, format);
-	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
-	va_end(ap);
-	rte_dump_stack();
-	rte_dump_registers();
-	abort();
-}
-
-/*
- * Like rte_panic this terminates the application. However, no traceback is
- * provided and no core-dump is generated.
- */
-void
-rte_exit(int exit_code, const char *format, ...)
-{
-	va_list ap;
-
-	/* disable history */
-	rte_log_set_history(0);
-
-	if (exit_code != 0)
-		RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
-				"  Cause: ", exit_code);
-
-	va_start(ap, format);
-	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
-	va_end(ap);
-
-#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
-	exit(exit_code);
-#else
-	rte_dump_stack();
-	rte_dump_registers();
-	abort();
-#endif
-}
diff --git a/lib/librte_eal/common/eal_common_debug.c b/lib/librte_eal/common/eal_common_debug.c
new file mode 100644
index 0000000..7a482b9
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_debug.c
@@ -0,0 +1,112 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <execinfo.h>
+#include <stdarg.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include <rte_log.h>
+#include <rte_debug.h>
+#include <rte_common.h>
+
+#define BACKTRACE_SIZE 256
+
+/* dump the stack of the calling core */
+void rte_dump_stack(void)
+{
+	void *func[BACKTRACE_SIZE];
+	char **symb = NULL;
+	int size;
+
+	size = backtrace(func, BACKTRACE_SIZE);
+	symb = backtrace_symbols(func, size);
+	while (size > 0) {
+		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
+			"%d: [%s]\n", size, symb[size - 1]);
+		size--;
+	}
+}
+
+/* not implemented in this environment */
+void rte_dump_registers(void)
+{
+}
+
+/* call abort(), it will generate a coredump if enabled */
+void __rte_panic(const char *funcname, const char *format, ...)
+{
+	va_list ap;
+
+	/* disable history */
+	rte_log_set_history(0);
+
+	rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "PANIC in %s():\n", funcname);
+	va_start(ap, format);
+	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
+	va_end(ap);
+	rte_dump_stack();
+	rte_dump_registers();
+	abort();
+}
+
+/*
+ * Like rte_panic this terminates the application. However, no traceback is
+ * provided and no core-dump is generated.
+ */
+void
+rte_exit(int exit_code, const char *format, ...)
+{
+	va_list ap;
+
+	/* disable history */
+	rte_log_set_history(0);
+
+	if (exit_code != 0)
+		RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
+				"  Cause: ", exit_code);
+
+	va_start(ap, format);
+	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
+	va_end(ap);
+
+#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	exit(exit_code);
+#else
+	rte_dump_stack();
+	rte_dump_registers();
+	abort();
+#endif
+}
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 72ecf3a..87b9bfc 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -62,7 +62,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_vfio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_vfio_mp_sync.c
-SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_interrupts.c
@@ -85,6 +84,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_hexdump.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_debug.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
deleted file mode 100644
index 44fc4f3..0000000
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <execinfo.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#include <rte_log.h>
-#include <rte_debug.h>
-#include <rte_common.h>
-
-#define BACKTRACE_SIZE 256
-
-/* dump the stack of the calling core */
-void rte_dump_stack(void)
-{
-	void *func[BACKTRACE_SIZE];
-	char **symb = NULL;
-	int size;
-
-	size = backtrace(func, BACKTRACE_SIZE);
-	symb = backtrace_symbols(func, size);
-	while (size > 0) {
-		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
-			"%d: [%s]\n", size, symb[size - 1]);
-		size --;
-	}
-}
-
-/* not implemented in this environment */
-void rte_dump_registers(void)
-{
-	return;
-}
-
-/* call abort(), it will generate a coredump if enabled */
-void __rte_panic(const char *funcname, const char *format, ...)
-{
-	va_list ap;
-
-	/* disable history */
-	rte_log_set_history(0);
-
-	rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "PANIC in %s():\n", funcname);
-	va_start(ap, format);
-	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
-	va_end(ap);
-	rte_dump_stack();
-	rte_dump_registers();
-	abort();
-}
-
-/*
- * Like rte_panic this terminates the application. However, no traceback is
- * provided and no core-dump is generated.
- */
-void
-rte_exit(int exit_code, const char *format, ...)
-{
-	va_list ap;
-
-	/* disable history */
-	rte_log_set_history(0);
-
-	if (exit_code != 0)
-		RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
-				"  Cause: ", exit_code);
-
-	va_start(ap, format);
-	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
-	va_end(ap);
-
-#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
-	exit(exit_code);
-#else
-	rte_dump_stack();
-	rte_dump_registers();
-	abort();
-#endif
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 3/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2 Ravi Kerur
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 2/7] Move EAL common functions Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2014-12-25 17:41   ` Neil Horman
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 4/7] " Ravi Kerur
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

eal_thread.c has minor difference between Linux and BSD, move
into common directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate minor difference.
Rename eal_thread.c to eal_common_thread.c
Makefile changes to reflect file move and name change.
Fix checkpatch warnings.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile        |   6 +-
 lib/librte_eal/bsdapp/eal/eal_thread.c    | 233 ----------------------------
 lib/librte_eal/common/eal_common_thread.c | 248 ++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile      |   6 +-
 lib/librte_eal/linuxapp/eal/eal_thread.c  | 233 ----------------------------
 5 files changed, 254 insertions(+), 472 deletions(-)
 delete mode 100644 lib/librte_eal/bsdapp/eal/eal_thread.c
 create mode 100644 lib/librte_eal/common/eal_common_thread.c
 delete mode 100644 lib/librte_eal/linuxapp/eal/eal_thread.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9b83e11..92dd9a6 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -50,7 +50,6 @@ CFLAGS += $(WERROR_FLAGS) -O3
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) := eal.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_hugepage_info.c
-SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_pci.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_lcore.c
@@ -73,16 +72,17 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_debug.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
-#CFLAGS_eal_thread.o := -D_GNU_SOURCE
+#CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
 CFLAGS_eal_log.o := -D_GNU_SOURCE
 CFLAGS_eal_common_log.o := -D_GNU_SOURCE
 
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
-CFLAGS_eal_thread.o += -Wno-return-type
+CFLAGS_eal_common_thread.o += -Wno-return-type
 CFLAGS_eal_hpet.o += -Wno-return-type
 endif
 
diff --git a/lib/librte_eal/bsdapp/eal/eal_thread.c b/lib/librte_eal/bsdapp/eal/eal_thread.c
deleted file mode 100644
index ab05368..0000000
--- a/lib/librte_eal/bsdapp/eal/eal_thread.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <sched.h>
-#include <pthread_np.h>
-#include <sys/queue.h>
-
-#include <rte_debug.h>
-#include <rte_atomic.h>
-#include <rte_launch.h>
-#include <rte_log.h>
-#include <rte_memory.h>
-#include <rte_memzone.h>
-#include <rte_per_lcore.h>
-#include <rte_tailq.h>
-#include <rte_eal.h>
-#include <rte_per_lcore.h>
-#include <rte_lcore.h>
-
-#include "eal_private.h"
-#include "eal_thread.h"
-
-RTE_DEFINE_PER_LCORE(unsigned, _lcore_id);
-
-/*
- * Send a message to a slave lcore identified by slave_id to call a
- * function f with argument arg. Once the execution is done, the
- * remote lcore switch in FINISHED state.
- */
-int
-rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
-{
-	int n;
-	char c = 0;
-	int m2s = lcore_config[slave_id].pipe_master2slave[1];
-	int s2m = lcore_config[slave_id].pipe_slave2master[0];
-
-	if (lcore_config[slave_id].state != WAIT)
-		return -EBUSY;
-
-	lcore_config[slave_id].f = f;
-	lcore_config[slave_id].arg = arg;
-
-	/* send message */
-	n = 0;
-	while (n == 0 || (n < 0 && errno == EINTR))
-		n = write(m2s, &c, 1);
-	if (n < 0)
-		rte_panic("cannot write on configuration pipe\n");
-
-	/* wait ack */
-	do {
-		n = read(s2m, &c, 1);
-	} while (n < 0 && errno == EINTR);
-
-	if (n <= 0)
-		rte_panic("cannot read on configuration pipe\n");
-
-	return 0;
-}
-
-/* set affinity for current thread */
-static int
-eal_thread_set_affinity(void)
-{
-	int s;
-	pthread_t thread;
-
-/*
- * According to the section VERSIONS of the CPU_ALLOC man page:
- *
- * The CPU_ZERO(), CPU_SET(), CPU_CLR(), and CPU_ISSET() macros were added
- * in glibc 2.3.3.
- *
- * CPU_COUNT() first appeared in glibc 2.6.
- *
- * CPU_AND(),     CPU_OR(),     CPU_XOR(),    CPU_EQUAL(),    CPU_ALLOC(),
- * CPU_ALLOC_SIZE(), CPU_FREE(), CPU_ZERO_S(),  CPU_SET_S(),  CPU_CLR_S(),
- * CPU_ISSET_S(),  CPU_AND_S(), CPU_OR_S(), CPU_XOR_S(), and CPU_EQUAL_S()
- * first appeared in glibc 2.7.
- */
-#if defined(CPU_ALLOC)
-	size_t size;
-	cpu_set_t *cpusetp;
-
-	cpusetp = CPU_ALLOC(RTE_MAX_LCORE);
-	if (cpusetp == NULL) {
-		RTE_LOG(ERR, EAL, "CPU_ALLOC failed\n");
-		return -1;
-	}
-
-	size = CPU_ALLOC_SIZE(RTE_MAX_LCORE);
-	CPU_ZERO_S(size, cpusetp);
-	CPU_SET_S(rte_lcore_id(), size, cpusetp);
-
-	thread = pthread_self();
-	s = pthread_setaffinity_np(thread, size, cpusetp);
-	if (s != 0) {
-		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
-		CPU_FREE(cpusetp);
-		return -1;
-	}
-
-	CPU_FREE(cpusetp);
-#else /* CPU_ALLOC */
-	cpuset_t cpuset;
-	CPU_ZERO( &cpuset );
-	CPU_SET( rte_lcore_id(), &cpuset );
-
-	thread = pthread_self();
-	s = pthread_setaffinity_np(thread, sizeof( cpuset ), &cpuset);
-	if (s != 0) {
-		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
-		return -1;
-	}
-#endif
-	return 0;
-}
-
-void eal_thread_init_master(unsigned lcore_id)
-{
-	/* set the lcore ID in per-lcore memory area */
-	RTE_PER_LCORE(_lcore_id) = lcore_id;
-
-	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
-		rte_panic("cannot set affinity\n");
-}
-
-/* main loop of threads */
-__attribute__((noreturn)) void *
-eal_thread_loop(__attribute__((unused)) void *arg)
-{
-	char c;
-	int n, ret;
-	unsigned lcore_id;
-	pthread_t thread_id;
-	int m2s, s2m;
-
-	thread_id = pthread_self();
-
-	/* retrieve our lcore_id from the configuration structure */
-	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-		if (thread_id == lcore_config[lcore_id].thread_id)
-			break;
-	}
-	if (lcore_id == RTE_MAX_LCORE)
-		rte_panic("cannot retrieve lcore id\n");
-
-	RTE_LOG(DEBUG, EAL, "Core %u is ready (tid=%p)\n",
-		lcore_id, thread_id);
-
-	m2s = lcore_config[lcore_id].pipe_master2slave[0];
-	s2m = lcore_config[lcore_id].pipe_slave2master[1];
-
-	/* set the lcore ID in per-lcore memory area */
-	RTE_PER_LCORE(_lcore_id) = lcore_id;
-
-	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
-		rte_panic("cannot set affinity\n");
-
-	/* read on our pipe to get commands */
-	while (1) {
-		void *fct_arg;
-
-		/* wait command */
-		do {
-			n = read(m2s, &c, 1);
-		} while (n < 0 && errno == EINTR);
-
-		if (n <= 0)
-			rte_panic("cannot read on configuration pipe\n");
-
-		lcore_config[lcore_id].state = RUNNING;
-
-		/* send ack */
-		n = 0;
-		while (n == 0 || (n < 0 && errno == EINTR))
-			n = write(s2m, &c, 1);
-		if (n < 0)
-			rte_panic("cannot write on configuration pipe\n");
-
-		if (lcore_config[lcore_id].f == NULL)
-			rte_panic("NULL function pointer\n");
-
-		/* call the function and store the return value */
-		fct_arg = lcore_config[lcore_id].arg;
-		ret = lcore_config[lcore_id].f(fct_arg);
-		lcore_config[lcore_id].ret = ret;
-		rte_wmb();
-		lcore_config[lcore_id].state = FINISHED;
-	}
-
-	/* never reached */
-	/* pthread_exit(NULL); */
-	/* return NULL; */
-}
diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c
new file mode 100644
index 0000000..9688f9a
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_thread.c
@@ -0,0 +1,248 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+#include <pthread_np.h>
+#else  /* RTE_EXEC_ENV_BSDAPP */
+#include <pthread.h>
+#endif /* RTE_EXEC_ENV_BSDAPP */
+
+#include <sched.h>
+#include <sys/queue.h>
+
+#include <rte_debug.h>
+#include <rte_atomic.h>
+#include <rte_launch.h>
+#include <rte_log.h>
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include <rte_per_lcore.h>
+#include <rte_tailq.h>
+#include <rte_eal.h>
+#include <rte_per_lcore.h>
+#include <rte_lcore.h>
+
+#include "eal_private.h"
+#include "eal_thread.h"
+
+RTE_DEFINE_PER_LCORE(unsigned, _lcore_id);
+
+/*
+ * Send a message to a slave lcore identified by slave_id to call a
+ * function f with argument arg. Once the execution is done, the
+ * remote lcore switch in FINISHED state.
+ */
+int
+rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
+{
+	int n;
+	char c = 0;
+	int m2s = lcore_config[slave_id].pipe_master2slave[1];
+	int s2m = lcore_config[slave_id].pipe_slave2master[0];
+
+	if (lcore_config[slave_id].state != WAIT)
+		return -EBUSY;
+
+	lcore_config[slave_id].f = f;
+	lcore_config[slave_id].arg = arg;
+
+	/* send message */
+	n = 0;
+	while (n == 0 || (n < 0 && errno == EINTR))
+		n = write(m2s, &c, 1);
+	if (n < 0)
+		rte_panic("cannot write on configuration pipe\n");
+
+	/* wait ack */
+	do {
+		n = read(s2m, &c, 1);
+	} while (n < 0 && errno == EINTR);
+
+	if (n <= 0)
+		rte_panic("cannot read on configuration pipe\n");
+
+	return 0;
+}
+
+/* set affinity for current thread */
+static int
+eal_thread_set_affinity(void)
+{
+	int s;
+	pthread_t thread;
+
+/*
+ * According to the section VERSIONS of the CPU_ALLOC man page:
+ *
+ * The CPU_ZERO(), CPU_SET(), CPU_CLR(), and CPU_ISSET() macros were added
+ * in glibc 2.3.3.
+ *
+ * CPU_COUNT() first appeared in glibc 2.6.
+ *
+ * CPU_AND(),     CPU_OR(),     CPU_XOR(),    CPU_EQUAL(),    CPU_ALLOC(),
+ * CPU_ALLOC_SIZE(), CPU_FREE(), CPU_ZERO_S(),  CPU_SET_S(),  CPU_CLR_S(),
+ * CPU_ISSET_S(),  CPU_AND_S(), CPU_OR_S(), CPU_XOR_S(), and CPU_EQUAL_S()
+ * first appeared in glibc 2.7.
+ */
+#if defined(CPU_ALLOC)
+	size_t size;
+	cpu_set_t *cpusetp;
+
+	cpusetp = CPU_ALLOC(RTE_MAX_LCORE);
+	if (cpusetp == NULL) {
+		RTE_LOG(ERR, EAL, "CPU_ALLOC failed\n");
+		return -1;
+	}
+
+	size = CPU_ALLOC_SIZE(RTE_MAX_LCORE);
+	CPU_ZERO_S(size, cpusetp);
+	CPU_SET_S(rte_lcore_id(), size, cpusetp);
+
+	thread = pthread_self();
+	s = pthread_setaffinity_np(thread, size, cpusetp);
+	if (s != 0) {
+		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
+		CPU_FREE(cpusetp);
+		return -1;
+	}
+
+	CPU_FREE(cpusetp);
+#else /* CPU_ALLOC */
+#ifdef RTE_EXEC_ENV_BSDAPP
+	cpuset_t cpuset;
+#else  /* RTE_EXEC_ENV_BSDAPP */
+	cpu_set_t cpuset;
+#endif /* RTE_EXEC_ENV_BSDAPP */
+	CPU_ZERO(&cpuset);
+	CPU_SET(rte_lcore_id(), &cpuset);
+
+	thread = pthread_self();
+	s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
+	if (s != 0) {
+		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
+		return -1;
+	}
+#endif
+	return 0;
+}
+
+void eal_thread_init_master(unsigned lcore_id)
+{
+	/* set the lcore ID in per-lcore memory area */
+	RTE_PER_LCORE(_lcore_id) = lcore_id;
+
+	/* set CPU affinity */
+	if (eal_thread_set_affinity() < 0)
+		rte_panic("cannot set affinity\n");
+}
+
+/* main loop of threads */
+__attribute__((noreturn)) void *
+eal_thread_loop(__attribute__((unused)) void *arg)
+{
+	char c;
+	int n, ret;
+	unsigned lcore_id;
+	pthread_t thread_id;
+	int m2s, s2m;
+
+	thread_id = pthread_self();
+
+	/* retrieve our lcore_id from the configuration structure */
+	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+		if (thread_id == lcore_config[lcore_id].thread_id)
+			break;
+	}
+	if (lcore_id == RTE_MAX_LCORE)
+		rte_panic("cannot retrieve lcore id\n");
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+	RTE_LOG(DEBUG, EAL, "Core %u is ready (tid=%p)\n",
+		lcore_id, thread_id);
+#else  /* RTE_EXEC_ENV_BSDAPP */
+	RTE_LOG(DEBUG, EAL, "Core %u is ready (tid=%x)\n",
+		lcore_id, (int)thread_id);
+#endif /* RTE_EXEC_ENV_BSDAPP */
+
+	m2s = lcore_config[lcore_id].pipe_master2slave[0];
+	s2m = lcore_config[lcore_id].pipe_slave2master[1];
+
+	/* set the lcore ID in per-lcore memory area */
+	RTE_PER_LCORE(_lcore_id) = lcore_id;
+
+	/* set CPU affinity */
+	if (eal_thread_set_affinity() < 0)
+		rte_panic("cannot set affinity\n");
+
+	/* read on our pipe to get commands */
+	while (1) {
+		void *fct_arg;
+
+		/* wait command */
+		do {
+			n = read(m2s, &c, 1);
+		} while (n < 0 && errno == EINTR);
+
+		if (n <= 0)
+			rte_panic("cannot read on configuration pipe\n");
+
+		lcore_config[lcore_id].state = RUNNING;
+
+		/* send ack */
+		n = 0;
+		while (n == 0 || (n < 0 && errno == EINTR))
+			n = write(s2m, &c, 1);
+		if (n < 0)
+			rte_panic("cannot write on configuration pipe\n");
+
+		if (lcore_config[lcore_id].f == NULL)
+			rte_panic("NULL function pointer\n");
+
+		/* call the function and store the return value */
+		fct_arg = lcore_config[lcore_id].arg;
+		ret = lcore_config[lcore_id].f(fct_arg);
+		lcore_config[lcore_id].ret = ret;
+		rte_wmb();
+		lcore_config[lcore_id].state = FINISHED;
+	}
+
+	/* never reached */
+	/* pthread_exit(NULL); */
+	/* return NULL; */
+}
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 87b9bfc..9252333 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -56,7 +56,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_memory.c
 ifeq ($(CONFIG_RTE_LIBRTE_XEN_DOM0),y)
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_xen_memory.c
 endif
-SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_pci_uio.c
@@ -85,9 +84,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_debug.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
-CFLAGS_eal_thread.o := -D_GNU_SOURCE
+CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
 CFLAGS_eal_log.o := -D_GNU_SOURCE
 CFLAGS_eal_common_log.o := -D_GNU_SOURCE
 CFLAGS_eal_hugepage_info.o := -D_GNU_SOURCE
@@ -98,7 +98,7 @@ CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
 ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
-CFLAGS_eal_thread.o += -Wno-return-type
+CFLAGS_eal_common_thread.o += -Wno-return-type
 endif
 
 INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h
diff --git a/lib/librte_eal/linuxapp/eal/eal_thread.c b/lib/librte_eal/linuxapp/eal/eal_thread.c
deleted file mode 100644
index 80a985f..0000000
--- a/lib/librte_eal/linuxapp/eal/eal_thread.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <sched.h>
-#include <sys/queue.h>
-
-#include <rte_debug.h>
-#include <rte_atomic.h>
-#include <rte_launch.h>
-#include <rte_log.h>
-#include <rte_memory.h>
-#include <rte_memzone.h>
-#include <rte_per_lcore.h>
-#include <rte_tailq.h>
-#include <rte_eal.h>
-#include <rte_per_lcore.h>
-#include <rte_lcore.h>
-
-#include "eal_private.h"
-#include "eal_thread.h"
-
-RTE_DEFINE_PER_LCORE(unsigned, _lcore_id);
-
-/*
- * Send a message to a slave lcore identified by slave_id to call a
- * function f with argument arg. Once the execution is done, the
- * remote lcore switch in FINISHED state.
- */
-int
-rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
-{
-	int n;
-	char c = 0;
-	int m2s = lcore_config[slave_id].pipe_master2slave[1];
-	int s2m = lcore_config[slave_id].pipe_slave2master[0];
-
-	if (lcore_config[slave_id].state != WAIT)
-		return -EBUSY;
-
-	lcore_config[slave_id].f = f;
-	lcore_config[slave_id].arg = arg;
-
-	/* send message */
-	n = 0;
-	while (n == 0 || (n < 0 && errno == EINTR))
-		n = write(m2s, &c, 1);
-	if (n < 0)
-		rte_panic("cannot write on configuration pipe\n");
-
-	/* wait ack */
-	do {
-		n = read(s2m, &c, 1);
-	} while (n < 0 && errno == EINTR);
-
-	if (n <= 0)
-		rte_panic("cannot read on configuration pipe\n");
-
-	return 0;
-}
-
-/* set affinity for current thread */
-static int
-eal_thread_set_affinity(void)
-{
-	int s;
-	pthread_t thread;
-
-/*
- * According to the section VERSIONS of the CPU_ALLOC man page:
- *
- * The CPU_ZERO(), CPU_SET(), CPU_CLR(), and CPU_ISSET() macros were added
- * in glibc 2.3.3.
- *
- * CPU_COUNT() first appeared in glibc 2.6.
- *
- * CPU_AND(),     CPU_OR(),     CPU_XOR(),    CPU_EQUAL(),    CPU_ALLOC(),
- * CPU_ALLOC_SIZE(), CPU_FREE(), CPU_ZERO_S(),  CPU_SET_S(),  CPU_CLR_S(),
- * CPU_ISSET_S(),  CPU_AND_S(), CPU_OR_S(), CPU_XOR_S(), and CPU_EQUAL_S()
- * first appeared in glibc 2.7.
- */
-#if defined(CPU_ALLOC)
-	size_t size;
-	cpu_set_t *cpusetp;
-
-	cpusetp = CPU_ALLOC(RTE_MAX_LCORE);
-	if (cpusetp == NULL) {
-		RTE_LOG(ERR, EAL, "CPU_ALLOC failed\n");
-		return -1;
-	}
-
-	size = CPU_ALLOC_SIZE(RTE_MAX_LCORE);
-	CPU_ZERO_S(size, cpusetp);
-	CPU_SET_S(rte_lcore_id(), size, cpusetp);
-
-	thread = pthread_self();
-	s = pthread_setaffinity_np(thread, size, cpusetp);
-	if (s != 0) {
-		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
-		CPU_FREE(cpusetp);
-		return -1;
-	}
-
-	CPU_FREE(cpusetp);
-#else /* CPU_ALLOC */
-	cpu_set_t cpuset;
-	CPU_ZERO( &cpuset );
-	CPU_SET( rte_lcore_id(), &cpuset );
-
-	thread = pthread_self();
-	s = pthread_setaffinity_np(thread, sizeof( cpuset ), &cpuset);
-	if (s != 0) {
-		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
-		return -1;
-	}
-#endif
-	return 0;
-}
-
-void eal_thread_init_master(unsigned lcore_id)
-{
-	/* set the lcore ID in per-lcore memory area */
-	RTE_PER_LCORE(_lcore_id) = lcore_id;
-
-	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
-		rte_panic("cannot set affinity\n");
-}
-
-/* main loop of threads */
-__attribute__((noreturn)) void *
-eal_thread_loop(__attribute__((unused)) void *arg)
-{
-	char c;
-	int n, ret;
-	unsigned lcore_id;
-	pthread_t thread_id;
-	int m2s, s2m;
-
-	thread_id = pthread_self();
-
-	/* retrieve our lcore_id from the configuration structure */
-	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-		if (thread_id == lcore_config[lcore_id].thread_id)
-			break;
-	}
-	if (lcore_id == RTE_MAX_LCORE)
-		rte_panic("cannot retrieve lcore id\n");
-
-	RTE_LOG(DEBUG, EAL, "Core %u is ready (tid=%x)\n",
-		lcore_id, (int)thread_id);
-
-	m2s = lcore_config[lcore_id].pipe_master2slave[0];
-	s2m = lcore_config[lcore_id].pipe_slave2master[1];
-
-	/* set the lcore ID in per-lcore memory area */
-	RTE_PER_LCORE(_lcore_id) = lcore_id;
-
-	/* set CPU affinity */
-	if (eal_thread_set_affinity() < 0)
-		rte_panic("cannot set affinity\n");
-
-	/* read on our pipe to get commands */
-	while (1) {
-		void *fct_arg;
-
-		/* wait command */
-		do {
-			n = read(m2s, &c, 1);
-		} while (n < 0 && errno == EINTR);
-
-		if (n <= 0)
-			rte_panic("cannot read on configuration pipe\n");
-
-		lcore_config[lcore_id].state = RUNNING;
-
-		/* send ack */
-		n = 0;
-		while (n == 0 || (n < 0 && errno == EINTR))
-			n = write(s2m, &c, 1);
-		if (n < 0)
-			rte_panic("cannot write on configuration pipe\n");
-
-		if (lcore_config[lcore_id].f == NULL)
-			rte_panic("NULL function pointer\n");
-
-		/* call the function and store the return value */
-		fct_arg = lcore_config[lcore_id].arg;
-		ret = lcore_config[lcore_id].f(fct_arg);
-		lcore_config[lcore_id].ret = ret;
-		rte_wmb();
-		lcore_config[lcore_id].state = FINISHED;
-	}
-
-	/* never reached */
-	/* pthread_exit(NULL); */
-	/* return NULL; */
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
                   ` (2 preceding siblings ...)
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 3/7] " Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2014-12-25 17:44   ` Neil Horman
  2015-01-05 15:59   ` Thomas Monjalon
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 5/7] " Ravi Kerur
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

Move common functions in eal.c to librte_eal/common directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common functions.
Makefile changes to reflect new file.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile    |   1 +
 lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
 lib/librte_eal/common/eal_common.c    | 328 ++++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_externs.h   |  42 +++++
 lib/librte_eal/common/eal_hugepages.h |   1 +
 lib/librte_eal/common/eal_private.h   |  47 +++++
 lib/librte_eal/linuxapp/eal/Makefile  |   1 +
 lib/librte_eal/linuxapp/eal/eal.c     | 246 ++-----------------------
 8 files changed, 439 insertions(+), 460 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common.c
 create mode 100644 lib/librte_eal/common/eal_externs.h

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 92dd9a6..050d70b 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 69f3c03..f925da7 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -80,30 +80,10 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_externs.h"
 
 #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;
-/* early configuration structure, when memory config is not mmapped */
-static struct rte_mem_config early_mem_config;
-
-/* 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;
-
-static struct flock wr_lock = {
-		.l_type = F_WRLCK,
-		.l_whence = SEEK_SET,
-		.l_start = offsetof(struct rte_mem_config, memseg),
-		.l_len = sizeof(early_mem_config.memseg),
-};
-
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
-		.mem_config = &early_mem_config,
-};
-
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
@@ -113,93 +93,14 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
+inline void *
+rte_eal_get_mem_cfg_addr(void)
 {
-	return &rte_config;
-}
-
-/* parse a sysfs (or other) file containing one integer value */
-int
-eal_parse_sysfs_value(const char *filename, unsigned long *val)
-{
-	FILE *f;
-	char buf[BUFSIZ];
-	char *end = NULL;
-
-	if ((f = fopen(filename, "r")) == NULL) {
-		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
-			__func__, filename);
-		return -1;
-	}
-
-	if (fgets(buf, sizeof(buf), f) == NULL) {
-		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
-			__func__, filename);
-		fclose(f);
-		return -1;
-	}
-	*val = strtoul(buf, &end, 0);
-	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
-		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
-				__func__, filename);
-		fclose(f);
-		return -1;
-	}
-	fclose(f);
-	return 0;
-}
-
-
-/* create memory configuration in shared/mmap memory. Take out
- * a write lock on the memsegs, so we can auto-detect primary/secondary.
- * This means we never close the file while running (auto-close on exit).
- * We also don't lock the whole file, so that in future we can use read-locks
- * on other parts, e.g. memzones, to detect if there are running secondary
- * processes. */
-static void
-rte_eal_config_create(void)
-{
-	void *rte_mem_cfg_addr;
-	int retval;
-
-	const char *pathname = eal_runtime_config_path();
-
-	if (internal_config.no_shconf)
-		return;
-
-	if (mem_cfg_fd < 0){
-		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
-		if (mem_cfg_fd < 0)
-			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
-	}
-
-	retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
-	if (retval < 0){
-		close(mem_cfg_fd);
-		rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
-	}
-
-	retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
-	if (retval < 0){
-		close(mem_cfg_fd);
-		rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
-				"process running?\n", pathname);
-	}
-
-	rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
-				PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
-
-	if (rte_mem_cfg_addr == MAP_FAILED){
-		rte_panic("Cannot mmap memory for rte_config\n");
-	}
-	memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
-	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
+	return NULL;
 }
 
 /* attach to an existing shared memory config */
-static void
+void
 rte_eal_config_attach(void)
 {
 	void *rte_mem_cfg_addr;
@@ -223,44 +124,11 @@ rte_eal_config_attach(void)
 	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
 }
 
-/* Detect if we are a primary or a secondary process */
-enum rte_proc_type_t
-eal_proc_type_detect(void)
+/* NOP for BSD */
+void
+rte_eal_config_reattach(void)
 {
-	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
-	const char *pathname = eal_runtime_config_path();
-
-	/* if we can open the file but not get a write-lock we are a secondary
-	 * process. NOTE: if we get a file handle back, we keep that open
-	 * and don't close it to prevent a race condition between multiple opens */
-	if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
-			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
-		ptype = RTE_PROC_SECONDARY;
-
-	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
-			ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
 
-	return ptype;
-}
-
-/* Sets up rte_config structure with the pointer to shared memory config.*/
-static void
-rte_config_init(void)
-{
-	rte_config.process_type = internal_config.process_type;
-
-	switch (rte_config.process_type){
-	case RTE_PROC_PRIMARY:
-		rte_eal_config_create();
-		break;
-	case RTE_PROC_SECONDARY:
-		rte_eal_config_attach();
-		rte_eal_mcfg_wait_complete(rte_config.mem_config);
-		break;
-	case RTE_PROC_AUTO:
-	case RTE_PROC_INVALID:
-		rte_panic("Invalid process type\n");
-	}
 }
 
 /* display usage */
@@ -276,37 +144,6 @@ eal_usage(const char *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)
-{
-	uint64_t size = 0;
-	unsigned i, j;
-
-	for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &internal_config.hugepage_info[i];
-		if (hpi->hugedir != NULL) {
-			for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-				size += hpi->hugepage_sz * hpi->num_pages[j];
-			}
-		}
-	}
-
-	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
-}
-
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -374,45 +211,6 @@ eal_parse_args(int argc, char **argv)
 	return ret;
 }
 
-static void
-eal_check_mem_on_local_socket(void)
-{
-	const struct rte_memseg *ms;
-	int i, socket_id;
-
-	socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
-
-	ms = rte_eal_get_physmem_layout();
-
-	for (i = 0; i < RTE_MAX_MEMSEG; i++)
-		if (ms[i].socket_id == socket_id &&
-				ms[i].len > 0)
-			return;
-
-	RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
-			"memory on local socket!\n");
-}
-
-static int
-sync_func(__attribute__((unused)) void *arg)
-{
-	return 0;
-}
-
-inline static void
-rte_eal_mcfg_complete(void)
-{
-	/* ALL shared mem_config related INIT DONE */
-	if (rte_config.process_type == RTE_PROC_PRIMARY)
-		rte_config.mem_config->magic = RTE_MAGIC;
-}
-
-/* return non-zero if hugepages are enabled. */
-int rte_eal_has_hugepages(void)
-{
-	return !internal_config.no_hugetlbfs;
-}
-
 /* Abstraction for port I/0 privilege */
 int
 rte_eal_iopl_init(void)
@@ -476,7 +274,7 @@ rte_eal_init(int argc, char **argv)
 
 	rte_srand(rte_rdtsc());
 
-	rte_config_init();
+	rte_eal_config_init();
 
 	if (rte_eal_memory_init() < 0)
 		rte_panic("Cannot init memory\n");
@@ -548,16 +346,3 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
-/* get core role */
-enum rte_lcore_role_t
-rte_eal_lcore_role(unsigned lcore_id)
-{
-	return (rte_config.lcore_role[lcore_id]);
-}
-
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
-	return (rte_config.process_type);
-}
-
diff --git a/lib/librte_eal/common/eal_common.c b/lib/librte_eal/common/eal_common.c
new file mode 100644
index 0000000..becf9c8
--- /dev/null
+++ b/lib/librte_eal/common/eal_common.c
@@ -0,0 +1,328 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2014 6WIND S.A.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <syslog.h>
+#include <getopt.h>
+#include <sys/file.h>
+#include <stddef.h>
+#include <errno.h>
+#include <limits.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/queue.h>
+
+#include <rte_common.h>
+#include <rte_debug.h>
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include <rte_launch.h>
+#include <rte_tailq.h>
+#include <rte_eal.h>
+#include <rte_eal_memconfig.h>
+#include <rte_per_lcore.h>
+#include <rte_lcore.h>
+#include <rte_log.h>
+#include <rte_random.h>
+#include <rte_cycles.h>
+#include <rte_string_fns.h>
+#include <rte_cpuflags.h>
+#include <rte_interrupts.h>
+#include <rte_pci.h>
+#include <rte_dev.h>
+#include <rte_devargs.h>
+#include <rte_common.h>
+#include <rte_version.h>
+#include <rte_atomic.h>
+#include <malloc_heap.h>
+#include <rte_eth_ring.h>
+
+#include "eal_private.h"
+#include "eal_thread.h"
+#include "eal_internal_cfg.h"
+#include "eal_filesystem.h"
+#include "eal_hugepages.h"
+#include "eal_options.h"
+
+/* Allow the application to print its usage message too if set */
+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 */
+int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
+/* Address of global and public configuration */
+struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
+
+static struct flock wr_lock = {
+		.l_type = F_WRLCK,
+		.l_whence = SEEK_SET,
+		.l_start = offsetof(struct rte_mem_config, memseg),
+		.l_len = sizeof(early_mem_config.memseg),
+};
+
+/* Return a pointer to the configuration structure */
+struct rte_config *
+rte_eal_get_configuration(void)
+{
+	return &rte_config;
+}
+
+/* parse a sysfs (or other) file containing one integer value */
+int
+eal_parse_sysfs_value(const char *filename, unsigned long *val)
+{
+	FILE *f;
+	char buf[BUFSIZ];
+	char *end = NULL;
+
+	f = fopen(filename, "r");
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
+			__func__, filename);
+		return -1;
+	}
+
+	if (fgets(buf, sizeof(buf), f) == NULL) {
+		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
+			__func__, filename);
+		fclose(f);
+		return -1;
+	}
+	*val = strtoul(buf, &end, 0);
+	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
+		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
+				__func__, filename);
+		fclose(f);
+		return -1;
+	}
+	fclose(f);
+	return 0;
+}
+
+
+/* create memory configuration in shared/mmap memory. Take out
+ * a write lock on the memsegs, so we can auto-detect primary/secondary.
+ * This means we never close the file while running (auto-close on exit).
+ * We also don't lock the whole file, so that in future we can use read-locks
+ * on other parts, e.g. memzones, to detect if there are running secondary
+ * processes. */
+static void
+rte_eal_config_create(void)
+{
+	void *rte_mem_cfg_addr;
+	int retval;
+
+	const char *pathname = eal_runtime_config_path();
+
+	if (internal_config.no_shconf)
+		return;
+
+	rte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();
+
+	if (mem_cfg_fd < 0) {
+		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
+		if (mem_cfg_fd < 0)
+			rte_panic("Cannot open '%s' for rte_mem_config\n",
+					pathname);
+	}
+
+	retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
+	if (retval < 0) {
+		close(mem_cfg_fd);
+		rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
+	}
+
+	retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
+	if (retval < 0) {
+		close(mem_cfg_fd);
+		rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. "
+			"Is another primary process running?\n", pathname);
+	}
+
+	rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
+			sizeof(*rte_config.mem_config), PROT_READ | PROT_WRITE,
+			MAP_SHARED, mem_cfg_fd, 0);
+
+	if (rte_mem_cfg_addr == MAP_FAILED)
+		rte_panic("Cannot mmap memory for rte_config\n");
+
+	memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
+	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
+
+#ifndef RTE_EXEC_ENV_BSDAPP
+	/* store address of the config in the config itself so that secondary
+	 * processes could later map the config into this exact location
+	 */
+	rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
+#endif /* RTE_EXEC_ENV_BSDAPP */
+}
+
+/* Detect if we are a primary or a secondary process */
+enum rte_proc_type_t
+eal_proc_type_detect(void)
+{
+	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
+	const char *pathname = eal_runtime_config_path();
+
+	/* if we can open the file but not get a write-lock we are
+	 * a secondary process. NOTE: if we get a file handle back,
+	 * we keep that open and don't close it to prevent a race
+	 * condition between multiple opens
+	 */
+	mem_cfg_fd = open(pathname, O_RDWR);
+	if ((mem_cfg_fd >= 0) &&
+			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
+		ptype = RTE_PROC_SECONDARY;
+
+	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
+			ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
+
+	return ptype;
+}
+
+/* Sets up rte_config structure with the pointer to shared memory config.*/
+void
+rte_eal_config_init(void)
+{
+	rte_config.process_type = internal_config.process_type;
+
+	switch (rte_config.process_type) {
+	case RTE_PROC_PRIMARY:
+		rte_eal_config_create();
+		break;
+	case RTE_PROC_SECONDARY:
+		rte_eal_config_attach();
+		rte_eal_mcfg_wait_complete(rte_config.mem_config);
+		rte_eal_config_reattach();
+		break;
+	case RTE_PROC_AUTO:
+	case RTE_PROC_INVALID:
+		rte_panic("Invalid process type\n");
+	}
+}
+
+/* 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;
+}
+
+inline size_t
+eal_get_hugepage_mem_size(void)
+{
+	uint64_t size = 0;
+	unsigned i, j;
+
+	for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
+		struct hugepage_info *hpi = &internal_config.hugepage_info[i];
+
+		if (hpi->hugedir != NULL) {
+			for (j = 0; j < RTE_MAX_NUMA_NODES; j++)
+				size += hpi->hugepage_sz * hpi->num_pages[j];
+		}
+	}
+
+	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
+}
+
+void
+eal_check_mem_on_local_socket(void)
+{
+	const struct rte_memseg *ms;
+	int i, socket_id;
+
+	socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
+
+	ms = rte_eal_get_physmem_layout();
+
+	for (i = 0; i < RTE_MAX_MEMSEG; i++)
+		if (ms[i].socket_id == socket_id &&
+				ms[i].len > 0)
+			return;
+
+	RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
+			"memory on local socket!\n");
+}
+
+int
+sync_func(__attribute__((unused)) void *arg)
+{
+	return 0;
+}
+
+inline void
+rte_eal_mcfg_complete(void)
+{
+	/* ALL shared mem_config related INIT DONE */
+	if (rte_config.process_type == RTE_PROC_PRIMARY)
+		rte_config.mem_config->magic = RTE_MAGIC;
+}
+
+/* return non-zero if hugepages are enabled. */
+int rte_eal_has_hugepages(void)
+{
+	return !internal_config.no_hugetlbfs;
+}
+
+/* get core role */
+enum rte_lcore_role_t
+rte_eal_lcore_role(unsigned lcore_id)
+{
+	return rte_config.lcore_role[lcore_id];
+}
+
+enum rte_proc_type_t
+rte_eal_process_type(void)
+{
+	return rte_config.process_type;
+}
diff --git a/lib/librte_eal/common/eal_externs.h b/lib/librte_eal/common/eal_externs.h
new file mode 100644
index 0000000..b19bea6
--- /dev/null
+++ b/lib/librte_eal/common/eal_externs.h
@@ -0,0 +1,42 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EAL_EXTERNS_H
+#define EAL_EXTERNS_H
+
+/* Extern declarations defined in eal_common.c */
+extern struct rte_config rte_config;
+extern int mem_cfg_fd;
+extern rte_usage_hook_t	rte_application_usage_hook;
+
+#endif
diff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h
index 38edac0..0b4d7a2 100644
--- a/lib/librte_eal/common/eal_hugepages.h
+++ b/lib/librte_eal/common/eal_hugepages.h
@@ -63,5 +63,6 @@ struct hugepage_file {
  * for the EAL to use
  */
 int eal_hugepage_info_init(void);
+inline size_t eal_get_hugepage_mem_size(void);
 
 #endif /* EAL_HUGEPAGES_H */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 232fcec..b1d68bc 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -203,4 +203,51 @@ int rte_eal_alarm_init(void);
  */
 int rte_eal_dev_init(void);
 
+/**
+ * This function sets up rte_config structure
+ *
+ * This function is private to the EAL.
+ */
+void rte_eal_config_init(void);
+
+/**
+ * This function checks memory on local socket(NUMA)
+ *
+ * This function is private to the EAL.
+ */
+void eal_check_mem_on_local_socket(void);
+
+/**
+ * This function updates shared mem_config INIT DONE
+ *
+ * This function is private to the EAL.
+ */
+inline void rte_eal_mcfg_complete(void);
+
+/**
+ *
+ * This function is private to the EAL.
+ */
+int sync_func(__attribute__((unused)) void *arg);
+
+/**
+ *
+ * This function is private to the EAL.
+ */
+inline void *rte_eal_get_mem_cfg_addr(void);
+
+/**
+ * This function attaches shared memory config
+ *
+ * This function is private to the EAL.
+ */
+void rte_eal_config_attach(void);
+
+/**
+ * This function reattaches shared memory config
+ *
+ * This function is private to the EAL.
+ */
+void rte_eal_config_reattach(void);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 9252333..60cc448 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -70,6 +70,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_ivshmem.c
 endif
 
 # from common dir
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 2fb1acc..6d3f854 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -84,14 +84,12 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_externs.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
 
 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
 
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t	rte_application_usage_hook = NULL;
-
 TAILQ_HEAD(shared_driver_list, shared_driver);
 
 /* Definition for shared object drivers. */
@@ -106,25 +104,6 @@ struct shared_driver {
 static struct shared_driver_list solib_list =
 TAILQ_HEAD_INITIALIZER(solib_list);
 
-/* early configuration structure, when memory config is not mmapped */
-static struct rte_mem_config early_mem_config;
-
-/* 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;
-
-static struct flock wr_lock = {
-		.l_type = F_WRLCK,
-		.l_whence = SEEK_SET,
-		.l_start = offsetof(struct rte_mem_config, memseg),
-		.l_len = sizeof(early_mem_config.memseg),
-};
-
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
-		.mem_config = &early_mem_config,
-};
-
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
@@ -134,106 +113,23 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
-	return &rte_config;
-}
-
-/* parse a sysfs (or other) file containing one integer value */
-int
-eal_parse_sysfs_value(const char *filename, unsigned long *val)
-{
-	FILE *f;
-	char buf[BUFSIZ];
-	char *end = NULL;
-
-	if ((f = fopen(filename, "r")) == NULL) {
-		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
-			__func__, filename);
-		return -1;
-	}
-
-	if (fgets(buf, sizeof(buf), f) == NULL) {
-		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
-			__func__, filename);
-		fclose(f);
-		return -1;
-	}
-	*val = strtoul(buf, &end, 0);
-	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
-		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
-				__func__, filename);
-		fclose(f);
-		return -1;
-	}
-	fclose(f);
-	return 0;
-}
-
-
-/* create memory configuration in shared/mmap memory. Take out
- * a write lock on the memsegs, so we can auto-detect primary/secondary.
- * This means we never close the file while running (auto-close on exit).
- * We also don't lock the whole file, so that in future we can use read-locks
- * on other parts, e.g. memzones, to detect if there are running secondary
- * processes. */
-static void
-rte_eal_config_create(void)
+inline void *
+rte_eal_get_mem_cfg_addr(void)
 {
-	void *rte_mem_cfg_addr;
-	int retval;
-
-	const char *pathname = eal_runtime_config_path();
-
-	if (internal_config.no_shconf)
-		return;
+	void *mem_cfg_addr;
 
-	/* map the config before hugepage address so that we don't waste a page */
 	if (internal_config.base_virtaddr != 0)
-		rte_mem_cfg_addr = (void *)
+		mem_cfg_addr = (void *)
 			RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
 			sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
 	else
-		rte_mem_cfg_addr = NULL;
-
-	if (mem_cfg_fd < 0){
-		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
-		if (mem_cfg_fd < 0)
-			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
-	}
-
-	retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
-	if (retval < 0){
-		close(mem_cfg_fd);
-		rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
-	}
-
-	retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
-	if (retval < 0){
-		close(mem_cfg_fd);
-		rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
-				"process running?\n", pathname);
-	}
-
-	rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
-				PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
-
-	if (rte_mem_cfg_addr == MAP_FAILED){
-		rte_panic("Cannot mmap memory for rte_config\n");
-	}
-	memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
-	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
-
-	/* store address of the config in the config itself so that secondary
-	 * processes could later map the config into this exact location */
-	rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
+		mem_cfg_addr = NULL;
 
+	return mem_cfg_addr;
 }
 
 /* attach to an existing shared memory config */
-static void
+void
 rte_eal_config_attach(void)
 {
 	struct rte_mem_config *mem_config;
@@ -259,7 +155,7 @@ rte_eal_config_attach(void)
 }
 
 /* reattach the shared config at exact memory location primary process has it */
-static void
+void
 rte_eal_config_reattach(void)
 {
 	struct rte_mem_config *mem_config;
@@ -285,47 +181,6 @@ rte_eal_config_reattach(void)
 	rte_config.mem_config = mem_config;
 }
 
-/* Detect if we are a primary or a secondary process */
-enum rte_proc_type_t
-eal_proc_type_detect(void)
-{
-	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
-	const char *pathname = eal_runtime_config_path();
-
-	/* if we can open the file but not get a write-lock we are a secondary
-	 * process. NOTE: if we get a file handle back, we keep that open
-	 * and don't close it to prevent a race condition between multiple opens */
-	if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
-			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
-		ptype = RTE_PROC_SECONDARY;
-
-	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
-			ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
-
-	return ptype;
-}
-
-/* Sets up rte_config structure with the pointer to shared memory config.*/
-static void
-rte_config_init(void)
-{
-	rte_config.process_type = internal_config.process_type;
-
-	switch (rte_config.process_type){
-	case RTE_PROC_PRIMARY:
-		rte_eal_config_create();
-		break;
-	case RTE_PROC_SECONDARY:
-		rte_eal_config_attach();
-		rte_eal_mcfg_wait_complete(rte_config.mem_config);
-		rte_eal_config_reattach();
-		break;
-	case RTE_PROC_AUTO:
-	case RTE_PROC_INVALID:
-		rte_panic("Invalid process type\n");
-	}
-}
-
 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
 static void
 eal_hugedirs_unlock(void)
@@ -371,19 +226,6 @@ eal_usage(const char *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_mem(char *socket_mem)
 {
@@ -485,24 +327,6 @@ eal_parse_vfio_intr(const char *mode)
 	return -1;
 }
 
-static inline size_t
-eal_get_hugepage_mem_size(void)
-{
-	uint64_t size = 0;
-	unsigned i, j;
-
-	for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &internal_config.hugepage_info[i];
-		if (hpi->hugedir != NULL) {
-			for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-				size += hpi->hugepage_sz * hpi->num_pages[j];
-			}
-		}
-	}
-
-	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
-}
-
 /* Parse the argument given in the command line of the application */
 static int
 eal_parse_args(int argc, char **argv)
@@ -643,39 +467,6 @@ eal_parse_args(int argc, char **argv)
 	return ret;
 }
 
-static void
-eal_check_mem_on_local_socket(void)
-{
-	const struct rte_memseg *ms;
-	int i, socket_id;
-
-	socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
-
-	ms = rte_eal_get_physmem_layout();
-
-	for (i = 0; i < RTE_MAX_MEMSEG; i++)
-		if (ms[i].socket_id == socket_id &&
-				ms[i].len > 0)
-			return;
-
-	RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
-			"memory on local socket!\n");
-}
-
-static int
-sync_func(__attribute__((unused)) void *arg)
-{
-	return 0;
-}
-
-inline static void
-rte_eal_mcfg_complete(void)
-{
-	/* ALL shared mem_config related INIT DONE */
-	if (rte_config.process_type == RTE_PROC_PRIMARY)
-		rte_config.mem_config->magic = RTE_MAGIC;
-}
-
 /*
  * Request iopl privilege for all RPL, returns 0 on success
  * iopl() call is mostly for the i386 architecture. For other architectures,
@@ -750,7 +541,7 @@ rte_eal_init(int argc, char **argv)
 
 	rte_srand(rte_rdtsc());
 
-	rte_config_init();
+	rte_eal_config_init();
 
 	if (rte_eal_pci_init() < 0)
 		rte_panic("Cannot init PCI\n");
@@ -842,20 +633,3 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
-/* get core role */
-enum rte_lcore_role_t
-rte_eal_lcore_role(unsigned lcore_id)
-{
-	return (rte_config.lcore_role[lcore_id]);
-}
-
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
-	return (rte_config.process_type);
-}
-
-int rte_eal_has_hugepages(void)
-{
-	return ! internal_config.no_hugetlbfs;
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 5/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
                   ` (3 preceding siblings ...)
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 4/7] " Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2015-01-05 15:32   ` Thomas Monjalon
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 6/7] " Ravi Kerur
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

Move common functions in eal_lcore.c to librte_eal/common
directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common functions.
Makefile changes to reflect new file.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile       |   1 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c    |  62 ++++--------------
 lib/librte_eal/common/eal_common_lcore.c | 106 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h      |  32 ++++++++++
 lib/librte_eal/linuxapp/eal/Makefile     |   1 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c  |  55 +---------------
 6 files changed, 155 insertions(+), 102 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 050d70b..560b7a3 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -74,6 +74,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
index 662f024..874fd88 100644
--- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
+++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
@@ -43,10 +43,19 @@
 #include "eal_private.h"
 
 /* No topology information available on FreeBSD including NUMA info */
-#define cpu_core_id(X) 0
-#define cpu_socket_id(X) 0
+unsigned
+cpu_core_id(__attribute__((unused)) unsigned lcore_id)
+{
+	return 0;
+}
+
+unsigned
+cpu_socket_id(__attribute__((unused)) unsigned lcore_id)
+{
+	return 0;
+}
 
-static int
+int
 get_ncpus(void)
 {
 	int mib[2] = {CTL_HW, HW_NCPU};
@@ -58,50 +67,3 @@ get_ncpus(void)
 	return ncpu;
 }
 
-/*
- * fill the cpu_info structure with as much info as we can get.
- * code is similar to linux version, but sadly available info is less.
- */
-int
-rte_eal_cpu_init(void)
-{
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	const unsigned ncpus = get_ncpus();
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		lcore_config[lcore_id].detected = (lcore_id < ncpus);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
-				lcore_id);
-		count++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
-	return 0;
-}
diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
new file mode 100644
index 0000000..af19d00
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -0,0 +1,106 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+#include <sys/sysctl.h>
+
+#include <rte_log.h>
+#include <rte_eal.h>
+#include <rte_lcore.h>
+#include <rte_common.h>
+#include <rte_debug.h>
+
+#include "eal_private.h"
+
+/*
+ * fill the cpu_info structure with as much info as we can get.
+ * code is similar to linux version, but sadly available info is less.
+ */
+int
+rte_eal_cpu_init(void)
+{
+	/* pointer to global configuration */
+	struct rte_config *config = rte_eal_get_configuration();
+	unsigned lcore_id;
+	unsigned count = 0;
+
+	/*
+	 * Parse the maximum set of logical cores, detect the subset of running
+	 * ones and enable them by default.
+	 */
+	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
+#ifdef RTE_EXEC_ENV_BSDAPP
+		const unsigned ncpus = get_ncpus();
+
+		lcore_config[lcore_id].detected = (lcore_id < ncpus);
+#else /* RTE_EXEC_ENV_BSDAPP */
+		lcore_config[lcore_id].detected = cpu_detected(lcore_id);
+#endif /* RTE_EXEC_ENV_BSDAPP */
+		if (lcore_config[lcore_id].detected == 0) {
+			config->lcore_role[lcore_id] = ROLE_OFF;
+			continue;
+		}
+		/* By default, each detected core is enabled */
+		config->lcore_role[lcore_id] = ROLE_RTE;
+		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
+		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
+		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
+#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
+			lcore_config[lcore_id].socket_id = 0;
+#else
+			rte_panic("Socket ID (%u) is greater than "
+				"RTE_MAX_NUMA_NODES (%d)\n",
+				lcore_config[lcore_id].socket_id,
+				RTE_MAX_NUMA_NODES);
+#endif
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
+				lcore_id);
+#else /* RTE_EXEC_ENV_BSDAPP */
+		RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
+				"core %u on socket %u\n",
+				lcore_id, lcore_config[lcore_id].core_id,
+				lcore_config[lcore_id].socket_id);
+#endif /* RTE_EXEC_ENV_BSDAPP */
+		count++;
+	}
+	/* Set the count of enabled logical cores of the EAL configuration */
+	config->lcore_count = count;
+	RTE_LOG(DEBUG, EAL,
+		"Support maximum %u logical core(s) by configuration.\n",
+		RTE_MAX_LCORE);
+	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
+
+	return 0;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b1d68bc..9fe91b3 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -250,4 +250,36 @@ void rte_eal_config_attach(void);
  */
 void rte_eal_config_reattach(void);
 
+/**
+ * This function gets cpu socket_id
+ *
+ * This function is private to the EAL.
+ */
+unsigned cpu_socket_id(unsigned lcore_id);
+
+/**
+ * This function gets cpu core_id
+ *
+ * This function is private to the EAL.
+ */
+unsigned cpu_core_id(unsigned lcore_id);
+
+#ifdef RTE_EXEC_ENV_BSDAPP
+/**
+ * This function gets no. of cpus
+ *
+ * This function is private to the EAL.
+ */
+int get_ncpus(void);
+
+#else /* RTE_EXEC_ENV_BSDAPP */
+/**
+ * This function check if cpu is present
+ *
+ * This function is private to the EAL.
+ */
+int cpu_detected(unsigned lcore_id);
+
+#endif /* RTE_EXEC_ENV_BSDAPP */
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 60cc448..ff185fd 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -86,6 +86,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c
index c67e0e6..4fe2a53 100644
--- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
+++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
@@ -51,7 +51,7 @@
 #define PHYS_PKG_FILE "topology/physical_package_id"
 
 /* Check if a cpu is present by the presence of the cpu information for it */
-static int
+int
 cpu_detected(unsigned lcore_id)
 {
 	char path[PATH_MAX];
@@ -71,7 +71,7 @@ cpu_detected(unsigned lcore_id)
  * Note: physical package id != NUMA node, but we use it as a
  * fallback for kernels which don't create a nodeY link
  */
-static unsigned
+unsigned
 cpu_socket_id(unsigned lcore_id)
 {
 	const char node_prefix[] = "node";
@@ -121,7 +121,7 @@ err:
 }
 
 /* Get the cpu core id value from the /sys/.../cpuX core_id value */
-static unsigned
+unsigned
 cpu_core_id(unsigned lcore_id)
 {
 	char path[PATH_MAX];
@@ -140,52 +140,3 @@ err:
 	return 0;
 }
 
-/*
- * Parse /sys/devices/system/cpu to get the number of physical and logical
- * processors on the machine. The function will fill the cpu_info
- * structure.
- */
-int
-rte_eal_cpu_init(void)
-{
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		lcore_config[lcore_id].detected = cpu_detected(lcore_id);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u as core %u on socket %u\n",
-				lcore_id,
-				lcore_config[lcore_id].core_id,
-				lcore_config[lcore_id].socket_id);
-		count ++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
-	return 0;
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 6/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
                   ` (4 preceding siblings ...)
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 5/7] " Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2015-01-05 15:49   ` Thomas Monjalon
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 7/7] " Ravi Kerur
  2014-12-29  8:47 ` [dpdk-dev] [PATCH 0/7] " Olivier MATZ
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

Move common functions in eal_timer.c to librte_eal/common
directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common functions.
Makefile changes to reflect new file.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile       |  1 +
 lib/librte_eal/bsdapp/eal/eal_timer.c    | 50 +---------------
 lib/librte_eal/common/eal_common_timer.c | 99 ++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_externs.h      |  3 +
 lib/librte_eal/common/eal_private.h      | 21 +++++++
 lib/librte_eal/linuxapp/eal/Makefile     |  1 +
 lib/librte_eal/linuxapp/eal/eal_timer.c  | 52 +----------------
 7 files changed, 129 insertions(+), 98 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_timer.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 560b7a3..fb1faa3 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -75,6 +75,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/bsdapp/eal/eal_timer.c
index 3163496..4341d3c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_timer.c
+++ b/lib/librte_eal/bsdapp/eal/eal_timer.c
@@ -49,6 +49,7 @@
 
 #include "eal_private.h"
 #include "eal_internal_cfg.h"
+#include "eal_externs.h"
 
 #ifdef RTE_LIBEAL_USE_HPET
 #warning HPET is not supported in FreeBSD
@@ -56,25 +57,7 @@
 
 enum timer_source eal_timer_source = EAL_TIMER_TSC;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
-uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
-static int
+int
 set_tsc_freq_from_sysctl(void)
 {
 	size_t sz;
@@ -104,35 +87,6 @@ set_tsc_freq_from_sysctl(void)
 	return 0;
 }
 
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. Read the TSC frequency value provided by the kernel
- * 2. If above does not work, just sleep for 1 second and tune off that,
- *    printing a warning about inaccuracy of timing
- */
-static void
-set_tsc_freq(void)
-{
-	if (set_tsc_freq_from_sysctl() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
-}
-
 int
 rte_eal_timer_init(void)
 {
diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
new file mode 100644
index 0000000..15f9ee7
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -0,0 +1,99 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <errno.h>
+
+#include <rte_common.h>
+#include <rte_log.h>
+#include <rte_cycles.h>
+
+#include "eal_private.h"
+#include "eal_internal_cfg.h"
+
+/* The frequency of the RDTSC timer resolution */
+uint64_t eal_tsc_resolution_hz = 0;
+
+void
+rte_delay_us(unsigned us)
+{
+	const uint64_t start = rte_get_timer_cycles();
+	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
+
+	while ((rte_get_timer_cycles() - start) < ticks)
+		rte_pause();
+}
+
+uint64_t
+rte_get_tsc_hz(void)
+{
+	return eal_tsc_resolution_hz;
+}
+
+static void
+set_tsc_freq_fallback(void)
+{
+	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
+		"CLOCK_MONOTONIC_RAW and HPET is not available"
+		" - clock timings may be less accurate.\n");
+	/* assume that the sleep(1) will sleep for 1 second */
+	uint64_t start = rte_rdtsc();
+
+	sleep(1);
+	eal_tsc_resolution_hz = rte_rdtsc() - start;
+}
+
+/*
+ * This function measures the TSC frequency. It uses a variety of approaches.
+ *
+ * 1. Read the TSC frequency value provided by the kernel
+ * 2. If above does not work, just sleep for 1 second and tune off that,
+ *    printing a warning about inaccuracy of timing
+ */
+void
+set_tsc_freq(void)
+{
+#ifdef RTE_EXEC_ENV_BSDAPP
+	if (set_tsc_freq_from_sysctl() < 0)
+#else /* RTE_EXEC_ENV_BSDAPP */
+	if (set_tsc_freq_from_clock() < 0)
+#endif /* RTE_EXEC_ENV_BSDAPP */
+		set_tsc_freq_fallback();
+
+	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
+			eal_tsc_resolution_hz/1000);
+}
diff --git a/lib/librte_eal/common/eal_externs.h b/lib/librte_eal/common/eal_externs.h
index b19bea6..124ab65 100644
--- a/lib/librte_eal/common/eal_externs.h
+++ b/lib/librte_eal/common/eal_externs.h
@@ -39,4 +39,7 @@ extern struct rte_config rte_config;
 extern int mem_cfg_fd;
 extern rte_usage_hook_t	rte_application_usage_hook;
 
+/* Extern declarations defined in eal_common_timer.c */
+extern uint64_t eal_tsc_resolution_hz;
+
 #endif
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 9fe91b3..19af23d 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -264,6 +264,13 @@ unsigned cpu_socket_id(unsigned lcore_id);
  */
 unsigned cpu_core_id(unsigned lcore_id);
 
+/**
+ * This function measures TSC frequency
+ *
+ * This function is private to the EAL.
+ */
+void set_tsc_freq(void);
+
 #ifdef RTE_EXEC_ENV_BSDAPP
 /**
  * This function gets no. of cpus
@@ -272,6 +279,13 @@ unsigned cpu_core_id(unsigned lcore_id);
  */
 int get_ncpus(void);
 
+/**
+ * This function sets TSC frequency from sysctl
+ *
+ * This function is private to the EAL.
+ */
+int set_tsc_freq_from_sysctl(void);
+
 #else /* RTE_EXEC_ENV_BSDAPP */
 /**
  * This function check if cpu is present
@@ -280,6 +294,13 @@ int get_ncpus(void);
  */
 int cpu_detected(unsigned lcore_id);
 
+/**
+ * This function sets TSC frequency from clock
+ *
+ * This function is private to the EAL.
+ */
+int set_tsc_freq_from_clock(void);
+
 #endif /* RTE_EXEC_ENV_BSDAPP */
 
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index ff185fd..2404423 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -87,6 +87,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_debug.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c
index ca57916..bce0498 100644
--- a/lib/librte_eal/linuxapp/eal/eal_timer.c
+++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
@@ -55,12 +55,10 @@
 
 #include "eal_private.h"
 #include "eal_internal_cfg.h"
+#include "eal_externs.h"
 
 enum timer_source eal_timer_source = EAL_TIMER_HPET;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
 #ifdef RTE_LIBEAL_USE_HPET
 
 #define DEV_HPET "/dev/hpet"
@@ -161,23 +159,6 @@ rte_get_hpet_cycles(void)
 
 #endif
 
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
-uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
-
 #ifdef RTE_LIBEAL_USE_HPET
 /*
  * Open and mmap /dev/hpet (high precision event timer) that will
@@ -276,7 +257,7 @@ check_tsc_flags(void)
 	fclose(stream);
 }
 
-static int
+int
 set_tsc_freq_from_clock(void)
 {
 #ifdef CLOCK_MONOTONIC_RAW
@@ -302,35 +283,6 @@ set_tsc_freq_from_clock(void)
 	return -1;
 }
 
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. If kernel provides CLOCK_MONOTONIC_RAW we use that to tune the TSC value
- * 2. If kernel does not provide that, and we have HPET support, tune using HPET
- * 3. Lastly, if neither of the above can be used, just sleep for 1 second and
- * tune off that, printing a warning about inaccuracy of timing
- */
-static void
-set_tsc_freq(void)
-{
-	if (set_tsc_freq_from_clock() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
-}
-
 int
 rte_eal_timer_init(void)
 {
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* [dpdk-dev] [PATCH 7/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
                   ` (5 preceding siblings ...)
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 6/7] " Ravi Kerur
@ 2014-12-25 15:33 ` Ravi Kerur
  2014-12-25 17:46   ` Neil Horman
  2014-12-29  8:47 ` [dpdk-dev] [PATCH 0/7] " Olivier MATZ
  7 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 15:33 UTC (permalink / raw)
  To: dev

Move common functions in eal_memory.c to librte_eal/common
directory.
Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common functions.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 36 ++------------------------
 lib/librte_eal/common/eal_common_memory.c | 43 +++++++++++++++++++++++++++++--
 lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 36 ++------------------------
 4 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c
index 65ee87d..b192705 100644
--- a/lib/librte_eal/bsdapp/eal/eal_memory.c
+++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
@@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
 	return RTE_BAD_PHYS_ADDR;
 }
 
-static int
+int
 rte_eal_contigmem_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -130,7 +130,7 @@ rte_eal_contigmem_init(void)
 	return 0;
 }
 
-static int
+int
 rte_eal_contigmem_attach(void)
 {
 	const struct hugepage_info *hpi;
@@ -190,35 +190,3 @@ error:
 	return -1;
 }
 
-
-static int
-rte_eal_memdevice_init(void)
-{
-	struct rte_config *config;
-
-	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-		return 0;
-
-	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_config.force_nchannel;
-	config->mem_config->nrank = internal_config.force_nrank;
-
-	return 0;
-}
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
-	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-			rte_eal_contigmem_init() :
-			rte_eal_contigmem_attach();
-	if (retval < 0)
-		return -1;
-
-	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-		return -1;
-
-	return 0;
-}
diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 77830f8..da7aa98 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -46,6 +46,7 @@
 #include <rte_log.h>
 
 #include "eal_private.h"
+#include "eal_internal_cfg.h"
 
 /*
  * Return a pointer to a read-only table of struct rte_physmem_desc
@@ -70,7 +71,7 @@ rte_eal_get_physmem_size(void)
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
 
-	for (i=0; i<RTE_MAX_MEMSEG; i++) {
+	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
 		if (mcfg->memseg[i].addr == NULL)
 			break;
 
@@ -90,7 +91,7 @@ rte_dump_physmem_layout(FILE *f)
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
 
-	for (i=0; i<RTE_MAX_MEMSEG; i++) {
+	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
 		if (mcfg->memseg[i].addr == NULL)
 			break;
 
@@ -119,3 +120,41 @@ unsigned rte_memory_get_nrank(void)
 {
 	return rte_eal_get_configuration()->mem_config->nrank;
 }
+
+static int
+rte_eal_memdevice_init(void)
+{
+	struct rte_config *config;
+
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
+		return 0;
+
+	config = rte_eal_get_configuration();
+	config->mem_config->nchannel = internal_config.force_nchannel;
+	config->mem_config->nrank = internal_config.force_nrank;
+
+	return 0;
+}
+
+/* init memory subsystem */
+int
+rte_eal_memory_init(void)
+{
+	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
+	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
+#ifdef RTE_EXEC_ENV_BSDAPP
+			rte_eal_contigmem_init() :
+			rte_eal_contigmem_attach();
+#else /* RTE_EXEC_ENV_BSDAPP */
+			rte_eal_hugepage_init() :
+			rte_eal_hugepage_attach();
+#endif /* RTE_EXEC_ENV_BSDAPP */
+
+	if (retval < 0)
+		return -1;
+
+	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
+		return -1;
+
+	return 0;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 19af23d..16338a2 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -286,6 +286,20 @@ int get_ncpus(void);
  */
 int set_tsc_freq_from_sysctl(void);
 
+/**
+ * This function prepares physical memory mapping
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_contigmem_init(void);
+
+/**
+ * This function creates memory mapping in secondary
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_contigmem_attach(void);
+
 #else /* RTE_EXEC_ENV_BSDAPP */
 /**
  * This function check if cpu is present
@@ -301,6 +315,20 @@ int cpu_detected(unsigned lcore_id);
  */
 int set_tsc_freq_from_clock(void);
 
+/**
+ * This function prepares physical memory mapping
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_init(void);
+
+/**
+ * This function creates memory mapping in secondary
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_attach(void);
+
 #endif /* RTE_EXEC_ENV_BSDAPP */
 
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index bae2507..f4d91df 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1031,7 +1031,7 @@ calc_num_pages_per_socket(uint64_t * memory,
  *  6. unmap the first mapping
  *  7. fill memsegs in configuration with contiguous zones
  */
-static int
+int
 rte_eal_hugepage_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -1369,7 +1369,7 @@ getFileSize(int fd)
  * configuration and finds the hugepages which form that segment, mapping them
  * in order to form a contiguous block in the virtual memory space
  */
-static int
+int
 rte_eal_hugepage_attach(void)
 {
 	const struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
@@ -1530,35 +1530,3 @@ error:
 	return -1;
 }
 
-static int
-rte_eal_memdevice_init(void)
-{
-	struct rte_config *config;
-
-	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-		return 0;
-
-	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_config.force_nchannel;
-	config->mem_config->nrank = internal_config.force_nrank;
-
-	return 0;
-}
-
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up memory...\n");
-	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-			rte_eal_hugepage_init() :
-			rte_eal_hugepage_attach();
-	if (retval < 0)
-		return -1;
-
-	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-		return -1;
-
-	return 0;
-}
-- 
1.9.1

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2 Ravi Kerur
@ 2014-12-25 17:21   ` Neil Horman
  2014-12-25 18:54     ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-25 17:21 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 10:33:11AM -0500, Ravi Kerur wrote:
> rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
> by checking for n.
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> ---
>  lib/librte_eal/common/include/rte_common.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 921b91f..8ac940c 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;
>  static inline int
>  rte_is_power_of_2(uint32_t n)
>  {
> -	return ((n-1) & n) == 0;
> +	return n && !(n & (n - 1));
>  }
>  
>  /**
> -- 
> 1.9.1
> 
> 

This is the third time you've tried to slip this change in with some larger
changeset.  I'm in favor of it, but please, stop trying to bury stuff in other,
larger changesets.  Its a legitimate bug, you can just post this on its own.

Neil

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 2/7] Move EAL common functions Ravi Kerur
@ 2014-12-25 17:30   ` Neil Horman
  2014-12-25 19:23     ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-25 17:30 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 10:33:12AM -0500, Ravi Kerur wrote:
> eal_debug.c has no difference between Linux and BSD, move
> into common directory.
> Rename eal_debug.c to eal_common_debug.c
> Makefile changes to reflect file move and name change.
> Fix checkpatch warnings.
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> +
> +/* not implemented in this environment */
> +void rte_dump_registers(void)
> +{
> +}
Clearly this function has no use, instead of keeping it around, can you please
remove it until someone works up the gumption to make it do something.  We're
just wasting an extra call instruction here so someone doesn't have to write a
prototype in the future.  I don't see the value.

> +/*
> + * Like rte_panic this terminates the application. However, no traceback is
> + * provided and no core-dump is generated.
> + */
> +void
> +rte_exit(int exit_code, const char *format, ...)
> +{
> +	va_list ap;
> +
> +	/* disable history */
> +	rte_log_set_history(0);
> +
> +	if (exit_code != 0)
> +		RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
> +				"  Cause: ", exit_code);
> +
> +	va_start(ap, format);
> +	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
> +	va_end(ap);
> +
> +#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> +	exit(exit_code);
> +#else
> +	rte_dump_stack();
> +	rte_dump_registers();
> +	abort();
> +#endif
This doesn't match with the commentary above.  If rte_exit isn't meant to
provide a traceback, it shouldn't do so.  If an application wants that to
happen, then they need to use rte_panic.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 3/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 3/7] " Ravi Kerur
@ 2014-12-25 17:41   ` Neil Horman
  2014-12-25 19:13     ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-25 17:41 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 10:33:13AM -0500, Ravi Kerur wrote:
> eal_thread.c has minor difference between Linux and BSD, move
> into common directory.
> Use RTE_EXEC_ENV_BSDAPP to differentiate minor difference.
> Rename eal_thread.c to eal_common_thread.c
> Makefile changes to reflect file move and name change.
> Fix checkpatch warnings.
> 
Don't you want to add RTE_EXEC_ENV_BSDAPP=y to config/common_bsdapp?

Neil

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 4/7] " Ravi Kerur
@ 2014-12-25 17:44   ` Neil Horman
  2014-12-25 19:17     ` Ravi Kerur
  2015-01-05 15:59   ` Thomas Monjalon
  1 sibling, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-25 17:44 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 10:33:14AM -0500, Ravi Kerur wrote:
> Move common functions in eal.c to librte_eal/common directory.
> Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> common functions.
> Makefile changes to reflect new file.
> Fix checkpatch warnings and errors.
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> ---
>  lib/librte_eal/bsdapp/eal/Makefile    |   1 +
>  lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
>  lib/librte_eal/common/eal_common.c    | 328 ++++++++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_externs.h   |  42 +++++
>  lib/librte_eal/common/eal_hugepages.h |   1 +
>  lib/librte_eal/common/eal_private.h   |  47 +++++
>  lib/librte_eal/linuxapp/eal/Makefile  |   1 +
>  lib/librte_eal/linuxapp/eal/eal.c     | 246 ++-----------------------
>  8 files changed, 439 insertions(+), 460 deletions(-)
>  create mode 100644 lib/librte_eal/common/eal_common.c
>  create mode 100644 lib/librte_eal/common/eal_externs.h
> 
> diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
> index 92dd9a6..050d70b 100644
> --- a/lib/librte_eal/bsdapp/eal/Makefile
> +++ b/lib/librte_eal/bsdapp/eal/Makefile
> @@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
>  
>  # from common dir
> +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
>  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
> diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
> index 69f3c03..f925da7 100644
> --- a/lib/librte_eal/bsdapp/eal/eal.c
> +++ b/lib/librte_eal/bsdapp/eal/eal.c
> @@ -80,30 +80,10 @@
>  #include "eal_filesystem.h"
>  #include "eal_hugepages.h"
>  #include "eal_options.h"
> +#include "eal_externs.h"
>  
>  #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;
> -/* early configuration structure, when memory config is not mmapped */
> -static struct rte_mem_config early_mem_config;
> -
> -/* 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;
> -
> -static struct flock wr_lock = {
> -		.l_type = F_WRLCK,
> -		.l_whence = SEEK_SET,
> -		.l_start = offsetof(struct rte_mem_config, memseg),
> -		.l_len = sizeof(early_mem_config.memseg),
> -};
> -
> -/* Address of global and public configuration */
> -static struct rte_config rte_config = {
> -		.mem_config = &early_mem_config,
> -};
> -
>  /* internal configuration (per-core) */
>  struct lcore_config lcore_config[RTE_MAX_LCORE];
>  
> @@ -113,93 +93,14 @@ struct internal_config internal_config;
>  /* used by rte_rdtsc() */
>  int rte_cycles_vmware_tsc_map;
>  
> -/* Return a pointer to the configuration structure */
> -struct rte_config *
> -rte_eal_get_configuration(void)
> +inline void *
> +rte_eal_get_mem_cfg_addr(void)
>  {
> -	return &rte_config;
> -}
> -
> -/* parse a sysfs (or other) file containing one integer value */
> -int
> -eal_parse_sysfs_value(const char *filename, unsigned long *val)
> -{
> -	FILE *f;
> -	char buf[BUFSIZ];
> -	char *end = NULL;
> -
> -	if ((f = fopen(filename, "r")) == NULL) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> -			__func__, filename);
> -		return -1;
> -	}
> -
> -	if (fgets(buf, sizeof(buf), f) == NULL) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> -			__func__, filename);
> -		fclose(f);
> -		return -1;
> -	}
> -	*val = strtoul(buf, &end, 0);
> -	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> -		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> -				__func__, filename);
> -		fclose(f);
> -		return -1;
> -	}
> -	fclose(f);
> -	return 0;
> -}
> -
> -
> -/* create memory configuration in shared/mmap memory. Take out
> - * a write lock on the memsegs, so we can auto-detect primary/secondary.
> - * This means we never close the file while running (auto-close on exit).
> - * We also don't lock the whole file, so that in future we can use read-locks
> - * on other parts, e.g. memzones, to detect if there are running secondary
> - * processes. */
> -static void
> -rte_eal_config_create(void)
> -{
> -	void *rte_mem_cfg_addr;
> -	int retval;
> -
> -	const char *pathname = eal_runtime_config_path();
> -
> -	if (internal_config.no_shconf)
> -		return;
> -
> -	if (mem_cfg_fd < 0){
> -		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> -		if (mem_cfg_fd < 0)
> -			rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
> -	}
> -
> -	retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> -	if (retval < 0){
> -		close(mem_cfg_fd);
> -		rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
> -	}
> -
> -	retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> -	if (retval < 0){
> -		close(mem_cfg_fd);
> -		rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
> -				"process running?\n", pathname);
> -	}
> -
> -	rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
> -				PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
> -
> -	if (rte_mem_cfg_addr == MAP_FAILED){
> -		rte_panic("Cannot mmap memory for rte_config\n");
> -	}
> -	memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
> -	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> +	return NULL;
>  }
>  
>  /* attach to an existing shared memory config */
> -static void
> +void
>  rte_eal_config_attach(void)
>  {
>  	void *rte_mem_cfg_addr;
> @@ -223,44 +124,11 @@ rte_eal_config_attach(void)
>  	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
>  }
>  
> -/* Detect if we are a primary or a secondary process */
> -enum rte_proc_type_t
> -eal_proc_type_detect(void)
> +/* NOP for BSD */
> +void
> +rte_eal_config_reattach(void)
>  {
> -	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
> -	const char *pathname = eal_runtime_config_path();
> -
> -	/* if we can open the file but not get a write-lock we are a secondary
> -	 * process. NOTE: if we get a file handle back, we keep that open
> -	 * and don't close it to prevent a race condition between multiple opens */
> -	if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
> -			(fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> -		ptype = RTE_PROC_SECONDARY;
> -
> -	RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
> -			ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
>  
> -	return ptype;
> -}
> -
> -/* Sets up rte_config structure with the pointer to shared memory config.*/
> -static void
> -rte_config_init(void)
> -{
> -	rte_config.process_type = internal_config.process_type;
> -
> -	switch (rte_config.process_type){
> -	case RTE_PROC_PRIMARY:
> -		rte_eal_config_create();
> -		break;
> -	case RTE_PROC_SECONDARY:
> -		rte_eal_config_attach();
> -		rte_eal_mcfg_wait_complete(rte_config.mem_config);
> -		break;
> -	case RTE_PROC_AUTO:
> -	case RTE_PROC_INVALID:
> -		rte_panic("Invalid process type\n");
> -	}
>  }
>  
>  /* display usage */
> @@ -276,37 +144,6 @@ eal_usage(const char *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)
> -{
> -	uint64_t size = 0;
> -	unsigned i, j;
> -
> -	for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
> -		struct hugepage_info *hpi = &internal_config.hugepage_info[i];
> -		if (hpi->hugedir != NULL) {
> -			for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
> -				size += hpi->hugepage_sz * hpi->num_pages[j];
> -			}
> -		}
> -	}
> -
> -	return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
> -}
> -
>  /* Parse the argument given in the command line of the application */
>  static int
>  eal_parse_args(int argc, char **argv)
> @@ -374,45 +211,6 @@ eal_parse_args(int argc, char **argv)
>  	return ret;
>  }
>  
> -static void
> -eal_check_mem_on_local_socket(void)
> -{
> -	const struct rte_memseg *ms;
> -	int i, socket_id;
> -
> -	socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
> -
> -	ms = rte_eal_get_physmem_layout();
> -
> -	for (i = 0; i < RTE_MAX_MEMSEG; i++)
> -		if (ms[i].socket_id == socket_id &&
> -				ms[i].len > 0)
> -			return;
> -
> -	RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
> -			"memory on local socket!\n");
> -}
> -
> -static int
> -sync_func(__attribute__((unused)) void *arg)
> -{
> -	return 0;
> -}
> -
> -inline static void
> -rte_eal_mcfg_complete(void)
> -{
> -	/* ALL shared mem_config related INIT DONE */
> -	if (rte_config.process_type == RTE_PROC_PRIMARY)
> -		rte_config.mem_config->magic = RTE_MAGIC;
> -}
> -
> -/* return non-zero if hugepages are enabled. */
> -int rte_eal_has_hugepages(void)
> -{
> -	return !internal_config.no_hugetlbfs;
> -}
> -
>  /* Abstraction for port I/0 privilege */
>  int
>  rte_eal_iopl_init(void)
> @@ -476,7 +274,7 @@ rte_eal_init(int argc, char **argv)
>  
>  	rte_srand(rte_rdtsc());
>  
> -	rte_config_init();
> +	rte_eal_config_init();
>  
>  	if (rte_eal_memory_init() < 0)
>  		rte_panic("Cannot init memory\n");
> @@ -548,16 +346,3 @@ rte_eal_init(int argc, char **argv)
>  	return fctret;
>  }
>  
> -/* get core role */
> -enum rte_lcore_role_t
> -rte_eal_lcore_role(unsigned lcore_id)
> -{
> -	return (rte_config.lcore_role[lcore_id]);
> -}
> -
> -enum rte_proc_type_t
> -rte_eal_process_type(void)
> -{
> -	return (rte_config.process_type);
> -}
> -
> diff --git a/lib/librte_eal/common/eal_common.c b/lib/librte_eal/common/eal_common.c
> new file mode 100644
> index 0000000..becf9c8
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common.c
> @@ -0,0 +1,328 @@
> +/*-
> + *   BSD LICENSE
> + *
> + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> + *   Copyright(c) 2014 6WIND S.A.
> + *   All rights reserved.
> + *
> + *   Redistribution and use in source and binary forms, with or without
> + *   modification, are permitted provided that the following conditions
> + *   are met:
> + *
> + *     * Redistributions of source code must retain the above copyright
> + *       notice, this list of conditions and the following disclaimer.
> + *     * Redistributions in binary form must reproduce the above copyright
> + *       notice, this list of conditions and the following disclaimer in
> + *       the documentation and/or other materials provided with the
> + *       distribution.
> + *     * Neither the name of Intel Corporation nor the names of its
> + *       contributors may be used to endorse or promote products derived
> + *       from this software without specific prior written permission.
> + *
> + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
> + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
> + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include <stdarg.h>
> +#include <unistd.h>
> +#include <pthread.h>
> +#include <syslog.h>
> +#include <getopt.h>
> +#include <sys/file.h>
> +#include <stddef.h>
> +#include <errno.h>
> +#include <limits.h>
> +#include <errno.h>
> +#include <sys/mman.h>
> +#include <sys/queue.h>
> +
> +#include <rte_common.h>
> +#include <rte_debug.h>
> +#include <rte_memory.h>
> +#include <rte_memzone.h>
> +#include <rte_launch.h>
> +#include <rte_tailq.h>
> +#include <rte_eal.h>
> +#include <rte_eal_memconfig.h>
> +#include <rte_per_lcore.h>
> +#include <rte_lcore.h>
> +#include <rte_log.h>
> +#include <rte_random.h>
> +#include <rte_cycles.h>
> +#include <rte_string_fns.h>
> +#include <rte_cpuflags.h>
> +#include <rte_interrupts.h>
> +#include <rte_pci.h>
> +#include <rte_dev.h>
> +#include <rte_devargs.h>
> +#include <rte_common.h>
> +#include <rte_version.h>
> +#include <rte_atomic.h>
> +#include <malloc_heap.h>
> +#include <rte_eth_ring.h>
> +
> +#include "eal_private.h"
> +#include "eal_thread.h"
> +#include "eal_internal_cfg.h"
> +#include "eal_filesystem.h"
> +#include "eal_hugepages.h"
> +#include "eal_options.h"
> +
> +/* Allow the application to print its usage message too if set */
> +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 */
> +int mem_cfg_fd = -1;
> +
> +/* early configuration structure, when memory config is not mmapped */
> +static struct rte_mem_config early_mem_config;
> +
> +/* Address of global and public configuration */
> +struct rte_config rte_config = {
> +		.mem_config = &early_mem_config,
> +};
> +
> +static struct flock wr_lock = {
> +		.l_type = F_WRLCK,
> +		.l_whence = SEEK_SET,
> +		.l_start = offsetof(struct rte_mem_config, memseg),
> +		.l_len = sizeof(early_mem_config.memseg),
> +};
> +
> +/* Return a pointer to the configuration structure */
> +struct rte_config *
> +rte_eal_get_configuration(void)
> +{
> +	return &rte_config;
> +}
> +
> +/* parse a sysfs (or other) file containing one integer value */
> +int
> +eal_parse_sysfs_value(const char *filename, unsigned long *val)
> +{
> +	FILE *f;
> +	char buf[BUFSIZ];
> +	char *end = NULL;
> +
> +	f = fopen(filename, "r");
> +	if (f == NULL) {
> +		RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> +			__func__, filename);
> +		return -1;
> +	}
> +
> +	if (fgets(buf, sizeof(buf), f) == NULL) {
> +		RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> +			__func__, filename);
> +		fclose(f);
> +		return -1;
> +	}
> +	*val = strtoul(buf, &end, 0);
> +	if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> +		RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> +				__func__, filename);
> +		fclose(f);
> +		return -1;
> +	}
> +	fclose(f);
> +	return 0;
> +}
> +
> +
> +/* create memory configuration in shared/mmap memory. Take out
> + * a write lock on the memsegs, so we can auto-detect primary/secondary.
> + * This means we never close the file while running (auto-close on exit).
> + * We also don't lock the whole file, so that in future we can use read-locks
> + * on other parts, e.g. memzones, to detect if there are running secondary
> + * processes. */
> +static void
> +rte_eal_config_create(void)
> +{
> +	void *rte_mem_cfg_addr;
> +	int retval;
> +
> +	const char *pathname = eal_runtime_config_path();
> +
> +	if (internal_config.no_shconf)
> +		return;
> +
> +	rte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();
> +
> +	if (mem_cfg_fd < 0) {
> +		mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> +		if (mem_cfg_fd < 0)
> +			rte_panic("Cannot open '%s' for rte_mem_config\n",
> +					pathname);
> +	}
> +
> +	retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> +	if (retval < 0) {
> +		close(mem_cfg_fd);
> +		rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
> +	}
> +
> +	retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> +	if (retval < 0) {
> +		close(mem_cfg_fd);
> +		rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. "
> +			"Is another primary process running?\n", pathname);
> +	}
> +
> +	rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
> +			sizeof(*rte_config.mem_config), PROT_READ | PROT_WRITE,
> +			MAP_SHARED, mem_cfg_fd, 0);
> +
> +	if (rte_mem_cfg_addr == MAP_FAILED)
> +		rte_panic("Cannot mmap memory for rte_config\n");
> +
> +	memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
> +	rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> +
> +#ifndef RTE_EXEC_ENV_BSDAPP
> +	/* store address of the config in the config itself so that secondary
> +	 * processes could later map the config into this exact location
> +	 */
> +	rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
> +#endif /* RTE_EXEC_ENV_BSDAPP */
Why is this a BSD/Linux Differentiator?
Neil

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 7/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 7/7] " Ravi Kerur
@ 2014-12-25 17:46   ` Neil Horman
  2014-12-25 19:22     ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-25 17:46 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 10:33:17AM -0500, Ravi Kerur wrote:
> Move common functions in eal_memory.c to librte_eal/common
> directory.
> Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> common functions.
> Fix checkpatch warnings and errors.
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> ---
>  lib/librte_eal/bsdapp/eal/eal_memory.c    | 36 ++------------------------
>  lib/librte_eal/common/eal_common_memory.c | 43 +++++++++++++++++++++++++++++--
>  lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/eal_memory.c  | 36 ++------------------------
>  4 files changed, 73 insertions(+), 70 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c
> index 65ee87d..b192705 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_memory.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
> @@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
>  	return RTE_BAD_PHYS_ADDR;
>  }
>  
> -static int
> +int
>  rte_eal_contigmem_init(void)
>  {
>  	struct rte_mem_config *mcfg;
> @@ -130,7 +130,7 @@ rte_eal_contigmem_init(void)
>  	return 0;
>  }
>  
> -static int
> +int
>  rte_eal_contigmem_attach(void)
>  {
>  	const struct hugepage_info *hpi;
> @@ -190,35 +190,3 @@ error:
>  	return -1;
>  }
>  
> -
> -static int
> -rte_eal_memdevice_init(void)
> -{
> -	struct rte_config *config;
> -
> -	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> -		return 0;
> -
> -	config = rte_eal_get_configuration();
> -	config->mem_config->nchannel = internal_config.force_nchannel;
> -	config->mem_config->nrank = internal_config.force_nrank;
> -
> -	return 0;
> -}
> -
> -/* init memory subsystem */
> -int
> -rte_eal_memory_init(void)
> -{
> -	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> -	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> -			rte_eal_contigmem_init() :
> -			rte_eal_contigmem_attach();
> -	if (retval < 0)
> -		return -1;
> -
> -	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> -		return -1;
> -
> -	return 0;
> -}
> diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
> index 77830f8..da7aa98 100644
> --- a/lib/librte_eal/common/eal_common_memory.c
> +++ b/lib/librte_eal/common/eal_common_memory.c
> @@ -46,6 +46,7 @@
>  #include <rte_log.h>
>  
>  #include "eal_private.h"
> +#include "eal_internal_cfg.h"
>  
>  /*
>   * Return a pointer to a read-only table of struct rte_physmem_desc
> @@ -70,7 +71,7 @@ rte_eal_get_physmem_size(void)
>  	/* get pointer to global configuration */
>  	mcfg = rte_eal_get_configuration()->mem_config;
>  
> -	for (i=0; i<RTE_MAX_MEMSEG; i++) {
> +	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
>  		if (mcfg->memseg[i].addr == NULL)
>  			break;
>  
> @@ -90,7 +91,7 @@ rte_dump_physmem_layout(FILE *f)
>  	/* get pointer to global configuration */
>  	mcfg = rte_eal_get_configuration()->mem_config;
>  
> -	for (i=0; i<RTE_MAX_MEMSEG; i++) {
> +	for (i = 0; i < RTE_MAX_MEMSEG; i++) {
>  		if (mcfg->memseg[i].addr == NULL)
>  			break;
>  
> @@ -119,3 +120,41 @@ unsigned rte_memory_get_nrank(void)
>  {
>  	return rte_eal_get_configuration()->mem_config->nrank;
>  }
> +
> +static int
> +rte_eal_memdevice_init(void)
> +{
> +	struct rte_config *config;
> +
> +	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> +		return 0;
> +
> +	config = rte_eal_get_configuration();
> +	config->mem_config->nchannel = internal_config.force_nchannel;
> +	config->mem_config->nrank = internal_config.force_nrank;
> +
> +	return 0;
> +}
> +
> +/* init memory subsystem */
> +int
> +rte_eal_memory_init(void)
> +{
> +	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> +	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> +#ifdef RTE_EXEC_ENV_BSDAPP
> +			rte_eal_contigmem_init() :
> +			rte_eal_contigmem_attach();
> +#else /* RTE_EXEC_ENV_BSDAPP */
> +			rte_eal_hugepage_init() :
> +			rte_eal_hugepage_attach();
> +#endif /* RTE_EXEC_ENV_BSDAPP */
Given that the functions you are calling here are only ever build for the
platform they are called from, it seems to me that you can give them a shared
name, and just build the appropriate one.  I.e. you don't need to add ifdeffery
here.

Neil

> +
> +	if (retval < 0)
> +		return -1;
> +
> +	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> +		return -1;
> +
> +	return 0;
> +}
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index 19af23d..16338a2 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -286,6 +286,20 @@ int get_ncpus(void);
>   */
>  int set_tsc_freq_from_sysctl(void);
>  
> +/**
> + * This function prepares physical memory mapping
> + *
> + * This function is private to the EAL.
> + */
> +int rte_eal_contigmem_init(void);
> +
> +/**
> + * This function creates memory mapping in secondary
> + *
> + * This function is private to the EAL.
> + */
> +int rte_eal_contigmem_attach(void);
> +
>  #else /* RTE_EXEC_ENV_BSDAPP */
>  /**
>   * This function check if cpu is present
> @@ -301,6 +315,20 @@ int cpu_detected(unsigned lcore_id);
>   */
>  int set_tsc_freq_from_clock(void);
>  
> +/**
> + * This function prepares physical memory mapping
> + *
> + * This function is private to the EAL.
> + */
> +int rte_eal_hugepage_init(void);
> +
> +/**
> + * This function creates memory mapping in secondary
> + *
> + * This function is private to the EAL.
> + */
> +int rte_eal_hugepage_attach(void);
> +
>  #endif /* RTE_EXEC_ENV_BSDAPP */
>  
>  #endif /* _EAL_PRIVATE_H_ */
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
> index bae2507..f4d91df 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> @@ -1031,7 +1031,7 @@ calc_num_pages_per_socket(uint64_t * memory,
>   *  6. unmap the first mapping
>   *  7. fill memsegs in configuration with contiguous zones
>   */
> -static int
> +int
>  rte_eal_hugepage_init(void)
>  {
>  	struct rte_mem_config *mcfg;
> @@ -1369,7 +1369,7 @@ getFileSize(int fd)
>   * configuration and finds the hugepages which form that segment, mapping them
>   * in order to form a contiguous block in the virtual memory space
>   */
> -static int
> +int
>  rte_eal_hugepage_attach(void)
>  {
>  	const struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
> @@ -1530,35 +1530,3 @@ error:
>  	return -1;
>  }
>  
> -static int
> -rte_eal_memdevice_init(void)
> -{
> -	struct rte_config *config;
> -
> -	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> -		return 0;
> -
> -	config = rte_eal_get_configuration();
> -	config->mem_config->nchannel = internal_config.force_nchannel;
> -	config->mem_config->nrank = internal_config.force_nrank;
> -
> -	return 0;
> -}
> -
> -
> -/* init memory subsystem */
> -int
> -rte_eal_memory_init(void)
> -{
> -	RTE_LOG(INFO, EAL, "Setting up memory...\n");
> -	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> -			rte_eal_hugepage_init() :
> -			rte_eal_hugepage_attach();
> -	if (retval < 0)
> -		return -1;
> -
> -	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> -		return -1;
> -
> -	return 0;
> -}
> -- 
> 1.9.1
> 
> 

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2
  2014-12-25 17:21   ` Neil Horman
@ 2014-12-25 18:54     ` Ravi Kerur
  0 siblings, 0 replies; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 18:54 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Sure, will post it separately.

Thanks.

On Thu, Dec 25, 2014 at 9:21 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:11AM -0500, Ravi Kerur wrote:
> > rte_is_power_of_2 returns true for 0 and 0 is not power_of_2. Fix
> > by checking for n.
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > ---
> >  lib/librte_eal/common/include/rte_common.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_eal/common/include/rte_common.h
> b/lib/librte_eal/common/include/rte_common.h
> > index 921b91f..8ac940c 100644
> > --- a/lib/librte_eal/common/include/rte_common.h
> > +++ b/lib/librte_eal/common/include/rte_common.h
> > @@ -203,7 +203,7 @@ extern int RTE_BUILD_BUG_ON_detected_error;
> >  static inline int
> >  rte_is_power_of_2(uint32_t n)
> >  {
> > -     return ((n-1) & n) == 0;
> > +     return n && !(n & (n - 1));
> >  }
> >
> >  /**
> > --
> > 1.9.1
> >
> >
>
> This is the third time you've tried to slip this change in with some larger
> changeset.  I'm in favor of it, but please, stop trying to bury stuff in
> other,
> larger changesets.  Its a legitimate bug, you can just post this on its
> own.
>
> Neil
>
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 3/7] Move EAL common functions
  2014-12-25 17:41   ` Neil Horman
@ 2014-12-25 19:13     ` Ravi Kerur
  2014-12-26 14:40       ` Neil Horman
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 19:13 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Inline <rk>

On Thu, Dec 25, 2014 at 9:41 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:13AM -0500, Ravi Kerur wrote:
> > eal_thread.c has minor difference between Linux and BSD, move
> > into common directory.
> > Use RTE_EXEC_ENV_BSDAPP to differentiate minor difference.
> > Rename eal_thread.c to eal_common_thread.c
> > Makefile changes to reflect file move and name change.
> > Fix checkpatch warnings.
> >
> Don't you want to add RTE_EXEC_ENV_BSDAPP=y to config/common_bsdapp?
>

<rk> Its already defined in common/common_bsdapp.

>
> Neil
>
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-25 17:44   ` Neil Horman
@ 2014-12-25 19:17     ` Ravi Kerur
  2014-12-26 14:42       ` Neil Horman
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 19:17 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Inline <rk>

On Thu, Dec 25, 2014 at 9:44 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:14AM -0500, Ravi Kerur wrote:
> > Move common functions in eal.c to librte_eal/common directory.
> > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > common functions.
> > Makefile changes to reflect new file.
> > Fix checkpatch warnings and errors.
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > ---
> >  lib/librte_eal/bsdapp/eal/Makefile    |   1 +
> >  lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
> >  lib/librte_eal/common/eal_common.c    | 328
> ++++++++++++++++++++++++++++++++++
> >  lib/librte_eal/common/eal_externs.h   |  42 +++++
> >  lib/librte_eal/common/eal_hugepages.h |   1 +
> >  lib/librte_eal/common/eal_private.h   |  47 +++++
> >  lib/librte_eal/linuxapp/eal/Makefile  |   1 +
> >  lib/librte_eal/linuxapp/eal/eal.c     | 246 ++-----------------------
> >  8 files changed, 439 insertions(+), 460 deletions(-)
> >  create mode 100644 lib/librte_eal/common/eal_common.c
> >  create mode 100644 lib/librte_eal/common/eal_externs.h
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/Makefile
> b/lib/librte_eal/bsdapp/eal/Makefile
> > index 92dd9a6..050d70b 100644
> > --- a/lib/librte_eal/bsdapp/eal/Makefile
> > +++ b/lib/librte_eal/bsdapp/eal/Makefile
> > @@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=
> eal_interrupts.c
> >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
> >
> >  # from common dir
> > +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common.c
> >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
> >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
> >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
> > diff --git a/lib/librte_eal/bsdapp/eal/eal.c
> b/lib/librte_eal/bsdapp/eal/eal.c
> > index 69f3c03..f925da7 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal.c
> > @@ -80,30 +80,10 @@
> >  #include "eal_filesystem.h"
> >  #include "eal_hugepages.h"
> >  #include "eal_options.h"
> > +#include "eal_externs.h"
> >
> >  #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;
> > -/* early configuration structure, when memory config is not mmapped */
> > -static struct rte_mem_config early_mem_config;
> > -
> > -/* 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;
> > -
> > -static struct flock wr_lock = {
> > -             .l_type = F_WRLCK,
> > -             .l_whence = SEEK_SET,
> > -             .l_start = offsetof(struct rte_mem_config, memseg),
> > -             .l_len = sizeof(early_mem_config.memseg),
> > -};
> > -
> > -/* Address of global and public configuration */
> > -static struct rte_config rte_config = {
> > -             .mem_config = &early_mem_config,
> > -};
> > -
> >  /* internal configuration (per-core) */
> >  struct lcore_config lcore_config[RTE_MAX_LCORE];
> >
> > @@ -113,93 +93,14 @@ struct internal_config internal_config;
> >  /* used by rte_rdtsc() */
> >  int rte_cycles_vmware_tsc_map;
> >
> > -/* Return a pointer to the configuration structure */
> > -struct rte_config *
> > -rte_eal_get_configuration(void)
> > +inline void *
> > +rte_eal_get_mem_cfg_addr(void)
> >  {
> > -     return &rte_config;
> > -}
> > -
> > -/* parse a sysfs (or other) file containing one integer value */
> > -int
> > -eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > -{
> > -     FILE *f;
> > -     char buf[BUFSIZ];
> > -     char *end = NULL;
> > -
> > -     if ((f = fopen(filename, "r")) == NULL) {
> > -             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > -                     __func__, filename);
> > -             return -1;
> > -     }
> > -
> > -     if (fgets(buf, sizeof(buf), f) == NULL) {
> > -             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > -                     __func__, filename);
> > -             fclose(f);
> > -             return -1;
> > -     }
> > -     *val = strtoul(buf, &end, 0);
> > -     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > -             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> > -                             __func__, filename);
> > -             fclose(f);
> > -             return -1;
> > -     }
> > -     fclose(f);
> > -     return 0;
> > -}
> > -
> > -
> > -/* create memory configuration in shared/mmap memory. Take out
> > - * a write lock on the memsegs, so we can auto-detect primary/secondary.
> > - * This means we never close the file while running (auto-close on
> exit).
> > - * We also don't lock the whole file, so that in future we can use
> read-locks
> > - * on other parts, e.g. memzones, to detect if there are running
> secondary
> > - * processes. */
> > -static void
> > -rte_eal_config_create(void)
> > -{
> > -     void *rte_mem_cfg_addr;
> > -     int retval;
> > -
> > -     const char *pathname = eal_runtime_config_path();
> > -
> > -     if (internal_config.no_shconf)
> > -             return;
> > -
> > -     if (mem_cfg_fd < 0){
> > -             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > -             if (mem_cfg_fd < 0)
> > -                     rte_panic("Cannot open '%s' for rte_mem_config\n",
> pathname);
> > -     }
> > -
> > -     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > -     if (retval < 0){
> > -             close(mem_cfg_fd);
> > -             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> pathname);
> > -     }
> > -
> > -     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > -     if (retval < 0){
> > -             close(mem_cfg_fd);
> > -             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is
> another primary "
> > -                             "process running?\n", pathname);
> > -     }
> > -
> > -     rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
> > -                             PROT_READ | PROT_WRITE, MAP_SHARED,
> mem_cfg_fd, 0);
> > -
> > -     if (rte_mem_cfg_addr == MAP_FAILED){
> > -             rte_panic("Cannot mmap memory for rte_config\n");
> > -     }
> > -     memcpy(rte_mem_cfg_addr, &early_mem_config,
> sizeof(early_mem_config));
> > -     rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> > +     return NULL;
> >  }
> >
> >  /* attach to an existing shared memory config */
> > -static void
> > +void
> >  rte_eal_config_attach(void)
> >  {
> >       void *rte_mem_cfg_addr;
> > @@ -223,44 +124,11 @@ rte_eal_config_attach(void)
> >       rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> >  }
> >
> > -/* Detect if we are a primary or a secondary process */
> > -enum rte_proc_type_t
> > -eal_proc_type_detect(void)
> > +/* NOP for BSD */
> > +void
> > +rte_eal_config_reattach(void)
> >  {
> > -     enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
> > -     const char *pathname = eal_runtime_config_path();
> > -
> > -     /* if we can open the file but not get a write-lock we are a
> secondary
> > -      * process. NOTE: if we get a file handle back, we keep that open
> > -      * and don't close it to prevent a race condition between multiple
> opens */
> > -     if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
> > -                     (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> > -             ptype = RTE_PROC_SECONDARY;
> > -
> > -     RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
> > -                     ptype == RTE_PROC_PRIMARY ? "PRIMARY" :
> "SECONDARY");
> >
> > -     return ptype;
> > -}
> > -
> > -/* Sets up rte_config structure with the pointer to shared memory
> config.*/
> > -static void
> > -rte_config_init(void)
> > -{
> > -     rte_config.process_type = internal_config.process_type;
> > -
> > -     switch (rte_config.process_type){
> > -     case RTE_PROC_PRIMARY:
> > -             rte_eal_config_create();
> > -             break;
> > -     case RTE_PROC_SECONDARY:
> > -             rte_eal_config_attach();
> > -             rte_eal_mcfg_wait_complete(rte_config.mem_config);
> > -             break;
> > -     case RTE_PROC_AUTO:
> > -     case RTE_PROC_INVALID:
> > -             rte_panic("Invalid process type\n");
> > -     }
> >  }
> >
> >  /* display usage */
> > @@ -276,37 +144,6 @@ eal_usage(const char *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)
> > -{
> > -     uint64_t size = 0;
> > -     unsigned i, j;
> > -
> > -     for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
> > -             struct hugepage_info *hpi =
> &internal_config.hugepage_info[i];
> > -             if (hpi->hugedir != NULL) {
> > -                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
> > -                             size += hpi->hugepage_sz *
> hpi->num_pages[j];
> > -                     }
> > -             }
> > -     }
> > -
> > -     return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
> > -}
> > -
> >  /* Parse the argument given in the command line of the application */
> >  static int
> >  eal_parse_args(int argc, char **argv)
> > @@ -374,45 +211,6 @@ eal_parse_args(int argc, char **argv)
> >       return ret;
> >  }
> >
> > -static void
> > -eal_check_mem_on_local_socket(void)
> > -{
> > -     const struct rte_memseg *ms;
> > -     int i, socket_id;
> > -
> > -     socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
> > -
> > -     ms = rte_eal_get_physmem_layout();
> > -
> > -     for (i = 0; i < RTE_MAX_MEMSEG; i++)
> > -             if (ms[i].socket_id == socket_id &&
> > -                             ms[i].len > 0)
> > -                     return;
> > -
> > -     RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
> > -                     "memory on local socket!\n");
> > -}
> > -
> > -static int
> > -sync_func(__attribute__((unused)) void *arg)
> > -{
> > -     return 0;
> > -}
> > -
> > -inline static void
> > -rte_eal_mcfg_complete(void)
> > -{
> > -     /* ALL shared mem_config related INIT DONE */
> > -     if (rte_config.process_type == RTE_PROC_PRIMARY)
> > -             rte_config.mem_config->magic = RTE_MAGIC;
> > -}
> > -
> > -/* return non-zero if hugepages are enabled. */
> > -int rte_eal_has_hugepages(void)
> > -{
> > -     return !internal_config.no_hugetlbfs;
> > -}
> > -
> >  /* Abstraction for port I/0 privilege */
> >  int
> >  rte_eal_iopl_init(void)
> > @@ -476,7 +274,7 @@ rte_eal_init(int argc, char **argv)
> >
> >       rte_srand(rte_rdtsc());
> >
> > -     rte_config_init();
> > +     rte_eal_config_init();
> >
> >       if (rte_eal_memory_init() < 0)
> >               rte_panic("Cannot init memory\n");
> > @@ -548,16 +346,3 @@ rte_eal_init(int argc, char **argv)
> >       return fctret;
> >  }
> >
> > -/* get core role */
> > -enum rte_lcore_role_t
> > -rte_eal_lcore_role(unsigned lcore_id)
> > -{
> > -     return (rte_config.lcore_role[lcore_id]);
> > -}
> > -
> > -enum rte_proc_type_t
> > -rte_eal_process_type(void)
> > -{
> > -     return (rte_config.process_type);
> > -}
> > -
> > diff --git a/lib/librte_eal/common/eal_common.c
> b/lib/librte_eal/common/eal_common.c
> > new file mode 100644
> > index 0000000..becf9c8
> > --- /dev/null
> > +++ b/lib/librte_eal/common/eal_common.c
> > @@ -0,0 +1,328 @@
> > +/*-
> > + *   BSD LICENSE
> > + *
> > + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> > + *   Copyright(c) 2014 6WIND S.A.
> > + *   All rights reserved.
> > + *
> > + *   Redistribution and use in source and binary forms, with or without
> > + *   modification, are permitted provided that the following conditions
> > + *   are met:
> > + *
> > + *     * Redistributions of source code must retain the above copyright
> > + *       notice, this list of conditions and the following disclaimer.
> > + *     * Redistributions in binary form must reproduce the above
> copyright
> > + *       notice, this list of conditions and the following disclaimer in
> > + *       the documentation and/or other materials provided with the
> > + *       distribution.
> > + *     * Neither the name of Intel Corporation nor the names of its
> > + *       contributors may be used to endorse or promote products derived
> > + *       from this software without specific prior written permission.
> > + *
> > + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> > + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> > + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
> FOR
> > + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> COPYRIGHT
> > + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> INCIDENTAL,
> > + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> > + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> USE,
> > + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> ANY
> > + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> > + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
> USE
> > + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
> DAMAGE.
> > + */
> > +
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <stdint.h>
> > +#include <string.h>
> > +#include <stdarg.h>
> > +#include <unistd.h>
> > +#include <pthread.h>
> > +#include <syslog.h>
> > +#include <getopt.h>
> > +#include <sys/file.h>
> > +#include <stddef.h>
> > +#include <errno.h>
> > +#include <limits.h>
> > +#include <errno.h>
> > +#include <sys/mman.h>
> > +#include <sys/queue.h>
> > +
> > +#include <rte_common.h>
> > +#include <rte_debug.h>
> > +#include <rte_memory.h>
> > +#include <rte_memzone.h>
> > +#include <rte_launch.h>
> > +#include <rte_tailq.h>
> > +#include <rte_eal.h>
> > +#include <rte_eal_memconfig.h>
> > +#include <rte_per_lcore.h>
> > +#include <rte_lcore.h>
> > +#include <rte_log.h>
> > +#include <rte_random.h>
> > +#include <rte_cycles.h>
> > +#include <rte_string_fns.h>
> > +#include <rte_cpuflags.h>
> > +#include <rte_interrupts.h>
> > +#include <rte_pci.h>
> > +#include <rte_dev.h>
> > +#include <rte_devargs.h>
> > +#include <rte_common.h>
> > +#include <rte_version.h>
> > +#include <rte_atomic.h>
> > +#include <malloc_heap.h>
> > +#include <rte_eth_ring.h>
> > +
> > +#include "eal_private.h"
> > +#include "eal_thread.h"
> > +#include "eal_internal_cfg.h"
> > +#include "eal_filesystem.h"
> > +#include "eal_hugepages.h"
> > +#include "eal_options.h"
> > +
> > +/* Allow the application to print its usage message too if set */
> > +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 */
> > +int mem_cfg_fd = -1;
> > +
> > +/* early configuration structure, when memory config is not mmapped */
> > +static struct rte_mem_config early_mem_config;
> > +
> > +/* Address of global and public configuration */
> > +struct rte_config rte_config = {
> > +             .mem_config = &early_mem_config,
> > +};
> > +
> > +static struct flock wr_lock = {
> > +             .l_type = F_WRLCK,
> > +             .l_whence = SEEK_SET,
> > +             .l_start = offsetof(struct rte_mem_config, memseg),
> > +             .l_len = sizeof(early_mem_config.memseg),
> > +};
> > +
> > +/* Return a pointer to the configuration structure */
> > +struct rte_config *
> > +rte_eal_get_configuration(void)
> > +{
> > +     return &rte_config;
> > +}
> > +
> > +/* parse a sysfs (or other) file containing one integer value */
> > +int
> > +eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > +{
> > +     FILE *f;
> > +     char buf[BUFSIZ];
> > +     char *end = NULL;
> > +
> > +     f = fopen(filename, "r");
> > +     if (f == NULL) {
> > +             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > +                     __func__, filename);
> > +             return -1;
> > +     }
> > +
> > +     if (fgets(buf, sizeof(buf), f) == NULL) {
> > +             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > +                     __func__, filename);
> > +             fclose(f);
> > +             return -1;
> > +     }
> > +     *val = strtoul(buf, &end, 0);
> > +     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > +             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> > +                             __func__, filename);
> > +             fclose(f);
> > +             return -1;
> > +     }
> > +     fclose(f);
> > +     return 0;
> > +}
> > +
> > +
> > +/* create memory configuration in shared/mmap memory. Take out
> > + * a write lock on the memsegs, so we can auto-detect primary/secondary.
> > + * This means we never close the file while running (auto-close on
> exit).
> > + * We also don't lock the whole file, so that in future we can use
> read-locks
> > + * on other parts, e.g. memzones, to detect if there are running
> secondary
> > + * processes. */
> > +static void
> > +rte_eal_config_create(void)
> > +{
> > +     void *rte_mem_cfg_addr;
> > +     int retval;
> > +
> > +     const char *pathname = eal_runtime_config_path();
> > +
> > +     if (internal_config.no_shconf)
> > +             return;
> > +
> > +     rte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();
> > +
> > +     if (mem_cfg_fd < 0) {
> > +             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > +             if (mem_cfg_fd < 0)
> > +                     rte_panic("Cannot open '%s' for rte_mem_config\n",
> > +                                     pathname);
> > +     }
> > +
> > +     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > +     if (retval < 0) {
> > +             close(mem_cfg_fd);
> > +             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> pathname);
> > +     }
> > +
> > +     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > +     if (retval < 0) {
> > +             close(mem_cfg_fd);
> > +             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. "
> > +                     "Is another primary process running?\n", pathname);
> > +     }
> > +
> > +     rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
> > +                     sizeof(*rte_config.mem_config), PROT_READ |
> PROT_WRITE,
> > +                     MAP_SHARED, mem_cfg_fd, 0);
> > +
> > +     if (rte_mem_cfg_addr == MAP_FAILED)
> > +             rte_panic("Cannot mmap memory for rte_config\n");
> > +
> > +     memcpy(rte_mem_cfg_addr, &early_mem_config,
> sizeof(early_mem_config));
> > +     rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> > +
> > +#ifndef RTE_EXEC_ENV_BSDAPP
> > +     /* store address of the config in the config itself so that
> secondary
> > +      * processes could later map the config into this exact location
> > +      */
> > +     rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
> > +#endif /* RTE_EXEC_ENV_BSDAPP */
> Why is this a BSD/Linux Differentiator?
>

<rk> Existing code where assignment is not present in BSD code hence the
differentiation.

> Neil
>
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 7/7] Move EAL common functions
  2014-12-25 17:46   ` Neil Horman
@ 2014-12-25 19:22     ` Ravi Kerur
  2014-12-26 14:44       ` Neil Horman
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 19:22 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Inline <rk>

On Thu, Dec 25, 2014 at 9:46 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:17AM -0500, Ravi Kerur wrote:
> > Move common functions in eal_memory.c to librte_eal/common
> > directory.
> > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > common functions.
> > Fix checkpatch warnings and errors.
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > ---
> >  lib/librte_eal/bsdapp/eal/eal_memory.c    | 36
> ++------------------------
> >  lib/librte_eal/common/eal_common_memory.c | 43
> +++++++++++++++++++++++++++++--
> >  lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
> >  lib/librte_eal/linuxapp/eal/eal_memory.c  | 36
> ++------------------------
> >  4 files changed, 73 insertions(+), 70 deletions(-)
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c
> b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > index 65ee87d..b192705 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal_memory.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > @@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
> >       return RTE_BAD_PHYS_ADDR;
> >  }
> >
> > -static int
> > +int
> >  rte_eal_contigmem_init(void)
> >  {
> >       struct rte_mem_config *mcfg;
> > @@ -130,7 +130,7 @@ rte_eal_contigmem_init(void)
> >       return 0;
> >  }
> >
> > -static int
> > +int
> >  rte_eal_contigmem_attach(void)
> >  {
> >       const struct hugepage_info *hpi;
> > @@ -190,35 +190,3 @@ error:
> >       return -1;
> >  }
> >
> > -
> > -static int
> > -rte_eal_memdevice_init(void)
> > -{
> > -     struct rte_config *config;
> > -
> > -     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > -             return 0;
> > -
> > -     config = rte_eal_get_configuration();
> > -     config->mem_config->nchannel = internal_config.force_nchannel;
> > -     config->mem_config->nrank = internal_config.force_nrank;
> > -
> > -     return 0;
> > -}
> > -
> > -/* init memory subsystem */
> > -int
> > -rte_eal_memory_init(void)
> > -{
> > -     RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> > -     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > -                     rte_eal_contigmem_init() :
> > -                     rte_eal_contigmem_attach();
> > -     if (retval < 0)
> > -             return -1;
> > -
> > -     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> > -             return -1;
> > -
> > -     return 0;
> > -}
> > diff --git a/lib/librte_eal/common/eal_common_memory.c
> b/lib/librte_eal/common/eal_common_memory.c
> > index 77830f8..da7aa98 100644
> > --- a/lib/librte_eal/common/eal_common_memory.c
> > +++ b/lib/librte_eal/common/eal_common_memory.c
> > @@ -46,6 +46,7 @@
> >  #include <rte_log.h>
> >
> >  #include "eal_private.h"
> > +#include "eal_internal_cfg.h"
> >
> >  /*
> >   * Return a pointer to a read-only table of struct rte_physmem_desc
> > @@ -70,7 +71,7 @@ rte_eal_get_physmem_size(void)
> >       /* get pointer to global configuration */
> >       mcfg = rte_eal_get_configuration()->mem_config;
> >
> > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> >               if (mcfg->memseg[i].addr == NULL)
> >                       break;
> >
> > @@ -90,7 +91,7 @@ rte_dump_physmem_layout(FILE *f)
> >       /* get pointer to global configuration */
> >       mcfg = rte_eal_get_configuration()->mem_config;
> >
> > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> >               if (mcfg->memseg[i].addr == NULL)
> >                       break;
> >
> > @@ -119,3 +120,41 @@ unsigned rte_memory_get_nrank(void)
> >  {
> >       return rte_eal_get_configuration()->mem_config->nrank;
> >  }
> > +
> > +static int
> > +rte_eal_memdevice_init(void)
> > +{
> > +     struct rte_config *config;
> > +
> > +     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > +             return 0;
> > +
> > +     config = rte_eal_get_configuration();
> > +     config->mem_config->nchannel = internal_config.force_nchannel;
> > +     config->mem_config->nrank = internal_config.force_nrank;
> > +
> > +     return 0;
> > +}
> > +
> > +/* init memory subsystem */
> > +int
> > +rte_eal_memory_init(void)
> > +{
> > +     RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> > +     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > +#ifdef RTE_EXEC_ENV_BSDAPP
> > +                     rte_eal_contigmem_init() :
> > +                     rte_eal_contigmem_attach();
> > +#else /* RTE_EXEC_ENV_BSDAPP */
> > +                     rte_eal_hugepage_init() :
> > +                     rte_eal_hugepage_attach();
> > +#endif /* RTE_EXEC_ENV_BSDAPP */
> Given that the functions you are calling here are only ever build for the
> platform they are called from, it seems to me that you can give them a
> shared
> name, and just build the appropriate one.  I.e. you don't need to add
> ifdeffery
> here.
>
>
<rk> Agreed and will be done. Only reason I left it as is because I thought
it might create confusion since in the code/document in BSD it's referred
as contigmem rather than hugepage.


> Neil
>
> > +
> > +     if (retval < 0)
> > +             return -1;
> > +
> > +     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> > +             return -1;
> > +
> > +     return 0;
> > +}
> > diff --git a/lib/librte_eal/common/eal_private.h
> b/lib/librte_eal/common/eal_private.h
> > index 19af23d..16338a2 100644
> > --- a/lib/librte_eal/common/eal_private.h
> > +++ b/lib/librte_eal/common/eal_private.h
> > @@ -286,6 +286,20 @@ int get_ncpus(void);
> >   */
> >  int set_tsc_freq_from_sysctl(void);
> >
> > +/**
> > + * This function prepares physical memory mapping
> > + *
> > + * This function is private to the EAL.
> > + */
> > +int rte_eal_contigmem_init(void);
> > +
> > +/**
> > + * This function creates memory mapping in secondary
> > + *
> > + * This function is private to the EAL.
> > + */
> > +int rte_eal_contigmem_attach(void);
> > +
> >  #else /* RTE_EXEC_ENV_BSDAPP */
> >  /**
> >   * This function check if cpu is present
> > @@ -301,6 +315,20 @@ int cpu_detected(unsigned lcore_id);
> >   */
> >  int set_tsc_freq_from_clock(void);
> >
> > +/**
> > + * This function prepares physical memory mapping
> > + *
> > + * This function is private to the EAL.
> > + */
> > +int rte_eal_hugepage_init(void);
> > +
> > +/**
> > + * This function creates memory mapping in secondary
> > + *
> > + * This function is private to the EAL.
> > + */
> > +int rte_eal_hugepage_attach(void);
> > +
> >  #endif /* RTE_EXEC_ENV_BSDAPP */
> >
> >  #endif /* _EAL_PRIVATE_H_ */
> > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c
> b/lib/librte_eal/linuxapp/eal/eal_memory.c
> > index bae2507..f4d91df 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> > @@ -1031,7 +1031,7 @@ calc_num_pages_per_socket(uint64_t * memory,
> >   *  6. unmap the first mapping
> >   *  7. fill memsegs in configuration with contiguous zones
> >   */
> > -static int
> > +int
> >  rte_eal_hugepage_init(void)
> >  {
> >       struct rte_mem_config *mcfg;
> > @@ -1369,7 +1369,7 @@ getFileSize(int fd)
> >   * configuration and finds the hugepages which form that segment,
> mapping them
> >   * in order to form a contiguous block in the virtual memory space
> >   */
> > -static int
> > +int
> >  rte_eal_hugepage_attach(void)
> >  {
> >       const struct rte_mem_config *mcfg =
> rte_eal_get_configuration()->mem_config;
> > @@ -1530,35 +1530,3 @@ error:
> >       return -1;
> >  }
> >
> > -static int
> > -rte_eal_memdevice_init(void)
> > -{
> > -     struct rte_config *config;
> > -
> > -     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > -             return 0;
> > -
> > -     config = rte_eal_get_configuration();
> > -     config->mem_config->nchannel = internal_config.force_nchannel;
> > -     config->mem_config->nrank = internal_config.force_nrank;
> > -
> > -     return 0;
> > -}
> > -
> > -
> > -/* init memory subsystem */
> > -int
> > -rte_eal_memory_init(void)
> > -{
> > -     RTE_LOG(INFO, EAL, "Setting up memory...\n");
> > -     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > -                     rte_eal_hugepage_init() :
> > -                     rte_eal_hugepage_attach();
> > -     if (retval < 0)
> > -             return -1;
> > -
> > -     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> > -             return -1;
> > -
> > -     return 0;
> > -}
> > --
> > 1.9.1
> >
> >
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-25 17:30   ` Neil Horman
@ 2014-12-25 19:23     ` Ravi Kerur
  2014-12-26 14:40       ` Neil Horman
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-25 19:23 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Thanks Neil for reviews. Inline <rk>

On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 10:33:12AM -0500, Ravi Kerur wrote:
> > eal_debug.c has no difference between Linux and BSD, move
> > into common directory.
> > Rename eal_debug.c to eal_common_debug.c
> > Makefile changes to reflect file move and name change.
> > Fix checkpatch warnings.
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > +
> > +/* not implemented in this environment */
> > +void rte_dump_registers(void)
> > +{
> > +}
> Clearly this function has no use, instead of keeping it around, can you
> please
> remove it until someone works up the gumption to make it do something.
> We're
> just wasting an extra call instruction here so someone doesn't have to
> write a
> prototype in the future.  I don't see the value.
>

<rk> This is existing code, I just removed "return" statement as per
checkpatch. Should I make it "inline" and add a comment indicating to
revisit whether to make it inline/no inline when the function is
implemented?

>
> > +/*
> > + * Like rte_panic this terminates the application. However, no
> traceback is
> > + * provided and no core-dump is generated.
> > + */
> > +void
> > +rte_exit(int exit_code, const char *format, ...)
> > +{
> > +     va_list ap;
> > +
> > +     /* disable history */
> > +     rte_log_set_history(0);
> > +
> > +     if (exit_code != 0)
> > +             RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
> > +                             "  Cause: ", exit_code);
> > +
> > +     va_start(ap, format);
> > +     rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
> > +     va_end(ap);
> > +
> > +#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> > +     exit(exit_code);
> > +#else
> > +     rte_dump_stack();
> > +     rte_dump_registers();
> > +     abort();
> > +#endif
> This doesn't match with the commentary above.  If rte_exit isn't meant to
> provide a traceback, it shouldn't do so.  If an application wants that to
> happen, then they need to use rte_panic.
>
> <rk> This is again existing code. I can change the comment which matches
the function, will it work?

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-25 19:23     ` Ravi Kerur
@ 2014-12-26 14:40       ` Neil Horman
  2014-12-26 15:28         ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-26 14:40 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 11:23:12AM -0800, Ravi Kerur wrote:
> Thanks Neil for reviews. Inline <rk>
> 
> On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> > On Thu, Dec 25, 2014 at 10:33:12AM -0500, Ravi Kerur wrote:
> > > eal_debug.c has no difference between Linux and BSD, move
> > > into common directory.
> > > Rename eal_debug.c to eal_common_debug.c
> > > Makefile changes to reflect file move and name change.
> > > Fix checkpatch warnings.
> > >
> > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > +
> > > +/* not implemented in this environment */
> > > +void rte_dump_registers(void)
> > > +{
> > > +}
> > Clearly this function has no use, instead of keeping it around, can you
> > please
> > remove it until someone works up the gumption to make it do something.
> > We're
> > just wasting an extra call instruction here so someone doesn't have to
> > write a
> > prototype in the future.  I don't see the value.
> >
> 
> <rk> This is existing code, I just removed "return" statement as per
> checkpatch. Should I make it "inline" and add a comment indicating to
> revisit whether to make it inline/no inline when the function is
> implemented?
> 
I understand its existing code, I'm saying that, while you're moving it around,
clean it up.  Don't make it inline, just remove it, since it does nothing.  If
you feel its important to keep around, I suppose you can make it inline, but I
don't really think its needed at all.

Neil

> >
> > > +/*
> > > + * Like rte_panic this terminates the application. However, no
> > traceback is
> > > + * provided and no core-dump is generated.
> > > + */
> > > +void
> > > +rte_exit(int exit_code, const char *format, ...)
> > > +{
> > > +     va_list ap;
> > > +
> > > +     /* disable history */
> > > +     rte_log_set_history(0);
> > > +
> > > +     if (exit_code != 0)
> > > +             RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
> > > +                             "  Cause: ", exit_code);
> > > +
> > > +     va_start(ap, format);
> > > +     rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
> > > +     va_end(ap);
> > > +
> > > +#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> > > +     exit(exit_code);
> > > +#else
> > > +     rte_dump_stack();
> > > +     rte_dump_registers();
> > > +     abort();
> > > +#endif
> > This doesn't match with the commentary above.  If rte_exit isn't meant to
> > provide a traceback, it shouldn't do so.  If an application wants that to
> > happen, then they need to use rte_panic.
> >
> > <rk> This is again existing code. I can change the comment which matches
> the function, will it work?

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 3/7] Move EAL common functions
  2014-12-25 19:13     ` Ravi Kerur
@ 2014-12-26 14:40       ` Neil Horman
  0 siblings, 0 replies; 41+ messages in thread
From: Neil Horman @ 2014-12-26 14:40 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 11:13:09AM -0800, Ravi Kerur wrote:
> Inline <rk>
> 
> On Thu, Dec 25, 2014 at 9:41 AM, Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> > On Thu, Dec 25, 2014 at 10:33:13AM -0500, Ravi Kerur wrote:
> > > eal_thread.c has minor difference between Linux and BSD, move
> > > into common directory.
> > > Use RTE_EXEC_ENV_BSDAPP to differentiate minor difference.
> > > Rename eal_thread.c to eal_common_thread.c
> > > Makefile changes to reflect file move and name change.
> > > Fix checkpatch warnings.
> > >
> > Don't you want to add RTE_EXEC_ENV_BSDAPP=y to config/common_bsdapp?
> >
> 
> <rk> Its already defined in common/common_bsdapp.
> 
Ah, my bad.
> >
> > Neil
> >
> >

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-25 19:17     ` Ravi Kerur
@ 2014-12-26 14:42       ` Neil Horman
  2014-12-26 15:30         ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-26 14:42 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 11:17:41AM -0800, Ravi Kerur wrote:
> Inline <rk>
> 
> On Thu, Dec 25, 2014 at 9:44 AM, Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> > On Thu, Dec 25, 2014 at 10:33:14AM -0500, Ravi Kerur wrote:
> > > Move common functions in eal.c to librte_eal/common directory.
> > > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > > common functions.
> > > Makefile changes to reflect new file.
> > > Fix checkpatch warnings and errors.
> > >
> > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > ---
> > >  lib/librte_eal/bsdapp/eal/Makefile    |   1 +
> > >  lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
> > >  lib/librte_eal/common/eal_common.c    | 328
> > ++++++++++++++++++++++++++++++++++
> > >  lib/librte_eal/common/eal_externs.h   |  42 +++++
> > >  lib/librte_eal/common/eal_hugepages.h |   1 +
> > >  lib/librte_eal/common/eal_private.h   |  47 +++++
> > >  lib/librte_eal/linuxapp/eal/Makefile  |   1 +
> > >  lib/librte_eal/linuxapp/eal/eal.c     | 246 ++-----------------------
> > >  8 files changed, 439 insertions(+), 460 deletions(-)
> > >  create mode 100644 lib/librte_eal/common/eal_common.c
> > >  create mode 100644 lib/librte_eal/common/eal_externs.h
> > >
> > > diff --git a/lib/librte_eal/bsdapp/eal/Makefile
> > b/lib/librte_eal/bsdapp/eal/Makefile
> > > index 92dd9a6..050d70b 100644
> > > --- a/lib/librte_eal/bsdapp/eal/Makefile
> > > +++ b/lib/librte_eal/bsdapp/eal/Makefile
> > > @@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=
> > eal_interrupts.c
> > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
> > >
> > >  # from common dir
> > > +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common.c
> > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
> > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
> > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
> > > diff --git a/lib/librte_eal/bsdapp/eal/eal.c
> > b/lib/librte_eal/bsdapp/eal/eal.c
> > > index 69f3c03..f925da7 100644
> > > --- a/lib/librte_eal/bsdapp/eal/eal.c
> > > +++ b/lib/librte_eal/bsdapp/eal/eal.c
> > > @@ -80,30 +80,10 @@
> > >  #include "eal_filesystem.h"
> > >  #include "eal_hugepages.h"
> > >  #include "eal_options.h"
> > > +#include "eal_externs.h"
> > >
> > >  #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;
> > > -/* early configuration structure, when memory config is not mmapped */
> > > -static struct rte_mem_config early_mem_config;
> > > -
> > > -/* 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;
> > > -
> > > -static struct flock wr_lock = {
> > > -             .l_type = F_WRLCK,
> > > -             .l_whence = SEEK_SET,
> > > -             .l_start = offsetof(struct rte_mem_config, memseg),
> > > -             .l_len = sizeof(early_mem_config.memseg),
> > > -};
> > > -
> > > -/* Address of global and public configuration */
> > > -static struct rte_config rte_config = {
> > > -             .mem_config = &early_mem_config,
> > > -};
> > > -
> > >  /* internal configuration (per-core) */
> > >  struct lcore_config lcore_config[RTE_MAX_LCORE];
> > >
> > > @@ -113,93 +93,14 @@ struct internal_config internal_config;
> > >  /* used by rte_rdtsc() */
> > >  int rte_cycles_vmware_tsc_map;
> > >
> > > -/* Return a pointer to the configuration structure */
> > > -struct rte_config *
> > > -rte_eal_get_configuration(void)
> > > +inline void *
> > > +rte_eal_get_mem_cfg_addr(void)
> > >  {
> > > -     return &rte_config;
> > > -}
> > > -
> > > -/* parse a sysfs (or other) file containing one integer value */
> > > -int
> > > -eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > > -{
> > > -     FILE *f;
> > > -     char buf[BUFSIZ];
> > > -     char *end = NULL;
> > > -
> > > -     if ((f = fopen(filename, "r")) == NULL) {
> > > -             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > > -                     __func__, filename);
> > > -             return -1;
> > > -     }
> > > -
> > > -     if (fgets(buf, sizeof(buf), f) == NULL) {
> > > -             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > > -                     __func__, filename);
> > > -             fclose(f);
> > > -             return -1;
> > > -     }
> > > -     *val = strtoul(buf, &end, 0);
> > > -     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > > -             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> > > -                             __func__, filename);
> > > -             fclose(f);
> > > -             return -1;
> > > -     }
> > > -     fclose(f);
> > > -     return 0;
> > > -}
> > > -
> > > -
> > > -/* create memory configuration in shared/mmap memory. Take out
> > > - * a write lock on the memsegs, so we can auto-detect primary/secondary.
> > > - * This means we never close the file while running (auto-close on
> > exit).
> > > - * We also don't lock the whole file, so that in future we can use
> > read-locks
> > > - * on other parts, e.g. memzones, to detect if there are running
> > secondary
> > > - * processes. */
> > > -static void
> > > -rte_eal_config_create(void)
> > > -{
> > > -     void *rte_mem_cfg_addr;
> > > -     int retval;
> > > -
> > > -     const char *pathname = eal_runtime_config_path();
> > > -
> > > -     if (internal_config.no_shconf)
> > > -             return;
> > > -
> > > -     if (mem_cfg_fd < 0){
> > > -             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > > -             if (mem_cfg_fd < 0)
> > > -                     rte_panic("Cannot open '%s' for rte_mem_config\n",
> > pathname);
> > > -     }
> > > -
> > > -     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > > -     if (retval < 0){
> > > -             close(mem_cfg_fd);
> > > -             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> > pathname);
> > > -     }
> > > -
> > > -     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > > -     if (retval < 0){
> > > -             close(mem_cfg_fd);
> > > -             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is
> > another primary "
> > > -                             "process running?\n", pathname);
> > > -     }
> > > -
> > > -     rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
> > > -                             PROT_READ | PROT_WRITE, MAP_SHARED,
> > mem_cfg_fd, 0);
> > > -
> > > -     if (rte_mem_cfg_addr == MAP_FAILED){
> > > -             rte_panic("Cannot mmap memory for rte_config\n");
> > > -     }
> > > -     memcpy(rte_mem_cfg_addr, &early_mem_config,
> > sizeof(early_mem_config));
> > > -     rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> > > +     return NULL;
> > >  }
> > >
> > >  /* attach to an existing shared memory config */
> > > -static void
> > > +void
> > >  rte_eal_config_attach(void)
> > >  {
> > >       void *rte_mem_cfg_addr;
> > > @@ -223,44 +124,11 @@ rte_eal_config_attach(void)
> > >       rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> > >  }
> > >
> > > -/* Detect if we are a primary or a secondary process */
> > > -enum rte_proc_type_t
> > > -eal_proc_type_detect(void)
> > > +/* NOP for BSD */
> > > +void
> > > +rte_eal_config_reattach(void)
> > >  {
> > > -     enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
> > > -     const char *pathname = eal_runtime_config_path();
> > > -
> > > -     /* if we can open the file but not get a write-lock we are a
> > secondary
> > > -      * process. NOTE: if we get a file handle back, we keep that open
> > > -      * and don't close it to prevent a race condition between multiple
> > opens */
> > > -     if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
> > > -                     (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> > > -             ptype = RTE_PROC_SECONDARY;
> > > -
> > > -     RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
> > > -                     ptype == RTE_PROC_PRIMARY ? "PRIMARY" :
> > "SECONDARY");
> > >
> > > -     return ptype;
> > > -}
> > > -
> > > -/* Sets up rte_config structure with the pointer to shared memory
> > config.*/
> > > -static void
> > > -rte_config_init(void)
> > > -{
> > > -     rte_config.process_type = internal_config.process_type;
> > > -
> > > -     switch (rte_config.process_type){
> > > -     case RTE_PROC_PRIMARY:
> > > -             rte_eal_config_create();
> > > -             break;
> > > -     case RTE_PROC_SECONDARY:
> > > -             rte_eal_config_attach();
> > > -             rte_eal_mcfg_wait_complete(rte_config.mem_config);
> > > -             break;
> > > -     case RTE_PROC_AUTO:
> > > -     case RTE_PROC_INVALID:
> > > -             rte_panic("Invalid process type\n");
> > > -     }
> > >  }
> > >
> > >  /* display usage */
> > > @@ -276,37 +144,6 @@ eal_usage(const char *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)
> > > -{
> > > -     uint64_t size = 0;
> > > -     unsigned i, j;
> > > -
> > > -     for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
> > > -             struct hugepage_info *hpi =
> > &internal_config.hugepage_info[i];
> > > -             if (hpi->hugedir != NULL) {
> > > -                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
> > > -                             size += hpi->hugepage_sz *
> > hpi->num_pages[j];
> > > -                     }
> > > -             }
> > > -     }
> > > -
> > > -     return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
> > > -}
> > > -
> > >  /* Parse the argument given in the command line of the application */
> > >  static int
> > >  eal_parse_args(int argc, char **argv)
> > > @@ -374,45 +211,6 @@ eal_parse_args(int argc, char **argv)
> > >       return ret;
> > >  }
> > >
> > > -static void
> > > -eal_check_mem_on_local_socket(void)
> > > -{
> > > -     const struct rte_memseg *ms;
> > > -     int i, socket_id;
> > > -
> > > -     socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
> > > -
> > > -     ms = rte_eal_get_physmem_layout();
> > > -
> > > -     for (i = 0; i < RTE_MAX_MEMSEG; i++)
> > > -             if (ms[i].socket_id == socket_id &&
> > > -                             ms[i].len > 0)
> > > -                     return;
> > > -
> > > -     RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
> > > -                     "memory on local socket!\n");
> > > -}
> > > -
> > > -static int
> > > -sync_func(__attribute__((unused)) void *arg)
> > > -{
> > > -     return 0;
> > > -}
> > > -
> > > -inline static void
> > > -rte_eal_mcfg_complete(void)
> > > -{
> > > -     /* ALL shared mem_config related INIT DONE */
> > > -     if (rte_config.process_type == RTE_PROC_PRIMARY)
> > > -             rte_config.mem_config->magic = RTE_MAGIC;
> > > -}
> > > -
> > > -/* return non-zero if hugepages are enabled. */
> > > -int rte_eal_has_hugepages(void)
> > > -{
> > > -     return !internal_config.no_hugetlbfs;
> > > -}
> > > -
> > >  /* Abstraction for port I/0 privilege */
> > >  int
> > >  rte_eal_iopl_init(void)
> > > @@ -476,7 +274,7 @@ rte_eal_init(int argc, char **argv)
> > >
> > >       rte_srand(rte_rdtsc());
> > >
> > > -     rte_config_init();
> > > +     rte_eal_config_init();
> > >
> > >       if (rte_eal_memory_init() < 0)
> > >               rte_panic("Cannot init memory\n");
> > > @@ -548,16 +346,3 @@ rte_eal_init(int argc, char **argv)
> > >       return fctret;
> > >  }
> > >
> > > -/* get core role */
> > > -enum rte_lcore_role_t
> > > -rte_eal_lcore_role(unsigned lcore_id)
> > > -{
> > > -     return (rte_config.lcore_role[lcore_id]);
> > > -}
> > > -
> > > -enum rte_proc_type_t
> > > -rte_eal_process_type(void)
> > > -{
> > > -     return (rte_config.process_type);
> > > -}
> > > -
> > > diff --git a/lib/librte_eal/common/eal_common.c
> > b/lib/librte_eal/common/eal_common.c
> > > new file mode 100644
> > > index 0000000..becf9c8
> > > --- /dev/null
> > > +++ b/lib/librte_eal/common/eal_common.c
> > > @@ -0,0 +1,328 @@
> > > +/*-
> > > + *   BSD LICENSE
> > > + *
> > > + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> > > + *   Copyright(c) 2014 6WIND S.A.
> > > + *   All rights reserved.
> > > + *
> > > + *   Redistribution and use in source and binary forms, with or without
> > > + *   modification, are permitted provided that the following conditions
> > > + *   are met:
> > > + *
> > > + *     * Redistributions of source code must retain the above copyright
> > > + *       notice, this list of conditions and the following disclaimer.
> > > + *     * Redistributions in binary form must reproduce the above
> > copyright
> > > + *       notice, this list of conditions and the following disclaimer in
> > > + *       the documentation and/or other materials provided with the
> > > + *       distribution.
> > > + *     * Neither the name of Intel Corporation nor the names of its
> > > + *       contributors may be used to endorse or promote products derived
> > > + *       from this software without specific prior written permission.
> > > + *
> > > + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> > > + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> > > + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
> > FOR
> > > + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> > COPYRIGHT
> > > + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> > INCIDENTAL,
> > > + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> > > + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> > USE,
> > > + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> > ANY
> > > + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> > > + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
> > USE
> > > + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
> > DAMAGE.
> > > + */
> > > +
> > > +#include <stdio.h>
> > > +#include <stdlib.h>
> > > +#include <stdint.h>
> > > +#include <string.h>
> > > +#include <stdarg.h>
> > > +#include <unistd.h>
> > > +#include <pthread.h>
> > > +#include <syslog.h>
> > > +#include <getopt.h>
> > > +#include <sys/file.h>
> > > +#include <stddef.h>
> > > +#include <errno.h>
> > > +#include <limits.h>
> > > +#include <errno.h>
> > > +#include <sys/mman.h>
> > > +#include <sys/queue.h>
> > > +
> > > +#include <rte_common.h>
> > > +#include <rte_debug.h>
> > > +#include <rte_memory.h>
> > > +#include <rte_memzone.h>
> > > +#include <rte_launch.h>
> > > +#include <rte_tailq.h>
> > > +#include <rte_eal.h>
> > > +#include <rte_eal_memconfig.h>
> > > +#include <rte_per_lcore.h>
> > > +#include <rte_lcore.h>
> > > +#include <rte_log.h>
> > > +#include <rte_random.h>
> > > +#include <rte_cycles.h>
> > > +#include <rte_string_fns.h>
> > > +#include <rte_cpuflags.h>
> > > +#include <rte_interrupts.h>
> > > +#include <rte_pci.h>
> > > +#include <rte_dev.h>
> > > +#include <rte_devargs.h>
> > > +#include <rte_common.h>
> > > +#include <rte_version.h>
> > > +#include <rte_atomic.h>
> > > +#include <malloc_heap.h>
> > > +#include <rte_eth_ring.h>
> > > +
> > > +#include "eal_private.h"
> > > +#include "eal_thread.h"
> > > +#include "eal_internal_cfg.h"
> > > +#include "eal_filesystem.h"
> > > +#include "eal_hugepages.h"
> > > +#include "eal_options.h"
> > > +
> > > +/* Allow the application to print its usage message too if set */
> > > +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 */
> > > +int mem_cfg_fd = -1;
> > > +
> > > +/* early configuration structure, when memory config is not mmapped */
> > > +static struct rte_mem_config early_mem_config;
> > > +
> > > +/* Address of global and public configuration */
> > > +struct rte_config rte_config = {
> > > +             .mem_config = &early_mem_config,
> > > +};
> > > +
> > > +static struct flock wr_lock = {
> > > +             .l_type = F_WRLCK,
> > > +             .l_whence = SEEK_SET,
> > > +             .l_start = offsetof(struct rte_mem_config, memseg),
> > > +             .l_len = sizeof(early_mem_config.memseg),
> > > +};
> > > +
> > > +/* Return a pointer to the configuration structure */
> > > +struct rte_config *
> > > +rte_eal_get_configuration(void)
> > > +{
> > > +     return &rte_config;
> > > +}
> > > +
> > > +/* parse a sysfs (or other) file containing one integer value */
> > > +int
> > > +eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > > +{
> > > +     FILE *f;
> > > +     char buf[BUFSIZ];
> > > +     char *end = NULL;
> > > +
> > > +     f = fopen(filename, "r");
> > > +     if (f == NULL) {
> > > +             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > > +                     __func__, filename);
> > > +             return -1;
> > > +     }
> > > +
> > > +     if (fgets(buf, sizeof(buf), f) == NULL) {
> > > +             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > > +                     __func__, filename);
> > > +             fclose(f);
> > > +             return -1;
> > > +     }
> > > +     *val = strtoul(buf, &end, 0);
> > > +     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > > +             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
> > > +                             __func__, filename);
> > > +             fclose(f);
> > > +             return -1;
> > > +     }
> > > +     fclose(f);
> > > +     return 0;
> > > +}
> > > +
> > > +
> > > +/* create memory configuration in shared/mmap memory. Take out
> > > + * a write lock on the memsegs, so we can auto-detect primary/secondary.
> > > + * This means we never close the file while running (auto-close on
> > exit).
> > > + * We also don't lock the whole file, so that in future we can use
> > read-locks
> > > + * on other parts, e.g. memzones, to detect if there are running
> > secondary
> > > + * processes. */
> > > +static void
> > > +rte_eal_config_create(void)
> > > +{
> > > +     void *rte_mem_cfg_addr;
> > > +     int retval;
> > > +
> > > +     const char *pathname = eal_runtime_config_path();
> > > +
> > > +     if (internal_config.no_shconf)
> > > +             return;
> > > +
> > > +     rte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();
> > > +
> > > +     if (mem_cfg_fd < 0) {
> > > +             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > > +             if (mem_cfg_fd < 0)
> > > +                     rte_panic("Cannot open '%s' for rte_mem_config\n",
> > > +                                     pathname);
> > > +     }
> > > +
> > > +     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > > +     if (retval < 0) {
> > > +             close(mem_cfg_fd);
> > > +             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> > pathname);
> > > +     }
> > > +
> > > +     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > > +     if (retval < 0) {
> > > +             close(mem_cfg_fd);
> > > +             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. "
> > > +                     "Is another primary process running?\n", pathname);
> > > +     }
> > > +
> > > +     rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
> > > +                     sizeof(*rte_config.mem_config), PROT_READ |
> > PROT_WRITE,
> > > +                     MAP_SHARED, mem_cfg_fd, 0);
> > > +
> > > +     if (rte_mem_cfg_addr == MAP_FAILED)
> > > +             rte_panic("Cannot mmap memory for rte_config\n");
> > > +
> > > +     memcpy(rte_mem_cfg_addr, &early_mem_config,
> > sizeof(early_mem_config));
> > > +     rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
> > > +
> > > +#ifndef RTE_EXEC_ENV_BSDAPP
> > > +     /* store address of the config in the config itself so that
> > secondary
> > > +      * processes could later map the config into this exact location
> > > +      */
> > > +     rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
> > > +#endif /* RTE_EXEC_ENV_BSDAPP */
> > Why is this a BSD/Linux Differentiator?
> >
> 
> <rk> Existing code where assignment is not present in BSD code hence the
> differentiation.
> 
I presume then that the BSD code doesn't use mem_cfg_addr at all?  If so, why
not just assign it unilaterally and avoid the ifdeffery?
Neil

> > Neil
> >
> >

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 7/7] Move EAL common functions
  2014-12-25 19:22     ` Ravi Kerur
@ 2014-12-26 14:44       ` Neil Horman
  2014-12-26 15:28         ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-26 14:44 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Thu, Dec 25, 2014 at 11:22:53AM -0800, Ravi Kerur wrote:
> Inline <rk>
> 
> On Thu, Dec 25, 2014 at 9:46 AM, Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> > On Thu, Dec 25, 2014 at 10:33:17AM -0500, Ravi Kerur wrote:
> > > Move common functions in eal_memory.c to librte_eal/common
> > > directory.
> > > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > > common functions.
> > > Fix checkpatch warnings and errors.
> > >
> > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > ---
> > >  lib/librte_eal/bsdapp/eal/eal_memory.c    | 36
> > ++------------------------
> > >  lib/librte_eal/common/eal_common_memory.c | 43
> > +++++++++++++++++++++++++++++--
> > >  lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
> > >  lib/librte_eal/linuxapp/eal/eal_memory.c  | 36
> > ++------------------------
> > >  4 files changed, 73 insertions(+), 70 deletions(-)
> > >
> > > diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c
> > b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > index 65ee87d..b192705 100644
> > > --- a/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > @@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
> > >       return RTE_BAD_PHYS_ADDR;
> > >  }
> > >
> > > -static int
> > > +int
> > >  rte_eal_contigmem_init(void)
> > >  {
> > >       struct rte_mem_config *mcfg;
> > > @@ -130,7 +130,7 @@ rte_eal_contigmem_init(void)
> > >       return 0;
> > >  }
> > >
> > > -static int
> > > +int
> > >  rte_eal_contigmem_attach(void)
> > >  {
> > >       const struct hugepage_info *hpi;
> > > @@ -190,35 +190,3 @@ error:
> > >       return -1;
> > >  }
> > >
> > > -
> > > -static int
> > > -rte_eal_memdevice_init(void)
> > > -{
> > > -     struct rte_config *config;
> > > -
> > > -     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > > -             return 0;
> > > -
> > > -     config = rte_eal_get_configuration();
> > > -     config->mem_config->nchannel = internal_config.force_nchannel;
> > > -     config->mem_config->nrank = internal_config.force_nrank;
> > > -
> > > -     return 0;
> > > -}
> > > -
> > > -/* init memory subsystem */
> > > -int
> > > -rte_eal_memory_init(void)
> > > -{
> > > -     RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> > > -     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > > -                     rte_eal_contigmem_init() :
> > > -                     rte_eal_contigmem_attach();
> > > -     if (retval < 0)
> > > -             return -1;
> > > -
> > > -     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
> > > -             return -1;
> > > -
> > > -     return 0;
> > > -}
> > > diff --git a/lib/librte_eal/common/eal_common_memory.c
> > b/lib/librte_eal/common/eal_common_memory.c
> > > index 77830f8..da7aa98 100644
> > > --- a/lib/librte_eal/common/eal_common_memory.c
> > > +++ b/lib/librte_eal/common/eal_common_memory.c
> > > @@ -46,6 +46,7 @@
> > >  #include <rte_log.h>
> > >
> > >  #include "eal_private.h"
> > > +#include "eal_internal_cfg.h"
> > >
> > >  /*
> > >   * Return a pointer to a read-only table of struct rte_physmem_desc
> > > @@ -70,7 +71,7 @@ rte_eal_get_physmem_size(void)
> > >       /* get pointer to global configuration */
> > >       mcfg = rte_eal_get_configuration()->mem_config;
> > >
> > > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> > >               if (mcfg->memseg[i].addr == NULL)
> > >                       break;
> > >
> > > @@ -90,7 +91,7 @@ rte_dump_physmem_layout(FILE *f)
> > >       /* get pointer to global configuration */
> > >       mcfg = rte_eal_get_configuration()->mem_config;
> > >
> > > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> > >               if (mcfg->memseg[i].addr == NULL)
> > >                       break;
> > >
> > > @@ -119,3 +120,41 @@ unsigned rte_memory_get_nrank(void)
> > >  {
> > >       return rte_eal_get_configuration()->mem_config->nrank;
> > >  }
> > > +
> > > +static int
> > > +rte_eal_memdevice_init(void)
> > > +{
> > > +     struct rte_config *config;
> > > +
> > > +     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > > +             return 0;
> > > +
> > > +     config = rte_eal_get_configuration();
> > > +     config->mem_config->nchannel = internal_config.force_nchannel;
> > > +     config->mem_config->nrank = internal_config.force_nrank;
> > > +
> > > +     return 0;
> > > +}
> > > +
> > > +/* init memory subsystem */
> > > +int
> > > +rte_eal_memory_init(void)
> > > +{
> > > +     RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
> > > +     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > > +#ifdef RTE_EXEC_ENV_BSDAPP
> > > +                     rte_eal_contigmem_init() :
> > > +                     rte_eal_contigmem_attach();
> > > +#else /* RTE_EXEC_ENV_BSDAPP */
> > > +                     rte_eal_hugepage_init() :
> > > +                     rte_eal_hugepage_attach();
> > > +#endif /* RTE_EXEC_ENV_BSDAPP */
> > Given that the functions you are calling here are only ever build for the
> > platform they are called from, it seems to me that you can give them a
> > shared
> > name, and just build the appropriate one.  I.e. you don't need to add
> > ifdeffery
> > here.
> >
> >
> <rk> Agreed and will be done. Only reason I left it as is because I thought
> it might create confusion since in the code/document in BSD it's referred
> as contigmem rather than hugepage.
> 
I agree, it might be a bit confusing, but I think documenting it would be
superior to creating separate function names with additional ifdeffery.  cscope
illustrates pretty well multiple function definitions.

Neil

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-26 14:40       ` Neil Horman
@ 2014-12-26 15:28         ` Ravi Kerur
  2015-01-05  9:40           ` Thomas Monjalon
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-26 15:28 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

On Fri, Dec 26, 2014 at 6:40 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 11:23:12AM -0800, Ravi Kerur wrote:
> > Thanks Neil for reviews. Inline <rk>
> >
> > On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <nhorman@tuxdriver.com>
> wrote:
> >
> > > On Thu, Dec 25, 2014 at 10:33:12AM -0500, Ravi Kerur wrote:
> > > > eal_debug.c has no difference between Linux and BSD, move
> > > > into common directory.
> > > > Rename eal_debug.c to eal_common_debug.c
> > > > Makefile changes to reflect file move and name change.
> > > > Fix checkpatch warnings.
> > > >
> > > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > > +
> > > > +/* not implemented in this environment */
> > > > +void rte_dump_registers(void)
> > > > +{
> > > > +}
> > > Clearly this function has no use, instead of keeping it around, can you
> > > please
> > > remove it until someone works up the gumption to make it do something.
> > > We're
> > > just wasting an extra call instruction here so someone doesn't have to
> > > write a
> > > prototype in the future.  I don't see the value.
> > >
> >
> > <rk> This is existing code, I just removed "return" statement as per
> > checkpatch. Should I make it "inline" and add a comment indicating to
> > revisit whether to make it inline/no inline when the function is
> > implemented?
> >
> I understand its existing code, I'm saying that, while you're moving it
> around,
> clean it up.  Don't make it inline, just remove it, since it does
> nothing.  If
> you feel its important to keep around, I suppose you can make it inline,
> but I
> don't really think its needed at all.
>
> Neil
>
>
<rk> Sure will remove it.

> > >
> > > > +/*
> > > > + * Like rte_panic this terminates the application. However, no
> > > traceback is
> > > > + * provided and no core-dump is generated.
> > > > + */
> > > > +void
> > > > +rte_exit(int exit_code, const char *format, ...)
> > > > +{
> > > > +     va_list ap;
> > > > +
> > > > +     /* disable history */
> > > > +     rte_log_set_history(0);
> > > > +
> > > > +     if (exit_code != 0)
> > > > +             RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
> > > > +                             "  Cause: ", exit_code);
> > > > +
> > > > +     va_start(ap, format);
> > > > +     rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
> > > > +     va_end(ap);
> > > > +
> > > > +#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> > > > +     exit(exit_code);
> > > > +#else
> > > > +     rte_dump_stack();
> > > > +     rte_dump_registers();
> > > > +     abort();
> > > > +#endif
> > > This doesn't match with the commentary above.  If rte_exit isn't meant
> to
> > > provide a traceback, it shouldn't do so.  If an application wants that
> to
> > > happen, then they need to use rte_panic.
> > >
> > > <rk> This is again existing code. I can change the comment which
> matches
> > the function, will it work?
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 7/7] Move EAL common functions
  2014-12-26 14:44       ` Neil Horman
@ 2014-12-26 15:28         ` Ravi Kerur
  0 siblings, 0 replies; 41+ messages in thread
From: Ravi Kerur @ 2014-12-26 15:28 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

On Fri, Dec 26, 2014 at 6:44 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 11:22:53AM -0800, Ravi Kerur wrote:
> > Inline <rk>
> >
> > On Thu, Dec 25, 2014 at 9:46 AM, Neil Horman <nhorman@tuxdriver.com>
> wrote:
> >
> > > On Thu, Dec 25, 2014 at 10:33:17AM -0500, Ravi Kerur wrote:
> > > > Move common functions in eal_memory.c to librte_eal/common
> > > > directory.
> > > > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > > > common functions.
> > > > Fix checkpatch warnings and errors.
> > > >
> > > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > > ---
> > > >  lib/librte_eal/bsdapp/eal/eal_memory.c    | 36
> > > ++------------------------
> > > >  lib/librte_eal/common/eal_common_memory.c | 43
> > > +++++++++++++++++++++++++++++--
> > > >  lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
> > > >  lib/librte_eal/linuxapp/eal/eal_memory.c  | 36
> > > ++------------------------
> > > >  4 files changed, 73 insertions(+), 70 deletions(-)
> > > >
> > > > diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > > index 65ee87d..b192705 100644
> > > > --- a/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > > +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
> > > > @@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
> > > >       return RTE_BAD_PHYS_ADDR;
> > > >  }
> > > >
> > > > -static int
> > > > +int
> > > >  rte_eal_contigmem_init(void)
> > > >  {
> > > >       struct rte_mem_config *mcfg;
> > > > @@ -130,7 +130,7 @@ rte_eal_contigmem_init(void)
> > > >       return 0;
> > > >  }
> > > >
> > > > -static int
> > > > +int
> > > >  rte_eal_contigmem_attach(void)
> > > >  {
> > > >       const struct hugepage_info *hpi;
> > > > @@ -190,35 +190,3 @@ error:
> > > >       return -1;
> > > >  }
> > > >
> > > > -
> > > > -static int
> > > > -rte_eal_memdevice_init(void)
> > > > -{
> > > > -     struct rte_config *config;
> > > > -
> > > > -     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > > > -             return 0;
> > > > -
> > > > -     config = rte_eal_get_configuration();
> > > > -     config->mem_config->nchannel = internal_config.force_nchannel;
> > > > -     config->mem_config->nrank = internal_config.force_nrank;
> > > > -
> > > > -     return 0;
> > > > -}
> > > > -
> > > > -/* init memory subsystem */
> > > > -int
> > > > -rte_eal_memory_init(void)
> > > > -{
> > > > -     RTE_LOG(INFO, EAL, "Setting up physically contiguous
> memory...\n");
> > > > -     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > > > -                     rte_eal_contigmem_init() :
> > > > -                     rte_eal_contigmem_attach();
> > > > -     if (retval < 0)
> > > > -             return -1;
> > > > -
> > > > -     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init()
> < 0)
> > > > -             return -1;
> > > > -
> > > > -     return 0;
> > > > -}
> > > > diff --git a/lib/librte_eal/common/eal_common_memory.c
> > > b/lib/librte_eal/common/eal_common_memory.c
> > > > index 77830f8..da7aa98 100644
> > > > --- a/lib/librte_eal/common/eal_common_memory.c
> > > > +++ b/lib/librte_eal/common/eal_common_memory.c
> > > > @@ -46,6 +46,7 @@
> > > >  #include <rte_log.h>
> > > >
> > > >  #include "eal_private.h"
> > > > +#include "eal_internal_cfg.h"
> > > >
> > > >  /*
> > > >   * Return a pointer to a read-only table of struct rte_physmem_desc
> > > > @@ -70,7 +71,7 @@ rte_eal_get_physmem_size(void)
> > > >       /* get pointer to global configuration */
> > > >       mcfg = rte_eal_get_configuration()->mem_config;
> > > >
> > > > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > > > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> > > >               if (mcfg->memseg[i].addr == NULL)
> > > >                       break;
> > > >
> > > > @@ -90,7 +91,7 @@ rte_dump_physmem_layout(FILE *f)
> > > >       /* get pointer to global configuration */
> > > >       mcfg = rte_eal_get_configuration()->mem_config;
> > > >
> > > > -     for (i=0; i<RTE_MAX_MEMSEG; i++) {
> > > > +     for (i = 0; i < RTE_MAX_MEMSEG; i++) {
> > > >               if (mcfg->memseg[i].addr == NULL)
> > > >                       break;
> > > >
> > > > @@ -119,3 +120,41 @@ unsigned rte_memory_get_nrank(void)
> > > >  {
> > > >       return rte_eal_get_configuration()->mem_config->nrank;
> > > >  }
> > > > +
> > > > +static int
> > > > +rte_eal_memdevice_init(void)
> > > > +{
> > > > +     struct rte_config *config;
> > > > +
> > > > +     if (rte_eal_process_type() == RTE_PROC_SECONDARY)
> > > > +             return 0;
> > > > +
> > > > +     config = rte_eal_get_configuration();
> > > > +     config->mem_config->nchannel = internal_config.force_nchannel;
> > > > +     config->mem_config->nrank = internal_config.force_nrank;
> > > > +
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +/* init memory subsystem */
> > > > +int
> > > > +rte_eal_memory_init(void)
> > > > +{
> > > > +     RTE_LOG(INFO, EAL, "Setting up physically contiguous
> memory...\n");
> > > > +     const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
> > > > +#ifdef RTE_EXEC_ENV_BSDAPP
> > > > +                     rte_eal_contigmem_init() :
> > > > +                     rte_eal_contigmem_attach();
> > > > +#else /* RTE_EXEC_ENV_BSDAPP */
> > > > +                     rte_eal_hugepage_init() :
> > > > +                     rte_eal_hugepage_attach();
> > > > +#endif /* RTE_EXEC_ENV_BSDAPP */
> > > Given that the functions you are calling here are only ever build for
> the
> > > platform they are called from, it seems to me that you can give them a
> > > shared
> > > name, and just build the appropriate one.  I.e. you don't need to add
> > > ifdeffery
> > > here.
> > >
> > >
> > <rk> Agreed and will be done. Only reason I left it as is because I
> thought
> > it might create confusion since in the code/document in BSD it's referred
> > as contigmem rather than hugepage.
> >
> I agree, it might be a bit confusing, but I think documenting it would be
> superior to creating separate function names with additional ifdeffery.
> cscope
> illustrates pretty well multiple function definitions.
>
> Neil
>
>
<rk> WIll take care of using common function names.

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-26 14:42       ` Neil Horman
@ 2014-12-26 15:30         ` Ravi Kerur
  0 siblings, 0 replies; 41+ messages in thread
From: Ravi Kerur @ 2014-12-26 15:30 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

On Fri, Dec 26, 2014 at 6:42 AM, Neil Horman <nhorman@tuxdriver.com> wrote:

> On Thu, Dec 25, 2014 at 11:17:41AM -0800, Ravi Kerur wrote:
> > Inline <rk>
> >
> > On Thu, Dec 25, 2014 at 9:44 AM, Neil Horman <nhorman@tuxdriver.com>
> wrote:
> >
> > > On Thu, Dec 25, 2014 at 10:33:14AM -0500, Ravi Kerur wrote:
> > > > Move common functions in eal.c to librte_eal/common directory.
> > > > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > > > common functions.
> > > > Makefile changes to reflect new file.
> > > > Fix checkpatch warnings and errors.
> > > >
> > > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > > ---
> > > >  lib/librte_eal/bsdapp/eal/Makefile    |   1 +
> > > >  lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
> > > >  lib/librte_eal/common/eal_common.c    | 328
> > > ++++++++++++++++++++++++++++++++++
> > > >  lib/librte_eal/common/eal_externs.h   |  42 +++++
> > > >  lib/librte_eal/common/eal_hugepages.h |   1 +
> > > >  lib/librte_eal/common/eal_private.h   |  47 +++++
> > > >  lib/librte_eal/linuxapp/eal/Makefile  |   1 +
> > > >  lib/librte_eal/linuxapp/eal/eal.c     | 246
> ++-----------------------
> > > >  8 files changed, 439 insertions(+), 460 deletions(-)
> > > >  create mode 100644 lib/librte_eal/common/eal_common.c
> > > >  create mode 100644 lib/librte_eal/common/eal_externs.h
> > > >
> > > > diff --git a/lib/librte_eal/bsdapp/eal/Makefile
> > > b/lib/librte_eal/bsdapp/eal/Makefile
> > > > index 92dd9a6..050d70b 100644
> > > > --- a/lib/librte_eal/bsdapp/eal/Makefile
> > > > +++ b/lib/librte_eal/bsdapp/eal/Makefile
> > > > @@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=
> > > eal_interrupts.c
> > > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
> > > >
> > > >  # from common dir
> > > > +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common.c
> > > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
> > > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
> > > >  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
> > > > diff --git a/lib/librte_eal/bsdapp/eal/eal.c
> > > b/lib/librte_eal/bsdapp/eal/eal.c
> > > > index 69f3c03..f925da7 100644
> > > > --- a/lib/librte_eal/bsdapp/eal/eal.c
> > > > +++ b/lib/librte_eal/bsdapp/eal/eal.c
> > > > @@ -80,30 +80,10 @@
> > > >  #include "eal_filesystem.h"
> > > >  #include "eal_hugepages.h"
> > > >  #include "eal_options.h"
> > > > +#include "eal_externs.h"
> > > >
> > > >  #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;
> > > > -/* early configuration structure, when memory config is not mmapped
> */
> > > > -static struct rte_mem_config early_mem_config;
> > > > -
> > > > -/* 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;
> > > > -
> > > > -static struct flock wr_lock = {
> > > > -             .l_type = F_WRLCK,
> > > > -             .l_whence = SEEK_SET,
> > > > -             .l_start = offsetof(struct rte_mem_config, memseg),
> > > > -             .l_len = sizeof(early_mem_config.memseg),
> > > > -};
> > > > -
> > > > -/* Address of global and public configuration */
> > > > -static struct rte_config rte_config = {
> > > > -             .mem_config = &early_mem_config,
> > > > -};
> > > > -
> > > >  /* internal configuration (per-core) */
> > > >  struct lcore_config lcore_config[RTE_MAX_LCORE];
> > > >
> > > > @@ -113,93 +93,14 @@ struct internal_config internal_config;
> > > >  /* used by rte_rdtsc() */
> > > >  int rte_cycles_vmware_tsc_map;
> > > >
> > > > -/* Return a pointer to the configuration structure */
> > > > -struct rte_config *
> > > > -rte_eal_get_configuration(void)
> > > > +inline void *
> > > > +rte_eal_get_mem_cfg_addr(void)
> > > >  {
> > > > -     return &rte_config;
> > > > -}
> > > > -
> > > > -/* parse a sysfs (or other) file containing one integer value */
> > > > -int
> > > > -eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > > > -{
> > > > -     FILE *f;
> > > > -     char buf[BUFSIZ];
> > > > -     char *end = NULL;
> > > > -
> > > > -     if ((f = fopen(filename, "r")) == NULL) {
> > > > -             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > > > -                     __func__, filename);
> > > > -             return -1;
> > > > -     }
> > > > -
> > > > -     if (fgets(buf, sizeof(buf), f) == NULL) {
> > > > -             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > > > -                     __func__, filename);
> > > > -             fclose(f);
> > > > -             return -1;
> > > > -     }
> > > > -     *val = strtoul(buf, &end, 0);
> > > > -     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > > > -             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value
> %s\n",
> > > > -                             __func__, filename);
> > > > -             fclose(f);
> > > > -             return -1;
> > > > -     }
> > > > -     fclose(f);
> > > > -     return 0;
> > > > -}
> > > > -
> > > > -
> > > > -/* create memory configuration in shared/mmap memory. Take out
> > > > - * a write lock on the memsegs, so we can auto-detect
> primary/secondary.
> > > > - * This means we never close the file while running (auto-close on
> > > exit).
> > > > - * We also don't lock the whole file, so that in future we can use
> > > read-locks
> > > > - * on other parts, e.g. memzones, to detect if there are running
> > > secondary
> > > > - * processes. */
> > > > -static void
> > > > -rte_eal_config_create(void)
> > > > -{
> > > > -     void *rte_mem_cfg_addr;
> > > > -     int retval;
> > > > -
> > > > -     const char *pathname = eal_runtime_config_path();
> > > > -
> > > > -     if (internal_config.no_shconf)
> > > > -             return;
> > > > -
> > > > -     if (mem_cfg_fd < 0){
> > > > -             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > > > -             if (mem_cfg_fd < 0)
> > > > -                     rte_panic("Cannot open '%s' for
> rte_mem_config\n",
> > > pathname);
> > > > -     }
> > > > -
> > > > -     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > > > -     if (retval < 0){
> > > > -             close(mem_cfg_fd);
> > > > -             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> > > pathname);
> > > > -     }
> > > > -
> > > > -     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > > > -     if (retval < 0){
> > > > -             close(mem_cfg_fd);
> > > > -             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is
> > > another primary "
> > > > -                             "process running?\n", pathname);
> > > > -     }
> > > > -
> > > > -     rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
> > > > -                             PROT_READ | PROT_WRITE, MAP_SHARED,
> > > mem_cfg_fd, 0);
> > > > -
> > > > -     if (rte_mem_cfg_addr == MAP_FAILED){
> > > > -             rte_panic("Cannot mmap memory for rte_config\n");
> > > > -     }
> > > > -     memcpy(rte_mem_cfg_addr, &early_mem_config,
> > > sizeof(early_mem_config));
> > > > -     rte_config.mem_config = (struct rte_mem_config *)
> rte_mem_cfg_addr;
> > > > +     return NULL;
> > > >  }
> > > >
> > > >  /* attach to an existing shared memory config */
> > > > -static void
> > > > +void
> > > >  rte_eal_config_attach(void)
> > > >  {
> > > >       void *rte_mem_cfg_addr;
> > > > @@ -223,44 +124,11 @@ rte_eal_config_attach(void)
> > > >       rte_config.mem_config = (struct rte_mem_config *)
> rte_mem_cfg_addr;
> > > >  }
> > > >
> > > > -/* Detect if we are a primary or a secondary process */
> > > > -enum rte_proc_type_t
> > > > -eal_proc_type_detect(void)
> > > > +/* NOP for BSD */
> > > > +void
> > > > +rte_eal_config_reattach(void)
> > > >  {
> > > > -     enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
> > > > -     const char *pathname = eal_runtime_config_path();
> > > > -
> > > > -     /* if we can open the file but not get a write-lock we are a
> > > secondary
> > > > -      * process. NOTE: if we get a file handle back, we keep that
> open
> > > > -      * and don't close it to prevent a race condition between
> multiple
> > > opens */
> > > > -     if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
> > > > -                     (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
> > > > -             ptype = RTE_PROC_SECONDARY;
> > > > -
> > > > -     RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
> > > > -                     ptype == RTE_PROC_PRIMARY ? "PRIMARY" :
> > > "SECONDARY");
> > > >
> > > > -     return ptype;
> > > > -}
> > > > -
> > > > -/* Sets up rte_config structure with the pointer to shared memory
> > > config.*/
> > > > -static void
> > > > -rte_config_init(void)
> > > > -{
> > > > -     rte_config.process_type = internal_config.process_type;
> > > > -
> > > > -     switch (rte_config.process_type){
> > > > -     case RTE_PROC_PRIMARY:
> > > > -             rte_eal_config_create();
> > > > -             break;
> > > > -     case RTE_PROC_SECONDARY:
> > > > -             rte_eal_config_attach();
> > > > -             rte_eal_mcfg_wait_complete(rte_config.mem_config);
> > > > -             break;
> > > > -     case RTE_PROC_AUTO:
> > > > -     case RTE_PROC_INVALID:
> > > > -             rte_panic("Invalid process type\n");
> > > > -     }
> > > >  }
> > > >
> > > >  /* display usage */
> > > > @@ -276,37 +144,6 @@ eal_usage(const char *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)
> > > > -{
> > > > -     uint64_t size = 0;
> > > > -     unsigned i, j;
> > > > -
> > > > -     for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
> > > > -             struct hugepage_info *hpi =
> > > &internal_config.hugepage_info[i];
> > > > -             if (hpi->hugedir != NULL) {
> > > > -                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
> > > > -                             size += hpi->hugepage_sz *
> > > hpi->num_pages[j];
> > > > -                     }
> > > > -             }
> > > > -     }
> > > > -
> > > > -     return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
> > > > -}
> > > > -
> > > >  /* Parse the argument given in the command line of the application
> */
> > > >  static int
> > > >  eal_parse_args(int argc, char **argv)
> > > > @@ -374,45 +211,6 @@ eal_parse_args(int argc, char **argv)
> > > >       return ret;
> > > >  }
> > > >
> > > > -static void
> > > > -eal_check_mem_on_local_socket(void)
> > > > -{
> > > > -     const struct rte_memseg *ms;
> > > > -     int i, socket_id;
> > > > -
> > > > -     socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
> > > > -
> > > > -     ms = rte_eal_get_physmem_layout();
> > > > -
> > > > -     for (i = 0; i < RTE_MAX_MEMSEG; i++)
> > > > -             if (ms[i].socket_id == socket_id &&
> > > > -                             ms[i].len > 0)
> > > > -                     return;
> > > > -
> > > > -     RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
> > > > -                     "memory on local socket!\n");
> > > > -}
> > > > -
> > > > -static int
> > > > -sync_func(__attribute__((unused)) void *arg)
> > > > -{
> > > > -     return 0;
> > > > -}
> > > > -
> > > > -inline static void
> > > > -rte_eal_mcfg_complete(void)
> > > > -{
> > > > -     /* ALL shared mem_config related INIT DONE */
> > > > -     if (rte_config.process_type == RTE_PROC_PRIMARY)
> > > > -             rte_config.mem_config->magic = RTE_MAGIC;
> > > > -}
> > > > -
> > > > -/* return non-zero if hugepages are enabled. */
> > > > -int rte_eal_has_hugepages(void)
> > > > -{
> > > > -     return !internal_config.no_hugetlbfs;
> > > > -}
> > > > -
> > > >  /* Abstraction for port I/0 privilege */
> > > >  int
> > > >  rte_eal_iopl_init(void)
> > > > @@ -476,7 +274,7 @@ rte_eal_init(int argc, char **argv)
> > > >
> > > >       rte_srand(rte_rdtsc());
> > > >
> > > > -     rte_config_init();
> > > > +     rte_eal_config_init();
> > > >
> > > >       if (rte_eal_memory_init() < 0)
> > > >               rte_panic("Cannot init memory\n");
> > > > @@ -548,16 +346,3 @@ rte_eal_init(int argc, char **argv)
> > > >       return fctret;
> > > >  }
> > > >
> > > > -/* get core role */
> > > > -enum rte_lcore_role_t
> > > > -rte_eal_lcore_role(unsigned lcore_id)
> > > > -{
> > > > -     return (rte_config.lcore_role[lcore_id]);
> > > > -}
> > > > -
> > > > -enum rte_proc_type_t
> > > > -rte_eal_process_type(void)
> > > > -{
> > > > -     return (rte_config.process_type);
> > > > -}
> > > > -
> > > > diff --git a/lib/librte_eal/common/eal_common.c
> > > b/lib/librte_eal/common/eal_common.c
> > > > new file mode 100644
> > > > index 0000000..becf9c8
> > > > --- /dev/null
> > > > +++ b/lib/librte_eal/common/eal_common.c
> > > > @@ -0,0 +1,328 @@
> > > > +/*-
> > > > + *   BSD LICENSE
> > > > + *
> > > > + *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
> > > > + *   Copyright(c) 2014 6WIND S.A.
> > > > + *   All rights reserved.
> > > > + *
> > > > + *   Redistribution and use in source and binary forms, with or
> without
> > > > + *   modification, are permitted provided that the following
> conditions
> > > > + *   are met:
> > > > + *
> > > > + *     * Redistributions of source code must retain the above
> copyright
> > > > + *       notice, this list of conditions and the following
> disclaimer.
> > > > + *     * Redistributions in binary form must reproduce the above
> > > copyright
> > > > + *       notice, this list of conditions and the following
> disclaimer in
> > > > + *       the documentation and/or other materials provided with the
> > > > + *       distribution.
> > > > + *     * Neither the name of Intel Corporation nor the names of its
> > > > + *       contributors may be used to endorse or promote products
> derived
> > > > + *       from this software without specific prior written
> permission.
> > > > + *
> > > > + *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> CONTRIBUTORS
> > > > + *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
> NOT
> > > > + *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
> FITNESS
> > > FOR
> > > > + *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
> > > COPYRIGHT
> > > > + *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
> > > INCIDENTAL,
> > > > + *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
> NOT
> > > > + *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
> OF
> > > USE,
> > > > + *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> ON
> > > ANY
> > > > + *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
> TORT
> > > > + *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
> THE
> > > USE
> > > > + *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
> > > DAMAGE.
> > > > + */
> > > > +
> > > > +#include <stdio.h>
> > > > +#include <stdlib.h>
> > > > +#include <stdint.h>
> > > > +#include <string.h>
> > > > +#include <stdarg.h>
> > > > +#include <unistd.h>
> > > > +#include <pthread.h>
> > > > +#include <syslog.h>
> > > > +#include <getopt.h>
> > > > +#include <sys/file.h>
> > > > +#include <stddef.h>
> > > > +#include <errno.h>
> > > > +#include <limits.h>
> > > > +#include <errno.h>
> > > > +#include <sys/mman.h>
> > > > +#include <sys/queue.h>
> > > > +
> > > > +#include <rte_common.h>
> > > > +#include <rte_debug.h>
> > > > +#include <rte_memory.h>
> > > > +#include <rte_memzone.h>
> > > > +#include <rte_launch.h>
> > > > +#include <rte_tailq.h>
> > > > +#include <rte_eal.h>
> > > > +#include <rte_eal_memconfig.h>
> > > > +#include <rte_per_lcore.h>
> > > > +#include <rte_lcore.h>
> > > > +#include <rte_log.h>
> > > > +#include <rte_random.h>
> > > > +#include <rte_cycles.h>
> > > > +#include <rte_string_fns.h>
> > > > +#include <rte_cpuflags.h>
> > > > +#include <rte_interrupts.h>
> > > > +#include <rte_pci.h>
> > > > +#include <rte_dev.h>
> > > > +#include <rte_devargs.h>
> > > > +#include <rte_common.h>
> > > > +#include <rte_version.h>
> > > > +#include <rte_atomic.h>
> > > > +#include <malloc_heap.h>
> > > > +#include <rte_eth_ring.h>
> > > > +
> > > > +#include "eal_private.h"
> > > > +#include "eal_thread.h"
> > > > +#include "eal_internal_cfg.h"
> > > > +#include "eal_filesystem.h"
> > > > +#include "eal_hugepages.h"
> > > > +#include "eal_options.h"
> > > > +
> > > > +/* Allow the application to print its usage message too if set */
> > > > +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 */
> > > > +int mem_cfg_fd = -1;
> > > > +
> > > > +/* early configuration structure, when memory config is not mmapped
> */
> > > > +static struct rte_mem_config early_mem_config;
> > > > +
> > > > +/* Address of global and public configuration */
> > > > +struct rte_config rte_config = {
> > > > +             .mem_config = &early_mem_config,
> > > > +};
> > > > +
> > > > +static struct flock wr_lock = {
> > > > +             .l_type = F_WRLCK,
> > > > +             .l_whence = SEEK_SET,
> > > > +             .l_start = offsetof(struct rte_mem_config, memseg),
> > > > +             .l_len = sizeof(early_mem_config.memseg),
> > > > +};
> > > > +
> > > > +/* Return a pointer to the configuration structure */
> > > > +struct rte_config *
> > > > +rte_eal_get_configuration(void)
> > > > +{
> > > > +     return &rte_config;
> > > > +}
> > > > +
> > > > +/* parse a sysfs (or other) file containing one integer value */
> > > > +int
> > > > +eal_parse_sysfs_value(const char *filename, unsigned long *val)
> > > > +{
> > > > +     FILE *f;
> > > > +     char buf[BUFSIZ];
> > > > +     char *end = NULL;
> > > > +
> > > > +     f = fopen(filename, "r");
> > > > +     if (f == NULL) {
> > > > +             RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
> > > > +                     __func__, filename);
> > > > +             return -1;
> > > > +     }
> > > > +
> > > > +     if (fgets(buf, sizeof(buf), f) == NULL) {
> > > > +             RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
> > > > +                     __func__, filename);
> > > > +             fclose(f);
> > > > +             return -1;
> > > > +     }
> > > > +     *val = strtoul(buf, &end, 0);
> > > > +     if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
> > > > +             RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value
> %s\n",
> > > > +                             __func__, filename);
> > > > +             fclose(f);
> > > > +             return -1;
> > > > +     }
> > > > +     fclose(f);
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +
> > > > +/* create memory configuration in shared/mmap memory. Take out
> > > > + * a write lock on the memsegs, so we can auto-detect
> primary/secondary.
> > > > + * This means we never close the file while running (auto-close on
> > > exit).
> > > > + * We also don't lock the whole file, so that in future we can use
> > > read-locks
> > > > + * on other parts, e.g. memzones, to detect if there are running
> > > secondary
> > > > + * processes. */
> > > > +static void
> > > > +rte_eal_config_create(void)
> > > > +{
> > > > +     void *rte_mem_cfg_addr;
> > > > +     int retval;
> > > > +
> > > > +     const char *pathname = eal_runtime_config_path();
> > > > +
> > > > +     if (internal_config.no_shconf)
> > > > +             return;
> > > > +
> > > > +     rte_mem_cfg_addr = rte_eal_get_mem_cfg_addr();
> > > > +
> > > > +     if (mem_cfg_fd < 0) {
> > > > +             mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
> > > > +             if (mem_cfg_fd < 0)
> > > > +                     rte_panic("Cannot open '%s' for
> rte_mem_config\n",
> > > > +                                     pathname);
> > > > +     }
> > > > +
> > > > +     retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
> > > > +     if (retval < 0) {
> > > > +             close(mem_cfg_fd);
> > > > +             rte_panic("Cannot resize '%s' for rte_mem_config\n",
> > > pathname);
> > > > +     }
> > > > +
> > > > +     retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
> > > > +     if (retval < 0) {
> > > > +             close(mem_cfg_fd);
> > > > +             rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. "
> > > > +                     "Is another primary process running?\n",
> pathname);
> > > > +     }
> > > > +
> > > > +     rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
> > > > +                     sizeof(*rte_config.mem_config), PROT_READ |
> > > PROT_WRITE,
> > > > +                     MAP_SHARED, mem_cfg_fd, 0);
> > > > +
> > > > +     if (rte_mem_cfg_addr == MAP_FAILED)
> > > > +             rte_panic("Cannot mmap memory for rte_config\n");
> > > > +
> > > > +     memcpy(rte_mem_cfg_addr, &early_mem_config,
> > > sizeof(early_mem_config));
> > > > +     rte_config.mem_config = (struct rte_mem_config *)
> rte_mem_cfg_addr;
> > > > +
> > > > +#ifndef RTE_EXEC_ENV_BSDAPP
> > > > +     /* store address of the config in the config itself so that
> > > secondary
> > > > +      * processes could later map the config into this exact
> location
> > > > +      */
> > > > +     rte_config.mem_config->mem_cfg_addr = (uintptr_t)
> rte_mem_cfg_addr;
> > > > +#endif /* RTE_EXEC_ENV_BSDAPP */
> > > Why is this a BSD/Linux Differentiator?
> > >
> >
> > <rk> Existing code where assignment is not present in BSD code hence the
> > differentiation.
> >
> I presume then that the BSD code doesn't use mem_cfg_addr at all?  If so,
> why
> not just assign it unilaterally and avoid the ifdeffery?
> Neil
>
>
<rk> Looking into the code my understanding it's not being used. I will
assign it unilaterally.


> > > Neil
> > >
> > >
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
                   ` (6 preceding siblings ...)
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 7/7] " Ravi Kerur
@ 2014-12-29  8:47 ` Olivier MATZ
  2014-12-29 12:47   ` Neil Horman
  7 siblings, 1 reply; 41+ messages in thread
From: Olivier MATZ @ 2014-12-29  8:47 UTC (permalink / raw)
  To: Ravi Kerur, dev

Hi Ravi,

On 12/25/2014 04:33 PM, Ravi Kerur wrote:
> Common functions in linuxapp and bsdapp are moved into
> librte_eal/common directory.
> New files added follow _common_ naming conventions.
> Tested against ubuntu and FreeBSD.

Trying to factorize the common code goes in the good direction.

However I'm wondering if "common" is the proper place. Initially,
the common directory was for code common to linuxapp and baremetal.
Now that baremetal does not exist anymore, a lot of code is common
to the 2 OSes that are supported (linux and FreeBSD).

What about moving this code in "common-posix" instead?
It would let the door open for future ports (Windows? or any
other real time OS? Or back in baremetal?).

Regards,
Olivier

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-29  8:47 ` [dpdk-dev] [PATCH 0/7] " Olivier MATZ
@ 2014-12-29 12:47   ` Neil Horman
  2014-12-29 13:16     ` Olivier MATZ
  0 siblings, 1 reply; 41+ messages in thread
From: Neil Horman @ 2014-12-29 12:47 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
> Hi Ravi,
> 
> On 12/25/2014 04:33 PM, Ravi Kerur wrote:
> > Common functions in linuxapp and bsdapp are moved into
> > librte_eal/common directory.
> > New files added follow _common_ naming conventions.
> > Tested against ubuntu and FreeBSD.
> 
> Trying to factorize the common code goes in the good direction.
> 
> However I'm wondering if "common" is the proper place. Initially,
> the common directory was for code common to linuxapp and baremetal.
> Now that baremetal does not exist anymore, a lot of code is common
> to the 2 OSes that are supported (linux and FreeBSD).
> 
> What about moving this code in "common-posix" instead?
> It would let the door open for future ports (Windows? or any
> other real time OS? Or back in baremetal?).
> 
Posix doesn't make sense IMO, in that a large segment of the functions embodied
in the common directory have nothing to do with posix API's, and are simply just
useful functions that have not OS specific dependency (the entire
eal_common_memory.c file for example, to name just one).  

If you wanted to rename the directory, I would say generic-os would be more
appropriate.

Neil

> Regards,
> Olivier
> 

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-29 12:47   ` Neil Horman
@ 2014-12-29 13:16     ` Olivier MATZ
  2014-12-29 16:17       ` Neil Horman
  2014-12-29 18:43       ` Ravi Kerur
  0 siblings, 2 replies; 41+ messages in thread
From: Olivier MATZ @ 2014-12-29 13:16 UTC (permalink / raw)
  To: Neil Horman; +Cc: dev

Hi Neil,

On 12/29/2014 01:47 PM, Neil Horman wrote:
> On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
>> Trying to factorize the common code goes in the good direction.
>>
>> However I'm wondering if "common" is the proper place. Initially,
>> the common directory was for code common to linuxapp and baremetal.
>> Now that baremetal does not exist anymore, a lot of code is common
>> to the 2 OSes that are supported (linux and FreeBSD).
>>
>> What about moving this code in "common-posix" instead?
>> It would let the door open for future ports (Windows? or any
>> other real time OS? Or back in baremetal?).
>>
> Posix doesn't make sense IMO, in that a large segment of the functions embodied
> in the common directory have nothing to do with posix API's, and are simply just
> useful functions that have not OS specific dependency (the entire
> eal_common_memory.c file for example, to name just one).  
> 
> If you wanted to rename the directory, I would say generic-os would be more
> appropriate.

That's probably right for most of the code in the patch. I just wanted
to point out that "common" is sometimes a bit vague (common to archs,
common to OSes, common to all).

>From a quick look, these 2 files could be concerned and could go to a
common-posix directory:
- eal.c (use fopen/ftruncate/fcntl/mmap/...)
- eal_thread.c (use pipe/read/write)

There's no urgency to do that now and maybe we should wait it's really
needed. I was just seizing the opportunity as the code is moved.

Regards,
Olivier

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-29 13:16     ` Olivier MATZ
@ 2014-12-29 16:17       ` Neil Horman
  2014-12-29 18:43       ` Ravi Kerur
  1 sibling, 0 replies; 41+ messages in thread
From: Neil Horman @ 2014-12-29 16:17 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

On Mon, Dec 29, 2014 at 02:16:16PM +0100, Olivier MATZ wrote:
> Hi Neil,
> 
> On 12/29/2014 01:47 PM, Neil Horman wrote:
> > On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
> >> Trying to factorize the common code goes in the good direction.
> >>
> >> However I'm wondering if "common" is the proper place. Initially,
> >> the common directory was for code common to linuxapp and baremetal.
> >> Now that baremetal does not exist anymore, a lot of code is common
> >> to the 2 OSes that are supported (linux and FreeBSD).
> >>
> >> What about moving this code in "common-posix" instead?
> >> It would let the door open for future ports (Windows? or any
> >> other real time OS? Or back in baremetal?).
> >>
> > Posix doesn't make sense IMO, in that a large segment of the functions embodied
> > in the common directory have nothing to do with posix API's, and are simply just
> > useful functions that have not OS specific dependency (the entire
> > eal_common_memory.c file for example, to name just one).  
> > 
> > If you wanted to rename the directory, I would say generic-os would be more
> > appropriate.
> 
> That's probably right for most of the code in the patch. I just wanted
> to point out that "common" is sometimes a bit vague (common to archs,
> common to OSes, common to all).
> 
Agreed, common isn't explicitly common to everything
> From a quick look, these 2 files could be concerned and could go to a
> common-posix directory:
> - eal.c (use fopen/ftruncate/fcntl/mmap/...)
> - eal_thread.c (use pipe/read/write)
> 
Thats what they use, sure, but they don't export any POSIX mapped API, nor are
they guaranteed to only use POSIX library calls in the future (e.g. eal.c
exports functions like eal_parse_sysfs_value, which is completely unrelated to
POSIX, and may be implemented using zzip_file_read, though I wouldn't recommend
it :)).  Point being naming the directory common-posix, is not a descriptor of
either its exported API, nor a guarantee of its internal implementation.  I
would be more comfortable with something that is descriptive of the fact that
this code exports an API that is common to all operating systems (something like
generic-eal).  If the implementation of a given function in common isn't
supported on a newly added operating system, then we need to either remove the
function from the common directory and do specific implementations of it for
each os, or develop an override mechanism (something like marking the common
function as weak, and implementing an override version in any OS that doesn't
support its implementation.

> There's no urgency to do that now and maybe we should wait it's really
> needed. I was just seizing the opportunity as the code is moved.
> 
No, no urgency, but its been my experience that this sort of work doesn't get
done unless theres a motivator to make it so.  We have a contributor here that
is willing to do the work, so this seems like an opportune time to suggest stuff
like this.  If he doesn't want to do it, so be it, this collapsing is definately
better that what is there now, but if he's willing, I think this would be
another great step forward.
Neil

> Regards,
> Olivier
> 

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-29 13:16     ` Olivier MATZ
  2014-12-29 16:17       ` Neil Horman
@ 2014-12-29 18:43       ` Ravi Kerur
  2015-01-04 23:10         ` Ravi Kerur
  1 sibling, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2014-12-29 18:43 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

Thanks Olivier and Neil. I will make a note on this and will work on it
after initial common code movement is completed.

On Mon, Dec 29, 2014 at 5:16 AM, Olivier MATZ <olivier.matz@6wind.com>
wrote:

> Hi Neil,
>
> On 12/29/2014 01:47 PM, Neil Horman wrote:
> > On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
> >> Trying to factorize the common code goes in the good direction.
> >>
> >> However I'm wondering if "common" is the proper place. Initially,
> >> the common directory was for code common to linuxapp and baremetal.
> >> Now that baremetal does not exist anymore, a lot of code is common
> >> to the 2 OSes that are supported (linux and FreeBSD).
> >>
> >> What about moving this code in "common-posix" instead?
> >> It would let the door open for future ports (Windows? or any
> >> other real time OS? Or back in baremetal?).
> >>
> > Posix doesn't make sense IMO, in that a large segment of the functions
> embodied
> > in the common directory have nothing to do with posix API's, and are
> simply just
> > useful functions that have not OS specific dependency (the entire
> > eal_common_memory.c file for example, to name just one).
> >
> > If you wanted to rename the directory, I would say generic-os would be
> more
> > appropriate.
>
> That's probably right for most of the code in the patch. I just wanted
> to point out that "common" is sometimes a bit vague (common to archs,
> common to OSes, common to all).
>
> From a quick look, these 2 files could be concerned and could go to a
> common-posix directory:
> - eal.c (use fopen/ftruncate/fcntl/mmap/...)
> - eal_thread.c (use pipe/read/write)
>
> There's no urgency to do that now and maybe we should wait it's really
> needed. I was just seizing the opportunity as the code is moved.
>
> Regards,
> Olivier
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2014-12-29 18:43       ` Ravi Kerur
@ 2015-01-04 23:10         ` Ravi Kerur
  2015-01-05 12:24           ` Bruce Richardson
  0 siblings, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2015-01-04 23:10 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

Hi,

I plan to work on this and would like to know if I need consider anything
else other than mentioned in the email by Olivier/Neil i.e.go with 2
directories

common-os/generic-os
common-posix

under librte_eal directory and move relevant files accordingly.

Thanks,
Ravi

On Mon, Dec 29, 2014 at 10:43 AM, Ravi Kerur <rkerur@gmail.com> wrote:

> Thanks Olivier and Neil. I will make a note on this and will work on it
> after initial common code movement is completed.
>
>
> On Mon, Dec 29, 2014 at 5:16 AM, Olivier MATZ <olivier.matz@6wind.com>
> wrote:
>
>> Hi Neil,
>>
>> On 12/29/2014 01:47 PM, Neil Horman wrote:
>> > On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
>> >> Trying to factorize the common code goes in the good direction.
>> >>
>> >> However I'm wondering if "common" is the proper place. Initially,
>> >> the common directory was for code common to linuxapp and baremetal.
>> >> Now that baremetal does not exist anymore, a lot of code is common
>> >> to the 2 OSes that are supported (linux and FreeBSD).
>> >>
>> >> What about moving this code in "common-posix" instead?
>> >> It would let the door open for future ports (Windows? or any
>> >> other real time OS? Or back in baremetal?).
>> >>
>> > Posix doesn't make sense IMO, in that a large segment of the functions
>> embodied
>> > in the common directory have nothing to do with posix API's, and are
>> simply just
>> > useful functions that have not OS specific dependency (the entire
>> > eal_common_memory.c file for example, to name just one).
>> >
>> > If you wanted to rename the directory, I would say generic-os would be
>> more
>> > appropriate.
>>
>> That's probably right for most of the code in the patch. I just wanted
>> to point out that "common" is sometimes a bit vague (common to archs,
>> common to OSes, common to all).
>>
>> From a quick look, these 2 files could be concerned and could go to a
>> common-posix directory:
>> - eal.c (use fopen/ftruncate/fcntl/mmap/...)
>> - eal_thread.c (use pipe/read/write)
>>
>> There's no urgency to do that now and maybe we should wait it's really
>> needed. I was just seizing the opportunity as the code is moved.
>>
>> Regards,
>> Olivier
>>
>
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 2/7] Move EAL common functions
  2014-12-26 15:28         ` Ravi Kerur
@ 2015-01-05  9:40           ` Thomas Monjalon
  0 siblings, 0 replies; 41+ messages in thread
From: Thomas Monjalon @ 2015-01-05  9:40 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2014-12-26 07:28, Ravi Kerur:
> On Fri, Dec 26, 2014 at 6:40 AM, Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> > On Thu, Dec 25, 2014 at 11:23:12AM -0800, Ravi Kerur wrote:
> > > Thanks Neil for reviews. Inline <rk>
> > >
> > > On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <nhorman@tuxdriver.com>
> > wrote:
> > >
> > > > On Thu, Dec 25, 2014 at 10:33:12AM -0500, Ravi Kerur wrote:
> > > > > eal_debug.c has no difference between Linux and BSD, move
> > > > > into common directory.
> > > > > Rename eal_debug.c to eal_common_debug.c
> > > > > Makefile changes to reflect file move and name change.
> > > > > Fix checkpatch warnings.
> > > > >
> > > > > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > > > > +
> > > > > +/* not implemented in this environment */
> > > > > +void rte_dump_registers(void)
> > > > > +{
> > > > > +}
> > > > Clearly this function has no use, instead of keeping it around, can you
> > > > please
> > > > remove it until someone works up the gumption to make it do something.
> > > > We're
> > > > just wasting an extra call instruction here so someone doesn't have to
> > > > write a
> > > > prototype in the future.  I don't see the value.
> > > >
> > >
> > > <rk> This is existing code, I just removed "return" statement as per
> > > checkpatch. Should I make it "inline" and add a comment indicating to
> > > revisit whether to make it inline/no inline when the function is
> > > implemented?
> > >
> > I understand its existing code, I'm saying that, while you're moving it
> > around,
> > clean it up.  Don't make it inline, just remove it, since it does
> > nothing.  If
> > you feel its important to keep around, I suppose you can make it inline,
> > but I
> > don't really think its needed at all.
> >
> > Neil
> >
> >
> <rk> Sure will remove it.

Please remove it in a separate patch (before this one).

> > > > > +/*
> > > > > + * Like rte_panic this terminates the application. However, no
> > > > traceback is
> > > > > + * provided and no core-dump is generated.
> > > > > + */
> > > > > +void
> > > > > +rte_exit(int exit_code, const char *format, ...)
> > > > > +{
> > > > > +     va_list ap;
> > > > > +
> > > > > +     /* disable history */
> > > > > +     rte_log_set_history(0);
> > > > > +
> > > > > +     if (exit_code != 0)
> > > > > +             RTE_LOG(CRIT, EAL, "Error - exiting with code: %d\n"
> > > > > +                             "  Cause: ", exit_code);
> > > > > +
> > > > > +     va_start(ap, format);
> > > > > +     rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
> > > > > +     va_end(ap);
> > > > > +
> > > > > +#ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> > > > > +     exit(exit_code);
> > > > > +#else
> > > > > +     rte_dump_stack();
> > > > > +     rte_dump_registers();
> > > > > +     abort();
> > > > > +#endif
> > > > This doesn't match with the commentary above.  If rte_exit isn't meant
> > to
> > > > provide a traceback, it shouldn't do so.  If an application wants that
> > to
> > > > happen, then they need to use rte_panic.
> > > >
> > > > <rk> This is again existing code. I can change the comment which
> > matches
> > > the function, will it work?

Please do not change anything (except perhaps code style) when moving code.
If RTE_EAL_ALWAYS_PANIC_ON_ERROR must be removed (to discuss), it should be
done in another patchset.

Thanks
-- 
Thomas

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2015-01-04 23:10         ` Ravi Kerur
@ 2015-01-05 12:24           ` Bruce Richardson
  2015-01-09  9:50             ` Olivier MATZ
  0 siblings, 1 reply; 41+ messages in thread
From: Bruce Richardson @ 2015-01-05 12:24 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

On Sun, Jan 04, 2015 at 03:10:46PM -0800, Ravi Kerur wrote:
> Hi,
> 
> I plan to work on this and would like to know if I need consider anything
> else other than mentioned in the email by Olivier/Neil i.e.go with 2
> directories
> 
> common-os/generic-os
> common-posix
> 
> under librte_eal directory and move relevant files accordingly.
> 
> Thanks,
> Ravi
> 

Hopefully that means two directories, not three. I think the existing common
folder should stay as it is, with the same name, and possibly add one new folder
for code that is common between BSD and Linux, but which would not be common
to other non-unix environments. I would be in favour of "common-posix" or
"common-unix" for such a folder name, if one is created. In the absense of
any other supported OS (or baremetal), I wonder as to the value of creating
such a separation at this point?

/Bruce

> On Mon, Dec 29, 2014 at 10:43 AM, Ravi Kerur <rkerur@gmail.com> wrote:
> 
> > Thanks Olivier and Neil. I will make a note on this and will work on it
> > after initial common code movement is completed.
> >
> >
> > On Mon, Dec 29, 2014 at 5:16 AM, Olivier MATZ <olivier.matz@6wind.com>
> > wrote:
> >
> >> Hi Neil,
> >>
> >> On 12/29/2014 01:47 PM, Neil Horman wrote:
> >> > On Mon, Dec 29, 2014 at 09:47:05AM +0100, Olivier MATZ wrote:
> >> >> Trying to factorize the common code goes in the good direction.
> >> >>
> >> >> However I'm wondering if "common" is the proper place. Initially,
> >> >> the common directory was for code common to linuxapp and baremetal.
> >> >> Now that baremetal does not exist anymore, a lot of code is common
> >> >> to the 2 OSes that are supported (linux and FreeBSD).
> >> >>
> >> >> What about moving this code in "common-posix" instead?
> >> >> It would let the door open for future ports (Windows? or any
> >> >> other real time OS? Or back in baremetal?).
> >> >>
> >> > Posix doesn't make sense IMO, in that a large segment of the functions
> >> embodied
> >> > in the common directory have nothing to do with posix API's, and are
> >> simply just
> >> > useful functions that have not OS specific dependency (the entire
> >> > eal_common_memory.c file for example, to name just one).
> >> >
> >> > If you wanted to rename the directory, I would say generic-os would be
> >> more
> >> > appropriate.
> >>
> >> That's probably right for most of the code in the patch. I just wanted
> >> to point out that "common" is sometimes a bit vague (common to archs,
> >> common to OSes, common to all).
> >>
> >> From a quick look, these 2 files could be concerned and could go to a
> >> common-posix directory:
> >> - eal.c (use fopen/ftruncate/fcntl/mmap/...)
> >> - eal_thread.c (use pipe/read/write)
> >>
> >> There's no urgency to do that now and maybe we should wait it's really
> >> needed. I was just seizing the opportunity as the code is moved.
> >>
> >> Regards,
> >> Olivier
> >>
> >
> >

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 5/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 5/7] " Ravi Kerur
@ 2015-01-05 15:32   ` Thomas Monjalon
  0 siblings, 0 replies; 41+ messages in thread
From: Thomas Monjalon @ 2015-01-05 15:32 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2014-12-25 10:33, Ravi Kerur:
> +#ifdef RTE_EXEC_ENV_BSDAPP
> +		const unsigned ncpus = get_ncpus();
> +
> +		lcore_config[lcore_id].detected = (lcore_id < ncpus);
> +#else /* RTE_EXEC_ENV_BSDAPP */
> +		lcore_config[lcore_id].detected = cpu_detected(lcore_id);
> +#endif /* RTE_EXEC_ENV_BSDAPP */

It would be nice to remove this ifdef by implementing cpu_detected() for BSD.

> +#ifdef RTE_EXEC_ENV_BSDAPP
> +		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
> +				lcore_id);
> +#else /* RTE_EXEC_ENV_BSDAPP */
> +		RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
> +				"core %u on socket %u\n",
> +				lcore_id, lcore_config[lcore_id].core_id,
> +				lcore_config[lcore_id].socket_id);
> +#endif /* RTE_EXEC_ENV_BSDAPP */

I think we should keep only the (full) Linux version
and remove this ifdef.
It can be done in a subsequent patch in the serie.

Thanks
-- 
Thomas

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 6/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 6/7] " Ravi Kerur
@ 2015-01-05 15:49   ` Thomas Monjalon
  0 siblings, 0 replies; 41+ messages in thread
From: Thomas Monjalon @ 2015-01-05 15:49 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2014-12-25 10:33, Ravi Kerur:
> +#ifdef RTE_EXEC_ENV_BSDAPP
> +	if (set_tsc_freq_from_sysctl() < 0)
> +#else /* RTE_EXEC_ENV_BSDAPP */
> +	if (set_tsc_freq_from_clock() < 0)
> +#endif /* RTE_EXEC_ENV_BSDAPP */

In case there is only 1 line in ifdef, it's clearer to not
comment #else and #endif.

> --- a/lib/librte_eal/common/eal_externs.h
> +++ b/lib/librte_eal/common/eal_externs.h
> @@ -39,4 +39,7 @@ extern struct rte_config rte_config;
>  extern int mem_cfg_fd;
>  extern rte_usage_hook_t	rte_application_usage_hook;
>  
> +/* Extern declarations defined in eal_common_timer.c */
> +extern uint64_t eal_tsc_resolution_hz;
> +

Why is this extern needed?
It would be nicer to have functions returning resolution after probing.
Then it's stored in linuxapp or bsdapp and retrieved with the existing
function rte_get_tsc_hz().

Thanks
-- 
Thomas

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2014-12-25 15:33 ` [dpdk-dev] [PATCH 4/7] " Ravi Kerur
  2014-12-25 17:44   ` Neil Horman
@ 2015-01-05 15:59   ` Thomas Monjalon
  2015-01-05 16:21     ` Ravi Kerur
  2015-01-05 18:56     ` Ravi Kerur
  1 sibling, 2 replies; 41+ messages in thread
From: Thomas Monjalon @ 2015-01-05 15:59 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2014-12-25 10:33, Ravi Kerur:
> Move common functions in eal.c to librte_eal/common directory.
[...]
>  lib/librte_eal/common/eal_common.c    | 328 ++++++++++++++++++++++++++++++++++
>  lib/librte_eal/common/eal_externs.h   |  42 +++++

I don't agree with these new files.
We must try to keep a semantic organization. The file eal_common_options.c
would be better for option-related functions.
Maybe that the split between system config, runtime config and internal config
must be reworked.

By the way, it would be nice to avoid extern variables.

-- 
Thomas

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2015-01-05 15:59   ` Thomas Monjalon
@ 2015-01-05 16:21     ` Ravi Kerur
  2015-01-05 18:56     ` Ravi Kerur
  1 sibling, 0 replies; 41+ messages in thread
From: Ravi Kerur @ 2015-01-05 16:21 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

Thanks Thomas for the reviews, do you want me to send "v4" version of this
patch series or start a different patch series?

Thanks,
Ravi

On Mon, Jan 5, 2015 at 7:59 AM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2014-12-25 10:33, Ravi Kerur:
> > Move common functions in eal.c to librte_eal/common directory.
> [...]
> >  lib/librte_eal/common/eal_common.c    | 328
> ++++++++++++++++++++++++++++++++++
> >  lib/librte_eal/common/eal_externs.h   |  42 +++++
>
> I don't agree with these new files.
> We must try to keep a semantic organization. The file eal_common_options.c
> would be better for option-related functions.
> Maybe that the split between system config, runtime config and internal
> config
> must be reworked.
>
> By the way, it would be nice to avoid extern variables.
>
> --
> Thomas
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2015-01-05 15:59   ` Thomas Monjalon
  2015-01-05 16:21     ` Ravi Kerur
@ 2015-01-05 18:56     ` Ravi Kerur
  2015-01-05 20:38       ` Thomas Monjalon
  1 sibling, 1 reply; 41+ messages in thread
From: Ravi Kerur @ 2015-01-05 18:56 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

Inline <rk>

On Mon, Jan 5, 2015 at 7:59 AM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2014-12-25 10:33, Ravi Kerur:
> > Move common functions in eal.c to librte_eal/common directory.
> [...]
> >  lib/librte_eal/common/eal_common.c    | 328
> ++++++++++++++++++++++++++++++++++
> >  lib/librte_eal/common/eal_externs.h   |  42 +++++
>
> I don't agree with these new files.
> We must try to keep a semantic organization. The file eal_common_options.c
> would be better for option-related functions.
> Maybe that the split between system config, runtime config and internal
> config
> must be reworked.
>
> By the way, it would be nice to avoid extern variables.
>

<rk> I have taken care of your comments and will generate v4 patch.
Currently I have moved common functions in eal.c into
"eal_common_system_options.c" file. Are you suggesting that we further
divide "eal_common_options.c" and "eal_common_system_options.c(new file
added)" into 3 separate files i.e.

eal_common_system_options.c
eal_common_runtime_options.c
eal_common_internal_options.c

Thanks.


>
> --
> Thomas
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2015-01-05 18:56     ` Ravi Kerur
@ 2015-01-05 20:38       ` Thomas Monjalon
  2015-01-06 17:35         ` Ravi Kerur
  0 siblings, 1 reply; 41+ messages in thread
From: Thomas Monjalon @ 2015-01-05 20:38 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2015-01-05 10:56, Ravi Kerur:
> On Mon, Jan 5, 2015 at 7:59 AM, Thomas Monjalon <thomas.monjalon@6wind.com>
> wrote:
> > 2014-12-25 10:33, Ravi Kerur:
> > > Move common functions in eal.c to librte_eal/common directory.
> > [...]
> > >  lib/librte_eal/common/eal_common.c    | 328 ++++++++++++++++++++++++++++++++++
> > >  lib/librte_eal/common/eal_externs.h   |  42 +++++
> >
> > I don't agree with these new files.
> > We must try to keep a semantic organization. The file eal_common_options.c
> > would be better for option-related functions.
> > Maybe that the split between system config, runtime config and internal
> > config
> > must be reworked.
> >
> > By the way, it would be nice to avoid extern variables.
> 
> <rk> I have taken care of your comments and will generate v4 patch.

Please do not forget v4 word and changelog when sending patches.
Check http://dpdk.org/dev#send

> Currently I have moved common functions in eal.c into
> "eal_common_system_options.c" file. Are you suggesting that we further
> divide "eal_common_options.c" and "eal_common_system_options.c(new file
> added)" into 3 separate files i.e.
> 
> eal_common_system_options.c
> eal_common_runtime_options.c
> eal_common_internal_options.c

You are already doing big changes. So let's iterate with existing files and
avoid creating new ones.
eal_common_options.c must be kept. But if some code is not really related to
runtime options, we could consider adding a new file eal_common_config.c, not
sure about this one.

-- 
Thomas

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 4/7] Move EAL common functions
  2015-01-05 20:38       ` Thomas Monjalon
@ 2015-01-06 17:35         ` Ravi Kerur
  0 siblings, 0 replies; 41+ messages in thread
From: Ravi Kerur @ 2015-01-06 17:35 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev

Inline <rk>

On Mon, Jan 5, 2015 at 12:38 PM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> 2015-01-05 10:56, Ravi Kerur:
> > On Mon, Jan 5, 2015 at 7:59 AM, Thomas Monjalon <
> thomas.monjalon@6wind.com>
> > wrote:
> > > 2014-12-25 10:33, Ravi Kerur:
> > > > Move common functions in eal.c to librte_eal/common directory.
> > > [...]
> > > >  lib/librte_eal/common/eal_common.c    | 328
> ++++++++++++++++++++++++++++++++++
> > > >  lib/librte_eal/common/eal_externs.h   |  42 +++++
> > >
> > > I don't agree with these new files.
> > > We must try to keep a semantic organization. The file
> eal_common_options.c
> > > would be better for option-related functions.
> > > Maybe that the split between system config, runtime config and internal
> > > config
> > > must be reworked.
> > >
> > > By the way, it would be nice to avoid extern variables.
> >
> > <rk> I have taken care of your comments and will generate v4 patch.
>
> Please do not forget v4 word and changelog when sending patches.
> Check http://dpdk.org/dev#send
>
> > Currently I have moved common functions in eal.c into
> > "eal_common_system_options.c" file. Are you suggesting that we further
> > divide "eal_common_options.c" and "eal_common_system_options.c(new file
> > added)" into 3 separate files i.e.
> >
> > eal_common_system_options.c
> > eal_common_runtime_options.c
> > eal_common_internal_options.c
>
> You are already doing big changes. So let's iterate with existing files and
> avoid creating new ones.
> eal_common_options.c must be kept. But if some code is not really related
> to
> runtime options, we could consider adding a new file eal_common_config.c,
> not
> sure about this one.
>
> --
>

<rk> i have divided eal_common.c (new file which was added in v1 PATCH)
into eal_common_system.c and eal_common_runtime.c and have moved
appropriate functions into it. If file names are not appropriate or changes
are not worth doing the split, I will merge them back into
eal_common_config.c.

Thanks.

> Thomas
>

^ permalink raw reply	[flat|nested] 41+ messages in thread

* Re: [dpdk-dev] [PATCH 0/7] Move EAL common functions
  2015-01-05 12:24           ` Bruce Richardson
@ 2015-01-09  9:50             ` Olivier MATZ
  0 siblings, 0 replies; 41+ messages in thread
From: Olivier MATZ @ 2015-01-09  9:50 UTC (permalink / raw)
  To: Bruce Richardson, Ravi Kerur; +Cc: dev

Hi,

Sorry for the late answer.

On 01/05/2015 01:24 PM, Bruce Richardson wrote:
> Hopefully that means two directories, not three. I think the existing common
> folder should stay as it is, with the same name, and possibly add one new folder
> for code that is common between BSD and Linux, but which would not be common
> to other non-unix environments. I would be in favour of "common-posix" or
> "common-unix" for such a folder name, if one is created. In the absense of
> any other supported OS (or baremetal), I wonder as to the value of creating
> such a separation at this point?

The idea of common-posix (or common-unix) was a way to identify which
code use the posix API, in the same logic than "common-x86". It would
help when porting on other environment.

But after thinking more about it, you are right, there is probably no
real advantage yet and, as we only support unix environment, we cannot
check that the separation would be correct.

Regards,
Olivier

^ permalink raw reply	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2015-01-09  9:50 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-25 15:33 [dpdk-dev] [PATCH 0/7] Move EAL common functions Ravi Kerur
2014-12-25 15:33 ` [dpdk-dev] [PATCH 1/7] Fix rte_is_power_of_2 Ravi Kerur
2014-12-25 17:21   ` Neil Horman
2014-12-25 18:54     ` Ravi Kerur
2014-12-25 15:33 ` [dpdk-dev] [PATCH 2/7] Move EAL common functions Ravi Kerur
2014-12-25 17:30   ` Neil Horman
2014-12-25 19:23     ` Ravi Kerur
2014-12-26 14:40       ` Neil Horman
2014-12-26 15:28         ` Ravi Kerur
2015-01-05  9:40           ` Thomas Monjalon
2014-12-25 15:33 ` [dpdk-dev] [PATCH 3/7] " Ravi Kerur
2014-12-25 17:41   ` Neil Horman
2014-12-25 19:13     ` Ravi Kerur
2014-12-26 14:40       ` Neil Horman
2014-12-25 15:33 ` [dpdk-dev] [PATCH 4/7] " Ravi Kerur
2014-12-25 17:44   ` Neil Horman
2014-12-25 19:17     ` Ravi Kerur
2014-12-26 14:42       ` Neil Horman
2014-12-26 15:30         ` Ravi Kerur
2015-01-05 15:59   ` Thomas Monjalon
2015-01-05 16:21     ` Ravi Kerur
2015-01-05 18:56     ` Ravi Kerur
2015-01-05 20:38       ` Thomas Monjalon
2015-01-06 17:35         ` Ravi Kerur
2014-12-25 15:33 ` [dpdk-dev] [PATCH 5/7] " Ravi Kerur
2015-01-05 15:32   ` Thomas Monjalon
2014-12-25 15:33 ` [dpdk-dev] [PATCH 6/7] " Ravi Kerur
2015-01-05 15:49   ` Thomas Monjalon
2014-12-25 15:33 ` [dpdk-dev] [PATCH 7/7] " Ravi Kerur
2014-12-25 17:46   ` Neil Horman
2014-12-25 19:22     ` Ravi Kerur
2014-12-26 14:44       ` Neil Horman
2014-12-26 15:28         ` Ravi Kerur
2014-12-29  8:47 ` [dpdk-dev] [PATCH 0/7] " Olivier MATZ
2014-12-29 12:47   ` Neil Horman
2014-12-29 13:16     ` Olivier MATZ
2014-12-29 16:17       ` Neil Horman
2014-12-29 18:43       ` Ravi Kerur
2015-01-04 23:10         ` Ravi Kerur
2015-01-05 12:24           ` Bruce Richardson
2015-01-09  9:50             ` Olivier MATZ

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git