perf tools: Introduce weak alternative to sched_getcpu()

Which is just a wrapper for sys_getcpu and is not present in at least
musl libc.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-kblef7svmhr0g93kkx78envg@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 4998a122
...@@ -7,3 +7,6 @@ ...@@ -7,3 +7,6 @@
#ifndef __NR_gettid #ifndef __NR_gettid
# define __NR_gettid 224 # define __NR_gettid 224
#endif #endif
#ifndef __NR_getcpu
# define __NR_getcpu 318
#endif
...@@ -7,3 +7,6 @@ ...@@ -7,3 +7,6 @@
#ifndef __NR_gettid #ifndef __NR_gettid
# define __NR_gettid 186 # define __NR_gettid 186
#endif #endif
#ifndef __NR_getcpu
# define __NR_getcpu 309
#endif
...@@ -4,18 +4,24 @@ ...@@ -4,18 +4,24 @@
#include "cloexec.h" #include "cloexec.h"
#include "asm/bug.h" #include "asm/bug.h"
#include "debug.h" #include "debug.h"
#include <unistd.h>
#include <asm/unistd.h>
#include <sys/syscall.h>
static unsigned long flag = PERF_FLAG_FD_CLOEXEC; static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
#ifdef __GLIBC_PREREQ
#if !__GLIBC_PREREQ(2, 6)
int __weak sched_getcpu(void) 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; errno = ENOSYS;
#endif
return -1; return -1;
} }
#endif
#endif
static int perf_flag_probe(void) static int perf_flag_probe(void)
{ {
......
...@@ -361,4 +361,8 @@ void print_binary(unsigned char *data, size_t len, ...@@ -361,4 +361,8 @@ void print_binary(unsigned char *data, size_t len,
size_t bytes_per_line, print_binary_t printer, size_t bytes_per_line, print_binary_t printer,
void *extra); void *extra);
#ifndef __GLIBC__
extern int sched_getcpu(void);
#endif
#endif /* GIT_COMPAT_UTIL_H */ #endif /* GIT_COMPAT_UTIL_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment