Skip to content

Commit 4112eb1

Browse files
committed
perf evlist: Default to syswide target when no thread/cpu maps set
If all a tool wants is to do system wide event monitoring, there is no more the need to setup thread_map and cpu_map objects, just call perf_evlist__open() and it will do create one fd per CPU monitoring all threads. Cc: Adrian Hunter <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: David Ahern <[email protected]> Cc: Don Zickus <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Jean Pihet <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 1aaf63b commit 4112eb1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tools/perf/util/evlist.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,11 +1175,51 @@ void perf_evlist__close(struct perf_evlist *evlist)
11751175
}
11761176
}
11771177

1178+
static int perf_evlist__create_syswide_maps(struct perf_evlist *evlist)
1179+
{
1180+
int err = -ENOMEM;
1181+
1182+
/*
1183+
* Try reading /sys/devices/system/cpu/online to get
1184+
* an all cpus map.
1185+
*
1186+
* FIXME: -ENOMEM is the best we can do here, the cpu_map
1187+
* code needs an overhaul to properly forward the
1188+
* error, and we may not want to do that fallback to a
1189+
* default cpu identity map :-\
1190+
*/
1191+
evlist->cpus = cpu_map__new(NULL);
1192+
if (evlist->cpus == NULL)
1193+
goto out;
1194+
1195+
evlist->threads = thread_map__new_dummy();
1196+
if (evlist->threads == NULL)
1197+
goto out_free_cpus;
1198+
1199+
err = 0;
1200+
out:
1201+
return err;
1202+
out_free_cpus:
1203+
cpu_map__delete(evlist->cpus);
1204+
evlist->cpus = NULL;
1205+
goto out;
1206+
}
1207+
11781208
int perf_evlist__open(struct perf_evlist *evlist)
11791209
{
11801210
struct perf_evsel *evsel;
11811211
int err;
11821212

1213+
/*
1214+
* Default: one fd per CPU, all threads, aka systemwide
1215+
* as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL
1216+
*/
1217+
if (evlist->threads == NULL && evlist->cpus == NULL) {
1218+
err = perf_evlist__create_syswide_maps(evlist);
1219+
if (err < 0)
1220+
goto out_err;
1221+
}
1222+
11831223
perf_evlist__update_id_pos(evlist);
11841224

11851225
evlist__for_each(evlist, evsel) {

0 commit comments

Comments
 (0)