- if (system_wide) {
- int cpu;
-
- for (cpu = 0; cpu < nr_cpus; cpu++) {
- fd[cpu][counter][0] = sys_perf_event_open(attr,
- -1, cpumap[cpu], -1, 0);
- if (fd[cpu][counter][0] < 0) {
- if (errno == EPERM || errno == EACCES)
- *perm_err = true;
- error(ERR_PERF_OPEN, counter,
- fd[cpu][counter][0], strerror(errno));
- } else {
- ++ncreated;
- }
- }
- } else {
- attr->inherit = !no_inherit;
- if (target_pid == -1 && target_tid == -1) {
- attr->disabled = 1;
- attr->enable_on_exec = 1;
- }
- for (thread = 0; thread < thread_num; thread++) {
- fd[0][counter][thread] = sys_perf_event_open(attr,
- all_tids[thread], -1, -1, 0);
- if (fd[0][counter][thread] < 0) {
- if (errno == EPERM || errno == EACCES)
- *perm_err = true;
- error(ERR_PERF_OPEN, counter,
- fd[0][counter][thread],
- strerror(errno));
- } else {
- ++ncreated;
- }
- }
+ if (system_wide)
+ return perf_evsel__open_per_cpu(evsel, cpus);
+
+ attr->inherit = !no_inherit;
+ if (target_pid == -1 && target_tid == -1) {
+ attr->disabled = 1;
+ attr->enable_on_exec = 1;