[1/2] eal: introduce last-init queue for libraries initialization
diff mbox series

Message ID 1586429580-6990-1-git-send-email-xiangxia.m.yue@gmail.com
State Superseded, archived
Delegated to: David Marchand
Headers show
Series
  • [1/2] eal: introduce last-init queue for libraries initialization
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/iol-testing fail Testing issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/checkpatch warning coding style issues

Commit Message

Tonghao Zhang April 9, 2020, 10:52 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@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@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

Comments

Jerin Jacob April 9, 2020, 11:31 a.m. UTC | #1
On Thu, Apr 9, 2020 at 4:24 PM <xiangxia.m.yue@gmail.com> wrote:
>
> From: Tonghao Zhang <xiangxia.m.yue@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@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 +++++++++++++++++++++++

Update doc/api/doxy-api-index.md and hook to documenion.

> +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));

Does not look like this memory is NOT freed anywhere.

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

> +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;
> +};

No need to expose this structure. Move to eal_private.h


> +
> +/** Double linked list of buses */
> +TAILQ_HEAD(rte_last_init_list, rte_last_init);

No need to expose this structure. Move to eal_private.h

> +
> +void rte_last_init_register(rte_last_init_cb cb, const void *arg);

Add Doxygen comment.

Should we change to rte_init_register()? add an enum to specify where to
call this RTE_INIT_PRE, RTE_INIT_POST to take care of the future needs.
Just thought of bringing this point to make sure we can use this
scheme for another use case IF ANY.


> +int rte_last_init_run(void);

No need to expose this function in public API. Move to eal_private.h.
Please start the internal functions with eal_(dont use rte_ for
internal functions)
Tonghao Zhang April 9, 2020, 3:04 p.m. UTC | #2
On Thu, Apr 9, 2020 at 7:31 PM Jerin Jacob <jerinjacobk@gmail.com> wrote:
>
> On Thu, Apr 9, 2020 at 4:24 PM <xiangxia.m.yue@gmail.com> wrote:
> >
> > From: Tonghao Zhang <xiangxia.m.yue@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@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 +++++++++++++++++++++++
>
> Update doc/api/doxy-api-index.md and hook to documenion.
>
> > +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));
>
> Does not look like this memory is NOT freed anywhere.
>
> > +       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
>
> > +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;
> > +};
>
> No need to expose this structure. Move to eal_private.h
>
>
> > +
> > +/** Double linked list of buses */
> > +TAILQ_HEAD(rte_last_init_list, rte_last_init);
>
> No need to expose this structure. Move to eal_private.h
>
> > +
> > +void rte_last_init_register(rte_last_init_cb cb, const void *arg);
>
> Add Doxygen comment.
>
> Should we change to rte_init_register()? add an enum to specify where to
> call this RTE_INIT_PRE, RTE_INIT_POST to take care of the future needs.
> Just thought of bringing this point to make sure we can use this
> scheme for another use case IF ANY.
>
>
> > +int rte_last_init_run(void);
>
> No need to expose this function in public API. Move to eal_private.h.
> Please start the internal functions with eal_(dont use rte_ for
> internal functions)
Thanks for your review, v2 is sent. thanks.

Patch
diff mbox series

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