DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v9 0/3] Move EAL common functions
@ 2015-07-25 19:34 Ravi Kerur
  2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
  0 siblings, 2 replies; 16+ messages in thread
From: Ravi Kerur @ 2015-07-25 19:34 UTC (permalink / raw)
  To: dev

As per Thomas's suggestion dividing v8 patch into multiple smaller
series.  This patch contains changes to eal_lcore.c, eal_timer.c
and eal_memory.c files. 

Tested on Ubuntu x86_64 14.04 GCC and Clang
Tested on FreeBSD 10.0 x86_64 GCC and Clang
testpmd, make test were run successfully.

Ravi Kerur (3):
  Move common functions in eal_lcore.c
  Move common functions in eal_timer.c
  Move common functions in eal_memory.c

 lib/librte_eal/bsdapp/eal/Makefile        |   2 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c     |  72 +++++---------------
 lib/librte_eal/bsdapp/eal/eal_memory.c    |  52 +++++++--------
 lib/librte_eal/bsdapp/eal/eal_timer.c     |  52 +++------------
 lib/librte_eal/common/eal_common_lcore.c  | 107 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_memory.c |  41 +++++++++++-
 lib/librte_eal/common/eal_common_timer.c  | 102 ++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h       |  63 ++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile      |   3 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c   |  66 ++----------------
 lib/librte_eal/linuxapp/eal/eal_memory.c  |  52 +++------------
 lib/librte_eal/linuxapp/eal/eal_timer.c   |  55 ++-------------
 12 files changed, 379 insertions(+), 288 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
 create mode 100644 lib/librte_eal/common/eal_common_timer.c

-- 
1.9.1

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

* [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c
  2015-07-25 19:34 [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
@ 2015-07-25 19:36 ` Ravi Kerur
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
                     ` (2 more replies)
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
  1 sibling, 3 replies; 16+ messages in thread
From: Ravi Kerur @ 2015-07-25 19:36 UTC (permalink / raw)
  To: dev

Changes in v9
Rebase to latest code.

Changes in v8
Reorder eal_common_lcore.c compilation.

Changes in v7
None.

Changes in v6
None.

Changes in v5
Rebase to latest code.

Changes in v4
Implement cpu_detected() for BSD.
Have common RTE_LOG for Linux and BSD in rte_eal_cpu_init().
Remove RTE_EXEC_ENV_BSDAPP in common file.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
None

Changes in v1
Move common function in eal_lcore.c to librte_eal/common/
eal_common_lcore.c file.

Following function is  moved to eal_common_lcore.c file

int rte_eal_cpu_init(void);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common function.
Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile       |   1 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c    |  72 +++++----------------
 lib/librte_eal/common/eal_common_lcore.c | 107 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h      |  14 ++++
 lib/librte_eal/linuxapp/eal/Makefile     |   2 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c  |  66 ++-----------------
 6 files changed, 143 insertions(+), 119 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 064b0c5..d5e4f4a 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -58,6 +58,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_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_common_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
index 162fb4f..b47eb1b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
+++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
@@ -44,11 +44,14 @@
 #include "eal_thread.h"
 
 /* No topology information available on FreeBSD including NUMA info */
-#define cpu_core_id(X) 0
-#define cpu_socket_id(X) 0
+unsigned
+eal_cpu_core_id(__rte_unused unsigned lcore_id)
+{
+	return 0;
+}
 
 static int
-get_ncpus(void)
+eal_get_ncpus(void)
 {
 	int mib[2] = {CTL_HW, HW_NCPU};
 	int ncpu;
@@ -59,63 +62,18 @@ get_ncpus(void)
 	return ncpu;
 }
 
-/*
- * fill the cpu_info structure with as much info as we can get.
- * code is similar to linux version, but sadly available info is less.
- */
-int
-rte_eal_cpu_init(void)
+unsigned
+eal_cpu_socket_id(__rte_unused unsigned cpu_id)
 {
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	const unsigned ncpus = get_ncpus();
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		/* init cpuset for per lcore config */
-		CPU_ZERO(&lcore_config[lcore_id].cpuset);
-
-		lcore_config[lcore_id].detected = (lcore_id < ncpus);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-
-		/* By default, lcore 1:1 map to cpu id */
-		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
-
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
-				lcore_id);
-		count++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
 	return 0;
 }
 
-unsigned
-eal_cpu_socket_id(__rte_unused unsigned cpu_id)
+/* Check if a cpu is present by the presence of the
+ * cpu information for it.
+ */
+int
+eal_cpu_detected(unsigned lcore_id)
 {
-	return cpu_socket_id(cpu_id);
+	const unsigned ncpus = eal_get_ncpus();
+	return (lcore_id < ncpus);
 }
diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
new file mode 100644
index 0000000..845140b
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -0,0 +1,107 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <dirent.h>
+
+#include <rte_log.h>
+#include <rte_eal.h>
+#include <rte_lcore.h>
+#include <rte_common.h>
+#include <rte_debug.h>
+
+#include "eal_private.h"
+#include "eal_thread.h"
+
+/*
+ * Parse /sys/devices/system/cpu to get the number of physical and logical
+ * processors on the machine. The function will fill the cpu_info
+ * structure.
+ */
+int
+rte_eal_cpu_init(void)
+{
+	/* pointer to global configuration */
+	struct rte_config *config = rte_eal_get_configuration();
+	unsigned lcore_id;
+	unsigned count = 0;
+
+	/*
+	 * Parse the maximum set of logical cores, detect the subset of running
+	 * ones and enable them by default.
+	 */
+	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
+		/* init cpuset for per lcore config */
+		CPU_ZERO(&lcore_config[lcore_id].cpuset);
+
+		/* in 1:1 mapping, record related cpu detected state */
+		lcore_config[lcore_id].detected = eal_cpu_detected(lcore_id);
+		if (lcore_config[lcore_id].detected == 0) {
+			config->lcore_role[lcore_id] = ROLE_OFF;
+			continue;
+		}
+
+		/* By default, lcore 1:1 map to cpu id */
+		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
+
+		/* By default, each detected core is enabled */
+		config->lcore_role[lcore_id] = ROLE_RTE;
+		lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id);
+		lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
+		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
+#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
+			lcore_config[lcore_id].socket_id = 0;
+#else
+			rte_panic("Socket ID (%u) is greater than "
+				"RTE_MAX_NUMA_NODES (%d)\n",
+				lcore_config[lcore_id].socket_id,
+				RTE_MAX_NUMA_NODES);
+#endif
+
+		RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
+				"core %u on socket %u\n",
+				lcore_id, lcore_config[lcore_id].core_id,
+				lcore_config[lcore_id].socket_id);
+		count++;
+	}
+	/* Set the count of enabled logical cores of the EAL configuration */
+	config->lcore_count = count;
+	RTE_LOG(DEBUG, EAL,
+		"Support maximum %u logical core(s) by configuration.\n",
+		RTE_MAX_LCORE);
+	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
+
+	return 0;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 73363f6..f80a9c4 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -300,4 +300,18 @@ int rte_eal_dev_init(void);
  */
 int rte_eal_check_module(const char *module_name);
 
+/**
+ * This function gets cpu core_id
+ *
+ * This function is private to the EAL.
+ */
+unsigned eal_cpu_core_id(unsigned lcore_id);
+
+/**
+ * This function check if cpu is present
+ *
+ * This function is private to the EAL.
+ */
+int eal_cpu_detected(unsigned lcore_id);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 00ed62e..b80a333 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -67,6 +67,7 @@ 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_common_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_alarm.c
@@ -107,6 +108,7 @@ CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE
 CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE
 CFLAGS_eal_common_options.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
+CFLAGS_eal_common_lcore.o := -D_GNU_SOURCE
 
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c
index 560039b..de5b426 100644
--- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
+++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
@@ -52,8 +52,8 @@
 #define NUMA_NODE_PATH "/sys/devices/system/node"
 
 /* Check if a cpu is present by the presence of the cpu information for it */
