Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp380097rwr; Wed, 26 Apr 2023 00:09:48 -0700 (PDT) X-Google-Smtp-Source: AKy350YTgeW9aeJEuzuaY54GSgWrysTB3j85Ai6RoGp/XRp2y0q69KVVByHl++upXa033wMsntJM X-Received: by 2002:a17:903:11c4:b0:1a6:9104:2047 with SMTP id q4-20020a17090311c400b001a691042047mr22090383plh.38.1682492988039; Wed, 26 Apr 2023 00:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682492988; cv=none; d=google.com; s=arc-20160816; b=t+ejtMHDWoNOFvst60t4CX4hsNO7J9m5/YesLlEINEOAJdDJWn7YIH7XBtbtie1h+9 rhSh9Gargy6sOflxw5b6m+nrJUaEeg2NDzjf9kyLnrbQj5zzuXwFvpIgMC8osqrtu19y ZJv5CK9gaMLm+1nUehZhk9tcJuqkZ2tcFO3ZzQk3vsFRVZGAbuCaJJvi7NhRLISZGDG1 xyBTn+U51TreAhUA8OHKY7WHNZ8IuGcah4CQu4lEWuvc/S3KDFMTVhGTb2L9rB2nk+qr qaZyCQvWJ29+LBV59uhatZYszKeTFfL3GDfBEDt3PrahjH6sUkxE0ReCpiBrLHvs9zpl ls2A== 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=w6zRrC4hUX7PhEDuCu1xgf2T0BrwgQLaocW+FLFGQhc=; b=b8B9WQK/tFv4cflv/m57nPW3tqIW8wxgeQLgfB9+kS7rjOnbIMvfIuYUDI5yHdK9y3 Z4e0BsofyPZgXFrMKZB9d5eWXIxt5N8U6u3ItMeg+vsqaU/52ROHIiz/sEKMo6KKcIin 48rx5e8s+1y1rGnTDFR4JGvuJIgbboWJAA16PnGQ1I7S7CllQAhY/bBej7v/KAEMdMTs HDbGP9ZRVrbG/r7QeHOv5mrdJtyWKBrn1WsuuU+BZs1UxgAOw+98wU//CxCPo/Tkov0d mLTAERaz1+05LVRPN6wppmcmHr38OQ7g9tD+MI4JQvYjSH6YnlKIsdj3cx6ZYm6es+j9 qCFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3UnvADMG; 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 q19-20020a170902f35300b001a5d5b97c74si14893874ple.259.2023.04.26.00.09.36; Wed, 26 Apr 2023 00:09:48 -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=3UnvADMG; 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 S239560AbjDZHGL (ORCPT + 99 others); Wed, 26 Apr 2023 03:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239897AbjDZHFm (ORCPT ); Wed, 26 Apr 2023 03:05:42 -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 4E1214685 for ; Wed, 26 Apr 2023 00:04:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9968fb4a8cso6733612276.0 for ; Wed, 26 Apr 2023 00:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682492650; x=1685084650; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=w6zRrC4hUX7PhEDuCu1xgf2T0BrwgQLaocW+FLFGQhc=; b=3UnvADMGiII/idx03XAm56r+ktXmNfMerZBFmOqGNncLDgwou2irg/laiIWINguUpg JQCELgweUNWqtgUNpv6q0gOdpu9ED3ls2ff2Nr/RmwcFlb9ipXSCdjFg7WBij7ZeLJcO Cp/rZyzoMbAlSD1ksmcQQHtEDnPIf5/5acJOo0d9Zo2qoBMgrwNw1My7kC6nAO4bu3bP sDtq8WP2QZPP1bwo1+q8tlV6rG1/Ap7ioZDpct9QO0pxCtlQeB0m5ljkORcn5BY74CrC 9/42U6uNNY8vjkGyCfos7au+GVFKy32Ub3akteJIboVE4XiZExoX4rndWUBFrEIN2fdb qW8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682492650; x=1685084650; 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=w6zRrC4hUX7PhEDuCu1xgf2T0BrwgQLaocW+FLFGQhc=; b=fJQpvd8QNbt0OTdMd6yUBBrXiZdpEfvPFth3K2+b562um+MWYMiPeLu3BsOexqJ7x8 FhJgvNSIkT0+oosSdNsDra9DCPpAn8eQvocGw1ngjJF8trdJVv4fCu8bsmo4OyqHBQzz 8O+fO1mspreJY+kj4USRPlZaTDZzR1lHbu0qGZyThavzIbHUetNqrEkNkt0+f8XbmTbh P+bKfVfx+BPflNpxIHK5lzewuRZqG2zg38EduW8biOSGckISK6oLGHJaQhIoQEdunJd7 q/r9s6LunfFQ2t+Em2dQypsJlJZNo0CdAaPBrIaj1zRdU4G3IzQ8/+G4Ypkv1sfwYBee SmPg== X-Gm-Message-State: AAQBX9dlRYisAJ1r7YDRUqwBNuUb235TuPWkv/ThkrdpKp1nqjr2Okbv kknkqDB7FYW56dg3tCKKq8bjHIHYkfre X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:144f:e890:2b29:48d9]) (user=irogers job=sendgmr) by 2002:a25:734e:0:b0:b99:4877:99e4 with SMTP id o75-20020a25734e000000b00b99487799e4mr6074655ybc.11.1682492649844; Wed, 26 Apr 2023 00:04:09 -0700 (PDT) Date: Wed, 26 Apr 2023 00:00:33 -0700 In-Reply-To: <20230426070050.1315519-1-irogers@google.com> Message-Id: <20230426070050.1315519-24-irogers@google.com> Mime-Version: 1.0 References: <20230426070050.1315519-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v1 23/40] perf parse-events: Support wildcards on raw events 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 Legacy raw events like r1a open as PERF_TYPE_RAW on non-hybrid systems and on each hybrid PMU on hybrid systems. Rather than iterate hybrid PMUs add a perf_pmu__supports_wildcard_numeric function that says when a numeric event should be opened upon it. If the parsed event specifies the type of the PMU then don't wildcard match PMUs, use the specified PMU type. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 43 ++++++++++++++++++++++++---------- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/parse-events.y | 13 ++++++---- tools/perf/util/pmu.c | 5 ++++ tools/perf/util/pmu.h | 1 + 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ae421a5c9ddd..12b312935353 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -25,7 +25,6 @@ #include "util/parse-branch-options.h" #include "util/evsel_config.h" #include "util/event.h" -#include "util/parse-events-hybrid.h" #include "util/pmu-hybrid.h" #include "util/bpf-filter.h" #include "util/util.h" @@ -1449,15 +1448,14 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, #endif } -int parse_events_add_numeric(struct parse_events_state *parse_state, - struct list_head *list, - u32 type, u64 config, - struct list_head *head_config) +static int __parse_events_add_numeric(struct parse_events_state *parse_state, + struct list_head *list, + u32 type, u64 config, + struct list_head *head_config) { struct perf_event_attr attr; LIST_HEAD(config_terms); const char *name, *metric_id; - bool hybrid; int ret; memset(&attr, 0, sizeof(attr)); @@ -1475,19 +1473,38 @@ int parse_events_add_numeric(struct parse_events_state *parse_state, name = get_config_name(head_config); metric_id = get_config_metric_id(head_config); - ret = parse_events__add_numeric_hybrid(parse_state, list, &attr, - name, metric_id, - &config_terms, &hybrid); - if (hybrid) - goto out_free_terms; - ret = add_event(list, &parse_state->idx, &attr, name, metric_id, &config_terms); -out_free_terms: free_config_terms(&config_terms); return ret; } +int parse_events_add_numeric(struct parse_events_state *parse_state, + struct list_head *list, + u32 type, u64 config, + struct list_head *head_config, + bool wildcard) +{ + struct perf_pmu *pmu = NULL; + bool found_supported = false; + + if (!wildcard) + return __parse_events_add_numeric(parse_state, list, type, config, head_config); + + while ((pmu = perf_pmu__scan(pmu)) != NULL) { + int ret; + + if (!perf_pmu__supports_wildcard_numeric(pmu)) + continue; + + found_supported = true; + ret = __parse_events_add_numeric(parse_state, list, pmu->type, config, head_config); + if (ret) + return ret; + } + return found_supported ? 0 : -EINVAL; +} + int parse_events_add_tool(struct parse_events_state *parse_state, struct list_head *list, int tool_event) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 4e49be290209..831cd1ff4702 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -166,7 +166,8 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state, int parse_events_add_numeric(struct parse_events_state *parse_state, struct list_head *list, u32 type, u64 config, - struct list_head *head_config); + struct list_head *head_config, + bool wildcard); int parse_events_add_tool(struct parse_events_state *parse_state, struct list_head *list, int tool_event); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index cc7528558845..5055a29a448f 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -435,7 +435,8 @@ value_sym '/' event_config '/' list = alloc_list(); ABORT_ON(!list); - err = parse_events_add_numeric(_parse_state, list, type, config, $3); + err = parse_events_add_numeric(_parse_state, list, type, config, $3, + /*wildcard=*/false); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -452,7 +453,9 @@ value_sym sep_slash_slash_dc list = alloc_list(); ABORT_ON(!list); - ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); + ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, + /*head_config=*/NULL, + /*wildcard=*/false)); $$ = list; } | @@ -596,7 +599,8 @@ PE_VALUE ':' PE_VALUE opt_event_config list = alloc_list(); ABORT_ON(!list); - err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4); + err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4, + /*wildcard=*/false); parse_events_terms__delete($4); if (err) { free(list); @@ -618,7 +622,8 @@ PE_RAW opt_event_config num = strtoull($1 + 1, NULL, 16); ABORT_ON(errno); free($1); - err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2); + err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, + /*wildcard=*/true); parse_events_terms__delete($2); if (err) { free(list); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 63071d876190..cd4247a379d4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1655,6 +1655,11 @@ bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); } +bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu) +{ + return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name); +} + 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 05702bc4bcf8..5a19536a5449 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -221,6 +221,7 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); bool is_pmu_core(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); void print_pmu_events(const struct print_callbacks *print_cb, void *print_state); bool pmu_have_event(const char *pname, const char *name); -- 2.40.1.495.gc816e09b53d-goog