2 * Ioctls that can be done on a perf counter fd:
4 #define PERF_COUNTER_IOC_ENABLE _IO('$', 0)
5 #define PERF_COUNTER_IOC_DISABLE _IO('$', 1)
8 * prctl(PR_TASK_PERF_COUNTERS_DISABLE) will (cheaply) disable all
9 * counters in the current task.
11 #define PR_TASK_PERF_COUNTERS_DISABLE 31
12 #define PR_TASK_PERF_COUNTERS_ENABLE 32
14 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
20 clock_gettime(CLOCK_MONOTONIC, &ts); \
21 ts.tv_sec * 1000000000ULL + ts.tv_nsec; \
25 * Pick up some kernel type conventions:
30 typedef unsigned int __u32;
31 typedef unsigned long long __u64;
32 typedef long long __s64;
35 * User-space ABI bits:
39 * Generalized performance counter event types, used by the hw_event.type
40 * parameter of the sys_perf_counter_open() syscall:
44 * Common hardware events, generalized by the kernel:
46 PERF_COUNT_CPU_CYCLES = 0,
47 PERF_COUNT_INSTRUCTIONS = 1,
48 PERF_COUNT_CACHE_REFERENCES = 2,
49 PERF_COUNT_CACHE_MISSES = 3,
50 PERF_COUNT_BRANCH_INSTRUCTIONS = 4,
51 PERF_COUNT_BRANCH_MISSES = 5,
52 PERF_COUNT_BUS_CYCLES = 6,
54 PERF_HW_EVENTS_MAX = 7,
57 * Special "software" counters provided by the kernel, even if
58 * the hardware does not support performance counters. These
59 * counters measure various physical and sw events of the
60 * kernel (and allow the profiling of them as well):
62 PERF_COUNT_CPU_CLOCK = -1,
63 PERF_COUNT_TASK_CLOCK = -2,
64 PERF_COUNT_PAGE_FAULTS = -3,
65 PERF_COUNT_CONTEXT_SWITCHES = -4,
66 PERF_COUNT_CPU_MIGRATIONS = -5,
68 PERF_SW_EVENTS_MIN = -6,
72 * IRQ-notification data record type:
74 enum perf_counter_record_type {
75 PERF_RECORD_SIMPLE = 0,
77 PERF_RECORD_GROUP = 2,
81 * Hardware event to monitor via a performance monitoring counter:
83 struct perf_counter_hw_event {
90 __u64 disabled : 1, /* off by default */
91 nmi : 1, /* NMI sampling */
92 raw : 1, /* raw event type */
93 inherit : 1, /* children inherit it */
94 pinned : 1, /* must always be on PMU */
95 exclusive : 1, /* only group on PMU */
96 exclude_user : 1, /* don't count user */
97 exclude_kernel : 1, /* ditto kernel */
98 exclude_hv : 1, /* ditto hypervisor */
99 exclude_idle : 1, /* don't count when idle */
103 __u32 extra_config_len;
112 # define __NR_perf_counter_open 295
116 # define __NR_perf_counter_open 333
120 #define __NR_perf_counter_open 319
123 asmlinkage int sys_perf_counter_open(
125 struct perf_counter_hw_event *hw_event_uptr __user,
134 __NR_perf_counter_open, hw_event_uptr, pid, cpu, group_fd, flags);
135 #if defined(__x86_64__) || defined(__i386__)
136 if (ret < 0 && ret > -4096) {