Skip to contentSkip to conversation

Move EAL common functions

PATCH Superseded Ravi Kerur 5 participants 41 messages Dec 25, 2014 – Jan 9, 2015 27 messages not in the archive

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Ravi Kerur

author
#0 lore raw

cover Move EAL common functions

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
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH 1/7 Fix rte_is_power_of_2

In reply to a message not in the archive

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

---
 lib/librte_eal/common/include/rte_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/include/rte_common.h +1 -1
index 921b91f..8ac940c 100644
@@ -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));
 }
 
 /**
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH 2/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +1 -1
index d434882..9b83e11 100644
@@ -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
lib/librte_eal/bsdapp/eal/eal_debug.c deleted +0 -113

113 lines not on this page · raw message

lib/librte_eal/common/eal_common_debug.c new file +112 -0

112 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -1
index 72ecf3a..87b9bfc 100644
@@ -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
lib/librte_eal/linuxapp/eal/eal_debug.c deleted +0 -113

113 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#18 lore raw

PATCH 3/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +3 -3
index 9b83e11..92dd9a6 100644
@@ -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
 
lib/librte_eal/bsdapp/eal/eal_thread.c deleted +0 -233

233 lines not on this page · raw message

lib/librte_eal/common/eal_common_thread.c new file +248 -0

248 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +3 -3
index 87b9bfc..9252333 100644
@@ -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
lib/librte_eal/linuxapp/eal/eal_thread.c deleted +0 -233

233 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#25 lore raw

PATCH 4/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 92dd9a6..050d70b 100644
@@ -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
lib/librte_eal/bsdapp/eal/eal.c +9 -224

281 lines not on this page · raw message

lib/librte_eal/common/eal_common.c new file +328 -0

328 lines not on this page · raw message

lib/librte_eal/common/eal_externs.h new file +42 -0

42 lines not on this page · raw message

lib/librte_eal/common/eal_hugepages.h +1 -0
index 38edac0..0b4d7a2 100644
@@ -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 */
lib/librte_eal/common/eal_private.h +47 -0

51 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 9252333..60cc448 100644
@@ -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
lib/librte_eal/linuxapp/eal/eal.c +10 -236

318 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#40 lore raw

PATCH 5/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 050d70b..560b7a3 100644
@@ -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
lib/librte_eal/bsdapp/eal/eal_lcore.c +12 -50

72 lines not on this page · raw message

lib/librte_eal/common/eal_common_lcore.c new file +106 -0

106 lines not on this page · raw message

lib/librte_eal/common/eal_private.h +32 -0
index b1d68bc..9fe91b3 100644
@@ -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_ */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 60cc448..ff185fd 100644
@@ -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
lib/librte_eal/linuxapp/eal/eal_lcore.c +3 -52

76 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#43 lore raw

PATCH 6/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 560b7a3..fb1faa3 100644
@@ -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
lib/librte_eal/bsdapp/eal/eal_timer.c +2 -48

68 lines not on this page · raw message

lib/librte_eal/common/eal_common_timer.c new file +99 -0

99 lines not on this page · raw message

lib/librte_eal/common/eal_externs.h +3 -0
index b19bea6..124ab65 100644
@@ -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
lib/librte_eal/common/eal_private.h +21 -0
index 9fe91b3..19af23d 100644
@@ -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_ */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index ff185fd..2404423 100644
@@ -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
lib/librte_eal/linuxapp/eal/eal_timer.c +2 -50

79 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#46 lore raw

PATCH 7/7 Move EAL common functions

In reply to a message not in the archive

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.

---
 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(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +2 -34
index 65ee87d..b192705 100644
@@ -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;
-}
lib/librte_eal/common/eal_common_memory.c +41 -2

64 lines not on this page · raw message

lib/librte_eal/common/eal_private.h +28 -0
index 19af23d..16338a2 100644
@@ -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_ */
lib/librte_eal/linuxapp/eal/eal_memory.c +2 -34
index bae2507..f4d91df 100644
@@ -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;
-}
Signature · 1 line
1.9.1
#4 lore raw

Re: [PATCH 1/7] Fix rte_is_power_of_2

In reply to a message not in the archive
Quoted 25 lines · Ravi Kerur

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

---
 lib/librte_eal/common/include/rte_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/common/include/rte_common.h +1 -1
