8 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
11 #if !__GLIBC_PREREQ(2, 6)
12 int __weak sched_getcpu(void)
20 static int perf_flag_probe(void)
22 /* use 'safest' configuration as used in perf_evsel__fallback() */
23 struct perf_event_attr attr = {
24 .type = PERF_TYPE_SOFTWARE,
25 .config = PERF_COUNT_SW_CPU_CLOCK,
32 char sbuf[STRERR_BUFSIZE];
39 * Using -1 for the pid is a workaround to avoid gratuitous jump label
43 /* check cloexec flag */
44 fd = sys_perf_event_open(&attr, pid, cpu, -1,
45 PERF_FLAG_FD_CLOEXEC);
46 if (fd < 0 && pid == -1 && errno == EACCES) {
59 WARN_ONCE(err != EINVAL && err != EBUSY,
60 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
61 err, strerror_r(err, sbuf, sizeof(sbuf)));
63 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
65 fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
66 if (fd < 0 && pid == -1 && errno == EACCES) {
77 if (WARN_ONCE(fd < 0 && err != EBUSY,
78 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
79 err, strerror_r(err, sbuf, sizeof(sbuf))))
85 unsigned long perf_event_open_cloexec_flag(void)
90 if (perf_flag_probe() <= 0)