perf.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 __hppa__
  19. #include "../../arch/parisc/include/asm/unistd.h"
  20. #define rmb() asm volatile("" ::: "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 "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 unlikely(x) __builtin_expect(!!(x), 0)
  50. #define min(x, y) ({ \
  51. typeof(x) _min1 = (x); \
  52. typeof(y) _min2 = (y); \
  53. (void) (&_min1 == &_min2); \
  54. _min1 < _min2 ? _min1 : _min2; })
  55. static inline int
  56. sys_perf_counter_open(struct perf_counter_attr *attr,
  57. pid_t pid, int cpu, int group_fd,
  58. unsigned long flags)
  59. {
  60. attr->size = sizeof(*attr);
  61. return syscall(__NR_perf_counter_open, attr, pid, cpu,
  62. group_fd, flags);
  63. }
  64. #define MAX_COUNTERS 256
  65. #define MAX_NR_CPUS 256
  66. struct perf_file_header {
  67. u64 version;
  68. u64 sample_type;
  69. u64 data_size;
  70. };
  71. #endif