perf.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef _PERF_PERF_H
  2. #define _PERF_PERF_H
  3. #if defined(__x86_64__) || defined(__i386__)
  4. #include "../../arch/x86/include/asm/unistd.h"
  5. #define rmb() asm volatile("lfence" ::: "memory")
  6. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  7. #endif
  8. #ifdef __powerpc__
  9. #include "../../arch/powerpc/include/asm/unistd.h"
  10. #define rmb() asm volatile ("sync" ::: "memory")
  11. #define cpu_relax() asm volatile ("" ::: "memory");
  12. #endif
  13. #ifdef __s390__
  14. #include "../../arch/s390/include/asm/unistd.h"
  15. #define rmb() asm volatile("bcr 15,0" ::: "memory")
  16. #define cpu_relax() asm volatile("" ::: "memory");
  17. #endif
  18. #ifdef __sh__
  19. #include "../../arch/sh/include/asm/unistd.h"
  20. #if defined(__SH4A__) || defined(__SH5__)
  21. # define rmb() asm volatile("synco" ::: "memory")
  22. #else
  23. # define rmb() asm volatile("" ::: "memory")
  24. #endif
  25. #define cpu_relax() asm volatile("" ::: "memory")
  26. #endif
  27. #ifdef __hppa__
  28. #include "../../arch/parisc/include/asm/unistd.h"
  29. #define rmb() asm volatile("" ::: "memory")
  30. #define cpu_relax() asm volatile("" ::: "memory");
  31. #endif
  32. #include <time.h>
  33. #include <unistd.h>
  34. #include <sys/types.h>
  35. #include <sys/syscall.h>
  36. #include "../../include/linux/perf_counter.h"
  37. #include "util/types.h"
  38. /*
  39. * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
  40. * counters in the current task.
  41. */
  42. #define PR_TASK_PERF_COUNTERS_DISABLE 31
  43. #define PR_TASK_PERF_COUNTERS_ENABLE 32
  44. #ifndef NSEC_PER_SEC
  45. # define NSEC_PER_SEC 1000000000ULL
  46. #endif
  47. static inline unsigned long long rdclock(void)
  48. {
  49. struct timespec ts;
  50. clock_gettime(CLOCK_MONOTONIC, &ts);
  51. return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
  52. }
  53. /*
  54. * Pick up some kernel type conventions:
  55. */
  56. #define __user
  57. #define asmlinkage
  58. #define unlikely(x) __builtin_expect(!!(x), 0)
  59. #define min(x, y) ({ \
  60. typeof(x) _min1 = (x); \
  61. typeof(y) _min2 = (y); \
  62. (void) (&_min1 == &_min2); \
  63. _min1 < _min2 ? _min1 : _min2; })
  64. static inline int
  65. sys_perf_counter_open(struct perf_counter_attr *attr,
  66. pid_t pid, int cpu, int group_fd,
  67. unsigned long flags)
  68. {
  69. attr->size = sizeof(*attr);
  70. return syscall(__NR_perf_counter_open, attr, pid, cpu,
  71. group_fd, flags);
  72. }
  73. #define MAX_COUNTERS 256
  74. #define MAX_NR_CPUS 256
  75. struct ip_callchain {
  76. u64 nr;
  77. u64 ips[0];
  78. };
  79. #endif