From patchwork Tue Dec 13 05:00:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 1715209 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=omQOjH/u; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NWRHh38v4z23pD for ; Tue, 13 Dec 2022 16:04:32 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NWRHh2Gssz3bhD for ; Tue, 13 Dec 2022 16:04:32 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=omQOjH/u; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--irogers.bounces.google.com (client-ip=2607:f8b0:4864:20::b4a; helo=mail-yb1-xb4a.google.com; envelope-from=3oweyywckdmw096yw9ay66y3w.u64305cf77u-vwd30aba.6h3sta.69y@flex--irogers.bounces.google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=omQOjH/u; dkim-atps=neutral Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NWRDY70m4z3bhY for ; Tue, 13 Dec 2022 16:01:49 +1100 (AEDT) Received: by mail-yb1-xb4a.google.com with SMTP id s6-20020a259006000000b00706c8bfd130so15463325ybl.11 for ; Mon, 12 Dec 2022 21:01:49 -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=/yu0KB4t7W5Xd9zmAyi2lGA9bjdxvCQ3UbAdr4QNgMY=; b=omQOjH/uMzQeAufRIrLE+kRo3ideghY40BKbwOZwFmudyu4uFE7auJtDweQ0mgBWBC Xe/ehOcpjuhrS8AnJNOFTXsn88ZjN2rxZ1t+wf1Sje7s60Z8rKlaPlGa65gqJyKyObec uaXybn0CaXL3zIdsOqEmqzRxfpSoNL4IRVhrkBEje3myCz/7e2IlWdz3F7kxnqg3iX0K a06iF6z0wPrCA15a9+OOX7ZloPFLa4zvD0XIQbLiMoC4dAqlJl5wj3k1NIpmp9X2CPqd BwqYepF5WXs+Q8tjTZWuR3DB4w9r3XPBqibOZPe8Mfj2HRajmijaCcPhBOEmYfP/J8K9 vqhQ== 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=/yu0KB4t7W5Xd9zmAyi2lGA9bjdxvCQ3UbAdr4QNgMY=; b=qPqgU8tbm5jb9aucQdCyUhwNOQUZVnnj+FRxdEAboK9kABYSIGFFP/eNI/+PkUIQ1S RTS+5XW02T6tRixkVjx3qngR+LzUbBHN2YBdA20EPmQKnKBw/TEoORJiHsOFfZMO7jH8 tyfkwxaEH2M+jqcVMClvR07oa8bpzkx40Ts+gcc/HA3RVmHD3PUJpj/hIXLeaNrZ/JcT 7AFjFFGomjO16gW1krwmytF/UnpjHP0d+VDC/ByZG6IyEnxYI13/Xpv/9gwyIZHrxoMV r0Dxt6RyqKQvK326FFqTUDbdyJJxDDnspzAEqTIBd8etjzaEiWAlLM0Up9S52mPul4pj gXJA== X-Gm-Message-State: ANoB5pkRAt0cpkI/o6sdfAwG/UbgyBBEKt05qmTXkQuLcXgs0/lU7XbV Rleq/auOBteuUrC8415Nql5rPcFFHa4R X-Google-Smtp-Source: AA0mqf6LMHxkSd1PpCxd+RlFoILbgtvWw1wyzKsAapYJZvZE1Kj8RskNcjPo93idzf1GhYNyS3ZVHXsus8j4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:6b9f:864c:28da:e99b]) (user=irogers job=sendgmr) by 2002:a81:b807:0:b0:3b3:3f1d:8623 with SMTP id v7-20020a81b807000000b003b33f1d8623mr1908277ywe.96.1670907707153; Mon, 12 Dec 2022 21:01:47 -0800 (PST) Date: Mon, 12 Dec 2022 21:00:37 -0800 In-Reply-To: <20221213050043.1199380-1-irogers@google.com> Message-Id: <20221213050043.1199380-4-irogers@google.com> Mime-Version: 1.0 References: <20221213050043.1199380-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Subject: [PATCH v1 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 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Rogers , Perry Taylor , Caleb Biggers , Stephane Eranian Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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."""