From nobody Sun May 24 21:37:42 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C7534384CCE for ; Thu, 21 May 2026 03:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779335988; cv=none; b=KrKvPPB1s+8hx8L64oo4HkKsd1yC+ftYF4wSVhBoesMjUhlR6D9fcKDmigi0G6t4ifeVANghqmVSBqdxddFTA+MEuxTkvBtI1nPgwYCpzZeDQIWhZ8cSzC/MP4k7KctgJGcqWTSrIf0aNhsZhmhY/L5faV5FjpAqY6G91Fku8Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779335988; c=relaxed/simple; bh=JF8wm3tZh9rnMOpXDieXBi5M2TeA1yUouuQY69iy1nU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=maE+yXUMea/YkzmolFSssN8SMlixj1YbIWM7ug1J+y3h4laP3GbmfZACvVtXrb2NYfjPD4O8F+PM5ov+wrMNa8Cn/zmTvlbUOrEy1jUc4VXCVEpNJhxZ2kpHpbBw5VuMhwYoxtsYx2kOhnME6o2V5yX85PySqv4QvznJZShn3mU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d+pW69vc; arc=none smtp.client-ip=209.85.216.73 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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d+pW69vc" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3663d5e9b9bso5562172a91.1 for ; Wed, 20 May 2026 20:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779335986; x=1779940786; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Es5OLNZJR1f68aIHWnCqNasuOCwHoEK1cPtEA+NE838=; b=d+pW69vcXILApPyl6h9U5JXddCJjKQRrQJ7iNAEwkyCCzdt3yPfgtV5q91H85rpLTD +0FtBJhruIjcKNQ9p8+yVd3o5NPB8iz4PQchUYR4Sw5vVIcu/rJyEAkotNhxHEADUp1z QmNn9bmJdtVYNA7J9ESo3PqJ6CTNcUuLxTIod8XA7biunKYFdZMLeCOh6InmFAxGnPNW m6JBMZmovadMMRQ2JBrv1h2muGxaAzO8xtSOjkgLhPKR9oS0m1bkBs8ybSY2I0XbAnmR 2ejaYYVylWHgqpShBjlX1v7HIAkHnuBIfUuU671tRKNAjLHvegT+rYXNNorziMeRmtD2 JO+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779335986; x=1779940786; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Es5OLNZJR1f68aIHWnCqNasuOCwHoEK1cPtEA+NE838=; b=tEI1jAKGX67FyBRp9f4F3YBkKmvBGBhx8wiKCKoO+Wa+pH31pY7gbL5eInFfWVK4ZG sojBjGoctplxNm9ltZowiAHXlxkaeOhy1SMelsM3XnkxCq+zASJBfyeQsJyKM2tlMBXH PamZj+5lWwQT6HG/JUELg1BZplNecrIaWAQ69nxz+1p0hS/eQ080AINizzcvsfOrdKWu eo24L6aENywekLwg6kVM/BboIUeCBjXJzDldVciSInERAyd6PC1c2YdMnE+PFP82nmJG klX/SBA10jDKqUZWNeHxdWj7W1OyZbOl5s43FXA77a1ogjecov3WNKiZm/UFfx4WPQ+t I9nw== X-Forwarded-Encrypted: i=1; AFNElJ+sDbpUJ9RyYy7hK834AGCekw2nxcqNAWUGBqxzzhrRdJ8BtLj7gXMVg5Skodq5ZeLbcaLy6XMvGs8iMWk=@vger.kernel.org X-Gm-Message-State: AOJu0YwtXQRQwyI5SupQYT5pwLRDrvs6pn5u9y1VYEAN7LWm93uFlkso qUVo7N2P81mDshFgY7PG5Hov1FWy2qcb7/FH+wWfzBR30iL8IWoDhX0SJDKEzwaHnZTX0dTOdWw NzXbkKg== X-Received: from pjwt6.prod.google.com ([2002:a17:90a:d146:b0:368:3aec:213]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3fcc:b0:368:d839:28d5 with SMTP id 98e67ed59e1d1-36a455f9526mr1147017a91.18.1779335985944; Wed, 20 May 2026 20:59:45 -0700 (PDT) Date: Wed, 20 May 2026 20:59:40 -0700 In-Reply-To: <20260521035941.3860145-1-ctshao@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260521035941.3860145-1-ctshao@google.com> X-Mailer: git-send-email 2.54.0.669.g59709faab0-goog Message-ID: <20260521035941.3860145-2-ctshao@google.com> Subject: [PATCH v2 1/2] perf stat: Add aggr_nr metric parser support From: Chun-Tse Shao To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, james.clark@linaro.org, sandipan.das@amd.com, leo.yan@arm.com, thomas.falcon@intel.com, yang.lee@linux.alibaba.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Chun-Tse Shao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the `aggr_nr` function to the metric expression parser. `aggr_nr` allows metric formulas to dynamically utilize the number of aggregated targets (`aggr->nr`) instead of relying on the static `source_count` (which represents the static socket or node count). This adds the `AGGR_NR` token to the lexer and parser, updates the expression parsing context helpers to store `aggr_nr`, and feeds `aggr->nr` from the aggregation structure in `prepare_metric`. Signed-off-by: Chun-Tse Shao Assisted-by: Gemini:gemini-3.1-pro-preview --- tools/perf/util/expr.c | 26 ++++++++++++++++++++++---- tools/perf/util/expr.h | 6 +++++- tools/perf/util/expr.l | 1 + tools/perf/util/expr.y | 24 +++++++++++++++++------- tools/perf/util/stat-shadow.c | 6 +++++- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 644769e92708..232998fef72b 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -27,6 +27,7 @@ struct expr_id_data { struct { double val; int source_count; + int aggr_nr; } val; struct { double val; @@ -151,8 +152,8 @@ int expr__add_id_val(struct expr_parse_ctx *ctx, const = char *id, double val) } =20 /* Caller must make sure id is allocated */ -int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *= id, - double val, int source_count) +int expr__add_id_val_source_count_aggr_nr(struct expr_parse_ctx *ctx, cons= t char *id, + double val, int source_count, int aggr_nr) { struct expr_id_data *data_ptr =3D NULL, *old_data =3D NULL; char *old_key =3D NULL; @@ -163,6 +164,7 @@ int expr__add_id_val_source_count(struct expr_parse_ctx= *ctx, const char *id, return -ENOMEM; data_ptr->val.val =3D val; data_ptr->val.source_count =3D source_count; + data_ptr->val.aggr_nr =3D aggr_nr; data_ptr->kind =3D EXPR_ID_DATA__VALUE; =20 ret =3D hashmap__set(ctx->ids, id, data_ptr, &old_key, &old_data); @@ -171,12 +173,20 @@ int expr__add_id_val_source_count(struct expr_parse_c= tx *ctx, const char *id, } else if (old_data) { data_ptr->val.val +=3D old_data->val.val; data_ptr->val.source_count +=3D old_data->val.source_count; + data_ptr->val.aggr_nr +=3D old_data->val.aggr_nr; } free(old_key); free(old_data); return ret; } =20 +/* Caller must make sure id is allocated */ +int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *= id, + double val, int source_count) +{ + return expr__add_id_val_source_count_aggr_nr(ctx, id, val, source_count, = 1); +} + int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref) { struct expr_id_data *data_ptr =3D NULL, *old_data =3D NULL; @@ -390,8 +400,16 @@ double expr_id_data__value(const struct expr_id_data *= data) =20 double expr_id_data__source_count(const struct expr_id_data *data) { - assert(data->kind =3D=3D EXPR_ID_DATA__VALUE); - return data->val.source_count; + if (data->kind =3D=3D EXPR_ID_DATA__VALUE) + return data->val.source_count; + return 1.0; +} + +double expr_id_data__aggr_nr(const struct expr_id_data *data) +{ + if (data->kind =3D=3D EXPR_ID_DATA__VALUE) + return data->val.aggr_nr; + return 1.0; } =20 double expr__get_literal(const char *literal, const struct expr_scanner_ct= x *ctx) diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index c0cec29ddc29..ed12e4007d2d 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -36,7 +36,9 @@ void expr__del_id(struct expr_parse_ctx *ctx, const char = *id); int expr__add_id(struct expr_parse_ctx *ctx, const char *id); int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double va= l); int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *= id, - double val, int source_count); + double val, int source_count); +int expr__add_id_val_source_count_aggr_nr(struct expr_parse_ctx *ctx, cons= t char *id, + double val, int source_count, int aggr_nr); int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); int expr__get_id(struct expr_parse_ctx *ctx, const char *id, struct expr_id_data **data); @@ -53,6 +55,8 @@ int expr__find_ids(const char *expr, const char *one, =20 double expr_id_data__value(const struct expr_id_data *data); double expr_id_data__source_count(const struct expr_id_data *data); +double expr_id_data__aggr_nr(const struct expr_id_data *data); + double expr__get_literal(const char *literal, const struct expr_scanner_ct= x *ctx); double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids,= const char *id); double expr__strcmp_cpuid_str(const struct expr_parse_ctx *ctx, bool compu= te_ids, const char *id); diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l index a2fc43159ee9..f16ccff278d0 100644 --- a/tools/perf/util/expr.l +++ b/tools/perf/util/expr.l @@ -121,6 +121,7 @@ min { return MIN; } if { return IF; } else { return ELSE; } source_count { return SOURCE_COUNT; } +aggr_nr { return AGGR_NR; } has_event { return HAS_EVENT; } strcmp_cpuid_str { return STRCMP_CPUID_STR; } NaN { return nan_value(yyscanner); } diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index e364790babb5..e20f649354cf 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -41,7 +41,7 @@ int expr_lex(YYSTYPE * yylval_param , void *yyscanner); } ids; } =20 -%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO SOURCE_COUNT HAS_EVENT ST= RCMP_CPUID_STR EXPR_ERROR +%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO SOURCE_COUNT AGGR_NR HAS_= EVENT STRCMP_CPUID_STR EXPR_ERROR %left MIN MAX IF %left '|' %left '^' @@ -87,8 +87,14 @@ static struct ids union_expr(struct ids ids1, struct ids= ids2) return result; } =20 +enum expr_id_kind { + EXPR_ID_KIND__VALUE, + EXPR_ID_KIND__SOURCE_COUNT, + EXPR_ID_KIND__AGGR_NR, +}; + static struct ids handle_id(struct expr_parse_ctx *ctx, char *id, - bool compute_ids, bool source_count) + bool compute_ids, enum expr_id_kind kind) { struct ids result; =20 @@ -101,9 +107,12 @@ static struct ids handle_id(struct expr_parse_ctx *ctx= , char *id, =20 result.val =3D NAN; if (expr__resolve_id(ctx, id, &data) =3D=3D 0) { - result.val =3D source_count - ? expr_id_data__source_count(data) - : expr_id_data__value(data); + if (kind =3D=3D EXPR_ID_KIND__SOURCE_COUNT) + result.val =3D expr_id_data__source_count(data); + else if (kind =3D=3D EXPR_ID_KIND__AGGR_NR) + result.val =3D expr_id_data__aggr_nr(data); + else + result.val =3D expr_id_data__value(data); } result.ids =3D NULL; free(id); @@ -201,8 +210,9 @@ expr: NUMBER $$.val =3D $1; $$.ids =3D NULL; } -| ID { $$ =3D handle_id(ctx, $1, compute_ids, /*source_count=3D*/false)= ; } -| SOURCE_COUNT '(' ID ')' { $$ =3D handle_id(ctx, $3, compute_ids, /*sourc= e_count=3D*/true); } +| ID { $$ =3D handle_id(ctx, $1, compute_ids, EXPR_ID_KIND__VALUE); } +| SOURCE_COUNT '(' ID ')' { $$ =3D handle_id(ctx, $3, compute_ids, EXPR_ID= _KIND__SOURCE_COUNT); } +| AGGR_NR '(' ID ')' { $$ =3D handle_id(ctx, $3, compute_ids, EXPR_ID_KIN= D__AGGR_NR); } | HAS_EVENT '(' ID ')' { $$.val =3D expr__has_event(ctx, compute_ids, $3); diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index bc2d44df7baf..c17373bb0e1e 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -53,6 +53,7 @@ static int prepare_metric(struct perf_stat_config *config, =20 for (i =3D 0; metric_events[i]; i++) { int source_count =3D 0, tool_aggr_idx; + int aggr_nr =3D 1; bool is_tool_time =3D tool_pmu__is_time_event(config, metric_events[i], &tool_aggr_idx); struct perf_stat_evsel *ps =3D metric_events[i]->stats; @@ -89,6 +90,7 @@ static int prepare_metric(struct perf_stat_config *config, */ val =3D NAN; source_count =3D 0; + aggr_nr =3D 0; } else { struct perf_stat_aggr *aggr =3D &ps->aggr[is_tool_time ? tool_aggr_idx : aggr_idx]; @@ -96,6 +98,7 @@ static int prepare_metric(struct perf_stat_config *config, if (aggr->counts.run =3D=3D 0) { val =3D NAN; source_count =3D 0; + aggr_nr =3D 0; } else { val =3D aggr->counts.val; if (is_tool_time) { @@ -104,13 +107,14 @@ static int prepare_metric(struct perf_stat_config *co= nfig, } if (!source_count) source_count =3D evsel__source_count(metric_events[i]); + aggr_nr =3D aggr->nr ?: 1; } } n =3D strdup(evsel__metric_id(metric_events[i])); if (!n) return -ENOMEM; =20 - expr__add_id_val_source_count(pctx, n, val, source_count); + expr__add_id_val_source_count_aggr_nr(pctx, n, val, source_count, aggr_n= r); } =20 for (int j =3D 0; metric_refs && metric_refs[j].metric_name; j++) { --=20 2.54.0.669.g59709faab0-goog From nobody Sun May 24 21:37:42 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 07321385D98 for ; Thu, 21 May 2026 03:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779335989; cv=none; b=DWEz4FA1Q/knrYdbzHSjFGzR3ulD0R0Q80ssqVQaNqooM8STad96fG40SxewRmBAZuys5tR+uvrc40gZDjTZfRDryhcDKMJL+5UT5G+h4HBWN5Sx5SLyAWT8oVwRv+YUUv4dYul2yZmYvEtoVOsMwJWmJAnlBU9aNkijxUS8WL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779335989; c=relaxed/simple; bh=oIraJFcdmCZeZxqwqAXFF/MvJAlmRPO/Y9o6YnJ1k2I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ukj8TqFvWkW6Gp3Gj0ojzvGgabhYpwPNjJ2PVTzTPLE/cCc/+c4W2oGBBT34CMRoVhczF7qaF7nEmTRksua1F6HDZyU7tDa9wdcN+kY08wZmZanHg2E8RBt1uT1lvxY4k71c8TRIguVM0SFuC/zBEXQE2JMZWVo6uGJQKa9Ytgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ctshao.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tvk/pgEh; arc=none smtp.client-ip=209.85.210.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--ctshao.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tvk/pgEh" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8397b14a689so3751666b3a.2 for ; Wed, 20 May 2026 20:59:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779335987; x=1779940787; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Km7j/1fh2HMB9gyR4gTuaHGP0nXdKFB9TrlgcUk5uNw=; b=tvk/pgEh4wCHrSa+WIuM9D2SKqwm7f2dPK4BQIgDiM8WPnri3S1VPS7aj2BOb+6Mb2 V0JnfIhLzrF1Oi19+OVLbeat8y+t7i7LbXBFa1fDFIZPilX53toCCnN7XYvqhyX30+Nk tS7pqb5FEazWxoYYRY/ogglUoBiiDySjmqG7bX4Wa7r3nA6aYRpo02F27bq2LBJKspWR NbdfoYBS0ff7Y9T8BxyNphvlAfzTIY2FyAP47i0C+y6X/SnGK0YpgtYeL90VHQQYjz1j 4K3ZZudan4AzN9EIOsXaEcimxfrG3kEFyRG+J4yOscvFYde92CqHplHBKGXVb1sjIVdK qYtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779335987; x=1779940787; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Km7j/1fh2HMB9gyR4gTuaHGP0nXdKFB9TrlgcUk5uNw=; b=WNGvNEdQTNj+6gn55R7ftn3NLi4644ZBtxC1ii96nbFRU2ESr+3TrbKxe0O/dh+h9b 4vxFTBZny+QplT8/kB/khAJoUK+379rQLRPZFYp+OCOyB3SK3n1Cfw/hkEKwuZSSH9tA 4cJbKrg+8UaK1CxMAjh6Bvie4KuiVHiX/m80OXmrXgExmIeAHQ/OUO/NQO8Hy6hvMfn3 nU+Y7pS5qTiH+28rspp6ItUaf4idBTZHzAd4hY2xma7CoAaOyDtqqitKMv/9gMSjIyAD uCs1j1ykA+ktD17s4hx2ruyaHLL+megUQXYibOfQToZcPU6Lo/4/gow4rDqeeR6Fysk4 Y85g== X-Forwarded-Encrypted: i=1; AFNElJ9r3tZIp+dG5bfbZmg+ozUIxkJAfyJZKl4luD7ngPnKXJB8hUotiiYiJ4wJNboBqjGzLcJJ6mmE5gPc0xY=@vger.kernel.org X-Gm-Message-State: AOJu0YzRGKaMvtM/3O3H4g2V4ixL+SRlViufElTnLp13nUJt7KBF6Ycq e6FRwV8DbWQf7IpWVh/wvc4SC9l6wfkvwCB03YRVZKoxIIQ+Ko+TdUBe18vnnXssnQUfMXA8J5m Lvw7u5Q== X-Received: from pfbik6.prod.google.com ([2002:a05:6a00:8d06:b0:835:394c:6e39]) (user=ctshao job=prod-delivery.src-stubby-dispatcher) by 2002:aa7:88cd:0:b0:837:d746:8e1a with SMTP id d2e1a72fcca58-8414ad4a498mr1255250b3a.22.1779335986920; Wed, 20 May 2026 20:59:46 -0700 (PDT) Date: Wed, 20 May 2026 20:59:41 -0700 In-Reply-To: <20260521035941.3860145-1-ctshao@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260521035941.3860145-1-ctshao@google.com> X-Mailer: git-send-email 2.54.0.669.g59709faab0-goog Message-ID: <20260521035941.3860145-3-ctshao@google.com> Subject: [PATCH v2 2/2] perf stat: Use aggr_nr scaling for Intel uncore miss latency metrics From: Chun-Tse Shao To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, james.clark@linaro.org, sandipan.das@amd.com, leo.yan@arm.com, thomas.falcon@intel.com, yang.lee@linux.alibaba.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Chun-Tse Shao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update `metric.py` to support the new `aggr_nr` keyword in the python metric generator. Replace the usage of `source_count` with `aggr_nr` in `IntelMissLat` inside `intel_metrics.py` so that uncore latency metrics (like `lpm_miss_lat`) scale correctly on multi-socket and SNC systems when aggregated globally. Signed-off-by: Chun-Tse Shao Assisted-by: Gemini:gemini-3.1-pro-preview --- tools/perf/pmu-events/intel_metrics.py | 6 +++--- tools/perf/pmu-events/metric.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/perf/pmu-events/intel_metrics.py b/tools/perf/pmu-events= /intel_metrics.py index 52035433b505..d99c7dd43797 100755 --- a/tools/perf/pmu-events/intel_metrics.py +++ b/tools/perf/pmu-events/intel_metrics.py @@ -7,7 +7,7 @@ import os import re from typing import Optional from common_metrics import Cycles -from metric import (d_ratio, has_event, max, source_count, CheckPmu, Event, +from metric import (d_ratio, has_event, max, aggr_nr, CheckPmu, Event, JsonEncodeMetric, JsonEncodeMetricGroupDescriptions, Literal, LoadEvents, Metric, MetricConstraint, MetricG= roup, MetricRef, Select) @@ -674,10 +674,10 @@ def IntelMissLat() -> Optional[MetricGroup]: else: assert data_rd_loc_occ.name =3D=3D "UNC_CHA_TOR_OCCUPANCY.IA_MISS_= DRD_LOCAL", data_rd_loc_occ =20 - ticks_per_cha =3D ticks / source_count(data_rd_loc_ins) + ticks_per_cha =3D ticks / aggr_nr(data_rd_loc_ins) loc_lat =3D interval_sec * 1e9 * data_rd_loc_occ / \ (ticks_per_cha * data_rd_loc_ins) - ticks_per_cha =3D ticks / source_count(data_rd_rem_ins) + ticks_per_cha =3D ticks / aggr_nr(data_rd_rem_ins) rem_lat =3D interval_sec * 1e9 * data_rd_rem_occ / \ (ticks_per_cha * data_rd_rem_ins) return MetricGroup("lpm_miss_lat", [ diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric= .py index ac582db785fc..6bce4eeed875 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -93,7 +93,7 @@ def CheckEveryEvent(*names: str) -> None: name =3D name[:name.find(':')] elif '/' in name: name =3D name[:name.find('/')] - if any([name.startswith(x) for x in ['amd', 'arm', 'cpu', 'msr', 'po= wer']]): + if any([name.startswith(x) for x in ['amd', 'arm', 'cpu', 'msr', 'po= wer', 'cha', 'uncore']]): continue if name not in all_events_all_models: raise Exception(f"Is {name} a named json event?") @@ -576,6 +576,12 @@ def source_count(event: Event) -> Function: return Function('source_count', event) =20 =20 +def aggr_nr(event: Event) -> Function: + # pylint: disable=3Dredefined-builtin + # pylint: disable=3Dinvalid-name + return Function('aggr_nr', event) + + def has_event(event: Event) -> Function: # pylint: disable=3Dredefined-builtin # pylint: disable=3Dinvalid-name @@ -762,7 +768,7 @@ def ParsePerfJson(orig: str) -> Expression: # Convert accidentally converted scientific notation constants back py =3D re.sub(r'([0-9]+)Event\(r"(e[0-9]*)"\)', r'\1\2', py) # Convert all the known keywords back from events to just the keyword - keywords =3D ['if', 'else', 'min', 'max', 'd_ratio', 'source_count', 'ha= s_event', 'strcmp_cpuid_str'] + keywords =3D ['if', 'else', 'min', 'max', 'd_ratio', 'source_count', 'ag= gr_nr', 'has_event', 'strcmp_cpuid_str'] for kw in keywords: py =3D re.sub(rf'Event\(r"{kw}"\)', kw, py) try: --=20 2.54.0.669.g59709faab0-goog