Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1869791lqp; Mon, 15 Apr 2024 23:16:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWaWNqX4b56ZOeoGkbx5fxiR5WmSa0TLDzpfPsGjSMjWY1fd5ya5RZPp/W7kHJWCUmtxjUa4BpRexnbtJszSeKkiqmZwuf/xHZTyEXNQw== X-Google-Smtp-Source: AGHT+IHBiNuRgxAUEeK1j56Rn2Cit3AZD7+hodXjoA40j3+0OQ1ObkeqTlgSKvCLtujTFFQQFyMS X-Received: by 2002:a05:6512:308f:b0:513:39a0:1fec with SMTP id z15-20020a056512308f00b0051339a01fecmr8365912lfd.66.1713248186971; Mon, 15 Apr 2024 23:16:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713248186; cv=pass; d=google.com; s=arc-20160816; b=y3/tGZuBJx/wgPmsHEQVlCZoyE0A0yUFdFy5d9eZJAh5CNQ4vf/mq2Jmshdwoj4PxM MsGJSYrektTM+aSx0LTZsD8vZQfjqkR0/IyMBMsK1HiE1DhU7cmdupX27qxZfu6i8Buc Q1Ky9O8cS98xRV2+Sp+oJzJg9m1iVGoeyTjdEQF/yioIQ5ceLAjU+pB7Gp8UXIEvxmRz sfsvDuxolOaNnBJxdAKHyQEkWCQ/QXdiqQ3lnFISXxUn30VHDH7iG7VdfhY+tPCjC7eb Bb51OXe81fzlTOUkUDMyKTXo+aJxHADdZqDYmUP5SQMuLH7aupe/R7dk+m2HQKgncEqf 45CQ== 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=ISxoCTVYs/kboJSJHGYt4b3mBkGEF06zZpMTEp5MU3o=; fh=v4gVDdDLltmDKZjREusI1Ll/LE7kpnOgHYzuLj8s5YI=; b=yjt0TtWatdCcGpZTnmgcINr1GN3MK/adpN2VK411fNj2NOgJsu3S0pQFB2JL8nEzNS /BjFqy4GfycvUtrsVtfCJ1BWPJC3vQ9eayVEYbQBAxn87jllFy3VjFEyTtQH/boMnWxg s211Hmexxnob9CL+JIgqMfVpnYAbRpMa/xLU6mDQX1ndMJatZn3d6Hs8QLZ0PI0SLsOl wgBI5p6bwQ3IsDgq/9cDuLQ10uULaGzgmpAOf90DeDS5hzRRDMp59psXpS7SYt793Xfl 6G9hLRwi3uhasfOKSMKImvs/lvjf71SPNju3K9BC/r9weo6etiOL/NrzHQfrDtzU++RH 1hBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kuSMI5oP; 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-146323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m18-20020a056402431200b0057020ac4578si2408572edc.124.2024.04.15.23.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 23:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kuSMI5oP; 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-146323-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146323-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EDA121F21545 for ; Tue, 16 Apr 2024 06:16:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80CE25A104; Tue, 16 Apr 2024 06:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kuSMI5oP" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 09EC53C6A6 for ; Tue, 16 Apr 2024 06:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248152; cv=none; b=IPWdqxvaoOUynRQkkJlOjb/rYd9a9FpOOmKbC4DoBlpIyliMwnh6qrxeUcTuImee4TxwTV729LYShBo3CnlsM9hFCsFASzIvobktnqnxiFN/jDa+PGVBwZz0cY+aJ+rv6ejlBxkvQiv7MNoG+EIVI7/WjfiLOOErirOkMDWCRCI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248152; c=relaxed/simple; bh=g8YcEYHoAU8u64DTdGK221vQkdSWAde1+LeEFZx1RPA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TQ713b4gicl5zh7Y7qxvVlZM4sqvBzCYhjq4WnCzhuYK/r3PSfy8U5lZvefpCpfoV893A1pAcDDO17iKhmq4ISonRvMncA3xAt/lmXqr+BShxmOpqOXKcwZRrPCNCBwB24NyHYplgRxQBe8Ad9KFwr4u2gBmO5y7of4Dtp6YNnU= 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=kuSMI5oP; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-615073c8dfbso84496177b3.1 for ; Mon, 15 Apr 2024 23:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248149; x=1713852949; 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=ISxoCTVYs/kboJSJHGYt4b3mBkGEF06zZpMTEp5MU3o=; b=kuSMI5oPgaqGTylGUzGkuQy5FLFKNaZZdy6P+1/0SmrCEB+ENRUp0LLK3KEd0abn1y UyszW27GiQ2x4+D/st/mEnLeWD2ABsdXuHY2xcPscs9QTRcBhotmigbckuQajRAXLsQz NjB1b93g3rNAEiWwd6PZ6I5g5+/cnTjSYix4B0WVrUjDDs+2svw6bx7sOzQksvNk5Ic/ SDBa/uVbnIyrfOZ40r+TiWgFUxMK46Solqfr+B+/y+ozL421FQzRseWGrKLP9QH3NvGi rCmUhiYLXhrn9E+tv+bO8itJ//mRcDDBggkbPWfZXNnN6NHCf4UvqKD39GsxSVHkUwCU zPGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248149; x=1713852949; 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=ISxoCTVYs/kboJSJHGYt4b3mBkGEF06zZpMTEp5MU3o=; b=ZkAxhzCQrbVZsgGfvCETRazZ87M0ZrXE4xiO3BqPOc4V3olMJbS7DN0YxI0a8im9Rx TcSpHN9zakcDFVqB1ul59yNA0PLzx16dJiIKK8UkC3AtvkaulR0MkF2pJU88DInGghBz L9A9ehgYYQ5A6SH6pwFav8AcfE+1yj71qMMcz1biZ/IxeTTr+GOXppUHd00B/T+ZONGi aS2k8XlO3LuBSinI6dhchwH/G8jkwlaSZX5zbDE85w9idxEYIUNqus2hlQ8fXrM0/xoE gfMEayjoKVFS+brLTd5tu9/qyFD4CtkaPg9M4II0fvdb+JAwoUJtJMQwZ56IhlpeaWLS jXlQ== X-Forwarded-Encrypted: i=1; AJvYcCX8JsC3VC8mpOpcNGjIu7nAVplnjWhRhLJv+eHJYUKSKH2zh1iB4aI78J96O4LupLiF9GP9pGTrc30UoUtHuXH9BXboAvQlEYdxIpxA X-Gm-Message-State: AOJu0YzumAMJbYrLsgw0bYPPI2qovky8XBC4QdtDLZJkc1YYbquQ8I/i GoF321r7hif/EpJn/2awAh/tWPnbL/gIn0xsctarWI1mw4pkmr3+h2a3DkNEghtZCWYqtLM8/N/ oVSqMOg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a5b:352:0:b0:dc6:44d4:bee0 with SMTP id q18-20020a5b0352000000b00dc644d4bee0mr1409504ybp.7.1713248149135; Mon, 15 Apr 2024 23:15:49 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:18 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-3-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 02/16] 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 Content-Type: text/plain; charset="UTF-8" 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 a6f71165ee1a..2d5a275dd257 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,9 +1648,9 @@ 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, + if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, - auto_merge_stats, loc)) { + auto_merge_stats)) { ok++; parse_state->wild_card_pmus = true; } -- 2.44.0.683.g7961c838ac-goog