From nobody Sun Feb 8 07:07:49 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 35E1FC77B7C for ; Fri, 26 May 2023 21:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243802AbjEZVyX (ORCPT ); Fri, 26 May 2023 17:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238005AbjEZVyT (ORCPT ); Fri, 26 May 2023 17:54:19 -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 3886410A for ; Fri, 26 May 2023 14:54:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bac6a453dd5so1641423276.2 for ; Fri, 26 May 2023 14:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138056; x=1687730056; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=EneS6k0fHW+m74eWzDjwM1uOc1Pmt8jkSJOP/MXeXmY=; b=cSJ9niReYqrmuFkcQ1ETRJue7gVxvLZ/VOGme3fOFi2IvXXWUxzlexmxLeii6Vk3H+ cLsn1mTS7p0IolvfXMXCCcSG3pZr2F0vHAvak0DcQV5u+qOEnJNZhQMG/grWoFWIcNlV qkQI42YHK+Whwhvuvq8AivZYqoqweVvJQ7Ei0qponQWqFogbx04XrLqpVPanTUn1NU/U vj7263FOe5ziX+J9eVs87CNz8I+o6jnzQk0wBzUrl7kKtV2etgGSU+ite4vgKFQILGPy tKaxK+kyaRiZJkPyM0WTDFRe0cYQ/QeC2DTcPidpySU063Lmok8QQTA3Cs21Oexqgo27 KMHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138056; x=1687730056; 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=EneS6k0fHW+m74eWzDjwM1uOc1Pmt8jkSJOP/MXeXmY=; b=aNNQalp/XsW+SlKmltUbgqxQDubJa77ZeCaRNPlYEqwmWKyRMp9aO+RhhtdE0RK74z L1/ZuaJJ15T/VMKRowFc6uDRj41zMAnca5dLzs46f3IMp91cJo+GMWQE/voftr4IheU4 qmfhMogXuRBxrRutSkyDYlSVI4YcNrB6CRk69fQ3OOBtZ5VhCNL9B1l038OdYUTaZud+ 8BV4RnjNZdHFIuEkuVbCTrNzsYtrhaKaDXxvvaprB6nHTJ8eXDKLcmfBt8DYRp11C4bD mCMX+zqwSGBw8NlQ1sPhABBi1OiM0s5PQJIyrzxmapCdb3COMyhI3IoRi29WQBO2D5/q Lm6w== X-Gm-Message-State: AC+VfDxtCgyUizrLt+6HzBTh6qqW2NvwDs8r9MrDlHaVi4XWWfqmLg73 A7Nl3osBno5ae6lzzuBLYgJ9wjH47inU X-Google-Smtp-Source: ACHHUZ7pyOT9lS3V6y+iDxHsLZyo/eaK+QtOpy4IcWNjPJIW/GXPNefY54a7T1cr2UkcUpsBxEIiNInXknTM X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:8204:0:b0:bac:fd63:b567 with SMTP id q4-20020a258204000000b00bacfd63b567mr1723894ybk.4.1685138056472; Fri, 26 May 2023 14:54:16 -0700 (PDT) Date: Fri, 26 May 2023 14:53:36 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-2-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 E9E34C7EE23 for ; Fri, 26 May 2023 21:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243852AbjEZVyb (ORCPT ); Fri, 26 May 2023 17:54:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243606AbjEZVyU (ORCPT ); Fri, 26 May 2023 17:54:20 -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 92838F3 for ; Fri, 26 May 2023 14:54:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba83a9779f3so2660558276.1 for ; Fri, 26 May 2023 14:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138059; x=1687730059; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=8S0Hv+a/Zvfp18A5nlLX6T7tZ0kZRLdYhlDuYf6C4lU=; b=Ic9P7IyNJyUX8+dGFzOhxlyMJxl5ZCGy2OhS5BWms0QeuJynt2dmm54BBT2HIawiXL 8EirOGt/fHGjWBek/XIMZp3lOa7cypL2GtbHz70XUytSdFl6TzKqB5oB4oWZ1ijvs+Eo G6Sfz1Ae0XVDeVzya5nc6DAsOdl+5RBUQp01L08aF5OrwiLymQmDX5/MQbgK9TL1xXR5 5TiWq11FCHdBO/u9uM6EvRWYuTd6vgw8qZSjG5682B0h7MXnHJVSEAw704mykSJ22Apr zZvRDDxK8+Ooqss5Zg1aYbYMFlJxIKyhM6l/grJIQdyEOmGIsw+Fl2Xy22Py9OV3D+rc bUOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138059; x=1687730059; 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=8S0Hv+a/Zvfp18A5nlLX6T7tZ0kZRLdYhlDuYf6C4lU=; b=MQKLTkeonbFES80z7PYIenlF/hWjtwPCAp54vx9PlkiaoNjQiTVU4PKl/H/yURRDr1 +BwzovSN0dO0s60IbxC9S79a2iDD/i5yXtuc2O0logWjyKo1Xa6oBwaI4eaCpSQ/goZG ZWI5vdx7KE52twK4vhRp5pbUSx7Vxm4UNiblMpug2xtmsnRyoI+CqAkkcly5D3yoBgSu 9+fYhuKhFZKbDhEIpdhk2QGwpMsMb3MkEkHD4dYjAnlQ+2C3K10KgyXB8YnWd47HwcF/ ojsNUOosLTU0D0QYuLaV17lfBhUbzLp0l1ZdiSujy0MxZ4vrgJzKIvQAIpdFdLWdpIPj zcgg== X-Gm-Message-State: AC+VfDyavEj3Ne6M7khHkPn82ULC/SwknGfowCxw87khMcPSK5/DFy7g rbORc2xsfnh4VBxSL0mF1K43TxpsKERM X-Google-Smtp-Source: ACHHUZ6wlwN1t7qV13GabHWFUElri+i1zZLXEXx4+eZbvTw4JBb5huMJ6Ed5ui05ffjbLI0Ms+DZshJaMdBG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:ab13:0:b0:ba8:757c:2523 with SMTP id u19-20020a25ab13000000b00ba8757c2523mr1698848ybi.9.1685138058810; Fri, 26 May 2023 14:54:18 -0700 (PDT) Date: Fri, 26 May 2023 14:53:37 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-3-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 13C38C7EE23 for ; Fri, 26 May 2023 21:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243937AbjEZVyg (ORCPT ); Fri, 26 May 2023 17:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243809AbjEZVy2 (ORCPT ); Fri, 26 May 2023 17:54:28 -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 C6DD3135 for ; Fri, 26 May 2023 14:54:21 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-babb76a9831so2570183276.2 for ; Fri, 26 May 2023 14:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138061; x=1687730061; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=V1U2ziVcPpOm/qKHHr+WvX9njq8KvU37fpVV+c0iggs=; b=No29L90urRbGu/qvhOIfzOBjsT7tUDaJTfhsBWC7LE/Xm9DPIn0Q8VxJ72ZqDHv0nF 9u1cIT9WCYcRsEgulDGtMCbBQ1y1jhpRHbdH1Mcxmci8YskYXDQuEjfn5VMBDmLIsuYM Nuvp7EXZZwcJETnyRH8PP0XEvBsqAZh6igQrnINsRd7DcMh/vwuZvN7TYHJKv6An9aLI VnwBN/yhy3hRe+k1WvDL34jRZT/nl78bEODrHi5EZFHmMTw1sh9MfyK6I2UPKfvu7HdE 0J/P6XnTLuO/fZCSl1fseHYzQ7rzO+kedIYy+I8hxZ/9bvjlnXMcmTzPL8v3lvNnTI9s 4GSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138061; x=1687730061; 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=V1U2ziVcPpOm/qKHHr+WvX9njq8KvU37fpVV+c0iggs=; b=UibpoJUPRKVVqA+teiKMrdBeInyDzrZVNbafCOPUTOFW2ianEoMp+rNBKbLdOKBx6t 4kW/chy8+XhuH74OPd+p/tdbv+0hMjp/th5aVIsR5EC30q/y/NchwlDCZWwxU82T2tgE OTaOev8Fa9p6pNbWFO5qDvFlWWBCnQsUZiZb/BYGSc19GDqhM6m/Q6fVDmfh7vYFQ2Dj UEi0XzfTuSX+zt4C3j40oPJjObyfJXcoSnEOXZHaSQJs1l/ZOHCdNH/6zOxV9seSUspf SYoX+yJOWn60taCH4djJjRM9r9YQ/mBvA1aCRLVJsxo0qlTc7OIbYzhJcNRUSBEufPYJ 3zJQ== X-Gm-Message-State: AC+VfDyZeztJVzpjh2ijzZjx+W5PTh68czF5fMsUsb1ofVoMzR2Nc4XO PEcdm1Qouovj/i44dlhZrI6QgaxuoW1l X-Google-Smtp-Source: ACHHUZ6Y64CaN/GUfKSzgxMO3uJ1KmJVI9+EkobZRekXnEKWJ7g3saJJIKpdBGiXtTuJN9eBLewNze2f4K18 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:aca1:0:b0:bab:9391:470a with SMTP id x33-20020a25aca1000000b00bab9391470amr1218547ybi.0.1685138061035; Fri, 26 May 2023 14:54:21 -0700 (PDT) Date: Fri, 26 May 2023 14:53:38 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-4-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 71CE6C77B7C for ; Fri, 26 May 2023 21:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244135AbjEZVyk (ORCPT ); Fri, 26 May 2023 17:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243840AbjEZVy3 (ORCPT ); Fri, 26 May 2023 17:54:29 -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 8BBCE1B0 for ; Fri, 26 May 2023 14:54:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bac6a453dd5so1641482276.2 for ; Fri, 26 May 2023 14:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138063; x=1687730063; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=Qwu/cGmcgGyAZcdMWJypusk9brpC8zbYxPdkwt9cWJxryrN+wWqFuUogdM/q+inaa3 X5CMwBG9pJsw8mJbgbYfB1YQAMRQXotN9Takvp+xsVfHlPCHVViaSXv2SoyszMDBacrk dnJQHYm60Hu7PUfcLwgd5sYlI3Awm7IuD6VS3ZNkzQyiH5jPefFnAHa5Rqpm2jbo+dMy Y8Df0g22q7KcE5U7lt3p7eQInc+bGhBFC3kSKBmlqnb7WKQnshPIw3QMtpZsklI8r4Da 1JZR8hAERpXiq/1x0G4WEi0rbKcb+3Y+1YDBdnSB4OtOFQi8OXVVITYzrnr2JS9jc6FW EtuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138063; x=1687730063; 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=5Jn8ptCZCPVVUXP02YSlLmlmO+syhCCeFR6clIYIMOY=; b=CWL8ZNlk9+CcPIscUX+XHKPd7Yl8gr4UgLwoH5pmQVxWulzNMzImlWYr7R1xOtBrbf BAHgefp/RLQQirKszVqUcjJouhMY9KuQ9UVNfNvhqG/Ek4DdF/cxzndlnI4n/aCDyZQZ zotvZbD7F39fIrpsm3NjWXEaRxu6oypBWwXbRxoBWeHEN0RGMkjS7AM7hh4xAKVlCB1G wC0c0d3PW7Re11AFHYyMoYLbjTOiqBK0/9EM5GRgej1TUfo11f1Xd6vprE0OrsDApNsj mKhFXwByAIHdAsurX7pBOUOpTYGs22MkS8B3klkai7BGhqivUKSIptCcY0D5tFumvMxC +eDQ== X-Gm-Message-State: AC+VfDyY3s4bHmHD/sGKnsys4isrEnJVBkaNuWBtcC5T7xISj41wFyFE aPI4hb2jDeJbYtgUZUbduSKl3eGzBllw X-Google-Smtp-Source: ACHHUZ7CPihlLsasw3b/sk86pIxYuwPTU/q0jnG123S0JRRNIklKIp43J/hfdTdzCRVbqzvIRy7dBEtJSqtd X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:4582:0:b0:ba8:4b22:4e8a with SMTP id s124-20020a254582000000b00ba84b224e8amr1753266yba.0.1685138063197; Fri, 26 May 2023 14:54:23 -0700 (PDT) Date: Fri, 26 May 2023 14:53:39 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-5-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 F2AFAC77B7C for ; Fri, 26 May 2023 21:54:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244140AbjEZVyn (ORCPT ); Fri, 26 May 2023 17:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243817AbjEZVyb (ORCPT ); Fri, 26 May 2023 17:54:31 -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 857ADE4C for ; Fri, 26 May 2023 14:54:26 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8c3186735so2605244276.3 for ; Fri, 26 May 2023 14:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138065; x=1687730065; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=zl5H/LAaMs6H1Jjaws3sJN4knTClvax7RvoNDB4HmA4=; b=lkHeOxJXxITrtWC/Otgvuj9osz7kLh5qCEQEF4jM+7E0xr2PpA+cOLlZ9b5Zyiw2P2 vAM/ZhA1uVAMDxMCpPMV6dcien+7D8BM/xk665SM5OmYVqMbSjf9RPqOsQYL8e4Znqe8 Rah+SvNQxwtRUgbCM80haR4iLZ7L1oNvi7WXO61FLRifnetM4F7pxAb+K3HI0JCt1EVB Bobn3+3JPiDocFSoyZcej7VImVFmRSS4ZYOOP+owc3u5eF32Y/8J+5K21zy0BN/C/jxR hms9z9Dglo/Flf37yW09lDCcRBJ521AFqIPTPDNI4nq4H//bTKrg7NRLKlxNOwP0Ldpu 0CSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138065; x=1687730065; 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=zl5H/LAaMs6H1Jjaws3sJN4knTClvax7RvoNDB4HmA4=; b=PiGhhW8eIIKQp5KPwuWkO2yYcjLj6QH4ZOHmYAhkoeAxfGOolt9ag5FG+1KAaIG6T3 j30LEp+5NBg/d8EVPUw0bnXghgTEMkVKaEz4AYr/pRYdMdy92qOpZ/8872UoiBCask1L EV3Hn9GNYwe3XXmG8SwaAHzVoseuQkqb963At08VoL/V12mT6ZVXdeVFFcW9PqS7Lmr7 v7EcNXjVgjcbJITiWS/2u2PBOViYvLOnimBmG/2JRg+SGAilttbiiiUPYY37liKjv5yu sCuj+ot/qr5RhQWYbY4l3Zs6JTPVhceb3CpCL0ca3gyKvneMRzVhOKG6DwMoItdzRM8B yuCQ== X-Gm-Message-State: AC+VfDz1qxCRVLKWcRbA8xXv+/jpXR8Vbehv+8q1NjZ2iwDJ3NaP+WER cWkqO4Hvwgf4r2w69adoIp31EWhmpmnv X-Google-Smtp-Source: ACHHUZ6Yw0OVQSwW5J0Snbt6TPuLc2in9MIppxGHwbx359iQrDoRDhBWkjN3g+LvKkjO3+0H/mlYB2Ay03zj X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:9191:0:b0:bab:a1e6:c87d with SMTP id w17-20020a259191000000b00baba1e6c87dmr1249182ybl.4.1685138065583; Fri, 26 May 2023 14:54:25 -0700 (PDT) Date: Fri, 26 May 2023 14:53:40 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-6-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 4B44EC7EE31 for ; Fri, 26 May 2023 21:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243907AbjEZVyz (ORCPT ); Fri, 26 May 2023 17:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243892AbjEZVyd (ORCPT ); Fri, 26 May 2023 17:54: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 8ED46E59 for ; Fri, 26 May 2023 14:54:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8c9e9e164so2630935276.2 for ; Fri, 26 May 2023 14:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138067; x=1687730067; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5JqGxN6yla1ONavwrAlpvOZ5bTLHXY2jrhduxUQXwek=; b=4W2Y2G9aOa6y160FTO6lssRsF9BLENDx7N+3hV6iFo6ESKfNXczbaXvi5HhvCzWJlE d7T90b2MVqhrZvLb3hJpADfx2YTojrQPWsVUnUGW+YJ2TcyMgioQRwN1j4UawOTs7C67 NKQ9aNzm14VLQ81S67IDsxnjSzckX3uox3M7RJcr7vcLYzMjYg5j+1+ekCVkTMmFiMRM WCFnZfI9q/QdQHeIDLOsSm3yrZYMnPGTlPk3EAa3C+ECkp3R0+5GfRKSsFwvHXmrpRvP 5hTZObnazL4F/jIdrJYsSIASl1Xc5w82pnFAbzLXPd3F0fUw6oTev4ZT77AeiMKRFvYp a/ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138067; x=1687730067; 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=5JqGxN6yla1ONavwrAlpvOZ5bTLHXY2jrhduxUQXwek=; b=G/Ryh9x+nd8T92RaI2Dyf4UjUxEmipEuggBMVkuSra1zFCpGi4B+An9D5bUzl6zfYO 4Jyjf7o9ddP5oMc+1Nmq6OV49qSPv5/ojI1/DE+1MI0eBRWtHR7d/M6YWuNwPy7W9wzz 9z1wDNymbyM6PtxzGVIDFtMX/1RsUIuX0mogEv8hLQe+7hex5SZNmEfbnIVEw9iL+5mc BUbZe8lMAdgT1LUQ3JjpcBSdozMFCVil/QshPsfKmLxGp0gR9zW4neQwMMs/tN/OW/yi da9LvbNVIYjdvUQsJvDp1OBa0gr4nOhc1UhgNUIvjZLPbwqWwz2Sr3p0cZobl3lgCOx/ Xszg== X-Gm-Message-State: AC+VfDx4iqtq8xcR4zGngzRntyfPHn2UZigfLhmLtevkA43p54Hgouj8 a8DvWSJwdPh3PJb0DvC3Tkirfr2jsqIL X-Google-Smtp-Source: ACHHUZ4NkuCULCa9RiO/6RfdQOF6aXh9H6urfdbhxjTo4KF9yDZrJ0iNVVbETH4SZHe4kabZR8Ki9OxLWHZM X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:1206:b0:bac:f387:735b with SMTP id s6-20020a056902120600b00bacf387735bmr1234158ybu.13.1685138067659; Fri, 26 May 2023 14:54:27 -0700 (PDT) Date: Fri, 26 May 2023 14:53:41 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-7-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 EDFEDC77B73 for ; Fri, 26 May 2023 21:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244111AbjEZVzB (ORCPT ); Fri, 26 May 2023 17:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243916AbjEZVyf (ORCPT ); Fri, 26 May 2023 17:54:35 -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 2CF97135 for ; Fri, 26 May 2023 14:54:31 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bacfa4eefd2so3139223276.0 for ; Fri, 26 May 2023 14:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138070; x=1687730070; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=sTjkcSrIthqBGUF6JyF++nlWwrpLfc1jVqkJtlkt6PQ=; b=w25K3uEgKsF2ESRt4NqswniKM+kqGVpYNbZAC3VV1XivKvawMUAL6LVTMMcJxXQBFb FRg3ZkENeETKjEOtpf9Oxs3HEnHv9vC702x+tfxnLj0KCOpviMP/uuvf3eHH4eVmCXX2 QlWwQxHFuKt0+sC/rwn7FmT/72Cb28MCup5wqZ6c+ghLtyHyrLcxED5iu7/4pUMw2f/H KP5tGz126hCsKh7w5htUiXSvgg5MhWi9cSbRfyC5lmpNzLrI3tHRUvnao8H/Zx7qap4I o5VgvKPBtaw4iY+aMhbxnS+e4o240Y8rT5A92F2E7tu5l9Ys1HwNRKOdkI9yOfCgPgI/ P1XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138070; x=1687730070; 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=sTjkcSrIthqBGUF6JyF++nlWwrpLfc1jVqkJtlkt6PQ=; b=jb8114hHrlHWGum3zVBsmkRqXQz6yzk1THDQ6v43ddVZ/VJQCLrxTw6XbvGwgr3BVk badRFPwwHgiya7jg3jrkhnBS7LtxKwPppON0gy7w5GIQKpYv02d7VEkAU7LDznV3dw6e zoKfLmWE+SnofjaIBkWGLWmrvkwydxjrUrKmevjaxejjl0SNoJkYveZ/eZ01czt7IYN3 mIjZmG9aHgrBeWsYS6aDkZJkgyLwkryDhx0EvIvrXAn+8dwcI+RtxTt1KZngBnne+GMN 6pUlH9xbTks3qH+CuXS9Rgtyhl+RxCkf5I4l7QoNXjgkZpyOaDouJ04+f+o7bLMUUUuc bQ0g== X-Gm-Message-State: AC+VfDzWwuKHd9Hh/wrd86x8I5o6Wv7eTWN4A2jdfjSvqBYg4TuuTbo6 l56qC6JQygkQGs1TXtnaE2gGF6iFo9sp X-Google-Smtp-Source: ACHHUZ5Y5u5GfQO+v2V+aKXbBLuLyabzsHyJ7UAvFYKMG8567omcANkCFynE5ebfsRhLLEDD5CY9TnAS+MCL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:e08b:0:b0:bad:939:77b9 with SMTP id x133-20020a25e08b000000b00bad093977b9mr1193175ybg.3.1685138070105; Fri, 26 May 2023 14:54:30 -0700 (PDT) Date: Fri, 26 May 2023 14:53:42 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-8-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 62B68C77B73 for ; Fri, 26 May 2023 21:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244152AbjEZVzE (ORCPT ); Fri, 26 May 2023 17:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244141AbjEZVyp (ORCPT ); Fri, 26 May 2023 17:54:45 -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 93B261BB for ; Fri, 26 May 2023 14:54:33 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bacfa4ef059so2814363276.2 for ; Fri, 26 May 2023 14:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138072; x=1687730072; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Augb3j/jljgyjV1KGpr82Z0gyjkQotdR/6uQepIkE7U=; b=2kB3hJaQUgcEcaVDXNq/fd3gWdE2bSBqcIL0t1IGnwV28LbcccROJklvngJeFV4DSq DufbTJ6/obrK8AhJrpMqL+XNuQmA06Avd4EHY87ZAOSlNYz3P8jqh8ujdXyqvxWOD6oT HVHoOwHoHvlyWmr/ArSlJeVgBFTbnUVTL6MW00xvMB349pRYplMeGvpg1Nm965u1sBid efvKaDXKZrijDyU9jIyvnlcEoeV5Dj2yo8ZtLt9ewIiMR6ZD+5WmT7YMIkSAyBr6QIbX dl4kDKcouAq6ZfyDZjGoSUDivoA53h8d8tr2otGAoSiVcHTTDFqyvRrvZdX0w1EdZ74T O48g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138072; x=1687730072; 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=Augb3j/jljgyjV1KGpr82Z0gyjkQotdR/6uQepIkE7U=; b=E4R3gAus+ZXoUBjNdQOyudQAvvu2DMu4eLfdLtY5SBi8zvixREvm9moqw/tgCseJmL NZEPwG4SRNuQEKSJboBjzGSYN0Zhzl1T/Vu6wFyzeNncqTEbzd1pj9rXqWUljPG3694J muemDCTe7JNYcOBL9bXLKHTHC3urSIcookQX91BXqak95yIzs4PJBV2hnYkDurjvkQPX awkKtu/mfszmD7ruxJfiMMD+GV4dMeC19CSg0f7C3ZstkBMUTD7MvmsBKKg3zdD0aW/5 NuPkl20GHFChE4PNeyNVU1D0F1VmxIb5QeXNfdcPWUkwwPsVe92QjIFekodbijWGhKTa Z3vg== X-Gm-Message-State: AC+VfDy1ZvgqBlDSjJ8Jx6Lg316uNVukSM7lwV42yp3DH3FNaL5EXnz/ e6/SSIGYE9IUsAQ7xzlsLQYQmjep3e7c X-Google-Smtp-Source: ACHHUZ5Nc508/25y5ajVWer0jZNeXKoT9lajVUzrqi2/BXoSY3vyyg0yHWgTWVWgkvFow+yWC1Tg5DfwgH5c X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:d690:0:b0:bad:4bb:c440 with SMTP id n138-20020a25d690000000b00bad04bbc440mr1706799ybg.10.1685138072366; Fri, 26 May 2023 14:54:32 -0700 (PDT) Date: Fri, 26 May 2023 14:53:43 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-9-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 0D8E5C77B73 for ; Fri, 26 May 2023 21:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244193AbjEZVzJ (ORCPT ); Fri, 26 May 2023 17:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244157AbjEZVyt (ORCPT ); Fri, 26 May 2023 17:54:49 -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 B394FE66 for ; Fri, 26 May 2023 14:54:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561bad0999aso31284027b3.0 for ; Fri, 26 May 2023 14:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138074; x=1687730074; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=uEP9U0nKmj8Ymr7ZepfrEW5aT5lelMPt3agjhkx5Hd62wHoNVyQhPIarzyb93cTaof qEF+JjQRput/yCXcaSUK5c1Y8Wi10/o9AbUmWWegqf0kGgW9uFoDO4soCi43EdVVKJd6 DnW5dGgnk6Km784NW11TV6D4IV4hTP8xcRzkmg4p23zhYWpZVgGVoBBkYr5blhiSHZ7s vszRrPl3ILHCVfGuPJhQ/110ab+lNdLR2JIKoQQQEe4oJj0dtKVuP4NNXHgU1v6AQrgD qwyf2BrAM6o97lBuBJetI3C+KdgQNUVXjHFi1IL1DVK0PPXiy7Q3f8KtllQeWaSkVlsN paQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138074; x=1687730074; 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=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=MgcpJK3dl/rI2LVbP4IBG8O5aHn1mSWNQN3DeDbxNxamUYJz02xzu3GAy+MGepMlmz JlEWruf09NeyfRkA0yIqNfqvfsUS2lunbZxM9kGt8GwN6sa2Y2pBnD7PHFza4q0LY29h /+2DpeyJVL+xi7adQJb6582ViyEIU00M2YNKy7ciuORtYOaWr/22lre6zn1QM3XzIWVS mBiIe4fBv/y6k02gamS3j1MQA1eKowdhV/xbPHdgSGB0Is1HuVDCp4fRSoOHsOg/5Kup x9GT4+h2zHMtS5fn7bFuuyX9bomAv2c0y8lrx+eHdRwu31E0zbtI/onaO/B0QvrQiNqp IMuQ== X-Gm-Message-State: AC+VfDxIrXaa4KAvN0PWWtGVSrPQc8B/liOfO0tVtLzgI6UVhxQ3C2v2 jfWmqqY1Vfrt3MGJnwWgs1ZQ7n7eCESw X-Google-Smtp-Source: ACHHUZ5T/7yAUIvjTc4+VaRWlhjcegjXRqmqsz6bUjSqb1T23XSW4W+5lov5726eTFuZg5EgBmj4O/Ky+rzg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:de06:0:b0:561:856f:69d3 with SMTP id k6-20020a81de06000000b00561856f69d3mr1828697ywj.7.1685138074694; Fri, 26 May 2023 14:54:34 -0700 (PDT) Date: Fri, 26 May 2023 14:53:44 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-10-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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. Fix the related comments for system_wide in struct perf_evsel. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/evlist.c | 25 ++++++++++++++++++++----- tools/lib/perf/include/internal/evsel.h | 6 +++--- 2 files changed, 23 insertions(+), 8 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); } diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index 4d6f2a032f45..5cd220a61962 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -62,9 +62,9 @@ struct perf_evsel { int nr_members; /* * system_wide is for events that need to be on every CPU, irrespective - * of user requested CPUs or threads. Map propagation will set cpus to - * this event's own_cpus, whereby they will contribute to evlist - * all_cpus. + * of user requested CPUs or threads. Tha main example of this is the + * dummy event. Map propagation will set cpus for this event to all CPUs + * as software PMU events like dummy, have a CPU map that is empty. */ bool system_wide; /* --=20 2.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 3A9AFC77B7C for ; Fri, 26 May 2023 21:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244221AbjEZVzN (ORCPT ); Fri, 26 May 2023 17:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244184AbjEZVyu (ORCPT ); Fri, 26 May 2023 17:54:50 -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 E9BB3E7E for ; Fri, 26 May 2023 14:54:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bad0f5d6a7dso2466989276.0 for ; Fri, 26 May 2023 14:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138077; x=1687730077; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=xKlpZwIe+ZNMqSgCu8evjP4rcM8k5wR/kLw9LO8buYU=; b=vNEf07wd38olMIygDeoN49eL3LrM0kx+zZ/2Cv31L5rDqcu2u2HMGY22UqYAcRclhi xWcmudR/+KOmxloT1A+yCwbznoNqXA4muU4fC1iUhPu8yMN49rI+7ouhO7dxgVUSV/1a M2GvRHB7/EIDnQRRuoPRWKiOBbbCg2df/G0QdYaRJuekP9Q7ni2yTvJ4WD+VfQaki8tq v/sa5aeVQjSgtZlOUbhllM0Nf92nMRqw5PvnH9rVL6CIb3pdJOWFElwTFpPs0jXZOuUg mF8eG457uLaz65pA5jmMcOcdiqubBxp0wvSQdZyfI+Jy+eu4iahJXLaJi18YYG4XDmDD tcTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138077; x=1687730077; 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=xKlpZwIe+ZNMqSgCu8evjP4rcM8k5wR/kLw9LO8buYU=; b=LPMTh5fQXFkbarlzV/kQdZ9N+PKVRtSW5H+vvIPa7xG8ycUXGLFan+jYHSoOhB4P04 BEu0YVA1fxyAmDlxbALHqDyTRF+vee8fzPz5ewddtvlOJV4aKmZCb+vttopXoX1fc1md F9VasMliS0iCrjXVW+/fZuSi4lqMQLBaqSOc/Xtg7CDPhQj8kzEBKCXOoGaaV2xyEvqV FhUUtg6SnvLb4VJxp/50W4GNdtpf/lgp103CA2eyHowN2lUnLS1q90rn7jYIdwAXVs5I W2GRh0aNTmOjs4DvaSW+zwZrbTjB4yXSt6p1wz7EEVifRy8cDEZ1lC3EaNhIsUx0cyKj I3tQ== X-Gm-Message-State: AC+VfDyY8c5+5/0BzNnSqf5hEKsWwjI44uXOJ5trOidnw/f1ZOCj2wEh AGPJz5iRDvG0Y4aram9SzIVTfKAhORKE X-Google-Smtp-Source: ACHHUZ7ivDl73fOYK0vU1vrJjuIWaoWY5OCr6BiWrhf+oEthpQhEpQTfyirjwDEjzcJSSvlUL0oqtE+qh/I2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:4ef:b0:b9d:d5dc:5971 with SMTP id w15-20020a05690204ef00b00b9dd5dc5971mr1726290ybs.2.1685138076985; Fri, 26 May 2023 14:54:36 -0700 (PDT) Date: Fri, 26 May 2023 14:53:45 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-11-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 0B17EC77B7C for ; Fri, 26 May 2023 21:55:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244154AbjEZVzZ (ORCPT ); Fri, 26 May 2023 17:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244142AbjEZVzD (ORCPT ); Fri, 26 May 2023 17:55:03 -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 84C3510D4 for ; Fri, 26 May 2023 14:54:40 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561bad0999aso31285207b3.0 for ; Fri, 26 May 2023 14:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138079; x=1687730079; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=4G044dwOBhR5m2jaMfIZVfXdRdn6jhcUb1KB/kVg+Hc=; b=xFmXSnutuvwQaRPV6MvNc57aHCMlqOrcBz+anlNUSEj3MwpOSghgrADN0poHTOpjvl hWWbB5YXJ8lmFqKU7VsZjKZ62D72heYstI9VI9J25vvwCODF1sC4jRL61fQn6D0Y9SdI /SaYfb2vwVwzFCJEPnO/JJDb5X3ENTIE1xam1KOApN01araedqO6Pf1o5FGwkrY86+PG D/eVaI0/Jmgwd8/570KnC/O9pEaEQ8us4rny5IhdRtFT6pmhd85Z9VZ9xcT11ZxFSMmJ EPBnSWVA6pr+ZMJ9rccFJKeU2UaNcLpnY498nB2pHVnEA/bdSWjQBiiz3oIaJzz0uvgV 4Eeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138079; x=1687730079; 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=4G044dwOBhR5m2jaMfIZVfXdRdn6jhcUb1KB/kVg+Hc=; b=dwdD+7vgwqBa/NG221DZF25ZcifndWjUWduxaTVMqIsULWRt9YBIfLmeZEhwyNcjdc 26iQVNNN3/OCt6GSHlLWeE6G2K7PDo6idmgMENTD6PQ1t7GdbGEveAkeN356sVnMUpyT Y21cLaN0fNPSP7RIC28kRuMoQc+I8iOVo5pn9Ex1JaaUx92kKlV8r/L6IJpwHlOX2MU7 PPqbdJnoDoID7QFh9YWiES0XvRdmrsdK13KvmvmpRysrkUNdigfaWiC6LSdxwdJ5lyOz MBgwbVCNw+MLnPGobgnl2E5NkKcRY/1+HsfmmNFCw8pJ/nRK3tOXYne1+gBTo6/phxpu fIGg== X-Gm-Message-State: AC+VfDwSrTu55hvO+5Pe//6K8U85a3VeCbsLz/BKJ4IGm23WTuoLDa2i Ja2ndryZTHCe5m0Di4T02gEoYJ6wv/kA X-Google-Smtp-Source: ACHHUZ5uHH81uEsfWXLMPgmeDcR/Pi44wMN/4hfHAU+pTAxpvx8n7c1uH67wCMUMU0MOfYOiju2EHAJuJsN6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:ae15:0:b0:55a:1488:b479 with SMTP id m21-20020a81ae15000000b0055a1488b479mr1842134ywh.1.1685138079209; Fri, 26 May 2023 14:54:39 -0700 (PDT) Date: Fri, 26 May 2023 14:53:46 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-12-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 6F155C7EE23 for ; Fri, 26 May 2023 21:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244205AbjEZVz2 (ORCPT ); Fri, 26 May 2023 17:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244157AbjEZVzL (ORCPT ); Fri, 26 May 2023 17:55:11 -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 330A710E7 for ; Fri, 26 May 2023 14:54:42 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb53e6952so2679188276.0 for ; Fri, 26 May 2023 14:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138081; x=1687730081; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=31sDiqMVdNNDfsC/IX5dtNMwy0qMI98BZrYnM8NuTi8=; b=XTDK8r2WfOYRKJKZ3AW7Y9EtKWLKKDQZxCWLpJttlrCQsB7MF80CkDG+S+h6zUe/ON Dx4YoHiyN4MnXdt00cczqCuiCFTfcjEzSzBn6Hiocw2yl1WcvEA0HMMLAII9+FgG2394 wfoeikvuLXkAH8lGg4La4lcG8baiYxfbe0fhJX4pUYmTGptXOZXEGADqw6QR/T69qS1y xd0c1RzUwFYef2FPhHHQgIUtFHNCIb8T8OiW5AToZkSb0UhHwdtLx5e/mklnX43DjyMR rj0oevn3AQ2bG3wV/fSLQ02wNM/XKt3QWVP93yTObtC+2TvOxsMr65qv0An1CNPc0ofT SYbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138081; x=1687730081; 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=31sDiqMVdNNDfsC/IX5dtNMwy0qMI98BZrYnM8NuTi8=; b=GzPWBg8SLITapvnu0I0zW+pOzBOGC8rWqSEN71F+9UMrwHgDTcfY8TVVC766JgETZL 8Ud7vUY7S1IhsBK7IHhpOBsPf9KGkx6lnRePw+nd2NRin7Mxk8OmOeHSnHTQS/LcjP7K RpWsEkFwHc0x46Elz1R0BvslvTanbMm92bC4h71k0m3XvXHvrbulvsrIIUBM/r19b+0e /G+D4ZjlwlX7xCLL9JyUO2thwL66L6aKODi+5A5bslylYgFSLtBsvhL5xNkmUFD91gMd sldxFzSKAh4h5XZM8VxVNZBRKeb9oFSju46A8rxxQIItSfXqIL4VCHas/XocXTTea3nP +obQ== X-Gm-Message-State: AC+VfDypGUGMEI0IrnuMyDr/UCkjRR04jcvIT7wg23/WtEOX9FEgBpxE AHyjMXe1ZK0x7deOYb2UtdFyW62vM6LW X-Google-Smtp-Source: ACHHUZ77UTmIwaM63gWY9jjRXu9bTBAgWieRCm7kuQ9llVPF/ldQbLVqEFIv+aT1HSNzSN7rLQ2HpL8xEnEx X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:ab13:0:b0:ba8:757c:2523 with SMTP id u19-20020a25ab13000000b00ba8757c2523mr1699220ybi.9.1685138081215; Fri, 26 May 2023 14:54:41 -0700 (PDT) Date: Fri, 26 May 2023 14:53:47 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-13-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 7E31EC7EE23 for ; Fri, 26 May 2023 21:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244131AbjEZVzj (ORCPT ); Fri, 26 May 2023 17:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244204AbjEZVzT (ORCPT ); Fri, 26 May 2023 17:55:19 -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 4193F10FF for ; Fri, 26 May 2023 14:54:44 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba69d93a6b5so2682289276.1 for ; Fri, 26 May 2023 14:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138083; x=1687730083; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=/FcwIRq48w1Sf/R9CE2AphWh51MG88ZTSOWgLdzsHyk=; b=Uh5akTdq29pZff6ceV4rl8xs+mTml+nXZjtVIPH8f32evyaLbdScpekkk2pmk8Dv+s kBpAkX/wKN4t7KDE2YUfHdKHOZSuDBgAxIPQf7+oTP4jOrdGNcyl+gU301ABNsly+tgO M0+zs/hjh876bF5DHQc+vPewDR8I9cLXaHMTQkTiD99IK8JxjRLWGTmXECnp4Nb4ynz8 VPIGGjt2pBNptgDa7WmWZ2kJW+Qlvnh+8PVvlch+fISFbjR5+0gD2Za9wt162wY8e9M7 R3SyKDj+Fr53spLWKzz/RpxRkCJ1kq6djrscuTQxMwViRlkJ+rbFm+VJJDa5VLBAyBur qnEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138083; x=1687730083; 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=/FcwIRq48w1Sf/R9CE2AphWh51MG88ZTSOWgLdzsHyk=; b=DsMZqcPdiK7T24QXfaksY25zxWeK769PtSnRHrnYXtOlaRPfQY89rpULCjC8t0ltK1 D3TKj9g4v4qbLQYXN4sBq9Dl1jr9QvO9CuS9Bwxi/JNBC+yLLPkKrGeeoHZv86Qg2tvd GLETSaLa25/QZORZKZyOQmAK3feQIi7uMNpcyoZIEq45Ww1ja6H4JNVZ4LhIzsgXtxv8 09DqQVk5He9SNIYmD3EjH4vcitEV8L64kkZF7CjsD2Qcs3aS630fmsYlbqUxuXDS8pJA Sc9f9zVI3W5oFEW7faIN+SheZ7F3csY4dbELk696bcKIfErhPxWeYBxSFRAX2Nvnndas zURg== X-Gm-Message-State: AC+VfDynpiLoXlY+El3wTs0Pq24uPtpTfs5l7D2XnjsSnJ9vq/huD2Mo pptCv4oiVsBWCvjwjWxnRGwYLml/sPpU X-Google-Smtp-Source: ACHHUZ6eAuZsXc9qLxGI9ElZR/aTTmZ3hTUd+YiyFW6ubTVHa8WZgjpxAOf0CaXJRD5Hs/bWBEZHOwOiFkai X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:aaf2:0:b0:bad:99d:f088 with SMTP id t105-20020a25aaf2000000b00bad099df088mr1716635ybi.11.1685138083607; Fri, 26 May 2023 14:54:43 -0700 (PDT) Date: Fri, 26 May 2023 14:53:48 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-14-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 73565C77B7C for ; Fri, 26 May 2023 21:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244185AbjEZVzm (ORCPT ); Fri, 26 May 2023 17:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244141AbjEZVzY (ORCPT ); Fri, 26 May 2023 17:55:24 -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 9A12FE52 for ; Fri, 26 May 2023 14:54:48 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56183784dd3so16666197b3.3 for ; Fri, 26 May 2023 14:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138086; x=1687730086; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RwwwjxGhBdfYap7unP7SQ0HQEBv8oo9B//S2Wm6hAfY=; b=VDjFOWchF4iASJssKI5uS4mtm0PwJ6/QuCiwJ6jDFyyKNpqYr73SvCv2JtFc1EgyiD 59gMXLVYCHfmsJbb6tDpNP9V80cEpD2mg0B2VyW8qXda1KZAmKHvT9uomPJu24in2eC9 aifhC+cloAb0YUg4bolJCQhZ3BG8Mz1tkaUePwNtdwcSUgiEkXOlgbtfu6npaoJcQ3Kj bf4hqPs6ZGsyXw5gJ9aW2D0zoKdProuxYE8MTYW0z6AveHCCh64m0tDvxWOf9lsvDdZv 0Oox2Q1xw3KfQXa1RWnPCU+axMSqsMkrcnRB0zD/nUGqUkAnHTwztTNYSekg/tRzofN8 GYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138086; x=1687730086; 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=RwwwjxGhBdfYap7unP7SQ0HQEBv8oo9B//S2Wm6hAfY=; b=Ndd5oDS8blWshAY/kIXm4cKNoWheE0XpQFa9swpavIwol75f26BMCDGi0bcVRhVSiW W06YHzaVQxGWlDCYsSH0SEvRQZM8/ioogaWgqhLUaPmGPUARMR/RqwSK7j+orCGLRFYO UCA1TNnKKZ9yow8qg0Eqrjf6n1POm0vOCZ4hJkKv7cxpODyggMpRl6Xqm0hNyyXtk2+E OZY9jeRB338RwrRvmM3hhzBqxVo0fqr8ddCQBGjekKc9E8fH0pmP7WfcgTxzoDGrXQKW JpbVP5/bsvjjNGIus7X280SkeiEPQstP/GmJlDRgGdV7QUQbLl5YcYzg04+4Zs64eyeB pAOg== X-Gm-Message-State: AC+VfDz/+rZBX0YQbtdX2colk66w6SxQ+qZ5JeujZgmlkGTNFhbZWrpV ZYN30Aiu5AlYxJJrfnpESvGIrBkEQFH3 X-Google-Smtp-Source: ACHHUZ4qKgJbfBiHV0xq0EPzsw8tvg/qhmixLTDPuLCpPnIkWCjbUHux0MNk/wTfCtWuU5pImtvlFvTJM0WR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:bc0d:0:b0:541:61aa:9e60 with SMTP id a13-20020a81bc0d000000b0054161aa9e60mr1827277ywi.6.1685138085819; Fri, 26 May 2023 14:54:45 -0700 (PDT) Date: Fri, 26 May 2023 14:53:49 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-15-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 859BCC77B7C for ; Fri, 26 May 2023 21:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244242AbjEZVzp (ORCPT ); Fri, 26 May 2023 17:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244206AbjEZVz3 (ORCPT ); Fri, 26 May 2023 17:55: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 71867119 for ; Fri, 26 May 2023 14:54:51 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bad1c8dce48so1839973276.0 for ; Fri, 26 May 2023 14:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138088; x=1687730088; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uQLy+VY7puWbfitln8G+spxphB2gCRmUi07gLeIATPU=; b=Bsjntan5Y2+dIlGuMVR4LMyjvy74tDv2Kb8Zu6GWYMtssbAPNbPFtWNoqLIAcBlC6j k3NrOYiIuvF9S8x9Xx9GePnRcrQhFWgeauMLwb/WOWij+LW9FViv6MqQffZ+NW9GSbtW 5Cb6CyARmaDGa+XCHM5mIvvPu5RzxIfXgeCljxg+5RWIPDDDuiya77rksXLvXYPayxTt +xSmGKiJhLm21w6AELNRt/lg/bFoEfJoq7raXg+B6r0i73EjBOaICftVzRE6mXINTlPp DKsO+HsItRD9rDwjPKCLGToWh9nm+Gfy7vY+JUDSgeZx6U5Wa3wVKHObpx+yAa1nOC97 cV8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138088; x=1687730088; 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=uQLy+VY7puWbfitln8G+spxphB2gCRmUi07gLeIATPU=; b=K3BPkFQ8calt8f8rVD9tDjK7q1x3DChx8wjaBzUHVQKmG+eHexTxNFRSwHdIsp7zqV O1mtZK2A6NjQKKsorjpvpHhp2+kWmepcovu6jE5umFCLXXSAMcrN1ZvoP8W5pQeV9DHP hm+o/bhkP3jusDBx9BAuWt2896F3ktxkkgqB0YhR5C+gTopqtjQL22cz5SLea3XAQNQn NQTHjZWuajv3a1imiVq5T7LdAyYRoSj2lmQ0ozPm8x4y+6wIuxJfstlVFKulTqGT+eie pG+VF6xWG3qix7Y+1k6Wz/0tjWim5B2qTETDG/OJx55RxWUe27nEuuuv7BHk+xFzoYO8 LQDg== X-Gm-Message-State: AC+VfDxNiGPjhpi6oiJ0YGHvpPPoAO/ksgPlmL9nIFZrPnQUzA0/aE4n Fx65wY/rC3MFxHzneWnE+VJuIp66PRwG X-Google-Smtp-Source: ACHHUZ5Iy9W6pUsgIX5TcxV+nKCckxbPOPFTSTz29+jdUj5JHkKkACwkmiASg2jdMxPtg4/9JCfiEvEm2IhZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:d648:0:b0:bab:9391:470d with SMTP id n69-20020a25d648000000b00bab9391470dmr1229422ybg.0.1685138088001; Fri, 26 May 2023 14:54:48 -0700 (PDT) Date: Fri, 26 May 2023 14:53:50 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-16-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 6CF87C77B7C for ; Fri, 26 May 2023 21:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244278AbjEZVzu (ORCPT ); Fri, 26 May 2023 17:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244224AbjEZVzb (ORCPT ); Fri, 26 May 2023 17:55:31 -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 B49611B0 for ; Fri, 26 May 2023 14:54:53 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8337a5861so3063141276.0 for ; Fri, 26 May 2023 14:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138090; x=1687730090; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oDuqTopdZxG/tZhzCpsOUxdl3hr1CdgTwDzFadwyJDk=; b=cN6RZVoMZUHPAfJbFWf90UK+o6yj3PXDnshig1R3nYUD5nhkJNhZaxPqedUgw2np0N mYqfYDOy7bbq5hWyQrqrSHs/B2URvS7pLYFNrGG1xp3OjLsunz0jHq3YCIlR+wUVQXlj nH0a5YpIyIi2C780sL6BfvqUiqhPvgURNdv/mtll4gchXtDsjiSWtzBuE1tmc+cgHvtt 2pB4015qwzMtpIYO/YQjdWLYV9+frAcY2QMgEwhb1nwbXpndDckitvLd7WyjcPXT97B4 EbBY2K32dtmSOIVh1SXS4d4yotcqKHb0IKvt9Lzr5QypBzni8xSrLtIEvlZRr7tyC0Kx E78g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138090; x=1687730090; 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=oDuqTopdZxG/tZhzCpsOUxdl3hr1CdgTwDzFadwyJDk=; b=hCC0gXMPn4mUz1qTB5Rihxl4m1QqZEdTfiBbZ+zckGfgLscFOZrWniG8OYi2E9/Jzf YmH7poe6whZAwTThHlS0Kog9A8RT2XqkUmiqspHTdgwr8EKvo94jSDK6/7eWEnsJYqGv 3WHPgYvK8fz++MU7KAAZ0K137dPWfEUq0gWkFhYpwzMMi1nlP9mU9QQ68LmewjPBaATA 0h+UeCjbx4VctYRhmXsfFia6Brb3LQEw6hcgi9ky+4cZj3Odtx19PEmJV1b/96F4L+Kb /yD9ubuCawWpMxUUX8R70criVQE8opMzQ4XD0mKTny9+bOWV56HPOzE8E0ThqyKxajUC iIVg== X-Gm-Message-State: AC+VfDwqKIvOpH22S7atDYExh1iUltX99ItCcxANqe/EXycEbGgubX6g xyIzCcw/nMApSFywsVmGs2Ujr1pAxYrf X-Google-Smtp-Source: ACHHUZ7yTJwEXmiBP+wP6WIVEGmqKho+m3IBcST1HGYx7R+IJnfGD81e4GtwX9lmjT/JG9knJiEXMk4GWHtj X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:dc81:0:b0:ba8:1e5f:8514 with SMTP id y123-20020a25dc81000000b00ba81e5f8514mr217351ybe.5.1685138090262; Fri, 26 May 2023 14:54:50 -0700 (PDT) Date: Fri, 26 May 2023 14:53:51 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-17-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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. Discussion [1] showed the empty cpus file check to be redundant and so pmu_lookup needn't have a call to perf_pmu__hybrid_mounted. 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. [1] https://lore.kernel.org/lkml/20230524221831.1741381-17-irogers@google.c= om/ 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 | 13 +------------ 3 files changed, 2 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..83c7eeb8abea 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; @@ -907,15 +904,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 @@ -936,7 +926,6 @@ static struct perf_pmu *pmu_lookup(int dirfd, const cha= r *lookup_name) =20 pmu->cpus =3D pmu_cpumask(dirfd, name); pmu->name =3D strdup(name); - if (!pmu->name) goto err; =20 @@ -967,7 +956,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 EFC90C77B73 for ; Fri, 26 May 2023 21:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244232AbjEZVzy (ORCPT ); Fri, 26 May 2023 17:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244252AbjEZVze (ORCPT ); Fri, 26 May 2023 17:55:34 -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 D4C23E41 for ; Fri, 26 May 2023 14:55:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba802c775caso2665541276.2 for ; Fri, 26 May 2023 14:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138092; x=1687730092; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cwNQ71nzWAtCurlrP6FCuEtDPR9XmwsHJykHXM8qing=; b=0ZoF1unr/orlOsISPFYBj91qnKAXDq0B3EiiKU5OTSFpjOBXJA0aWUu1j90QwPC9U5 zQZY2svERZPcvFvL5HADSim5BXMLe99VMVh5TaUANLTqD7x57rwQnP1Yj6t1NAJZ1BB9 s2feus1/WhOreHXwAcdg/EC9WX3hMLCAq32rjeeqqhUEz1bGCoUAKsC9/ygb8/bPWQRY JKzFdUN8fKyeG+O7DZke/2EGzjVo/PX1PD3tMR3oHXRh/0Bu1UyUfE+STE6HwpM4LzL7 qV8BwVBzee3XEg2GNqk8HKXajmUgGUssAU+mSA+Ysk8uY/HepVstX0wwIYt+3XZa4buC 3wBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138092; x=1687730092; 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=cwNQ71nzWAtCurlrP6FCuEtDPR9XmwsHJykHXM8qing=; b=j4wdB6JF4qraaYbHfskRjAt5qPf8gJjkLyyozyJWTwsHNJMuRYIUjRWx71cGBwm6cd iiKgEBw63/FOJgMzIXjPKsST5Mn7UQ4UmRzpQmFnPfX2lqiBpIcCwMyy2jbWe92M7xHy L52Lb07q/r2dH7HwDyQWCxV3ST2Kf3JgQYYsMpp2vSv/I3aDeIEYoQyTyNtc3vimh/1u 9dkD65wDaZh+hl04U/WkldNwmR79Pazg+4Pe4N9woPXHysyojgrdW2m8wq4+cMI2mJAI HJoNpQE8gZM9qj+EIz9nYXXglPN39t+A+6F9w3qF60VJ1IBax105mTidRwD+/EwSup4i didg== X-Gm-Message-State: AC+VfDyd/B0ayZ+y3XmrTZpBKHD3mFPRQsPrQUCOCDSxTReubr2yAQy7 7sOr2iTLavaJ6fiF5fU7AlvKJOJHdjvR X-Google-Smtp-Source: ACHHUZ4HPM1O+jGGQYqWpg/LatJr3hW14F3fnfsoBZ0mfOfU/MqJU94PR4Mc+EfWfWfhhCNIIU52c8Dpgsvi X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:2646:0:b0:bad:41b:f343 with SMTP id m67-20020a252646000000b00bad041bf343mr1730299ybm.1.1685138092595; Fri, 26 May 2023 14:54:52 -0700 (PDT) Date: Fri, 26 May 2023 14:53:52 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-18-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 83c7eeb8abea..5a7bfbf621d0 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 /* @@ -2013,12 +2011,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 3EAD9C77B7C for ; Fri, 26 May 2023 21:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244257AbjEZVz5 (ORCPT ); Fri, 26 May 2023 17:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244255AbjEZVzf (ORCPT ); Fri, 26 May 2023 17:55:35 -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 124C8E4D for ; Fri, 26 May 2023 14:55:03 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bac6a453dd5so1641847276.2 for ; Fri, 26 May 2023 14:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138095; x=1687730095; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=nSaQksCEVnEDaXN3VKZfEAQXs7LM72JmREmXfmsPZ08=; b=mpP88j8PaNXTEL2D/+IpKFmopIS2Jq0caewR5A8NBTRADf+MTFgSjeECfUiLSS9rYm m40GWUI314gxo3O3wklFV96hkIXsp1VaK+czkj/Y5uCDp2vHGhV6qof9FfmNf1mi1dgH RokewExO6LMD3dtpK3+RHiNaix0rS4Fwoj4mIhRYWY27HluY/6WoU0WVzSaLajlpytUd ASlCV9Q0OcS1ZEDW4arvXlyJ/Q/m75osCkAKBQFcw1Pfwvol0tsOjVlA3H1wejyRdW/q YiSy+uNreunl0RRHYKz1oypYV3iX7xEC+hnwHlqCHqMJYwHNtuFa1vU9Mfsa+jqjK6bE ZjVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138095; x=1687730095; 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=nSaQksCEVnEDaXN3VKZfEAQXs7LM72JmREmXfmsPZ08=; b=fLpaEPLSL4F6sejjFfcIilMAGhhwZETO0+WccTe2rVsJKi+WGllSarf4B2lPCQY7p6 j1ijTi4PQZnny579rXhaq+B/COmZM1i8TpWTQ82yD/6Iwsj/iP9eOlA9SFjmGboZSJGm TZVXMw81W8uU8AsWHiCdn+XWhZGArHHOJqEo2ZPfjpGQgHGE8VRQaF7V7UatXMKMw0Rn hgZZwhKxlTq1CqUIHQ6064DutoiNzHucTE3ScuBB1zm9dhv+34oGVWe3P9Dl8CFhND4w 89wEHtO+ZgRY+6afBeUhW461ctqKQ+YrWLx5kmRmWImFw0TPD/E9aCURKL7jV187353u Lriw== X-Gm-Message-State: AC+VfDwKon6VTdGIhpHIUxhad47qI1YGUg4JWwj+zT5E6iC0ckiKYkfh +2ku9Ntnza2qqRKWsncRcRjCrQz+rcW2 X-Google-Smtp-Source: ACHHUZ5cqJSlzhtTQe/Z6EyPf1csdAOirFufe+QgZ1XxjJnGG1GzNlbcbw7Hn7rdzirV8Ufp79bECpAC8F+J X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:dc87:0:b0:ba8:45d6:dd8a with SMTP id y129-20020a25dc87000000b00ba845d6dd8amr1699689ybe.9.1685138094890; Fri, 26 May 2023 14:54:54 -0700 (PDT) Date: Fri, 26 May 2023 14:53:53 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-19-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 D2BA2C77B7C for ; Fri, 26 May 2023 21:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244304AbjEZV4A (ORCPT ); Fri, 26 May 2023 17:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244198AbjEZVzf (ORCPT ); Fri, 26 May 2023 17:55:35 -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 A85BCE58 for ; Fri, 26 May 2023 14:55:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba82ed6e450so2611877276.2 for ; Fri, 26 May 2023 14:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138097; x=1687730097; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=csOWTo951DO4baytRGvCV+AGtywhGll+tnrLNxjPQY0=; b=j9NAAVXq5iGO4JhTa7MDsqCpgld3dg374djTNEgrNq8tyZyjPTnlp3eazGoLfZr3RK IkEh8Xa9RttPpnUSLFgXiMejZ6BUZ9sKk6d48yN9TF1JzCCP7dz5ClHlU8c9hD1mnKWh DaSelOVeHG9WXCdD09QHcmDrSZs+iZW/DMyZEPx5xrgB6Xxp46jryiTZWUzt7auxYmP3 hTYCfePL36YKY3tU7vCBSGErERVzdvrcWnFVss48XlHn72LdegcAc+zpzq0N7mhbm5pU B/wOu6p5OR7eXgI5UWfesif2QOnxNDkZRsg1N3u/6X6bJomR03NBuhOox9cbMslglvhs u3bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138097; x=1687730097; 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=csOWTo951DO4baytRGvCV+AGtywhGll+tnrLNxjPQY0=; b=DuWIi+Uae/+Ww/UgG9unl7DAmK0rjIlYWVYvR3QNiH+VhFvQxXdvCe8YO4Ulr+qnSf tiUCHKNKAXvgpcbw0qNV6qw1pEnOMh6t+ZKYm9GKTUYSh35k//scXTDXrCvJO0KY3bJS 6Vw0Wb8yKILscyRoIBXFjWmz8mPr0X/cB1wmY4QCkp8o35Sq+jcpFl251WIRANCnd+Ox MrvxWwW5OOqkFJhU0WRRdvmCqpUl7ou/+mipML+ythuo8+0wDkklVf3/o4NQvoaZ/DcJ q0e/kfLK2y+qp7lDj6G3QDRAv/qfSxQ2Z+i87xt988mnReyvhk7iO63GVSTMRNXALfzP 7Vjw== X-Gm-Message-State: AC+VfDyi15TSRZk4gcRWl83RUrO2draLadRita3vEVgMDJI0PvmHSyQi 0rAnrdS8u1TLNOi1d5mhYHcSOi0g7l0G X-Google-Smtp-Source: ACHHUZ6rK9vXFFe6bA1cOlIdln1XgJFys+yiHDV71eOLRBfjur55rI9Xe7Cku48l9+iEiobNEnOmOe69OKPH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:1341:b0:ba8:2e79:c193 with SMTP id g1-20020a056902134100b00ba82e79c193mr1253603ybu.12.1685138096930; Fri, 26 May 2023 14:54:56 -0700 (PDT) Date: Fri, 26 May 2023 14:53:54 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-20-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 C5767C77B7C for ; Fri, 26 May 2023 21:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244229AbjEZV4I (ORCPT ); Fri, 26 May 2023 17:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244170AbjEZVzl (ORCPT ); Fri, 26 May 2023 17:55:41 -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 7115BE6C for ; Fri, 26 May 2023 14:55:12 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8338f20bdso1621376276.0 for ; Fri, 26 May 2023 14:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138099; x=1687730099; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=OgTQ1iEJGskpPHfEYybesE3qQwBGSnBu79Mg3GVHTdE=; b=C06rKEXYr6sGGHXGQF8ebpofD61Y65PP7APe2G3FE3PQ0Jv6x1fX+I1wj77Jk98CpM PnjT3pZ7n8nxr/Wu0o4zyMxXEOot7eKSkaPNu1dtuCE/+p3/ScGbByZjMr23kbsIJQ7W SMBpK4soCaeBT2tRu/2pLgbUPMf9eERfAm/opO5P2N2U7VfJaSsc+QZNxjGk9udPensM vJul9wllepIcufFPXTW97znuXfvxZuDaicIOUcfkbvQO/QpugIrJ6T+kI3X5Bg+pUnBc dVWz84pYD0zBkL37vSCpRUGXSoMeGr15OswAs8gQH51GuWu8s0nL3ah2uixOqVCG2ZPa aLMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138099; x=1687730099; 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=OgTQ1iEJGskpPHfEYybesE3qQwBGSnBu79Mg3GVHTdE=; b=AUtXD+RfTD8rXBS9zswOkrcehl4lNDl+A9HIOPz1/WYokiLIJfXNrPuZs3522PHwoU gmLi5Q4GLGlgKcSsS+KQUJZ9dOoNnz7TMX0Zy4MQVopPe3g2fUYKsgaTKinzAHwJdrkU dWXpzUeH/drAeBMAWTOE/TmTKHllnYtVUnfkbpP++pgI77RvF2CGzNKmWfJY/OY7dzIX Fx0Vx6v4JtSfx/0KMwUpeBsRcIV2VV7yBTELS3QrDp3ZMulgAN8jkwOO7mgD4qkHdY2t TeBB4jLnXUkOW1zUxEfIv1BeaecDqc1yfOVQSqiwTgIAyXRW77cBpPbaAgZxdgFZOlMA SoCA== X-Gm-Message-State: AC+VfDzaF50k14RIF0EYZUa+s/SKX1HWKP2fEv60HrJHMpLUFf1vXpDc voPazdzMUpAA4HH/2CfywicpMHCjMjps X-Google-Smtp-Source: ACHHUZ4bB7g8nhd96w/L/fl4sYgmRAHWC+6YJnv5PjTZXis8me1qLpFi36zK9C/llTi90esMz0wguF7COqPi X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:8e06:0:b0:bac:fd27:28c1 with SMTP id p6-20020a258e06000000b00bacfd2728c1mr1699730ybl.0.1685138098902; Fri, 26 May 2023 14:54:58 -0700 (PDT) Date: Fri, 26 May 2023 14:53:55 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-21-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 E64C4C77B73 for ; Fri, 26 May 2023 21:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244335AbjEZV4O (ORCPT ); Fri, 26 May 2023 17:56:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244239AbjEZVzp (ORCPT ); Fri, 26 May 2023 17:55:45 -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 F2EA1E7D for ; Fri, 26 May 2023 14:55:15 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-565a33c35b1so24835517b3.0 for ; Fri, 26 May 2023 14:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138101; x=1687730101; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9JhuPa0yYdr5XE/axPY0rbTmGM2hgd+SHnXF4ixe3X8=; b=p0hBHqS/kbJjbfJGwxuRUo04ZHzZbtiNWdu0VCN16lg2GCJKFhldQ3gID0UCNDrGb1 JOWxsmzR3ywCY/Gm3Pl4YYD/zV4eBhbkic6TCsvAflXi4lTIB61pRixmuNxGz8vI/qkf yyjNMq9HSpljKwvyxhiZhmK2eWeI33/fERKy4D1iHYrlE8l2KpG1UK6pqoShCsXX0vB7 XzVUxo2tDj66XT77zGSdnRNR2gw3KzJJCdlpmTB3UHpxKKMYfZGvkp1ul1/VX0nANezt wyAB/4em/wmseHezl+U2xh+KsmCgIkQFD1MHX051cfvrYUKz6dfR1r8WtHXKO5Hvh6Ed ZVVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138101; x=1687730101; 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=9JhuPa0yYdr5XE/axPY0rbTmGM2hgd+SHnXF4ixe3X8=; b=kejc4FOesye8hY1GQ74CLZGG4XEJRhYc6wrt9/ATKKPPMsRx1gyfp7tsqvWdpN25Ix pPsQ+mYAWDM+MLA+JUCABS+ksra6cVH717GU8z3EO+1eV66FgXPnagad8hNduidiwJkZ Qe3I6D3lhod2ttPYfhIS6Ilb8Jd03HHqNeAPXcs8AAuzQiqY5hBJPz0ZF+wJOE91hKpH UJRWjCiQCFuc2oA8RTpZcmVoQktpM8UAxbkeVYuxwIFg9E7cIVUSB9gFhl2aD+kaFn6l WoD893CICR3yOVMIQi6elqyl3acKOvLS8DHshN1+X3F5gtU7A9HarSi6KsLqif4qVTpN OAIA== X-Gm-Message-State: AC+VfDwF0bN77OvGQLULU9Zo4icuXB3Chl+gfpEV9LvwuyS5T0uTLY/j a12H8Yv4yFbpXZJ9RRziHhKfHSnj6Vj/ X-Google-Smtp-Source: ACHHUZ4A0QwFGk16QfrxzwtIBAupC8GjSkfGg2PYWQQdvdXEGuWw24/+woiJ/4Rrhd0rgNdBl/p0Z5U9NhWo X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:ce01:0:b0:565:9e73:f92f with SMTP id t1-20020a81ce01000000b005659e73f92fmr1805177ywi.10.1685138100933; Fri, 26 May 2023 14:55:00 -0700 (PDT) Date: Fri, 26 May 2023 14:53:56 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-22-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 83FFEC77B7C for ; Fri, 26 May 2023 21:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244224AbjEZV4S (ORCPT ); Fri, 26 May 2023 17:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244263AbjEZVzr (ORCPT ); Fri, 26 May 2023 17:55:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B63B510C4 for ; Fri, 26 May 2023 14:55:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8338f20bdso1621449276.0 for ; Fri, 26 May 2023 14:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138103; x=1687730103; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=FOWg7xv6khXlnHXVYLJhfsnkHXaBKspybsIekBElbCY=; b=W0sbXBZjTNC5elb4bFAzWrSj03V+jXeRptyRfgeZBFfYPiQ/kEzaCQ7ecf978AgSai 7dK1N5NXfuK1R9jZezbIg9o5SyfFUKxumw+dUzdIhalmB74iFOxurgajxQuXAZAb/dRP oDMO6/hPF58YGXDmNCIjdv26YtzsU7CLgiqPkgFHcYlf8Gj5dCs2oj2wC+yXLvPxVUSt 1M0AyuCe82OcLft1ytjm52Sxl6YZcYlxUf2ldW7RjcEBeRXxJgGg59inv3KhNfknnJUv 1hyUVVzxLc2ZmQ0kJ52A36IGJPJ9wc+hKSDW/zqy3tffkBZWKsoIldeGy2inRZ+2gdl1 AYUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138103; x=1687730103; 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=FOWg7xv6khXlnHXVYLJhfsnkHXaBKspybsIekBElbCY=; b=RL80Rr40c9hpwCEo23RY1a5cYyrUP1mi79iPix82E0s6HNcORmAY4tidjMJt5MLb1N AYts904y3h99/7eMzBFWtuwO8fKewBGbokLj6uMKUaXBRWyfTicmlb5BzazsH9x8fPDa ARN5HBjzNncV0/6Uy3tJEBFPOoWgZz02byae4ubFx0jqWSKB0HjUwDx98snfKU96Vdax BGMKEKtoC4sOmom3q4ZcxJZhXtYeO1NQIvzrILj4U1Iwoft7wlTo7jeksy39aaB69bqD GVrtXm68Np0AA+iHu0Pqh7Y4F+9n1TTXILmrO0i9d/Ft2wfJl+tlhYwTie5idepemVhW 2OBw== X-Gm-Message-State: AC+VfDyGl0w9R3PxJwtNrGzI5planv1PbneSgPPhdcE3gv7kkA/U1OAm dKJO2Bs6Hu4oyEfzr0FHOL2cbH17TbkT X-Google-Smtp-Source: ACHHUZ43XEAJO3f00pn7wWSBbjxBs6NDSOWGch/bUqBzmufYwYUeVNJDfIIp13hDPrkPN+Pth1/fwjjLgClD X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:ad93:0:b0:ba8:37f6:a586 with SMTP id z19-20020a25ad93000000b00ba837f6a586mr1668359ybi.3.1685138103181; Fri, 26 May 2023 14:55:03 -0700 (PDT) Date: Fri, 26 May 2023 14:53:57 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-23-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 80ffd6da70c7..3f04a686d1cd 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 69ADCC77B73 for ; Fri, 26 May 2023 21:56:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244345AbjEZV42 (ORCPT ); Fri, 26 May 2023 17:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244291AbjEZVzy (ORCPT ); Fri, 26 May 2023 17:55:54 -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 D183210D7 for ; Fri, 26 May 2023 14:55:27 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5653c160973so25959877b3.3 for ; Fri, 26 May 2023 14:55:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138105; x=1687730105; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=o9BuxLyiQzY2TC1wkUXo7pk2ilQpQDkXjoqwEb1YJT0=; b=W4bgolXSBG/aM6AAMIrVWP8PxrTIfod6JPer3GBXCt/gN9PGx6HtMZdQ92CeOZsa0h zto7T/TZcJU13XvCS1fJ3zC6gCHGwi9hu2T0yxjiibFt6RECA9r3Sm8v5SJXfJBG97Ob BCsF752HlXeNrbkdvQt7a8CLZpmFgZXROjXeJJRreDjpnMem33Z1uV3WQBI/0HLWTR0j GXD8vnRftGkrCiB7DlrqDFo03fWiwGOSSE44isOVGB3aRZH9yf0ugO+Rc6OTMgAYVbr6 5W83aTlVpMuuuAGLVnulvKdPmZ2MZOn6osFHjw3ZjUJYvdKSndmvenGnm6z4+pzlL2PS 1drw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138105; x=1687730105; 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=o9BuxLyiQzY2TC1wkUXo7pk2ilQpQDkXjoqwEb1YJT0=; b=PAUbX4f/Ub7jLYNaNR3TUWbvHxZSUkbpyCrKpv/I/pmFCH4NDt+qFxp4WtQO3D1hBY gLfEzoh3Svv4+5jVBXIRLf3BM7c1hxkBiOIt7pjq0dOLVjbI9ZZs+/lSIFmv6q8LCiy+ Nx8jKHsIKjHSq4dWfutH2HP3s57l3lZQ73nrLUJLbaHZMxHdD/d0ml55Lh2+LjfKPEjn 766TXuEBX4tFUrzPNILkB2p+Q+18HFbmvxMbd7hW3GHphTF0SyFjpJQoztXBdiMHXlZH TkM44b3sgyaqU6akL12QUBBMmkyeN79niUCP+iVjUuKSl3iwtccTERB7hvnaKrHko2b2 +kGw== X-Gm-Message-State: AC+VfDwDfsEgNBRLZB2fvEKC70jpmNIs2IMFUOEvSOLiJidoINP53N8X UzM8TnFamAztDc4lVnPmxu3xMTya34nm X-Google-Smtp-Source: ACHHUZ53ZLD5rWItTLlXnBT5M5rNiiWHb6EfXc4TAHoG/yypTknS6qdXXrehh+0oWJXgSwo1bZOSR4eZx8H7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:d20d:0:b0:561:8fc0:24af with SMTP id x13-20020a81d20d000000b005618fc024afmr1776134ywi.9.1685138105639; Fri, 26 May 2023 14:55:05 -0700 (PDT) Date: Fri, 26 May 2023 14:53:58 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-24-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 C9957C77B73 for ; Fri, 26 May 2023 21:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244157AbjEZV4d (ORCPT ); Fri, 26 May 2023 17:56:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244294AbjEZVz4 (ORCPT ); Fri, 26 May 2023 17:55:56 -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 0492C10DB for ; Fri, 26 May 2023 14:55:29 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba8c3186735so2606328276.3 for ; Fri, 26 May 2023 14:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138108; x=1687730108; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RcROT9jp6OZa4Pd3xwGvZ+cvDZqw5Cwo0zsZ9qLHIG4=; b=PRpGI04BjG6Nf2Geo2iXSnO+vuKQ7zMaN4/+RitHxWHXbECoECRvjp5iOrkgoKFlDU lTaFWwhRNYtcYb5X16Lt3Gn8oiBJhhkIPqTZVGChjjKQmBJ3MNqojpVgu1RfVSxF7tXw +PWeBr/DZF5dASCKgJcnV1GlXA7/XM89A7t3AYPbYqNt7FzOfvzw2HTbSBWR4OB/FZsY V6mDJDAJ5SVVY930XtO+buo46H2cxA1rJK1n1YkcSXEYHWBiMaTZich+dm/KEjb5VMIC 0UtKxaVQbiH5DtwUEe54bVfZKGmyvzIO9mw9FvjAsuC77fh/GK9asmhSv7d1VIg4T1Ml UeaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138108; x=1687730108; 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=RcROT9jp6OZa4Pd3xwGvZ+cvDZqw5Cwo0zsZ9qLHIG4=; b=bhnjHu4oFe4IG9VWLC4IVq5JUfn7hIT8BNOjUJ4PzO47H9AVx7laReGSH61TcafCtP feWrj/J6rNkkJhmPk4F321de7CX8fCkwv4rjWDLwDFd52Yq2d9sbv8exEEAixtVUEmk5 gKDtkgKDqF2tQwVL6mG5+g9mkBn7JH48NoP3qTrn3D3LZcAUjDVcI65XCzxU7g/l3i2L LAJ27vgx9HW55M/0XbsqIMqEUJVVZ73P1PGczVFjKf4eBvs55h5T9FY673Ca65Zs+Nkf KOxKzrxM0AnrZxVBCBklS6UTCogU9lfvUd8tqSoDUqIssAVq4IJqEEkc/hLnjgWbJqYB USFQ== X-Gm-Message-State: AC+VfDydgB7s3UVnzX+ayUbyQTwaIAvCLr93WrKwB3xd6tGZZYeDsMOH bUBHmbWIXGgIkZpAhd20W2PxWvAdeNe2 X-Google-Smtp-Source: ACHHUZ5Pnlf2xMgGAhdYazUVA8pJkRIOBL3CvGPM/60yY1Pw5MnOiedoe4bXGIoHhJnLmOMajJrDNVolzAqT X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:1341:b0:ba8:2e79:c193 with SMTP id g1-20020a056902134100b00ba82e79c193mr1253763ybu.12.1685138107923; Fri, 26 May 2023 14:55:07 -0700 (PDT) Date: Fri, 26 May 2023 14:53:59 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-25-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 5a7bfbf621d0..65daa0cc71d6 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1660,6 +1660,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 16195C7EE2F for ; Fri, 26 May 2023 21:56:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244358AbjEZV4g (ORCPT ); Fri, 26 May 2023 17:56:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244259AbjEZVz5 (ORCPT ); Fri, 26 May 2023 17:55: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 9803910DF for ; Fri, 26 May 2023 14:55:30 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bacfa4eefcbso3029875276.1 for ; Fri, 26 May 2023 14:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138110; x=1687730110; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=FHLFLct9vm+JF5+hDruAHJApiqqRufRTiKPYhWzqyW8=; b=pHaAj2eZKtFrHzgOTKFGvRMCxuCuQuS8NsqeS6JTjRXsFmMD08CbHgTDCIGE+jcuTI LL/AhAcu5baFTinVUtQQew3AVi9GP34uHsqzXJIc6xqJy5f6Mo1LQm1usV2HHXKY0Y8h 1nzJgS5FL0ZQaJ1Svbg1cw8LeNpqaMffh5vkzpLPc/3ivN+1sg4kYOuFe8gTK0uE6wwb zqBPshvribliIMj0P+272GgHu1t29asHsxKK0ifUW15ZBtFrZhtUSMu/6ILuDW14xTF6 26iMl8pCC/L98EHKtoU4bK/pj7GrswZcraqahfym2ewmGsXI+Sswn51K+SsWC4Z/tX8N ZoAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138110; x=1687730110; 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=FHLFLct9vm+JF5+hDruAHJApiqqRufRTiKPYhWzqyW8=; b=bi9AtnP1phoyJ8qU4uq0R+jOYoWxbKs2Dc61xWJph8FZ55pB0U22VZ14p20Vi+zz9X +FXYUFI5sGk9y+j9OLy8D3kpA41emXJjjmF3ORNLNyTX2OgVTSLkm3x+dZgADxJGqrNL NAiG17lX22UQtf0tPHsvYzMLETnGMNF0+Tk9H80JGqvPF80I+iDdWVFKnW7sjmXlYjvZ ro8ynt8Myt7I/jzOrk6UJoEoxFSgVFALatVKGCUAhrqKCJqMeUj4USaX79GZS7IAugxV vy3xk73i32fSle4OFPi6ZwHspqNsJw7psS2o7lgEbNrZuxG/V9QhS7DLCLDnqMvGtSZb bniw== X-Gm-Message-State: AC+VfDzEJSoqa1Zb5rJBACsMtS+281m4+6USb18W2Rw42JTAHTsJY/4b jTCMSDJHxuF1wl/AByROBDmbJo4JVS04 X-Google-Smtp-Source: ACHHUZ65SLrFYg95PAKQ1z86tR/S28H0lU2g+RJzGp+MjpnpDhAUrYb3ceGb6a/wr1gR8/hcCQPvTun2aKKA X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:dc81:0:b0:ba8:1e5f:8514 with SMTP id y123-20020a25dc81000000b00ba81e5f8514mr217694ybe.5.1685138110169; Fri, 26 May 2023 14:55:10 -0700 (PDT) Date: Fri, 26 May 2023 14:54:00 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-26-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 65daa0cc71d6..21ee23b78f5a 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; @@ -954,11 +953,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; @@ -2131,7 +2125,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 54024C77B73 for ; Fri, 26 May 2023 21:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244216AbjEZV4j (ORCPT ); Fri, 26 May 2023 17:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244317AbjEZV4G (ORCPT ); Fri, 26 May 2023 17:56:06 -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 B157910A for ; Fri, 26 May 2023 14:55:39 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba2b9ecfadaso2654863276.2 for ; Fri, 26 May 2023 14:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138112; x=1687730112; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=T/X9gvmqqlTr2f+usNH0lBMlck3ST4ivZvyTzKecxnA=; b=65p+PGvBBSTJXTUKvDEvTX52HLsGXIN0McqSA3HwufIBaYpAFamqKbdTBekOVORjpa XIMfWf13BpPomeVwm7X6wOpkxIzD6mo8f7RMl9P4el5HI2pfv2TQTpZnC71TqLue0dcw 64PabADsTap6OYPsTjKY/P2VrnxsMgTm0pAo8vTnP2FrD4gJ02LufnzRDYAzeqMOgprA 6i1tNW9chg3NqfKbX8111epyJTQrR4TmfUkWg8USza2ed4z1SJmJZBX265DJ/n2Y1e/t 2uTSQutHDnb/DzVvRQkorC7zHfcQLLNKQ6kRPr7fW8CJCjS5m/YRSJ7VxLOWBG/6XZ0X pWPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138112; x=1687730112; 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=T/X9gvmqqlTr2f+usNH0lBMlck3ST4ivZvyTzKecxnA=; b=UAzKWK/GhEgdQACUP3ZGf2Xr5k69V+JQMYwhfNoYCmZPbmk5ok9XFssOPlj4S2Bcne l3qCfQ1OmMZu6LZQPW6qCdRERYCXdS7cyzaBPoOYRxBvtvvzingCDM08orBa4zZAxbiq Lkv4NpByp//CbeQxZUDQs+Mfc7BSTfbptvyo+WzcNFn3GesJnm/V03viFreohygVczdN iUx41HPv8uqdiZmY/VzFFwm7EvOpj5nU0XixepHOqvFgPbT+C3/BwioKI88wqIMzDkQF F761Of5bV2odd/+jsqmIbevivU3dsqvEWm5aEQuA3diC+WMeP6zb3dRXYuS3hh7VGgGj zGAg== X-Gm-Message-State: AC+VfDyVVr7vovTuGUjZIUxeL22xNHL/1Sdkom8Ak1jyUopLAzihlLp7 xwZpOLBMdXbMcNAPT8YKMUSwqIwCqai1 X-Google-Smtp-Source: ACHHUZ6gxH9Jydh1jcuLGZQPtV/wofR+I6ueG/3SpSJ2Pp7mGx6yUANCLB0wC8G9bjzuKqk+P4ubuDM6L3oe X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:ab13:0:b0:ba8:757c:2523 with SMTP id u19-20020a25ab13000000b00ba8757c2523mr1699724ybi.9.1685138112380; Fri, 26 May 2023 14:55:12 -0700 (PDT) Date: Fri, 26 May 2023 14:54:01 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-27-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 89A12C7EE23 for ; Fri, 26 May 2023 21:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244388AbjEZV4l (ORCPT ); Fri, 26 May 2023 17:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244168AbjEZV4H (ORCPT ); Fri, 26 May 2023 17:56:07 -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 68C6C119 for ; Fri, 26 May 2023 14:55:40 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56536dd5f79so30384807b3.3 for ; Fri, 26 May 2023 14:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138115; x=1687730115; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6J3cKUGVc8jbchvN9nhXCNUg1ciZv4CLd2svHk2zTKw=; b=0X2D2xRpKNyCid4P4x9RXrBU+RCykPnm8OQdKJb/p+h88BXPtIdg0V1cIUJPoL8Bon XE7+Ilxkyiwu+dG6j2vD3qx7i+aF/lOf9Tm8p6zFRlQ9gA9Uoq5cklXR42MSRw42u9rg iuOU73vk6hnV/3n5sUxVvoJTikWYj04nNJBPjjO76WvLHolSdnlXcvRGgqfi1U6dzbb1 3PhALv4QQYg8MimZHnZL2T1iYGv+5Wby/hbaszTs8iq6kSgFS+L4tSM/Yuis6HPYjKb4 0eNHrVCAZghSMW4StovwWK715oWI2TXcbrF//ywS8Kr6XYtK+HuyvG622KLor4E//e/X k6uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138115; x=1687730115; 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=6J3cKUGVc8jbchvN9nhXCNUg1ciZv4CLd2svHk2zTKw=; b=dAYy0FOpvw8IE+AbZksmOiOT0Yw9CkKNjnmcBZVzKc2RTi4w32GMLO8wOFHU2tbt/s /Wtyh85zB4RbKOgBGhY5QMEM+ErBsJCBMynazBJPJPz6oClR+IdPiw20c+gvVgj1Fx0M n2Z75A+Y0a07cheePRaUTx1NxdGAncV0emiRZ+I5ZxnYlCxEvLze68IEwxKxm5mCD+hG JNHaPh23ocJvrKhwTZw0XsgUkb9o7Irxm80OFjxLjvCnFOpe+psALB5FdsfT0jiFqWV0 +C1QKJypvgwFB9wwuij50fV4zMZYZGmyQ6Mp2looQzqOx93a2YIf/HobtaVzIplB8f8a Os9Q== X-Gm-Message-State: AC+VfDyXycRhYxFpgUO/q+LknQtL6wvV6DUpx1JLnb1LDCqESA7r3B6F QTUftBOitqKaUUPOo6+WIli7HK9IYav8 X-Google-Smtp-Source: ACHHUZ5fh+g0oWPOYU4V3fSHO16qS0KDLFwGEPTlYVs6dT6fSSrv1wCW/h7+SM/BMmcHAg03PYVCPvRnq/uv X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:ed0a:0:b0:565:bf4b:de20 with SMTP id k10-20020a81ed0a000000b00565bf4bde20mr1243298ywm.2.1685138114815; Fri, 26 May 2023 14:55:14 -0700 (PDT) Date: Fri, 26 May 2023 14:54:02 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-28-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 445E3C77B73 for ; Fri, 26 May 2023 21:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244134AbjEZV45 (ORCPT ); Fri, 26 May 2023 17:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244288AbjEZV4X (ORCPT ); Fri, 26 May 2023 17:56:23 -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 AB17AE47 for ; Fri, 26 May 2023 14:55:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5655d99da53so30624117b3.0 for ; Fri, 26 May 2023 14:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138117; x=1687730117; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=NYaA+n2sLTyd06+IyNEUjRtw0+7m2ncbV26Asj1lgZY=; b=BF4Sy3OLPOKUCv9q1ICgyRtTxy3K3iICzjG6URO/+iOX6pzC+C5p7EJfKRSaE5MKHw a4eyd49mM+6EUkHW6HGFazHqhnSfKPQtNpxxuNEAqrEcGMYmxdadnXLI9ebohQGD2lBr 9H7PglibnTrZI9xjGUPEVGMeKEMbOsjYWL1jsd4nybZI6pO5QbXcdX9+lCA6XIHBAwgk PjXozlfW72GE30MaMuqFWzEJAZYo8CT7B/55FFU6WvWxjVGi9D6z/GJ8z/biQCnLg4vp TsG87TQaBYO6BK5YOGlRwO5Rnzcnig28m0Z8VBN5kfUM3d6NJguvKAd5pNPNEh+diL0f 64iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138117; x=1687730117; 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=NYaA+n2sLTyd06+IyNEUjRtw0+7m2ncbV26Asj1lgZY=; b=VOq+SfND4rCKN8GD7PKdWRu8RfjdkRgKqKIKR9wV2o5aA3tZnMIpYiurm/9XtLwzkH 8RyORoBBOIqPZ0rjiffzHEyJH+Ntzx3x4itDlpPXA0VCNlDoKnsma4l5/tc/ggSeThb3 /qINtrauEztvWWUkFKx+VlZwdw7PH00XPUJ2XRVLsYDy2UixaFEWBzfoyJF2cYlfOxy7 0MoQV60uo3XboTQcicjG99OFWKNRDXi9Nec+eAdaJlhRHhVKPMQWrNbs/QaUFF2wxxLd SGl3XvO1eRbt5aX7Uy9vsq3zyB7sptrSaFy4HSYktnzbfZP9Og/rKFQp5/rLsIkNL40J tpCg== X-Gm-Message-State: AC+VfDxgvuwAFW/cfqQ1Xw408jKeQ/iiFm2bHyPVeCJhC0oN94+s55zo i5yJFa+FkM/7by8ii1WasuXq6hCKJnc8 X-Google-Smtp-Source: ACHHUZ4lrBRlXCtg+hIvsu66JnihpGVarw/2VN4GZGXBO/5JDQIVNf5L3SK6N9FovRZn+QZ8waBzy5A4oYMg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:c543:0:b0:561:b252:41f9 with SMTP id o3-20020a81c543000000b00561b25241f9mr287543ywj.3.1685138116881; Fri, 26 May 2023 14:55:16 -0700 (PDT) Date: Fri, 26 May 2023 14:54:03 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-29-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 3f04a686d1cd..092ed6386a39 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 21ee23b78f5a..05056305fb58 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. @@ -894,7 +862,7 @@ static int pmu_max_precise(int dirfd, struct perf_pmu *= pmu) return max_precise; } =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); @@ -951,7 +919,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 @@ -979,61 +947,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); @@ -1070,43 +983,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) { @@ -1536,99 +1412,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); @@ -1654,167 +1437,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; } @@ -2020,24 +1654,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) @@ -2105,7 +1721,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); @@ -2118,14 +1734,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 EB4DEC77B73 for ; Fri, 26 May 2023 21:57:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244299AbjEZV5E (ORCPT ); Fri, 26 May 2023 17:57:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244201AbjEZV41 (ORCPT ); Fri, 26 May 2023 17:56:27 -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 DF53110FD for ; Fri, 26 May 2023 14:55:53 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8c9e9e164so2632151276.2 for ; Fri, 26 May 2023 14:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138119; x=1687730119; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=Pqi2RY0gp1d4rWnKg5tMvNvJV+6YQ4Iv3/YfBY/0/ZxAHBiPmz7i8PVDcEFHsDKIpC 1eXIrPALzIVeM6SgkajaJS3WDDYiDWK0igrzGok4XkRP9+KymLXeB4cx3VwfAeGTw/T0 oizkz4/zJpAdYaXkVRPoDiGwExRFSz/PbVS6XErYXS6IOu31JtQXuJNmjtKp5Fm26Fxw HzgGexdvvdnHnhSywNOm0LXnY6L/EddF1ohOrGZzYypOf2NdjxbFfGOhO7ujZLZrnVip xPprjYgr/dR7EhPPVfYG+MqYZcIQXUE9djG6v9Dz63UYwEj8EESwaeWPukk/vYO4BCot 0Dfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138119; x=1687730119; 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=kWjpW1u76sBxbsm1hYEhA0qZQ3555o3L2cIJC7DUwoI=; b=SX48JGabFD3RH02j2RjIrxU2EcEv92m8xW4S6KpNc+fqhdfOvTKa12QjGmFgiDQxFF 3h6GKOsCUAeVA6uFHh3Ef4O6cJrB/nFa6SwzZdB1k84b5Nh88wUquWvVlIWSNDChpttW 6MDwCU8upwOCuI932sndzp8zdwC7Tp62ZHP5VtxAYKth0FFy2bvPIYH8dHSYbTeMFdl0 zu7765u9qhqoBBTlhfQOhAZJjxEeiJHKnfSCAMQUSs+9VLJKNZnKTm0PE8rlUeCdMCtE WCDLChFvKmDH+aJnr4ZGVJggZXdcwLfkhmsTe3mPPH8lWrw09cXimgTKshbzQhXxH6sL M07w== X-Gm-Message-State: AC+VfDzWcE0anwABRpzbzLkoEqjU8m7ncasYD354Sw+Qs4lbxX1ooU3N bwYK7u7wTm/kyNejoq4pVWj6cV0s3Vo4 X-Google-Smtp-Source: ACHHUZ4C3ngzT52VBFoUiSc1f/YidlmtHxZJbZ+IMGAvn52S50DrIorMenlPZjXaVLl1md5/rMj/AzEtanjq X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a05:6902:1206:b0:bac:f387:735b with SMTP id s6-20020a056902120600b00bacf387735bmr1234872ybu.13.1685138118999; Fri, 26 May 2023 14:55:18 -0700 (PDT) Date: Fri, 26 May 2023 14:54:04 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-30-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 731D0C7EE23 for ; Fri, 26 May 2023 21:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244413AbjEZV5Y (ORCPT ); Fri, 26 May 2023 17:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244386AbjEZV4l (ORCPT ); Fri, 26 May 2023 17:56:41 -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 A1B2E171A for ; Fri, 26 May 2023 14:56:04 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56536dd5f79so30386027b3.3 for ; Fri, 26 May 2023 14:56:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138121; x=1687730121; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=v2RmrP8ViILj9UOxwpCsK4ubrlijNC2J1d0mqbYVqQ8=; b=da7p8SoTNKBvb9jCIDguxibPUtupua4motxGO/JzxaCpbvI9IBzJ/wgKQWkSJ11QER ZkJKu7TGrnHf3RtEt7Ycb6C7YMVfzqigk4sJgYuBYHBKWg5wVH0YJPFYnrHue3tHje+K yMR12ASvjVv9sHnOi0UxyOvRp2mX0HfhWYBtQRdRBKCEwsM0O1Ew58OUldhS1fVzqM48 E0KjtDANjJNm/sUtpN6Ilt+y7zl1nB5JjXr95Elo/d4i2/IztvdNSGnDu/PTqIwVe4CM TNp6tHm9MNHzXqWrUywb1n8dlFLJSw66gk5qgEx7D8PwqC4CdrpRpbew7xESfgjnIk8E EV0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138121; x=1687730121; 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=v2RmrP8ViILj9UOxwpCsK4ubrlijNC2J1d0mqbYVqQ8=; b=bBpB16+8dDtcdBhsrtdWJZDpkJO8DfoW7LU7e5EhXgBGc5E3UL884+u0Qtn+WLi9RC hu6387AsN8qy21fj2rFY8jXXg6lBVh4RI4sKpWsWcE0dCO0U2PdpvlXGTpT4lPnp2W5N sy7qOkoaEj5Koe8htZeZ07UjRC7wGzWneQpqVl/7i1/vTf5tcZg7e2KlAvcv4lnBIvkU SJLXSS3uxet8vp9D8Z0TFpDXcJCtHlTXKjzTyaJWphhp5QSKcHcTKCc2TbNo9kgFGAgY yuiejp7cbaaYYf8WBsVZ8DtVB2pz2g+wepzmv6ShAzslyCRGuut6fXf9OMj1/t/Wg9L2 Zy2g== X-Gm-Message-State: AC+VfDzTHILvkPIkdiQKJg4vcWMJlMwCeH7v0p36AyDIpETzMMyFQZct 8ZUkHJ8gWToY6WZJx63T2nXi9cDkAb2i X-Google-Smtp-Source: ACHHUZ5sM9ZuiRmD8z6Z9Pw7N0hD1JOQRI8UuObZg0u+Fcb6kvHMpHrYvRM0ehk7feDe0F+W0ydukL4zJdmT X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:af60:0:b0:55d:ea61:d8e9 with SMTP id x32-20020a81af60000000b0055dea61d8e9mr1907122ywj.7.1685138121076; Fri, 26 May 2023 14:55:21 -0700 (PDT) Date: Fri, 26 May 2023 14:54:05 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-31-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 05056305fb58..7102084dd3aa 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1427,21 +1427,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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 5CB9FC77B73 for ; Fri, 26 May 2023 21:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244417AbjEZV5a (ORCPT ); Fri, 26 May 2023 17:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244276AbjEZV4y (ORCPT ); Fri, 26 May 2023 17:56:54 -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 96829170F for ; Fri, 26 May 2023 14:56:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-babb5e91ab4so2702560276.0 for ; Fri, 26 May 2023 14:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138123; x=1687730123; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=rh9VPjugtBPm6X+hrybIGNZEfoE06aG1Vq+cBf1Euw8=; b=NT47HnCq13e2wZRzBEQWWbHa/45uvSJ/XVEwTiDIWl1gDOzU7WvOS2G/IJ5doVx4AG HDJ+am3vb+kV/p1Z7SsxVG2Xpvdd5jMwtiWLTdgSOWbczhyR+kDdn3YesUdkW6qJvfeT rYAq1RljWhu/+pnAP2BF6TRkkP3YaZatsjHazMIyTwIglHKhqD2l33MfmWciS6kTcqgF b6B9h4GNjQwp6TxdvDgQCv5pLmko9M+nBiGytDeb9QNrigkOPNFadhoiw4Eq4zwqUtix qVYZ79buD0oir3DABZBTE8DO/WSaGe4DoB4bVCoQXYB4tdLNUCQMsBHc+MEEu6MXtOiG BBpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138123; x=1687730123; 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=rh9VPjugtBPm6X+hrybIGNZEfoE06aG1Vq+cBf1Euw8=; b=BsEROEH2vuxyGuIRa80dQGSK0uDyEwAFCaOtnFxNceTJbyl1iFteiORWtD98Th+lqP outBlr8s83htcoB26HBzns+fPkjIaprMu9bEvDF8nG99IWL4UvVUts6PzlkvlxtquPTR zSdZqqwRWMF6qcJ5gIBDDsz0LYDBsFZWimhErhj3S622MQKCrMMDcBpRyvDW6MWYMuNW ab7dF6fu6Uk+GZmcYfUiExXruPTsqacScn64rldyXcJyAnr2R0w4RPowrsAi712uYmf/ INyaYaUioDSvZ62aTQ6I3C0pZrAwdRqEdIv9Wf7or/RcC+HGE666n8PtWLBiRiLkN/Qr LlMQ== X-Gm-Message-State: AC+VfDxW9Y7HBF3Emgo7fArY9oZLofloZnqV2avDL7fxTb14JL3DxcU1 op2PdQM3lkGBfUH4/QQwfMtyl+jYk0Le X-Google-Smtp-Source: ACHHUZ6Iu1fmtHJGUmPzxev78Fx3TvKNcbnqx6CoeWzqHZJpPNCQBBZPeyu1JlueZVJRFDGqvNyf/oaRflmQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:2646:0:b0:bad:41b:f343 with SMTP id m67-20020a252646000000b00bad041bf343mr1730959ybm.1.1685138123360; Fri, 26 May 2023 14:55:23 -0700 (PDT) Date: Fri, 26 May 2023 14:54:06 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-32-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 58599C77B7C for ; Fri, 26 May 2023 21:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244314AbjEZV5j (ORCPT ); Fri, 26 May 2023 17:57:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244399AbjEZV44 (ORCPT ); Fri, 26 May 2023 17:56:56 -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 CA71310CA for ; Fri, 26 May 2023 14:56:19 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba82ed6e450so2612608276.2 for ; Fri, 26 May 2023 14:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138125; x=1687730125; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=WOjxsGu2+B4s1nXlsSxqdUIWzY+WQ/eQBroudZlXVAc=; b=3heuIJcivna50pM+nhJIiF6g54QHYqLhnoOYTDWRfe/uGH0H7OuM0NUlGBfdIEbEvc rBhz0+plkzaxpfydo4SF5XQwTGgZGU+UDzrIO2nTY0OIxyVc5QodUaYo9YSQNTezXEUk uTEJ3kDf04So354A/p1dvASNE3iPhQvUTNUBgI2kNdoxMIhaKt3Pkf01ZgeX8GOlVatJ R6S8oP0+OfCgY/LfTnJJyTlzBlxKwuHTdF56hV1rjOU+nsTWH31ictUoTby/cP2z0dP1 IrwgBOkzMERCjdOUhhUYHerSGNvf6qOJxYgNVJzjinJNyF15C1insSO5x9hNu7S/2oLQ QVkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138125; x=1687730125; 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=WOjxsGu2+B4s1nXlsSxqdUIWzY+WQ/eQBroudZlXVAc=; b=RV+L5+JC1C2p2RgknZQDWPrB8kywVWZ1ADf7qu3rxFc8gft+qHdlYTKP1CHY4S5bCR i6QH1gS0J6QfSyBcy6X7Q0Jg9TzD8Lswb/Y9Y9qPg5A7T8I/w96stplo9VjQnrQzMv28 2VRuvB85bywdKS+/kCNADpXd/M2oVlMnHKEI4ia4/0NhfpvJfJVKjdEozw636DeCeLGr h+r3sBTL9my9bQEaoFeCn1DSx1O82VluhsutXIGfYXs5zcMDzXX6yJ3HrQDviNp5/BEj udw4MJrsKLuoJa1GXB5Ua02gYfVFrK/XrWgH/8DSloX5I+na8Wi3gacN7PY4Rx8zYVAK gdQA== X-Gm-Message-State: AC+VfDzSwWX48nKe9Hhw6CrW38ehJ9em+yLG+BuY/QabzYiOAghDnoXu LccAkPtbZjZYVQrj9PFj6eK50Pp2dgIm X-Google-Smtp-Source: ACHHUZ6P7LZw8PLm0hOntGTBJwTABtv2oXXPc9NN7Hx0EtYByo5ppbaUNCOqwaYLvt4xnyMTAIuUqp9sxHtf X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:8046:0:b0:ba8:8ec4:db50 with SMTP id a6-20020a258046000000b00ba88ec4db50mr1241672ybn.1.1685138125618; Fri, 26 May 2023 14:55:25 -0700 (PDT) Date: Fri, 26 May 2023 14:54:07 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-33-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 0F444C77B73 for ; Fri, 26 May 2023 21:56:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244346AbjEZV4a (ORCPT ); Fri, 26 May 2023 17:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244190AbjEZVzy (ORCPT ); Fri, 26 May 2023 17:55:54 -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 2353310D8 for ; Fri, 26 May 2023 14:55:28 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56183784dd3so16670987b3.3 for ; Fri, 26 May 2023 14:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138127; x=1687730127; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=vW2lbdpPJdg/r6QP2GPnX5xgemELHxkJ0mClCQxJlXE=; b=XgJYAm41O7NNFLVHPpeeRZju9bD5zUvsAC0wt/UXOVLw3GOfF0JaoBMe6TBnPqkDUE jYdH81MvGVvclARKFyJ+Jgl7dihH7i1nYuM33T1qAdu9hQxuma0ZNocFspbqG5fg53kf 4CrE581+2bLeQ/wzdCJdRvTbLVN5+U11VRZTFLjVH5/IOwxEBng7w3jNTu1ciOoSniUD DFKPeorSfxpLWSMYHLy6dm+O2HDNl5TYai1K5TOZvxeVRCUhuNBy43xF9GawgVp2vtYq dC5SFDsDu1an8pxHIAPY58ESVMsOOWY6NjEK8t3G7kD/zcEjKDJ/j8pZhZcvZTis1nwh rpdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138127; x=1687730127; 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=vW2lbdpPJdg/r6QP2GPnX5xgemELHxkJ0mClCQxJlXE=; b=P9ddR7cjoqjlX2iuOdCp4JZc3OZsCYnO67OqfC9zpzNXyFWgpGXDVzBlZbio0SQ25w fVqg8qhMozb+cWE/e0IEOHqO7jIBw0xu73aK2y/XRQdSEqRHcIjfcQ1X1WEp/s3kZgXX KgI/GkdayA1+XGiVDMyk5VnAjMvmpJCh4bwNxBg6+cOD+ik374DYBVTG1Z8AXTj5rOog UF47GXDZ1WmaWwoZEY+1We2GX2ZGzbFJ64ZQbkV+9yFzPliJLU1z3G8R1/WkHXlNO/bp xm2R6TfmwthCCJQ1KkQvHpPM4BbXUeAJIaI9m6DCJS/wW7WDHqBCXTg+JK5dIumm9MfD TN3A== X-Gm-Message-State: AC+VfDyNaKH9ojszG0JULPEkutX1NW/qjxoLBY//8B9BS6Vb5crh4baI i8ub/aTylPo21UVG8Z0oaZfN/RGkHvqj X-Google-Smtp-Source: ACHHUZ4NRRDlyH/flCqp3jYK/1HAot9LkkCV9xPcWa5EvIdoqnj1c7Po8JDOungTNQVgPDVDILQcujc4hqvO X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:b710:0:b0:565:cfdf:7a70 with SMTP id v16-20020a81b710000000b00565cfdf7a70mr64876ywh.2.1685138127743; Fri, 26 May 2023 14:55:27 -0700 (PDT) Date: Fri, 26 May 2023 14:54:08 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-34-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 16EC3C77B7C for ; Fri, 26 May 2023 21:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244436AbjEZV5v (ORCPT ); Fri, 26 May 2023 17:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244204AbjEZV5X (ORCPT ); Fri, 26 May 2023 17:57:23 -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 DF07A10EC for ; Fri, 26 May 2023 14:56:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba81b24b8a4so1599249276.2 for ; Fri, 26 May 2023 14:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138130; x=1687730130; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fJLTnwV96VTYWt/t+i/N6FNmsulvvGuMBF5CYxxo44I=; b=6vVFdfxlmW94h1Ojr2ucJ282VaNFkQwwiYveUMZciEynzjuOpuLAKw+VasXmoEx4dS U6Wpt9w1vb+z3xCNiIKfYFyQt9W/1m79kyX59g6DnAKhrbmsQreARLnQ+0bOjyNdVgL8 +wH+0fCjZEW8k4RGoIsFSLw3cDYpaQHoohEKalXTw/kWvX6KX3TJB6t1OX68oNIakOik I+ioE21050nNT06MlB254T+h78Le4C9yniyGudwco3Xhao7KrXkdEFwqQwFC964ghE8K wfZel90AYsj5I9P6cFadiJ+l9/u7brgt+3cV2tcyWPoL4GQUN+20TGJvTLe/mTf/laiM GVTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138130; x=1687730130; 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=fJLTnwV96VTYWt/t+i/N6FNmsulvvGuMBF5CYxxo44I=; b=AW2dRhyBNYDm9S4UFxEqeYxgl0CIN+FbgeuFyVoU/OXMkiEgpAAQWrtjWpQR+k7O7d rTSVeGEesFI405Zj5zYBrNCeb6SsI+thIlQj9jfrhDhw5ozDoDkVKsLf381pcIR2rd9z jOdeDN33jiCHQlPRLBJcF5+kDKz1rXMj+GDWqC/r8lcwD+v5b8u99EPcKfVgvDxtSXjo X4h3u92d8TqzLQfFwWjs5T0HWRYrStva6eIFr+g6ifYsZwiIzLc1erxpHHtAzAWOg9E3 DGshBAIdNCwvGB4+avCUnR5nw2ksRL6HkXDh2IQ0fE6dG/l7kcDrDA53Esg0sBF/kUNd +bSA== X-Gm-Message-State: AC+VfDwYP7Xn3l2JqWU3E9fy/ao/81zWu7z2TvmZsh0sIBX44jL2RnvJ +Y2KgnmPrszA9wvhbMG6FKv1SBtcKgPl X-Google-Smtp-Source: ACHHUZ5JSw9MwJpgeeRQddqLUrTAbd+s/kSn1HsSnDAzsdtK4khvOjctgFOPzfIYF4HkrdZArpDEBfxL2sUm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:2403:0:b0:ba8:8ab3:3806 with SMTP id k3-20020a252403000000b00ba88ab33806mr1580252ybk.13.1685138130199; Fri, 26 May 2023 14:55:30 -0700 (PDT) Date: Fri, 26 May 2023 14:54:09 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-35-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 092ed6386a39..70ef2e23a710 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.41.0.rc0.172.g3f132b7071-goog From nobody Sun Feb 8 07:07:49 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 A4BFFC77B73 for ; Fri, 26 May 2023 21:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244276AbjEZV5y (ORCPT ); Fri, 26 May 2023 17:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244390AbjEZV5Z (ORCPT ); Fri, 26 May 2023 17:57:25 -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 6C56C116 for ; Fri, 26 May 2023 14:56:42 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-564fb1018bcso30867997b3.0 for ; Fri, 26 May 2023 14:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138132; x=1687730132; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=I37rqh5cG8jyPI8CnkZDKw7uLKTCQzZXDibgw5Pks+s=; b=7vbUEjTg++uSRlxt9/L8w7EUfHc0cEng9J5xXYzkNK4RtEub32q+k1MjWS4ZoqgJVp bPakSgV6smTXGiuXxRwa+gbjMAHBndhZ0m4m7hRjgRVz+pMZzBDU+8jPInIiyMCbcDFO zhK0BCKwSsIXCqjGxY8icTH2xYVL8LcmhKtERl7jtq5kBg03lb5Z8+c5XjLm5udvEf+w qaU1g/frJAEfQgaE+aXUU1tmJcdcdkPHa3fqhn0uMJwn2rLJicoPv8aiFc4gkXi+Pacw g7/MqOE388AMWjIY+OcZdDllz8WfOf9h9CoQZCpSqa4kUAuh8KytEZ9C0cTpfsm172eC Arsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138132; x=1687730132; 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=I37rqh5cG8jyPI8CnkZDKw7uLKTCQzZXDibgw5Pks+s=; b=O3Yo4h/g9q+XFUii+gC6640ti1b8hE22RtOFnzgAdLj1L1YqQndVEo6EWgCe+D9IBd Soj+vUK6qsWqhAn7+jKIWNitl5GMEXbl3ytXW9q5qZDcgUyHExiGJKbi6oBZW6U/tYtR fKUBRKzkr6lKsRd9eiOzTz17zlrh+jrTG87wQe5VnFoSkfMo07mmVfaGLtcSDeUlcT/M vdaLfAoATThJuXB3+Wq+iPTiqUh4BMyHpQBCrSvdvw7CeNuGhfkON2/8x21vboVOMVbS jPz91xLTDGeCSrrkHSnW05qM4ViGG+HonW9KLWFAGBIswhHGCIZGTosx+TX4G79vi/yB ZdaA== X-Gm-Message-State: AC+VfDyRN4hA/PiuN6JSDMuYWvmzzQw/bDY/RII1a91NBI9ZoDa4A1Yp xAck/UjG/tbbVerXG7pf9oxtIOOa861e X-Google-Smtp-Source: ACHHUZ48ljorUNxuemfq25gYwZO+QkJCDIdXd2cai4k6TFvPbsNPR0m3OMWBkqmC6SCuVN9fnpWdn+ntMCja X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:d84a:0:b0:562:837:122f with SMTP id n10-20020a81d84a000000b005620837122fmr1901844ywl.9.1685138132485; Fri, 26 May 2023 14:55:32 -0700 (PDT) Date: Fri, 26 May 2023 14:54:10 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-36-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 7102084dd3aa..0520aa9fe991 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1417,11 +1417,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; @@ -1429,7 +1424,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.41.0.rc0.172.g3f132b7071-goog