Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 1 | #ifndef _PERF_SYS_H |
| 2 | #define _PERF_SYS_H |
| 3 | |
Jiri Olsa | 82baa0e | 2014-05-05 12:58:31 +0200 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | #include <sys/types.h> |
| 6 | #include <sys/syscall.h> |
| 7 | #include <linux/types.h> |
Arnaldo Carvalho de Melo | 14f0652 | 2016-07-18 17:40:49 -0300 | [diff] [blame] | 8 | #include <linux/compiler.h> |
Jiri Olsa | 82baa0e | 2014-05-05 12:58:31 +0200 | [diff] [blame] | 9 | #include <linux/perf_event.h> |
Arnaldo Carvalho de Melo | 361c564 | 2015-04-30 12:33:22 -0300 | [diff] [blame] | 10 | #include <asm/barrier.h> |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 11 | |
| 12 | #if defined(__i386__) |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 13 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 14 | #define CPUINFO_PROC {"model name"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 15 | #endif |
| 16 | |
| 17 | #if defined(__x86_64__) |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 18 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 19 | #define CPUINFO_PROC {"model name"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 20 | #endif |
| 21 | |
| 22 | #ifdef __powerpc__ |
| 23 | #include "../../arch/powerpc/include/uapi/asm/unistd.h" |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 24 | #define CPUINFO_PROC {"cpu"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 25 | #endif |
| 26 | |
| 27 | #ifdef __s390__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 28 | #define CPUINFO_PROC {"vendor_id"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #ifdef __sh__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 32 | #define CPUINFO_PROC {"cpu type"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | #ifdef __hppa__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 36 | #define CPUINFO_PROC {"cpu"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #ifdef __sparc__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 40 | #define CPUINFO_PROC {"cpu"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | #ifdef __alpha__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 44 | #define CPUINFO_PROC {"cpu model"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | #ifdef __ia64__ |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 48 | #define cpu_relax() asm volatile ("hint @pause" ::: "memory") |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 49 | #define CPUINFO_PROC {"model name"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 50 | #endif |
| 51 | |
| 52 | #ifdef __arm__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 53 | #define CPUINFO_PROC {"model name", "Processor"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 54 | #endif |
| 55 | |
| 56 | #ifdef __aarch64__ |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 57 | #define cpu_relax() asm volatile("yield" ::: "memory") |
| 58 | #endif |
| 59 | |
| 60 | #ifdef __mips__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 61 | #define CPUINFO_PROC {"cpu model"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | #ifdef __arc__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 65 | #define CPUINFO_PROC {"Processor"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | #ifdef __metag__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 69 | #define CPUINFO_PROC {"CPU"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | #ifdef __xtensa__ |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 73 | #define CPUINFO_PROC {"core ID"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 74 | #endif |
| 75 | |
| 76 | #ifdef __tile__ |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 77 | #define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory") |
Wang Nan | 493c303 | 2014-10-24 09:45:26 +0800 | [diff] [blame] | 78 | #define CPUINFO_PROC {"model name"} |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 79 | #endif |
| 80 | |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 81 | #ifndef cpu_relax |
| 82 | #define cpu_relax() barrier() |
| 83 | #endif |
| 84 | |
Jiri Olsa | 82baa0e | 2014-05-05 12:58:31 +0200 | [diff] [blame] | 85 | static inline int |
| 86 | sys_perf_event_open(struct perf_event_attr *attr, |
| 87 | pid_t pid, int cpu, int group_fd, |
| 88 | unsigned long flags) |
| 89 | { |
| 90 | int fd; |
| 91 | |
| 92 | fd = syscall(__NR_perf_event_open, attr, pid, cpu, |
| 93 | group_fd, flags); |
| 94 | |
| 95 | #ifdef HAVE_ATTR_TEST |
| 96 | if (unlikely(test_attr__enabled)) |
| 97 | test_attr__open(attr, pid, cpu, fd, group_fd, flags); |
| 98 | #endif |
| 99 | return fd; |
| 100 | } |
| 101 | |
Jiri Olsa | 43599d1 | 2014-05-05 12:53:20 +0200 | [diff] [blame] | 102 | #endif /* _PERF_SYS_H */ |