perf.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #ifndef _PERF_PERF_H
  2. #define _PERF_PERF_H
  3. #include <asm/unistd.h>
  4. #if defined(__i386__)
  5. #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  6. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  7. #define CPUINFO_PROC "model name"
  8. #ifndef __NR_perf_event_open
  9. # define __NR_perf_event_open 336
  10. #endif
  11. #endif
  12. #if defined(__x86_64__)
  13. #define rmb() asm volatile("lfence" ::: "memory")
  14. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  15. #define CPUINFO_PROC "model name"
  16. #ifndef __NR_perf_event_open
  17. # define __NR_perf_event_open 298
  18. #endif
  19. #endif
  20. #ifdef __powerpc__
  21. #include "../../arch/powerpc/include/uapi/asm/unistd.h"
  22. #define rmb() asm volatile ("sync" ::: "memory")
  23. #define cpu_relax() asm volatile ("" ::: "memory");
  24. #define CPUINFO_PROC "cpu"
  25. #endif
  26. #ifdef __s390__
  27. #define rmb() asm volatile("bcr 15,0" ::: "memory")
  28. #define cpu_relax() asm volatile("" ::: "memory");
  29. #endif
  30. #ifdef __sh__
  31. #if defined(__SH4A__) || defined(__SH5__)
  32. # define rmb() asm volatile("synco" ::: "memory")
  33. #else
  34. # define rmb() asm volatile("" ::: "memory")
  35. #endif
  36. #define cpu_relax() asm volatile("" ::: "memory")
  37. #define CPUINFO_PROC "cpu type"
  38. #endif
  39. #ifdef __hppa__
  40. #define rmb() asm volatile("" ::: "memory")
  41. #define cpu_relax() asm volatile("" ::: "memory");
  42. #define CPUINFO_PROC "cpu"
  43. #endif
  44. #ifdef __sparc__
  45. #define rmb() asm volatile("":::"memory")
  46. #define cpu_relax() asm volatile("":::"memory")
  47. #define CPUINFO_PROC "cpu"
  48. #endif
  49. #ifdef __alpha__
  50. #define rmb() asm volatile("mb" ::: "memory")
  51. #define cpu_relax() asm volatile("" ::: "memory")
  52. #define CPUINFO_PROC "cpu model"
  53. #endif
  54. #ifdef __ia64__
  55. #define rmb() asm volatile ("mf" ::: "memory")
  56. #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
  57. #define CPUINFO_PROC "model name"
  58. #endif
  59. #ifdef __arm__
  60. /*
  61. * Use the __kuser_memory_barrier helper in the CPU helper page. See
  62. * arch/arm/kernel/entry-armv.S in the kernel source for details.
  63. */
  64. #define rmb() ((void(*)(void))0xffff0fa0)()
  65. #define cpu_relax() asm volatile("":::"memory")
  66. #define CPUINFO_PROC "Processor"
  67. #endif
  68. #ifdef __aarch64__
  69. #define rmb() asm volatile("dmb ld" ::: "memory")
  70. #define cpu_relax() asm volatile("yield" ::: "memory")
  71. #endif
  72. #ifdef __mips__
  73. #define rmb() asm volatile( \
  74. ".set mips2\n\t" \
  75. "sync\n\t" \
  76. ".set mips0" \
  77. : /* no output */ \
  78. : /* no input */ \
  79. : "memory")
  80. #define cpu_relax() asm volatile("" ::: "memory")
  81. #define CPUINFO_PROC "cpu model"
  82. #endif
  83. #include <time.h>
  84. #include <unistd.h>
  85. #include <sys/types.h>
  86. #include <sys/syscall.h>
  87. #include <linux/perf_event.h>
  88. #include "util/types.h"
  89. #include <stdbool.h>
  90. /*
  91. * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
  92. * counters in the current task.
  93. */
  94. #define PR_TASK_PERF_EVENTS_DISABLE 31
  95. #define PR_TASK_PERF_EVENTS_ENABLE 32
  96. #ifndef NSEC_PER_SEC
  97. # define NSEC_PER_SEC 1000000000ULL
  98. #endif
  99. static inline unsigned long long rdclock(void)
  100. {
  101. struct timespec ts;
  102. clock_gettime(CLOCK_MONOTONIC, &ts);
  103. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  104. }
  105. /*
  106. * Pick up some kernel type conventions:
  107. */
  108. #define __user
  109. #define asmlinkage
  110. #define unlikely(x) __builtin_expect(!!(x), 0)
  111. #define min(x, y) ({ \
  112. typeof(x) _min1 = (x); \
  113. typeof(y) _min2 = (y); \
  114. (void) (&_min1 == &_min2); \
  115. _min1 < _min2 ? _min1 : _min2; })
  116. extern bool test_attr__enabled;
  117. void test_attr__init(void);
  118. void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu,
  119. int fd, int group_fd, unsigned long flags);
  120. static inline int
  121. sys_perf_event_open(struct perf_event_attr *attr,
  122. pid_t pid, int cpu, int group_fd,
  123. unsigned long flags)
  124. {
  125. int fd;
  126. fd = syscall(__NR_perf_event_open, attr, pid, cpu,
  127. group_fd, flags);
  128. if (unlikely(test_attr__enabled))
  129. test_attr__open(attr, pid, cpu, fd, group_fd, flags);
  130. return fd;
  131. }
  132. #define MAX_COUNTERS 256
  133. #define MAX_NR_CPUS 256
  134. struct ip_callchain {
  135. u64 nr;
  136. u64 ips[0];
  137. };
  138. struct branch_flags {
  139. u64 mispred:1;
  140. u64 predicted:1;
  141. u64 reserved:62;
  142. };
  143. struct branch_entry {
  144. u64 from;
  145. u64 to;
  146. struct branch_flags flags;
  147. };
  148. struct branch_stack {
  149. u64 nr;
  150. struct branch_entry entries[0];
  151. };
  152. extern const char *input_name;
  153. extern bool perf_host, perf_guest;
  154. extern const char perf_version_string[];
  155. void pthread__unblock_sigwinch(void);
  156. #include "util/target.h"
  157. enum perf_call_graph_mode {
  158. CALLCHAIN_NONE,
  159. CALLCHAIN_FP,
  160. CALLCHAIN_DWARF
  161. };
  162. struct perf_record_opts {
  163. struct perf_target target;
  164. int call_graph;
  165. bool group;
  166. bool inherit_stat;
  167. bool no_delay;
  168. bool no_inherit;
  169. bool no_samples;
  170. bool pipe_output;
  171. bool raw_samples;
  172. bool sample_address;
  173. bool sample_time;
  174. bool period;
  175. unsigned int freq;
  176. unsigned int mmap_pages;
  177. unsigned int user_freq;
  178. u64 branch_stack;
  179. u64 default_interval;
  180. u64 user_interval;
  181. u16 stack_dump_size;
  182. };
  183. #endif