From patchwork Mon Apr 15 06:36:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629488 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 7B9CBC04FF9 for ; Mon, 15 Apr 2024 06:36:45 +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=BSos8lRVoJKNaz+gvZ85AqTXQw26bZqI5DJlgiS+dEI=; b=YRLYaV/5GT//hw aY4Dk6oCjW35adqhcBuIwO+jB2wPtegaB7a/HVI4X2pHBElajuJHA5oKCNBNsf4dHrGVbDbSwGjM7 PTEA5qpg/+i60peZxDQAp8vbnnegb3bhwqEI8p9YPamBvPr7BRXOeEc5bzkzq0itLB6gb5bYpUwK4 F76Bu8ixv00fB0/0YkAY2U2IWu2n+E4dfDy1Q6fXpi5fIWyw7yTvxCakoLCmtYlCYLnvzAyKiWGh/ 0z1qFP3ezqNcX/s/txSwK/w560YXlHEaOs/uvqcV9KKuDfq72pcDFmBNyuSE5mAgavKfFO6XaEHWj nz4w1x5SooJuTRw8Xy+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxE-00000007Awp-33tJ; Mon, 15 Apr 2024 06:36:36 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxB-00000007AvT-2FXD for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:34 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6183c4a6d18so44839727b3.3 for ; Sun, 14 Apr 2024 23:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713162992; x=1713767792; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=3/UXsGbRM4hk6gURXUv3cQgeMnu1X8cp+uoMKx5i54A=; b=4YKKudxn329RztacrcnsOv+Xxv42kYgFsCDoMwSJ600t+2kWxBiGtWhfRpMrgvsdHX UjvJHm5VXNsG1kKVZzqav+Uy9R7cuoSbHv5blWbXZUZvFQGT3Ro0UJP4Dg+dhM6TyrIh S+0WtVphSMaVhK3L0u9uHABO828A//jWAS1KUZOu/AhpClTpReoN04mNxKjHFIGhZHr6 Klf0gdUOXUIDiT34BSYEJr5lSaPFUqw+hEpEklDJG2LC05x4J2WaGfQEa74a9gQvQER3 8Fx0fQDInEVoQgSoZvNkLaGbmtb/fbu9R4wLkC+WbRlEjf6v6ItYi2ykdBoBUTly6SW6 laAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713162992; x=1713767792; 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=3/UXsGbRM4hk6gURXUv3cQgeMnu1X8cp+uoMKx5i54A=; b=CN+Ov9rhenqGLoVSzcI9A/AYt8jAMSpU/13OiU9sWoHH2GkW5UfcgLO5OoJoZtBg57 8pjzJBb+P1IXx/pr89GewXbpLIL9IIMpfJk1DZS3LB2Hk3dWF3b7if025aUdLZBXHSfh 4ra8AEwZTPwUjBfhlKxLYhI3q4kb2PBq6a5yY1ZVmPaot0NRB6IW1mJBUtyFJrKgl9FO WDhHNCeSdL5B2KEr7Dl4h5rdKO0elhMTvkR1G9zRckRbaOO4q7gzgvcyiTxTrWb67P3M n42XyoTdYMmr/6/gbWr3S39ifnYjDvwXMN4H4OBBUmsFQabOkHZk5peSRgs/D2cg3LoB /pjg== X-Forwarded-Encrypted: i=1; AJvYcCUqaSIeKR5HoCnCjTX01dO3ujiUYkvz5sTX1qb8znvA5Ej9u67yk0PIy6e4TDbI9N+i2IqbChXpxGVb1ZGLwEmFg827tD4bRPispDjneuRG X-Gm-Message-State: AOJu0Ywj866/xV9GQTdxwp0NRkbNgYTMv9rb7NKOvIEzmqf2fV46JqjY rqrp0p/eXVCQpNqY4QpDl91+j1aVILlUUzzOnvzU8Mj0fIuTNX5cTp/GkaCd+OnswgGD7q9MPZQ xw4ZDug== X-Google-Smtp-Source: AGHT+IEpPwiuctvi4YKU+jbWzpMd0bbjy29hbZCztwCayE2Xpwu2Te6+qRZrYddkUXa58px17V/U1JOs3MD6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a0d:c241:0:b0:615:80c8:94eb with SMTP id e62-20020a0dc241000000b0061580c894ebmr2287735ywd.10.1713162992269; Sun, 14 Apr 2024 23:36:32 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:18 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-2-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 1/9] perf parse-events: Factor out '/.../' parsing From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233633_604169_36B196E8 X-CRM114-Status: GOOD ( 18.01 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Factor out the case of an event or PMU name followed by a slash based term list. This is with a view to sharing the code with new legacy hardware parsing. Use early return to reduce indentation in the code. Make parse_events_add_pmu static now it doesn't need sharing with parse-events.y. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 69 +++++++++++++++++++++++++++++++- tools/perf/util/parse-events.h | 10 +++-- tools/perf/util/parse-events.y | 73 +++------------------------------- 3 files changed, 80 insertions(+), 72 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6f8b0fa17689..b16c75bf5580 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1385,7 +1385,7 @@ static bool config_term_percore(struct list_head *config_terms) return false; } -int parse_events_add_pmu(struct parse_events_state *parse_state, +static int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, const char *name, const struct parse_events_terms *const_parsed_terms, bool auto_merge_stats, void *loc_) @@ -1618,6 +1618,73 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, return ok ? 0 : -1; } +int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state, + const char *event_or_pmu, + const struct parse_events_terms *const_parsed_terms, + struct list_head **listp, + void *loc_) +{ + char *pattern = NULL; + YYLTYPE *loc = loc_; + struct perf_pmu *pmu = NULL; + int ok = 0; + char *help; + + *listp = malloc(sizeof(**listp)); + if (!*listp) + return -ENOMEM; + + INIT_LIST_HEAD(*listp); + + /* Attempt to add to list assuming event_or_pmu is a PMU name. */ + if (!parse_events_add_pmu(parse_state, *listp, event_or_pmu, const_parsed_terms, + /*auto_merge_stats=*/false, loc)) + return 0; + + /* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */ + if (asprintf(&pattern, "%s*", event_or_pmu) < 0) { + zfree(listp); + return -ENOMEM; + } + + while ((pmu = perf_pmus__scan(pmu)) != NULL) { + const char *name = pmu->name; + + if (parse_events__filter_pmu(parse_state, pmu)) + continue; + + if (!strncmp(name, "uncore_", 7) && + strncmp(event_or_pmu, "uncore_", 7)) + name += 7; + if (!perf_pmu__match(pattern, name, event_or_pmu) || + !perf_pmu__match(pattern, pmu->alias_name, event_or_pmu)) { + bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); + + if (!parse_events_add_pmu(parse_state, *listp, pmu->name, const_parsed_terms, + auto_merge_stats, loc)) { + ok++; + parse_state->wild_card_pmus = true; + } + } + } + zfree(&pattern); + if (ok) + return 0; + + /* Failure to add, assume event_or_pmu is an event name. */ + zfree(listp); + if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, const_parsed_terms, listp, loc)) + return 0; + + if (asprintf(&help, "Unable to find PMU or event on a PMU of '%s'", event_or_pmu) < 0) + help = NULL; + parse_events_error__handle(parse_state->error, loc->first_column, + strdup("Bad event or PMU"), + help); + zfree(listp); + return -EINVAL; +} + int parse_events__modifier_group(struct list_head *list, char *event_mod) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 809359e8544e..a331b9f0da2b 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -209,10 +209,6 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state, struct list_head *list, u64 addr, char *type, u64 len, struct parse_events_terms *head_config); -int parse_events_add_pmu(struct parse_events_state *parse_state, - struct list_head *list, const char *name, - const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats, void *loc); struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, const char *name, const char *metric_id, @@ -223,6 +219,12 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc); +int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state, + const char *event_or_pmu, + const struct parse_events_terms *const_parsed_terms, + struct list_head **listp, + void *loc_); + void parse_events__set_leader(char *name, struct list_head *list); void parse_events_update_lists(struct list_head *list_event, struct list_head *list_all); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index d70f5d84af92..14175eee9489 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -273,78 +273,17 @@ event_def: event_pmu | event_pmu: PE_NAME opt_pmu_config { - struct parse_events_state *parse_state = _parse_state; /* List of created evsels. */ struct list_head *list = NULL; - char *pattern = NULL; - -#define CLEANUP \ - do { \ - parse_events_terms__delete($2); \ - free(list); \ - free($1); \ - free(pattern); \ - } while(0) + int err = parse_events_multi_pmu_add_or_add_pmu(_parse_state, $1, $2, &list, &@1); - list = alloc_list(); - if (!list) { - CLEANUP; + parse_events_terms__delete($2); + free($1); + if (err == -ENOMEM) YYNOMEM; - } - /* Attempt to add to list assuming $1 is a PMU name. */ - if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false, &@1)) { - struct perf_pmu *pmu = NULL; - int ok = 0; - - /* Failure to add, try wildcard expansion of $1 as a PMU name. */ - if (asprintf(&pattern, "%s*", $1) < 0) { - CLEANUP; - YYNOMEM; - } - - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - const char *name = pmu->name; - - if (parse_events__filter_pmu(parse_state, pmu)) - continue; - - if (!strncmp(name, "uncore_", 7) && - strncmp($1, "uncore_", 7)) - name += 7; - if (!perf_pmu__match(pattern, name, $1) || - !perf_pmu__match(pattern, pmu->alias_name, $1)) { - bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); - - if (!parse_events_add_pmu(parse_state, list, pmu->name, $2, - auto_merge_stats, &@1)) { - ok++; - parse_state->wild_card_pmus = true; - } - } - } - - if (!ok) { - /* Failure to add, assume $1 is an event name. */ - zfree(&list); - ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list, &@1); - } - if (!ok) { - struct parse_events_error *error = parse_state->error; - char *help; - - if (asprintf(&help, "Unable to find PMU or event on a PMU of '%s'", $1) < 0) - help = NULL; - parse_events_error__handle(error, @1.first_column, - strdup("Bad event or PMU"), - help); - CLEANUP; - YYABORT; - } - } + if (err) + YYABORT; $$ = list; - list = NULL; - CLEANUP; -#undef CLEANUP } | PE_NAME sep_dc From patchwork Mon Apr 15 06:36:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629489 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 6B6D9C4345F for ; Mon, 15 Apr 2024 06:36:47 +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=G1NWcWhbpHvDMWNWHD649xzZT+hHzDD+jpX2iCjh8B8=; b=FsxscZg63kbpT4 afZKcc4FQWrdiqe4Nd6w+S0BJcws/+psy+eDMr0jtz9AMWuESNKe3TSmVHdR/UHbbz1LuXyh9ZGTj 9hjv/eqF5s1WBeR7wQmqdQXP90pz88QEWq65OH0KOprcGcbw2ESiaAaIF/bRQmEEp+oO+u0IoKEdI c1IJMF2ii0YpVcL1+/sCTwRQA5AkmG8PYI9ctrCC4tRx/rqgKqXjOxZrN+EUUWGYMEJKGEKQq6fTa 1bJYyjaMfZb8f3B7p5dyn5dgWxlvltS8oJ4IEUs7NpCqBLBJNFa3S/5JFHgcjjWINHuHjRXFPKW6+ 9Y85M7OfFBz+Aw2nDysA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxI-00000007Ayc-2qWe; Mon, 15 Apr 2024 06:36:40 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxE-00000007AwP-3ioG for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:38 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5d8dd488e09so3129697a12.2 for ; Sun, 14 Apr 2024 23:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713162995; x=1713767795; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cBIPczyGmK1H1pt2G8mgcHP61YsaqzYuWfuwlwliFdk=; b=LMS/94jkE00QuEXq/Xkc59BZ5l5ew0/cDJMMSwcO8MwHDqDoH9SpQ63YhDqASeZdqu kSRRQYdWNjR07yH+bD6rhT/Vhvn+L06sRVd6//LZu5LxwcsJTzpyT2xgFppTeK5yc4AC 3z0p31Qe01Wl3kTbcQIQgdZ4GGYJ2Qdt1j4E91hnuN+8UXe6JjBCevLZFGhcbd+yHvBN /i1hvyhTYLGLF/7hi+KUZQIYlFusamQ9TegPHUsqTMYbHqspV6WYAxVRGJ0h/AwoYwBk Xnt6n4qoongYAPKXY1i/NKmJP6FYjf1wVu/hUEYbJHxbS11diP0OqQXMS53OF/Jn6EF0 c1eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713162995; x=1713767795; 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=cBIPczyGmK1H1pt2G8mgcHP61YsaqzYuWfuwlwliFdk=; b=f4q2QlSFWXloIvsrjVU27Nv1gmPAm4N11ZVDs45LHT1Z36hjzs3e7MhNGWYkqe/Bfr ddjzHoJiQPHyT60mO6JPGCRBUuxE8L8LW9FbpDNPIliJR6YRj3OR5JUvkZYX0Lc8kmKX HJM1/3gGZT42n1SQqvIk43A5ZKX6+xkhZgQZcFDwCNzZXAh0L2h0hFdWH5pillvtCKs6 tSTfWVtyLq40hrtnI/qJLw/jdwkj1EvjNnou3rru2gGkZe3fnFm2cfPHdqoe634OqXH9 dP05NPDw0+GpMBl9yTlk1GFQuumZbl7CJse18jVFsuqwl2AiWCQY1deoAXiK/Tcm6tUb H/sA== X-Forwarded-Encrypted: i=1; AJvYcCVQg3p1OJlZ0PoAY85DHqVIjjnoTPTA4j3sBb38+OemiIpE2vE1Afaupn7HCBgp2LsJ2ztc8z1z942TZZXk9/jtxdOc3EUTGCrRUBTwg8tV X-Gm-Message-State: AOJu0YwZ5O4YYuOnkRTI1a1QP6EhiYflUsWb0WiJy2kMwQKIJzGpAiE6 80CtonMCb3R77JP+Qe4ll3U35ZI7tSVEQ+xkUWtJ+o3nbv9Z4BHZhWyMKUggoBqBPPYkxcec+d/ pKvyiAw== X-Google-Smtp-Source: AGHT+IHksE11INoODcmfSA8PUTVNGXIlCH66XxnH2VvOntZKJzWoEyBWTiUDIjjhs1caK8c5pV3a1jp10fJX X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a63:f919:0:b0:5db:edca:d171 with SMTP id h25-20020a63f919000000b005dbedcad171mr25389pgi.6.1713162994834; Sun, 14 Apr 2024 23:36:34 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:19 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-3-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 2/9] perf parse-events: Directly pass PMU to parse_events_add_pmu From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233636_971919_0807B72D X-CRM114-Status: GOOD ( 15.99 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Avoid passing the name of a PMU then finding it again, just directly pass the PMU. parse_events_multi_pmu_add_or_add_pmu is the only version that needs to find a PMU, so move the find there. Remove the error message as parse_events_multi_pmu_add_or_add_pmu will given an error at the end when a name isn't either a PMU name or event name. Without the error message being created the location in the input parameter (loc) can be removed. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 46 +++++++++++++--------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b16c75bf5580..bc4a5e3c6c21 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1386,32 +1386,18 @@ static bool config_term_percore(struct list_head *config_terms) } static int parse_events_add_pmu(struct parse_events_state *parse_state, - struct list_head *list, const char *name, - const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats, void *loc_) + struct list_head *list, struct perf_pmu *pmu, + const struct parse_events_terms *const_parsed_terms, + bool auto_merge_stats) { struct perf_event_attr attr; struct perf_pmu_info info; - struct perf_pmu *pmu; struct evsel *evsel; struct parse_events_error *err = parse_state->error; - YYLTYPE *loc = loc_; LIST_HEAD(config_terms); struct parse_events_terms parsed_terms; bool alias_rewrote_terms = false; - pmu = parse_state->fake_pmu ?: perf_pmus__find(name); - - if (!pmu) { - char *err_str; - - if (asprintf(&err_str, - "Cannot find PMU `%s'. Missing kernel support?", - name) >= 0) - parse_events_error__handle(err, loc->first_column, err_str, NULL); - return -EINVAL; - } - parse_events_terms__init(&parsed_terms); if (const_parsed_terms) { int ret = parse_events_terms__copy(const_parsed_terms, &parsed_terms); @@ -1425,9 +1411,9 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, strbuf_init(&sb, /*hint=*/ 0); if (pmu->selectable && list_empty(&parsed_terms.terms)) { - strbuf_addf(&sb, "%s//", name); + strbuf_addf(&sb, "%s//", pmu->name); } else { - strbuf_addf(&sb, "%s/", name); + strbuf_addf(&sb, "%s/", pmu->name); parse_events_terms__to_strbuf(&parsed_terms, &sb); strbuf_addch(&sb, '/'); } @@ -1469,7 +1455,7 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, strbuf_init(&sb, /*hint=*/ 0); parse_events_terms__to_strbuf(&parsed_terms, &sb); - fprintf(stderr, "..after resolving event: %s/%s/\n", name, sb.buf); + fprintf(stderr, "..after resolving event: %s/%s/\n", pmu->name, sb.buf); strbuf_release(&sb); } @@ -1583,8 +1569,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, continue; auto_merge_stats = perf_pmu__auto_merge_stats(pmu); - if (!parse_events_add_pmu(parse_state, list, pmu->name, - &parsed_terms, auto_merge_stats, loc)) { + if (!parse_events_add_pmu(parse_state, list, pmu, + &parsed_terms, auto_merge_stats)) { struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); @@ -1596,8 +1582,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, } if (parse_state->fake_pmu) { - if (!parse_events_add_pmu(parse_state, list, event_name, &parsed_terms, - /*auto_merge_stats=*/true, loc)) { + if (!parse_events_add_pmu(parse_state, list, parse_state->fake_pmu, &parsed_terms, + /*auto_merge_stats=*/true)) { struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); @@ -1626,7 +1612,7 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state { char *pattern = NULL; YYLTYPE *loc = loc_; - struct perf_pmu *pmu = NULL; + struct perf_pmu *pmu; int ok = 0; char *help; @@ -1637,10 +1623,12 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state INIT_LIST_HEAD(*listp); /* Attempt to add to list assuming event_or_pmu is a PMU name. */ - if (!parse_events_add_pmu(parse_state, *listp, event_or_pmu, const_parsed_terms, - /*auto_merge_stats=*/false, loc)) + pmu = parse_state->fake_pmu ?: perf_pmus__find(event_or_pmu); + if (pmu && !parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, + /*auto_merge_stats=*/false)) return 0; + pmu = NULL; /* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */ if (asprintf(&pattern, "%s*", event_or_pmu) < 0) { zfree(listp); @@ -1660,8 +1648,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state !perf_pmu__match(pattern, pmu->alias_name, event_or_pmu)) { bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); - if (!parse_events_add_pmu(parse_state, *listp, pmu->name, const_parsed_terms, - auto_merge_stats, loc)) { + if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, + auto_merge_stats)) { ok++; parse_state->wild_card_pmus = true; } From patchwork Mon Apr 15 06:36:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629490 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 5317BC04FF9 for ; Mon, 15 Apr 2024 06:36:49 +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=W9/Xp/nEPtB6KQG2asW6J+tGpEjfRxApEyATNrELhqk=; b=m2rpAt1h0HW4SU jAXM4y0i1smsVa9vOtdlwAWdU7XMYrxdpPhhOkTcqpLyCCFN6N7aipDtF7GlKvG9Mto9h8Dg5CFem S02PhkCHeEbHf5rmWfqkWLKGVkiC7MqZP3bS+uE9g/GlauWqfX/YvTpwtyyr+9dz1Vkim0lUszsy2 2uySjGKhXeHPLSmhdLidXXgwqwTIzRXVvXLjQ27kz2yo5vNFC8rACpL1eV0KjN63heMm1UJUt9/4o 8lOmA6M1P1KenZ1+DIjPdVXgCnyyCC7GzVm0y6WH9SOBKXqHadark9eMeUpqPV4JN5Q0W58TdvKEn /O4fBxkYzL9oVJ2UQi7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxJ-00000007AzM-3yaU; Mon, 15 Apr 2024 06:36:45 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxH-00000007Axk-13Cj for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:40 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dcc05887ee9so3511758276.1 for ; Sun, 14 Apr 2024 23:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713162997; x=1713767797; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=p+gciuZSLFdHIk1i0SV08AyznRpAEm+5KjCzM2jFJbc=; b=o2JHHHgup4hS74w9wUKF0OtCsbxhbQJ5pocFjD2/1JS2j4EJsUHR0cooVj/PIKIEWS UZn0BNx8mCNi/cqYKG+V29f/AsnMdrLEw08FIbClgnQmAG0rvaktCtpS0KFGqUoM5hAT 6X6tVPbPjx3VJsip6VASpi4apfifw8ZEmwQ8kQLCJiVN9CO/CFQXDVoHjxfl4dQZW51o PlLnDyd28Zb8RptNO8E1fPTodpcfMi3XxQ2QUrtcrtAzIG7hjUZ3r68yMCmySYOnOouH F7L6mvxHkbsZcnI5TtFL+pnftri4QmDEojbW2dV7P3lNHoRc+3rOloDB4IZ06KwwzExi uYtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713162997; x=1713767797; 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=p+gciuZSLFdHIk1i0SV08AyznRpAEm+5KjCzM2jFJbc=; b=p3CLZ+gF/maEoqLLM76cGLVE2LaPwq/8ceHqVrcVQ75zR1yvEiHDRH3H/a5vKICAnr zSKdKJWOzESp+88sN7cAmkCl8ursanK2nLUVdYw24a0Lwdtx5o5ctYhYD0TGxaTe/zCA rZlSBP72XS7SlcZg8f8uxya02hBXp5r1hS2i6y99A94+FoMj0DGYsyJSxME3qj4yM5gs rO2GnWyE4skO1yTiujT3bVzL+Q9CV8hOhOS1HjbS/2CyeslE+yvIZF3M2Hm3OX1J80AV 7iFmLfWR/yb3mZhL87jMa9loDbEb8xLuQJFQhh0kaJHw5LKhNROzM1NCJCnK+Gdbjan7 dAgw== X-Forwarded-Encrypted: i=1; AJvYcCUv4bG4YP8l4Q5z1nEsJLUg0Yt2vCewMMsSp5lPLkgWyUBjBdAxKvUHBs/BHTpvCv2ewvU0AGNIbrg7mo3Ld28B3oqCJrhDWDtogpxSeKp/ X-Gm-Message-State: AOJu0Yw6BN4g3QB9dSMZmp5Dhh+I97s0g6cgqGHDVMboytqcdGiRgg/v iifQ/rt8ojRdOjpfX2Xe5NXgzIxMKsJwUxnOeodNcYRnUZJedyV4pRpro5S0ht6bPwiTK7DPgSx ySzEnvA== X-Google-Smtp-Source: AGHT+IFL+Tvkj6R3nO3XnJ0ewuekhH4PPx8UF3ahuI3cz/n03WZ3OYIbXOAvlx9w1Oc053fj9XHZnbkS+UNY X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a25:b21b:0:b0:dda:c566:dadd with SMTP id i27-20020a25b21b000000b00ddac566daddmr529521ybj.4.1713162997423; Sun, 14 Apr 2024 23:36:37 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:20 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-4-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 3/9] perf parse-events: Avoid copying an empty list From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233639_314489_2FF303A3 X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In parse_events_add_pmu, delay copying the list of terms until it is known the list contains terms. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index bc4a5e3c6c21..7e23168deeb9 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1398,29 +1398,20 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, struct parse_events_terms parsed_terms; bool alias_rewrote_terms = false; - parse_events_terms__init(&parsed_terms); - if (const_parsed_terms) { - int ret = parse_events_terms__copy(const_parsed_terms, &parsed_terms); - - if (ret) - return ret; - } - if (verbose > 1) { struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); - if (pmu->selectable && list_empty(&parsed_terms.terms)) { + if (pmu->selectable && const_parsed_terms && list_empty(&const_parsed_terms->terms)) { strbuf_addf(&sb, "%s//", pmu->name); } else { strbuf_addf(&sb, "%s/", pmu->name); - parse_events_terms__to_strbuf(&parsed_terms, &sb); + parse_events_terms__to_strbuf(const_parsed_terms, &sb); strbuf_addch(&sb, '/'); } fprintf(stderr, "Attempt to add: %s\n", sb.buf); strbuf_release(&sb); } - fix_raw(&parsed_terms, pmu); memset(&attr, 0, sizeof(attr)); if (pmu->perf_event_attr_init_default) @@ -1428,7 +1419,7 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, attr.type = pmu->type; - if (list_empty(&parsed_terms.terms)) { + if (!const_parsed_terms || list_empty(&const_parsed_terms->terms)) { evsel = __add_event(list, &parse_state->idx, &attr, /*init_attr=*/true, /*name=*/NULL, /*metric_id=*/NULL, pmu, @@ -1437,6 +1428,15 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, return evsel ? 0 : -ENOMEM; } + parse_events_terms__init(&parsed_terms); + if (const_parsed_terms) { + int ret = parse_events_terms__copy(const_parsed_terms, &parsed_terms); + + if (ret) + return ret; + } + fix_raw(&parsed_terms, pmu); + /* Configure attr/terms with a known PMU, this will set hardcoded terms. */ if (config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu)) { parse_events_terms__exit(&parsed_terms); From patchwork Mon Apr 15 06:36:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629491 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 BCB38C4345F for ; Mon, 15 Apr 2024 06:36:54 +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=w3i9ZzfrJ3O43zXjy1sYxfnKNsTugbyGVl1E+4XnhYw=; b=SRRGJeafqQvZ2a E6+o6vk6x+HcG7Vle/FtTlD4audl+ZzZNl+7Eb/bje6LRcajkv34m9wigdtAZJGvQEySSFzVaGmNp subSMPVJUdXvf26f9/ufbnzMKCpCfnQygq6+mWzAn16Oh3mfk1JDjL/SYy7OmAhEMvtZVuETEDYYf pzovkCCPLj+QPFZyFLDzIJSMEYyyM9XXx1WjAQVKvfuOVbUGN+bRgqKXwtfJ1tAdlQ4qQGCv6wzEd QWO1OWuJMjyL1hLZWq6J85mlkkrxSm/1HolzkeuwsChKlcCYBQB5pE3O7pQ5ghx6t6hpHB6962iY6 5hne8GVQjONDGBftJF0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxR-00000007B3G-0Ec8; Mon, 15 Apr 2024 06:36:49 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxN-00000007AyX-0OoK for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:47 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-2a4b60f8806so3202224a91.1 for ; Sun, 14 Apr 2024 23:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163000; x=1713767800; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Vbu7aFj7CDfYjc9NaQu8KLUrRIg296ZgDVYr3Mka6h8=; b=KTm8Izn8dd8YxNd1U0YEhiyuBqqnBoRpfFSXz9YzEZVK/JCEPY/rnd1QzIJvkNH1Ye vh3EkwCS9rXCxIZxUeCihX6NSLoC+TscsqkBf4AcRBUE9L34owQu9gvrsNTrzbLoaiyO x+kr/TzX7vg7vURPyBAaoUpTi0RqfoSVlsDBhXwtE/agClNXqt7kF7baf1Pzk3wy2N+g 5HYBtKp8d9eCOnYAOX+0BmCm+NhBJHwZY0zI+POkfDtSC141g1HA9mpr7MxI+EeE95S3 yXUpF0He9N8aNWnJARrsZb9SUEmTC2lHl9R5ktnl7D6hPAAHtBKzex1HGfDURiFfGlzZ cZsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163000; x=1713767800; 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=Vbu7aFj7CDfYjc9NaQu8KLUrRIg296ZgDVYr3Mka6h8=; b=Ps15jZ4Ea5xdoVk0mg4mucXxtQkCC4FS9S3SkIM4xUk+pzsz+XJxhgrLpn+fJ7lZ9f vAfSIW3vU0rGURjakSQUfSW994BAud8+7aLya3x3oYvp0QGFGnpE+3iejs882Vlk3ACI sxM6uxbezwQpx/8xsbUkO5hTHKohOZPCd9vjKtqnmiVTu9RPdazP6ldJ5LZG7KPOCeP+ GeTObEgxeN0bMqbscIcyf1OZu7lSEV49lmbgHWJhAK9pCTd7g/ipEMoUku98zHy943UB 2cBkQRZ8iBo88r8rNIrd+gPJ9/BEXFZBhKkpfUTI+ZptTgwtrhkg941CWVgTii58OKU3 L9lQ== X-Forwarded-Encrypted: i=1; AJvYcCViORxRE/IF7tPgSHnmVUTw2GT24Gcefhwm0++oYQYZnL0KUWrrz7SgUFBQKwVzBBhsLPo/vMFn9UTrIdFGyGkzRZ6fZ6GegrzG6WheXxAl X-Gm-Message-State: AOJu0YzjD/byAtgma4VGur5+5db/d5dNd3bzN4SeEX/rMFV4pjA40aNB 8fDn3+3/PocpcjWSvK4NRD0QrfOrpj6/OlT14ZkxGymwdSPLdH4pVUbwCSvUM4Q8v8ExFamxWmV kqnZkcg== X-Google-Smtp-Source: AGHT+IF81B9h9k2M6zDz/afTJ7Wc9UGW5/Q0UBXG/tDqklKUIScYFFrhSUp9FPvMgq45GrANH22AdKOozLUh X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a17:90a:f287:b0:29b:f937:cc00 with SMTP id fs7-20020a17090af28700b0029bf937cc00mr27827pjb.7.1713162999848; Sun, 14 Apr 2024 23:36:39 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:21 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-5-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 4/9] perf pmu: Refactor perf_pmu__match From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233645_996914_591969CB X-CRM114-Status: GOOD ( 13.29 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Move all implementation to pmu code. Don't allocate a fnmatch wildcard pattern, matching ignoring the suffix already handles this, and only use fnmatch if the given PMU name has a '*' in it. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 19 ++----------------- tools/perf/util/pmu.c | 27 +++++++++++++++++++-------- tools/perf/util/pmu.h | 2 +- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 7e23168deeb9..f4de374dab59 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1610,7 +1610,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state struct list_head **listp, void *loc_) { - char *pattern = NULL; YYLTYPE *loc = loc_; struct perf_pmu *pmu; int ok = 0; @@ -1630,22 +1629,9 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state pmu = NULL; /* Failed to add, try wildcard expansion of event_or_pmu as a PMU name. */ - if (asprintf(&pattern, "%s*", event_or_pmu) < 0) { - zfree(listp); - return -ENOMEM; - } - while ((pmu = perf_pmus__scan(pmu)) != NULL) { - const char *name = pmu->name; - - if (parse_events__filter_pmu(parse_state, pmu)) - continue; - - if (!strncmp(name, "uncore_", 7) && - strncmp(event_or_pmu, "uncore_", 7)) - name += 7; - if (!perf_pmu__match(pattern, name, event_or_pmu) || - !perf_pmu__match(pattern, pmu->alias_name, event_or_pmu)) { + if (!parse_events__filter_pmu(parse_state, pmu) && + perf_pmu__match(pmu, event_or_pmu)) { bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, @@ -1655,7 +1641,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state } } } - zfree(&pattern); if (ok) return 0; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ce72c99e4f61..d7521d84fe4a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2073,18 +2073,29 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, name ?: "N/A", buf, config_name, config); } -int perf_pmu__match(const char *pattern, const char *name, const char *tok) +bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok) { - if (!name) - return -1; + const char *name = pmu->name; + bool need_fnmatch = strchr(tok, '*') != NULL; - if (fnmatch(pattern, name, 0)) - return -1; + if (!strncmp(tok, "uncore_", 7)) + tok += 7; + if (!strncmp(name, "uncore_", 7)) + name += 7; - if (tok && !perf_pmu__match_ignoring_suffix(name, tok)) - return -1; + if (perf_pmu__match_ignoring_suffix(name, tok) || + (need_fnmatch && !fnmatch(tok, name, 0))) + return true; - return 0; + name = pmu->alias_name; + if (!name) + return false; + + if (!strncmp(name, "uncore_", 7)) + name += 7; + + return perf_pmu__match_ignoring_suffix(name, tok) || + (need_fnmatch && !fnmatch(tok, name, 0)); } double __weak perf_pmu__cpu_slots_per_cycle(void) diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 152700f78455..93d03bd3ecbe 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -263,7 +263,7 @@ void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, const char *config_name); void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu); -int perf_pmu__match(const char *pattern, const char *name, const char *tok); +bool perf_pmu__match(const struct perf_pmu *pmu, const char *tok); double perf_pmu__cpu_slots_per_cycle(void); int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size); From patchwork Mon Apr 15 06:36:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629494 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 912A9C04FF9 for ; Mon, 15 Apr 2024 06:37: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=ttsxRKmX0i4Nwr1v65N+HaXYOKgvPxYxmrbLaGP5L54=; b=OUrr6c66WnsJfa QuPnaigN1ecl1uVnD/ALrG37rvMI8AfBMebVniiLlIdtQLuydfOBqTxhTiip42v3MKhq8WqXZ4N0i cVvQ2oZuUpv98niddg2pzHsZB7ZQqERXI23sXQHUwFlb6jBnpWSHfcmTrYwJTW3lmmmFGy3UF0lsQ J6GGURK0sqlvbHeWQE2b2uHRXVRlrp1PFBbYSC4uISbzl+CN5l3OaaFqurZgDJPZtUSU5iCY2vAQi LqJmQzpf1U8qQMjkz12zKLCzDSFdXEDSs3Eu9a1+EvUVsP8HDgPctN2boKL2fC91x6TUNP73CAkXp 9NVHyHyTYfoSehzoQ19g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxZ-00000007B9e-1lBM; Mon, 15 Apr 2024 06:36:57 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxO-00000007AzP-2OpT for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:49 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc64f63d768so5174063276.2 for ; Sun, 14 Apr 2024 23:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163002; x=1713767802; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=UJgB8sDKrPml3/XRc3D6gD41xE7ASJL2MP2+Oe/niCE=; b=oKuLxA4nCkF3s98kZEOABJQUEgS87N59U3lqUW1szyaEa3WOybNOxVn3ZQvYrOUE8M k8cpTbTFDoDWXEy1wSjgXRMYqlBdesAxI+iPppqIjsJDVcjiIe20MvxrnK/MiJdacpmN y3WJuVX0VDYi8BblPc0FdOY6Q+YuKiWLYaGBKkcWrZ5SQILufSSElSa4qE4LhMFIJVbZ BD8qW3uFPoCKbm5Dny35Ym9E6uo8c5pRXmaOtUNlLllwzyOaZ2btJ02E/UN4ud/QQ8wn 0/TV8XGlfQGYbp1aCVkO1dgDVzDOUxe275/oHoS9rEpWpWdpt2+17RX5/vRtJ2kUr0c0 bYUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163002; x=1713767802; 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=UJgB8sDKrPml3/XRc3D6gD41xE7ASJL2MP2+Oe/niCE=; b=KfNplt/rLZtZH2+i86dPv/aLoZM/mawe0Gk8/fyA1F8qbWH13sXbgRAu8Axtkzwv7U SuhKSVmIxNdPCBBdjfUK7R7wTo4PitecK/fFq8mqlcOccSirro/sPEqi8cgjgnkw/w1e QMpdmTIuw+2SDjmHTp/v/oaEF2S2FsYykvrwEuoQUUX1Dl26rnllXeEA8SDbroKUzlsC +uXyvyC9ycvIbcmxG8BPAFfw3t5S9x4L47EGO4DWPQiBjYzPvkrKy1DB7+EttDdQgyQZ LKh22YuLfOk5JP8t/0arXrjEn6pNfjwoo6TWIpdddC6q8uU6kMKH1/NxtMTmhN8mXx4F w+6w== X-Forwarded-Encrypted: i=1; AJvYcCWEeeoIMldzOrYj3j/4y+/mn1tCKDVauWYn4/9juA13xnh/Ow737cvdDshet9bbdYybyIIq6GQkP/SzpqWSZmjtN1cYW1VgPXYzHNUojYUp X-Gm-Message-State: AOJu0YzYq192wRhve6n07av34LBFxQqKU/CgjvABVFfZH6xueAmMcw7P 88a/hVZkzpjKbJvOd1t+Bfqu+ayQV7f0+FlC+s8h47DS2ZmGc1p95tWT1xE4INQSQAP/wd2VbKL ZdpsDhw== X-Google-Smtp-Source: AGHT+IEiiZuVjgyhNgTTLyZ6Sh7UYfcc0UNFuJ2n/bK+2GCusGz73ratukmMFcwYpUzQY+G7b8Ltwey08z2j X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a05:6902:1549:b0:dc6:dfd9:d431 with SMTP id r9-20020a056902154900b00dc6dfd9d431mr2983520ybu.1.1713163002294; Sun, 14 Apr 2024 23:36:42 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:22 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-6-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 5/9] perf tests parse-events: Use branches rather than cache-references From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233646_635606_6C90C3C5 X-CRM114-Status: GOOD ( 13.10 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Switch from cache-references to branches in test as Intel has a sysfs event for cache-references and changing the priority for sysfs over legacy causes the test to fail. Signed-off-by: Ian Rogers --- tools/perf/tests/parse-events.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 0b70451451b3..993e482f094c 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -942,8 +942,8 @@ static int test__group2(struct evlist *evlist) continue; } if (evsel->core.attr.type == PERF_TYPE_HARDWARE && - test_config(evsel, PERF_COUNT_HW_CACHE_REFERENCES)) { - /* cache-references + :u modifier */ + test_config(evsel, PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) { + /* branches + :u modifier */ TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); @@ -2032,7 +2032,7 @@ static const struct evlist_test test__events[] = { /* 8 */ }, { - .name = "{faults:k,cache-references}:u,cycles:k", + .name = "{faults:k,branches}:u,cycles:k", .check = test__group2, /* 9 */ }, From patchwork Mon Apr 15 06:36:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629492 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 8F8EAC4345F for ; Mon, 15 Apr 2024 06:36:59 +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=nqpkBQh7P6OAMV8M2M/Rhs7cQXrLcU3kHe5mls4pyMA=; b=ReNQWEwzv4l/4O nTK8vbLW0SOkZigYjgwgfPLE8UsBnhsOumI6dVIt7fDe7/ETdIooJ21DjGNW5CzjdTN5WnvyeR7gP ZDEEAK7bW4dgA3J6TJLhkf+QG/UtvyrntQHH4lMnpOf/igBFsAnPmtGMkPln9zUE0CmIMj1UAqB+8 cA0WWQrkME5Egcx2ibw2Njzvf3d1TH5PoeAl6njqAPkvBWq+M+1+9unK5grvIX2EKTXhKPXQuuf1n t57fTFWKuGOiwb5ldVhbbrdKSWiY5K6wadOTEBadsLPJxpx7clawfknfw2+4ImBSfVroS963Gg497 4IHzDrLJ9KJM/kt9kE2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxX-00000007B8b-2EF1; Mon, 15 Apr 2024 06:36:55 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxO-00000007Azl-0n0W for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:48 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc6b269686aso4160336276.1 for ; Sun, 14 Apr 2024 23:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163005; x=1713767805; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=hx/Ta0rDGqfG4yTzEhISDdPx4oXkJbCeHRtXa2sGNYw=; b=M6DbR5UxZlnlT7NnQr6G36QdHCTbH6etSjR3v3guBxvjup7Kg6JwcepHU07i5Swh8Y 5G0UEb69trnjtrsodm/+WthPUpt6uOPsLWTIGcbJEANbC3OTvbgnJ0v3/R9LhBjURnSB rVnJEDWAok8QMin0qYLcJkhkxHFayPP6VwbwE4o1zNLoG0qfoKa5Vv8d2CyuX7mds1Rk 2f3RWE2Gx07X1F9+f20Wjn4WGvRAW5b/7xWODh+fI4oH4HuVczuqeYhh3W5ci+pSCpt/ cN3/mmAFj5MsiZfmUM1oChaKuGt2sbPAwF1+cuxc39SMTu1IEd0ehRfAs8Gg3yukjC4T kdZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163005; x=1713767805; 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=hx/Ta0rDGqfG4yTzEhISDdPx4oXkJbCeHRtXa2sGNYw=; b=HvXha21QGAApHkQn8Nkk7m0MgQWnm+OVEPG+aC9QIhU7tNIN6V1Af8/kZWRxVOadzO 9h2EkxXV4WwedNKNHZWgThyQ0nzUd9KRjSJAj4xxvOzY3G25+6BoGzWYFNNz0RVTXH1+ 4KlA6nIInAAJHijR8ZcjXJ49vPA6TC6zwCX7R6ygr1R5oyhgWr4OjtIYF8eEq/DElTKo /UTRKVk2UgeSBb6MwOTgFyw1kLeUf8vNzc9l6rt/U+maOYCIIKEGn+yR90QJ3jR8ZnDY 8SjKoHI9w59U9s29NoknohHxZrqNrbCpy9uNYA8+ZHQ8B3OuWiiLtYCbLP+TXtomoPhn kWJg== X-Forwarded-Encrypted: i=1; AJvYcCXhjNkVrL9bnwEinAsTa7Z0QzZTEkmLonZJqS0R/SYr7iC5vTm3VtVkbZBeXXI2jVi6GJJrhgZFUULGBxpSs3V6+f0E9znR37UOm3CTgqN5 X-Gm-Message-State: AOJu0YzSfiVbyoNDRR6xzrPNDInrmV8ThHUYXTRwadTy+DNEax7crVH7 Pf2vtL6XOoXrUmJtgpQd18z3cX73bC9C0vOH8Rp4DLG4TymUzX2biZxAyG1IBd9x/yXvYfCxGW5 DHQeFaQ== X-Google-Smtp-Source: AGHT+IGKjbFopUbPAz4023seU2rQZ1FOntIZ8rt7x+OCB1yu2RcNgzS+jPNzrST2MfTWwwugdpm9slVKlTFo X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a05:6902:120b:b0:de0:ecc6:87b with SMTP id s11-20020a056902120b00b00de0ecc6087bmr742661ybu.1.1713163004978; Sun, 14 Apr 2024 23:36:44 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:23 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-7-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 6/9] perf parse-events: Legacy cache names on all PMUs and lower priority From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233646_324074_6EBC7A36 X-CRM114-Status: GOOD ( 18.49 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Prior behavior is to not look for legacy cache names in sysfs/json and to create events on all core PMUs. New behavior is to look for sysfs/json events first on all PMUs, for core PMUs add a legacy event if the sysfs/json event isn't present. This is done so that there is consistency with how event names in terms are handled and their prioritization of sysfs/json over legacy. It may make sense to use a legacy cache event name as an event name on a non-core PMU so we should allow it. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 38 +++++++++++++++++++++++++++------- tools/perf/util/parse-events.h | 2 +- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index f4de374dab59..f711ad9b18f0 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -442,17 +442,21 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, return strcmp(parse_state->pmu_filter, pmu->name) != 0; } +static int parse_events_add_pmu(struct parse_events_state *parse_state, + struct list_head *list, struct perf_pmu *pmu, + const struct parse_events_terms *const_parsed_terms, + bool auto_merge_stats); + int parse_events_add_cache(struct list_head *list, int *idx, const char *name, struct parse_events_state *parse_state, - struct parse_events_terms *head_config) + struct parse_events_terms *parsed_terms) { struct perf_pmu *pmu = NULL; bool found_supported = false; - const char *config_name = get_config_name(head_config); - const char *metric_id = get_config_metric_id(head_config); + const char *config_name = get_config_name(parsed_terms); + const char *metric_id = get_config_metric_id(parsed_terms); - /* Legacy cache events are only supported by core PMUs. */ - while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + while ((pmu = perf_pmus__scan(pmu)) != NULL) { LIST_HEAD(config_terms); struct perf_event_attr attr; int ret; @@ -460,6 +464,24 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name, if (parse_events__filter_pmu(parse_state, pmu)) continue; + if (perf_pmu__have_event(pmu, name)) { + /* + * The PMU has the event so add as not a legacy cache + * event. + */ + ret = parse_events_add_pmu(parse_state, list, pmu, + parsed_terms, + perf_pmu__auto_merge_stats(pmu)); + if (ret) + return ret; + continue; + } + + if (!pmu->is_core) { + /* Legacy cache events are only supported by core PMUs. */ + continue; + } + memset(&attr, 0, sizeof(attr)); attr.type = PERF_TYPE_HW_CACHE; @@ -469,11 +491,11 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name, found_supported = true; - if (head_config) { - if (config_attr(&attr, head_config, parse_state->error, config_term_common)) + if (parsed_terms) { + if (config_attr(&attr, parsed_terms, parse_state->error, config_term_common)) return -EINVAL; - if (get_config_terms(head_config, &config_terms)) + if (get_config_terms(parsed_terms, &config_terms)) return -ENOMEM; } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index a331b9f0da2b..db47913e54bc 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -203,7 +203,7 @@ int parse_events_add_tool(struct parse_events_state *parse_state, int tool_event); int parse_events_add_cache(struct list_head *list, int *idx, const char *name, struct parse_events_state *parse_state, - struct parse_events_terms *head_config); + struct parse_events_terms *parsed_terms); int parse_events__decode_legacy_cache(const char *name, int pmu_type, __u64 *config); int parse_events_add_breakpoint(struct parse_events_state *parse_state, struct list_head *list, From patchwork Mon Apr 15 06:36:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629493 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 5203CC4345F for ; Mon, 15 Apr 2024 06:37: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=6IxuwOJ0BtfMSvmyRcJhZxv2c1zWVWom9waZmIFHibg=; b=MACncIr14+7IL0 GtL6WobXqWLda7JkrH4ukhyr6xD7xNTPEXI51mnL50K7fxRJmpyTHXvupbOPHIbeo6MGPTp5g+8Fn +h9fqhR5g2/98dOSkRRfXnnvhw5yROBAWejLYoyLO7AELdfThA+RTWEbuw08bmdatOECelWM+5j8B eQyI59FoOTCXXG13rLs/Or/axTBQuVO71q4pvK2D08lZlW0HpbVCZDoKQyAtxRYoOb98a9Boadd1w mUUPcITuu1Gill7cXUyeCOnIHYbyiyyxUdn//bpqO/ajfzthMZaW65lRW+7dq3bjrO/qA/wkEL2GX 6ZMp+YCv1l0HH8+wsHPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxb-00000007BAw-06IE; Mon, 15 Apr 2024 06:36:59 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxR-00000007B1j-1iMo for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:52 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6150e36ca0dso42463777b3.1 for ; Sun, 14 Apr 2024 23:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163007; x=1713767807; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=t6u9K3gcjLrMHLCFAhYLG4bnVQmGcLUFFxbpFKDU6RA=; b=DsRTP3OX3kH3LoSMK2VkA52/jvVgTgPqqcfX+uGo7ATFjtoj60itQUXW6ijRz5f5LR V5939r8rVNV7NhGY4o14RxevR2PgfWqncQ3qk6/PxODx6Q3XbaHdRXmFyC3SFwHues6A 6etH5CuvbeMpMqSCy7DQwHDwd8OmHclJ1OBEwAtWHTVqFfxhuybOugRtPyQqlvSXBop1 Uc59U8lc2eOorrMSOvHXPD95XxPa9COyLrtIgJu/gp2pfBMT0fnS1ijbaoRokShI+W0V 2kiMdk3R1De7U6Msk71/RKXMcvVy8kvtRb0nfUJ5xnOuJWkU3pQ87oCGKLTcTZfjcTCQ VO2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163007; x=1713767807; 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=t6u9K3gcjLrMHLCFAhYLG4bnVQmGcLUFFxbpFKDU6RA=; b=cn373DbOTpvROatvCFQZDwFlBzgzPmE+c7Fyp79GMWDwk4U+graSjgVVlazvY2xdTz +g2gFN43F0AOVxQxUOgucG4DRrW/4YTcxeBDr7TCmJdenaUYmwCuS3f7Ko+GjnradMT8 5D8Mz0aumgiK5/pmfzHhS1ir9D1j3gm2zUyO71yIvgK4NDatRyI38pD3+L3HlI5iMZQW wBSexfo17nLD1gn5hXJVW3mGagfOtD5934Vk+qRTABKknwRW2JGfQW6hYIf9xR6lPiiq k1gF7/dBqVQ2NHNZTwYQEgh5C0UKf/83EvFNdRHdD9ibLSxM8M/p/iF+4V0OB0oi0B+W inPA== X-Forwarded-Encrypted: i=1; AJvYcCXXJoZv1FbFA0EohgwWNHemcxtMjBrD8rat+OoXbJLF4eoN55B8YajLZH8/sQUPTd8F7Xm7e6aMj065s+i73/M+xY9xDqS1Eu+0q6EMmJ7G X-Gm-Message-State: AOJu0YxpdTWP9fyOnssx2QYXqQLlfEyxLG7vSvjLqqXWQFy37b7+h2pK PzdJqQmomTu1AQHu9cY2+lpkyulcMXtLdFD5TOnmH/6VnxwPMapSAGyA2VG3h79TUeIeIAbt9LX g6DHLlw== X-Google-Smtp-Source: AGHT+IG8RJ4TxbVqnYh/ZFFdHmJfxbpZPCmfmXJfgiLHBndDiPsUAFRcqUnZUMNnHTZLEpylkDO/67CKESCA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a05:690c:64c7:b0:61a:c98c:c2a3 with SMTP id ht7-20020a05690c64c700b0061ac98cc2a3mr623165ywb.10.1713163007703; Sun, 14 Apr 2024 23:36:47 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:24 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-8-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 7/9] perf parse-events: Handle PE_TERM_HW in name_or_raw From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233649_689166_B7C75B74 X-CRM114-Status: UNSURE ( 9.49 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Avoid duplicate logic for name_or_raw and PE_TERM_HW by having a rule to turn PE_TERM_HW into a name_or_raw. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.y | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 14175eee9489..bb9bee5c8a2b 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -605,6 +605,11 @@ event_term } name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE +| +PE_TERM_HW +{ + $$ = $1.str; +} event_term: PE_RAW @@ -646,20 +651,6 @@ name_or_raw '=' PE_VALUE $$ = term; } | -name_or_raw '=' PE_TERM_HW -{ - struct parse_events_term *term; - int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, - $1, $3.str, &@1, &@3); - - if (err) { - free($1); - free($3.str); - PE_ABORT(err); - } - $$ = term; -} -| PE_LEGACY_CACHE { struct parse_events_term *term; @@ -712,18 +703,6 @@ PE_TERM '=' name_or_raw $$ = term; } | -PE_TERM '=' PE_TERM_HW -{ - struct parse_events_term *term; - int err = parse_events_term__str(&term, $1, /*config=*/NULL, $3.str, &@1, &@3); - - if (err) { - free($3.str); - PE_ABORT(err); - } - $$ = term; -} -| PE_TERM '=' PE_TERM { struct parse_events_term *term; From patchwork Mon Apr 15 06:36:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629495 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 768BAC4345F for ; Mon, 15 Apr 2024 06:37:10 +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=ukvnKKfEjw5puQUWJp5ZY6e0aEUvTAbuumnXClMizhY=; b=18MHmiAnqCRS4U 4HL6IDNHI66uH64qxAf7OePouDoLs6ZpNgcFixDj3py+NVakwBd4+K7Z+/wZFsApiOv3h/M30IeQb TlNZKQuLeAqVTLamiZAyaNU2oNyTDRy3maqZyG/4bdwTNW3QmNdB6A99YT8M7PZvXnirquBa9mL4u Vo2dEyTrxk9Z3wlu5D3BYVM7QpZLPS+sxs9HENRBrljSnKLypJcOshQHTEkcpqhOwlgSiDSDQC5GP huMezo5gHBjyaLe5d9UCwmVvcElEktNjpZ3c8y7xlnGOCm2vlE1G81zKeg+ENK6d2L9wArfECLDlg f9dRzSUdfV52P760w9FA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxh-00000007BGl-3avY; Mon, 15 Apr 2024 06:37:05 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxT-00000007B4S-1DoW for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:54 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso5618521276.1 for ; Sun, 14 Apr 2024 23:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163010; x=1713767810; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=SsM8Y1cj6kmrsHpwiXYtXKur/DOQuLkG4gE86ZL8CEk=; b=lrAhcTzIVFa2IhY/3lNsD5EZQTqj7Un/a96EF4crV0Ba8aETXMKn+TU8NkHl4HinT+ 00Bi8Ts1eONjtZDSJVVC+h24zP9XRx1F+40oAf8/OaMqY+kqJb+0eKmA/4go1+Je9K55 4Ekyvdkn+CPwdKZ9AuJh78Zo3c4BJPrFrUG2TV5NY4JpNq/S5slMFAOfi8ZfJPYBKClq vXhrllmC73RzsjkEUaU++zizETN64VcEMk0IZKqDNDzij7+pXbARfDOxs7crbT5GJLFm oasPPUVgZ9rKUkc56AuphJA42oevXpIvmOMf2cL0kr0ygASSmhqFozcadsVaSYy9SDEk m4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163010; x=1713767810; 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=SsM8Y1cj6kmrsHpwiXYtXKur/DOQuLkG4gE86ZL8CEk=; b=DPCpqBOgbV9/ikn4mLj6CVqirNoikkkFB75f9egOrrfieID7w/eOfMbod0L23DoQ+r YUebPFFt1LZd2VxcTmZRuZeh0jGSOQoQnE3XdP/6SK5tWKqxxHuQX6I8cHAEbHnifNwg Y4wlvUAnYAZT/bNNopVW2Zhs/rEdLh5OA3Fi5Q7nvvcRiC8nl48sfbiQjAIFYuvKtgB/ 5THPtjU5yzrRt02Ft8rXqMTil49Giq8o3AEH/XkCUQrB5BRmsADA2cCvw7zjsPs3QD7v O+qLtIlujpE7fjHAeJY1yES8Q8EPxulH7O1/ghx/LAJJ10R2/ZE5tBB0GWBTj7FiS96L bMvg== X-Forwarded-Encrypted: i=1; AJvYcCVnCXrZhWcYmWqdJigxBxpDoE9icF9PxojtSog3Z8c49a2pHjpZmdXYrbDef5PdcRo61rI8ymhh3pxFnSL+fBKUb8+RToabuG1XJp2KP/zH X-Gm-Message-State: AOJu0YwXB+sC1j0CxZBQtm0vo6KyBOrbQ3q+tbgkGBQjtb9XoHf4OSY+ lyhGxMuFZlruh3EfGL8m2J+urH+LLG41MMKyC5jDfuqG3UWlGLe2IH3pH6ZgVDj+Iwicl6IkuE6 AXZcHbg== X-Google-Smtp-Source: AGHT+IGgmCtdEtZrTu/VTbHRcGxy01TSWSnKf6exxI0DVUKXLBA7LgeFtUQlO61tu+Bc2rAGxXCSISNxPEr+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a05:6902:1549:b0:dc6:dfd9:d431 with SMTP id r9-20020a056902154900b00dc6dfd9d431mr2983582ybu.1.1713163009901; Sun, 14 Apr 2024 23:36:49 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:25 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-9-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 8/9] perf parse-events: Constify parse_events_add_numeric From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233651_653533_8807A504 X-CRM114-Status: GOOD ( 11.22 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Allow the term list to be const so that other functions can pass const term lists. Add const as necessary to called functions. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 20 +++++++++++--------- tools/perf/util/parse-events.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index f711ad9b18f0..50c4012c737e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -34,7 +34,8 @@ #ifdef PARSER_DEBUG extern int parse_events_debug; #endif -static int get_config_terms(struct parse_events_terms *head_config, struct list_head *head_terms); +static int get_config_terms(const struct parse_events_terms *head_config, + struct list_head *head_terms); static int parse_events_terms__copy(const struct parse_events_terms *src, struct parse_events_terms *dest); @@ -154,7 +155,7 @@ const char *event_type(int type) return "unknown"; } -static char *get_config_str(struct parse_events_terms *head_terms, +static char *get_config_str(const struct parse_events_terms *head_terms, enum parse_events__term_type type_term) { struct parse_events_term *term; @@ -169,12 +170,12 @@ static char *get_config_str(struct parse_events_terms *head_terms, return NULL; } -static char *get_config_metric_id(struct parse_events_terms *head_terms) +static char *get_config_metric_id(const struct parse_events_terms *head_terms) { return get_config_str(head_terms, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } -static char *get_config_name(struct parse_events_terms *head_terms) +static char *get_config_name(const struct parse_events_terms *head_terms) { return get_config_str(head_terms, PARSE_EVENTS__TERM_TYPE_NAME); } @@ -358,7 +359,7 @@ static int config_term_common(struct perf_event_attr *attr, struct parse_events_term *term, struct parse_events_error *err); static int config_attr(struct perf_event_attr *attr, - struct parse_events_terms *head, + const struct parse_events_terms *head, struct parse_events_error *err, config_term_func_t config_term); @@ -1107,7 +1108,7 @@ static int config_term_tracepoint(struct perf_event_attr *attr, #endif static int config_attr(struct perf_event_attr *attr, - struct parse_events_terms *head, + const struct parse_events_terms *head, struct parse_events_error *err, config_term_func_t config_term) { @@ -1120,7 +1121,8 @@ static int config_attr(struct perf_event_attr *attr, return 0; } -static int get_config_terms(struct parse_events_terms *head_config, struct list_head *head_terms) +static int get_config_terms(const struct parse_events_terms *head_config, + struct list_head *head_terms) { #define ADD_CONFIG_TERM(__type, __weak) \ struct evsel_config_term *__t; \ @@ -1324,7 +1326,7 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, static int __parse_events_add_numeric(struct parse_events_state *parse_state, struct list_head *list, struct perf_pmu *pmu, u32 type, u32 extended_type, - u64 config, struct parse_events_terms *head_config) + u64 config, const struct parse_events_terms *head_config) { struct perf_event_attr attr; LIST_HEAD(config_terms); @@ -1360,7 +1362,7 @@ static int __parse_events_add_numeric(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 parse_events_terms *head_config, + const struct parse_events_terms *head_config, bool wildcard) { struct perf_pmu *pmu = NULL; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index db47913e54bc..5005782766e9 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -196,7 +196,7 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_numeric(struct parse_events_state *parse_state, struct list_head *list, u32 type, u64 config, - struct parse_events_terms *head_config, + const struct parse_events_terms *head_config, bool wildcard); int parse_events_add_tool(struct parse_events_state *parse_state, struct list_head *list, From patchwork Mon Apr 15 06:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13629496 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 E561EC00A94 for ; Mon, 15 Apr 2024 06:37:11 +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=Uc7SGcR7Ff4Zm4V8vcj8QFPXPW+qqOJ+lglKNIFvWfQ=; b=GlXzsYbcknntcf CgJrk4BP6GavH/lC6qqC+7WDkh0k1OpyylTftKqM9zZrwXe9/iIOnfihlWFXypM/yirkMwPEV/5pU sOYxCAERe+3+Q5I/IpBoDeFpYNkE0aM92BwJdv9EcOA7coNkf5UYGwTdVWO41EbIkzfSjBHE3LvDz sUjjQm62w1NxaNdehEyb+Yk9GIHO8JPFHhijQOWdHUoi3E5EeGAVK/drgT3euHs6kszmCzHy531KS UOaOL3TRQ0SHIITDK9pqB7zofIaLyZgU2JSvbJ1q6hSUH9aUJKDESTs+ys/a1k76vVlAgoLjG1+bP 8nzmKHt/C8Hpn1xUguNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxi-00000007BHo-3jJg; Mon, 15 Apr 2024 06:37:06 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwFxV-00000007B6C-3tbQ for linux-riscv@lists.infradead.org; Mon, 15 Apr 2024 06:36:56 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-609fe93b5cfso45379647b3.0 for ; Sun, 14 Apr 2024 23:36:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713163012; x=1713767812; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=C2zYz2p9SuP23YkC/Puz1S5ccaK/qlF1ObCAaC2jTYw=; b=m50pbd7uUc41KTBjYqMnCerTe6DImfZ/Fy56VJGJPWnCbh3xKdXRPAEZ70zOarBCUV likUKpY7aTMyx6u7hTVDyPTo/n01RhzQbvu/14j4pq6P94W74xgt01IJ8Rr/08X5ZcVS OifAgTMHlG7WnXL9nAbPW+AniYV3fYxBhECjXYKpwq1kTl0Sg1rWY9IOkbjfhw0gakpV Xj0FCwN3d0PBJl0WiDoYDBmE6t+NW5swYKy5zrtVyZ8ZpUDCV03HLBcanvJNl5R8iIW6 a0+/QimK8pVBKTgn51N01iLGs9kwCj5iYCsMyNt3eDMpOABD8vEzSKtkhWRHNzOtt3qm C+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713163012; x=1713767812; 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=C2zYz2p9SuP23YkC/Puz1S5ccaK/qlF1ObCAaC2jTYw=; b=W+neHUd7Q35Y5RjkIC9VtusgkUu2TXOMc5Lm5uMmP2hqykMux4+1Ug5dW9C/70fasx ELBaDnChTCzZHk3IT0jb3kewvsYjcN57bGH2YjI7bbzJP3n4wgAz2/8slAfkK6sWLLUz sQORK+OV2cwltsnXYjzddfUxDY5sbgZ+7ZqKU5W27gxW6f+PziTZ14vxVdNLuzIwe2y5 jWweC4QsrWFz2YLgfRroNxhi3UHyvBdTLt5jH/RqgtfByyv1UKWyPxL3fi/fp3DbVV9Z 0Yqb8dd31AtPqdhsDuESKN3EI26lRDYLQIoIh7w2TvGhYU96e6GIKzUvj0vCmTBZSTWC XNUA== X-Forwarded-Encrypted: i=1; AJvYcCV31iREUmpZEUNh8HVhHkN8AmhXLUG+DChrA8eWZHA3PH/TnU2kWImgdItgTNNZDlx7PbNXm+R99sDmNxlId/EeDVterYSc9m8825M+5FkE X-Gm-Message-State: AOJu0YxaPi3Q/kE5h5UI6DOcC3OoltDahJ0r+hUkeNiNtgfVCLtET6Hx E0qWAIOU1yfNH2eZUeQBd6u9hDvwkeYf54BJNnt9ziess8ZU65QYILS5tqByE6j4jgJTdjrnO5f c2gEqtg== X-Google-Smtp-Source: AGHT+IFc8oupYxi0XroaQS1qPNvf09WVo0Z2C9KWMqj3BnRf4KigO+cieQFWNrE8mh6AO/gRMa+AxYq+tlzc X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:f304:d776:d707:4b57]) (user=irogers job=sendgmr) by 2002:a05:6902:1207:b0:dc8:27e6:cde1 with SMTP id s7-20020a056902120700b00dc827e6cde1mr1092814ybu.5.1713163012522; Sun, 14 Apr 2024 23:36:52 -0700 (PDT) Date: Sun, 14 Apr 2024 23:36:26 -0700 In-Reply-To: <20240415063626.453987-1-irogers@google.com> Message-Id: <20240415063626.453987-10-irogers@google.com> Mime-Version: 1.0 References: <20240415063626.453987-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v1 9/9] perf parse-events: Prefer sysfs/json hardware events over legacy From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Atish Patra , linux-riscv@lists.infradead.org, Beeman Strong X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_233654_132689_98C52841 X-CRM114-Status: GOOD ( 20.78 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org It was requested that RISC-V be able to add events to the perf tool so the PMU driver didn't need to map legacy events to config encodings: https://lore.kernel.org/lkml/20240217005738.3744121-1-atishp@rivosinc.com/ This change makes the priority of events specified without a PMU the same as those specified with a PMU, namely sysfs and json events are checked first before using the legacy encoding. The hw_term is made more generic as a hardware_event that encodes a pair of string and int value, allowing parse_events_multi_pmu_add to fall back on a known encoding when the sysfs/json adding fails for core events. As this covers PE_VALUE_SYM_HW, that token is removed and related code simplified. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 31 ++++++++++---- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.l | 76 +++++++++++++++++----------------- tools/perf/util/parse-events.y | 62 +++++++++++++++++---------- 4 files changed, 103 insertions(+), 68 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 50c4012c737e..71b0c5d518f1 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1541,7 +1541,7 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, } int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, + const char *event_name, u64 hw_config, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc_) { @@ -1549,8 +1549,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, struct list_head *list = NULL; struct perf_pmu *pmu = NULL; YYLTYPE *loc = loc_; - int ok = 0; - const char *config; + int ok = 0, core_ok = 0; + const char *tmp; struct parse_events_terms parsed_terms; *listp = NULL; @@ -1563,15 +1563,15 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, return ret; } - config = strdup(event_name); - if (!config) + tmp = strdup(event_name); + if (!tmp) goto out_err; if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - config, /*num=*/1, /*novalue=*/true, + tmp, /*num=*/1, /*novalue=*/true, loc, /*loc_val=*/NULL) < 0) { - zfree(&config); + zfree(&tmp); goto out_err; } list_add_tail(&term->list, &parsed_terms.terms); @@ -1602,6 +1602,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, pr_debug("%s -> %s/%s/\n", event_name, pmu->name, sb.buf); strbuf_release(&sb); ok++; + if (pmu->is_core) + core_ok++; } } @@ -1618,6 +1620,18 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, } } + if (hw_config != PERF_COUNT_HW_MAX && !core_ok) { + /* + * The event wasn't found on core PMUs but it has a hardware + * config version to try. + */ + if (!parse_events_add_numeric(parse_state, list, + PERF_TYPE_HARDWARE, hw_config, + const_parsed_terms, + /*wildcard=*/true)) + ok++; + } + out_err: parse_events_terms__exit(&parsed_terms); if (ok) @@ -1670,7 +1684,8 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state /* Failure to add, assume event_or_pmu is an event name. */ zfree(listp); - if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, const_parsed_terms, listp, loc)) + if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, PERF_COUNT_HW_MAX, + const_parsed_terms, listp, loc)) return 0; if (asprintf(&help, "Unable to find PMU or event on a PMU of '%s'", event_or_pmu) < 0) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 5005782766e9..7e5afad3feb8 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -215,7 +215,7 @@ struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, struct perf_pmu *pmu); int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, + const char *event_name, u64 hw_config, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc); diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index e86c45675e1d..6fe37003ab7b 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -100,12 +100,12 @@ do { \ yyless(0); \ } while (0) -static int sym(yyscan_t scanner, int type, int config) +static int sym(yyscan_t scanner, int config) { YYSTYPE *yylval = parse_events_get_lval(scanner); - yylval->num = (type << 16) + config; - return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; + yylval->num = config; + return PE_VALUE_SYM_SW; } static int tool(yyscan_t scanner, enum perf_tool_event event) @@ -124,13 +124,13 @@ static int term(yyscan_t scanner, enum parse_events__term_type type) return PE_TERM; } -static int hw_term(yyscan_t scanner, int config) +static int hw(yyscan_t scanner, int config) { YYSTYPE *yylval = parse_events_get_lval(scanner); char *text = parse_events_get_text(scanner); - yylval->hardware_term.str = strdup(text); - yylval->hardware_term.num = PERF_TYPE_HARDWARE + config; + yylval->hardware_event.str = strdup(text); + yylval->hardware_event.num = config; return PE_TERM_HW; } @@ -246,16 +246,16 @@ percore { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_PERCORE); } aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE); } metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } -cpu-cycles|cycles { return hw_term(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return hw_term(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return hw_term(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return hw_term(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } -cache-references { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } -cache-misses { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } -branch-instructions|branches { return hw_term(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return hw_term(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } -bus-cycles { return hw_term(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } -ref-cycles { return hw_term(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } r{num_raw_hex} { return str(yyscanner, PE_RAW); } r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } , { return ','; } @@ -299,31 +299,31 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } <> { BEGIN(INITIAL); } } -cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } -cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } -cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } -branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } -bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } -ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } -cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } -task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } -page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } -minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } -major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } -context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } -cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } -alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } -emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } -dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-clock { return sym(yyscanner, PERF_COUNT_SW_CPU_CLOCK); } +task-clock { return sym(yyscanner, PERF_COUNT_SW_TASK_CLOCK); } +page-faults|faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS); } +minor-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MIN); } +major-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } +context-switches|cs { return sym(yyscanner, PERF_COUNT_SW_CONTEXT_SWITCHES); } +cpu-migrations|migrations { return sym(yyscanner, PERF_COUNT_SW_CPU_MIGRATIONS); } +alignment-faults { return sym(yyscanner, PERF_COUNT_SW_ALIGNMENT_FAULTS); } +emulation-faults { return sym(yyscanner, PERF_COUNT_SW_EMULATION_FAULTS); } +dummy { return sym(yyscanner, PERF_COUNT_SW_DUMMY); } duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } user_time { return tool(yyscanner, PERF_TOOL_USER_TIME); } system_time { return tool(yyscanner, PERF_TOOL_SYSTEM_TIME); } -bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } -cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CGROUP_SWITCHES); } +bpf-output { return sym(yyscanner, PERF_COUNT_SW_BPF_OUTPUT); } +cgroup-switches { return sym(yyscanner, PERF_COUNT_SW_CGROUP_SWITCHES); } {lc_type} { return str(yyscanner, PE_LEGACY_CACHE); } {lc_type}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index bb9bee5c8a2b..ebac73786065 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -55,7 +55,7 @@ static void free_list_evsel(struct list_head* list_evsel) %} %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM +%token PE_VALUE PE_VALUE_SYM_SW PE_TERM %token PE_VALUE_SYM_TOOL %token PE_EVENT_NAME %token PE_RAW PE_NAME @@ -66,11 +66,9 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_DRV_CFG_TERM %token PE_TERM_HW %type PE_VALUE -%type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW %type PE_VALUE_SYM_TOOL %type PE_TERM -%type value_sym %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE @@ -87,6 +85,7 @@ static void free_list_evsel(struct list_head* list_evsel) %type opt_pmu_config %destructor { parse_events_terms__delete ($$); } %type event_pmu +%type event_legacy_hardware %type event_legacy_symbol %type event_legacy_cache %type event_legacy_mem @@ -104,8 +103,8 @@ static void free_list_evsel(struct list_head* list_evsel) %destructor { free_list_evsel ($$); } %type tracepoint_name %destructor { free ($$.sys); free ($$.event); } -%type PE_TERM_HW -%destructor { free ($$.str); } +%type PE_TERM_HW +%destructor { free ($$.str); } %union { @@ -119,10 +118,10 @@ static void free_list_evsel(struct list_head* list_evsel) char *sys; char *event; } tracepoint_name; - struct hardware_term { + struct hardware_event { char *str; u64 num; - } hardware_term; + } hardware_event; } %% @@ -263,6 +262,7 @@ PE_EVENT_NAME event_def event_def event_def: event_pmu | + event_legacy_hardware | event_legacy_symbol | event_legacy_cache sep_dc | event_legacy_mem sep_dc | @@ -291,7 +291,7 @@ PE_NAME sep_dc struct list_head *list; int err; - err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); + err = parse_events_multi_pmu_add(_parse_state, $1, PERF_COUNT_HW_MAX, NULL, &list, &@1); if (err < 0) { struct parse_events_state *parse_state = _parse_state; struct parse_events_error *error = parse_state->error; @@ -307,24 +307,45 @@ PE_NAME sep_dc $$ = list; } -value_sym: -PE_VALUE_SYM_HW +event_legacy_hardware: +PE_TERM_HW opt_pmu_config +{ + /* List of created evsels. */ + struct list_head *list = NULL; + int err = parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, $2, &list, &@1); + + free($1.str); + parse_events_terms__delete($2); + if (err) + PE_ABORT(err); + + $$ = list; +} | -PE_VALUE_SYM_SW +PE_TERM_HW sep_dc +{ + struct list_head *list; + int err; + + err = parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, NULL, &list, &@1); + free($1.str); + if (err) + PE_ABORT(err); + $$ = list; +} event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM_SW '/' event_config '/' { struct list_head *list; - int type = $1 >> 16; - int config = $1 & 255; int err; - bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard); + err = parse_events_add_numeric(_parse_state, list, + /*type=*/PERF_TYPE_SOFTWARE, /*config=*/$1, + $3, /*wildcard=*/false); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -333,18 +354,17 @@ value_sym '/' event_config '/' $$ = list; } | -value_sym sep_slash_slash_dc +PE_VALUE_SYM_SW sep_slash_slash_dc { struct list_head *list; - int type = $1 >> 16; - int config = $1 & 255; - bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); int err; list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard); + err = parse_events_add_numeric(_parse_state, list, + /*type=*/PERF_TYPE_SOFTWARE, /*config=*/$1, + /*head_config=*/NULL, /*wildcard=*/false); if (err) PE_ABORT(err); $$ = list;