index 921b91f..8ac940c 100644
@@ -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));
 }
 
 /**
Signature · 1 line
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

#9 lore raw
In reply to a message not in the archive

lib/librte_eal/common/eal_common_debug.c line 66

Quoted 12 lines · Ravi Kerur

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.

lib/librte_eal/common/eal_common_debug.c new file +5 -0
+
+/* 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.

Quoted 17 lines
lib/librte_eal/common/eal_common_debug.c new file +17 -0
+/*
+ * 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);

lib/librte_eal/common/eal_common_debug.c line 111

Quoted 10 lines
lib/librte_eal/common/eal_common_debug.c new file +10 -0
+	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.

#20 lore raw
In reply to a message not in the archive
Quoted 7 lines · Ravi Kerur

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

#27 lore raw
In reply to a message not in the archive
Quoted 520 lines · Ravi Kerur

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.

---
 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
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 92dd9a6..050d70b 100644
@@ -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
lib/librte_eal/bsdapp/eal/eal.c +9 -224
index 69f3c03..f925da7 100644
@@ -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);
-}
-
lib/librte_eal/common/eal_common.c new file +190 -0
new file mode 100644
index 0000000..becf9c8
@@ -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");

lib/librte_eal/common/eal_common.c line 200

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+
+	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

#48 lore raw
In reply to a message not in the archive
Quoted 125 lines · Ravi Kerur

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.

---
 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(-)
lib/librte_eal/bsdapp/eal/eal_memory.c +2 -34
index 65ee87d..b192705 100644
@@ -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;
-}
lib/librte_eal/common/eal_common_memory.c +22 -2
index 77830f8..da7aa98 100644
@@ -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)

lib/librte_eal/common/eal_common_memory.c unsigned rte_memory_get_nrank(void) · line 151

Quoted 10 lines
lib/librte_eal/common/eal_common_memory.c +10 -0
+{
+	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

Quoted 117 lines
lib/librte_eal/common/eal_common_memory.c +9 -0
+
+	if (retval < 0)
+		return -1;
+
+	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
+		return -1;
+
+	return 0;
+}
lib/librte_eal/common/eal_private.h +28 -0
index 19af23d..16338a2 100644
@@ -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_ */
lib/librte_eal/linuxapp/eal/eal_memory.c +2 -34
index bae2507..f4d91df 100644
@@ -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;
-}
Signature · 1 line
1.9.1
author
#6 lore raw

Re: [PATCH 1/7] Fix rte_is_power_of_2

In reply to a message not in the archive

Sure, will post it separately.

Thanks.

Quoted 37 lines · Neil Horman

Review

Quoted 9 lines · Ravi Kerur

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

---
 lib/librte_eal/common/include/rte_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_eal/common/include/rte_common.h

Quoted 13 lines

index 921b91f..8ac940c 100644

lib/librte_eal/common/include/rte_common.h +1 -2
@@ -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));
 }
 
 /**
--
Quoted 3 lines

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

author
#22 lore raw
In reply to a message not in the archive

Inline <rk>

Quoted 10 lines · Neil Horman
Quoted 7 lines · Ravi Kerur

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.

Quoted 4 lines

Neil

author
#29 lore raw
In reply to a message not in the archive

Inline <rk>

Quoted 565 lines · Neil Horman
Quoted 11 lines · Ravi Kerur

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.

---
 lib/librte_eal/bsdapp/eal/Makefile    |   1 +
 lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
 lib/librte_eal/common/eal_common.c    | 328

++++++++++++++++++++++++++++++++++

Review

Quoted 10 lines
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/Makefile

lib/librte_eal/bsdapp/eal/Makefile SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

Quoted 4 lines

index 92dd9a6..050d70b 100644

lib/librte_eal/bsdapp/eal/Makefile +0 -0
@@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

eal_interrupts.c

Review

Quoted 8 lines
lib/librte_eal/bsdapp/eal/Makefile +1 -0
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal.c

Quoted 8 lines

index 69f3c03..f925da7 100644

lib/librte_eal/bsdapp/eal/eal.c +1 -0
@@ -80,30 +80,10 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_externs.h"

lib/librte_eal/bsdapp/eal/eal.c line 92

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
 
 #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 */

Quoted 55 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -45
-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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 157

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -10
-             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).

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 158

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 159

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
- * processes. */
-static void
-rte_eal_config_create(void)
-{
-     void *rte_mem_cfg_addr;
-     int retval;

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -10
-
-     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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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 "

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-                             "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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-
-     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));

Quoted 15 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -3
-     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 */

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 233

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +3 -6
-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

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 235

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -2
-      * 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 */

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void)

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     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");

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void)

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -4
-     return ptype;
-}
-
-/* Sets up rte_config structure with the pointer to shared memory

config.*/

Quoted 21 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -17
-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 */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 285

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -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. */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 286

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-     old_func                                        =

rte_application_usage_hook;

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname)

Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -13
-     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];

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname)

Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
-             if (hpi->hugedir != NULL) {
-                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-                             size += hpi->hugepage_sz *

hpi->num_pages[j];

Review

Quoted 83 lines
lib/librte_eal/bsdapp/eal/eal.c +1 -60
-                     }
-             }
-     }
-
-     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);
-}
-
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common.c

Quoted 9 lines

new file mode 100644
index 0000000..becf9c8

lib/librte_eal/common/eal_common.c new file +4 -0
@@ -0,0 +1,328 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.

lib/librte_eal/common/eal_common.c line 14

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+ *   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

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+ *       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

lib/librte_eal/common/eal_common.c line 25

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

COPYRIGHT

lib/librte_eal/common/eal_common.c line 26

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

lib/librte_eal/common/eal_common.c line 28

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

USE,

lib/librte_eal/common/eal_common.c line 29

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

ANY

lib/librte_eal/common/eal_common.c line 31

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE

USE

lib/librte_eal/common/eal_common.c line 32

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 46 lines
lib/librte_eal/common/eal_common.c new file +46 -0
+ */
+
+#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"

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+#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 */

Quoted 50 lines
lib/librte_eal/common/eal_common.c new file +50 -0
+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);

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+             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).

lib/librte_eal/common/eal_common.c line 149

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/common/eal_common.c line 150

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 15 lines
lib/librte_eal/common/eal_common.c new file +15 -0
+ * 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) {

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -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);

lib/librte_eal/common/eal_common.c

