public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] getcpu01: Reinstate node_id test
@ 2022-12-13  9:44 Richard Palethorpe via ltp
  2022-12-13  9:53 ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Palethorpe via ltp @ 2022-12-13  9:44 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

Presently the node_id is only checked on i386 and it is broken. The
sched_getcpu call was substituted for getcpu when
available. sched_getcpu does not have the node_id parameter, it's not
the same thing as getcpu.

Also we can check the node_id on any platform which has NUMA. Which
includes more than just x86.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Cc: Cyril Hrubis <chrubis@suse.cz>
---

V2:
* Removed all the ifdefs
* Use libc getcpu when available
* Remove kernel version check

 configure.ac                                |  1 +
 include/lapi/sched.h                        |  7 +++++
 testcases/kernel/syscalls/getcpu/getcpu01.c | 35 ++-------------------
 3 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/configure.ac b/configure.ac
index e9b15c7f7..1ab7cc60d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,7 @@ AC_CHECK_FUNCS_ONCE([ \
     fstatat \
     getauxval \
     getcontext \
+    getcpu \
     getdents \
     getdents64 \
     io_pgetevents \
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index 1d22a9d7e..1065665d1 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -70,6 +70,13 @@ static inline void clone3_supported_by_kernel(void)
 	}
 }
 
+#ifndef HAVE_GETCPU
+static inline int getcpu(unsigned *cpu, unsigned *node)
+{
+	return tst_syscall(__NR_getcpu, cpu, node, NULL);
+}
+#endif
+
 #ifndef SCHED_DEADLINE
 # define SCHED_DEADLINE	6
 #endif
diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
index fcc273e29..f6fcc4fc1 100644
--- a/testcases/kernel/syscalls/getcpu/getcpu01.c
+++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
@@ -11,26 +11,12 @@
 #define _GNU_SOURCE
 #include <dirent.h>
 #include <errno.h>
-#include <sched.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
-#include "lapi/syscalls.h"
-#include "lapi/cpuset.h"
 #include "tst_test.h"
-#include "config.h"
-
-static inline int get_cpu(unsigned *cpu_id,
-			  unsigned *node_id LTP_ATTRIBUTE_UNUSED,
-			  void *cache_struct LTP_ATTRIBUTE_UNUSED)
-{
-#ifndef HAVE_SCHED_GETCPU
-	return tst_syscall(__NR_getcpu, cpu_id, node_id, cache_struct);
-#else
-	*cpu_id = sched_getcpu();
-#endif
-	return 0;
-}
+#include "lapi/cpuset.h"
+#include "lapi/sched.h"
 
 static unsigned int max_cpuid(size_t size, cpu_set_t * set)
 {
@@ -78,7 +64,6 @@ realloc:
 	return cpu_max;
 }
 
-#ifdef __i386__
 static unsigned int get_nodeid(unsigned int cpu_id)
 {
 	DIR *directory_parent, *directory_node;
@@ -119,33 +104,26 @@ static unsigned int get_nodeid(unsigned int cpu_id)
 	}
 	return node_id;
 }
-#endif
 
 static void run(void)
 {
 	unsigned int cpu_id, node_id = 0;
 	unsigned int cpu_set;
-#ifdef __i386__
 	unsigned int node_set;
-#endif
 
 	cpu_set = set_cpu_affinity();
-#ifdef __i386__
 	node_set = get_nodeid(cpu_set);
-#endif
 
-	TEST(get_cpu(&cpu_id, &node_id, NULL));
+	TEST(getcpu(&cpu_id, &node_id));
 	if (TST_RET == 0) {
 		if (cpu_id != cpu_set)
 			tst_res(TFAIL, "getcpu() returned wrong value"
 				" expected cpuid:%d, returned value cpuid: %d",
 				cpu_set, cpu_id);
-#ifdef __i386__
 		else if (node_id != node_set)
 			tst_res(TFAIL, "getcpu() returned wrong value"
 				" expected  node id:%d returned  node id:%d",
 				node_set, node_id);
-#endif
 		else
 			tst_res(TPASS, "getcpu() returned proper"
 				" cpuid:%d, node id:%d", cpu_id,
@@ -156,13 +134,6 @@ static void run(void)
 	}
 }
 
-static void setup(void)
-{
-	if (tst_kvercmp(2, 6, 20) < 0)
-		tst_brk(TCONF, "kernel >= 2.6.20 required");
-}
-
 static struct tst_test test = {
 	.test_all = run,
-	.setup = setup,
 };
-- 
2.38.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2] getcpu01: Reinstate node_id test
  2022-12-13  9:44 [LTP] [PATCH v2] getcpu01: Reinstate node_id test Richard Palethorpe via ltp
