* [PATCH v4 1/4] lib/copperplate: Get session name from env var
2024-09-02 13:11 [PATCH v4 0/4] Add env vars for session and cpu-affinity Simon Graber
@ 2024-09-02 13:11 ` Simon Graber
2024-09-02 13:11 ` [PATCH v4 2/4] lib/boilerplate: Get cpu-affinity " Simon Graber
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Simon Graber @ 2024-09-02 13:11 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Simon Graber
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.
Signed-off-by: Simon Graber <simon.graber@sigma-star.at>
---
lib/copperplate/init.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 16fc59f7a..01969cfea 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -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;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 2/4] lib/boilerplate: Get cpu-affinity from env var
2024-09-02 13:11 [PATCH v4 0/4] Add env vars for session and cpu-affinity Simon Graber
2024-09-02 13:11 ` [PATCH v4 1/4] lib/copperplate: Get session name from env var Simon Graber
@ 2024-09-02 13:11 ` Simon Graber
2024-09-02 13:11 ` [PATCH v4 3/4] alchemytests: Set cpu-affinity by " Simon Graber
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Simon Graber @ 2024-09-02 13:11 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Simon Graber
It 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.
Signed-off-by: Simon Graber <simon.graber@sigma-star.at>
---
lib/boilerplate/setup.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 26c8c4cf5..9573a546f 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -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.
--
2.46.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
2024-09-02 13:11 [PATCH v4 0/4] Add env vars for session and cpu-affinity Simon Graber
2024-09-02 13:11 ` [PATCH v4 1/4] lib/copperplate: Get session name from env var Simon Graber
2024-09-02 13:11 ` [PATCH v4 2/4] lib/boilerplate: Get cpu-affinity " Simon Graber
@ 2024-09-02 13:11 ` Simon Graber
2024-10-15 10:02 ` Jan Kiszka
2024-09-02 13:11 ` [PATCH v4 4/4] Add documentation for env vars Simon Graber
2024-09-02 13:25 ` [PATCH v4 0/4] Add env vars for session and cpu-affinity Jan Kiszka
4 siblings, 1 reply; 9+ messages in thread
From: Simon Graber @ 2024-09-02 13:11 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Simon Graber
The 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.
Signed-off-by: Simon Graber <simon.graber@sigma-star.at>
---
testsuite/smokey/alchemytests/alchemytests.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/testsuite/smokey/alchemytests/alchemytests.c b/testsuite/smokey/alchemytests/alchemytests.c
index cf9f970f1..edbafe6e7 100644
--- a/testsuite/smokey/alchemytests/alchemytests.c
+++ b/testsuite/smokey/alchemytests/alchemytests.c
@@ -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)
--
2.46.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
2024-09-02 13:11 ` [PATCH v4 3/4] alchemytests: Set cpu-affinity by " Simon Graber
@ 2024-10-15 10:02 ` Jan Kiszka
2024-10-15 10:04 ` Richard Weinberger
0 siblings, 1 reply; 9+ messages in thread
From: Jan Kiszka @ 2024-10-15 10:02 UTC (permalink / raw)
To: Simon Graber, xenomai; +Cc: upstream+xenomai
On 02.09.24 15:11, Simon Graber wrote:
> The 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.
>
> Signed-off-by: Simon Graber <simon.graber@sigma-star.at>
> ---
> testsuite/smokey/alchemytests/alchemytests.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/testsuite/smokey/alchemytests/alchemytests.c b/testsuite/smokey/alchemytests/alchemytests.c
> index cf9f970f1..edbafe6e7 100644
> --- a/testsuite/smokey/alchemytests/alchemytests.c
> +++ b/testsuite/smokey/alchemytests/alchemytests.c
> @@ -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)
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
--
Siemens AG, Technology
Linux Expert Center
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
2024-10-15 10:02 ` Jan Kiszka
@ 2024-10-15 10:04 ` Richard Weinberger
2024-10-15 15:24 ` Jan Kiszka
0 siblings, 1 reply; 9+ messages in thread
From: Richard Weinberger @ 2024-10-15 10:04 UTC (permalink / raw)
To: Simon Graber, xenomai, upstream+xenomai; +Cc: Jan Kiszka
Am Dienstag, 15. Oktober 2024, 12:02:01 CEST schrieb 'Jan Kiszka' via upstream:
> 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?
I'll. Simon was our intern this summer. :-)
Thanks,
//richard
--
sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT
UID/VAT Nr: ATU 66964118 | FN: 374287y
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 3/4] alchemytests: Set cpu-affinity by env var
2024-10-15 10:04 ` Richard Weinberger
@ 2024-10-15 15:24 ` Jan Kiszka
0 siblings, 0 replies; 9+ messages in thread
From: Jan Kiszka @ 2024-10-15 15:24 UTC (permalink / raw)
To: Richard Weinberger, Simon Graber, xenomai, upstream+xenomai
On 15.10.24 12:04, Richard Weinberger wrote:
> Am Dienstag, 15. Oktober 2024, 12:02:01 CEST schrieb 'Jan Kiszka' via upstream:
>> 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?
>
> 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
--
Siemens AG, Technology
Linux Expert Center
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/4] Add documentation for env vars
2024-09-02 13:11 [PATCH v4 0/4] Add env vars for session and cpu-affinity Simon Graber
` (2 preceding siblings ...)
2024-09-02 13:11 ` [PATCH v4 3/4] alchemytests: Set cpu-affinity by " Simon Graber
@ 2024-09-02 13:11 ` Simon Graber
2024-09-02 13:25 ` [PATCH v4 0/4] Add env vars for session and cpu-affinity Jan Kiszka
4 siblings, 0 replies; 9+ messages in thread
From: Simon Graber @ 2024-09-02 13:11 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Simon Graber
Usage 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.
Signed-off-by: Simon Graber <simon.graber@sigma-star.at>
---
doc/asciidoc/README.INSTALL.adoc | 7 ++++---
lib/boilerplate/setup.c | 22 +++++++++++++---------
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/doc/asciidoc/README.INSTALL.adoc b/doc/asciidoc/README.INSTALL.adoc
index d2b7e6f78..52bef566d 100644
--- a/doc/asciidoc/README.INSTALL.adoc
+++ b/doc/asciidoc/README.INSTALL.adoc
@@ -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+.
diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c
index 9573a546f..7bb24f6f4 100644
--- a/lib/boilerplate/setup.c
+++ b/lib/boilerplate/setup.c
@@ -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)
--
2.46.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v4 0/4] Add env vars for session and cpu-affinity
2024-09-02 13:11 [PATCH v4 0/4] Add env vars for session and cpu-affinity Simon Graber
` (3 preceding siblings ...)
2024-09-02 13:11 ` [PATCH v4 4/4] Add documentation for env vars Simon Graber
@ 2024-09-02 13:25 ` Jan Kiszka
4 siblings, 0 replies; 9+ messages in thread
From: Jan Kiszka @ 2024-09-02 13:25 UTC (permalink / raw)
To: Simon Graber, xenomai; +Cc: upstream+xenomai
On 02.09.24 15:11, Simon Graber wrote:
> 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(-)
>
Thanks, applied.
Jan
--
Siemens AG, Technology
Linux Expert Center
^ permalink raw reply [flat|nested] 9+ messages in thread