From patchwork Thu Jan 26 23:36:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82C09C54EAA for ; Thu, 26 Jan 2023 23:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=elhhQheaAdG9noeyfyE88a31Xp9A9+8sgturQ8wN6YM=; b=UMXolLyKRAwME2bDk+mstPOPUG bHno1/lXNdcae9OP/Z/Vr0eSMtusf9556NLPp2+o7/pA65SXyZSNU02PQ3uLHgfc2MVmtHfpHrn4q XHVkmrE3Auo0VdHJcWM4zMdbjmtOveEHjsT+DDqw+cnoPrSSlPL4F3+Txob+8dsGCRMiqeSEe8H9Z Mei54VxM/e0QNqGYyECn0lGffsjgUSlc4FpjqHWc5NskXS+6ICoWX43zR29cyS+AdIAseDENIrruI MQ748Ctbm8hSb5NPBN0P5sNwR73GA8Vewsat68NDg2Mo315RABNjLYojNNsiu/ncDgXQ61EGbXJ12 uSNMIg7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBo1-00Ckuy-B0; Thu, 26 Jan 2023 23:37:21 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBny-00Cksc-9Y for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:19 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id n8-20020a258d08000000b007facaf67acfso3626272ybl.0 for ; Thu, 26 Jan 2023 15:37:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ExyRpkcDLmvPbAA8QgL36/HbLE4lSe5Woy02Q1CnQZ0=; b=b7HSkW9BPwilG22qgpz9e/XOczfoW9yCKXfLOvRsQ9wBfqrGhxw2TaKrwXSt1PVsdd M84LPosr6r3kuqQWcN/LiSEFmX+TevYFm1LpD7/Li9Wl50Vsaf3LCddQumROgGmGUQQo epcbUYKS1qYwHxdY3eYWhKb5WXtHQlyT4DGWMlEDAMRxU6fx9f/ndV3g1nvwZ0EbCP4u 7PWHk+CStL2Y52640ZelIpaMIrqnKYJMMCSRgY4Yf4cjgJ/FlSpmQMgJ2ek0reIkgHqU qVc2P92NXw7JlhdQKxeHJhHhZGm/8MMORkIPhEqswrvqLVXc9MnbKxUzglvGNAe127by LbSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=ExyRpkcDLmvPbAA8QgL36/HbLE4lSe5Woy02Q1CnQZ0=; b=TZTlG0hID+WwSVrQhpFMdo/zBIXGQktBNTDEI83BK2AVYPkGHA7BMP/vokogEB0L7C gKsvBUZxtqoLh7G1DhiUJs4AIIZd7G3Qcpp7EMxbtPgGlaEQfi3tc/A6fJzD4NNxz3A/ EpLGPq7UGwCyn4b2Gf8LU3x1NBhDaqWfDxcD+npXehoHm8nwSeVuwdmB6zEKbrQ0WwN+ wpuWC+IHM4qlEhg2TfNxtykkmWyGZC2xioEql2R4LV6rju9NmvJkAdtDosi5h5zKqKwD lYCDBXl/+pMja2Hl7uVhsy4OGL6IKALz3VbDBrJUAYIL+LdCN0KcTWEa3t21PPFtGWan Rjjw== X-Gm-Message-State: AFqh2koU+p3HKUwUmFS7rbbYQY4VjgJUWvPTIKrFRx85Nm28hRlQ259S 42inqm8mtO0izxSgqkjRX7cmuRVb8XIh X-Google-Smtp-Source: AMrXdXuVZJSXhsLBJF4s+rqkvT9ejKCkIXS7lhPHPbiIAmWd7TUMwVa2Yo0mIGWQgyijPi/6uHMwa59GCZY/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a81:ed4:0:b0:4dd:c62f:d65a with SMTP id 203-20020a810ed4000000b004ddc62fd65amr3419482ywo.427.1674776225629; Thu, 26 Jan 2023 15:37:05 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:31 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-2-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 01/15] perf jevents metric: Correct Function equality From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153718_373012_58146FD3 X-CRM114-Status: GOOD ( 11.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org rhs may not be defined, say for source_count, so add a guard. Reviewed-by: Kajol Jain --- tools/perf/pmu-events/metric.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py index 4797ed4fd817..2f2fd220e843 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -261,8 +261,10 @@ class Function(Expression): def Equals(self, other: Expression) -> bool: if isinstance(other, Function): - return self.fn == other.fn and self.lhs.Equals( - other.lhs) and self.rhs.Equals(other.rhs) + result = self.fn == other.fn and self.lhs.Equals(other.lhs) + if self.rhs: + result = result and self.rhs.Equals(other.rhs) + return result return False From patchwork Thu Jan 26 23:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2E576C05027 for ; Thu, 26 Jan 2023 23:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=v6mNVLqvHddm2jj+Qfx5OKtCAA9wh21J/0iPInnOo1Y=; b=jJmxBztNG9o+C/7uqdW12gUJWW 21kBLAr1Q9YNo9+F8mQrVobZkolZMBuWGQpuCEcXjxIyAvZZWKxEMbXLMm5tAhlhAosbY0xcMlnEm v9uQ1NR8/uVJcIC03kAXIKVuefK++MU50xHxFXHBjxs+Q6E1OiG0yj2bt8JtNBx02zhnHk7jrcr/4 p2rpZLXPSNcWlZ7mtKgULcv+VzLg5SV9ICGcOdnoOPBkoMMdBFThj3N3Alp4+8Ol5PONydfbTSvmJ 4bscJ7dYVE//rcFAiHlC+oVxf6tBGofJbxErD79vh2v7zX/s1avLh2aa0nQdvzGEA7nunvXb+aZE+ yAhxw/Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoB-00CkyH-Sp; Thu, 26 Jan 2023 23:37:32 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBny-00CktF-D0 for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:20 +0000 Received: by mail-yb1-xb49.google.com with SMTP id n194-20020a2540cb000000b008038647d9ebso3587766yba.5 for ; Thu, 26 Jan 2023 15:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zVzLGDFk0ATwExjUMDftjSNFZ72W3NZoCawlQdDdpKY=; b=g6B2e931x3l/7IDGJTFRhdD+fs2W/iVGC/9/OGD/9xMyNzGYszCJRBhKhZt8qdb0WS Mj4civh5fQtEFSx7ZF/uP0ogEmf9FMzTNTsU8yOqUqcVDSt5VwMNO54ItUxJPiA8uJTg AL1z5/zKgUzr27kAbh21VOmJTCvtddk6RlAZjaVOzky+kZxObvNrMiuJFnCpUkFR4yvq dKqqGywWp2j8skVstAWywqYG+9Pko+yV+k+DLlDTB+OMOjp8bxuAroLXZbINOHKvRfbz dAbYmSe2q28FTiGup4oyTPsrSx8RsMEOI/JK4pIcY9DLJ4ch4Zxbzv+g9fBeBmdT/Yar Kv1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=zVzLGDFk0ATwExjUMDftjSNFZ72W3NZoCawlQdDdpKY=; b=pa7mGYgCXkraaler//DgsVWvii/R/tDiXm+Z4VbES1I0uAkAdZdRNOj6lhWbkSRRWR 04Htvn1Vi3vwY0LpNrKggLG2bFR+1+8EB3pkkb0nMHgFkGxUgnVc34IygQX7bz8JWPLU wAGIjSgoQ2/xv6KRYcsi8u3nWNaQPp3/89bLQCePk5lpIEbl4qb4mjhRV5NuBef1qhwU ByBi8PNbr6LeHyft70PeVJHpv5TJoxYiajXySvk2WS5qSKrLvT2HZo4AYjY0TM9rVvuW RKd+lJFz/WEWKMDPpuLJsKiLDai/lZfrWGUAED/19pVghOkXTNGH8G5wq1Y0919KH/7B 5hbw== X-Gm-Message-State: AO0yUKUMwMyA+c9uQ3I38GhlZji0jX3K/ImFL0Ax7yRSihRQeccWiKll z1JlekvXcGd/2zNZq84BoGH/r9hDAlw4 X-Google-Smtp-Source: AK7set+Iv2jmW6JOcsgy1uCNPGEoi/rn7S52ZxdpjWt6UB9uRDAOijygh48h7MPGC6ch2gn93vDjHr3/VJ1L X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:6e84:0:b0:80b:4da5:cf19 with SMTP id j126-20020a256e84000000b0080b4da5cf19mr1962472ybc.455.1674776233289; Thu, 26 Jan 2023 15:37:13 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:32 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-3-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 02/15] perf jevents metric: Add ability to rewrite metrics in terms of others From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153718_491512_E4D431C5 X-CRM114-Status: GOOD ( 15.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add RewriteMetricsInTermsOfOthers that iterates over pairs of names and expressions trying to replace an expression, within the current expression, with its name. --- tools/perf/pmu-events/metric.py | 73 +++++++++++++++++++++++++++- tools/perf/pmu-events/metric_test.py | 10 ++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py index 2f2fd220e843..77ea6ff98538 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -4,7 +4,7 @@ import ast import decimal import json import re -from typing import Dict, List, Optional, Set, Union +from typing import Dict, List, Optional, Set, Tuple, Union class Expression: @@ -26,6 +26,9 @@ class Expression: """Returns true when two expressions are the same.""" raise NotImplementedError() + def Substitute(self, name: str, expression: 'Expression') -> 'Expression': + raise NotImplementedError() + def __str__(self) -> str: return self.ToPerfJson() @@ -186,6 +189,15 @@ class Operator(Expression): other.lhs) and self.rhs.Equals(other.rhs) return False + def Substitute(self, name: str, expression: Expression) -> Expression: + if self.Equals(expression): + return Event(name) + lhs = self.lhs.Substitute(name, expression) + rhs = None + if self.rhs: + rhs = self.rhs.Substitute(name, expression) + return Operator(self.operator, lhs, rhs) + class Select(Expression): """Represents a select ternary in the parse tree.""" @@ -225,6 +237,14 @@ class Select(Expression): other.false_val) and self.true_val.Equals(other.true_val) return False + def Substitute(self, name: str, expression: Expression) -> Expression: + if self.Equals(expression): + return Event(name) + true_val = self.true_val.Substitute(name, expression) + cond = self.cond.Substitute(name, expression) + false_val = self.false_val.Substitute(name, expression) + return Select(true_val, cond, false_val) + class Function(Expression): """A function in an expression like min, max, d_ratio.""" @@ -267,6 +287,15 @@ class Function(Expression): return result return False + def Substitute(self, name: str, expression: Expression) -> Expression: + if self.Equals(expression): + return Event(name) + lhs = self.lhs.Substitute(name, expression) + rhs = None + if self.rhs: + rhs = self.rhs.Substitute(name, expression) + return Function(self.fn, lhs, rhs) + def _FixEscapes(s: str) -> str: s = re.sub(r'([^\\]),', r'\1\\,', s) @@ -293,6 +322,9 @@ class Event(Expression): def Equals(self, other: Expression) -> bool: return isinstance(other, Event) and self.name == other.name + def Substitute(self, name: str, expression: Expression) -> Expression: + return self + class Constant(Expression): """A constant within the expression tree.""" @@ -317,6 +349,9 @@ class Constant(Expression): def Equals(self, other: Expression) -> bool: return isinstance(other, Constant) and self.value == other.value + def Substitute(self, name: str, expression: Expression) -> Expression: + return self + class Literal(Expression): """A runtime literal within the expression tree.""" @@ -336,6 +371,9 @@ class Literal(Expression): def Equals(self, other: Expression) -> bool: return isinstance(other, Literal) and self.value == other.value + def Substitute(self, name: str, expression: Expression) -> Expression: + return self + def min(lhs: Union[int, float, Expression], rhs: Union[int, float, Expression]) -> Function: @@ -461,6 +499,7 @@ class MetricGroup: class _RewriteIfExpToSelect(ast.NodeTransformer): + """Transformer to convert if-else nodes to Select expressions.""" def visit_IfExp(self, node): # pylint: disable=invalid-name @@ -498,7 +537,37 @@ def ParsePerfJson(orig: str) -> Expression: for kw in keywords: py = re.sub(rf'Event\(r"{kw}"\)', kw, py) - parsed = ast.parse(py, mode='eval') + try: + parsed = ast.parse(py, mode='eval') + except SyntaxError as e: + raise SyntaxError(f'Parsing expression:\n{orig}') from e _RewriteIfExpToSelect().visit(parsed) parsed = ast.fix_missing_locations(parsed) return _Constify(eval(compile(parsed, orig, 'eval'))) + + +def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, Expression]] + )-> Dict[str, Expression]: + """Shorten metrics by rewriting in terms of others. + + Args: + metrics (list): pairs of metric names and their expressions. + Returns: + Dict: mapping from a metric name to a shortened expression. + """ + updates: Dict[str, Expression] = dict() + for outer_name, outer_expression in metrics: + updated = outer_expression + while True: + for inner_name, inner_expression in metrics: + if inner_name.lower() == outer_name.lower(): + continue + if inner_name in updates: + inner_expression = updates[inner_name] + updated = updated.Substitute(inner_name, inner_expression) + if updated.Equals(outer_expression): + break + if outer_name in updates and updated.Equals(updates[outer_name]): + break + updates[outer_name] = updated + return updates diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py index 15315d0f716c..ced5998bd827 100644 --- a/tools/perf/pmu-events/metric_test.py +++ b/tools/perf/pmu-events/metric_test.py @@ -2,7 +2,9 @@ import unittest from metric import Constant from metric import Event +from metric import Expression from metric import ParsePerfJson +from metric import RewriteMetricsInTermsOfOthers class TestMetricExpressions(unittest.TestCase): @@ -153,5 +155,13 @@ class TestMetricExpressions(unittest.TestCase): after = '0 * SLOTS' self.assertEqual(ParsePerfJson(before).Simplify().ToPerfJson(), after) + def test_RewriteMetricsInTermsOfOthers(self): + Expression.__eq__ = lambda e1, e2: e1.Equals(e2) + before = [('m1', ParsePerfJson('a + b + c + d')), + ('m2', ParsePerfJson('a + b + c'))] + after = {'m1': ParsePerfJson('m2 + d')} + self.assertEqual(RewriteMetricsInTermsOfOthers(before), after) + Expression.__eq__ = None + if __name__ == '__main__': unittest.main() From patchwork Thu Jan 26 23:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19A0CC61D97 for ; Thu, 26 Jan 2023 23:38:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7dHBh9wrrprkvm1R6kfDI2wNEW/v4nDDycu0i7MjJ7I=; b=Fn+4LbIPGbLB3fC49FRBDs2UbJ rHdwYE3l1fYQmArv0fOemJFw4YQ5XwHGekQL6j8Hqs/2cazr6/XCGO94neLtuYAet7SeSU68ovpLz nZdgv4vCvpAajtqEHT5k3gzLTULLMqE74xxGdU9zPPFJgR6Z8uat2ddoNyGApdnlB1MNqUbd3Qd6c hTL3q0Q/OzJ73JjMf6dlwkbpvvNfrNepfD/izQdNWRi7HJ61fNiDCJsnrnP5YUqC4cc/70JeeYzw+ UX2qnX9rg3zFeT9qznBhkXispbLFTNHDOjUVS15JGh13qGBVaESs1hXYWLEGcb/3nwPalneMCxrk5 2MWCwz1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoO-00Cl2j-B9; Thu, 26 Jan 2023 23:37:46 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBo2-00Ckvc-Cf for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:23 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id t13-20020a056902018d00b0074747131938so3595519ybh.12 for ; Thu, 26 Jan 2023 15:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:from:to:cc:subject:date :message-id:reply-to; bh=sZMgv7d+qS2IPgaZDQ3hwKBijNPiryE68frwCkys2NE=; b=p07QyxNyuqbp4f6wdTyQ7nt4VdaMwxGyoUK/0k2+63P0aiCeLgEz6DjMog0g+BetuJ q4pQTACbjzryhviMQ7vTHUrQI24o/45haTUFAOLWErFNTxgCq5X5+HRsBn9eyAWoH4N4 kF3zZU3ZD5vxAiRvXWqhkXutjZAdJZbRD7+JVrpfqF/FValQvpWBkxlakz+yZRJ8lepk SGDXDTqhl0YpGkN+hMyL0Rem7V4cd7OfHr057iRaKSizy6p8XVO9HOOaU4/hv8m32p0Y aeTuUyycKmjfDfm76GbEp6ylGlX0/qmzKS6fY4eGiYHwbWPrrVLMtnbfxgsipHXOy3mk RLeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc: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=sZMgv7d+qS2IPgaZDQ3hwKBijNPiryE68frwCkys2NE=; b=gW+FtqRh2StkT5oKv2N6mZ/NA3iw6BdrLBzeCypbmyN4zXLwC45Na2ae6PISfJwcuq 2/qSaGmMr1Oaqjjj0O+IhC0FzuMsfhl6UmOHSApY90EyjugeTIO9zW+i+Db8moea/gmm SCPhqQ5F0vhFekuRHvSYWM0DlBRbtEtvRuKTKd0puQFTYg84+9dixq6p9ErtG4VTD9Eg lsXxDQTbEqoyAMD4Lj4xGj7ApUI/C0/Dnx4v3ngO2FNvmilRZQ9fAqESQc1OvZ2XwHoc 0ez+gQYrAFw4VVjvRXdaQjjNcA1ZShXn63sFScATBhLXRpwqFq0Sk6S1Kzba7tYXma5v MLew== X-Gm-Message-State: AO0yUKVdwqUmKtJF1PEPaiL3wegzdYlb8YzDgy3fWsFUjhRmb90VkXeJ QelbdlaHcBWbMRNTPQeDG56KiTuvOh6v X-Google-Smtp-Source: AK7set8J8fjITXrFkqjV8qoRxG/OptJXGdliAd6Ni2HXOVXiJKUwFJUhB7iGDfPx931wpEDI7WZbS7czEKbF X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:491:0:b0:80b:d57a:612f with SMTP id 139-20020a250491000000b0080bd57a612fmr361423ybe.448.1674776240866; Thu, 26 Jan 2023 15:37:20 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:33 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-4-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 03/15] perf jevents: Rewrite metrics in the same file with each other From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153722_471745_F516B55C X-CRM114-Status: GOOD ( 13.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rewrite metrics within the same file in terms of each other. For example, on Power8 other_stall_cpi is rewritten from: "PM_CMPLU_STALL / PM_RUN_INST_CMPL - PM_CMPLU_STALL_BRU_CRU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_FXU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_VSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_LSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NTCG_FLUSH / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NO_NTF / PM_RUN_INST_CMPL" to: "stall_cpi - bru_cru_stall_cpi - fxu_stall_cpi - vsu_stall_cpi - lsu_stall_cpi - ntcg_flush_cpi - no_ntf_stall_cpi" Which more closely matches the definition on Power9. To avoid recomputation decorate the function with a cache. --- tools/perf/pmu-events/jevents.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 0416b7442171..15a1671740cc 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -3,6 +3,7 @@ """Convert directories of JSON events to C code.""" import argparse import csv +from functools import lru_cache import json import metric import os @@ -337,18 +338,28 @@ class JsonEvent: s = self.build_c_string() return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n' - +@lru_cache(maxsize=None) def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" - try: - result = json.load(open(path), object_hook=JsonEvent) + events = json.load(open(path), object_hook=JsonEvent) except BaseException as err: print(f"Exception processing {path}") raise - for event in result: + metrics: list[Tuple[str, metric.Expression]] = [] + for event in events: event.topic = topic - return result + if event.metric_name and '-' not in event.metric_name: + metrics.append((event.metric_name, event.metric_expr)) + updates = metric.RewriteMetricsInTermsOfOthers(metrics) + if updates: + for event in events: + if event.metric_name in updates: + # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n' + # f'to\n"{updates[event.metric_name]}"') + event.metric_expr = updates[event.metric_name] + + return events def preprocess_arch_std_files(archpath: str) -> None: """Read in all architecture standard events.""" From patchwork Thu Jan 26 23:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D416C05027 for ; Thu, 26 Jan 2023 23:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2C2Dip+5CCVADq28zYDNcNR1w7ascDybVrhoWTjcVPk=; b=3SrQ5X2H43nCFt6QbPIoK93unW QAX+Vq1478l9opsfzkWL1SCGWaNteya9obITWEcObI9TUJMyGFbfIF3ZPcdIIsPS5J6FFjUPQ8Txn SQxaBci5Yz1KTnRDG1YSSv9KSzsW3JEQpasQcb2JS4cepMvM/Ct6h/SI+f87rw6x+HXRhUDO17AZy MqPLetoLRZzVnWPoPkvK2qGpbBZmhzm/7OGZ2FUouUEo3gIgDAFmEN0qMNuIE+qFGn22mgL0Ks/Ep WUH+SZBkYqkWaeofe7Gg96MCl0KXIgd5wWqFW3Libv/nnPb9Bm/t0+ROIs+9vzSYxjuQqqg3m5x4g L0/1UUFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBog-00Cl8f-K3; Thu, 26 Jan 2023 23:38:02 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBo9-00CkxB-0p for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:33 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5065604854eso37497037b3.16 for ; Thu, 26 Jan 2023 15:37:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cR8g2rjfxuT2CGwb5MVZPHAjpY3ojCm5F266K7G8T4Y=; b=VrIiz6M2bS0P821l70QzmKF/K5ssQZQZHDv8WTmHzUc7ldtl54etZm99pItD+lxh82 0+rNw3oTYAUA1bXmrlgPIxSfY1kg/PNvTom0LQDn8yVXVXTz4ZagGS8GLMdpiyBL/jch 04jLWIgWpJ7XDC7KKhmSNK4CGwfVCtIZ4sVEDBEukUgs1c9zeC2q0Qm8GGHAzawo0XPg +7GMh20zwFE7ZO+CnlKrXmFmhb6WgAJOm1GaPeKtu+Ku0K9HVo1npWijAddca0mntn8L lkPnKlKsB+6eHfO3fVUdcCIQIqE/46EtsvPUh4O06W76mvltEFdo03gYtdEKt3vT/3A3 uBCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=cR8g2rjfxuT2CGwb5MVZPHAjpY3ojCm5F266K7G8T4Y=; b=2iLWgRRjhLLM3wInQQ7fljXleX5V/YpBbX1RTwW7qJCjozBq0qYfm/fCkChp9iyyfX ogX2eSKKEKiO9vXw8SwqAYOkp/0JfSGsFoBEItANrkhX8GUttr4sQvCNoe2NkKDIMze8 WUFTgwlOBQLuF5uKPK6Lo1N6orxWr2e3q63jGlsVCMYIbrOlMqU1NcNFO9qe80DGOA4a p6Sj8MYwJoMcCxSt1Tqszh0SawPgoxLMwW1wwkIyF8jkHO5ortUd68LiF2rvmSBO+Zrd IPIo5DaeXf+gFsjq8q2FZUXauASYbzE7mqYDfDl8X7SDAyIEJlYI+jTuVTUGbbRybMCy cFNw== X-Gm-Message-State: AO0yUKWhyUEV8K3lKS/wmPdQlpR3l5sD2nrVsAhOf/UK08CljFLgYKzk yePhXYe0rlpKqWP6LuSPMuPvbfs1upHl X-Google-Smtp-Source: AK7set8QVcQNzPHHxLzc3vSenH5aLkYTqp0N0T/0I0cA7DeSjPP/PCAtGdBs+o2XeKEhvbFxG8YNPk9NGnui X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a0d:d4c5:0:b0:506:6859:bc1e with SMTP id w188-20020a0dd4c5000000b005066859bc1emr1132175ywd.183.1674776247451; Thu, 26 Jan 2023 15:37:27 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:34 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-5-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 04/15] perf pmu-events: Add separate metric from pmu_event From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153729_323618_DBF27246 X-CRM114-Status: GOOD ( 23.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Create a new pmu_metric for the metric related variables from pmu_event but that is initially just a clone of pmu_event. Add iterators for pmu_metric and use in places that metrics are desired rather than events. Make the event iterator skip metric only events, and the metric iterator skip event only events. Reviewed-by: John Garry --- tools/perf/arch/powerpc/util/header.c | 4 +- tools/perf/pmu-events/empty-pmu-events.c | 49 ++++++- tools/perf/pmu-events/jevents.py | 62 ++++++++- tools/perf/pmu-events/pmu-events.h | 26 ++++ tools/perf/tests/pmu-events.c | 35 +++-- tools/perf/util/metricgroup.c | 161 +++++++++++------------ tools/perf/util/metricgroup.h | 2 +- 7 files changed, 228 insertions(+), 111 deletions(-) diff --git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c index e8fe36b10d20..78eef77d8a8d 100644 --- a/tools/perf/arch/powerpc/util/header.c +++ b/tools/perf/arch/powerpc/util/header.c @@ -40,11 +40,11 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused) return bufp; } -int arch_get_runtimeparam(const struct pmu_event *pe) +int arch_get_runtimeparam(const struct pmu_metric *pm) { int count; char path[PATH_MAX] = "/devices/hv_24x7/interface/"; - atoi(pe->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip"); + atoi(pm->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip"); return sysfs__read_int(path, &count) < 0 ? 1 : count; } diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 480e8f0d30c8..4e39d1a8d6d6 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -181,6 +181,11 @@ struct pmu_events_table { const struct pmu_event *entries; }; +/* Struct used to make the PMU metric table implementation opaque to callers. */ +struct pmu_metrics_table { + const struct pmu_metric *entries; +}; + /* * Map a CPU to its table of PMU events. The CPU is identified by the * cpuid field, which is an arch-specific identifier for the CPU. @@ -254,11 +259,29 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data) { - for (const struct pmu_event *pe = &table->entries[0]; - pe->name || pe->metric_group || pe->metric_name; - pe++) { - int ret = fn(pe, table, data); + for (const struct pmu_event *pe = &table->entries[0]; pe->name || pe->metric_expr; pe++) { + int ret; + if (!pe->name) + continue; + ret = fn(pe, table, data); + if (ret) + return ret; + } + return 0; +} + +int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, pmu_metric_iter_fn fn, + void *data) +{ + struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable; + + for (const struct pmu_metric *pm = &table->entries[0]; pm->name || pm->metric_expr; pm++) { + int ret; + + if (!pm->metric_expr) + continue; + ret = fn(pm, etable, data); if (ret) return ret; } @@ -305,11 +328,22 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch } int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { + int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + + if (ret) + return ret; + } + return 0; +} + +int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); if (ret) return ret; @@ -340,3 +374,8 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) } return 0; } + +int pmu_for_each_sys_metric(pmu_metric_iter_fn fn __maybe_unused, void *data __maybe_unused) +{ + return 0; +} diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 15a1671740cc..858787a12302 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -564,7 +564,19 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { \t}, }; -static void decompress(int offset, struct pmu_event *pe) +static void decompress_event(int offset, struct pmu_event *pe) +{ +\tconst char *p = &big_c_string[offset]; +""") + for attr in _json_event_attributes: + _args.output_file.write(f""" +\tpe->{attr} = (*p == '\\0' ? NULL : p); +""") + if attr == _json_event_attributes[-1]: + continue + _args.output_file.write('\twhile (*p++);') + _args.output_file.write("""} +static void decompress_metric(int offset, struct pmu_metric *pe) { \tconst char *p = &big_c_string[offset]; """) @@ -585,7 +597,9 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, struct pmu_event pe; int ret; - decompress(table->entries[i].offset, &pe); + decompress_event(table->entries[i].offset, &pe); + if (!pe.name) + continue; ret = fn(&pe, table, data); if (ret) return ret; @@ -593,6 +607,24 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, return 0; } +int pmu_events_table_for_each_metric(const struct pmu_events_table *table, + pmu_metric_iter_fn fn, + void *data) +{ + for (size_t i = 0; i < table->length; i++) { + struct pmu_metric pm; + int ret; + + decompress_metric(table->entries[i].offset, &pm); + if (!pm.metric_expr) + continue; + ret = fn(&pm, table, data); + if (ret) + return ret; + } + return 0; +} + const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) { const struct pmu_events_table *table = NULL; @@ -644,6 +676,19 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) return 0; } +int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + + if (ret) + return ret; + } + return 0; +} + const struct pmu_events_table *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; @@ -667,6 +712,19 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) } return 0; } + +int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + + if (ret) + return ret; + } + return 0; +} """) diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index fe343c4d8016..45c0f508af23 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -30,20 +30,46 @@ struct pmu_event { const char *metric_constraint; }; +struct pmu_metric { + const char *name; + const char *compat; + const char *event; + const char *desc; + const char *topic; + const char *long_desc; + const char *pmu; + const char *unit; + const char *perpkg; + const char *aggr_mode; + const char *metric_expr; + const char *metric_name; + const char *metric_group; + const char *deprecated; + const char *metric_constraint; +}; + struct pmu_events_table; typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, const struct pmu_events_table *table, void *data); +typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm, + const struct pmu_events_table *table, + void *data); + int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data); +int pmu_events_table_for_each_metric(const struct pmu_events_table *table, pmu_metric_iter_fn fn, + void *data); const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); +int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); const struct pmu_events_table *find_sys_events_table(const char *name); int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); +int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data); #endif diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index a9f2330f6257..e5fb3d5a06c3 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -840,7 +840,7 @@ struct metric { struct metric_ref metric_ref; }; -static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_events_table *table, +static int test__parsing_callback(const struct pmu_metric *pm, const struct pmu_events_table *table, void *data) { int *failures = data; @@ -854,10 +854,10 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e }; int err = 0; - if (!pe->metric_expr) + if (!pm->metric_expr) return 0; - pr_debug("Found metric '%s'\n", pe->metric_name); + pr_debug("Found metric '%s'\n", pm->metric_name); (*failures)++; /* @@ -877,14 +877,14 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e perf_evlist__set_maps(&evlist->core, cpus, NULL); runtime_stat__init(&st); - err = metricgroup__parse_groups_test(evlist, table, pe->metric_name, + err = metricgroup__parse_groups_test(evlist, table, pm->metric_name, false, false, &metric_events); if (err) { - if (!strcmp(pe->metric_name, "M1") || !strcmp(pe->metric_name, "M2") || - !strcmp(pe->metric_name, "M3")) { + if (!strcmp(pm->metric_name, "M1") || !strcmp(pm->metric_name, "M2") || + !strcmp(pm->metric_name, "M3")) { (*failures)--; - pr_debug("Expected broken metric %s skipping\n", pe->metric_name); + pr_debug("Expected broken metric %s skipping\n", pm->metric_name); err = 0; } goto out_err; @@ -912,7 +912,7 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e struct metric_expr *mexp; list_for_each_entry (mexp, &me->head, nd) { - if (strcmp(mexp->metric_name, pe->metric_name)) + if (strcmp(mexp->metric_name, pm->metric_name)) continue; pr_debug("Result %f\n", test_generic_metric(mexp, 0, &st)); err = 0; @@ -921,11 +921,11 @@ static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_e } } } - pr_debug("Didn't find parsed metric %s", pe->metric_name); + pr_debug("Didn't find parsed metric %s", pm->metric_name); err = 1; out_err: if (err) - pr_debug("Broken metric %s\n", pe->metric_name); + pr_debug("Broken metric %s\n", pm->metric_name); /* ... cleanup. */ metricgroup__rblist_exit(&metric_events); @@ -941,8 +941,8 @@ static int test__parsing(struct test_suite *test __maybe_unused, { int failures = 0; - pmu_for_each_core_event(test__parsing_callback, &failures); - pmu_for_each_sys_event(test__parsing_callback, &failures); + pmu_for_each_core_metric(test__parsing_callback, &failures); + pmu_for_each_sys_metric(test__parsing_callback, &failures); return failures == 0 ? TEST_OK : TEST_FAIL; } @@ -1021,14 +1021,11 @@ static int metric_parse_fake(const char *metric_name, const char *str) return ret; } -static int test__parsing_fake_callback(const struct pmu_event *pe, +static int test__parsing_fake_callback(const struct pmu_metric *pm, const struct pmu_events_table *table __maybe_unused, void *data __maybe_unused) { - if (!pe->metric_expr) - return 0; - - return metric_parse_fake(pe->metric_name, pe->metric_expr); + return metric_parse_fake(pm->metric_name, pm->metric_expr); } /* @@ -1047,11 +1044,11 @@ static int test__parsing_fake(struct test_suite *test __maybe_unused, return err; } - err = pmu_for_each_core_event(test__parsing_fake_callback, NULL); + err = pmu_for_each_core_metric(test__parsing_fake_callback, NULL); if (err) return err; - return pmu_for_each_sys_event(test__parsing_fake_callback, NULL); + return pmu_for_each_sys_metric(test__parsing_fake_callback, NULL); } static struct test_case pmu_events_tests[] = { diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index b9c273ed080a..47fd02af66f1 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -167,14 +167,14 @@ static void metricgroup___watchdog_constraint_hint(const char *name, bool foot) " echo 1 > /proc/sys/kernel/nmi_watchdog\n"); } -static bool metricgroup__has_constraint(const struct pmu_event *pe) +static bool metricgroup__has_constraint(const struct pmu_metric *pm) { - if (!pe->metric_constraint) + if (!pm->metric_constraint) return false; - if (!strcmp(pe->metric_constraint, "NO_NMI_WATCHDOG") && + if (!strcmp(pm->metric_constraint, "NO_NMI_WATCHDOG") && sysctl__nmi_watchdog_enabled()) { - metricgroup___watchdog_constraint_hint(pe->metric_name, false); + metricgroup___watchdog_constraint_hint(pm->metric_name, false); return true; } @@ -193,7 +193,7 @@ static void metric__free(struct metric *m) free(m); } -static struct metric *metric__new(const struct pmu_event *pe, +static struct metric *metric__new(const struct pmu_metric *pm, const char *modifier, bool metric_no_group, int runtime, @@ -210,15 +210,15 @@ static struct metric *metric__new(const struct pmu_event *pe, if (!m->pctx) goto out_err; - m->metric_name = pe->metric_name; + m->metric_name = pm->metric_name; m->modifier = NULL; if (modifier) { m->modifier = strdup(modifier); if (!m->modifier) goto out_err; } - m->metric_expr = pe->metric_expr; - m->metric_unit = pe->unit; + m->metric_expr = pm->metric_expr; + m->metric_unit = pm->unit; m->pctx->sctx.user_requested_cpu_list = NULL; if (user_requested_cpu_list) { m->pctx->sctx.user_requested_cpu_list = strdup(user_requested_cpu_list); @@ -227,7 +227,7 @@ static struct metric *metric__new(const struct pmu_event *pe, } m->pctx->sctx.runtime = runtime; m->pctx->sctx.system_wide = system_wide; - m->has_constraint = metric_no_group || metricgroup__has_constraint(pe); + m->has_constraint = metric_no_group || metricgroup__has_constraint(pm); m->metric_refs = NULL; m->evlist = NULL; @@ -348,10 +348,10 @@ static bool match_metric(const char *n, const char *list) return false; } -static bool match_pe_metric(const struct pmu_event *pe, const char *metric) +static bool match_pm_metric(const struct pmu_metric *pm, const char *metric) { - return match_metric(pe->metric_group, metric) || - match_metric(pe->metric_name, metric); + return match_metric(pm->metric_group, metric) || + match_metric(pm->metric_name, metric); } /** struct mep - RB-tree node for building printing information. */ @@ -420,13 +420,13 @@ static struct mep *mep_lookup(struct rblist *groups, const char *metric_group, return NULL; } -static int metricgroup__add_to_mep_groups(const struct pmu_event *pe, +static int metricgroup__add_to_mep_groups(const struct pmu_metric *pm, struct rblist *groups) { const char *g; char *omg, *mg; - mg = strdup(pe->metric_group ?: "No_group"); + mg = strdup(pm->metric_group ?: "No_group"); if (!mg) return -ENOMEM; omg = mg; @@ -435,15 +435,15 @@ static int metricgroup__add_to_mep_groups(const struct pmu_event *pe, g = skip_spaces(g); if (strlen(g)) - me = mep_lookup(groups, g, pe->metric_name); + me = mep_lookup(groups, g, pm->metric_name); else - me = mep_lookup(groups, "No_group", pe->metric_name); + me = mep_lookup(groups, "No_group", pm->metric_name); if (me) { - me->metric_desc = pe->desc; - me->metric_long_desc = pe->long_desc; - me->metric_expr = pe->metric_expr; - me->metric_unit = pe->unit; + me->metric_desc = pm->desc; + me->metric_long_desc = pm->long_desc; + me->metric_expr = pm->metric_expr; + me->metric_unit = pm->unit; } } free(omg); @@ -452,40 +452,37 @@ static int metricgroup__add_to_mep_groups(const struct pmu_event *pe, } struct metricgroup_iter_data { - pmu_event_iter_fn fn; + pmu_metric_iter_fn fn; void *data; }; -static int metricgroup__sys_event_iter(const struct pmu_event *pe, +static int metricgroup__sys_event_iter(const struct pmu_metric *pm, const struct pmu_events_table *table, void *data) { struct metricgroup_iter_data *d = data; struct perf_pmu *pmu = NULL; - if (!pe->metric_expr || !pe->compat) + if (!pm->metric_expr || !pm->compat) return 0; while ((pmu = perf_pmu__scan(pmu))) { - if (!pmu->id || strcmp(pmu->id, pe->compat)) + if (!pmu->id || strcmp(pmu->id, pm->compat)) continue; - return d->fn(pe, table, d->data); + return d->fn(pm, table, d->data); } return 0; } -static int metricgroup__add_to_mep_groups_callback(const struct pmu_event *pe, +static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric *pm, const struct pmu_events_table *table __maybe_unused, void *vdata) { struct rblist *groups = vdata; - if (!pe->metric_name) - return 0; - - return metricgroup__add_to_mep_groups(pe, groups); + return metricgroup__add_to_mep_groups(pm, groups); } void metricgroup__print(const struct print_callbacks *print_cb, void *print_state) @@ -500,16 +497,16 @@ void metricgroup__print(const struct print_callbacks *print_cb, void *print_stat groups.node_delete = mep_delete; table = pmu_events_table__find(); if (table) { - pmu_events_table_for_each_event(table, - metricgroup__add_to_mep_groups_callback, - &groups); + pmu_events_table_for_each_metric(table, + metricgroup__add_to_mep_groups_callback, + &groups); } { struct metricgroup_iter_data data = { .fn = metricgroup__add_to_mep_groups_callback, .data = &groups, }; - pmu_for_each_sys_event(metricgroup__sys_event_iter, &data); + pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data); } for (node = rb_first_cached(&groups.entries); node; node = next) { @@ -743,7 +740,7 @@ static int metricgroup__build_event_string(struct strbuf *events, #undef RETURN_IF_NON_ZERO } -int __weak arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused) +int __weak arch_get_runtimeparam(const struct pmu_metric *pm __maybe_unused) { return 1; } @@ -773,10 +770,10 @@ struct metricgroup_add_iter_data { static bool metricgroup__find_metric(const char *metric, const struct pmu_events_table *table, - struct pmu_event *pe); + struct pmu_metric *pm); static int add_metric(struct list_head *metric_list, - const struct pmu_event *pe, + const struct pmu_metric *pm, const char *modifier, bool metric_no_group, const char *user_requested_cpu_list, @@ -816,10 +813,10 @@ static int resolve_metric(struct list_head *metric_list, size_t bkt; struct to_resolve { /* The metric to resolve. */ - struct pmu_event pe; + struct pmu_metric pm; /* * The key in the IDs map, this may differ from in case, - * etc. from pe->metric_name. + * etc. from pm->metric_name. */ const char *key; } *pending = NULL; @@ -830,15 +827,15 @@ static int resolve_metric(struct list_head *metric_list, * the pending array. */ hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) { - struct pmu_event pe; + struct pmu_metric pm; - if (metricgroup__find_metric(cur->pkey, table, &pe)) { + if (metricgroup__find_metric(cur->pkey, table, &pm)) { pending = realloc(pending, (pending_cnt + 1) * sizeof(struct to_resolve)); if (!pending) return -ENOMEM; - memcpy(&pending[pending_cnt].pe, &pe, sizeof(pe)); + memcpy(&pending[pending_cnt].pm, &pm, sizeof(pm)); pending[pending_cnt].key = cur->pkey; pending_cnt++; } @@ -853,7 +850,7 @@ static int resolve_metric(struct list_head *metric_list, * context. */ for (i = 0; i < pending_cnt; i++) { - ret = add_metric(metric_list, &pending[i].pe, modifier, metric_no_group, + ret = add_metric(metric_list, &pending[i].pm, modifier, metric_no_group, user_requested_cpu_list, system_wide, root_metric, visited, table); if (ret) @@ -867,7 +864,7 @@ static int resolve_metric(struct list_head *metric_list, /** * __add_metric - Add a metric to metric_list. * @metric_list: The list the metric is added to. - * @pe: The pmu_event containing the metric to be added. + * @pm: The pmu_metric containing the metric to be added. * @modifier: if non-null event modifiers like "u". * @metric_no_group: Should events written to events be grouped "{}" or * global. Grouping is the default but due to multiplexing the @@ -884,7 +881,7 @@ static int resolve_metric(struct list_head *metric_list, * architecture perf is running upon. */ static int __add_metric(struct list_head *metric_list, - const struct pmu_event *pe, + const struct pmu_metric *pm, const char *modifier, bool metric_no_group, int runtime, @@ -898,13 +895,13 @@ static int __add_metric(struct list_head *metric_list, int ret; bool is_root = !root_metric; struct visited_metric visited_node = { - .name = pe->metric_name, + .name = pm->metric_name, .parent = visited, }; for (vm = visited; vm; vm = vm->parent) { - if (!strcmp(pe->metric_name, vm->name)) { - pr_err("failed: recursion detected for %s\n", pe->metric_name); + if (!strcmp(pm->metric_name, vm->name)) { + pr_err("failed: recursion detected for %s\n", pm->metric_name); return -1; } } @@ -914,7 +911,7 @@ static int __add_metric(struct list_head *metric_list, * This metric is the root of a tree and may reference other * metrics that are added recursively. */ - root_metric = metric__new(pe, modifier, metric_no_group, runtime, + root_metric = metric__new(pm, modifier, metric_no_group, runtime, user_requested_cpu_list, system_wide); if (!root_metric) return -ENOMEM; @@ -929,7 +926,7 @@ static int __add_metric(struct list_head *metric_list, */ if (root_metric->metric_refs) { for (; root_metric->metric_refs[cnt].metric_name; cnt++) { - if (!strcmp(pe->metric_name, + if (!strcmp(pm->metric_name, root_metric->metric_refs[cnt].metric_name)) return 0; } @@ -947,8 +944,8 @@ static int __add_metric(struct list_head *metric_list, * need to change them, so there's no need to create * our own copy. */ - root_metric->metric_refs[cnt].metric_name = pe->metric_name; - root_metric->metric_refs[cnt].metric_expr = pe->metric_expr; + root_metric->metric_refs[cnt].metric_name = pm->metric_name; + root_metric->metric_refs[cnt].metric_expr = pm->metric_expr; /* Null terminate array. */ root_metric->metric_refs[cnt+1].metric_name = NULL; @@ -959,7 +956,7 @@ static int __add_metric(struct list_head *metric_list, * For both the parent and referenced metrics, we parse * all the metric's IDs and add it to the root context. */ - if (expr__find_ids(pe->metric_expr, NULL, root_metric->pctx) < 0) { + if (expr__find_ids(pm->metric_expr, NULL, root_metric->pctx) < 0) { /* Broken metric. */ ret = -EINVAL; } else { @@ -981,37 +978,37 @@ static int __add_metric(struct list_head *metric_list, struct metricgroup__find_metric_data { const char *metric; - struct pmu_event *pe; + struct pmu_metric *pm; }; -static int metricgroup__find_metric_callback(const struct pmu_event *pe, +static int metricgroup__find_metric_callback(const struct pmu_metric *pm, const struct pmu_events_table *table __maybe_unused, void *vdata) { struct metricgroup__find_metric_data *data = vdata; - if (!match_metric(pe->metric_name, data->metric)) + if (!match_metric(pm->metric_name, data->metric)) return 0; - memcpy(data->pe, pe, sizeof(*pe)); + memcpy(data->pm, pm, sizeof(*pm)); return 1; } static bool metricgroup__find_metric(const char *metric, const struct pmu_events_table *table, - struct pmu_event *pe) + struct pmu_metric *pm) { struct metricgroup__find_metric_data data = { .metric = metric, - .pe = pe, + .pm = pm, }; - return pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data) + return pmu_events_table_for_each_metric(table, metricgroup__find_metric_callback, &data) ? true : false; } static int add_metric(struct list_head *metric_list, - const struct pmu_event *pe, + const struct pmu_metric *pm, const char *modifier, bool metric_no_group, const char *user_requested_cpu_list, @@ -1022,16 +1019,16 @@ static int add_metric(struct list_head *metric_list, { int ret = 0; - pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name); + pr_debug("metric expr %s for %s\n", pm->metric_expr, pm->metric_name); - if (!strstr(pe->metric_expr, "?")) { - ret = __add_metric(metric_list, pe, modifier, metric_no_group, 0, + if (!strstr(pm->metric_expr, "?")) { + ret = __add_metric(metric_list, pm, modifier, metric_no_group, 0, user_requested_cpu_list, system_wide, root_metric, visited, table); } else { int j, count; - count = arch_get_runtimeparam(pe); + count = arch_get_runtimeparam(pm); /* This loop is added to create multiple * events depend on count value and add @@ -1039,7 +1036,7 @@ static int add_metric(struct list_head *metric_list, */ for (j = 0; j < count && !ret; j++) - ret = __add_metric(metric_list, pe, modifier, metric_no_group, j, + ret = __add_metric(metric_list, pm, modifier, metric_no_group, j, user_requested_cpu_list, system_wide, root_metric, visited, table); } @@ -1047,17 +1044,17 @@ static int add_metric(struct list_head *metric_list, return ret; } -static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe, +static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm, const struct pmu_events_table *table __maybe_unused, void *data) { struct metricgroup_add_iter_data *d = data; int ret; - if (!match_pe_metric(pe, d->metric_name)) + if (!match_pm_metric(pm, d->metric_name)) return 0; - ret = add_metric(d->metric_list, pe, d->modifier, d->metric_no_group, + ret = add_metric(d->metric_list, pm, d->modifier, d->metric_no_group, d->user_requested_cpu_list, d->system_wide, d->root_metric, d->visited, d->table); if (ret) @@ -1107,19 +1104,19 @@ struct metricgroup__add_metric_data { bool has_match; }; -static int metricgroup__add_metric_callback(const struct pmu_event *pe, +static int metricgroup__add_metric_callback(const struct pmu_metric *pm, const struct pmu_events_table *table, void *vdata) { struct metricgroup__add_metric_data *data = vdata; int ret = 0; - if (pe->metric_expr && - (match_metric(pe->metric_group, data->metric_name) || - match_metric(pe->metric_name, data->metric_name))) { + if (pm->metric_expr && + (match_metric(pm->metric_group, data->metric_name) || + match_metric(pm->metric_name, data->metric_name))) { data->has_match = true; - ret = add_metric(data->list, pe, data->modifier, data->metric_no_group, + ret = add_metric(data->list, pm, data->modifier, data->metric_no_group, data->user_requested_cpu_list, data->system_wide, /*root_metric=*/NULL, /*visited_metrics=*/NULL, table); } @@ -1166,8 +1163,8 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier * Iterate over all metrics seeing if metric matches either the * name or group. When it does add the metric to the list. */ - ret = pmu_events_table_for_each_event(table, metricgroup__add_metric_callback, - &data); + ret = pmu_events_table_for_each_metric(table, metricgroup__add_metric_callback, + &data); if (ret) goto out; @@ -1189,7 +1186,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier }, }; - pmu_for_each_sys_event(metricgroup__sys_event_iter, &data); + pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data); } /* End of pmu events. */ if (!has_match) @@ -1603,16 +1600,16 @@ int metricgroup__parse_groups_test(struct evlist *evlist, &perf_pmu__fake, metric_events, table); } -static int metricgroup__has_metric_callback(const struct pmu_event *pe, +static int metricgroup__has_metric_callback(const struct pmu_metric *pm, const struct pmu_events_table *table __maybe_unused, void *vdata) { const char *metric = vdata; - if (!pe->metric_expr) + if (!pm->metric_expr) return 0; - if (match_metric(pe->metric_name, metric)) + if (match_metric(pm->metric_name, metric)) return 1; return 0; @@ -1625,8 +1622,8 @@ bool metricgroup__has_metric(const char *metric) if (!table) return false; - return pmu_events_table_for_each_event(table, metricgroup__has_metric_callback, - (void *)metric) ? true : false; + return pmu_events_table_for_each_metric(table, metricgroup__has_metric_callback, + (void *)metric) ? true : false; } int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 0013cf582173..b1f186d0f514 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -81,7 +81,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist, void metricgroup__print(const struct print_callbacks *print_cb, void *print_state); bool metricgroup__has_metric(const char *metric); -int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused); +int arch_get_runtimeparam(const struct pmu_metric *pm); void metricgroup__rblist_exit(struct rblist *metric_events); int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp, From patchwork Thu Jan 26 23:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F3026C05027 for ; Thu, 26 Jan 2023 23:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GdRDedA4OgGa9BAAjL050gh4q/MvbPIDp+ebO9AUNnw=; b=34ulzRTiVi0RowHy8J5t+eq1rp OyK+8mVfC1Si71rYhMo1VGLs229IDk6ktZDoLj1Of/Mi8IErWlW5v55a1Cw/Io+nzWNLZNzu5zFPQ kjJuWtQwB+lq3Z3dy38wiGBp4V7ll7frQAR1qCsVpy2NypJ3+yfLOIUFshvLAESaGaN27qDsOxh2q ekq3HN5Ukoo/TlCr6h3tbwebeoEfk4FDJz4Gn8kAhS6o+Qz7Gha9QnU3CYAVCxhCk+roSrqfOgHxA 1n1bj/wgvy9Qm57oXZ992NR2Y+uK/a426KoPJEXWjosPnUGoFKW25/4MSTuRBE489BKSjd/izcMt8 vXtzEuqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBp4-00ClK5-CR; Thu, 26 Jan 2023 23:38:26 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoG-00Ckzo-LM for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:39 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-509ab88f98fso28353647b3.10 for ; Thu, 26 Jan 2023 15:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VKGQ3UMcGBfYsEagUEP2tt2hFRwSrRyVp71e2QE2hiM=; b=aV7vKVkhORJ2QG8ykWx6y2ItWk9jTsmmbc4n9E21UNeXKoEDgAIOeZzZ/LdZO1RQN3 FrU2ZAREeD3okbeK80SPEWl6FOC0UFYNlgqNBP9OxKiOdY9vHI+0knTbXwfgHVDzB7tC WU/38NdEoKBs6fetvNwIcoIOhBK64V1h5Ge2iTLfLiuE0kXkH3/X4jLoJNYcwrTHM10C x50TP+xn+lh7A/DbX6ln4q/qIbsoTFxrv7TWodicY2vbc+ZYcM+d7okP/m7gCt1G+dlH nQKhYLdlydtCydVyf2r8lHmmaOEWu/nfHje+JHRu3RcAXwI5WF5g9qbO4/FhOEa5UOTa W2rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=VKGQ3UMcGBfYsEagUEP2tt2hFRwSrRyVp71e2QE2hiM=; b=Lb47qkLvoEebhhojDCr1rxqXrzltddk6cGZI2dpzJd3CueV/osdasGcRBainaytYeh vY0h+edzNrODXVvCfiernbpPp8+Dchi7Kvwhfd2tTaMjxi+gaXydFRs0a7vwUYkR4vgI HP/THN4mcvWeMtBJvu3MeeRPSRLcMZMN0AzK0xt70yMwSpma+CSdjk5msFvJ7LlepJwV sSPQnkO/pdmj8uD17VuvsfEgDHwtfvL64rTVM7GcJd+HLQOjYnLGi5ng1mJESoHgxafl P/Zr8U0jGNDq5wOxVHYmpuvTaht7lmYEzffV9+3OrOs1SRkJL+kX+J/t4PPnMvNKl1LR 56UA== X-Gm-Message-State: AO0yUKXa7C95Jau2V9flPeV2EUeCxSURTWMRqFk7HOJBThkqGK9pjS7D ygtD5ers1qm4doBPkiyBcY6aukOs14dX X-Google-Smtp-Source: AK7set8gWwYykkaFWU14EGjYcNcEBDVQZrbnovUFySkGKnETHkfL8FsYFRudVpYUi1imLlkceh4e3ToiALuL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a05:690c:607:b0:506:c9b7:ae6f with SMTP id bq7-20020a05690c060700b00506c9b7ae6fmr928091ywb.310.1674776255242; Thu, 26 Jan 2023 15:37:35 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:35 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-6-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 05/15] perf pmu-events: Separate the metrics from events for no jevents From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153736_796545_B293E846 X-CRM114-Status: GOOD ( 24.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Separate the event and metric table when building without jevents. Add find_core_metrics_table and perf_pmu__find_metrics_table while renaming existing utilities to be event specific, so that users can find the right table for their need. Reviewed-by: John Garry --- tools/perf/pmu-events/empty-pmu-events.c | 88 ++++++++++++++++++------ tools/perf/pmu-events/jevents.py | 7 +- tools/perf/pmu-events/pmu-events.h | 4 +- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/util/pmu.c | 4 +- 6 files changed, 79 insertions(+), 28 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 4e39d1a8d6d6..10bd4943ebf8 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -11,7 +11,7 @@ #include #include -static const struct pmu_event pme_test_soc_cpu[] = { +static const struct pmu_event pmu_events__test_soc_cpu[] = { { .name = "l3_cache_rd", .event = "event=0x40", @@ -105,6 +105,14 @@ static const struct pmu_event pme_test_soc_cpu[] = { .desc = "L2 BTB Correction", .topic = "branch", }, + { + .name = 0, + .event = 0, + .desc = 0, + }, +}; + +static const struct pmu_metric pmu_metrics__test_soc_cpu[] = { { .metric_expr = "1 / IPC", .metric_name = "CPI", @@ -170,9 +178,8 @@ static const struct pmu_event pme_test_soc_cpu[] = { .metric_name = "L1D_Cache_Fill_BW", }, { - .name = 0, - .event = 0, - .desc = 0, + .metric_expr = 0, + .metric_name = 0, }, }; @@ -197,7 +204,8 @@ struct pmu_metrics_table { struct pmu_events_map { const char *arch; const char *cpuid; - const struct pmu_events_table table; + const struct pmu_events_table event_table; + const struct pmu_metrics_table metric_table; }; /* @@ -208,12 +216,14 @@ static const struct pmu_events_map pmu_events_map[] = { { .arch = "testarch", .cpuid = "testcpu", - .table = { pme_test_soc_cpu }, + .event_table = { pmu_events__test_soc_cpu }, + .metric_table = { pmu_metrics__test_soc_cpu }, }, { .arch = 0, .cpuid = 0, - .table = { 0 }, + .event_table = { 0 }, + .metric_table = { 0 }, }, }; @@ -259,12 +269,9 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data) { - for (const struct pmu_event *pe = &table->entries[0]; pe->name || pe->metric_expr; pe++) { - int ret; + for (const struct pmu_event *pe = &table->entries[0]; pe->name; pe++) { + int ret = fn(pe, table, data); - if (!pe->name) - continue; - ret = fn(pe, table, data); if (ret) return ret; } @@ -276,19 +283,44 @@ int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, pmu_ { struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable; - for (const struct pmu_metric *pm = &table->entries[0]; pm->name || pm->metric_expr; pm++) { - int ret; + for (const struct pmu_metric *pm = &table->entries[0]; pm->metric_expr; pm++) { + int ret = fn(pm, etable, data); - if (!pm->metric_expr) - continue; - ret = fn(pm, etable, data); if (ret) return ret; } return 0; } -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) +{ + const struct pmu_events_table *table = NULL; + char *cpuid = perf_pmu__getcpuid(pmu); + int i; + + /* on some platforms which uses cpus map, cpuid can be NULL for + * PMUs other than CORE PMUs. + */ + if (!cpuid) + return NULL; + + i = 0; + for (;;) { + const struct pmu_events_map *map = &pmu_events_map[i++]; + + if (!map->cpuid) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = &map->event_table; + break; + } + } + free(cpuid); + return table; +} + +const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) { const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); @@ -308,7 +340,7 @@ const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = &map->table; + table = (const struct pmu_events_table *)&map->metric_table; break; } } @@ -322,7 +354,18 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return &tables->table; + return &tables->event_table; + } + return NULL; +} + +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return (const struct pmu_events_table *)&tables->metric_table; } return NULL; } @@ -330,7 +373,7 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->event_table, fn, data); if (ret) return ret; @@ -343,7 +386,8 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + int ret = pmu_events_table_for_each_metric( + (const struct pmu_events_table *)&tables->metric_table, fn, data); if (ret) return ret; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 858787a12302..8df14ab14fcf 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -625,7 +625,7 @@ int pmu_events_table_for_each_metric(const struct pmu_events_table *table, return 0; } -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) { const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); @@ -663,6 +663,11 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch return NULL; } +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +{ + return (struct pmu_events_table *)find_core_events_table(arch, cpuid); +} + int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 45c0f508af23..e2cd3e61acef 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -63,8 +63,10 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_ev int pmu_events_table_for_each_metric(const struct pmu_events_table *table, pmu_metric_iter_fn fn, void *data); -const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu); +const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); +const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); +const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index 51fb5f34c1dd..4f3195b84463 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -186,7 +186,7 @@ static int expand_metric_events(void) TEST_ASSERT_VAL("failed to get evlist", evlist); rblist__init(&metric_events); - pme_test = find_core_events_table("testarch", "testcpu"); + pme_test = find_core_metrics_table("testarch", "testcpu"); ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str, false, false, &metric_events); if (ret < 0) { diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 21b7ac00d798..6c527cd805fe 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -96,7 +96,7 @@ static int __compute_metric(const char *name, struct value *vals, runtime_stat__init(&st); /* Parse the metric into metric_events list. */ - pme_test = find_core_events_table("testarch", "testcpu"); + pme_test = find_core_metrics_table("testarch", "testcpu"); err = metricgroup__parse_groups_test(evlist, pme_test, name, false, false, &metric_events); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 8abf5b8439a7..3a67b17b4a16 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -663,7 +663,7 @@ char *perf_pmu__getcpuid(struct perf_pmu *pmu) __weak const struct pmu_events_table *pmu_events_table__find(void) { - return perf_pmu__find_table(NULL); + return perf_pmu__find_events_table(NULL); } /* @@ -794,7 +794,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) { const struct pmu_events_table *table; - table = perf_pmu__find_table(pmu); + table = perf_pmu__find_events_table(pmu); if (!table) return; From patchwork Thu Jan 26 23:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FF9AC05027 for ; Thu, 26 Jan 2023 23:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XzBZBQh/upIOQFzJWznEZlEDjO0cZjokF4r5VgIIW3A=; b=nzVSgySiFMzw88VNQWEFrLoX84 pUUdnklonN8TULq0Aq8eObffcoDmcJqEbH2MWx+BbAXIpNFqZ7S5bp3LiXvOAx9O1L0hDJuqDb0ZU QJT+2EkmcujysZ1+8lktLHm5uQG2fNNgOoftayT/OuneBsdi3RjP8h9oHXfWBKFGKFq3VehryuHzF k4eebJyHVQqWvlaUDK6+OVwJj45W0Yt9WRqJJvlOV0vnflmhFMxCMRpgqFEFF85iHGUg74+Dwwc2x keIxwOzRRoWC6uLNrYM5zsBD9pGLb5cYytTRy1D2eQNeHFMK1do1HSOudnMpElRKaS7lOMwGWsIX+ vP/aNcDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBpT-00ClWd-Ch; Thu, 26 Jan 2023 23:38:51 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoP-00CktF-UQ for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:50 +0000 Received: by mail-yb1-xb49.google.com with SMTP id n194-20020a2540cb000000b008038647d9ebso3588885yba.5 for ; Thu, 26 Jan 2023 15:37:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SS90grWgohlzb32OUVYWhu+Lm8wOsXwcckr8iyu5ib4=; b=jVn+xYURfrGty296mf/7/X4eT5g/5K0s4Skr+7+jvrbQTXSCvBW6lK7hi4SKw6ZMmO LOMNd56aJjjf4xLmbKgdDMpo9x+4KrKqieelSQDA6gMWzJCeeCFBwGB5X/YMIkRtlo5P 1KlfnvOWBSBdS21QES3AEIFk8csrxL9DbqbVhKdC0za9CHoAk7aCzgIYPS924IrmF789 Bi5ucCS7MTGK4PbHPzbbMx1FLozRpMXkSER7wcL9wpTALRoYzFwqbHrN0Yr6637ONCs8 9zPmCbUne7TGhIi1IwTXTK2jqVO2AcJdhoWq8XG3o66r/EaXinQ5ZQGTcNfGgwaiY4c2 E19Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=SS90grWgohlzb32OUVYWhu+Lm8wOsXwcckr8iyu5ib4=; b=sP8853pS3FduwIcFsA4rPMTppABfP0hsijzY2D30OVvk+qpEHh1/odCr54GvsjAaSp JyMYmuQkOZM0XFeHfnFxtK+9+acMw539mXIz9yzmbpH7ctQCVQiUyuWXL9l8iSjoYWFi yEbm17RlN+teBknPjKSbQrk7S7egA+89ZDdt120xIJ+2E4GuT9Lk9eeQLILKbCsgITeB VZIaw+K6KUOCtD7G/b+oKSXfj1NXFu+O/LRqOS7karAwv1Tf6Ek+HZ5pAV9zYAW0DNJy 4ethDb+4iiDyPCoZnDXSuxRHoswpMASmcErwvnN3bz1c9w5I+fN8mSbj9QGoYWGQ1p98 vuJA== X-Gm-Message-State: AO0yUKXpQbjIwAFBX6PH+o7iLvYA8StlWeZUsExBvuSSPK+/hr798f+3 FoVQo1nFm/AVvV8Mj2/KCg39/y6IR96D X-Google-Smtp-Source: AK7set/FzwChscHCORzrVvwZxguBH0dXtRx3KpvVbE2VEccCu699HQGlCl8mK8JRXgOdh8jqKI/pPQ7fASKB X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:ce90:0:b0:80b:6168:a831 with SMTP id x138-20020a25ce90000000b0080b6168a831mr1670013ybe.408.1674776263409; Thu, 26 Jan 2023 15:37:43 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:36 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-7-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 06/15] perf pmu-events: Remove now unused event and metric variables From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153746_722574_EE88FF82 X-CRM114-Status: GOOD ( 20.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Previous changes separated the uses of pmu_event and pmu_metric, however, both structures contained all the variables of event and metric. This change removes the event variables from metric and the metric variables from event. Note, this change removes the setting of evsel's metric_name/expr as these fields are no longer part of struct pmu_event. The metric remains but is no longer implicitly requested when the event is. This impacts a few Intel uncore events, however, as the ScaleUnit is shared by the event and the metric this utility is questionable. Also the MetricNames look broken (contain spaces) in some cases and when trying to use the functionality with '-e' the metrics fail but regular metrics with '-M' work. For example, on SkylakeX '-M' works: ``` $ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1 Performance counter stats for 'system wide': 0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 # 57896.0 Bytes LLC_MISSES.PCIE_WRITE (49.84%) 7,174 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 (49.85%) 0 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 (50.16%) 63 UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 (50.15%) 1.004576381 seconds time elapsed ``` whilst the event '-e' version is broken even with --group/-g (fwiw, we should also remove -g [1]): ``` $ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1 Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE Performance counter stats for 'system wide': 27,316 Bytes LLC_MISSES.PCIE_WRITE 1.004505469 seconds time elapsed ``` The code also carries warnings where the user is supposed to select events for metrics [2] but given the lack of use of such a feature, let's clean the code and just remove. [1] https://lore.kernel.org/lkml/20220707195610.303254-1-irogers@google.com/ [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425 Reviewed-by: John Garry --- tools/perf/builtin-list.c | 20 ++--------------- tools/perf/pmu-events/jevents.py | 20 +++++++++++++---- tools/perf/pmu-events/pmu-events.h | 22 +++++-------------- tools/perf/tests/pmu-events.c | 27 ----------------------- tools/perf/util/parse-events.c | 2 -- tools/perf/util/pmu.c | 35 +++--------------------------- tools/perf/util/pmu.h | 9 -------- tools/perf/util/print-events.c | 32 +++++++-------------------- tools/perf/util/print-events.h | 3 +-- 9 files changed, 36 insertions(+), 134 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 137d73edb541..791f513ae5b4 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -99,8 +99,7 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi const char *scale_unit __maybe_unused, bool deprecated, const char *event_type_desc, const char *desc, const char *long_desc, - const char *encoding_desc, - const char *metric_name, const char *metric_expr) + const char *encoding_desc) { struct print_state *print_state = ps; int pos; @@ -159,10 +158,6 @@ static void default_print_event(void *ps, const char *pmu_name, const char *topi if (print_state->detailed && encoding_desc) { printf("%*s", 8, ""); wordwrap(encoding_desc, 8, pager_get_columns(), 0); - if (metric_name) - printf(" MetricName: %s", metric_name); - if (metric_expr) - printf(" MetricExpr: %s", metric_expr); putchar('\n'); } } @@ -308,8 +303,7 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic, const char *scale_unit, bool deprecated, const char *event_type_desc, const char *desc, const char *long_desc, - const char *encoding_desc, - const char *metric_name, const char *metric_expr) + const char *encoding_desc) { struct json_print_state *print_state = ps; bool need_sep = false; @@ -366,16 +360,6 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic, encoding_desc); need_sep = true; } - if (metric_name) { - fix_escape_printf(&buf, "%s\t\"MetricName\": \"%S\"", need_sep ? ",\n" : "", - metric_name); - need_sep = true; - } - if (metric_expr) { - fix_escape_printf(&buf, "%s\t\"MetricExpr\": \"%S\"", need_sep ? ",\n" : "", - metric_expr); - need_sep = true; - } printf("%s}", need_sep ? "\n" : ""); strbuf_release(&buf); } diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 8df14ab14fcf..4cdbf34b7298 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -37,6 +37,11 @@ _json_event_attributes = [ 'metric_constraint', 'metric_expr', 'long_desc' ] +# Attributes that are in pmu_metric rather than pmu_event. +_json_metric_attributes = [ + 'metric_name', 'metric_group', 'metric_constraint', 'metric_expr', 'desc', + 'long_desc', 'unit', 'compat', 'aggr_mode' +] def removesuffix(s: str, suffix: str) -> str: """Remove the suffix from a string @@ -569,21 +574,28 @@ static void decompress_event(int offset, struct pmu_event *pe) \tconst char *p = &big_c_string[offset]; """) for attr in _json_event_attributes: - _args.output_file.write(f""" + if attr in _json_metric_attributes and 'metric_' in attr: + _args.output_file.write(f'\n\t/* Skip {attr} */\n') + else: + _args.output_file.write(f""" \tpe->{attr} = (*p == '\\0' ? NULL : p); """) if attr == _json_event_attributes[-1]: continue _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} -static void decompress_metric(int offset, struct pmu_metric *pe) + +static void decompress_metric(int offset, struct pmu_metric *pm) { \tconst char *p = &big_c_string[offset]; """) for attr in _json_event_attributes: - _args.output_file.write(f""" -\tpe->{attr} = (*p == '\\0' ? NULL : p); + if attr in _json_metric_attributes: + _args.output_file.write(f""" +\tpm->{attr} = (*p == '\\0' ? NULL : p); """) + else: + _args.output_file.write(f'\n\t/* Skip {attr} */\n') if attr == _json_event_attributes[-1]: continue _args.output_file.write('\twhile (*p++);') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index e2cd3e61acef..dca32979d6a4 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -23,29 +23,19 @@ struct pmu_event { const char *unit; const char *perpkg; const char *aggr_mode; - const char *metric_expr; - const char *metric_name; - const char *metric_group; const char *deprecated; - const char *metric_constraint; }; struct pmu_metric { - const char *name; - const char *compat; - const char *event; - const char *desc; - const char *topic; - const char *long_desc; - const char *pmu; - const char *unit; - const char *perpkg; - const char *aggr_mode; - const char *metric_expr; const char *metric_name; const char *metric_group; - const char *deprecated; + const char *metric_expr; + const char *unit; + const char *compat; + const char *aggr_mode; const char *metric_constraint; + const char *desc; + const char *long_desc; }; struct pmu_events_table; diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index e5fb3d5a06c3..c2b3ada57cbc 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -337,36 +337,12 @@ static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event return -1; } - if (!is_same(e1->metric_expr, e2->metric_expr)) { - pr_debug2("testing event e1 %s: mismatched metric_expr, %s vs %s\n", - e1->name, e1->metric_expr, e2->metric_expr); - return -1; - } - - if (!is_same(e1->metric_name, e2->metric_name)) { - pr_debug2("testing event e1 %s: mismatched metric_name, %s vs %s\n", - e1->name, e1->metric_name, e2->metric_name); - return -1; - } - - if (!is_same(e1->metric_group, e2->metric_group)) { - pr_debug2("testing event e1 %s: mismatched metric_group, %s vs %s\n", - e1->name, e1->metric_group, e2->metric_group); - return -1; - } - if (!is_same(e1->deprecated, e2->deprecated)) { pr_debug2("testing event e1 %s: mismatched deprecated, %s vs %s\n", e1->name, e1->deprecated, e2->deprecated); return -1; } - if (!is_same(e1->metric_constraint, e2->metric_constraint)) { - pr_debug2("testing event e1 %s: mismatched metric_constant, %s vs %s\n", - e1->name, e1->metric_constraint, e2->metric_constraint); - return -1; - } - return 0; } @@ -432,9 +408,6 @@ static int test__pmu_event_table_core_callback(const struct pmu_event *pe, struct perf_pmu_test_event const **test_event_table; bool found = false; - if (!pe->name) - return 0; - if (pe->pmu) test_event_table = &uncore_events[0]; else diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 21cce83462b3..0336ff27c15f 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1570,8 +1570,6 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, evsel->scale = info.scale; evsel->per_pkg = info.per_pkg; evsel->snapshot = info.snapshot; - evsel->metric_expr = info.metric_expr; - evsel->metric_name = info.metric_name; return 0; } diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 3a67b17b4a16..f8c214d8815f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -280,10 +280,6 @@ static void perf_pmu_update_alias(struct perf_pmu_alias *old, perf_pmu_assign_str(old->name, "long_desc", &old->long_desc, &newalias->long_desc); perf_pmu_assign_str(old->name, "topic", &old->topic, &newalias->topic); - perf_pmu_assign_str(old->name, "metric_expr", &old->metric_expr, - &newalias->metric_expr); - perf_pmu_assign_str(old->name, "metric_name", &old->metric_name, - &newalias->metric_name); perf_pmu_assign_str(old->name, "value", &old->str, &newalias->str); old->scale = newalias->scale; old->per_pkg = newalias->per_pkg; @@ -299,8 +295,6 @@ void perf_pmu_free_alias(struct perf_pmu_alias *newalias) zfree(&newalias->long_desc); zfree(&newalias->topic); zfree(&newalias->str); - zfree(&newalias->metric_expr); - zfree(&newalias->metric_name); zfree(&newalias->pmu_name); parse_events_terms__purge(&newalias->terms); free(newalias); @@ -337,16 +331,13 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, int num; char newval[256]; char *long_desc = NULL, *topic = NULL, *unit = NULL, *perpkg = NULL, - *metric_expr = NULL, *metric_name = NULL, *deprecated = NULL, - *pmu_name = NULL; + *deprecated = NULL, *pmu_name = NULL; if (pe) { long_desc = (char *)pe->long_desc; topic = (char *)pe->topic; unit = (char *)pe->unit; perpkg = (char *)pe->perpkg; - metric_expr = (char *)pe->metric_expr; - metric_name = (char *)pe->metric_name; deprecated = (char *)pe->deprecated; pmu_name = (char *)pe->pmu; } @@ -401,8 +392,6 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, perf_pmu__parse_snapshot(alias, dir, name); } - alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL; - alias->metric_name = metric_name ? strdup(metric_name): NULL; alias->desc = desc ? strdup(desc) : NULL; alias->long_desc = long_desc ? strdup(long_desc) : desc ? strdup(desc) : NULL; @@ -756,9 +745,6 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, struct pmu_add_cpu_aliases_map_data *data = vdata; const char *pname = pe->pmu ? pe->pmu : data->cpu_name; - if (!pe->name) - return 0; - if (data->pmu->is_uncore && pmu_uncore_alias_match(pname, data->name)) goto new_alias; @@ -813,12 +799,6 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, struct pmu_sys_event_iter_data *idata = data; struct perf_pmu *pmu = idata->pmu; - if (!pe->name) { - if (pe->metric_group || pe->metric_name) - return 0; - return -EINVAL; - } - if (!pe->compat || !pe->pmu) return 0; @@ -1400,8 +1380,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, info->unit = NULL; info->scale = 0.0; info->snapshot = false; - info->metric_expr = NULL; - info->metric_name = NULL; list_for_each_entry_safe(term, h, head_terms, list) { alias = pmu_find_alias(pmu, term); @@ -1417,8 +1395,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, if (alias->per_pkg) info->per_pkg = true; - info->metric_expr = alias->metric_expr; - info->metric_name = alias->metric_name; list_del_init(&term->list); parse_events_term__delete(term); @@ -1634,8 +1610,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state) for (j = 0; j < len; j++) { const char *name, *alias = NULL, *scale_unit = NULL, *desc = NULL, *long_desc = NULL, - *encoding_desc = NULL, *topic = NULL, - *metric_name = NULL, *metric_expr = NULL; + *encoding_desc = NULL, *topic = NULL; bool deprecated = false; size_t buf_used; @@ -1673,8 +1648,6 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state) buf_used += snprintf(buf + buf_used, sizeof(buf) - buf_used, "%s/%s/", aliases[j].pmu->name, aliases[j].event->str) + 1; - metric_name = aliases[j].event->metric_name; - metric_expr = aliases[j].event->metric_expr; deprecated = aliases[j].event->deprecated; } print_cb->print_event(print_state, @@ -1687,9 +1660,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state) "Kernel PMU event", desc, long_desc, - encoding_desc, - metric_name, - metric_expr); + encoding_desc); } if (printed && pager_in_use()) printf("\n"); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 2bdc560f19c7..64c596a358cc 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -132,8 +132,6 @@ extern struct perf_pmu perf_pmu__fake; struct perf_pmu_info { const char *unit; - const char *metric_expr; - const char *metric_name; double scale; bool per_pkg; bool snapshot; @@ -187,13 +185,6 @@ struct perf_pmu_alias { * default. */ bool deprecated; - /** - * @metric_expr: A metric expression associated with an event. Doing - * this makes little sense due to scale and unit applying to both. - */ - char *metric_expr; - /** @metric_name: A name for the metric. unit applying to both. */ - char *metric_name; /** @pmu_name: The name copied from struct perf_pmu. */ char *pmu_name; }; diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 2646ae18d9f9..62e9ea7dcf40 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -101,9 +101,7 @@ void print_tracepoint_events(const struct print_callbacks *print_cb, void *print "Tracepoint event", /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); } free(dir_path); free(evt_namelist); @@ -195,9 +193,7 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) "SDT event", /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); free(evt_name); } @@ -255,9 +251,7 @@ int print_hwcache_events(const struct print_callbacks *print_cb, void *print_sta event_type_descriptors[PERF_TYPE_HW_CACHE], /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); } strlist__delete(evt_name_list); return 0; @@ -277,9 +271,7 @@ void print_tool_events(const struct print_callbacks *print_cb, void *print_state "Tool event", /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); } } @@ -331,9 +323,7 @@ void print_symbol_events(const struct print_callbacks *print_cb, void *print_sta event_type_descriptors[type], /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); } strlist__delete(evt_name_list); } @@ -364,9 +354,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state) event_type_descriptors[PERF_TYPE_RAW], /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); print_cb->print_event(print_state, /*topic=*/NULL, @@ -378,9 +366,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state) event_type_descriptors[PERF_TYPE_RAW], "(see 'man perf-list' on how to encode it)", /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); print_cb->print_event(print_state, /*topic=*/NULL, @@ -392,9 +378,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state) event_type_descriptors[PERF_TYPE_BREAKPOINT], /*desc=*/NULL, /*long_desc=*/NULL, - /*encoding_desc=*/NULL, - /*metric_name=*/NULL, - /*metric_expr=*/NULL); + /*encoding_desc=*/NULL); print_tracepoint_events(print_cb, print_state); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index c237e53c4487..716dcf4b4859 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -16,8 +16,7 @@ struct print_callbacks { const char *scale_unit, bool deprecated, const char *event_type_desc, const char *desc, const char *long_desc, - const char *encoding_desc, - const char *metric_name, const char *metric_expr); + const char *encoding_desc); void (*print_metric)(void *print_state, const char *group, const char *name, From patchwork Thu Jan 26 23:36:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4540C05027 for ; Thu, 26 Jan 2023 23:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VUCVXCCmdChf7FXzzKSoaNpSJWpd3HtQJUV/9MmOxj0=; b=gitPhG4HQk3I+wRgdjNk0g9QYP 8YFMtnPTRdPCzO1/XCvbHDbCdsC4oTlhgl9xCl/kdVLSae2+Y9m4uYQDBq+OgftHVRrFBomX0HdAS 1qEZrRHCggGQenSFgzeGzyT1mPL9vv51d1vdIW5V7EK6quG0YSJuA0ga4oFiWaAjvsdlCqlR5SInc VI3fnnJuR/ycSqLvxGshLRuI4YQ09PD9COa4MfXmwHfFhfQj9jxUgRjCuhp0FzhmLszXbKrJke6aN On5HCSYRcq7vJHdtInat4QtX8SEDDCzx6LZ8T6g+7R4/4WITJrw4KJi+uXMbA/vC5jCchRvSZdOE2 4kiXVTog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBq9-00Clo6-O2; Thu, 26 Jan 2023 23:39:33 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoX-00Cl55-4O for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:37:55 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id o1-20020a252801000000b0080b8600bdc9so3595125ybo.3 for ; Thu, 26 Jan 2023 15:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=uI6fIFedsJpOLIOhQhVhxz0/qvMMlyLGFRBReTiGS9A=; b=neW8DlQWi2lJmMRPeteCYNGulGhd5+sl3R9twMzOL/sQzVTOiXbkNrb7B+Qzf3Vvw2 J5vWZ2r4e8Jxvn5QxrI5vWU+f3/3QgLoM93eTKJD0gAjso0UgHM+b/odVK9IXxVcq8yq SUZhri48HxAwysAtfSopd2wCYGpwKfpnH/eW2AjX4/HMQA4i0vasmZ+fT01RldkHYiJi PbOf+DP1oK/4wlGLfg9bNb4gEpeDNAxH3+myDdxXubSrGvInXMYmajLuAVvaMlLOXEvK MbHyPrke9xDAXJlyvwrFuANXQail/XmFA1BnPOcgxi00XT7AQEvu0BYkucOoBUop0Z/I 5s7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=uI6fIFedsJpOLIOhQhVhxz0/qvMMlyLGFRBReTiGS9A=; b=N+6S6RUPQmhekL9uZCGQsDIzNfD6sJS7yXtVPGfV0lnGAuz6gW0YBsMUHWjJH5TZkp wv9M2rJ4vNbM6E6F0efOeMlEyHvP/6U7f5o/xh/Sx4G9eKRLIja54ZgMkJZyw/aJg7Vu RS9ZQynUNKdnbaqbndrg6CE6XFsWX7n0RiYyJLCuefjpM1082bBORZnrAqiRcol1SBDj oaoWuPEBdal2QBnQOQ9V5gwK62dBBYqNcJCcoVCG5R7Kwes/KcqWp+7HeKwkRuKzd2GV gubLgM81jINJLI8puz2Wx+5rddJpsJMPtBXyRE0cE72t+uK+aLK+QwlIz43ZKQud4+b+ KqKA== X-Gm-Message-State: AFqh2kqZg/QRmzcj0NR5cavZgSoG3YBG5IC3SgBmLmM6dusTqmzA8tvo T9nxf3QTZBB4rLRhYmVBOpK6gqpNTy2P X-Google-Smtp-Source: AMrXdXt8cJmrdwmhepz48xZc9rh0NdIvBjWhKKsC8kPd5k7GrcZkKEQetjN142/SCNeDupzozABKHTmqtkug X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:7e81:0:b0:7e5:ecf1:ebde with SMTP id z123-20020a257e81000000b007e5ecf1ebdemr3102826ybc.375.1674776270909; Thu, 26 Jan 2023 15:37:50 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:37 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-8-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 07/15] perf stat: Remove evsel metric_name/expr From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153753_225030_8676185F X-CRM114-Status: GOOD ( 18.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Metrics are their own unit and these variables held broken metrics previously and now just hold the value NULL. Remove code that used these variables. Reviewed-by: John Garry --- tools/perf/builtin-stat.c | 1 - tools/perf/util/cgroup.c | 1 - tools/perf/util/evsel.c | 2 - tools/perf/util/evsel.h | 2 - tools/perf/util/python.c | 7 --- tools/perf/util/stat-shadow.c | 112 ---------------------------------- tools/perf/util/stat.h | 1 - 7 files changed, 126 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9f3e4b257516..5d18a5a6f662 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2524,7 +2524,6 @@ int cmd_stat(int argc, const char **argv) &stat_config.metric_events); zfree(&metrics); } - perf_stat__collect_metric_expr(evsel_list); perf_stat__init_shadow_stats(); if (add_default_attributes()) diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index cd978c240e0d..bfb13306d82c 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -481,7 +481,6 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str, nr_cgroups++; if (metric_events) { - perf_stat__collect_metric_expr(tmp_list); if (metricgroup__copy_metric_events(tmp_list, cgrp, metric_events, &orig_metric_events) < 0) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8550638587e5..a90e998826e0 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -285,8 +285,6 @@ void evsel__init(struct evsel *evsel, evsel->sample_size = __evsel__sample_size(attr->sample_type); evsel__calc_id_pos(evsel); evsel->cmdline_group_boundary = false; - evsel->metric_expr = NULL; - evsel->metric_name = NULL; evsel->metric_events = NULL; evsel->per_pkg_mask = NULL; evsel->collect_stat = false; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d572be41b960..24cb807ef6ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -105,8 +105,6 @@ struct evsel { * metric fields are similar, but needs more care as they can have * references to other metric (evsel). */ - const char * metric_expr; - const char * metric_name; struct evsel **metric_events; struct evsel *metric_leader; diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 9e5d881b0987..42e8b813d010 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -76,13 +76,6 @@ const char *perf_env__arch(struct perf_env *env __maybe_unused) return NULL; } -/* - * Add this one here not to drag util/stat-shadow.c - */ -void perf_stat__collect_metric_expr(struct evlist *evsel_list) -{ -} - /* * These ones are needed not to drag the PMU bandwagon, jevents generated * pmu_sys_event_tables, etc and evsel__find_pmu() is used so far just for diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index cadb2df23c87..35ea4813f468 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -346,114 +346,6 @@ static const char *get_ratio_color(enum grc_type type, double ratio) return color; } -static struct evsel *perf_stat__find_event(struct evlist *evsel_list, - const char *name) -{ - struct evsel *c2; - - evlist__for_each_entry (evsel_list, c2) { - if (!strcasecmp(c2->name, name) && !c2->collect_stat) - return c2; - } - return NULL; -} - -/* Mark MetricExpr target events and link events using them to them. */ -void perf_stat__collect_metric_expr(struct evlist *evsel_list) -{ - struct evsel *counter, *leader, **metric_events, *oc; - bool found; - struct expr_parse_ctx *ctx; - struct hashmap_entry *cur; - size_t bkt; - int i; - - ctx = expr__ctx_new(); - if (!ctx) { - pr_debug("expr__ctx_new failed"); - return; - } - evlist__for_each_entry(evsel_list, counter) { - bool invalid = false; - - leader = evsel__leader(counter); - if (!counter->metric_expr) - continue; - - expr__ctx_clear(ctx); - metric_events = counter->metric_events; - if (!metric_events) { - if (expr__find_ids(counter->metric_expr, - counter->name, - ctx) < 0) - continue; - - metric_events = calloc(sizeof(struct evsel *), - hashmap__size(ctx->ids) + 1); - if (!metric_events) { - expr__ctx_free(ctx); - return; - } - counter->metric_events = metric_events; - } - - i = 0; - hashmap__for_each_entry(ctx->ids, cur, bkt) { - const char *metric_name = cur->pkey; - - found = false; - if (leader) { - /* Search in group */ - for_each_group_member (oc, leader) { - if (!strcasecmp(oc->name, - metric_name) && - !oc->collect_stat) { - found = true; - break; - } - } - } - if (!found) { - /* Search ignoring groups */ - oc = perf_stat__find_event(evsel_list, - metric_name); - } - if (!oc) { - /* Deduping one is good enough to handle duplicated PMUs. */ - static char *printed; - - /* - * Adding events automatically would be difficult, because - * it would risk creating groups that are not schedulable. - * perf stat doesn't understand all the scheduling constraints - * of events. So we ask the user instead to add the missing - * events. - */ - if (!printed || - strcasecmp(printed, metric_name)) { - fprintf(stderr, - "Add %s event to groups to get metric expression for %s\n", - metric_name, - counter->name); - free(printed); - printed = strdup(metric_name); - } - invalid = true; - continue; - } - metric_events[i++] = oc; - oc->collect_stat = true; - } - metric_events[i] = NULL; - if (invalid) { - free(metric_events); - counter->metric_events = NULL; - counter->metric_expr = NULL; - } - } - expr__ctx_free(ctx); -} - static double runtime_stat_avg(struct runtime_stat *st, enum stat_type type, int map_idx, struct runtime_stat_data *rsd) @@ -1299,10 +1191,6 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, color = NULL; print_metric(config, ctxp, color, "%8.1f%%", "Core Bound", core_bound * 100.); - } else if (evsel->metric_expr) { - generic_metric(config, evsel->metric_expr, evsel->metric_events, NULL, - evsel->name, evsel->metric_name, NULL, 1, - map_idx, out, st); } else if (runtime_stat_n(st, STAT_NSECS, map_idx, &rsd) != 0) { char unit = ' '; char unit_buf[10] = "/sec"; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 499c3bf81333..b1c29156c560 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -257,7 +257,6 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct perf_stat_output_ctx *out, struct rblist *metric_events, struct runtime_stat *st); -void perf_stat__collect_metric_expr(struct evlist *); int evlist__alloc_stats(struct perf_stat_config *config, struct evlist *evlist, bool alloc_raw); From patchwork Thu Jan 26 23:36:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 613C3C05027 for ; Thu, 26 Jan 2023 23:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Hs1APtIGbhXWzcNYJQNSpEEk4qguK8InT+AQx6KyoSg=; b=Mi+dciIBpb4eBLeG/1jQvNe7+S GyDfNDK6hlpf3KqS5W/90lEABwIwUOmcKSDc83UdqzGnLIWQJN3z/xZrtH9BHk2qIjjSqxsxAwSlA oe11H0rgxI8FuGPwNIzr4Q6tQX7LZPr5sffKTcbQeEDv1Mve787e5KFR+wFf6Kw74m/mprZ1dnOwS jq0vTYn1/upJl2WMbd2j9Hf8SmdqTICqktLF6ryELnBqpzY93AswiQxC2e3a8xqUKlR1unEYgWede BvecEHIuwCVqnKbbG4gfJiyMLb6Cs4/4kpMZDJQ7dWQBGr2UPPLV0Ms7gf1I1LeRxEQsHfpYgRYFa 3Dnbi5zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBqZ-00Clys-Es; Thu, 26 Jan 2023 23:39:59 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBod-00Cl7a-Ue for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:01 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5005ef73cf3so37452147b3.2 for ; Thu, 26 Jan 2023 15:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FoTYT9Og9W7mOnq4wl24j8oeZ9sXDx0pwBnIKjojMSA=; b=ULUppHbH0Lds8PRb4HCInj6sdVtWfg1huViMQi1YE0ul63ee8883+M0MnHN4Us2V7i TmjI70t+lcCBgmZxtoL/jVWPJ6sNnKqitAyb4vnBVnY/dMkVpEDZBvCVPjCW3YmSEr4F AKZBMBxOLYx67TrJvqXkt8MfTBW1ftqkkF1sbbshp97ZvIv+FuvNWM5Pl0BCYc+fMQjF jG3XD5ioKeQ1A5FPzRWN6yoxg3PDQSVRSrZ9uTL5IG0keeoCO+uX8swHm+XxplFeE095 9igTX6u9qNkN705TCI2pwnGERWhDZUmphBbqVscDIST1+JZmSqkpiApPjtWUTiwkTlXA dj3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=FoTYT9Og9W7mOnq4wl24j8oeZ9sXDx0pwBnIKjojMSA=; b=EVWKUzVDcc2C537pXRO7T4aRm90VFLjpWW0wYBFO4qepx+fRCM4mb4wU0sMSJohhIw 3QO+1LsN7Trhmr5ZP+azQfvMXOZgBNdqnAl5iQKufHBgIBzG7gY/taRUjHDnFfS+TKkF XnbIaVBl1Ok3F/r9CDSB2b40stYACkRlXX9cYqxrTCs8TD2USLXjc3TU1jvSqRxlD5kh Eale4iJH6qjiehAz2KYCLTYzhOl0saqx8DNRDrbR1eGnV8wc6nvYQOoohO5bn4XyI7XZ JFF4hY9UgJ5+CPWSm9CmUbq7LM+EQd44/+aMXBi15mHlczJWEnVlGneFugr2zfuLEyjU 5PuA== X-Gm-Message-State: AO0yUKWSZ/Kx0i8jyjvqag4dUukA6IcOqjpHp9Z0mN8bwdFFHSsDljdE 88qQIv+t11CLaE7pu6bUT4t+djEbBYeC X-Google-Smtp-Source: AK7set83ZU/+aIZhovn+Ujc40CNNaJnunjOMXWOZV5je7wWwRjnplJ+bu5E9859RuJWtZNCyTfNVH7wZOkFk X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:2f88:0:b0:80b:c194:655c with SMTP id v130-20020a252f88000000b0080bc194655cmr677594ybv.236.1674776278610; Thu, 26 Jan 2023 15:37:58 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:38 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-9-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 08/15] perf jevents: Combine table prefix and suffix writing From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153800_028375_009B8518 X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Combine into a single function to simplify, in a later change, writing metrics separately. --- tools/perf/pmu-events/jevents.py | 36 +++++++++++++------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 4cdbf34b7298..5f8d490c7269 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -19,10 +19,10 @@ _sys_event_tables = [] # JsonEvent. Architecture standard events are in json files in the top # f'{_args.starting_dir}/{_args.arch}' directory. _arch_std_events = {} -# Track whether an events table is currently being defined and needs closing. -_close_table = False # Events to write out when the table is closed _pending_events = [] +# Name of table to be written out +_pending_events_tblname = None # Global BigCString shared by all structures. _bcs = None # Order specific JsonEvent attributes will be visited. @@ -378,24 +378,13 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.metric_name.lower()] = event -def print_events_table_prefix(tblname: str) -> None: - """Called when a new events table is started.""" - global _close_table - if _close_table: - raise IOError('Printing table prefix but last table has no suffix') - _args.output_file.write(f'static const struct compact_pmu_event {tblname}[] = {{\n') - _close_table = True - - def add_events_table_entries(item: os.DirEntry, topic: str) -> None: """Add contents of file to _pending_events table.""" - if not _close_table: - raise IOError('Table entries missing prefix') for e in read_json_events(item.path, topic): _pending_events.append(e) -def print_events_table_suffix() -> None: +def print_pending_events() -> None: """Optionally close events table.""" def event_cmp_key(j: JsonEvent) -> Tuple[bool, str, str, str, str]: @@ -407,17 +396,19 @@ def print_events_table_suffix() -> None: return (j.desc is not None, fix_none(j.topic), fix_none(j.name), fix_none(j.pmu), fix_none(j.metric_name)) - global _close_table - if not _close_table: + global _pending_events + if not _pending_events: return - global _pending_events + global _pending_events_tblname + _args.output_file.write( + f'static const struct compact_pmu_event {_pending_events_tblname}[] = {{\n') + for event in sorted(_pending_events, key=event_cmp_key): _args.output_file.write(event.to_c_string()) - _pending_events = [] + _pending_events = [] _args.output_file.write('};\n\n') - _close_table = False def get_topic(topic: str) -> str: if topic.endswith('metrics.json'): @@ -455,12 +446,13 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: # model directory, reset topic if item.is_dir() and is_leaf_dir(item.path): - print_events_table_suffix() + print_pending_events() tblname = file_name_to_table_name(parents, item.name) if item.name == 'sys': _sys_event_tables.append(tblname) - print_events_table_prefix(tblname) + global _pending_events_tblname + _pending_events_tblname = tblname return # base dir or too deep @@ -809,7 +801,7 @@ struct compact_pmu_event { for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file) - print_events_table_suffix() + print_pending_events() print_mapping_table(archs) print_system_mapping_table() From patchwork Thu Jan 26 23:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07BF7C05027 for ; Thu, 26 Jan 2023 23:41:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dnBag2pCGoPmu7QI8WDYZ6KJLuXagkMT0C2beu21jsA=; b=Dm7zEOLPCxM/DQconN/XMmx24v sWjVMqxO/oybXYwRUDaok8Woklbsdt5f5W3rzLvIoWlRabqA0kLtnxjqrDAIyD2ovSHqGIIUIYhgD vyXlU0d5pL3IwOFh9wjCCRG6BGZptC/3pY4yn2/n0xq0gSJNxAvEEenetuB0W8F8T99J5QKn6nq2T ZCOhIeCN3CvMz2IeXTBUR5P6Cpl2FQcBr/ykE7VguXc7IK+pLG3tGvmHFkNESdwTk2U895MHmZuHf aRqWR3x2m2Df2NS0MGtokbCaSncEDyPbVmLdI2Cv/3N/LFMtZ4gV3nShgPg0uHTPhcjvik2KdUVFZ rHwyTwHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBqy-00CmBA-Ol; Thu, 26 Jan 2023 23:40:25 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBom-00ClBH-En for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:11 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-50660dd3263so37367037b3.19 for ; Thu, 26 Jan 2023 15:38:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=EwmlnWAznmIuSklcPXcPcZQenZPbuVtqsMsWpkC7XfE=; b=WsmfLZ16mU7tmkDOEdOasbyJpZYKYWwZvo0hz744whCpnejZ8uY4DvPUVrPACYQ7JK e5klKA70QwUEM8GJpJebkCWo28s/8hc9v3xPcb8yABPtgYUsk8QJ7lxWU1wMoD5HnLhB WUXIWdZIi1DtFHWNAzDTgDDXucixEWFbGUYb5NR7Dxh218qZ+LrYcY16vxQ6DRheqdjG al6MEmN+HdMB0qtzMbN1qInTY5ax4YEN/QNS90h106C2grPPak0ITyBnQxzToyhpapGd HTIf/oXZLmL9LOeJAE2e7GTfkhuQBHCful+NpS7sQ3T31kFFeLFi/c0LFlsv+7eXGpKb PcVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=EwmlnWAznmIuSklcPXcPcZQenZPbuVtqsMsWpkC7XfE=; b=oJdVpGVm8pcyExyPmAhJZFfXtD8rxo9iClpp24mVj6/MZZqpdYV5TajoWzCNSDJ33Z MJP15+3M9uZrz5QLj93f8kMc7m8XBmrZXbaT1/V9vUqEIH1L005N1eX74Z8P7xLAbwLc SchvokuiF4GRo/rD2psggtyYHKed67dUW3v1ElxhukT5qK9IwqMNWSS4b5xzjCG1F6Te UvTwyqfQgUB0jeP+VkpwJVZafbQHRj+BHPXzQdUCUgdt6eoJD5cuZ9vX8w8Pro/fultM +nOBWMMNqCX7wUXygenqWEAjTqsIwQTU0SjaIBAXa/2vAZEqARdSrR9OXakV3Mow0Rop V+Rg== X-Gm-Message-State: AFqh2krbjaSjwXkzQ8HIoZnJMZq9ASe+IeRyBlFpTMjFTTVJYJqQJ/5e 9Rz833jTR6w3WQ+MrbY7uEKtVX/xseX7 X-Google-Smtp-Source: AMrXdXv7tpkLcYzwlE6PaLht9x4pKv6DPLDmn8PpWuAxHjdYOaNA9iEIhy+3OjKUlea7DkReR0vEtWrjCrW0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a81:e94c:0:b0:4b1:9930:6c06 with SMTP id e12-20020a81e94c000000b004b199306c06mr4713403ywm.327.1674776286845; Thu, 26 Jan 2023 15:38:06 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:39 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-10-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 09/15] perf pmu-events: Introduce pmu_metrics_table From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153808_557466_13C4F562 X-CRM114-Status: GOOD ( 21.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a metrics table that is just a cast from pmu_events_table. This changes the APIs so that event and metric usage of the underlying table is different. For the no jevents case the tables are already separate, later changes will separate the tables for the jevents case. --- tools/perf/arch/arm64/util/pmu.c | 11 ++++- tools/perf/pmu-events/empty-pmu-events.c | 21 ++++----- tools/perf/pmu-events/jevents.py | 21 ++++++--- tools/perf/pmu-events/pmu-events.h | 10 +++-- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 5 ++- tools/perf/util/metricgroup.c | 54 ++++++++++++------------ tools/perf/util/metricgroup.h | 2 +- tools/perf/util/pmu.c | 5 +++ tools/perf/util/pmu.h | 1 + 11 files changed, 78 insertions(+), 56 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c index 801bf52e2ea6..2779840d8896 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -22,7 +22,14 @@ static struct perf_pmu *pmu__find_core_pmu(void) return NULL; return pmu; - } +} + +const struct pmu_metrics_table *pmu_metrics_table__find(void) +{ + struct perf_pmu *pmu = pmu__find_core_pmu(); + + if (pmu) + return perf_pmu__find_metrics_table(pmu); return NULL; } @@ -32,7 +39,7 @@ const struct pmu_events_table *pmu_events_table__find(void) struct perf_pmu *pmu = pmu__find_core_pmu(); if (pmu) - return perf_pmu__find_table(pmu); + return perf_pmu__find_events_table(pmu); return NULL; } diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 10bd4943ebf8..a938b74cf487 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -278,13 +278,11 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_ev return 0; } -int pmu_events_table_for_each_metric(const struct pmu_events_table *etable, pmu_metric_iter_fn fn, - void *data) +int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, + void *data) { - struct pmu_metrics_table *table = (struct pmu_metrics_table *)etable; - for (const struct pmu_metric *pm = &table->entries[0]; pm->metric_expr; pm++) { - int ret = fn(pm, etable, data); + int ret = fn(pm, table, data); if (ret) return ret; @@ -320,9 +318,9 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) return table; } -const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) +const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) { - const struct pmu_events_table *table = NULL; + const struct pmu_metrics_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); int i; @@ -340,7 +338,7 @@ const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = (const struct pmu_events_table *)&map->metric_table; + table = &map->metric_table; break; } } @@ -359,13 +357,13 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch return NULL; } -const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return (const struct pmu_events_table *)&tables->metric_table; + return &tables->metric_table; } return NULL; } @@ -386,8 +384,7 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_metric( - (const struct pmu_events_table *)&tables->metric_table, fn, data); + int ret = pmu_metrics_table_for_each_metric(&tables->metric_table, fn, data); if (ret) return ret; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 5f8d490c7269..d83cc94af51f 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -611,10 +611,12 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, return 0; } -int pmu_events_table_for_each_metric(const struct pmu_events_table *table, +int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *mtable, pmu_metric_iter_fn fn, void *data) { + const struct pmu_events_table *table = (const struct pmu_events_table *)mtable; + for (size_t i = 0; i < table->length; i++) { struct pmu_metric pm; int ret; @@ -622,7 +624,7 @@ int pmu_events_table_for_each_metric(const struct pmu_events_table *table, decompress_metric(table->entries[i].offset, &pm); if (!pm.metric_expr) continue; - ret = fn(&pm, table, data); + ret = fn(&pm, mtable, data); if (ret) return ret; } @@ -656,6 +658,11 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) return table; } +const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) +{ + return (struct pmu_metrics_table *)perf_pmu__find_events_table(pmu); +} + const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) { for (const struct pmu_events_map *tables = &pmu_events_map[0]; @@ -667,9 +674,9 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch return NULL; } -const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid) +const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid) { - return (struct pmu_events_table *)find_core_events_table(arch, cpuid); + return (struct pmu_metrics_table *)find_core_events_table(arch, cpuid); } int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) @@ -690,7 +697,8 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + int ret = pmu_metrics_table_for_each_metric( + (struct pmu_metrics_table *)&tables->table, fn, data); if (ret) return ret; @@ -727,7 +735,8 @@ int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; tables->name; tables++) { - int ret = pmu_events_table_for_each_metric(&tables->table, fn, data); + int ret = pmu_metrics_table_for_each_metric( + (struct pmu_metrics_table *)&tables->table, fn, data); if (ret) return ret; diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index dca32979d6a4..b7d4a66b8ad2 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -39,28 +39,30 @@ struct pmu_metric { }; struct pmu_events_table; +struct pmu_metrics_table; typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, const struct pmu_events_table *table, void *data); typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, void *data); int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data); -int pmu_events_table_for_each_metric(const struct pmu_events_table *table, pmu_metric_iter_fn fn, +int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, void *data); const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); -const struct pmu_events_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); +const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu); const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); -const struct pmu_events_table *find_core_metrics_table(const char *arch, const char *cpuid); +const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); const struct pmu_events_table *find_sys_events_table(const char *name); +const struct pmu_metrics_table *find_sys_metrics_table(const char *name); int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data); diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index 4f3195b84463..672a27f37060 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -180,7 +180,7 @@ static int expand_metric_events(void) struct evlist *evlist; struct rblist metric_events; const char metric_str[] = "CPI"; - const struct pmu_events_table *pme_test; + const struct pmu_metrics_table *pme_test; evlist = evlist__new(); TEST_ASSERT_VAL("failed to get evlist", evlist); diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 6c527cd805fe..9fec6040950c 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -72,7 +72,7 @@ static int __compute_metric(const char *name, struct value *vals, struct rblist metric_events = { .nr_entries = 0, }; - const struct pmu_events_table *pme_test; + const struct pmu_metrics_table *pme_test; struct perf_cpu_map *cpus; struct runtime_stat st; struct evlist *evlist; diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index c2b3ada57cbc..9f2e385e0991 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -813,7 +813,8 @@ struct metric { struct metric_ref metric_ref; }; -static int test__parsing_callback(const struct pmu_metric *pm, const struct pmu_events_table *table, +static int test__parsing_callback(const struct pmu_metric *pm, + const struct pmu_metrics_table *table, void *data) { int *failures = data; @@ -995,7 +996,7 @@ static int metric_parse_fake(const char *metric_name, const char *str) } static int test__parsing_fake_callback(const struct pmu_metric *pm, - const struct pmu_events_table *table __maybe_unused, + const struct pmu_metrics_table *table __maybe_unused, void *data __maybe_unused) { return metric_parse_fake(pm->metric_name, pm->metric_expr); diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 47fd02af66f1..f3559be95541 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -457,7 +457,7 @@ struct metricgroup_iter_data { }; static int metricgroup__sys_event_iter(const struct pmu_metric *pm, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, void *data) { struct metricgroup_iter_data *d = data; @@ -477,8 +477,8 @@ static int metricgroup__sys_event_iter(const struct pmu_metric *pm, } static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric *pm, - const struct pmu_events_table *table __maybe_unused, - void *vdata) + const struct pmu_metrics_table *table __maybe_unused, + void *vdata) { struct rblist *groups = vdata; @@ -488,16 +488,16 @@ static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric *pm, void metricgroup__print(const struct print_callbacks *print_cb, void *print_state) { struct rblist groups; - const struct pmu_events_table *table; + const struct pmu_metrics_table *table; struct rb_node *node, *next; rblist__init(&groups); groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; - table = pmu_events_table__find(); + table = pmu_metrics_table__find(); if (table) { - pmu_events_table_for_each_metric(table, + pmu_metrics_table_for_each_metric(table, metricgroup__add_to_mep_groups_callback, &groups); } @@ -765,11 +765,11 @@ struct metricgroup_add_iter_data { bool system_wide; struct metric *root_metric; const struct visited_metric *visited; - const struct pmu_events_table *table; + const struct pmu_metrics_table *table; }; static bool metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, struct pmu_metric *pm); static int add_metric(struct list_head *metric_list, @@ -780,7 +780,7 @@ static int add_metric(struct list_head *metric_list, bool system_wide, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_table *table); + const struct pmu_metrics_table *table); /** * resolve_metric - Locate metrics within the root metric and recursively add @@ -807,7 +807,7 @@ static int resolve_metric(struct list_head *metric_list, bool system_wide, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { struct hashmap_entry *cur; size_t bkt; @@ -889,7 +889,7 @@ static int __add_metric(struct list_head *metric_list, bool system_wide, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { const struct visited_metric *vm; int ret; @@ -982,7 +982,7 @@ struct metricgroup__find_metric_data { }; static int metricgroup__find_metric_callback(const struct pmu_metric *pm, - const struct pmu_events_table *table __maybe_unused, + const struct pmu_metrics_table *table __maybe_unused, void *vdata) { struct metricgroup__find_metric_data *data = vdata; @@ -995,7 +995,7 @@ static int metricgroup__find_metric_callback(const struct pmu_metric *pm, } static bool metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, struct pmu_metric *pm) { struct metricgroup__find_metric_data data = { @@ -1003,7 +1003,7 @@ static bool metricgroup__find_metric(const char *metric, .pm = pm, }; - return pmu_events_table_for_each_metric(table, metricgroup__find_metric_callback, &data) + return pmu_metrics_table_for_each_metric(table, metricgroup__find_metric_callback, &data) ? true : false; } @@ -1015,7 +1015,7 @@ static int add_metric(struct list_head *metric_list, bool system_wide, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { int ret = 0; @@ -1045,8 +1045,8 @@ static int add_metric(struct list_head *metric_list, } static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm, - const struct pmu_events_table *table __maybe_unused, - void *data) + const struct pmu_metrics_table *table __maybe_unused, + void *data) { struct metricgroup_add_iter_data *d = data; int ret; @@ -1105,7 +1105,7 @@ struct metricgroup__add_metric_data { }; static int metricgroup__add_metric_callback(const struct pmu_metric *pm, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, void *vdata) { struct metricgroup__add_metric_data *data = vdata; @@ -1143,7 +1143,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier const char *user_requested_cpu_list, bool system_wide, struct list_head *metric_list, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { LIST_HEAD(list); int ret; @@ -1163,7 +1163,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier * Iterate over all metrics seeing if metric matches either the * name or group. When it does add the metric to the list. */ - ret = pmu_events_table_for_each_metric(table, metricgroup__add_metric_callback, + ret = pmu_metrics_table_for_each_metric(table, metricgroup__add_metric_callback, &data); if (ret) goto out; @@ -1219,7 +1219,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier static int metricgroup__add_metric_list(const char *list, bool metric_no_group, const char *user_requested_cpu_list, bool system_wide, struct list_head *metric_list, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { char *list_itr, *list_copy, *metric_name, *modifier; int ret, count = 0; @@ -1429,7 +1429,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, bool system_wide, struct perf_pmu *fake_pmu, struct rblist *metric_events_list, - const struct pmu_events_table *table) + const struct pmu_metrics_table *table) { struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); @@ -1577,7 +1577,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool system_wide, struct rblist *metric_events) { - const struct pmu_events_table *table = pmu_events_table__find(); + const struct pmu_metrics_table *table = pmu_metrics_table__find(); if (!table) return -EINVAL; @@ -1588,7 +1588,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, } int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, const char *str, bool metric_no_group, bool metric_no_merge, @@ -1601,7 +1601,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist, } static int metricgroup__has_metric_callback(const struct pmu_metric *pm, - const struct pmu_events_table *table __maybe_unused, + const struct pmu_metrics_table *table __maybe_unused, void *vdata) { const char *metric = vdata; @@ -1617,12 +1617,12 @@ static int metricgroup__has_metric_callback(const struct pmu_metric *pm, bool metricgroup__has_metric(const char *metric) { - const struct pmu_events_table *table = pmu_events_table__find(); + const struct pmu_metrics_table *table = pmu_metrics_table__find(); if (!table) return false; - return pmu_events_table_for_each_metric(table, metricgroup__has_metric_callback, + return pmu_metrics_table_for_each_metric(table, metricgroup__has_metric_callback, (void *)metric) ? true : false; } diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index b1f186d0f514..84030321a057 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -73,7 +73,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, bool system_wide, struct rblist *metric_events); int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_events_table *table, + const struct pmu_metrics_table *table, const char *str, bool metric_no_group, bool metric_no_merge, diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f8c214d8815f..c256b29defad 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -655,6 +655,11 @@ __weak const struct pmu_events_table *pmu_events_table__find(void) return perf_pmu__find_events_table(NULL); } +__weak const struct pmu_metrics_table *pmu_metrics_table__find(void) +{ + return perf_pmu__find_metrics_table(NULL); +} + /* * Suffix must be in form tok_{digits}, or tok{digits}, or same as pmu_name * to be valid. diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 64c596a358cc..6b770f17eb86 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -231,6 +231,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu, char *perf_pmu__getcpuid(struct perf_pmu *pmu); const struct pmu_events_table *pmu_events_table__find(void); +const struct pmu_metrics_table *pmu_metrics_table__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); From patchwork Thu Jan 26 23:36:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0F9B1C54EAA for ; Thu, 26 Jan 2023 23:42:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=355wuQj1kcnhIblpy13oVGLe64cboUD8PuLEsJTNQcw=; b=hHWVh1tZEGUB1GeS/AH+Xs1oCC FLSUV3uOyunnIFo68E+VJGmppFEDbEsH9hlQ24hbC4ZlC+JNeMOm9GcbJyHu5bJ1e0zgaFsuYCpAp tz6eEbu5XY+v/aqUNv7jT/TxxOPdFJ6kcFEMwXsA4DuxKL5rMMuOBqi1B0eODdomLG29FChxLcLCU JHJHNLyj62CQ3SHRaskb8u6tpzXVNdkjrts8xldTuFSTUmWmTz/H/bbTtNu7OdjGa/6ig9Qw1psVR upYNHOmC7FNoHlwxpWXLDTFQAyNXqQ6S6WDjbuAxOm2kq1N0cadOcnZ2K9p5T6xauQi9wjh5verEs 77aUXZeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBrZ-00CmPd-Gm; Thu, 26 Jan 2023 23:41:02 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBos-00ClE8-Qe for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:18 +0000 Received: by mail-yb1-xb49.google.com with SMTP id n203-20020a2572d4000000b0078f09db9888so3571529ybc.18 for ; Thu, 26 Jan 2023 15:38:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rgaL7fTLciRMj0236xUDyoUjWYE0YTTX8Uwd7deoYFM=; b=UVxY0+8bHvxk1X6SHpPSWfIvGslOtlfOLKXmOTnkORMBu28G6kEYL9CzDjLGKeCO8f dNcau7D6gNGqlGyLAjIpLVBtouLhyudm4OH3M3FMibjXXWUymr0q22iMQextFSqVUDCC c5sB2R4RyQ2b4y2s2GfdbuRH+j/afqZ0Tz1ag2KaNcmVdfXsDha2Cvd9bM8/TBDU8kWI ur/oOCfA0SB7rDo5mC5I25U1G0StkkKnabrTYpDQU3JERiFaP4WkyI/NGFDC/AiRqTO/ cqIalsR6UGApQyuwvUzLaDKXGXf0WSna6yWOIZEH0gPk6Uw+tpI1SFHZU7XJhR2VNoaw l01g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=rgaL7fTLciRMj0236xUDyoUjWYE0YTTX8Uwd7deoYFM=; b=QZNgXEd3xNaV+H6OrItDDX3ykX8KwHEDw+68h7rwhdYvG0EsNGme2YML1iljgNirh9 5eDTVqq1gj10SK4dmHECSz/i0SzgzBkZ0spUhoBsAdc6B0985AAxkMEaHdDPzfeRo+da mdAL0EdwZqvCJkNCquVaEF9U4v9f3ga88rfS9gg0CQLVzEbM+f4i2iLqpz9+3PMWeGWw J+LbyDXy2JFEPuJW8KnYPe1zp3czb9gvVL5dKmYkecjljx9K167XLcKZLWDQ9rtExHst DBhFa6i999AGUxRJktMyubabB1QBlWIoJyKiqyG82kfkBUMdfUlZDF5hAiEuxE59dUfK eUhQ== X-Gm-Message-State: AO0yUKXOQ6hMow90gJ3fC0aZlflSx/NDRXFsLNI8b6cRYoPjWCGMIyC3 Hu9iSD8GPhNliViRApcW/OLC+g8uO9W2 X-Google-Smtp-Source: AK7set9WYPebKTDJi3N21r2zohiiq+IqM7CiMzlWGE/ve+FhjdvtcCA8n9sTLwkvl44e8Wokgmv2NvyfdMYs X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a81:5ca:0:b0:506:4e9b:2104 with SMTP id 193-20020a8105ca000000b005064e9b2104mr1535676ywf.492.1674776293282; Thu, 26 Jan 2023 15:38:13 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:40 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-11-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 10/15] perf jevents: Generate metrics and events as separate tables From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153814_942109_24A9E7F0 X-CRM114-Status: GOOD ( 24.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Turn a perf json event into an event, metric or both. This reduces the number of events needed to scan to find an event or metric. As events no longer need the relatively seldom used metric fields, 4 bytes is saved per event. This reduces the big C string's size by 335kb (14.8%) on x86. Note, for the test PMU architecture pme_test_soc_cpu is renamed pmu_events__test_soc_cpu for consistency with the event vs metric naming convention. --- tools/perf/pmu-events/jevents.py | 244 +++++++++++++++++++++++-------- tools/perf/tests/pmu-events.c | 3 +- 2 files changed, 189 insertions(+), 58 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index d83cc94af51f..627ee817f57f 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -13,28 +13,40 @@ import collections # Global command line arguments. _args = None +# List of regular event tables. +_event_tables = [] # List of event tables generated from "/sys" directories. _sys_event_tables = [] +# List of regular metric tables. +_metric_tables = [] +# List of metric tables generated from "/sys" directories. +_sys_metric_tables = [] +# Mapping between sys event table names and sys metric table names. +_sys_event_table_to_metric_table_mapping = {} # Map from an event name to an architecture standard # JsonEvent. Architecture standard events are in json files in the top # f'{_args.starting_dir}/{_args.arch}' directory. _arch_std_events = {} # Events to write out when the table is closed _pending_events = [] -# Name of table to be written out +# Name of events table to be written out _pending_events_tblname = None +# Metrics to write out when the table is closed +_pending_metrics = [] +# Name of metrics table to be written out +_pending_metrics_tblname = None # Global BigCString shared by all structures. _bcs = None # Order specific JsonEvent attributes will be visited. _json_event_attributes = [ # cmp_sevent related attributes. - 'name', 'pmu', 'topic', 'desc', 'metric_name', 'metric_group', + 'name', 'pmu', 'topic', 'desc', # Seems useful, put it early. 'event', # Short things in alphabetical order. 'aggr_mode', 'compat', 'deprecated', 'perpkg', 'unit', # Longer things (the last won't be iterated over during decompress). - 'metric_constraint', 'metric_expr', 'long_desc' + 'long_desc' ] # Attributes that are in pmu_metric rather than pmu_event. @@ -52,14 +64,16 @@ def removesuffix(s: str, suffix: str) -> str: return s[0:-len(suffix)] if s.endswith(suffix) else s -def file_name_to_table_name(parents: Sequence[str], dirname: str) -> str: +def file_name_to_table_name(prefix: str, parents: Sequence[str], + dirname: str) -> str: """Generate a C table name from directory names.""" - tblname = 'pme' + tblname = prefix for p in parents: tblname += '_' + p tblname += '_' + dirname return tblname.replace('-', '_') + def c_len(s: str) -> int: """Return the length of s a C string @@ -277,7 +291,7 @@ class JsonEvent: self.metric_constraint = jd.get('MetricConstraint') self.metric_expr = None if 'MetricExpr' in jd: - self.metric_expr = metric.ParsePerfJson(jd['MetricExpr']).Simplify() + self.metric_expr = metric.ParsePerfJson(jd['MetricExpr']).Simplify() arch_std = jd.get('ArchStdEvent') if precise and self.desc and '(Precise Event)' not in self.desc: @@ -326,23 +340,24 @@ class JsonEvent: s += f'\t{attr} = {value},\n' return s + '}' - def build_c_string(self) -> str: + def build_c_string(self, metric: bool) -> str: s = '' - for attr in _json_event_attributes: + for attr in _json_metric_attributes if metric else _json_event_attributes: x = getattr(self, attr) - if x and attr == 'metric_expr': + if metric and x and attr == 'metric_expr': # Convert parsed metric expressions into a string. Slashes # must be doubled in the file. x = x.ToPerfJson().replace('\\', '\\\\') s += f'{x}\\000' if x else '\\000' return s - def to_c_string(self) -> str: + def to_c_string(self, metric: bool) -> str: """Representation of the event as a C struct initializer.""" - s = self.build_c_string() + s = self.build_c_string(metric) return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n' + @lru_cache(maxsize=None) def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" @@ -381,7 +396,10 @@ def preprocess_arch_std_files(archpath: str) -> None: def add_events_table_entries(item: os.DirEntry, topic: str) -> None: """Add contents of file to _pending_events table.""" for e in read_json_events(item.path, topic): - _pending_events.append(e) + if e.name: + _pending_events.append(e) + if e.metric_name: + _pending_metrics.append(e) def print_pending_events() -> None: @@ -401,15 +419,54 @@ def print_pending_events() -> None: return global _pending_events_tblname + if _pending_events_tblname.endswith('_sys'): + global _sys_event_tables + _sys_event_tables.append(_pending_events_tblname) + else: + global event_tables + _event_tables.append(_pending_events_tblname) + _args.output_file.write( f'static const struct compact_pmu_event {_pending_events_tblname}[] = {{\n') for event in sorted(_pending_events, key=event_cmp_key): - _args.output_file.write(event.to_c_string()) + _args.output_file.write(event.to_c_string(metric=False)) _pending_events = [] _args.output_file.write('};\n\n') +def print_pending_metrics() -> None: + """Optionally close metrics table.""" + + def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]: + def fix_none(s: Optional[str]) -> str: + if s is None: + return '' + return s + + return (j.desc is not None, fix_none(j.pmu), fix_none(j.metric_name)) + + global _pending_metrics + if not _pending_metrics: + return + + global _pending_metrics_tblname + if _pending_metrics_tblname.endswith('_sys'): + global _sys_metric_tables + _sys_metric_tables.append(_pending_metrics_tblname) + else: + global metric_tables + _metric_tables.append(_pending_metrics_tblname) + + _args.output_file.write( + f'static const struct compact_pmu_event {_pending_metrics_tblname}[] = {{\n') + + for metric in sorted(_pending_metrics, key=metric_cmp_key): + _args.output_file.write(metric.to_c_string(metric=True)) + _pending_metrics = [] + + _args.output_file.write('};\n\n') + def get_topic(topic: str) -> str: if topic.endswith('metrics.json'): return 'metrics' @@ -432,12 +489,13 @@ def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None: topic = get_topic(item.name) for event in read_json_events(item.path, topic): - _bcs.add(event.build_c_string()) + if event.name: + _bcs.add(event.build_c_string(metric=False)) + if event.metric_name: + _bcs.add(event.build_c_string(metric=True)) def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: """Process a JSON file during the main walk.""" - global _sys_event_tables - def is_leaf_dir(path: str) -> bool: for item in os.scandir(path): if item.is_dir(): @@ -447,12 +505,15 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: # model directory, reset topic if item.is_dir() and is_leaf_dir(item.path): print_pending_events() + print_pending_metrics() - tblname = file_name_to_table_name(parents, item.name) - if item.name == 'sys': - _sys_event_tables.append(tblname) global _pending_events_tblname - _pending_events_tblname = tblname + _pending_events_tblname = file_name_to_table_name('pmu_events_', parents, item.name) + global _pending_metrics_tblname + _pending_metrics_tblname = file_name_to_table_name('pmu_metrics_', parents, item.name) + + if item.name == 'sys': + _sys_event_table_to_metric_table_mapping[_pending_events_tblname] = _pending_metrics_tblname return # base dir or too deep @@ -477,6 +538,12 @@ struct pmu_events_table { size_t length; }; +/* Struct used to make the PMU metric table implementation opaque to callers. */ +struct pmu_metrics_table { + const struct compact_pmu_event *entries; + size_t length; +}; + /* * Map a CPU to its table of PMU events. The CPU is identified by the * cpuid field, which is an arch-specific identifier for the CPU. @@ -488,7 +555,8 @@ struct pmu_events_table { struct pmu_events_map { const char *arch; const char *cpuid; - struct pmu_events_table table; + struct pmu_events_table event_table; + struct pmu_metrics_table metric_table; }; /* @@ -502,9 +570,13 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = "testarch", \t.cpuid = "testcpu", -\t.table = { -\t.entries = pme_test_soc_cpu, -\t.length = ARRAY_SIZE(pme_test_soc_cpu), +\t.event_table = { +\t\t.entries = pmu_events__test_soc_cpu, +\t\t.length = ARRAY_SIZE(pmu_events__test_soc_cpu), +\t}, +\t.metric_table = { +\t\t.entries = pmu_metrics__test_soc_cpu, +\t\t.length = ARRAY_SIZE(pmu_metrics__test_soc_cpu), \t} }, """) @@ -515,14 +587,29 @@ const struct pmu_events_map pmu_events_map[] = { for row in table: # Skip the first row or any row beginning with #. if not first and len(row) > 0 and not row[0].startswith('#'): - tblname = file_name_to_table_name([], row[2].replace('/', '_')) + event_tblname = file_name_to_table_name('pmu_events_', [], row[2].replace('/', '_')) + if event_tblname in _event_tables: + event_size = f'ARRAY_SIZE({event_tblname})' + else: + event_tblname = 'NULL' + event_size = '0' + metric_tblname = file_name_to_table_name('pmu_metrics_', [], row[2].replace('/', '_')) + if metric_tblname in _metric_tables: + metric_size = f'ARRAY_SIZE({metric_tblname})' + else: + metric_tblname = 'NULL' + metric_size = '0' cpuid = row[0].replace('\\', '\\\\') _args.output_file.write(f"""{{ \t.arch = "{arch}", \t.cpuid = "{cpuid}", -\t.table = {{ -\t\t.entries = {tblname}, -\t\t.length = ARRAY_SIZE({tblname}) +\t.event_table = {{ +\t\t.entries = {event_tblname}, +\t\t.length = {event_size} +\t}}, +\t.metric_table = {{ +\t\t.entries = {metric_tblname}, +\t\t.length = {metric_size} \t}} }}, """) @@ -531,7 +618,8 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = 0, \t.cpuid = 0, -\t.table = { 0, 0 }, +\t.event_table = { 0, 0 }, +\t.metric_table = { 0, 0 }, } }; """) @@ -542,14 +630,36 @@ def print_system_mapping_table() -> None: _args.output_file.write(""" struct pmu_sys_events { \tconst char *name; -\tstruct pmu_events_table table; +\tstruct pmu_events_table event_table; +\tstruct pmu_metrics_table metric_table; }; static const struct pmu_sys_events pmu_sys_event_tables[] = { """) + printed_metric_tables = [] for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ -\t\t.table = {{ +\t\t.event_table = {{ +\t\t\t.entries = {tblname}, +\t\t\t.length = ARRAY_SIZE({tblname}) +\t\t}},""") + metric_tblname = _sys_event_table_to_metric_table_mapping[tblname] + if metric_tblname in _sys_metric_tables: + _args.output_file.write(f""" +\t\t.metric_table = {{ +\t\t\t.entries = {metric_tblname}, +\t\t\t.length = ARRAY_SIZE({metric_tblname}) +\t\t}},""") + printed_metric_tables.append(metric_tblname) + _args.output_file.write(f""" +\t\t.name = \"{tblname}\", +\t}}, +""") + for tblname in _sys_metric_tables: + if tblname in printed_metric_tables: + continue + _args.output_file.write(f"""\t{{ +\t\t.metric_table = {{ \t\t\t.entries = {tblname}, \t\t\t.length = ARRAY_SIZE({tblname}) \t\t}}, @@ -557,7 +667,8 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { \t}}, """) _args.output_file.write("""\t{ -\t\t.table = { 0, 0 } +\t\t.event_table = { 0, 0 }, +\t\t.metric_table = { 0, 0 }, \t}, }; @@ -566,10 +677,7 @@ static void decompress_event(int offset, struct pmu_event *pe) \tconst char *p = &big_c_string[offset]; """) for attr in _json_event_attributes: - if attr in _json_metric_attributes and 'metric_' in attr: - _args.output_file.write(f'\n\t/* Skip {attr} */\n') - else: - _args.output_file.write(f""" + _args.output_file.write(f""" \tpe->{attr} = (*p == '\\0' ? NULL : p); """) if attr == _json_event_attributes[-1]: @@ -581,14 +689,11 @@ static void decompress_metric(int offset, struct pmu_metric *pm) { \tconst char *p = &big_c_string[offset]; """) - for attr in _json_event_attributes: - if attr in _json_metric_attributes: - _args.output_file.write(f""" + for attr in _json_metric_attributes: + _args.output_file.write(f""" \tpm->{attr} = (*p == '\\0' ? NULL : p); """) - else: - _args.output_file.write(f'\n\t/* Skip {attr} */\n') - if attr == _json_event_attributes[-1]: + if attr == _json_metric_attributes[-1]: continue _args.output_file.write('\twhile (*p++);') _args.output_file.write("""} @@ -611,12 +716,10 @@ int pmu_events_table_for_each_event(const struct pmu_events_table *table, return 0; } -int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *mtable, +int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, void *data) { - const struct pmu_events_table *table = (const struct pmu_events_table *)mtable; - for (size_t i = 0; i < table->length; i++) { struct pmu_metric pm; int ret; @@ -624,7 +727,7 @@ int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *mtable, decompress_metric(table->entries[i].offset, &pm); if (!pm.metric_expr) continue; - ret = fn(&pm, mtable, data); + ret = fn(&pm, table, data); if (ret) return ret; } @@ -650,7 +753,7 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = &map->table; + table = &map->event_table; break; } } @@ -660,7 +763,29 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) { - return (struct pmu_metrics_table *)perf_pmu__find_events_table(pmu); + const struct pmu_metrics_table *table = NULL; + char *cpuid = perf_pmu__getcpuid(pmu); + int i; + + /* on some platforms which uses cpus map, cpuid can be NULL for + * PMUs other than CORE PMUs. + */ + if (!cpuid) + return NULL; + + i = 0; + for (;;) { + const struct pmu_events_map *map = &pmu_events_map[i++]; + if (!map->arch) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = &map->metric_table; + break; + } + } + free(cpuid); + return table; } const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid) @@ -669,14 +794,20 @@ const struct pmu_events_table *find_core_events_table(const char *arch, const ch tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return &tables->table; + return &tables->event_table; } return NULL; } const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid) { - return (struct pmu_metrics_table *)find_core_events_table(arch, cpuid); + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->arch; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return &tables->metric_table; + } + return NULL; } int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) @@ -684,7 +815,7 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->event_table, fn, data); if (ret) return ret; @@ -697,8 +828,7 @@ int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_events_map *tables = &pmu_events_map[0]; tables->arch; tables++) { - int ret = pmu_metrics_table_for_each_metric( - (struct pmu_metrics_table *)&tables->table, fn, data); + int ret = pmu_metrics_table_for_each_metric(&tables->metric_table, fn, data); if (ret) return ret; @@ -712,7 +842,7 @@ const struct pmu_events_table *find_sys_events_table(const char *name) tables->name; tables++) { if (!strcmp(tables->name, name)) - return &tables->table; + return &tables->event_table; } return NULL; } @@ -722,7 +852,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; tables->name; tables++) { - int ret = pmu_events_table_for_each_event(&tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->event_table, fn, data); if (ret) return ret; @@ -735,8 +865,7 @@ int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data) for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; tables->name; tables++) { - int ret = pmu_metrics_table_for_each_metric( - (struct pmu_metrics_table *)&tables->table, fn, data); + int ret = pmu_metrics_table_for_each_metric(&tables->metric_table, fn, data); if (ret) return ret; @@ -811,6 +940,7 @@ struct compact_pmu_event { arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file) print_pending_events() + print_pending_metrics() print_mapping_table(archs) print_system_mapping_table() diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 9f2e385e0991..962c3c0d53ba 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -469,7 +469,8 @@ static int test__pmu_event_table_sys_callback(const struct pmu_event *pe, static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_events_table *sys_event_table = find_sys_events_table("pme_test_soc_sys"); + const struct pmu_events_table *sys_event_table = + find_sys_events_table("pmu_events__test_soc_sys"); const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu"); int map_events = 0, expected_events, err; From patchwork Thu Jan 26 23:36:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D97A8C05027 for ; Thu, 26 Jan 2023 23:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XKutUaKOv5DLGS2A3Ba9Dd5f27sidPcxZj//yt6OLD8=; b=SWvlHG/7gPsBGQwwswS4mMeBMe 3ZbuSUTstrl/flMpW6ZFiB6pGgzfnTpl4+OK1cJ76Sd1KbFr+KBLHvav5fJlIazgua6Qe5peYVZsn UU2OQ1Fwl6MWwFwboFaePzJ5YUc7ADHxXxLOmCwUB7qJbZpeImml476HAqRAvVOpGBzKn7fo6a0AO O5UOhXDdqSP7Ex6FswDONUEafV0NdOuLjL8ohJLWFyVMnVLTjwQyL14FjH1wdCGX74/vnIXuG5ZZq a94eq5oQG+zntm/fufzVJ9V/+uvUD5fCIn7LP+HsPC/QV9NJ6ZQdIg+2+yTzeWMAIuUvFCRGNFpo0 4JJNeozA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBsC-00CmhL-M3; Thu, 26 Jan 2023 23:41:40 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBoz-00ClHP-Te for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:23 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id z9-20020a25ba49000000b007d4416e3667so3593081ybj.23 for ; Thu, 26 Jan 2023 15:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IwLDElolHzeZLKuISE9CI+5UsjDPN8soJqHYYoHyVfU=; b=mUVaju3nOKChRdBXbRrG511ZdgeydKkpFLygk8N9IPus6RUGwOirgTw3T6gdfTfzr2 ri2wpt+PrZ42Xn071wp+LQhqH+elR/Nhbz7KYAQnHJlHyNNLoKZpCvvBG10Yl6WQp5aB c0RgZOrBDK8Uw0YakyZNIx9PANqn5sClNxkHQRGcotQ/ARkKa5jR0XxJTlVECLtXQWrB egfCOCLsUNdY589QTAYSBtfFFgAXhNKt8rbTYZVi6OPusPOvrIqGxaiKZ1+wMgAPfyFY 7kjQdlvg8gkyYZkY2CDPI3EukUo8dYC249pP6eTQxENksi+EprnuE1duKfwv/RJUDlwJ NIkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=IwLDElolHzeZLKuISE9CI+5UsjDPN8soJqHYYoHyVfU=; b=wn+XYo4Rv3Lr+Koytm2fpw1JoRedxle+Wd3GVWe4ykhgtl4onJlKkxAFze8kpv0NPA fZ7nUxzVSggGRtQsGqlUzI2/pJJWqEPtQwaZWPHmx/X685kPO4poCpNKECWET3LEVNuu S+BCR2R0okuPBDzl6bpUSf7YcM9qTy5P8Id/bABdhqUs2TQ1X0qepuNBsGHKPf1vJUNu RJf3kMcqDRWaSOaNdjVDGGooxKH76a2YdnP0QOph0yVqu1KgZ8K/jC2rLF2Jhz3pgUPP ZPVKennKzefbwwwIqGU7gu39rU/II8oAa6PA5d3ffvi1rzIxtKuo1dVL3XsDENU8NjQV TSmA== X-Gm-Message-State: AFqh2kpGKRlSxeEwuu1xJ3sY4o9Fz6hCJJ1a6LJatdv/CKMJC1Ys9B87 JXq5duv3ka3hRO8GyoXP3Nqn2a7YbL9G X-Google-Smtp-Source: AMrXdXurlT/MBprPyUf0wEkWYa4By5hnxMjN10TK8OtYnoQ9X72UaUExeqjlvkTePRgt8wZMr3APhFQ44gi9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a0d:f047:0:b0:4e0:c054:9c60 with SMTP id z68-20020a0df047000000b004e0c0549c60mr4471856ywe.490.1674776300084; Thu, 26 Jan 2023 15:38:20 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:41 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-12-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 11/15] perf jevents: Add model list option From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153822_000807_BB5BBBA0 X-CRM114-Status: GOOD ( 16.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This allows the set of generated jevents events and metrics be limited to a subset of the model names. Appropriate if trying to minimize the binary size where only a set of models are possible. --- tools/perf/pmu-events/Build | 3 ++- tools/perf/pmu-events/jevents.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 15b9e8fdbffa..a14de24ecb69 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -10,6 +10,7 @@ JEVENTS_PY = pmu-events/jevents.py ifeq ($(JEVENTS_ARCH),) JEVENTS_ARCH=$(SRCARCH) endif +JEVENTS_MODEL ?= all # # Locate/process JSON files in pmu-events/arch/ @@ -23,5 +24,5 @@ $(OUTPUT)pmu-events/pmu-events.c: pmu-events/empty-pmu-events.c else $(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) pmu-events/metric.py $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) pmu-events/arch $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ endif diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 627ee817f57f..2bcd07ce609f 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -599,6 +599,8 @@ const struct pmu_events_map pmu_events_map[] = { else: metric_tblname = 'NULL' metric_size = '0' + if event_size == '0' and metric_size == '0': + continue cpuid = row[0].replace('\\', '\\\\') _args.output_file.write(f"""{{ \t.arch = "{arch}", @@ -888,12 +890,24 @@ def main() -> None: action: Callable[[Sequence[str], os.DirEntry], None]) -> None: """Replicate the directory/file walking behavior of C's file tree walk.""" for item in os.scandir(path): + if _args.model != 'all' and item.is_dir(): + # Check if the model matches one in _args.model. + if len(parents) == _args.model.split(',')[0].count('/'): + # We're testing the correct directory. + item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + item.name + if 'test' not in item_path and item_path not in _args.model.split(','): + continue action(parents, item) if item.is_dir(): ftw(item.path, parents + [item.name], action) ap = argparse.ArgumentParser() ap.add_argument('arch', help='Architecture name like x86') + ap.add_argument('model', help='''Select a model such as skylake to +reduce the code size. Normally set to "all". For architectures like +ARM64 with an implementor/model, the model must include the implementor +such as "arm/cortex-a34".''', + default='all') ap.add_argument( 'starting_dir', type=dir_path, From patchwork Thu Jan 26 23:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A94BFC54EAA for ; Thu, 26 Jan 2023 23:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DYmNL/5QGBQSP6Cwj8A60lceErnZ4x6CvXKMnn5AnQc=; b=Q3PGgyAymllXL6qLmSilsivWTG Ofo+uGHZzM+NKZyrTWq1RXFaOAs1lpQlC5jozTHPYfpQnM8SnVx1f+gatTvJycgxVjhEkLi9hdcQZ fxKLH9D1idI2g0dz+KtTilXTfxIyb+2dD8T9+hrSpfrD6XtpRsnoXD+IwuXhMvjtdyTl8S2AHgei7 MtxomY+3VP5N8NyKgu9B2HiUMWb3Ne/X4gQaWKUMFinuPAnxfaLPW4ES6fHmVX9Y0XSdC/oyfxRqq wAcg4nSS2PHhO2PWF91cKjHJn3JO/6NNGBw5g71e1Ve4MOZBdp7Tz7faXnF+Boh6E8kgkDDrSxDmg vJceVXQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBsi-00CmwD-UQ; Thu, 26 Jan 2023 23:42:13 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBp6-00ClKV-UY for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:30 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id d21-20020a25add5000000b007ff8112e8b8so3610505ybe.17 for ; Thu, 26 Jan 2023 15:38:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wSC7IGbFplNjrd7OktgTvuZJ+ddPP0r726YUt977o3g=; b=gZCa5OqiYz7NyA6wxR3fCZCky6kk8dd2ivPt2CaREtn9Z9XF7e58Rav+cA+K9bCEQN 6o/MuJmb4H9idBb7vfMk6bOdgVuHCE0F1qZipjYthhqjcv0pQUDz7YLAwSnEwbtHbdUa Wgxo77095ctlPwQfJX+yHJM0Uan+lqnh/xUw7edMCiC9weIc2kyt+nqBL14pgSN2L2vb SR6CTArsAMMpLftaHCc2QfE0zG4i+0XSSZyQT1M9E5/QyPP+wKGZh3F8G7xJ3tmQPakA Bn6o3nUY8Q2zmRZGMjElSQ0vZRi9PIeDYDzIB/xxyyVnQhkZaUw/lcuFrgqIk2uBkGz2 r/Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=wSC7IGbFplNjrd7OktgTvuZJ+ddPP0r726YUt977o3g=; b=n9Cj1+2hJdmqjUwGIXldVdzypY6vemFfYSToA1BK1QAIQa6zhipUM0k1YlYizZKl/2 S+gQIDzrGGiYYba4v8gfsQyioC4i1UOVFfrVxHsDiL8ZI9/65MHUCXG3K4eknWdX4PvP oXEGQhkPWyZ5D7opR1YtzjUQ20VChbrmTsZwOqQINcVWDG9ychPQ9VoyS5li2wT8Zcju YCa4RitQZxYDQP4EZuRSS/BZVBisrjMOQoQdZj/H11z8s5ZBN/uNrpdJrIAg2Mzq4YZB ESutEzCayXOtC/X/diMxL1fe31HW/IpppZYLCWHhG+vLKbpx5wbwro+cE41pyOdxY1In 9JcQ== X-Gm-Message-State: AO0yUKUG9gKf49NKvy+/yIT13PtIB2QNdZU6KwD3Jh95XRD6JQgFtsU5 ukkYcwZJlytgnRsonV5hnrGX5AcVRnkV X-Google-Smtp-Source: AK7set+OUpwXf8Bx1zrRtgOMDopCjgg4Qbg1GA9ZQB3lT9ReFsdmmO2a+c65JJvtRAYo78u7CvJ3tHwlJO8s X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a81:b246:0:b0:506:55d9:3a78 with SMTP id q67-20020a81b246000000b0050655d93a78mr1019749ywh.339.1674776306506; Thu, 26 Jan 2023 15:38:26 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:42 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-13-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 12/15] perf pmu-events: Fix testing with JEVENTS_ARCH=all From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153829_046126_3D48D657 X-CRM114-Status: GOOD ( 15.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The #slots literal will return NAN when not on ARM64 which causes a perf test failure when not on an ARM64 for a JEVENTS_ARCH=all build: .. 10.4: Parsing of PMU event table metrics with fake PMUs : FAILED! .. Add an is_test boolean so that the failure can be avoided when running as a test. Fixes: acef233b7ca7 ("perf pmu: Add #slots literal support for arm64") Reviewed-by: John Garry --- tools/perf/tests/pmu-events.c | 1 + tools/perf/util/expr.h | 1 + tools/perf/util/expr.l | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 962c3c0d53ba..accf44b3d968 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -950,6 +950,7 @@ static int metric_parse_fake(const char *metric_name, const char *str) pr_debug("expr__ctx_new failed"); return TEST_FAIL; } + ctx->sctx.is_test = true; if (expr__find_ids(str, NULL, ctx) < 0) { pr_err("expr__find_ids failed\n"); return -1; diff --git a/tools/perf/util/expr.h b/tools/perf/util/expr.h index 029271540fb0..eaa44b24c555 100644 --- a/tools/perf/util/expr.h +++ b/tools/perf/util/expr.h @@ -9,6 +9,7 @@ struct expr_scanner_ctx { char *user_requested_cpu_list; int runtime; bool system_wide; + bool is_test; }; struct expr_parse_ctx { diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l index 0168a9637330..72ff4f3d6d4b 100644 --- a/tools/perf/util/expr.l +++ b/tools/perf/util/expr.l @@ -84,9 +84,11 @@ static int literal(yyscan_t scanner, const struct expr_scanner_ctx *sctx) YYSTYPE *yylval = expr_get_lval(scanner); yylval->num = expr__get_literal(expr_get_text(scanner), sctx); - if (isnan(yylval->num)) - return EXPR_ERROR; - + if (isnan(yylval->num)) { + if (!sctx->is_test) + return EXPR_ERROR; + yylval->num = 1; + } return LITERAL; } %} From patchwork Thu Jan 26 23:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2F29C54EAA for ; Thu, 26 Jan 2023 23:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bkxWGPR3TlGz+uM15JP3vR4wfi33T/SQj5L5hVtkUw0=; b=l+QD80QYh4WFu+DktUXX2UPN9R u3HtiDWqv7biwJORlGtx9j9c6836tOvdYoRmlr2hIvsue8Q2NUoazzQ8ZI4aRVZrohrE7S2zdhNwD B6+HcIaFnnmJmXL+J7WWhOAFKFqesJY8gFnNvCqzaWzCnw8MgaxYySGbjg25tifHgDkGZPHdJayC2 IYUugr7ue9IRwboBr00Vcx2Fm8VGV1P0RXcIs4lE9v+sUa8JQed8MbYvIcTAGMaqT71xOcxUhYmwp DImJRaVTFecOILZotO9029a4xI2IZd9nFdTzKHigByZhfo5tjF0ymWvrZtrAGRHcT+vsNNbIPFp9C GRNgiFIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBtJ-00CnBH-3N; Thu, 26 Jan 2023 23:42:50 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBpC-00ClO0-Pc for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:36 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4ff7c6679f2so37561607b3.12 for ; Thu, 26 Jan 2023 15:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xTYdmI9og0perxBFMnwOyD8JALYBo9fFqhvIGnAB7iw=; b=pN++yaxhHw5hsqtHgPMZeHJr1T+f83UqE4aoFtt5+LAeg4UHQo6kEIwVfN/W5KzpWd NAKHo1zdw7heZJbx1WfqGp1S+SxrOx8iQQEmdAlVDg2VTtwzUZXBX9I4nN6s/ySTc+jr 3ZaRTEU2LdtjdBqC28mfYKA3RWWRWiipp0ubURRbSnB2td+dOXW6A6Z1YmXTTTs7lrMt kSSpO1HdzzSc0Io1imdV8ICez2HaQFT3vzJjPfo5xcK7Rc2m+quLXQ9DiPdQKhFDh9i9 7D6enP4ZWLDUdi03ANNOdVpbRaEKQA7hGat0dQrO/F54JVVNV8CR5DwopbFxCgwL+Ylt 8iEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=xTYdmI9og0perxBFMnwOyD8JALYBo9fFqhvIGnAB7iw=; b=fOgffaf4riTJMfwJsxY0lzbpd9Cn4sTnJ+8n5QyYVmr8KVtZ2WTnMrmwVJLIrkEOZP btI/hxq5LfC2+QBWiaC4KbwBOomuMfnumvgytf0JsC/RfOCgVkkW7L5Xis3d75AKnxi+ AUnAoE0FYRsZhL32VZ5qfFgci24/R+xWAZBjlTIUPrVSCj+E+u1Sb+Th95TsXq6NDpDn 1hHLgtn2S60RB1Opm0njJeX2eiCiyHhjsb+2T161D7QdP6TECv9JFRLvCCEEwM0DO/P8 se+OuRuYfUROti37kl+VO4GutJAy54rFCJMWn6hbb2LtPtoABGsj5QloUNOZ59w14blw ma4g== X-Gm-Message-State: AO0yUKUeV9ioGsLnffyaGFJz1Rbzdw7dj+pcWCz76Gp1+0KxxzK8/EDW adizYy7eWjwUVJBuN5Yvqm1VcMFw5Fz9 X-Google-Smtp-Source: AK7set8ogChtzu8dxXsUiUpTxkmy4XJKX0fEnPVUFfp8yLVVlaZbFvMbbtXJs9Lil32EN+jbOQsVkSj+abRi X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:ce90:0:b0:80b:6168:a831 with SMTP id x138-20020a25ce90000000b0080b6168a831mr1670207ybe.408.1674776313147; Thu, 26 Jan 2023 15:38:33 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:43 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-14-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 13/15] perf jevents: Correct bad character encoding From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153834_865812_D6B5C14A X-CRM114-Status: GOOD ( 12.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A character encoding issue added a "3D" character that breaks the metrics test. Fixes: 40769665b63d ("perf jevents: Parse metrics during conversion") --- tools/perf/pmu-events/metric_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py index ced5998bd827..e4c792428277 100644 --- a/tools/perf/pmu-events/metric_test.py +++ b/tools/perf/pmu-events/metric_test.py @@ -89,8 +89,8 @@ class TestMetricExpressions(unittest.TestCase): after = r'min((a + b if c > 1 else c + d), e + f)' self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) - before =3D r'a if b else c if d else e' - after =3D r'(a if b else (c if d else e))' + before = r'a if b else c if d else e' + after = r'(a if b else (c if d else e))' self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) def test_ToPython(self): From patchwork Thu Jan 26 23:36:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39AD0C54EAA for ; Thu, 26 Jan 2023 23:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Go+tFCPONz5fq0OFBcZ2EYzh4mgCEVQf0v7aTyeRyYg=; b=hcGDJ5OYyM4RLNlINkrbP0sbTF EvUCMaUY4+Ki6znL/IVE15tjfHL/vmBOTWcs7ONFngwkD1waDfLVOa+KBxyq8anZJrnMOqg5cnm+8 U+WRhiDSKk/doA1Z5WExnBQo0l44cxMTXI17/SYKv3gJ4C8KsHk7Kh5SyM0zN//qLiUli/RM058QG jzxd3cykRqcBsdtG2EB1OS2/Q4EJuGNcGlVQ7ogcuYdPH9FRdHH9Ps+iDxH5HBKZCzu0rksrMAjhj FQYufiqs5arDWxsQHVm5oREwTYr6rsAyI4FdoWNQdk77AypIpH0QCGH145soReqwxXOyOfM5PSU9g HGLjeP3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBu4-00CnVe-I3; Thu, 26 Jan 2023 23:43:37 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBpM-00ClSq-AF for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:46 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4bdeb1bbeafso37310517b3.4 for ; Thu, 26 Jan 2023 15:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=snCBxLwh7jm6krd4EQPzPcciOFAFt0fWD1CpQDw1t+8=; b=e6ohvklUxI4ipjwUCogc5GWZzMwgpvonuMqEFAldtcrN5gwr7vxUrcVT0vO30kWL/u UTKdHnDRG6MmsGo21+eZky1ijnGvGJykYoL/kbFW9ydXTr28qfBvoBzw4x0iBjSVI/qy VTCRwVi0mxUxy0SzS4w3U/CgWKzSOIkd80PZW3EXNp2goqcaJGRQYStILOiyjyH57toU Ov2TmXZBqoiT6exgPN6QdRQYDvkEyTP7AI0uIu/zVKmHN2V4qhHd+ihEH4gbDypEXF5s B7IQpf7Q7r5YYT3Gs4h8bzZo9lqB4lzNuM0ur+i/xVRYO3M91t6R/XihIzHynFsRrdw4 oOWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=snCBxLwh7jm6krd4EQPzPcciOFAFt0fWD1CpQDw1t+8=; b=2U3fxWzE/V08x1W0n9T6yg7r4jAQ6p1qssB+OaNRXaN5hEJJ1AtY8qNgxQ8mth7+zp 3uCvHcij+6UtgyCawas6kjevNPg/3VLSsaZb8DDSzhDTIv9Cgbf6ZvaM8axgRx95GwQ7 6Ti7F2WcvCUXbeQDc3mSb9BmPLNf5X5cRqOLIb1Qwa+83y51I4DRQzQNYrdcIiMKaL+S z+yvY/h/DKiHwBNvE1it7XFc5m1VWBz2j6e3gk1sU0pX70wJtKrYdj5cXijpzxkvDOF/ ENJ0vbXLj+beIWTeqMzIB+36IpJLvJkTzgdYOSEE4D3NIia68OYeRMI70e9O+kSUI+Xh R2Xg== X-Gm-Message-State: AO0yUKUh3UFOZJv3mSoZV0fZY2JA/jyK3NFHrMJ+B/IgyPx+EfG9cdkn /eiPEsb7iRCbF4NvXFId1ua2m9wl84b1 X-Google-Smtp-Source: AK7set/8zwjdXupmXxmE3nxBHcDXM+9r4moQ67xxfCC3ARU9uYuzrlHsQS14Uo2BYtJ6Y5jtB3/pbR3UBgqM X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a0d:fb43:0:b0:506:5a29:80ce with SMTP id l64-20020a0dfb43000000b005065a2980cemr1081160ywf.254.1674776321949; Thu, 26 Jan 2023 15:38:41 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:44 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-15-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 14/15] tools build: Add test echo-cmd From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153845_144015_B096B316 X-CRM114-Status: GOOD ( 10.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add quiet_cmd_test so that: $(Q)$(call echo-cmd,test) will print: TEST This is useful for executing compile-time tests similar to what happens for fortify tests in the kernel's lib directory. --- tools/build/Makefile.build | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build index 715092fc6a23..89430338a3d9 100644 --- a/tools/build/Makefile.build +++ b/tools/build/Makefile.build @@ -53,6 +53,7 @@ build-file := $(dir)/Build quiet_cmd_flex = FLEX $@ quiet_cmd_bison = BISON $@ +quiet_cmd_test = TEST $@ # Create directory unless it exists quiet_cmd_mkdir = MKDIR $(dir $@) From patchwork Thu Jan 26 23:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13117923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A30DCC61D97 for ; Thu, 26 Jan 2023 23:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/SsF2ie75DHb1sQeK8QwywhPJR6qNLzpBc0yP2RbpUc=; b=fKL/8U+MuSV8x8h9F0RobYOZq1 IJwbMtJS2+bMPsZU7CbYgaTgl0mTMCKnoAdj0y+REDV7eIjLbQCcN0yrHRnX3z2ZGGpe54/Th7fDx uv8Ln6upe+S7inAQQu8UscWv/uf4owwGdDygBxs6bQfvIPkE7sp/7vCJUdLJUU0CpD3HFDdFGO2xx lVy+rU7s95CjwiuBwTsOWyjb7tHq6ecqje+gN1ZboDCAa+S3IEcmM5Z5QOLoZCQgKMZTSFs7v+YCs NX8eFn1Jpwoy++sP60OgM7mnjZmI9WKehmFoQez4jz/A1SXlh2MlgF3mnnU4yrikcS1JOZxZSeFZz CTJrNfUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBuq-00CnqN-Js; Thu, 26 Jan 2023 23:44:25 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLBpT-00ClWY-DF for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 23:38:53 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4c8e781bc0aso37743407b3.22 for ; Thu, 26 Jan 2023 15:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8yQHRXERZFizphhJ63mW6mIE9BNCBXqYeW1Mn7KMwfU=; b=Y/sQCucBClKQsTlXfwP8ONsiTL9RBPVsVmQF37414RJnG7UMV4/CLL3uZgMmJMXlNI bmcqCC6rD4WN3YgsoeoeLzw8JmATIoAQDNMUufDoROLYDCNnC2CJ6kutrZrVTpofZUPb Rtvndbylyci2/1G8lrvGJRIbW/Oh8eZ3fFBgdOrVGger8kG8DIrc0JHOj9P1vAjFUywa seo641oGr/QFHGj4MNa0LJYVvArR5kd8jFfji8UmGXmYyDiBIXi7XL8HXfoJyISEJOr4 7vkN1CEc6H95EKbtasAdsf/amK+ceYtHrq6/lI0J4iqtFjcBun8/pqQviQk6V/ay37zd YebQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc: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=8yQHRXERZFizphhJ63mW6mIE9BNCBXqYeW1Mn7KMwfU=; b=NirmVGVTYT7tafmnu6hGuz/cMxN1U8L2xqWA2rh5R+DwMUtlhLvayOpFxPsRbsQBFD HfrTCQJ5VAzxzHguPF8yRottp6EsoQ7jDDJ2kOdbkZxDR6sh/lF9ECj/EwiSENHi1QW9 cQWQG1dtnBY07y6GgWsF5DHgPCSGqChxGC0nTQAeJkyvPXPd6swTHk08+4wlfRmxtJp9 0dPOg+DrTHfkdazpBCc4UzvJ8X++5ICOOir5TzJo34OKeJP0b1SU0mTrbVwg9rnRcfAC Zg090iGGCsUXmbHWkzZhKtSaPMd7Yydt060yL0YJ60+FWfb6Yp3ZPBqK8k+ZEJHbxKg5 OwKw== X-Gm-Message-State: AFqh2krBmWfd4Ud85yMP7lpvYzUjECVP1DWF9tCWoAxtb9KqQFrv41b0 Rqw5+qXF6quOhZ6gLqG+7ghjs+wz6dqk X-Google-Smtp-Source: AMrXdXvjSOd1GSGigNKbLZhLK5pRh1N/XxjXT7JcXzHRlezRc4DR2tD5b4t3IXtvKemh8xSO34tQlBHylaTn X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b9b8:6de0:39b3:4cf7]) (user=irogers job=sendgmr) by 2002:a25:24c4:0:b0:803:197f:3f41 with SMTP id k187-20020a2524c4000000b00803197f3f41mr2749703ybk.489.1674776330013; Thu, 26 Jan 2023 15:38:50 -0800 (PST) Date: Thu, 26 Jan 2023 15:36:45 -0800 In-Reply-To: <20230126233645.200509-1-irogers@google.com> Message-Id: <20230126233645.200509-16-irogers@google.com> Mime-Version: 1.0 References: <20230126233645.200509-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v5 15/15] perf jevents: Run metric_test.py at compile-time From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230126_153851_978079_2C40332E X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a target that generates a log file for running metric_test.py and make this a dependency on generating pmu-events.c. The log output is displayed if the test fails like (the test was modified to make it fail): ``` TEST /tmp/perf/pmu-events/metric_test.log F...... ====================================================================== FAIL: test_Brackets (__main__.TestMetricExpressions) ---------------------------------------------------------------------- Traceback (most recent call last): File "tools/perf/pmu-events/metric_test.py", line 33, in test_Brackets self.assertEqual((a * b + c).ToPerfJson(), 'a * b + d') AssertionError: 'a * b + c' != 'a * b + d' - a * b + c ? ^ + a * b + d ? ^ ---------------------------------------------------------------------- Ran 7 tests in 0.004s FAILED (failures=1) make[3]: *** [pmu-events/Build:32: /tmp/perf/pmu-events/metric_test.log] Error 1 ``` However, normal execution will just show the TEST line. This is roughly modeled on fortify testing in the kernel lib directory. Modify metric_test.py so that it is executable. This is necessary when PYTHON isn't specified in the build, the normal case. Use variables to make the paths to files clearer and more consistent. --- tools/perf/pmu-events/Build | 13 +++++++++++-- tools/perf/pmu-events/metric_test.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) mode change 100644 => 100755 tools/perf/pmu-events/metric_test.py diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index a14de24ecb69..150765f2baee 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -6,6 +6,11 @@ JDIR_TEST = pmu-events/arch/test JSON_TEST = $(shell [ -d $(JDIR_TEST) ] && \ find $(JDIR_TEST) -name '*.json') JEVENTS_PY = pmu-events/jevents.py +METRIC_PY = pmu-events/metric.py +METRIC_TEST_PY = pmu-events/metric_test.py +EMPTY_PMU_EVENTS_C = pmu-events/empty-pmu-events.c +PMU_EVENTS_C = $(OUTPUT)pmu-events/pmu-events.c +METRIC_TEST_LOG = $(OUTPUT)pmu-events/metric_test.log ifeq ($(JEVENTS_ARCH),) JEVENTS_ARCH=$(SRCARCH) @@ -18,11 +23,15 @@ JEVENTS_MODEL ?= all # ifeq ($(NO_JEVENTS),1) -$(OUTPUT)pmu-events/pmu-events.c: pmu-events/empty-pmu-events.c +$(PMU_EVENTS_C): $(EMPTY_PMU_EVENTS_C) $(call rule_mkdir) $(Q)$(call echo-cmd,gen)cp $< $@ else -$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS_PY) pmu-events/metric.py +$(METRIC_TEST_LOG): $(METRIC_TEST_PY) $(METRIC_PY) + $(call rule_mkdir) + $(Q)$(call echo-cmd,test)$(PYTHON) $< 2> $@ || (cat $@ && false) + +$(PMU_EVENTS_C): $(JSON) $(JSON_TEST) $(JEVENTS_PY) $(METRIC_PY) $(METRIC_TEST_LOG) $(call rule_mkdir) $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) $(JEVENTS_MODEL) pmu-events/arch $@ endif diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py old mode 100644 new mode 100755 index e4c792428277..40a3c7d8b2bc --- a/tools/perf/pmu-events/metric_test.py +++ b/tools/perf/pmu-events/metric_test.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) import unittest from metric import Constant