@ 2022-12-13  9:53 ` Petr Vorel
  2022-12-13 10:00   ` xuyang2018.jy
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2022-12-13  9:53 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi Xu,

> Presently the node_id is only checked on i386 and it is broken. The
> sched_getcpu call was substituted for getcpu when
> available. sched_getcpu does not have the node_id parameter, it's not
> the same thing as getcpu.

> Also we can check the node_id on any platform which has NUMA. Which
> includes more than just x86.

> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
> Cc: Cyril Hrubis <chrubis@suse.cz>
> ---

> V2:
> * Removed all the ifdefs
> * Use libc getcpu when available
> * Remove kernel version check

>  configure.ac                                |  1 +
>  include/lapi/sched.h                        |  7 +++++
>  testcases/kernel/syscalls/getcpu/getcpu01.c | 35 ++-------------------
>  3 files changed, 11 insertions(+), 32 deletions(-)

> diff --git a/configure.ac b/configure.ac
> index e9b15c7f7..1ab7cc60d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -101,6 +101,7 @@ AC_CHECK_FUNCS_ONCE([ \
>      fstatat \
>      getauxval \
>      getcontext \
> +    getcpu \
>      getdents \
>      getdents64 \
>      io_pgetevents \
> diff --git a/include/lapi/sched.h b/include/lapi/sched.h
> index 1d22a9d7e..1065665d1 100644
> --- a/include/lapi/sched.h
> +++ b/include/lapi/sched.h
> @@ -70,6 +70,13 @@ static inline void clone3_supported_by_kernel(void)
>  	}
>  }

> +#ifndef HAVE_GETCPU
> +static inline int getcpu(unsigned *cpu, unsigned *node)
> +{
> +	return tst_syscall(__NR_getcpu, cpu, node, NULL);
> +}
> +#endif
> +
>  #ifndef SCHED_DEADLINE
>  # define SCHED_DEADLINE	6
>  #endif
> diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
> index fcc273e29..f6fcc4fc1 100644
> --- a/testcases/kernel/syscalls/getcpu/getcpu01.c
> +++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
> @@ -11,26 +11,12 @@
>  #define _GNU_SOURCE
>  #include <dirent.h>
>  #include <errno.h>
> -#include <sched.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <sys/types.h>
> -#include "lapi/syscalls.h"
> -#include "lapi/cpuset.h"
>  #include "tst_test.h"
> -#include "config.h"
> -
> -static inline int get_cpu(unsigned *cpu_id,
> -			  unsigned *node_id LTP_ATTRIBUTE_UNUSED,
> -			  void *cache_struct LTP_ATTRIBUTE_UNUSED)
> -{
> -#ifndef HAVE_SCHED_GETCPU
> -	return tst_syscall(__NR_getcpu, cpu_id, node_id, cache_struct);
> -#else
> -	*cpu_id = sched_getcpu();
> -#endif
> -	return 0;
> -}
> +#include "lapi/cpuset.h"
> +#include "lapi/sched.h"

>  static unsigned int max_cpuid(size_t size, cpu_set_t * set)
>  {
> @@ -78,7 +64,6 @@ realloc:
>  	return cpu_max;
>  }

> -#ifdef __i386__
>  static unsigned int get_nodeid(unsigned int cpu_id)
>  {
>  	DIR *directory_parent, *directory_node;
> @@ -119,33 +104,26 @@ static unsigned int get_nodeid(unsigned int cpu_id)
>  	}
>  	return node_id;
>  }
> -#endif

