Skip to content

Commit

Permalink
perf tools: Introduce weak alternative to sched_getcpu()
Browse files Browse the repository at this point in the history
Which is just a wrapper for sys_getcpu and is not present in at least
musl libc.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jul 12, 2016
1 parent 4998a12 commit c7007e9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tools/arch/x86/include/asm/unistd_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
#ifndef __NR_gettid
# define __NR_gettid 224
#endif
#ifndef __NR_getcpu
# define __NR_getcpu 318
#endif
3 changes: 3 additions & 0 deletions tools/arch/x86/include/asm/unistd_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
#ifndef __NR_gettid
# define __NR_gettid 186
#endif
#ifndef __NR_getcpu
# define __NR_getcpu 309
#endif
14 changes: 10 additions & 4 deletions tools/perf/util/cloexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit c7007e9

Please sign in to comment.