syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
PATCH 1/1 syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
1)sched_getcpu() isn't defined on some old distros, so we can add dection and fix compiler error.
2)If CPU_ALLOC isn't defined on some old distros, it will used "include/lapi/cpuset" CPU_ALLOC macro. But getcpu01.c has converted into new library, so it will report "cleanup" undefine error. We should ensure CPU_ALLOC can be used both new cases and old cases.
--- configure.ac | 1 + include/lapi/cpuset.h | 10 +++++++++- testcases/kernel/syscalls/getcpu/getcpu01.c | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-)
configure.ac +1 -0
@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \
include/lapi/cpuset.h +9 -1
@@ -33,11 +33,19 @@#define LTP_CPUSET_H #ifndef CPU_ALLOC +#ifndef TST_TEST_H__ #define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ if (ncpus > CPU_SETSIZE) { \ tst_brkm(TCONF, cleanup, \ - "Your libc does not support masks with %ld cpus", ncpus); \ + "Your libc does not support masks with %d cpus", ncpus); \ } +#else +#define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ +if (ncpus > CPU_SETSIZE) { \ + tst_brk(TCONF, \ + "Your libc does not support masks with %d cpus", ncpus); \ +} +#endif #endif #ifndef CPU_FREE
testcases/kernel/syscalls/getcpu/getcpu01.c +3 -3
@@ -16,15 +16,15 @@#include <stdlib.h> #include <sys/types.h> #include "lapi/syscalls.h" -#include "lapi/cpuset.h" #include "tst_test.h" +#include "lapi/cpuset.h" static inline int get_cpu (unsigned *cpu_id, unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif
Signature · 1 line
1.7.11.rc0
PATCH 1/1 syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
Hi!
Quoted 40 lines
1)sched_getcpu() isn't defined on some old distros, so we can add dection and fix compiler error.
2)If
CPU_ALLOCisn't defined on some old distros, it will used "include/lapi/cpuset"CPU_ALLOCmacro. Butgetcpu01.chas converted into new library, so it will report "cleanup" undefine error. We should ensureCPU_ALLOCcan be used both new cases and old cases.Signed-off-by Yang Xu <[email protected]>--- configure.ac | 1 + include/lapi/cpuset.h | 10 +++++++++- testcases/kernel/syscalls/getcpu/getcpu01.c | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-)configure.ac +1
-0@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \include/lapi/cpuset.h +1
-1@@ -33,11 +33,19 @@#define LTP_CPUSET_H #ifndef CPU_ALLOC +#ifndef TST_TEST_H__ #define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ if (ncpus > CPU_SETSIZE) { \ tst_brkm(TCONF, cleanup, \ - "Your libc does not support masks with %ld cpus", ncpus); \
include/lapi/cpuset.h line 49
Quoted 10 lines
include/lapi/cpuset.h +8
-0+ "Your libc does not support masks with %d cpus", ncpus); \ } +#else +#define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ +if (ncpus > CPU_SETSIZE) { \ + tst_brk(TCONF, \ + "Your libc does not support masks with %d cpus", ncpus); \ +} +#endif #endif
Good catch.
I would be happier if we converted the sched_setaffinity01 to new library then we could simply change the tst_brkm() to tst_brk(), but we can always do that later on.
Quoted 14 lines
include/lapi/cpuset.h +0
-0#ifndef CPU_FREE testcases/kernel/syscalls/getcpu/getcpu01.c +1
-1@@ -16,15 +16,15 @@#include <stdlib.h> #include <sys/types.h> #include "lapi/syscalls.h" -#include "lapi/cpuset.h" #include "tst_test.h" +#include "lapi/cpuset.h" static inline int get_cpu(unsigned *cpu_id,
testcases/kernel/syscalls/getcpu/getcpu01.c line 30
Quoted 10 lines
testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif
So when __NR_getcpu is not implemented we end up with tst_brk(TCONF, ...) called from the tst_syscall, right? Since AFAIK the getcpu syscall is not implemented on all architectures...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
Quoted 53 lines · Cyril Hrubis
Hi!
Quoted 40 lines
1)sched_getcpu() isn't defined on some old distros, so we can add dection and fix compiler error.
2)If
CPU_ALLOCisn't defined on some old distros, it will used "include/lapi/cpuset"CPU_ALLOCmacro. Butgetcpu01.chas converted into new library, so it will report "cleanup" undefine error. We should ensureCPU_ALLOCcan be used both new cases and old cases.Signed-off-by Yang Xu<[email protected]>--- configure.ac | 1 + include/lapi/cpuset.h | 10 +++++++++- testcases/kernel/syscalls/getcpu/getcpu01.c | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-)configure.ac +1
-0@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \include/lapi/cpuset.h +1
-1@@ -33,11 +33,19 @@#define LTP_CPUSET_H #ifndef CPU_ALLOC +#ifndef TST_TEST_H__ #define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ if (ncpus> CPU_SETSIZE) { \ tst_brkm(TCONF, cleanup, \ - "Your libc does not support masks with %ld cpus", ncpus); \include/lapi/cpuset.h line 49
Quoted 10 lines
include/lapi/cpuset.h +8
-0+ "Your libc does not support masks with %d cpus", ncpus); \ } +#else +#define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ +if (ncpus> CPU_SETSIZE) { \ + tst_brk(TCONF, \ + "Your libc does not support masks with %d cpus", ncpus); \ +} +#endif #endif Good catch.
Quoted 4 lines
I would be happier if we converted the
sched_setaffinity01to new library then we could simply change thetst_brkm()totst_brk(), but we can always do that later on.
Hi Cyril
I will converted the sched_setaffinity01 to new library in V2 patch.
Quoted 13 lines
Quoted 13 lines
include/lapi/cpuset.h +0
-0#ifndef CPU_FREE testcases/kernel/syscalls/getcpu/getcpu01.c +1
-1@@ -16,15 +16,15 @@#include <stdlib.h> #include <sys/types.h> #include "lapi/syscalls.h" -#include "lapi/cpuset.h" #include "tst_test.h" +#include "lapi/cpuset.h"
Quoted 14 lines
testcases/kernel/syscalls/getcpu/getcpu01.c line 30
Quoted 11 lines
testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2static inline int get_cpu (unsigned *cpu_id, unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif So when
__NR_getcpuis not implemented we end up withtst_brk(TCONF, ...)called from thetst_syscall, right? Since AFAIK the getcpu syscall is not implemented on all architectures...
Yes. It will report TCONF if __NR_getcpu is not implemented.
From getcpu manpage, it is not implemented on all architectures as you
said, I think we can remove sched_getcpu and use __NR_getcpu directly.
PATCH 1/1 syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
Hi!
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/getcpu/getcpu01.c line 30
Quoted 7 lines
testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2-#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif So when
__NR_getcpuis not implemented we end up withtst_brk(TCONF, ...)called from thetst_syscall, right? Since AFAIK the getcpu syscall is not implemented on all architectures...
Quoted 4 lines
Yes. It will report TCONF if
__NR_getcpuis not implemented.From getcpu manpage, it is not implemented on all architectures as you
said, I think we can removesched_getcpuand use__NR_getcpudirectly.
Reading the manual pages I think it's correct to fall back to sched_getcpu() since as far as I can tell platforms that don't support getcpu syscall have implemented the functionality as vDSO. So unless we implement vDSO variant of getcpu we have to rely on sched_getcpu().
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
Quoted 11 lines · Cyril Hrubis
Hi!
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/getcpu/getcpu01.c line 30
Quoted 7 lines
testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2-#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif So when
__NR_getcpuis not implemented we end up withtst_brk(TCONF, ...)called from thetst_syscall, right? Since AFAIK the getcpu syscall is not implemented on all architectures...
Quoted 9 lines
Quoted 4 lines
Yes. It will report TCONF if
__NR_getcpuis not implemented.From getcpu manpage, it is not implemented on all architectures as you
said, I think we can removesched_getcpuand use__NR_getcpudirectly.Reading the manual pages I think it's correct to fall back to
sched_getcpu()since as far as I can tell platforms that don't support getcpu syscall have implemented the functionality as vDSO. So unless we implement vDSO variant of getcpu we have to rely onsched_getcpu().
Hi cyril
Reading the sched_getcpu manpage,I mistakenly think the sched_getcpu uses the getcpu syscall diretly.| |Actually|sched_getcpu uses VDSO getcpu() syscall since glibc 2.22. Thanks for you explanation.|
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190415/5499b512/attachment.html>
PATCH v2 1/2 syscalls/sched_getaffinity: Cleanup && Convert to new API
In reply to Cyril HrubisConvert test to new library. It also fixes a rare compile error for getcpu01.c on some old distros that use ltp CPU_ALLOC(report cleanup undefined error).
--- include/lapi/cpuset.h | 4 +- .../sched_getaffinity/sched_getaffinity01.c | 151 ++++-------------- 2 files changed, 32 insertions(+), 123 deletions(-)
include/lapi/cpuset.h +2 -2
@@ -35,8 +35,8 @@#ifndef CPU_ALLOC #define CPU_ALLOC (ncpus) malloc(sizeof(cpu_set_t)); \ if (ncpus > CPU_SETSIZE) { \ - tst_brkm(TCONF, cleanup, \ - "Your libc does not support masks with %ld cpus", ncpus); \ + tst_brk(TCONF, \ + "Your libc does not support masks with %d cpus", ncpus); \ }#endif
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +30 -121
200 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v2 2/2 syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors
sched_getcpu() isn't defined on some old distros, so we can add dection and fix compiler error.
--- configure.ac | 1 + testcases/kernel/syscalls/getcpu/getcpu01.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)
configure.ac +1 -0
@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \
testcases/kernel/syscalls/getcpu/getcpu01.c +3 -2
@@ -18,13 +18,14 @@#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) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif
Signature · 1 line
2.18.1
PATCH v2 2/2 syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors
Quoted 32 lines · Yang Xu
sched_getcpu()isn't defined on some old distros, so we can add dection and fix compiler error.Signed-off-by Yang Xu <[email protected]>--- configure.ac | 1 + testcases/kernel/syscalls/getcpu/getcpu01.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)configure.ac +1
-0@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \testcases/kernel/syscalls/getcpu/getcpu01.c +1
-0@@ -18,13 +18,14 @@#include "lapi/syscalls.h" #include "lapi/cpuset.h" #include "tst_test.h" +#include "config.h" static inline int get_cpu(unsigned *cpu_id,
testcases/kernel/syscalls/getcpu/getcpu01.c line 31
Quoted 10 lines
testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif
Hi,
Ping. :-)
PATCH v2 2/2 syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors
In reply to Yang XuHi,
Quoted 4 lines
sched_getcpu()isn't defined on some old distros, so we can add dection and fix compiler error.Signed-off-by Yang Xu <[email protected]>
@Metan: I'd be for pushing this before new release.
...
testcases/kernel/syscalls/getcpu/getcpu01.c line 31
Quoted 11 lines
static inline int get_cpu(unsigned
*cpu_id,testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif
BTW: when rewriting into new C API (whenever it happens) it'd be nice to test both syscall and libc sched_getcpu() (if available) via recently added test_variants [1].
Kind regards,
Petr
PATCH v2 2/2 syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors
Hi!
Quoted 7 lines
Quoted 4 lines
sched_getcpu()isn't defined on some old distros, so we can add dection and fix compiler error.Signed-off-by Yang Xu <[email protected]>Acked-by Petr Vorel <[email protected]>@Metan: I'd be for pushing this before new release.
Acked, please go ahead.
Quoted 16 lines
...
testcases/kernel/syscalls/getcpu/getcpu01.c line 31
Quoted 11 lines
static inline int get_cpu(unsigned
*cpu_id,testcases/kernel/syscalls/getcpu/getcpu01.c +2
-2unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) -return syscall (__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU +return tst_syscall (__NR_getcpu, cpu_id, node_id, cache_struct);#else *cpu_id =sched_getcpu ();#endif BTW: when rewriting into new C API (whenever it happens) it'd be nice to test both syscall and libc
sched_getcpu()(if available) via recently addedtest_variants[1].
Quoted 4 lines
Kind regards,
Petr
Sure, but let's aim for that after the release has been finished.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors
Hi,
Quoted 3 lines
Quoted 1 line
@Metan: I'd be for pushing this before new release.
Acked, please go ahead.
Merged.
...
Quoted 5 lines
Quoted 3 lines
BTW: when rewriting into new C API (whenever it happens) it'd be nice to test
both syscall and libcsched_getcpu()(if available) via recently addedtest_variants[1].
[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2229-testing-similar-syscalls-in-one-testSure, but let's aim for that after the release has been finished.
Sure, nothing should block release :).
Kind regards,
Petr
PATCH v2 1/2 syscalls/sched_getaffinity: Cleanup && Convert to new API
In reply to Yang XuHi!
I've did some fixes, split the patch into two and applied, thanks.
As it was the sched_getaffinity() test was really wrong since the CPU_ISSET_S() does not return -1 at all. Also it's not guaranteed that all cpus are in the affinity mask for a given process. So what I changed it to instead is to check if sum of the enabled bits in the mask is greater than zero and smaller or equal the number of the configured processors as reported by the sysconf() call.
I've also changed the negative testcases to check errno as well, full diff follows.
And lastly but not least I've split the patch into two, since the change in the lapi/cpuset.h is unrelated to the conversion.
testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +43 -29
@@ -14,20 +14,35 @@#include "tst_safe_macros.h" #include "lapi/cpuset.h" -#define QUICK_TEST (t) \ -do { \ - TEST(t); \ - tst_res((TST_RET == -1 ? TPASS : TFAIL) | TTERRNO, #t); \ -} while (0) +static long ncpu; -static long num; +static void *bad_addr; + +static void errno_test (pid_t pid,size_t cpusize,void *mask,int exp_errno) +{ +TEST (sched_getaffinity (pid, cpusize, mask)); + +if (TST_RET !=-1 ) { +tst_res (TFAIL , +"sched_getaffinity() returned %ld, expected -1" , +TST_RET ); +return ; + } + +if (TST_ERR != exp_errno) { +tst_res (TFAIL |TTERRNO , +"sched_getaffinity() should fail with %s" , +tst_strerrno (exp_errno)); +return ; + } + +tst_res (TPASS |TTERRNO ,"sched_getaffinity() failed" ); +}static void do_test (void ) { -int i;cpu_set_t *mask;int nrcpus =1024 ; -pid_t unused_pid;unsigned len; realloc:
@@ -38,42 +53,41 @@ realloc: len =CPU_ALLOC_SIZE (nrcpus);CPU_ZERO_S (len, mask); -/* positive test */ TEST (sched_getaffinity (0 , len, mask));if (TST_RET ==-1 ) {CPU_FREE (mask); -if (errno ==EINVAL && nrcpus < (1024 <<8 )) { +if (TST_ERR ==EINVAL && nrcpus < (1024 <<8 )) { nrcpus = nrcpus <<2 ; goto realloc; } -tst_res (TFAIL |TTERRNO ,"fail to get cpu affinity" ); - }else { -tst_res (TINFO ,"cpusetsize is %d" , len); -tst_res (TINFO ,"mask.__bits[0] = %lu " , mask->__bits[0 ]); -for (i =0 ; i < num; i++) { -TEST (CPU_ISSET_S (i, len, mask)); -if (TST_RET !=-1 ) -tst_res (TPASS ,"sched_getaffinity() succeed, " -"this process %d is running " -"processor: %d" ,getpid (), i); - } +tst_brk (TBROK |TTERRNO ,"fail to get cpu affinity" ); } -CPU_ZERO_S (len, mask); +long i, af_cpus =0 ; -/* negative tests */ -QUICK_TEST (sched_getaffinity (0 , len, (cpu_set_t *) -1 )); -QUICK_TEST (sched_getaffinity (0 ,0 , mask)); +for (i =0 ; i < nrcpus; i++) + af_cpus += !!CPU_ISSET_S (i, len, mask); + +if (af_cpus ==0 ) +tst_res (TFAIL ,"No cpus enabled in mask" ); +else if (af_cpus > ncpu) +tst_res (TFAIL ,"Enabled cpus = %li > system cpus %li" , af_cpus, ncpu); +else +tst_res (TPASS ,"cpuset size = %u, enabled cpus %ld" , len, af_cpus); + +errno_test (0 , len, bad_addr,EFAULT ); +errno_test (0 ,0 , mask,EINVAL ); +errno_test (tst_get_unused_pid (), len, mask,ESRCH ); - unused_pid =tst_get_unused_pid (); -QUICK_TEST (sched_getaffinity (unused_pid, len, mask));CPU_FREE (mask); }static void setup (void ) { - num =SAFE_SYSCONF (_SC_NPROCESSORS_CONF); -tst_res (TINFO ,"system has %ld processor(s)." , num); + ncpu =SAFE_SYSCONF (_SC_NPROCESSORS_CONF); +tst_res (TINFO ,"system has %ld processor(s)." , ncpu); + + bad_addr =tst_get_bad_addr (NULL ); }static struct tst_test test = {
Signature · 2 lines
Cyril Hrubis [email protected]