From patchwork Fri May 26 21:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13257362 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 447A7C7EE2F for ; Fri, 26 May 2023 21:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id :Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=w4KucBGBVosr6Bq7LPk+xVwLTaccZRj8r9Zu+28l0TI=; b=RhLIcOXLQ8IdCo LoaDNWXbGRyZA1ZEP1GsDMuyOCUGIjKiwBS/8nkgd0sVCVw0mMfF3E5A16v/ot6rcLQlGdQXgGOVS M3CMaJGdNGNCRC66wb6yUNBJ4GNy2VoLfwGN25g2HQYBWsbQMI/Gzg9S0d6yqiP88avfXqZHwruhy FDyzfR7qYRLQ0lzTdP6Tf/Cn13qk7JISlaRp9qSQds3wpWZmF16vM0PENN+QZ4iG31OZNcn36A//0 uIrltLWNWe5B7kJ+Ere7FHuoPRF6H3qKy1y50HeYGpyQQlyc2G0OYDxrapBmonSrlsvhz1iLQ1PWY q5dZHUbRu1mp8YbgwO7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2fOA-0042wD-0H; Fri, 26 May 2023 21:54:22 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fO5-0042sJ-1z for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:54:19 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba87bd29e9dso1637149276.3 for ; Fri, 26 May 2023 14:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138054; x=1687730054; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=/VeaQPRlwfc+cfqeHAnnZK+9G9F+QnHDTT1HWy7dy+0=; b=6bj4A8znRG1OQU3ZCyVR0H++Iov5wi2qcofQvQOsetiMglZCIcpGe33EymKXEOCMXU 7Grn/ztrUPjAkG5G7S9rfPDGkIbMSOyzklqvP/eTwmbBMoZhachtmDjNLPadIgr5ZywA vkUCx57LAcSDWzT1TqDKWlSEjCI4yIUsQnRTlECL9V/G0SQ6BWPyD44ZEfba/kHxnnCh WMuBeyAq4FtPvipnSFzE1zRdKGyEJp5kuQibkJJYJY3mmZsRERW5jz8Bpjk9H7gdHdi7 NXObPOyxthM0SfVcSOBeAcrvId6GH3UjkCqdKdVSpuQE7ETgFZzZojlgwqKyGJnO3/da 3Vww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138054; x=1687730054; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/VeaQPRlwfc+cfqeHAnnZK+9G9F+QnHDTT1HWy7dy+0=; b=TVHo8hDg7i9Ci0cTPbKR8cXADl2ajBM/ehlYlcafjjTBmoIbAcnHXzBT+1Rvaj03RC 46o5siQz3BrBEZ8YctOATDuom9dq37ARYTuOxIVzmJrguNhT3a25ut6Mo6qSAXFAd/No +jnV87XZxlE+GM7p4knbRrz5s3dTZoq4xYb13bufki5fX10cMEvMCDJV4XrMybM6FsOh XsFZMY1O4zVlJd6OnicMR05iR4kleFLRiv/1fvi54G0qhCJGVNnym8aYDTnmWNpbAocN at9dqmhB7kERt02/MpVk6Lewc2Dvw8/7k7q7um30fxlkGHEY/K3VOOqw0hVYFBPfc9lc sw8g== X-Gm-Message-State: AC+VfDwRnKyqa25up5GivF+e3TxAqCY3IUwPp31ZzXtlpJ37mwRo7AV5 gsE+Bu4jkcCsFCgrd5OsKJeHtu411+5a X-Google-Smtp-Source: ACHHUZ7pzilsbkWjsEY/9b69o/a8X9JMVvQGe2hCRyOJKTwWLMIT4SaGiakVICpApGIIhC6kwUUlgct60p3f 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-20020a258204000000b00bacfd63b567mr1723856ybk.4.1685138054005; Fri, 26 May 2023 14:54:14 -0700 (PDT) Date: Fri, 26 May 2023 14:53:35 -0700 Message-Id: <20230526215410.2435674-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 00/35] PMU refactoring and improvements 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_145417_673235_48F5576B X-CRM114-Status: GOOD ( 20.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Separate the code in pmu.[ch] into the set/list of PMUs and the code for a particular PMU. Move the set/list of PMUs code into pmus.[ch]. Clean up hybrid code and remove hybrid PMU list, it is sufficient to scan PMUs looking for core ones. Add core PMU list and perf_pmus__scan_core that just reads core PMUs. Switch code that skips non-core PMUs during a perf_pmus__scan, to use the perf_pmus__scan_core variant. Don't scan sysfs for PMUs if all such PMUs have been previously scanned/loaded. Scanning just core PMUs, for the cases it is applicable, can improve the sysfs reading time by more than 4 fold on my laptop, as servers generally have many more uncore PMUs the improvement there should be larger: ``` $ 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) ``` The patch "perf pmu: Separate pmu and pmus" moves and renames a lot of functions, and is consequently large. The changes are trivial, but kept together to keep the overall number of patches more reasonable. v4. On patch 16 (perf pmu: Remove perf_pmu__hybrid_mounted) remove the handling of no cpus for a hybrid core PMU following discussion with Kan: https://lore.kernel.org/lkml/20230524221831.1741381-17-irogers@google.com/ On patch 9 (perf evlist: Propagate user CPU maps intersecting core PMU maps) fix the comment on struct perf_evsel's system_wide variable from conversation with Namhyung: https://lore.kernel.org/lkml/20230524221831.1741381-10-irogers@google.com/ v3. Address fixing hybrid user specified CPU maps by doing it in propagate maps. Remove nearly all references to cpu_core/cpu_atom in particular by removing is_pmu_hybrid - hybrid is now >1 core PMU. Addresses comments by Kan and Namhyung. v2. Address Kan's review comments wrt "cycles" -> "cycles:P" and "uncore_pmus" -> "other_pmus". Ian Rogers (35): perf cpumap: Add intersect function perf tests: Organize cpu_map tests into a single suite perf cpumap: Add equal function libperf cpumap: Add "any CPU"/dummy test function perf pmu: Detect ARM and hybrid PMUs with sysfs perf pmu: Add is_core to pmu perf evsel: Add is_pmu_core inorder to interpret own_cpus perf pmu: Add CPU map for "cpu" PMUs perf evlist: Propagate user CPU maps intersecting core PMU maps perf evlist: Allow has_user_cpus to be set on hybrid perf target: Remove unused hybrid value perf tools: Warn if no user requested CPUs match PMU's CPUs perf evlist: Remove evlist__warn_hybrid_group perf evlist: Remove __evlist__add_default perf evlist: Reduce scope of evlist__has_hybrid perf pmu: Remove perf_pmu__hybrid_mounted perf pmu: Rewrite perf_pmu__has_hybrid to avoid list perf x86: Iterate hybrid PMUs as core PMUs perf topology: Avoid hybrid list for hybrid topology perf evsel: Compute is_hybrid from PMU being core perf header: Avoid hybrid PMU list in write_pmu_caps perf metrics: Remove perf_pmu__is_hybrid use perf stat: Avoid hybrid PMU list perf mem: Avoid hybrid PMU list perf pmu: Remove perf_pmu__hybrid_pmus list perf pmus: Prefer perf_pmu__scan over perf_pmus__for_each_pmu perf x86 mem: minor refactor to is_mem_loads_aux_event perf pmu: Separate pmu and pmus perf pmus: Split pmus list into core and other perf pmus: Allow just core PMU scanning perf pmus: Avoid repeated sysfs scanning perf pmus: Ensure all PMUs are read for find_by_type perf pmus: Add function to return count of core PMUs perf pmus: Remove perf_pmus__has_hybrid perf pmu: Remove is_pmu_hybrid tools/lib/perf/cpumap.c | 61 +++ tools/lib/perf/evlist.c | 25 +- tools/lib/perf/include/internal/evsel.h | 15 +- tools/lib/perf/include/perf/cpumap.h | 14 + tools/perf/arch/arm/util/auxtrace.c | 7 +- tools/perf/arch/arm/util/cs-etm.c | 4 +- tools/perf/arch/arm64/util/pmu.c | 6 +- tools/perf/arch/x86/tests/hybrid.c | 7 +- tools/perf/arch/x86/util/auxtrace.c | 5 +- tools/perf/arch/x86/util/evlist.c | 25 +- tools/perf/arch/x86/util/evsel.c | 27 +- 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 | 17 +- tools/perf/arch/x86/util/perf_regs.c | 15 +- tools/perf/arch/x86/util/topdown.c | 5 +- tools/perf/bench/pmu-scan.c | 60 +-- tools/perf/builtin-c2c.c | 9 +- tools/perf/builtin-list.c | 4 +- tools/perf/builtin-mem.c | 9 +- tools/perf/builtin-record.c | 29 +- tools/perf/builtin-stat.c | 14 +- tools/perf/builtin-top.c | 10 +- tools/perf/tests/attr.c | 11 +- tools/perf/tests/builtin-test.c | 4 +- tools/perf/tests/cpumap.c | 92 ++++- tools/perf/tests/event_groups.c | 7 +- tools/perf/tests/parse-events.c | 15 +- tools/perf/tests/parse-metric.c | 9 +- tools/perf/tests/pmu-events.c | 6 +- tools/perf/tests/switch-tracking.c | 14 +- tools/perf/tests/tests.h | 4 +- tools/perf/tests/topology.c | 16 +- tools/perf/util/Build | 2 - tools/perf/util/cpumap.c | 4 +- tools/perf/util/cpumap.h | 4 +- tools/perf/util/cputopo.c | 12 +- tools/perf/util/env.c | 5 +- tools/perf/util/evlist-hybrid.c | 162 -------- tools/perf/util/evlist-hybrid.h | 15 - tools/perf/util/evlist.c | 64 +++- tools/perf/util/evlist.h | 9 +- tools/perf/util/evsel.c | 60 +-- tools/perf/util/evsel.h | 3 - tools/perf/util/header.c | 27 +- tools/perf/util/mem-events.c | 25 +- tools/perf/util/metricgroup.c | 9 +- tools/perf/util/parse-events.c | 25 +- tools/perf/util/parse-events.y | 3 +- tools/perf/util/pfm.c | 6 +- tools/perf/util/pmu-hybrid.c | 52 --- tools/perf/util/pmu-hybrid.h | 32 -- tools/perf/util/pmu.c | 470 +----------------------- tools/perf/util/pmu.h | 25 +- tools/perf/util/pmus.c | 465 ++++++++++++++++++++++- tools/perf/util/pmus.h | 15 +- tools/perf/util/print-events.c | 15 +- tools/perf/util/python-ext-sources | 1 - tools/perf/util/stat-display.c | 19 +- tools/perf/util/target.h | 1 - 60 files changed, 992 insertions(+), 1092 deletions(-) delete mode 100644 tools/perf/util/evlist-hybrid.c delete mode 100644 tools/perf/util/evlist-hybrid.h delete mode 100644 tools/perf/util/pmu-hybrid.c delete mode 100644 tools/perf/util/pmu-hybrid.h