Quoted 11 lines
lib/librte_eal/common/eal_common.c new file +11 -0
+     }
+
+     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,

lib/librte_eal/common/eal_common.c

Quoted 6 lines
lib/librte_eal/common/eal_common.c new file +6 -0
+                     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));

lib/librte_eal/common/eal_common.c

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+     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

Quoted 6 lines

lib/librte_eal/common/eal_common.c line 200

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+      * 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.

Quoted 3 lines

Neil

author
#50 lore raw
In reply to a message not in the archive

Inline <rk>

Quoted 139 lines · Neil Horman
Quoted 9 lines · Ravi Kerur

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.

---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 36

++------------------------

Quoted 1 line
 lib/librte_eal/common/eal_common_memory.c | 43

+++++++++++++++++++++++++++++--

Quoted 2 lines
 lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 36

++------------------------

Review

Quoted 3 lines
 4 files changed, 73 insertions(+), 70 deletions(-)
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal_memory.c

Review

Quoted 58 lines

index 65ee87d..b192705 100644

lib/librte_eal/bsdapp/eal/eal_memory.c +2 -34
@@ -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;
-}
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_memory.c

Quoted 60 lines

index 77830f8..da7aa98 100644

lib/librte_eal/common/eal_common_memory.c +30 -2
@@ -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() :
Quoted 10 lines

lib/librte_eal/common/eal_common_memory.c unsigned rte_memory_get_nrank(void) · line 151

Quoted 2 lines
lib/librte_eal/common/eal_common_memory.c +2 -0
+                     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.

Quoted 124 lines

Neil

Review

Quoted 10 lines
lib/librte_eal/common/eal_common_memory.c +9 -0
+
+     if (retval < 0)
+             return -1;
+
+     if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
+             return -1;
+
+     return 0;
+}
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_private.h

Review

Quoted 46 lines

index 19af23d..16338a2 100644

lib/librte_eal/common/eal_private.h +28 -0
@@ -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_ */
(quoted diff) +0 -0

b/lib/librte_eal/linuxapp/eal/eal_memory.c

Quoted 13 lines

index bae2507..f4d91df 100644

lib/librte_eal/linuxapp/eal/eal_memory.c +1 -1
@@ -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;

lib/librte_eal/linuxapp/eal/eal_memory.c getFileSize(int fd) · line 1369

Quoted 1 line
lib/librte_eal/linuxapp/eal/eal_memory.c +0 -0
@@ -1369,7 +1369,7 @@ getFileSize(int fd)
  * configuration and finds the hugepages which form that segment,

mapping them

lib/librte_eal/linuxapp/eal/eal_memory.c getFileSize(int fd)

Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_memory.c +1 -1
  * 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;

Quoted 40 lines
lib/librte_eal/linuxapp/eal/eal_memory.c +0 -33
@@ -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

author
#11 lore raw
In reply to a message not in the archive

Thanks Neil for reviews. Inline <rk>

Quoted 7 lines · Neil Horman
Quoted 6 lines · Ravi Kerur

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.

Quoted 14 lines

lib/librte_eal/common/eal_common_debug.c line 66

Quoted 6 lines
lib/librte_eal/common/eal_common_debug.c new file +5 -0
+
+/* 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?

Quoted 33 lines
Quoted 3 lines

+/*
+ * Like rte_panic this terminates the application. However, no

traceback is

Quoted 15 lines

+ * provided and no core-dump is generated.
+ */

lib/librte_eal/common/eal_common_debug.c new file +13 -0
+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);

lib/librte_eal/common/eal_common_debug.c line 111

Quoted 10 lines
lib/librte_eal/common/eal_common_debug.c new file +10 -0
+     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.

Quoted 1 line

<rk> This is again existing code. I can change the comment which matches

the function, will it work?

#13 lore raw
In reply to a message not in the archive
Quoted 26 lines · Ravi Kerur

Thanks Neil for reviews. Inline <rk>

Quoted 7 lines · Neil Horman
Quoted 6 lines · Ravi Kerur

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.

Quoted 14 lines

lib/librte_eal/common/eal_common_debug.c line 66

Quoted 6 lines
lib/librte_eal/common/eal_common_debug.c new file +5 -0
+
+/* 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.

Quoted 5 lines

<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

Quoted 35 lines
Quoted 33 lines
Quoted 3 lines

+/*
+ * Like rte_panic this terminates the application. However, no

traceback is

Quoted 15 lines

+ * provided and no core-dump is generated.
+ */

lib/librte_eal/common/eal_common_debug.c new file +13 -0
+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);

lib/librte_eal/common/eal_common_debug.c line 111

Quoted 10 lines
lib/librte_eal/common/eal_common_debug.c new file +10 -0
+     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.

Quoted 1 line

<rk> This is again existing code. I can change the comment which matches

the function, will it work?

#24 lore raw
In reply to a message not in the archive
Quoted 12 lines · Ravi Kerur

Inline <rk>

Quoted 8 lines · Neil Horman
Quoted 7 lines · Ravi Kerur

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.

Quoted 5 lines
Quoted 2 lines

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.

Quoted 4 lines
Quoted 4 lines

Neil

#31 lore raw
In reply to a message not in the archive
Quoted 573 lines · Ravi Kerur

Inline <rk>