-static int
-cpu_detected(unsigned lcore_id)
+int
+eal_cpu_detected(unsigned lcore_id)
 {
 	char path[PATH_MAX];
 	int len = snprintf(path, sizeof(path), SYS_CPU_DIR
@@ -90,8 +90,8 @@ eal_cpu_socket_id(unsigned lcore_id)
 }
 
 /* Get the cpu core id value from the /sys/.../cpuX core_id value */
-static unsigned
-cpu_core_id(unsigned lcore_id)
+unsigned
+eal_cpu_core_id(unsigned lcore_id)
 {
 	char path[PATH_MAX];
 	unsigned long id;
@@ -108,61 +108,3 @@ err:
 			"for lcore %u - assuming core 0\n", SYS_CPU_DIR, lcore_id);
 	return 0;
 }
-
-/*
- * Parse /sys/devices/system/cpu to get the number of physical and logical
- * processors on the machine. The function will fill the cpu_info
- * structure.
- */
-int
-rte_eal_cpu_init(void)
-{
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		/* init cpuset for per lcore config */
-		CPU_ZERO(&lcore_config[lcore_id].cpuset);
-
-		/* in 1:1 mapping, record related cpu detected state */
-		lcore_config[lcore_id].detected = cpu_detected(lcore_id);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-
-		/* By default, lcore 1:1 map to cpu id */
-		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
-
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u as core %u on socket %u\n",
-				lcore_id,
-				lcore_config[lcore_id].core_id,
-				lcore_config[lcore_id].socket_id);
-		count ++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
-	return 0;
-}
-- 
1.9.1

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

