perf.h 2.1 KB

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