perf.h 5.4 KB

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