Quoted 569 lines · Neil Horman
Quoted 11 lines · Ravi Kerur

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.

---
 lib/librte_eal/bsdapp/eal/Makefile    |   1 +
 lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
 lib/librte_eal/common/eal_common.c    | 328

++++++++++++++++++++++++++++++++++

Review

Quoted 10 lines
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/Makefile

lib/librte_eal/bsdapp/eal/Makefile SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

Quoted 4 lines

index 92dd9a6..050d70b 100644

lib/librte_eal/bsdapp/eal/Makefile +0 -0
@@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

eal_interrupts.c

Review

Quoted 8 lines
lib/librte_eal/bsdapp/eal/Makefile +1 -0
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal.c

Quoted 8 lines

index 69f3c03..f925da7 100644

lib/librte_eal/bsdapp/eal/eal.c +1 -0
@@ -80,30 +80,10 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_externs.h"

lib/librte_eal/bsdapp/eal/eal.c line 92

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
 
 #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 */

Quoted 55 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -45
-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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 157

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -10
-             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).

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 158

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 159

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
- * processes. */
-static void
-rte_eal_config_create(void)
-{
-     void *rte_mem_cfg_addr;
-     int retval;

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -10
-
-     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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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 "

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-                             "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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config;

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-
-     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));

Quoted 15 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -3
-     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 */

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 233

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +3 -6
-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

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 235

Quoted 2 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -2
-      * 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 */

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void)

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     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");

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void)

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -4
-     return ptype;
-}
-
-/* Sets up rte_config structure with the pointer to shared memory

config.*/

Quoted 21 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -17
-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 */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 285

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -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. */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 286

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-     old_func                                        =

rte_application_usage_hook;

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname)

Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -13
-     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];

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname)

Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
-             if (hpi->hugedir != NULL) {
-                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-                             size += hpi->hugepage_sz *

hpi->num_pages[j];

Review

Quoted 83 lines
lib/librte_eal/bsdapp/eal/eal.c +1 -60
-                     }
-             }
-     }
-
-     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);
-}
-
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common.c

Quoted 9 lines

new file mode 100644
index 0000000..becf9c8

lib/librte_eal/common/eal_common.c new file +4 -0
@@ -0,0 +1,328 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.

lib/librte_eal/common/eal_common.c line 14

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+ *   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

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+ *       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

lib/librte_eal/common/eal_common.c line 25

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

COPYRIGHT

lib/librte_eal/common/eal_common.c line 26

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

lib/librte_eal/common/eal_common.c line 28

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

USE,

lib/librte_eal/common/eal_common.c line 29

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON

ANY

lib/librte_eal/common/eal_common.c line 31

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE

USE

lib/librte_eal/common/eal_common.c line 32

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 46 lines
lib/librte_eal/common/eal_common.c new file +46 -0
+ */
+
+#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"

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+#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 */

Quoted 50 lines
lib/librte_eal/common/eal_common.c new file +50 -0
+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);

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+             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).

lib/librte_eal/common/eal_common.c line 149

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/common/eal_common.c line 150

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 15 lines
lib/librte_eal/common/eal_common.c new file +15 -0
+ * 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) {

lib/librte_eal/common/eal_common.c

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -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);

lib/librte_eal/common/eal_common.c

Quoted 11 lines
lib/librte_eal/common/eal_common.c new file +11 -0
+     }
+
+     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,

lib/librte_eal/common/eal_common.c

Quoted 6 lines
lib/librte_eal/common/eal_common.c new file +6 -0
+                     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));

lib/librte_eal/common/eal_common.c

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+     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

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+      * 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 */
Quoted 6 lines
Quoted 2 lines

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

Quoted 3 lines
Quoted 3 lines

Neil

#52 lore raw
In reply to a message not in the archive
Quoted 153 lines · Ravi Kerur

Inline <rk>

Quoted 139 lines · Neil Horman
Quoted 9 lines · Ravi Kerur

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.

---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 36

++------------------------

Quoted 1 line
 lib/librte_eal/common/eal_common_memory.c | 43

+++++++++++++++++++++++++++++--

Quoted 2 lines
 lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 36

++------------------------

Review

Quoted 3 lines
 4 files changed, 73 insertions(+), 70 deletions(-)
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal_memory.c

Review

Quoted 58 lines

index 65ee87d..b192705 100644

lib/librte_eal/bsdapp/eal/eal_memory.c +2 -34
@@ -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;
-}
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_memory.c

Quoted 60 lines

index 77830f8..da7aa98 100644

lib/librte_eal/common/eal_common_memory.c +30 -2
@@ -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() :
Quoted 10 lines

lib/librte_eal/common/eal_common_memory.c unsigned rte_memory_get_nrank(void) · line 151

Quoted 2 lines
lib/librte_eal/common/eal_common_memory.c +2 -0
+                     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.

Quoted 4 lines

<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

author
#15 lore raw
In reply to a message not in the archive
Quoted 41 lines · Neil Horman
Quoted 3 lines · Ravi Kerur

Thanks Neil for reviews. Inline <rk>

On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <[email protected]>

Quoted 23 lines · wrote:
Quoted 8 lines · Ravi Kerur
Quoted 6 lines

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.

