8 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
10 int __weak sched_getcpu(void)
16 static int perf_flag_probe(void)
18 /* use 'safest' configuration as used in perf_evsel__fallback() */
19 struct perf_event_attr attr = {
20 .type = PERF_TYPE_SOFTWARE,
21 .config = PERF_COUNT_SW_CPU_CLOCK,
28 char sbuf[STRERR_BUFSIZE];
35 * Using -1 for the pid is a workaround to avoid gratuitous jump label
39 /* check cloexec flag */
40 fd = sys_perf_event_open(&attr, pid, cpu, -1,
41 PERF_FLAG_FD_CLOEXEC);
42 if (fd < 0 && pid == -1 && errno == EACCES) {
55 WARN_ONCE(err != EINVAL && err != EBUSY,
56 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
57 err, strerror_r(err, sbuf, sizeof(sbuf)));
59 /* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
61 fd = sys_perf_event_open(&attr, pid, cpu, -1, 0);
62 if (fd < 0 && pid == -1 && errno == EACCES) {
73 if (WARN_ONCE(fd < 0 && err != EBUSY,
74 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
75 err, strerror_r(err, sbuf, sizeof(sbuf))))
81 unsigned long perf_event_open_cloexec_flag(void)
86 if (perf_flag_probe() <= 0)