From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796334761; b=Q24PKAeYEcwF+SHBvNE/5RenIP3kOFo0QMsW8TK6pBuRdQPMa7YtZfCnTxNON9eEBkIk TFbCPDbkqQ/GgJ9CnSDomKoFFJZIzfsbRArRJID+A57C4c0rfh9IK9biBFX12e3Sxnnxm FpceIHnRLC35k0I8jKIHTVqHERWsAzk4+P7DGA9acJI8IEi33uWJjbtsBn8fEmPIc6H1O 9o9Ih82iAm+n3OcO6TtYqS5WKClSR1lsz0uWRK172sUux+3WnhYpDsQUEMmJm3Ei0aKqM nC+HEUMuT/gqYWN9/WHAZPvJu/8pr1dxrNBoLYiWb7DAXEJjlCU8JjjIrXKqRZwiolw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334761; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=rn04ORtTmzn00vqkses5nPwLV14oJdOmMf1LzTI6sZc=; b=fF7tAAqJXNfr17TAZ1wF74HsCPRnmUr/fQnE08rcr1rKgibv9BhkTC8+9l2XkH6VGe/R jyeDeko8GC908q2l21r2SMqKeqJFK9h/eRLWlnOiRMwXUDxkQuloFWsa+BeoFeU07O17G 29HV/uhdcLhhIY0FjBRm10xfF9iG5veS+ZKqa+6qpNb+WV7MpXAwhdMxsay4JESm+oTsU lClmUh4/q+SQSJDdScGxBIj05hbz3IejgMrKYS+AjiJ7hRpXdboUXhg5Hga9w4Tp2tv6x sTmHXUaV8KSCSMXA3+xwZ5BPKavTkaxFIlJwXTT/C2McZHX/S4pEJiYlrdwOseGIwlw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LPsVJfyi; arc=none smtp.remote-ip=209.85.160.71 Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DBF8606A698 for ; Thu, 3 Dec 2026 21:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DBF8606A698 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=LPsVJfyi Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-46509ab0149so296024fac.2 for ; Thu, 03 Dec 2026 13:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796334760; x=1796939560; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=rn04ORtTmzn00vqkses5nPwLV14oJdOmMf1LzTI6sZc=; b=LPsVJfyi8FuixIzUXzQH3yc50W6syRa8yoeMoorEu/a3xDlwZLaYcdsF2Tnp2o1DRm Sxzm1AQRdxA190BodDvI9ebSygxPCZMDZr5pWA6xFemaJMmVB60DfzscEkkPTHFnNYQp axdKPqxu9rFlN/iQlXeiXUuMv9NfEXyWIdnkhbvw/vci5NHiLdmSCHOmwDn1chQVusiy 0X2BYjBD857gsJaALplzSgjfCJH2dBJYujGg1Ozi/7NbqNdOl3OIgwHy29p+kNkOiCoJ TYLSZI53MOXiZ0DOy28ibSbZvgCS8W9LAwkKGyP2+e/AtyJ68VDQV3nIgHke+IsSaoLp V8pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796334760; x=1796939560; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rn04ORtTmzn00vqkses5nPwLV14oJdOmMf1LzTI6sZc=; b=INaZaUzkKhu5E/xlqhybU6cFWMvNE2EFzPnzIGkW4bSkUNWv+njyClkfX6qgWffciN M2XR8mfmGjlHS5nEogYEHkAaATatEE5Czxim7a6aqHSzLpqiAtMSKLpyhgxVJG5yY62I 56HFmTeNWpNqV6tRsT3GCqu54WLnNQ8he13a216QYF4J0LQ7h7JUrhjzWEGidW7GJJlR ArehM7Mv3VWVDBfr16z7lfz2vHdl+oUZWssyY6tD8+CfGpY5j+BKAdug8NUgLbywVBYx YCv/5HFgG0KwAaMwRxFmD+Hy4U6J9Mq87DOG3I4pZkd4HUJYV3sQd1oBfsP9Hua2BaL8 +ikQ== X-Forwarded-Encrypted: i=1; AL+hErETbzXypX5Qpk6CBn7bRBr8z9oCa4R4utCZcKMd2RcnTysL/wqFCFM7ZDrbakTd22PNnD9NnA8v/iOr1Zc=@vger.kernel.org X-Gm-Message-State: APuU4Z9GP/3GFf5hjglOIy+0MtbA8oJU1iEQtbc0QB/Kc1OTyMbdMdTi 4iZFNYXbEl/zAlVRhTgCTUnH82p9EyFmLPMiPmzkMbNw2AqGAb8xciFZqGQvL1RCri2qV82SPRF e5p/bBU6UjA== X-Received: from oatm18-n2.prod.google.com ([2002:a05:687c:4492:20b0:4ad:867b:6ccf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:c0d4:b0:48f:e0e5:a1fe with SMTP id 586e51a60fabf-4bc84d1b7abmr41869808fac.50.1796334759880; Thu, 03 Dec 2026 13:52:39 -0800 (PST) Date: Thu, 3 Dec 2026 13:52:14 -0800 In-Reply-To: <20261203215222.1392035-1-irogers@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261203215222.1392035-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261203215222.1392035-6-irogers@google.com> Subject: [PATCH v2 05/13] perf stat: Preserve per-evsel CPU maps across stat record and report From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark Cc: Athira Rajeev , TAKANO Mitsuhiro , Hang Zhengyang , Howard Chu , Thomas Falcon , Song Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Commit 6d765f5f7ec6 ("libperf evsel: Rename own_cpus to pmu_cpus") and commit 811082e4b668 ("perf parse-events: Support user CPUs mixed with threads/processes") separated an evsel's PMU cpumask (pmu_cpus) from the actual CPUs on which the event is opened (cpus) and taught __perf_evlist__propagate_maps() to collapse evsel->cpus to the "any CPU" (-1) map when user_requested_cpus is -1 and !evsel->requires_cpu. However, perf_event__synthesize_event_update_cpus() continued to serialize evsel->core.pmu_cpus instead of evsel->core.cpus, and perf_event__process_event_update() only populated evsel->core.pmu_cpus without setting evsel->core.cpus or evsel->core.requires_cpu. This broke perf stat record/report (and perf script) in three ways: 1. When recording an event opened per-CPU alongside a workload target (where user_requested_cpus is -1), such as an event with a cpu= term, an uncore counter, --bpf-counters, or a BPF-filtered counter, PERF_RECORD_STAT events are written with concrete CPU numbers, but perf stat report's perf_evlist__set_maps() collapses evsel->cpus to -1 and fails with: $ perf stat record -e 'task-clock/cpu=0/,task-clock' -- true $ perf stat report Invalid CPU 0 for event task-clock/cpu=0/. In addition, perf stat report -A (and other CPU aggregation modes) built stat_config.aggr_map from user_requested_cpus (-1) rather than all_cpus, omitting per-CPU counters recorded alongside a workload. 2. In system-wide mode (-a), per-evsel CPU restrictions such as cpu=0 were overwritten by the full PMU cpumask during report, causing perf stat report -A to report bogus entries on every other CPU. Fix perf_event__synthesize_event_update_cpus() to serialize evsel->core.cpus, and update perf_event__process_event_update() to populate evsel->core.cpus (and evsel->core.pmu_cpus when the recorded CPU map does not use the "any CPU" -1 placeholder) and set requires_cpu when concrete CPUs are recorded. Guard counter->counts in perf_event__process_stat_event(), and for backward compatibility with data files recorded by older perf binaries that wrote pmu_cpus for per-task (-1) counters, fall back to the "any CPU" map if a -1 CPU stat event arrives for an evsel without -1 in its CPU map. When user_requested_cpus uses the "any CPU" (-1) placeholder, build stat_config.aggr_map from evlist->all_cpus (and check all_cpus for task-only data in process_stat_config_event()) so perf stat report -A displays per-evsel CPU counters. Update the event_update unit test and stat.sh record/report/script tests to cover per-evsel CPU maps (including -A) on workload targets. Fixes: 6d765f5f7ec6 ("libperf evsel: Rename own_cpus to pmu_cpus") Fixes: 811082e4b668 ("perf parse-events: Support user CPUs mixed with threads/processes") Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 17 +++++++----- tools/perf/tests/event_update.c | 43 ++++++++++++++++++++++++++---- tools/perf/tests/shell/stat.sh | 33 ++++++++++++++++++++++- tools/perf/util/evsel.c | 2 +- tools/perf/util/header.c | 20 ++++++++++++-- tools/perf/util/stat-display.c | 6 ++++- tools/perf/util/stat.c | 22 +++++++++++++++ tools/perf/util/synthetic-events.c | 7 +++-- 8 files changed, 132 insertions(+), 18 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 52d89fddfa10..e68168ad67f0 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1606,9 +1606,11 @@ static int perf_stat_init_aggr_mode(void) if (get_id) { bool needs_sort = stat_config.aggr_mode != AGGR_NONE; - stat_config.aggr_map = cpu_aggr_map__new( - evlist__core(evsel_list)->user_requested_cpus, - get_id, /*data=*/NULL, needs_sort); + const struct perf_cpu_map *cpus = evlist__core(evsel_list)->user_requested_cpus; + + if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + cpus = evlist__core(evsel_list)->all_cpus; + stat_config.aggr_map = cpu_aggr_map__new(cpus, get_id, /*data=*/NULL, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map\n", aggr_mode__string[stat_config.aggr_mode]); return -1; @@ -1920,6 +1922,7 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) { struct perf_env *env = perf_session__env(st->session); aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); + const struct perf_cpu_map *cpus; bool needs_sort = stat_config.aggr_mode != AGGR_NONE; if (stat_config.aggr_mode == AGGR_THREAD) { @@ -1941,8 +1944,10 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) if (!get_id) return 0; - stat_config.aggr_map = cpu_aggr_map__new(evlist__core(evsel_list)->user_requested_cpus, - get_id, env, needs_sort); + cpus = evlist__core(evsel_list)->user_requested_cpus; + if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + cpus = evlist__core(evsel_list)->all_cpus; + stat_config.aggr_map = cpu_aggr_map__new(cpus, get_id, env, needs_sort); if (!stat_config.aggr_map) { pr_err("cannot build %s map\n", aggr_mode__string[stat_config.aggr_mode]); return -1; @@ -2268,7 +2273,7 @@ int process_stat_config_event(const struct perf_tool *tool, perf_event__read_stat_config(&stat_config, &event->stat_config); - if (perf_cpu_map__is_empty(st->cpus)) { + if (perf_cpu_map__is_any_cpu_or_is_empty(evlist__core(session->evlist)->all_cpus)) { if (st->aggr_mode != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); } else if (st->aggr_mode != AGGR_UNSET) { diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c index 220cc0347747..bacf3c44c8e2 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include "cpumap.h" #include "evlist.h" @@ -58,13 +59,20 @@ static int process_event_name(const struct perf_tool *tool, return 0; } -static int process_event_cpus(const struct perf_tool *tool __maybe_unused, +struct event_cpus { + struct perf_tool tool; + struct evlist *evlist; +}; + +static int process_event_cpus(const struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused) { + struct event_cpus *tmp = container_of(tool, struct event_cpus, tool); struct perf_record_event_update *ev = (struct perf_record_event_update *)event; - struct perf_cpu_map *map; + struct perf_cpu_map *map, *any_cpu; + struct evsel *evsel; map = cpu_map__new_data(&ev->cpus.cpus); @@ -75,6 +83,26 @@ static int process_event_cpus(const struct perf_tool *tool __maybe_unused, TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 1).cpu == 2); TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 2).cpu == 3); perf_cpu_map__put(map); + + evsel = evlist__first(tmp->evlist); + perf_cpu_map__put(evsel->core.cpus); + evsel->core.cpus = NULL; + perf_cpu_map__put(evsel->core.pmu_cpus); + evsel->core.pmu_cpus = NULL; + evsel->core.requires_cpu = false; + + TEST_ASSERT_VAL("failed to process attr update cpus", + !perf_event__process_event_update(tool, event, &tmp->evlist)); + + any_cpu = perf_cpu_map__new_any_cpu(); + TEST_ASSERT_VAL("failed to allocate any_cpu map", any_cpu); + perf_evlist__set_maps(evlist__core(tmp->evlist), any_cpu, NULL); + perf_cpu_map__put(any_cpu); + + TEST_ASSERT_VAL("wrong processed cpus", perf_cpu_map__nr(evsel->core.cpus) == 3); + TEST_ASSERT_VAL("wrong processed cpus", perf_cpu_map__cpu(evsel->core.cpus, 0).cpu == 1); + TEST_ASSERT_VAL("wrong processed cpus", perf_cpu_map__cpu(evsel->core.cpus, 1).cpu == 2); + TEST_ASSERT_VAL("wrong processed cpus", perf_cpu_map__cpu(evsel->core.cpus, 2).cpu == 3); return 0; } @@ -82,6 +110,7 @@ static int test__event_update(struct test_suite *test __maybe_unused, int subtes { struct evsel *evsel; struct event_name tmp; + struct event_cpus tmp_cpus; struct target target = {}; struct evlist *evlist = evlist__new_default(&target, /*sample_callchains=*/false); @@ -111,11 +140,15 @@ static int test__event_update(struct test_suite *test __maybe_unused, int subtes TEST_ASSERT_VAL("failed to synthesize attr update name", !perf_event__synthesize_event_update_name(&tmp.tool, evsel, process_event_name)); - perf_cpu_map__put(evsel->core.pmu_cpus); - evsel->core.pmu_cpus = perf_cpu_map__new("1,2,3"); + perf_cpu_map__put(evsel->core.cpus); + evsel->core.cpus = perf_cpu_map__new("1,2,3"); + + perf_tool__init(&tmp_cpus.tool, /*ordered_events=*/false); + tmp_cpus.evlist = evlist; TEST_ASSERT_VAL("failed to synthesize attr update cpus", - !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_event_cpus)); + !perf_event__synthesize_event_update_cpus(&tmp_cpus.tool, evsel, + process_event_cpus)); evlist__put(evlist); return 0; diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh index 7cd9999fd526..e99a4dddb484 100755 --- a/tools/perf/tests/shell/stat.sh +++ b/tools/perf/tests/shell/stat.sh @@ -6,9 +6,10 @@ set -e err=0 stat_output=$(mktemp /tmp/perf-stat-test-output.XXXXX) +stat_data=$(mktemp /tmp/perf-stat-test-data.XXXXX) cleanup() { - rm -f "${stat_output}" + rm -f "${stat_output}" "${stat_data}" trap - EXIT TERM INT } @@ -84,6 +85,27 @@ test_stat_record_report() { err=1 return fi + cpu=$(sed 's/[-,].*//' /sys/devices/system/cpu/online) + if ! perf stat record -e "task-clock/cpu=${cpu}/,task-clock" -o "${stat_data}" true > /dev/null 2>&1 + then + echo "stat record and report test [Failed per-evsel CPU record]" + err=1 + return + fi + if ! perf stat report -i "${stat_data}" > "${stat_output}" 2>&1 || \ + ! grep -E -q "msec[[:space:]]+task-clock/cpu=${cpu}/" "${stat_output}" + then + echo "stat record and report test [Failed per-evsel CPU]" + err=1 + return + fi + if ! perf stat report -A -i "${stat_data}" > "${stat_output}" 2>&1 || \ + ! grep -E -q "^CPU${cpu}[[:space:]].*task-clock/cpu=${cpu}/" "${stat_output}" + then + echo "stat record and report test [Failed per-evsel CPU -A]" + err=1 + return + fi echo "stat record and report test [Success]" } @@ -96,6 +118,15 @@ test_stat_record_script() { err=1 return fi + cpu=$(sed 's/[-,].*//' /sys/devices/system/cpu/online) + if ! perf stat record -e "task-clock/cpu=${cpu}/,task-clock" -o "${stat_data}" true > /dev/null 2>&1 || \ + ! perf script -i "${stat_data}" > "${stat_output}" 2>&1 || \ + ! grep -E -q "^[[:space:]]*${cpu}[[:space:]].*task-clock/cpu=${cpu}/" "${stat_output}" + then + echo "stat record and script test [Failed per-evsel CPU]" + err=1 + return + fi echo "stat record and script test [Success]" } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 708e6cbc05ea..f04db2e01292 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1822,7 +1822,7 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts, attr->exclude_user = 1; } - if (evsel->core.pmu_cpus || evsel->unit) + if (evsel->core.cpus || evsel->core.pmu_cpus || evsel->unit) evsel->core.attr.read_format |= PERF_FORMAT_ID; /* diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 80fa9a896933..0bbd592b7804 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -5988,8 +5988,24 @@ int perf_event__process_event_update(const struct perf_tool *tool __maybe_unused case PERF_EVENT_UPDATE__CPUS: map = cpu_map__new_data(&ev->cpus.cpus); if (map) { - perf_cpu_map__put(evsel->core.pmu_cpus); - evsel->core.pmu_cpus = map; + /* + * Recorded perf.data files do not carry a separate PMU + * cpumask. Populate pmu_cpus when map has concrete CPUs + * so __perf_evlist__propagate_maps() does not intersect + * recorded CPUs against the reporting host's online + * CPUs, while avoiding placing "any CPU" (-1) in + * pmu_cpus. + */ + if (!perf_cpu_map__has_any_cpu(map)) { + perf_cpu_map__put(evsel->core.pmu_cpus); + evsel->core.pmu_cpus = perf_cpu_map__get(map); + } + if (!evsel->counts) { + perf_cpu_map__put(evsel->core.cpus); + evsel->core.cpus = perf_cpu_map__get(map); + evsel->core.requires_cpu = !perf_cpu_map__has_any_cpu(map); + } + perf_cpu_map__put(map); } else pr_err("failed to get event_update cpus\n"); break; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 493ed6c88685..bc0c02f27732 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1146,10 +1146,14 @@ static void print_no_aggr_metric(struct perf_stat_config *config, struct evlist *evlist, struct outstate *os) { + const struct perf_cpu_map *cpus = evlist__core(evlist)->user_requested_cpus; unsigned int all_idx; struct perf_cpu cpu; - perf_cpu_map__for_each_cpu(cpu, all_idx, evlist__core(evlist)->user_requested_cpus) { + if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + cpus = evlist__core(evlist)->all_cpus; + + perf_cpu_map__for_each_cpu(cpu, all_idx, cpus) { struct evsel *counter; bool first = true; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 6da3dbbde0e2..4565c2228e63 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -8,6 +8,7 @@ #include #include +#include #include "counts.h" #include "cpumap.h" @@ -673,7 +674,28 @@ int perf_event__process_stat_event(const struct perf_tool *tool __maybe_unused, pr_err("Failed to resolve counter for stat event.\n"); return -EINVAL; } + if (!counter->counts) { + pr_err("Unexpected stat event before counter allocation for %s.\n", + evsel__name(counter)); + return -EINVAL; + } cpu_map_idx = perf_cpu_map__idx(evsel__cpus(counter), (struct perf_cpu){.cpu = st->cpu}); + if (cpu_map_idx == -1 && (s32)st->cpu == -1 && evsel__nr_cpus(counter) > 0) { + /* + * Older perf tools wrote pmu_cpus instead of cpus in + * PERF_EVENT_UPDATE__CPUS, leaving per-task counters with a + * CPU list instead of the "any CPU" (-1) map used by their + * PERF_RECORD_STAT events. + */ + struct perf_cpu_map *any_cpu = perf_cpu_map__new_any_cpu(); + + if (any_cpu) { + perf_cpu_map__put(counter->core.cpus); + counter->core.cpus = any_cpu; + counter->core.requires_cpu = false; + cpu_map_idx = 0; + } + } if (cpu_map_idx == -1) { pr_err("Invalid CPU %d for event %s.\n", st->cpu, evsel__name(counter)); return -EINVAL; diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index 3c8d29f27fd9..b87d15a5be6a 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2234,10 +2234,13 @@ int perf_event__synthesize_event_update_name(const struct perf_tool *tool, struc int perf_event__synthesize_event_update_cpus(const struct perf_tool *tool, struct evsel *evsel, perf_event__handler_t process) { - struct synthesize_cpu_map_data syn_data = { .map = evsel->core.pmu_cpus }; + struct synthesize_cpu_map_data syn_data = { .map = evsel->core.cpus }; struct perf_record_event_update *ev; int err; + if (!evsel->core.cpus) + return 0; + ev = cpu_map_data__alloc(&syn_data, sizeof(struct perf_event_header) + 2 * sizeof(u64)); if (!ev) return -ENOMEM; @@ -2315,7 +2318,7 @@ int perf_event__synthesize_extra_attr(const struct perf_tool *tool, struct evlis } } - if (evsel->core.pmu_cpus) { + if (evsel->core.cpus) { err = perf_event__synthesize_event_update_cpus(tool, evsel, process); if (err < 0) { pr_err("Couldn't synthesize evsel cpus.\n"); -- 2.56.1.915.g69d5ec7298-goog