Quoted 14 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+
+/* 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.

Quoted 5 lines

<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.

Quoted 3 lines

Neil

<rk> Sure will remove it.

Quoted 39 lines
Quoted 22 lines
Quoted 22 lines
Quoted 3 lines

+/*
+ * Like rte_panic this terminates the application. However, no

traceback is

Quoted 18 lines

+ * provided and no core-dump is generated.
+ */

(quoted diff) +16 -0
+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);
+
Quoted 8 lines
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+#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

Quoted 1 line
Quoted 1 line

provide a traceback, it shouldn't do so. If an application wants that

to

Quoted 3 lines
Quoted 3 lines

happen, then they need to use rte_panic.

<rk> This is again existing code. I can change the comment which

matches

Quoted 1 line

the function, will it work?

author
#54 lore raw
In reply to a message not in the archive
Quoted 164 lines · Neil Horman
Quoted 3 lines · Ravi Kerur

Inline <rk>

On Thu, Dec 25, 2014 at 9:46 AM, Neil Horman <[email protected]>

Quoted 59 lines · wrote:
Quoted 59 lines · Ravi Kerur
Quoted 9 lines

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.

---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 36

++------------------------

Quoted 1 line
 lib/librte_eal/common/eal_common_memory.c | 43

+++++++++++++++++++++++++++++--

Quoted 2 lines
 lib/librte_eal/common/eal_private.h       | 28 ++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 36

++------------------------

Review

Quoted 3 lines
 4 files changed, 73 insertions(+), 70 deletions(-)
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal_memory.c

Quoted 38 lines

index 65ee87d..b192705 100644

lib/librte_eal/bsdapp/eal/eal_memory.c +2 -15
@@ -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;
-
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal_memory.c error: · line 213

Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal_memory.c +0 -8
-     return 0;
-}
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-     RTE_LOG(INFO, EAL, "Setting up physically contiguous

memory...\n");

Quoted 7 lines
Quoted 7 lines

lib/librte_eal/bsdapp/eal/eal_memory.c error: · line 220

Quoted 7 lines
lib/librte_eal/bsdapp/eal/eal_memory.c +0 -7
-     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)

Quoted 52 lines
Quoted 52 lines

Review

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal_memory.c +0 -4
-             return -1;
-
-     return 0;
-}
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common_memory.c

Quoted 46 lines

index 77830f8..da7aa98 100644

lib/librte_eal/common/eal_common_memory.c +16 -2
@@ -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;
+
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/common/eal_common_memory.c unsigned rte_memory_get_nrank(void) · line 143

Quoted 8 lines
lib/librte_eal/common/eal_common_memory.c +8 -0
+     return 0;
+}
+
+/* init memory subsystem */
+int
+rte_eal_memory_init(void)
+{
+     RTE_LOG(INFO, EAL, "Setting up physically contiguous

memory...\n");

Quoted 9 lines
Quoted 9 lines

lib/librte_eal/common/eal_common_memory.c unsigned rte_memory_get_nrank(void) · line 151

Quoted 8 lines
lib/librte_eal/common/eal_common_memory.c +8 -0
+     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

Quoted 8 lines
Quoted 7 lines

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

Quoted 3 lines

it might create confusion since in the code/document in BSD it's referred as contigmem rather than hugepage.

Quoted 8 lines

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.

author
#33 lore raw
In reply to a message not in the archive
Quoted 613 lines · Neil Horman
Quoted 3 lines · Ravi Kerur

Inline <rk>

On Thu, Dec 25, 2014 at 9:44 AM, Neil Horman <[email protected]>

Quoted 13 lines · wrote:
Quoted 13 lines · Ravi Kerur
Quoted 11 lines

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.

---
 lib/librte_eal/bsdapp/eal/Makefile    |   1 +
 lib/librte_eal/bsdapp/eal/eal.c       | 233 +-----------------------
 lib/librte_eal/common/eal_common.c    | 328
Quoted 6 lines
Quoted 6 lines

++++++++++++++++++++++++++++++++++

Quoted 5 lines
 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

++-----------------------

Quoted 29 lines
Quoted 29 lines

Review

Quoted 5 lines
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/Makefile

lib/librte_eal/bsdapp/eal/Makefile SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

Quoted 4 lines

index 92dd9a6..050d70b 100644

lib/librte_eal/bsdapp/eal/Makefile +0 -0
@@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

eal_interrupts.c

Review

Quoted 8 lines
lib/librte_eal/bsdapp/eal/Makefile +1 -0
 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
(quoted diff) +0 -0

b/lib/librte_eal/bsdapp/eal/eal.c

Quoted 9 lines

index 69f3c03..f925da7 100644

lib/librte_eal/bsdapp/eal/eal.c +1 -0
@@ -80,30 +80,10 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_externs.h"
 
Quoted 5 lines
Quoted 5 lines

lib/librte_eal/bsdapp/eal/eal.c line 88

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
 #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

*/

Quoted 3 lines
Quoted 3 lines

lib/librte_eal/bsdapp/eal/eal.c line 91

Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
-static struct rte_mem_config early_mem_config;
-
-/* define fd variable here, because file needs to be kept open for

the

Quoted 47 lines
Quoted 47 lines

lib/librte_eal/bsdapp/eal/eal.c line 92

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * duration of the program, as we hold a write lock on it in the

primary proc */

Quoted 45 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -35
-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) {
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 145

Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -8
-             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",

Quoted 11 lines
Quoted 11 lines

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 156

Quoted 11 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -11
-                             __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.

Quoted 6 lines
Quoted 6 lines

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 157

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * This means we never close the file while running (auto-close on

exit).

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 158

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 159

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
- * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -8
- * processes. */
-static void
-rte_eal_config_create(void)
-{
-     void *rte_mem_cfg_addr;
-     int retval;
-
-     const char *pathname = eal_runtime_config_path();
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 175

Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -8
-
-     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",

Quoted 20 lines
Quoted 20 lines

pathname);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 181

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 187

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     }
-
-     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 "

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-                             "process running?\n", pathname);
-     }
-
-     rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
-                             PROT_READ | PROT_WRITE, MAP_SHARED,
Quoted 8 lines
Quoted 8 lines