>  static void run(void)
>  {
>  	unsigned int cpu_id, node_id = 0;
>  	unsigned int cpu_set;
> -#ifdef __i386__
>  	unsigned int node_set;
> -#endif

>  	cpu_set = set_cpu_affinity();
> -#ifdef __i386__
>  	node_set = get_nodeid(cpu_set);
> -#endif

> -	TEST(get_cpu(&cpu_id, &node_id, NULL));
> +	TEST(getcpu(&cpu_id, &node_id));
>  	if (TST_RET == 0) {
>  		if (cpu_id != cpu_set)
>  			tst_res(TFAIL, "getcpu() returned wrong value"
>  				" expected cpuid:%d, returned value cpuid: %d",
>  				cpu_set, cpu_id);
> -#ifdef __i386__
>  		else if (node_id != node_set)
>  			tst_res(TFAIL, "getcpu() returned wrong value"
>  				" expected  node id:%d returned  node id:%d",
>  				node_set, node_id);
> -#endif
>  		else
>  			tst_res(TPASS, "getcpu() returned proper"
>  				" cpuid:%d, node id:%d", cpu_id,
> @@ -156,13 +134,6 @@ static void run(void)
>  	}
>  }

FYI Richie is touching the same code, one of you will need to rebase.
IMHO it's better to remove this in dedicated patchset (i.e. in Xu).

Kind regards,
Petr

> -static void setup(void)
> -{
> -	if (tst_kvercmp(2, 6, 20) < 0)
> -		tst_brk(TCONF, "kernel >= 2.6.20 required");
> -}
> -
>  static struct tst_test test = {
>  	.test_all = run,
> -	.setup = setup,
>  };

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2] getcpu01: Reinstate node_id test
  2022-12-13  9:53 ` Petr Vorel
@ 2022-12-13 10:00   ` xuyang2018.jy
  2022-12-13 10:36     ` Richard Palethorpe
  0 siblings, 1 reply; 5+ messages in thread
From: xuyang2018.jy @ 2022-12-13 10:00 UTC (permalink / raw)
  To: Petr Vorel, Richard Palethorpe; +Cc: ltp@lists.linux.it

Hi Petr

> Hi Xu,
> 
>> Presently the node_id is only checked on i386 and it is broken. The
>> sched_getcpu call was substituted for getcpu when
>> available. sched_getcpu does not have the node_id parameter, it's not
>> the same thing as getcpu.
> 
>> Also we can check the node_id on any platform which has NUMA. Which
>> includes more than just x86.
> 
>> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
>> Cc: Cyril Hrubis <chrubis@suse.cz>
>> ---
> 
>> V2:
>> * Removed all the ifdefs
>> * Use libc getcpu when available
>> * Remove kernel version check
> 
>>   configure.ac                                |  1 +
>>   include/lapi/sched.h                        |  7 +++++
>>   testcases/kernel/syscalls/getcpu/getcpu01.c | 35 ++-------------------
>>   3 files changed, 11 insertions(+), 32 deletions(-)
> 
>> diff --git a/configure.ac b/configure.ac
>> index e9b15c7f7..1ab7cc60d 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -101,6 +101,7 @@ AC_CHECK_FUNCS_ONCE([ \
>>       fstatat \
>>       getauxval \
>>       getcontext \
>> +    getcpu \
>>       getdents \
>>       getdents64 \
>>       io_pgetevents \
>> diff --git a/include/lapi/sched.h b/include/lapi/sched.h
>> index 1d22a9d7e..1065665d1 100644
>> --- a/include/lapi/sched.h
>> +++ b/include/lapi/sched.h
>> @@ -70,6 +70,13 @@ static inline void clone3_supported_by_kernel(void)
>>   	}
>>   }
> 
>> +#ifndef HAVE_GETCPU
>> +static inline int getcpu(unsigned *cpu, unsigned *node)
>> +{
>> +	return tst_syscall(__NR_getcpu, cpu, node, NULL);
>> +}
>> +#endif
>> +
>>   #ifndef SCHED_DEADLINE
>>   # define SCHED_DEADLINE	6
>>   #endif
>> diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
>> index fcc273e29..f6fcc4fc1 100644
>> --- a/testcases/kernel/syscalls/getcpu/getcpu01.c
>> +++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
>> @@ -11,26 +11,12 @@
>>   #define _GNU_SOURCE
>>   #include <dirent.h>
>>   #include <errno.h>
>> -#include <sched.h>
>>   #include <stdio.h>
>>   #include <stdlib.h>
>>   #include <sys/types.h>
>> -#include "lapi/syscalls.h"
>> -#include "lapi/cpuset.h"
>>   #include "tst_test.h"
>> -#include "config.h"
>> -
>> -static inline int get_cpu(unsigned *cpu_id,
>> -			  unsigned *node_id LTP_ATTRIBUTE_UNUSED,
>> -			  void *cache_struct LTP_ATTRIBUTE_UNUSED)
>> -{
>> -#ifndef HAVE_SCHED_GETCPU
>> -	return tst_syscall(__NR_getcpu, cpu_id, node_id, cache_struct);
>> -#else
>> -	*cpu_id = sched_getcpu();
>> -#endif
>> -	return 0;
>> -}
>> +#include "lapi/cpuset.h"
>> +#include "lapi/sched.h"
> 
>>   static unsigned int max_cpuid(size_t size, cpu_set_t * set)
>>   {
>> @@ -78,7 +64,6 @@ realloc:
>>   	return cpu_max;
>>   }
> 
>> -#ifdef __i386__
>>   static unsigned int get_nodeid(unsigned int cpu_id)
>>   {
>>   	DIR *directory_parent, *directory_node;
>> @@ -119,33 +104,26 @@ static unsigned int get_nodeid(unsigned int cpu_id)
>>   	}
>>   	return node_id;
>>   }
>> -#endif
> 
>>   static void run(void)
>>   {
>>   	unsigned int cpu_id, node_id = 0;
>>   	unsigned int cpu_set;
>> -#ifdef __i386__
>>   	unsigned int node_set;
>> -#endif
> 
>>   	cpu_set = set_cpu_affinity();
>> -#ifdef __i386__
>>   	node_set = get_nodeid(cpu_set);
>> -#endif
> 
>> -	TEST(get_cpu(&cpu_id, &node_id, NULL));
>> +	TEST(getcpu(&cpu_id, &node_id));
>>   	if (TST_RET == 0) {
>>   		if (cpu_id != cpu_set)
>>   			tst_res(TFAIL, "getcpu() returned wrong value"
>>   				" expected cpuid:%d, returned value cpuid: %d",
>>   				cpu_set, cpu_id);
>> -#ifdef __i386__
>>   		else if (node_id != node_set)
>>   			tst_res(TFAIL, "getcpu() returned wrong value"
>>   				" expected  node id:%d returned  node id:%d",
>>   				node_set, node_id);
>> -#endif
>>   		else
>>   			tst_res(TPASS, "getcpu() returned proper"
>>   				" cpuid:%d, node id:%d", cpu_id,
>> @@ -156,13 +134,6 @@ static void run(void)
>>   	}
>>   }
> 
> FYI Richie is touching the same code, one of you will need to rebase.
> IMHO it's better to remove this in dedicated patchset (i.e. in Xu).

Even I will limit the kernel version check to 3.0 in my patchset because 
we don't reach the same target to 3.10, so let me rebase.

ps: If we reach the same target to 3.10, then we can remove remain old 
version check in the future.

Best Regards
Yang Xu
> 
> Kind regards,
> Petr
> 
>> -static void setup(void)
>> -{
>> -	if (tst_kvercmp(2, 6, 20) < 0)
>> -		tst_brk(TCONF, "kernel >= 2.6.20 required");
>> -}
>> -
>>   static struct tst_test test = {
>>   	.test_all = run,
>> -	.setup = setup,
>>   };

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2] getcpu01: Reinstate node_id test
  2022-12-13 10:00   ` xuyang2018.jy
