From patchwork Tue Apr 16 06:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631316 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 ABB3A3C6A6 for ; Tue, 16 Apr 2024 06:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248149; cv=none; b=Vx6Gzv8kuB0Aywn3Ctz1r6CrfmLTISO4zWDHp2JNsTZD/r/XnK9xFl458DE8oFn53yDYshVO4ttARMx6AzFweqo4Dx9lYMZF07xMN/uBCc92OCS4Ofngzpp05L5FJ1HMWr/PSPRrgrzvkYOiO/mqmz/aUgMxrTBolRccuAotdDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248149; c=relaxed/simple; bh=EEkwQ6nsrkJfCdd+xL56HS073O9RsNgTTq8Kh2mCF+E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jIt4cfv4CcUrP3XfqbgkYr1oNAB1g/mu+8c+ZHT4z3eoX8zMkGinMk/8dZlTw6wSOnOuTTOnySPa68VyYVsnzFGzXhb/Z8YBhX9Yd6Zd1AsFPodG8RBauf/ZEUxWSLa5d3i/OiYS0oerOnhkULxXqQbGt+lcRA7/dODK8u8zc3s= 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.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TI3wmC4w" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd1395fd1bfso7080775276.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=Ihve3lvW0RpYpM80kku49B0vS0thGn7SbJWr2VNPye/1acu+FR54AmYTUWE90tKbs5 7Hfx0g+DMhZ7IeatS9nq4XuLi0n6ZCMN0hofjKghvme17TXSCQxdnXXuWOoYMc2giuj3 0s+WvCQ7qSNowHVwviRSCVxalQIlMmmLuN8iuytnegIMs36hLiRXFtfFWpDJwHb2QpOw zxR0vuAH6GiGwjpIe6p+nLlbFYFE6NjovTxvzvAoifbn7x9EXoHj6AXKj+fvMfp9+Jee qHV2786PCN7e+qeRnoT+IGycHgW2ZpM8/E2k9lAxK2Mv0GE6RUGpddy1q24Ei5CRC71y AQlA== X-Forwarded-Encrypted: i=1; AJvYcCX9C9Gz+MD+2dnsCKtbHJgcK8KrHgizg0xmgyT4HyWq/xwBD1FqQN52/WRrYmIftNAVJ9TgCEsYG4MjpbJvE4sV9ZbN X-Gm-Message-State: AOJu0YwqcObZQXjAgvZd+VJcSRn0Zi4HzscS5j+tQ/vVelmcMiL+ySQs rTXi183BfaZqW32FejlSmCB6NYu7Wm/k3D02L+QOTOGv7bOXMAyaG5ZOcpd8JhfOQ/ScDbKO/0a R6Djegw== X-Google-Smtp-Source: AGHT+IGb1Z1MH8mrJs7TUuzjYGsHip0fG+66XHrIF4uEyiZCBMkf4G0cyFGOrCW/aJTepnynA8OowMuWg4As 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: bpf@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 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 From patchwork Tue Apr 16 06:15: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: 13631317 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 14DEA42070 for ; Tue, 16 Apr 2024 06:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248151; cv=none; b=cQQ0/jWAMzsmfmBT9+H+fFS6aS2KIPsmEE3c9hrP7nuAPiWJCHTLBhK7aBs1Iq1KyjZWdqunvPiqfnm6hKuLwGKBSAcoU97Y+DW0dL0ESTAyhYGVWTi82BBuqJmAXEZVK6dAvEdH9Evnk7/kGdXY21Iedd6EK9VMQqawCaqWKVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248151; c=relaxed/simple; bh=g8YcEYHoAU8u64DTdGK221vQkdSWAde1+LeEFZx1RPA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=KKHbO9I+bhU0mV8Y9aGaPBeWYJUUIE2l6w7EeKmqiC2Xft3orNLm+jmR3gCpHJnOM2DWpGiMR8QgDU1+NWxPEU20HHoAFdXI3V/Se4bdTxhvpEh6dvI6p5Cz1GLEd4rorcedzVG730ln7TlMJZ4rP5kkYal/GSz8IOdsFqYiAKk= 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.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kuSMI5oP" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-615073c8dfbso84496187b3.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=o8VHaZFldhxHplIhWTdI9ELXbJ5RGt7jndPUAPIsGVqJxuTV7idzm0V71d7Gd8+0A5 OoyLhxc5Mshj/8vcZDUTKoLVf9AwnDunNdBomeN+59zCadeMd6o2xciSgkAAHbokq7QO rAjpX3qrVf2W9PTINiafofovp4TqIQ2xOckQCFWz8AbW0KXdjthft1Oodntm+s8nlbJQ AG8MKl0s2Oz4VYtHvyf4VWd8M6G11pzxzQPKerZn1mz47OBCgEXRqTEXxiKWBrO7xNum 78fOUazJFuRkH0CyPN8CqK9UCB9ZlcW2vCE5dUQi2pa0Ef5OnSLJStdgq+KjPtcFdRG5 bh5Q== X-Forwarded-Encrypted: i=1; AJvYcCU0QhS2J+xcE5/ll0qnhKg/QKLhwaaRKJXVtBJXCYjEmW7X3mgG/KOjTps5Jo5mAqfsNvfJq3MT0ZoQI23aqoVuEsNt X-Gm-Message-State: AOJu0YyiOdj+uigUbh7mbeTRvLe+/UcDauNqRO/BYmqOGob5MaH5pRrx U8qPUTVWaA7+yVbgya+Je4Fe1x5kMcHCCvEK1NNE0gnQ9Hhf4+BBprGfyFscIvfunb2EIO25q26 yzFrXUg== X-Google-Smtp-Source: AGHT+IF5Mb5jcMAhhRkK6u6Kb3obJDXY76FnyOuX7taBUES+/AUIezgqNp2zlhbtwtn4M0p3sfRXH6RFeieK 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: bpf@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 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; } From patchwork Tue Apr 16 06:15: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: 13631318 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 465D853381 for ; Tue, 16 Apr 2024 06:15:52 +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=1713248153; cv=none; b=NFTdGuzkij7IkLml7V1lPFsWB74LfbJiYrBdt2YTQjd7xaZhoYMyn8xWv+TXTeCa918m+lbUT8XqxhgLkcoBMafd703gEDGrdQmj3jS5ER3mXYaoxSvzVIytPke/lqvoGJPb691IX/Bd8aqBYGN4I36S64G6uN0+a+bMKNUHXEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248153; c=relaxed/simple; bh=IERvH/Ao6HfWGEykCXtiWrApDF698nujkO4wwCpYmzw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=H7IJBE5w1pkPtoYu+sGI9CCajGwzV93BHN6P4lXUU50top9NTRaBm9oDd+0n2B5KQpzVY8CkxctBu0efZ6j3dbWhwXsmyKhPi6pKK9smhqFHjZ8F4xlCSIp1QQSZ0mnnlOW/nJtCnCtGstc1cC+BLH4cUxSxNMZx2vbzmprdMDk= 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=XNN4qflV; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XNN4qflV" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-619151db81cso31527407b3.0 for ; Mon, 15 Apr 2024 23:15:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248151; x=1713852951; 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=trVc8Z3cM9HfuUa79775aNx5De/ILl71mqLeEIudwkY=; b=XNN4qflVBY4y9wyZFiv0CpHJcPKMRC7AEpYwTL2cRaJQDuj6JK1i9EDrFqhyXSY4ih RsW/5rpPp/tXv4Ygt424I5TOBks3HxBrLTO+eHniPjok95LQPzu0YnWf46AjZ5vkgIc5 Jh3+xbHXNq0lM9vloV2y94TIByFwtdip9eWaLX2IOAUVXSZDjGMpSAzO09EZwKtjLVj/ 2b7kZi+sEBjL1CpmQle52ix7WJr50iH7b0HX1qmFsO5olvaI2kklsycZX8AV7JHXt5MH VvaXSZrbkxAQG5PKyXMPiCDcesROb4qqpMhVL28wmMoMn/Hw8hOmtorLX9lPrcqGOXaU 9E9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248151; x=1713852951; 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=trVc8Z3cM9HfuUa79775aNx5De/ILl71mqLeEIudwkY=; b=ZOU3VgRSoY8f/bwXkRf52iuLgCmYiltvpRp1O6NfGmwnaLGBEwrmnyXDk4lEW7U9TC fhemfBSxF/0Pn/WDFf+YtQBoqgXtLEWEKB0j7AjJzhkB/PRWg9O7n2B975GZOhCbKz6o 7Z0B7h9HpB2UBuRcKl5YS+lZ7uK4QIykyufXwWm4QrcncAawbidApLouja8vqHatiMs2 B9j3FYx3HvrXoydFOrrMrBl3L9x3WtKBKdBOK4kSvbmi60Xj+ImdkW8ZqSBU5aT8A0Uy YsNlx7OWzUTBnbSQiC9S6GkVDzq61bKDE4YTc36w6npGQwfI6aDvzvAdUiFT7Wpc2u8G qYxg== X-Forwarded-Encrypted: i=1; AJvYcCW2xkvzROfIjWH5ppffYYBn9go2V8pdAOrTJDCMd8agKDOUsw11f8FEwJPv2YyYec95dUWgV8xuRCJvG74ysZ/rPLFQ X-Gm-Message-State: AOJu0YwixtBQhN95v6PBbTNbYgf1YOkdCXXo5B+lTsn9nUq5uYN/qfZU s1NAGKtawUDtG4TdYOY7Cv8CbvDRkZ9Hccc4PRnNPCapI1MbAWkmULC+sA19E61YCBwnYEcUOZW THeyMkA== X-Google-Smtp-Source: AGHT+IHbe1DxlHRAKrzSKiVOtakxA6Q18A5QeFHX1nkM8ma5D0AnWniiwkUYIfGXxIcoemP4HQq1Zn/FTkGf X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:100d:b0:dbd:ee44:8908 with SMTP id w13-20020a056902100d00b00dbdee448908mr615704ybt.0.1713248151392; Mon, 15 Apr 2024 23:15:51 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:19 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-4-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 03/16] 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 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 | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 2d5a275dd257..3b1f767039fa 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1398,29 +1398,21 @@ 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 +1420,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 +1429,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 Tue Apr 16 06:15: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: 13631319 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 57FE23C48E for ; Tue, 16 Apr 2024 06:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248155; cv=none; b=BcFNCcM62Q8FfBNt0hdToLdIyJkFFZ/ee2Qc1l4YEVbSQql5Tl/xk1xhQE7VLrduqAlU07nujWpu8dxwWJetBa9cjywkRGUdeC0T30e+N/IjLG3RouBYWk/HyV7aIPwqzIaQN4O04HZ/KDihupX+yzCg5Y4TxpQYVRjnIJhbgts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248155; c=relaxed/simple; bh=lLSR9Zme6R3eaZpgcappeWu5jfr6jnHFV6BaEVpUHMk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=OUonCbdCDMc1UbyEdkopqF4Fec/nDNkPozMpQ9gFDT65FB5ZKXhkzRmdTFjNxHOJfR2SoOs3dIMzQ4O4Vq7QW5j2VxFMFyruVhfgeLr8CD2RkcNM8zH0U9x5fh2jAgF/JI+47kzpIfLibpy1LMK5q3Yl+8v+7WDT5Woa8VfWhhA= 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=Bi8kZoQZ; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Bi8kZoQZ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-615138794f5so68039807b3.2 for ; Mon, 15 Apr 2024 23:15:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248153; x=1713852953; 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=OoQwW/NovL7e2tX2zfVq3KY3APeKDAqGoyhJSMq8amM=; b=Bi8kZoQZjCB2V/V0PplZ6NWHRF0PNQ8XrwjwDQMY4xt+cbR+96VttCc2QwHQ6sW92g Z4E0vPbWXIBVeoysmXe6mOEHVgg37vcLDwtbrmcroiu1BE19nHxoa4htzMBO7rz9ggjj hIONz7dl0L8LdXXVY9EuEEg4SxWrkrUjqZ+Qc+LAvPTzPNbRb1RZRzWTSctfWVIFaQfO 6LyJowHdGDj1MbznqiklJmLMZOUFXUNT3NAv8ZSmnwl8J6/tOB6BEE3m6PdNvj87oF+N h1J81C6K1XWdTsigKh374hrRlqEOIeW2Y3Xv1LIv8bhlhJLwbZziU/lJuLwVd298GTl8 O7NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248153; x=1713852953; 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=OoQwW/NovL7e2tX2zfVq3KY3APeKDAqGoyhJSMq8amM=; b=vin6dhcGlO2JkVvztaR8VoFG6Zo7SPjHEU5RQhMlwxdRB1RWr8J5RYmD38G0MWJpav aJXCxSLp2arJjwTUEZmpjORP2Z+aoE0dyIqn2zY5Oor8T9qmj9m1dSBoILW8jRcgGNH9 NQfQnDDfz11tQi+zUi7XPCBnYn35Ov2FU7Wup0h6z2uKCu6Pn4pgYTm6Uwvmb8+wt64p FQIy/DwnONDbrmLLuF6QIxsuV8a4ADdDKCzlWl1Fmn+itpuW+WAUdgJQsujZD1Q9vj9Q bXHileYwiObNOFgkR3KAV4dywieoIa6RcJ+IWMZKMlx1jwMkiiB0r/6UQJFqsn/fUJyI tkpQ== X-Forwarded-Encrypted: i=1; AJvYcCXXmRED6WBqw0YbjCrGQJqX+6/QYiYgYNj3E5Y3nZYKknjMfqVwvp02fZYyByufMxLcMHCzj3Y3uHg+QDkoDAy39nY3 X-Gm-Message-State: AOJu0YwGORPnlh1kyAJh3oCHCopdSINGgNWTTAOQnvBtUWZBf3h5N/9Y eznRAsUmkp8NPtgDty3XtCs84gTnKE8DkS/xwwgbZ+197hviCbk1PUgMRWy/7rCrKhUvyJZYzh8 6UfOojQ== X-Google-Smtp-Source: AGHT+IHOfFNw3FUspTDzag8H1Vs2s4R7H3wtDbw+0o1oktnOEpdBiBC3Jt+NP9eC79ubMPCeMtZbdbJRfZUt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:1027:b0:dc6:dfd9:d423 with SMTP id x7-20020a056902102700b00dc6dfd9d423mr968428ybt.3.1713248153495; Mon, 15 Apr 2024 23:15:53 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:20 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-5-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 04/16] 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 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 3b1f767039fa..39548ec645ec 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1611,7 +1611,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; @@ -1631,22 +1630,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, @@ -1657,7 +1643,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 Tue Apr 16 06:15: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: 13631320 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 B1F7A6CDCE for ; Tue, 16 Apr 2024 06:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248159; cv=none; b=u2P6vhfGsJomt/YHKOGG6pWhUF+Z2MPXHLORIHVSwlPBWI9zWTaekQRoXjM9ojqBXyeWuap/jmXKbx+DLziPtaccltCSZdZ+lT4Ssj4yQTWlBlu0wO3rU158H4IcFrFVXtKnI/jrjRH8Nhrf4jeY4bvoqYwKn69mRPj0rm5BTy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248159; c=relaxed/simple; bh=jUPnR8Eh1nwHTyI5wvU5SHFzAhN1eHw5S1/Bwquryzg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=rbsDBya2nOEkX8EGc96EZuPB9y2BYewgttXtJI1SEre3pbLBp6bVNwziZ1n1TNFHG8k6J/uBOzrxGDwfE2STzWr8JKrV4R/ZMbq5Vg2OxON8Hxcxmfj1I1yqukuptQq/WvTkESDnfh700NP55WvJa/MC8/J507F9t/Sy3IS4GOA= 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=T4zthJnQ; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="T4zthJnQ" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-610b96c8ca2so67233507b3.2 for ; Mon, 15 Apr 2024 23:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248156; x=1713852956; 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=UJgB8sDKrPml3/XRc3D6gD41xE7ASJL2MP2+Oe/niCE=; b=T4zthJnQjIgsQSTjSiNfDEarAik0KXjq92p6b3EBIeUPznZRCGJ4Ar/gsCIUiWkotW l6t5+Zji2uVxVHC7mPk/vGoTeOHyf2C0WSmpPNhDsudRIp5QrHfIDqmdqcpCPw14lMqs fpGRN4h6vnZWfH0OA56y9WRVmS21SML5rQDx/gXlzLAsoFbwoQk8EixnBRw5d7gYAzSA 2bCM48y7m/rBQWwYisR65iZYGpANvn6zJp4HAm8WNrxTmPeWxmqJT7ztSLIKvz5nlEkJ GLcTiW7Wswmdn7TXiRDFaW/89eOzdOyT9qpb9AobL/xZP+8cVCzay3ZwGrz0oDkY+BF/ RZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248156; x=1713852956; 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=EtEfNhM1TgD+AcCIrF6ygXEVc8wmeNJB+qOB4t1lghRFTOpxqXF/AqmuDjfGBqIoia rj/jNa3levKGHz9RQz6qWnCnvY4+1nNk6+KcRUm+bokvLHxRGwwFlkC5nVRRGlsIJP4Z NDmWTsFIINnoo7hKh++REJIsv+4jmLjVtv9l3TPlQPgNtwIPz0oj5AM5tB+GMG8nmnVS 89ihJ4f/anXKp07YLQsy8ty6ijsyXiqGQC0LW1rzBcqXi8HAee2y3wuVWDSea9cWGIzk iB0iKefMmo9TT0kAF7Rtkuk7U2CazRm+kTPRJkpyMPJ1dQ0ix8Dr8iA44NTpt3chwtZJ r+Tw== X-Forwarded-Encrypted: i=1; AJvYcCUXhX8Dns/wOwTtrclI7bBOyeWjpZEh8faVy1nKuzUK/1WOYVJBvuDNx+2V4+qt9oI0ubwKDZMF7+FiKC4mOZoOk5uo X-Gm-Message-State: AOJu0YxcKoyjzs6VuXh8gGQZ7M31GtMk2OZX4En6dtvz3g1ZhHjJKFVT D2dJlCv/fRXymSGW4MNRhstaaY7lWERZ+n3jN7vZa7l/6KVjhe2s4KNZ3leZ+tZ4gszWAhvEOmZ /SqoiDA== X-Google-Smtp-Source: AGHT+IFvz2/ElMb8sqisE4iRWPUFBqPFEJev0kX5N83qt2rasL8K27n6w9ssQTNUocmaX8KnE4uhTcFVZFa+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:1509:b0:dc2:398d:a671 with SMTP id q9-20020a056902150900b00dc2398da671mr3887166ybu.10.1713248155750; Mon, 15 Apr 2024 23:15:55 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:21 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-6-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 05/16] 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 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 Tue Apr 16 06:15: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: 13631321 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 F2AFC6DD0D for ; Tue, 16 Apr 2024 06:15:58 +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=1713248160; cv=none; b=CgFWVLT38Rii+UeEKr41Qu32i4k6SNYHLOqZY3aPX3iKOcBRRm14qfZn928L1BiaJkV+8mZj9sJkVNKOPBJTJ7Nzz8I5HRGpY1wyLn1plUViZivA+qYl3Ng8rdQurRuKq3qo0PqY2egETXj6FPt4nWT0Jf2ymKbueg2kfrkvyMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248160; c=relaxed/simple; bh=uAsvZz6qZ6F1ygzrsRJ+PGu0crnaXT8b4/31RPpmBkY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ofwG4I3t85F5bd0KiMFztGAlcuYqeDPqFOGOUX4H0Dc66jepXwcr4kTruYgpPEeKZXEEUindXs0R3q5en21Gt5oFnT+1dhH1HlcftVX9ghb6JqccYdfWkVMpzeIeUYKXBzYQpTA5ob+JSiTmB0XSI573EpguTaM6doWyrxQV/G4= 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=yBNYMtQx; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yBNYMtQx" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60a20c33f06so46127877b3.2 for ; Mon, 15 Apr 2024 23:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248158; x=1713852958; 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=k83zolc/tumM7XBpJQ8EaNI+D4ORxoBWKEwoUmDFaek=; b=yBNYMtQxir6VYwDh5XjEXed/iwXo97ERNTTpncTAZOspIy2szGImrLF88elDbKUviM ljCMXX3zgvYXijCpyqUL32YIMSlIFMHf9hFKjW9R3SS0jzjTLcPkEXNDYIjVwQByANUi oC6EWekCLNvoy7DKFbJRdInn+3qIm43Kj2xAky9PE7jGH2BsiXdQUzPxMHqJ0BQOQjDc BvogPfFuLHH6HlmUYXGt9n0YBxgIMZsvgJ0SNjb270ohsmqRuuORHlUQI9FcxC/8YcJu XwwZM5b+NdP8JU9mC2gBMxpNIYymWBeDcub0nKZjiMnQ6t1rZrXhoXNvEpvz07xjh3RQ FoOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248158; x=1713852958; 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=k83zolc/tumM7XBpJQ8EaNI+D4ORxoBWKEwoUmDFaek=; b=aaktRKIQZx5i1bGZ4giybspltuQZieRvGo5WQ6EjTPUEuvEbguSEh/z9QXzaATCPQK 2AURM7bBaw9ISTqxfJpyQbrIvzqdXgocgzXPFuzO0tx+CdKNUHGhX+D/LFa6GMlkri59 c2vDgkasFYw8LCr6bFKHS/TnmWqFJe7+ggYTaVU3/HT50OLtCvLWjo/juDTVvgLn+xmu EqqmnQOtiGhhX78HN+vAD/yM07PkxMpbYM/5hHrKbL2CpGDsV/hk+3GUUY94S2ba9pP8 NFsgpugOC8k7/UPl6dl9xJwKzDB7fvdtNoN2XfR9umGnZD6aeuqCypl5nxeCCQ3BGBrL J9Bg== X-Forwarded-Encrypted: i=1; AJvYcCWjBNa8PWxjDShOkKnrzRUKJYqKF3i3SerFjy48gSLrtkd1hNqovZsskI1vEP2iZkNpglqrii59YDPdbXg2ey0zv0tJ X-Gm-Message-State: AOJu0YyynCknFWfcyQ5xTPvtN+Mp2apbvtIegyogAb4J8V+q8yuVrcos GWwAzjcgmyYFUDFjJLHdubCH0wFfHQ6VG4MVuyCs39T9kGEQLeccUKBZMzgp9QjzXgI7vnao88d q+126lg== X-Google-Smtp-Source: AGHT+IEpN/W9bPJeui69q0ZUQ4qSKte3BSaEqlY+RZGoPcSYQ+AbbeHfa7sJctYDOzeLW8y3VSjctuWlZy+r X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a0d:ca07:0:b0:615:27b6:7624 with SMTP id m7-20020a0dca07000000b0061527b67624mr3084038ywd.6.1713248158096; Mon, 15 Apr 2024 23:15:58 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:22 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-7-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 06/16] 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 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 | 39 +++++++++++++++++++++++++++------- tools/perf/util/parse-events.h | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 39548ec645ec..1440a3b4b674 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,12 @@ 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 Tue Apr 16 06:15: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: 13631322 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 4AD286DD0D for ; Tue, 16 Apr 2024 06:16:01 +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=1713248162; cv=none; b=IR6XTxqx3Zmod3+j0UbPLl4I7QW+wajfS8B4Y8IRBX4z/WVX5Yoj5ioDFxgLdF0wcjqFAHedjLZb7JBLDmoORcfR9aByM3YyGyNEqIJZTxB74SVC5alP2mxnRPHAVmwirC5CGWwyfRBgErVRLMRHTKeMqj2W80PA8O61+pKJ/6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248162; c=relaxed/simple; bh=lOkYV7UGjD7uAxaUJi//kJNpEQe6aaH4534slbGiVvI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=C5fphLrirqyE0vsRXWCWc9qN4wmRsHgi/sv54DIDF3PIiHNglzWubFpcl2d8ucoeYuLnN2oCrs3P0BohFPGCoQH134vMJjH0Edlltd8h1xo4SL5rAQZ3w2R7KQQY2Q3xdEo2+8lsNES6suXo9cn1AQDxwIYKoCXvaNeB8bhbEPQ= 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=d7dsJHEw; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d7dsJHEw" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6150e36ca0dso59251557b3.1 for ; Mon, 15 Apr 2024 23:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248160; x=1713852960; 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=ykRC4diMMUuCn1traUy9Psb15efHJHW4XPDrKAUvlVg=; b=d7dsJHEwoGbzVJyhb9z95qeHkUoM0lJlG7dgYzjC0nKumwiF9wshNHwulLAaALs1y9 jHnga1kxnggAaAfEoNWXwaKwUVOtpx+NdEu3do6aCIkaz68EGsRw+Pup6+YsdCAqIUAH XX16xlHkYQk1TcR0INwF2gq7xiR6zfiEagUKEhCLgnaBx09kT7/HQ8DukDzbGNU51QXz V62WvmwExH/b+qncoP+EujYRak7QHyReivee7q2NmZCibjFkJgachDStOpWYHtsTTgxS 8iUy88wXyBVm4hzDWcHFk5r+GwXwCCkeh57Qo7RRqZfm8sGfvOLv6/xYzgqFdWTBzzG3 /OCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248160; x=1713852960; 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=ykRC4diMMUuCn1traUy9Psb15efHJHW4XPDrKAUvlVg=; b=isbzMcDDLT51y8UX2P+3v2flKr03EgpEx2sSUNSbkoh4iwbad1tSoAaskn9q2tH3eO 3ApmK8xIkdYh8ZnrxySDnPS8tMipnry3mYKFgN+4BJXuxELnMS3b3W15Xw4zBF8TW/oJ Jtlg1ZNygU3NjU3gBqmDS4n97ZilkCY2zrMOsMvugk4LH+EAiJNgbi10i86CF6Woug1G nWFc5dp6q4ImJYgkbrI9h+L58607oWHf7XAaxK7mFrpzvMx9pbvAyVUDfw8phmKiT6mu 83cKUuA0VCUx885Brw8XEOhmarOfFrvYPyeJfV0msrD1kBIJ0Eqhx7r7T/VA5aAuVZaP cXeg== X-Forwarded-Encrypted: i=1; AJvYcCXXTXl0A84kUfEqi6E3ClwsdCulLT/HX30Ur/zXNs+6k+YmR9ExrQOoVeKivzjZ2hl1uQ4rWtP6Gnyos5Q2UexCYwmE X-Gm-Message-State: AOJu0YyG2pbprfqoTv2GtB5uhJgTWX4unUygWkwmtfx/ubzv7c4vGm8X JsGFfd5W2tBPXumvDYDRA/G8mm7m8MkKYBivYlehy6Q4fYvVdgYpDzRlTXK4ftcZzacv49XGvW8 rS+WQgQ== X-Google-Smtp-Source: AGHT+IE1BkM8u1uMxF/LJ+oAvk+/Ck61XwF1nrFOd9+nZTm6s22+JsAiR5ckes/nbIKLU3LTA7VFsn18XwaJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a0d:d44e:0:b0:61a:d0d2:b31 with SMTP id w75-20020a0dd44e000000b0061ad0d20b31mr1012904ywd.3.1713248160541; Mon, 15 Apr 2024 23:16:00 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:23 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-8-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 07/16] 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 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 7764e5895210..254f8aeca461 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -603,6 +603,11 @@ event_term } name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE +| +PE_TERM_HW +{ + $$ = $1.str; +} event_term: PE_RAW @@ -644,20 +649,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; @@ -710,18 +701,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 Tue Apr 16 06:15: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: 13631323 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 B1F8271B50 for ; Tue, 16 Apr 2024 06:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248165; cv=none; b=mumekIMY9d1VsZg1cWCLEMtEfypBHIC4no/4heubwPeVRTQIgxxCSWQpubrm7x4UgFLY5hq/Zw1RzBaIkG4+F1XP+oDlmOTlYKzXRKGmfdx8GxFhD6xBXHrM4eGGZZ5vSwi1L3hj7yvKvbWdoSLxUefbOoJ4MjSgwauqR4LJCNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248165; c=relaxed/simple; bh=qTcWKln4Bv6yJVZEBzUGSZ6Dxr+KFG7fKA4y6PwELqs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=PP5vg90+VFIZ3YqS/VrCbfWB3atsnf2GC4xlXJE3BGgOxcRNzZ9dCL4sVmRh9Ey4YvXrbyGd0rLzXa3rCfwtB+H3fH31WI7yUT0NcBZVANPiuULrv5ZtkdfrDN990Su1PoU/HGMvSSuHa7rlvsj5F2hmXJI+bfB65NeNwfJxNc4= 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=s4SjUfhK; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s4SjUfhK" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61acc68c1bdso16319767b3.1 for ; Mon, 15 Apr 2024 23:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248163; x=1713852963; 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=OT8KC34fIpe9dV5ekpHBVAc8u9M7U+9LMtZzVFuRsJU=; b=s4SjUfhKJyRgAT6fUUjZdmGIc4WwhFeFWN5I5apS5tOGuGq+v/Xg+w/JIzyZ6AqNyE Pxvxr0+OGCENQcsegXFnbl8wg6kZKp6Mo08AuLKpXRh9BQY0woEkMT0ARk0zG/RXTq2v i4eN2J+w1gNsRSzc3wbEvJLXl4v/dc/fKDEgYpn4abWZ8WIPizvA3PTgqnvZQ70lAUN+ IPtaemc2OHLIPiFb8cOl3yrvnqSIRybYpnJg9ECZz5rFj4LPJCZdCGfjz6LxzGKHmKxS VWRYRfzio6pUwlaLOjP6yW8FHfmlDfcmIQH1SkprjP34j6+aur3B54+0rk5agCxLoAuI vJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248163; x=1713852963; 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=OT8KC34fIpe9dV5ekpHBVAc8u9M7U+9LMtZzVFuRsJU=; b=LfxYofeLSXfZS7Zk6BLq5B2XRzUDzmhDGQ8WbCCBcYE8Nfx/oHK6s8HY2SaTUw3ZaV Qn90fzhli1sNUevVGOM0G572ZDaIu+QIHJ2XvSZ9RlBjtavrjBInVBFQwYJomlCjcMrQ 4dapn8+MF/2CMVemDRgIgBmmo24TFxRlFwz0+cdnC9gkZh3noWN37QOibkSBpwUtq+6l AUR0M8xrQSGlMLi7G70bLncp4fDND83xh0lD1f6LjlBo95AW0Df8WZEvQKIfLhDDowtH TvIfDxJzoMbAw7ya9SpiLrzmWjHFxRjnQqEnEUsAQF8vo41cH9rFBHqBCYKBs7NJPIgM LH6g== X-Forwarded-Encrypted: i=1; AJvYcCWnck1V2TOE2cl9GEHaBK9IRoFjHLQG+xE1tSNiAzJPARVFRnhYZUHnJiR+tFLFHbvNK9/NQcWtKQ7E7cx455f1JgVc X-Gm-Message-State: AOJu0YwCJ18n0WXEZO6M9RHftw5Sa3bwVb0i1PIIc/qmnNIpWwLys0u7 HAVobVWifbsqEIkPxZE2gL/wz4+O8OzDx+/oRctWRG/WC0/+xRYfNSGVEEiIULA/EuowOkVUh0R okwu7ow== X-Google-Smtp-Source: AGHT+IFBtPJYigu1UNX+GxG1HR1ZdO9/jLJVgWPHL5U4mEa5M4iyJ8CDK6Wzt09A6xnIJAoSUf1Qycy+LsVf X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:c0c:b0:dd9:20c1:85b6 with SMTP id fs12-20020a0569020c0c00b00dd920c185b6mr576115ybb.2.1713248162866; Mon, 15 Apr 2024 23:16:02 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:24 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-9-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 08/16] 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 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 1440a3b4b674..1b408e3dccc7 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); @@ -1108,7 +1109,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) { @@ -1121,7 +1122,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; \ @@ -1325,7 +1327,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); @@ -1361,7 +1363,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 Tue Apr 16 06:15: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: 13631324 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 3280C7FBB4 for ; Tue, 16 Apr 2024 06:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248168; cv=none; b=eCUFQ6Y0g3p5npRYgh+Tviw4+REFo1HeHY1ejsE8OIHETmFhOVNoLS+tXV214UXI/zMsfzMZw0iddQundQNU7soExSfjEzVL7OuuJMMjsUVjTf2WfQX9Gp1XCsX4Sa6pjFZwGA0hubaCNlQEPwRc2QL5AhpPXkQoo+kehq3X9GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248168; c=relaxed/simple; bh=41p271UID1U/EgM4ZyNia92qrKmgbbms7gxwSefAdeo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=HWD9OohfmtjQicPm5PhuBRzjkMfDaBEPNo/wc9rJxkGQhns/UBOpQRTHT7TbjFhrws2El7Ve8M88XhQW8oIuPkvVlI6CSkgSbwE0pmC6zM2TyQGgeC/M0e9ZmLLIwYte1ltdNnANQz31b4yKu57BWNW4yNEfxh9amVO1nRzhkRg= 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=rAUfDOcW; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rAUfDOcW" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61ae9ff0322so13825887b3.3 for ; Mon, 15 Apr 2024 23:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248165; x=1713852965; 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=C36r2tqelRWs6L7r88/GKNbOUewmK6XvJFIwgoq4Nzg=; b=rAUfDOcWzpre2OTYnj86uNEfgQMOLb+cTN6ch8Kd8I4G1fFs6dHMqj/1zC5NL4L3Dx QSID6tt4Ae806OLjYUsRYfIyHM5ZK8oVJgGdqj076qIgWjQenFU6MgVCA7wWaivfzgmI jiWmbSmaS1+BJ6PCqRmC1B2NeLQ2PI1RXjPeN6h/U+jJmshEdrVFspmeowc++x8ul6M6 3EIBDtg+6MnlULtQaz+8O2CQA09VTQHE/ADKBTOx5sv1DLNn1h8luI8U4PlmmGurj5y4 izAO46QeH1uuIjuY5gUxy1hgdNi5jKcbqK59Ig8d7udHUoY6qzM4Imbas3q7zQirhQ59 kVag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248165; x=1713852965; 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=C36r2tqelRWs6L7r88/GKNbOUewmK6XvJFIwgoq4Nzg=; b=VjbJOOgvWZXvLJJ3tAifAgHU7oAf0DR+OLoxcqU4as5cLiAvHaynq9NAVnc0ftuGLX T8XOA579aKIRDUTi78vRpPbEPQvBysYNB0oLjxlAATOnwzOvXJ8SH5gcngF5Tc2LH0y5 gEw1SefS9PeZIKa5rzEHjmdkPXwXR+Mfskbs/SOgZtwxN72w3Dewj1Eyti5a8ajFvBgz 4afZdcleR6ThNI2BDXDxxGi/TQFhzKyyQWLBANxiefgbOrkJV6/xRHMBtbrbAHxMqtjT 3GT1SrByw2iRpYYetjB2LVzPlX+NLdsvx767XIKj9R74kKcY1q40s25UNSOEBZLaZC93 RMnA== X-Forwarded-Encrypted: i=1; AJvYcCWfzSKcITla2WO1mpnxXsZuMRCI6Jfxp+W5EAuBxlmGVaoa97jXbsfqOwYNYaMSJYHf8wiMkhiowkx1+RH0VHBu/qXw X-Gm-Message-State: AOJu0YwKty6PWVtnVNkV/7jlaw3f7WndNGTOTwFIfnKSvp3qVy6TAhw5 QN9l+5fEeKlUNmiVHBk2Bi5lweIcI+YipddFRNOio42xW5Sk4Yo8vH5qxjNBsxTDgWd173DjBf/ tvkpfpw== X-Google-Smtp-Source: AGHT+IGfI9hI86qBWCQ9iFMpUcMIcQ8Bvb3tiAz+gLM+yN6JgYTHeFn6UJJFxzvv6MAOCca+nbvzL+9wRP00 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a81:a056:0:b0:61a:d418:59bd with SMTP id x83-20020a81a056000000b0061ad41859bdmr1097020ywg.10.1713248165432; Mon, 15 Apr 2024 23:16:05 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:25 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-10-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 09/16] 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 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 1b408e3dccc7..805872c90a3e 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1543,7 +1543,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_) { @@ -1551,8 +1551,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; @@ -1565,15 +1565,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); @@ -1604,6 +1604,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++; } } @@ -1620,6 +1622,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) @@ -1673,7 +1687,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 254f8aeca461..31fe8cf428ff 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 | @@ -289,7 +289,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; @@ -305,24 +305,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); @@ -331,18 +352,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; From patchwork Tue Apr 16 06:15: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: 13631325 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 C45A784D26 for ; Tue, 16 Apr 2024 06:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248171; cv=none; b=FomL8haQRZkFnScdlTdcadIK5HvwqXRilMBEMbf4HHl7qoPAEQakBscedaLa+wgwMazXrIKK0wqQSQpBf+qGTpvAMknE8q0rwyOlGGylLkuIYrmtW2bLwwg46R+jz00nxt0lofavowV8hp9ZVar1b6Qo8uBqxZjEaigcOIpe24c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248171; c=relaxed/simple; bh=O8OUGtb6bTGqfSyRVlfSK5T8OB2WkT+9dGZAqdqh/Cs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dHrB8kxnXl3H4yT6qiXqn95il3Bv00CNWiBEqPXFzcdjqEk5wGNSsYTJ/wzDVj8WtSqx3I1hGY46s0iqH0k5zMpFHjD3TBpi2CzJ1vgBfNp6vucygvkfWWVCKDnxY4fzVGlOZi12ti0LIpSsVxVODP2qWBq5nLtvmSKA635o+1I= 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=MxdiMkSt; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MxdiMkSt" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61891efba06so53600917b3.0 for ; Mon, 15 Apr 2024 23:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248168; x=1713852968; 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=+PPi7agW0cdqI/eav98kRS0rctCNoN8MXcmmiJuSnV8=; b=MxdiMkStihO7e4lTLn3RbwoirBdNzvt5ov3NOwHLmnM6Z91/xTBJKXWNvoeS+ww1lM BQJJIzlhPn+/OSHvtMeiKwoZmM/mQnXovIH8xqJvZigGu9sJ8/lPhwEGSwqJJVeHA8k3 CkRBlZQTUUHlpgFW3SYk0PlIIjAPULZO9FatnbmNRJzTdEcPNmF+DOI0URQjkbQPDvzK wW9NKS9EwnLNOR3ISpRNw725sg9H+9B9ONerKHIDoLjyWr3XjjNJhbOcpHzX+DQqKJWI oJcwIMCFVyshepxMkdBFoGSXyC9GSPaR+DJrTVfPygsJc7nF/a43CtmXc+gM94DrdI63 gOLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248168; x=1713852968; 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=+PPi7agW0cdqI/eav98kRS0rctCNoN8MXcmmiJuSnV8=; b=KuobJkep5ep5vuV8ZIek1ZnuHIvotjnmkZDZjD8SMyt5ZQ5L7gid5NlD643wzg08jT 8aGgUUnw9e+j6b8ka1P9cyFWIThwqhZMpUfh+njASkVC8u2XJ2rqBYCOGNH8fMUskSBY LA405ISFl4mBoA2wNsx6ZmaAZFzSQGLUQ2ik6PPqeEEC6i8r08U3CZW6NZ3i9bk7Y6Nr UwiRaXQrts2LNY79LpeBgxMiHUvd1aX3bLwOYm+lUSDmV8FKTfJg5wmKRomE7r4BA4W+ J1WyTNyc6G2+jUtWa1ggu3RpeIxyz9x2lqJL8+thgK8unfoOnUdrGQOdI8JSm7fzOZQ2 Mjtw== X-Forwarded-Encrypted: i=1; AJvYcCWEFFfIExuvmLazf1q9IjgzkBviUdPhFc1K+IQ38dglEv28PttVZqGEsYVWNRL5nck9AcoOHZvRAwRA0gsxqd36awDN X-Gm-Message-State: AOJu0Yx9ClMFDSAgmFUHsnLZC4oIYqx10nKK920CGAS7uu/EhEX6WsED sgfKbi30yxulOZqkkp3pKigoWluNIw8qa+b3LMoNDQMGsPEAlvP1CbVhgTvREDjm7ttwO+rKQCa qkxblwQ== X-Google-Smtp-Source: AGHT+IH2niG4HLP7/x+KA0mPGPOc5Cee9M3cvuF12USU8FSK8dwpi2y2t4/mArka5E1ZbdSzG8VUZRYDDFLw X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:1501:b0:dd9:1b94:edb5 with SMTP id q1-20020a056902150100b00dd91b94edb5mr1355225ybu.10.1713248167928; Mon, 15 Apr 2024 23:16:07 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:26 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-11-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 10/16] perf parse-events: Inline parse_events_update_lists 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 The helper function just wraps a splice and free. Making the free inline removes a comment, so then it just wraps a splice which we can make inline too. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 13 ----------- tools/perf/util/parse-events.h | 2 -- tools/perf/util/parse-events.y | 41 +++++++++++++++++++++------------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 805872c90a3e..7eba714f0d73 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1720,19 +1720,6 @@ void parse_events__set_leader(char *name, struct list_head *list) leader->group_name = name; } -/* list_event is assumed to point to malloc'ed memory */ -void parse_events_update_lists(struct list_head *list_event, - struct list_head *list_all) -{ - /* - * Called for single event definition. Update the - * 'all event' list, and reinit the 'single event' - * list, for next event definition. - */ - list_splice_tail(list_event, list_all); - free(list_event); -} - struct event_modifier { int eu; int ek; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 7e5afad3feb8..e8f2aebea10f 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -226,8 +226,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state 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); void parse_events_evlist_error(struct parse_events_state *parse_state, int idx, const char *str); diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 31fe8cf428ff..51490f0f8c50 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -125,6 +125,10 @@ static void free_list_evsel(struct list_head* list_evsel) } %% + /* + * Entry points. We are either parsing events or terminals. Just terminal + * parsing is used for parsing events in sysfs. + */ start: PE_START_EVENTS start_events | @@ -132,31 +136,36 @@ PE_START_TERMS start_terms start_events: groups { + /* Take the parsed events, groups.. and place into parse_state. */ + struct list_head *groups = $1; struct parse_events_state *parse_state = _parse_state; - /* frees $1 */ - parse_events_update_lists($1, &parse_state->list); + list_splice_tail(groups, &parse_state->list); + free(groups); } -groups: +groups: /* A list of groups or events. */ groups ',' group { - struct list_head *list = $1; - struct list_head *group = $3; + /* Merge group into the list of events/groups. */ + struct list_head *groups = $1; + struct list_head *group = $3; - /* frees $3 */ - parse_events_update_lists(group, list); - $$ = list; + list_splice_tail(group, groups); + free(group); + $$ = groups; } | groups ',' event { - struct list_head *list = $1; + /* Merge event into the list of events/groups. */ + struct list_head *groups = $1; struct list_head *event = $3; - /* frees $3 */ - parse_events_update_lists(event, list); - $$ = list; + + list_splice_tail(event, groups); + free(event); + $$ = groups; } | group @@ -206,12 +215,12 @@ PE_NAME '{' events '}' events: events ',' event { + struct list_head *events = $1; struct list_head *event = $3; - struct list_head *list = $1; - /* frees $3 */ - parse_events_update_lists(event, list); - $$ = list; + list_splice_tail(event, events); + free(event); + $$ = events; } | event From patchwork Tue Apr 16 06:15:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631326 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 3560284E0D for ; Tue, 16 Apr 2024 06:16:11 +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=1713248172; cv=none; b=S0NVqutCG9EGw3FdHGwXeTMioS9BW5Hk0KJ/wOOR4rJkfV8ZY14HkaKbHtnaFqkzUSzKrpMsh90l0MNDoECwBvt9QPzLrSu8Wuh6k6CzttqXjzLyNRGkkCpl1+45nrGM9OnrhIbG1msk7JxWSjUPib5I+qG4UPmOlk+/txNdDfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248172; c=relaxed/simple; bh=eftodLo96oKKWTTBK2VOKzkPV1r4wS9wxU2SLYPC8Eo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=e/Fpk2DIJyflxiPAUJCW+UMjzlJucswNrjlPvvNeoeS7aaW2cnVonDapQjI8mbcm3wUKvWdnrGnofK51c0tmH1ag7t4oK3uzmbVusZHkJo5lL6YjWOLdASunuJq5sSuv+MjWZSXII2PGvxQoJyLAgjmo15rN8w3rl3qxug6MQ0Q= 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=l4ufWgn0; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l4ufWgn0" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ddaf165a8d9so6490549276.1 for ; Mon, 15 Apr 2024 23:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248170; x=1713852970; 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=boFz9eIMJ+Fb11V/P0+sRNFH04HSu2tXThEFb/mBZSs=; b=l4ufWgn0MhCDqXGTY4M+/K46oVdjcrnyp7udcxTfCbTxbiz6JHuVM3X7jnH/Ipp1zZ MFS+GbuMJEhjzv/CHSIORIittQBgSFk9EjM5RkevL6aR1VCnqwXL6IohwbLjGP9ryr16 S+VNrHP2a1slYeT6FDyWGzQNF1lak1gCGhQYV6yntNRoNk1TpVDhmHg8Gx1lTekHuZjn fQE0PV+U8bNAisUThsyFCsE//dj0BrFu+f5MzxDdXwXIFnIsUeW+yKVf/Dcb7VkeY1U7 6o60Id47PMn7A21AgM3Oevyu1oR1iS8VF31h48U8YfDGrojUOmcqYpY3NAQCOa/ymc7g DCtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248170; x=1713852970; 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=boFz9eIMJ+Fb11V/P0+sRNFH04HSu2tXThEFb/mBZSs=; b=J8gkxA4cuHiHcuqQWo+rDQZeQeDb2vqs/5u9e7ZTPDTzAfvja6YAfBf2Zs6TB4ARbF XVksL9VKoXokZewNEsXXgWjVG9RiIMtIOklxmiWtYb0wOmzLgJ7tST/w4CpNLtP9uNyj UtsyShdKMBGYdNd38c49128bVrasLnMIwAi1ZwMLwemeEFeSdQNOHqumSQv/9C7VTZVG kfAcfOuiWn0PHdQhe8YB0v2G/QRUdDAn4iHR9CL4LV+DcFz1CaYNmCmAGax6fFnZcomu 9j7k6z3zni/Ild417LjcpZJlyNRSQJu+eRNGQ8HWtfxrEwQQyc7CD2fG9DBsE4bc/YYP UFSw== X-Forwarded-Encrypted: i=1; AJvYcCWFF4XCnsCjOJziJHwN3ka96y6o1cpT1Ou4x8RjmiYzqrE0diR/td0AUG8cgSxQNWnlFjfX7VloS+90tW+3V73iL2bD X-Gm-Message-State: AOJu0YxF45wHUlLfBvRmaXxmqUuhdb9wSAEjYlOEiuyT1J2p1VqLasgj obWpnk9vYzMuShUPBBiHp1NwLE0Rh+H0MGjfngDtxbWRKiTk8rVLshtHe4YAuFEOoeu4ddSHCgR 5hxgh3A== X-Google-Smtp-Source: AGHT+IHd9B6qnuS0vDMu71FLmzqF2ZG7fcWnX6FbkHfRo5r1HZC5wXOQPvp4ubEYNvo/IQi3a4rVn7px521z X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:c07:b0:dbe:a0c2:df25 with SMTP id fs7-20020a0569020c0700b00dbea0c2df25mr1501367ybb.8.1713248170374; Mon, 15 Apr 2024 23:16:10 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:27 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-12-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 11/16] perf parse-events: Improve error message for bad numbers 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 Use the error handler from the parse_state to give a more informative error message. Before: ``` $ perf stat -e 'cycles/period=99999999999999999999/' true event syntax error: 'cycles/period=99999999999999999999/' \___ parser error Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events ``` After: ``` $ perf stat -e 'cycles/period=99999999999999999999/' true event syntax error: 'cycles/period=99999999999999999999/' \___ parser error event syntax error: '..les/period=99999999999999999999/' \___ Bad base 10 number "99999999999999999999" Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events ``` Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.l | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 6fe37003ab7b..0cd68c9f0d4f 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -18,26 +18,34 @@ char *parse_events_get_text(yyscan_t yyscanner); YYSTYPE *parse_events_get_lval(yyscan_t yyscanner); +int parse_events_get_column(yyscan_t yyscanner); +int parse_events_get_leng(yyscan_t yyscanner); -static int __value(YYSTYPE *yylval, char *str, int base, int token) +static int get_column(yyscan_t scanner) { - u64 num; - - errno = 0; - num = strtoull(str, NULL, base); - if (errno) - return PE_ERROR; - - yylval->num = num; - return token; + return parse_events_get_column(scanner) - parse_events_get_leng(scanner); } -static int value(yyscan_t scanner, int base) +static int value(struct parse_events_state *parse_state, yyscan_t scanner, int base) { YYSTYPE *yylval = parse_events_get_lval(scanner); char *text = parse_events_get_text(scanner); + u64 num; - return __value(yylval, text, base, PE_VALUE); + errno = 0; + num = strtoull(text, NULL, base); + if (errno) { + struct parse_events_error *error = parse_state->error; + char *help = NULL; + + if (asprintf(&help, "Bad base %d number \"%s\"", base, text) > 0) + parse_events_error__handle(error, get_column(scanner), help , NULL); + + return PE_ERROR; + } + + yylval->num = num; + return PE_VALUE; } static int str(yyscan_t scanner, int token) @@ -283,8 +291,8 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } */ "/"/{digit} { return PE_BP_SLASH; } "/"/{non_digit} { BEGIN(config); return '/'; } -{num_dec} { return value(yyscanner, 10); } -{num_hex} { return value(yyscanner, 16); } +{num_dec} { return value(_parse_state, yyscanner, 10); } +{num_hex} { return value(_parse_state, yyscanner, 16); } /* * We need to separate 'mem:' scanner part, in order to get specific * modifier bits parsed out. Otherwise we would need to handle PE_NAME @@ -330,8 +338,8 @@ cgroup-switches { return sym(yyscanner, PERF_COUNT_SW_CGROUP_SWITCHES); } {lc_type}-{lc_op_result}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } mem: { BEGIN(mem); return PE_PREFIX_MEM; } r{num_raw_hex} { return str(yyscanner, PE_RAW); } -{num_dec} { return value(yyscanner, 10); } -{num_hex} { return value(yyscanner, 16); } +{num_dec} { return value(_parse_state, yyscanner, 10); } +{num_hex} { return value(_parse_state, yyscanner, 16); } {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } {name} { return str(yyscanner, PE_NAME); } From patchwork Tue Apr 16 06:15:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631327 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 3C38984FBE for ; Tue, 16 Apr 2024 06:16:13 +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=1713248175; cv=none; b=JzNz83lvK+jT3prk9bvkuTfYudo2E0UsoaeXhB0SoYqlxpyxjsApoQygOt7pqA2GZMTlwcEeYkij5I6wodbxPnaSs6OIzU/OLvSZE/TyXyrDn5i+YepvP8ZXF+FH1POgg5bOV8GmkxJqfMdcyjOeTWGLb4vik+Fd4LF2lQI1WEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248175; c=relaxed/simple; bh=XX1cj9K5No2BuXWbuQ0xkOkv7ge+rMh/BIMFSe0VdkM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Pfa7he7FyAX1kHnNfIRQjnnzOJuBpwiVxFB2qkwvU2I59ukWGrt/FGr9O+hibJlg3f15v8gEYbg62wfW6bVet6gGFFT5RKyfZhLWz38mAYQ/hcyHGF//mzItF0Y80p8It7BKh82nglvAMaUH5NGKUbNXTBex2p8xFUHwy0y7/Co= 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=z6d98tz5; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="z6d98tz5" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6180514a5ffso43663697b3.0 for ; Mon, 15 Apr 2024 23:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248172; x=1713852972; 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=+hPbZ7lnhh9QoC+3t1lsGMaRdpOWz8T0ZMfEFKF068g=; b=z6d98tz5J8ufr6y8Qe77yJlhTbm7A6YzhrZwxiLFzMNU1lKv/9UyY3eHg7RmZMyXu0 jBDml5xVko5Svu6fg9UWWuJaT/MqagRNtwJ7PfpGEgm1dCPrOWHG/jRBufDzHEQlxdky B/oTXWtTrWfukS7aFs7ENWvxV9ELlpGMQfaBLcdQANlAyfvsLshvznU73I9sL2k96aE6 RYVw2ZNdPzFK3mO4A6Tg3srLbv8RWetCVb9+8y4iPNpYwZjlhwOqu4q5uPINvBTtFMUz 29ZAl40sNY5uL3ndHJCP1ljezT8F97kRKd51HyfREW0blkfbtrWoPYWhjdKEI/d5IwEU Rgdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248172; x=1713852972; 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=+hPbZ7lnhh9QoC+3t1lsGMaRdpOWz8T0ZMfEFKF068g=; b=qKMmuSFPyUb4xdraUEHWBwpbj0p4ehw90UxbTtyQWFB6oNGVgG9oisbeen/aZck8k+ 5rpzDGtNyV/kkeHtBZuuyoIKN7bwrotWtZfHvU8EdifVx0LsQoXYkYs1l7v8vAaUT94R aUiVV2QEjBZ1kN6qu7edKhyUAgb+9mMeOVW64vTzmv7yN6Cgz9XKYy4rULxvwX8y01EN obeeym7xEGn9gBkH6jNBMOrBzn3aePr7bRsJlEh1IVxTi8dOWRmk4Uk3jV/a6PjIVQFP x52u0M4Lrzu7UD5G9oEN2bgHYocnnTIvZ6IcMtRWb0kT8BGGZo4WsnkJjZ8Fz3CGSWYQ cckA== X-Forwarded-Encrypted: i=1; AJvYcCXj8c2JoWF6JiyodzrepGTHT1zY41KGJRsevcMGICwuMvvB0fHl1R2Ae3AQbRHfzQc9UrKPaJVMz1Q2pkOOCalcXQVq X-Gm-Message-State: AOJu0YzgHK3D2Fi+ZCBzHBEDd7wUzpdP0M/H1p7jd0NFNhblElSv48KD Sck2QjrJD7Fb+Ry4ABW6+JbYbAuHuOmjGwkduLMc+Yme6HoQE4dtkVI19K0me5RPqVHlbuWASBs OODhHIQ== X-Google-Smtp-Source: AGHT+IH09dNa2Ep6hGWotz5Z/1B2yBTk2hy320YLi4pZ6NH6aEgIxJHZyqUteQDBUak/iqd6skeTLPOdRDRw X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a81:8309:0:b0:618:308f:e418 with SMTP id t9-20020a818309000000b00618308fe418mr489314ywf.4.1713248172501; Mon, 15 Apr 2024 23:16:12 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:28 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-13-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 12/16] perf parse-events: Inline parse_events_evlist_error 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 Inline parse_events_evlist_error that is only used in parse_events_error. Modify parse_events_error to not report a parser error unless errors haven't already been reported. Make it clearer that the latter case only happens for unrecognized input. Before: ``` $ perf stat -e 'cycles/period=99999999999999999999/' true event syntax error: 'cycles/period=99999999999999999999/' \___ parser error event syntax error: '..les/period=99999999999999999999/' \___ Bad base 10 number "99999999999999999999" Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events $ perf stat -e 'cycles:xyz' true event syntax error: 'cycles:xyz' \___ parser error Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events ``` After: ``` $ perf stat -e 'cycles/period=99999999999999999999/xyz' true event syntax error: '..les/period=99999999999999999999/xyz' \___ Bad base 10 number "99999999999999999999" Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events $ perf stat -e 'cycles:xyz' true event syntax error: 'cycles:xyz' \___ Unrecognized input Run 'perf list' for a list of valid events Usage: perf stat [] [] -e, --event event selector. use 'perf list' to list available events ``` Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 9 --------- tools/perf/util/parse-events.h | 2 -- tools/perf/util/parse-events.y | 10 ++++++++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 7eba714f0d73..ebada37ef98a 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2760,15 +2760,6 @@ int parse_events_terms__to_strbuf(const struct parse_events_terms *terms, struct return 0; } -void parse_events_evlist_error(struct parse_events_state *parse_state, - int idx, const char *str) -{ - if (!parse_state->error) - return; - - parse_events_error__handle(parse_state->error, idx, strdup(str), NULL); -} - static void config_terms_list(char *buf, size_t buf_sz) { int i; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e8f2aebea10f..290ae6c72ec5 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -226,8 +226,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state void *loc_); void parse_events__set_leader(char *name, struct list_head *list); -void parse_events_evlist_error(struct parse_events_state *parse_state, - int idx, const char *str); struct event_symbol { const char *symbol; diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 51490f0f8c50..2c4817e126c1 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -790,9 +790,15 @@ sep_slash_slash_dc: '/' '/' | ':' | %% -void parse_events_error(YYLTYPE *loc, void *parse_state, +void parse_events_error(YYLTYPE *loc, void *_parse_state, void *scanner __maybe_unused, char const *msg __maybe_unused) { - parse_events_evlist_error(parse_state, loc->last_column, "parser error"); + struct parse_events_state *parse_state = _parse_state; + + if (!parse_state->error || !list_empty(&parse_state->error->list)) + return; + + parse_events_error__handle(parse_state->error, loc->last_column, + strdup("Unrecognized input"), NULL); } From patchwork Tue Apr 16 06:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631328 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 A238C4596B for ; Tue, 16 Apr 2024 06:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248178; cv=none; b=n1tHHVW7iqjKsRhfSY/LbEOw9Hr9dszamTKGw9z6vhF1wa8SDy9ZH0crb1//9+joSwoirm8cX6jhijMOQQfj/KQq55UzuqOcYSOP8ShhIVuwp9gynzMJABo/t253yIhl7xVzYtWUJBVVspunfMtWHjaE8L+LWgTJKDy63xOx8b8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248178; c=relaxed/simple; bh=2JLJEqgocioKqNHfii+5wBTOxGZ8Be6F/7ih4JdBn7g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=PwRUNJeEKfdcLktWvE41rDLj2RODTnxfdOZ5ZkVETtxvOXxQT04Kk1BdJfH5VV6B85CUl6zSbRKvvlV6yVkN+o39OeqtgS3KKsGng8haWyp6DfloRKLF68+9zcnsW6oAI46j/jqVUBen/ysCF1JoXxZfHgtwPChBubrjp5W/kuU= 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=Do7awE1o; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Do7awE1o" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61ae9ff0322so13827517b3.3 for ; Mon, 15 Apr 2024 23:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248175; x=1713852975; 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=gmdXM5hWuk31JKHSQhfePomAmthpx27vl44PJ3DD+Zg=; b=Do7awE1oSw4XbhcBWodQAvArZNu9btALTrX7QgHcd3zFKbp7FYLRKjiPefV+nw43Et FEFrm6oawSiXwxnBqre1AAoSV2JZ56i4eiJ3E4FOS0qJ2/LCpwB0CblXEy91rj1l0JJD JyxpVEBh0G6Syw4TEeS1V/7Xo0jiZv/DUYVY2AI7MzY+4bCTdQQmtcueK/G5+YPnNRgz 4Ap6fMMHIeitkCQYTjYvBCA2XxCLQ+LCDL2x67D6pNUULXPhzObcRQwo8aYa3Y8p/Zp2 lO3o1EI862B9WUNc9X28zilbm2kEqf9DgFHq8u3fHXb+gulls3D1scauLnebVRqe19CX iyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248175; x=1713852975; 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=gmdXM5hWuk31JKHSQhfePomAmthpx27vl44PJ3DD+Zg=; b=vJ89PexfrR8hMBaaVTvNwFKb6Nw73fTxTxqD3vDUC3NFIlkQgaALS5Hgm1zN577AHX 75F2F3HjxMERTcESRAeJaugWJC/I+xwjV8RDhxsPnydcoLvlpbtG8BDvCGdZkbOpHfKX ef0Q2aJC472WRsiKqO04D6bs8PE2UUv+SuhW2aGSHwLS1c5xiClLRt5P5PeEAEIvKMez 4mzNH1sZpBdBBWyjSok5BnyoR4cTvnCH9rmVRtb5hVvQE1a+j7b7I7SmrTHwflVMlDkn MkYkVtUVinPuw9CA+L3lQSyZ49yxlbcf6BswSgqCXmDIKIV0BsnzPgvcLG9moKRgmc+J LGBg== X-Forwarded-Encrypted: i=1; AJvYcCX/MpE9gqjcEW111fk23bK1nC2gSJDlueulSWGWerqn8wi+9goze4nbhUY5JNohKRgtqefj+lHJuMQ1f8VeKyoNk6eE X-Gm-Message-State: AOJu0YyAYUVwdHXdowATA188HiykG/VkAmr6ok1j1eWflWy/I7wiaKKm pdMLXFKjKzrZF6s9NJNKUi3CFtCNpUR4O95GrQTJT9/ep37aOx6Mo0ZuhazzHM4Pb7bmeSgvgHX KKPsqUA== X-Google-Smtp-Source: AGHT+IFALjETCbl00Svj23mgqIjReHvSFT/iihiPUIAVPjIgwm0CLEdQy9JiG2BgYIJRtbHg9mHle47NQB9D X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:1502:b0:dc7:49a9:6666 with SMTP id q2-20020a056902150200b00dc749a96666mr4012859ybu.3.1713248174817; Mon, 15 Apr 2024 23:16:14 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:29 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-14-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 13/16] perf parse-events: Improvements to modifier 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 Use a struct/bitmap rather than a copied string from lexer. In lexer give improved error message when too many precise flags are given or repeated modifiers. Before: ``` $ perf stat -e 'cycles:kuk' true event syntax error: 'cycles:kuk' \___ Bad modifier ... $ perf stat -e 'cycles:pppp' true event syntax error: 'cycles:pppp' \___ Bad modifier ... $ perf stat -e '{instructions:p,cycles:pp}:pp' -a true event syntax error: '..cycles:pp}:pp' \___ Bad modifier ... ``` After: ``` $ perf stat -e 'cycles:kuk' true event syntax error: 'cycles:kuk' \___ Duplicate modifier 'k' (kernel) ... $ perf stat -e 'cycles:pppp' true event syntax error: 'cycles:pppp' \___ Maximum precise value is 3 ... $ perf stat -e '{instructions:p,cycles:pp}:pp' true event syntax error: '..cycles:pp}:pp' \___ Maximum combined precise value is 3, adding precision to "cycles:pp" ... ``` Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 250 ++++++++++++--------------------- tools/perf/util/parse-events.h | 23 ++- tools/perf/util/parse-events.l | 75 +++++++++- tools/perf/util/parse-events.y | 28 +--- 4 files changed, 194 insertions(+), 182 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ebada37ef98a..3ab533d0e653 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1700,12 +1700,6 @@ int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state *parse_state return -EINVAL; } -int parse_events__modifier_group(struct list_head *list, - char *event_mod) -{ - return parse_events__modifier_event(list, event_mod, true); -} - void parse_events__set_leader(char *name, struct list_head *list) { struct evsel *leader; @@ -1720,183 +1714,125 @@ void parse_events__set_leader(char *name, struct list_head *list) leader->group_name = name; } -struct event_modifier { - int eu; - int ek; - int eh; - int eH; - int eG; - int eI; - int precise; - int precise_max; - int exclude_GH; - int sample_read; - int pinned; - int weak; - int exclusive; - int bpf_counter; -}; +static int parse_events__modifier_list(struct parse_events_state *parse_state, + YYLTYPE *loc, + struct list_head *list, + struct parse_events_modifier mod, + bool group) +{ + struct evsel *evsel; -static int get_event_modifier(struct event_modifier *mod, char *str, - struct evsel *evsel) -{ - int eu = evsel ? evsel->core.attr.exclude_user : 0; - int ek = evsel ? evsel->core.attr.exclude_kernel : 0; - int eh = evsel ? evsel->core.attr.exclude_hv : 0; - int eH = evsel ? evsel->core.attr.exclude_host : 0; - int eG = evsel ? evsel->core.attr.exclude_guest : 0; - int eI = evsel ? evsel->core.attr.exclude_idle : 0; - int precise = evsel ? evsel->core.attr.precise_ip : 0; - int precise_max = 0; - int sample_read = 0; - int pinned = evsel ? evsel->core.attr.pinned : 0; - int exclusive = evsel ? evsel->core.attr.exclusive : 0; - - int exclude = eu | ek | eh; - int exclude_GH = evsel ? evsel->exclude_GH : 0; - int weak = 0; - int bpf_counter = 0; - - memset(mod, 0, sizeof(*mod)); - - while (*str) { - if (*str == 'u') { + if (!group && mod.weak) { + parse_events_error__handle(parse_state->error, loc->first_column, + strdup("Weak modifier is for use with groups"), NULL); + return -EINVAL; + } + + __evlist__for_each_entry(list, evsel) { + /* Translate modifiers into the equivalent evsel excludes. */ + int eu = group ? evsel->core.attr.exclude_user : 0; + int ek = group ? evsel->core.attr.exclude_kernel : 0; + int eh = group ? evsel->core.attr.exclude_hv : 0; + int eH = group ? evsel->core.attr.exclude_host : 0; + int eG = group ? evsel->core.attr.exclude_guest : 0; + int exclude = eu | ek | eh; + int exclude_GH = group ? evsel->exclude_GH : 0; + + if (mod.precise) { + /* use of precise requires exclude_guest */ + eG = 1; + } + if (mod.user) { if (!exclude) exclude = eu = ek = eh = 1; if (!exclude_GH && !perf_guest) eG = 1; eu = 0; - } else if (*str == 'k') { + } + if (mod.kernel) { if (!exclude) exclude = eu = ek = eh = 1; ek = 0; - } else if (*str == 'h') { + } + if (mod.hypervisor) { if (!exclude) exclude = eu = ek = eh = 1; eh = 0; - } else if (*str == 'G') { + } + if (mod.guest) { if (!exclude_GH) exclude_GH = eG = eH = 1; eG = 0; - } else if (*str == 'H') { + } + if (mod.host) { if (!exclude_GH) exclude_GH = eG = eH = 1; eH = 0; - } else if (*str == 'I') { - eI = 1; - } else if (*str == 'p') { - precise++; - /* use of precise requires exclude_guest */ - if (!exclude_GH) - eG = 1; - } else if (*str == 'P') { - precise_max = 1; - } else if (*str == 'S') { - sample_read = 1; - } else if (*str == 'D') { - pinned = 1; - } else if (*str == 'e') { - exclusive = 1; - } else if (*str == 'W') { - weak = 1; - } else if (*str == 'b') { - bpf_counter = 1; - } else - break; - - ++str; + } + evsel->core.attr.exclude_user = eu; + evsel->core.attr.exclude_kernel = ek; + evsel->core.attr.exclude_hv = eh; + evsel->core.attr.exclude_host = eH; + evsel->core.attr.exclude_guest = eG; + evsel->exclude_GH = exclude_GH; + + /* Simple modifiers copied to the evsel. */ + if (mod.precise) { + u8 precise = evsel->core.attr.precise_ip + mod.precise; + /* + * precise ip: + * + * 0 - SAMPLE_IP can have arbitrary skid + * 1 - SAMPLE_IP must have constant skid + * 2 - SAMPLE_IP requested to have 0 skid + * 3 - SAMPLE_IP must have 0 skid + * + * See also PERF_RECORD_MISC_EXACT_IP + */ + if (precise > 3) { + char *help; + + if (asprintf(&help, + "Maximum combined precise value is 3, adding precision to \"%s\"", + evsel__name(evsel)) > 0) { + parse_events_error__handle(parse_state->error, + loc->first_column, + help, NULL); + } + return -EINVAL; + } + evsel->core.attr.precise_ip = precise; + } + if (mod.precise_max) + evsel->precise_max = 1; + if (mod.non_idle) + evsel->core.attr.exclude_idle = 1; + if (mod.sample_read) + evsel->sample_read = 1; + if (mod.pinned && evsel__is_group_leader(evsel)) + evsel->core.attr.pinned = 1; + if (mod.exclusive && evsel__is_group_leader(evsel)) + evsel->core.attr.exclusive = 1; + if (mod.weak) + evsel->weak_group = true; + if (mod.bpf) + evsel->bpf_counter = true; } - - /* - * precise ip: - * - * 0 - SAMPLE_IP can have arbitrary skid - * 1 - SAMPLE_IP must have constant skid - * 2 - SAMPLE_IP requested to have 0 skid - * 3 - SAMPLE_IP must have 0 skid - * - * See also PERF_RECORD_MISC_EXACT_IP - */ - if (precise > 3) - return -EINVAL; - - mod->eu = eu; - mod->ek = ek; - mod->eh = eh; - mod->eH = eH; - mod->eG = eG; - mod->eI = eI; - mod->precise = precise; - mod->precise_max = precise_max; - mod->exclude_GH = exclude_GH; - mod->sample_read = sample_read; - mod->pinned = pinned; - mod->weak = weak; - mod->bpf_counter = bpf_counter; - mod->exclusive = exclusive; - return 0; } -/* - * Basic modifier sanity check to validate it contains only one - * instance of any modifier (apart from 'p') present. - */ -static int check_modifier(char *str) +int parse_events__modifier_group(struct parse_events_state *parse_state, void *loc, + struct list_head *list, + struct parse_events_modifier mod) { - char *p = str; - - /* The sizeof includes 0 byte as well. */ - if (strlen(str) > (sizeof("ukhGHpppPSDIWeb") - 1)) - return -1; - - while (*p) { - if (*p != 'p' && strchr(p + 1, *p)) - return -1; - p++; - } - - return 0; + return parse_events__modifier_list(parse_state, loc, list, mod, /*group=*/true); } -int parse_events__modifier_event(struct list_head *list, char *str, bool add) +int parse_events__modifier_event(struct parse_events_state *parse_state, void *loc, + struct list_head *list, + struct parse_events_modifier mod) { - struct evsel *evsel; - struct event_modifier mod; - - if (str == NULL) - return 0; - - if (check_modifier(str)) - return -EINVAL; - - if (!add && get_event_modifier(&mod, str, NULL)) - return -EINVAL; - - __evlist__for_each_entry(list, evsel) { - if (add && get_event_modifier(&mod, str, evsel)) - return -EINVAL; - - evsel->core.attr.exclude_user = mod.eu; - evsel->core.attr.exclude_kernel = mod.ek; - evsel->core.attr.exclude_hv = mod.eh; - evsel->core.attr.precise_ip = mod.precise; - evsel->core.attr.exclude_host = mod.eH; - evsel->core.attr.exclude_guest = mod.eG; - evsel->core.attr.exclude_idle = mod.eI; - evsel->exclude_GH = mod.exclude_GH; - evsel->sample_read = mod.sample_read; - evsel->precise_max = mod.precise_max; - evsel->weak_group = mod.weak; - evsel->bpf_counter = mod.bpf_counter; - - if (evsel__is_group_leader(evsel)) { - evsel->core.attr.pinned = mod.pinned; - evsel->core.attr.exclusive = mod.exclusive; - } - } - - return 0; + return parse_events__modifier_list(parse_state, loc, list, mod, /*group=*/false); } int parse_events_name(struct list_head *list, const char *name) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 290ae6c72ec5..f104faef1a78 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -186,8 +186,27 @@ void parse_events_terms__init(struct parse_events_terms *terms); void parse_events_terms__exit(struct parse_events_terms *terms); int parse_events_terms(struct parse_events_terms *terms, const char *str, FILE *input); int parse_events_terms__to_strbuf(const struct parse_events_terms *terms, struct strbuf *sb); -int parse_events__modifier_event(struct list_head *list, char *str, bool add); -int parse_events__modifier_group(struct list_head *list, char *event_mod); + +struct parse_events_modifier { + u8 precise; /* Number of repeated 'p' for precision. */ + bool precise_max : 1; /* 'P' */ + bool non_idle : 1; /* 'I' */ + bool sample_read : 1; /* 'S' */ + bool pinned : 1; /* 'D' */ + bool exclusive : 1; /* 'e' */ + bool weak : 1; /* 'W' */ + bool bpf : 1; /* 'b' */ + bool user : 1; /* 'u' */ + bool kernel : 1; /* 'k' */ + bool hypervisor : 1; /* 'h' */ + bool guest : 1; /* 'G' */ + bool host : 1; /* 'H' */ +}; + +int parse_events__modifier_event(struct parse_events_state *parse_state, void *loc, + struct list_head *list, struct parse_events_modifier mod); +int parse_events__modifier_group(struct parse_events_state *parse_state, void *loc, + struct list_head *list, struct parse_events_modifier mod); int parse_events_name(struct list_head *list, const char *name); int parse_events_add_tracepoint(struct list_head *list, int *idx, const char *sys, const char *event, diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 0cd68c9f0d4f..4aaf0c53d9b6 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -142,6 +142,77 @@ static int hw(yyscan_t scanner, int config) return PE_TERM_HW; } +static void modifiers_error(struct parse_events_state *parse_state, yyscan_t scanner, + int pos, char mod_char, const char *mod_name) +{ + struct parse_events_error *error = parse_state->error; + char *help = NULL; + + if (asprintf(&help, "Duplicate modifier '%c' (%s)", mod_char, mod_name) > 0) + parse_events_error__handle(error, get_column(scanner) + pos, help , NULL); +} + +static int modifiers(struct parse_events_state *parse_state, yyscan_t scanner) +{ + YYSTYPE *yylval = parse_events_get_lval(scanner); + char *text = parse_events_get_text(scanner); + struct parse_events_modifier mod = { .precise = 0, }; + + for (size_t i = 0, n = strlen(text); i < n; i++) { +#define CASE(c, field) \ + case c: \ + if (mod.field) { \ + modifiers_error(parse_state, scanner, i, c, #field); \ + return PE_ERROR; \ + } \ + mod.field = true; \ + break + + switch (text[i]) { + CASE('u', user); + CASE('k', kernel); + CASE('h', hypervisor); + CASE('I', non_idle); + CASE('G', guest); + CASE('H', host); + case 'p': + mod.precise++; + /* + * precise ip: + * + * 0 - SAMPLE_IP can have arbitrary skid + * 1 - SAMPLE_IP must have constant skid + * 2 - SAMPLE_IP requested to have 0 skid + * 3 - SAMPLE_IP must have 0 skid + * + * See also PERF_RECORD_MISC_EXACT_IP + */ + if (mod.precise > 3) { + struct parse_events_error *error = parse_state->error; + char *help = strdup("Maximum precise value is 3"); + + if (help) { + parse_events_error__handle(error, get_column(scanner) + i, + help , NULL); + } + return PE_ERROR; + } + break; + CASE('P', precise_max); + CASE('S', sample_read); + CASE('D', pinned); + CASE('W', weak); + CASE('e', exclusive); + CASE('b', bpf); + default: + return PE_ERROR; + } +#undef CASE + } + yylval->mod = mod; + return PE_MODIFIER_EVENT; +} + #define YY_USER_ACTION \ do { \ yylloc->last_column = yylloc->first_column; \ @@ -174,7 +245,7 @@ drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)? * If you add a modifier you need to update check_modifier(). * Also, the letters in modifier_event must not be in modifier_bp. */ -modifier_event [ukhpPGHSDIWeb]+ +modifier_event [ukhpPGHSDIWeb]{1,15} modifier_bp [rwx]{1,3} lc_type (L1-dcache|l1-d|l1d|L1-data|L1-icache|l1-i|l1i|L1-instruction|LLC|L2|dTLB|d-tlb|Data-TLB|iTLB|i-tlb|Instruction-TLB|branch|branches|bpu|btb|bpc|node) lc_op_result (load|loads|read|store|stores|write|prefetch|prefetches|speculative-read|speculative-load|refs|Reference|ops|access|misses|miss) @@ -341,7 +412,7 @@ r{num_raw_hex} { return str(yyscanner, PE_RAW); } {num_dec} { return value(_parse_state, yyscanner, 10); } {num_hex} { return value(_parse_state, yyscanner, 16); } -{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } +{modifier_event} { return modifiers(_parse_state, yyscanner); } {name} { return str(yyscanner, PE_NAME); } {name_tag} { return str(yyscanner, PE_NAME); } "/" { BEGIN(config); return '/'; } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 2c4817e126c1..79f254189be6 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -68,11 +68,11 @@ static void free_list_evsel(struct list_head* list_evsel) %type PE_VALUE %type PE_VALUE_SYM_SW %type PE_VALUE_SYM_TOOL +%type PE_MODIFIER_EVENT %type PE_TERM %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE -%type PE_MODIFIER_EVENT %type PE_MODIFIER_BP %type PE_EVENT_NAME %type PE_DRV_CFG_TERM @@ -110,6 +110,7 @@ static void free_list_evsel(struct list_head* list_evsel) { char *str; u64 num; + struct parse_events_modifier mod; enum parse_events__term_type term_type; struct list_head *list_evsel; struct parse_events_terms *list_terms; @@ -175,20 +176,13 @@ event group: group_def ':' PE_MODIFIER_EVENT { + /* Apply the modifier to the events in the group_def. */ struct list_head *list = $1; int err; - err = parse_events__modifier_group(list, $3); - free($3); - if (err) { - struct parse_events_state *parse_state = _parse_state; - struct parse_events_error *error = parse_state->error; - - parse_events_error__handle(error, @3.first_column, - strdup("Bad modifier"), NULL); - free_list_evsel(list); + err = parse_events__modifier_group(_parse_state, &@3, list, $3); + if (err) YYABORT; - } $$ = list; } | @@ -238,17 +232,9 @@ event_name PE_MODIFIER_EVENT * (there could be more events added for multiple tracepoint * definitions via '*?'. */ - err = parse_events__modifier_event(list, $2, false); - free($2); - if (err) { - struct parse_events_state *parse_state = _parse_state; - struct parse_events_error *error = parse_state->error; - - parse_events_error__handle(error, @2.first_column, - strdup("Bad modifier"), NULL); - free_list_evsel(list); + err = parse_events__modifier_event(_parse_state, &@2, list, $2); + if (err) YYABORT; - } $$ = list; } | From patchwork Tue Apr 16 06:15:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631329 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 0CE9D158861 for ; Tue, 16 Apr 2024 06:16:17 +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=1713248179; cv=none; b=ENYZUluUZkFWLs5Cof3UzFMkITLbbeDyrH3kXeWhKsK2nR55cP/fyj0Xy2EI7d9LKW2+bdB1MdQLVYew3A+jfIKau8mprtuF/GfKGLMWwZ6ER1Nf/O3LslrxYbrUL6Y+fBtclqNcBRdPnmPOb98bjLDML6eFOlBAk4cX8pjmHZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248179; c=relaxed/simple; bh=RJLEGacEoWTcJGv5R0SFmVMGUwKOfcVwsf41gQZkJ4U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=oFyiRAgaf6obNH4uiBjnck//mB8k1g4libV1K9CdeqNGRlDYw+4YoOot3KxPg5cDPANmheexGr3o1OVdSsl4RA7WAoK/OQQ3XjNEkLCeDL9cJ5zyr4hgdmqBcT0B/lV9SLaW01nnzpMzNcOKydRbop0RH0QGLIQX3CufqT0edd8= 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=2JEn8eOz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2JEn8eOz" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso7990816276.0 for ; Mon, 15 Apr 2024 23:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248177; x=1713852977; 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=CS464tDCakpyTmrmcLFcR8YYU9aH6y31Ipzi53/1x7k=; b=2JEn8eOzqJsheImB37OB5RjMrLuxx1MmAAVe1ESawyN7MwgjXfNak80eiQDclyluRf B9dQuSQBB18S5eMNDtgwwGxa8FsMscw4o21oH9jDQdezNqeWRvj+zAFqRbx/pvQSycQj RDkMHIOKKF90NZlfqkNay9oVQvH/bSmIF68LV+wNjFfa21vtFiEvbBvljMJaO6MRFx69 bJqXXm/cf2yAdsIGut2gEjd3//GVZ2tbqhshsIyHm5cL5qBSwBzWETqFstGGvfXCDBcZ VxcQSIWHvgc2HwYRXfEj/HDRhfb9xoCBmMQ/FzgreaCtZVzf1esFO1ayK2Q2cB5u/Bgq 2xHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248177; x=1713852977; 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=CS464tDCakpyTmrmcLFcR8YYU9aH6y31Ipzi53/1x7k=; b=ibDNntcNUR5LB6N6YuKpbxVMYcjmwMd0Z4RGEr98FFb2mEDydIm+sws/BoHqteXwq1 URa4k9VOWtpgssnCiWaBNTqh7W5xKOyWAPYdA/6ga7cYn69gYlChhULDCEfhwwtxY6Bd EnqGn377oI53/EPBAN49/vd469vPLM4JuKn673POr05IJLXpPyP00UFD56DZW9eOrwSy qmC8pSOCfpSr2f15Nx9HsG7FFGLrwSfBlMurI5d4kyTSNZuVi+hdMETT9/ATLf5rj8lP ERcM86hRt1qkfzilsPPj9smaHMz5nYVfdAYhJmsgWyUix3wfoq4oJIjJLdA5ZVVmVnt5 zqtw== X-Forwarded-Encrypted: i=1; AJvYcCUY6MkgnGzT4wrxx3pgBZXc00gMDu4QjBPAynEmLqqEnZz8eCIhIa1V716Cli5JiTQnLuyDXjsoAlYjfkD88S+xaGyy X-Gm-Message-State: AOJu0YwemDuziYldaQngeeOhcOexUYm/bB1Kelc5eA+LD8oPwLB3AMFD g3XIgct2RIQKoCllY4VVYiBUNHOvXxjHdroyGCpxHaesLyPT8Q4h1OPCrbqD/ZinPbAadJZIj42 s+5xnpA== X-Google-Smtp-Source: AGHT+IHO0Fo9+D3NBOjv38HGGbmFqRswvl8m/oJgT2uKaZFhVmwhvI9Qz+b/36nYjScIaD300oJtaekLWfEs X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:100d:b0:dbd:ee44:8908 with SMTP id w13-20020a056902100d00b00dbdee448908mr615874ybt.0.1713248177044; Mon, 15 Apr 2024 23:16:17 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:30 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-15-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 14/16] perf parse-event: Constify event_symbol arrays 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 Moves 352 bytes from .data to .data.rel.ro. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/parse-events.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3ab533d0e653..8d3d692d219d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -39,7 +39,7 @@ static int get_config_terms(const struct parse_events_terms *head_config, static int parse_events_terms__copy(const struct parse_events_terms *src, struct parse_events_terms *dest); -struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { +const struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { [PERF_COUNT_HW_CPU_CYCLES] = { .symbol = "cpu-cycles", .alias = "cycles", @@ -82,7 +82,7 @@ struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = { }, }; -struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { +const struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = { [PERF_COUNT_SW_CPU_CLOCK] = { .symbol = "cpu-clock", .alias = "", diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index f104faef1a78..0bb5f0c80a5e 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -250,8 +250,8 @@ struct event_symbol { const char *symbol; const char *alias; }; -extern struct event_symbol event_symbols_hw[]; -extern struct event_symbol event_symbols_sw[]; +extern const struct event_symbol event_symbols_hw[]; +extern const struct event_symbol event_symbols_sw[]; char *parse_events_formats_error_string(char *additional_terms); From patchwork Tue Apr 16 06:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631330 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 542741598FC for ; Tue, 16 Apr 2024 06:16:20 +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=1713248181; cv=none; b=AC2bIywJFnQ9YmKQQ3umgDxt7psNVjUnCHcW2krPF1gqfK+mvPmd4Hu3IhPukHCSztk7qbisiMCO0C3vfEKZwJKav+yA97VmhG9KejdJCuiLNblhuOEe3U7zZoqB2JLd8Jg8li+Lvtc7ntR9iTU0C1M1xE6uF594D6xIy3QerDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248181; c=relaxed/simple; bh=KaJz8yoO4z8kzF8PImegTLz6lTpKAp/f4nY2Hi+9ZYE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=UDSvAmtwkpQ5ZV0JuWRq2Um7MRxtPPMOlPryPhNvQAd94GoOC4srXQUwUpwHFVOM1/1/QqZFGnseqpbRDHxYRYU4VKaJEkTOrPKOefrps1+BHKEiB/rA7sxb831p70TSdTG4Z6ymJG2uRUDfZWucyhKNR7rhoHbzzPvlhpQwBAk= 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=L86ujXW4; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L86ujXW4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61acc68c1bdso16320857b3.1 for ; Mon, 15 Apr 2024 23:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248179; x=1713852979; 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=9VrQN7n3xmbjqa9xka2YhMJJYnp++PDb8jkPaxpbY/Q=; b=L86ujXW47MrrrUBU6wy2Ce0+FPpX97SC3vv1D0VGToXbMm+AeAUXPYi7gkmHty2En3 p4QeiNHegkTPB7XpAKoKnsyuw0/NnLWBJ7AcrPTq5wu7UA9YfeR+R3BCz9vYTVEOII9c aUW/hB/SVsV3KFczD3ZjqROsazjPOCjAhwGWGYz3cjAXmHhY5VLSlnF2YOo120/DmxxG M6mQhdWGv75Sd928kCpZZ/G1gM+BWFgDiK3QOdbCYVBkWwWA9jz4qEH3TSpuGeNARNV9 TEQ7pMVmFl3qd0ZjgKcN9+xoH5visKlTHC8WDnkGtDEBzT6wSXnJ6AZ81kTZXXFVVJ+t HOIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248179; x=1713852979; 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=9VrQN7n3xmbjqa9xka2YhMJJYnp++PDb8jkPaxpbY/Q=; b=H3ury8cjaWvuz8Y7dQneQZS9dDbofmq2/93IV3XstGBSFP2ouHPOLu40SOMm97L93L s7Eua6DzED9LZAFDVlUNxMXZv52S1jy9+haVXvIOO4NQTFh0P7oavZWoDknWNJqNpZRG oA3QgQLmdZOriCVPQXt0y0DGcbkoesas09fbWHBo4DfV2tsfZIn65uTkTVc77FmQvmy2 fgycayM3no8umyMs7BOIPIGZ9sh0O8ORi3Vq1aUdeHA2DjNJJhBLJyN4YbV5470HAhy8 tY2VHneX0QduCj91vTwaHbVmu3kqAihvoxYIMqj+7AuSDU4HZvdmeHX/gUn+2gOyPMVk Jycg== X-Forwarded-Encrypted: i=1; AJvYcCU3D8QDdqHp55Ljaz5TpmxWtLYuJ9OJmEJzybEu7X1dQkWr/+20ap0nUc4r+OAmYQziUl64QmbZ84wctQp4LqT/ZVYy X-Gm-Message-State: AOJu0YxEvMnA1SRx7JFM2F3yEtUV0SlYFQN3J1k82UtiOU+aE3M8Z7rN 8lTY4pvQ1SXg6oC+avWfNlTmsq1CnpafCeA9tybjtCea2t2tv6avSoTt3Cr1Q5+BYNq5aD617q2 RUxQahA== X-Google-Smtp-Source: AGHT+IERSGPTpkVgBfw9PFFOt/D0ky1G3+P1qSBu4bKGGyUriqoLEpK5IFzVUX9JSbM2dKNl22D4bBUM9mgq X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a25:2054:0:b0:dc6:b7c2:176e with SMTP id g81-20020a252054000000b00dc6b7c2176emr369458ybg.4.1713248179377; Mon, 15 Apr 2024 23:16:19 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:31 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-16-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 15/16] perf parse-events: Minor grouping tidy up 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 Add comments. Ensure leader->group_name is freed before overwriting it. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 1 + tools/perf/util/parse-events.y | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 8d3d692d219d..1c1b1bcb78e8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1711,6 +1711,7 @@ void parse_events__set_leader(char *name, struct list_head *list) leader = list_first_entry(list, struct evsel, core.node); __perf_evlist__set_leader(list, &leader->core); + zfree(&leader->group_name); leader->group_name = name; } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 79f254189be6..6f1042272dda 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -193,7 +193,10 @@ PE_NAME '{' events '}' { struct list_head *list = $3; - /* Takes ownership of $1. */ + /* + * Set the first entry of list to be the leader. Set the group name on + * the leader to $1 taking ownership. + */ parse_events__set_leader($1, list); $$ = list; } @@ -202,6 +205,7 @@ PE_NAME '{' events '}' { struct list_head *list = $2; + /* Set the first entry of list to be the leader clearing the group name. */ parse_events__set_leader(NULL, list); $$ = list; } From patchwork Tue Apr 16 06:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13631331 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 D158515A4A5 for ; Tue, 16 Apr 2024 06:16:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248184; cv=none; b=EYfnCaIYvjq8nS56LRl07f6MfLzq/2TIXvVF5uh3lo6V3zq33i+RuRFf2qNHQbaZoZ6LYFJaGE2R7T/vPubtvYKCAOe7/Ccls1ot27kaEPvYHa/ZDxmY73n2R+DvqfBeD9jEjh175xiPYDE5uW9/fmEiEVU5gQ0/RbkYIqZrs7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713248184; c=relaxed/simple; bh=bkVSoExev596RyG9a0xHTwh3L4XVRhShc31xUW/v3J4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RMIohMdNBY1Jp+R6xMCQnctYSJ6VserLoAPMiZhE2KG/u32WoJdCGjo2tvz3v7Hqrr8UUJ9VAea6NPacRlmXHQp7MFMkK4oxJAfOgpVGJFxhme6MfQ5B7cALgYKLWTwb476SuQ9iWhhZavUdSqOPaRRNcu4EvdZiELqaoApuOSo= 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=PQeB8gBK; arc=none smtp.client-ip=209.85.219.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PQeB8gBK" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd933a044baso5741177276.0 for ; Mon, 15 Apr 2024 23:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713248182; x=1713852982; 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=yAZaI9XNl5kKuFXYgLfdboqZLBXY1vO78aqvi2rTEGA=; b=PQeB8gBKfWhMDRZ/+6lhtE2EhneqpHgUrmetRflVDI02OM0cF5OpOPR3TM4bT0d5Rv 5DFX3T884cQCtYyw+/0z8E+DwQU5oDj3EMKHDi83jdiBmqExQO6GWuEUUFvLwTWv0RAU tRtAbHrkdpzLKTcftlCwuPSH/wGFofh0649wAXmDKdITYRSbXsWjRjfYXJCjHoQobOIj todwGN4EYroZn0AMgG8jKYBpWSQ6fNp+yQnJwW1HqIxi2/bFZGZ2zxx0iJQqokn3/3zj 3C9aPwZsz6lkpxchw3UHPSguXJOhS8kStPMRSdtUN/agJu2R34quVOowYgRpUpw/wBle knQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713248182; x=1713852982; 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=yAZaI9XNl5kKuFXYgLfdboqZLBXY1vO78aqvi2rTEGA=; b=QM2gsnXf2lUUC/vNqG9XD+MgRcMKf8jr39aoMgVpu6y0w/hR+iIoGepTCzWeVAJ4DI 3Ej7pRjK8DP/O5FAnxa3a7TTcqr8XNwtjPgMDCqFadMzQ+BmVXXbWCKDhjph28alyrnU 5GBB/qZZjTuCopn2ArWWS3HZ9YYybk4IbIhp40LoHjWz5keJI8bnF26nLwHbw3p/dgWt 6U0+zw30o3w5+hNH/g9lnZrV1U/6LzSQ+KNsiMY0qb8LG3KZgtbwK3PgWnjNU8HPwlOl ulrdgZ3uis44+jffBe3VOFfs24pICUdqlWsYUNBYwLpNvpeRfXPIZQD10t1UClT35j64 MPyg== X-Forwarded-Encrypted: i=1; AJvYcCX65+mBLFQAJhxmdtOgBGcxs9YT5Tsqseuwi4q8XWajWFCGk66aDBGeoWIz688xN/5AORoY6IjZDQ/U7j/4oAylW2xt X-Gm-Message-State: AOJu0Yz1bL7GqNsDOtbIq6nYvigb+wCS29xkhr/bo6Z7n3oAiSxzQZX+ Zy4pqpgHm1mI2sghOaOoYknXWot2RJ6nDYwwAgYyFuAdai8eH3WPkfymwBE7noYhmgvY6k2uAG2 C21/mVQ== X-Google-Smtp-Source: AGHT+IHU62mxVZT/57o8lZIqos+5GU3yfPQj1+CocC7s8g9X2ZXqugU/fUPUNRs0dJBS3aK51ZiyqFZ/eNM7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:30c8:f541:acad:b4f7]) (user=irogers job=sendgmr) by 2002:a05:6902:154f:b0:dbe:d0a9:2be3 with SMTP id r15-20020a056902154f00b00dbed0a92be3mr573082ybu.3.1713248181960; Mon, 15 Apr 2024 23:16:21 -0700 (PDT) Date: Mon, 15 Apr 2024 23:15:32 -0700 In-Reply-To: <20240416061533.921723-1-irogers@google.com> Message-Id: <20240416061533.921723-17-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@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 16/16] perf parse-events: Tidy the setting of the default event name 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 Add comments. Pass ownership of the event name to save on a strdup. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 9 ++++++--- tools/perf/util/parse-events.h | 2 +- tools/perf/util/parse-events.l | 5 +++++ tools/perf/util/parse-events.y | 10 +++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1c1b1bcb78e8..0f308b4db2b9 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1836,18 +1836,21 @@ int parse_events__modifier_event(struct parse_events_state *parse_state, void *l return parse_events__modifier_list(parse_state, loc, list, mod, /*group=*/false); } -int parse_events_name(struct list_head *list, const char *name) +int parse_events__set_default_name(struct list_head *list, char *name) { struct evsel *evsel; + bool used_name = false; __evlist__for_each_entry(list, evsel) { if (!evsel->name) { - evsel->name = strdup(name); + evsel->name = used_name ? strdup(name) : name; + used_name = true; if (!evsel->name) return -ENOMEM; } } - + if (!used_name) + free(name); return 0; } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 0bb5f0c80a5e..5695308efab9 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -207,7 +207,7 @@ int parse_events__modifier_event(struct parse_events_state *parse_state, void *l struct list_head *list, struct parse_events_modifier mod); int parse_events__modifier_group(struct parse_events_state *parse_state, void *loc, struct list_head *list, struct parse_events_modifier mod); -int parse_events_name(struct list_head *list, const char *name); +int parse_events__set_default_name(struct list_head *list, char *name); int parse_events_add_tracepoint(struct list_head *list, int *idx, const char *sys, const char *event, struct parse_events_error *error, diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 4aaf0c53d9b6..08ea2d845dc3 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -96,6 +96,11 @@ static int drv_str(yyscan_t scanner, int token) return token; } +/* + * Use yyless to return all the characaters to the input. Update the column for + * location debugging. If __alloc is non-zero set yylval to the text for the + * returned token's value. + */ #define REWIND(__alloc) \ do { \ YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \ diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 6f1042272dda..68b3b06c7ff0 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -247,10 +247,14 @@ event_name event_name: PE_EVENT_NAME event_def { - int err; + /* + * When an event is parsed the text is rewound and the entire text of + * the event is set to the str of PE_EVENT_NAME token matched here. If + * no name was on an event via a term, set the name to the entire text + * taking ownership of the allocation. + */ + int err = parse_events__set_default_name($2, $1); - err = parse_events_name($2, $1); - free($1); if (err) { free_list_evsel($2); YYNOMEM;