mem_cfg_fd, 0);

lib/librte_eal/bsdapp/eal/eal.c struct internal_config internal_config; · line 197

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -5
-
-     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));

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-     rte_config.mem_config = (struct rte_mem_config *)

rte_mem_cfg_addr;

Quoted 11 lines
Quoted 11 lines

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 124

Quoted 11 lines
lib/librte_eal/bsdapp/eal/eal.c +2 -1
+     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;

Quoted 14 lines
Quoted 14 lines

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 233

Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal.c +3 -7
 }
 
-/* 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

Quoted 1 line
Quoted 1 line

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 234

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-      * process. NOTE: if we get a file handle back, we keep that

open

Quoted 1 line
Quoted 1 line

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 235

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-      * and don't close it to prevent a race condition between

multiple

Quoted 66 lines
Quoted 66 lines

opens */

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 241

Quoted 6 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -6
-     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");

lib/librte_eal/bsdapp/eal/eal.c rte_eal_config_attach(void) · line 245

Quoted 5 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -4
-     return ptype;
-}
-
-/* Sets up rte_config structure with the pointer to shared memory

config.*/

Quoted 21 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -17
-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 */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 285

Quoted 10 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
@@ -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. */

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 286

Quoted 1 line
lib/librte_eal/bsdapp/eal/eal.c +0 -1
-     old_func                                        =

rte_application_usage_hook;

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 299

Quoted 13 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -13
-     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];

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 302

Quoted 3 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -3
-             if (hpi->hugedir != NULL) {
-                     for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
-                             size += hpi->hugepage_sz *

hpi->num_pages[j];

Quoted 8 lines
Quoted 8 lines

lib/librte_eal/bsdapp/eal/eal.c eal_usage(const char *prgname) · line 147

Quoted 8 lines
lib/librte_eal/bsdapp/eal/eal.c +0 -7
-                     }
-             }
-     }
-
-     return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
-}
-
 /* Parse the argument given in the command line of the application

*/

Quoted 76 lines
Quoted 76 lines

Review

Quoted 75 lines
lib/librte_eal/bsdapp/eal/eal.c +1 -53
 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);
-}
-
(quoted diff) +0 -0

b/lib/librte_eal/common/eal_common.c

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines

new file mode 100644
index 0000000..becf9c8

lib/librte_eal/common/eal_common.c new file +0 -0
@@ -0,0 +1,328 @@
Quoted 8 lines

lib/librte_eal/common/eal_common.c line 8

Quoted 8 lines
lib/librte_eal/common/eal_common.c new file +8 -0
+/*-
+ *   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

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 9

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   modification, are permitted provided that the following

conditions

Quoted 3 lines
Quoted 3 lines

lib/librte_eal/common/eal_common.c line 12

Quoted 3 lines
lib/librte_eal/common/eal_common.c new file +3 -0
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above

copyright

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 13

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *       notice, this list of conditions and the following

disclaimer.

Quoted 3 lines
Quoted 3 lines

lib/librte_eal/common/eal_common.c line 14

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *     * Redistributions in binary form must reproduce the above

copyright

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *       notice, this list of conditions and the following

disclaimer in

Quoted 4 lines
Quoted 4 lines

lib/librte_eal/common/eal_common.c line 19

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+ *       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

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 20

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *       from this software without specific prior written

permission.

Quoted 2 lines
Quoted 2 lines

lib/librte_eal/common/eal_common.c line 22

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 23

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT

NOT

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 24

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

FITNESS

Quoted 6 lines
Quoted 6 lines

FOR

lib/librte_eal/common/eal_common.c line 25

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

COPYRIGHT

lib/librte_eal/common/eal_common.c line 26

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT

NOT

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 28

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS

OF

Quoted 2 lines
Quoted 2 lines

USE,

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND

ON

Quoted 2 lines
Quoted 2 lines

ANY

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR

TORT

Quoted 1 line
Quoted 1 line

lib/librte_eal/common/eal_common.c line 31

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF

THE

Quoted 50 lines
Quoted 50 lines

USE

lib/librte_eal/common/eal_common.c line 32

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 47 lines
lib/librte_eal/common/eal_common.c new file +47 -0
+ */
+
+#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"
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/common/eal_common.c line 87

Quoted 8 lines
lib/librte_eal/common/eal_common.c new file +8 -0
+#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

Quoted 5 lines
Quoted 5 lines

lib/librte_eal/common/eal_common.c line 88

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * duration of the program, as we hold a write lock on it in the

primary proc */

lib/librte_eal/common/eal_common.c line 91

