From: John Kacur <jkacur@redhat.com>
To: Jonathan Schwender <schwenderjonathan@gmail.com>
Cc: williams@redhat.com, linux-rt-users@vger.kernel.org
Subject: Re: [PATCH v3 1/2] cyclictest: Move main pid setaffinity handling into a function
Date: Fri, 7 May 2021 13:07:21 -0400 (EDT) [thread overview]
Message-ID: <851142bc-eadf-e89-821a-c4bd9fe567b@redhat.com> (raw)
In-Reply-To: <7204424803922d15bb11bba65bb5672cd76aa20c.1616702706.git.schwenderjonathan@gmail.com>
On Thu, 25 Mar 2021, Jonathan Schwender wrote:
> Move error handling for setting the affinity of the main pid
> into a separate function.
> This prevents duplicating the code in the next commit,
> where the main thread pid can be restricted to one of
> two bitmasks depending on the passed parameters.
>
> After feedback from John Kacur, the function is now
> located in src/lib/rt-numa.c.
> This allows other tests to reuse this, if they also
> prefer to warn if numa_sched_setaffinity fails.
>
> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
> ---
> src/cyclictest/cyclictest.c | 8 +-------
> src/include/rt-numa.h | 2 ++
> src/lib/rt-numa.c | 11 +++++++++++
> 3 files changed, 14 insertions(+), 7 deletions(-)
>
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index dca9610..460f6ae 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -1791,13 +1791,7 @@ int main(int argc, char **argv)
>
> /* Restrict the main pid to the affinity specified by the user */
> if (affinity_mask != NULL) {
> - int res;
> -
> - errno = 0;
> - res = numa_sched_setaffinity(getpid(), affinity_mask);
> - if (res != 0)
> - warn("Couldn't setaffinity in main thread: %s\n", strerror(errno));
> -
> + try_numa_sched_setaffinity(getpid(), affinity_mask);
> if (verbose)
> printf("Using %u cpus.\n",
> numa_bitmask_weight(affinity_mask));
> diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h
> index ca86a45..e9fa312 100644
> --- a/src/include/rt-numa.h
> +++ b/src/include/rt-numa.h
> @@ -18,4 +18,6 @@ int cpu_for_thread_ua(int thread_num, int max_cpus);
>
> int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask);
>
> +void try_numa_sched_setaffinity(__pid_t pid, struct bitmask *cpumask);
> +
> #endif
> diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
> index babcc63..9a81cfb 100644
> --- a/src/lib/rt-numa.c
> +++ b/src/lib/rt-numa.c
> @@ -138,3 +138,14 @@ int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask)
>
> return 0;
> }
> +
> +void try_numa_sched_setaffinity(pid_t pid, struct bitmask *cpumask)
> +{
> + int res;
> +
> + errno = 0;
> + res = numa_sched_setaffinity(pid, cpumask);
> + if (res != 0)
> + warn("Couldn't setaffinity for thread %d: %s\n", pid,
> + strerror(errno));
> +}
> --
> 2.30.2
>
>
Yuck. My bad, this is some pretty inelegant error code wrapped around a
numa call, I don't think it really warrents trying to make an API out of
it. That said, I might need to do this anyway, when I put back code that
can run when numa is not available on a target machine.
For now, can you just leave this inline and respin?
Thanks
John Kacur
next prev parent reply other threads:[~2021-05-07 17:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 20:18 [PATCH v3 0/2] rt-tests: cyclictest: Add option to specify main pid affinity Jonathan Schwender
2021-03-25 20:18 ` [PATCH v3 1/2] cyclictest: Move main pid setaffinity handling into a function Jonathan Schwender
2021-05-07 17:07 ` John Kacur [this message]
2021-03-25 20:18 ` [PATCH v3 2/2] cyclictest: Add --mainaffinity=[CPUSET] option Jonathan Schwender
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=851142bc-eadf-e89-821a-c4bd9fe567b@redhat.com \
--to=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=schwenderjonathan@gmail.com \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).