* [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c
  2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
@ 2015-07-25 19:36   ` Ravi Kerur
  2015-07-26 23:32     ` Thomas Monjalon
  2015-07-26 23:40     ` Thomas Monjalon
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c Ravi Kerur
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
  2 siblings, 2 replies; 16+ messages in thread
From: Ravi Kerur @ 2015-07-25 19:36 UTC (permalink / raw)
  To: dev

Changes in v9
Rebase to latest code.

Changes in v8
Reorder eal_common_timer.c compilation.

Changes in v7
None

Changes in v6
Added new line between Copyright and header file inclusion
in eal_common_timer.c.

Changes in v5
Rebase to latest code.

Changes in v4
Removed extern declaration of eal_tsc_resolution_hz,
instead provided _set_ API.
Make set_tsc_freq_from_clock as wrapper function for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function name set_tsc_freq_from_sysctl for BSD and Linux.
Update comments about its actuality in function declaration.

Changes in v1
Move common functions in eal_timer.c to librte_eal/common/
eal_common_timer.c file.

Following functions are  moved to eal_common_timer.c file

void rte_delay_us(unsigned us);
uint64_t rte_get_tsc_hz(void);
static void set_tsc_freq_fallback(void);
void set_tsc_freq(void);

Makefile changes to reflect new file added.
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile       |   1 +
 lib/librte_eal/bsdapp/eal/eal_timer.c    |  52 +++-------------
 lib/librte_eal/common/eal_common_timer.c | 102 +++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h      |  24 ++++++++
 lib/librte_eal/linuxapp/eal/Makefile     |   1 +
 lib/librte_eal/linuxapp/eal/eal_timer.c  |  55 ++---------------
 6 files changed, 140 insertions(+), 95 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_timer.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index d5e4f4a..102f310 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -60,6 +60,7 @@ 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_common_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_timer.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
diff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/bsdapp/eal/eal_timer.c
index 7147abe..ee7a5ac 100644
--- a/lib/librte_eal/bsdapp/eal/eal_timer.c
+++ b/lib/librte_eal/bsdapp/eal/eal_timer.c
@@ -55,29 +55,12 @@
 
 enum timer_source eal_timer_source = EAL_TIMER_TSC;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
-uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
 static int
 set_tsc_freq_from_sysctl(void)
 {
 	size_t sz;
 	int tmp;
+	uint64_t tsc_hz;
 
 	sz = sizeof(tmp);
 	tmp = 0;
@@ -94,42 +77,23 @@ set_tsc_freq_from_sysctl(void)
 	else if (tmp != 1)
 		RTE_LOG(WARNING, EAL, "TSC is not invariant\n");
 
-	sz = sizeof(eal_tsc_resolution_hz);
-	if (sysctlbyname("machdep.tsc_freq", &eal_tsc_resolution_hz, &sz, NULL, 0)) {
+	sz = sizeof(tsc_hz);
+	if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
 		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
 		return -1;
 	}
+	rte_set_tsc_hz(tsc_hz);
 
 	return 0;
 }
 
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-
 /*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. Read the TSC frequency value provided by the kernel
- * 2. If above does not work, just sleep for 1 second and tune off that,
- *    printing a warning about inaccuracy of timing
+ * Wrapper function to get TSC frequency from sysctl.
  */
-static void
-set_tsc_freq(void)
+int
+set_tsc_freq_from_clock(void)
 {
-	if (set_tsc_freq_from_sysctl() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
+	return set_tsc_freq_from_sysctl();
 }
 
 int
diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
new file mode 100644
index 0000000..5fddd6e
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -0,0 +1,102 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <errno.h>
+
+#include <rte_common.h>
+#include <rte_log.h>
+#include <rte_cycles.h>
+
+#include "eal_private.h"
+#include "eal_internal_cfg.h"
+
+/* The frequency of the RDTSC timer resolution */
+uint64_t eal_tsc_resolution_hz = 0;
+
+void
+rte_delay_us(unsigned us)
+{
+	const uint64_t start = rte_get_timer_cycles();
+	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
+
+	while ((rte_get_timer_cycles() - start) < ticks)
+		rte_pause();
+}
+
+uint64_t
+rte_get_tsc_hz(void)
+{
+	return eal_tsc_resolution_hz;
+}
+
+void
+rte_set_tsc_hz(uint64_t tsc_hz)
+{
+	eal_tsc_resolution_hz = tsc_hz;
+}
+
+static void
+set_tsc_freq_fallback(void)
+{
+	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
+		"CLOCK_MONOTONIC_RAW and HPET is not available"
+		" - clock timings may be less accurate.\n");
+	/* assume that the sleep(1) will sleep for 1 second */
+	uint64_t start = rte_rdtsc();
+
+	sleep(1);
+	eal_tsc_resolution_hz = rte_rdtsc() - start;
+}
+
+/*
+ * This function measures the TSC frequency. It uses a variety of approaches.
+ *
+ * 1. Read the TSC frequency value provided by the kernel
+ * 2. If above does not work, just sleep for 1 second and tune off that,
+ *    printing a warning about inaccuracy of timing
+ */
+void
+set_tsc_freq(void)
+{
+	if (set_tsc_freq_from_clock() < 0)
+		set_tsc_freq_fallback();
+
+	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
+			eal_tsc_resolution_hz/1000);
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index f80a9c4..b33b701 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -314,4 +314,28 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
  */
 int eal_cpu_detected(unsigned lcore_id);
 
+/**
+ * This function measures TSC frequency
+ *
+ * This function is private to the EAL.
+ */
+void set_tsc_freq(void);
+
+/**
+ * This function sets TSC frequency from sysctl
+ * for BSD and from clock for Linux.
+ * Is a wrapper function for BSD which will
+ * internally call set_tsc_freq_from_sysctl.
+ *
+ * This function is private to the EAL.
+ */
+int set_tsc_freq_from_clock(void);
+
+/**
+ * This function sets TSC frequency
+ *
+ * This function is private to the EAL.
+ */
+void rte_set_tsc_hz(uint64_t tsc_hz);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index b80a333..f001ca6 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -69,6 +69,7 @@ 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_common_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_timer.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_alarm.c
 ifeq ($(CONFIG_RTE_LIBRTE_IVSHMEM),y)
diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c
index 94909ed..ef70682 100644
--- a/lib/librte_eal/linuxapp/eal/eal_timer.c
+++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
@@ -57,9 +57,6 @@
 
 enum timer_source eal_timer_source = EAL_TIMER_HPET;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
 #ifdef RTE_LIBEAL_USE_HPET
 
 #define DEV_HPET "/dev/hpet"
@@ -160,23 +157,6 @@ rte_get_hpet_cycles(void)
 
 #endif
 
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
-uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
-
 #ifdef RTE_LIBEAL_USE_HPET
 /*
  * Open and mmap /dev/hpet (high precision event timer) that will
@@ -275,7 +255,7 @@ check_tsc_flags(void)
 	fclose(stream);
 }
 
-static int
+int
 set_tsc_freq_from_clock(void)
 {
 #ifdef CLOCK_MONOTONIC_RAW
@@ -284,6 +264,7 @@ set_tsc_freq_from_clock(void)
 	struct timespec sleeptime = {.tv_nsec = 5E8 }; /* 1/2 second */
 
 	struct timespec t_start, t_end;
+	uint64_t tsc_hz;
 
 	if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) {
 		uint64_t ns, end, start = rte_rdtsc();
@@ -294,42 +275,14 @@ set_tsc_freq_from_clock(void)
 		ns += (t_end.tv_nsec - t_start.tv_nsec);
 
 		double secs = (double)ns/NS_PER_SEC;
-		eal_tsc_resolution_hz = (uint64_t)((end - start)/secs);
+		tsc_hz = (uint64_t)((end - start)/secs);
+		rte_set_tsc_hz(tsc_hz);
 		return 0;
 	}
 #endif
 	return -1;
 }
 
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. If kernel provides CLOCK_MONOTONIC_RAW we use that to tune the TSC value
- * 2. If kernel does not provide that, and we have HPET support, tune using HPET
- * 3. Lastly, if neither of the above can be used, just sleep for 1 second and
- * tune off that, printing a warning about inaccuracy of timing
- */
-static void
-set_tsc_freq(void)
-{
-	if (set_tsc_freq_from_clock() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
-}
-
 int
 rte_eal_timer_init(void)
 {
-- 
1.9.1

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

* [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c
  2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
@ 2015-07-25 19:36   ` Ravi Kerur
  2015-07-27  0:35     ` Thomas Monjalon
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
  2 siblings, 1 reply; 16+ messages in thread
From: Ravi Kerur @ 2015-07-25 19:36 UTC (permalink / raw)
  To: dev

Changes in v9
Rebase to latest code.

Changes in v8
None

Changes in v7
None

Changes in v6
Removed unnecessary comments in function declaration.

Changes in v5
Rebase to latest code.

Changes in v4
Make rte_eal_hugepage_init and rte_eal_hugepage_attach as
wrapper functions for BSD.

Changes in v3
Changed subject to be more explicit on file name inclusion.

Changes in v2
Use common function names rte_eal_hugepage_init and
rte_eal_hugepage_attach for BSD and Linux. Update comments about its
actuality in function declaration.

Changes in v1
Move common functions in eal_memory.c to librte_eal/common/
eal_common_memory.c file.

Following functions are moved to eal_common_memory.c file

static int rte_eal_memdevice_init(void); int rte_eal_memory_init(void);
Fix checkpatch warnings and errors.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 52 ++++++++++++++-----------------
 lib/librte_eal/common/eal_common_memory.c | 41 ++++++++++++++++++++++--
 lib/librte_eal/common/eal_private.h       | 29 +++++++++++++++--
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 52 ++++++-------------------------
 4 files changed, 98 insertions(+), 76 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c
index a3242a5..28231bb 100644
--- a/lib/librte_eal/bsdapp/eal/eal_memory.c
+++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
@@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
 	return RTE_BAD_PHYS_ADDR;
 }
 
-static int
+static inline int
 rte_eal_contigmem_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -132,7 +132,16 @@ rte_eal_contigmem_init(void)
 	return 0;
 }
 
-static int
+/*
+ * Wrapper function to initialize contigmem.
+ */
+int
+rte_eal_hugepage_init(void)
+{
+	return rte_eal_contigmem_init();
+}
+
+static inline int
 rte_eal_contigmem_attach(void)
 {
 	const struct hugepage_info *hpi;
@@ -193,35 +202,20 @@ error:
 	return -1;
 }
 
-
-static int
-rte_eal_memdevice_init(void)
+/*
+ * Wrapper function to attach contigmem.
+ */
+int
+rte_eal_hugepage_attach(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;
+	return rte_eal_contigmem_attach();
 }
 
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
+/*
+ * Wrapper function, no-op here.
+ */
+void
+test_proc_pagemap_readable(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;
+	return;
 }
diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 9a07b1e..95f0a50 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -45,6 +45,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
@@ -69,7 +70,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;
 
@@ -89,7 +90,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;
 
@@ -118,3 +119,39 @@ 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");
+
+	test_proc_pagemap_readable();
+
+	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;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index b33b701..58510ca 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -324,8 +324,6 @@ void set_tsc_freq(void);
 /**
  * This function sets TSC frequency from sysctl
  * for BSD and from clock for Linux.
- * Is a wrapper function for BSD which will
- * internally call set_tsc_freq_from_sysctl.
  *
  * This function is private to the EAL.
  */
@@ -338,4 +336,31 @@ int set_tsc_freq_from_clock(void);
  */
 void rte_set_tsc_hz(uint64_t tsc_hz);
 
+/**
+ * This function prepares physical memory mapping
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_init(void);
+
+/**
+ * This function creates memory mapping in secondary
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_attach(void);
+
+/**
+ * This function checks /proc filesystem
+ * on Linux.
+ *
+ * This function is private to the EAL.
+ */
+void
+test_proc_pagemap_readable(void);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index d529016..4ac6cb2 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1037,7 +1037,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;
@@ -1378,7 +1378,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;
@@ -1539,55 +1539,21 @@ 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;
-}
-
-static int
+void
 test_proc_pagemap_readable(void)
 {
 	int fd = open("/proc/self/pagemap", O_RDONLY);
 
-	if (fd < 0)
-		return 0;
-	/* Is readable */
-	close(fd);
-
-	return 1;
-}
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up memory...\n");
-
-	proc_pagemap_readable = test_proc_pagemap_readable();
-	if (!proc_pagemap_readable)
+	if (fd < 0) {
 		RTE_LOG(ERR, EAL,
 			"Cannot open /proc/self/pagemap: %s. "
 			"virt2phys address translation will not work\n",
 			strerror(errno));
+		return;
+	}
 
-	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;
+	/* Is readable */
+	close(fd);
 
-	return 0;
+	proc_pagemap_readable = 1;
 }
-- 
1.9.1

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

* [dpdk-dev] [PATCH v9 0/3] Move EAL common functions
  2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c Ravi Kerur
@ 2015-07-25 19:36   ` Ravi Kerur
  2 siblings, 0 replies; 16+ messages in thread
From: Ravi Kerur @ 2015-07-25 19:36 UTC (permalink / raw)
  To: dev

As per Thomas's suggestion dividing v8 patch into multiple smaller
series.  This patch contains changes to eal_lcore.c, eal_timer.c
and eal_memory.c files. 

Tested on Ubuntu x86_64 14.04 GCC and Clang
Tested on FreeBSD 10.0 x86_64 GCC and Clang
testpmd, make test were run successfully.

Ravi Kerur (3):
  Move common functions in eal_lcore.c
  Move common functions in eal_timer.c
  Move common functions in eal_memory.c

 lib/librte_eal/bsdapp/eal/Makefile        |   2 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c     |  72 +++++---------------
 lib/librte_eal/bsdapp/eal/eal_memory.c    |  52 +++++++--------
 lib/librte_eal/bsdapp/eal/eal_timer.c     |  52 +++------------
 lib/librte_eal/common/eal_common_lcore.c  | 107 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_memory.c |  41 +++++++++++-
 lib/librte_eal/common/eal_common_timer.c  | 102 ++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h       |  63 ++++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile      |   3 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c   |  66 ++----------------
 lib/librte_eal/linuxapp/eal/eal_memory.c  |  52 +++------------
 lib/librte_eal/linuxapp/eal/eal_timer.c   |  55 ++-------------
 12 files changed, 379 insertions(+), 288 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_lcore.c
 create mode 100644 lib/librte_eal/common/eal_common_timer.c

-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
@ 2015-07-26 23:32     ` Thomas Monjalon
  2015-07-26 23:40     ` Thomas Monjalon
  1 sibling, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-26 23:32 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2015-07-25 12:36, Ravi Kerur:
> +static void
> +set_tsc_freq_fallback(void)
> +{
> +	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
> +		"CLOCK_MONOTONIC_RAW and HPET is not available"

Not generic enough for BSD.
We can say "TSC frequency estimated roughly"

> +		" - clock timings may be less accurate.\n");
> +	/* assume that the sleep(1) will sleep for 1 second */
[...]
> +/**
> + * This function sets TSC frequency from sysctl

It is not the style of the file to start with "This function..."

> + * for BSD and from clock for Linux.
> + * Is a wrapper function for BSD which will
> + * internally call set_tsc_freq_from_sysctl.

This sentence is an implementation detail.

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

* Re: [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
  2015-07-26 23:32     ` Thomas Monjalon
@ 2015-07-26 23:40     ` Thomas Monjalon
  1 sibling, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-26 23:40 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2015-07-25 12:36, Ravi Kerur
>  static int
>  set_tsc_freq_from_sysctl(void)
>  {
>  	size_t sz;
>  	int tmp;
> +	uint64_t tsc_hz;
>  
>  	sz = sizeof(tmp);
>  	tmp = 0;
> @@ -94,42 +77,23 @@ set_tsc_freq_from_sysctl(void)
>  	else if (tmp != 1)
>  		RTE_LOG(WARNING, EAL, "TSC is not invariant\n");
>  
> -	sz = sizeof(eal_tsc_resolution_hz);
> -	if (sysctlbyname("machdep.tsc_freq", &eal_tsc_resolution_hz, &sz, NULL, 0)) {
> +	sz = sizeof(tsc_hz);
> +	if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
>  		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
>  		return -1;
>  	}
> +	rte_set_tsc_hz(tsc_hz);
>  
>  	return 0;
>  }
[...]
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common_timer.c
> +void
> +rte_set_tsc_hz(uint64_t tsc_hz)
> +{
> +	eal_tsc_resolution_hz = tsc_hz;
> +}
[...]
> +void
> +set_tsc_freq(void)
> +{
> +	if (set_tsc_freq_from_clock() < 0)
> +		set_tsc_freq_fallback();

It would be simpler to get value from return of these functions
and store it in eal_tsc_resolution_hz here.

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

* Re: [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c
  2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c Ravi Kerur
@ 2015-07-27  0:35     ` Thomas Monjalon
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:35 UTC (permalink / raw)
  To: Ravi Kerur; +Cc: dev

2015-07-25 12:36, Ravi Kerur:
> --- a/lib/librte_eal/bsdapp/eal/eal_memory.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
[...]
> +/*
> + * Wrapper function to initialize contigmem.
> + */
> +int
> +rte_eal_hugepage_init(void)
> +{
> +	return rte_eal_contigmem_init();
> +}

The useless wrapper can be avoid by renaming the function: contigmem_init to
hugepage_init.

> +/*
> + * Wrapper function, no-op here.
> + */
> +void
> +test_proc_pagemap_readable(void)
>  {
> +	return;
>  }
[...]
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
[...]
> +/**
> + * This function checks /proc filesystem
> + * on Linux.
> + *
> + * This function is private to the EAL.
> + */
> +void
> +test_proc_pagemap_readable(void);

This check is specific to Linux. So it should not be in the common file.

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

* [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions
  2015-07-25 19:34 [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
  2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
@ 2015-07-27  0:56 ` Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization Thomas Monjalon
                     ` (3 more replies)
  1 sibling, 4 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:56 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

v9 was a subset of previous deduplications by Ravi Kerur.
This v10 address the comments I've done on v9.

Ravi Kerur (3):
  eal: deduplicate lcore initialization
  eal: deduplicate timer functions
  eal: deduplicate memory initialization

 lib/librte_eal/bsdapp/eal/Makefile                 |  2 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c              | 72 ++++---------------
 lib/librte_eal/bsdapp/eal/eal_memory.c             | 39 +----------
 lib/librte_eal/bsdapp/eal/eal_timer.c              | 58 ++--------------
 .../eal/eal_lcore.c => common/eal_common_lcore.c}  | 52 +++++---------
 lib/librte_eal/common/eal_common_memory.c          | 38 +++++++++-
 .../eal/eal_timer.c => common/eal_common_timer.c}  | 79 +++------------------
 lib/librte_eal/common/eal_private.h                | 46 +++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile               |  3 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c            | 66 ++----------------
 lib/librte_eal/linuxapp/eal/eal_memory.c           | 80 +++++++---------------
 lib/librte_eal/linuxapp/eal/eal_timer.c            | 60 ++--------------
 12 files changed, 175 insertions(+), 420 deletions(-)
 copy lib/librte_eal/{bsdapp/eal/eal_lcore.c => common/eal_common_lcore.c} (75%)
 copy lib/librte_eal/{bsdapp/eal/eal_timer.c => common/eal_common_timer.c} (57%)

-- 
2.4.2

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

* [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
@ 2015-07-27  0:56   ` Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 2/3] eal: deduplicate timer functions Thomas Monjalon
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:56 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

From: Ravi Kerur <rkerur@gmail.com>

Implement cpu_detected() for BSD.
Move common function in eal_lcore.c to eal_common_lcore.c file.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |  1 +
 lib/librte_eal/bsdapp/eal/eal_lcore.c              | 72 +++++-----------------
 .../eal/eal_lcore.c => common/eal_common_lcore.c}  | 52 ++++++----------
 lib/librte_eal/common/eal_private.h                | 14 +++++
 lib/librte_eal/linuxapp/eal/Makefile               |  2 +
 lib/librte_eal/linuxapp/eal/eal_lcore.c            | 66 ++------------------
 6 files changed, 55 insertions(+), 152 deletions(-)
 copy lib/librte_eal/{bsdapp/eal/eal_lcore.c => common/eal_common_lcore.c} (75%)

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 01e5972..24733ae 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -60,6 +60,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_lcore.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c
index 162fb4f..b47eb1b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
+++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c
@@ -44,11 +44,14 @@
 #include "eal_thread.h"
 
 /* No topology information available on FreeBSD including NUMA info */
-#define cpu_core_id(X) 0
-#define cpu_socket_id(X) 0
+unsigned
+eal_cpu_core_id(__rte_unused unsigned lcore_id)
+{
+	return 0;
+}
 
 static int
-get_ncpus(void)
+eal_get_ncpus(void)
 {
 	int mib[2] = {CTL_HW, HW_NCPU};
 	int ncpu;
@@ -59,63 +62,18 @@ get_ncpus(void)
 	return ncpu;
 }
 
-/*
- * fill the cpu_info structure with as much info as we can get.
- * code is similar to linux version, but sadly available info is less.
- */
-int
-rte_eal_cpu_init(void)
+unsigned
+eal_cpu_socket_id(__rte_unused unsigned cpu_id)
 {
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	const unsigned ncpus = get_ncpus();
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		/* init cpuset for per lcore config */
-		CPU_ZERO(&lcore_config[lcore_id].cpuset);
-
-		lcore_config[lcore_id].detected = (lcore_id < ncpus);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-
-		/* By default, lcore 1:1 map to cpu id */
-		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
-
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
-				lcore_id);
-		count++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
 	return 0;
 }
 
-unsigned
-eal_cpu_socket_id(__rte_unused unsigned cpu_id)
+/* Check if a cpu is present by the presence of the
+ * cpu information for it.
+ */
+int
+eal_cpu_detected(unsigned lcore_id)
 {
-	return cpu_socket_id(cpu_id);
+	const unsigned ncpus = eal_get_ncpus();
+	return (lcore_id < ncpus);
 }
diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
similarity index 75%
copy from lib/librte_eal/bsdapp/eal/eal_lcore.c
copy to lib/librte_eal/common/eal_common_lcore.c
index 162fb4f..845140b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_lcore.c
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -32,7 +32,9 @@
  */
 
 #include <unistd.h>
-#include <sys/sysctl.h>
+#include <limits.h>
+#include <string.h>
+#include <dirent.h>
 
 #include <rte_log.h>
 #include <rte_eal.h>
@@ -43,25 +45,10 @@
 #include "eal_private.h"
 #include "eal_thread.h"
 
-/* No topology information available on FreeBSD including NUMA info */
-#define cpu_core_id(X) 0
-#define cpu_socket_id(X) 0
-
-static int
-get_ncpus(void)
-{
-	int mib[2] = {CTL_HW, HW_NCPU};
-	int ncpu;
-	size_t len = sizeof(ncpu);
-
-	sysctl(mib, 2, &ncpu, &len, NULL, 0);
-	RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu);
-	return ncpu;
-}
-
 /*
- * fill the cpu_info structure with as much info as we can get.
- * code is similar to linux version, but sadly available info is less.
+ * Parse /sys/devices/system/cpu to get the number of physical and logical
+ * processors on the machine. The function will fill the cpu_info
+ * structure.
  */
 int
 rte_eal_cpu_init(void)
@@ -71,7 +58,6 @@ rte_eal_cpu_init(void)
 	unsigned lcore_id;
 	unsigned count = 0;
 
-	const unsigned ncpus = get_ncpus();
 	/*
 	 * Parse the maximum set of logical cores, detect the subset of running
 	 * ones and enable them by default.
@@ -80,7 +66,8 @@ rte_eal_cpu_init(void)
 		/* init cpuset for per lcore config */
 		CPU_ZERO(&lcore_config[lcore_id].cpuset);
 
-		lcore_config[lcore_id].detected = (lcore_id < ncpus);
+		/* in 1:1 mapping, record related cpu detected state */
+		lcore_config[lcore_id].detected = eal_cpu_detected(lcore_id);
 		if (lcore_config[lcore_id].detected == 0) {
 			config->lcore_role[lcore_id] = ROLE_OFF;
 			continue;
@@ -91,31 +78,30 @@ rte_eal_cpu_init(void)
 
 		/* By default, each detected core is enabled */
 		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id);
+		lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id);
+		lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
 		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
 #ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
 			lcore_config[lcore_id].socket_id = 0;
 #else
 			rte_panic("Socket ID (%u) is greater than "
 				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
+				lcore_config[lcore_id].socket_id,
+				RTE_MAX_NUMA_NODES);
 #endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u\n",
-				lcore_id);
+
+		RTE_LOG(DEBUG, EAL, "Detected lcore %u as "
+				"core %u on socket %u\n",
+				lcore_id, lcore_config[lcore_id].core_id,
+				lcore_config[lcore_id].socket_id);
 		count++;
 	}
 	/* Set the count of enabled logical cores of the EAL configuration */
 	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
+	RTE_LOG(DEBUG, EAL,
+		"Support maximum %u logical core(s) by configuration.\n",
 		RTE_MAX_LCORE);
 	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
 
 	return 0;
 }
-
-unsigned
-eal_cpu_socket_id(__rte_unused unsigned cpu_id)
-{
-	return cpu_socket_id(cpu_id);
-}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 73363f6..8505b05 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -300,4 +300,18 @@ int rte_eal_dev_init(void);
  */
 int rte_eal_check_module(const char *module_name);
 
+/**
+ * Get cpu core_id.
+ *
+ * This function is private to the EAL.
+ */
+unsigned eal_cpu_core_id(unsigned lcore_id);
+
+/**
+ * Check if cpu is present.
+ *
+ * This function is private to the EAL.
+ */
+int eal_cpu_detected(unsigned lcore_id);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 0726ce1..f4f8cdf 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -70,6 +70,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_ivshmem.c
 endif
 
 # from common dir
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.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
@@ -102,6 +103,7 @@ CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE
 CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE
 CFLAGS_eal_common_options.o := -D_GNU_SOURCE
 CFLAGS_eal_common_thread.o := -D_GNU_SOURCE
+CFLAGS_eal_common_lcore.o := -D_GNU_SOURCE
 
 # workaround for a gcc bug with noreturn attribute
 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c
index 560039b..de5b426 100644
--- a/lib/librte_eal/linuxapp/eal/eal_lcore.c
+++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c
@@ -52,8 +52,8 @@
 #define NUMA_NODE_PATH "/sys/devices/system/node"
 
 /* Check if a cpu is present by the presence of the cpu information for it */
-static int
-cpu_detected(unsigned lcore_id)
+int
+eal_cpu_detected(unsigned lcore_id)
 {
 	char path[PATH_MAX];
 	int len = snprintf(path, sizeof(path), SYS_CPU_DIR
@@ -90,8 +90,8 @@ eal_cpu_socket_id(unsigned lcore_id)
 }
 
 /* Get the cpu core id value from the /sys/.../cpuX core_id value */
-static unsigned
-cpu_core_id(unsigned lcore_id)
+unsigned
+eal_cpu_core_id(unsigned lcore_id)
 {
 	char path[PATH_MAX];
 	unsigned long id;
@@ -108,61 +108,3 @@ err:
 			"for lcore %u - assuming core 0\n", SYS_CPU_DIR, lcore_id);
 	return 0;
 }
-
-/*
- * Parse /sys/devices/system/cpu to get the number of physical and logical
- * processors on the machine. The function will fill the cpu_info
- * structure.
- */
-int
-rte_eal_cpu_init(void)
-{
-	/* pointer to global configuration */
-	struct rte_config *config = rte_eal_get_configuration();
-	unsigned lcore_id;
-	unsigned count = 0;
-
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		/* init cpuset for per lcore config */
-		CPU_ZERO(&lcore_config[lcore_id].cpuset);
-
-		/* in 1:1 mapping, record related cpu detected state */
-		lcore_config[lcore_id].detected = cpu_detected(lcore_id);
-		if (lcore_config[lcore_id].detected == 0) {
-			config->lcore_role[lcore_id] = ROLE_OFF;
-			continue;
-		}
-
-		/* By default, lcore 1:1 map to cpu id */
-		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
-
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = ROLE_RTE;
-		lcore_config[lcore_id].core_id = cpu_core_id(lcore_id);
-		lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id);
-		if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES)
-#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID
-			lcore_config[lcore_id].socket_id = 0;
-#else
-			rte_panic("Socket ID (%u) is greater than "
-				"RTE_MAX_NUMA_NODES (%d)\n",
-				lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES);
-#endif
-		RTE_LOG(DEBUG, EAL, "Detected lcore %u as core %u on socket %u\n",
-				lcore_id,
-				lcore_config[lcore_id].core_id,
-				lcore_config[lcore_id].socket_id);
-		count ++;
-	}
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n",
-		RTE_MAX_LCORE);
-	RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count);
-
-	return 0;
-}
-- 
2.4.2

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

* [dpdk-dev] [PATCH v10 2/3] eal: deduplicate timer functions
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization Thomas Monjalon
@ 2015-07-27  0:56   ` Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 3/3] eal: deduplicate memory initialization Thomas Monjalon
  2015-07-27  0:59   ` [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions Thomas Monjalon
  3 siblings, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:56 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

From: Ravi Kerur <rkerur@gmail.com>

Move common functions from BSD/Linux to eal_common_timer.c.
BSD uses sysctl and Linux uses CLOCK_MONOTIC_RAW to calibrate TSC.
HPET is specific to Linux and not integrated in the common init.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |  1 +
 lib/librte_eal/bsdapp/eal/eal_timer.c              | 58 ++--------------
 .../eal/eal_timer.c => common/eal_common_timer.c}  | 79 +++-------------------
 lib/librte_eal/common/eal_private.h                | 14 ++++
 lib/librte_eal/linuxapp/eal/Makefile               |  1 +
 lib/librte_eal/linuxapp/eal/eal_timer.c            | 60 ++--------------
 6 files changed, 39 insertions(+), 174 deletions(-)
 copy lib/librte_eal/{bsdapp/eal/eal_timer.c => common/eal_common_timer.c} (57%)

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 24733ae..a969435 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -61,6 +61,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/bsdapp/eal/eal_timer.c
index 7147abe..f12d9bd 100644
--- a/lib/librte_eal/bsdapp/eal/eal_timer.c
+++ b/lib/librte_eal/bsdapp/eal/eal_timer.c
@@ -55,29 +55,12 @@
 
 enum timer_source eal_timer_source = EAL_TIMER_TSC;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
 uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
-static int
-set_tsc_freq_from_sysctl(void)
+get_tsc_freq(void)
 {
 	size_t sz;
 	int tmp;
+	uint64_t tsc_hz;
 
 	sz = sizeof(tmp);
 	tmp = 0;
@@ -94,42 +77,13 @@ set_tsc_freq_from_sysctl(void)
 	else if (tmp != 1)
 		RTE_LOG(WARNING, EAL, "TSC is not invariant\n");
 
-	sz = sizeof(eal_tsc_resolution_hz);
-	if (sysctlbyname("machdep.tsc_freq", &eal_tsc_resolution_hz, &sz, NULL, 0)) {
+	sz = sizeof(tsc_hz);
+	if (sysctlbyname("machdep.tsc_freq", &tsc_hz, &sz, NULL, 0)) {
 		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
-		return -1;
+		return 0;
 	}
 
-	return 0;
-}
-
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. Read the TSC frequency value provided by the kernel
- * 2. If above does not work, just sleep for 1 second and tune off that,
- *    printing a warning about inaccuracy of timing
- */
-static void
-set_tsc_freq(void)
-{
-	if (set_tsc_freq_from_sysctl() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
+	return tsc_hz;
 }
 
 int
diff --git a/lib/librte_eal/bsdapp/eal/eal_timer.c b/lib/librte_eal/common/eal_common_timer.c
similarity index 57%
copy from lib/librte_eal/bsdapp/eal/eal_timer.c
copy to lib/librte_eal/common/eal_common_timer.c
index 7147abe..2956703 100644
--- a/lib/librte_eal/bsdapp/eal/eal_timer.c
+++ b/lib/librte_eal/common/eal_common_timer.c
@@ -30,6 +30,7 @@
  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -41,22 +42,11 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_cycles.h>
-#include <rte_memory.h>
-#include <rte_memzone.h>
-#include <rte_eal.h>
-#include <rte_debug.h>
 
 #include "eal_private.h"
-#include "eal_internal_cfg.h"
-
-#ifdef RTE_LIBEAL_USE_HPET
-#warning HPET is not supported in FreeBSD
-#endif
-
-enum timer_source eal_timer_source = EAL_TIMER_TSC;
 
 /* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
+static uint64_t eal_tsc_resolution_hz;
 
 void
 rte_delay_us(unsigned us)
@@ -73,68 +63,21 @@ rte_get_tsc_hz(void)
 	return eal_tsc_resolution_hz;
 }
 
-static int
-set_tsc_freq_from_sysctl(void)
+static uint64_t
+estimate_tsc_freq(void)
 {
-	size_t sz;
-	int tmp;
-
-	sz = sizeof(tmp);
-	tmp = 0;
-
-	if (sysctlbyname("kern.timecounter.smp_tsc", &tmp, &sz, NULL, 0))
-		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
-	else if (tmp != 1)
-		RTE_LOG(WARNING, EAL, "TSC is not safe to use in SMP mode\n");
-
-	tmp = 0;
-
-	if (sysctlbyname("kern.timecounter.invariant_tsc", &tmp, &sz, NULL, 0))
-		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
-	else if (tmp != 1)
-		RTE_LOG(WARNING, EAL, "TSC is not invariant\n");
-
-	sz = sizeof(eal_tsc_resolution_hz);
-	if (sysctlbyname("machdep.tsc_freq", &eal_tsc_resolution_hz, &sz, NULL, 0)) {
-		RTE_LOG(WARNING, EAL, "%s\n", strerror(errno));
-		return -1;
-	}
-
-	return 0;
-}
-
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
+	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
+		" - clock timings may be less accurate.\n");
 	/* assume that the sleep(1) will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
 	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
+	return rte_rdtsc() - start;
 }
 
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. Read the TSC frequency value provided by the kernel
- * 2. If above does not work, just sleep for 1 second and tune off that,
- *    printing a warning about inaccuracy of timing
- */
-static void
+void
 set_tsc_freq(void)
 {
-	if (set_tsc_freq_from_sysctl() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
-}
-
-int
-rte_eal_timer_init(void)
-{
-	set_tsc_freq();
-	return 0;
+	uint64_t freq = get_tsc_freq() || estimate_tsc_freq();
+	RTE_LOG(INFO, EAL, "TSC frequency is ~%" PRIu64 " KHz\n", freq / 1000);
+	eal_tsc_resolution_hz = freq;
 }
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 8505b05..f8e8869 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -314,4 +314,18 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
  */
 int eal_cpu_detected(unsigned lcore_id);
 
+/**
+ * Set TSC frequency from precise value or estimation
+ *
+ * This function is private to the EAL.
+ */
+void set_tsc_freq(void);
+
+/**
+ * Get precise TSC frequency from system
+ *
+ * This function is private to the EAL.
+ */
+uint64_t get_tsc_freq(void);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index f4f8cdf..376d275 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -71,6 +71,7 @@ endif
 
 # from common dir
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c
index 94909ed..76a8a65 100644
--- a/lib/librte_eal/linuxapp/eal/eal_timer.c
+++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
@@ -57,9 +57,6 @@
 
 enum timer_source eal_timer_source = EAL_TIMER_HPET;
 
-/* The frequency of the RDTSC timer resolution */
-static uint64_t eal_tsc_resolution_hz = 0;
-
 #ifdef RTE_LIBEAL_USE_HPET
 
 #define DEV_HPET "/dev/hpet"
@@ -160,23 +157,6 @@ rte_get_hpet_cycles(void)
 
 #endif
 
-
-void
-rte_delay_us(unsigned us)
-{
-	const uint64_t start = rte_get_timer_cycles();
-	const uint64_t ticks = (uint64_t)us * rte_get_timer_hz() / 1E6;
-	while ((rte_get_timer_cycles() - start) < ticks)
-		rte_pause();
-}
-
-uint64_t
-rte_get_tsc_hz(void)
-{
-	return eal_tsc_resolution_hz;
-}
-
-
 #ifdef RTE_LIBEAL_USE_HPET
 /*
  * Open and mmap /dev/hpet (high precision event timer) that will
@@ -275,8 +255,8 @@ check_tsc_flags(void)
 	fclose(stream);
 }
 
-static int
-set_tsc_freq_from_clock(void)
+uint64_t
+get_tsc_freq(void)
 {
 #ifdef CLOCK_MONOTONIC_RAW
 #define NS_PER_SEC 1E9
@@ -284,6 +264,7 @@ set_tsc_freq_from_clock(void)
 	struct timespec sleeptime = {.tv_nsec = 5E8 }; /* 1/2 second */
 
 	struct timespec t_start, t_end;
+	uint64_t tsc_hz;
 
 	if (clock_gettime(CLOCK_MONOTONIC_RAW, &t_start) == 0) {
 		uint64_t ns, end, start = rte_rdtsc();
@@ -294,40 +275,11 @@ set_tsc_freq_from_clock(void)
 		ns += (t_end.tv_nsec - t_start.tv_nsec);
 
 		double secs = (double)ns/NS_PER_SEC;
-		eal_tsc_resolution_hz = (uint64_t)((end - start)/secs);
-		return 0;
+		tsc_hz = (uint64_t)((end - start)/secs);
+		return tsc_hz;
 	}
 #endif
-	return -1;
-}
-
-static void
-set_tsc_freq_fallback(void)
-{
-	RTE_LOG(WARNING, EAL, "WARNING: clock_gettime cannot use "
-			"CLOCK_MONOTONIC_RAW and HPET is not available"
-			" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
-	uint64_t start = rte_rdtsc();
-	sleep(1);
-	eal_tsc_resolution_hz = rte_rdtsc() - start;
-}
-/*
- * This function measures the TSC frequency. It uses a variety of approaches.
- *
- * 1. If kernel provides CLOCK_MONOTONIC_RAW we use that to tune the TSC value
- * 2. If kernel does not provide that, and we have HPET support, tune using HPET
- * 3. Lastly, if neither of the above can be used, just sleep for 1 second and
- * tune off that, printing a warning about inaccuracy of timing
- */
-static void
-set_tsc_freq(void)
-{
-	if (set_tsc_freq_from_clock() < 0)
-		set_tsc_freq_fallback();
-
-	RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
-			eal_tsc_resolution_hz/1000);
+	return 0;
 }
 
 int
-- 
2.4.2

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

* [dpdk-dev] [PATCH v10 3/3] eal: deduplicate memory initialization
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization Thomas Monjalon
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 2/3] eal: deduplicate timer functions Thomas Monjalon
@ 2015-07-27  0:56   ` Thomas Monjalon
  2015-07-27  0:59   ` [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions Thomas Monjalon
  3 siblings, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:56 UTC (permalink / raw)
  To: david.marchand; +Cc: dev

From: Ravi Kerur <rkerur@gmail.com>

Move common functions from BSD/Linux to eal_common_memory.c file.
BSD uses contigmem kernel module and Linux uses /proc/self/pagemap file.

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 lib/librte_eal/bsdapp/eal/eal_memory.c    | 39 ++-------------
 lib/librte_eal/common/eal_common_memory.c | 38 ++++++++++++++-
 lib/librte_eal/common/eal_private.h       | 18 +++++++
 lib/librte_eal/linuxapp/eal/eal_memory.c  | 80 ++++++++++---------------------
 4 files changed, 81 insertions(+), 94 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c
index a3242a5..937e8db 100644
--- a/lib/librte_eal/bsdapp/eal/eal_memory.c
+++ b/lib/librte_eal/bsdapp/eal/eal_memory.c
@@ -59,7 +59,7 @@ rte_mem_virt2phy(const void *virtaddr)
 	return RTE_BAD_PHYS_ADDR;
 }
 
-static int
+int
 rte_eal_contigmem_init(void)
 {
 	struct rte_mem_config *mcfg;
@@ -132,8 +132,8 @@ rte_eal_contigmem_init(void)
 	return 0;
 }
 
-static int
-rte_eal_contigmem_attach(void)
+int
+rte_eal_hugepage_attach(void)
 {
 	const struct hugepage_info *hpi;
 	int fd_hugepage_info, fd_hugepage = -1;
@@ -192,36 +192,3 @@ error:
 		close(fd_hugepage);
 	return -1;
 }
-
-
-static int
-rte_eal_memdevice_init(void)
-{
-	struct rte_config *config;
-
-	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-		return 0;
-
-	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_config.force_nchannel;
-	config->mem_config->nrank = internal_config.force_nrank;
-
-	return 0;
-}
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
-	const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-			rte_eal_contigmem_init() :
-			rte_eal_contigmem_attach();
-	if (retval < 0)
-		return -1;
-
-	if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-		return -1;
-
-	return 0;
-}
diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 9a07b1e..b647573 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -45,6 +45,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
@@ -69,7 +70,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;
 
@@ -89,7 +90,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;
 
@@ -118,3 +119,36 @@ 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 ?
+			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;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index f8e8869..072e672 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -328,4 +328,22 @@ void set_tsc_freq(void);
  */
 uint64_t get_tsc_freq(void);
 
+/**
+ * Prepare physical memory mapping
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_init(void);
+
+/**
+ * Creates memory mapping in secondary process
+ * i.e. hugepages on Linux and
+ *      contigmem on BSD.
+ *
+ * This function is private to the EAL.
+ */
+int rte_eal_hugepage_attach(void);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index d529016..ac2745e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -115,6 +115,24 @@ static unsigned proc_pagemap_readable;
 
 #define RANDOMIZE_VA_SPACE_FILE "/proc/sys/kernel/randomize_va_space"
 
+static void
+test_proc_pagemap_readable(void)
+{
+	int fd = open("/proc/self/pagemap", O_RDONLY);
+
+	if (fd < 0) {
+		RTE_LOG(ERR, EAL,
+			"Cannot open /proc/self/pagemap: %s. "
+			"virt2phys address translation will not work\n",
+			strerror(errno));
+		return;
+	}
+
+	/* Is readable */
+	close(fd);
+	proc_pagemap_readable = 1;
+}
+
 /* Lock page in physical memory and prevent from swapping. */
 int
 rte_mem_lock_page(const void *virt)
@@ -1037,7 +1055,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;
@@ -1054,6 +1072,8 @@ rte_eal_hugepage_init(void)
 	int new_pages_count[MAX_HUGEPAGE_SIZES];
 #endif
 
+	test_proc_pagemap_readable();
+
 	memset(used_hp, 0, sizeof(used_hp));
 
 	/* get pointer to global configuration */
@@ -1087,7 +1107,6 @@ rte_eal_hugepage_init(void)
 #endif
 	}
 
-
 	/* calculate total number of hugepages available. at this point we haven't
 	 * yet started sorting them so they all are on socket 0 */
 	for (i = 0; i < (int) internal_config.num_hugepage_sizes; i++) {
@@ -1378,7 +1397,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;
@@ -1395,6 +1414,8 @@ rte_eal_hugepage_attach(void)
 				"into secondary processes\n");
 	}
 
+	test_proc_pagemap_readable();
+
 	if (internal_config.xen_dom0_support) {
 #ifdef RTE_LIBRTE_XEN_DOM0
 		if (rte_xen_dom0_memory_attach() < 0) {
@@ -1538,56 +1559,3 @@ error:
 		close(fd_hugepage);
 	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;
-}
-
-static int
-test_proc_pagemap_readable(void)
-{
-	int fd = open("/proc/self/pagemap", O_RDONLY);
-
-	if (fd < 0)
-		return 0;
-	/* Is readable */
-	close(fd);
-
-	return 1;
-}
-
-/* init memory subsystem */
-int
-rte_eal_memory_init(void)
-{
-	RTE_LOG(INFO, EAL, "Setting up memory...\n");
-
-	proc_pagemap_readable = test_proc_pagemap_readable();
-	if (!proc_pagemap_readable)
-		RTE_LOG(ERR, EAL,
-			"Cannot open /proc/self/pagemap: %s. "
-			"virt2phys address translation will not work\n",
-			strerror(errno));
-
-	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;
-}
-- 
2.4.2

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

* Re: [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions
  2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
                     ` (2 preceding siblings ...)
  2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 3/3] eal: deduplicate memory initialization Thomas Monjalon
