10 #include <asm/unistd.h> 11 #include <sys/syscall.h> 19 int err =
syscall(__NR_getcpu, &cpu, NULL, NULL);
31 struct perf_event_attr attr = {
32 .type = PERF_TYPE_SOFTWARE,
33 .config = PERF_COUNT_SW_CPU_CLOCK,
54 if (fd < 0 && pid == -1 && errno == EACCES) {
67 WARN_ONCE(err != EINVAL && err != EBUSY,
68 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
69 err, str_error_r(err, sbuf,
sizeof(sbuf)));
74 if (fd < 0 && pid == -1 && errno == EACCES) {
85 if (WARN_ONCE(fd < 0 && err != EBUSY,
86 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
87 err, str_error_r(err, sbuf,
sizeof(sbuf))))
static unsigned long flag
static int sys_perf_event_open(struct perf_event_attr *attr, pid_t pid, int cpu, int group_fd, unsigned long flags)
static int perf_flag_probe(void)
unsigned long perf_event_open_cloexec_flag(void)
int __weak sched_getcpu(void)
#define PERF_FLAG_FD_CLOEXEC