linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cyclictest: Fix --affinity when intermediate CPUs are offline
@ 2021-01-14 11:50 Jonathan Schwender
  2021-01-22 23:45 ` John Kacur
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Schwender @ 2021-01-14 11:50 UTC (permalink / raw)
  To: jkacur, williams; +Cc: linux-rt-users

Use max_cpus = sysconf(_SC_NPROCESSORS_CONF) to determine the number of
the maximum CPU (+1).
The cpu_for_thread_*() functions check the first max_cpus bits
in the cpuset / cpumask.
This fixes failing to set the affinity to CPUs >= num_online_cpus,
if some intermediate CPU is offline, e.g. on an AMD system
with nosmt.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
---
 src/cyclictest/cyclictest.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
index f38c453..b104e4c 100644
--- a/src/cyclictest/cyclictest.c
+++ b/src/cyclictest/cyclictest.c
@@ -1741,7 +1741,8 @@ int main(int argc, char **argv)
 	int signum = SIGALRM;
 	int mode;
 	int cpu;
-	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
+	int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 	int i, ret = -1;
 	int status;
 
@@ -1750,8 +1751,10 @@ int main(int argc, char **argv)
 	if (check_privs())
 		exit(EXIT_FAILURE);
 
-	if (verbose)
+	if (verbose) {
 		printf("Max CPUs = %d\n", max_cpus);
+		printf("Online CPUs = %d\n", online_cpus);
+	}
 
 	/* Restrict the main pid to the affinity specified by the user */
 	if (affinity_mask != NULL) {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cyclictest: Fix --affinity when intermediate CPUs are offline
  2021-01-14 11:50 [PATCH] cyclictest: Fix --affinity when intermediate CPUs are offline Jonathan Schwender
@ 2021-01-22 23:45 ` John Kacur
  0 siblings, 0 replies; 2+ messages in thread
From: John Kacur @ 2021-01-22 23:45 UTC (permalink / raw)
  To: Jonathan Schwender; +Cc: williams, linux-rt-users



On Thu, 14 Jan 2021, Jonathan Schwender wrote:

> Use max_cpus = sysconf(_SC_NPROCESSORS_CONF) to determine the number of
> the maximum CPU (+1).
> The cpu_for_thread_*() functions check the first max_cpus bits
> in the cpuset / cpumask.
> This fixes failing to set the affinity to CPUs >= num_online_cpus,
> if some intermediate CPU is offline, e.g. on an AMD system
> with nosmt.
> 
> Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
> ---
>  src/cyclictest/cyclictest.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c
> index f38c453..b104e4c 100644
> --- a/src/cyclictest/cyclictest.c
> +++ b/src/cyclictest/cyclictest.c
> @@ -1741,7 +1741,8 @@ int main(int argc, char **argv)
>  	int signum = SIGALRM;
>  	int mode;
>  	int cpu;
> -	int max_cpus = sysconf(_SC_NPROCESSORS_ONLN);
> +	int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
> +	int online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
>  	int i, ret = -1;
>  	int status;
>  
> @@ -1750,8 +1751,10 @@ int main(int argc, char **argv)
>  	if (check_privs())
>  		exit(EXIT_FAILURE);
>  
> -	if (verbose)
> +	if (verbose) {
>  		printf("Max CPUs = %d\n", max_cpus);
> +		printf("Online CPUs = %d\n", online_cpus);
> +	}
>  
>  	/* Restrict the main pid to the affinity specified by the user */
>  	if (affinity_mask != NULL) {
> -- 
> 2.29.2
> 
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

Thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-22 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 11:50 [PATCH] cyclictest: Fix --affinity when intermediate CPUs are offline Jonathan Schwender
2021-01-22 23:45 ` John Kacur

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).