[FIX-OPTION-2,1/2] eal: use named memzone to store user mempool ops name

Message ID 1517558582-27108-1-git-send-email-hemant.agrawal@nxp.com
State New
Headers show
Series
  • [FIX-OPTION-2,1/2] eal: use named memzone to store user mempool ops name
Related show

Commit Message

Hemant Agrawal Feb. 2, 2018, 8:03 a.m.
The new mbuf pool ops name API uses the named memzone to store different
types of configured mempool ops name. It is better to also save the user
configured mempool ops name in named memzone. This way the best mempool
ops name can easily get the user configured mempool ops name for it's
decisions.

This will also avoid the need to maintain a eal api for default mempool
ops name. 

Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>

---
 lib/librte_eal/bsdapp/eal/Makefile         |  1 +
 lib/librte_eal/bsdapp/eal/eal.c            |  5 +++
 lib/librte_eal/common/eal_common_mempool.c | 50 ++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h        | 12 +++++++
 lib/librte_eal/common/meson.build          |  1 +
 lib/librte_eal/linuxapp/eal/Makefile       |  1 +
 lib/librte_eal/linuxapp/eal/eal.c          |  5 +++
 7 files changed, 75 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common_mempool.c

-- 
2.7.4

Patch

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index dd455e6..f07dace 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -38,6 +38,7 @@  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_mempool.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memory.c
diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 1622a41..2c33a60 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -621,6 +621,11 @@  rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	if (rte_eal_mempool_ops_config() < 0) {
+		rte_eal_init_alert("Cannot config user Mempool Ops\n");
+		return -1;
+	}
+
 	eal_check_mem_on_local_socket();
 
 	eal_thread_init_master(rte_config.master_lcore);
diff --git a/lib/librte_eal/common/eal_common_mempool.c b/lib/librte_eal/common/eal_common_mempool.c
new file mode 100644
index 0000000..1d10a75
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_mempool.c
@@ -0,0 +1,50 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2018 NXP
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <inttypes.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/queue.h>
+
+#include <rte_memory.h>
+#include <rte_eal.h>
+#include <rte_log.h>
+#include <rte_errno.h>
+#include <rte_memzone.h>
+
+#include "eal_private.h"
+#include "eal_internal_cfg.h"
+
+/* init mempool ops */
+int
+rte_eal_mempool_ops_config(void)
+{
+	RTE_LOG(DEBUG, EAL, "Configuring user mempool ops name...\n");
+
+	/* secondary processes don't need to initialise anything */
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
+		return 0;
+
+	if (internal_config.user_mbuf_pool_ops_name) {
+		const struct rte_memzone *mz;
+
+		mz = rte_memzone_lookup("mbuf_user_pool_ops");
+		if (mz == NULL) {
+			mz = rte_memzone_reserve("mbuf_user_pool_ops",
+				32, SOCKET_ID_ANY, 0);
+			if (mz == NULL)
+				return -rte_errno;
+		}
+
+		strncpy(mz->addr, internal_config.user_mbuf_pool_ops_name,
+			strlen(internal_config.user_mbuf_pool_ops_name));
+	}
+
+	return 0;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 0b28770..76beaff 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -205,4 +205,16 @@  struct rte_bus *rte_bus_find_by_device_name(const char *str);
 
 int rte_mp_channel_init(void);
 
+/**
+ * Mempool ops configuration
+ *
+ * This function is private to EAL.
+ *
+ * Set the user defined mempool ops in the named memzone area.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int rte_eal_mempool_ops_config(void);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build
index 82b8910..3c6125b 100644
--- a/lib/librte_eal/common/meson.build
+++ b/lib/librte_eal/common/meson.build
@@ -16,6 +16,7 @@  common_sources = files(
 	'eal_common_lcore.c',
 	'eal_common_log.c',
 	'eal_common_memory.c',
+	'eal_common_mempool.c',
 	'eal_common_memzone.c',
 	'eal_common_options.c',
 	'eal_common_proc.c',
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 7e5bbe8..83a08b0 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -46,6 +46,7 @@  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_mempool.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memory.c
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 451fdaf..42a79d1 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -877,6 +877,11 @@  rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	if (rte_eal_mempool_ops_config() < 0) {
+		rte_eal_init_alert("Cannot config user Mempool Ops\n");
+		return -1;
+	}
+
 	eal_check_mem_on_local_socket();
 
 	eal_thread_init_master(rte_config.master_lcore);