perf.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef _PERF_PERF_H
  2. #define _PERF_PERF_H
  3. #if defined(__i386__)
  4. #include "../../arch/x86/include/asm/unistd.h"
  5. #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
  6. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  7. #endif
  8. #if defined(__x86_64__)
  9. #include "../../arch/x86/include/asm/unistd.h"
  10. #define rmb() asm volatile("lfence" ::: "memory")
  11. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  12. #endif
  13. #ifdef __powerpc__
  14. #include "../../arch/powerpc/include/asm/unistd.h"
  15. #define rmb() asm volatile ("sync" ::: "memory")
  16. #define cpu_relax() asm volatile ("" ::: "memory");
  17. #endif
  18. #ifdef __s390__
  19. #include "../../arch/s390/include/asm/unistd.h"
  20. #define rmb() asm volatile("bcr 15,0" ::: "memory")
  21. #define cpu_relax() asm volatile("" ::: "memory");
  22. #endif
  23. #ifdef __sh__
  24. #include "../../arch/sh/include/asm/unistd.h"
  25. #if defined(__SH4A__) || defined(__SH5__)
  26. # define rmb() asm volatile("synco" ::: "memory")
  27. #else
  28. # define rmb() asm volatile("" ::: "memory")
  29. #endif
  30. #define cpu_relax() asm volatile("" ::: "memory")
  31. #endif
  32. #ifdef __hppa__
  33. #include "../../arch/parisc/include/asm/unistd.h"
  34. #define rmb() asm volatile("" ::: "memory")
  35. #define cpu_relax() asm volatile("" ::: "memory");
  36. #endif
  37. #ifdef __sparc__
  38. #include "../../arch/sparc/include/asm/unistd.h"
  39. #define rmb() asm volatile("":::"memory")
  40. #define cpu_relax() asm volatile("":::"memory")
  41. #endif
  42. #ifdef __alpha__
  43. #include "../../arch/alpha/include/asm/unistd.h"
  44. #define rmb() asm volatile("mb" ::: "memory")
  45. #define cpu_relax() asm volatile("" ::: "memory")
  46. #endif
  47. #ifdef __ia64__
  48. #include "../../arch/ia64/include/asm/unistd.h"
  49. #define rmb() asm volatile ("mf" ::: "memory")
  50. #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
  51. #endif
  52. #ifdef __arm__
  53. #include "../../arch/arm/include/asm/unistd.h"
  54. /*
  55. * Use the __kuser_memory_barrier helper in the CPU helper page. See
  56. * arch/arm/kernel/entry-armv.S in the kernel source for details.
  57. */
  58. #define rmb() asm volatile("mov r0, #0xffff0fff; mov lr, pc;" \
  59. "sub pc, r0, #95" ::: "r0", "lr", "cc", \
  60. "memory")
  61. #define cpu_relax() asm volatile("":::"memory")
  62. #endif
  63. #include <time.h>
  64. #include <unistd.h>
  65. #include <sys/types.h>
  66. #include <sys/syscall.h>
  67. #include "../../include/linux/perf_event.h"
  68. #include "util/types.h"
  69. /*
  70. * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
  71. * counters in the current task.
  72. */
  73. #define PR_TASK_PERF_EVENTS_DISABLE 31
  74. #define PR_TASK_PERF_EVENTS_ENABLE 32
  75. #ifndef NSEC_PER_SEC
  76. # define NSEC_PER_SEC 1000000000ULL
  77. #endif
  78. static inline unsigned long long rdclock(void)
  79. {
  80. struct timespec ts;
  81. clock_gettime(CLOCK_MONOTONIC, &ts);
  82. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  83. }
  84. /*
  85. * Pick up some kernel type conventions:
  86. */
  87. #define __user
  88. #define asmlinkage
  89. #define __used __attribute__((__unused__))
  90. #define unlikely(x) __builtin_expect(!!(x), 0)
  91. #define min(x, y) ({ \
  92. typeof(x) _min1 = (x); \
  93. typeof(y) _min2 = (y); \
  94. (void) (&_min1 == &_min2); \
  95. _min1 < _min2 ? _min1 : _min2; })
  96. static inline int
  97. sys_perf_event_open(struct perf_event_attr *attr,
  98. pid_t pid, int cpu, int group_fd,
  99. unsigned long flags)
  100. {
  101. attr->size = sizeof(*attr);
  102. return syscall(__NR_perf_event_open, attr, pid, cpu,
  103. group_fd, flags);
  104. }
  105. #define MAX_COUNTERS 256
  106. #define MAX_NR_CPUS 256
  107. struct ip_callchain {
  108. u64 nr;
  109. u64 ips[0];
  110. };
  111. #endif