diff mbox series

[rt-tests,v3,1/1] rt-numa: Use sched_getaffinity() instead of pthread_getaffinity_np()

Message ID 20210719081505.520-2-dwagner@suse.de
State New
Headers show
Series Fix a few fallouts | expand

Commit Message

Daniel Wagner July 19, 2021, 8:15 a.m. UTC
pthread_getaffinity_np() prevents static builds as glibc does not
expose it for this configuration. Instead use sched_getaffinity()
directly as pthread_getaffinity_np() is just a fancy glibc wrapper
around sched_getaffinity().

Static builds helps in in situation where the rootfs is minimal
and does for example not ship libnuma.

The pthread_getaffinity_np call was introduced by commit
f240656b056b ("rt-tests: cyclictest: Fix -t without a user specified
[NUM]")

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 src/lib/rt-numa.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Daniel Wagner Aug. 27, 2021, 7:31 a.m. UTC | #1
On Mon, Jul 19, 2021 at 10:15:05AM +0200, Daniel Wagner wrote:
> pthread_getaffinity_np() prevents static builds as glibc does not

> expose it for this configuration. Instead use sched_getaffinity()

> directly as pthread_getaffinity_np() is just a fancy glibc wrapper

> around sched_getaffinity().

> 

> Static builds helps in in situation where the rootfs is minimal

> and does for example not ship libnuma.

> 

> The pthread_getaffinity_np call was introduced by commit

> f240656b056b ("rt-tests: cyclictest: Fix -t without a user specified

> [NUM]")


ping
John Kacur Aug. 27, 2021, 5:09 p.m. UTC | #2
On Mon, 19 Jul 2021, Daniel Wagner wrote:

> pthread_getaffinity_np() prevents static builds as glibc does not

> expose it for this configuration. Instead use sched_getaffinity()

> directly as pthread_getaffinity_np() is just a fancy glibc wrapper

> around sched_getaffinity().

> 

> Static builds helps in in situation where the rootfs is minimal

> and does for example not ship libnuma.

> 

> The pthread_getaffinity_np call was introduced by commit

> f240656b056b ("rt-tests: cyclictest: Fix -t without a user specified

> [NUM]")

> 

> Signed-off-by: Daniel Wagner <dwagner@suse.de>

> ---

>  src/lib/rt-numa.c | 6 ++----

>  1 file changed, 2 insertions(+), 4 deletions(-)

> 

> diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c

> index babcc634d57e..bb0121a65eca 100644

> --- a/src/lib/rt-numa.c

> +++ b/src/lib/rt-numa.c

> @@ -68,15 +68,13 @@ int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)

>  int cpu_for_thread_ua(int thread_num, int max_cpus)

>  {

>  	int res, num_cpus, i, m, cpu;

> -	pthread_t thread;

>  	cpu_set_t cpuset;

>  

> -	thread = pthread_self();

>  	CPU_ZERO(&cpuset);

>  

> -	res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);

> +	res = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);

>  	if (res != 0)

> -		fatal("pthread_getaffinity_np failed: %s\n", strerror(res));

> +		fatal("sched_getaffinity failed: %s\n", strerror(res));

>  

>  	num_cpus = CPU_COUNT(&cpuset);

>  	m = thread_num % num_cpus;

> -- 

> 2.32.0

> 

> 


-Some minor fixes to the description
Signed-off-by: John Kacur <jkacur@redhat.com>
Daniel Wagner Aug. 29, 2021, 7:58 p.m. UTC | #3
Hi John,

On Fri, Aug 27, 2021 at 01:09:41PM -0400, John Kacur wrote:
> -Some minor fixes to the description


Thanks a lot. Do you plan to do a release soon? I'd like to update the
versions in LAVA's test-definition test suite. And it's way simpler to
base it on a released version.

Thanks,
Daniel
John Kacur Aug. 30, 2021, 12:54 p.m. UTC | #4
On Sun, 29 Aug 2021, Daniel Wagner wrote:

> Hi John,

> 

> On Fri, Aug 27, 2021 at 01:09:41PM -0400, John Kacur wrote:

> > -Some minor fixes to the description

> 

> Thanks a lot. Do you plan to do a release soon? I'd like to update the

> versions in LAVA's test-definition test suite. And it's way simpler to

> base it on a released version.

> 

> Thanks,

> Daniel

> 


I hadn't planned on doing so, but I can do so if it will help you out.
I can probably get to this, this afternoon my time, or if not, then 
tomorrow.

Could you provide a link to LAVA again so I don't have to go looking for 
it.?

Thanks

John
Daniel Wagner Aug. 30, 2021, 1:10 p.m. UTC | #5
Hi John,

On Mon, Aug 30, 2021 at 08:54:18AM -0400, John Kacur wrote:
> I hadn't planned on doing so, but I can do so if it will help you out.

> I can probably get to this, this afternoon my time, or if not, then 

> tomorrow.


Great. Thanks!

> Could you provide a link to LAVA again so I don't have to go looking for 

> it.?


  https://github.com/Linaro/test-definitions

and the main script for cyclictest is here:

  https://github.com/Linaro/test-definitions/tree/master/automated/linux/cyclictest

There is the 'bin' folder which contains a static build binary. I know,
this is a bit strange. I'll try to argue with upstream and see if we get
this dropped eventually. But for this update I'd like to get the JSON
output feature enabled first and not get lost in the discussion why the
static build binary should be dropped.

BTW, I've queued the JSON changes in my tree:

  https://github.com/igaw/test-definitions/tree/rt-tests-json

I think I could get this ready before Plumbers, so that we can discuss
the next steps during a MC/BoF.

Thanks,
Daniel
diff mbox series

Patch

diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c
index babcc634d57e..bb0121a65eca 100644
--- a/src/lib/rt-numa.c
+++ b/src/lib/rt-numa.c
@@ -68,15 +68,13 @@  int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask)
 int cpu_for_thread_ua(int thread_num, int max_cpus)
 {
 	int res, num_cpus, i, m, cpu;
-	pthread_t thread;
 	cpu_set_t cpuset;
 
-	thread = pthread_self();
 	CPU_ZERO(&cpuset);
 
-	res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+	res = sched_getaffinity(0, sizeof(cpu_set_t), &cpuset);
 	if (res != 0)
-		fatal("pthread_getaffinity_np failed: %s\n", strerror(res));
+		fatal("sched_getaffinity failed: %s\n", strerror(res));
 
 	num_cpus = CPU_COUNT(&cpuset);
 	m = thread_num % num_cpus;