Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3039376rwr; Fri, 28 Apr 2023 22:46:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5j3+CSAKPubnTPh+j2QGU7bLNUZnOf//EdKTzA3zPkBbUblwzl+tf79WY5MvLqf8MHmEAZ X-Received: by 2002:a05:6a00:22cb:b0:63b:5257:6837 with SMTP id f11-20020a056a0022cb00b0063b52576837mr9024587pfj.1.1682747182108; Fri, 28 Apr 2023 22:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682747182; cv=none; d=google.com; s=arc-20160816; b=u4zf5PSaRPqaHN0iZokN/OTKatN9vM2uxCnbybZ83SjF6uEiWEAj4jB1Q6dK5o0R5I FKsxnJA3F2a3Cq2oBl6ujR4IjbWXpZTdNWMSTjEOCI9vCF46L3hpG8r3x/ZPE4x7rZb0 8be7Z6UnoOTT6tkum4C2Sm05GcSNfcdmEcDEgmlHJTawA+5ItC8X7l7NNQuQIAHEYILZ BmqnhWY2UqAJetJkkabsZJ8ObmLxJkH89A7Q568Yh/qfmN441vHpEMa9TG7P3rVo/lqZ 6BW3ZoD6mtnP5SyhVuaHfb6kjnnYZmDKXal9WAIJ4XQtQxIUwitSQlk3LFdecnh7BBRU 2sSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=2y4q2qf1jE1jVFV1Y6Jg7+4CKbDyf3jlrprDWOHxkBA=; b=o26Ld/CEEsD1klxebmgiB9+6jZ11ECmCjslZROgD/Qm7z8pa+WjFK++1xA3ydKSYsU gjhBh3nWVpLZbuXRg88Ostgv14mVJiW9BS7Du6b4hs2NmGYYn+2vaYFIdnbsclnicATC V12iW4necIl7d9OcLQHhp4uo6RpvJ1lZ0mAG0Lo/gCz/hI5EjWa6pRwmw3fTPAeu+BsY vrJcbGvpuKHnFRnhGSNS7WenD32Muft0TA1u81o97NDbvNSWg+B2yN69MJLOA0L566JP 0CgRwrXmfereYI0jhV/8yc1IjIv3lCGT6o/p1erfp+9oPfUdxRLFDcdULWO+lrF7faTQ +yfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=q15rfIEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020aa79ae3000000b0063b89861ec1si22760463pfp.361.2023.04.28.22.46.09; Fri, 28 Apr 2023 22:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=q15rfIEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347385AbjD2Flb (ORCPT + 99 others); Sat, 29 Apr 2023 01:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347391AbjD2FlU (ORCPT ); Sat, 29 Apr 2023 01:41:20 -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 57DD53AAF for ; Fri, 28 Apr 2023 22:40:55 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-559de0d40b1so6644457b3.0 for ; Fri, 28 Apr 2023 22:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682746788; x=1685338788; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2y4q2qf1jE1jVFV1Y6Jg7+4CKbDyf3jlrprDWOHxkBA=; b=q15rfIEW7uzeY1Z5EOawB3lHB2VrT5OLoCqydTRFno04C7lvF1EdOB3v3KFDqU4sXu Aikoa3QFkHKZN/FpMYpr7RMLXr9armb1WBA3ibi6QG6de60yv79CXMpASQ8wJ9B8NJ9X m14Z3L7zYhndWa+gJWlogAsYaqvcFOQf3fSf9EsVhUl5vLErV9oItcIutYP1xw1HZMXG X4Qr3ITGs9Yl7DrgQYfnlpL5H2xt3TeWlPtSDKhTFcNpD+0/cZjD9SOhyLWCxXcJlbgj e1IoxUHIjwGnlanZaPmRzzv3wHQHBEPEj8F01dDAQQsugfd2v1yNROPjQTUUxOH+Km9I dVXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682746788; x=1685338788; h=cc: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=2y4q2qf1jE1jVFV1Y6Jg7+4CKbDyf3jlrprDWOHxkBA=; b=XX7CHF994T14tkpTzI6as/HV+gQK1Cramy3QYN7RUUM4y/5ufK+liDdrbem6c1Zxng +qDYrlyDw5aJWxpHRAxGYkxpjAiXrzjoO8hivrt589Pt6TpWkU7BkDiHizHNIVTX2IIu ZTtrUQ3T9X+yFSUlHEbLQ6T4Yb8MRoLAlm+rtYiDATrtmgao9RwjbgKkJtn8OiMAvWO9 x3CM4ROEGO0Bjqe/daOjv8IO0kKdqP2lVoT/0QFPf50lqsPfR/DWe7l4L6lR+ncvCy3W DdtG6T/yOya4BAk5GeNmUlYH0bMmXqBDELBggbhm4h7IjaWRQmMt1+OfqFQtRkJota4E q23g== X-Gm-Message-State: AC+VfDw4Rq7kzkLSsIjF78lA+Rt3/HfiTQxNrAmb2Zsf8NoXAZO/15CT uCa800fuqHbQYF1wrprXCtZBq4r6qJyL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:c563:7e28:fb7c:bce3]) (user=irogers job=sendgmr) by 2002:a81:de03:0:b0:54c:cd:f38d with SMTP id k3-20020a81de03000000b0054c00cdf38dmr4278539ywj.10.1682746788716; Fri, 28 Apr 2023 22:39:48 -0700 (PDT) Date: Fri, 28 Apr 2023 22:34:52 -0700 In-Reply-To: <20230429053506.1962559-1-irogers@google.com> Message-Id: <20230429053506.1962559-33-irogers@google.com> Mime-Version: 1.0 References: <20230429053506.1962559-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v3 32/46] perf stat: Make cputype filter generic From: Ian Rogers To: Arnaldo Carvalho de Melo , Kan Liang , Ahmad Yasin , Peter Zijlstra , Ingo Molnar , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Florian Fischer , Rob Herring , Zhengjun Xing , John Garry , Kajol Jain , Sumanth Korikkar , Thomas Richter , Tiezhu Yang , Ravi Bangoria , Leo Yan , Yang Jihong , James Clark , Suzuki Poulouse , Kang Minchul , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rather than limit the --cputype argument for "perf list" and "perf stat" to hybrid PMUs of just cpu_atom and cpu_core, allow any PMU. Note, that if cpu_atom isn't mounted but a filter of cpu_atom is requested, then this will now fail. As such a filter would never succeed, no events can come from that unmounted PMU, then this behavior could never have been useful and failing is clearer. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 19 +++++++++++-------- tools/perf/builtin-stat.c | 12 +++++++----- tools/perf/util/pmu-hybrid.c | 20 -------------------- tools/perf/util/pmu-hybrid.h | 1 - tools/perf/util/pmus.c | 25 ++++++++++++++++++++++++- tools/perf/util/pmus.h | 3 +++ 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 1f5dbd5f0ba4..1b48cf214b6e 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -11,8 +11,8 @@ #include "builtin.h" #include "util/print-events.h" +#include "util/pmus.h" #include "util/pmu.h" -#include "util/pmu-hybrid.h" #include "util/debug.h" #include "util/metricgroup.h" #include "util/string2.h" @@ -429,7 +429,7 @@ int cmd_list(int argc, const char **argv) .print_event = default_print_event, .print_metric = default_print_metric, }; - const char *hybrid_name = NULL; + const char *cputype = NULL; const char *unit_name = NULL; bool json = false; struct option list_options[] = { @@ -443,8 +443,8 @@ int cmd_list(int argc, const char **argv) "Print information on the perf event names and expressions used internally by events."), OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated, "Print deprecated events."), - OPT_STRING(0, "cputype", &hybrid_name, "hybrid cpu type", - "Limit PMU or metric printing to the given hybrid PMU (e.g. core or atom)."), + OPT_STRING(0, "cputype", &cputype, "cpu type", + "Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."), OPT_STRING(0, "unit", &unit_name, "PMU name", "Limit PMU or metric printing to the specified PMU."), OPT_INCR(0, "debug", &verbose, @@ -484,10 +484,13 @@ int cmd_list(int argc, const char **argv) assert(default_ps.visited_metrics); if (unit_name) default_ps.pmu_glob = strdup(unit_name); - else if (hybrid_name) { - default_ps.pmu_glob = perf_pmu__hybrid_type_to_pmu(hybrid_name); - if (!default_ps.pmu_glob) - pr_warning("WARNING: hybrid cputype is not supported!\n"); + else if (cputype) { + const struct perf_pmu *pmu = perf_pmus__pmu_for_pmu_filter(cputype); + + if (!pmu) + pr_warning("WARNING: cputype is not supported!\n"); + + default_ps.pmu_glob = pmu->name; } } print_cb.print_start(ps); diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 3b25fcab5cd1..06a1d71a49a5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -44,6 +44,7 @@ #include "util/cgroup.h" #include #include "util/parse-events.h" +#include "util/pmus.h" #include "util/pmu.h" #include "util/event.h" #include "util/evlist.h" @@ -69,7 +70,6 @@ #include "util/pfm.h" #include "util/bpf_counter.h" #include "util/iostat.h" -#include "util/pmu-hybrid.h" #include "util/util.h" #include "asm/bug.h" @@ -1089,10 +1089,11 @@ static int parse_stat_cgroups(const struct option *opt, return parse_cgroups(opt, str, unset); } -static int parse_hybrid_type(const struct option *opt, +static int parse_cputype(const struct option *opt, const char *str, int unset __maybe_unused) { + const struct perf_pmu *pmu; struct evlist *evlist = *(struct evlist **)opt->value; if (!list_empty(&evlist->core.entries)) { @@ -1100,11 +1101,12 @@ static int parse_hybrid_type(const struct option *opt, return -1; } - parse_events_option_args.pmu_filter = perf_pmu__hybrid_type_to_pmu(str); - if (!parse_events_option_args.pmu_filter) { + pmu = perf_pmus__pmu_for_pmu_filter(str); + if (!pmu) { fprintf(stderr, "--cputype %s is not supported!\n", str); return -1; } + parse_events_option_args.pmu_filter = pmu->name; return 0; } @@ -1230,7 +1232,7 @@ static struct option stat_options[] = { OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type", "Only enable events on applying cpu with this type " "for hybrid platform (e.g. core or atom)", - parse_hybrid_type), + parse_cputype), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events", diff --git a/tools/perf/util/pmu-hybrid.c b/tools/perf/util/pmu-hybrid.c index 38628805a952..bc4cb0738c35 100644 --- a/tools/perf/util/pmu-hybrid.c +++ b/tools/perf/util/pmu-hybrid.c @@ -50,23 +50,3 @@ bool perf_pmu__is_hybrid(const char *name) { return perf_pmu__find_hybrid_pmu(name) != NULL; } - -char *perf_pmu__hybrid_type_to_pmu(const char *type) -{ - char *pmu_name = NULL; - - if (asprintf(&pmu_name, "cpu_%s", type) < 0) - return NULL; - - if (perf_pmu__is_hybrid(pmu_name)) - return pmu_name; - - /* - * pmu may be not scanned, check the sysfs. - */ - if (perf_pmu__hybrid_mounted(pmu_name)) - return pmu_name; - - free(pmu_name); - return NULL; -} diff --git a/tools/perf/util/pmu-hybrid.h b/tools/perf/util/pmu-hybrid.h index 2b186c26a43e..206b94931531 100644 --- a/tools/perf/util/pmu-hybrid.h +++ b/tools/perf/util/pmu-hybrid.h @@ -17,7 +17,6 @@ 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); -char *perf_pmu__hybrid_type_to_pmu(const char *type); static inline int perf_pmu__hybrid_pmu_num(void) { diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 7f3b93c4d229..140e11f00b29 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -1,5 +1,28 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include +#include +#include "pmus.h" +#include "pmu.h" LIST_HEAD(pmus); + +const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str) +{ + struct perf_pmu *pmu = NULL; + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + if (!strcmp(pmu->name, str)) + return pmu; + /* Ignore "uncore_" prefix. */ + if (!strncmp(pmu->name, "uncore_", 7)) { + if (!strcmp(pmu->name + 7, str)) + return pmu; + } + /* Ignore "cpu_" prefix on Intel hybrid PMUs. */ + if (!strncmp(pmu->name, "cpu_", 4)) { + if (!strcmp(pmu->name + 4, str)) + return pmu; + } + } + return NULL; +} diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index 5ec12007eb5c..d475e2960c10 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -3,7 +3,10 @@ #define __PMUS_H extern struct list_head pmus; +struct perf_pmu; #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); + #endif /* __PMUS_H */ -- 2.40.1.495.gc816e09b53d-goog