@ 2022-12-13 10:36     ` Richard Palethorpe
  2022-12-13 19:02       ` Petr Vorel
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Palethorpe @ 2022-12-13 10:36 UTC (permalink / raw)
  To: xuyang2018.jy@fujitsu.com; +Cc: ltp

Hello,

>> 
>> FYI Richie is touching the same code, one of you will need to rebase.
>> IMHO it's better to remove this in dedicated patchset (i.e. in Xu).
>
> Even I will limit the kernel version check to 3.0 in my patchset because 
> we don't reach the same target to 3.10, so let me rebase.
>
> ps: If we reach the same target to 3.10, then we can remove remain old 
> version check in the future.

I'm not sure what you mean. It's not the important thing for this patch
though. I'll just remove it before merge.

>
> Best Regards
> Yang Xu
>> 
>> Kind regards,
>> Petr
>> 
>>> -static void setup(void)
>>> -{
>>> -	if (tst_kvercmp(2, 6, 20) < 0)
>>> -		tst_brk(TCONF, "kernel >= 2.6.20 required");
>>> -}
>>> -
>>>   static struct tst_test test = {
>>>   	.test_all = run,
>>> -	.setup = setup,
>>>   };


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

* Re: [LTP] [PATCH v2] getcpu01: Reinstate node_id test
  2022-12-13 10:36     ` Richard Palethorpe
@ 2022-12-13 19:02       ` Petr Vorel
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2022-12-13 19:02 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

> Hello,


> >> FYI Richie is touching the same code, one of you will need to rebase.
> >> IMHO it's better to remove this in dedicated patchset (i.e. in Xu).

> > Even I will limit the kernel version check to 3.0 in my patchset because 
> > we don't reach the same target to 3.10, so let me rebase.

> > ps: If we reach the same target to 3.10, then we can remove remain old 
> > version check in the future.

> I'm not sure what you mean. It's not the important thing for this patch
> though. I'll just remove it before merge.

Thank you Richie!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

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

end of thread, other threads:[~2022-12-13 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-13  9:44 [LTP] [PATCH v2] getcpu01: Reinstate node_id test Richard Palethorpe via ltp
2022-12-13  9:53 ` Petr Vorel
2022-12-13 10:00   ` xuyang2018.jy
2022-12-13 10:36     ` Richard Palethorpe
2022-12-13 19:02       ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox