* [PATCH 0/3] Add env vars for session and cpu-affinity
@ 2024-08-22 8:07 Simon Graber
2024-08-22 8:07 ` [PATCH 1/3] lib/copperplate: Get session name from env var Simon Graber
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Simon Graber @ 2024-08-22 8:07 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Simon Graber
Hello,
This patch set introduces two environment variables, for session
and cpu-affinity. This is to avoid having to pass them as args which
was suboptimal for larger projects with many helper programs.
The first two patches in lib/ add checks for the presence of env vars,
the third patch utilizes these for the alchemy tests.
Simon Graber (3):
lib/copperplate: Get session name from env var
lib/boilerplate: Get cpu-affinity from env var
alchemytests: Set cpu-affinity by env var
lib/boilerplate/setup.c | 16 +++++++++++++++
lib/copperplate/init.c | 21 ++++++++++++++------
testsuite/smokey/alchemytests/alchemytests.c | 10 +++++++++-
3 files changed, 40 insertions(+), 7 deletions(-)
--
2.46.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 8:07 [PATCH 0/3] Add env vars for session and cpu-affinity Simon Graber @ 2024-08-22 8:07 ` Simon Graber 2024-08-22 10:51 ` Jan Kiszka 2024-08-22 8:07 ` [PATCH 2/3] lib/boilerplate: Get cpu-affinity " Simon Graber 2024-08-22 8:07 ` [PATCH 3/3] alchemytests: Set cpu-affinity by " Simon Graber 2 siblings, 1 reply; 10+ messages in thread From: Simon Graber @ 2024-08-22 8:07 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. 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 16fc59f..e695c52 100644 --- a/lib/copperplate/init.c +++ b/lib/copperplate/init.c @@ -114,19 +114,28 @@ static int get_session_root(int *regflags_r) { char *sessdir, *session; struct passwd *pw; + char *sn_env; int ret; pw = getpwuid(geteuid()); if (pw == NULL) return -errno; + sn_env = getenv("XENO_SESSION_NAME"); 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, '/')) { + 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] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 8:07 ` [PATCH 1/3] lib/copperplate: Get session name from env var Simon Graber @ 2024-08-22 10:51 ` Jan Kiszka 2024-08-22 10:57 ` Richard Weinberger 2024-08-22 11:38 ` Simon 0 siblings, 2 replies; 10+ messages in thread From: Jan Kiszka @ 2024-08-22 10:51 UTC (permalink / raw) To: Simon Graber, xenomai; +Cc: upstream+xenomai On 22.08.24 10:07, Simon Graber wrote: > 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. Hmm, did we discuss priorities already, and did I say that this ordering would be best? Then I'm no longer that sure, and my feeling is rather that env should overrule command line. Still looking for other examples, though. > > 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 16fc59f..e695c52 100644 > --- a/lib/copperplate/init.c > +++ b/lib/copperplate/init.c > @@ -114,19 +114,28 @@ static int get_session_root(int *regflags_r) > { > char *sessdir, *session; > struct passwd *pw; > + char *sn_env; > int ret; > > pw = getpwuid(geteuid()); > if (pw == NULL) > return -errno; > > + sn_env = getenv("XENO_SESSION_NAME"); Why fetching sn_env uncondtionally? > 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, '/')) { > + 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; > } Jan -- Siemens AG, Technology Linux Expert Center ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 10:51 ` Jan Kiszka @ 2024-08-22 10:57 ` Richard Weinberger 2024-08-22 10:59 ` Jan Kiszka 2024-08-22 11:38 ` Simon 1 sibling, 1 reply; 10+ messages in thread From: Richard Weinberger @ 2024-08-22 10:57 UTC (permalink / raw) To: Simon Graber, xenomai, upstream+xenomai, Jan Kiszka Am Donnerstag, 22. August 2024, 12:51:34 CEST schrieb 'Jan Kiszka' via upstream: > On 22.08.24 10:07, Simon Graber wrote: > > 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. > > Hmm, did we discuss priorities already, and did I say that this ordering > would be best? Then I'm no longer that sure, and my feeling is rather > that env should overrule command line. Still looking for other examples, > though. I remember, but the other way around. Env overruling commandline seems not natural too me. Passing --session= to an application and seeing no effect is not user friendly. IMHO, the environment should be a default/fallback. Thanks, //richard -- sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr: ATU 66964118 | FN: 374287y ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 10:57 ` Richard Weinberger @ 2024-08-22 10:59 ` Jan Kiszka 2024-08-22 11:16 ` Richard Weinberger 0 siblings, 1 reply; 10+ messages in thread From: Jan Kiszka @ 2024-08-22 10:59 UTC (permalink / raw) To: Richard Weinberger, Simon Graber, xenomai, upstream+xenomai On 22.08.24 12:57, Richard Weinberger wrote: > Am Donnerstag, 22. August 2024, 12:51:34 CEST schrieb 'Jan Kiszka' via upstream: >> On 22.08.24 10:07, Simon Graber wrote: >>> 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. >> >> Hmm, did we discuss priorities already, and did I say that this ordering >> would be best? Then I'm no longer that sure, and my feeling is rather >> that env should overrule command line. Still looking for other examples, >> though. > > I remember, but the other way around. > Env overruling commandline seems not natural too me. > Passing --session= to an application and seeing no effect is not > user friendly. > IMHO, the environment should be a default/fallback. > I'm all for least surprise, that's why I'm looking for existing patterns now, rather than personal (my included) feelings. Jan -- Siemens AG, Technology Linux Expert Center ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 10:59 ` Jan Kiszka @ 2024-08-22 11:16 ` Richard Weinberger 2024-08-22 12:35 ` Jan Kiszka 0 siblings, 1 reply; 10+ messages in thread From: Richard Weinberger @ 2024-08-22 11:16 UTC (permalink / raw) To: Simon Graber, xenomai, upstream+xenomai, Jan Kiszka Am Donnerstag, 22. August 2024, 12:59:54 CEST schrieb Jan Kiszka: > On 22.08.24 12:57, Richard Weinberger wrote: > > Am Donnerstag, 22. August 2024, 12:51:34 CEST schrieb 'Jan Kiszka' via upstream: > >> On 22.08.24 10:07, Simon Graber wrote: > >>> 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. > >> > >> Hmm, did we discuss priorities already, and did I say that this ordering > >> would be best? Then I'm no longer that sure, and my feeling is rather > >> that env should overrule command line. Still looking for other examples, > >> though. > > > > I remember, but the other way around. > > Env overruling commandline seems not natural too me. > > Passing --session= to an application and seeing no effect is not > > user friendly. > > IMHO, the environment should be a default/fallback. > > > > I'm all for least surprise, that's why I'm looking for existing patterns > now, rather than personal (my included) feelings. AFAIK, at least git, curl and GNU make give command line options precedence over environment. Thanks, //richard -- sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr: ATU 66964118 | FN: 374287y ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 11:16 ` Richard Weinberger @ 2024-08-22 12:35 ` Jan Kiszka 0 siblings, 0 replies; 10+ messages in thread From: Jan Kiszka @ 2024-08-22 12:35 UTC (permalink / raw) To: Richard Weinberger, Simon Graber, xenomai, upstream+xenomai On 22.08.24 13:16, Richard Weinberger wrote: > Am Donnerstag, 22. August 2024, 12:59:54 CEST schrieb Jan Kiszka: >> On 22.08.24 12:57, Richard Weinberger wrote: >>> Am Donnerstag, 22. August 2024, 12:51:34 CEST schrieb 'Jan Kiszka' via upstream: >>>> On 22.08.24 10:07, Simon Graber wrote: >>>>> 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. >>>> >>>> Hmm, did we discuss priorities already, and did I say that this ordering >>>> would be best? Then I'm no longer that sure, and my feeling is rather >>>> that env should overrule command line. Still looking for other examples, >>>> though. >>> >>> I remember, but the other way around. >>> Env overruling commandline seems not natural too me. >>> Passing --session= to an application and seeing no effect is not >>> user friendly. >>> IMHO, the environment should be a default/fallback. >>> >> >> I'm all for least surprise, that's why I'm looking for existing patterns >> now, rather than personal (my included) feelings. > > AFAIK, at least git, curl and GNU make give command line options precedence > over environment. > Good points, then let's keep it like proposed. BTW, all those new variables still have to be documented. Jan -- Siemens AG, Technology Linux Expert Center ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] lib/copperplate: Get session name from env var 2024-08-22 10:51 ` Jan Kiszka 2024-08-22 10:57 ` Richard Weinberger @ 2024-08-22 11:38 ` Simon 1 sibling, 0 replies; 10+ messages in thread From: Simon @ 2024-08-22 11:38 UTC (permalink / raw) To: Jan Kiszka, xenomai; +Cc: upstream+xenomai On 8/22/24 12:51, Jan Kiszka wrote: > On 22.08.24 10:07, Simon Graber wrote: >> 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. > Hmm, did we discuss priorities already, and did I say that this ordering > would be best? Then I'm no longer that sure, and my feeling is rather > that env should overrule command line. Still looking for other examples, > though. > >> 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 16fc59f..e695c52 100644 >> --- a/lib/copperplate/init.c >> +++ b/lib/copperplate/init.c >> @@ -114,19 +114,28 @@ static int get_session_root(int *regflags_r) >> { >> char *sessdir, *session; >> struct passwd *pw; >> + char *sn_env; >> int ret; >> >> pw = getpwuid(geteuid()); >> if (pw == NULL) >> return -errno; >> >> + sn_env = getenv("XENO_SESSION_NAME"); > Why fetching sn_env uncondtionally? Right, that's only needed in one branch. I'll include this in v2 once I know whether args or env should take priority. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] lib/boilerplate: Get cpu-affinity from env var 2024-08-22 8:07 [PATCH 0/3] Add env vars for session and cpu-affinity Simon Graber 2024-08-22 8:07 ` [PATCH 1/3] lib/copperplate: Get session name from env var Simon Graber @ 2024-08-22 8:07 ` Simon Graber 2024-08-22 8:07 ` [PATCH 3/3] alchemytests: Set cpu-affinity by " Simon Graber 2 siblings, 0 replies; 10+ messages in thread From: Simon Graber @ 2024-08-22 8:07 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/boilerplate/setup.c b/lib/boilerplate/setup.c index 26c8c4c..4249cd2 100644 --- a/lib/boilerplate/setup.c +++ b/lib/boilerplate/setup.c @@ -383,6 +383,19 @@ void xenomai_usage(void) fprintf(stderr, "--help display help\n"); } +static int get_affinity_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 +573,9 @@ 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 */ + get_affinity_env(); + /* * Parse the base options first, to bootstrap the core with * the right config values. -- 2.46.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] alchemytests: Set cpu-affinity by env var 2024-08-22 8:07 [PATCH 0/3] Add env vars for session and cpu-affinity Simon Graber 2024-08-22 8:07 ` [PATCH 1/3] lib/copperplate: Get session name from env var Simon Graber 2024-08-22 8:07 ` [PATCH 2/3] lib/boilerplate: Get cpu-affinity " Simon Graber @ 2024-08-22 8:07 ` Simon Graber 2 siblings, 0 replies; 10+ messages in thread From: Simon Graber @ 2024-08-22 8:07 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 inidvidual test programs. 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 cf9f970..edbafe6 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] 10+ messages in thread
end of thread, other threads:[~2024-08-22 12:36 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-22 8:07 [PATCH 0/3] Add env vars for session and cpu-affinity Simon Graber 2024-08-22 8:07 ` [PATCH 1/3] lib/copperplate: Get session name from env var Simon Graber 2024-08-22 10:51 ` Jan Kiszka 2024-08-22 10:57 ` Richard Weinberger 2024-08-22 10:59 ` Jan Kiszka 2024-08-22 11:16 ` Richard Weinberger 2024-08-22 12:35 ` Jan Kiszka 2024-08-22 11:38 ` Simon 2024-08-22 8:07 ` [PATCH 2/3] lib/boilerplate: Get cpu-affinity " Simon Graber 2024-08-22 8:07 ` [PATCH 3/3] alchemytests: Set cpu-affinity by " Simon Graber
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.