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