Quoted 3 lines
lib/librte_eal/common/eal_common.c new file +3 -0
+int mem_cfg_fd = -1;
+
+/* early configuration structure, when memory config is not mmapped

*/

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
lib/librte_eal/common/eal_common.c new file +37 -0
+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) {
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/common/eal_common.c line 136

Quoted 8 lines
lib/librte_eal/common/eal_common.c new file +8 -0
+             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",

Quoted 11 lines
Quoted 11 lines

lib/librte_eal/common/eal_common.c line 147

Quoted 11 lines
lib/librte_eal/common/eal_common.c new file +11 -0
+                             __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.

Quoted 16 lines
Quoted 16 lines

lib/librte_eal/common/eal_common.c line 148

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * This means we never close the file while running (auto-close on

exit).

lib/librte_eal/common/eal_common.c line 149

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * We also don't lock the whole file, so that in future we can use

read-locks

lib/librte_eal/common/eal_common.c line 150

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+ * on other parts, e.g. memzones, to detect if there are running

secondary

Quoted 10 lines
lib/librte_eal/common/eal_common.c new file +10 -0
+ * 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)
Quoted 8 lines
Quoted 8 lines

lib/librte_eal/common/eal_common.c line 168

Quoted 8 lines
lib/librte_eal/common/eal_common.c new file +8 -0
+             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",

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_eal/common/eal_common.c new file +7 -0
+                                     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",
Quoted 8 lines
Quoted 8 lines

pathname);

Quoted 7 lines
lib/librte_eal/common/eal_common.c new file +7 -0
+     }
+
+     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);

Quoted 5 lines
Quoted 5 lines

lib/librte_eal/common/eal_common.c line 186

Quoted 4 lines
lib/librte_eal/common/eal_common.c new file +4 -0
+     }
+
+     rte_mem_cfg_addr = mmap(rte_mem_cfg_addr,
+                     sizeof(*rte_config.mem_config), PROT_READ |

PROT_WRITE,

Quoted 8 lines
Quoted 8 lines

lib/librte_eal/common/eal_common.c line 192

Quoted 6 lines
lib/librte_eal/common/eal_common.c new file +6 -0
+                     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));

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+     rte_config.mem_config = (struct rte_mem_config *)

rte_mem_cfg_addr;

Quoted 5 lines
Quoted 5 lines

lib/librte_eal/common/eal_common.c line 196

Quoted 3 lines
lib/librte_eal/common/eal_common.c new file +3 -0
+
+#ifndef RTE_EXEC_ENV_BSDAPP
+     /* store address of the config in the config itself so that

secondary

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+      * processes could later map the config into this exact

location

Quoted 2 lines
Quoted 2 lines

lib/librte_eal/common/eal_common.c line 199

Quoted 2 lines
lib/librte_eal/common/eal_common.c new file +2 -0
+      */
+     rte_config.mem_config->mem_cfg_addr = (uintptr_t)

rte_mem_cfg_addr;

Quoted 4 lines
Quoted 3 lines

lib/librte_eal/common/eal_common.c line 200

Quoted 1 line
lib/librte_eal/common/eal_common.c new file +1 -0
+#endif /* RTE_EXEC_ENV_BSDAPP */

Why is this a BSD/Linux Differentiator?

Quoted 9 lines
Quoted 3 lines

<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.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

Neil

#55 lore raw
In reply to a message not in the archive

Hi Ravi,

Quoted 4 lines · Ravi Kerur

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

#57 lore raw
In reply to a message not in the archive
Quoted 10 lines · Olivier MATZ

Hi Ravi,

Quoted 4 lines · Ravi Kerur

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.

Quoted 9 lines

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

Quoted 3 lines

Regards,
Olivier

#59 lore raw
In reply to a message not in the archive

Hi Neil,

Quoted 12 lines · Neil Horman
Quoted 11 lines · Olivier MATZ

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?).

Quoted 7 lines

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).

Quoted 1 line

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

#61 lore raw
In reply to a message not in the archive
Quoted 20 lines · Olivier MATZ

Hi Neil,

Quoted 17 lines · Neil Horman
Quoted 11 lines · Olivier MATZ

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).

Quoted 7 lines
Quoted 2 lines

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

Quoted 5 lines

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.

Quoted 3 lines

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

Quoted 3 lines

Regards,
Olivier

author
#62 lore raw
In reply to a message not in the archive

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

Quoted 41 lines · Olivier MATZ

Hi Neil,

Quoted 8 lines · Neil Horman
Quoted 7 lines · Olivier MATZ

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).

Quoted 5 lines
Quoted 4 lines

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

Quoted 1 line

in the common directory have nothing to do with posix API's, and are

simply just

Quoted 4 lines

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

Quoted 1 line

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

author
#64 lore raw
In reply to a message not in the archive

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

Quoted 50 lines · Ravi Kerur

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

Quoted 41 lines · Olivier MATZ

Hi Neil,

Quoted 8 lines · Neil Horman
Quoted 7 lines · Olivier MATZ

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).

Quoted 5 lines
Quoted 4 lines

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

Quoted 1 line

in the common directory have nothing to do with posix API's, and are

simply just

Quoted 4 lines

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

Quoted 1 line

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

#17 lore raw
In reply to a message not in the archive

2014-12-26 07:28, Ravi Kerur:

Quoted 43 lines · Neil Horman
Quoted 42 lines · Ravi Kerur
Quoted 3 lines