@ 2015-07-27  0:59   ` Thomas Monjalon
  2015-07-30  8:12     ` Olivier MATZ
  3 siblings, 1 reply; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-27  0:59 UTC (permalink / raw)
  To: rkerur; +Cc: dev

2015-07-27 02:56, Thomas Monjalon:
> v9 was a subset of previous deduplications by Ravi Kerur.
> This v10 address the comments I've done on v9.
> 
> Ravi Kerur (3):
>   eal: deduplicate lcore initialization
>   eal: deduplicate timer functions
>   eal: deduplicate memory initialization

Applied shortly to integrate this old pending cleanup in RC2.

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

* Re: [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions
  2015-07-27  0:59   ` [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions Thomas Monjalon
@ 2015-07-30  8:12     ` Olivier MATZ
  2015-07-30 12:15       ` Ravi Kerur
  2015-07-30 13:43       ` Thomas Monjalon
  0 siblings, 2 replies; 16+ messages in thread
From: Olivier MATZ @ 2015-07-30  8:12 UTC (permalink / raw)
  To: Thomas Monjalon, rkerur; +Cc: dev

Hi Thomas & Ravi,

On 07/27/2015 02:59 AM, Thomas Monjalon wrote:
> 2015-07-27 02:56, Thomas Monjalon:
>> v9 was a subset of previous deduplications by Ravi Kerur.
>> This v10 address the comments I've done on v9.
>>
>> Ravi Kerur (3):
>>    eal: deduplicate lcore initialization
>>    eal: deduplicate timer functions
>>    eal: deduplicate memory initialization
>
> Applied shortly to integrate this old pending cleanup in RC2.
>

When I try to compile the dpdk for x86_x32-native-linuxapp-gcc , I
get the following compilation error:

   CC eal_common_timer.o
In file included from /usr/include/sys/sysctl.h:63:0,
                  from 
/home/matz/dpdk-pkg-cron/dpdk.org/lib/librte_eal/common/eal_common_timer.c:39:
/usr/include/bits/sysctl.h:19:3: error: #error "sysctl system call is 
unsupported in x32 kernel"
  # error "sysctl system call is unsupported in x32 kernel"
    ^

Removing the "#include <sys/sysctl.h>" line fixes the issue without
impacting the compilation. I think this include is not needed and
could be removed.
I can provide a patch if it's ok for you.

Regards,
Olivier

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

* Re: [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions
  2015-07-30  8:12     ` Olivier MATZ
@ 2015-07-30 12:15       ` Ravi Kerur
  2015-07-30 13:43       ` Thomas Monjalon
  1 sibling, 0 replies; 16+ messages in thread
From: Ravi Kerur @ 2015-07-30 12:15 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

Hi Olivier,


On Thu, Jul 30, 2015 at 1:12 AM, Olivier MATZ <olivier.matz@6wind.com>
wrote:

> Hi Thomas & Ravi,
>
>
> On 07/27/2015 02:59 AM, Thomas Monjalon wrote:
>
>> 2015-07-27 02:56, Thomas Monjalon:
>>
>>> v9 was a subset of previous deduplications by Ravi Kerur.
>>> This v10 address the comments I've done on v9.
>>>
>>> Ravi Kerur (3):
>>>    eal: deduplicate lcore initialization
>>>    eal: deduplicate timer functions
>>>    eal: deduplicate memory initialization
>>>
>>
>> Applied shortly to integrate this old pending cleanup in RC2.
>>
>>
> When I try to compile the dpdk for x86_x32-native-linuxapp-gcc , I
> get the following compilation error:
>
>   CC eal_common_timer.o
> In file included from /usr/include/sys/sysctl.h:63:0,
>                  from /home/matz/dpdk-pkg-cron/
> dpdk.org/lib/librte_eal/common/eal_common_timer.c:39:
> /usr/include/bits/sysctl.h:19:3: error: #error "sysctl system call is
> unsupported in x32 kernel"
>  # error "sysctl system call is unsupported in x32 kernel"
>    ^
>
> Removing the "#include <sys/sysctl.h>" line fixes the issue without
> impacting the compilation. I think this include is not needed and
> could be removed.
> I can provide a patch if it's ok for you.
>
>
If it compiles fine on FreeBSD then it should be fine. It primarily needed
for eal_timer.c in FreeBSD environment, during code movement it slipped
through my mind. Sorry for the inconvenience.

Thanks,
Ravi


> Regards,
> Olivier
>
>

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

* Re: [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions
  2015-07-30  8:12     ` Olivier MATZ
  2015-07-30 12:15       ` Ravi Kerur
@ 2015-07-30 13:43       ` Thomas Monjalon
  1 sibling, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2015-07-30 13:43 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev

2015-07-30 10:12, Olivier MATZ:
> Hi Thomas & Ravi,
> 
> On 07/27/2015 02:59 AM, Thomas Monjalon wrote:
> > 2015-07-27 02:56, Thomas Monjalon:
> >> v9 was a subset of previous deduplications by Ravi Kerur.
> >> This v10 address the comments I've done on v9.
> >>
> >> Ravi Kerur (3):
> >>    eal: deduplicate lcore initialization
> >>    eal: deduplicate timer functions
> >>    eal: deduplicate memory initialization
> >
> > Applied shortly to integrate this old pending cleanup in RC2.
> >
> 
> When I try to compile the dpdk for x86_x32-native-linuxapp-gcc , I
> get the following compilation error:
> 
>    CC eal_common_timer.o
> In file included from /usr/include/sys/sysctl.h:63:0,
>                   from 
> /home/matz/dpdk-pkg-cron/dpdk.org/lib/librte_eal/common/eal_common_timer.c:39:
> /usr/include/bits/sysctl.h:19:3: error: #error "sysctl system call is 
> unsupported in x32 kernel"
>   # error "sysctl system call is unsupported in x32 kernel"
>     ^
> 
> Removing the "#include <sys/sysctl.h>" line fixes the issue without
> impacting the compilation. I think this include is not needed and
> could be removed.
> I can provide a patch if it's ok for you.

After fixing another build issue on FreeBSD (patch sent), it builds well
without sys/sysctl.h.
So it seems to be an useless inclusion.

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

end of thread, other threads:[~2015-07-30 13:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-25 19:34 [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
2015-07-25 19:36 ` [dpdk-dev] [PATCH v9 1/3] Move common functions in eal_lcore.c Ravi Kerur
2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 2/3] Move common functions in eal_timer.c Ravi Kerur
2015-07-26 23:32     ` Thomas Monjalon
2015-07-26 23:40     ` Thomas Monjalon
2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 3/3] Move common functions in eal_memory.c Ravi Kerur
2015-07-27  0:35     ` Thomas Monjalon
2015-07-25 19:36   ` [dpdk-dev] [PATCH v9 0/3] Move EAL common functions Ravi Kerur
2015-07-27  0:56 ` [dpdk-dev] [PATCH v10 0/3] deduplicate " Thomas Monjalon
2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization Thomas Monjalon
2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 2/3] eal: deduplicate timer functions Thomas Monjalon
2015-07-27  0:56   ` [dpdk-dev] [PATCH v10 3/3] eal: deduplicate memory initialization Thomas Monjalon
2015-07-27  0:59   ` [dpdk-dev] [PATCH v10 0/3] deduplicate EAL common functions Thomas Monjalon
2015-07-30  8:12     ` Olivier MATZ
2015-07-30 12:15       ` Ravi Kerur
2015-07-30 13:43       ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).