From patchwork Thu Jan 26 01:18: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: 13116483 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 CF26AC27C76 for ; Thu, 26 Jan 2023 01:20:54 +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=Su5bzzoIWD2ikbZBm/jgw9rq6d6vm14C1glohnU+nl8=; b=ZU11MAmMEbQaQvYg6ckjMr8kjm 3WMASMAvgmmT/xfx1mQu2tKdDqoPh7o6QDxvnZwZjbCLllBj8qaP+tlTG59jSKBc60qZ1ACWtGoYd 9yvINLdkKqc6CyqD0+2ec4VR/30T3wqknkSieyu7DPfbxaG7p38MtHt0Ha0wquJ+hd1Anh5j0zefz CG4k22yj3O/jXDvxcNoXzld7Q68qmZBOCyxbt3LajjM5meFUk5WdEUQPT4/yAeRtZFqgYr0o9jeXz LGa5rgxZXWi4jZ2ynQG2wQyQN7ZsiAFPUzhCyT0NXY8nMJhWdu7ztdNFu4V6PL4i0229T/0dwKsNw S2GTkdQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKqva-009JNz-TY; Thu, 26 Jan 2023 01:19:47 +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 1pKqvL-009JDp-F7 for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 01:19:32 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4ff7c6679f2so3843887b3.12 for ; Wed, 25 Jan 2023 17:19:30 -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=WNubpHubQS9oijDNkedGQDFmSM8xq+UbZvj/SDA553c=; b=pgVAJ11gdMFkeQekNhg7CG7ZryLoBS4Ig9z31agnkDHhcFuu1h2UQxELiNMU5/eouW AmDXXHJs33hYQ1Git4k0IBvqj1KGq4W1crRxsSzkXMz4nDinq3C2o9mqZBiSEmHhSbGQ YV6CSMrklfPXAuzDQhCuNxFw8xAEdMRrEB42XBTC2GrZuQUQCUuGDqJv1SrV61u0TuDm atI3pOn21Udq6n5T+hDG/+SA8z3SMnkY9PFKCYOM6YVFPH+lqWH27hp9T3xvj1zpwzxF vkpCOV0nUI6NLe3jLZOfClko+tFd/y+mXGOONM770ARZazBvODooA38YJVFXcxO4qKgF o16Q== 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=WNubpHubQS9oijDNkedGQDFmSM8xq+UbZvj/SDA553c=; b=EmhpPLF5bfQZCfcv8xCtnQkZakmiJaE/muc45w+QyPW5aFn5UNIv0kCwn1ZUwfRzph 5hnZxy/0+K9mwN5OOq0vvqYVeFXcgVdxQeLUNTtCs+z5Qo7fZpWH344MW6fxpXTpHa+L qGtrPxY+10Op29Eyu0C6ZeQ0BObgjh2JA5Iy1ymdPJDQnT35TuYHgKbBrVtBC8FavLx1 Iagn5D22hxYroXrl5+I24Ix6Da1CTqHcE3+lZMZbm3kdgmawdhEoJEyD1+oVgIXSsfaP ddplZJ8FVq3A8XT0/VTntnBCrd7+9rNr8QZM1Q+UQ7g8XlkN30ibLwwm1Y94AA5ezhJg x/Hw== X-Gm-Message-State: AO0yUKUL4XrBV/r2yF63CUm4xqdRlzKA2k7pZGco7ah4YW3UGAYDx/Wm +N2s+CvKYQJPK4YjFWspY+YbXe8MAWOx X-Google-Smtp-Source: AK7set+O3oLnATb/7nfISfjXSs716r/624JlSux3EJyoImU7UQJNO4w7zyM5uiaeIT2G7JdN+7NIe89dmJRI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:568d:4d98:b468:b025]) (user=irogers job=sendgmr) by 2002:a25:e0cd:0:b0:80b:7727:8363 with SMTP id x196-20020a25e0cd000000b0080b77278363mr670452ybg.366.1674695970390; Wed, 25 Jan 2023 17:19:30 -0800 (PST) Date: Wed, 25 Jan 2023 17:18:45 -0800 In-Reply-To: <20230126011854.198243-1-irogers@google.com> Message-Id: <20230126011854.198243-4-irogers@google.com> Mime-Version: 1.0 References: <20230126011854.198243-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v4 03/12] 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-20230125_171931_537909_DC8EDA55 X-CRM114-Status: GOOD ( 13.84 ) 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 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."""