[PATCH 41/66] perf tools: Introduce weak alternative to sched_getcpu()
From: Arnaldo Carvalho de Melo
Date: Tue Jul 12 2016 - 18:45:12 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Which is just a wrapper for sys_getcpu and is not present in at least
musl libc.
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-kblef7svmhr0g93kkx78envg@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/arch/x86/include/asm/unistd_32.h | 3 +++
tools/arch/x86/include/asm/unistd_64.h | 3 +++
tools/perf/util/cloexec.c | 14 ++++++++++----
tools/perf/util/util.h | 4 ++++
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/tools/arch/x86/include/asm/unistd_32.h b/tools/arch/x86/include/asm/unistd_32.h
index cf33ab09273d..88b3f8c8920c 100644
--- a/tools/arch/x86/include/asm/unistd_32.h
+++ b/tools/arch/x86/include/asm/unistd_32.h
@@ -7,3 +7,6 @@
#ifndef __NR_gettid
# define __NR_gettid 224
#endif
+#ifndef __NR_getcpu
+# define __NR_getcpu 318
+#endif
diff --git a/tools/arch/x86/include/asm/unistd_64.h b/tools/arch/x86/include/asm/unistd_64.h
index 2c9835695b56..fbdb70ee8837 100644
--- a/tools/arch/x86/include/asm/unistd_64.h
+++ b/tools/arch/x86/include/asm/unistd_64.h
@@ -7,3 +7,6 @@
#ifndef __NR_gettid
# define __NR_gettid 186
#endif
+#ifndef __NR_getcpu
+# define __NR_getcpu 309
+#endif
diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index fde772db1d5c..f0dcd0ee0afa 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -4,18 +4,24 @@
#include "cloexec.h"
#include "asm/bug.h"
#include "debug.h"
+#include <unistd.h>
+#include <asm/unistd.h>
+#include <sys/syscall.h>
static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
-#ifdef __GLIBC_PREREQ
-#if !__GLIBC_PREREQ(2, 6)
int __weak sched_getcpu(void)
{
+#ifdef __NR_getcpu
+ unsigned cpu;
+ int err = syscall(__NR_getcpu, &cpu, NULL, NULL);
+ if (!err)
+ return cpu;
+#else
errno = ENOSYS;
+#endif
return -1;
}
-#endif
-#endif
static int perf_flag_probe(void)
{
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 2370cfb902b2..d8d41ef8da57 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -361,4 +361,8 @@ void print_binary(unsigned char *data, size_t len,
size_t bytes_per_line, print_binary_t printer,
void *extra);
+#ifndef __GLIBC__
+extern int sched_getcpu(void);
+#endif
+
#endif /* GIT_COMPAT_UTIL_H */
--
2.7.4