Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1869707lqp; Mon, 15 Apr 2024 23:16:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9ZAZgP5ToKyCokhkWMaNxc1CnlWmvZLuFP9rbgzFY3IXks/OExKWHt1izjYD6BAyd9xi99vRDnIETqCJBMKa3JVjQWOSDovxjFYklnA== X-Google-Smtp-Source: AGHT+IE4wjGL6f9FBBtA4UNYx70MSPaYKPFGpIM3dvK+IBy9kpXstMk7ji63gCHYUNBIZyylfDYg X-Received: by 2002:a05:620a:4482:b0:78e:ddf9:5f5d with SMTP id x2-20020a05620a448200b0078eddf95f5dmr9516777qkp.18.1713248173913; Mon, 15 Apr 2024 23:16:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713248173; cv=pass; d=google.com; s=arc-20160816; b=xx/iW7LTPnAI35oEx4tQvjtg8amYdCuurKl/Qh4auBNKZ8thxQ46xqeF7ybdKlCDO9 Oe2DQQ6q7LRlNxXH8mN831SUwN4FZiXdd95fsYuXmC2cjviTyVGLL00n392vcv3//3p5 nlxgzj/Qa/h/vM5uiaBxGRrt2ZtbAOZWf7qjEdJjfPopoP1ghF+RtM56sH1hJVx7wNDl 3TlcS0lL6E+gpciNd+ms4z5e32hMxSeRSwBVSBra3u3K9853WPajbj94BHwb2ahkviFz EfZVOM/VxnSMcCJIDjjl38655I5dghRItddU8xAzbh+YcEGNhA/TtAeQgiY/SgZadV3m 3PSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=LZDaJNkBNQzqTbOVORPBbpHI26H/bVA4sAmx4hPV1q4=; fh=ySdwGVXXAEdeoPWEET3lxqW2BEWt7tXKCNWljgc7KWg=; b=ZyaF6sEOeFNm6Og2qLR0jc4JI57UQjTyvPkv0M0nGqR6SdVpJi4J9/ejUqlPeiuFNe tJP4DDiW0r3EqkU7KfEN/0leKHINwpCz09YCBie3TWTgogsznV6LLGDT4bUdHS+637dF tKuojAs0x64aE53MfHVZbdrN0OM5gexb9RYu3ujv2rEN1GjIebtRhRWDaPj1c1Uq2W1c YBbd8Vc/dy+cbnB6OvKbPepmc6IeoLYQkoJSG6TcK+IpozO74+hhfavpjBEVJ0HW16OL EoWcvW2XGyPGv5g72YMP1fDmml+uhc16UerZo99WGfBM5eDw8/txdOyknYUfkJzYuNc+ pxvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TI3wmC4w; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-146322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bq39-20020a05620a46a700b0078eca5876f9si10950550qkb.379.2024.04.15.23.16.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 23:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TI3wmC4w; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-146322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8F48A1C20BBF for ; Tue, 16 Apr 2024 06:16:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7DCE44C81; Tue, 16 Apr 2024 06:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TI3wmC4w" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32D33CF63 for ; Tue, 16 Apr 2024 06:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248150; cv=none; b=a1zxQMdRul5EuTILCC1vLvtG+6q9/FJpYyO1WyLZ08muD50eldDC/8CB/0g4mLY7wsP4pus8TxVYIWZnRrR1HNTNJnurSil8yh86xoYDoIFMhIX8WOlkkGZlzwI5E5ibhxJq73mTcSwgl/yu9sNzO7/w1MHJWZdIp3cnwV59y9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248150; c=relaxed/simple; bh=EEkwQ6nsrkJfCdd+xL56HS073O9RsNgTTq8Kh2mCF+E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=VmWq8qOkyNPyQDjc//3k1Lkdf24j4HReGinuMmb1PYPFRfwEQxvJoX6AOT0eninZcuhHyF5Eh+tYEkiUj8JWoyTjFdOotHAMKD2joxChauPc2jng7cDkUF8hBnfr3c8UnogCFhDEnQywbJMcW28AHRkwHFVggQOnjcGN9mOFFXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TI3wmC4w; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd1395fd1bfso7080776276.0 for ; Mon, 15 Apr 2024 23:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248147; x=1713852947; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LZDaJNkBNQzqTbOVORPBbpHI26H/bVA4sAmx4hPV1q4=; b=TI3wmC4wh53vlomE12i7TZXlYXONmBke+E4CaqqfK/jDW0REFesz48UqOnrgfKxjTS Rmh6VS97YkwbYprAbeFkGzjxT+390lL9RDwmooLhxjUMpn60wNBrmoiNXA8mJFPiczao 3sF5D5hjcqWZk2zNKXk5pGWKlRq9X0IjaZlAOb1O+Dcixjr1ARBjO1U1AAZlJLK8AhTu mN13eYEKYoPJjQlWGc5DdN6xTRekhZACQ66Te/7k2AAAUZdXL2gdGpgfCB9vw8YTJ4bw /IMgE3RME4hsvNtFXAw2216s+22yaz1IRxTf00Qw2il5oitfcly/Mlo2cxp7+meOLJSf wajw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248147; x=1713852947; 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=LZDaJNkBNQzqTbOVORPBbpHI26H/bVA4sAmx4hPV1q4=; b=f6kUlKLSNs1aWN+SQhgMSv6r2XFx+hUElRQwWCOCmg/CVTJ93a6yZcbys23YkfaFzu vQokNR3mWMHUr90uwg0c9Ngej4SKD1HivCanRz+0CLx0YbCwlGnaGjIQekwqMIiFt6v5 iVgABrNyyKeasSF5mxppZtcC0ZS6vLtOIE0VzKZIsqhKSpIA4rmbOOzIREvFwmUrc44V /ssAGkeMGMAtepo8N1eDnXEgQhfIVBTGFVdDTWlLHc5+/EA0yK3fpPjJKgqe6l/x1ora /M4N1Qg/LyUblfZM0ejxe6a2r0oJfXewFher9YD+ccBstNCunM6enkFnOGLiKWVX4s7M dVVw== X-Forwarded-Encrypted: i=1; AJvYcCXfasJuvhtYLOwINhPtOgWFDomKV9TMZ6jx2K6w6vDm8nQO7w0PzXYN7F8mzsVYRno0jTMBMT70TSW5Uek9nfDT4ydfCJjOFrjsLPh8 X-Gm-Message-State: AOJu0Yw67kRVN/SnbNUyQKpb9ytTGrhKO8MaG3EYtDcfmUcLvgsjHqMf 3vQGI0d0PUTh5+c276hJdM/ZD2NIAVcq50X3kU3OxuLtR+teGUrIHA4gtsK9/NTPPsgVkAZ+MO8 /eJfigQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a25:addf:0:b0:dd9:1db5:8348 with SMTP id d31-20020a25addf000000b00dd91db58348mr3597111ybe.8.1713248146694; Mon, 15 Apr 2024 23:15:46 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:17 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240416061533.921723-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [PATCH v2 01/16] 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 Content-Type: text/plain; charset="UTF-8" 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 | 70 +++++++++++++++++++++++++++++++- tools/perf/util/parse-events.h | 10 +++-- tools/perf/util/parse-events.y | 73 +++------------------------------- 3 files changed, 80 insertions(+), 73 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 6f8b0fa17689..a6f71165ee1a 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,74 @@ 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..7764e5895210 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -273,78 +273,15 @@ 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; - 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; - } - } + parse_events_terms__delete($2); + free($1); + if (err) + PE_ABORT(err); $$ = list; - list = NULL; - CLEANUP; -#undef CLEANUP } | PE_NAME sep_dc -- 2.44.0.683.g7961c838ac-goog