[dpdk-dev] [PATCH dpdk-dev 1/2] eal: introduce last-init queue for libraries initialization
xiangxia.m.yue at gmail.com
xiangxia.m.yue at gmail.com
Thu Apr 9 12:52:59 CEST 2020
From: Tonghao Zhang <xiangxia.m.yue at gmail.com>
This patch introduces last-init queue, user can register a
callback for theirs initialization. Running rte_last_init_run(),
the almost resource of DPDK are available, such as memzone, ring.
With this way, user don't introduce additional codes in eal layer.
[This patch will be used for next patch.]
Signed-off-by: Tonghao Zhang <xiangxia.m.yue at gmail.com>
---
lib/librte_eal/common/eal_common_last_init.c | 43 ++++++++++++++++++++++++++++
lib/librte_eal/common/meson.build | 1 +
lib/librte_eal/freebsd/Makefile | 1 +
lib/librte_eal/freebsd/eal.c | 7 +++++
lib/librte_eal/include/rte_last_init.h | 36 +++++++++++++++++++++++
lib/librte_eal/linux/Makefile | 1 +
lib/librte_eal/linux/eal.c | 8 ++++++
7 files changed, 97 insertions(+)
create mode 100644 lib/librte_eal/common/eal_common_last_init.c
create mode 100644 lib/librte_eal/include/rte_last_init.h
diff --git a/lib/librte_eal/common/eal_common_last_init.c b/lib/librte_eal/common/eal_common_last_init.c
new file mode 100644
index 0000000..4f168e9
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_last_init.c
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 DPDK Community
+ */
+
+#include <sys/queue.h>
+
+#include <rte_last_init.h>
+#include <rte_debug.h>
+
+static struct rte_last_init_list rte_last_init_list =
+ TAILQ_HEAD_INITIALIZER(rte_last_init_list);
+
+void
+rte_last_init_register(rte_last_init_cb cb, const void *arg)
+{
+ struct rte_last_init *last;
+
+ RTE_VERIFY(cb);
+
+ last = malloc(sizeof(*last));
+ if (last == NULL)
+ rte_panic("Alloc memory for rte_last_init node failed\n");
+
+ last->cb = cb;
+ last->arg = arg;
+
+ TAILQ_INSERT_TAIL(&rte_last_init_list, last, next);
+}
+
+int
+rte_last_init_run(void)
+{
+ struct rte_last_init *init;
+ int ret;
+
+ TAILQ_FOREACH(init, &rte_last_init_list, next) {
+ ret = init->cb(init->arg);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build
index 02d9280..8107b24 100644
--- a/lib/librte_eal/common/meson.build
+++ b/lib/librte_eal/common/meson.build
@@ -43,6 +43,7 @@ sources += files(
'eal_common_thread.c',
'eal_common_timer.c',
'eal_common_uuid.c',
+ 'eal_common_last_init.c',
'hotplug_mp.c',
'malloc_elem.c',
'malloc_heap.c',
diff --git a/lib/librte_eal/freebsd/Makefile b/lib/librte_eal/freebsd/Makefile
index e5d4d8f..63cb0b9 100644
--- a/lib/librte_eal/freebsd/Makefile
+++ b/lib/librte_eal/freebsd/Makefile
@@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_thread.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_last_init.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c
SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_elem.c
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 6ae37e7..b51615f 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -44,6 +44,7 @@
#include <rte_option.h>
#include <rte_atomic.h>
#include <malloc_heap.h>
+#include <rte_last_init.h>
#include "eal_private.h"
#include "eal_thread.h"
@@ -874,6 +875,12 @@ static void rte_eal_init_alert(const char *msg)
eal_check_mem_on_local_socket();
+ if (rte_last_init_run() < 0) {
+ rte_eal_init_alert("Cannot init objects in last-init queue");
+ rte_errno = EFAULT;
+ return -1;
+ }
+
eal_thread_init_master(rte_config.master_lcore);
ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
diff --git a/lib/librte_eal/include/rte_last_init.h b/lib/librte_eal/include/rte_last_init.h
new file mode 100644
index 0000000..8c91a97
--- /dev/null
+++ b/lib/librte_eal/include/rte_last_init.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 DPDK Community
+ */
+
+#ifndef _RTE_LAST_INIT_H_
+#define _RTE_LAST_INIT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <sys/queue.h>
+
+typedef int (*rte_last_init_cb)(const void *arg);
+
+/**
+ * A structure describing a generic initialization.
+ */
+struct rte_last_init {
+ TAILQ_ENTRY(rte_last_init) next; /**< Next bus object in linked list */
+ const void *arg;
+ rte_last_init_cb cb;
+};
+
+/** Double linked list of buses */
+TAILQ_HEAD(rte_last_init_list, rte_last_init);
+
+void rte_last_init_register(rte_last_init_cb cb, const void *arg);
+int rte_last_init_run(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_LAST_INIT_H_ */
diff --git a/lib/librte_eal/linux/Makefile b/lib/librte_eal/linux/Makefile
index e5f4495..3a476a7 100644
--- a/lib/librte_eal/linux/Makefile
+++ b/lib/librte_eal/linux/Makefile
@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_thread.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_last_init.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_elem.c
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 9530ee5..61fc540 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -51,6 +51,7 @@
#include <malloc_heap.h>
#include <rte_vfio.h>
#include <rte_option.h>
+#include <rte_last_init.h>
#include "eal_private.h"
#include "eal_thread.h"
@@ -1203,6 +1204,13 @@ static void rte_eal_init_alert(const char *msg)
eal_check_mem_on_local_socket();
+
+ if (rte_last_init_run() < 0) {
+ rte_eal_init_alert("Cannot init objects in last-init queue");
+ rte_errno = EFAULT;
+ return -1;
+ }
+
eal_thread_init_master(rte_config.master_lcore);
ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
--
1.8.3.1
More information about the dev
mailing list