All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors
@ 2019-04-12  7:03 Yang Xu
  2019-04-12  9:43 ` Cyril Hrubis
  0 siblings, 1 reply; 12+ messages in thread
From: Yang Xu @ 2019-04-12  7:03 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
---
 configure.ac                                |  1 +
 include/lapi/cpuset.h                       | 10 +++++++++-
 testcases/kernel/syscalls/getcpu/getcpu01.c |  6 +++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index de12499..3ac0f28 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \
     readlinkat \
     renameat \
     renameat2 \
+    sched_getcpu \
     sigpending \
     splice \
     stime \
diff --git a/include/lapi/cpuset.h b/include/lapi/cpuset.h
index b946650..959462b 100644
--- a/include/lapi/cpuset.h
+++ b/include/lapi/cpuset.h
@@ -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
diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c
index eb6ded8..d033119 100644
--- a/testcases/kernel/syscalls/getcpu/getcpu01.c
+++ b/testcases/kernel/syscalls/getcpu/getcpu01.c
@@ -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
-- 
1.7.11.rc0




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

end of thread, other threads:[~2019-05-13  9:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12  7:03 [LTP] [PATCH] syscalls/getcpu: Add libc sched_getcpu() detection && fix compiler errors Yang Xu
2019-04-12  9:43 ` Cyril Hrubis
2019-04-12 10:46   ` xuyang
2019-04-12 11:46     ` Cyril Hrubis
2019-04-15  5:39       ` xuyang
2019-04-17  6:05       ` [LTP] [PATCH v2 1/2] syscalls/sched_getaffinity: Cleanup && Convert to new API Yang Xu
2019-04-17  6:05         ` [LTP] [PATCH v2 2/2] syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors Yang Xu
2019-05-13  7:54           ` xuyang
2019-05-13  8:27           ` Petr Vorel
2019-05-13  8:55             ` Cyril Hrubis
2019-05-13  9:40               ` Petr Vorel
2019-04-18 15:27         ` [LTP] [PATCH v2 1/2] syscalls/sched_getaffinity: Cleanup && Convert to new API Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.