From patchwork Wed Dec 21 22:34:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13079206 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 5076CC4332F for ; Wed, 21 Dec 2022 22:36: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=TZGQJHxGDoLHHVl+rd7/Y/fVJB+Oo4iVS+4L9plsLM4=; b=zCUWLl3VaYIEdWNrUI5OALhUSB GxWSL0vKgYHnK6ZBcO9xfAwVf675nCmTs2p98ULvZN/Hn+L+Qw2gHPHm3YtJQAhmEYHjgthKCJ55A F31qUDCawmi6fhxD9XpDrnYg4Rv0GSlwim9evgoB7rATxtaDDI0VRhvqJOLcjEddTP/vvVTSq7aaf va+JSLEbbS5Kf+N4POqdvZ3YJNt/4PJ3ZTNmO0WzA+4E3S5K4Wpa0GehgqETgrv2nmMVdIAbBiJkI LoZCdhfXE6tK7gm9sX5d2USKViUem1uAzAcKQdwNYm7PFqGRluk2AXJC7FyX0futiat6yJf02sJYj grKiRaAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p87gQ-0039Pr-7y; Wed, 21 Dec 2022 22:35:30 +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 1p87fr-00397U-U1 for linux-arm-kernel@lists.infradead.org; Wed, 21 Dec 2022 22:34:57 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id a4-20020a5b0004000000b006fdc6aaec4fso19284309ybp.20 for ; Wed, 21 Dec 2022 14:34:51 -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=p6Ltg4f6uWL2k+LZiF466krcgS3aBizbqVelMESPLmU=; b=KLo5zAINtEhTy5AFiXvYhnTWFonz2gHXklS2cIgblZMzDqBGkvD/GjAhIbm8nbedAP G43TLqjfZ6HYOq6kQ3M6MlobEyHfYtBTwzBDWRY/dm++ym7mS1yUHPofAqRwrn2R9QTg ZUN2Z4vunBRPE/O73l2AeZy+wuvJR97b1giojICmxup/IQgwWU+JA9ojKBP2fkomqql7 ScZmQ7bSmFvruZvR4ImWtFGVRKLnQvkCks8Yq4MAzbAYZrWkjagLKSOjUwM0JrgKJDd6 x8JqtGCGq7mXrCezWgcnTJlXlDVc4lMkKIq32ZgeQ7x4oKx+RdEHJsX3QoiCzLZLgNCa iyYQ== 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=p6Ltg4f6uWL2k+LZiF466krcgS3aBizbqVelMESPLmU=; b=BmWIwEhNeYqTGHjBaZGw81/cRxupE2f0PbawqPaiICQE2h9XrUG0wiLoHbnyb9Etd2 RuzBlQJIi+F29T7uBZtTl/0waqKrqy+PI6PH2hGG60IQqzpJTk3dPhPjkvowc2Oe6ddB AddEdGJkYvp9oT1cSUpioyRFZLLJ42n/GRHZa+mdDy2lbbcKi1IRaQRxgsOIFK6xzoOU qFPZHzbBRhNjM3DHemBE5bgiGqyZZBWcbfD27F1PeayiWvTmITmEn9bGQo49SXjnwTzQ yhSGY18uiLue/G64JBinz7S3IZ582skX/inRk+16OtWLqfckYieZ7YaieRhp50c42TJj unQA== X-Gm-Message-State: AFqh2krlaN989fiFMM30Yz/93D+UoYreCCOuEU52euCxwpDsCLSySsbp nJ3RcJEh8NdxHfPZOlzGxmLXoySZWjUj X-Google-Smtp-Source: AMrXdXsci0AMSF8Hr2DpdojcQrgVMbQ5l9lfm2lHEIIViWRShp+iXq7vcYMkxVW6Y3EwFrGoDRp5Su0CP7t4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:62bd:f120:1fd8:1d21]) (user=irogers job=sendgmr) by 2002:a81:b642:0:b0:373:6e8a:e7db with SMTP id h2-20020a81b642000000b003736e8ae7dbmr317784ywk.144.1671662090799; Wed, 21 Dec 2022 14:34:50 -0800 (PST) Date: Wed, 21 Dec 2022 14:34:14 -0800 In-Reply-To: <20221221223420.2157113-1-irogers@google.com> Message-Id: <20221221223420.2157113-4-irogers@google.com> Mime-Version: 1.0 References: <20221221223420.2157113-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v2 3/9] 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-20221221_143456_012114_378E9AE9 X-CRM114-Status: GOOD ( 13.37 ) 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. Signed-off-by: Ian Rogers --- 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 4c398e0eeb2f..229402565425 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."""