|
5 | 5 | #include <internal/evsel.h> |
6 | 6 | #include <linux/zalloc.h> |
7 | 7 | #include <stdlib.h> |
| 8 | +#include <perf/cpumap.h> |
| 9 | +#include <perf/threadmap.h> |
8 | 10 |
|
9 | 11 | void perf_evlist__init(struct perf_evlist *evlist) |
10 | 12 | { |
11 | 13 | INIT_LIST_HEAD(&evlist->entries); |
12 | 14 | evlist->nr_entries = 0; |
13 | 15 | } |
14 | 16 |
|
| 17 | +static void __perf_evlist__propagate_maps(struct perf_evlist *evlist, |
| 18 | + struct perf_evsel *evsel) |
| 19 | +{ |
| 20 | + /* |
| 21 | + * We already have cpus for evsel (via PMU sysfs) so |
| 22 | + * keep it, if there's no target cpu list defined. |
| 23 | + */ |
| 24 | + if (!evsel->own_cpus || evlist->has_user_cpus) { |
| 25 | + perf_cpu_map__put(evsel->cpus); |
| 26 | + evsel->cpus = perf_cpu_map__get(evlist->cpus); |
| 27 | + } else if (evsel->cpus != evsel->own_cpus) { |
| 28 | + perf_cpu_map__put(evsel->cpus); |
| 29 | + evsel->cpus = perf_cpu_map__get(evsel->own_cpus); |
| 30 | + } |
| 31 | + |
| 32 | + perf_thread_map__put(evsel->threads); |
| 33 | + evsel->threads = perf_thread_map__get(evlist->threads); |
| 34 | +} |
| 35 | + |
| 36 | +static void perf_evlist__propagate_maps(struct perf_evlist *evlist) |
| 37 | +{ |
| 38 | + struct perf_evsel *evsel; |
| 39 | + |
| 40 | + perf_evlist__for_each_evsel(evlist, evsel) |
| 41 | + __perf_evlist__propagate_maps(evlist, evsel); |
| 42 | +} |
| 43 | + |
15 | 44 | void perf_evlist__add(struct perf_evlist *evlist, |
16 | 45 | struct perf_evsel *evsel) |
17 | 46 | { |
18 | 47 | list_add_tail(&evsel->node, &evlist->entries); |
19 | 48 | evlist->nr_entries += 1; |
| 49 | + __perf_evlist__propagate_maps(evlist, evsel); |
20 | 50 | } |
21 | 51 |
|
22 | 52 | void perf_evlist__remove(struct perf_evlist *evlist, |
@@ -60,3 +90,27 @@ void perf_evlist__delete(struct perf_evlist *evlist) |
60 | 90 | { |
61 | 91 | free(evlist); |
62 | 92 | } |
| 93 | + |
| 94 | +void perf_evlist__set_maps(struct perf_evlist *evlist, |
| 95 | + struct perf_cpu_map *cpus, |
| 96 | + struct perf_thread_map *threads) |
| 97 | +{ |
| 98 | + /* |
| 99 | + * Allow for the possibility that one or another of the maps isn't being |
| 100 | + * changed i.e. don't put it. Note we are assuming the maps that are |
| 101 | + * being applied are brand new and evlist is taking ownership of the |
| 102 | + * original reference count of 1. If that is not the case it is up to |
| 103 | + * the caller to increase the reference count. |
| 104 | + */ |
| 105 | + if (cpus != evlist->cpus) { |
| 106 | + perf_cpu_map__put(evlist->cpus); |
| 107 | + evlist->cpus = perf_cpu_map__get(cpus); |
| 108 | + } |
| 109 | + |
| 110 | + if (threads != evlist->threads) { |
| 111 | + perf_thread_map__put(evlist->threads); |
| 112 | + evlist->threads = perf_thread_map__get(threads); |
| 113 | + } |
| 114 | + |
| 115 | + perf_evlist__propagate_maps(evlist); |
| 116 | +} |
0 commit comments