From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64914C433F5 for ; Mon, 28 Mar 2022 23:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbiC1X2v (ORCPT ); Mon, 28 Mar 2022 19:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbiC1X2h (ORCPT ); Mon, 28 Mar 2022 19:28:37 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20051277A for ; Mon, 28 Mar 2022 16:26:55 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id k13-20020a25c60d000000b006339008b92fso12027305ybf.1 for ; Mon, 28 Mar 2022 16:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Fupq3XJMUIvfZtd7nCWtM0IzLS07K7rgInQ7zuEb4wY=; b=KVEofwtPahchiHI4Z6dqBFVjvduH18BDAzc6Li3xhStcNzxjpwFFX11Q4eX2TBBix9 bcvhgJlkLEtrOvuv9FKy2sJxw5zcHfTv5UUBVZB0SYOOjrfPzED19tZE6GMBHz4NXOrB Il1jPsV3VZv7kzeFLRm8qblxI6/0YvASO5yNOLMeL34nbwkU3DQEZ62p1vlSUPGsn3DM jtljGlSYN0zjnXHRyvS9dXBJmtmuqAB0dvm+rifZFDUFHRQWBPIIdZTTLAg3K/Q08ZvO utwSViH/8XrW1j3KwEgfyRJZrZGFVy0cXqw0UMISd+diKqlJWkeCjB56JIjUp8obP2J9 oIRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Fupq3XJMUIvfZtd7nCWtM0IzLS07K7rgInQ7zuEb4wY=; b=BO1kL8MCf+5iJ63bCStEZuwEF865OqfH8Fs0sHv+4l6ZpiUG0WJzOp1l/Te0lPl1IT MZuIPISk/GqUBWJ2dfk+xQy9bmnOB8VbjtwBuMQz8L7hxLINSkjy3/Cmmhd/UVtmYjAT clK8ISD6s+cXHXLDJpxKRMimmkc8c5w6wmI30vTgbYwzOfbB6abdcvSe2/5LsRB2bdi2 WDTMAdPPjuajrSBZaFY73dqAI3JjdWcoJNPdbgjcfy+oWROjpYXYWLhiHIA9zCUCIGNF Et0u2iaXdc+WSvqP2YzwMiiU1g2s6UXVQZy1UyPA/JO3pxVc5oOv+pYFTXC3iOxvCdBJ 0UUA== X-Gm-Message-State: AOAM531XiHBnl7DG0FlICDCprcWck4LBKS2c1Doyf2QzjXcmisLTnoGG 2sxVb1HMAuPDbkWIpwFaeHJf6Mla5D8t X-Google-Smtp-Source: ABdhPJwhgyfHz9+dsnfidErRLGIU1bseQ1e85VsPFp79nt7lIgS3DYCsPf0dsDthmUWrgaFylWFZLs6Ui+gJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a25:3246:0:b0:633:af97:a3eb with SMTP id y67-20020a253246000000b00633af97a3ebmr24623187yby.274.1648510015000; Mon, 28 Mar 2022 16:26:55 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:43 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-2-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 1/6] perf stat: Avoid segv if core.user_cpus isn't set. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Passing null to perf_cpu_map__max doesn't make sense as there is no valid max. Avoid this problem by null checking in perf_stat_init_aggr_mode. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 4ee40de698a4..b81ae5053218 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1472,7 +1472,10 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - nr =3D perf_cpu_map__max(evsel_list->core.cpus).cpu; + if (evsel_list->core.cpus) + nr =3D perf_cpu_map__max(evsel_list->core.cpus).cpu; + else + nr =3D 0; stat_config.cpus_aggr_map =3D cpu_aggr_map__empty_new(nr + 1); return stat_config.cpus_aggr_map ? 0 : -ENOMEM; } --=20 2.35.1.1021.g381101b075-goog From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCDA2C43217 for ; Mon, 28 Mar 2022 23:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230479AbiC1X25 (ORCPT ); Mon, 28 Mar 2022 19:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbiC1X2r (ORCPT ); Mon, 28 Mar 2022 19:28:47 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935D039149 for ; Mon, 28 Mar 2022 16:26:58 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i5-20020a258b05000000b006347131d40bso11919116ybl.17 for ; Mon, 28 Mar 2022 16:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4v15mL/KsIPcjfWANW6CoPVghkgsTalbfK+klAHCJek=; b=Z+T8cdctJOlwOxOPCD8FwbVN5jmTHQhwkJeSpfR5EUpH8oHbldDxVNFatl9FApzrYe jJoV2TD71fCY1Xk3UPGG3ldm7deIvEPOOwnwgkHcBSWsTAz9SU31GvMHRqko2Tsl+UWa atqnoPx546YcT3rQ5IuzgDkFPi4CjarrDjerygQTCbC2/968Y8SN6x3v6/mUob/Drbi8 ME7HsxtVLQAtCxW4kQuNYrwg/JgYahEiQJxSd/6f7Am/HbHBHhDFOyWXyzMx0LWJVqug ha74LCrLi0ejucXjBRd5k1Is5VI7MyLwxSIYGh67nSI5vgTpS42+Unm/DANEc5XldaX5 Xm0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4v15mL/KsIPcjfWANW6CoPVghkgsTalbfK+klAHCJek=; b=PpZ196bWu20LWt49yWKe2TKolPjO1e4nOjXOV/mQwjZcriof3MNWbsfEuraRE0783D 5QHa/MD8x9EIZlUQlVUZV6Mi2CBkGdXoy5gMOW26YN8V3mm2jOUyjZ2rqRoX2m8tBCd0 Oa9fAg2CE4AA5cohVVQmb82ramZulo3dcb1CnPiJGUn2GKCV1CoAvkYnpDmBiQ/cRb8l BTfBpOupy890JV15arcaop6o/0QF2uoRuxb2qtvbrktn0H3EalSn+5A3ZnNCPl/YPO/i 7V4DTREWc6RiMULtfJPfIJEFZVnyrCPCvrxUxqFejqITXc+vDWfVSP8etdtH/xiy3h34 x6bg== X-Gm-Message-State: AOAM53212jKf9DnegHscxS7knO4wluv2QSE7LMJtYk+edX1Tx7w02CFX BFwPH2wP0F4/BvMWLGB0atOwHk9FbM15 X-Google-Smtp-Source: ABdhPJxKqcBq06zaby/ljA8yCASn4AANh+tfk1ttaLKylHz4aHnc3KQov81yk153WqOHf8Xek4FEkUrT+AgG X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a25:608:0:b0:634:5ff5:7c65 with SMTP id 8-20020a250608000000b006345ff57c65mr24798354ybg.282.1648510017688; Mon, 28 Mar 2022 16:26:57 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:44 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-3-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 2/6] perf evlist: Rename cpus to user_requested_cpus From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" evlist contains cpus and all_cpus. all_cpus is the union of the cpu maps of all evsels. For non-task targets, cpus is set to be cpus requested from the command line, defaulting to all online cpus if no cpus are specified. For an uncore event, all_cpus may be just CPU 0 or every online CPU. This causes all_cpus to have fewer values than the cpus variable which is confusing given the 'all' in the name. To try to make the behavior clearer, rename cpus to user_requested_cpus and add comments on the two struct variables. Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 28 ++++++++++++------------ tools/lib/perf/include/internal/evlist.h | 7 +++++- tools/perf/arch/arm/util/cs-etm.c | 8 +++---- tools/perf/arch/arm64/util/arm-spe.c | 2 +- tools/perf/arch/x86/util/intel-bts.c | 2 +- tools/perf/arch/x86/util/intel-pt.c | 4 ++-- tools/perf/bench/evlist-open-close.c | 2 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-record.c | 6 ++--- tools/perf/builtin-stat.c | 10 ++++----- tools/perf/builtin-top.c | 2 +- tools/perf/util/auxtrace.c | 2 +- tools/perf/util/bpf_ftrace.c | 4 ++-- tools/perf/util/evlist.c | 15 +++++++------ tools/perf/util/record.c | 6 ++--- tools/perf/util/sideband_evlist.c | 3 ++- tools/perf/util/stat-display.c | 2 +- tools/perf/util/synthetic-events.c | 2 +- tools/perf/util/top.c | 8 ++++--- 19 files changed, 62 insertions(+), 53 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 9a770bfdc804..1b15ba13c477 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -41,10 +41,10 @@ static void __perf_evlist__propagate_maps(struct perf_e= vlist *evlist, */ if (!evsel->own_cpus || evlist->has_user_cpus) { perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__get(evlist->cpus); - } else if (!evsel->system_wide && perf_cpu_map__empty(evlist->cpus)) { + evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); + } else if (!evsel->system_wide && perf_cpu_map__empty(evlist->user_reques= ted_cpus)) { perf_cpu_map__put(evsel->cpus); - evsel->cpus =3D perf_cpu_map__get(evlist->cpus); + evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); } else if (evsel->cpus !=3D evsel->own_cpus) { perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__get(evsel->own_cpus); @@ -123,10 +123,10 @@ static void perf_evlist__purge(struct perf_evlist *ev= list) =20 void perf_evlist__exit(struct perf_evlist *evlist) { - perf_cpu_map__put(evlist->cpus); + perf_cpu_map__put(evlist->user_requested_cpus); perf_cpu_map__put(evlist->all_cpus); perf_thread_map__put(evlist->threads); - evlist->cpus =3D NULL; + evlist->user_requested_cpus =3D NULL; evlist->all_cpus =3D NULL; evlist->threads =3D NULL; fdarray__exit(&evlist->pollfd); @@ -155,9 +155,9 @@ void perf_evlist__set_maps(struct perf_evlist *evlist, * original reference count of 1. If that is not the case it is up to * the caller to increase the reference count. */ - if (cpus !=3D evlist->cpus) { - perf_cpu_map__put(evlist->cpus); - evlist->cpus =3D perf_cpu_map__get(cpus); + if (cpus !=3D evlist->user_requested_cpus) { + perf_cpu_map__put(evlist->user_requested_cpus); + evlist->user_requested_cpus =3D perf_cpu_map__get(cpus); } =20 if (threads !=3D evlist->threads) { @@ -294,7 +294,7 @@ int perf_evlist__id_add_fd(struct perf_evlist *evlist, =20 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) { - int nr_cpus =3D perf_cpu_map__nr(evlist->cpus); + int nr_cpus =3D perf_cpu_map__nr(evlist->user_requested_cpus); int nr_threads =3D perf_thread_map__nr(evlist->threads); int nfds =3D 0; struct perf_evsel *evsel; @@ -426,7 +426,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_= evlist_mmap_ops *ops, int idx, struct perf_mmap_param *mp, int cpu_idx, int thread, int *_output, int *_output_overwrite) { - struct perf_cpu evlist_cpu =3D perf_cpu_map__cpu(evlist->cpus, cpu_idx); + struct perf_cpu evlist_cpu =3D perf_cpu_map__cpu(evlist->user_requested_c= pus, cpu_idx); struct perf_evsel *evsel; int revent; =20 @@ -536,7 +536,7 @@ mmap_per_cpu(struct perf_evlist *evlist, struct perf_ev= list_mmap_ops *ops, struct perf_mmap_param *mp) { int nr_threads =3D perf_thread_map__nr(evlist->threads); - int nr_cpus =3D perf_cpu_map__nr(evlist->cpus); + int nr_cpus =3D perf_cpu_map__nr(evlist->user_requested_cpus); int cpu, thread; =20 for (cpu =3D 0; cpu < nr_cpus; cpu++) { @@ -564,8 +564,8 @@ static int perf_evlist__nr_mmaps(struct perf_evlist *ev= list) { int nr_mmaps; =20 - nr_mmaps =3D perf_cpu_map__nr(evlist->cpus); - if (perf_cpu_map__empty(evlist->cpus)) + nr_mmaps =3D perf_cpu_map__nr(evlist->user_requested_cpus); + if (perf_cpu_map__empty(evlist->user_requested_cpus)) nr_mmaps =3D perf_thread_map__nr(evlist->threads); =20 return nr_mmaps; @@ -576,7 +576,7 @@ int perf_evlist__mmap_ops(struct perf_evlist *evlist, struct perf_mmap_param *mp) { struct perf_evsel *evsel; - const struct perf_cpu_map *cpus =3D evlist->cpus; + const struct perf_cpu_map *cpus =3D evlist->user_requested_cpus; const struct perf_thread_map *threads =3D evlist->threads; =20 if (!ops || !ops->get || !ops->mmap) diff --git a/tools/lib/perf/include/internal/evlist.h b/tools/lib/perf/incl= ude/internal/evlist.h index 4cefade540bd..e3e64f37db7b 100644 --- a/tools/lib/perf/include/internal/evlist.h +++ b/tools/lib/perf/include/internal/evlist.h @@ -19,7 +19,12 @@ struct perf_evlist { int nr_entries; int nr_groups; bool has_user_cpus; - struct perf_cpu_map *cpus; + /** + * The cpus passed from the command line or all online CPUs by + * default. + */ + struct perf_cpu_map *user_requested_cpus; + /** The union of all evsel cpu maps. */ struct perf_cpu_map *all_cpus; struct perf_thread_map *threads; int nr_mmaps; diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index cbc555245959..11c71aa219f7 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -199,7 +199,7 @@ static int cs_etm_set_option(struct auxtrace_record *it= r, struct evsel *evsel, u32 option) { int i, err =3D -EINVAL; - struct perf_cpu_map *event_cpus =3D evsel->evlist->core.cpus; + struct perf_cpu_map *event_cpus =3D evsel->evlist->core.user_requested_cp= us; struct perf_cpu_map *online_cpus =3D perf_cpu_map__new(NULL); =20 /* Set option of each CPU we have */ @@ -299,7 +299,7 @@ static int cs_etm_recording_options(struct auxtrace_rec= ord *itr, container_of(itr, struct cs_etm_recording, itr); struct perf_pmu *cs_etm_pmu =3D ptr->cs_etm_pmu; struct evsel *evsel, *cs_etm_evsel =3D NULL; - struct perf_cpu_map *cpus =3D evlist->core.cpus; + struct perf_cpu_map *cpus =3D evlist->core.user_requested_cpus; bool privileged =3D perf_event_paranoid_check(-1); int err =3D 0; =20 @@ -522,7 +522,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __may= be_unused, { int i; int etmv3 =3D 0, etmv4 =3D 0, ete =3D 0; - struct perf_cpu_map *event_cpus =3D evlist->core.cpus; + struct perf_cpu_map *event_cpus =3D evlist->core.user_requested_cpus; struct perf_cpu_map *online_cpus =3D perf_cpu_map__new(NULL); =20 /* cpu map is not empty, we have specific CPUs to work with */ @@ -713,7 +713,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, u32 offset; u64 nr_cpu, type; struct perf_cpu_map *cpu_map; - struct perf_cpu_map *event_cpus =3D session->evlist->core.cpus; + struct perf_cpu_map *event_cpus =3D session->evlist->core.user_requested_= cpus; struct perf_cpu_map *online_cpus =3D perf_cpu_map__new(NULL); struct cs_etm_recording *ptr =3D container_of(itr, struct cs_etm_recording, itr); diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/u= til/arm-spe.c index 5860bbaea95a..86e2e926aa0e 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -144,7 +144,7 @@ static int arm_spe_recording_options(struct auxtrace_re= cord *itr, container_of(itr, struct arm_spe_recording, itr); struct perf_pmu *arm_spe_pmu =3D sper->arm_spe_pmu; struct evsel *evsel, *arm_spe_evsel =3D NULL; - struct perf_cpu_map *cpus =3D evlist->core.cpus; + struct perf_cpu_map *cpus =3D evlist->core.user_requested_cpus; bool privileged =3D perf_event_paranoid_check(-1); struct evsel *tracking_evsel; int err; diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/uti= l/intel-bts.c index 4a76d49d25d6..d68a0f48e41e 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -110,7 +110,7 @@ static int intel_bts_recording_options(struct auxtrace_= record *itr, container_of(itr, struct intel_bts_recording, itr); struct perf_pmu *intel_bts_pmu =3D btsr->intel_bts_pmu; struct evsel *evsel, *intel_bts_evsel =3D NULL; - const struct perf_cpu_map *cpus =3D evlist->core.cpus; + const struct perf_cpu_map *cpus =3D evlist->core.user_requested_cpus; bool privileged =3D perf_event_paranoid_check(-1); =20 if (opts->auxtrace_sample_mode) { diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index 8c31578d6f4a..38ec2666ec12 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -382,7 +382,7 @@ static int intel_pt_info_fill(struct auxtrace_record *i= tr, ui__warning("Intel Processor Trace: TSC not available\n"); } =20 - per_cpu_mmaps =3D !perf_cpu_map__empty(session->evlist->core.cpus); + per_cpu_mmaps =3D !perf_cpu_map__empty(session->evlist->core.user_request= ed_cpus); =20 auxtrace_info->type =3D PERF_AUXTRACE_INTEL_PT; auxtrace_info->priv[INTEL_PT_PMU_TYPE] =3D intel_pt_pmu->type; @@ -632,7 +632,7 @@ static int intel_pt_recording_options(struct auxtrace_r= ecord *itr, struct perf_pmu *intel_pt_pmu =3D ptr->intel_pt_pmu; bool have_timing_info, need_immediate =3D false; struct evsel *evsel, *intel_pt_evsel =3D NULL; - const struct perf_cpu_map *cpus =3D evlist->core.cpus; + const struct perf_cpu_map *cpus =3D evlist->core.user_requested_cpus; bool privileged =3D perf_event_paranoid_check(-1); u64 tsc_bit; int err; diff --git a/tools/perf/bench/evlist-open-close.c b/tools/perf/bench/evlist= -open-close.c index de56601f69ee..5a27691469ed 100644 --- a/tools/perf/bench/evlist-open-close.c +++ b/tools/perf/bench/evlist-open-close.c @@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr) =20 init_stats(&time_stats); =20 - printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.cpus)); + printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.user_requ= ested_cpus)); printf(" Number of threads:\t%d\n", evlist->core.threads->nr); printf(" Number of events:\t%d (%d fds)\n", evlist->core.nr_entries, evlist__count_evsel_fds(evlist)); diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index ad9ce1bfffa1..7de07bb16d23 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -301,7 +301,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpu= map) =20 static int set_tracing_cpu(struct perf_ftrace *ftrace) { - struct perf_cpu_map *cpumap =3D ftrace->evlist->core.cpus; + struct perf_cpu_map *cpumap =3D ftrace->evlist->core.user_requested_cpus; =20 if (!target__has_cpu(&ftrace->target)) return 0; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 0b4abed555d8..ba74fab02e62 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -987,7 +987,7 @@ static int record__thread_data_init_maps(struct record_= thread *thread_data, stru int m, tm, nr_mmaps =3D evlist->core.nr_mmaps; struct mmap *mmap =3D evlist->mmap; struct mmap *overwrite_mmap =3D evlist->overwrite_mmap; - struct perf_cpu_map *cpus =3D evlist->core.cpus; + struct perf_cpu_map *cpus =3D evlist->core.user_requested_cpus; =20 thread_data->nr_mmaps =3D bitmap_weight(thread_data->mask->maps.bits, thread_data->mask->maps.nbits); @@ -1881,7 +1881,7 @@ static int record__synthesize(struct record *rec, boo= l tail) return err; } =20 - err =3D perf_event__synthesize_cpu_map(&rec->tool, rec->evlist->core.cpus, + err =3D perf_event__synthesize_cpu_map(&rec->tool, rec->evlist->core.user= _requested_cpus, process_synthesized_event, NULL); if (err < 0) { pr_err("Couldn't synthesize cpu map.\n"); @@ -3675,7 +3675,7 @@ static int record__init_thread_default_masks(struct r= ecord *rec, struct perf_cpu static int record__init_thread_masks(struct record *rec) { int ret =3D 0; - struct perf_cpu_map *cpus =3D rec->evlist->core.cpus; + struct perf_cpu_map *cpus =3D rec->evlist->core.user_requested_cpus; =20 if (!record__threads_enabled(rec)) return record__init_thread_default_masks(rec, cpus); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b81ae5053218..a96f106dc93a 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -804,7 +804,7 @@ static int __run_perf_stat(int argc, const char **argv,= int run_idx) if (group) evlist__set_leader(evsel_list); =20 - if (!cpu_map__is_dummy(evsel_list->core.cpus)) { + if (!cpu_map__is_dummy(evsel_list->core.user_requested_cpus)) { if (affinity__setup(&saved_affinity) < 0) return -1; affinity =3D &saved_affinity; @@ -1458,7 +1458,7 @@ static int perf_stat_init_aggr_mode(void) aggr_cpu_id_get_t get_id =3D aggr_mode__get_aggr(stat_config.aggr_mode); =20 if (get_id) { - stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.cpus, + stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.user_request= ed_cpus, get_id, /*data=3D*/NULL); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); @@ -1472,8 +1472,8 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - if (evsel_list->core.cpus) - nr =3D perf_cpu_map__max(evsel_list->core.cpus).cpu; + if (evsel_list->core.user_requested_cpus) + nr =3D perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; else nr =3D 0; stat_config.cpus_aggr_map =3D cpu_aggr_map__empty_new(nr + 1); @@ -1630,7 +1630,7 @@ static int perf_stat_init_aggr_mode_file(struct perf_= stat *st) if (!get_id) return 0; =20 - stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.cpus, get_id,= env); + stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.user_requeste= d_cpus, get_id, env); if (!stat_config.aggr_map) { pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); return -1; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 9b08e44a31d9..fd8fd913c533 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1021,7 +1021,7 @@ static int perf_top__start_counters(struct perf_top *= top) =20 evlist__for_each_entry(evlist, counter) { try_again: - if (evsel__open(counter, top->evlist->core.cpus, + if (evsel__open(counter, top->evlist->core.user_requested_cpus, top->evlist->core.threads) < 0) { =20 /* diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 9e48652662d4..df1c5bbbaa0d 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -174,7 +174,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap= _params *mp, mp->idx =3D idx; =20 if (per_cpu) { - mp->cpu =3D perf_cpu_map__cpu(evlist->core.cpus, idx); + mp->cpu =3D perf_cpu_map__cpu(evlist->core.user_requested_cpus, idx); if (evlist->core.threads) mp->tid =3D perf_thread_map__pid(evlist->core.threads, 0); else diff --git a/tools/perf/util/bpf_ftrace.c b/tools/perf/util/bpf_ftrace.c index 4f4d3aaff37c..7a4297d8fd2c 100644 --- a/tools/perf/util/bpf_ftrace.c +++ b/tools/perf/util/bpf_ftrace.c @@ -38,7 +38,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *= ftrace) =20 /* don't need to set cpu filter for system-wide mode */ if (ftrace->target.cpu_list) { - ncpus =3D perf_cpu_map__nr(ftrace->evlist->core.cpus); + ncpus =3D perf_cpu_map__nr(ftrace->evlist->core.user_requested_cpus); bpf_map__set_max_entries(skel->maps.cpu_filter, ncpus); } =20 @@ -63,7 +63,7 @@ int perf_ftrace__latency_prepare_bpf(struct perf_ftrace *= ftrace) fd =3D bpf_map__fd(skel->maps.cpu_filter); =20 for (i =3D 0; i < ncpus; i++) { - cpu =3D perf_cpu_map__cpu(ftrace->evlist->core.cpus, i).cpu; + cpu =3D perf_cpu_map__cpu(ftrace->evlist->core.user_requested_cpus, i).= cpu; bpf_map_update_elem(fd, &cpu, &val, BPF_ANY); } } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 9bb79e049957..cb2cf4463c08 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -440,7 +440,7 @@ static void __evlist__disable(struct evlist *evlist, ch= ar *evsel_name) bool has_imm =3D false; =20 // See explanation in evlist__close() - if (!cpu_map__is_dummy(evlist->core.cpus)) { + if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { if (affinity__setup(&saved_affinity) < 0) return; affinity =3D &saved_affinity; @@ -500,7 +500,7 @@ static void __evlist__enable(struct evlist *evlist, cha= r *evsel_name) struct affinity saved_affinity, *affinity =3D NULL; =20 // See explanation in evlist__close() - if (!cpu_map__is_dummy(evlist->core.cpus)) { + if (!cpu_map__is_dummy(evlist->core.user_requested_cpus)) { if (affinity__setup(&saved_affinity) < 0) return; affinity =3D &saved_affinity; @@ -565,7 +565,7 @@ static int evlist__enable_event_cpu(struct evlist *evli= st, struct evsel *evsel, static int evlist__enable_event_thread(struct evlist *evlist, struct evsel= *evsel, int thread) { int cpu; - int nr_cpus =3D perf_cpu_map__nr(evlist->core.cpus); + int nr_cpus =3D perf_cpu_map__nr(evlist->core.user_requested_cpus); =20 if (!evsel->core.fd) return -EINVAL; @@ -580,7 +580,7 @@ static int evlist__enable_event_thread(struct evlist *e= vlist, struct evsel *evse =20 int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, i= nt idx) { - bool per_cpu_mmaps =3D !perf_cpu_map__empty(evlist->core.cpus); + bool per_cpu_mmaps =3D !perf_cpu_map__empty(evlist->core.user_requested_c= pus); =20 if (per_cpu_mmaps) return evlist__enable_event_cpu(evlist, evsel, idx); @@ -1301,10 +1301,11 @@ void evlist__close(struct evlist *evlist) struct affinity affinity; =20 /* - * With perf record core.cpus is usually NULL. + * With perf record core.user_requested_cpus is usually NULL. * Use the old method to handle this for now. */ - if (!evlist->core.cpus || cpu_map__is_dummy(evlist->core.cpus)) { + if (!evlist->core.user_requested_cpus || + cpu_map__is_dummy(evlist->core.user_requested_cpus)) { evlist__for_each_entry_reverse(evlist, evsel) evsel__close(evsel); return; @@ -1367,7 +1368,7 @@ int evlist__open(struct evlist *evlist) * Default: one fd per CPU, all threads, aka systemwide * as sys_perf_event_open(cpu =3D -1, thread =3D -1) is EINVAL */ - if (evlist->core.threads =3D=3D NULL && evlist->core.cpus =3D=3D NULL) { + if (evlist->core.threads =3D=3D NULL && evlist->core.user_requested_cpus = =3D=3D NULL) { err =3D evlist__create_syswide_maps(evlist); if (err < 0) goto out_err; diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 007a64681416..5b09ecbb05dc 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -106,7 +106,7 @@ void evlist__config(struct evlist *evlist, struct recor= d_opts *opts, struct call if (opts->group) evlist__set_leader(evlist); =20 - if (perf_cpu_map__cpu(evlist->core.cpus, 0).cpu < 0) + if (perf_cpu_map__cpu(evlist->core.user_requested_cpus, 0).cpu < 0) opts->no_inherit =3D true; =20 use_comm_exec =3D perf_can_comm_exec(); @@ -244,7 +244,7 @@ bool evlist__can_select_event(struct evlist *evlist, co= nst char *str) =20 evsel =3D evlist__last(temp_evlist); =20 - if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) { + if (!evlist || perf_cpu_map__empty(evlist->core.user_requested_cpus)) { struct perf_cpu_map *cpus =3D perf_cpu_map__new(NULL); =20 if (cpus) @@ -252,7 +252,7 @@ bool evlist__can_select_event(struct evlist *evlist, co= nst char *str) =20 perf_cpu_map__put(cpus); } else { - cpu =3D perf_cpu_map__cpu(evlist->core.cpus, 0); + cpu =3D perf_cpu_map__cpu(evlist->core.user_requested_cpus, 0); } =20 while (1) { diff --git a/tools/perf/util/sideband_evlist.c b/tools/perf/util/sideband_e= vlist.c index 748371ac22be..388846f17bc1 100644 --- a/tools/perf/util/sideband_evlist.c +++ b/tools/perf/util/sideband_evlist.c @@ -114,7 +114,8 @@ int evlist__start_sb_thread(struct evlist *evlist, stru= ct target *target) } =20 evlist__for_each_entry(evlist, counter) { - if (evsel__open(counter, evlist->core.cpus, evlist->core.threads) < 0) + if (evsel__open(counter, evlist->core.user_requested_cpus, + evlist->core.threads) < 0) goto out_delete_evlist; } =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 9cbe351b141f..138e3ab9d638 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -929,7 +929,7 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, int all_idx; struct perf_cpu cpu; =20 - perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.cpus) { + perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.user_requested_cpus= ) { struct evsel *counter; bool first =3D true; =20 diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index b654de0841f8..27acdc5e5723 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -2127,7 +2127,7 @@ int perf_event__synthesize_stat_events(struct perf_st= at_config *config, struct p return err; } =20 - err =3D perf_event__synthesize_cpu_map(tool, evlist->core.cpus, process, = NULL); + err =3D perf_event__synthesize_cpu_map(tool, evlist->core.user_requested_= cpus, process, NULL); if (err < 0) { pr_err("Couldn't synthesize thread map.\n"); return err; diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c index c1ebfc5d2e0c..b8b32431d2f7 100644 --- a/tools/perf/util/top.c +++ b/tools/perf/util/top.c @@ -95,15 +95,17 @@ size_t perf_top__header_snprintf(struct perf_top *top, = char *bf, size_t size) =20 if (target->cpu_list) ret +=3D SNPRINTF(bf + ret, size - ret, ", CPU%s: %s)", - perf_cpu_map__nr(top->evlist->core.cpus) > 1 ? "s" : "", + perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 + ? "s" : "", target->cpu_list); else { if (target->tid) ret +=3D SNPRINTF(bf + ret, size - ret, ")"); else ret +=3D SNPRINTF(bf + ret, size - ret, ", %d CPU%s)", - perf_cpu_map__nr(top->evlist->core.cpus), - perf_cpu_map__nr(top->evlist->core.cpus) > 1 ? "s" : ""); + perf_cpu_map__nr(top->evlist->core.user_requested_cpus), + perf_cpu_map__nr(top->evlist->core.user_requested_cpus) > 1 + ? "s" : ""); } =20 perf_top__reset_sample_counters(top); --=20 2.35.1.1021.g381101b075-goog From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D140C433EF for ; Mon, 28 Mar 2022 23:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231128AbiC1X3L (ORCPT ); Mon, 28 Mar 2022 19:29:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbiC1X2r (ORCPT ); Mon, 28 Mar 2022 19:28:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A6DC369DC for ; Mon, 28 Mar 2022 16:27:00 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e7-20020a258747000000b00633ee0cbca5so11980422ybn.23 for ; Mon, 28 Mar 2022 16:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fd8zO3I7cR3jn/Jx1EW0YLNB0c8F/thF/fGaitvvb58=; b=jhWfrBgC3Vidx16ZXPyaLDraZh3tQuBYXM724VRgco4ncvfxUi7yyZL7BAMENECuRr c8ZOwIgO5+uZy4p89VQXhbbCrSL8Cd0fRgY7Qgttlf7fm0fUgJe7cfxJoGx0+cGnFh7N KEB+IRtL1LlXsuam7rw7lu71qt2dGcSOIUCAjAPnee7ZkCJxJfye0EhEXY60jtniThLR W/hBrZyqmOKkZUOvGE6itlT47MOqBU1C+DuAI8pS9d/x1QpFDWyaip6AFrUXzzx+rM4Q qHMX7xcid4VCbEkpxBxj7NPPx8jYtHKTG09Hyjy3FN0YubprJa9gxwYNJH5xntFBiNm3 06uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fd8zO3I7cR3jn/Jx1EW0YLNB0c8F/thF/fGaitvvb58=; b=pzX1XzWSi7NX/KmgQHbji8fzbM45Xv2FBfxxhV0IbVDL6coohgdBvRT7NxouQW4aiy J83xiqpWKh+Ye4CJAeAcXftKSoG6JTuOAnQQIbu+Z5G9p1/AL/HTiJ0r2bvk5MoVy8oH 43m1ZXR58UdvCee3LkwQYahMgxQVvR0Vk7OJ4gXigkLO73x1/5dTZ/cSF710tluf9VlQ LvnA0VhMlrStcdMXuqIuSd9nIFdQZtT7/VUdeA7UtLTzqr6sht0WN7ZIb1G/nCYDadwN xjHtwFGPklo93HcZJW5UTrDtfZdq99G9qlxMMx0HJMxVKWl1BDxC5amJraUjiadJDfoS 2OMQ== X-Gm-Message-State: AOAM533N9VQW/kyGp5hqGSV5VmpxWc4nT8kdunkSfgzG0jOjObDvMdcS g9yMxZzzOZK/jvwjRBpxHFv9OfDuxNBb X-Google-Smtp-Source: ABdhPJx9mX24vBUXKujfAxpZd4EOEF4CDe3zBNIYlkFzjKX9KG29aQUbCRbBy+3NfgADLi4J9ufU7jNV4G8B X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a0d:eb4c:0:b0:2e5:bd5c:12cf with SMTP id u73-20020a0deb4c000000b002e5bd5c12cfmr28160203ywe.116.1648510019835; Mon, 28 Mar 2022 16:26:59 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:45 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-4-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 3/6] perf cpumap: Add is_subset function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Returns true if the second argument is a subset of the first. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 20 ++++++++++++++++++++ tools/lib/perf/include/internal/cpumap.h | 1 + 2 files changed, 21 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ee66760f1e63..23701024e0c0 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -319,6 +319,26 @@ struct perf_cpu perf_cpu_map__max(struct perf_cpu_map = *map) return map->nr > 0 ? map->map[map->nr - 1] : result; } =20 +/** Is 'b' a subset of 'a'. */ +bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct pe= rf_cpu_map *b) +{ + if (a =3D=3D b || !b) + return true; + if (!a || b->nr > a->nr) + return false; + + for (int i =3D 0, j =3D 0; i < a->nr; i++) { + if (a->map[i].cpu > b->map[j].cpu) + return false; + if (a->map[i].cpu =3D=3D b->map[j].cpu) { + j++; + if (j =3D=3D b->nr) + return true; + } + } + return false; +} + /* * Merge two cpumaps * diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 1973a18c096b..35dd29642296 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -25,5 +25,6 @@ struct perf_cpu_map { #endif =20 int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu= ); +bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct pe= rf_cpu_map *b); =20 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ --=20 2.35.1.1021.g381101b075-goog From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5BBFC433EF for ; Mon, 28 Mar 2022 23:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230518AbiC1X3I (ORCPT ); Mon, 28 Mar 2022 19:29:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbiC1X2r (ORCPT ); Mon, 28 Mar 2022 19:28:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FE4F186E0 for ; Mon, 28 Mar 2022 16:27:03 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id b16-20020a253410000000b00633b9e71eecso11941707yba.14 for ; Mon, 28 Mar 2022 16:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=wTKe8RpF21rMt2kcDMmTht0LJEvhd7SCLcprAeqvk0k=; b=T+4CDrUc5B8KgUxLdGAYIFFTV/O9bYCD2ejWPkf6qr6F1udOCh/a2NQLPEB+f3E/NX 4TWmJqbMg2E9di4NS0w6fgrYVbAYscM4TtPW15WASNVFdWbW4eNnH2cHi0Ld3Mk1u6l+ aRkS3ldnET20rnCamLxmrQuXIDBXQDi9UG/NdvJ1h1itQe2WvqFiz/QGC1DXWyZjF8eh PZJ43qGpWsndy7U8UxNZkEd4PrX+UBILlb0wU9QU2Qgeh99PvTxAh3LRjkaZxeFHT7GX wMFm3Im+nIYQIFbJdUfT4UE0Y7ZyLX7I9IdOPOEvOjJFyVb+ArG5Ui/FgzgqWPqc0er1 IhyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=wTKe8RpF21rMt2kcDMmTht0LJEvhd7SCLcprAeqvk0k=; b=TRtHLk0v/YdWdlRjQWSFR/njAYATpaxE++w3oAlEUnPfGMPsBGFqSwrnzbBbXeNAO9 8SHA/SrarPMvK//vs6LPbWcE3+uL1MHNkqDIKYPwKWx94jZFV2/nyafbsw499Hv1LOZg ECLsYaFQbiyrccYVS0VoLvB5IEqUf/o2tONt1Btymzs7ciDob2LtkXAmk+qiJKtLOBpP Aka9E/fI+LSp+3+9ZuqaLheU1+6e7IkO8PEK9iqb+cOX5GUGkyjN42rm3i++FgSjd4oO 0uSE0W1nKg7je08iGED34kTH9B5k/wxjuzMJfJxvYL0Pvmh8O31enLly+N5bhDClq2pV b0Dw== X-Gm-Message-State: AOAM531RJU23PTQJYOCqh37j7IWq05s38vPlLfCeQCv5ZdRSOCKDXlFG LjsG1vG6xdvPawHNUlD7ETrD+AKYPSeX X-Google-Smtp-Source: ABdhPJz0C9b/wpARXJ780K4O2sn/803EfldbYME8HRYxuiKm0vuJpVEupKAKTIMkx4gfX2bF+RArPAe9TLyO X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a25:5f06:0:b0:633:80e1:6336 with SMTP id t6-20020a255f06000000b0063380e16336mr25503992ybb.100.1648510022185; Mon, 28 Mar 2022 16:27:02 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:46 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-5-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 4/6] perf cpumap: More cpu map reuse by merge. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_cpu_map__merge will reuse one of its arguments if they are equal or the other argument is NULL. The arguments could be reused if it is known one set of values is a subset of the other. For example, a map of 0-1 and a map of just 0 when merged yields the map of 0-1. Currently a new map is created rather than adding a reference count to the original 0-1 map. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 23701024e0c0..384d5e076ee4 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -355,17 +355,12 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_= cpu_map *orig, int i, j, k; struct perf_cpu_map *merged; =20 - if (!orig && !other) - return NULL; - if (!orig) { - perf_cpu_map__get(other); - return other; - } - if (!other) - return orig; - if (orig->nr =3D=3D other->nr && - !memcmp(orig->map, other->map, orig->nr * sizeof(struct perf_cpu))) + if (perf_cpu_map__is_subset(orig, other)) return orig; + if (perf_cpu_map__is_subset(other, orig)) { + perf_cpu_map__put(orig); + return perf_cpu_map__get(other); + } =20 tmp_len =3D orig->nr + other->nr; tmp_cpus =3D malloc(tmp_len * sizeof(struct perf_cpu)); --=20 2.35.1.1021.g381101b075-goog From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F31E5C433FE for ; Mon, 28 Mar 2022 23:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbiC1X3E (ORCPT ); Mon, 28 Mar 2022 19:29:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbiC1X2s (ORCPT ); Mon, 28 Mar 2022 19:28:48 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 573122DD44 for ; Mon, 28 Mar 2022 16:27:05 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b16-20020a253410000000b00633b9e71eecso11941752yba.14 for ; Mon, 28 Mar 2022 16:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HI7lVdFOSrlQd5wT9t/SBLu67RK0OyhqHS+mLTojDoE=; b=OOfLyxjdfGI/Zzi87JL87OQfMszCNTUskyTB3iTykwAXRjAEpDXIS+voGrvIAZfDpR Epwup6CsDlPPO2kU6QMzOn0Epm3iM+kImr6kf8OxgLNzzbnruKyXgm/LeewSSA3k0yqp favmnY4DSQkIBaEiZz6q5NwUzkwJ78hb2Y4huCXqqEqyWjpOuVAB67CcxkD9vdR/hOfJ 1u2AhCfGi1Mi+uCrQi8MiQH9uaS7hzSH+fiRw0fJ6TwTPMsnj4O6XGGzZLMpkd9BNXO9 fGG+9nyuNkcRx+Dxg1AF6oDiL2h9rmOclzepyuG1ulyjca+zHJxSTl+seEh1kjNQXI3I S4RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HI7lVdFOSrlQd5wT9t/SBLu67RK0OyhqHS+mLTojDoE=; b=uLISn4BTYIMZ7ScpYTpOTBH6eiy2OKbj84SZncHGeeVuFTxgy0eqJNsXy4PJeUjMGU wKLfAs8vt/yzkgqM6mm/Mw1k6zd/Rvp1211eTnCu4lpHlGWmFwxnBRw6T753So1NZZ70 2uoavGnh5XUHlU38s/mvPirNAigcuQMRoS7T2Ah8choFwFikrQX4zM2oPHFFhu3MKN3X mHUQPtpx56ni4HpRF6Ze8AChQH/xXMrq3/K+03MphEIfqGyBGvVk5F6m4GWRJ1JltNHX 811Vr3mWBglVE8JKAayA54gsRVr81wckJSf21XiiqC4W8NM1Cjez31KO4HkMd0qnqJtV Cd1A== X-Gm-Message-State: AOAM533OdPiNiOYHprLuYZDkl2a76gP7ymYWlvnUdxWU5zaIy8j6J76H uRQHZFOocO6vx5WeLMwEcgqldW87Y6FJ X-Google-Smtp-Source: ABdhPJxq3SawZ28lJ97d+m1B27jGZL3+ADhO9V4EPLQfdWt+wZImHtVrn+mTGk9KAcNNkDb7tpvSE9m8TcX9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a05:6902:241:b0:633:d3e1:ff5e with SMTP id k1-20020a056902024100b00633d3e1ff5emr25241467ybs.625.1648510024506; Mon, 28 Mar 2022 16:27:04 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:47 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-6-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 5/6] perf cpumap: Add intersect function. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The merge function gives the union of two cpu maps. Add an intersect function which will be used in the next change. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 38 ++++++++++++++++++++++++++++ tools/lib/perf/include/perf/cpumap.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 384d5e076ee4..60cccd05f243 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -390,3 +390,41 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_c= pu_map *orig, perf_cpu_map__put(orig); return merged; } + +struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_map *orig, + struct perf_cpu_map *other) +{ + struct perf_cpu *tmp_cpus; + int tmp_len; + int i, j, k; + struct perf_cpu_map *merged =3D NULL; + + if (perf_cpu_map__is_subset(other, orig)) + return orig; + if (perf_cpu_map__is_subset(orig, other)) { + perf_cpu_map__put(orig); + return perf_cpu_map__get(other); + } + + tmp_len =3D max(orig->nr, other->nr); + tmp_cpus =3D malloc(tmp_len * sizeof(struct perf_cpu)); + if (!tmp_cpus) + return NULL; + + i =3D j =3D k =3D 0; + while (i < orig->nr && j < other->nr) { + if (orig->map[i].cpu < other->map[j].cpu) + i++; + else if (orig->map[i].cpu > other->map[j].cpu) + j++; + else { + j++; + tmp_cpus[k++] =3D orig->map[i++]; + } + } + if (k) + merged =3D cpu_map__trim_new(k, tmp_cpus); + free(tmp_cpus); + perf_cpu_map__put(orig); + return merged; +} diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 4a2edbdb5e2b..a2a7216c0b78 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -19,6 +19,8 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE = *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *ma= p); LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *= orig, struct perf_cpu_map *other); +LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersect(struct perf_cpu_m= ap *orig, + struct perf_cpu_map *other); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *c= pus, int idx); LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); --=20 2.35.1.1021.g381101b075-goog From nobody Fri Jun 19 21:30:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C22A1C433F5 for ; Mon, 28 Mar 2022 23:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231136AbiC1X3Q (ORCPT ); Mon, 28 Mar 2022 19:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbiC1X2t (ORCPT ); Mon, 28 Mar 2022 19:28:49 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE7003151B for ; Mon, 28 Mar 2022 16:27:07 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2ea05573995so55490077b3.8 for ; Mon, 28 Mar 2022 16:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=62T0/TU1Sa4Wqe+eN5txv4UBeKWrByFVFuAcfl2TJUY=; b=WuFWAPyS7pgyWDgjtlzsKpFPsxxPd9tgW0nM0IULEGbEsaEs5zE0BwR/iV0yiRyiUr C9LzDD7OQikFacW2EZ3HgTOERW8ioeMdDmGtbxjGjdAvIgFqPAGlWSKO/Fo07kxOusQj xXQTuUoN7COi2/I3yvyXPwYeetZ2hVDiAs6t36XmpeIj0N0pXu41bgEpHgFvTMqjwxGS YkJ0glvboVcb8xY9ZZdbAAgSHoReMnojd0N4VWMYdi2aBcDvyxepEb8RTHF4ZzMUgt9m qUiIro8106ztVL4WbMUEwnsQ0Z0mF/k9xEPBZD0X3XV3XPniYpCSNqCpBNG82OklWGGW su1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=62T0/TU1Sa4Wqe+eN5txv4UBeKWrByFVFuAcfl2TJUY=; b=UmUUvfVi7lDKMTKaexeGChexThSj5zvHrNm5vZWRPuoCVpLTXObTZ2kcuC78ULF460 RjZV9iDKfz5w4GUQDf2Z1bY8ti/XgcQ81AmHhIooUWky3Qgp+bxNnIAwlvH8EliHGghP PXXA/rqhz7GEKiY7o3jaYlbR75++4kpi7YFxJK+Xb2kYyVepyDS34HgC1bnPVRZ9PktH st4tyBf4HQsCKqvYgfyp4WntzsJ/Nr9m/8/I0iPcSpHb3hoQRG9iBSXXUDZ/gOON6tB1 34d+K91VgdpiumPcoruKEZIl7u2k38SxCMH7y9vlmUCd6p77j83k4rci+kyHzFGUaFou bCSA== X-Gm-Message-State: AOAM531BCapJfQXEAY8mSlDJMgdUuK4Oq6VPkdaNFYZBy2PspG8qfMAb WVULA7N+tiNR2vAVxXCCTBDVAVVpe9yY X-Google-Smtp-Source: ABdhPJyGiiWxc4ARHStwB+ZXo/aW9HRYLxvc/de+ZQtJa8gJqpvKLIH6JBfkA9BFTOaLI3PuawSjmI+3PmmF X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:9d6a:527d:cf46:71e2]) (user=irogers job=sendgmr) by 2002:a25:ba04:0:b0:623:ed7a:701d with SMTP id t4-20020a25ba04000000b00623ed7a701dmr25269976ybg.209.1648510026853; Mon, 28 Mar 2022 16:27:06 -0700 (PDT) Date: Mon, 28 Mar 2022 16:26:48 -0700 In-Reply-To: <20220328232648.2127340-1-irogers@google.com> Message-Id: <20220328232648.2127340-7-irogers@google.com> Mime-Version: 1.0 References: <20220328232648.2127340-1-irogers@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 6/6] perf evlist: Respect all_cpus when setting user_requested_cpus From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Kajol Jain , James Clark , German Gomez , Adrian Hunter , Riccardo Mancini , Andi Kleen , Alexey Bayduraev , Alexander Antonov , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If all_cpus is calculated it represents the merge/union of all evsel cpu maps. By default user_requested_cpus is computed to be the online CPUs. For uncore events, it is often the case currently that all_cpus is a subset of user_requested_cpus. Metrics printed without aggregation and with metric-only, in print_no_aggr_metric, iterate over user_requested_cpus assuming every CPU has a metric to print. For each CPU the prefix is printed, but then if the evsel's cpus doesn't contain anything you get an empty line like the following on a 2 socket 36 core SkylakeX: ``` $ perf stat -A -M DRAM_BW_Use -a --metric-only -I 1000 1.000453137 CPU0 0.00 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 CPU18 0.00 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 1.000453137 2.003717143 CPU0 0.00 ... ``` While it is possible to be lazier in printing the prefix and trailing newline, having user_requested_cpus not be a subset of all_cpus is preferential so that wasted work isn't done elsewhere user_requested_cpus is used. The change modifies user_requested_cpus to be the intersection of user specified CPUs, or default all online CPUs, with the CPUs computed through the merge of all evsel cpu maps. New behavior: ``` $ perf stat -A -M DRAM_BW_Use -a --metric-only -I 1000 1.001086325 CPU0 0.00 1.001086325 CPU18 0.00 2.003671291 CPU0 0.00 2.003671291 CPU18 0.00 ... ``` Signed-off-by: Ian Rogers --- tools/perf/util/evlist.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index cb2cf4463c08..1a3308ec35f1 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1036,6 +1036,8 @@ int evlist__create_maps(struct evlist *evlist, struct= target *target) if (!cpus) goto out_delete_threads; =20 + if (evlist->core.all_cpus) + cpus =3D perf_cpu_map__intersect(cpus, evlist->core.all_cpus); evlist->core.has_user_cpus =3D !!target->cpu_list && !target->hybrid; =20 perf_evlist__set_maps(&evlist->core, cpus, threads); --=20 2.35.1.1021.g381101b075-goog