perf-sys.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _PERF_SYS_H
  2. #define _PERF_SYS_H
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/syscall.h>
  6. #include <linux/types.h>
  7. #include <linux/perf_event.h>
  8. #include <asm/barrier.h>
  9. #if defined(__i386__)
  10. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  11. #define CPUINFO_PROC {"model name"}
  12. #ifndef __NR_perf_event_open
  13. # define __NR_perf_event_open 336
  14. #endif
  15. #ifndef __NR_futex
  16. # define __NR_futex 240
  17. #endif
  18. #ifndef __NR_gettid
  19. # define __NR_gettid 224
  20. #endif
  21. #endif
  22. #if defined(__x86_64__)
  23. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  24. #define CPUINFO_PROC {"model name"}
  25. #ifndef __NR_perf_event_open
  26. # define __NR_perf_event_open 298
  27. #endif
  28. #ifndef __NR_futex
  29. # define __NR_futex 202
  30. #endif
  31. #ifndef __NR_gettid
  32. # define __NR_gettid 186
  33. #endif
  34. #endif
  35. #ifdef __powerpc__
  36. #include "../../arch/powerpc/include/uapi/asm/unistd.h"
  37. #define CPUINFO_PROC {"cpu"}
  38. #endif
  39. #ifdef __s390__
  40. #define CPUINFO_PROC {"vendor_id"}
  41. #endif
  42. #ifdef __sh__
  43. #define CPUINFO_PROC {"cpu type"}
  44. #endif
  45. #ifdef __hppa__
  46. #define CPUINFO_PROC {"cpu"}
  47. #endif
  48. #ifdef __sparc__
  49. #define CPUINFO_PROC {"cpu"}
  50. #endif
  51. #ifdef __alpha__
  52. #define CPUINFO_PROC {"cpu model"}
  53. #endif
  54. #ifdef __ia64__
  55. #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
  56. #define CPUINFO_PROC {"model name"}
  57. #endif
  58. #ifdef __arm__
  59. #define CPUINFO_PROC {"model name", "Processor"}
  60. #endif
  61. #ifdef __aarch64__
  62. #define cpu_relax() asm volatile("yield" ::: "memory")
  63. #endif
  64. #ifdef __mips__
  65. #define CPUINFO_PROC {"cpu model"}
  66. #endif
  67. #ifdef __arc__
  68. #define CPUINFO_PROC {"Processor"}
  69. #endif
  70. #ifdef __metag__
  71. #define CPUINFO_PROC {"CPU"}
  72. #endif
  73. #ifdef __xtensa__
  74. #define CPUINFO_PROC {"core ID"}
  75. #endif
  76. #ifdef __tile__
  77. #define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory")
  78. #define CPUINFO_PROC {"model name"}
  79. #endif
  80. #ifndef cpu_relax
  81. #define cpu_relax() barrier()
  82. #endif
  83. static inline int
  84. sys_perf_event_open(struct perf_event_attr *attr,
  85. pid_t pid, int cpu, int group_fd,
  86. unsigned long flags)
  87. {
  88. int fd;
  89. fd = syscall(__NR_perf_event_open, attr, pid, cpu,
  90. group_fd, flags);
  91. #ifdef HAVE_ATTR_TEST
  92. if (unlikely(test_attr__enabled))
  93. test_attr__open(attr, pid, cpu, fd, group_fd, flags);
  94. #endif
  95. return fd;
  96. }
  97. #endif /* _PERF_SYS_H */