blob: 83a25cef82fdd2747ab0bc7f8b4fdc50c3c65b62 [file] [log] [blame]
Jiri Olsa43599d12014-05-05 12:53:20 +02001#ifndef _PERF_SYS_H
2#define _PERF_SYS_H
3
Jiri Olsa82baa0e2014-05-05 12:58:31 +02004#include <unistd.h>
5#include <sys/types.h>
6#include <sys/syscall.h>
7#include <linux/types.h>
8#include <linux/perf_event.h>
Arnaldo Carvalho de Melo361c5642015-04-30 12:33:22 -03009#include <asm/barrier.h>
Jiri Olsa43599d12014-05-05 12:53:20 +020010
11#if defined(__i386__)
Jiri Olsa43599d12014-05-05 12:53:20 +020012#define cpu_relax() asm volatile("rep; nop" ::: "memory");
Wang Nan493c3032014-10-24 09:45:26 +080013#define CPUINFO_PROC {"model name"}
Jiri Olsa43599d12014-05-05 12:53:20 +020014#ifndef __NR_perf_event_open
15# define __NR_perf_event_open 336
16#endif
17#ifndef __NR_futex
18# define __NR_futex 240
19#endif
20#ifndef __NR_gettid
21# define __NR_gettid 224
22#endif
23#endif
24
25#if defined(__x86_64__)
Jiri Olsa43599d12014-05-05 12:53:20 +020026#define cpu_relax() asm volatile("rep; nop" ::: "memory");
Wang Nan493c3032014-10-24 09:45:26 +080027#define CPUINFO_PROC {"model name"}
Jiri Olsa43599d12014-05-05 12:53:20 +020028#ifndef __NR_perf_event_open
29# define __NR_perf_event_open 298
30#endif
31#ifndef __NR_futex
32# define __NR_futex 202
33#endif
34#ifndef __NR_gettid
35# define __NR_gettid 186
36#endif
37#endif
38
39#ifdef __powerpc__
40#include "../../arch/powerpc/include/uapi/asm/unistd.h"
Wang Nan493c3032014-10-24 09:45:26 +080041#define CPUINFO_PROC {"cpu"}
Jiri Olsa43599d12014-05-05 12:53:20 +020042#endif
43
44#ifdef __s390__
Wang Nan493c3032014-10-24 09:45:26 +080045#define CPUINFO_PROC {"vendor_id"}
Jiri Olsa43599d12014-05-05 12:53:20 +020046#endif
47
48#ifdef __sh__
Wang Nan493c3032014-10-24 09:45:26 +080049#define CPUINFO_PROC {"cpu type"}
Jiri Olsa43599d12014-05-05 12:53:20 +020050#endif
51
52#ifdef __hppa__
Wang Nan493c3032014-10-24 09:45:26 +080053#define CPUINFO_PROC {"cpu"}
Jiri Olsa43599d12014-05-05 12:53:20 +020054#endif
55
56#ifdef __sparc__
Wang Nan493c3032014-10-24 09:45:26 +080057#define CPUINFO_PROC {"cpu"}
Jiri Olsa43599d12014-05-05 12:53:20 +020058#endif
59
60#ifdef __alpha__
Wang Nan493c3032014-10-24 09:45:26 +080061#define CPUINFO_PROC {"cpu model"}
Jiri Olsa43599d12014-05-05 12:53:20 +020062#endif
63
64#ifdef __ia64__
Jiri Olsa43599d12014-05-05 12:53:20 +020065#define cpu_relax() asm volatile ("hint @pause" ::: "memory")
Wang Nan493c3032014-10-24 09:45:26 +080066#define CPUINFO_PROC {"model name"}
Jiri Olsa43599d12014-05-05 12:53:20 +020067#endif
68
69#ifdef __arm__
Wang Nan493c3032014-10-24 09:45:26 +080070#define CPUINFO_PROC {"model name", "Processor"}
Jiri Olsa43599d12014-05-05 12:53:20 +020071#endif
72
73#ifdef __aarch64__
Jiri Olsa43599d12014-05-05 12:53:20 +020074#define cpu_relax() asm volatile("yield" ::: "memory")
75#endif
76
77#ifdef __mips__
Wang Nan493c3032014-10-24 09:45:26 +080078#define CPUINFO_PROC {"cpu model"}
Jiri Olsa43599d12014-05-05 12:53:20 +020079#endif
80
81#ifdef __arc__
Wang Nan493c3032014-10-24 09:45:26 +080082#define CPUINFO_PROC {"Processor"}
Jiri Olsa43599d12014-05-05 12:53:20 +020083#endif
84
85#ifdef __metag__
Wang Nan493c3032014-10-24 09:45:26 +080086#define CPUINFO_PROC {"CPU"}
Jiri Olsa43599d12014-05-05 12:53:20 +020087#endif
88
89#ifdef __xtensa__
Wang Nan493c3032014-10-24 09:45:26 +080090#define CPUINFO_PROC {"core ID"}
Jiri Olsa43599d12014-05-05 12:53:20 +020091#endif
92
93#ifdef __tile__
Jiri Olsa43599d12014-05-05 12:53:20 +020094#define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory")
Wang Nan493c3032014-10-24 09:45:26 +080095#define CPUINFO_PROC {"model name"}
Jiri Olsa43599d12014-05-05 12:53:20 +020096#endif
97
Jiri Olsa43599d12014-05-05 12:53:20 +020098#ifndef cpu_relax
99#define cpu_relax() barrier()
100#endif
101
Jiri Olsa82baa0e2014-05-05 12:58:31 +0200102static inline int
103sys_perf_event_open(struct perf_event_attr *attr,
104 pid_t pid, int cpu, int group_fd,
105 unsigned long flags)
106{
107 int fd;
108
109 fd = syscall(__NR_perf_event_open, attr, pid, cpu,
110 group_fd, flags);
111
112#ifdef HAVE_ATTR_TEST
113 if (unlikely(test_attr__enabled))
114 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
115#endif
116 return fd;
117}
118
Jiri Olsa43599d12014-05-05 12:53:20 +0200119#endif /* _PERF_SYS_H */