driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IAQFZR CVE: NA
----------------------------------------------------------------------
Linux mainline changed the type of perf CPU map into struct perf_cpu to avoid confuses of CPU maps from cpu. The change affects a lot of infrastructures of Perf tool which this patchset depends on to fix perf undesirably scrutinizing events on offline CPUs issue[1].
This patch, with the purpose of adapting of following patches from Linux mainline to openeuler, is a mere copy of the patch [2] which changes the type of perf CPU map with careful refaction of affected code.
[1] https://lore.kernel.org/lkml/20240603092812.46616-1-yangyicong@huawei.com/ [2] https://lore.kernel.org/r/20220105061351.120843-49-irogers@google.com
Signed-off-by: Yushan Wang wangyushan12@huawei.com --- tools/lib/perf/cpumap.c | 28 ++++++++-------- tools/lib/perf/evsel.c | 2 +- tools/lib/perf/include/internal/cpumap.h | 3 +- tools/lib/perf/include/perf/cpumap.h | 5 +++ tools/perf/bench/epoll-ctl.c | 2 +- tools/perf/bench/epoll-wait.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/builtin-c2c.c | 6 ++-- tools/perf/builtin-script.c | 2 +- tools/perf/builtin-stat.c | 12 +++---- tools/perf/tests/bitmap.c | 2 +- tools/perf/tests/cpumap.c | 6 ++-- tools/perf/tests/event_update.c | 6 ++-- tools/perf/tests/mem2node.c | 2 +- tools/perf/tests/mmap-basic.c | 4 +-- tools/perf/tests/openat-syscall-all-cpus.c | 14 ++++---- tools/perf/tests/topology.c | 4 +-- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/cpumap.c | 32 +++++++++---------- tools/perf/util/cpumap.h | 2 +- tools/perf/util/cputopo.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 4 +-- tools/perf/util/mmap.c | 2 +- tools/perf/util/perf_api_probe.c | 4 +-- tools/perf/util/record.c | 6 ++-- .../scripting-engines/trace-event-python.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/stat-display.c | 10 +++--- tools/perf/util/svghelper.c | 2 +- tools/perf/util/synthetic-events.c | 6 ++-- 35 files changed, 97 insertions(+), 91 deletions(-)
diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ca0215047c32..778b50f71744 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -16,7 +16,7 @@ struct perf_cpu_map *perf_cpu_map__dummy_new(void)
if (cpus != NULL) { cpus->nr = 1; - cpus->map[0] = -1; + cpus->map[0].cpu = -1; refcount_set(&cpus->refcnt, 1); }
@@ -59,7 +59,7 @@ static struct perf_cpu_map *cpu_map__default_new(void) int i;
for (i = 0; i < nr_cpus; ++i) - cpus->map[i] = i; + cpus->map[i].cpu = i;
cpus->nr = nr_cpus; refcount_set(&cpus->refcnt, 1); @@ -85,7 +85,7 @@ static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) /* Remove dups */ j = 0; for (i = 0; i < nr_cpus; i++) { - if (i == 0 || cpus->map[i] != cpus->map[i - 1]) + if (i == 0 || cpus->map[i].cpu != cpus->map[i - 1].cpu) cpus->map[j++] = cpus->map[i]; } cpus->nr = j; @@ -248,7 +248,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx) { if (cpus && idx < cpus->nr) - return cpus->map[idx]; + return cpus->map[idx].cpu;
return -1; } @@ -260,7 +260,7 @@ int perf_cpu_map__nr(const struct perf_cpu_map *cpus)
bool perf_cpu_map__empty(const struct perf_cpu_map *map) { - return map ? map->map[0] == -1 : true; + return map ? map->map[0].cpu == -1 : true; }
int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) @@ -268,7 +268,7 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) int i;
for (i = 0; i < cpus->nr; ++i) { - if (cpus->map[i] == cpu) + if (cpus->map[i].cpu == cpu) return i; }
@@ -280,8 +280,8 @@ int perf_cpu_map__max(struct perf_cpu_map *map) int i, max = -1;
for (i = 0; i < map->nr; i++) { - if (map->map[i] > max) - max = map->map[i]; + if (map->map[i].cpu > max) + max = map->map[i].cpu; }
return max; @@ -323,19 +323,19 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, /* Standard merge algorithm from wikipedia */ i = j = k = 0; while (i < orig->nr && j < other->nr) { - if (orig->map[i] <= other->map[j]) { - if (orig->map[i] == other->map[j]) + if (orig->map[i].cpu <= other->map[j].cpu) { + if (orig->map[i].cpu == other->map[j].cpu) j++; - tmp_cpus[k++] = orig->map[i++]; + tmp_cpus[k++] = orig->map[i++].cpu; } else - tmp_cpus[k++] = other->map[j++]; + tmp_cpus[k++] = other->map[j++].cpu; }
while (i < orig->nr) - tmp_cpus[k++] = orig->map[i++]; + tmp_cpus[k++] = orig->map[i++].cpu;
while (j < other->nr) - tmp_cpus[k++] = other->map[j++]; + tmp_cpus[k++] = other->map[j++].cpu; assert(k <= tmp_len);
merged = cpu_map__trim_new(k, tmp_cpus); diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 4dc06289f4c7..eb8b838c228e 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -102,7 +102,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
fd = sys_perf_event_open(&evsel->attr, threads->map[thread].pid, - cpus->map[cpu], -1, 0); + cpus->map[cpu].cpu, -1, 0);
if (fd < 0) return -errno; diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/internal/cpumap.h index 840d4032587b..2d30168ee2fc 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -3,11 +3,12 @@ #define __LIBPERF_INTERNAL_CPUMAP_H
#include <linux/refcount.h> +#include <perf/cpumap.h>
struct perf_cpu_map { refcount_t refcnt; int nr; - int map[]; + struct perf_cpu map[]; };
#ifndef MAX_NR_CPUS diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 6a17ad730cbc..101a0f2b7693 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -6,6 +6,11 @@ #include <stdio.h> #include <stdbool.h>
+/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */ +struct perf_cpu { + int cpu; +}; + struct perf_cpu_map;
LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c index ca2d591aad8a..c4e8465017a7 100644 --- a/tools/perf/bench/epoll-ctl.c +++ b/tools/perf/bench/epoll-ctl.c @@ -254,7 +254,7 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
if (!noaffinity) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); if (ret) diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c index 75dca9773186..4bcafb10cf95 100644 --- a/tools/perf/bench/epoll-wait.c +++ b/tools/perf/bench/epoll-wait.c @@ -343,7 +343,7 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
if (!noaffinity) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); if (ret) diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index 915bf3da7ce2..58b1a4f7b2e0 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -170,7 +170,7 @@ int bench_futex_hash(int argc, const char **argv) goto errmem;
CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); if (ret) diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c index 159bc89e6a79..ab97173d94f3 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c @@ -134,7 +134,7 @@ static void create_threads(struct worker *w, pthread_attr_t thread_attr, worker[i].futex = &global_futex;
CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index 105b36cdc42d..3543b8d6d108 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c @@ -95,7 +95,7 @@ static void block_threads(pthread_t *w, /* create and block all threads */ for (i = 0; i < nthreads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c index a129c94eb3fe..930fe67fed3c 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -149,7 +149,7 @@ static void block_threads(pthread_t *w, pthread_attr_t thread_attr, /* create and block all threads */ for (i = 0; i < nblocked_threads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 507ff533612c..e43a6664f9a7 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c @@ -101,7 +101,7 @@ static void block_threads(pthread_t *w, /* create and block all threads */ for (i = 0; i < nthreads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(cpu->map[i % cpu->nr].cpu, &cpuset);
if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset)) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index cf308b90d671..e12e24ca1eef 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -2383,12 +2383,12 @@ static int setup_nodes(struct perf_session *session) continue;
for (cpu = 0; cpu < map->nr; cpu++) { - set_bit(map->map[cpu], set); + set_bit(map->map[cpu].cpu, set);
- if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug")) + if (WARN_ONCE(cpu2node[map->map[cpu].cpu] != -1, "node/cpu topology bug")) return -EINVAL;
- cpu2node[map->map[cpu]] = node; + cpu2node[map->map[cpu].cpu] = node; } }
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 44e3f4a83549..fc6be5d7db10 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2047,7 +2047,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp) counts = perf_counts(counter->counts, cpu, thread);
printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", - counter->core.cpus->map[cpu], + counter->core.cpus->map[cpu].cpu, perf_thread_map__pid(counter->core.threads, thread), counts->val, counts->ena, diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1f8a23a1b867..a5dafba23d93 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -213,7 +213,7 @@ static bool cpus_map_matched(struct evsel *a, struct evsel *b) return false;
for (int i = 0; i < a->core.cpus->nr; i++) { - if (a->core.cpus->map[i] != b->core.cpus->map[i]) + if (a->core.cpus->map[i].cpu != b->core.cpus->map[i].cpu) return false; }
@@ -1222,12 +1222,12 @@ static int perf_stat__get_aggr(struct perf_stat_config *config, if (idx >= map->nr) return -1;
- cpu = map->map[idx]; + cpu = map->map[idx].cpu;
- if (config->cpus_aggr_map->map[cpu] == -1) - config->cpus_aggr_map->map[cpu] = get_id(config, map, idx); + if (config->cpus_aggr_map->map[cpu].cpu == -1) + config->cpus_aggr_map->map[cpu].cpu = get_id(config, map, idx);
- return config->cpus_aggr_map->map[cpu]; + return config->cpus_aggr_map->map[cpu].cpu; }
static int perf_stat__get_socket_cached(struct perf_stat_config *config, @@ -1341,7 +1341,7 @@ static inline int perf_env__get_cpu(struct perf_env *env, struct perf_cpu_map *m if (idx > map->nr) return -1;
- cpu = map->map[idx]; + cpu = map->map[idx].cpu;
if (cpu >= env->nr_cpus_avail) return -1; diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 96c137360918..8717e03924dd 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -18,7 +18,7 @@ static unsigned long *get_bitmap(const char *str, int nbits)
if (map && bm) { for (i = 0; i < map->nr; i++) - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); }
if (map) diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 29c793ac7d10..08e0faf3e8a2 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -38,7 +38,7 @@ static int process_event_mask(struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong nr", map->nr == 20);
for (i = 0; i < 20; i++) { - TEST_ASSERT_VAL("wrong cpu", map->map[i] == i); + TEST_ASSERT_VAL("wrong cpu", map->map[i].cpu == i); }
perf_cpu_map__put(map); @@ -67,8 +67,8 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,
map = cpu_map__new_data(data); TEST_ASSERT_VAL("wrong nr", map->nr == 2); - TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1); - TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256); + TEST_ASSERT_VAL("wrong cpu", map->map[0].cpu == 1); + TEST_ASSERT_VAL("wrong cpu", map->map[1].cpu == 256); TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1); perf_cpu_map__put(map); return 0; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c index 1c9a6138fba1..0ffe1ef0f1a7 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -76,9 +76,9 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong id", ev->id == 123); TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); TEST_ASSERT_VAL("wrong cpus", map->nr == 3); - TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); - TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); - TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); + TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu == 1); + TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu == 2); + TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu == 3); perf_cpu_map__put(map); return 0; } diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index a258bd51f1a4..96afd0e7599f 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -31,7 +31,7 @@ static unsigned long *get_bitmap(const char *str, int nbits)
if (map && bm) { for (i = 0; i < map->nr; i++) { - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); } }
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 7b0dbfc0e17d..e2c3aa27c8f1 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -59,11 +59,11 @@ int test__basic_mmap(struct test *test __maybe_unused, int subtest __maybe_unuse }
CPU_ZERO(&cpu_set); - CPU_SET(cpus->map[0], &cpu_set); + CPU_SET(cpus->map[0].cpu, &cpu_set); sched_setaffinity(0, sizeof(cpu_set), &cpu_set); if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { pr_debug("sched_setaffinity() failed on CPU %d: %s ", - cpus->map[0], str_error_r(errno, sbuf, sizeof(sbuf))); + cpus->map[0].cpu, str_error_r(errno, sbuf, sizeof(sbuf))); goto out_free_cpus; }
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c index 71f85e2cc127..10279c22ac03 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -66,15 +66,15 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int * without CPU_ALLOC. 1024 cpus in 2010 still seems * a reasonable upper limit tho :-) */ - if (cpus->map[cpu] >= CPU_SETSIZE) { - pr_debug("Ignoring CPU %d\n", cpus->map[cpu]); + if (cpus->map[cpu].cpu >= CPU_SETSIZE) { + pr_debug("Ignoring CPU %d\n", cpus->map[cpu].cpu); continue; }
- CPU_SET(cpus->map[cpu], &cpu_set); + CPU_SET(cpus->map[cpu].cpu, &cpu_set); if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { pr_debug("sched_setaffinity() failed on CPU %d: %s ", - cpus->map[cpu], + cpus->map[cpu].cpu, str_error_r(errno, sbuf, sizeof(sbuf))); goto out_close_fd; } @@ -82,7 +82,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int fd = openat(0, "/etc/passwd", O_RDONLY); close(fd); } - CPU_CLR(cpus->map[cpu], &cpu_set); + CPU_CLR(cpus->map[cpu].cpu, &cpu_set); }
/* @@ -100,7 +100,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int for (cpu = 0; cpu < cpus->nr; ++cpu) { unsigned int expected;
- if (cpus->map[cpu] >= CPU_SETSIZE) + if (cpus->map[cpu].cpu >= CPU_SETSIZE) continue;
if (evsel__read_on_cpu(evsel, cpu, 0) < 0) { @@ -112,7 +112,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test __maybe_unused, int expected = nr_openat_calls + cpu; if (perf_counts(evsel->counts, cpu, 0)->val != expected) { pr_debug("evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n", - expected, cpus->map[cpu], perf_counts(evsel->counts, cpu, 0)->val); + expected, cpus->map[cpu].cpu, perf_counts(evsel->counts, cpu, 0)->val); err = -1; } } diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index f4a2c0df0954..9913bd5a0734 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -101,10 +101,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
for (i = 0; i < map->nr; i++) { TEST_ASSERT_VAL("Core ID doesn't match", - (session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff))); + (session->header.env.cpu[map->map[i].cpu].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff)));
TEST_ASSERT_VAL("Socket ID doesn't match", - (session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i, NULL))); + (session->header.env.cpu[map->map[i].cpu].socket_id == cpu_map__get_socket(map, i, NULL))); }
perf_session__delete(session); diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 5d58b2f653ed..382d2c96d803 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -189,7 +189,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, mp->idx = idx;
if (per_cpu) { - mp->cpu = evlist->core.cpus->map[idx]; + mp->cpu = evlist->core.cpus->map[idx].cpu; if (evlist->core.threads) mp->tid = perf_thread_map__pid(evlist->core.threads, 0); else diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index dc5c5e6fc502..2731356d7192 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -33,9 +33,9 @@ static struct perf_cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus) * otherwise it would become 65535. */ if (cpus->cpu[i] == (u16) -1) - map->map[i] = -1; + map->map[i].cpu = -1; else - map->map[i] = (int) cpus->cpu[i]; + map->map[i].cpu = (int) cpus->cpu[i]; } }
@@ -54,7 +54,7 @@ static struct perf_cpu_map *cpu_map__from_mask(struct perf_record_record_cpu_map int cpu, i = 0;
for_each_set_bit(cpu, mask->mask, nbits) - map->map[i++] = cpu; + map->map[i++].cpu = cpu; } return map;
@@ -87,7 +87,7 @@ struct perf_cpu_map *perf_cpu_map__empty_new(int nr)
cpus->nr = nr; for (i = 0; i < nr; i++) - cpus->map[i] = -1; + cpus->map[i].cpu = -1;
refcount_set(&cpus->refcnt, 1); } @@ -118,7 +118,7 @@ int cpu_map__get_socket(struct perf_cpu_map *map, int idx, void *data __maybe_un if (idx > map->nr) return -1;
- cpu = map->map[idx]; + cpu = map->map[idx].cpu;
return cpu_map__get_socket_id(cpu); } @@ -144,11 +144,11 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res, for (cpu = 0; cpu < nr; cpu++) { s1 = f(cpus, cpu, data); for (s2 = 0; s2 < c->nr; s2++) { - if (s1 == c->map[s2]) + if (s1 == c->map[s2].cpu) break; } if (s2 == c->nr) { - c->map[c->nr] = s1; + c->map[c->nr].cpu = s1; c->nr++; } } @@ -174,7 +174,7 @@ int cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data) if (idx > map->nr) return -1;
- cpu = map->map[idx]; + cpu = map->map[idx].cpu;
die_id = cpu_map__get_die_id(cpu); /* There is no die_id on legacy system. */ @@ -218,7 +218,7 @@ int cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data) if (idx > map->nr) return -1;
- cpu = map->map[idx]; + cpu = map->map[idx].cpu;
cpu = cpu_map__get_core_id(cpu);
@@ -245,7 +245,7 @@ int cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data __maybe_unus if (idx < 0 || idx >= map->nr) return -1;
- return cpu_map__get_node_id(map->map[idx]); + return cpu_map__get_node_id(map->map[idx].cpu); }
int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct perf_cpu_map **sockp) @@ -482,7 +482,7 @@ bool cpu_map__has(struct perf_cpu_map *cpus, int cpu)
int cpu_map__cpu(struct perf_cpu_map *cpus, int idx) { - return cpus->map[idx]; + return cpus->map[idx].cpu; }
size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) @@ -496,26 +496,26 @@ size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) for (i = 0; i < map->nr + 1; i++) { bool last = i == map->nr;
- cpu = last ? INT_MAX : map->map[i]; + cpu = last ? INT_MAX : map->map[i].cpu;
if (start == -1) { start = i; if (last) { ret += snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[i]); + map->map[i].cpu); } - } else if (((i - start) != (cpu - map->map[start])) || last) { + } else if (((i - start) != (cpu - map->map[start].cpu)) || last) { int end = i - 1;
if (start == end) { ret += snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[start]); + map->map[start].cpu); } else { ret += snprintf(buf + ret, size - ret, "%s%d-%d", COMMA, - map->map[start], map->map[end]); + map->map[start].cpu, map->map[end].cpu); } first = false; start = i; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 3a442f021468..446c48f18fe2 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -32,7 +32,7 @@ static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) { if (!sock || s > sock->nr || s < 0) return 0; - return sock->map[s]; + return sock->map[s].cpu; }
static inline int cpu_map__id_to_socket(int id) diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 1b52402a8923..0cf6567da87f 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -328,7 +328,7 @@ struct numa_topology *numa_topology__new(void) tp->nr = nr;
for (i = 0; i < nr; i++) { - if (load_numa_node(&tp->nodes[i], node_map->map[i])) { + if (load_numa_node(&tp->nodes[i], node_map->map[i].cpu)) { numa_topology__delete(tp); tp = NULL; break; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 66b230fe3e26..ad864e032116 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -373,7 +373,7 @@ bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu) { if (ev->cpu_iter >= ev->core.cpus->nr) return true; - if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter] != cpu) + if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter].cpu != cpu) return true; return false; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9fd9c3cb2330..70dbe4d79203 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1792,13 +1792,13 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, retry_open: test_attr__ready();
- fd = perf_event_open(evsel, pid, cpus->map[cpu], + fd = perf_event_open(evsel, pid, cpus->map[cpu].cpu, group_fd, flags);
FD(evsel, cpu, thread) = fd;
if (unlikely(test_attr__enabled)) { - test_attr__open(&evsel->core.attr, pid, cpus->map[cpu], + test_attr__open(&evsel->core.attr, pid, cpus->map[cpu].cpu, fd, group_fd, flags); }
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index daedd2fc3928..9f184911f754 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -249,7 +249,7 @@ static void build_node_mask(int node, struct mmap_cpu_mask *mask)
nr_cpus = perf_cpu_map__nr(cpu_map); for (c = 0; c < nr_cpus; c++) { - cpu = cpu_map->map[c]; /* map c index to online cpu index */ + cpu = cpu_map->map[c].cpu; /* map c index to online cpu index */ if (cpu__get_node(cpu) == node) set_bit(cpu, mask->bits); } diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_probe.c index 3840d02f0f7b..27d6ac6bfd04 100644 --- a/tools/perf/util/perf_api_probe.c +++ b/tools/perf/util/perf_api_probe.c @@ -66,7 +66,7 @@ static bool perf_probe_api(setup_probe_fn_t fn) cpus = perf_cpu_map__new(NULL); if (!cpus) return false; - cpu = cpus->map[0]; + cpu = cpus->map[0].cpu; perf_cpu_map__put(cpus);
do { @@ -131,7 +131,7 @@ bool perf_can_record_cpu_wide(void) cpus = perf_cpu_map__new(NULL); if (!cpus) return false; - cpu = cpus->map[0]; + cpu = cpus->map[0].cpu; perf_cpu_map__put(cpus);
fd = sys_perf_event_open(&attr, -1, cpu, -1, 0); diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 07e4b96a6625..5ca210d73a6d 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -104,7 +104,7 @@ void perf_evlist__config(struct evlist *evlist, struct record_opts *opts, if (opts->group) perf_evlist__set_leader(evlist);
- if (evlist->core.cpus->map[0] < 0) + if (evlist->core.cpus->map[0].cpu < 0) opts->no_inherit = true;
use_comm_exec = perf_can_comm_exec(); @@ -238,10 +238,10 @@ bool perf_evlist__can_select_event(struct evlist *evlist, const char *str) if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) { struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
- cpu = cpus ? cpus->map[0] : 0; + cpu = cpus ? cpus->map[0].cpu : 0; perf_cpu_map__put(cpus); } else { - cpu = evlist->core.cpus->map[0]; + cpu = evlist->core.cpus->map[0].cpu; }
while (1) { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 23dc5014e711..dc15f0bf6b7f 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1425,7 +1425,7 @@ static void python_process_stat(struct perf_stat_config *config,
for (thread = 0; thread < threads->nr; thread++) { for (cpu = 0; cpu < cpus->nr; cpu++) { - process_stat(counter, cpus->map[cpu], + process_stat(counter, cpus->map[cpu].cpu, perf_thread_map__pid(threads, thread), tstamp, perf_counts(counter->counts, cpu, thread)); } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 95cf2e09d443..d621b6dccf05 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2444,7 +2444,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, }
for (i = 0; i < map->nr; i++) { - int cpu = map->map[i]; + int cpu = map->map[i].cpu;
if (cpu >= nr_cpus) { pr_err("Requested CPU %d too large. " diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 4688e39de52a..e84206f957b2 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -120,7 +120,7 @@ static void aggr_printout(struct perf_stat_config *config, } else if (id > -1) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7, - evsel__cpus(evsel)->map[id], + evsel__cpus(evsel)->map[id].cpu, config->csv_sep); } break; @@ -331,7 +331,7 @@ static int first_shadow_cpu(struct perf_stat_config *config, return 0;
for (i = 0; i < evsel__nr_cpus(evsel); i++) { - int cpu2 = evsel__cpus(evsel)->map[i]; + int cpu2 = evsel__cpus(evsel)->map[i].cpu;
if (config->aggr_get_id(config, evlist->core.cpus, cpu2) == id) return cpu2; @@ -501,7 +501,7 @@ static void aggr_update_shadow(struct perf_stat_config *config, struct evsel *counter;
for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; + id = config->aggr_map->map[s].cpu; evlist__for_each_entry(evlist, counter) { val = 0; for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { @@ -632,7 +632,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config, int id, nr; double uval;
- ad.id = id = config->aggr_map->map[s]; + ad.id = id = config->aggr_map->map[s].cpu; ad.val = ad.ena = ad.run = 0; ad.nr = 0; if (!collect_data(config, counter, aggr_cb, &ad)) @@ -1147,7 +1147,7 @@ static void print_percore_thread(struct perf_stat_config *config, for (int i = 0; i < evsel__nr_cpus(counter); i++) { s2 = config->aggr_get_id(config, evsel__cpus(counter), i); for (s = 0; s < config->aggr_map->nr; s++) { - id = config->aggr_map->map[s]; + id = config->aggr_map->map[s].cpu; if (s2 == id) break; } diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 96f941e01681..660702eb4d79 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -735,7 +735,7 @@ static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus) return -1;
for (i = 0; i < m->nr; i++) { - c = m->map[i]; + c = m->map[i].cpu; if (c >= nr_cpus) { ret = -1; break; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index b4cf6dd57dd6..3865f0e48374 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1101,7 +1101,7 @@ static void synthesize_cpus(struct cpu_map_entries *cpus, cpus->nr = map->nr;
for (i = 0; i < map->nr; i++) - cpus->cpu[i] = map->map[i]; + cpus->cpu[i] = map->map[i].cpu; }
static void synthesize_mask(struct perf_record_record_cpu_map *mask, @@ -1113,7 +1113,7 @@ static void synthesize_mask(struct perf_record_record_cpu_map *mask, mask->long_size = sizeof(long);
for (i = 0; i < map->nr; i++) - set_bit(map->map[i], mask->mask); + set_bit(map->map[i].cpu, mask->mask); }
static size_t cpus_size(struct perf_cpu_map *map) @@ -1129,7 +1129,7 @@ static size_t mask_size(struct perf_cpu_map *map, int *max)
for (i = 0; i < map->nr; i++) { /* bit possition of the cpu is + 1 */ - int bit = map->map[i] + 1; + int bit = map->map[i].cpu + 1;
if (bit > *max) *max = bit;