From nobody Thu Nov 28 23:35:30 2024 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 D770E17C9AB for ; Thu, 26 Sep 2024 17:50:55 +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=1727373057; cv=none; b=fpbgbZk+6rr7+AiekPBI7gnW50+oSCi7bPyzULVSekqBOwOxpLV+/QuHctppuVKqXuPBuUXxjpmSJyQfVk8PUB6ColkH2iPTO/foWLbtvguQvexJK4uMVD5rsRXM2QniJvoyB03UlbzckZxqRmRYvbdsYKeUiUXnWN52xFds+Bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727373057; c=relaxed/simple; bh=ICcVxv+UyFgPMNrlS4j3aiB4i7w/ckgDEbEFD25XhuA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=gpm3QwCwOYte5i4nbzvKstK79p/U6WwgGH1dPrkkpd7hahBlfXjra4NsXZ+lb1kqWgUs4VbQnBQ0RQiAaO4Eln19sWaUDKV860wp6B75K8kR67MbU7vPhrhvB+Wzqi51Sma3CGc0sLFC7kpDZ/JfUmMzns4eFQWy09JPEizIU7k= 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=Gj8Iu4hI; 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="Gj8Iu4hI" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e230808455so14652247b3.0 for ; Thu, 26 Sep 2024 10:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1727373055; x=1727977855; 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=4B9vpDYckgMVzZMwIS1VEulT7jmK7bkxMhwxzZt+RHc=; b=Gj8Iu4hIDjUYV6w6Vd7tk5muLbWJ3E2xwfAi+eyhK7fXzHnWS753eDjjiyRjrSkMYO QIAUraOxhZLyM7OoX1/Dm4hhDtPmxUFYY69ZHqc6jSjQ/tidImvRx/DEKgseEyMWTNUy fgWHRprQVgTMb4/KbusMcDn6d2xTAqfdTrb3wb+QMdLS2pGv+noK3B6jYyDyzh/BFAmw DeHLibX7Bfql1SJMBs6dASzKV71l9Gg0jdXm9/XsOGD1ZZ0elPb9gAmPX2rpsJ+xhbvt pvHHPBTgDaJymLC/TD4aXuxNsiGd0YdsbG4kb2egcbZa0MpB4ZysgJn6lfYF2kXYb2eI 0eeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727373055; x=1727977855; 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=4B9vpDYckgMVzZMwIS1VEulT7jmK7bkxMhwxzZt+RHc=; b=VUpbRS8F2u0jj/cCgR8iUlAoHHghL6FylXYG0UD0V8xEQQFRkOb0BAUsTUD+Kcnb5J 9roJDvptFw/LGukgqjhpjyQSxuk6eVbPB0agmAQOXQb/bqlRUPE+fNx7YK/rTAyWyTQY zuhX1BC1Pipkt0PMPPEkE46zWhK0x+4hlYjkOHAQ0IzmxgLek5Tc7fQYW49QMrk5MtCs XxKFnpcWFT6K0ByyRhXllwUl8ShJu1rJPajvpzDjttUuKbN8ouH/jWAkEzK1XXZTSt33 vZ/BMj//3zzYYtZPXz2ncCecKPowydouLwg5pmTfORvnAfeKMI+pFQztACX04Hz4NYJl BIXg== X-Forwarded-Encrypted: i=1; AJvYcCUaY1/W3W/r5vDbwrPaqjTq5+Y6p6Oj1LptmWeF3nU5cxTO78B4ljIKbOeu77/zHWEEqxX78SCiq3yz9zE=@vger.kernel.org X-Gm-Message-State: AOJu0Yxa/W9KAXo+EMtwo0EfFiuqJWAVy+3GSNTZb+taWw/uqLTFYy0g Lde5r8FNpVojMJJNdc8Bgngcej0kVVp02JkJyK+tGR26YOtW98tAZr1Yz/w0kUkGP+k40MUGwuT L2MhpTQ== X-Google-Smtp-Source: AGHT+IHu1Wu1yvCEeVXIoy6Myp89+gmMr8a38UxhSha+KdoN53xDvk4XhZ7obE8Tjukw75hteMPc8VyI5Nyn X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:8872:3585:18ed:a056]) (user=irogers job=sendgmr) by 2002:a05:690c:d8c:b0:6b1:8b74:978a with SMTP id 00721157ae682-6e2475a7f4emr52837b3.4.1727373054895; Thu, 26 Sep 2024 10:50:54 -0700 (PDT) Date: Thu, 26 Sep 2024 10:50:18 -0700 In-Reply-To: <20240926175035.408668-1-irogers@google.com> Message-Id: <20240926175035.408668-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240926175035.408668-1-irogers@google.com> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog Subject: [PATCH v4 05/22] perf jevents: Mark metrics with experimental events as experimental 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker 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 --- 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 e1847cccfdb0..5a5b149dd286 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", "cycles", @@ -30,6 +32,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"]) =20 @@ -55,6 +59,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 @@ -76,6 +92,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() @@ -243,6 +263,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( @@ -291,6 +314,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( @@ -339,6 +366,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) @@ -378,6 +408,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 @@ -410,6 +443,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 @@ -437,6 +473,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 @@ -459,6 +498,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 @@ -521,6 +563,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.46.1.824.gd892dcdcdd-goog