perf.h 2.0 KB

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