Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evlist: Add evlist__add_dummy_on_all_cpus()

Add evlist__add_dummy_on_all_cpus() to enable creating a system-wide dummy
event that sets up the system-wide maps before map propagation.

For convenience, add evlist__add_aux_dummy() so that the logic can be used
whether or not the event needs to be system-wide.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Link: https://lore.kernel.org/r/20220524075436.29144-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
126d68fd 82944899

+50
+45
tools/perf/util/evlist.c
··· 264 264 return 0; 265 265 } 266 266 267 + static void evlist__add_on_all_cpus(struct evlist *evlist, struct evsel *evsel) 268 + { 269 + evsel->core.system_wide = true; 270 + 271 + /* 272 + * All CPUs. 273 + * 274 + * Note perf_event_open() does not accept CPUs that are not online, so 275 + * in fact this CPU list will include only all online CPUs. 276 + */ 277 + perf_cpu_map__put(evsel->core.own_cpus); 278 + evsel->core.own_cpus = perf_cpu_map__new(NULL); 279 + perf_cpu_map__put(evsel->core.cpus); 280 + evsel->core.cpus = perf_cpu_map__get(evsel->core.own_cpus); 281 + 282 + /* No threads */ 283 + perf_thread_map__put(evsel->core.threads); 284 + evsel->core.threads = perf_thread_map__new_dummy(); 285 + 286 + evlist__add(evlist, evsel); 287 + } 288 + 289 + struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide) 290 + { 291 + struct evsel *evsel = evlist__dummy_event(evlist); 292 + 293 + if (!evsel) 294 + return NULL; 295 + 296 + evsel->core.attr.exclude_kernel = 1; 297 + evsel->core.attr.exclude_guest = 1; 298 + evsel->core.attr.exclude_hv = 1; 299 + evsel->core.attr.freq = 0; 300 + evsel->core.attr.sample_period = 1; 301 + evsel->no_aux_samples = true; 302 + evsel->name = strdup("dummy:u"); 303 + 304 + if (system_wide) 305 + evlist__add_on_all_cpus(evlist, evsel); 306 + else 307 + evlist__add(evlist, evsel); 308 + 309 + return evsel; 310 + } 311 + 267 312 static int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs) 268 313 { 269 314 struct evsel *evsel, *n;
+5
tools/perf/util/evlist.h
··· 114 114 struct evsel *arch_evlist__leader(struct list_head *list); 115 115 116 116 int evlist__add_dummy(struct evlist *evlist); 117 + struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide); 118 + static inline struct evsel *evlist__add_dummy_on_all_cpus(struct evlist *evlist) 119 + { 120 + return evlist__add_aux_dummy(evlist, true); 121 + } 117 122 118 123 int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr, 119 124 evsel__sb_cb_t cb, void *data);