Add env vars for session and cpu-affinity
v4 cover Add env vars for session and cpu-affinity
Hello,
Revision 4 of this patchset clarifies the purpose of patch 3.
Changes since v1:
* Usage of environment variables is documented
* lib/copperplate/init.c: Conditionally query XENO_SESSION_NAME
* Reformat patch 2 to adhere to code style
* Reword commit message of patch 3
Simon Graber (4):
lib/copperplate: Get session name from env var
lib/boilerplate: Get cpu-affinity from env var
alchemytests: Set cpu-affinity by env var
Add documentation for env vars
doc/asciidoc/README.INSTALL.adoc | 7 ++-- lib/boilerplate/setup.c | 39 +++++++++++++++----- lib/copperplate/init.c | 21 ++++++++--- testsuite/smokey/alchemytests/alchemytests.c | 10 ++++- 4 files changed, 58 insertions(+), 19 deletions(-)
Signature · 1 line
2.46.0
PATCH v4 1/4 lib/copperplate: Get session name from env var
At present, for two Xenomai processes to share resources, they must be started with identical --session= parameters.
This is cumbersome for extensive projects involving numerous helper processes. This commit allows the specification of the session name via a global environment variable, namely XENO_SESSION_NAME. The --session= parameter overrules the environment variable.
In a later patch, the --vm argument will be passed via an env var too.
--- lib/copperplate/init.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
lib/copperplate/init.c +15 -6
@@ -114,6 +114,7 @@ static int get_session_root(int *regflags_r) {char *sessdir, *session;struct passwd *pw; +char *sn_env;int ret; pw =getpwuid (geteuid ());
@@ -121,12 +122,20 @@ static int get_session_root(int *regflags_r)return -errno;if (__copperplate_setup_data.session_label ==NULL ) { - ret =asprintf (&session,"anon@%d" , __node_id); -if (ret <0 ) -return -ENOMEM ; - __copperplate_setup_data.session_label = session; - *regflags_r |=REGISTRY_ANON ; - }else if (strchr (__copperplate_setup_data.session_label,'/' )) { + sn_env =getenv ("XENO_SESSION_NAME" ); +if (sn_env) { + __copperplate_setup_data.session_label =strdup (sn_env); +if (__copperplate_setup_data.session_label ==NULL ) +return -ENOMEM ; + }else { + ret =asprintf (&session,"anon@%d" , __node_id); +if (ret <0 ) +return -ENOMEM ; + __copperplate_setup_data.session_label = session; + *regflags_r |=REGISTRY_ANON ; + } + } +if (strchr (__copperplate_setup_data.session_label,'/' )) {warning ("session name may not contain slashes" );return -EINVAL ; }
Signature · 1 line
2.46.0
PATCH v4 2/4 lib/boilerplate: Get cpu-affinity from env var
In reply to Simon GraberIt might be helpful to specify the cpu-affinity via an env var, XENO_CPU_AFFINITY.
This commit adds a helper function, called in __xenomai_init. The --cpu-affinity= parameter overrules the environment variable.
--- lib/boilerplate/setup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
lib/boilerplate/setup.c +17 -0
@@ -383,6 +383,18 @@ void xenomai_usage(void)fprintf (stderr,"--help display help\n" ); } +static int set_affinity_from_env (void ) +{ +char *affinity_env; +int ret =0 ; + + affinity_env =getenv ("XENO_CPU_AFFINITY" ); +if (affinity_env) + ret =collect_cpu_affinity (affinity_env); + +return ret; +} +static int parse_base_options (int *argcp,char **uargv,const struct option *options,int base_opt_start)
@@ -560,6 +572,11 @@ static void __xenomai_init(int *argcp, char *const **argvp, const char *me)/* Retrieve the default CPU affinity. */ retrieve_default_cpu_affinity (); +/* Environment variables can be overruled by arguments */ + ret =set_affinity_from_env (); +if (ret) + goto fail; +/* * Parse the base options first, to bootstrap the core with * the right config values.
Signature · 1 line
2.46.0
PATCH v4 3/4 alchemytests: Set cpu-affinity by env var
In reply to Simon GraberThe alchemy test runner can now make use of the XENO_CPU_AFFINITY environment variable by setting it before dispatching to the individual test programs.
While not changing anything user-visibly, this stresses the new interface in CI and allows in a later commit to pass the --vm argument via an env var too, removing command line injection from this test case.
--- testsuite/smokey/alchemytests/alchemytests.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
testsuite/smokey/alchemytests/alchemytests.c +9 -1
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <string.h> +#include <stdlib.h> #include <smokey/smokey.h> static const char *const tests[] = {
@@ -31,12 +32,19 @@ static const char * const tests[] = {static int run_alchemytests (struct smokey_test *t,int argc,char *const argv[]) { -const char *args ="--vm --cpu-affinity=0" ;const char *const mod ="xeno_rtipc" ; +const char *args ="--vm" ;int test_ret =0 ;int ret =0 ;int tmp; + ret =setenv ("XENO_CPU_AFFINITY" ,"0" ,0 ); +if (ret !=0 ) { +fprintf (stderr,"%s failed to set XENO_CPU_AFFINITY: %m\n" , + __func__); +return ret; + } +/* Try loading the xeno_rtipc module as the pipe test depends on it */ tmp =smokey_modprobe (mod, true);if (tmp)
Signature · 1 line
2.46.0
Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
Quoted 36 lines · Simon Graber
The alchemy test runner can now make use of the
XENO_CPU_AFFINITYenvironment variable by setting it before dispatching to the individual test programs.While not changing anything user-visibly, this stresses the new interface in CI and allows in a later commit to pass the --vm argument via an env var too, removing command line injection from this test case.
Signed-off-by Simon Graber <[email protected]>--- testsuite/smokey/alchemytests/alchemytests.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)testsuite/smokey/alchemytests/alchemytests.c +2
-1@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <string.h> +#include <stdlib.h> #include <smokey/smokey.h> static const char *const tests[] = {@@ -31,12 +32,19 @@ static const char * const tests[] = {static int run_alchemytests (struct smokey_test *t,int argc,char *const argv[]) { -const char *args ="--vm --cpu-affinity=0" ;const char *const mod ="xeno_rtipc" ; +const char *args ="--vm" ;int test_ret =0 ;int ret =0 ;int tmp;
testsuite/smokey/alchemytests/alchemytests.c static const char * const tests[] = { · line 50
Quoted 10 lines
testsuite/smokey/alchemytests/alchemytests.c +7
-0+ ret =setenv ("XENO_CPU_AFFINITY" ,"0" ,0 ); +if (ret !=0 ) { +fprintf (stderr,"%s failed to set XENO_CPU_AFFINITY: %m\n" , + __func__); +return ret; + } +/* Try loading the xeno_rtipc module as the pipe test depends on it */ tmp =smokey_modprobe (mod, true);if (tmp)
I suspect we have some regression here as I see a lot of heap-1 tests failing in qemu runners, see eg.
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918773
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918984
Could you check this?
Jan
Signature · 2 lines
Siemens AG, Technology Linux Expert Center
Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
Am Dienstag, 15. Oktober 2024, 12:02:01 CEST schrieb 'Jan Kiszka' via upstream:
Quoted 7 lines
I suspect we have some regression here as I see a lot of heap-1 tests failing in qemu runners, see eg.
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918773
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918984Could you check this?
I'll. Simon was our intern this summer. :-)
Thanks,
//richard
Signature · 2 lines
sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr: ATU 66964118 | FN: 374287y
Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
Quoted 11 lines · Richard Weinberger
Am Dienstag, 15. Oktober 2024, 12:02:01 CEST schrieb 'Jan Kiszka' via upstream:
Quoted 7 lines
I suspect we have some regression here as I see a lot of heap-1 tests failing in qemu runners, see eg.
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918773
https://source.denx.de/Xenomai/xenomai-images/-/jobs/918984Could you check this?
I'll. Simon was our intern this summer. :-)
Looks more like another on-vm issue: We are only waiting 1 ms in foreground_task for the background_task to run into its final rt_heap_alloc. If the host is busy, that may not be enough.
Jan
Signature · 2 lines
Siemens AG, Technology Linux Expert Center
PATCH v4 4/4 Add documentation for env vars
In reply to Simon GraberUsage message in lib/boilerplate/setup.c now prints XENO_CPU_AFFINITY and XENO_SESSION_NAME.
The usage of the session arg/env var are also
described in README.INSTALL.adoc.
--- doc/asciidoc/README.INSTALL.adoc | 7 ++++--- lib/boilerplate/setup.c | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-)
doc/asciidoc/README.INSTALL.adoc +4 -3
@@ -428,9 +428,10 @@ Generic configuration options (both cores) When this option is enabled, the system creates a file hierachy at `<user>/<session>/<pid>` under the registry root path, where you can access the internal state of the active real-time objects. The -session label is obtained from the --session runtime switch. If no -session name is specified, `anon@<pid>` will be used. E.g. looking at -the properties of a VxWorks task could be done as follows: +session label is obtained from the `--session` runtime switch, which +takes precedence over the environment variable `XENO_SESSION_NAME`. +If neither of these are specified, `anon@<pid>` will be used. E.g. +looking at the properties of a VxWorks task could be done as follows: If not specified in the configuration switch, the registry root path will be +/var/run/xenomai+.
lib/boilerplate/setup.c +13 -9
@@ -370,17 +370,21 @@ void xenomai_usage(void) } } -fprintf (stderr,"--cpu-affinity=<cpu[,cpu]...> set CPU affinity of threads\n" ); -fprintf (stderr,"--[no-]sanity disable/enable sanity checks\n" ); -fprintf (stderr,"--verbose[=level] set verbosity to desired level [=1]\n" ); -fprintf (stderr,"--silent, --quiet same as --verbose=0\n" ); -fprintf (stderr,"--trace[=level] set tracing to desired level [=1]\n" ); -fprintf (stderr,"--version get version information\n" ); -fprintf (stderr,"--dump-config dump configuration settings\n" ); +fprintf (stderr,"--session=<label>[/<group>] enable shared session\n" ); +fprintf (stderr,"--cpu-affinity=<cpu[,cpu]...> set CPU affinity of threads\n" ); +fprintf (stderr,"--[no-]sanity disable/enable sanity checks\n" ); +fprintf (stderr,"--verbose[=level] set verbosity to desired level [=1]\n" ); +fprintf (stderr,"--silent, --quiet same as --verbose=0\n" ); +fprintf (stderr,"--trace[=level] set tracing to desired level [=1]\n" ); +fprintf (stderr,"--version get version information\n" ); +fprintf (stderr,"--dump-config dump configuration settings\n" );#ifdef CONFIG_XENO_MERCURY -fprintf (stderr,"--no-mlock do not lock memory at init\n" ); +fprintf (stderr,"--no-mlock do not lock memory at init\n" );#endif -fprintf (stderr,"--help display help\n" ); +fprintf (stderr,"--help display help\n" ); +fprintf (stderr,"\nEnvironment variables (arguments take priority):\n" +"XENO_SESSION_NAME=<label>[/<group>] enable shared session\n" +"XENO_CPU_AFFINITY=<cpu[,cpu]...> set CPU affinity of threads\n" ); }static int set_affinity_from_env (void )
Signature · 1 line
2.46.0
Jan Kiszka
AppliedQuoted 16 lines · Simon Graber
Hello,
Revision 4 of this patchset clarifies the purpose of patch 3.
Changes since v1:
* Usage of environment variables is documented
*lib/copperplate/init.c: Conditionally queryXENO_SESSION_NAME
* Reformat patch 2 to adhere to code style
* Reword commit message of patch 3Simon Graber (4):
lib/copperplate: Get session name from env var
lib/boilerplate: Get cpu-affinity from env var
alchemytests: Set cpu-affinity by env var
Add documentation for env vars
Quoted 6 lines
doc/asciidoc/README.INSTALL.adoc | 7 ++-- lib/boilerplate/setup.c | 39 +++++++++++++++----- lib/copperplate/init.c | 21 ++++++++--- testsuite/smokey/alchemytests/alchemytests.c | 10 ++++- 4 files changed, 58 insertions(+), 19 deletions(-)
Thanks, applied.
Jan
Signature · 2 lines
Siemens AG, Technology Linux Expert Center