Skip to contentSkip to conversation

boilerplate: do not call xenomai_init 2 times

PATCH In review Ronny Meeus 2 participants 5 messages Dec 15, 2016 – Dec 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boilerplate: do not call xenomai_init 2 times

bootstrap.o is linked to the application code.
In case the execution of the static constructors is postponed in the applicaion and the auto-init feature is used, the xenomai_init is called 2 times:
- once in the path of the wrap_main
- later in the context of the static constructor

A check is already in place to not call xenomain_init when it is called from __real_main. This patch adds a check in the static constructor to skip it in case the __real_main already did the init.

lib/boilerplate/init/bootstrap.c +7 -1
@@ -26,6 +26,8 @@ static int early_argc;
 
 static char *const *early_argv;
 
+static int xenomai_init_done;
+
 const int xenomai_auto_bootstrap = 1;
 
 int __real_main(int argc, char *const argv[]);
@@ -37,8 +39,9 @@ int xenomai_main(int argc, char *const a
 {
 	if (early_argc)
 		return __real_main(early_argc, early_argv);
-	
+
 	xenomai_init(&argc, &argv);
+	xenomai_init_done = 1;
 
 	return __real_main(argc, argv);
 }
@@ -49,6 +52,9 @@ int xenomai_main(int argc, char *const a
 	ssize_t len, ret;
 	int fd, n, argc;
 
+	if (xenomai_init_done)
+		return;
+
 	len = 1024;
 
 	for (;;) {
#1 lore raw
Quoted 7 lines · Ronny Meeus

bootstrap.o is linked to the application code.
In case the execution of the static constructors is postponed in the applicaion and the auto-init feature is used, the xenomai_init is called 2 times:
- once in the path of the wrap_main
- later in the context of the static constructor

Why do you keep the auto-init feature on, given that you already control the early init code by postponing the execution of the C++ ctors? I would rather expect something like:

- build with no-auto-init
- call xenomai_init() manually from your entry point to activate the Xenomai services when you see fit.
- call the ctor init chain.

Signature · 1 line
Philippe.
#2 lore raw
Quoted 9 lines · Philippe Gerum
Quoted 7 lines · Ronny Meeus

bootstrap.o is linked to the application code.
In case the execution of the static constructors is postponed in the applicaion and the auto-init feature is used, the xenomai_init is called 2 times:
- once in the path of the wrap_main
- later in the context of the static constructor

Quoted 8 lines

Why do you keep the auto-init feature on, given that you already control the early init code by postponing the execution of the C++ ctors? I would rather expect something like:

- build with no-auto-init
- call xenomai_init() manually from your entry point to activate the Xenomai services when you see fit.
- call the ctor init chain.

We have a lot of applications, some of them postpone the execution of the constructors while others dont.
We were calling the init function ourselves before, but we would like to remove this code to keep the application code cleaner and to have less explicit dependencies.

Using the auto-init has advantages as well, one of them being that the init code of xenomai can change completely transparant for the application code.

Ronny

Quoted 2 lines

--
Philippe.

#3 lore raw
Quoted 19 lines · Ronny Meeus
Quoted 9 lines · Philippe Gerum
Quoted 7 lines · Ronny Meeus

bootstrap.o is linked to the application code.
In case the execution of the static constructors is postponed in the applicaion and the auto-init feature is used, the xenomai_init is called 2 times:
- once in the path of the wrap_main
- later in the context of the static constructor

Quoted 8 lines

Why do you keep the auto-init feature on, given that you already control the early init code by postponing the execution of the C++ ctors? I would rather expect something like:

- build with no-auto-init
- call xenomai_init() manually from your entry point to activate the Xenomai services when you see fit.
- call the ctor init chain.

Quoted 6 lines

We have a lot of applications, some of them postpone the execution of the constructors while others dont.
We were calling the init function ourselves before, but we would like to remove this code to keep the application code cleaner and to have less explicit dependencies.

It may be cleaner for your app, but this is pushing the specifics of your application to the Xenomai core, making it clumsier. I mean that the intent, purpose and function of the bootstrap code is to init the system when present. Adding a hack to nullify it instead of not adding it to the app basically turns the logic upside down, for no obvious gain.

Quoted 4 lines

Using the auto-init has advantages as well, one of them being that the init code of xenomai can change completely transparant for the application code.

I genuinely don't get your point. xenomai_init() does all the inits for Xenomai, there is nothing in the bootstrap module beyond calling this routine. I still don't understand what could be the additional advantage of having the bootstrap module in, which calling xenomai_init() would not have.

Signature · 1 line
Philippe.
#4 lore raw
Quoted 38 lines · Philippe Gerum
Quoted 19 lines · Ronny Meeus
Quoted 9 lines · Philippe Gerum
Quoted 7 lines · Ronny Meeus

bootstrap.o is linked to the application code.
In case the execution of the static constructors is postponed in the applicaion and the auto-init feature is used, the xenomai_init is called 2 times:
- once in the path of the wrap_main
- later in the context of the static constructor

Quoted 8 lines

Why do you keep the auto-init feature on, given that you already control the early init code by postponing the execution of the C++ ctors? I would rather expect something like:

- build with no-auto-init
- call xenomai_init() manually from your entry point to activate the Xenomai services when you see fit.
- call the ctor init chain.

Quoted 6 lines

We have a lot of applications, some of them postpone the execution of the constructors while others dont.
We were calling the init function ourselves before, but we would like to remove this code to keep the application code cleaner and to have less explicit dependencies.

It may be cleaner for your app, but this is pushing the specifics of your application to the Xenomai core, making it clumsier. I mean that the intent, purpose and function of the bootstrap code is to init the system when present. Adding a hack to nullify it instead of not adding it to the app basically turns the logic upside down, for no obvious gain.

Quoted 4 lines

Using the auto-init has advantages as well, one of them being that the init code of xenomai can change completely transparant for the application code.

Quoted 5 lines

I genuinely don't get your point. xenomai_init() does all the inits for Xenomai, there is nothing in the bootstrap module beyond calling this routine. I still don't understand what could be the additional advantage of having the bootstrap module in, which calling xenomai_init() would not have.

Over time the required init function has change already several times:

-  copperplate_init(argc,argv);
-  copperplate_init(&argc,&argv);
-  xenomai_init(&argc,&argv);

This means that all applications need to be adapted (small effort) but more important that there is a dependency between the application SW and the Xenomai library. Since we build Xenomai using buildroot and the application in a non-buildroot context this can be annoying. We wanted to solve this by the auto-init feature but if you don't agree we will adapt the application code and keep on using --no-auto-init.

FYI: This is how our init will look like:

#include <version.h>
#if (CONFIG_XENO_VERSION_MAJOR < 3)
#include <copperplate/init.h>
#else
#include <xenomai/init.h>
#endif

....

#if (CONFIG_XENO_VERSION_MAJOR < 3)
#ifdef USE_COPPERPLATE_INIT_VECTOR
copperplate_init(&argc,&argv);
#else
copperplate_init(argc,argv);
#endif /* USE_COPPERPLATE_INIT_VECTOR */
#else /* CONFIG_XENO_VERSION_MAJOR >= 3) */
xenomai_init(&argc,&argv);
#endif /* CONFIG_XENO_VERSION_MAJOR >= 3) */

For the above construction to work, 2 additional private patches that we need to apply are needed:
- we add a define USE_COPPERPLATE_INIT_VECTOR to the copperplate/init,h file
- in xenomai-3.03 we need to add an in include path since the version.h has moved.

By using auto-init, all this code could be removed and this would work with all versions of Xenomai that we use.

Ronny

Quoted 2 lines

--
Philippe.