perf.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <time.h>
  38. #include <unistd.h>
  39. #include <sys/types.h>
  40. #include <sys/syscall.h>
  41. #include "../../include/linux/perf_counter.h"
  42. #include "util/types.h"
  43. /*
  44. * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
  45. * counters in the current task.
  46. */
  47. #define PR_TASK_PERF_COUNTERS_DISABLE 31
  48. #define PR_TASK_PERF_COUNTERS_ENABLE 32
  49. #ifndef NSEC_PER_SEC
  50. # define NSEC_PER_SEC 1000000000ULL
  51. #endif
  52. static inline unsigned long long rdclock(void)
  53. {
  54. struct timespec ts;
  55. clock_gettime(CLOCK_MONOTONIC, &ts);
  56. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  57. }
  58. /*
  59. * Pick up some kernel type conventions:
  60. */
  61. #define __user
  62. #define asmlinkage
  63. #define __used __attribute__((__unused__))
  64. #define unlikely(x) __builtin_expect(!!(x), 0)
  65. #define min(x, y) ({ \
  66. typeof(x) _min1 = (x); \
  67. typeof(y) _min2 = (y); \
  68. (void) (&_min1 == &_min2); \
  69. _min1 < _min2 ? _min1 : _min2; })
  70. static inline int
  71. sys_perf_counter_open(struct perf_counter_attr *attr,
  72. pid_t pid, int cpu, int group_fd,
  73. unsigned long flags)
  74. {
  75. attr->size = sizeof(*attr);
  76. return syscall(__NR_perf_counter_open, attr, pid, cpu,
  77. group_fd, flags);
  78. }
  79. #define MAX_COUNTERS 256
  80. #define MAX_NR_CPUS 256
  81. struct ip_callchain {
  82. u64 nr;
  83. u64 ips[0];
  84. };
  85. #endif