perf tools: Move arm(64) barrier.h stuff to tools/arch/arm*/include/asm/barrier.h
[platform/kernel/linux-starfive.git] / tools / perf / perf-sys.h
1 #ifndef _PERF_SYS_H
2 #define _PERF_SYS_H
3
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/syscall.h>
7 #include <linux/types.h>
8 #include <linux/perf_event.h>
9 #include <asm/barrier.h>
10
11 #if defined(__i386__)
12 #define cpu_relax()     asm volatile("rep; nop" ::: "memory");
13 #define CPUINFO_PROC    {"model name"}
14 #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__)
26 #define cpu_relax()     asm volatile("rep; nop" ::: "memory");
27 #define CPUINFO_PROC    {"model name"}
28 #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"
41 #define CPUINFO_PROC    {"cpu"}
42 #endif
43
44 #ifdef __s390__
45 #define CPUINFO_PROC    {"vendor_id"}
46 #endif
47
48 #ifdef __sh__
49 #define CPUINFO_PROC    {"cpu type"}
50 #endif
51
52 #ifdef __hppa__
53 #define mb()            asm volatile("" ::: "memory")
54 #define wmb()           asm volatile("" ::: "memory")
55 #define rmb()           asm volatile("" ::: "memory")
56 #define CPUINFO_PROC    {"cpu"}
57 #endif
58
59 #ifdef __sparc__
60 #define CPUINFO_PROC    {"cpu"}
61 #endif
62
63 #ifdef __alpha__
64 #define CPUINFO_PROC    {"cpu model"}
65 #endif
66
67 #ifdef __ia64__
68 #define cpu_relax()     asm volatile ("hint @pause" ::: "memory")
69 #define CPUINFO_PROC    {"model name"}
70 #endif
71
72 #ifdef __arm__
73 #define CPUINFO_PROC    {"model name", "Processor"}
74 #endif
75
76 #ifdef __aarch64__
77 #define cpu_relax()     asm volatile("yield" ::: "memory")
78 #endif
79
80 #ifdef __mips__
81 #define mb()            asm volatile(                                   \
82                                 ".set   mips2\n\t"                      \
83                                 "sync\n\t"                              \
84                                 ".set   mips0"                          \
85                                 : /* no output */                       \
86                                 : /* no input */                        \
87                                 : "memory")
88 #define wmb()   mb()
89 #define rmb()   mb()
90 #define CPUINFO_PROC    {"cpu model"}
91 #endif
92
93 #ifdef __arc__
94 #define mb()            asm volatile("" ::: "memory")
95 #define wmb()           asm volatile("" ::: "memory")
96 #define rmb()           asm volatile("" ::: "memory")
97 #define CPUINFO_PROC    {"Processor"}
98 #endif
99
100 #ifdef __metag__
101 #define mb()            asm volatile("" ::: "memory")
102 #define wmb()           asm volatile("" ::: "memory")
103 #define rmb()           asm volatile("" ::: "memory")
104 #define CPUINFO_PROC    {"CPU"}
105 #endif
106
107 #ifdef __xtensa__
108 #define mb()            asm volatile("memw" ::: "memory")
109 #define wmb()           asm volatile("memw" ::: "memory")
110 #define rmb()           asm volatile("" ::: "memory")
111 #define CPUINFO_PROC    {"core ID"}
112 #endif
113
114 #ifdef __tile__
115 #define mb()            asm volatile ("mf" ::: "memory")
116 #define wmb()           asm volatile ("mf" ::: "memory")
117 #define rmb()           asm volatile ("mf" ::: "memory")
118 #define cpu_relax()     asm volatile ("mfspr zero, PASS" ::: "memory")
119 #define CPUINFO_PROC    {"model name"}
120 #endif
121
122 #ifndef cpu_relax
123 #define cpu_relax() barrier()
124 #endif
125
126 static inline int
127 sys_perf_event_open(struct perf_event_attr *attr,
128                       pid_t pid, int cpu, int group_fd,
129                       unsigned long flags)
130 {
131         int fd;
132
133         fd = syscall(__NR_perf_event_open, attr, pid, cpu,
134                      group_fd, flags);
135
136 #ifdef HAVE_ATTR_TEST
137         if (unlikely(test_attr__enabled))
138                 test_attr__open(attr, pid, cpu, fd, group_fd, flags);
139 #endif
140         return fd;
141 }
142
143 #endif /* _PERF_SYS_H */