perf-sys.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/compiler.h>
  8. #include <linux/perf_event.h>
  9. #include <asm/barrier.h>
  10. #if defined(__i386__)
  11. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  12. #define CPUINFO_PROC {"model name"}
  13. #endif
  14. #if defined(__x86_64__)
  15. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  16. #define CPUINFO_PROC {"model name"}
  17. #endif
  18. #ifdef __powerpc__
  19. #define CPUINFO_PROC {"cpu"}
  20. #endif
  21. #ifdef __s390__
  22. #define CPUINFO_PROC {"vendor_id"}
  23. #endif
  24. #ifdef __sh__
  25. #define CPUINFO_PROC {"cpu type"}
  26. #endif
  27. #ifdef __hppa__
  28. #define CPUINFO_PROC {"cpu"}
  29. #endif
  30. #ifdef __sparc__
  31. #define CPUINFO_PROC {"cpu"}
  32. #endif
  33. #ifdef __alpha__
  34. #define CPUINFO_PROC {"cpu model"}
  35. #endif
  36. #ifdef __ia64__
  37. #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
  38. #define CPUINFO_PROC {"model name"}
  39. #endif
  40. #ifdef __arm__
  41. #define CPUINFO_PROC {"model name", "Processor"}
  42. #endif
  43. #ifdef __aarch64__
  44. #define cpu_relax() asm volatile("yield" ::: "memory")
  45. #endif
  46. #ifdef __mips__
  47. #define CPUINFO_PROC {"cpu model"}
  48. #endif
  49. #ifdef __arc__
  50. #define CPUINFO_PROC {"Processor"}
  51. #endif
  52. #ifdef __metag__
  53. #define CPUINFO_PROC {"CPU"}
  54. #endif
  55. #ifdef __xtensa__
  56. #define CPUINFO_PROC {"core ID"}
  57. #endif
  58. #ifdef __tile__
  59. #define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory")
  60. #define CPUINFO_PROC {"model name"}
  61. #endif
  62. #ifndef cpu_relax
  63. #define cpu_relax() barrier()
  64. #endif
  65. static inline int
  66. sys_perf_event_open(struct perf_event_attr *attr,
  67. pid_t pid, int cpu, int group_fd,
  68. unsigned long flags)
  69. {
  70. int fd;
  71. fd = syscall(__NR_perf_event_open, attr, pid, cpu,
  72. group_fd, flags);
  73. #ifdef HAVE_ATTR_TEST
  74. if (unlikely(test_attr__enabled))
  75. test_attr__open(attr, pid, cpu, fd, group_fd, flags);
  76. #endif
  77. return fd;
  78. }
  79. #endif /* _PERF_SYS_H */