From nobody Sun Feb 8 00:11:56 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 72A07C77B7A for ; Wed, 24 May 2023 22:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236606AbjEXWSr (ORCPT ); Wed, 24 May 2023 18:18:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236518AbjEXWSj (ORCPT ); Wed, 24 May 2023 18:18:39 -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 6E2B113A for ; Wed, 24 May 2023 15:18:38 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba81b37d9d2so2863426276.3 for ; Wed, 24 May 2023 15:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966717; x=1687558717; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oOYhuvl7j4rILtDYoGdkPuYJrVXEqJknY6wScK522SU=; b=67+9ALB3eZ2ZAz2DQQxqS9HpMTTA2RMnCLODfUbzvIf2IN2exBLSJWH+utQF2kJCC3 8Yeuq5eqt/fW0Vd9MzYgXMa/brXXO+Slc7bNtXryqVvjvwL+Qc1gaGBkowPvoKd65BV3 lCP1CT9xWxjoBgKR2Bqo4rUqoxCk1c7/t26JsaF0pdbhm6SqVGo2b7w9exP17WpU+JTQ 2G2JR47bt4R6ZVVhayAnsWyUb3PgyHFpGFMlg1kwkBxY6w7a56HuLqkO0OrrH5m8ezp3 wHDKWhIwtPsBTCa7h/ETGkqI2utZVjWAeD+/lzVCFTgJeY2ZL1N1pYXxkx0Y51fKmrhG fuew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966717; x=1687558717; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oOYhuvl7j4rILtDYoGdkPuYJrVXEqJknY6wScK522SU=; b=ClbNsVNXhxnNB1WMdFrQNcYY5nCwNwNUrGuzdY+r+FS/RlDNMkAlub/u08LtnVPncM xViLITJO0c0O0J3m5jLg+WiTe2wzdVhvfxlClIEgspa2sJ3Js+0qf6OHhX2MrmX/TA7R jk326C1bPmvzCWaY6cyQAhJEqUQeHEHGr5Gf+fL++oFHVc7/lASdU6uX5FblLdDY9Wom Pqj2lNNclL3cGzQRRBEz75W8tLTXH1Z8mzAWSNYpU+NgfCNylPtd9wNPOI+lTCjjKit8 M5npBl29icrdry5ujZDYXjHD4b7GiN6fobKSAPTM3CCl2x2uhkiBjRjUZM0QrBh6KXeR /KTQ== X-Gm-Message-State: AC+VfDwoDInOKA3BFzdyHKwksZVCE2iLM/C/c7TUIWKhbPfBLP+GZj6v m9J9G+fhj8YILrKkz1+tIaMv3KN6mHSk X-Google-Smtp-Source: ACHHUZ5RlOQlKwSPkAmv8JiRproRQrkYaHEo+hNcLC6PUdaeblJ0iScX+tlypvYK2W6mwqg5V3Z4OtevgWkw X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a05:6902:1615:b0:ba7:8099:c5f2 with SMTP id bw21-20020a056902161500b00ba78099c5f2mr588863ybb.8.1684966717718; Wed, 24 May 2023 15:18:37 -0700 (PDT) Date: Wed, 24 May 2023 15:17:57 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-2-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 01/35] perf cpumap: Add intersect function From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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 is necessary, for example, when intersecting a PMUs supported CPUs with user requested. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/cpumap.c | 35 ++++++++++++++++++++++++ tools/lib/perf/include/perf/cpumap.h | 2 ++ tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/cpumap.c | 41 ++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 5 files changed, 80 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 1229b18bcdb1..d4f3a1a12522 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -402,3 +402,38 @@ 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 perf_cpu_map__get(orig); + if (perf_cpu_map__is_subset(orig, other)) + 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); + return merged; +} diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 3f43f770cdac..0466c4216fbb 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -20,6 +20,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); diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index b89d69afcef0..eef400025fca 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -97,6 +97,7 @@ static struct test_suite *generic_tests[] =3D { &suite__backward_ring_buffer, &suite__cpu_map_print, &suite__cpu_map_merge, + &suite__cpu_map_intersect, &suite__sdt_event, &suite__is_printable_array, &suite__bitmap_print, diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index b1a924314e09..92232978fe5e 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -171,6 +171,47 @@ static int test__cpu_map_merge(struct test_suite *test= __maybe_unused, int subte return 0; } =20 +static int __test__cpu_map_intersect(const char *lhs, const char *rhs, int= nr, const char *expected) +{ + struct perf_cpu_map *a =3D perf_cpu_map__new(lhs); + struct perf_cpu_map *b =3D perf_cpu_map__new(rhs); + struct perf_cpu_map *c =3D perf_cpu_map__intersect(a, b); + char buf[100]; + + TEST_ASSERT_EQUAL("failed to intersect map: bad nr", perf_cpu_map__nr(c),= nr); + cpu_map__snprint(c, buf, sizeof(buf)); + TEST_ASSERT_VAL("failed to intersect map: bad result", !strcmp(buf, expec= ted)); + perf_cpu_map__put(a); + perf_cpu_map__put(b); + perf_cpu_map__put(c); + return 0; +} + +static int test__cpu_map_intersect(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + int ret; + + ret =3D __test__cpu_map_intersect("4,2,1", "4,5,7", 1, "4"); + if (ret) + return ret; + ret =3D __test__cpu_map_intersect("1-8", "6-9", 3, "6-8"); + if (ret) + return ret; + ret =3D __test__cpu_map_intersect("1-8,12-20", "6-9,15", 4, "6-8,15"); + if (ret) + return ret; + ret =3D __test__cpu_map_intersect("4,2,1", "1", 1, "1"); + if (ret) + return ret; + ret =3D __test__cpu_map_intersect("1", "4,2,1", 1, "1"); + if (ret) + return ret; + ret =3D __test__cpu_map_intersect("1", "1", 1, "1"); + return ret; +} + DEFINE_SUITE("Synthesize cpu map", cpu_map_synthesize); DEFINE_SUITE("Print cpu map", cpu_map_print); DEFINE_SUITE("Merge cpu map", cpu_map_merge); +DEFINE_SUITE("Intersect cpu map", cpu_map_intersect); diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 9a0f3904e53d..b4e54f08bc39 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -127,6 +127,7 @@ DECLARE_SUITE(event_times); DECLARE_SUITE(backward_ring_buffer); DECLARE_SUITE(cpu_map_print); DECLARE_SUITE(cpu_map_merge); +DECLARE_SUITE(cpu_map_intersect); DECLARE_SUITE(sdt_event); DECLARE_SUITE(is_printable_array); DECLARE_SUITE(bitmap_print); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:56 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 21025C7EE2C for ; Wed, 24 May 2023 22:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236522AbjEXWSu (ORCPT ); Wed, 24 May 2023 18:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236244AbjEXWSl (ORCPT ); Wed, 24 May 2023 18:18:41 -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 7C543189 for ; Wed, 24 May 2023 15:18:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb78a3daaso1870342276.1 for ; Wed, 24 May 2023 15:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966719; x=1687558719; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=057e7HsRfrUjB66n+MyXVmP8dOuM02fcMdiEZVZgYrU=; b=dvNFdxGwO9BK6xjIp7teO+7XWdJt0dgU7vf5V7rd/YsFOhzIgMpFrbrtDFBFtxoVTC IXUMA5Snqk6STJbRPnPC6NRUCVN/XKKpoPSYYPkizRP2ZrWjLp57I8/bVgtryxfYjWmM 3gGWsnyzMbe/2RHSI49yEeWAHdSDRtLXMF+yz+MToG4z7LOL8qSOISIDYynJHTmGFLpz reyoa3oidSBF2UpYsmeuVhyDrldlpdotnyeVJUHIt0KjHKthIf0RvOZXWJr2znegOq+4 SDWOnBIM2nwCMKkFD/OlkiNH6Rt3jAaNbZM/TFKjwodoDtJqWQTxIqcJFfB8c4NuS08+ h5Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966719; x=1687558719; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=057e7HsRfrUjB66n+MyXVmP8dOuM02fcMdiEZVZgYrU=; b=BuBdePmU0tYdwfwHPRJoHVhiB7UONytTT5WFbys4XmX1CibqPDiuzbAY6/UvPzxSKa /S3BAkqn2rwuSFD1L+D4xxf+RGPSUYVj9wTUAbl7NcX2FDNjyXAIk8898cZrGE8s2rST wZQfuuz+nGa3OTf826+iwU3SYRcLnr2q/bJNsjws6sN2l59QiUOOEIsqPUVr4nZ3gndG FyysqaEb2z6P31fJ18wwCWX8sjs6vYN0R02/C6Xbi0I6uJWq8oVPhwqQlJJj0JumesRf r9ZAbnvV87YRh2pUFxcC1yOo7ern0pQXXSAZRijcyqkR9vPZ+GQOwWjQ83gmMIfVyY7m j2ew== X-Gm-Message-State: AC+VfDwYCEiYRMuBL4eRExvSMub9MVwnxP7OPO1fT/WIXGSk6Aoyxvlw Hy+5j3g9A9FMSWXTzcEgPLvuiqqdehrh X-Google-Smtp-Source: ACHHUZ4nZ3QY3W3yj3bCT/LKMCbuUt+ei31h9EkO/cLy/9wr8TKW2dnJI7BNr9GOkD6EIhYQ/DP+/8mE3Upv X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:6702:0:b0:ba7:4dda:f858 with SMTP id b2-20020a256702000000b00ba74ddaf858mr745406ybc.10.1684966719719; Wed, 24 May 2023 15:18:39 -0700 (PDT) Date: Wed, 24 May 2023 15:17:58 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-3-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 02/35] perf tests: Organize cpu_map tests into a single suite From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Go from 4 suites to a single suite with 4 test cases. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/tests/builtin-test.c | 5 +---- tools/perf/tests/cpumap.c | 16 ++++++++++++---- tools/perf/tests/tests.h | 5 +---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index eef400025fca..aa44fdc84763 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -88,16 +88,13 @@ static struct test_suite *generic_tests[] =3D { &suite__bpf, &suite__thread_map_synthesize, &suite__thread_map_remove, - &suite__cpu_map_synthesize, + &suite__cpu_map, &suite__synthesize_stat_config, &suite__synthesize_stat, &suite__synthesize_stat_round, &suite__event_update, &suite__event_times, &suite__backward_ring_buffer, - &suite__cpu_map_print, - &suite__cpu_map_merge, - &suite__cpu_map_intersect, &suite__sdt_event, &suite__is_printable_array, &suite__bitmap_print, diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 92232978fe5e..83805690c209 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -211,7 +211,15 @@ static int test__cpu_map_intersect(struct test_suite *= test __maybe_unused, return ret; } =20 -DEFINE_SUITE("Synthesize cpu map", cpu_map_synthesize); -DEFINE_SUITE("Print cpu map", cpu_map_print); -DEFINE_SUITE("Merge cpu map", cpu_map_merge); -DEFINE_SUITE("Intersect cpu map", cpu_map_intersect); +static struct test_case tests__cpu_map[] =3D { + TEST_CASE("Synthesize cpu map", cpu_map_synthesize), + TEST_CASE("Print cpu map", cpu_map_print), + TEST_CASE("Merge cpu map", cpu_map_merge), + TEST_CASE("Intersect cpu map", cpu_map_intersect), + { .name =3D NULL, } +}; + +struct test_suite suite__cpu_map =3D { + .desc =3D "CPU map", + .test_cases =3D tests__cpu_map, +}; diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index b4e54f08bc39..f424c0b7f43f 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -118,16 +118,13 @@ DECLARE_SUITE(bpf); DECLARE_SUITE(session_topology); DECLARE_SUITE(thread_map_synthesize); DECLARE_SUITE(thread_map_remove); -DECLARE_SUITE(cpu_map_synthesize); +DECLARE_SUITE(cpu_map); DECLARE_SUITE(synthesize_stat_config); DECLARE_SUITE(synthesize_stat); DECLARE_SUITE(synthesize_stat_round); DECLARE_SUITE(event_update); DECLARE_SUITE(event_times); DECLARE_SUITE(backward_ring_buffer); -DECLARE_SUITE(cpu_map_print); -DECLARE_SUITE(cpu_map_merge); -DECLARE_SUITE(cpu_map_intersect); DECLARE_SUITE(sdt_event); DECLARE_SUITE(is_printable_array); DECLARE_SUITE(bitmap_print); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:56 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 A26D9C77B7C for ; Wed, 24 May 2023 22:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjEXWTA (ORCPT ); Wed, 24 May 2023 18:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236596AbjEXWSn (ORCPT ); Wed, 24 May 2023 18:18:43 -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 A3A2013A for ; Wed, 24 May 2023 15:18:42 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8338f2103so2884419276.1 for ; Wed, 24 May 2023 15:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966722; x=1687558722; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xAoaFyBJOeyjHfZvGABM9yDThQmXliV0lqnBHOLa6q0=; b=zlbh0StDHb0NXfGfXg/X3LfsmeDzOHLH1YC1qEfX6cRN7wrLa7RBRNYltOVYHQZznF Qj6tcRduEffZVSuvM+NkKpIzs2/Yn/1/v2OXQHBbzm/KyggfjUhzB3z07p5R7onauVA4 BzzwVCRgEtBeKzsW7mXUpaSM5tYjehgTBXO+RvfETWvvcrWvHyiCk1xmfjFA4tG9OXVy vqnu09Hp/mrjZd+mt28IXuvqkdyd+8dV2AlzFpGd4QAToETp/lnxRQrJ3dkeh5sSJRG6 pOrHodyD/8xM3NQnw0fnY6Ff97Ye2bV9guPTrRxmve80oAhJLFbO/Iao7HNgd2Gi80I0 y4sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966722; x=1687558722; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xAoaFyBJOeyjHfZvGABM9yDThQmXliV0lqnBHOLa6q0=; b=Cyrq9SEkcKwWGd59EwpKCb8pbtyvy04cH/xuZlPRGJPXgkz/oG5mlfF20lVisv5Rwp mEwb06tzD2fDgQ4VgmEGs5EMdYsAmvJt2m6YMyl4lydhSUTcbOVKuwthfNnq6Lyvt9dP skN+wddPRam7sGHGB+1RHlBRpZUexWc/QkwIzk+lZgA3CNoMbLt8TmzwWzQwBE9WiLTe WyyQq5V+0EQx5evOyXoYqY3DJlBSuC2eB3nbBaj/w9ZxVawvoV4K+X5YubB5eCNhSQPY qYln0Oc+VvC15qW4IfdE3/02K+Xr/4K7cifKE641hFtAIRpwHDiJ8PZCF9pyZ56HUonr SnHA== X-Gm-Message-State: AC+VfDzFCT/iDWQ7iIZHFiPwGeiC0TO+UENuaI9WpiF3K1l5duhFFm8z 4xvkMnjy3kpZ6/D2GeGMot59zJhOYQ4A X-Google-Smtp-Source: ACHHUZ67iw6irCTpD7UvqWqkTdeLj7Zvgy/Do6A19KOegEO5oEs6WH6+/P6qeq5gp6xRG1thiKj91Wt3B8s7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:3256:0:b0:b8f:53e1:64b with SMTP id y83-20020a253256000000b00b8f53e1064bmr570703yby.13.1684966721885; Wed, 24 May 2023 15:18:41 -0700 (PDT) Date: Wed, 24 May 2023 15:17:59 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-4-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 03/35] perf cpumap: Add equal function From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Equality is a useful property to compare after merging and intersecting maps. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/cpumap.c | 21 ++++++++++++++++ tools/lib/perf/include/perf/cpumap.h | 2 ++ tools/perf/tests/cpumap.c | 37 ++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index d4f3a1a12522..48595a3ad69c 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -321,6 +321,27 @@ bool perf_cpu_map__has(const struct perf_cpu_map *cpus= , struct perf_cpu cpu) return perf_cpu_map__idx(cpus, cpu) !=3D -1; } =20 +bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, const struct perf= _cpu_map *rhs) +{ + int nr; + + if (lhs =3D=3D rhs) + return true; + + if (!lhs || !rhs) + return false; + + nr =3D perf_cpu_map__nr(lhs); + if (nr !=3D perf_cpu_map__nr(rhs)) + return false; + + for (int idx =3D 0; idx < nr; idx++) { + if (RC_CHK_ACCESS(lhs)->map[idx].cpu !=3D RC_CHK_ACCESS(rhs)->map[idx].c= pu) + return false; + } + return true; +} + struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) { struct perf_cpu result =3D { diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 0466c4216fbb..d0ae9552f8e2 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -28,6 +28,8 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_ma= p *cpus); LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *m= ap); LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct = perf_cpu cpu); +LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, + const struct perf_cpu_map *rhs); =20 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) =3D 0, (cpu) =3D perf_cpu_map__cpu(cpus, idx); \ diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 83805690c209..7730fc2ab40b 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -211,11 +211,48 @@ static int test__cpu_map_intersect(struct test_suite = *test __maybe_unused, return ret; } =20 +static int test__cpu_map_equal(struct test_suite *test __maybe_unused, int= subtest __maybe_unused) +{ + struct perf_cpu_map *any =3D perf_cpu_map__dummy_new(); + struct perf_cpu_map *one =3D perf_cpu_map__new("1"); + struct perf_cpu_map *two =3D perf_cpu_map__new("2"); + struct perf_cpu_map *empty =3D perf_cpu_map__intersect(one, two); + struct perf_cpu_map *pair =3D perf_cpu_map__new("1-2"); + struct perf_cpu_map *tmp; + struct perf_cpu_map *maps[] =3D {empty, any, one, two, pair}; + + for (size_t i =3D 0; i < ARRAY_SIZE(maps); i++) { + /* Maps equal themself. */ + TEST_ASSERT_VAL("equal", perf_cpu_map__equal(maps[i], maps[i])); + for (size_t j =3D 0; j < ARRAY_SIZE(maps); j++) { + /* Maps dont't equal each other. */ + if (i =3D=3D j) + continue; + TEST_ASSERT_VAL("not equal", !perf_cpu_map__equal(maps[i], maps[j])); + } + } + + /* Maps equal made maps. */ + tmp =3D perf_cpu_map__merge(perf_cpu_map__get(one), two); + TEST_ASSERT_VAL("pair", perf_cpu_map__equal(pair, tmp)); + perf_cpu_map__put(tmp); + + tmp =3D perf_cpu_map__intersect(pair, one); + TEST_ASSERT_VAL("one", perf_cpu_map__equal(one, tmp)); + perf_cpu_map__put(tmp); + + for (size_t i =3D 0; i < ARRAY_SIZE(maps); i++) + perf_cpu_map__put(maps[i]); + + return TEST_OK; +} + static struct test_case tests__cpu_map[] =3D { TEST_CASE("Synthesize cpu map", cpu_map_synthesize), TEST_CASE("Print cpu map", cpu_map_print), TEST_CASE("Merge cpu map", cpu_map_merge), TEST_CASE("Intersect cpu map", cpu_map_intersect), + TEST_CASE("Equal cpu map", cpu_map_equal), { .name =3D NULL, } }; =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 95B30C77B7C for ; Wed, 24 May 2023 22:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236848AbjEXWTG (ORCPT ); Wed, 24 May 2023 18:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236660AbjEXWSs (ORCPT ); Wed, 24 May 2023 18:18:48 -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 A7AA4194 for ; Wed, 24 May 2023 15:18:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-556011695d1so28678687b3.1 for ; Wed, 24 May 2023 15:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966724; x=1687558724; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=L9hyOxVMtag083U3DrBABQpzrKUd2k9oDsc9+XJnAEA=; b=LtpxsdvrVIHpyYlb3xLC8sqG58Bzm9j5cBtRTcbu3rsLbnqcZy2LpSxSNxzA50XG5w /AUONv2Gk38DiQ/sYYuLmGBrZ/dzL4pyU88PhOjIqusuhk7jVExQGDVPzetaywcYi+Un wlZ8DlLrDhrD5XMNTk6j7Y8NGCryNgqHWNZXjk3X79vkNmKHzrZ1avClFhIeEuor36PF wbHuvGb3DpL5LShCo/zH9iD455YuPM9wYpj4zAl6NMTsAZMedl+TUr0q6YbTi/3QCBUV 5Bb5M5U55AZMpwbXdhswy+/+aqWe3ropFnOYFQj4k/s1Y7okZgYYUlSi/pGomDTdRQJB Q/ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966724; x=1687558724; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L9hyOxVMtag083U3DrBABQpzrKUd2k9oDsc9+XJnAEA=; b=gVkDD7xVSWFCfZG4fkqyigu40WEgbnrm+nG5IWV8ZpWPa18vzN6zKrKqD9QrvsEfXW hXg8cH97I70cccwDvI+7pEhVk288RUuBksy2qFvKWRqPsudZwBmyXKqevxpVEmaCLpBv gBDVTgme9W80DH4sFUBz0HzX+6oxcrsoxOeoE+PBwp8tBuACciG8/aRHszkn+GMbzCtj L/Mv8XI3A9axdzBlt+CPVQawCjKpUgUFgFvnRzTk8I2snAlaVes4hP9+/Thy6GQ3y5b7 q7gx3wWh7DZ0H/F3s+kA1dIN/WhmVvbhllBbmAz+SIiOWltzwa8xN6YmY9FffS/Bcz9m RRSw== X-Gm-Message-State: AC+VfDzsZZzdXKdH7xSMvLnwYLCBO5YzzsqgjPGp8VpUZHEWxblB6inq d6z4GuIaYv7ecM1sBJfztl4g17eaGrU/ X-Google-Smtp-Source: ACHHUZ4A9xBsf2NqNhBKrjOga52LfeOavCka+IP0c2dGDJ+fOrU4kiCHN5RkZ7kCcC0QXT4WglaRezW0Dn7i X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ad57:0:b0:561:be13:2fd3 with SMTP id l23-20020a81ad57000000b00561be132fd3mr11098955ywk.1.1684966723958; Wed, 24 May 2023 15:18:43 -0700 (PDT) Date: Wed, 24 May 2023 15:18:00 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-5-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 04/35] libperf cpumap: Add "any CPU"/dummy test function From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is common in the code currently to test a map for "empty" when in fact the "any CPU"/dummy value of -1 is being sought. Add a new function to enable this and document the behavior of two other functions. The term "any CPU" comes from perf_event_open, where the value is consumed, but it is more typical in the code to see this value/map referred to as the dummy value. This could be misleading due to the dummy event and also dummy not being intention revealing, so it is hoped to migrate the code to referring to this as "any CPU". Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/cpumap.c | 5 +++++ tools/lib/perf/include/perf/cpumap.h | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 48595a3ad69c..7c8237a9e902 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -342,6 +342,11 @@ bool perf_cpu_map__equal(const struct perf_cpu_map *lh= s, const struct perf_cpu_m return true; } =20 +bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map) +{ + return map && perf_cpu_map__cpu(map, 0).cpu =3D=3D -1; +} + struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) { struct perf_cpu result =3D { diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index d0ae9552f8e2..3b7c965a17f2 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -13,6 +13,9 @@ struct perf_cpu { =20 struct perf_cpu_map; =20 +/** + * perf_cpu_map__dummy_new - a map with a singular "any CPU"/dummy -1 valu= e. + */ LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); @@ -25,11 +28,18 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__intersec= t(struct perf_cpu_map *or 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); +/** + * perf_cpu_map__empty - is map either empty or the "any CPU"/dummy value. + */ LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *m= ap); LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct = perf_cpu cpu); LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, const struct perf_cpu_map *rhs); +/** + * perf_cpu_map__any_cpu - Does the map contain the "any CPU"/dummy -1 val= ue? + */ +LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map); =20 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) =3D 0, (cpu) =3D perf_cpu_map__cpu(cpus, idx); \ --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 DF9C5C77B7C for ; Wed, 24 May 2023 22:19:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237188AbjEXWTJ (ORCPT ); Wed, 24 May 2023 18:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236734AbjEXWSt (ORCPT ); Wed, 24 May 2023 18:18:49 -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 668341A2 for ; Wed, 24 May 2023 15:18:47 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b238ee8so2876756276.0 for ; Wed, 24 May 2023 15:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966726; x=1687558726; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rFns1xCRwQs2VyvHbQeG+YbR09DfXce+1D3kwfuUbnc=; b=QBr9lERJqVOyRESMrYuu86b2CdwP8E37LjcND2+YwAsaaYAwrXeS6BLSwafdlxK582 1YgxVxE51wwGv+MrZUjxItnJYOoIch1+Hlf6+GWfUCygqxEYKJb0b6v2CmDirxj7b9Hd n8C/uLbNhq+0WIAbhLhQFfHXsXpmEbPkjb1vT8dIUiHCSRIDv4IPgal067zwTt2CVv2d s+gLhZ4BMoZRaUTH8XNILpUOZ32qsYcQ1OWhL/TY/AarkNrfQZd8TOCMXSJ4miuSHTEM amZTsMRWpEHsvCOU+gQ2sgWYxcJ3Mj9CQShfjDTOBP/+eisezlXKsDvNsi13BI79bD4Q dX3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966726; x=1687558726; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rFns1xCRwQs2VyvHbQeG+YbR09DfXce+1D3kwfuUbnc=; b=dILMcVe4vXCyFRXzK6IUmYcRu6/FAdyJEIXyefWvmPv/slW25pGFnm9/uZ/OpbTmHj f3h67admajG/3AxPj1dMqmC0+STFw69Jcmhh7HCHLTpOAOWdfTEo53ljTGE8JWprIkit 4DGkqMjVzpsx5mRfmjrEfI+Hh3nHB/r3OS1BW3ITiwGshFc+uQ1jooxfPLjevSXjWgTk WpTGj0aaW1KJ4wpWTIIjOsb6MFbP1j+nrHJxOp1V5l/mJyek6y0JOu/an3yb+HHvb0Rq GcyZfs/XLYKf81kFT2s3dWyXwGc6hLB3RRFR7IvVoXiSQoNlJFS1eEupq/nlB9zEbm+/ pFRg== X-Gm-Message-State: AC+VfDyJZ9us3XQOQznxoX396kehonHAbtyd/mnSVFeLCe/4Jltf1Q1m paZTWCHw19JMLW7bDMUdvFdLfQAgVPIy X-Google-Smtp-Source: ACHHUZ5LWVtjDgkHe3VGgp6svl3iqUT5s26of6Cnt+3BMjpCYvoth9HVqtVzYx+uGVMnna+JIgbHZhIaupNd X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:5285:0:b0:ba8:8d92:caea with SMTP id g127-20020a255285000000b00ba88d92caeamr579597ybb.1.1684966726491; Wed, 24 May 2023 15:18:46 -0700 (PDT) Date: Wed, 24 May 2023 15:18:01 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-6-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 05/35] perf pmu: Detect ARM and hybrid PMUs with sysfs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" is_arm_pmu_core detects a core PMU via the presence of a "cpus" file rather than a "cpumask" file. This pattern holds for hybrid PMUs so rename the function and remove redundant perf_pmu__is_hybrid tests. Add a new helper is_pmu_hybrid similar to is_pmu_core. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmu.c | 29 ++++++++++++++++++----------- tools/perf/util/pmu.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f4f0afbc391c..7392cec725bf 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -643,12 +643,14 @@ static char *pmu_id(const char *name) return str; } =20 -/* - * PMU CORE devices have different name other than cpu in sysfs on some - * platforms. - * Looking for possible sysfs files to identify the arm core device. +/** + * is_sysfs_pmu_core() - PMU CORE devices have different name other than c= pu in + * sysfs on some platforms like ARM or Intel hybrid. Looking for + * possible the cpus file in sysfs files to identify whether this = is a + * core device. + * @name: The PMU name such as "cpu_atom". */ -static int is_arm_pmu_core(const char *name) +static int is_sysfs_pmu_core(const char *name) { char path[PATH_MAX]; =20 @@ -814,7 +816,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, = struct perf_pmu *pmu, struct pmu_add_cpu_aliases_map_data data =3D { .head =3D head, .name =3D pmu->name, - .cpu_name =3D is_arm_pmu_core(pmu->name) ? pmu->name : "cpu", + .cpu_name =3D is_sysfs_pmu_core(pmu->name) ? pmu->name : "cpu", .pmu =3D pmu, }; =20 @@ -1647,22 +1649,27 @@ static int cmp_sevent(const void *a, const void *b) =20 bool is_pmu_core(const char *name) { - return !strcmp(name, "cpu") || is_arm_pmu_core(name); + return !strcmp(name, "cpu") || is_sysfs_pmu_core(name); +} + +bool is_pmu_hybrid(const char *name) +{ + return !strcmp(name, "cpu_atom") || !strcmp(name, "cpu_core"); } =20 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + return is_pmu_core(pmu->name); } =20 bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + return is_pmu_core(pmu->name); } =20 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { - return !perf_pmu__is_hybrid(pmu->name); + return !is_pmu_hybrid(pmu->name); } =20 static bool pmu_alias_is_duplicate(struct sevent *alias_a, @@ -1716,7 +1723,7 @@ void print_pmu_events(const struct print_callbacks *p= rint_cb, void *print_state) pmu =3D NULL; j =3D 0; while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); + bool is_cpu =3D is_pmu_core(pmu->name); =20 list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event =3D event; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 0e0cb6283594..f50919f1b34c 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -220,6 +220,7 @@ void perf_pmu__del_formats(struct list_head *formats); struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); =20 bool is_pmu_core(const char *name); +bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 4513EC77B7A for ; Wed, 24 May 2023 22:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237422AbjEXWTT (ORCPT ); Wed, 24 May 2023 18:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236692AbjEXWS6 (ORCPT ); Wed, 24 May 2023 18:18:58 -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 985301B1 for ; Wed, 24 May 2023 15:18:49 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8c3186735so2677288276.3 for ; Wed, 24 May 2023 15:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966728; x=1687558728; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=f6ARFnsShab3VUnC8Sy2LkNPFWjyLZdSNydBFV23IFk=; b=WkyS6Afb90FUud0LxsdKmCb0VbkRe9m484H8ADjpO6UNGvuAHVAye0aaglkXIEFVci ckvJxndJzT5yWtkwTLmT1ZRih/WAMKK8iVbl6mGg+Fg9UcBPc2ps+iXFU3RMUCfxMwlA zuKUkJErOORn83lxGeoRqOTkPYzw3QjsrSGo3KVE892ZYbtlt/k4h1936SSVfQxQ+ORC 15y3qDa9T2WnhVp1VIhnOdJ2oNHOIo5ntJhJREFMQ6gHS21QkbzfSlJaKOaHkxxrOVOk 9qW2OOKj3CgzG8OzkC5OhAuj1pMCs6fMC/TQmQX9Kzi2NeoFk9+P3bRLLaKtJBX/3dd6 HbOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966728; x=1687558728; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f6ARFnsShab3VUnC8Sy2LkNPFWjyLZdSNydBFV23IFk=; b=Y3bkP3kh6vUaPPwTq6Y4lxOg/3i1o+IHQhYLtoqPmPvQqY1x+Tl1niX5hcpEIK4wXl q5uAPg0Vgj1MBVaRlmcF8ARAHpvSIXc5Yr2bdcCQzIoelc/iN51aKzYh7YpQQSEtWNQQ RwfVz+HcxFu1vrB8zK5/C+nuVjQsWWoG9fLMXdZZ3Pai6DeK3VaGb0xvuyA3acNt52VL pgsgVO49OTFEvRf/l6/NFwE/XrK7vpVMrb2FXPE3xGya0LR+rb+eDvz78PQHwmJ9//Fg Hc7zDFhWz1RVVqn0v0u2ufOn28YHus8F6NZmwJ9qLiR7PH92eMyEbAlFK8J0CHgO03RM Ap3Q== X-Gm-Message-State: AC+VfDwHUiCKrezekJHGTdXxRFkK4JhCHjoRgifLuXcps4rO0Ksp80W9 j8LWeQW0Z3aBV7SoP3vmBlD9U6Pr2eol X-Google-Smtp-Source: ACHHUZ7XBYnZO2uhMGuSnsWVJiC7PL6RhVQiB0SP4HBy2wQ3gSfqdJASvFAp3xt8/SSnxEeIybbl30w+RhCp X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a5b:652:0:b0:ba8:8fad:c19d with SMTP id o18-20020a5b0652000000b00ba88fadc19dmr556589ybq.8.1684966728557; Wed, 24 May 2023 15:18:48 -0700 (PDT) Date: Wed, 24 May 2023 15:18:02 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-7-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 06/35] perf pmu: Add is_core to pmu From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cache is_pmu_core in the pmu to avoid recomputation. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmu.c | 7 ++++--- tools/perf/util/pmu.h | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 7392cec725bf..e8c0762c311a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -952,6 +952,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) } =20 pmu->type =3D type; + pmu->is_core =3D is_pmu_core(name); pmu->is_uncore =3D pmu_is_uncore(dirfd, name); if (pmu->is_uncore) pmu->id =3D pmu_id(name); @@ -1659,12 +1660,12 @@ bool is_pmu_hybrid(const char *name) =20 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } =20 bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) { - return is_pmu_core(pmu->name); + return pmu->is_core; } =20 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) @@ -1723,7 +1724,7 @@ void print_pmu_events(const struct print_callbacks *p= rint_cb, void *print_state) pmu =3D NULL; j =3D 0; while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D is_pmu_core(pmu->name); + bool is_cpu =3D pmu->is_core; =20 list_for_each_entry(event, &pmu->aliases, list) { aliases[j].event =3D event; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index f50919f1b34c..96236a79c6fd 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -59,6 +59,13 @@ struct perf_pmu { * @selectable: Can the PMU name be selected as if it were an event? */ bool selectable; + /** + * @is_core: Is the PMU the core CPU PMU? Determined by the name being + * "cpu" or by the presence of + * /bus/event_source/devices//cpus. There may be >1 core + * PMU on systems like Intel hybrid. + */ + bool is_core; /** * @is_uncore: Is the PMU not within the CPU core? Determined by the * presence of /bus/event_source/devices//cpumask. --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 B2DCDC7EE2C for ; Wed, 24 May 2023 22:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237479AbjEXWTX (ORCPT ); Wed, 24 May 2023 18:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236995AbjEXWS6 (ORCPT ); Wed, 24 May 2023 18:18:58 -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 822F9186 for ; Wed, 24 May 2023 15:18:51 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8cf175f5bso853454276.0 for ; Wed, 24 May 2023 15:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966731; x=1687558731; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=c2Fu8Hh2fRZjS6aZytO0Djl8Sie1Qlvn6RQorz5XdqQ=; b=Ev8OlsiXMdtu6FlOgdizkae87AqhWPM7LWi4Pz2YIJ9tsGVdgoW7Efn6yopiotMOXY /RzHMjyEcpMqh8gdAZoPRjXZ6DK/qlv1VuVe7isIGvvOybJCxWYpVXWkuT0FBTT52PEb x/nSvvHn9yhkumGCzrbVeGiuUQkTEcPjobeCv3i94Do/b5elK/+xAjXTZZNXH21uCVcU ginf8tZxLhE6DEWNa218qJT2oxUW+8GRyaMXpm0049KDScJYYQ577V76F5+IfOB80Bxh FTYnYBNxSKwNI+gj8ZnDRrLXuYoxoPnWrBLCVt13zTbkZIJWqRNV5S7FN8BKH5WFOlRR xnKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966731; x=1687558731; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=c2Fu8Hh2fRZjS6aZytO0Djl8Sie1Qlvn6RQorz5XdqQ=; b=YMVAePH95TjP+vNoTSmPKYqEovcREufZSu4ed0Nks0dlGdYnS3ENt8mrWfg36rK5T8 X3CFhjsh6GBScdRF/pCMXhT5NB88b/cNUlZCUBbMrULjzoPKLntlIGEO5qNBQ7uItmPM wZM6TjgwKfqFLoLCQrYyq3g53iV5plJejNoOd1EFop0TA3e9+YoCMFbhRDdQY1SXC1Du WN/iNYp8G81+hS6wJMKvfuzFAYKuTd/x7De2GOnUxOFpG/yBrdKRee4U4Cd3gFI9nUR8 +9xU9EuIPd6aZy5q3SgWcXHjEaZpcsG3evQEP92J5ETzwvK7Yg1Q/KtJa6Bpd7lIV92z 6x5A== X-Gm-Message-State: AC+VfDzMhIHNlIVz6N9Ei+aZEWDZNF3i4ekjypoTZP7nD9b1sAtGDlZG RcTh6TgGJ0sSZ3LQZQy9576SSrAuPetF X-Google-Smtp-Source: ACHHUZ7+88/7aU7x/bNjqJ77lAS3J/2553bHTBYqqnN3uD2LBkSyMbYgzljU/D8Sr5q/j4OyZ/8PyKJam29X X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:6612:0:b0:b94:6989:7fa6 with SMTP id a18-20020a256612000000b00b9469897fa6mr569267ybc.4.1684966731195; Wed, 24 May 2023 15:18:51 -0700 (PDT) Date: Wed, 24 May 2023 15:18:03 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-8-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 07/35] perf evsel: Add is_pmu_core inorder to interpret own_cpus From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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 behaviour of handling cpu maps varies for core and other PMUs. For core PMUs the cpu map lists all valid CPUs, whereas for other PMUs the map is the default CPU. Add a flag in the evsel to indicate if a PMU is core to help with later interpreting of the cpu maps and populate it when the evsel is created during parsing. When propagating cpu maps, core PMUs should intersect the cpu map of the PMU with the user requested one. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/include/internal/evsel.h | 9 +++++++++ tools/perf/util/evsel.c | 1 + tools/perf/util/parse-events.c | 1 + 3 files changed, 11 insertions(+) diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index a99a75d9e78f..4d6f2a032f45 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -41,7 +41,14 @@ struct perf_sample_id { struct perf_evsel { struct list_head node; struct perf_event_attr attr; + /** The commonly used cpu map of CPUs the event should be opened upon, et= c. */ struct perf_cpu_map *cpus; + /** + * The cpu map read from the PMU. For core PMUs this is the list of all + * CPUs the event can be opened upon. For other PMUs this is the default + * cpu map for opening the event on, for example, the first CPU on a + * socket for an uncore event. + */ struct perf_cpu_map *own_cpus; struct perf_thread_map *threads; struct xyarray *fd; @@ -65,6 +72,8 @@ struct perf_evsel { * i.e. it cannot be the 'any CPU' value of -1. */ bool requires_cpu; + /** Is the PMU for the event a core one? Effects the handling of own_cpus= . */ + bool is_pmu_core; int idx; }; =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2f5910b31fa9..8c8f371ea2b5 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -415,6 +415,7 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->core.nr_members =3D orig->core.nr_members; evsel->core.system_wide =3D orig->core.system_wide; evsel->core.requires_cpu =3D orig->core.requires_cpu; + evsel->core.is_pmu_core =3D orig->core.is_pmu_core; =20 if (orig->name) { evsel->name =3D strdup(orig->name); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b93264f8a37c..1a0be395c887 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -260,6 +260,7 @@ __add_event(struct list_head *list, int *idx, evsel->core.cpus =3D cpus; evsel->core.own_cpus =3D perf_cpu_map__get(cpus); evsel->core.requires_cpu =3D pmu ? pmu->is_uncore : false; + evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; evsel->pmu_name =3D pmu && pmu->name ? strdup(pmu->name) : NULL; --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 3A54AC77B7A for ; Wed, 24 May 2023 22:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237539AbjEXWT2 (ORCPT ); Wed, 24 May 2023 18:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236837AbjEXWTB (ORCPT ); Wed, 24 May 2023 18:19:01 -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 03921E46 for ; Wed, 24 May 2023 15:18:54 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba83fed51b0so1861216276.3 for ; Wed, 24 May 2023 15:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966733; x=1687558733; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=SukIuxaoO84Z2N5/tbMdB22CiO94rsJEEkavNjO0alo=; b=xXvaZIob15m9BhOyeJ9ui08mh6OJC4bT99hRIPeTVXfrpP9xnsmelHY2dmsb/wpag7 iAP7Mr9NjMYUHMX+QBUES3Zs0sZbYQd7aQtdyvx2FgPosw0ylDPSM1dpP4c9t4eVhKIU r4LC7cq0a/H1w4jinqvYIGdxX2oV6/A1eWQqLpQTNvfCXMjWfC5qMGjSj0tKOGcCqN6j 8Y10IA0Tz3UjGDnkT/QDm6jWgiRugZekRKdmFofLPZW4RLGxVF6C/w/x7a6YmYRgrYdm wLZAtQjICcSnF7CMAHqYiwYUb71Yk66ERw/eV92ByLIrwFu8mQzvIILwukoVPnjhhHrQ 5T8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966733; x=1687558733; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SukIuxaoO84Z2N5/tbMdB22CiO94rsJEEkavNjO0alo=; b=MU3vuPjW1GdA/bL7cYQLSQtf+19gFEIDh0MSQys8IQSG3v09kKgtLWJkGf0FPMUrXa C4UF8mUm8moaHGovaMsQvZdcNgZd3g5LyHUkplNmMBX3BmTOaIh5md6VRy88TWYmflIT EgYeRK3d9l3Y3qeRqyEIl+tTaEAY6gTkbSYnwotRsSQnDIQ5izSpZ0WIUDzEoc3CGWIz SV/LxZCv2yMjGtc8z8haSSSJYZL04jKKxRQeElqFfdpC2cAiyx159L2yYn/4slhpYtBW aPZ53gyysv2VU6CEjPE7lTyIanKfW9aB8tVNz6af06SYXI8KSn8Z+0QwR5a7zSHOsG5N 3LOg== X-Gm-Message-State: AC+VfDx34luCUAPXOMke8efKaMtGFn750Fubf602BYxsnyyE+IkmJnh+ avktNoHESkYCMA/iqm4g2Bzkr3yqxbUD X-Google-Smtp-Source: ACHHUZ6kUC+/b7eqs9c4jxHPTriyXHDKWHvZph0q2o9wc+IPQrpvP9irpFnHBysM//pLtj5KTw1TYrleX6Ji X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:6b06:0:b0:ba8:97f8:620f with SMTP id g6-20020a256b06000000b00ba897f8620fmr756124ybc.8.1684966733649; Wed, 24 May 2023 15:18:53 -0700 (PDT) Date: Wed, 24 May 2023 15:18:04 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-9-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 08/35] perf pmu: Add CPU map for "cpu" PMUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A typical "cpu" PMU has no "cpus" or "cpumask" file meaning the CPU map is set to NULL, which also encodes an empty CPU map. Update pmu_cpumask so that if the "cpu" PMU fails to load a CPU map, use a default of all online PMUs. Remove const from cpu_map__online for the sake of reference counting. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/cpumap.c | 4 ++-- tools/perf/util/cpumap.h | 4 ++-- tools/perf/util/pmu.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 75d9c73e0184..75c5bed37805 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -663,9 +663,9 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, = char *buf, size_t size) return ptr - buf; } =20 -const struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ +struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ { - static const struct perf_cpu_map *online =3D NULL; + static struct perf_cpu_map *online; =20 if (!online) online =3D perf_cpu_map__new(NULL); /* from /sys/devices/system/cpu/onli= ne */ diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index e3426541e0aa..05201b31810c 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -48,7 +48,7 @@ struct perf_cpu_map *cpu_map__new_data(const struct perf_= record_cpu_map_data *da size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t s= ize); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); -const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ +struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ =20 int cpu__setup_cpunode_map(void); =20 @@ -59,7 +59,7 @@ struct perf_cpu cpu__max_present_cpu(void); /** * cpu_map__is_dummy - Events associated with a pid, rather than a CPU, us= e a single dummy map with an entry of -1. */ -static inline bool cpu_map__is_dummy(struct perf_cpu_map *cpus) +static inline bool cpu_map__is_dummy(const struct perf_cpu_map *cpus) { return perf_cpu_map__nr(cpus) =3D=3D 1 && perf_cpu_map__cpu(cpus, 0).cpu = =3D=3D -1; } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e8c0762c311a..d992f5242d99 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -610,7 +610,7 @@ static struct perf_cpu_map *pmu_cpumask(int dirfd, cons= t char *name) return cpus; } =20 - return NULL; + return !strcmp(name, "cpu") ? perf_cpu_map__get(cpu_map__online()) : NULL; } =20 static bool pmu_is_uncore(int dirfd, const char *name) --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 40C90C77B7A for ; Wed, 24 May 2023 22:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229826AbjEXWTf (ORCPT ); Wed, 24 May 2023 18:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237204AbjEXWTJ (ORCPT ); Wed, 24 May 2023 18:19:09 -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 6ED9EE53 for ; Wed, 24 May 2023 15:18:56 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56561689700so28562357b3.2 for ; Wed, 24 May 2023 15:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966735; x=1687558735; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Cy7gJw+E0ntMAmmRtEPYe8LOCyWrq0W20Q546Olgu7k=; b=mczbeLVP6vX9XhKEziiSA4SHBbGgx2XKtK4C8T3nL2qBfrmK8L0ktZhE+3H+9hl3wO vZBzFZdDzO387cRVpPmDkguqDFclulv6SykRF7vHY81JkGOb3sxhp1Jr7cAI2qNBeIco MKYHE6p0rfCgmH5GZ3JTHfaMHatUYVk/wSF4UxFUjqLXJFh3oBytoVa0EENGQJ4fuVF1 kM2BtrC35B9cQwKcRzeuKSH00qpZ7cthUKCBntTvCVwwX5aKebznc7SOtjQBl1NnYD7y A7P1KhlD3aEUqrQ2DS2ennyo05n4LJide3clV07VmLmnno5PPoUIi9vPNlmkIouyd6js R77w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966735; x=1687558735; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Cy7gJw+E0ntMAmmRtEPYe8LOCyWrq0W20Q546Olgu7k=; b=H0cqxx/13NjEKpkmzcM8KiB+ehIG8+bRALe3FfyGwydo5wG8KWwZTIu1jSnX7WEHNr k4QBwJeyp3AXBZihzUVkLOhxxxF3N+DjGWD4LAytCJsxzJZdymU3kWGRFwWtxuQ7Tto5 Ef7xNKG5NW5/CNCX3TCvybpud8XkhWYX2xz8h1cGNfNwLaQXFIFuGSFHS1wvqPTOSY6K aKfxaPpWMGJhvEXhTXSrElqt4yPblj2w03mrKd4R1SVqWevE9JZW1XXswk/mk2ZGnP56 /aDW8UbjhIA2C4EHwu3PRucXraCjslIGcGklkH5GdmhU/KqoXMAjnvo8LgyyKoPvu1kT 5Ixw== X-Gm-Message-State: AC+VfDy05nwTxkMSKzpswMpreOmJOUOFxGY1/ajMgmuRXInoJKJYSKHl zmMom4Ncpy3VV5bi9WVQbI/gVN+0r8na X-Google-Smtp-Source: ACHHUZ4+pI9OmzMNkQ1yM/rYnP9CZDetV7ZHH1aIpmqtDz+7oLUAKsSkrbsqtJtcIdRYOtffR7G25A/eVQXh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:b717:0:b0:560:d237:43dc with SMTP id v23-20020a81b717000000b00560d23743dcmr11977209ywh.3.1684966735605; Wed, 24 May 2023 15:18:55 -0700 (PDT) Date: Wed, 24 May 2023 15:18:05 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-10-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 09/35] perf evlist: Propagate user CPU maps intersecting core PMU maps From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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 CPU map for a non-core PMU gives a default CPU value for perf_event_open. For core PMUs the CPU map lists all CPUs the evsel may be opened on. If there are >1 core PMU, the CPU maps will list the CPUs for that core PMU, but the user_requested_cpus may contain CPUs that are invalid for the PMU and cause perf_event_open to fail. To avoid this, when propagating the CPU map for core PMUs intersect it with the CPU map of the PMU (the evsel's "own_cpus"). Add comments to __perf_evlist__propagate_maps to explain its somewhat complex behavior. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/evlist.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 81e8b5fcd8ba..b8b066d0dc5e 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -36,18 +36,33 @@ void perf_evlist__init(struct perf_evlist *evlist) static void __perf_evlist__propagate_maps(struct perf_evlist *evlist, struct perf_evsel *evsel) { - /* - * We already have cpus for evsel (via PMU sysfs) so - * keep it, if there's no target cpu list defined. - */ if (evsel->system_wide) { + /* System wide: set the cpu map of the evsel to all online CPUs. */ perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__new(NULL); + } else if (evlist->has_user_cpus && evsel->is_pmu_core) { + /* + * User requested CPUs on a core PMU, ensure the requested CPUs + * are valid by intersecting with those of the PMU. + */ + perf_cpu_map__put(evsel->cpus); + evsel->cpus =3D perf_cpu_map__intersect(evlist->user_requested_cpus, evs= el->own_cpus); } else if (!evsel->own_cpus || evlist->has_user_cpus || - (!evsel->requires_cpu && perf_cpu_map__empty(evlist->user_requested_c= pus))) { + (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requeste= d_cpus))) { + /* + * The PMU didn't specify a default cpu map, this isn't a core + * event and the user requested CPUs or the evlist user + * requested CPUs have the "any CPU" (aka dummy) CPU value. In + * which case use the user requested CPUs rather than the PMU + * ones. + */ perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__get(evlist->user_requested_cpus); } else if (evsel->cpus !=3D evsel->own_cpus) { + /* + * No user requested cpu map but the PMU cpu map doesn't match + * the evsel's. Reset it back to the PMU cpu map. + */ perf_cpu_map__put(evsel->cpus); evsel->cpus =3D perf_cpu_map__get(evsel->own_cpus); } --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 2597CC77B7C for ; Wed, 24 May 2023 22:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237303AbjEXWTj (ORCPT ); Wed, 24 May 2023 18:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236674AbjEXWTR (ORCPT ); Wed, 24 May 2023 18:19:17 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F18AB1A2 for ; Wed, 24 May 2023 15:18:58 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5657dbf8cecso12750777b3.3 for ; Wed, 24 May 2023 15:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966738; x=1687558738; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1GDqhuhALscXPKh6eW/Ok5E7hxu+Cdr1krhYltfFoAk=; b=SNqtFPGQVnr4w8egpCSubSaXhVTLKjLdVF/wFOSP5H++vlIJPYJLnjJa+r5b/zXpdj sf86HjTJZfzi8pfsa9/f6DQvL2Z5FwyfBykVVjj/ZHiYiiXCPTt0tO+7swzm2O5E0RNl 6/zf9HDiY1pm0LGnLTrEZzJPX4Rd76VXns+uHlNI+lvhyOzahLwiqLEfh1aTqkEWjhaK CIGKxQVPZKq7wkVr7w7w4K28rVnMOSjTDFFQi7yUE5UXpjgB5v5G2VrwtQVzBXpdgaHf gDy0Rnq/caZLJZuHgB6qF/VM+Spj9vnVcbEcsH0vYdwkESqr8D7m4HlzTBQUv9KJaNDo 6qoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966738; x=1687558738; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1GDqhuhALscXPKh6eW/Ok5E7hxu+Cdr1krhYltfFoAk=; b=Iz8vVvMD5M2OELOSKWI86W3nwtmQFFQBlCE6cuy+MJ7wJ+FbRU2MeO8bn0FPvfcIAg rL36D6EjTMjTjppI5MkPBDyKuDKczzL83Odwa8+gYd467h9M7SID6OfWgzMRu0DXsnXb kQJP95Sb55VpMQsLVsr/ZcvfN74rp4AWbb1NUTStZB2xygYoMU/C5slWPSZbmVqWbl9y Q2OOMK9wj7IOGPXIbHkKT2qmhcWgWS9XnS1uCZ7pPL2cFNsfnpdSuW43L5/i5nss9TyT jALPw1NArPg/bxveSZGGV9kATLBLPUb12c1cJZuInjbkV4L+vOnY0c/Ozhin6U475Qb2 tZHQ== X-Gm-Message-State: AC+VfDwVXQPR2ed7IOcrngT5xWVj9LzCPdXe1G623aYUbX5+O1my+O6w fgbPLLTiklp97Zo3ksiud6qb3z9ntXMx X-Google-Smtp-Source: ACHHUZ62cL31QtcLPt6L7GAvXC3BNk7BWMiqw6dzsT68FbgIH7rTRzHWyAjtzVAe9UpHLGfWmGYM7NAUHAtz X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ac0e:0:b0:561:a7d5:ec0d with SMTP id k14-20020a81ac0e000000b00561a7d5ec0dmr11443469ywh.0.1684966737912; Wed, 24 May 2023 15:18:57 -0700 (PDT) Date: Wed, 24 May 2023 15:18:06 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-11-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 10/35] perf evlist: Allow has_user_cpus to be set on hybrid From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that CPU map propagation only sets valid CPUs for core PMUs, there is no reason to disable "has_user_cpus" for hybrid. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/evlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a0504316b06f..2e2c3509bec3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1067,7 +1067,7 @@ int evlist__create_maps(struct evlist *evlist, struct= target *target) if (!cpus) goto out_delete_threads; =20 - evlist->core.has_user_cpus =3D !!target->cpu_list && !target->hybrid; + evlist->core.has_user_cpus =3D !!target->cpu_list; =20 perf_evlist__set_maps(&evlist->core, cpus, threads); =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 6A36AC7EE2E for ; Wed, 24 May 2023 22:19:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237580AbjEXWT5 (ORCPT ); Wed, 24 May 2023 18:19:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236151AbjEXWTV (ORCPT ); Wed, 24 May 2023 18:19:21 -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 AEBD610C0 for ; Wed, 24 May 2023 15:19:09 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-560ee0df572so29563177b3.0 for ; Wed, 24 May 2023 15:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966740; x=1687558740; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=02rUQOyiNwiIsyzOJl6kmDGqZDjZZQRLfOwGjV/VqPE=; b=6nKoJ2ZO2zIHMG8Vdhftw3G8IlB6fVDXK39qsnSEPChSilm0wJ/DBoEf/QAb9CKCtT sfl6tJ20fNMBLh97PdjBYAb4xwqrGbsF0B0qpOXvzMqb/SbfEy09hJ36UhQFCY2+3EkZ Ecs+YMXsSgSVwlenuoOLTusuDp6eMpj4MthxKqw7ozC/oX/4yiAau6Ja80T5wm+YIZph wg2k7TOddlTZGJ5APBshhaqD7+LEbnxMoJV6jtZYQq0CsMy27uPahpzu5IDpGWSkBCKC hX5nos7aAoj3UzTj18VQxbOd1qzYBmweEpaWI1d5IvW0Fz2DhWgg+2qTJc+zCcK6Z6cc uBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966740; x=1687558740; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=02rUQOyiNwiIsyzOJl6kmDGqZDjZZQRLfOwGjV/VqPE=; b=ew5sau7aZ26skqVhcOYe1Q0kqiv2P6MtKiWUeFAH/9nVwZ2JSbwLtJvn2/glaSJO6D Rya5SMzrvO5+KClWwgANCh3xeQ6K/I5zlrR6alnNEpNiWdq/eUDgfSxh130tmorANQzC aWpbOpQdvHsDzxUqYgW8Wk8dp+rEacLcCzA48Z8KLBimXh0NCOKEggFBx8w2O5OYwiPj kVtm9gZaB4QX+ZYMtDf8yYzO/EuHR+2tf2w124kGD/OKpulBLVW7ic8pDltJkklOdpr5 4RJBYD5VvlG9xtoSbq/OmogXjpAZ+R8xqvMCO0AEU8k+zCh7C5Mcrl3ttdU84CzH5n/j 9qhA== X-Gm-Message-State: AC+VfDz9Qze7UQlOchHMXg2faKwpP/sv6l1YUzfra/jmOGmC6p6iWtnS BY+uKlFv4Q16/Ka8EFhm0hna8eWEpxcE X-Google-Smtp-Source: ACHHUZ4T7vcSgycY4rtVGxUs6e/PZeDHYPYD8NwHQcrQfDN3dFzRusqoyw6Y03vhVSWmL2KloRvoUXcR1GS5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ad4d:0:b0:552:d924:a304 with SMTP id l13-20020a81ad4d000000b00552d924a304mr11478114ywk.4.1684966740240; Wed, 24 May 2023 15:19:00 -0700 (PDT) Date: Wed, 24 May 2023 15:18:07 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-12-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 11/35] perf target: Remove unused hybrid value From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously this was used to modify CPU map propagation, but it is now unnecessary as map propagation ensure core PMUs only have valid PMUs in the CPU map from user requested CPUs. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-record.c | 2 -- tools/perf/builtin-stat.c | 1 - tools/perf/util/target.h | 1 - 3 files changed, 4 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ec0f2d5f189f..d152ab04a209 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4204,8 +4204,6 @@ int cmd_record(int argc, const char **argv) goto out; } =20 - rec->opts.target.hybrid =3D perf_pmu__has_hybrid(); - if (callchain_param.enabled && callchain_param.record_mode =3D=3D CALLCHA= IN_FP) arch__add_leaf_frame_record_opts(&rec->opts); =20 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bc45cee3f77c..c70cb0990661 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2467,7 +2467,6 @@ int cmd_stat(int argc, const char **argv) goto out; } =20 - target.hybrid =3D perf_pmu__has_hybrid(); if (evlist__create_maps(evsel_list, &target) < 0) { if (target__has_task(&target)) { pr_err("Problems finding threads of monitor\n"); diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 880f1af7f6ad..d582cae8e105 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -17,7 +17,6 @@ struct target { bool default_per_cpu; bool per_thread; bool use_bpf; - bool hybrid; int initial_delay; const char *attr_map; }; --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 6F486C77B7C for ; Wed, 24 May 2023 22:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237665AbjEXWUH (ORCPT ); Wed, 24 May 2023 18:20:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237592AbjEXWTa (ORCPT ); Wed, 24 May 2023 18:19:30 -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 8946810D2 for ; Wed, 24 May 2023 15:19:15 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-babb79a17b8so2054212276.0 for ; Wed, 24 May 2023 15:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966742; x=1687558742; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wlI6oimZU02XfkfcVbSHs4R5neH26SuCZgaFNSdpQYk=; b=DKXkRqv1ZpFDBXPBbHvAsR5GLgDQ1Q4zIP7i5X3T8m8nggvzvpIaJyoGZ2WZ//Ab7x 6wL05ioSwA8Yuhoq9Ck+gDaCuRoiLEg7AOksOsjSziglNLfjYO8mljHjfxsjlHLwOlkd QBrl4T4wKeKTjsQLEYJVkjLO1HPG9xK3lTEO6zHTzaK1g8fuuReOaTy7Qkv/dW4xDgCs XHnj9UcZI6SwsmSOKOwewR9sTPIQVLZgTSzdF3KWTINSt7MWYWRisJg5iV30zlzZQnLz H2s6rw/ZFgzTlKS9ON7iXPAHxcPQDXjXm/8RBYj0ebUr2LdAwOk+LU9gtDyODj3vMO34 tqzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966742; x=1687558742; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wlI6oimZU02XfkfcVbSHs4R5neH26SuCZgaFNSdpQYk=; b=WXdH7fKQZzg7GRt2jUz41xcMgANk2otOkYkV9BbdXpkcWpXC1VCpnWarBmEkjHd0wS y2ZO8ntSZWWw4B5wDgWlFaQBuYeWgFv2g3qEV3qHrn9F4E7DN4+HgGgEhoeUf9rlWi9Z KQQSs9TWPTdHERCZ2pKeWyBoTnJfisFpcXTdxJIJ1AWk8tuI7cybcsD7Bi9/69WuDd+B Zr/+QkZo/8VbwUMY29bNfFS0irQOU0Ag7zS9WeXrc7KnYvWs0BldP8ptSyU95sVR7PUw CYPdqSeVYNRofySjTd1OYT0TVe6k62W2g7QYqDvLIaNaz8uD/fdxbsi+isum47Inx6yw PH+w== X-Gm-Message-State: AC+VfDxf4mw0T+WZuykmCCyfYMCFtsoLrY/CgzZ8Mydetzua4ONfAZst jIYmzgk5XXvaHDmQPcTGM/RP45oxgBd3 X-Google-Smtp-Source: ACHHUZ7CFO4HRgNI2Rgb125/Y1HoOSJlFJc2haWEQzZ8q55MKD1ASrhcsNacYnOX66MFC30xQhhTH+HfuZ6D X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a05:6902:4ca:b0:ba1:6f1b:8905 with SMTP id v10-20020a05690204ca00b00ba16f1b8905mr782762ybs.4.1684966742565; Wed, 24 May 2023 15:19:02 -0700 (PDT) Date: Wed, 24 May 2023 15:18:08 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-13-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 12/35] perf tools: Warn if no user requested CPUs match PMU's CPUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In commit 1d3351e631fc ("perf tools: Enable on a list of CPUs for hybrid") perf on hybrid will warn if a user requested CPU doesn't match the PMU of the given event but only for hybrid PMUs. Make the logic generic for all PMUs and remove the hybrid logic. Warn if a CPU is requested that isn't present/offline for events not on the core. Warn if a CPU is requested for a core PMU, but the CPU isn't within the cpu map of that PMU. For example on a 16 (0-15) CPU system: ``` $ perf stat -e imc_free_running/data_read/,cycles -C 16 true WARNING: A requested CPU in '16' is not supported by PMU 'uncore_imc_free_r= unning_1' (CPUs 0-15) for event 'imc_free_running/data_read/' WARNING: A requested CPU in '16' is not supported by PMU 'uncore_imc_free_r= unning_0' (CPUs 0-15) for event 'imc_free_running/data_read/' WARNING: A requested CPU in '16' is not supported by PMU 'cpu' (CPUs 0-15) = for event 'cycles' Performance counter stats for 'CPU(s) 16': MiB imc_free_running/data_read/ cycles 0.000575312 seconds time elapsed ``` Remove evlist__fix_hybrid_cpus that previously produced the warnings and also perf_pmu__cpus_match that worked with evlist__fix_hybrid_cpus to change CPU maps for hybrid CPUs, something that is no longer necessary as CPU map propagation properly intersects user requested CPUs with the core PMU's CPU map. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-record.c | 6 +-- tools/perf/builtin-stat.c | 5 +-- tools/perf/util/evlist-hybrid.c | 74 --------------------------------- tools/perf/util/evlist-hybrid.h | 1 - tools/perf/util/evlist.c | 39 +++++++++++++++++ tools/perf/util/evlist.h | 2 + tools/perf/util/pmu.c | 33 --------------- tools/perf/util/pmu.h | 4 -- 8 files changed, 43 insertions(+), 121 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d152ab04a209..88f7b4241153 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4198,11 +4198,7 @@ int cmd_record(int argc, const char **argv) /* Enable ignoring missing threads when -u/-p option is defined. */ rec->opts.ignore_missing_thread =3D rec->opts.target.uid !=3D UINT_MAX ||= rec->opts.target.pid; =20 - if (evlist__fix_hybrid_cpus(rec->evlist, rec->opts.target.cpu_list)) { - pr_err("failed to use cpu list %s\n", - rec->opts.target.cpu_list); - goto out; - } + evlist__warn_user_requested_cpus(rec->evlist, rec->opts.target.cpu_list); =20 if (callchain_param.enabled && callchain_param.record_mode =3D=3D CALLCHA= IN_FP) arch__add_leaf_frame_record_opts(&rec->opts); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index c70cb0990661..04c9289e6ceb 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2462,10 +2462,7 @@ int cmd_stat(int argc, const char **argv) } } =20 - if (evlist__fix_hybrid_cpus(evsel_list, target.cpu_list)) { - pr_err("failed to use cpu list %s\n", target.cpu_list); - goto out; - } + evlist__warn_user_requested_cpus(evsel_list, target.cpu_list); =20 if (evlist__create_maps(evsel_list, &target) < 0) { if (target__has_task(&target)) { diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index 57f02beef023..db3f5fbdebe1 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -86,77 +86,3 @@ bool evlist__has_hybrid(struct evlist *evlist) =20 return false; } - -int evlist__fix_hybrid_cpus(struct evlist *evlist, const char *cpu_list) -{ - struct perf_cpu_map *cpus; - struct evsel *evsel, *tmp; - struct perf_pmu *pmu; - int ret, unmatched_count =3D 0, events_nr =3D 0; - - if (!perf_pmu__has_hybrid() || !cpu_list) - return 0; - - cpus =3D perf_cpu_map__new(cpu_list); - if (!cpus) - return -1; - - /* - * The evsels are created with hybrid pmu's cpus. But now we - * need to check and adjust the cpus of evsel by cpu_list because - * cpu_list may cause conflicts with cpus of evsel. For example, - * cpus of evsel is cpu0-7, but the cpu_list is cpu6-8, we need - * to adjust the cpus of evsel to cpu6-7. And then propatate maps - * in evlist__create_maps(). - */ - evlist__for_each_entry_safe(evlist, tmp, evsel) { - struct perf_cpu_map *matched_cpus, *unmatched_cpus; - char buf1[128], buf2[128]; - - pmu =3D perf_pmu__find_hybrid_pmu(evsel->pmu_name); - if (!pmu) - continue; - - ret =3D perf_pmu__cpus_match(pmu, cpus, &matched_cpus, - &unmatched_cpus); - if (ret) - goto out; - - events_nr++; - - if (perf_cpu_map__nr(matched_cpus) > 0 && - (perf_cpu_map__nr(unmatched_cpus) > 0 || - perf_cpu_map__nr(matched_cpus) < perf_cpu_map__nr(cpus) || - perf_cpu_map__nr(matched_cpus) < perf_cpu_map__nr(pmu->cpus))) { - perf_cpu_map__put(evsel->core.cpus); - perf_cpu_map__put(evsel->core.own_cpus); - evsel->core.cpus =3D perf_cpu_map__get(matched_cpus); - evsel->core.own_cpus =3D perf_cpu_map__get(matched_cpus); - - if (perf_cpu_map__nr(unmatched_cpus) > 0) { - cpu_map__snprint(matched_cpus, buf1, sizeof(buf1)); - pr_warning("WARNING: use %s in '%s' for '%s', skip other cpus in list.= \n", - buf1, pmu->name, evsel->name); - } - } - - if (perf_cpu_map__nr(matched_cpus) =3D=3D 0) { - evlist__remove(evlist, evsel); - evsel__delete(evsel); - - cpu_map__snprint(cpus, buf1, sizeof(buf1)); - cpu_map__snprint(pmu->cpus, buf2, sizeof(buf2)); - pr_warning("WARNING: %s isn't a '%s', please use a CPU list in the '%s'= range (%s)\n", - buf1, pmu->name, pmu->name, buf2); - unmatched_count++; - } - - perf_cpu_map__put(matched_cpus); - perf_cpu_map__put(unmatched_cpus); - } - if (events_nr) - ret =3D (unmatched_count =3D=3D events_nr) ? -1 : 0; -out: - perf_cpu_map__put(cpus); - return ret; -} diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index aacdb1b0f948..19f74b4c340a 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -10,6 +10,5 @@ int evlist__add_default_hybrid(struct evlist *evlist, bool precise); void evlist__warn_hybrid_group(struct evlist *evlist); bool evlist__has_hybrid(struct evlist *evlist); -int evlist__fix_hybrid_cpus(struct evlist *evlist, const char *cpu_list); =20 #endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 2e2c3509bec3..9dfa977193b3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -2465,3 +2465,42 @@ void evlist__check_mem_load_aux(struct evlist *evlis= t) } } } + +/** + * evlist__warn_user_requested_cpus() - Check each evsel against requested= CPUs + * and warn if the user CPU list is inapplicable for the event's PMU's + * CPUs. Not core PMUs list a CPU in sysfs, but this may be overwritte= n by a + * user requested CPU and so any online CPU is applicable. Core PMUs h= andle + * events on the CPUs in their list and otherwise the event isn't supp= orted. + * @evlist: The list of events being checked. + * @cpu_list: The user provided list of CPUs. + */ +void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *c= pu_list) +{ + struct perf_cpu_map *user_requested_cpus; + struct evsel *pos; + + if (!cpu_list) + return; + + user_requested_cpus =3D perf_cpu_map__new(cpu_list); + if (!user_requested_cpus) + return; + + evlist__for_each_entry(evlist, pos) { + struct perf_cpu_map *intersect, *to_test; + const struct perf_pmu *pmu =3D evsel__find_pmu(pos); + + to_test =3D pmu && pmu->is_core ? pmu->cpus : cpu_map__online(); + intersect =3D perf_cpu_map__intersect(to_test, user_requested_cpus); + if (!perf_cpu_map__equal(intersect, user_requested_cpus)) { + char buf[128]; + + cpu_map__snprint(to_test, buf, sizeof(buf)); + pr_warning("WARNING: A requested CPU in '%s' is not supported by PMU '%= s' (CPUs %s) for event '%s'\n", + cpu_list, pmu ? pmu->name : "cpu", buf, evsel__name(pos)); + } + perf_cpu_map__put(intersect); + } + perf_cpu_map__put(user_requested_cpus); +} diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index e7e5540cc970..5e7ff44f3043 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -447,4 +447,6 @@ struct evsel *evlist__find_evsel(struct evlist *evlist,= int idx); =20 int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf); void evlist__check_mem_load_aux(struct evlist *evlist); +void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *c= pu_list); + #endif /* __PERF_EVLIST_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index d992f5242d99..cd94abe7a87a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2046,39 +2046,6 @@ int perf_pmu__match(char *pattern, char *name, char = *tok) return 0; } =20 -int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus, - struct perf_cpu_map **mcpus_ptr, - struct perf_cpu_map **ucpus_ptr) -{ - struct perf_cpu_map *pmu_cpus =3D pmu->cpus; - struct perf_cpu_map *matched_cpus, *unmatched_cpus; - struct perf_cpu cpu; - int i, matched_nr =3D 0, unmatched_nr =3D 0; - - matched_cpus =3D perf_cpu_map__default_new(); - if (!matched_cpus) - return -1; - - unmatched_cpus =3D perf_cpu_map__default_new(); - if (!unmatched_cpus) { - perf_cpu_map__put(matched_cpus); - return -1; - } - - perf_cpu_map__for_each_cpu(cpu, i, cpus) { - if (!perf_cpu_map__has(pmu_cpus, cpu)) - RC_CHK_ACCESS(unmatched_cpus)->map[unmatched_nr++] =3D cpu; - else - RC_CHK_ACCESS(matched_cpus)->map[matched_nr++] =3D cpu; - } - - perf_cpu_map__set_nr(unmatched_cpus, unmatched_nr); - perf_cpu_map__set_nr(matched_cpus, matched_nr); - *mcpus_ptr =3D matched_cpus; - *ucpus_ptr =3D unmatched_cpus; - return 0; -} - double __weak perf_pmu__cpu_slots_per_cycle(void) { return NAN; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 96236a79c6fd..af10d137e2b5 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -265,10 +265,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *p= mu); bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); =20 -int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus, - struct perf_cpu_map **mcpus_ptr, - struct perf_cpu_map **ucpus_ptr); - char *pmu_find_real_name(const char *name); char *pmu_find_alias_name(const char *name); double perf_pmu__cpu_slots_per_cycle(void); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 356A5C77B7C for ; Wed, 24 May 2023 22:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237794AbjEXWUD (ORCPT ); Wed, 24 May 2023 18:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237564AbjEXWTa (ORCPT ); Wed, 24 May 2023 18:19:30 -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 527291B0 for ; Wed, 24 May 2023 15:19:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8337a578dso2033063276.1 for ; Wed, 24 May 2023 15:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966745; x=1687558745; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3sOBUMwNNCEoqzsDPVQsAi+V2ZTdHisiz6s6WUsWey4=; b=IUAL4nxf95HA/L6zeo7fXaZVJqZqwpz32+FkVl/s9ls/CHo3bOYqB/L4VNQ8e0/tUI s/29FyrZuJObJpQFmg96C3gGsMHuU6411j3fVUS2xrGr/0gHOBNNWDEQyAexq6HUEqMD 8JitU105N/s59aUBBQ9V5qt8KX3GVE+p++6feXSvRCwe/q0vHphsyE58EcrEnLu4HWb0 A8etjsub1iBPBDbM9dVL8eUI12U6cnC+J1R5qzcJZFkHQ/eUFH+i6G0yJ4gxwQMqUI1l I5OAFfgR3qPN/ZMiLH8iPJ2VIEd1Savg2SLL0gy9mFGoQA2dW+gIcEsyzPQN9yUzcBZI M5ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966745; x=1687558745; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3sOBUMwNNCEoqzsDPVQsAi+V2ZTdHisiz6s6WUsWey4=; b=M09qpcjO6D6wekk1qYUM+qJwoh1JZJtfHJ1PS701RzWvK581JnDbyS82HCDqEpVeGk 4PcYbtxgLEet/1qH6BrU307yQQjxIiqiW0N3C1JZ+YJPZ+HivAqI09eFyqgy4YpmfbIs Ph0MHEhOArHQFreJFxCHoYmDpuR1oNrbC4nw/vfUq0QHGHYHO/vzNsRhU0JBgS1UAeZS GhlQfk/vuoV52dO5MIGjsqpg6GtePJQ7eTdJLCxVB/XJmfrUezE5kpad/CstfADkRux/ Yd6H/vb1tVZRJD52oOoaL9pn8Fxf03s1XsYBRI1oXgvZBqG3PvaCNXsZJkNYAVmpE87t kFmQ== X-Gm-Message-State: AC+VfDxMtCvJoYeEmP/7MJOagolj4eQdGJdXtkUVmaVz8k1CJhs1HlEI k8AGMEEubFr5OhmM/puRVOcJl+GNMnVX X-Google-Smtp-Source: ACHHUZ7/3ZvdsVAhmVmEq3HnZSBR2aiwjKzN8YLQjODHD8I+5EewidQMppMVSUcAfCNg4IiAWIB90XU5luau X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:e786:0:b0:ba8:93c3:393b with SMTP id e128-20020a25e786000000b00ba893c3393bmr781880ybh.2.1684966745054; Wed, 24 May 2023 15:19:05 -0700 (PDT) Date: Wed, 24 May 2023 15:18:09 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-14-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 13/35] perf evlist: Remove evlist__warn_hybrid_group From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse events now corrects PMU groups in parse_events__sort_events_and_fix_groups and so this warning is no longer possible. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-stat.c | 3 --- tools/perf/util/evlist-hybrid.c | 32 -------------------------------- tools/perf/util/evlist-hybrid.h | 1 - 3 files changed, 36 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 04c9289e6ceb..cc4d96de1851 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -187,9 +187,6 @@ static void evlist__check_cpu_maps(struct evlist *evlis= t) { struct evsel *evsel, *warned_leader =3D NULL; =20 - if (evlist__has_hybrid(evlist)) - evlist__warn_hybrid_group(evlist); - evlist__for_each_entry(evlist, evsel) { struct evsel *leader =3D evsel__leader(evsel); =20 diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index db3f5fbdebe1..0f59c80f27b2 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -41,38 +41,6 @@ int evlist__add_default_hybrid(struct evlist *evlist, bo= ol precise) return 0; } =20 -static bool group_hybrid_conflict(struct evsel *leader) -{ - struct evsel *pos, *prev =3D NULL; - - for_each_group_evsel(pos, leader) { - if (!evsel__is_hybrid(pos)) - continue; - - if (prev && strcmp(prev->pmu_name, pos->pmu_name)) - return true; - - prev =3D pos; - } - - return false; -} - -void evlist__warn_hybrid_group(struct evlist *evlist) -{ - struct evsel *evsel; - - evlist__for_each_entry(evlist, evsel) { - if (evsel__is_group_leader(evsel) && - evsel->core.nr_members > 1 && - group_hybrid_conflict(evsel)) { - pr_warning("WARNING: events in group from " - "different hybrid PMUs!\n"); - return; - } - } -} - bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index 19f74b4c340a..4b000eda6626 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -8,7 +8,6 @@ #include =20 int evlist__add_default_hybrid(struct evlist *evlist, bool precise); -void evlist__warn_hybrid_group(struct evlist *evlist); bool evlist__has_hybrid(struct evlist *evlist); =20 #endif /* __PERF_EVLIST_HYBRID_H */ --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 35097C77B7A for ; Wed, 24 May 2023 22:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237826AbjEXWUM (ORCPT ); Wed, 24 May 2023 18:20:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237227AbjEXWTh (ORCPT ); Wed, 24 May 2023 18:19: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 007AB1B8 for ; Wed, 24 May 2023 15:19:18 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8a5cbb012so2835613276.3 for ; Wed, 24 May 2023 15:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966747; x=1687558747; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=KvYI76SN3LSsDGBG627TEqFEqoZE169lDakPXaks7wo=; b=LtNd1sQ1nR/tVT5PcLtarn5jp9Pff92GyzyO3QGdW+jYyOgNiferLf2Z/5TEQDatqe LMBmKujbWP9OUnMx9F8cFQtFsn5JNJAknbkWSl5MCGT4mQhbj/T0bL7h3ojv0g8HscnA ny267xSWe+TaTr9y2L/aj1vRXrzGL7L/PiTKoex9s3fSuSICP5lqc1ly6v2Lax1VB7r2 NIG0ltCupgrkU4ZErGXA5dNgPrJNoR2idq1/NNMtKumd/SJsE7AB1mhAPWSkZIP0yU1+ Vtp63Lcwmh2tSYUygKQJZxpU85Zk7Xxpp7ROAFkgU5qX5bTujEIvdBL8a0H4Iem+UhNy zj0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966747; x=1687558747; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KvYI76SN3LSsDGBG627TEqFEqoZE169lDakPXaks7wo=; b=W+p7B7fWa5f9NgQfVuAexKI2whC4tcH95XTQ+UM3UdM6iL7xcbS39lgnp5P4er6ehh avC7H4e9pmvu2JOUyVoQQi9zaHt79ArSjMYug1DJMWo29IgfiWva3aWYu+mQkH0FaKmP uhUL4/5ctp9GEGu4sg30UgBD7heyq6t7oRBP777UJQZy41I6DxLilyyJgJ/8zp5lP0l0 HLekCwiguIFbQoqR1xtoUjwKVXvE2MyrAYeovrJPY+le9xOcCruOmQS3nwgg77tk3FlC EGc1fTiV9A1V5hmfgW95Hhm6bjMhXSbV9xvUPC5MxKbhpQGSdzaA9g84US/PqeDNeSa5 moxg== X-Gm-Message-State: AC+VfDwpmDklbeIl+faeBM4c9oatY5ZaNUTEnCiAr081rYzjPRGMihaE 3kRf6eIUmM4soZD0NMAFVhGTZBCnIAXr X-Google-Smtp-Source: ACHHUZ5D/yUipWEDiqSUQ3rcMif94S1VlO1gGnqpCF1RxrNods675HwSbtRDhVW0rXw1HwI9CBryYTOySrBc X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:db47:0:b0:ba8:6148:4300 with SMTP id g68-20020a25db47000000b00ba861484300mr577117ybf.6.1684966747454; Wed, 24 May 2023 15:19:07 -0700 (PDT) Date: Wed, 24 May 2023 15:18:10 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-15-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 14/35] perf evlist: Remove __evlist__add_default From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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__add_default adds a cycles event to a typically empty evlist and was extended for hybrid with evlist__add_default_hybrid, as more than 1 PMU was necessary. Rather than have dedicated logic for the cycles event, this change switches to parsing 'cycles:P' which will handle wildcarding the PMUs appropriately for hybrid. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/x86/util/evsel.c | 20 -------------- tools/perf/builtin-record.c | 13 +++------ tools/perf/builtin-top.c | 10 ++++--- tools/perf/util/evlist-hybrid.c | 25 ----------------- tools/perf/util/evlist-hybrid.h | 1 - tools/perf/util/evlist.c | 22 ++++++--------- tools/perf/util/evlist.h | 7 ----- tools/perf/util/evsel.c | 46 -------------------------------- tools/perf/util/evsel.h | 3 --- 9 files changed, 17 insertions(+), 130 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index ea3972d785d1..153cdca94cd4 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -16,26 +16,6 @@ void arch_evsel__set_sample_weight(struct evsel *evsel) evsel__set_sample_bit(evsel, WEIGHT_STRUCT); } =20 -void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr) -{ - struct perf_env env =3D { .total_mem =3D 0, } ; - - if (!perf_env__cpuid(&env)) - return; - - /* - * On AMD, precise cycles event sampling internally uses IBS pmu. - * But IBS does not have filtering capabilities and perf by default - * sets exclude_guest =3D 1. This makes IBS pmu event init fail and - * thus perf ends up doing non-precise sampling. Avoid it by clearing - * exclude_guest. - */ - if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD")) - attr->exclude_guest =3D 0; - - free(env.cpuid); -} - /* Check whether the evsel's PMU supports the perf metrics */ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) { diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 88f7b4241153..d80b54a6f450 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4161,18 +4161,11 @@ int cmd_record(int argc, const char **argv) record.opts.tail_synthesize =3D true; =20 if (rec->evlist->core.nr_entries =3D=3D 0) { - if (perf_pmu__has_hybrid()) { - err =3D evlist__add_default_hybrid(rec->evlist, - !record.opts.no_samples); - } else { - err =3D __evlist__add_default(rec->evlist, - !record.opts.no_samples); - } + bool can_profile_kernel =3D perf_event_paranoid_check(1); =20 - if (err < 0) { - pr_err("Not enough memory for event selector list\n"); + err =3D parse_event(rec->evlist, can_profile_kernel ? "cycles:P" : "cycl= es:Pu"); + if (err) goto out; - } } =20 if (rec->opts.target.tid && !rec->opts.no_inherit_set) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 48ee49e95c5e..27a7f068207d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1653,10 +1653,12 @@ int cmd_top(int argc, const char **argv) if (annotate_check_args(&top.annotation_opts) < 0) goto out_delete_evlist; =20 - if (!top.evlist->core.nr_entries && - evlist__add_default(top.evlist) < 0) { - pr_err("Not enough memory for event selector list\n"); - goto out_delete_evlist; + if (!top.evlist->core.nr_entries) { + bool can_profile_kernel =3D perf_event_paranoid_check(1); + int err =3D parse_event(top.evlist, can_profile_kernel ? "cycles:P" : "c= ycles:Pu"); + + if (err) + goto out_delete_evlist; } =20 status =3D evswitch__init(&top.evswitch, top.evlist, stderr); diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c index 0f59c80f27b2..64f78d06fe19 100644 --- a/tools/perf/util/evlist-hybrid.c +++ b/tools/perf/util/evlist-hybrid.c @@ -16,31 +16,6 @@ #include #include =20 -int evlist__add_default_hybrid(struct evlist *evlist, bool precise) -{ - struct evsel *evsel; - struct perf_pmu *pmu; - __u64 config; - struct perf_cpu_map *cpus; - - perf_pmu__for_each_hybrid_pmu(pmu) { - config =3D PERF_COUNT_HW_CPU_CYCLES | - ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT); - evsel =3D evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - config); - if (!evsel) - return -ENOMEM; - - cpus =3D perf_cpu_map__get(pmu->cpus); - evsel->core.cpus =3D cpus; - evsel->core.own_cpus =3D perf_cpu_map__get(cpus); - evsel->pmu_name =3D strdup(pmu->name); - evlist__add(evlist, evsel); - } - - return 0; -} - bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h index 4b000eda6626..0cded76eb344 100644 --- a/tools/perf/util/evlist-hybrid.h +++ b/tools/perf/util/evlist-hybrid.h @@ -7,7 +7,6 @@ #include "evlist.h" #include =20 -int evlist__add_default_hybrid(struct evlist *evlist, bool precise); bool evlist__has_hybrid(struct evlist *evlist); =20 #endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 9dfa977193b3..63f8821a5395 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -93,8 +93,15 @@ struct evlist *evlist__new(void) struct evlist *evlist__new_default(void) { struct evlist *evlist =3D evlist__new(); + bool can_profile_kernel; + int err; + + if (!evlist) + return NULL; =20 - if (evlist && evlist__add_default(evlist)) { + can_profile_kernel =3D perf_event_paranoid_check(1); + err =3D parse_event(evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu"= ); + if (err) { evlist__delete(evlist); evlist =3D NULL; } @@ -237,19 +244,6 @@ static void evlist__set_leader(struct evlist *evlist) perf_evlist__set_leader(&evlist->core); } =20 -int __evlist__add_default(struct evlist *evlist, bool precise) -{ - struct evsel *evsel; - - evsel =3D evsel__new_cycles(precise, PERF_TYPE_HARDWARE, - PERF_COUNT_HW_CPU_CYCLES); - if (evsel =3D=3D NULL) - return -ENOMEM; - - evlist__add(evlist, evsel); - return 0; -} - static struct evsel *evlist__dummy_event(struct evlist *evlist) { struct perf_event_attr attr =3D { diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 5e7ff44f3043..664c6bf7b3e0 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -100,13 +100,6 @@ void evlist__delete(struct evlist *evlist); void evlist__add(struct evlist *evlist, struct evsel *entry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); =20 -int __evlist__add_default(struct evlist *evlist, bool precise); - -static inline int evlist__add_default(struct evlist *evlist) -{ - return __evlist__add_default(evlist, true); -} - int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs= , size_t nr_attrs); =20 int __evlist__add_default_attrs(struct evlist *evlist, diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8c8f371ea2b5..1df8f967d2eb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -316,48 +316,6 @@ struct evsel *evsel__new_idx(struct perf_event_attr *a= ttr, int idx) return evsel; } =20 -static bool perf_event_can_profile_kernel(void) -{ - return perf_event_paranoid_check(1); -} - -struct evsel *evsel__new_cycles(bool precise __maybe_unused, __u32 type, _= _u64 config) -{ - struct perf_event_attr attr =3D { - .type =3D type, - .config =3D config, - .exclude_kernel =3D !perf_event_can_profile_kernel(), - }; - struct evsel *evsel; - - event_attr_init(&attr); - - /* - * Now let the usual logic to set up the perf_event_attr defaults - * to kick in when we return and before perf_evsel__open() is called. - */ - evsel =3D evsel__new(&attr); - if (evsel =3D=3D NULL) - goto out; - - arch_evsel__fixup_new_cycles(&evsel->core.attr); - - evsel->precise_max =3D true; - - /* use asprintf() because free(evsel) assumes name is allocated */ - if (asprintf(&evsel->name, "cycles%s%s%.*s", - (attr.precise_ip || attr.exclude_kernel) ? ":" : "", - attr.exclude_kernel ? "u" : "", - attr.precise_ip ? attr.precise_ip + 1 : 0, "ppp") < 0) - goto error_free; -out: - return evsel; -error_free: - evsel__delete(evsel); - evsel =3D NULL; - goto out; -} - int copy_config_terms(struct list_head *dst, struct list_head *src) { struct evsel_config_term *pos, *tmp; @@ -1131,10 +1089,6 @@ void __weak arch_evsel__set_sample_weight(struct evs= el *evsel) evsel__set_sample_bit(evsel, WEIGHT); } =20 -void __weak arch_evsel__fixup_new_cycles(struct perf_event_attr *attr __ma= ybe_unused) -{ -} - void __weak arch__post_evsel_config(struct evsel *evsel __maybe_unused, struct perf_event_attr *attr __maybe_unused) { diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index df8928745fc6..429b172cc94d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -243,8 +243,6 @@ static inline struct evsel *evsel__newtp(const char *sy= s, const char *name) } #endif =20 -struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config); - #ifdef HAVE_LIBTRACEEVENT struct tep_event *event_format__new(const char *sys, const char *name); #endif @@ -312,7 +310,6 @@ void __evsel__reset_sample_bit(struct evsel *evsel, enu= m perf_event_sample_forma void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); =20 void arch_evsel__set_sample_weight(struct evsel *evsel); -void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr); void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *= attr); =20 int evsel__set_filter(struct evsel *evsel, const char *filter); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 652D5C7EE2C for ; Wed, 24 May 2023 22:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237851AbjEXWUP (ORCPT ); Wed, 24 May 2023 18:20:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbjEXWTh (ORCPT ); Wed, 24 May 2023 18:19: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 D0D0E1BC for ; Wed, 24 May 2023 15:19:19 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb53e6952so3139465276.0 for ; Wed, 24 May 2023 15:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966750; x=1687558750; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2Ev/Umag+1kF8B15W9g1QM1ZWvuEFBejQXrwI+WR21A=; b=JMsQYU8+yomo5jSbLSRJBjA6TPdzXTPm3ryzbqOjQ7HfpZVXJADxYoGFbCtFk2p9Ac gy8yeurv+ybzg2s44BB3EsfcuBqOuGvKxjI8UJZPLDGzJrSIS4j/BEF4MDpDrDAPg+6X WAwALlGobCGXKvC7SSI6X0v6yzULWHrch28mGvGXl3LdL3lrRMLTeHJ+Sj1TC2z+ZEji zOr13lKE/zy/d0IxU6HRONlAsH28ebWFz+xOHSaANWq1uiZQWhWvhS36+N2LGaSTk/kG k4WpRB3sTmDGcH0Vvk9niZDX3o9VTdPtrhZD2kBb6iuaFfoMpJBP4Q9yZvOfdRPq8n5x LG2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966750; x=1687558750; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2Ev/Umag+1kF8B15W9g1QM1ZWvuEFBejQXrwI+WR21A=; b=Vb3pSvLg/U8b9cMRW3QRY6ctH7dkL+/Wpu5fsaQOeglqoGazfzXGloHBhmWbiCPNwS aYLdDaXMtIqaiLz30askNs0Ocj5qgh6BVkLHqeiJ836RZbCJ2svF88xVLyfknWjyJKRt bB25NEvpi2z4OqslASe11aAWalwb7rBaqj+ZJjVxzzk6abOnRdg2jximoGzG7AuAnoCR AI7dHBEH6UZfpgIFyNU8YZnPnvRRLqoaUwGNmNKd71bsS2czpVQvxHRW+kliLT+GcaCz jKNPCcEeScL6IaSAFQJQUoQA/dWRnzxmbsPx4+wIHiu9b7YJRuigm2HB6At4TogdBINJ wNxg== X-Gm-Message-State: AC+VfDwxcq2jHNp2FZprwgzmj49dxTUtsuBYc+l6f9KryCIsQl2DNgbi l0ERe9zP5ILDcMKHTgzI9auDwewSDyyT X-Google-Smtp-Source: ACHHUZ6nk7KPim+zmUUj154fvDJHp2Oy0J25GAXFhwzJha51YxFfXSRvFi9Uiblj4LbpUvvE76tjnkiiTBt1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:aacc:0:b0:ba8:757c:2523 with SMTP id t70-20020a25aacc000000b00ba8757c2523mr797390ybi.9.1684966749986; Wed, 24 May 2023 15:19:09 -0700 (PDT) Date: Wed, 24 May 2023 15:18:11 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-16-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 15/35] perf evlist: Reduce scope of evlist__has_hybrid From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Function is only used in printout, reduce scope to stat-display.c. Remove the now empty evlist-hybrid.c and evlist-hybrid.h. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-record.c | 1 - tools/perf/builtin-stat.c | 1 - tools/perf/util/Build | 1 - tools/perf/util/evlist-hybrid.c | 31 ------------------------------- tools/perf/util/evlist-hybrid.h | 12 ------------ tools/perf/util/evlist.c | 1 - tools/perf/util/stat-display.c | 15 ++++++++++++++- 7 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 tools/perf/util/evlist-hybrid.c delete mode 100644 tools/perf/util/evlist-hybrid.h diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d80b54a6f450..e30e8d6a6575 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -50,7 +50,6 @@ #include "util/pfm.h" #include "util/clockid.h" #include "util/pmu-hybrid.h" -#include "util/evlist-hybrid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" #include "asm/bug.h" diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cc4d96de1851..3b90d742b023 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -48,7 +48,6 @@ #include "util/pmu.h" #include "util/event.h" #include "util/evlist.h" -#include "util/evlist-hybrid.h" #include "util/evsel.h" #include "util/debug.h" #include "util/color.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index c146736ead19..21e4cdcba504 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -11,7 +11,6 @@ perf-y +=3D db-export.o perf-y +=3D env.o perf-y +=3D event.o perf-y +=3D evlist.o -perf-y +=3D evlist-hybrid.o perf-y +=3D sideband_evlist.o perf-y +=3D evsel.o perf-y +=3D evsel_fprintf.o diff --git a/tools/perf/util/evlist-hybrid.c b/tools/perf/util/evlist-hybri= d.c deleted file mode 100644 index 64f78d06fe19..000000000000 --- a/tools/perf/util/evlist-hybrid.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include -#include -#include "cpumap.h" -#include "evlist.h" -#include "evsel.h" -#include "../perf.h" -#include "util/pmu-hybrid.h" -#include "util/evlist-hybrid.h" -#include "debug.h" -#include -#include -#include -#include -#include -#include -#include - -bool evlist__has_hybrid(struct evlist *evlist) -{ - struct evsel *evsel; - - evlist__for_each_entry(evlist, evsel) { - if (evsel->pmu_name && - perf_pmu__is_hybrid(evsel->pmu_name)) { - return true; - } - } - - return false; -} diff --git a/tools/perf/util/evlist-hybrid.h b/tools/perf/util/evlist-hybri= d.h deleted file mode 100644 index 0cded76eb344..000000000000 --- a/tools/perf/util/evlist-hybrid.h +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __PERF_EVLIST_HYBRID_H -#define __PERF_EVLIST_HYBRID_H - -#include -#include -#include "evlist.h" -#include - -bool evlist__has_hybrid(struct evlist *evlist); - -#endif /* __PERF_EVLIST_HYBRID_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 63f8821a5395..82c0b3d0c822 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -28,7 +28,6 @@ #include "util/string2.h" #include "util/perf_api_probe.h" #include "util/evsel_fprintf.h" -#include "util/evlist-hybrid.h" #include "util/pmu.h" #include "util/sample.h" #include "util/bpf-filter.h" diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index bf5a6c14dfcd..ede0477d958a 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -20,7 +20,6 @@ #include "util.h" #include "iostat.h" #include "pmu-hybrid.h" -#include "evlist-hybrid.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -677,6 +676,20 @@ static bool is_mixed_hw_group(struct evsel *counter) return false; } =20 +static bool evlist__has_hybrid(struct evlist *evlist) +{ + struct evsel *evsel; + + evlist__for_each_entry(evlist, evsel) { + if (evsel->pmu_name && + perf_pmu__is_hybrid(evsel->pmu_name)) { + return true; + } + } + + return false; +} + static void printout(struct perf_stat_config *config, struct outstate *os, double uval, u64 run, u64 ena, double noise, int aggr_idx) { --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 96C62C77B7C for ; Wed, 24 May 2023 22:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231278AbjEXWUT (ORCPT ); Wed, 24 May 2023 18:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237276AbjEXWTi (ORCPT ); Wed, 24 May 2023 18:19:38 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6E9E42 for ; Wed, 24 May 2023 15:19:21 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56183784dd3so18363857b3.3 for ; Wed, 24 May 2023 15:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966752; x=1687558752; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wZYg2JPOF5mh3/s2R7+J9pQ85BbOWb9mT0CXNZohOl8=; b=CD5hlVHqEv/Y7LWF/Spza457wbC1CEDsm/P+9HoyOabOuNgeuvyrFQLdBLAvMRBXy6 lrXn898aq2EUWKPiSdpCTV2BnE00nVGYWbN7Rmap/hIGhmJs/eEM0PfaahZ4HNqh11lU p0sCvaBiHhPW307HM2Zxj1AKhOSwQa3ScmnN9fK0snogBpVdNg/fZuQKubHX6rKZ6UBn R/njOEYTnBHfRqdWGKtcemHDlTvHdG/GYSdxwoddYp2C9UzLSUXu/rhh8K9xSfUbAAkB ShGEhuK5OJHMCNSlO5ZzVEf0mFqU4nnn+uYq1nsz7AEep5uvJ/UwxwYqpeCKznLZqsa+ 9+5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966752; x=1687558752; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wZYg2JPOF5mh3/s2R7+J9pQ85BbOWb9mT0CXNZohOl8=; b=CQYFhd0+aUZXwrdpL76QgzwegN3PUAlOmdq6a/nBsCP4hkZ40XDVjqYUfeicVEDF4V vtdsiXPFQtfFymvT9jgM1rzUzPycgR+dJi3szFtsgMAMP3aBzSVtVQFAYL/ILeH9J0oV N+xdBw4/PuLxlOnlt/SbH9J+2vZYZQs152wmXMhDEVE685SguID3ndIeBCKyWqKa43o9 ZQz83ZedhJCJlEtHx1xt/Q5fvpJaiiA2G7jKaHnZRTQV/VxH7K/ZgKsr8FcJn/PN3SoU hCj6CZXsSx1HVnS6f9oGBurp9ypScwTTF7pd37SnEdFl4p+tVjPLjqM9X/LbaKFNbbLx Xk4A== X-Gm-Message-State: AC+VfDyafoSgFWaUSpNLgROZ8+5Ucfn606GFFzg/eF4GyENT/F1FBQkh /mIWvWg7O+T1FdwlYpgEHmmY2F+N7dFS X-Google-Smtp-Source: ACHHUZ7bYaKDOPGf0vOTAfySDo8dgtk3bBSmCzfAWgcCnDA9+/qbenId3D6EtgKGdRUNwdx0wWFFOIDjBmLI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:7652:0:b0:561:c567:c8ff with SMTP id j18-20020a817652000000b00561c567c8ffmr11891423ywk.4.1684966752285; Wed, 24 May 2023 15:19:12 -0700 (PDT) Date: Wed, 24 May 2023 15:18:12 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-17-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 16/35] perf pmu: Remove perf_pmu__hybrid_mounted From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmu__hybrid_mounted is used to detect whether cpu_core or cpu_atom is mounted with a non-empty cpus file by pmu_lookup. pmu_lookup will attempt to read the cpus file too and so the check can be folded into this. Checking hybrid_mounted in pmu_is_uncore is redundant as the next cpumask read will fail returning false. Reduce the scope of perf_pmu__find_hybrid_pmu by making it static. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmu-hybrid.c | 15 +-------------- tools/perf/util/pmu-hybrid.h | 3 --- tools/perf/util/pmu.c | 26 ++++++++++++++------------ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c index bc4cb0738c35..7fe943dd3217 100644 --- a/tools/perf/util/pmu-hybrid.c +++ b/tools/perf/util/pmu-hybrid.c @@ -18,20 +18,7 @@ =20 LIST_HEAD(perf_pmu__hybrid_pmus); =20 -bool perf_pmu__hybrid_mounted(const char *name) -{ - int cpu; - char pmu_name[PATH_MAX]; - struct perf_pmu pmu =3D {.name =3D pmu_name}; - - if (strncmp(name, "cpu_", 4)) - return false; - - strlcpy(pmu_name, name, sizeof(pmu_name)); - return perf_pmu__scan_file(&pmu, "cpus", "%u", &cpu) > 0; -} - -struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) +static struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) { struct perf_pmu *pmu; =20 diff --git a/tools/perf/util/pmu-hybrid.h b/tools/perf/util/pmu-hybrid.h index 206b94931531..8dbcae935020 100644 --- a/tools/perf/util/pmu-hybrid.h +++ b/tools/perf/util/pmu-hybrid.h @@ -13,9 +13,6 @@ extern struct list_head perf_pmu__hybrid_pmus; #define perf_pmu__for_each_hybrid_pmu(pmu) \ list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) =20 -bool perf_pmu__hybrid_mounted(const char *name); - -struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); bool perf_pmu__is_hybrid(const char *name); =20 static inline int perf_pmu__hybrid_pmu_num(void) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index cd94abe7a87a..e9f3e6a777c0 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -617,9 +617,6 @@ static bool pmu_is_uncore(int dirfd, const char *name) { int fd; =20 - if (perf_pmu__hybrid_mounted(name)) - return false; - fd =3D perf_pmu__pathname_fd(dirfd, name, "cpumask", O_PATH); if (fd < 0) return false; @@ -900,6 +897,16 @@ static int pmu_max_precise(int dirfd, struct perf_pmu = *pmu) return max_precise; } =20 +/** + * perf_pmu__skip_empty_cpus() - should pmu_lookup skip the named PMU if t= he + * cpus or cpumask file isn't present? + * @name: Name of PMU. + */ +static bool perf_pmu__skip_empty_cpus(const char *name) +{ + return !strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom"); +} + static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) { struct perf_pmu *pmu; @@ -907,15 +914,8 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) LIST_HEAD(aliases); __u32 type; char *name =3D pmu_find_real_name(lookup_name); - bool is_hybrid =3D perf_pmu__hybrid_mounted(name); char *alias_name; =20 - /* - * Check pmu name for hybrid and the pmu may be invalid in sysfs - */ - if (!strncmp(name, "cpu_", 4) && !is_hybrid) - return NULL; - /* * The pmu data we store & need consists of the pmu * type value and format definitions. Load both right @@ -935,8 +935,10 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) return NULL; =20 pmu->cpus =3D pmu_cpumask(dirfd, name); - pmu->name =3D strdup(name); + if (!pmu->cpus && perf_pmu__skip_empty_cpus(name)) + goto err; =20 + pmu->name =3D strdup(name); if (!pmu->name) goto err; =20 @@ -967,7 +969,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); =20 - if (is_hybrid) + if (!strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom")) list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus); else INIT_LIST_HEAD(&pmu->hybrid_list); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 15008C77B7A for ; Wed, 24 May 2023 22:20:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237247AbjEXWUA (ORCPT ); Wed, 24 May 2023 18:20:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231658AbjEXWT3 (ORCPT ); Wed, 24 May 2023 18:19:29 -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 1E89610D0 for ; Wed, 24 May 2023 15:19:15 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba83fed51b0so1861728276.3 for ; Wed, 24 May 2023 15:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966755; x=1687558755; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T1T7njr7JkWMvDDZnEk/t/BOuD5WuTu8PcvmdAEMrg8=; b=ySSNKtAZRkZfdrXUqJSOlEp1TXX2LZPRSt+VlUljfAOealn0tl+3yQPXwNviNIUsPS /n/9N1KdMBfE4JUt+jNy5w6m0tkFUcAF80uJX/6QzVwGMK5Sgdxm4VrH0miQn40xd9mm obprTgtKg0ThCaT4frbwOAHpDCGfwdLhpOpN4tjl/hLS5G+HCr/bOU6XDg2q5txLWA8B XlCHbKFm+gvuImcNx2BRCZo46+hcnOG5bzpPFuAVAU7r+79Bji2ZJpvkZo/xBbiasPMm 83NgkjqwhAj6+KsKfrK2E1PIzavbOsWBD3FxzG6wQSbciTUpaHQp1nQW9OlVyOO9udiz GPTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966755; x=1687558755; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T1T7njr7JkWMvDDZnEk/t/BOuD5WuTu8PcvmdAEMrg8=; b=ix8c5rFL0gPlwJEZxBYclbfudMMgCbSb33xE9fIRcEGyMgrsia230HZkoHJN1ZoEwe 1JjZbZ4hGLBOG4YXwHnoXmUB8MX9vHE26/6a35PAwBfrG9A2qEL4n/2qiFCirDOC8hGB JTqkznD9nEx6HEpRJH2J+W0yT/v4aBI/Oo/VfOy5VD8IJiwVwfbHUXoi/ZjBSZxtb+RC xxGtUs06xzGv5cQYf0i8UjbsQ9uX6IHJh1gLUbIBP2dT0kSA78d4E6ZJxK475w/qSUi3 sV5qbzSsH7RwbQUNS4OjoyveHDVdV8BoM1C2NRLkpMuhAdKuCBzX66o1B0/PHOrl0sF3 YW5g== X-Gm-Message-State: AC+VfDwnczpsNs0IT0jNsUilYspczq5lG0Ye6yS47AqmtlVr7vl7eal7 xCPbNZqytXPRfvisfwhHQJEgG1C3YImb X-Google-Smtp-Source: ACHHUZ6qH9PCyRVFSAUQW8f9PmxZgpl8Yzylqljyq6W3cock0VJZmarcGXaRRN+3X5MziK1RwyHWEWWZ62UB X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:5442:0:b0:ba8:8ab3:3806 with SMTP id i63-20020a255442000000b00ba88ab33806mr731563ybb.13.1684966754736; Wed, 24 May 2023 15:19:14 -0700 (PDT) Date: Wed, 24 May 2023 15:18:13 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-18-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 17/35] perf pmu: Rewrite perf_pmu__has_hybrid to avoid list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than list empty on perf_pmu__hybrid_pmus, detect if any core PMUs match the hybrid name. Computed values held in statics to avoid recomputation. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e9f3e6a777c0..821cdd79db48 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -60,8 +60,6 @@ struct perf_pmu_format { struct list_head list; }; =20 -static bool hybrid_scanned; - static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); =20 /* @@ -2026,12 +2024,20 @@ void perf_pmu__warn_invalid_config(struct perf_pmu = *pmu, __u64 config, =20 bool perf_pmu__has_hybrid(void) { + static bool hybrid_scanned, has_hybrid; + if (!hybrid_scanned) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid =3D true; + break; + } + } hybrid_scanned =3D true; - perf_pmu__scan(NULL); } - - return !list_empty(&perf_pmu__hybrid_pmus); + return has_hybrid; } =20 int perf_pmu__match(char *pattern, char *name, char *tok) --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 B65D6C77B7A for ; Wed, 24 May 2023 22:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235933AbjEXWUX (ORCPT ); Wed, 24 May 2023 18:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236940AbjEXWTq (ORCPT ); Wed, 24 May 2023 18:19:46 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFBCBE4C for ; Wed, 24 May 2023 15:19:23 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5618857518dso17132357b3.2 for ; Wed, 24 May 2023 15:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966757; x=1687558757; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cjAbWq1xZ7aD31R1h5+Cy8ZSDZyyIBasEI10DVMtL4M=; b=p0AhpgXvZl8O7RhTTMtAr534BDXoiK4d/HxTufbtoGDKujmUAJho6GTXP8kd6FAbKl HVIdVGezNvfTcmbLbZIj2zZRsM4FsEy6iN6IWt+evEgx8S8XI1x1ZtfRltJRmPu30hd2 kkIFB/josxZHZWjTz//UdEi3TZqb4OnOn0EaVu0FhPE27c1gkvWp2B//EcHGDg8e3ThF 18xvAzudf0X9+XnMuE1fC9PiNi2n3flAM7q+czmWCENi/N7vYvEuMdKO9wSmKo2uIPTt qNVxvbOW/fw4VVdd7cR50euAcg7TmYSqKPksPwCwGrzvRiekbPTPwzxLgP+w+CclTopP dvhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966757; x=1687558757; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cjAbWq1xZ7aD31R1h5+Cy8ZSDZyyIBasEI10DVMtL4M=; b=B2HEvVF87SugB0tv7E2PhWcd17qGCHZ9L8AYF16C9gyndUrmE1HPhwKxhzl6/ukSCv YjQShixkD2ih7MpWYiUDp37iDVGREhMfKPqn/fHs3jvqy6y48H7goAcl3s0sUQVi9fiO +8g4eWF0YKiGl+2f8a/fW0VNnleoAOSgjRQRWlLspoWxeHPLwP3Z8a43MTSryWd8hZpA ie0A35+pkNqGfCoJ6ai1hecTY8QPb6YHXk00WDtwiYOMWu50IxiSb2Z5DYkysibGAhjG U23VZh4E5rxXHlcZ/qiFWAqUWmT/qa4QnpGekDarIO02gvzVhJWFPfkkWaFYIEZya01b v55Q== X-Gm-Message-State: AC+VfDy4CcXXXSSfLnPFoSYVvuBVTDd7IE8J+QUohE//1oT2TCEixfBX fHbgCDTpWG+6V+N5xPWhb1wiyaY6qghE X-Google-Smtp-Source: ACHHUZ7A/zgz61i+jDQae5egqZTZUd2asN0Lc32kLdqF4kB08b2NQcqeXPmsMs8FXQsh8XavrY8B6mFmujRA X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:a749:0:b0:565:51b:c6f0 with SMTP id e70-20020a81a749000000b00565051bc6f0mr7187150ywh.6.1684966757019; Wed, 24 May 2023 15:19:17 -0700 (PDT) Date: Wed, 24 May 2023 15:18:14 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-19-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 18/35] perf x86: Iterate hybrid PMUs as core PMUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than iterating over a separate hybrid list, iterate all PMUs with the hybrid ones having is_core as true. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/x86/tests/hybrid.c | 2 +- tools/perf/arch/x86/util/evlist.c | 25 +++++++++++++++++-------- tools/perf/arch/x86/util/perf_regs.c | 14 ++++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index 941a9edfed4e..944bd1b4bab6 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -3,7 +3,7 @@ #include "debug.h" #include "evlist.h" #include "evsel.h" -#include "pmu-hybrid.h" +#include "pmu.h" #include "tests/tests.h" =20 static bool test_config(const struct evsel *evsel, __u64 expected_config) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 1b6065841fb0..03f7eb4cf0a4 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -4,7 +4,6 @@ #include "util/evlist.h" #include "util/parse-events.h" #include "util/event.h" -#include "util/pmu-hybrid.h" #include "topdown.h" #include "evsel.h" =20 @@ -12,9 +11,6 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, struct perf_event_attr *attrs, size_t nr_attrs) { - struct perf_cpu_map *cpus; - struct evsel *evsel, *n; - struct perf_pmu *pmu; LIST_HEAD(head); size_t i =3D 0; =20 @@ -25,15 +21,24 @@ static int ___evlist__add_default_attrs(struct evlist *= evlist, return evlist__add_attrs(evlist, attrs, nr_attrs); =20 for (i =3D 0; i < nr_attrs; i++) { + struct perf_pmu *pmu =3D NULL; + if (attrs[i].type =3D=3D PERF_TYPE_SOFTWARE) { - evsel =3D evsel__new(attrs + i); + struct evsel *evsel =3D evsel__new(attrs + i); + if (evsel =3D=3D NULL) goto out_delete_partial_list; list_add_tail(&evsel->core.node, &head); continue; } =20 - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + struct perf_cpu_map *cpus; + struct evsel *evsel; + + if (!pmu->is_core) + continue; + evsel =3D evsel__new(attrs + i); if (evsel =3D=3D NULL) goto out_delete_partial_list; @@ -51,8 +56,12 @@ static int ___evlist__add_default_attrs(struct evlist *e= vlist, return 0; =20 out_delete_partial_list: - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); + { + struct evsel *evsel, *n; + + __evlist__for_each_entry_safe(&head, n, evsel) + evsel__delete(evsel); + } return -1; } =20 diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index 0ed177991ad0..26abc159fc0e 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -10,7 +10,6 @@ #include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/pmu.h" -#include "../../../util/pmu-hybrid.h" =20 const struct sample_reg sample_reg_masks[] =3D { SMPL_REG(AX, PERF_REG_X86_AX), @@ -286,7 +285,6 @@ uint64_t arch__intr_reg_mask(void) .disabled =3D 1, .exclude_kernel =3D 1, }; - struct perf_pmu *pmu; int fd; /* * In an unnamed union, init it here to build on older gcc versions @@ -294,12 +292,20 @@ uint64_t arch__intr_reg_mask(void) attr.sample_period =3D 1; =20 if (perf_pmu__has_hybrid()) { + struct perf_pmu *pmu =3D NULL; + __u64 type =3D PERF_TYPE_RAW; + /* * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - pmu =3D list_first_entry(&perf_pmu__hybrid_pmus, typeof(*pmu), hybrid_li= st); - attr.config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core) { + type =3D pmu->type; + break; + } + } + attr.config |=3D type << PERF_PMU_TYPE_SHIFT; } =20 event_attr_init(&attr); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 13FCBC77B7C for ; Wed, 24 May 2023 22:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237951AbjEXWUd (ORCPT ); Wed, 24 May 2023 18:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236038AbjEXWTs (ORCPT ); Wed, 24 May 2023 18:19:48 -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 CA2BC10D7 for ; Wed, 24 May 2023 15:19:26 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-560ee0df572so29568147b3.0 for ; Wed, 24 May 2023 15:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966759; x=1687558759; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/eS5iHSDHpFh4XdVaHBCbrVny8PCbF73cyIUIzaUWEw=; b=NOCz+nx/NdHrPcizU4MdSkA0WBYp0H9Nf+F0NieGY60JSYl6AF2S+CnMb/dlfziqBk SNH4dssbJwRHXcvUoZ75cIaneT6FAyO+RD40b3bYt/ivPRlyaUhPjcWffNE4plZNHk7B 85Pk3dn4eV7+z9VbZe3ftQwYaRLvlEoPyUrJecJI4zZjFdpsXLXrNFLGCCTR8yD47+lw 1lDf48a8NZvNawqoBz8WAQLdrQLFWRHgitHfKcAoqr17q16mRxGZ8JMqhlJB2UzXb7N8 oDKXnLY5ppa/bPZUkg0E5pzMtux5QWv/od7FtU+msEMoASarZrFObKcNTb6XkZJNtm8l F4Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966759; x=1687558759; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/eS5iHSDHpFh4XdVaHBCbrVny8PCbF73cyIUIzaUWEw=; b=KmvDWtSw5HqFlL2kdmSfxn6cbsQz10cBv1WKU9f3iHlB3Pc+0/DLw4jH9PAQjulFIf UhBobO6QXaHEOVeI89iQRraqPlP72JA7WqkKmlF5Z2Xi0tq3g0AGAV0hddHjapWd+Lgl zuJeAe2a/Ir66WuSCxL8qIUFr7r5ACDq/rBHgds8Ff2HExGZpCzCg7h9tVZgSpqFL6Jr Z0/+WbL6ZVgFLQgg9VHFR6JO6pRkPIFkMeuLdFGczzr7S6LZDg+c5sYrgnW22MSqY9tl 9aY6iSCz/ZZuIh795JdkxfZvcAvx5K3YULe1Qgb9Cyf+ZmntPZMO6B8Si40JhdutPAGN Bi2w== X-Gm-Message-State: AC+VfDy+BVkr7TITfDc1wMULR9YrnWaUaQhOOO9CvN/L++KHZZgMPg+8 39iHZdkKnd7+IEDkKz7F9cm3Ud1uVtii X-Google-Smtp-Source: ACHHUZ5rsi2pKjCTlzd+MdEj65Y6PrSrlVw2S+xS+bJJXjv14kZ8uWv5F1wr1NxRMs43HWII98fVEDfi8AHZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:de06:0:b0:55d:955b:360 with SMTP id k6-20020a81de06000000b0055d955b0360mr11554971ywj.5.1684966759076; Wed, 24 May 2023 15:19:19 -0700 (PDT) Date: Wed, 24 May 2023 15:18:15 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-20-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 19/35] perf topology: Avoid hybrid list for hybrid topology From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid perf_pmu__for_each_hybrid_pmu in hybrid_topology__new by scanning all PMUs and processing the is_core ones. Add early exit for non-hybrid. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/cputopo.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index ca1d833a0c26..a5c259bd5cc0 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -12,7 +12,7 @@ #include "cpumap.h" #include "debug.h" #include "env.h" -#include "pmu-hybrid.h" +#include "pmu.h" =20 #define PACKAGE_CPUS_FMT \ "%s/devices/system/cpu/cpu%d/topology/package_cpus_list" @@ -469,11 +469,17 @@ static int load_hybrid_node(struct hybrid_topology_no= de *node, =20 struct hybrid_topology *hybrid_topology__new(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; struct hybrid_topology *tp =3D NULL; - u32 nr, i =3D 0; + u32 nr =3D 0, i =3D 0; =20 - nr =3D perf_pmu__hybrid_pmu_num(); + if (!perf_pmu__has_hybrid()) + return NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (pmu->is_core) + nr++; + } if (nr =3D=3D 0) return NULL; =20 @@ -482,7 +488,10 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; + if (load_hybrid_node(&tp->nodes[i], pmu)) { hybrid_topology__delete(tp); return NULL; --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 98FE6C77B7A for ; Wed, 24 May 2023 22:20:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237736AbjEXWUg (ORCPT ); Wed, 24 May 2023 18:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237059AbjEXWTu (ORCPT ); Wed, 24 May 2023 18:19:50 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA9E1194 for ; Wed, 24 May 2023 15:19:29 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561eb6c66f6so17356307b3.0 for ; Wed, 24 May 2023 15:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966761; x=1687558761; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1xd01CL3jOJbGF1MdyCfHBtynZgthLa7uNIoTlZJdaI=; b=sfZwY4oHNiERT5Ej4VI2afyCtp6uICFBvoLiXGVvFrtLNuHnwLhezYlJn0HqZcp3zl TlU9iGhSmDyrtPStvmTlhj0KGIknmCK0GNmJeF7HQ7T59DIoQKUNx1L3xSizNhbJi6z1 O98VBZmY9BzuHjvQFQH8fBvB6merTovoP0+WNsaTQg2go7RVmFLHCsyR7uWAAeiX2qRd ivAHYJB6+sz3QnKQIJKskdj2lL8PZt1xgh5Jbh3L1MHi79jXMgtiag4hKUS3TN6pZxNe plmtCeuXG8x9hkON0EqRlH6fVi+JAFPWj2OQMiwW4B3araTSpJgGGFEydXRaIrR/WN4T zFSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966761; x=1687558761; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1xd01CL3jOJbGF1MdyCfHBtynZgthLa7uNIoTlZJdaI=; b=TiIhpP+PKUcZRdGDmBSJwIegUk/UsFsa/efFyVIPCoN2REXWaEUC+3nzvZBBol+4lE q6r1rxZJdljR7Z3njJNQY9ZGsoFHJVsg7yScaPhgS2cXkcmC2sMY+YMVhQpC8jxgac9a gTSLRqzEPx0QmcqxRIGMLXESbahM/sj5YykhMYTA1iwExZXiE0i1U9+EhI59Li49UE3S KqcEd0Fj7KyVEglLee9g9hTZ6UIcxTTrCY+QAhBabnaCJrxsOgoG4Ej7oKcK/KRa3RxJ PHH9HfqGnFtNJCknjf/Dr+egQm3ZH8hGc/CWnYvhblp50ZkMx5AB9ZmFls270QBkThJ9 E9Kw== X-Gm-Message-State: AC+VfDxIjrsGd2fNZhCpsio0kTM5RLJFSkj/GuePenEfo0P8j4DfHRai X5nGRKUobBmCpwucIJrhMsny3h9ZMPLP X-Google-Smtp-Source: ACHHUZ6bVQEXtGkTgDxBcWnN++oUxBK/vjzxL4GN/XJx3EK1ZxC+pTtG2hZQ11b/lDM9hIloqisUyeXjFTXR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:4523:0:b0:54f:646d:19c8 with SMTP id s35-20020a814523000000b0054f646d19c8mr12119291ywa.3.1684966761430; Wed, 24 May 2023 15:19:21 -0700 (PDT) Date: Wed, 24 May 2023 15:18:16 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-21-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 20/35] perf evsel: Compute is_hybrid from PMU being core From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Short-cut when has_hybrid is false, otherwise return if the evsel's PMU is core. Add a comment for the some what surprising no PMU cases of hardware and legacy cache events. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/evsel.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1df8f967d2eb..1c6e22e3f345 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -46,8 +46,8 @@ #include "memswap.h" #include "util.h" #include "util/hashmap.h" -#include "pmu-hybrid.h" #include "off_cpu.h" +#include "pmu.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" #include "util/bpf-filter.h" @@ -3132,9 +3132,17 @@ void evsel__zero_per_pkg(struct evsel *evsel) } } =20 +/** + * evsel__is_hybrid - does the evsel have a known PMU that is hybrid. Note= , this + * will be false on hybrid systems for hardware and leg= acy + * cache events. + */ bool evsel__is_hybrid(const struct evsel *evsel) { - return evsel->pmu_name && perf_pmu__is_hybrid(evsel->pmu_name); + if (!perf_pmu__has_hybrid()) + return false; + + return evsel->core.is_pmu_core; } =20 struct evsel *evsel__leader(const struct evsel *evsel) --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 42343C77B7C for ; Wed, 24 May 2023 22:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238006AbjEXWUl (ORCPT ); Wed, 24 May 2023 18:20:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237415AbjEXWTv (ORCPT ); Wed, 24 May 2023 18:19:51 -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 10B55E57 for ; Wed, 24 May 2023 15:19:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba83fed51adso2722048276.0 for ; Wed, 24 May 2023 15:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966763; x=1687558763; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2FXlJjlrAGttKZp5HRCBcxE0XLHUZdESbTdmHXPLxLA=; b=3yVSTrx8Mj/sAfPpyXcwtDmu1s8wS3BNQY4DcgjkHCjjNuG5f7fYODkaec1jAeMHbk 948ZhQzCP9ucuU/NerNvGaFaen9uEJ9nmi1II9/hV574vTT53wF27P20ZcAaG1RnwKqd yG7WaUiezHKd+3MJ07j64jrUuIouyvhnDapEvya2xXQiigMIxwHcdge2VsIWApiot4DT 4A4zchwqlLnhrSZuEE+VGXAl6UTB6it4E1cOg9G9rzLmozPXPgoF0pMaIZznyq/gStZn KFpBK1yug2lMGKgn8aEioYpAI/StTlSnDr/Z8lt6LIydmB0T/gUCyxzaS8JkJtXQRX64 XeOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966763; x=1687558763; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2FXlJjlrAGttKZp5HRCBcxE0XLHUZdESbTdmHXPLxLA=; b=CoAvVYx0ZmsbCcOVHxVFrzPYH3H/MwbWaxRcYjR6HLpIFLo2xOg1AiEHJH3O4EJNBV op7HLnkFJ2fM0pt037ZCLaJ3SY7DgULy7jgj/TrZwoTaDQF+zTigm9JQRKFJXXrEATxi O9fdNEafIdsslXIvvtelI2+t4CdL1GYX6AfrletQxwmcd+v0X4xotuf4g9NM+GuMrZLk DhXW/9TkQ6STwJmSMrJqfWSpF/xgjyw1npexVuPKqFci1SYosroKKUdxf5BBpFM8jVbD kHp9ogsHc++yJt6b9mv7OmK24iRJgI0cuw6yjk+7tkWYzU1UIcwaP7v+wJItcKAwIrhm GDpg== X-Gm-Message-State: AC+VfDwRNFQ90NMpBbRbV1QtiDiTwYj8qWPwP0QT9HYarJehP7ubWPVf J1OtXDG2UDapoWOrE5ZTg32UDZ1J2xhL X-Google-Smtp-Source: ACHHUZ4PfyjIYTN0Xg7UbZJBhh6EAlz+Yf/YFps+nRbKyTsxLZxmw/LJCUOuf9Y9hPOCl8LRyMul4sWoKjea X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a05:6902:b21:b0:bac:6d5a:f69f with SMTP id ch33-20020a0569020b2100b00bac6d5af69fmr554341ybb.10.1684966763374; Wed, 24 May 2023 15:19:23 -0700 (PDT) Date: Wed, 24 May 2023 15:18:17 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-22-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 21/35] perf header: Avoid hybrid PMU list in write_pmu_caps From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid perf_pmu__for_each_hybrid_pmu by iterating all PMUs are dumping the core ones. This will eventually allow removal of the hybrid PMU list. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/header.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 276870221ce0..e24cc8f316cd 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -51,7 +51,6 @@ #include "bpf-event.h" #include "bpf-utils.h" #include "clockid.h" -#include "pmu-hybrid.h" =20 #include #include @@ -1589,17 +1588,21 @@ static int write_pmu_caps(struct feat_fd *ff, * Write hybrid pmu caps first to maintain compatibility with * older perf tool. */ - pmu =3D NULL; - perf_pmu__for_each_hybrid_pmu(pmu) { - ret =3D __write_pmu_caps(ff, pmu, true); - if (ret < 0) - return ret; + if (perf_pmu__has_hybrid()) { + pmu =3D NULL; + while ((pmu =3D perf_pmu__scan(pmu))) { + if (!pmu->is_core) + continue; + + ret =3D __write_pmu_caps(ff, pmu, true); + if (ret < 0) + return ret; + } } =20 pmu =3D NULL; while ((pmu =3D perf_pmu__scan(pmu))) { - if (!pmu->name || !strcmp(pmu->name, "cpu") || - !pmu->nr_caps || perf_pmu__is_hybrid(pmu->name)) + if (pmu->is_core || !pmu->nr_caps) continue; =20 ret =3D __write_pmu_caps(ff, pmu, true); --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 D9D1AC77B7A for ; Wed, 24 May 2023 22:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237617AbjEXWUs (ORCPT ); Wed, 24 May 2023 18:20:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236857AbjEXWTz (ORCPT ); Wed, 24 May 2023 18:19:55 -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 4B4771A2 for ; Wed, 24 May 2023 15:19:37 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba88ec544ddso3169932276.1 for ; Wed, 24 May 2023 15:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966765; x=1687558765; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LP27CftfdHYnLweWt0lX22v4lNIGIpmQh1ljDLrV4jA=; b=lYADs1VbYR/2zJtQXymNcu0XOzeLjuk2kW8pz8OEiHhfvUHQJh2Atn4PtH+6mAx8FM iYs86lOXb4OVWuHjuhHOXgtWOs9oKpr9ezh6cskrIOHTv/UssX/i7dMlopbgunerspC7 h2/ymCj6IQ/Lrk9hfyUloxKOsD5s3zG0Iygd+8lhERAnPDD8++D5i7HBtkpxEJ4iC1rg vNCLff8bwWgFpYXRO1lDLFJ/rNciZmDSrji6mjomGnYqBHisbvWLkfnYTBqQ+3K5Naa0 Cvf9AHBTpz+hi/c1c3jRw2tjeSUq3nv8Qm25Ek5YlVHftKpKiDk4+oTPtNBHD0srlDeB Maig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966765; x=1687558765; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LP27CftfdHYnLweWt0lX22v4lNIGIpmQh1ljDLrV4jA=; b=iu4n9B09z+183nKDafMlpDHna7lWEuPTO5D3bvi+PP0tQvu9Wmg3fqHErfIoMYRB/g ml+P4moLWQ0WXzGxRaj87H0IDXyiqP+XbsOj7et9IbsyxG6MRpie/8O2tE1gdi/r9qcf lFolDE3O5zoJU/WdqO8R6IevTN3IPugOv7EgsBd3/E3m4PwZqJ1WQD+zbM8iWodBn3Um dYwqIZUnlirIwJFVn4pdxO4omuAb9DOZ1R4+xOOBeZU5stWNj8FrLBeOAUThqywA25nU owZexv5gmrTOorRrQNrd39msUzXPYRgACZui7w7V6zxfmf59MS/ktf9GqtKGQg7SnxZy FXGQ== X-Gm-Message-State: AC+VfDxyGM2qs4PQAXrx/0XE5Q378OhyypdXI7PJDszfT83MYfEddpz9 1epX35yMuYNHKPiZ3XpwstpPkYvYBL/u X-Google-Smtp-Source: ACHHUZ665i5nk9ovpEFzjxU1ohjxl63X2v7RPNE5lzH+XoYby7ipz6hZU7xMBGBWZkIBZfe03YbJ3muJ6Bn0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a5b:b45:0:b0:ba8:939b:6574 with SMTP id b5-20020a5b0b45000000b00ba8939b6574mr756838ybr.12.1684966765640; Wed, 24 May 2023 15:19:25 -0700 (PDT) Date: Wed, 24 May 2023 15:18:18 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-23-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 22/35] perf metrics: Remove perf_pmu__is_hybrid use From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from perf_pmu__is_hybrid to avoid implicitly using the hybrid PMU list. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/metricgroup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 7de721e9d895..72583f62eda8 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -11,7 +11,6 @@ #include "evsel.h" #include "strbuf.h" #include "pmu.h" -#include "pmu-hybrid.h" #include "print-events.h" #include "smt.h" #include "expr.h" @@ -274,7 +273,7 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, const char *metric_id; struct evsel *ev; size_t ids_size, matched_events, i; - bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmu__is_hybrid(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmu__has_hybrid() || !is_p= mu_hybrid(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); @@ -288,8 +287,7 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, struct expr_id_data *val_ptr; =20 /* Don't match events for the wrong hybrid PMU. */ - if (!all_pmus && ev->pmu_name && - perf_pmu__is_hybrid(ev->pmu_name) && + if (!all_pmus && ev->pmu_name && evsel__is_hybrid(ev) && strcmp(ev->pmu_name, pmu)) continue; /* --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 CE7DBC77B7A for ; Wed, 24 May 2023 22:20:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238097AbjEXWUw (ORCPT ); Wed, 24 May 2023 18:20:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237596AbjEXWT5 (ORCPT ); Wed, 24 May 2023 18:19:57 -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 CF7AA10F9 for ; Wed, 24 May 2023 15:19:40 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba88ec544ddso3170011276.1 for ; Wed, 24 May 2023 15:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966768; x=1687558768; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xohs+RPxgQPJo1czRcXVjEN6Ep07r6+wQ3n8ob7tftg=; b=IgfaH00zw1PRDkqwd/QwU4Sg5TJxQ7feV/pDX0v7A7dRzdpe13pLIG6GaS/JKXqvvg ev2dtZc04e9KWDyVr2G86au0saClF58Kh2k5UqyhLSFrZRim46pA8475WEW10d+nK7Q8 AuJ5Qrusdz12jpgCcZCwhMqm6k5meHHrATRSwUpNhDNhVd1uq/as7AANV0NTOK0sIDaC ylyZNhgvKKWdgx6eILUv8tsxyqBsW3CbkhNkI5BgQ5mVc2/sMQtqHzkp55NEtG97JRyE PCuklBhHC8GBSKDKsBZoIfEtwM9VGUpouwsQJY4fCBgYF5Cb9M3ZTxkWD9/qm6+pKPCH 27CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966768; x=1687558768; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xohs+RPxgQPJo1czRcXVjEN6Ep07r6+wQ3n8ob7tftg=; b=IJdtf2I5Z+6o6yXj4Vh6/L6j9MeV4TjAZr9iDxqOA2ywwCuuytzInGjcGBiUiVgBkO wEebvV600nA+CdRTU/pYTKXC83hRcjtXKeYZP8lg7se/Z8CHE5SEPfAETrxlpmefjREe j3FI+9CXsUJHszUE4YcYCY0JoEfwWV988c+gx+H2sTNNgDydkcFr7U8cnWml/q+zo4ke ABTwwA89gNB4uGbIP/KZzugHwP6O0Avur0TbMcvoiFJVZRGhkg0hTRVSbYxxQa8fIlKL QXpOtMjSAiNSwroV1t6H9jsDJN/UKiifFJvqCgS60ZOT1V0SB/UGw/hhKSY/jtLO+j24 IHxg== X-Gm-Message-State: AC+VfDz/AU8dUzAjdeMibObxzzUKkMOUbDySQ7bzfhqMVPSAbSkjos8E u/SfnJ9jI/ADxDnONGb2zbF6en7rNa41 X-Google-Smtp-Source: ACHHUZ74qT7vuVNsbtmSv30uJE6ZkJtddOJ2ysembhatAzi/XHx184YwKBpC20/oi8O5XKcLYnGlaUmTM7AH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a05:6902:4ca:b0:ba8:84fb:6ad with SMTP id v10-20020a05690204ca00b00ba884fb06admr789426ybs.4.1684966767759; Wed, 24 May 2023 15:19:27 -0700 (PDT) Date: Wed, 24 May 2023 15:18:19 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-24-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 23/35] perf stat: Avoid hybrid PMU list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmu__is_hybrid implicitly uses the hybrid PMU list. Instead return false if hybrid isn't present, if it is then see if any evsel's PMUs are core. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/stat-display.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ede0477d958a..78ce7095dbcb 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -19,7 +19,7 @@ #include #include "util.h" #include "iostat.h" -#include "pmu-hybrid.h" +#include "pmu.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,11 +680,12 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; =20 + if (!perf_pmu__has_hybrid()) + return false; + evlist__for_each_entry(evlist, evsel) { - if (evsel->pmu_name && - perf_pmu__is_hybrid(evsel->pmu_name)) { + if (evsel->core.is_pmu_core) return true; - } } =20 return false; --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 BC799C77B7C for ; Wed, 24 May 2023 22:21:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237916AbjEXWVF (ORCPT ); Wed, 24 May 2023 18:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234015AbjEXWU3 (ORCPT ); Wed, 24 May 2023 18:20:29 -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 BB2761711 for ; Wed, 24 May 2023 15:19:44 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb76a9831so2835862276.2 for ; Wed, 24 May 2023 15:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966770; x=1687558770; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/wfJ/y0HTXpP4SfThXWLklmlTbbjNt14J5e/cCO34dg=; b=M/5LKeZsS4Join3b/N5o6PtajiBLqms83/4Mg/i9sUlIxdRAMOlgGeShcs7f0zn9+6 9m0jZ9d+614Klo2TUlv1UW/82rTEO6fPxhi0PWMzyEgoCEb54VA/tY1RkfNBPB7SDnBB wxB/HdoAslerbOD5a67EB0p6Wvw5JMGR4lYQQl8eoy+LTHqfMIq0r3PsmpNWW5ka4nMe iCHfEeLIULrVHjr2WqvFikaZXCA5YrikMy884vYw+eOm3Tlq3LSVttTjOLVmVR7GseiB YPfQAr82fT1ufBvYh0eIgGyt2L7ivZBCdJpn2ejnbXCW7nHgvhG4fg50R2epB4W4wSqW zuYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966770; x=1687558770; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/wfJ/y0HTXpP4SfThXWLklmlTbbjNt14J5e/cCO34dg=; b=WQOOxwoyvQYtv/e86hycDfth8Gq4xvQnzepF8UjviSs1H9SEegf/HF7H4EANT7kO8M MQGbkRoo0T5bOT01FrBcZBDYpnwFNcW03tjK+2zKPcxa5q46VaWw22MI2mCeZB5lTvkR ueRSGjh7N+U8PUrsJixJ5D3xvDhVuTeR2I23EGlMkuK48VqASlDXBrMJAga/PH/CAiQ+ fRj8ew0SSw9C/GQvZLPGf8GycChyUingZZ+VUQlM+iIcXTNIGGt6RVZO2EknxhWjOzxp 0399QdD91q+dh5RaNVlT9UrUfIFqlKFAiRUegYvFIRa6eYK8/d5LJx6ZqoauJ1c4wLk2 VgcA== X-Gm-Message-State: AC+VfDy3cDWt69pIB5ij0yMvK1tOl9vOyVjs8XsG2RCGpkXjEVdQxMXr GfJy5HDdBHUD2jvXRPEMrlh5IPK0+Rdq X-Google-Smtp-Source: ACHHUZ4sXK5s0yERreneq9mdtnEvAqW6QA0zbmcOGvUusUrlV8hiTT2jVHqi7N3SONXjS0akNs4cu3eJ9/j+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:db47:0:b0:ba8:6148:4300 with SMTP id g68-20020a25db47000000b00ba861484300mr577608ybf.6.1684966770047; Wed, 24 May 2023 15:19:30 -0700 (PDT) Date: Wed, 24 May 2023 15:18:20 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-25-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 24/35] perf mem: Avoid hybrid PMU list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_pmu__num_mem_pmus that scans/counts the number of PMUs for mem events. Switch perf_pmu__for_each_hybrid_pmu to iterating all PMUs and only handling is_core ones. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-c2c.c | 7 ++----- tools/perf/builtin-mem.c | 7 ++----- tools/perf/util/mem-events.c | 20 ++++++++++++++------ tools/perf/util/pmu.c | 17 +++++++++++++++++ tools/perf/util/pmu.h | 1 + 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 08455e26b606..2757ccc19c5e 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -42,7 +42,6 @@ #include "ui/ui.h" #include "ui/progress.h" #include "pmu.h" -#include "pmu-hybrid.h" #include "string2.h" #include "util/util.h" =20 @@ -3259,10 +3258,8 @@ static int perf_c2c__record(int argc, const char **a= rgv) argc =3D parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); =20 - if (!perf_pmu__has_hybrid()) - rec_argc =3D argc + 11; /* max number of arguments */ - else - rec_argc =3D argc + 11 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support = them. */ + rec_argc =3D argc + 11 * perf_pmu__num_mem_pmus(); =20 rec_argv =3D calloc(rec_argc + 1, sizeof(char *)); if (!rec_argv) diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index 65465930ef8e..f4f1ff76d49d 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -18,7 +18,6 @@ #include "util/map.h" #include "util/symbol.h" #include "util/pmu.h" -#include "util/pmu-hybrid.h" #include "util/sample.h" #include "util/string2.h" #include "util/util.h" @@ -93,10 +92,8 @@ static int __cmd_record(int argc, const char **argv, str= uct perf_mem *mem) argc =3D parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); =20 - if (!perf_pmu__has_hybrid()) - rec_argc =3D argc + 9; /* max number of arguments */ - else - rec_argc =3D argc + 9 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support = them. */ + rec_argc =3D argc + 9 * perf_pmu__num_mem_pmus(); =20 if (mem->cpu_list) rec_argc +=3D 2; diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index ed1ee4b05356..c9e422a38258 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -13,7 +13,6 @@ #include "debug.h" #include "symbol.h" #include "pmu.h" -#include "pmu-hybrid.h" =20 unsigned int perf_mem_events__loads_ldlat =3D 30; =20 @@ -120,7 +119,6 @@ int perf_mem_events__init(void) =20 for (j =3D 0; j < PERF_MEM_EVENTS__MAX; j++) { struct perf_mem_event *e =3D perf_mem_events__ptr(j); - struct perf_pmu *pmu; char sysfs_name[100]; =20 /* @@ -135,7 +133,12 @@ int perf_mem_events__init(void) e->sysfs_name, "cpu"); e->supported =3D perf_mem_event__supported(mnt, sysfs_name); } else { - perf_pmu__for_each_hybrid_pmu(pmu) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); @@ -170,9 +173,12 @@ static void perf_mem_events__print_unsupport_hybrid(st= ruct perf_mem_event *e, { const char *mnt =3D sysfs__mount(); char sysfs_name[100]; - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; =20 - perf_pmu__for_each_hybrid_pmu(pmu) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); if (!perf_mem_event__supported(mnt, sysfs_name)) { @@ -210,7 +216,9 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (!pmu->is_core) + continue; rec_argv[i++] =3D "-e"; s =3D perf_mem_events__name(j, pmu->name); if (s) { diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 821cdd79db48..12446f63d1b3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1673,6 +1673,23 @@ bool perf_pmu__auto_merge_stats(const struct perf_pm= u *pmu) return !is_pmu_hybrid(pmu->name); } =20 +static bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) +{ + return pmu->is_core; +} + +int perf_pmu__num_mem_pmus(void) +{ + struct perf_pmu *pmu =3D NULL; + int count =3D 0; + + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + if (perf_pmu__is_mem_pmu(pmu)) + count++; + } + return count; +} + static bool pmu_alias_is_duplicate(struct sevent *alias_a, struct sevent *alias_b) { diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index af10d137e2b5..5f5de7c20ab6 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -231,6 +231,7 @@ bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); +int perf_pmu__num_mem_pmus(void); void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state); bool pmu_have_event(const char *pname, const char *name); =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 47A8CC77B7A for ; Wed, 24 May 2023 22:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237977AbjEXWVJ (ORCPT ); Wed, 24 May 2023 18:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236692AbjEXWUd (ORCPT ); Wed, 24 May 2023 18:20:33 -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 C8816E69 for ; Wed, 24 May 2023 15:19:50 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb5e91ab4so2931976276.0 for ; Wed, 24 May 2023 15:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966772; x=1687558772; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=a6taGAsuRUZNNlfmTueUaSzwpbmizvV1tsVG1sacRHQ=; b=aLHieteVM59/jfF+zT9UAD6nXuFByztQxXY9T1ueT4vVv0zaJAH7Y2Qq1+voD20jfg T3q9lfDpNykjST8+Ubtyh+uAFrzOCAbTMzaUY4dPlU9n5bZsvyIJRsMORWxMM7V+hAfU kitwaJ3DkRzG+xljHUznqNjBVdADH+mo/Z1hvCC+xUsy7JOldru37a1IjGyZ5iM5Hxnf /IPItkCcX6N/TakUDD6RCpyDQUt8eQ0x5Mn3z4qe84SSn54qgNhNUGGbWmbRQLThVu1H RpNA5WP7t8D5eaWjKqojokKHTF3TJudlndfR3FMTag1oUyLpvzLaLuTV/VmHW3ADo83B clZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966772; x=1687558772; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a6taGAsuRUZNNlfmTueUaSzwpbmizvV1tsVG1sacRHQ=; b=L2tre87m1CfppOeXLWli7/+2eRyjTMRvyFd2Agh8pY1m9gPWmiW4YTG+byOYburlz7 KstIyhbruMjF74IYjZKmcN6f4YL+/MDeGBqhMg/fuTKBsWExlahC1Ztv2PQDvpsuhtLO HXtUTYV7Swdu3k45AkrGquhVlowSgKN6uKMo780Qep1vQU6gmI2DdVxckoCFu+wfhuKB Eg1eBAToikud+WvcZZ4Og+ygYGHUKRHsrX9wzFSjFhYk9WneahMIlSyxpK7GFmIExuBJ JxX2vp/sKFQ1LydYyUieZF7Zz+nKYzHkwneJgFxUxYVMM9wnEWNwSqwwJla+R8fGGC+f Jvqg== X-Gm-Message-State: AC+VfDyBL81ldAT2ecZeyDdYgK9KsFhu8muzGKZublUIPYlkGNHeIlXW R+6GRUaPfbEEWgvtMGFugZ334liCx9oE X-Google-Smtp-Source: ACHHUZ7mltbDViAiAbhpjxYBrIhENa03TRP7my9wrpYDBzhEgBy0Y+fK9QOpyt6T7RQ0fSMa5vSPBU/j2e4m X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:c5c4:0:b0:bab:a1e6:c882 with SMTP id v187-20020a25c5c4000000b00baba1e6c882mr802148ybe.1.1684966772300; Wed, 24 May 2023 15:19:32 -0700 (PDT) Date: Wed, 24 May 2023 15:18:21 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-26-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 25/35] perf pmu: Remove perf_pmu__hybrid_pmus list From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than iterate hybrid PMUs, inhererently Intel specific, iterate all PMUs checking whether they are core. To only get hybrid cores, first call perf_pmu__has_hybrid. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/builtin-record.c | 1 - tools/perf/util/Build | 1 - tools/perf/util/pmu-hybrid.c | 39 ------------------------------ tools/perf/util/pmu-hybrid.h | 29 ---------------------- tools/perf/util/pmu.c | 7 ------ tools/perf/util/pmu.h | 2 -- tools/perf/util/print-events.c | 1 - tools/perf/util/python-ext-sources | 1 - 8 files changed, 81 deletions(-) delete mode 100644 tools/perf/util/pmu-hybrid.c delete mode 100644 tools/perf/util/pmu-hybrid.h diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index e30e8d6a6575..2abcad2998f6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -49,7 +49,6 @@ #include "util/util.h" #include "util/pfm.h" #include "util/clockid.h" -#include "util/pmu-hybrid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" #include "asm/bug.h" diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 21e4cdcba504..0d68be51a739 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -73,7 +73,6 @@ perf-y +=3D pmu.o perf-y +=3D pmus.o perf-y +=3D pmu-flex.o perf-y +=3D pmu-bison.o -perf-y +=3D pmu-hybrid.o perf-y +=3D svghelper.o perf-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o perf-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c deleted file mode 100644 index 7fe943dd3217..000000000000 --- a/tools/perf/util/pmu-hybrid.c +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fncache.h" -#include "pmu-hybrid.h" - -LIST_HEAD(perf_pmu__hybrid_pmus); - -static struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name) -{ - struct perf_pmu *pmu; - - if (!name) - return NULL; - - perf_pmu__for_each_hybrid_pmu(pmu) { - if (!strcmp(name, pmu->name)) - return pmu; - } - - return NULL; -} - -bool perf_pmu__is_hybrid(const char *name) -{ - return perf_pmu__find_hybrid_pmu(name) !=3D NULL; -} diff --git a/tools/perf/util/pmu-hybrid.h b/tools/perf/util/pmu-hybrid.h deleted file mode 100644 index 8dbcae935020..000000000000 --- a/tools/perf/util/pmu-hybrid.h +++ /dev/null @@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __PMU_HYBRID_H -#define __PMU_HYBRID_H - -#include -#include -#include -#include -#include "pmu.h" - -extern struct list_head perf_pmu__hybrid_pmus; - -#define perf_pmu__for_each_hybrid_pmu(pmu) \ - list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) - -bool perf_pmu__is_hybrid(const char *name); - -static inline int perf_pmu__hybrid_pmu_num(void) -{ - struct perf_pmu *pmu; - int num =3D 0; - - perf_pmu__for_each_hybrid_pmu(pmu) - num++; - - return num; -} - -#endif /* __PMU_HYBRID_H */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 12446f63d1b3..62cd795e2fd3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -32,7 +32,6 @@ #include "string2.h" #include "strbuf.h" #include "fncache.h" -#include "pmu-hybrid.h" #include "util/evsel_config.h" =20 struct perf_pmu perf_pmu__fake; @@ -967,11 +966,6 @@ static struct perf_pmu *pmu_lookup(int dirfd, const ch= ar *lookup_name) list_splice(&aliases, &pmu->aliases); list_add_tail(&pmu->list, &pmus); =20 - if (!strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom")) - list_add_tail(&pmu->hybrid_list, &perf_pmu__hybrid_pmus); - else - INIT_LIST_HEAD(&pmu->hybrid_list); - pmu->default_config =3D perf_pmu__get_default_config(pmu); =20 return pmu; @@ -2144,7 +2138,6 @@ void perf_pmu__destroy(void) =20 list_for_each_entry_safe(pmu, tmp, &pmus, list) { list_del(&pmu->list); - list_del(&pmu->hybrid_list); =20 perf_pmu__delete(pmu); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 5f5de7c20ab6..cb51ad6e40fa 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -119,8 +119,6 @@ struct perf_pmu { struct list_head caps; /** @list: Element on pmus list in pmu.c. */ struct list_head list; - /** @hybrid_list: Element on perf_pmu__hybrid_pmus. */ - struct list_head hybrid_list; =20 /** * @missing_features: Features to inhibit when events on this PMU are diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 69492cbd6921..8d823bc906e6 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -26,7 +26,6 @@ #include "strlist.h" #include "tracepoint.h" #include "pfm.h" -#include "pmu-hybrid.h" #include "thread_map.h" =20 #define MAX_NAME_LEN 100 diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ex= t-sources index aa5156c2bcff..d4c9b4cd35ef 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -39,5 +39,4 @@ util/affinity.c util/rwsem.c util/hashmap.c util/perf_regs.c -util/pmu-hybrid.c util/fncache.c --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 5BACCC7EE2C for ; Wed, 24 May 2023 22:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238036AbjEXWUp (ORCPT ); Wed, 24 May 2023 18:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237763AbjEXWTx (ORCPT ); Wed, 24 May 2023 18:19:53 -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 07A3D10EC for ; Wed, 24 May 2023 15:19:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba81b24b8a4so1861216276.2 for ; Wed, 24 May 2023 15:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966774; x=1687558774; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=e3QTDmJoeAun/x66qVBqgKH7fCw3cWk6avEC85L7N9Cg8LlgXzAtlioNM7cjPnq1gY a4SWY0Ah5jhpHg9uI5KbifN8N8KX8O8ZwDxTX7fDdgfY4LtKi9vRQKdi3KpOfuPyei/V +0VYoyOigrLvJBZVgHiG7ICrKnWrURTSkfMMJ1hsXfC5zlCmh/ZbIy/Xy6i/SWP6IXaw fN/r6zDvDBu9AHTBmLQfQYFqiG7nCrMRCOMAFvbA6aTyTqlH4XXAuo9AaU9JRDE0Ym3q UKF3Pgqjupvk7wL5YSz8RpDHbO5wh0h1ppMymLaIyJideR1C3C96K8H/eGGLsplQXWu4 PBSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966774; x=1687558774; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XP34/lTHk88aGi5g16tiqPPlFvPYUI/7slAn7kxjnhU=; b=anqUCr2txO+G70utR2BJ9AO4MmhK9kFOJM/niOphQSUvt+ziDwzAZ1zUBjO90nWRaF lERBSH/Vh2kJB5NXuwHvxK//RsBTUPiwTwNU1YJ3ptN2Pcx4PHUeeEtNSSs0A0jvJtDU cJVPFBVh67v1Fb7pRpYKCdLhGcBrBabjC1r6I7tDZWgjFmCcq5V1odzhy+5ok9Y/Y8O+ isplz+YxZWU1s3jaaxW6BPKrZk8wTI9LFtkOf8iqV+QCRTYD4YcEzSNjMrF6/UGo5xdC MfQYQlT4kfue0GU/mzuQNpvJEIkgC7cDbpz/rrpOqe1pTSsf1pdsivlH/WB6nv8izB+f jdzw== X-Gm-Message-State: AC+VfDyjF7MdgYz+ai0pvm3kxMaSYCguRyn9P/ZQo0RjnKZQtt3Tg2lJ pOHFHghbFFMfhs9B86wlRPsa9k4AWQsc X-Google-Smtp-Source: ACHHUZ7D9drqIRB2MyurLXcxiCePzmUOMC9VFsJ8EjeKLTVsgpR53rwm2NFY69hSSmDfa3llKWHekDfBwYID X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a5b:c03:0:b0:ba8:5bc9:80fe with SMTP id f3-20020a5b0c03000000b00ba85bc980femr795184ybq.1.1684966774678; Wed, 24 May 2023 15:19:34 -0700 (PDT) Date: Wed, 24 May 2023 15:18:22 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-27-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 26/35] perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmus__for_each_pmu doesn't lazily initialize pmus making its use error prone. Just use perf_pmu__scan as this only impacts non-performance critical tests. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/bench/pmu-scan.c | 6 ++---- tools/perf/tests/event_groups.c | 7 ++----- tools/perf/tests/parse-events.c | 11 ++++------- tools/perf/util/pmus.h | 2 -- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f0f007843bb8..f4a6c37cbe27 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -40,13 +40,11 @@ static struct pmu_scan_result *results; =20 static int save_result(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; struct list_head *list; struct pmu_scan_result *r; =20 - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { r =3D realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r =3D=3D NULL) return -ENOMEM; diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_group= s.c index 029442b4e9c6..3d9a2b524bba 100644 --- a/tools/perf/tests/event_groups.c +++ b/tools/perf/tests/event_groups.c @@ -50,13 +50,10 @@ static int event_open(int type, unsigned long config, i= nt group_fd) =20 static int setup_uncore_event(void) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int i, fd; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { for (i =3D 0; i < NR_UNCORE_PMUS; i++) { if (!strcmp(uncore_pmus[i].name, pmu->name)) { pr_debug("Using %s for uncore pmu event\n", pmu->name); diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 72a10bed84fd..277607ede060 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -108,11 +108,11 @@ static int test__checkevent_raw(struct evlist *evlist) TEST_ASSERT_VAL("wrong number of entries", 0 !=3D evlist->core.nr_entries= ); =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched =3D true; @@ -2243,13 +2243,10 @@ static int test__terms2(struct test_suite *test __m= aybe_unused, int subtest __ma =20 static int test__pmu_events(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) { - struct perf_pmu *pmu; + struct perf_pmu *pmu =3D NULL; int ret =3D TEST_OK; =20 - if (list_empty(&pmus)) - perf_pmu__scan(NULL); - - perf_pmus__for_each_pmu(pmu) { + while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { struct stat st; char path[PATH_MAX]; struct dirent *ent; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index d475e2960c10..257de10788e8 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -5,8 +5,6 @@ extern struct list_head pmus; struct perf_pmu; =20 -#define perf_pmus__for_each_pmu(pmu) list_for_each_entry(pmu, &pmus, list) - const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 #endif /* __PMUS_H */ --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 4B784C77B7C for ; Wed, 24 May 2023 22:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236302AbjEXWVZ (ORCPT ); Wed, 24 May 2023 18:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238100AbjEXWVD (ORCPT ); Wed, 24 May 2023 18:21:03 -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 8B116E4D for ; Wed, 24 May 2023 15:20:06 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56552a72cfbso29697447b3.3 for ; Wed, 24 May 2023 15:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966777; x=1687558777; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d/uSoOkKrLV2P01KOT7/05nAwNtg1NZmOZIVSrGqD1k=; b=AnKvdlUdQjQEEAq6HeZq7zmB6gXv01G0cNNgNxVh13Iy+L8MK0uM/sSyX8zOpVJzzj LtvtAjrsF6ZUkNcumXtEBBqhAtaTXivZg5uh9HUG3ggoCvT1KBDP5u6fGhM2uPhybH+0 IRPtuFglOvFjuOWq6/CbvzlITCjdA4TyXBPz19kXSoq7VcI4CYMwdBQxFdBnjnbjoL6P LxSPLWqi5o7mHIUqLRxbYbRi/kTwfvbWyjhyeaTnIYhge/LAYfV6+KLEKMuPY3zpQM0A 43v2qjCsMWYwXQDEQ08GdcQRHh9y9JvpJizhR5eGNt/mVktDaKoGL7OMDri5nQHfF3mJ WXgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966777; x=1687558777; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d/uSoOkKrLV2P01KOT7/05nAwNtg1NZmOZIVSrGqD1k=; b=LNYk+YepakPkNyFFthR0KAyqMLRb0Wc7ZsmEaS2guDevjYLNOhOCLyoIF6dfFps9iy MclMWQgo+FRVaqBFXafw0wmbjc9xJ5GFKG30eba6DocPVQvI/NPf3rfw/HTFFPhJQYV1 GtkJFrMyQf/facvsL0mFbYRwcD8MgBkDC4BexkqCiT+4qPZdy6LjtzuCMa8lR4DJap55 rskwOIBICk6bt/OPws5vQEFiGsvnYFbS5ym4Wcj3SP1PMSuX6XUNAoYYx6EYZIJe8keD 773ycPN8yTSRaIIUCg/3luiOGF2FPv457sC8m6Bz/e5NRF7S8vJEmORiG+ccsEGBD/I9 GGXA== X-Gm-Message-State: AC+VfDxab2bLCK9xBJNgMc3nYcc1G8S+8exoqcAMduFQBMLRN/LiVid1 1AWzaPnu96SKY2Bfpb63VPe6z91HDsJw X-Google-Smtp-Source: ACHHUZ7sEtK0LR8WwQQK9cpyIqNh6Pc7ybEP8C6sxaWdG4+eXpOeGFVug3xou45ngKes3xW1FpxdzJYoO/4m X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:441b:0:b0:55d:9484:f153 with SMTP id r27-20020a81441b000000b0055d9484f153mr11963093ywa.7.1684966777192; Wed, 24 May 2023 15:19:37 -0700 (PDT) Date: Wed, 24 May 2023 15:18:23 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-28-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 27/35] perf x86 mem: minor refactor to is_mem_loads_aux_event From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Find the PMU and then the event off of it. Reviewed-by: Kan Liang Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/mem-events.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/ut= il/mem-events.c index f683ac702247..02d65e446f46 100644 --- a/tools/perf/arch/x86/util/mem-events.c +++ b/tools/perf/arch/x86/util/mem-events.c @@ -55,13 +55,13 @@ struct perf_mem_event *perf_mem_events__ptr(int i) =20 bool is_mem_loads_aux_event(struct evsel *leader) { - if (perf_pmu__find("cpu")) { - if (!pmu_have_event("cpu", "mem-loads-aux")) - return false; - } else if (perf_pmu__find("cpu_core")) { - if (!pmu_have_event("cpu_core", "mem-loads-aux")) - return false; - } + struct perf_pmu *pmu =3D perf_pmu__find("cpu"); + + if (!pmu) + pmu =3D perf_pmu__find("cpu_core"); + + if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + return false; =20 return leader->core.attr.config =3D=3D MEM_LOADS_AUX; } --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 44294C77B7C for ; Wed, 24 May 2023 22:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238023AbjEXWVn (ORCPT ); Wed, 24 May 2023 18:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237470AbjEXWVS (ORCPT ); Wed, 24 May 2023 18:21:18 -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 4A4B21731 for ; Wed, 24 May 2023 15:20:18 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba69d93a6b5so2909349276.1 for ; Wed, 24 May 2023 15:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966780; x=1687558780; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PVZ+W72Mlc+ZBYcTa78jTLswCvcz/Ng3wAPDKo3/ljE=; b=yUOvdoYKdbiXvRE6PmHPILo6TBdGjxmc9omrfSWVpqaDPEU/g2yFWZS7Pc7aQEF0ps c0o0rkXp1C47Kc4y55UcAfwM1PRT0gaKq0KXd/ZjKDVU4BQtB5GJkziW3MB8m/nKIm97 3lXT37VOiLvkdvwEREwqzrDAJku9KHMrqoeYe6GDoZ20MlFMAxoqNL2HKJg5hIH0wugP C9WIH7KF/6/piWQuiKc0WikcW5H0O+63nuPNE+XXXF2BACPCMg5NCbS7fdxuCGZXZp21 fo5JaQWmgVK3YETnXW7dXeg496O532Gsxxb8mE7avgG2BUln6poXV4ps7kaWJTXcsMcm /HWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966780; x=1687558780; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PVZ+W72Mlc+ZBYcTa78jTLswCvcz/Ng3wAPDKo3/ljE=; b=VOHUWbxkGxtCIGQ5kiMpy6NbNR/VX9MOC3xEDuFicZGNx7mdahzO2DKrnZ2b5k+sjd IQlBwQOgdhmkSJqihiumMgU9DUiF7JTkf2kVr0O0Kpp+4fwU3FEV3MQcmO/XTlrjTCje gMbHoE1RjWtuGu50qxuK+H0MlRjiUst7er+LBDjf8kuEhqEnAq8yDKqb3idpaHpQtf5g 0GdON7HpX17xkLTsV8uMhxb7JOmnt2kUj7ktbyeCW70uJ6SaTTmvMPVVmkz5+wKc+EpD Iyp3lvwSAZNgE7dPeVc9uDvjN+fZXb6juBmQmYlWM/GYwfZvawM502rZnXMmxIvqZjw+ coQw== X-Gm-Message-State: AC+VfDxXTGZjZKN5SUQX7IcVQHWVfklIKXuQHE5oQfJG1aRDMvq32oUH qwQ2ZOfGhzM8oSSN7BUWtPAvRibSH8PZ X-Google-Smtp-Source: ACHHUZ5sscjBfrbafSxu5WuB9T3Plhz8EjCrwmCJng9cGIMIYlAOZuK+MZ2ruOMDFIwHHuMt0J6MGnhE3IUg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:c014:0:b0:ba8:457d:1f22 with SMTP id c20-20020a25c014000000b00ba8457d1f22mr759324ybf.9.1684966779781; Wed, 24 May 2023 15:19:39 -0700 (PDT) Date: Wed, 24 May 2023 15:18:24 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-29-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 28/35] perf pmu: Separate pmu and pmus From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Separate and hide the pmus list in pmus.[ch]. Move pmus functionality out of pmu.[ch] into pmus.[ch] renaming pmus functions which were prefixed perf_pmu__ to perf_pmus__. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/arm/util/auxtrace.c | 7 +- tools/perf/arch/arm/util/cs-etm.c | 4 +- tools/perf/arch/arm64/util/pmu.c | 3 +- tools/perf/arch/x86/tests/hybrid.c | 5 +- tools/perf/arch/x86/util/auxtrace.c | 5 +- tools/perf/arch/x86/util/evlist.c | 5 +- tools/perf/arch/x86/util/evsel.c | 7 +- tools/perf/arch/x86/util/intel-bts.c | 4 +- tools/perf/arch/x86/util/intel-pt.c | 4 +- tools/perf/arch/x86/util/mem-events.c | 9 +- tools/perf/arch/x86/util/perf_regs.c | 5 +- tools/perf/arch/x86/util/topdown.c | 5 +- tools/perf/bench/pmu-scan.c | 10 +- tools/perf/builtin-c2c.c | 4 +- tools/perf/builtin-list.c | 4 +- tools/perf/builtin-mem.c | 4 +- tools/perf/builtin-record.c | 6 +- tools/perf/builtin-stat.c | 4 +- tools/perf/tests/attr.c | 4 +- tools/perf/tests/event_groups.c | 2 +- tools/perf/tests/parse-events.c | 8 +- tools/perf/tests/parse-metric.c | 4 +- tools/perf/tests/pmu-events.c | 3 +- tools/perf/tests/switch-tracking.c | 4 +- tools/perf/tests/topology.c | 4 +- tools/perf/util/cputopo.c | 7 +- tools/perf/util/env.c | 5 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.c | 15 +- tools/perf/util/mem-events.c | 11 +- tools/perf/util/metricgroup.c | 5 +- tools/perf/util/parse-events.c | 15 +- tools/perf/util/parse-events.y | 3 +- tools/perf/util/pfm.c | 6 +- tools/perf/util/pmu.c | 411 +------------------------- tools/perf/util/pmu.h | 13 +- tools/perf/util/pmus.c | 396 ++++++++++++++++++++++++- tools/perf/util/pmus.h | 14 +- tools/perf/util/print-events.c | 5 +- tools/perf/util/stat-display.c | 3 +- 40 files changed, 531 insertions(+), 505 deletions(-) diff --git a/tools/perf/arch/arm/util/auxtrace.c b/tools/perf/arch/arm/util= /auxtrace.c index adec6c9ee11d..3b8eca0ffb17 100644 --- a/tools/perf/arch/arm/util/auxtrace.c +++ b/tools/perf/arch/arm/util/auxtrace.c @@ -14,6 +14,7 @@ #include "../../../util/debug.h" #include "../../../util/evlist.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "cs-etm.h" #include "arm-spe.h" #include "hisi-ptt.h" @@ -40,7 +41,7 @@ static struct perf_pmu **find_all_arm_spe_pmus(int *nr_sp= es, int *err) return NULL; } =20 - arm_spe_pmus[*nr_spes] =3D perf_pmu__find(arm_spe_pmu_name); + arm_spe_pmus[*nr_spes] =3D perf_pmus__find(arm_spe_pmu_name); if (arm_spe_pmus[*nr_spes]) { pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n", __func__, __LINE__, *nr_spes, @@ -87,7 +88,7 @@ static struct perf_pmu **find_all_hisi_ptt_pmus(int *nr_p= tts, int *err) rewinddir(dir); while ((dent =3D readdir(dir))) { if (strstr(dent->d_name, HISI_PTT_PMU_NAME) && idx < *nr_ptts) { - hisi_ptt_pmus[idx] =3D perf_pmu__find(dent->d_name); + hisi_ptt_pmus[idx] =3D perf_pmus__find(dent->d_name); if (hisi_ptt_pmus[idx]) idx++; } @@ -131,7 +132,7 @@ struct auxtrace_record if (!evlist) return NULL; =20 - cs_etm_pmu =3D perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu =3D perf_pmus__find(CORESIGHT_ETM_PMU_NAME); arm_spe_pmus =3D find_all_arm_spe_pmus(&nr_spes, err); hisi_ptt_pmus =3D find_all_hisi_ptt_pmus(&nr_ptts, err); =20 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 9ca040bfb1aa..7c51fa182b51 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -25,7 +25,7 @@ #include "../../../util/evsel.h" #include "../../../util/perf_api_probe.h" #include "../../../util/evsel_config.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/cs-etm.h" #include // page_size #include "../../../util/session.h" @@ -881,7 +881,7 @@ struct auxtrace_record *cs_etm_record_init(int *err) struct perf_pmu *cs_etm_pmu; struct cs_etm_recording *ptr; =20 - cs_etm_pmu =3D perf_pmu__find(CORESIGHT_ETM_PMU_NAME); + cs_etm_pmu =3D perf_pmus__find(CORESIGHT_ETM_PMU_NAME); =20 if (!cs_etm_pmu) { *err =3D -EINVAL; diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index ef1ed645097c..2504d43a39a7 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -3,6 +3,7 @@ #include #include "../../../util/cpumap.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include #include =20 @@ -10,7 +11,7 @@ static struct perf_pmu *pmu__find_core_pmu(void) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!is_pmu_core(pmu->name)) continue; =20 diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index 944bd1b4bab6..e466735d68d5 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -4,6 +4,7 @@ #include "evlist.h" #include "evsel.h" #include "pmu.h" +#include "pmus.h" #include "tests/tests.h" =20 static bool test_config(const struct evsel *evsel, __u64 expected_config) @@ -113,7 +114,7 @@ static int test__hybrid_raw1(struct evlist *evlist) struct perf_evsel *evsel; =20 perf_evlist__for_each_evsel(&evlist->core, evsel) { - struct perf_pmu *pmu =3D perf_pmu__find_by_type(evsel->attr.type); + struct perf_pmu *pmu =3D perf_pmus__find_by_type(evsel->attr.type); =20 TEST_ASSERT_VAL("missing pmu", pmu); TEST_ASSERT_VAL("unexpected pmu", !strncmp(pmu->name, "cpu_", 4)); @@ -280,7 +281,7 @@ static int test_events(const struct evlist_test *events= , int cnt) =20 int test__hybrid(struct test_suite *test __maybe_unused, int subtest __may= be_unused) { - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return TEST_SKIP; =20 return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events)); diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util= /auxtrace.c index 330d03216b0e..354780ff1605 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -10,6 +10,7 @@ #include "../../../util/header.h" #include "../../../util/debug.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/auxtrace.h" #include "../../../util/intel-pt.h" #include "../../../util/intel-bts.h" @@ -25,8 +26,8 @@ struct auxtrace_record *auxtrace_record__init_intel(struc= t evlist *evlist, bool found_pt =3D false; bool found_bts =3D false; =20 - intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); - intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); + intel_pt_pmu =3D perf_pmus__find(INTEL_PT_PMU_NAME); + intel_bts_pmu =3D perf_pmus__find(INTEL_BTS_PMU_NAME); =20 evlist__for_each_entry(evlist, evsel) { if (intel_pt_pmu && evsel->core.attr.type =3D=3D intel_pt_pmu->type) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 03f7eb4cf0a4..03240c640c7f 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include "util/pmu.h" +#include "util/pmus.h" #include "util/evlist.h" #include "util/parse-events.h" #include "util/event.h" @@ -17,7 +18,7 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, for (i =3D 0; i < nr_attrs; i++) event_attr_init(attrs + i); =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return evlist__add_attrs(evlist, attrs, nr_attrs); =20 for (i =3D 0; i < nr_attrs; i++) { @@ -32,7 +33,7 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, continue; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; =20 diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 153cdca94cd4..25da46c8cca9 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -4,6 +4,7 @@ #include "util/evsel.h" #include "util/env.h" #include "util/pmu.h" +#include "util/pmus.h" #include "linux/string.h" #include "evsel.h" #include "util/debug.h" @@ -30,7 +31,7 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evse= l) * should be good enough to detect the perf metrics feature. */ if ((evsel->core.attr.type =3D=3D PERF_TYPE_RAW) && - pmu_have_event(pmu_name, "slots")) + perf_pmus__have_event(pmu_name, "slots")) return true; =20 return false; @@ -98,8 +99,8 @@ void arch__post_evsel_config(struct evsel *evsel, struct = perf_event_attr *attr) if (!evsel_pmu) return; =20 - ibs_fetch_pmu =3D perf_pmu__find("ibs_fetch"); - ibs_op_pmu =3D perf_pmu__find("ibs_op"); + ibs_fetch_pmu =3D perf_pmus__find("ibs_fetch"); + ibs_op_pmu =3D perf_pmus__find("ibs_op"); =20 if (ibs_fetch_pmu && ibs_fetch_pmu->type =3D=3D evsel_pmu->type) { if (attr->config & IBS_FETCH_L3MISSONLY) { diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/uti= l/intel-bts.c index 439c2956f3e7..d2c8cac11470 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -17,7 +17,7 @@ #include "../../../util/evlist.h" #include "../../../util/mmap.h" #include "../../../util/session.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/debug.h" #include "../../../util/record.h" #include "../../../util/tsc.h" @@ -416,7 +416,7 @@ static int intel_bts_find_snapshot(struct auxtrace_reco= rd *itr, int idx, =20 struct auxtrace_record *intel_bts_recording_init(int *err) { - struct perf_pmu *intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); + struct perf_pmu *intel_bts_pmu =3D perf_pmus__find(INTEL_BTS_PMU_NAME); struct intel_bts_recording *btsr; =20 if (!intel_bts_pmu) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index 17336da08b58..74b70fd379df 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -23,7 +23,7 @@ #include "../../../util/mmap.h" #include #include "../../../util/parse-events.h" -#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/debug.h" #include "../../../util/auxtrace.h" #include "../../../util/perf_api_probe.h" @@ -1185,7 +1185,7 @@ static u64 intel_pt_reference(struct auxtrace_record = *itr __maybe_unused) =20 struct auxtrace_record *intel_pt_recording_init(int *err) { - struct perf_pmu *intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); + struct perf_pmu *intel_pt_pmu =3D perf_pmus__find(INTEL_PT_PMU_NAME); struct intel_pt_recording *ptr; =20 if (!intel_pt_pmu) diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/ut= il/mem-events.c index 02d65e446f46..32879d12a8d5 100644 --- a/tools/perf/arch/x86/util/mem-events.c +++ b/tools/perf/arch/x86/util/mem-events.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "util/pmu.h" +#include "util/pmus.h" #include "util/env.h" #include "map_symbol.h" #include "mem-events.h" @@ -55,12 +56,12 @@ struct perf_mem_event *perf_mem_events__ptr(int i) =20 bool is_mem_loads_aux_event(struct evsel *leader) { - struct perf_pmu *pmu =3D perf_pmu__find("cpu"); + struct perf_pmu *pmu =3D perf_pmus__find("cpu"); =20 if (!pmu) - pmu =3D perf_pmu__find("cpu_core"); + pmu =3D perf_pmus__find("cpu_core"); =20 - if (pmu && !pmu_have_event(pmu->name, "mem-loads-aux")) + if (pmu && !perf_pmu__have_event(pmu, "mem-loads-aux")) return false; =20 return leader->core.attr.config =3D=3D MEM_LOADS_AUX; @@ -82,7 +83,7 @@ char *perf_mem_events__name(int i, char *pmu_name) pmu_name =3D (char *)"cpu"; } =20 - if (pmu_have_event(pmu_name, "mem-loads-aux")) { + if (perf_pmus__have_event(pmu_name, "mem-loads-aux")) { scnprintf(mem_loads_name, sizeof(mem_loads_name), MEM_LOADS_AUX_NAME, pmu_name, pmu_name, perf_mem_events__loads_ldlat); diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index 26abc159fc0e..befa7f3659b9 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -10,6 +10,7 @@ #include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/pmu.h" +#include "../../../util/pmus.h" =20 const struct sample_reg sample_reg_masks[] =3D { SMPL_REG(AX, PERF_REG_X86_AX), @@ -291,7 +292,7 @@ uint64_t arch__intr_reg_mask(void) */ attr.sample_period =3D 1; =20 - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { struct perf_pmu *pmu =3D NULL; __u64 type =3D PERF_TYPE_RAW; =20 @@ -299,7 +300,7 @@ uint64_t arch__intr_reg_mask(void) * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->is_core) { type =3D pmu->type; break; diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/= topdown.c index 9ad5e5c7bd27..3f9a267d4501 100644 --- a/tools/perf/arch/x86/util/topdown.c +++ b/tools/perf/arch/x86/util/topdown.c @@ -2,6 +2,7 @@ #include "api/fs/fs.h" #include "util/evsel.h" #include "util/pmu.h" +#include "util/pmus.h" #include "util/topdown.h" #include "topdown.h" #include "evsel.h" @@ -22,8 +23,8 @@ bool topdown_sys_has_perf_metrics(void) * The slots event is only available when the core PMU * supports the perf metrics feature. */ - pmu =3D perf_pmu__find_by_type(PERF_TYPE_RAW); - if (pmu && pmu_have_event(pmu->name, "slots")) + pmu =3D perf_pmus__find_by_type(PERF_TYPE_RAW); + if (pmu && perf_pmu__have_event(pmu, "slots")) has_perf_metrics =3D true; =20 cached =3D true; diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index f4a6c37cbe27..51cae2d03353 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -44,7 +44,7 @@ static int save_result(void) struct list_head *list; struct pmu_scan_result *r; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { r =3D realloc(results, (nr_pmus + 1) * sizeof(*r)); if (r =3D=3D NULL) return -ENOMEM; @@ -68,7 +68,7 @@ static int save_result(void) nr_pmus++; } =20 - perf_pmu__destroy(); + perf_pmus__destroy(); return 0; } =20 @@ -81,7 +81,7 @@ static int check_result(void) =20 for (int i =3D 0; i < nr_pmus; i++) { r =3D &results[i]; - pmu =3D perf_pmu__find(r->name); + pmu =3D perf_pmus__find(r->name); if (pmu =3D=3D NULL) { pr_err("Cannot find PMU %s\n", r->name); return -1; @@ -144,7 +144,7 @@ static int run_pmu_scan(void) =20 for (i =3D 0; i < iterations; i++) { gettimeofday(&start, NULL); - perf_pmu__scan(NULL); + perf_pmus__scan(NULL); gettimeofday(&end, NULL); =20 timersub(&end, &start, &diff); @@ -152,7 +152,7 @@ static int run_pmu_scan(void) update_stats(&stats, runtime_us); =20 ret =3D check_result(); - perf_pmu__destroy(); + perf_pmus__destroy(); if (ret < 0) break; } diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 2757ccc19c5e..05dfd98af170 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -41,7 +41,7 @@ #include "symbol.h" #include "ui/ui.h" #include "ui/progress.h" -#include "pmu.h" +#include "pmus.h" #include "string2.h" #include "util/util.h" =20 @@ -3259,7 +3259,7 @@ static int perf_c2c__record(int argc, const char **ar= gv) PARSE_OPT_KEEP_UNKNOWN); =20 /* Max number of arguments multiplied by number of PMUs that can support = them. */ - rec_argc =3D argc + 11 * perf_pmu__num_mem_pmus(); + rec_argc =3D argc + 11 * perf_pmus__num_mem_pmus(); =20 rec_argv =3D calloc(rec_argc + 1, sizeof(char *)); if (!rec_argv) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index c6bd0aa4a56e..6a2e74bdb1db 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -522,7 +522,7 @@ int cmd_list(int argc, const char **argv) strcmp(argv[i], "hwcache") =3D=3D 0) print_hwcache_events(&print_cb, ps); else if (strcmp(argv[i], "pmu") =3D=3D 0) - print_pmu_events(&print_cb, ps); + perf_pmus__print_pmu_events(&print_cb, ps); else if (strcmp(argv[i], "sdt") =3D=3D 0) print_sdt_events(&print_cb, ps); else if (strcmp(argv[i], "metric") =3D=3D 0 || strcmp(argv[i], "metrics"= ) =3D=3D 0) { @@ -562,7 +562,7 @@ int cmd_list(int argc, const char **argv) event_symbols_sw, PERF_COUNT_SW_MAX); print_tool_events(&print_cb, ps); print_hwcache_events(&print_cb, ps); - print_pmu_events(&print_cb, ps); + perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index f4f1ff76d49d..960bfd4b732a 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -17,7 +17,7 @@ #include "util/dso.h" #include "util/map.h" #include "util/symbol.h" -#include "util/pmu.h" +#include "util/pmus.h" #include "util/sample.h" #include "util/string2.h" #include "util/util.h" @@ -93,7 +93,7 @@ static int __cmd_record(int argc, const char **argv, stru= ct perf_mem *mem) PARSE_OPT_KEEP_UNKNOWN); =20 /* Max number of arguments multiplied by number of PMUs that can support = them. */ - rec_argc =3D argc + 9 * perf_pmu__num_mem_pmus(); + rec_argc =3D argc + 9 * perf_pmus__num_mem_pmus(); =20 if (mem->cpu_list) rec_argc +=3D 2; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 2abcad2998f6..4b9212f75493 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -48,6 +48,8 @@ #include "util/bpf-event.h" #include "util/util.h" #include "util/pfm.h" +#include "util/pmu.h" +#include "util/pmus.h" #include "util/clockid.h" #include "util/off_cpu.h" #include "util/bpf-filter.h" @@ -1292,7 +1294,7 @@ static int record__open(struct record *rec) * of waiting or event synthesis. */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || - perf_pmu__has_hybrid()) { + perf_pmus__has_hybrid()) { pos =3D evlist__get_tracking_event(evlist); if (!evsel__is_dummy_event(pos)) { /* Set up dummy event. */ @@ -2191,7 +2193,7 @@ static void record__uniquify_name(struct record *rec) char *new_name; int ret; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return; =20 evlist__for_each_entry(evlist, pos) { diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 3b90d742b023..0736225d8015 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1882,11 +1882,11 @@ static int add_default_attributes(void) =20 if (evlist__add_default_attrs(evsel_list, default_attrs0) < 0) return -1; - if (pmu_have_event("cpu", "stalled-cycles-frontend")) { + if (perf_pmus__have_event("cpu", "stalled-cycles-frontend")) { if (evlist__add_default_attrs(evsel_list, frontend_attrs) < 0) return -1; } - if (pmu_have_event("cpu", "stalled-cycles-backend")) { + if (perf_pmus__have_event("cpu", "stalled-cycles-backend")) { if (evlist__add_default_attrs(evsel_list, backend_attrs) < 0) return -1; } diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 56fba08a3037..674876e6c8e6 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -34,7 +34,7 @@ #include "event.h" #include "util.h" #include "tests.h" -#include "pmu.h" +#include "pmus.h" =20 #define ENV "PERF_TEST_ATTR" =20 @@ -185,7 +185,7 @@ static int test__attr(struct test_suite *test __maybe_u= nused, int subtest __mayb char path_dir[PATH_MAX]; char *exec_path; =20 - if (perf_pmu__has_hybrid()) + if (perf_pmus__has_hybrid()) return TEST_SKIP; =20 /* First try development tree tests. */ diff --git a/tools/perf/tests/event_groups.c b/tools/perf/tests/event_group= s.c index 3d9a2b524bba..ccd9d8b2903f 100644 --- a/tools/perf/tests/event_groups.c +++ b/tools/perf/tests/event_groups.c @@ -53,7 +53,7 @@ static int setup_uncore_event(void) struct perf_pmu *pmu =3D NULL; int i, fd; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { for (i =3D 0; i < NR_UNCORE_PMUS; i++) { if (!strcmp(uncore_pmus[i].name, pmu->name)) { pr_debug("Using %s for uncore pmu event\n", pmu->name); diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 277607ede060..9d05bc551791 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -112,7 +112,7 @@ static int test__checkevent_raw(struct evlist *evlist) bool type_matched =3D false; =20 TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, 0x1a)); - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->type =3D=3D evsel->attr.type) { TEST_ASSERT_VAL("PMU type expected once", !type_matched); type_matched =3D true; @@ -1443,12 +1443,12 @@ static int test__checkevent_config_cache(struct evl= ist *evlist) =20 static bool test__pmu_cpu_valid(void) { - return !!perf_pmu__find("cpu"); + return !!perf_pmus__find("cpu"); } =20 static bool test__intel_pt_valid(void) { - return !!perf_pmu__find("intel_pt"); + return !!perf_pmus__find("intel_pt"); } =20 static int test__intel_pt(struct evlist *evlist) @@ -2246,7 +2246,7 @@ static int test__pmu_events(struct test_suite *test _= _maybe_unused, int subtest struct perf_pmu *pmu =3D NULL; int ret =3D TEST_OK; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct stat st; char path[PATH_MAX]; struct dirent *ent; diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metri= c.c index c05148ea400c..1d6493a5a956 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -11,7 +11,7 @@ #include "debug.h" #include "expr.h" #include "stat.h" -#include "pmu.h" +#include "pmus.h" =20 struct value { const char *event; @@ -303,7 +303,7 @@ static int test__parse_metric(struct test_suite *test _= _maybe_unused, int subtes TEST_ASSERT_VAL("recursion fail failed", test_recursion_fail() =3D=3D 0); TEST_ASSERT_VAL("Memory bandwidth", test_memory_bandwidth() =3D=3D 0); =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() =3D= =3D 0); TEST_ASSERT_VAL("test metric group", test_metric_group() =3D=3D 0); } diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 734004f1a37d..64ecb7845af4 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -2,6 +2,7 @@ #include "math.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "tests.h" #include #include @@ -708,7 +709,7 @@ static int test__aliases(struct test_suite *test __mayb= e_unused, struct perf_pmu *pmu =3D NULL; unsigned long i; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { int count =3D 0; =20 if (!is_pmu_core(pmu->name)) diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index b3bd14b025a8..cff6ab87b2f6 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -20,7 +20,7 @@ #include "tests.h" #include "util/mmap.h" #include "util/sample.h" -#include "pmu.h" +#include "pmus.h" =20 static int spin_sleep(void) { @@ -375,7 +375,7 @@ static int test__switch_tracking(struct test_suite *tes= t __maybe_unused, int sub cpu_clocks_evsel =3D evlist__last(evlist); =20 /* Second event */ - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { cycles =3D "cpu_core/cycles/u"; err =3D parse_event(evlist, cycles); if (err) { diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index c4630cfc80ea..49e80d15420b 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -8,7 +8,7 @@ #include "session.h" #include "evlist.h" #include "debug.h" -#include "pmu.h" +#include "pmus.h" #include =20 #define TEMPL "/tmp/perf-test-XXXXXX" @@ -41,7 +41,7 @@ static int session_write_header(char *path) session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { session->evlist =3D evlist__new_default(); TEST_ASSERT_VAL("can't get evlist", session->evlist); } else { diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index a5c259bd5cc0..4578c26747e1 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -13,6 +13,7 @@ #include "debug.h" #include "env.h" #include "pmu.h" +#include "pmus.h" =20 #define PACKAGE_CPUS_FMT \ "%s/devices/system/cpu/cpu%d/topology/package_cpus_list" @@ -473,10 +474,10 @@ struct hybrid_topology *hybrid_topology__new(void) struct hybrid_topology *tp =3D NULL; u32 nr =3D 0, i =3D 0; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (pmu->is_core) nr++; } @@ -488,7 +489,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 4a4fdad820d6..9eabf3ec56e9 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -10,6 +10,7 @@ #include #include #include +#include "pmus.h" #include "strbuf.h" =20 struct perf_env perf_env; @@ -323,7 +324,7 @@ int perf_env__read_pmu_mappings(struct perf_env *env) u32 pmu_num =3D 0; struct strbuf sb; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; pmu_num++; @@ -337,7 +338,7 @@ int perf_env__read_pmu_mappings(struct perf_env *env) if (strbuf_init(&sb, 128 * pmu_num) < 0) return -ENOMEM; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1c6e22e3f345..b4237fc713d5 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -48,6 +48,7 @@ #include "util/hashmap.h" #include "off_cpu.h" #include "pmu.h" +#include "pmus.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" #include "util/bpf-filter.h" @@ -3139,7 +3140,7 @@ void evsel__zero_per_pkg(struct evsel *evsel) */ bool evsel__is_hybrid(const struct evsel *evsel) { - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; =20 return evsel->core.is_pmu_core; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e24cc8f316cd..fa3f7dbbd90e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -37,6 +37,7 @@ #include "debug.h" #include "cpumap.h" #include "pmu.h" +#include "pmus.h" #include "vdso.h" #include "strbuf.h" #include "build-id.h" @@ -744,7 +745,7 @@ static int write_pmu_mappings(struct feat_fd *ff, * Do a first pass to count number of pmu to avoid lseek so this * works in pipe mode as well. */ - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; pmu_num++; @@ -754,7 +755,7 @@ static int write_pmu_mappings(struct feat_fd *ff, if (ret < 0) return ret; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name) continue; =20 @@ -1550,7 +1551,7 @@ static int __write_pmu_caps(struct feat_fd *ff, struc= t perf_pmu *pmu, static int write_cpu_pmu_caps(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { - struct perf_pmu *cpu_pmu =3D perf_pmu__find("cpu"); + struct perf_pmu *cpu_pmu =3D perf_pmus__find("cpu"); int ret; =20 if (!cpu_pmu) @@ -1570,7 +1571,7 @@ static int write_pmu_caps(struct feat_fd *ff, int nr_pmu =3D 0; int ret; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->name || !strcmp(pmu->name, "cpu") || perf_pmu__caps_parse(pmu) <=3D 0) continue; @@ -1588,9 +1589,9 @@ static int write_pmu_caps(struct feat_fd *ff, * Write hybrid pmu caps first to maintain compatibility with * older perf tool. */ - if (perf_pmu__has_hybrid()) { + if (perf_pmus__has_hybrid()) { pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (!pmu->is_core) continue; =20 @@ -1601,7 +1602,7 @@ static int write_pmu_caps(struct feat_fd *ff, } =20 pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { if (pmu->is_core || !pmu->nr_caps) continue; =20 diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index c9e422a38258..08ac3ea2e366 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -13,6 +13,7 @@ #include "debug.h" #include "symbol.h" #include "pmu.h" +#include "pmus.h" =20 unsigned int perf_mem_events__loads_ldlat =3D 30; =20 @@ -128,14 +129,14 @@ int perf_mem_events__init(void) if (!e->tag) continue; =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, "cpu"); e->supported =3D perf_mem_event__supported(mnt, sysfs_name); } else { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 @@ -175,7 +176,7 @@ static void perf_mem_events__print_unsupport_hybrid(str= uct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; =20 @@ -201,7 +202,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, if (!e->record) continue; =20 - if (!perf_pmu__has_hybrid()) { + if (!perf_pmus__has_hybrid()) { if (!e->supported) { pr_err("failed: event '%s' not supported\n", perf_mem_events__name(j, NULL)); @@ -216,7 +217,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!pmu->is_core) continue; rec_argv[i++] =3D "-e"; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 72583f62eda8..27310eff49ab 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -11,6 +11,7 @@ #include "evsel.h" #include "strbuf.h" #include "pmu.h" +#include "pmus.h" #include "print-events.h" #include "smt.h" #include "expr.h" @@ -273,7 +274,7 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, const char *metric_id; struct evsel *ev; size_t ids_size, matched_events, i; - bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmu__has_hybrid() || !is_p= mu_hybrid(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmus__has_hybrid() || !is_= pmu_hybrid(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); @@ -488,7 +489,7 @@ static int metricgroup__sys_event_iter(const struct pmu= _metric *pm, if (!pm->metric_expr || !pm->compat) return 0; =20 - while ((pmu =3D perf_pmu__scan(pmu))) { + while ((pmu =3D perf_pmus__scan(pmu))) { =20 if (!pmu->id || strcmp(pmu->id, pm->compat)) continue; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1a0be395c887..be544f948be2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -21,6 +21,7 @@ #include "parse-events-bison.h" #include "parse-events-flex.h" #include "pmu.h" +#include "pmus.h" #include "asm/bug.h" #include "util/parse-branch-options.h" #include "util/evsel_config.h" @@ -452,7 +453,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, const char *config_name =3D get_config_name(head_config); const char *metric_id =3D get_config_metric_id(head_config); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; @@ -1193,7 +1194,7 @@ static int config_term_pmu(struct perf_event_attr *at= tr, struct parse_events_error *err) { if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE) { - const struct perf_pmu *pmu =3D perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu =3D perf_pmus__find_by_type(attr->type); =20 if (perf_pmu__supports_legacy_cache(pmu)) { attr->type =3D PERF_TYPE_HW_CACHE; @@ -1203,7 +1204,7 @@ static int config_term_pmu(struct perf_event_attr *at= tr, term->type_term =3D PARSE_EVENTS__TERM_TYPE_USER; } if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_HARDWARE) { - const struct perf_pmu *pmu =3D perf_pmu__find_by_type(attr->type); + const struct perf_pmu *pmu =3D perf_pmus__find_by_type(attr->type); =20 if (!pmu) { pr_debug("Failed to find PMU for type %d", attr->type); @@ -1480,7 +1481,7 @@ int parse_events_add_numeric(struct parse_events_stat= e *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=3D*/NULL, type, config, head_config); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { int ret; =20 if (!perf_pmu__supports_wildcard_numeric(pmu)) @@ -1529,7 +1530,7 @@ int parse_events_add_pmu(struct parse_events_state *p= arse_state, struct parse_events_error *err =3D parse_state->error; LIST_HEAD(config_terms); =20 - pmu =3D parse_state->fake_pmu ?: perf_pmu__find(name); + pmu =3D parse_state->fake_pmu ?: perf_pmus__find(name); =20 if (verbose > 1 && !(pmu && pmu->selectable)) { fprintf(stderr, "Attempting to add event pmu '%s' with '", @@ -1674,7 +1675,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 INIT_LIST_HEAD(list); =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { struct perf_pmu_alias *alias; bool auto_merge_stats; =20 @@ -2410,7 +2411,7 @@ static int set_filter(struct evsel *evsel, const void= *arg) return 0; } =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) if (pmu->type =3D=3D evsel->core.attr.type) { found =3D true; break; diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 4e1f5de35be8..abd6ab460e12 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -15,6 +15,7 @@ #include #include #include "pmu.h" +#include "pmus.h" #include "evsel.h" #include "parse-events.h" #include "parse-events-bison.h" @@ -316,7 +317,7 @@ PE_NAME opt_pmu_config if (asprintf(&pattern, "%s*", $1) < 0) CLEANUP_YYABORT; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { char *name =3D pmu->name; =20 if (parse_events__filter_pmu(parse_state, pmu)) diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index 6c11914c179f..076aecc22c16 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -10,7 +10,7 @@ #include "util/evlist.h" #include "util/evsel.h" #include "util/parse-events.h" -#include "util/pmu.h" +#include "util/pmus.h" #include "util/pfm.h" #include "util/strbuf.h" =20 @@ -49,7 +49,7 @@ int parse_libpfm_events_option(const struct option *opt, = const char *str, /* * force loading of the PMU list */ - perf_pmu__scan(NULL); + perf_pmus__scan(NULL); =20 for (q =3D p; strsep(&p, ",{}"); q =3D p) { sep =3D p ? str + (p - p_orig - 1) : ""; @@ -86,7 +86,7 @@ int parse_libpfm_events_option(const struct option *opt, = const char *str, goto error; } =20 - pmu =3D perf_pmu__find_by_type((unsigned int)attr.type); + pmu =3D perf_pmus__find_by_type((unsigned int)attr.type); evsel =3D parse_events__add_event(evlist->core.nr_entries, &attr, q, /*metric_id=3D*/NULL, pmu); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 62cd795e2fd3..044f31f9d0ff 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -4,20 +4,15 @@ #include #include #include -#include #include -#include #include #include #include #include #include -#include #include #include #include -#include -#include #include #include #include "debug.h" @@ -59,8 +54,6 @@ struct perf_pmu_format { struct list_head list; }; =20 -static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name); - /* * Parse & process all the sysfs attributes located under * the directory specified in 'dir' parameter. @@ -554,31 +547,6 @@ static int pmu_alias_terms(struct perf_pmu_alias *alia= s, return 0; } =20 -/* Add all pmus in sysfs to pmu list: */ -static void pmu_read_sysfs(void) -{ - int fd; - DIR *dir; - struct dirent *dent; - - fd =3D perf_pmu__event_source_devices_fd(); - if (fd < 0) - return; - - dir =3D fdopendir(fd); - if (!dir) - return; - - while ((dent =3D readdir(dir))) { - if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) - continue; - /* add to static LIST_HEAD(pmus): */ - perf_pmu__find2(fd, dent->d_name); - } - - closedir(dir); -} - /* * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/ar= m64) * may have a "cpus" file. @@ -904,7 +872,7 @@ static bool perf_pmu__skip_empty_cpus(const char *name) return !strcmp(name, "cpu_core") || !strcmp(name, "cpu_atom"); } =20 -static struct perf_pmu *pmu_lookup(int dirfd, const char *lookup_name) +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name) { struct perf_pmu *pmu; LIST_HEAD(format); @@ -964,7 +932,7 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) INIT_LIST_HEAD(&pmu->caps); list_splice(&format, &pmu->format); list_splice(&aliases, &pmu->aliases); - list_add_tail(&pmu->list, &pmus); + list_add_tail(&pmu->list, pmus); =20 pmu->default_config =3D perf_pmu__get_default_config(pmu); =20 @@ -992,61 +960,6 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *p= mu) } } =20 -static struct perf_pmu *pmu_find(const char *name) -{ - struct perf_pmu *pmu; - - list_for_each_entry(pmu, &pmus, list) { - if (!strcmp(pmu->name, name) || - (pmu->alias_name && !strcmp(pmu->alias_name, name))) - return pmu; - } - - return NULL; -} - -struct perf_pmu *perf_pmu__find_by_type(unsigned int type) -{ - struct perf_pmu *pmu; - - list_for_each_entry(pmu, &pmus, list) - if (pmu->type =3D=3D type) - return pmu; - - return NULL; -} - -struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu) -{ - /* - * pmu iterator: If pmu is NULL, we start at the begin, - * otherwise return the next pmu. Returns NULL on end. - */ - if (!pmu) { - pmu_read_sysfs(); - pmu =3D list_prepare_entry(pmu, &pmus, list); - } - list_for_each_entry_continue(pmu, &pmus, list) - return pmu; - return NULL; -} - -struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) -{ - struct perf_pmu *pmu =3D NULL; - - if (evsel->pmu) - return evsel->pmu; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (pmu->type =3D=3D evsel->core.attr.type) - break; - } - - ((struct evsel *)evsel)->pmu =3D pmu; - return pmu; -} - bool evsel__is_aux_event(const struct evsel *evsel) { struct perf_pmu *pmu =3D evsel__find_pmu(evsel); @@ -1083,43 +996,6 @@ void evsel__set_config_if_unset(struct perf_pmu *pmu,= struct evsel *evsel, evsel->core.attr.config |=3D field_prep(bits, val); } =20 -struct perf_pmu *perf_pmu__find(const char *name) -{ - struct perf_pmu *pmu; - int dirfd; - - /* - * Once PMU is loaded it stays in the list, - * so we keep us from multiple reading/parsing - * the pmu format definitions. - */ - pmu =3D pmu_find(name); - if (pmu) - return pmu; - - dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D pmu_lookup(dirfd, name); - close(dirfd); - - return pmu; -} - -static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) -{ - struct perf_pmu *pmu; - - /* - * Once PMU is loaded it stays in the list, - * so we keep us from multiple reading/parsing - * the pmu format definitions. - */ - pmu =3D pmu_find(name); - if (pmu) - return pmu; - - return pmu_lookup(dirfd, name); -} - static struct perf_pmu_format * pmu_find_format(struct list_head *formats, const char *name) { @@ -1549,99 +1425,6 @@ void perf_pmu__del_formats(struct list_head *formats) } } =20 -static int sub_non_neg(int a, int b) -{ - if (b > a) - return 0; - return a - b; -} - -static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, - const struct perf_pmu_alias *alias) -{ - struct parse_events_term *term; - int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); - - list_for_each_entry(term, &alias->terms, list) { - if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) - used +=3D snprintf(buf + used, sub_non_neg(len, used), - ",%s=3D%s", term->config, - term->val.str); - } - - if (sub_non_neg(len, used) > 0) { - buf[used] =3D '/'; - used++; - } - if (sub_non_neg(len, used) > 0) { - buf[used] =3D '\0'; - used++; - } else - buf[len - 1] =3D '\0'; - - return buf; -} - -/** Struct for ordering events as output in perf list. */ -struct sevent { - /** PMU for event. */ - const struct perf_pmu *pmu; - /** - * Optional event for name, desc, etc. If not present then this is a - * selectable PMU and the event name is shown as "//". - */ - const struct perf_pmu_alias *event; - /** Is the PMU for the CPU? */ - bool is_cpu; -}; - -static int cmp_sevent(const void *a, const void *b) -{ - const struct sevent *as =3D a; - const struct sevent *bs =3D b; - const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; - const char *a_name =3D "//", *a_desc =3D NULL, *a_topic =3D ""; - const char *b_name =3D "//", *b_desc =3D NULL, *b_topic =3D ""; - int ret; - - if (as->event) { - a_name =3D as->event->name; - a_desc =3D as->event->desc; - a_topic =3D as->event->topic ?: ""; - a_pmu_name =3D as->event->pmu_name; - } - if (bs->event) { - b_name =3D bs->event->name; - b_desc =3D bs->event->desc; - b_topic =3D bs->event->topic ?: ""; - b_pmu_name =3D bs->event->pmu_name; - } - /* Put extra events last. */ - if (!!a_desc !=3D !!b_desc) - return !!a_desc - !!b_desc; - - /* Order by topics. */ - ret =3D strcmp(a_topic, b_topic); - if (ret) - return ret; - - /* Order CPU core events to be first */ - if (as->is_cpu !=3D bs->is_cpu) - return as->is_cpu ? -1 : 1; - - /* Order by PMU name. */ - if (as->pmu !=3D bs->pmu) { - a_pmu_name =3D a_pmu_name ?: (as->pmu->name ?: ""); - b_pmu_name =3D b_pmu_name ?: (bs->pmu->name ?: ""); - ret =3D strcmp(a_pmu_name, b_pmu_name); - if (ret) - return ret; - } - - /* Order by event name. */ - return strcmp(a_name, b_name); -} - bool is_pmu_core(const char *name) { return !strcmp(name, "cpu") || is_sysfs_pmu_core(name); @@ -1667,167 +1450,18 @@ bool perf_pmu__auto_merge_stats(const struct perf_= pmu *pmu) return !is_pmu_hybrid(pmu->name); } =20 -static bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) +bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) { return pmu->is_core; } =20 -int perf_pmu__num_mem_pmus(void) -{ - struct perf_pmu *pmu =3D NULL; - int count =3D 0; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (perf_pmu__is_mem_pmu(pmu)) - count++; - } - return count; -} - -static bool pmu_alias_is_duplicate(struct sevent *alias_a, - struct sevent *alias_b) -{ - const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; - const char *a_name =3D "//", *b_name =3D "//"; - - - if (alias_a->event) { - a_name =3D alias_a->event->name; - a_pmu_name =3D alias_a->event->pmu_name; - } - if (alias_b->event) { - b_name =3D alias_b->event->name; - b_pmu_name =3D alias_b->event->pmu_name; - } - - /* Different names -> never duplicates */ - if (strcmp(a_name, b_name)) - return false; - - /* Don't remove duplicates for different PMUs */ - a_pmu_name =3D a_pmu_name ?: (alias_a->pmu->name ?: ""); - b_pmu_name =3D b_pmu_name ?: (alias_b->pmu->name ?: ""); - return strcmp(a_pmu_name, b_pmu_name) =3D=3D 0; -} - -void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state) -{ - struct perf_pmu *pmu; - struct perf_pmu_alias *event; - char buf[1024]; - int printed =3D 0; - int len, j; - struct sevent *aliases; - - pmu =3D NULL; - len =3D 0; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - list_for_each_entry(event, &pmu->aliases, list) - len++; - if (pmu->selectable) - len++; - } - aliases =3D zalloc(sizeof(struct sevent) * len); - if (!aliases) { - pr_err("FATAL: not enough memory to print PMU events\n"); - return; - } - pmu =3D NULL; - j =3D 0; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - bool is_cpu =3D pmu->is_core; - - list_for_each_entry(event, &pmu->aliases, list) { - aliases[j].event =3D event; - aliases[j].pmu =3D pmu; - aliases[j].is_cpu =3D is_cpu; - j++; - } - if (pmu->selectable) { - aliases[j].event =3D NULL; - aliases[j].pmu =3D pmu; - aliases[j].is_cpu =3D is_cpu; - j++; - } - } - len =3D j; - qsort(aliases, len, sizeof(struct sevent), cmp_sevent); - for (j =3D 0; j < len; j++) { - const char *name, *alias =3D NULL, *scale_unit =3D NULL, - *desc =3D NULL, *long_desc =3D NULL, - *encoding_desc =3D NULL, *topic =3D NULL, - *pmu_name =3D NULL; - bool deprecated =3D false; - size_t buf_used; - - /* Skip duplicates */ - if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) - continue; - - if (!aliases[j].event) { - /* A selectable event. */ - pmu_name =3D aliases[j].pmu->name; - buf_used =3D snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; - name =3D buf; - } else { - if (aliases[j].event->desc) { - name =3D aliases[j].event->name; - buf_used =3D 0; - } else { - name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, - aliases[j].event); - if (aliases[j].is_cpu) { - alias =3D name; - name =3D aliases[j].event->name; - } - buf_used =3D strlen(buf) + 1; - } - pmu_name =3D aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); - if (strlen(aliases[j].event->unit) || aliases[j].event->scale !=3D 1.0)= { - scale_unit =3D buf + buf_used; - buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%G%s", aliases[j].event->scale, - aliases[j].event->unit) + 1; - } - desc =3D aliases[j].event->desc; - long_desc =3D aliases[j].event->long_desc; - topic =3D aliases[j].event->topic; - encoding_desc =3D buf + buf_used; - buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, - "%s/%s/", pmu_name, aliases[j].event->str) + 1; - deprecated =3D aliases[j].event->deprecated; - } - print_cb->print_event(print_state, - pmu_name, - topic, - name, - alias, - scale_unit, - deprecated, - "Kernel PMU event", - desc, - long_desc, - encoding_desc); - } - if (printed && pager_in_use()) - printf("\n"); - - zfree(&aliases); - return; -} - -bool pmu_have_event(const char *pname, const char *name) +bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name) { - struct perf_pmu *pmu; struct perf_pmu_alias *alias; =20 - pmu =3D NULL; - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (strcmp(pname, pmu->name)) - continue; - list_for_each_entry(alias, &pmu->aliases, list) - if (!strcmp(alias->name, name)) - return true; + list_for_each_entry(alias, &pmu->aliases, list) { + if (!strcmp(alias->name, name)) + return true; } return false; } @@ -2033,24 +1667,6 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *= pmu, __u64 config, name ?: "N/A", buf, config); } =20 -bool perf_pmu__has_hybrid(void) -{ - static bool hybrid_scanned, has_hybrid; - - if (!hybrid_scanned) { - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { - has_hybrid =3D true; - break; - } - } - hybrid_scanned =3D true; - } - return has_hybrid; -} - int perf_pmu__match(char *pattern, char *name, char *tok) { if (!name) @@ -2118,7 +1734,7 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_= name, const char *filename, return openat(dirfd, path, flags); } =20 -static void perf_pmu__delete(struct perf_pmu *pmu) +void perf_pmu__delete(struct perf_pmu *pmu) { perf_pmu__del_formats(&pmu->format); perf_pmu__del_aliases(pmu); @@ -2131,14 +1747,3 @@ static void perf_pmu__delete(struct perf_pmu *pmu) zfree(&pmu->alias_name); free(pmu); } - -void perf_pmu__destroy(void) -{ - struct perf_pmu *pmu, *tmp; - - list_for_each_entry_safe(pmu, tmp, &pmus, list) { - list_del(&pmu->list); - - perf_pmu__delete(pmu); - } -} diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index cb51ad6e40fa..f1f3e8a2e00e 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -198,8 +198,6 @@ struct perf_pmu_alias { char *pmu_name; }; =20 -struct perf_pmu *perf_pmu__find(const char *name); -struct perf_pmu *perf_pmu__find_by_type(unsigned int type); void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu); int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, struct list_head *head_terms, @@ -222,16 +220,13 @@ void perf_pmu__set_format(unsigned long *bits, long f= rom, long to); int perf_pmu__format_parse(int dirfd, struct list_head *head); void perf_pmu__del_formats(struct list_head *formats); =20 -struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); - bool is_pmu_core(const char *name); bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); -int perf_pmu__num_mem_pmus(void); -void print_pmu_events(const struct print_callbacks *print_cb, void *print_= state); -bool pmu_have_event(const char *pname, const char *name); +bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu); +bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name); =20 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name); FILE *perf_pmu__open_file_at(struct perf_pmu *pmu, int dirfd, const char *= name); @@ -261,7 +256,6 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu= , __u64 config, const char *name); void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu); =20 -bool perf_pmu__has_hybrid(void); int perf_pmu__match(char *pattern, char *name, char *tok); =20 char *pmu_find_real_name(const char *name); @@ -273,6 +267,7 @@ int perf_pmu__pathname_scnprintf(char *buf, size_t size, int perf_pmu__event_source_devices_fd(void); int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *fil= ename, int flags); =20 -void perf_pmu__destroy(void); +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name); +void perf_pmu__delete(struct perf_pmu *pmu); =20 #endif /* __PMU_H */ diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 140e11f00b29..58ff7937e9b7 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -1,16 +1,136 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include +#include +#include +#include #include +#include +#include "debug.h" +#include "evsel.h" #include "pmus.h" #include "pmu.h" +#include "print-events.h" =20 -LIST_HEAD(pmus); +static LIST_HEAD(pmus); + +void perf_pmus__destroy(void) +{ + struct perf_pmu *pmu, *tmp; + + list_for_each_entry_safe(pmu, tmp, &pmus, list) { + list_del(&pmu->list); + + perf_pmu__delete(pmu); + } +} + +static struct perf_pmu *pmu_find(const char *name) +{ + struct perf_pmu *pmu; + + list_for_each_entry(pmu, &pmus, list) { + if (!strcmp(pmu->name, name) || + (pmu->alias_name && !strcmp(pmu->alias_name, name))) + return pmu; + } + + return NULL; +} + +struct perf_pmu *perf_pmus__find(const char *name) +{ + struct perf_pmu *pmu; + int dirfd; + + /* + * Once PMU is loaded it stays in the list, + * so we keep us from multiple reading/parsing + * the pmu format definitions. + */ + pmu =3D pmu_find(name); + if (pmu) + return pmu; + + dirfd =3D perf_pmu__event_source_devices_fd(); + pmu =3D perf_pmu__lookup(&pmus, dirfd, name); + close(dirfd); + + return pmu; +} + +static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) +{ + struct perf_pmu *pmu; + + /* + * Once PMU is loaded it stays in the list, + * so we keep us from multiple reading/parsing + * the pmu format definitions. + */ + pmu =3D pmu_find(name); + if (pmu) + return pmu; + + return perf_pmu__lookup(&pmus, dirfd, name); +} + +/* Add all pmus in sysfs to pmu list: */ +static void pmu_read_sysfs(void) +{ + int fd; + DIR *dir; + struct dirent *dent; + + fd =3D perf_pmu__event_source_devices_fd(); + if (fd < 0) + return; + + dir =3D fdopendir(fd); + if (!dir) + return; + + while ((dent =3D readdir(dir))) { + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) + continue; + /* add to static LIST_HEAD(pmus): */ + perf_pmu__find2(fd, dent->d_name); + } + + closedir(dir); +} + +struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +{ + struct perf_pmu *pmu; + + list_for_each_entry(pmu, &pmus, list) + if (pmu->type =3D=3D type) + return pmu; + + return NULL; +} + +struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) +{ + /* + * pmu iterator: If pmu is NULL, we start at the begin, + * otherwise return the next pmu. Returns NULL on end. + */ + if (!pmu) { + pmu_read_sysfs(); + pmu =3D list_prepare_entry(pmu, &pmus, list); + } + list_for_each_entry_continue(pmu, &pmus, list) + return pmu; + return NULL; +} =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { if (!strcmp(pmu->name, str)) return pmu; /* Ignore "uncore_" prefix. */ @@ -26,3 +146,275 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(c= onst char *str) } return NULL; } + +int perf_pmus__num_mem_pmus(void) +{ + struct perf_pmu *pmu =3D NULL; + int count =3D 0; + + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + if (perf_pmu__is_mem_pmu(pmu)) + count++; + } + return count; +} + +/** Struct for ordering events as output in perf list. */ +struct sevent { + /** PMU for event. */ + const struct perf_pmu *pmu; + /** + * Optional event for name, desc, etc. If not present then this is a + * selectable PMU and the event name is shown as "//". + */ + const struct perf_pmu_alias *event; + /** Is the PMU for the CPU? */ + bool is_cpu; +}; + +static int cmp_sevent(const void *a, const void *b) +{ + const struct sevent *as =3D a; + const struct sevent *bs =3D b; + const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; + const char *a_name =3D "//", *a_desc =3D NULL, *a_topic =3D ""; + const char *b_name =3D "//", *b_desc =3D NULL, *b_topic =3D ""; + int ret; + + if (as->event) { + a_name =3D as->event->name; + a_desc =3D as->event->desc; + a_topic =3D as->event->topic ?: ""; + a_pmu_name =3D as->event->pmu_name; + } + if (bs->event) { + b_name =3D bs->event->name; + b_desc =3D bs->event->desc; + b_topic =3D bs->event->topic ?: ""; + b_pmu_name =3D bs->event->pmu_name; + } + /* Put extra events last. */ + if (!!a_desc !=3D !!b_desc) + return !!a_desc - !!b_desc; + + /* Order by topics. */ + ret =3D strcmp(a_topic, b_topic); + if (ret) + return ret; + + /* Order CPU core events to be first */ + if (as->is_cpu !=3D bs->is_cpu) + return as->is_cpu ? -1 : 1; + + /* Order by PMU name. */ + if (as->pmu !=3D bs->pmu) { + a_pmu_name =3D a_pmu_name ?: (as->pmu->name ?: ""); + b_pmu_name =3D b_pmu_name ?: (bs->pmu->name ?: ""); + ret =3D strcmp(a_pmu_name, b_pmu_name); + if (ret) + return ret; + } + + /* Order by event name. */ + return strcmp(a_name, b_name); +} + +static bool pmu_alias_is_duplicate(struct sevent *alias_a, + struct sevent *alias_b) +{ + const char *a_pmu_name =3D NULL, *b_pmu_name =3D NULL; + const char *a_name =3D "//", *b_name =3D "//"; + + + if (alias_a->event) { + a_name =3D alias_a->event->name; + a_pmu_name =3D alias_a->event->pmu_name; + } + if (alias_b->event) { + b_name =3D alias_b->event->name; + b_pmu_name =3D alias_b->event->pmu_name; + } + + /* Different names -> never duplicates */ + if (strcmp(a_name, b_name)) + return false; + + /* Don't remove duplicates for different PMUs */ + a_pmu_name =3D a_pmu_name ?: (alias_a->pmu->name ?: ""); + b_pmu_name =3D b_pmu_name ?: (alias_b->pmu->name ?: ""); + return strcmp(a_pmu_name, b_pmu_name) =3D=3D 0; +} + +static int sub_non_neg(int a, int b) +{ + if (b > a) + return 0; + return a - b; +} + +static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, + const struct perf_pmu_alias *alias) +{ + struct parse_events_term *term; + int used =3D snprintf(buf, len, "%s/%s", pmu->name, alias->name); + + list_for_each_entry(term, &alias->terms, list) { + if (term->type_val =3D=3D PARSE_EVENTS__TERM_TYPE_STR) + used +=3D snprintf(buf + used, sub_non_neg(len, used), + ",%s=3D%s", term->config, + term->val.str); + } + + if (sub_non_neg(len, used) > 0) { + buf[used] =3D '/'; + used++; + } + if (sub_non_neg(len, used) > 0) { + buf[used] =3D '\0'; + used++; + } else + buf[len - 1] =3D '\0'; + + return buf; +} + +void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state) +{ + struct perf_pmu *pmu; + struct perf_pmu_alias *event; + char buf[1024]; + int printed =3D 0; + int len, j; + struct sevent *aliases; + + pmu =3D NULL; + len =3D 0; + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + list_for_each_entry(event, &pmu->aliases, list) + len++; + if (pmu->selectable) + len++; + } + aliases =3D zalloc(sizeof(struct sevent) * len); + if (!aliases) { + pr_err("FATAL: not enough memory to print PMU events\n"); + return; + } + pmu =3D NULL; + j =3D 0; + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + bool is_cpu =3D pmu->is_core; + + list_for_each_entry(event, &pmu->aliases, list) { + aliases[j].event =3D event; + aliases[j].pmu =3D pmu; + aliases[j].is_cpu =3D is_cpu; + j++; + } + if (pmu->selectable) { + aliases[j].event =3D NULL; + aliases[j].pmu =3D pmu; + aliases[j].is_cpu =3D is_cpu; + j++; + } + } + len =3D j; + qsort(aliases, len, sizeof(struct sevent), cmp_sevent); + for (j =3D 0; j < len; j++) { + const char *name, *alias =3D NULL, *scale_unit =3D NULL, + *desc =3D NULL, *long_desc =3D NULL, + *encoding_desc =3D NULL, *topic =3D NULL, + *pmu_name =3D NULL; + bool deprecated =3D false; + size_t buf_used; + + /* Skip duplicates */ + if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1])) + continue; + + if (!aliases[j].event) { + /* A selectable event. */ + pmu_name =3D aliases[j].pmu->name; + buf_used =3D snprintf(buf, sizeof(buf), "%s//", pmu_name) + 1; + name =3D buf; + } else { + if (aliases[j].event->desc) { + name =3D aliases[j].event->name; + buf_used =3D 0; + } else { + name =3D format_alias(buf, sizeof(buf), aliases[j].pmu, + aliases[j].event); + if (aliases[j].is_cpu) { + alias =3D name; + name =3D aliases[j].event->name; + } + buf_used =3D strlen(buf) + 1; + } + pmu_name =3D aliases[j].event->pmu_name ?: (aliases[j].pmu->name ?: ""); + if (strlen(aliases[j].event->unit) || aliases[j].event->scale !=3D 1.0)= { + scale_unit =3D buf + buf_used; + buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%G%s", aliases[j].event->scale, + aliases[j].event->unit) + 1; + } + desc =3D aliases[j].event->desc; + long_desc =3D aliases[j].event->long_desc; + topic =3D aliases[j].event->topic; + encoding_desc =3D buf + buf_used; + buf_used +=3D snprintf(buf + buf_used, sizeof(buf) - buf_used, + "%s/%s/", pmu_name, aliases[j].event->str) + 1; + deprecated =3D aliases[j].event->deprecated; + } + print_cb->print_event(print_state, + pmu_name, + topic, + name, + alias, + scale_unit, + deprecated, + "Kernel PMU event", + desc, + long_desc, + encoding_desc); + } + if (printed && pager_in_use()) + printf("\n"); + + zfree(&aliases); +} + +bool perf_pmus__have_event(const char *pname, const char *name) +{ + struct perf_pmu *pmu =3D perf_pmus__find(pname); + + return pmu && perf_pmu__have_event(pmu, name); +} + +bool perf_pmus__has_hybrid(void) +{ + static bool hybrid_scanned, has_hybrid; + + if (!hybrid_scanned) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + has_hybrid =3D true; + break; + } + } + hybrid_scanned =3D true; + } + return has_hybrid; +} + +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) +{ + struct perf_pmu *pmu =3D evsel->pmu; + + if (!pmu) { + pmu =3D perf_pmus__find_by_type(evsel->core.attr.type); + ((struct evsel *)evsel)->pmu =3D pmu; + } + return pmu; +} diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 257de10788e8..2a771d9f8da7 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -2,9 +2,21 @@ #ifndef __PMUS_H #define __PMUS_H =20 -extern struct list_head pmus; struct perf_pmu; +struct print_callbacks; + +void perf_pmus__destroy(void); + +struct perf_pmu *perf_pmus__find(const char *name); +struct perf_pmu *perf_pmus__find_by_type(unsigned int type); + +struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 +int perf_pmus__num_mem_pmus(void); +void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state); +bool perf_pmus__have_event(const char *pname, const char *name); +bool perf_pmus__has_hybrid(void); + #endif /* __PMUS_H */ diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 8d823bc906e6..9cee7bb7a561 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -20,6 +20,7 @@ #include "metricgroup.h" #include "parse-events.h" #include "pmu.h" +#include "pmus.h" #include "print-events.h" #include "probe-file.h" #include "string2.h" @@ -271,7 +272,7 @@ int print_hwcache_events(const struct print_callbacks *= print_cb, void *print_sta struct perf_pmu *pmu =3D NULL; const char *event_type_descriptor =3D event_type_descriptors[PERF_TYPE_HW= _CACHE]; =20 - while ((pmu =3D perf_pmu__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { /* * Skip uncore PMUs for performance. PERF_TYPE_HW_CACHE type * attributes can accept software PMUs in the extended type, so @@ -404,7 +405,7 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) =20 print_hwcache_events(print_cb, print_state); =20 - print_pmu_events(print_cb, print_state); + perf_pmus__print_pmu_events(print_cb, print_state); =20 print_cb->print_event(print_state, /*topic=3D*/NULL, diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 78ce7095dbcb..9355ddf7bca9 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -20,6 +20,7 @@ #include "util.h" #include "iostat.h" #include "pmu.h" +#include "pmus.h" =20 #define CNTR_NOT_SUPPORTED "" #define CNTR_NOT_COUNTED "" @@ -680,7 +681,7 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; =20 - if (!perf_pmu__has_hybrid()) + if (!perf_pmus__has_hybrid()) return false; =20 evlist__for_each_entry(evlist, evsel) { --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 E587EC7EE2C for ; Wed, 24 May 2023 22:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238295AbjEXWWB (ORCPT ); Wed, 24 May 2023 18:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235667AbjEXWVY (ORCPT ); Wed, 24 May 2023 18:21:24 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAFEDE59 for ; Wed, 24 May 2023 15:20:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561bad0999aso35279357b3.0 for ; Wed, 24 May 2023 15:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966782; x=1687558782; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=MvmCy8eCu3J+48fIwJySu6/NGqr6B+GI7lxSpQxNvyJQhdn/XJGu3tRQms8lXbb/mp fMXKKsCd5rbdAqCF1TmAHC2IcNQb8sG9HQlZs1Bwye+MlJl0dARXIlihtUJ5G9jn35vC n0bqk5RnApfckwFWdRl6CTxgRmShYFpM373VOmvX/4Bec6vOEjlIm8KscNwcB5MXLVXF HVuwl5z7sSqnm6fj2mh90+ZuwckfP6U/pUskAhby3ZSFzYnc4GKipfq/f4l1CpDL2/2Y 7B/6Ln9k5Cy61FE653HTiPUaHr2pBf+pxWhi7I2eKCQzggaAzXPVLm1SNAYK0n9q51Ym /dLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966782; x=1687558782; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GMM9vMp4aqYytcqLPDz/iiJMs6KDe9Jl9sq1ptTjl+0=; b=Mg24kBYAkEjAI8ZGuVcTqMeYCNpUQ4he3zH5LT/XZ2AW+r05SZ7MLP6cRW4jhEP7s0 2855jRk5VNyylOUfKYLZVPq9C0PYRQW0JDCOahXO6AgH+NZa7UoxgO+qfA4aQO+KI8Sb P2qdlWBqdeOYmk/xtjypCnjPXe9vbJgWWVi9AzILKjQ+mN7MAbh7Ojs4eiP9WhJ/DaA1 Q+2sPnKw+Z3CwmZBnkPXw2DiqiGAb+J3OxHG9YVK2pUvR2PjQeTqzEeB5EDcG/8U5Y9x Gr3NETy80Xhe50D/PYEAjXc3pD7oC4okawhDW+2pB86KfQkZI3TPt5RXNkgMp2baRBZz pcmQ== X-Gm-Message-State: AC+VfDyzjb6ygpb6w6Sikm4BeuU18Io0pCSh3P7ZxFIkLNgBKiaLF+O6 oKjhZ3OiLxoHdAO0C3fuozIc8MBN//Hq X-Google-Smtp-Source: ACHHUZ4Hie0jo3VkTqExA880N8d0gJAH1peyWNkf3rk0bbCBNfDD3lXI4p8YwUqyZJmk9SodS9Mg7Lbe60em X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ae21:0:b0:54c:7a1:ef50 with SMTP id m33-20020a81ae21000000b0054c07a1ef50mr11781823ywh.6.1684966782088; Wed, 24 May 2023 15:19:42 -0700 (PDT) Date: Wed, 24 May 2023 15:18:25 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-30-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 29/35] perf pmus: Split pmus list into core and other From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split the pmus list into core and other. This will later allow for the core and other pmus to be populated separately. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 58ff7937e9b7..4ef4fecd335f 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -12,13 +12,19 @@ #include "pmu.h" #include "print-events.h" =20 -static LIST_HEAD(pmus); +static LIST_HEAD(core_pmus); +static LIST_HEAD(other_pmus); =20 void perf_pmus__destroy(void) { struct perf_pmu *pmu, *tmp; =20 - list_for_each_entry_safe(pmu, tmp, &pmus, list) { + list_for_each_entry_safe(pmu, tmp, &core_pmus, list) { + list_del(&pmu->list); + + perf_pmu__delete(pmu); + } + list_for_each_entry_safe(pmu, tmp, &other_pmus, list) { list_del(&pmu->list); =20 perf_pmu__delete(pmu); @@ -29,7 +35,12 @@ static struct perf_pmu *pmu_find(const char *name) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) { + list_for_each_entry(pmu, &core_pmus, list) { + if (!strcmp(pmu->name, name) || + (pmu->alias_name && !strcmp(pmu->alias_name, name))) + return pmu; + } + list_for_each_entry(pmu, &other_pmus, list) { if (!strcmp(pmu->name, name) || (pmu->alias_name && !strcmp(pmu->alias_name, name))) return pmu; @@ -53,7 +64,7 @@ struct perf_pmu *perf_pmus__find(const char *name) return pmu; =20 dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(&pmus, dirfd, name); + pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); close(dirfd); =20 return pmu; @@ -72,7 +83,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const = char *name) if (pmu) return pmu; =20 - return perf_pmu__lookup(&pmus, dirfd, name); + return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -93,7 +104,7 @@ static void pmu_read_sysfs(void) while ((dent =3D readdir(dir))) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; - /* add to static LIST_HEAD(pmus): */ + /* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */ perf_pmu__find2(fd, dent->d_name); } =20 @@ -104,24 +115,37 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int= type) { struct perf_pmu *pmu; =20 - list_for_each_entry(pmu, &pmus, list) + list_for_each_entry(pmu, &core_pmus, list) { if (pmu->type =3D=3D type) return pmu; - + } + list_for_each_entry(pmu, &other_pmus, list) { + if (pmu->type =3D=3D type) + return pmu; + } return NULL; } =20 +/* + * pmu iterator: If pmu is NULL, we start at the begin, otherwise return t= he + * next pmu. Returns NULL on end. + */ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) { - /* - * pmu iterator: If pmu is NULL, we start at the begin, - * otherwise return the next pmu. Returns NULL on end. - */ + bool use_core_pmus =3D !pmu || pmu->is_core; + if (!pmu) { pmu_read_sysfs(); - pmu =3D list_prepare_entry(pmu, &pmus, list); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } + if (use_core_pmus) { + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + pmu =3D NULL; + pmu =3D list_prepare_entry(pmu, &other_pmus, list); } - list_for_each_entry_continue(pmu, &pmus, list) + list_for_each_entry_continue(pmu, &other_pmus, list) return pmu; return NULL; } --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 46668C77B7A for ; Wed, 24 May 2023 22:22:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237983AbjEXWWM (ORCPT ); Wed, 24 May 2023 18:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237942AbjEXWVg (ORCPT ); Wed, 24 May 2023 18:21:36 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0092BE61 for ; Wed, 24 May 2023 15:20:44 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5653a78102eso34985827b3.1 for ; Wed, 24 May 2023 15:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966784; x=1687558784; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=d2m8FCQU5f6Ioa+GIEPJ7ohNlU2+57v/29FfIGJHiv0=; b=Va09/5ZaUqbhLPfZ7TrX4BBZQZoQGTfF+SeSx/iytCLh0KsrwrSoC2trewGhWPSXYY dkTwu4wn5W1+1bje71GpkIQbkukCWg0QT138Ef8vJQRIJxfc4gVF72J97+H1NmGm/kjk zXqPWiq6b+Orn09zo5MtHRL/fxVV+469VR11hgThplEVolkhmbwSGIUiSytYBUZhIRfX NT4IC8mfgxbQlUEvkkJRBAfLxlJvFs+FhE3jM/yLmsl7YQnFJWiY/0xkYnhqUDdwTSZl b8A2Wgei3PQD9H3cpQJ+vSi6Msndtv+h8meWaQy8B85mf8/wAXx8ouzKaOdfVSDFs/8C 9Uhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966784; x=1687558784; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d2m8FCQU5f6Ioa+GIEPJ7ohNlU2+57v/29FfIGJHiv0=; b=kTgehC3iySvQcJBI0kkISpvWTNApaP2gU/cH5Otwz8rpo4fbBeF94oCRp/CJ2Aunys xcuHPMZpqxhbcPcv6SRZlP6ti1/fLGLqStFY8qZAGNLQp98OWTVOlYPjcBuuWduoysh9 jkIllbgHAjD4PoEW0sTSCOvfrHU4t0MEFUnRdtkbpgAfqqsFhXGtyW2hE3m59g4EKSAL X7WcoZEQ9vGgPwOfJB4dYG1kTtTsY3FYt2GvuBuSep/3AMfNgqAx8JEzYtA9v7AxNILx JWUquK8SRtc8TgL+gpeGGqf18OELZ61WkYTrdFWziWumtW9Dynww1fJjEpP/mdsjvhnC 90kw== X-Gm-Message-State: AC+VfDxnbYyTwwSGNcp3lv/PPcNAPu8iuSLsLviYGE22K8Lh6DQxahGW CEnO98UX8r+lRxJRVSsHWDKDGpHQbKwE X-Google-Smtp-Source: ACHHUZ4wp88axtZPHvM6PTguaDmtoSJ7Qj52twoEY9CYUQFgaP+3FnjovPD4S2qtxWEA+PKxnLZYX8XXaw6C X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ae21:0:b0:54c:7a1:ef50 with SMTP id m33-20020a81ae21000000b0054c07a1ef50mr11781887ywh.6.1684966784349; Wed, 24 May 2023 15:19:44 -0700 (PDT) Date: Wed, 24 May 2023 15:18:26 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-31-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 30/35] perf pmus: Allow just core PMU scanning From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Scanning all PMUs is expensive as all PMUs sysfs entries are loaded, benchmarking shows more than 4x the cost: ``` $ perf bench internals pmu-scan -i 1000 Computing performance of sysfs PMU event scan for 1000 times Average core PMU scanning took: 989.231 usec (+- 1.535 usec) Average PMU scanning took: 4309.425 usec (+- 74.322 usec) ``` Add new perf_pmus__scan_core routine that scans just core PMUs. Replace perf_pmus__scan calls with perf_pmus__scan_core when non-core PMUs are being ignored. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/arm64/util/pmu.c | 5 +-- tools/perf/arch/x86/util/evlist.c | 5 +-- tools/perf/arch/x86/util/perf_regs.c | 8 ++--- tools/perf/bench/pmu-scan.c | 50 ++++++++++++++++------------ tools/perf/tests/pmu-events.c | 5 +-- tools/perf/util/cputopo.c | 12 +++---- tools/perf/util/header.c | 5 +-- tools/perf/util/mem-events.c | 14 ++------ tools/perf/util/parse-events.c | 13 +++----- tools/perf/util/pmu.c | 10 ------ tools/perf/util/pmu.h | 2 -- tools/perf/util/pmus.c | 30 ++++++++++++----- tools/perf/util/pmus.h | 1 + tools/perf/util/print-events.c | 11 +++--- 14 files changed, 75 insertions(+), 96 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/= pmu.c index 2504d43a39a7..561de0cb6b95 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -11,10 +11,7 @@ static struct perf_pmu *pmu__find_core_pmu(void) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu))) { - if (!is_pmu_core(pmu->name)) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu))) { /* * The cpumap should cover all CPUs. Otherwise, some CPUs may * not support some events or have different event IDs. diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 03240c640c7f..8a6a0b98b976 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -33,13 +33,10 @@ static int ___evlist__add_default_attrs(struct evlist *= evlist, continue; } =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { struct perf_cpu_map *cpus; struct evsel *evsel; =20 - if (!pmu->is_core) - continue; - evsel =3D evsel__new(attrs + i); if (evsel =3D=3D NULL) goto out_delete_partial_list; diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index befa7f3659b9..116384f19baf 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -300,11 +300,9 @@ uint64_t arch__intr_reg_mask(void) * The same register set is supported among different hybrid PMUs. * Only check the first available one. */ - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core) { - type =3D pmu->type; - break; - } + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + type =3D pmu->type; + break; } attr.config |=3D type << PERF_PMU_TYPE_SHIFT; } diff --git a/tools/perf/bench/pmu-scan.c b/tools/perf/bench/pmu-scan.c index 51cae2d03353..c7d207f8e13c 100644 --- a/tools/perf/bench/pmu-scan.c +++ b/tools/perf/bench/pmu-scan.c @@ -22,6 +22,7 @@ struct pmu_scan_result { int nr_aliases; int nr_formats; int nr_caps; + bool is_core; }; =20 static const struct option options[] =3D { @@ -53,6 +54,7 @@ static int save_result(void) r =3D results + nr_pmus; =20 r->name =3D strdup(pmu->name); + r->is_core =3D pmu->is_core; r->nr_caps =3D pmu->nr_caps; =20 r->nr_aliases =3D 0; @@ -72,7 +74,7 @@ static int save_result(void) return 0; } =20 -static int check_result(void) +static int check_result(bool core_only) { struct pmu_scan_result *r; struct perf_pmu *pmu; @@ -81,6 +83,9 @@ static int check_result(void) =20 for (int i =3D 0; i < nr_pmus; i++) { r =3D &results[i]; + if (core_only && !r->is_core) + continue; + pmu =3D perf_pmus__find(r->name); if (pmu =3D=3D NULL) { pr_err("Cannot find PMU %s\n", r->name); @@ -130,7 +135,6 @@ static int run_pmu_scan(void) struct timeval start, end, diff; double time_average, time_stddev; u64 runtime_us; - unsigned int i; int ret; =20 init_stats(&stats); @@ -142,26 +146,30 @@ static int run_pmu_scan(void) return -1; } =20 - for (i =3D 0; i < iterations; i++) { - gettimeofday(&start, NULL); - perf_pmus__scan(NULL); - gettimeofday(&end, NULL); - - timersub(&end, &start, &diff); - runtime_us =3D diff.tv_sec * USEC_PER_SEC + diff.tv_usec; - update_stats(&stats, runtime_us); - - ret =3D check_result(); - perf_pmus__destroy(); - if (ret < 0) - break; + for (int j =3D 0; j < 2; j++) { + bool core_only =3D (j =3D=3D 0); + + for (unsigned int i =3D 0; i < iterations; i++) { + gettimeofday(&start, NULL); + if (core_only) + perf_pmus__scan_core(NULL); + else + perf_pmus__scan(NULL); + gettimeofday(&end, NULL); + timersub(&end, &start, &diff); + runtime_us =3D diff.tv_sec * USEC_PER_SEC + diff.tv_usec; + update_stats(&stats, runtime_us); + + ret =3D check_result(core_only); + perf_pmus__destroy(); + if (ret < 0) + break; + } + time_average =3D avg_stats(&stats); + time_stddev =3D stddev_stats(&stats); + pr_info(" Average%s PMU scanning took: %.3f usec (+- %.3f usec)\n", + core_only ? " core" : "", time_average, time_stddev); } - - time_average =3D avg_stats(&stats); - time_stddev =3D stddev_stats(&stats); - pr_info(" Average PMU scanning took: %.3f usec (+- %.3f usec)\n", - time_average, time_stddev); - delete_result(); return 0; } diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 64ecb7845af4..64383fc34ef1 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -709,12 +709,9 @@ static int test__aliases(struct test_suite *test __may= be_unused, struct perf_pmu *pmu =3D NULL; unsigned long i; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { int count =3D 0; =20 - if (!is_pmu_core(pmu->name)) - continue; - if (list_empty(&pmu->format)) { pr_debug2("skipping testing core PMU %s\n", pmu->name); continue; diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 4578c26747e1..729142ec9a9a 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -477,10 +477,9 @@ struct hybrid_topology *hybrid_topology__new(void) if (!perf_pmus__has_hybrid()) return NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core) - nr++; - } + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) + nr++; + if (nr =3D=3D 0) return NULL; =20 @@ -489,10 +488,7 @@ struct hybrid_topology *hybrid_topology__new(void) return NULL; =20 tp->nr =3D nr; - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { if (load_hybrid_node(&tp->nodes[i], pmu)) { hybrid_topology__delete(tp); return NULL; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index fa3f7dbbd90e..c701cc474d79 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1591,10 +1591,7 @@ static int write_pmu_caps(struct feat_fd *ff, */ if (perf_pmus__has_hybrid()) { pmu =3D NULL; - while ((pmu =3D perf_pmus__scan(pmu))) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu))) { ret =3D __write_pmu_caps(ff, pmu, true); if (ret < 0) return ret; diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 08ac3ea2e366..c5596230a308 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -136,10 +136,7 @@ int perf_mem_events__init(void) } else { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); @@ -176,10 +173,7 @@ static void perf_mem_events__print_unsupport_hybrid(st= ruct perf_mem_event *e, char sysfs_name[100]; struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; - + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); if (!perf_mem_event__supported(mnt, sysfs_name)) { @@ -217,9 +211,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, return -1; } =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (!pmu->is_core) - continue; + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { rec_argv[i++] =3D "-e"; s =3D perf_mem_events__name(j, pmu->name); if (s) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index be544f948be2..e0c3f2037477 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -453,15 +453,12 @@ int parse_events_add_cache(struct list_head *list, in= t *idx, const char *name, const char *config_name =3D get_config_name(head_config); const char *metric_id =3D get_config_metric_id(head_config); =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + /* Legacy cache events are only supported by core PMUs. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; =20 - /* Skip unsupported PMUs. */ - if (!perf_pmu__supports_legacy_cache(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; =20 @@ -1481,12 +1478,10 @@ int parse_events_add_numeric(struct parse_events_st= ate *parse_state, return __parse_events_add_numeric(parse_state, list, /*pmu=3D*/NULL, type, config, head_config); =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { + /* Wildcards on numeric values are only supported by core PMUs. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { int ret; =20 - if (!perf_pmu__supports_wildcard_numeric(pmu)) - continue; - if (parse_events__filter_pmu(parse_state, pmu)) continue; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 044f31f9d0ff..4dd40a38f6bf 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1440,21 +1440,11 @@ bool perf_pmu__supports_legacy_cache(const struct p= erf_pmu *pmu) return pmu->is_core; } =20 -bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) -{ - return pmu->is_core; -} - bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { return !is_pmu_hybrid(pmu->name); } =20 -bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu) -{ - return pmu->is_core; -} - bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name) { struct perf_pmu_alias *alias; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index f1f3e8a2e00e..02fec0a7d4c8 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -223,9 +223,7 @@ void perf_pmu__del_formats(struct list_head *formats); bool is_pmu_core(const char *name); bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); -bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); -bool perf_pmu__is_mem_pmu(const struct perf_pmu *pmu); bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name); =20 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name); diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 4ef4fecd335f..de7fc36519c9 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -87,7 +87,7 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const = char *name) } =20 /* Add all pmus in sysfs to pmu list: */ -static void pmu_read_sysfs(void) +static void pmu_read_sysfs(bool core_only) { int fd; DIR *dir; @@ -104,6 +104,8 @@ static void pmu_read_sysfs(void) while ((dent =3D readdir(dir))) { if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) continue; + if (core_only && !is_pmu_core(dent->d_name)) + continue; /* add to static LIST_HEAD(core_pmus) or LIST_HEAD(other_pmus): */ perf_pmu__find2(fd, dent->d_name); } @@ -135,7 +137,7 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) bool use_core_pmus =3D !pmu || pmu->is_core; =20 if (!pmu) { - pmu_read_sysfs(); + pmu_read_sysfs(/*core_only=3D*/false); pmu =3D list_prepare_entry(pmu, &core_pmus, list); } if (use_core_pmus) { @@ -150,6 +152,18 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu) return NULL; } =20 +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu) +{ + if (!pmu) { + pmu_read_sysfs(/*core_only=3D*/true); + pmu =3D list_prepare_entry(pmu, &core_pmus, list); + } + list_for_each_entry_continue(pmu, &core_pmus, list) + return pmu; + + return NULL; +} + const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) { struct perf_pmu *pmu =3D NULL; @@ -176,10 +190,10 @@ int perf_pmus__num_mem_pmus(void) struct perf_pmu *pmu =3D NULL; int count =3D 0; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (perf_pmu__is_mem_pmu(pmu)) - count++; - } + /* All core PMUs are for mem events. */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) + count++; + return count; } =20 @@ -421,8 +435,8 @@ bool perf_pmus__has_hybrid(void) if (!hybrid_scanned) { struct perf_pmu *pmu =3D NULL; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - if (pmu->is_core && is_pmu_hybrid(pmu->name)) { + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + if (is_pmu_hybrid(pmu->name)) { has_hybrid =3D true; break; } diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 2a771d9f8da7..9de0222ed52b 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -11,6 +11,7 @@ struct perf_pmu *perf_pmus__find(const char *name); struct perf_pmu *perf_pmus__find_by_type(unsigned int type); =20 struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu); +struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu); =20 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str); =20 diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 9cee7bb7a561..7a5f87392720 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -272,12 +272,11 @@ int print_hwcache_events(const struct print_callbacks= *print_cb, void *print_sta struct perf_pmu *pmu =3D NULL; const char *event_type_descriptor =3D event_type_descriptors[PERF_TYPE_HW= _CACHE]; =20 - while ((pmu =3D perf_pmus__scan(pmu)) !=3D NULL) { - /* - * Skip uncore PMUs for performance. PERF_TYPE_HW_CACHE type - * attributes can accept software PMUs in the extended type, so - * also skip. - */ + /* + * Only print core PMUs, skipping uncore for performance and + * PERF_TYPE_SOFTWARE that can succeed in opening legacy cache evenst. + */ + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { if (pmu->is_uncore || pmu->type =3D=3D PERF_TYPE_SOFTWARE) continue; =20 --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 9A0E0C77B7C for ; Wed, 24 May 2023 22:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238378AbjEXWWR (ORCPT ); Wed, 24 May 2023 18:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237776AbjEXWVk (ORCPT ); Wed, 24 May 2023 18:21:40 -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 D33D210FB for ; Wed, 24 May 2023 15:20:55 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-564f6099813so29602187b3.2 for ; Wed, 24 May 2023 15:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966787; x=1687558787; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Oxcc/fbHqqjPzgaZ7RoCmF9ePDnlZuETNbTW2zw+MN8=; b=4r0YNvfUcwIDoJ2EzMpnJcIyMz4UPDfw4aLOoOLXEvSFAABfi/cJgQVwjJTD5eTYZr 1feUPiAb6nqK3LtcPFGwHKEz0eSrVWniMGNsr027dyp1mV/8NUmZdyMHe11WziC822SE mDKwrtajc1w+upC/UnBE92BB+egOUCfeqLUSLc8sg7KcnTIp+WJLMARWI2AxWqj6LieQ +WxqqvJXfPNkdV1mrh1OyY3z8AT12zn97m5dloj6c0uefZ54+BaNWrAXP4KCd6M7SUGA 6mRPDf3Lr4MVRAX51s8H8yIoVdm36qnVZ6H6Hb82EbxDLFBlNVgtaqIFodgQz0iIkZYJ z6tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966787; x=1687558787; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Oxcc/fbHqqjPzgaZ7RoCmF9ePDnlZuETNbTW2zw+MN8=; b=Xomh7opxjlRLGA1LcUzkJ2xeTefyzXBuEmfWuFfn5fSb8hAaVJl3GodmTsYQri6Rfn no/AmZ2gLd7gcZKabFw3Pps+ULB7G6v6m2tolyY85dtsSrxubH5PmKp7zt12+09/Sl1u k+6G2gRBiYTZFM2CJl24zL9bxn4CrbilI6RGyMmJIAxFptLqrgQWokMQo7uA8dP2xeZa CaLGgi+pR6afz8U2iSIXqv1GH1vtAvhMzUuEYK2V2sT0k6XaPWxuiJ7zMXYl/6IYx0tp smXcVPOimxJLT88kZIURpx7+WpaR/VSGDdkb68nGqyxNJW3r2hRyYaBLnG38GM7vaCH+ u14w== X-Gm-Message-State: AC+VfDxKSyfYAHqYrVhPArHTro6xkDVlAi9EAA2PbxRymk9fXuikSMwO 3XdfvKwF7Z4InL7VfkKUt8pVElg+u1Li X-Google-Smtp-Source: ACHHUZ4hxYOEKZAlxv6B/ZHjwYUBf7VbvsH4D70/hGfEFD0oIKDcCPEkaro3LYXhusi1YwNICEQTUx63uNUk X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:ae68:0:b0:561:94a8:29c5 with SMTP id g40-20020a81ae68000000b0056194a829c5mr11391391ywk.4.1684966787215; Wed, 24 May 2023 15:19:47 -0700 (PDT) Date: Wed, 24 May 2023 15:18:27 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-32-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 31/35] perf pmus: Avoid repeated sysfs scanning From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmus__scan will process every directory in sysfs to see if it is a PMU, attempting to add it if not already in the pmus list. Add two booleans to record whether this scanning has been done for core or all PMUs. Skip scanning in the event that scanning has already occurred. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index de7fc36519c9..2c512345191d 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -14,6 +14,8 @@ =20 static LIST_HEAD(core_pmus); static LIST_HEAD(other_pmus); +static bool read_sysfs_core_pmus; +static bool read_sysfs_all_pmus; =20 void perf_pmus__destroy(void) { @@ -29,6 +31,8 @@ void perf_pmus__destroy(void) =20 perf_pmu__delete(pmu); } + read_sysfs_core_pmus =3D false; + read_sysfs_all_pmus =3D false; } =20 static struct perf_pmu *pmu_find(const char *name) @@ -53,6 +57,7 @@ struct perf_pmu *perf_pmus__find(const char *name) { struct perf_pmu *pmu; int dirfd; + bool core_pmu; =20 /* * Once PMU is loaded it stays in the list, @@ -63,8 +68,15 @@ struct perf_pmu *perf_pmus__find(const char *name) if (pmu) return pmu; =20 + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, di= rfd, name); + pmu =3D perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name= ); close(dirfd); =20 return pmu; @@ -73,6 +85,7 @@ struct perf_pmu *perf_pmus__find(const char *name) static struct perf_pmu *perf_pmu__find2(int dirfd, const char *name) { struct perf_pmu *pmu; + bool core_pmu; =20 /* * Once PMU is loaded it stays in the list, @@ -83,7 +96,14 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, const= char *name) if (pmu) return pmu; =20 - return perf_pmu__lookup(is_pmu_core(name) ? &core_pmus : &other_pmus, dir= fd, name); + if (read_sysfs_all_pmus) + return NULL; + + core_pmu =3D is_pmu_core(name); + if (core_pmu && read_sysfs_core_pmus) + return NULL; + + return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); } =20 /* Add all pmus in sysfs to pmu list: */ @@ -93,6 +113,9 @@ static void pmu_read_sysfs(bool core_only) DIR *dir; struct dirent *dent; =20 + if (read_sysfs_all_pmus || (core_only && read_sysfs_core_pmus)) + return; + fd =3D perf_pmu__event_source_devices_fd(); if (fd < 0) return; @@ -111,6 +134,12 @@ static void pmu_read_sysfs(bool core_only) } =20 closedir(dir); + if (core_only) { + read_sysfs_core_pmus =3D true; + } else { + read_sysfs_core_pmus =3D true; + read_sysfs_all_pmus =3D true; + } } =20 struct perf_pmu *perf_pmus__find_by_type(unsigned int type) --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 F0F03C77B7A for ; Wed, 24 May 2023 22:22:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238298AbjEXWWa (ORCPT ); Wed, 24 May 2023 18:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238285AbjEXWVq (ORCPT ); Wed, 24 May 2023 18:21:46 -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 F367B1A1 for ; Wed, 24 May 2023 15:21:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-babb3528ce5so2695632276.1 for ; Wed, 24 May 2023 15:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966789; x=1687558789; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Yt6BXRhpcaagH+Rv9t2cYW9/1vlblP5mhKX6P/6LKqg=; b=dJbzSZQQie8CHjExrHF45ZUOMtyCX1iCnt44dhP0OcA5CdcTLww+elNVsvkuol2Vqo 6SAtAw+mNF64uiMUukV3FIbXgscnC1H8RCedPPxT5kIPawwbC1Azu8buOB18bZXd+OBh K3tOIFrGyS9Dw+tYYATG1AYjKwtz4qN4zHHTljemHMmZIW5OkZgdqresjHxIHakHZCzR EmD55LBaK2EO2bV3CAnhi+0njGSbHSFnrYT/+5aU0DvPHHsrzXclbobUBLfZRGF2mCZj 7JM5COM39iCmu26T0JCSACrCzOLBe9AmUPWFHwldn/SzoFkfA1BoWDjl8nwEoAD3lIb5 CapA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966789; x=1687558789; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yt6BXRhpcaagH+Rv9t2cYW9/1vlblP5mhKX6P/6LKqg=; b=Jaj09XycLnMAtaIeHq380/L3WOzmf0RAe55SBI+8e5qkWZWLpRXwbn77hL7ByJ4cNO lpO+hyMzX27BpYpHxO2YCUtBZhMPd0wwvjGV/SbFAXWtp0v4jv5koGW178XZ2q1HUK39 sIKGPx4dwGfpFwYoSvQVkYkGovF1hOv5BPjP8XEgVQucbkVI5f8gOnKEXs4EKPG1BD+f qjrME9ZtPZgBx5Bnu/uUu4R+0shMXmqMUVMS6JXYyXT6AWk7FVehP9dOHIyCuFrohnsx wbUWM7C4u3riTQmhNDVi0x1nJiDR7l/hC2em64ma8mevb8asEfXWo3M8V3Xb8EHY2tph kdwA== X-Gm-Message-State: AC+VfDwLX9HGMoa4a9xv7TAAyPETGJwe4ql7zB837Fy9hJ2gVtf+9KXN 7FOtxwC0mNoINOQWW+LMFObh5CnEO+8K X-Google-Smtp-Source: ACHHUZ5oTxfW0VyTQCXsS1bjQIoxiAPiAEQHOJqrX6Swyr52eRMCYLy2UrYgwc4t82Dkyrnr017L3WqUUqX6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:2414:0:b0:ba7:68ff:a441 with SMTP id k20-20020a252414000000b00ba768ffa441mr605861ybk.0.1684966789477; Wed, 24 May 2023 15:19:49 -0700 (PDT) Date: Wed, 24 May 2023 15:18:28 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-33-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 32/35] perf pmus: Ensure all PMUs are read for find_by_type From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmus__find_by_type may be called for something like a raw event, in which case the PMU isn't guaranteed to have been looked up. Add a second check to make sure all PMUs are loaded. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 2c512345191d..6ecccb5ad03e 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -142,7 +142,7 @@ static void pmu_read_sysfs(bool core_only) } } =20 -struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +static struct perf_pmu *__perf_pmus__find_by_type(unsigned int type) { struct perf_pmu *pmu; =20 @@ -150,6 +150,7 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int t= ype) if (pmu->type =3D=3D type) return pmu; } + list_for_each_entry(pmu, &other_pmus, list) { if (pmu->type =3D=3D type) return pmu; @@ -157,6 +158,18 @@ struct perf_pmu *perf_pmus__find_by_type(unsigned int = type) return NULL; } =20 +struct perf_pmu *perf_pmus__find_by_type(unsigned int type) +{ + struct perf_pmu *pmu =3D __perf_pmus__find_by_type(type); + + if (pmu || read_sysfs_all_pmus) + return pmu; + + pmu_read_sysfs(/*core_only=3D*/false); + pmu =3D __perf_pmus__find_by_type(type); + return pmu; +} + /* * pmu iterator: If pmu is NULL, we start at the begin, otherwise return t= he * next pmu. Returns NULL on end. --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 C1F15C77B7A for ; Wed, 24 May 2023 22:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238434AbjEXWWe (ORCPT ); Wed, 24 May 2023 18:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238307AbjEXWWH (ORCPT ); Wed, 24 May 2023 18:22:07 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D29DE6F for ; Wed, 24 May 2023 15:21:13 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-255dfed764dso765811a91.1 for ; Wed, 24 May 2023 15:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966792; x=1687558792; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=dtfIK0Ng/M2Pg4C34SglSHaqm2V1d201IwuIsvGzJ2Y=; b=jZqOUs4khalhefWZA9ZH5Cd3Ak1pZuDgONShr5OBFfs90o9+6fZ+v/uPtshEsqbn5D cSeOiEQMwnIcIpdU4Q9uR4gXcwb67sUxfNNC6qgG8f+UFz+3ChzROoXCnoGdMTgpHS5j fKudJ7McBlaqp4uNamm9fScATnN3d//SXLTOCFVT2WAAIzGn+4ffUzdWYkIw+VZB5O55 aAq3mAUfDSxUhzH00Y5i8001CewqddXbVpPRVEXJrQaq9Ij2DKPsdrDvX992n2uziLlo qW/TBZCbnVYFlkw+ZvwdbbEFnTlA+wBYepun9M9kdevhU8ALCHQ19BTnnoJBQ4rWdozH CXzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966792; x=1687558792; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dtfIK0Ng/M2Pg4C34SglSHaqm2V1d201IwuIsvGzJ2Y=; b=YCAFO3eSEj9RfW9Uhgx87rt9u/1/qlbIiuxRG2WHIoSUyPDpt+W91m9MkKm9dxjqDd zw4TCwFdEJZznp9OuiWfK1LmTvuiyskbYsdPmGry6cMroFDPzeOkbpOJhRlRaEiaU4rQ 86tGL8HGp0r2FdQ9RN+6g7VPbmdoyg3GSQrxBiO4R042n9ZkIjfpxFxyN1bGnuT5Wwjx ylzGGHyAqCyj9yAZUCQtXnsNM9Ig7v5HVoWQrHDSVBwUeDr+csp+vyKvam7WftidD12C rIwpY2Hh64P9FuzoJDw84UaoHrpbDu8ps67p/S5SKXfeWmTdPlbTw3jJZZx05YRhejIl Fgvg== X-Gm-Message-State: AC+VfDx/K+4cUMppeJx1BaLkjmqmmpBbziwp+9ne7m7/md7nsO3Vv4Vj 39Gj1cIvvnbs/TUSas0E3VvQManG6N93 X-Google-Smtp-Source: ACHHUZ4Gz3sOCvjHJxUs0XNMvaqhY/GCtlI3yryh2ai00McLuG0za9EWtTnr4ygxbEv+fbo273yNoWXm8EPG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a17:90a:2e12:b0:253:2388:9d44 with SMTP id q18-20020a17090a2e1200b0025323889d44mr4425400pjd.9.1684966791898; Wed, 24 May 2023 15:19:51 -0700 (PDT) Date: Wed, 24 May 2023 15:18:29 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-34-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 33/35] perf pmus: Add function to return count of core PMUs From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add perf_pmus__num_core_pmus that will count core PMUs holding the result in a static. Reuse for perf_pmus__num_mem_pmus. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmus.c | 21 ++++++++++++++------- tools/perf/util/pmus.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 6ecccb5ad03e..bf927aed162e 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -229,14 +229,8 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(c= onst char *str) =20 int perf_pmus__num_mem_pmus(void) { - struct perf_pmu *pmu =3D NULL; - int count =3D 0; - /* All core PMUs are for mem events. */ - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) - count++; - - return count; + return perf_pmus__num_core_pmus(); } =20 /** Struct for ordering events as output in perf list. */ @@ -488,6 +482,19 @@ bool perf_pmus__has_hybrid(void) return has_hybrid; } =20 +int perf_pmus__num_core_pmus(void) +{ + static int count; + + if (!count) { + struct perf_pmu *pmu =3D NULL; + + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) + count++; + } + return count; +} + struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) { struct perf_pmu *pmu =3D evsel->pmu; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 9de0222ed52b..27400a027d41 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -19,5 +19,6 @@ int perf_pmus__num_mem_pmus(void); void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state); bool perf_pmus__have_event(const char *pname, const char *name); bool perf_pmus__has_hybrid(void); +int perf_pmus__num_core_pmus(void); =20 #endif /* __PMUS_H */ --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 4DF0FC77B7A for ; Wed, 24 May 2023 22:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238454AbjEXWWj (ORCPT ); Wed, 24 May 2023 18:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238062AbjEXWWJ (ORCPT ); Wed, 24 May 2023 18:22:09 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A54E78 for ; Wed, 24 May 2023 15:21:15 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-5308f5d8ac9so493440a12.0 for ; Wed, 24 May 2023 15:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966794; x=1687558794; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=g/iZTM2aqbni2uB+Hg7SvwR++buyFhodRiSlbt2iVyU=; b=dLD9deZmA02GoycwjkRiVoNs/vnDMedu8HA7qp1GXV3CIClVgku58vrDCICs08/ckp SMqDYuEqxXRARF/PupH0uIzZ8FHajKJVVyKpX26+qtwuUpRWjjNfEaBwkkQ22HfYPtGJ sQaJXyZtNGE7Mig1m7xblEtlVG/meWQDhxdcajAXqYaVPCkK6iSSvI/lWkrn5wZk0a5a NouJjzmVv8GafduVjcLvGgdR6vE7bpmmE76AIi4Z4kXcnATkOE04I+YP0i5+YCDO6IGd 2CvY6HReKB1Nfx56CHAYF5tJQ5oduOQX9YbLk73NlIujYs8EHhFWXtqyvrWImXU1l4Ak aeyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966794; x=1687558794; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g/iZTM2aqbni2uB+Hg7SvwR++buyFhodRiSlbt2iVyU=; b=X9TME1ruGCUBOJ2aANOPoLR5ZWrl1tO6FAFS+AlkLHSpvhXzt0VM14MEy+2PnUM9Kv gJxkRK48Zt4T+tJlXdldoLBQhc1K6Q1EiwpJ1syv8jZo1/XJE0m5k/84Y14Axa4Bc7U1 vjf6opNEQ0XkehNvSWZyxmT1eicKoe/iEM6U9uqXRPdZGAN8gJp69mkfDKf3ztvnPRkB tD5RHuW9z0bf2xCJzTwkWu+1nqxe6gpVJfLMxbWxhnFuBf47d6zJn/mShOCb4HcaxdjH H1lwekjaziZGn9RbahQ+hx2nKP6eLeFmQ0UlEr8Sw+AhrlfkYMjeHD2W04gNSfYRPw9a qQFw== X-Gm-Message-State: AC+VfDy+DPY111PYyY5B8rFxYizdpAz7bJMs8Yl/PoLB4Pqo69+i7iWP 9kmS4khiW0uMXdLmnqAClCLEbHsaL7/d X-Google-Smtp-Source: ACHHUZ4SSq9UXIUiH8EplnISYn5LMtWSPpN2w9m8dM3mE9z4cvTM+eRhuwtF+5JhLaFSqJceJBbJ8FIWS/PG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a63:ba06:0:b0:51b:500e:55d3 with SMTP id k6-20020a63ba06000000b0051b500e55d3mr4500102pgf.6.1684966794346; Wed, 24 May 2023 15:19:54 -0700 (PDT) Date: Wed, 24 May 2023 15:18:30 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-35-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 34/35] perf pmus: Remove perf_pmus__has_hybrid From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org 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_pmus__has_hybrid was used to detect when there was >1 core PMU, this can be achieved with perf_pmus__num_core_pmus that doesn't depend upon is_pmu_hybrid and PMU name comparisons. When modifying the function calls take the opportunity to improve comments, enable/simplify tests that were previously failing for hybrid but now pass and to simplify generic code. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/arch/x86/tests/hybrid.c | 2 +- tools/perf/arch/x86/util/evlist.c | 2 +- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/builtin-record.c | 4 ++-- tools/perf/tests/attr.c | 9 ++++++++- tools/perf/tests/parse-metric.c | 7 ++----- tools/perf/tests/switch-tracking.c | 12 +----------- tools/perf/tests/topology.c | 14 ++------------ tools/perf/util/cputopo.c | 10 ++-------- tools/perf/util/evsel.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/mem-events.c | 18 +++++------------- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/pmus.c | 18 ------------------ tools/perf/util/pmus.h | 1 - tools/perf/util/stat-display.c | 2 +- 16 files changed, 29 insertions(+), 78 deletions(-) diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index e466735d68d5..eb152770f148 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -281,7 +281,7 @@ static int test_events(const struct evlist_test *events= , int cnt) =20 int test__hybrid(struct test_suite *test __maybe_unused, int subtest __may= be_unused) { - if (!perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() =3D=3D 1) return TEST_SKIP; =20 return test_events(test__hybrid_events, ARRAY_SIZE(test__hybrid_events)); diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 8a6a0b98b976..cbd582182932 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -18,7 +18,7 @@ static int ___evlist__add_default_attrs(struct evlist *ev= list, for (i =3D 0; i < nr_attrs; i++) event_attr_init(attrs + i); =20 - if (!perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() =3D=3D 1) return evlist__add_attrs(evlist, attrs, nr_attrs); =20 for (i =3D 0; i < nr_attrs; i++) { diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/uti= l/perf_regs.c index 116384f19baf..8ad4112ad10c 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c @@ -292,7 +292,7 @@ uint64_t arch__intr_reg_mask(void) */ attr.sample_period =3D 1; =20 - if (perf_pmus__has_hybrid()) { + if (perf_pmus__num_core_pmus() > 1) { struct perf_pmu *pmu =3D NULL; __u64 type =3D PERF_TYPE_RAW; =20 diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 4b9212f75493..aec18db7ff23 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1294,7 +1294,7 @@ static int record__open(struct record *rec) * of waiting or event synthesis. */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || - perf_pmus__has_hybrid()) { + perf_pmus__num_core_pmus() > 1) { pos =3D evlist__get_tracking_event(evlist); if (!evsel__is_dummy_event(pos)) { /* Set up dummy event. */ @@ -2193,7 +2193,7 @@ static void record__uniquify_name(struct record *rec) char *new_name; int ret; =20 - if (!perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() =3D=3D 1) return; =20 evlist__for_each_entry(evlist, pos) { diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 674876e6c8e6..61186d0d1cfa 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -185,8 +185,15 @@ static int test__attr(struct test_suite *test __maybe_= unused, int subtest __mayb char path_dir[PATH_MAX]; char *exec_path; =20 - if (perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() > 1) { + /* + * TODO: Attribute tests hard code the PMU type. If there are >1 + * core PMU then each PMU will have a different type whic + * requires additional support. + */ + pr_debug("Skip test on hybrid systems"); return TEST_SKIP; + } =20 /* First try development tree tests. */ if (!lstat("./tests", &st)) diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metri= c.c index 1d6493a5a956..2c28fb50dc24 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -302,11 +302,8 @@ static int test__parse_metric(struct test_suite *test = __maybe_unused, int subtes TEST_ASSERT_VAL("DCache_L2 failed", test_dcache_l2() =3D=3D 0); TEST_ASSERT_VAL("recursion fail failed", test_recursion_fail() =3D=3D 0); TEST_ASSERT_VAL("Memory bandwidth", test_memory_bandwidth() =3D=3D 0); - - if (!perf_pmus__has_hybrid()) { - TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() =3D= =3D 0); - TEST_ASSERT_VAL("test metric group", test_metric_group() =3D=3D 0); - } + TEST_ASSERT_VAL("cache_miss_cycles failed", test_cache_miss_cycles() =3D= =3D 0); + TEST_ASSERT_VAL("test metric group", test_metric_group() =3D=3D 0); return 0; } =20 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index cff6ab87b2f6..e52b031bedc5 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -375,17 +375,7 @@ static int test__switch_tracking(struct test_suite *te= st __maybe_unused, int sub cpu_clocks_evsel =3D evlist__last(evlist); =20 /* Second event */ - if (perf_pmus__has_hybrid()) { - cycles =3D "cpu_core/cycles/u"; - err =3D parse_event(evlist, cycles); - if (err) { - cycles =3D "cpu_atom/cycles/u"; - pr_debug("Trying %s\n", cycles); - err =3D parse_event(evlist, cycles); - } - } else { - err =3D parse_event(evlist, cycles); - } + err =3D parse_event(evlist, cycles); if (err) { pr_debug("Failed to parse event %s\n", cycles); goto out_err; diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 49e80d15420b..9dee63734e66 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -41,18 +41,8 @@ static int session_write_header(char *path) session =3D perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); =20 - if (!perf_pmus__has_hybrid()) { - session->evlist =3D evlist__new_default(); - TEST_ASSERT_VAL("can't get evlist", session->evlist); - } else { - struct parse_events_error err; - - session->evlist =3D evlist__new(); - TEST_ASSERT_VAL("can't get evlist", session->evlist); - parse_events_error__init(&err); - parse_events(session->evlist, "cpu_core/cycles/", &err); - parse_events_error__exit(&err); - } + session->evlist =3D evlist__new_default(); + TEST_ASSERT_VAL("can't get evlist", session->evlist); =20 perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY); perf_header__set_feat(&session->header, HEADER_NRCPUS); diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 729142ec9a9a..81cfc85f4668 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -472,15 +472,9 @@ struct hybrid_topology *hybrid_topology__new(void) { struct perf_pmu *pmu =3D NULL; struct hybrid_topology *tp =3D NULL; - u32 nr =3D 0, i =3D 0; + int nr =3D perf_pmus__num_core_pmus(), i =3D 0; =20 - if (!perf_pmus__has_hybrid()) - return NULL; - - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) - nr++; - - if (nr =3D=3D 0) + if (nr <=3D 1) return NULL; =20 tp =3D zalloc(sizeof(*tp) + sizeof(tp->nodes[0]) * nr); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b4237fc713d5..ec2ce39d66d8 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3140,7 +3140,7 @@ void evsel__zero_per_pkg(struct evsel *evsel) */ bool evsel__is_hybrid(const struct evsel *evsel) { - if (!perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() =3D=3D 1) return false; =20 return evsel->core.is_pmu_core; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index c701cc474d79..8682784cbec1 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1589,7 +1589,7 @@ static int write_pmu_caps(struct feat_fd *ff, * Write hybrid pmu caps first to maintain compatibility with * older perf tool. */ - if (perf_pmus__has_hybrid()) { + if (perf_pmus__num_core_pmus() > 1) { pmu =3D NULL; while ((pmu =3D perf_pmus__scan_core(pmu))) { ret =3D __write_pmu_caps(ff, pmu, true); diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index c5596230a308..be15aadb6b14 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -121,6 +121,7 @@ int perf_mem_events__init(void) for (j =3D 0; j < PERF_MEM_EVENTS__MAX; j++) { struct perf_mem_event *e =3D perf_mem_events__ptr(j); char sysfs_name[100]; + struct perf_pmu *pmu =3D NULL; =20 /* * If the event entry isn't valid, skip initialization @@ -129,18 +130,9 @@ int perf_mem_events__init(void) if (!e->tag) continue; =20 - if (!perf_pmus__has_hybrid()) { - scnprintf(sysfs_name, sizeof(sysfs_name), - e->sysfs_name, "cpu"); - e->supported =3D perf_mem_event__supported(mnt, sysfs_name); - } else { - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - scnprintf(sysfs_name, sizeof(sysfs_name), - e->sysfs_name, pmu->name); - e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); - } + while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); + e->supported |=3D perf_mem_event__supported(mnt, sysfs_name); } =20 if (e->supported) @@ -196,7 +188,7 @@ int perf_mem_events__record_args(const char **rec_argv,= int *argv_nr, if (!e->record) continue; =20 - if (!perf_pmus__has_hybrid()) { + if (perf_pmus__num_core_pmus() =3D=3D 1) { if (!e->supported) { pr_err("failed: event '%s' not supported\n", perf_mem_events__name(j, NULL)); diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 27310eff49ab..ab06133cd153 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -274,7 +274,7 @@ static int setup_metric_events(const char *pmu, struct = hashmap *ids, const char *metric_id; struct evsel *ev; size_t ids_size, matched_events, i; - bool all_pmus =3D !strcmp(pmu, "all") || !perf_pmus__has_hybrid() || !is_= pmu_hybrid(pmu); + bool all_pmus =3D !strcmp(pmu, "all") || perf_pmus__num_core_pmus() =3D= =3D 1 || !is_pmu_core(pmu); =20 *out_metric_events =3D NULL; ids_size =3D hashmap__size(ids); diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index bf927aed162e..53f11f6ce878 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -464,24 +464,6 @@ bool perf_pmus__have_event(const char *pname, const ch= ar *name) return pmu && perf_pmu__have_event(pmu, name); } =20 -bool perf_pmus__has_hybrid(void) -{ - static bool hybrid_scanned, has_hybrid; - - if (!hybrid_scanned) { - struct perf_pmu *pmu =3D NULL; - - while ((pmu =3D perf_pmus__scan_core(pmu)) !=3D NULL) { - if (is_pmu_hybrid(pmu->name)) { - has_hybrid =3D true; - break; - } - } - hybrid_scanned =3D true; - } - return has_hybrid; -} - int perf_pmus__num_core_pmus(void) { static int count; diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 27400a027d41..1e710720aec7 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -18,7 +18,6 @@ const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(cons= t char *str); int perf_pmus__num_mem_pmus(void); void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, v= oid *print_state); bool perf_pmus__have_event(const char *pname, const char *name); -bool perf_pmus__has_hybrid(void); int perf_pmus__num_core_pmus(void); =20 #endif /* __PMUS_H */ diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 9355ddf7bca9..c1765c878e03 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -681,7 +681,7 @@ static bool evlist__has_hybrid(struct evlist *evlist) { struct evsel *evsel; =20 - if (!perf_pmus__has_hybrid()) + if (perf_pmus__num_core_pmus() =3D=3D 1) return false; =20 evlist__for_each_entry(evlist, evsel) { --=20 2.40.1.698.g37aff9b760-goog From nobody Sun Feb 8 00:11:57 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 73AB3C77B7A for ; Wed, 24 May 2023 22:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238034AbjEXWW7 (ORCPT ); Wed, 24 May 2023 18:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236932AbjEXWWV (ORCPT ); Wed, 24 May 2023 18:22:21 -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 0757EE7E for ; Wed, 24 May 2023 15:21:27 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb7aaa605so3103989276.3 for ; Wed, 24 May 2023 15:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966797; x=1687558797; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=OJl2Qmk86RzYSzEwmiy6LV4523vj02eAYK9mH/h/bGY=; b=N9u3K41yQWo85u+L9dLmhBr//frjJo96Jzl9Y0GBUqtMnU1V7vx1lO+YDlrL7mTkqw IBDLmNBumnqLVxne9LyiaZ/rQeDda1UBh4f/k8U/x9L2OY9XJD6VmRBC2FL7/To1iTaO dSotwoIvo9cFbenpuXX0PEMSt8fMnnnNABcoLYocgLScC3EMWfVTu0Bxv87qIkbptHpM uclZYvVyE7hIA7RPYZv63I7OscBQvh9tTI7DSAk7/IoK2U9Am+OCCTdBV01WrDvrBltX KwuKdlkI5scTLqMVy82UXs8oDbFYlEic8znEALv1OJu9j+nHjKFk/uQsobl5TFhj8W+R YpDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966797; x=1687558797; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OJl2Qmk86RzYSzEwmiy6LV4523vj02eAYK9mH/h/bGY=; b=NGl8/U+p1I+oRUNSVTrR0V17fi/IcpL9XBbSAOCW9t0WT111Bn2U3P8L5OEarLczZY bzLnsFcUj6PZIdX13Qv46ECwg9slAZXQvI3ja8l3vOLo9VJOmDEJbrG2ywKHXiRlmtT6 CcUZXdnxwKujzixPuuElUjYWEEUTtz+kgyXs3r5hGmMYW+kh0LIJ2astbGgyQzo3rGuI o4H6ethzlV306TfgIYT0m3N6np5UO20kNUa9qT2rEX/EcUwQ0BoehnK3C7AKy9dLBZnT 1mktBedQfbkI38PzJbRl1SZie/EXNmpF7Rf8xu7Z9gQl7Ps00bblzlS+pQi6qEi9ylIe Ps9w== X-Gm-Message-State: AC+VfDyPhK1JzwsDzWGGmjfyBhBkSyHICEyX8QftoWqKxhBLKBQ4S5UT AwOL5KVPJG6IZXTxSZLOnorJgYPhCdkU X-Google-Smtp-Source: ACHHUZ5BhCMW/yG0L5tcLlBXdiJdisihTKXeBoYDi9ikOrotsFs2GV8qeZqUWqRaMkKtmgsWoBq6EQT++fSa X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a25:aacc:0:b0:ba8:757c:2523 with SMTP id t70-20020a25aacc000000b00ba8757c2523mr798851ybi.9.1684966797045; Wed, 24 May 2023 15:19:57 -0700 (PDT) Date: Wed, 24 May 2023 15:18:31 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-36-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 35/35] perf pmu: Remove is_pmu_hybrid From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Users have been removed or switched to using pmu->is_core with perf_pmus__num_core_pmus() > 1. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/perf/util/pmu.c | 7 +------ tools/perf/util/pmu.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4dd40a38f6bf..a548d38f2a07 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1430,11 +1430,6 @@ bool is_pmu_core(const char *name) return !strcmp(name, "cpu") || is_sysfs_pmu_core(name); } =20 -bool is_pmu_hybrid(const char *name) -{ - return !strcmp(name, "cpu_atom") || !strcmp(name, "cpu_core"); -} - bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) { return pmu->is_core; @@ -1442,7 +1437,7 @@ bool perf_pmu__supports_legacy_cache(const struct per= f_pmu *pmu) =20 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) { - return !is_pmu_hybrid(pmu->name); + return pmu->is_core && perf_pmus__num_core_pmus() > 1; } =20 bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name) diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 02fec0a7d4c8..287f593b15c7 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -221,7 +221,6 @@ int perf_pmu__format_parse(int dirfd, struct list_head = *head); void perf_pmu__del_formats(struct list_head *formats); =20 bool is_pmu_core(const char *name); -bool is_pmu_hybrid(const char *name); bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu); bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu); bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name); --=20 2.40.1.698.g37aff9b760-goog