perfcounters.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Ioctls that can be done on a perf counter fd:
  3. */
  4. #define PERF_COUNTER_IOC_ENABLE _IO('$', 0)
  5. #define PERF_COUNTER_IOC_DISABLE _IO('$', 1)
  6. /*
  7. * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
  8. * counters in the current task.
  9. */
  10. #define PR_TASK_PERF_COUNTERS_DISABLE 31
  11. #define PR_TASK_PERF_COUNTERS_ENABLE 32
  12. #define MAX_COUNTERS 64
  13. #define MAX_NR_CPUS 256
  14. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  15. /*
  16. * Pick up some kernel type conventions:
  17. */
  18. #define __user
  19. #define asmlinkage
  20. typedef unsigned int __u32;
  21. typedef unsigned long long __u64;
  22. typedef long long __s64;
  23. /*
  24. * User-space ABI bits:
  25. */
  26. /*
  27. * Generalized performance counter event types, used by the hw_event.type
  28. * parameter of the sys_perf_counter_open() syscall:
  29. */
  30. enum hw_event_types {
  31. /*
  32. * Common hardware events, generalized by the kernel:
  33. */
  34. PERF_COUNT_CPU_CYCLES = 0,
  35. PERF_COUNT_INSTRUCTIONS = 1,
  36. PERF_COUNT_CACHE_REFERENCES = 2,
  37. PERF_COUNT_CACHE_MISSES = 3,
  38. PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
  39. PERF_COUNT_BRANCH_MISSES = 5,
  40. PERF_COUNT_BUS_CYCLES = 6,
  41. PERF_HW_EVENTS_MAX = 7,
  42. /*
  43. * Special "software" counters provided by the kernel, even if
  44. * the hardware does not support performance counters. These
  45. * counters measure various physical and sw events of the
  46. * kernel (and allow the profiling of them as well):
  47. */
  48. PERF_COUNT_CPU_CLOCK = -1,
  49. PERF_COUNT_TASK_CLOCK = -2,
  50. PERF_COUNT_PAGE_FAULTS = -3,
  51. PERF_COUNT_CONTEXT_SWITCHES = -4,
  52. PERF_COUNT_CPU_MIGRATIONS = -5,
  53. PERF_SW_EVENTS_MIN = -6,
  54. };
  55. /*
  56. * IRQ-notification data record type:
  57. */
  58. enum perf_counter_record_type {
  59. PERF_RECORD_SIMPLE = 0,
  60. PERF_RECORD_IRQ = 1,
  61. PERF_RECORD_GROUP = 2,
  62. };
  63. /*
  64. * Hardware event to monitor via a performance monitoring counter:
  65. */
  66. struct perf_counter_hw_event {
  67. __s64 type;
  68. __u64 irq_period;
  69. __u64 record_type;
  70. __u64 read_format;
  71. __u64 disabled : 1, /* off by default */
  72. nmi : 1, /* NMI sampling */
  73. raw : 1, /* raw event type */
  74. inherit : 1, /* children inherit it */
  75. pinned : 1, /* must always be on PMU */
  76. exclusive : 1, /* only group on PMU */
  77. exclude_user : 1, /* don't count user */
  78. exclude_kernel : 1, /* ditto kernel */
  79. exclude_hv : 1, /* ditto hypervisor */
  80. exclude_idle : 1, /* don't count when idle */
  81. __reserved_1 : 54;
  82. __u32 extra_config_len;
  83. __u32 __reserved_4;
  84. __u64 __reserved_2;
  85. __u64 __reserved_3;
  86. };
  87. #ifdef __x86_64__
  88. # define __NR_perf_counter_open 295
  89. #endif
  90. #ifdef __i386__
  91. # define __NR_perf_counter_open 333
  92. #endif
  93. #ifdef __powerpc__
  94. #define __NR_perf_counter_open 319
  95. #endif
  96. asmlinkage int sys_perf_counter_open(
  97. struct perf_counter_hw_event *hw_event_uptr __user,
  98. pid_t pid,
  99. int cpu,
  100. int group_fd,
  101. unsigned long flags)
  102. {
  103. int ret;
  104. ret = syscall(
  105. __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
  106. #if defined(__x86_64__) || defined(__i386__)
  107. if (ret < 0 && ret > -4096) {
  108. errno = -ret;
  109. ret = -1;
  110. }
  111. #endif
  112. return ret;
  113. }