perf-sys.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #endif
  13. #if defined(__x86_64__)
  14. #define cpu_relax() asm volatile("rep; nop" ::: "memory");
  15. #define CPUINFO_PROC {"model name"}
  16. #endif
  17. #ifdef __powerpc__
  18. #include "../../arch/powerpc/include/uapi/asm/unistd.h"
  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 */