Thanks Neil for reviews. Inline <rk>

On Thu, Dec 25, 2014 at 9:30 AM, Neil Horman <[email protected]>

Quoted 23 lines · wrote:
Quoted 8 lines · Ravi Kerur
Quoted 6 lines

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.

Quoted 14 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+
+/* 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.

Quoted 5 lines

<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.

Quoted 4 lines
Quoted 3 lines

Neil

<rk> Sure will remove it.

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

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 2 lines

+/*
+ * Like rte_panic this terminates the application. However, no

traceback is

Quoted 15 lines

+ * provided and no core-dump is generated.
+ */

(quoted diff) +13 -0
+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);

Review

Quoted 10 lines
(quoted diff) +10 -0
+     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

Quoted 8 lines
Quoted 8 lines

to

Quoted 1 line
Quoted 1 line

provide a traceback, it shouldn't do so. If an application wants that

to

Quoted 3 lines
Quoted 3 lines

happen, then they need to use rte_panic.

<rk> This is again existing code. I can change the comment which

matches

Quoted 1 line

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

Signature · 1 line
Thomas
#66 lore raw
In reply to a message not in the archive
Quoted 6 lines · Ravi Kerur

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

Quoted 8 lines

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

Quoted 52 lines · Ravi Kerur
Quoted 51 lines

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

Quoted 41 lines · Olivier MATZ

Hi Neil,

Quoted 8 lines · Neil Horman
Quoted 7 lines · Olivier MATZ

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).

Quoted 5 lines
Quoted 4 lines

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

Quoted 1 line

in the common directory have nothing to do with posix API's, and are

simply just

Quoted 4 lines

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

Quoted 1 line

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

#42 lore raw
In reply to a message not in the archive

2014-12-25 10:33, Ravi Kerur:

lib/librte_eal/common/eal_common_lcore.c line 68

Quoted 7 lines
lib/librte_eal/common/eal_common_lcore.c new file +7 -0
+#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.

lib/librte_eal/common/eal_common_lcore.c line 95

Quoted 9 lines
lib/librte_eal/common/eal_common_lcore.c new file +9 -0
+#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

Signature · 1 line
Thomas
#45 lore raw
In reply to a message not in the archive

2014-12-25 10:33, Ravi Kerur:

lib/librte_eal/common/eal_common_timer.c line 94

Quoted 5 lines
lib/librte_eal/common/eal_common_timer.c new file +5 -0
+#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.

lib/librte_eal/common/eal_externs.h extern struct rte_config rte_config; · line 44

Quoted 9 lines
lib/librte_eal/common/eal_externs.h +3 -0
@@ -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

Signature · 1 line
Thomas
#34 lore raw
In reply to a message not in the archive

2014-12-25 10:33, Ravi Kerur:

Quoted 1 line

Move common functions in eal.c to librte_eal/common directory.

[...]

Quoted 2 lines
 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.

Signature · 1 line
Thomas
author
#35 lore raw

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

Quoted 19 lines · Thomas Monjalon

2014-12-25 10:33, Ravi Kerur:

Quoted 1 line

Move common functions in eal.c to librte_eal/common directory.

[...]

Quoted 1 line
 lib/librte_eal/common/eal_common.c    | 328

++++++++++++++++++++++++++++++++++

Quoted 1 line
 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

author
#36 lore raw
In reply to Thomas Monjalon

Inline <rk>

Quoted 7 lines · Thomas Monjalon

2014-12-25 10:33, Ravi Kerur:

Quoted 1 line

Move common functions in eal.c to librte_eal/common directory.

[...]

Quoted 1 line
 lib/librte_eal/common/eal_common.c    | 328

++++++++++++++++++++++++++++++++++

Quoted 1 line
 lib/librte_eal/common/eal_externs.h   |  42 +++++
Quoted 9 lines

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.

Quoted 4 lines

--
Thomas

#38 lore raw
In reply to a message not in the archive

2015-01-05 10:56, Ravi Kerur:

Quoted 15 lines
Quoted 13 lines · Thomas Monjalon

2014-12-25 10:33, Ravi Kerur:

Quoted 1 line

Move common functions in eal.c to librte_eal/common directory.

[...]

Quoted 2 lines
 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.

Quoted 3 lines
Quoted 1 line

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

Quoted 8 lines

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.

Signature · 1 line
Thomas
author
#39 lore raw

Inline <rk>

Quoted 43 lines · Thomas Monjalon

2015-01-05 10:56, Ravi Kerur:

Quoted 1 line

On Mon, Jan 5, 2015 at 7:59 AM, Thomas Monjalon <

[email protected]>

Quoted 5 lines
Quoted 4 lines · wrote:

2014-12-25 10:33, Ravi Kerur:

Quoted 1 line

Move common functions in eal.c to librte_eal/common directory.

[...]

Quoted 1 line
 lib/librte_eal/common/eal_common.c    | 328

++++++++++++++++++++++++++++++++++

Quoted 4 lines
Quoted 4 lines
Quoted 1 line
 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

Quoted 8 lines
Quoted 6 lines

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

Quoted 8 lines

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.

Quoted 2 lines

--

<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.

Quoted 2 lines

Thomas

#67 lore raw
In reply to Bruce Richardson

Hi,

Sorry for the late answer.

Quoted 7 lines · Bruce Richardson

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