From patchwork Fri May 26 21:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13257430 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 6DCEBC7EE2F for ; Fri, 26 May 2023 23:06:02 +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:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vgmv+2ayptfWp+tZe/MSY21o+NS7Y+eca9NIQo8oczs=; b=ZNVLCX/dpVMa2s 31MF19mhHreARqyXM2Fl95k+TySqKvVknWVJovwg/uZQDUZIhfOCee0Y5JptHLWxE+z0mMnNDrLEN gSwQ8K/yMd6HAOaPZ9VoCbMNr9+TA2Q0Z+cXUZKJDnei2JyD8OilDrcGjwTVcIwVtbUgvlVZLEtjh 1U2pq2j9U1kBUvBgvRzh+7Di7UYNFaFjQfwq2DHfdT/FHEtSzBEMKv2us+o7KWb4YvXqVg3uG7UkW 0sL/t6FFqjHYrMpw9K3n7jSVOUrFCTpBqhFVIiR+OTpS26aq7S1bx+u9lq9vDUCXBOnYbnVrDeVDT sNHljYzEgbMSQ0fPbyIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2gVJ-004Eu6-1F; Fri, 26 May 2023 23:05:49 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fOu-0043B1-2S for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:55:10 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-babb3528ce5so2622423276.1 for ; Fri, 26 May 2023 14:55:08 -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=E+FFHeueY4WP+flmaW1p2SKjAaFrnRlaHLSJWfBCOMFWGsCbyidWPF3TIcrZ6iQqji NgLAZddHOKSAlNYwL5iusw+20YwOJkwhsYgq0DCsWT2/Lofk2dUjUt5JIyt2Iu5XIKdh txgIrmIzhupxM8kaYfIVmlv54F9hOPCh2IZm9LdcSB1lnFdAdRUihMPcmQk/wxokDVaS aa2lj6qYzFLUhJQ1eSQ0SEMs64FHhyuZpAe2aai6CLoJhoEIOnNHNMEDt4nXF+4Q+m6J M/4hbSVsqJ0vCIRcASI8zDMBhCpJ8V2P0BOhu3ht2kVkO/gZBdK6EE6lNDUMcXQPGpVU oimw== X-Gm-Message-State: AC+VfDxE1HKAsP393gK6zVYCRbnJ46erNImKgYW8DClU574PQLldtY3P qNgVFRDzMm+62+iENGJTXzFjCmtIQB1I 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_145508_843981_F052F45C X-CRM114-Status: GOOD ( 17.78 ) 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 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" @@ -3259,10 +3258,8 @@ static int perf_c2c__record(int argc, const char **argv) argc = parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); - if (!perf_pmu__has_hybrid()) - rec_argc = argc + 11; /* max number of arguments */ - else - rec_argc = argc + 11 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support them. */ + rec_argc = argc + 11 * perf_pmu__num_mem_pmus(); rec_argv = 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, struct perf_mem *mem) argc = parse_options(argc, argv, options, record_mem_usage, PARSE_OPT_KEEP_UNKNOWN); - if (!perf_pmu__has_hybrid()) - rec_argc = argc + 9; /* max number of arguments */ - else - rec_argc = argc + 9 * perf_pmu__hybrid_pmu_num(); + /* Max number of arguments multiplied by number of PMUs that can support them. */ + rec_argc = argc + 9 * perf_pmu__num_mem_pmus(); if (mem->cpu_list) rec_argc += 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" unsigned int perf_mem_events__loads_ldlat = 30; @@ -120,7 +119,6 @@ int perf_mem_events__init(void) for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) { struct perf_mem_event *e = perf_mem_events__ptr(j); - struct perf_pmu *pmu; char sysfs_name[100]; /* @@ -135,7 +133,12 @@ int perf_mem_events__init(void) e->sysfs_name, "cpu"); e->supported = perf_mem_event__supported(mnt, sysfs_name); } else { - perf_pmu__for_each_hybrid_pmu(pmu) { + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; + scnprintf(sysfs_name, sizeof(sysfs_name), e->sysfs_name, pmu->name); e->supported |= perf_mem_event__supported(mnt, sysfs_name); @@ -170,9 +173,12 @@ static void perf_mem_events__print_unsupport_hybrid(struct perf_mem_event *e, { const char *mnt = sysfs__mount(); char sysfs_name[100]; - struct perf_pmu *pmu; + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; - 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; } - perf_pmu__for_each_hybrid_pmu(pmu) { + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!pmu->is_core) + continue; rec_argv[i++] = "-e"; s = 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_pmu *pmu) return !is_pmu_hybrid(pmu->name); } +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 = NULL; + int count = 0; + + while ((pmu = perf_pmu__scan(pmu)) != 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);