From nobody Thu Dec 11 19:23:43 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 D74F92DCC1C for ; Tue, 2 Dec 2025 17:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698011; cv=none; b=V1IoXm92q+9JYRhijxGdhHUBMAZiW+pfZqcpX7LfPeHoWvoiAY9SN8Rber+wRjM3bzIeuIzgWJGRWrRjP1yXeNprc69mV2PsQyZJfGXm4TbEeMgo3kx1ym+4NlE6el/SL/AGKaFMMs376qwnhEQOQ/tqZwT+/8kjf4HALnuGQAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698011; c=relaxed/simple; bh=MZXPJkMLlvQNY7LHqMpGBAhv97bAcZIryty0ZB5qdjg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=d6gPLvYEuFdQ7nspHtOoYhV/Yx1xCEjoDFkIkzmj5bJa5rELPXPGlZSvhHEMHdd/fOyxmDRy23D8ZZYfUPkFjWFmft+kFNyIoST3xBjm0V2Tl6ASTKcCR4pHSWf9NzO29MNd2RJF4lv/ncBADFdpcib4MjIiT5nPNxkGp6VqpsE= 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=HcGtmwUq; arc=none smtp.client-ip=209.85.215.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="HcGtmwUq" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b62da7602a0so5749932a12.2 for ; Tue, 02 Dec 2025 09:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764698009; x=1765302809; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6yKsrOLMclOdMSfZ+6mo1yB+Cr3YWn8XAIMVSOQS/0A=; b=HcGtmwUqgrOxpCs6Sj1Ixtcy7mcDHImackitLrxcRAJwp4cGOEClyyOYwxwSVSjhuw OPwnXjlZ9bLaDQsmkrXDktzhSMfRJY4HrlyU/+s8Mpde3HL0Sz1OBwhzNgHoyBNJ+XQE uGC9FfsSivXQWy3AOG1TOg4+hWchtGXrnlU1P0GEnCuMRl3MKABAmHppdWTk+li8xZXN gbjr9g2lvLs9ZT85hzQHYMVvrXSw+EH2JRZo+tW4jNwDegJR9NipSbD27HiSxpFIK4bL RWlxrgIHH5Wc4SDo3I6dLyTuoS0EHPctvLRdjstkygHIYsfmtwjyYMvA9gNMnnwFDFr7 ht3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764698009; x=1765302809; h=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=6yKsrOLMclOdMSfZ+6mo1yB+Cr3YWn8XAIMVSOQS/0A=; b=gy3a9rJSY1SaYQz8daDEJ9CID9DNu7kXalua/ZRktNkPJ0xp+S2SyjpwHSgKOH1jwC b7CyU3qEB3j7KqQqo6+LI32I9pL1fOhUY1tehYR/EES6brQi+h2ZLU4R7OYMY/hQ27DW NMYpKnEfsRkYMexLMZiVtEVIVUsye1S150Gw7PidpHBsbJXgVI8E5TZ2F7D+EW3+Kuce q8ew3nj6Sq5cUfZ6Vk6EV1uBvlOA+/L8pjNIwGlafvZKJm9dxUnNIcCbJWI3MghhSD4x 3GK4WIYl4L/Ea4inaA/od2CEBJKGepFtJwrMoHy+3arKHuHT4rKvHNTcRjEw9EKkJn7Q ipRA== X-Forwarded-Encrypted: i=1; AJvYcCXGcYLPmNQYZzwa7GQHrWMzvW1wW0GLmcDyYjwgNXyWazwAp9vUA6bvgKdS8W5b6IeCxlI9nYJ2rEoyyao=@vger.kernel.org X-Gm-Message-State: AOJu0YwcTl5Qp8VkQR75HXmsvCP06jpzBeUHuF9duOaoVvLnb6OFhdoE kfZuljyQgHkRU3oYmE5TNWJd4pBCUiUry75IJVg1FH97T/RQ9q+X9pt2h3QyZVzo+rOoCnvlFI8 07CbKGx/jMg== X-Google-Smtp-Source: AGHT+IFSIde/+fPa+0ZqRrpBH+S18iPNZHaJ0ifGIDW2rIQ4u05BWtnonHxrlryeIKv0J8KmlzXSZM6K5qoW X-Received: from dybmz9.prod.google.com ([2002:a05:7300:d4c9:b0:2a4:6f9d:b3cb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6a9:b0:11b:9152:b3ad with SMTP id a92af1059eb24-11defcfa65fmr154636c88.31.1764698009304; Tue, 02 Dec 2025 09:53:29 -0800 (PST) Date: Tue, 2 Dec 2025 09:50:23 -0800 In-Reply-To: <20251202175043.623597-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251202175043.623597-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251202175043.623597-29-irogers@google.com> Subject: [PATCH v9 28/48] perf jevents: Mark metrics with experimental events as experimental From: Ian Rogers To: Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Benjamin Gray , Caleb Biggers , Edward Baker , Ian Rogers , Ingo Molnar , James Clark , Jing Zhang , Jiri Olsa , John Garry , Leo Yan , Namhyung Kim , Perry Taylor , Peter Zijlstra , Samantha Alt , Sandipan Das , Thomas Falcon , Weilin Wang , Xu Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When metrics are made with experimental events it is desirable the metric description also carries this information in case of metric inaccuracies. Suggested-by: Perry Taylor Signed-off-by: Ian Rogers Tested-by: Thomas Falcon --- tools/perf/pmu-events/metric.py | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric= .py index 62d1a1e1d458..2029b6e28365 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -10,11 +10,13 @@ from typing import Dict, List, Optional, Set, Tuple, Un= ion =20 all_pmus =3D set() all_events =3D set() +experimental_events =3D set() =20 def LoadEvents(directory: str) -> None: """Populate a global set of all known events for the purpose of validati= ng Event names""" global all_pmus global all_events + global experimental_events all_events =3D { "context\\-switches", "cpu\\-cycles", @@ -32,6 +34,8 @@ def LoadEvents(directory: str) -> None: all_pmus.add(x["Unit"]) if "EventName" in x: all_events.add(x["EventName"]) + if "Experimental" in x and x["Experimental"] =3D=3D "1": + experimental_events.add(x["EventName"]) elif "ArchStdEvent" in x: all_events.add(x["ArchStdEvent"]) except json.decoder.JSONDecodeError: @@ -61,6 +65,18 @@ def CheckEvent(name: str) -> bool: return name in all_events =20 =20 +def IsExperimentalEvent(name: str) -> bool: + global experimental_events + if ':' in name: + # Remove trailing modifier. + name =3D name[:name.find(':')] + elif '/' in name: + # Name could begin with a PMU or an event, for now assume it is not ex= perimental. + return False + + return name in experimental_events + + class MetricConstraint(Enum): GROUPED_EVENTS =3D 0 NO_GROUP_EVENTS =3D 1 @@ -82,6 +98,10 @@ class Expression: """Returns a simplified version of self.""" raise NotImplementedError() =20 + def HasExperimentalEvents(self) -> bool: + """Are experimental events used in the expression?""" + raise NotImplementedError() + def Equals(self, other) -> bool: """Returns true when two expressions are the same.""" raise NotImplementedError() @@ -249,6 +269,9 @@ class Operator(Expression): =20 return Operator(self.operator, lhs, rhs) =20 + def HasExperimentalEvents(self) -> bool: + return self.lhs.HasExperimentalEvents() or self.rhs.HasExperimentalEve= nts() + def Equals(self, other: Expression) -> bool: if isinstance(other, Operator): return self.operator =3D=3D other.operator and self.lhs.Equals( @@ -297,6 +320,10 @@ class Select(Expression): =20 return Select(true_val, cond, false_val) =20 + def HasExperimentalEvents(self) -> bool: + return (self.cond.HasExperimentalEvents() or self.true_val.HasExperime= ntalEvents() or + self.false_val.HasExperimentalEvents()) + def Equals(self, other: Expression) -> bool: if isinstance(other, Select): return self.cond.Equals(other.cond) and self.false_val.Equals( @@ -345,6 +372,9 @@ class Function(Expression): =20 return Function(self.fn, lhs, rhs) =20 + def HasExperimentalEvents(self) -> bool: + return self.lhs.HasExperimentalEvents() or (self.rhs and self.rhs.HasE= xperimentalEvents()) + def Equals(self, other: Expression) -> bool: if isinstance(other, Function): result =3D self.fn =3D=3D other.fn and self.lhs.Equals(other.lhs) @@ -384,6 +414,9 @@ class Event(Expression): global all_events raise Exception(f"No event {error} in:\n{all_events}") =20 + def HasExperimentalEvents(self) -> bool: + return IsExperimentalEvent(self.name) + def ToPerfJson(self): result =3D re.sub('/', '@', self.name) return result @@ -416,6 +449,9 @@ class MetricRef(Expression): def Simplify(self) -> Expression: return self =20 + def HasExperimentalEvents(self) -> bool: + return False + def Equals(self, other: Expression) -> bool: return isinstance(other, MetricRef) and self.name =3D=3D other.name =20 @@ -443,6 +479,9 @@ class Constant(Expression): def Simplify(self) -> Expression: return self =20 + def HasExperimentalEvents(self) -> bool: + return False + def Equals(self, other: Expression) -> bool: return isinstance(other, Constant) and self.value =3D=3D other.value =20 @@ -465,6 +504,9 @@ class Literal(Expression): def Simplify(self) -> Expression: return self =20 + def HasExperimentalEvents(self) -> bool: + return False + def Equals(self, other: Expression) -> bool: return isinstance(other, Literal) and self.value =3D=3D other.value =20 @@ -527,6 +569,8 @@ class Metric: self.name =3D name self.description =3D description self.expr =3D expr.Simplify() + if self.expr.HasExperimentalEvents(): + self.description +=3D " (metric should be considered experimental as= it contains experimental events)." # Workraound valid_only_metric hiding certain metrics based on unit. scale_unit =3D scale_unit.replace('/sec', ' per sec') if scale_unit[0].isdigit(): --=20 2.52.0.158.g65b55ccf14-goog