From patchwork Fri Jul 29 07:43:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932092 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 4EFA8C00144 for ; Fri, 29 Jul 2022 07:45:40 +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=g74cUKB0hGDNqhCjyX+qnuS7RSKE8YbfbQTxdqzEDgc=; b=FgFwHgr1/zzqWqg7QPpFJ/+FB4 ruBEJT9CvpcVcSi3sVKQLIuIQa6LP+Fk6OMi4InzxQ8piBTM6k/k1sXY+jZlMI64W2cshls0NNMC3 R+zC8VP/q4Ny5qeGmKvvHSuY/s2Scv9hDkBABOjNaJLEHC2vlN26/kGw7uqSnFTGvqmaisQ8EFmzZ jePkVFXv5xOYiJx8AhNnpvicrJ3QCLi23zxotYt+pmBpL9jAqfU3+D1tWk/je/1Hx8S906Mde7S4V qXTPfrCdK51BosmA0n+9CxdGtOBFkFBzSpv1M/5Q+/DWuNfkgOuOgiimdrEh7/o/DMS0BPD3f7CUV pRrVcF3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfh-002jFT-8A; Fri, 29 Jul 2022 07:44: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 1oHKfI-002iz0-28 for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:09 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id m5-20020a2598c5000000b0066faab590c5so3289289ybo.7 for ; Fri, 29 Jul 2022 00:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gJpUpfYLbWgWjOwgXjGO+9lnopmpvExo4+EzC9HEZTY=; b=dGCDlxqp0N92i8FI8IxZI0RMts2CVs6exeUrA29GDqYZd2sk37RGoacdGjeaGAaPEl veyYOZBOQmOc24vq5FT0+v67NmYoZPupwBcSbyu/TNItgl51jakqAeFTk7FmNHcuwF5s pyIEjbOqMtfjIMC0SNfrA/UQR/Pr/nXMZCMoS2MA3Tz7jvRTZwt4bIihGAMsFxtssia9 seAGqe9IhHByUB8BHUkgIW6PmueRB80GtUkYVRFSbRtaBOL1aiIn8a/sQ1FGp59m7yT7 JqR4pii4eZKYpIEeR1WUkTYi/kra01qzW5F6bRMrxFc4RW5XMmwU+T37ESVmuzmhsVCX WIqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gJpUpfYLbWgWjOwgXjGO+9lnopmpvExo4+EzC9HEZTY=; b=AQB81wfOeWtaUi3nPV14+z0LVh1rXxnCnnac8fkLotll53ugm3wy0PiMA661MSvamb 2p8oBCUpayYo9+qV45ElS2M/ojqWVrRqH5DkT9k53clyJqg9ssLiLn4gvNvRo38vzwuU W+vDdh/jPnByrahnRZBdeo8FA5wY7L2tZ9WDouqCAEH40Ax+fkgeJq9p085XESRtDoN9 c8fuUcyqw1pW8cxw7nmOWZ8xUTPJJPOM3ATDqxOw5Z075sSp9fiX3xKk+TuFN50jJMdT rlWHxw9eYG34U+vkWhCMCf0zPGlfp1M0zP4OsNXogYB0nFUAytwwt2n/7ZCzTKSXna5l i6Tw== X-Gm-Message-State: ACgBeo2Z6Af8V/bjYQENwcBSux+Hgs44v4LZOBfw+MJhTafNu3O2YQpH p/kSEp1Gq7pUp8IUuj7t/5TKVcOfWs0F X-Google-Smtp-Source: AA6agR4xDcMfnB3k6eIsa+YSBZau3gw42uQA+UFZp9uzUXHPo8lYPYIQ1NrBgvJdmk8BPuBm/TWyurtIPhKV X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a05:6902:70c:b0:670:bb85:766e with SMTP id k12-20020a056902070c00b00670bb85766emr1640653ybt.428.1659080644298; Fri, 29 Jul 2022 00:44:04 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:35 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-2-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 01/17] perf jevents: Clean up pytype warnings 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004408_124362_C7B2C58E X-CRM114-Status: GOOD ( 13.57 ) 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 Improve type hints to clean up pytype warnings. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 83e0dcbeac9a..5b72048d50da 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -6,8 +6,7 @@ import csv import json import os import sys -from typing import Callable -from typing import Sequence +from typing import (Callable, Optional, Sequence) # Global command line arguments. _args = None @@ -57,7 +56,7 @@ class JsonEvent: '. '), '.').replace('\n', '\\n').replace( '\"', '\\"').replace('\r', '\\r') - def convert_aggr_mode(aggr_mode: str) -> str: + def convert_aggr_mode(aggr_mode: str) -> Optional[str]: """Returns the aggr_mode_class enum value associated with the JSON string.""" if not aggr_mode: return None @@ -67,7 +66,7 @@ class JsonEvent: } return aggr_mode_to_enum[aggr_mode] - def lookup_msr(num: str) -> str: + def lookup_msr(num: str) -> Optional[str]: """Converts the msr number, or first in a list to the appropriate event field.""" if not num: return None @@ -79,7 +78,7 @@ class JsonEvent: } return msrmap[int(num.split(',', 1)[0], 0)] - def real_event(name: str, event: str) -> str: + def real_event(name: str, event: str) -> Optional[str]: """Convert well known event names to an event string otherwise use the event argument.""" fixed = { 'inst_retired.any': 'event=0xc0,period=2000003', @@ -95,7 +94,7 @@ class JsonEvent: return fixed[name.lower()] return event - def unit_to_pmu(unit: str) -> str: + def unit_to_pmu(unit: str) -> Optional[str]: """Convert a JSON Unit to Linux PMU name.""" if not unit: return None @@ -154,7 +153,7 @@ class JsonEvent: if self.metric_expr: self.metric_expr = self.metric_expr.replace('\\', '\\\\') arch_std = jd.get('ArchStdEvent') - if precise and self.desc and not '(Precise Event)' in self.desc: + if precise and self.desc and '(Precise Event)' not in self.desc: extra_desc += ' (Must be precise)' if precise == '2' else (' (Precise ' 'event)') event = f'config={llx(configcode)}' if configcode is not None else f'event={llx(eventcode)}' From patchwork Fri Jul 29 07:43:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932095 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 B80BFC00144 for ; Fri, 29 Jul 2022 07:46: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=ugzNQNxjLlAiq63MLqR3Tok1xD+91JH+ky2QV2B9zes=; b=eezWTNG+saZGTtu5Ac22a4QugP 2thk4nwAvyvHllh95JFh9XfZ8E7X8fWbWy1WV5KwltgWqlVXxmkFJK826R5Zbsx11iecG7k4XonSk a1KRBls4efx9G5S3wznyV/cfX7tSAAkbvpUwHoBOD9ESQzYPiiIGVzrX8TDVLre+GV/qLu2byTdeE T5Yo8DN3AsHjJ515x/yA3reVp+Y5uf9pEdrHwe6Pn6QoNrNRhgo7rOMxD3g8T4faNMJN06enJ0CK8 H6bIZ/at8NXbYQIQIv8RY0MabUhhe+eDjmzoIFu2JbgE5GHHGY+TL6cDtDtnFC/gz2SY/8X8Zl8p5 nv/awdUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKgp-002jnH-Us; Fri, 29 Jul 2022 07:45:44 +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 1oHKfM-002j0f-GW for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:14 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f3959ba41so36503927b3.2 for ; Fri, 29 Jul 2022 00:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=envuPbzzq2H54VKr3RstW6kg8N0kUvXDq8KS/IJYJi4=; b=oRwQiy17hOjBg79amu8cXv0HG3YS23fNp9hgX4XS6A3pX3ZvRQVEU3+98y70aFyWbQ 3knxj5i78Ot4CR/NK5LytuHU6ia5SqlDgp4WKLsoyqk2HV3YMNCadVKE0aGhmW9Klgsz WT7Ozg6cYj4AAr5pD4BASrxxeA36XGonvNb4Hq6IA7XLE2uhUtQ3xprXG+MOXXRn+uon wlxC8z6+D640QlNVWRHrAlCeZA0aw3W5TGUUL199sGO8Rg0Ew4PyTFReek2ogfesAZ0f /9zKy6CsSJDOe7vqxxRNl7IBxDDYepJJkVmm77pUlaYFiPC/hDLDPoT5Ub0jRQvocfZg uakA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=envuPbzzq2H54VKr3RstW6kg8N0kUvXDq8KS/IJYJi4=; b=QAk438f0PxEVmz6cxmh5X5lA9XJOf2QcKdEqAJSniHB0hNG9mn4aoaU0suLNjm/01z jJP6mlEeQjlcqpZN6o7QQHhEyHIPQo8qpHUCbftX2VpytsKjogQrqZuEgxoLDDfUxKgN UTAQav9LNaSijVQulZVfA7qzurVJ/o6uFos1LRwp/i6C/1DXkXHlaQ5lnZPXcVxJ8F6a +xC+wdIn3CztZUNrKWJRRVLpWzgrF4ifj3u3LAfSL227bIKfRCf/i5R4cgqgpLbeTRP+ Muw9MXpzqBeKaeqBcoLEO5GKtSuyH60bpTTkak8QmnTdJe4uzD+HPJIPMZolGK6PKM+O 8ysA== X-Gm-Message-State: ACgBeo3S6N6tyUGGctYPGnNLRfHiGNmdOpqR65imtNwqyEZ4qkGDSG8d pK/y6iLVMsC5u5UgSBesGVKiPQ2elL3q X-Google-Smtp-Source: AA6agR4cBEhcuit+eTvxeDSrr/fqU2sZZsNPKXEiBrGn3UWxvMJCZdiwO7Liknsg7sbmU0z0rRHmeY40o8Kh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:c1c6:0:b0:66f:5acc:7fb8 with SMTP id r189-20020a25c1c6000000b0066f5acc7fb8mr1570670ybf.634.1659080647103; Fri, 29 Jul 2022 00:44:07 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:36 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-3-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 02/17] perf jevents: Simplify generation of C-string 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004412_602171_2A6CD625 X-CRM114-Status: GOOD ( 12.43 ) 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 implementation wanted variable order and '(null)' string output to match the C implementation. The '(null)' string output was a quirk/bug and so there is no need to carry it forward. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 5b72048d50da..cdfa4e0e7557 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -203,7 +203,7 @@ class JsonEvent: """Representation of the event as a C struct initializer.""" def attr_string(attr: str, value: str) -> str: - return '\t.%s = \"%s\",\n' % (attr, value) + return f'\t.{attr} = \"{value}\",\n' def str_if_present(self, attr: str) -> str: if not getattr(self, attr): @@ -211,17 +211,11 @@ class JsonEvent: return attr_string(attr, getattr(self, attr)) s = '{\n' - for attr in ['name', 'event']: - s += str_if_present(self, attr) - if self.desc is not None: - s += attr_string('desc', self.desc) - else: - s += attr_string('desc', '(null)') - s += str_if_present(self, 'compat') s += f'\t.topic = "{topic_local}",\n' for attr in [ - 'long_desc', 'pmu', 'unit', 'perpkg', 'aggr_mode', 'metric_expr', - 'metric_name', 'metric_group', 'deprecated', 'metric_constraint' + 'aggr_mode', 'compat', 'deprecated', 'desc', 'event', 'long_desc', + 'metric_constraint', 'metric_expr', 'metric_group', 'metric_name', + 'name', 'perpkg', 'pmu', 'unit' ]: s += str_if_present(self, attr) s += '},\n' From patchwork Fri Jul 29 07:43: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: 12932093 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 9CC45C00144 for ; Fri, 29 Jul 2022 07:46:07 +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=3FvaCu6nwEb5qCUfleDjoEPNZPC4tExYPC3PMilwrE8=; b=CGIBzT6Ui9Jr91pUwPCHmZNRYv hLU1UDR46IO4zAGzuwl8jkEWabuV7U7RY7Ii6EvwIIphOgYs6VGZGU3BoWgPAHS6jmlkuH/zuh2Rh 3jlP7yAWMFGJIGn+ggaBp8TvYRAICRMSlnDlNcQYJqnoAw8rH1QSOK/pi85j80UC72Cq4ea5xE93y 6kiIePATNdHz8xwfWhZ1CunZ7X3JEfnf6QwmPNoS/CBqJjjJjYhEtP0i2HDX2u3Sa+oVRS6GRCvkC mZJ+k0bOgphFvjq0BK2xGGIlYVMVG5xrwr7Ok5f9SXRXMdECWjB5LTwYHggwA2OrvfkxRJQF20r19 FKQD8Gnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKg7-002jSw-P7; Fri, 29 Jul 2022 07:45:00 +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 1oHKfL-002j1l-13 for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:12 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id a11-20020a5b090b000000b00672acbe13c1so3320012ybq.2 for ; Fri, 29 Jul 2022 00:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=n6t/pfc0M41ToUc5HflmTh98LQ2xLoF6/7gvlW5ZK2Q=; b=RmaMHRM7ZCMs2/Sqd/a9cdMCmqaHieNXVHN4Vuvjr+TsV/F8AClPvTIRagoDGDteWP JtTrLV93NxFRO9qxISgnIVfKmNRq7AhrSL9eH75+iyu2fez+WJO0lxUj+jqV/oKCfe3i nuyp1wAIJyjwZvdYgpNF0Ol7SaSvyWX3/OmBZc8xGOSfwNMMDJu83rG8aYZjNa9VjNGX 68nHrV2nLH2zt4bKDZntZlSECtedzjURSUOIwFLvjqkwwAKOEq7Zao1TaGUi05MPmxbF xOeW23WnznBfPNyM8bDBJvTUDbitnImpHaGkGAe9c5bPYLuz2XRTTC+A6k5lQej39y3d o5Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=n6t/pfc0M41ToUc5HflmTh98LQ2xLoF6/7gvlW5ZK2Q=; b=4FdAd36vw8lDzBpzedGeTfC5rfsfgWmWpviWiaiULaowmtzLxVaP/8UDVZmfcKAMtu 05CYY9zU4MUBDC8o4JlEccT1vgZ8K73/vlrDNNNum2AFes3I/LrtUKPvoy+AvJkikmQS Oub8/PzKuP3Kju4HE13nB0jbtYERRCu7FpDqpky3xah96Nm+FdMKb6tuV8djNes4XPDT rC2ZxzqJI4gPDckV8UYzUSHNvqWVJxFXAhKuA55lbT0AaeSSHaDR3Morgy1IIZheap7B nbHvlIAtzjv46RgDLdLsP9qLCnxJkDJT9lFJF7EhtjlGDvCN1NzJ3jywWOptv7ebbVc/ 8cLQ== X-Gm-Message-State: ACgBeo2+xZ4/7PV0UyvXaN1qz7upd3ZP3GtUpZTFuh12Zb6zdkvidHUR YfMYDOJgGHK5UAOX7yfEVFhcz3GJy9Qu X-Google-Smtp-Source: AA6agR74CvzVSNoMfgJMhkgoW3tzfGVsYV/loT9yHflje8Np4KrnICz0V3tzbIuEozNJGPQW5nvajE6RSnDh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:aa2e:0:b0:674:d1f6:4480 with SMTP id s43-20020a25aa2e000000b00674d1f64480mr1535820ybi.591.1659080649673; Fri, 29 Jul 2022 00:44:09 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:37 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-4-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 03/17] perf jevents: Add JEVENTS_ARCH make 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004411_086690_A7678EA1 X-CRM114-Status: GOOD ( 12.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 Allow the architecture built into pmu-events.c to be set on the make command line with JEVENTS_ARCH. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/Build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 28a9d01b08af..04ef95174660 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -7,6 +7,10 @@ JSON_TEST = $(shell [ -d $(JDIR_TEST) ] && \ find $(JDIR_TEST) -name '*.json') JEVENTS_PY = pmu-events/jevents.py +ifeq ($(JEVENTS_ARCH),) +JEVENTS_ARCH=$(SRCARCH) +endif + # # Locate/process JSON files in pmu-events/arch/ # directory and create tables in pmu-events.c. @@ -19,5 +23,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) $(call rule_mkdir) - $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(SRCARCH) pmu-events/arch $@ + $(Q)$(call echo-cmd,gen)$(PYTHON) $(JEVENTS_PY) $(JEVENTS_ARCH) pmu-events/arch $@ endif From patchwork Fri Jul 29 07:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932096 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 EF74FC19F2B for ; Fri, 29 Jul 2022 07:47: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=n4S8U1wM8ERH9La/MgaZrwYw258dmTxh4ijcbVFYgfA=; b=HgeOrR8RfEindrX4hpM6gcoRDD i+F/qOoh6uG20ArBB+zopY/QZc2LNCtzVRdJWNXukW2YJ3MiwJWRTJO1QAVNy1y6EqAQu+cINKNoH IzjtgUYMRkzDpDD4CwMSqaeFRyzKvYLB+iKz3eHawF+CfAoyxMrrwMVQKyZpGcBRW+EBYxNqTSqVN c0IoPJuuaRY6vFl0olOt/6M1xcyk8ibwZQiSgG6Mq3a7/q4y775s6CQ29pZbMtd/Ztvm1esWsomTh Y5v4YJ6GDtArGV6C7vZARRnf8Gz9Awl/6AxjsHLwxpzkCXmUDlMeOmMC5GJpMOlVZgN2f9a/rbDwp hsk5nZ2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKh8-002jvo-Fk; Fri, 29 Jul 2022 07:46:02 +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 1oHKfN-002j3D-Gh for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:15 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id f3-20020a5b0d43000000b00671194e39abso3314393ybr.4 for ; Fri, 29 Jul 2022 00:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=EjcW2819bK3ME3rSbBlXh7xG57ULhBVjyEq6SCnJgHs=; b=Q+jaj+dVmVWsljBSPYTpmdqOXVicg9AGaWh1ve7iGaro2yUiFb9EbEpzlHcUumAh+I birhsTaWS7VUc7Ai6egLJUB6iZ9Y8q7Gw/NOCuivCXrSPl1guInU8wHgfLMyGyRcpJOU jiomfTWcm8zrpnK7X91SWa2YQa4i4XnHrXT4245hwxHM00pdOsQW+5RrBkEj02Os8EMS 9ylCnAe2AzstfykP8LDN7qEGUb0Ir3430t2OU3y4nRGWOGq2mpK3G+p6AiPzKGTwlkSX cTdC1uG/nZ8rsBIG4s+DFbJMETYZ3xw7GQME93y0np2DMlSDFmpD890446EhAweaY4Ce NNJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EjcW2819bK3ME3rSbBlXh7xG57ULhBVjyEq6SCnJgHs=; b=MNr2bu14TKmsLRwXjM6pZ5S6gcIij5i3CuIBNTdxC0vTo3eBUVTY9xphrx1I7vJgvu IeJ0R0m+aL1jHrUbdsmUtLw0qwMHo0VllSH11KSgfLz8N0gbbLWArKuFI1Tt7I1ckWDX gkqNQbAhza304z0rrB+jE6ZmwdbDgdRFzLHwsbdGicyZ8WASwVlgrunmZClFexZzlDL4 QXO5InKdoSL8P8dpiz9tOCZuxdr9QhZq+n448llKfIr3wdW7FuRclICyiPTZsC7OvtjS WuU+aBzVrkHoPCvxlZHtwWwFVAk0G5jS9exHxZDRbr7693KpfQmVUM7eZzU+LxP67eex VJ6w== X-Gm-Message-State: ACgBeo1IPrIZop+4mis8Z4Wtt8AGLLrgWUyfoM/NARAJSaOX7Uz6VJqw owPNH5YCtYi8lqKLOFwDesu03zv2x5pu X-Google-Smtp-Source: AA6agR7FJFm/zePAwFdaLuEQB8H/PqGRX8IU3YjwZixunkmchzQY1GHOYMRcP36hjVCwrEMBWBNzE4eKg1XC X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:19d5:0:b0:670:7c04:8593 with SMTP id 204-20020a2519d5000000b006707c048593mr1551592ybz.95.1659080652160; Fri, 29 Jul 2022 00:44:12 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:38 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-5-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 04/17] perf jevent: Add an 'all' architecture argument 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004413_593955_6F7E9360 X-CRM114-Status: GOOD ( 18.66 ) 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 When 'all' is passed as the architecture generate a mapping table for all architectures. This simplifies testing. To identify the table for an architecture add an arch variable to the pmu_events_map. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 70 ++++++++++++++++++------------ tools/perf/pmu-events/pmu-events.h | 1 + tools/perf/tests/pmu-events.c | 3 +- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index cdfa4e0e7557..e6e6c42c3f8a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -304,38 +304,45 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: print_events_table_entries(item, get_topic(item.name)) -def print_mapping_table() -> None: +def print_mapping_table(archs: Sequence[str]) -> None: """Read the mapfile and generate the struct from cpuid string to event table.""" - with open(f'{_args.starting_dir}/{_args.arch}/mapfile.csv') as csvfile: - table = csv.reader(csvfile) - _args.output_file.write( - 'const struct pmu_events_map pmu_events_map[] = {\n') - first = True - 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('/', '_')) - _args.output_file.write("""{ -\t.cpuid = \"%s\", -\t.version = \"%s\", -\t.type = \"%s\", -\t.table = %s -}, -""" % (row[0].replace('\\', '\\\\'), row[1], row[3], tblname)) - first = False - - _args.output_file.write("""{ + _args.output_file.write('const struct pmu_events_map pmu_events_map[] = {\n') + for arch in archs: + if arch == 'test': + _args.output_file.write("""{ +\t.arch = "testarch", \t.cpuid = "testcpu", \t.version = "v1", \t.type = "core", \t.table = pme_test_soc_cpu, }, -{ +""") + else: + with open(f'{_args.starting_dir}/{arch}/mapfile.csv') as csvfile: + table = csv.reader(csvfile) + first = True + 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('/', '_')) + cpuid = row[0].replace('\\', '\\\\') + _args.output_file.write(f"""{{ +\t.arch = "{arch}", +\t.cpuid = "{cpuid}", +\t.version = "{row[1]}", +\t.type = "{row[3]}", +\t.table = {tblname} +}}, +""") + first = False + + _args.output_file.write("""{ +\t.arch = 0, \t.cpuid = 0, \t.version = 0, \t.type = 0, \t.table = 0, -}, +} }; """) @@ -386,15 +393,24 @@ def main() -> None: _args = ap.parse_args() _args.output_file.write("#include \"pmu-events/pmu-events.h\"\n") - for path in [_args.arch, 'test']: - arch_path = f'{_args.starting_dir}/{path}' - if not os.path.isdir(arch_path): - raise IOError(f'Missing architecture directory in \'{arch_path}\'') + archs = [] + for item in os.scandir(_args.starting_dir): + if not item.is_dir(): + continue + if item.name == _args.arch or _args.arch == 'all' or item.name == 'test': + archs.append(item.name) + + if len(archs) < 2: + raise IOError(f'Missing architecture directory \'{_args.arch}\'') + + archs.sort() + for arch in archs: + arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) ftw(arch_path, [], process_one_file) print_events_table_suffix() - print_mapping_table() + print_mapping_table(archs) print_system_mapping_table() diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 6efe73976440..7a360792635f 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -38,6 +38,7 @@ struct pmu_event { * The cpuid can contain any character other than the comma. */ struct pmu_events_map { + const char *arch; const char *cpuid; const char *version; const char *type; /* core, uncore etc */ diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 263cbb67c861..82192f1a7bf7 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -864,8 +864,7 @@ static void expr_failure(const char *msg, const struct pmu_events_map *map, const struct pmu_event *pe) { - pr_debug("%s for map %s %s %s\n", - msg, map->cpuid, map->version, map->type); + pr_debug("%s for map %s %s\n", msg, map->arch, map->cpuid); pr_debug("On metric %s\n", pe->metric_name); pr_debug("On expression %s\n", pe->metric_expr); } From patchwork Fri Jul 29 07:43:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932097 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 F0BDBC00144 for ; Fri, 29 Jul 2022 07:47:23 +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=QoXYk/gTmUmihtj1wP9/4vXCIiHMIkylJXGUZezz7YM=; b=rvK7YN389uPvTobwGmznLaTj0N RWfkCl6pp8fsJxIr2UOqFjvztI1OQXYbov3hLc96iU9Dbh0kczILGdJBMnuOBCmeLR/RB3xAg0uVK Ex2DVrEnh9aAojzxcpgIB6fCYZE+yV6a9xzbapY0zqF8OfrF0Vl0JXhuRkCNGfpdxogBQjWRRqxtV +E5qeaiEdb2YxKWrb/ZyImRqaa3pWODCA3NehyCZ6/zlnogL6teJc6X6X8YallEAMoiA1Uewte0vO LvEPF43TnRPP6px58FkebOQlCn8Guay9PTL89LA8xfXEwwLfCz/hEbbnqWPEOEhKPEwoBh9KuIHKS hLWriBvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKhT-002k5I-Qf; Fri, 29 Jul 2022 07:46:24 +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 1oHKfQ-002j4n-Bk for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:17 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s14-20020a5b044e000000b00672caf96368so3305784ybp.21 for ; Fri, 29 Jul 2022 00:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0p5UtNhgly+OTzkIJIIsc2EA2UcuBV0UctPUvpqsf3w=; b=m8bPlFQpgLYJUbB+UeU3eNFKTszNzcYKPY4sMWEB4i8lPeEdHF1ko8hWyRi7g6lflv +OsMGJFc6EY6Oy2kIuGOxIFqAaorn1NeHpngcC6WNYuMY22GpCAK+IRSYroXU0SP3sLG VKp0QcUBs8jzqjp/66l8mYymCba/9iFJmqatIxgyuwIc6GMe2mhND79XxhWDZ8PT5/mq pawV8GV2vnCV7YY6jaXHOG3hjx6Q3jPSrjZRuxZCmmrwEzZ9i2l+CbXRkN5aVDeR5/PO flR+ilwXLJDqxXYCf1af4n+QE4YDuze779KGRZtKigtjGnhg3othnTFwB5P40oXX53Fn 22kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0p5UtNhgly+OTzkIJIIsc2EA2UcuBV0UctPUvpqsf3w=; b=nj0QwY1yxTyyWPf7UwYVibpI7EBenp7IOKXA0TRDqa5+hMrrOCvwjpWXGgCqNzyS30 WZdLBOhnboXsp9v9I/gJlIiWGo+O+N7rCVcvaTdF12A4p6/bs0O/Q6DMynizeJRM8WAV fiezkFGKDh1VQb0080M+frFq88yBzhIdN0G4X+eM4QtugXvryskK+okan92o+z/C2/IU 9AIYC8lI02jprx1ZYKYPEE1yRUqddpw8R0EeqZCBMSMbagVrUYxnNmenekl+oeKdWxwA P846Sxu4Uv/LLwgX3lChtrOjKdcbNlfsqQ1ZkZixHt+UFK6kISrQlq7f0BIj8MDZDjFz lyrg== X-Gm-Message-State: ACgBeo3qiJhdNPj1Ct7QRRTM4kn8QCxRS2tSCCy+iIJ3NdhOoiOpaoWT dF2YG4lkP9zZXkRmMyt0nG3giMlsYIZb X-Google-Smtp-Source: AA6agR5UupBuBpyx9U7oV6Zn/0T9hjA3Obc+2V2iQvV2q7Rr0iTRvbk9/ckSXIRERBkQ06cuJvrB/n2XF+Of X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a05:6902:ce:b0:670:82dd:d174 with SMTP id i14-20020a05690200ce00b0067082ddd174mr1627428ybs.76.1659080654685; Fri, 29 Jul 2022 00:44:14 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:39 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-6-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 05/17] perf jevents: Remove the type/version 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004416_460227_841E1590 X-CRM114-Status: GOOD ( 17.32 ) 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 pmu_events_map has a type variable that is always initialized to "core" and a version variable that is never read. Remove these from the API as it is straightforward to add them back when necessary. Signed-off-by: Ian Rogers Reviewed-by: John Garry --- tools/perf/pmu-events/empty-pmu-events.c | 6 ++---- tools/perf/pmu-events/jevents.py | 6 ------ tools/perf/pmu-events/pmu-events.h | 2 -- tools/perf/tests/expand-cgroup.c | 2 -- tools/perf/tests/parse-metric.c | 2 -- 5 files changed, 2 insertions(+), 16 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 77e655c6f116..4182a986f505 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -110,15 +110,13 @@ static const struct pmu_event pme_test_soc_cpu[] = { const struct pmu_events_map pmu_events_map[] = { { + .arch = "testarch", .cpuid = "testcpu", - .version = "v1", - .type = "core", .table = pme_test_soc_cpu, }, { + .arch = 0, .cpuid = 0, - .version = 0, - .type = 0, .table = 0, }, }; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index e6e6c42c3f8a..98d18d5c3830 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -312,8 +312,6 @@ def print_mapping_table(archs: Sequence[str]) -> None: _args.output_file.write("""{ \t.arch = "testarch", \t.cpuid = "testcpu", -\t.version = "v1", -\t.type = "core", \t.table = pme_test_soc_cpu, }, """) @@ -329,8 +327,6 @@ def print_mapping_table(archs: Sequence[str]) -> None: _args.output_file.write(f"""{{ \t.arch = "{arch}", \t.cpuid = "{cpuid}", -\t.version = "{row[1]}", -\t.type = "{row[3]}", \t.table = {tblname} }}, """) @@ -339,8 +335,6 @@ def print_mapping_table(archs: Sequence[str]) -> None: _args.output_file.write("""{ \t.arch = 0, \t.cpuid = 0, -\t.version = 0, -\t.type = 0, \t.table = 0, } }; diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 7a360792635f..a491b117c8ac 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -40,8 +40,6 @@ struct pmu_event { struct pmu_events_map { const char *arch; const char *cpuid; - const char *version; - const char *type; /* core, uncore etc */ const struct pmu_event *table; }; diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index dfefe5b60eb2..dc4038f997d7 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -197,8 +197,6 @@ static int expand_metric_events(void) }; const struct pmu_events_map ev_map = { .cpuid = "test", - .version = "1", - .type = "core", .table = pme_test, }; diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 07b6f4ec024f..1b811a26f4ee 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -81,8 +81,6 @@ static struct pmu_event pme_test[] = { static const struct pmu_events_map map = { .cpuid = "test", - .version = "1", - .type = "core", .table = pme_test, }; From patchwork Fri Jul 29 07:43:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932098 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 8A659C00144 for ; Fri, 29 Jul 2022 07:47:45 +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=MIuAbGQZj+6t3uK/MuSnecQjZeGz0OH2lHmMeiARPaM=; b=dFheA/i0rGslFePYhmuqvZLlhY mmdYte788q84WPiz9kqTLcAz+l4qQgjOCl9ukaKrgO8CRcr4SsvZ4ZzXtru72you07cGig8NObqfW R11+1F4I4dkLVbqNBbXTI4+Vh+FFS3HlXQcirgT/wctVhhEiH6p7Jorr/WuxVicFVOIDji1IKAs4W 543mQBsmChoby/3xIGexWtJ1X8CxnpXM2c7/KVlr0tiPBLS00W9tgN2i2ul3RxPdmqtRMTn4mbd+o RGVfme9mAK5yzgB243UrHBJhAV1iEMlTScvM9dCRnnD8mHIHp0HTv1DmSH6S3Hh4geIWxSOdHvJoz A1L9GEIA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKhi-002kCI-NX; Fri, 29 Jul 2022 07:46:38 +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 1oHKfS-002j6s-O1 for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:20 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id u6-20020a25b7c6000000b00670862c5b16so3303740ybj.12 for ; Fri, 29 Jul 2022 00:44:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=mqNHYsVWGj0fcO4+XKl+I9RLjcmp/sKEanarsLP2wxg=; b=RJcVJE+hnyZrLqpNeLhiP9SbUZi5PF1h2Xz8hG5gfDrto2ZQvRbIcC6+pAXjRuhbXS hxf5W34jXcMzU2CSQeY4iX89QrtXGzGakLrL+jut524o4UiZznud+g/U7dnxxAqrqlQT pzXDXlpBwMSb0l3uxn+/I7DzOr+PXPhV5f2aefc12bYS8AsaCHGNI7SYJli4tevGjywb sjAke3+r/1BZzyPlQMjKvu4ZlUqYoJZIcGX2HFRv2ByMovs9934a832sOvC4E/EY360c Z9KwuNdsFQwBBf5wGlduUlXAcoWQRtqSha80ussn7tI3v6pjtpcTMvkdeP2C/mBzt5DT vnJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mqNHYsVWGj0fcO4+XKl+I9RLjcmp/sKEanarsLP2wxg=; b=Yde7dws8ywZ2vGXrEalipAHRwVwGyftt4KV4S6oX0vq1XADXjRJB8dGVe6JOSYGw93 AgN1i4FMshRiurIJLlyK9qs+HBunJO1+eh2ME8TRZhs704RVm98fB5Ie3gCOYSvutIJ8 nCH3kMBZTNsrycVOvnUAsTwVVMrhD/t5RyGqS3/DHfzj+HeSh1y+aW5U+SnU0mO3yE2x OdpN9hQEy6Hlsw1vgwuyCwi03678GS1jD9j62QV2Ek59HOvet8T7aARnYsuK0P2nsgcM wW/Ba2yCKfFSvI9J7AVIjOnMkOJRAoyq98y4zSruZs+t8QFVlwdDA0snAwBZFjti1z1W dCzA== X-Gm-Message-State: ACgBeo2VnVZnmiWbsyNJ6PhgoCBJaQIdFzzF+z8tIcc1BummaZWGU0Z+ RVIFA1gob3Vak6NV9UJCWVDW8Ij70A8l X-Google-Smtp-Source: AA6agR5bkDJ5EE78BgJwxPU+WAXWDt1bh9VDrLedHC8RwnOPxWMaMu2tKQ6y1risxyc6dYbK0QDT6tXW0iKG X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a0d:c602:0:b0:31c:822a:c168 with SMTP id i2-20020a0dc602000000b0031c822ac168mr2198798ywd.134.1659080657058; Fri, 29 Jul 2022 00:44:17 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:40 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-7-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 06/17] perf jevents: Provide path to json file on error 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004418_837028_1E3DD72D X-CRM114-Status: GOOD ( 12.28 ) 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 If a JSONDecoderError or similar is raised then it is useful to know the path. Print this and then raise the exception agan. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 98d18d5c3830..12d2daf3570c 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -224,7 +224,12 @@ class JsonEvent: def read_json_events(path: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" - return json.load(open(path), object_hook=lambda d: JsonEvent(d)) + + try: + return json.load(open(path), object_hook=lambda d: JsonEvent(d)) + except BaseException as err: + print(f"Exception processing {path}") + raise def preprocess_arch_std_files(archpath: str) -> None: From patchwork Fri Jul 29 07:43:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932099 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 F034BC00144 for ; Fri, 29 Jul 2022 07:48:08 +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=vHooxptAB6uZkmRozbzzljgMeRI/SZN7Y9cgu3rsREs=; b=216EQqNKXqbY/XdRHllfubjMPx UPNZWqftzNyy2jMoY66PM3uOa3uf37A3PQDt8EzdCQLVqcuD1RMx2cUWW8wVEyZRrREH4fcDfhBQr i25IwceCPO6lHz+B4Clatfu6hAxgNAQwfi4nxPMwoV2aomW6m8m3Bqrz4RixMlRXV738mOyD4cz9j VZCejZ8vjQYzC0EqdhLla1wixxm91qcshdxhZWJulZTAWoPRNlhGeBQ+yD8PwUREwBh6Hvckaj6sE tGPOQi6H7vACeByqjAots0Mc5jmCBBJF03B/VIdvvb3vx+mGsvBL1/T+L4+GITSo57UEfpVbge347 4BlZq8CQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKhz-002kLy-Sy; Fri, 29 Jul 2022 07:46:56 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfW-002j8A-MK for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:24 +0000 Received: by mail-pg1-x54a.google.com with SMTP id d66-20020a636845000000b0040a88edd9c1so2022129pgc.13 for ; Fri, 29 Jul 2022 00:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3yOwoFZ3Wf3i4mCbDyBSkX0NefzV6upIW3aFDzVLgcY=; b=XWlzqABpM6mfUKHqdgs03Q1OMATyLjTsT+obDuGtUoYQ2Suf2CieHkfRGSuBk1qCQK Z46IBmlwp0snGR8PF6G3rEx+eyM/ooZGwfJW5c9kwfQJu5Nt70RO1H+DIQB6skalORNq bGzIvYaFCAXGHbNgsrUYxVgjSz8OLHmNtmkOoe+6A5YrHwEqFHyi8we11fObjVt6S/C8 6Zg/qKT7coGx4Fp2xCxAN/Odl7C6L6nOkddiN3Xaju1DvmFhrwnqaPxprBUpOdECobUe M3+xJVc0ROzH332G6SyXz+AQhsv9Ulan8vnh/pb3n7tS8CIQ/JGH1gZra1+1IRThykpB cauA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3yOwoFZ3Wf3i4mCbDyBSkX0NefzV6upIW3aFDzVLgcY=; b=aEGhFW9dA9qO2dNSkRWyi09PGxVPk6waHkbx3Eq9ql2RDW6c3NCa7AXI5hzLBxZisZ 060oFQiez195BN1UUYqmhYbQeeHnOKQFFas3VniuuGJVjeRrbs4eoROHyJp0KDG+7hbr rAvHlDPqMEVkfN4dD81Ff7XxP53bbuSqwxl/vJCcSMZx0qqfkiYsEbC4y3h4yAHH0zqT yEMVr+abI2ntyj54mLPaS912gHZE96gJ6apJWSIvTLLvPirQ9/do+eaV5mj5aXhlAZqZ hvvxihRptdpyWpaarAL/vueH4dWA4yT2fUOe2CPeGv2F1oRpF7QcF3RepTu2+0/xlc0L H9JQ== X-Gm-Message-State: ACgBeo3uZsmv3FT9StgUUKgVg0EreJLKWTGpsQ/SlYZMxPL+P5Hvvmbo XSgJeG/FsxZDD8CWoT0fT9T+zcW38svh X-Google-Smtp-Source: AA6agR4X2OdUFG3Qzn8PCM8EFybFzGARwPe8r1WhL3LwDYzR0P8x9tl8f4DrUGUCiSqSNOhjh2ZjnCQFRyF6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a17:90a:94c2:b0:1f3:2590:8693 with SMTP id j2-20020a17090a94c200b001f325908693mr3400234pjw.153.1659080659864; Fri, 29 Jul 2022 00:44:19 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:41 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-8-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 07/17] perf jevents: Sort json files entries 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004422_798405_C2BD3C06 X-CRM114-Status: GOOD ( 16.11 ) 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 Sort the json files entries on conversion to C. The sort order tries to replicated cmp_sevent from pmu.c so that the input there is already sorted except for sysfs events. Add the topic to JsonEvent on reading to simplify. Remove an unnecessary lambda in the json reading. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 48 +++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 12d2daf3570c..30e0e792221a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -18,6 +18,8 @@ _sys_event_tables = [] _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 = [] def removesuffix(s: str, suffix: str) -> str: @@ -127,6 +129,7 @@ class JsonEvent: eventcode |= int(jd['ExtSel']) << 8 configcode = int(jd['ConfigCode'], 0) if 'ConfigCode' in jd else None self.name = jd['EventName'].lower() if 'EventName' in jd else None + self.topic = '' self.compat = jd.get('Compat') self.desc = fixdesc(jd.get('BriefDescription')) self.long_desc = fixdesc(jd.get('PublicDescription')) @@ -199,7 +202,7 @@ class JsonEvent: s += f'\t{attr} = {value},\n' return s + '}' - def to_c_string(self, topic_local: str) -> str: + def to_c_string(self) -> str: """Representation of the event as a C struct initializer.""" def attr_string(attr: str, value: str) -> str: @@ -211,25 +214,27 @@ class JsonEvent: return attr_string(attr, getattr(self, attr)) s = '{\n' - s += f'\t.topic = "{topic_local}",\n' for attr in [ 'aggr_mode', 'compat', 'deprecated', 'desc', 'event', 'long_desc', 'metric_constraint', 'metric_expr', 'metric_group', 'metric_name', - 'name', 'perpkg', 'pmu', 'unit' + 'name', 'perpkg', 'pmu', 'topic', 'unit' ]: s += str_if_present(self, attr) s += '},\n' return s -def read_json_events(path: str) -> Sequence[JsonEvent]: +def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: """Read json events from the specified file.""" try: - return json.load(open(path), object_hook=lambda d: JsonEvent(d)) + result = json.load(open(path), object_hook=JsonEvent) except BaseException as err: print(f"Exception processing {path}") raise + for event in result: + event.topic = topic + return result def preprocess_arch_std_files(archpath: str) -> None: @@ -237,7 +242,7 @@ def preprocess_arch_std_files(archpath: str) -> None: global _arch_std_events for item in os.scandir(archpath): if item.is_file() and item.name.endswith('.json'): - for event in read_json_events(item.path): + for event in read_json_events(item.path, topic=''): if event.name: _arch_std_events[event.name.lower()] = event @@ -251,19 +256,36 @@ def print_events_table_prefix(tblname: str) -> None: _close_table = True -def print_events_table_entries(item: os.DirEntry, topic: str) -> None: - """Create contents of an events table.""" +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 event in read_json_events(item.path): - _args.output_file.write(event.to_c_string(topic)) + for e in read_json_events(item.path, topic): + _pending_events.append(e) def print_events_table_suffix() -> None: """Optionally close events table.""" + + def event_cmp_key(j: JsonEvent): + def fix_none(s: str): + if s is None: + return '' + return s + + return (not j.desc is None, fix_none(j.topic), fix_none(j.name), fix_none(j.pmu), + fix_none(j.metric_name)) + global _close_table - if _close_table: - _args.output_file.write("""{ + if not _close_table: + return + + global _pending_events + for event in sorted(_pending_events, key=event_cmp_key): + _args.output_file.write(event.to_c_string()) + _pending_events = [] + + _args.output_file.write("""{ \t.name = 0, \t.event = 0, \t.desc = 0, @@ -306,7 +328,7 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: if not item.is_file() or not item.name.endswith('.json'): return - print_events_table_entries(item, get_topic(item.name)) + add_events_table_entries(item, get_topic(item.name)) def print_mapping_table(archs: Sequence[str]) -> None: From patchwork Fri Jul 29 07:43:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932100 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 DC13DC19F2B for ; Fri, 29 Jul 2022 07:48:25 +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=5E4ItD8Td2jdojn/rBkUf4boccnlsfv/f8JPr1x3zIk=; b=Ty/nxmxjEvVzkGq2eOoVDzsTPh 6fOvU6DTFBEY7kF3DALuiFuf2AqQLgE/Ta/67sRnqhIssCg9sjSJef5lgwwbp+5nYvXNknUhUwpyL cj35QxTTf29Cxg2w0ZYOYZZiR76VB2zf2huuwCJKbVOAMqeGMDW4KaSGE2DwlN5sdbJ45T1aWJObc EKK9PiJejiVgiSFdTCd2aI+6XL165P2Oq0m0KsaFXFv1r5B+sHNlgtSFB0X8WWUWiya1tBeeNDWWu sRjVeYVzAitXPfi/O7MxAzgZ3UaoYilZb9SM4KIgkUd6YltL9wgNhlKx9EfPDnSQv9rRNbvIWQ4Wr dTs7Ry4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKiM-002kYy-9l; Fri, 29 Jul 2022 07:47:18 +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 1oHKfX-002j93-UV for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:25 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31f46b4759bso36510597b3.0 for ; Fri, 29 Jul 2022 00:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=L9UT7pFKEMv8kmhKTFboeMQHgbNjypzxWtClefHRJXeuk7El88DNhUGL4PqSb2pxBt UUcOzUDVOnbLXDk7ADQF8gwzoy0tFbnIJQoWp00c6r1J4xo8jWshWT4mpOhestPPnV2m 31p0htLfJiSCQ2GcnIhA8XjMPzhJ6UF1OOS72tmsudDUX5X5uOjGU4aDnEPbBzQtFfPR h9/FepigXVjZTiyqlOKgRSaq9TO9PIy2rPBTb5Jiuxn3ceLTiENmnJj2kVS37+Xg+5sN C+JZfVZ4SXaxQMf/IsC0qlPUQKGYUPG8J+i1wpIpv4uwKIjNgz+tD/cTlkJWh3krAyHJ duMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5r7KpXClmZzIJUu6VoWF+PxBHcALGulwqyZkCHJz+dc=; b=hslxldq2tkEvhM14xPtLlRk0XMEUEJ5wwV4D6yVpqDBHmbdzzoZF7SVXOTcygyiFhe CZPsAAnBtORG6kXr/gu8vvgsV15AQFSTQeJWT0SA+sXsic3rEfhLKWeOuhfTa2Q3QUqf 0z2Qy+qhUm3UshGgsGatdvICizAF0f9kwUMqMVdO8da3AY/HfroPy/agxzY26oSrDEG7 QPOiSHq5WUL8Dt05oFhdqLr5XXmep/US2VSG/k8CnFGvsOQTJ72Ga8Ln9ggNf/6eBg2s 6pRXVS5bGGXLCH6ruhVp8uQzX/4YffrbzUskeZe1hrCzN/KXiJNA/5E2C9YIDJxGOPaH kHeQ== X-Gm-Message-State: ACgBeo3yZeNMg5nvsabipBd1f5F8v5Esg/CgEdE8IPDxD6DfRLJQondR mP92v/VFHOf5yWfG7090cH8m4MZPebAB X-Google-Smtp-Source: AA6agR4lvVMHfSoejMkozQjmS9qJTDKTwsU5cAD6r+dvPCEB7yVOfvYBAS7Y09yz2U8G7/kdQP/Wm9mQYGrh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:41d6:0:b0:673:817c:e163 with SMTP id o205-20020a2541d6000000b00673817ce163mr1461338yba.561.1659080662475; Fri, 29 Jul 2022 00:44:22 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:42 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-9-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 08/17] perf pmu-events: Hide pmu_sys_event_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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004424_039183_FC9A29BB X-CRM114-Status: GOOD ( 21.05 ) 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 Move usage of the table to pmu-events.c so it may be hidden. By abstracting the table the implementation can later be changed. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 37 ++++++++++++++++++- tools/perf/pmu-events/jevents.py | 45 ++++++++++++++++++++++-- tools/perf/pmu-events/pmu-events.h | 11 +++--- tools/perf/tests/pmu-events.c | 14 +------- tools/perf/util/pmu.c | 27 -------------- tools/perf/util/pmu.h | 2 -- 6 files changed, 84 insertions(+), 52 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 4182a986f505..216ea0482c37 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -6,6 +6,8 @@ * The test cpu/soc is provided for testing. */ #include "pmu-events/pmu-events.h" +#include +#include static const struct pmu_event pme_test_soc_cpu[] = { { @@ -145,7 +147,12 @@ static const struct pmu_event pme_test_soc_sys[] = { }, }; -const struct pmu_sys_events pmu_sys_event_tables[] = { +struct pmu_sys_events { + const char *name; + const struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { { .table = pme_test_soc_sys, .name = "pme_test_soc_sys", @@ -154,3 +161,31 @@ const struct pmu_sys_events pmu_sys_event_tables[] = { .table = 0 }, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +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++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 30e0e792221a..dd21bc9eeeed 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -370,8 +370,14 @@ def print_mapping_table(archs: Sequence[str]) -> None: def print_system_mapping_table() -> None: """C struct mapping table array for tables from /sys directories.""" - _args.output_file.write( - '\nconst struct pmu_sys_events pmu_sys_event_tables[] = {\n') + _args.output_file.write(""" +struct pmu_sys_events { +\tconst char *name; +\tconst struct pmu_event *table; +}; + +static const struct pmu_sys_events pmu_sys_event_tables[] = { +""") for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ \t\t.table = {tblname}, @@ -382,6 +388,34 @@ def print_system_mapping_table() -> None: \t\t.table = 0 \t}, }; + +const struct pmu_event *find_sys_events_table(const char *name) +{ + for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; + tables->name; + tables++) { + if (!strcmp(tables->name, name)) + return tables->table; + } + return NULL; +} + +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++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, data); + + if (ret) + return ret; + } + } + return 0; +} """) @@ -413,7 +447,12 @@ def main() -> None: 'output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout) _args = ap.parse_args() - _args.output_file.write("#include \"pmu-events/pmu-events.h\"\n") + _args.output_file.write(""" +#include "pmu-events/pmu-events.h" +#include +#include + +""") archs = [] for item in os.scandir(_args.starting_dir): if not item.is_dir(): diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index a491b117c8ac..2386212b1df0 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -43,16 +43,15 @@ struct pmu_events_map { const struct pmu_event *table; }; -struct pmu_sys_events { - const char *name; - const struct pmu_event *table; -}; - /* * Global table mapping each known CPU for the architecture to its * table of PMU events. */ extern const struct pmu_events_map pmu_events_map[]; -extern const struct pmu_sys_events pmu_sys_event_tables[]; + +const struct pmu_event *find_sys_events_table(const char *name); + +typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, void *data); +int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); #endif diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 82192f1a7bf7..a39a2c99ede6 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -286,18 +286,6 @@ static const struct pmu_events_map *__test_pmu_get_events_map(void) return NULL; } -static const struct pmu_event *__test_pmu_get_sys_events_table(void) -{ - const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; - - for ( ; tables->name; tables++) { - if (!strcmp("pme_test_soc_sys", tables->name)) - return tables->table; - } - - return NULL; -} - static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2) { if (!is_same(e1->name, e2->name)) { @@ -451,7 +439,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); + const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); const struct pmu_events_map *map = __test_pmu_get_events_map(); const struct pmu_event *table; int map_events = 0, expected_events; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0112e1c36418..d8717c4548a4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -868,33 +868,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) pmu_add_cpu_aliases_map(head, pmu, map); } -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data) -{ - int i = 0; - - while (1) { - const struct pmu_sys_events *event_table; - int j = 0; - - event_table = &pmu_sys_event_tables[i++]; - - if (!event_table->table) - break; - - while (1) { - const struct pmu_event *pe = &event_table->table[j++]; - int ret; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - - ret = fn(pe, data); - if (ret) - break; - } - } -} - struct pmu_sys_event_iter_data { struct list_head *head; struct perf_pmu *pmu; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 4b45fd8da5a3..7e667eec2a01 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -133,8 +133,6 @@ const struct pmu_events_map *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); -typedef int (*pmu_sys_event_iter_fn)(const struct pmu_event *pe, void *data); -void pmu_for_each_sys_event(pmu_sys_event_iter_fn fn, void *data); int perf_pmu__convert_scale(const char *scale, char **end, double *sval); int perf_pmu__caps_parse(struct perf_pmu *pmu); From patchwork Fri Jul 29 07:43:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932101 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 5DA25C00144 for ; Fri, 29 Jul 2022 07:49:23 +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=9ZBOWyePNeecZz9cgbd1cM8r189y6o1UicH1DZTDdwo=; b=nBtzNkel0VROUJEEyAFHarFdvT BTEqB+ZteZz1QPBKkUJMPgBpLpy22momI55C2+D35LVsxQZV5YZp73cuHE+5zy45FZMx+H5qRRV4G cqqPgCpBxmKanCUTl7y4oUO6Fr5vjXMmCTJkKEv1ZVBxVVOC/6FzBvsK8VfHTAzy6H8F4kISiL0Jn HhN7RpZR/TtNJbNeZbO39ITwtcyF8cMflHb9LbnyEdxuOg7FRTsuPRG3fJwcHMp0QpHyiZGRyNpB3 7An2hZfe0ZIXBPn3pl9bO/f2k0J/5pkEGepH/33hOqEvAVlZkdKYmk7AapL23DQTr4/y783mBRFcG 1iwEgwyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKj9-002kzs-GC; Fri, 29 Jul 2022 07:48:07 +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 1oHKfl-002j4n-5P for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:40 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s14-20020a5b044e000000b00672caf96368so3306391ybp.21 for ; Fri, 29 Jul 2022 00:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VXhSTEVkI/CrVpUsFXZjiJMJG+T/lVKu57GVikOUMIo=; b=iDZ3RzuaMriM5TbNinn1vfx+4YjiSrq8msuoETb7vN7iMAtNVYGzBJttomfm6TQxHm vnTIn53H6xSQS5vtv93vVsmvr2DBX5QGrkT/JKrgNkD2CsdBjr61yaKbmE2BIS9WQ797 mkfIzCSojoWWaTPtY4ZqiJUrGQiVzmxLBBAp3veXxKglJGk3x97+ITRVSGRguyjcKoEf loMn/iMPQAj8pd3Yd8HEieMRpcNL08ED/B5N9UFzQx4Uc0zgSEdB5wL3882XpQT6xykw iSvqCSSpAuycAAp736uCerBI8I1isiihh/LFUZEVNErMv1vu/JBmZ1GkkKGrMZLB4uMd h8dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VXhSTEVkI/CrVpUsFXZjiJMJG+T/lVKu57GVikOUMIo=; b=XP57m8wc21TO67YrEcstVjOfHJ3Kpfy3qVgeaBacbmw8WmxRP6JR3tGuOnECr2Cu4R eLuRIFDMMcTYuamyZ5jERZ3/ZkaewrwebNc94CPmGpVK1E3yqgpr+0OISD172jg5pXFp Sf9mDfHRn9jKFxACHtA/WRU8s7FSfp9XeFxAM3LaXtNlBVUDCI/bO3ItneucVPcRXCaT MMdO3J42yX2tmhOgnxJFjhAR6BFtfRu1eWFSIzg6jNtvIyMsXK1WtqVRfWW7uSW1lfgu WECUGEnzsU5bsmL5VbUTMlWRsR3PFARYBkIvX5SaY1J3hM0vMBCbS1hVfFuDeytvU4ly NW/Q== X-Gm-Message-State: ACgBeo1/tqoVmAJ4P3ipQ92VHmFbz5OkTyqmYO9RemXGHun2s0hVxoyd 3hgM5YTTK++b8CwjDNy8wstdxvGC70XJ X-Google-Smtp-Source: AA6agR79M5lTtcVXR8ESBr+LElXJ1o823HAgMQZYQYcmdLpTy26roPZ3fJB+0HnULpZ7kBasw2XCKEIQmjl7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a25:a41:0:b0:673:746:76ef with SMTP id 62-20020a250a41000000b00673074676efmr1702620ybk.132.1659080665126; Fri, 29 Jul 2022 00:44:25 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:43 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-10-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 09/17] perf pmu-events: Avoid passing pmu_events_map 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_004437_241965_DCD9DA1A X-CRM114-Status: GOOD ( 25.15 ) 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 Preparation for hiding pmu_events_map as an implementation detail. While the map is passed, the table of events is all that is normally wanted. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 4 +- tools/perf/tests/expand-cgroup.c | 6 +-- tools/perf/tests/parse-metric.c | 7 +-- tools/perf/tests/pmu-events.c | 63 +++++++++++------------- tools/perf/util/metricgroup.c | 82 +++++++++++++++---------------- tools/perf/util/metricgroup.h | 4 +- tools/perf/util/pmu.c | 33 +++++++------ tools/perf/util/pmu.h | 6 +-- tools/perf/util/s390-sample-raw.c | 12 ++--- 9 files changed, 99 insertions(+), 118 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c index 79124bba713e..646af8603227 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -3,7 +3,7 @@ #include "../../../util/cpumap.h" #include "../../../util/pmu.h" -const struct pmu_events_map *pmu_events_map__find(void) +const struct pmu_event *pmu_events_map__find(void) { struct perf_pmu *pmu = NULL; @@ -18,7 +18,7 @@ const struct pmu_events_map *pmu_events_map__find(void) if (pmu->cpus->nr != cpu__max_cpu().cpu) return NULL; - return perf_pmu__find_map(pmu); + return perf_pmu__find_table(pmu); } return NULL; diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index dc4038f997d7..411fc578e5a4 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -195,16 +195,12 @@ static int expand_metric_events(void) .metric_name = NULL, }, }; - const struct pmu_events_map ev_map = { - .cpuid = "test", - .table = pme_test, - }; evlist = evlist__new(); TEST_ASSERT_VAL("failed to get evlist", evlist); rblist__init(&metric_events); - ret = metricgroup__parse_groups_test(evlist, &ev_map, metric_str, + ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str, false, false, &metric_events); if (ret < 0) { pr_debug("failed to parse '%s' metric\n", metric_str); diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 1b811a26f4ee..7aebde7c37ec 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -79,11 +79,6 @@ static struct pmu_event pme_test[] = { } }; -static const struct pmu_events_map map = { - .cpuid = "test", - .table = pme_test, -}; - struct value { const char *event; u64 val; @@ -166,7 +161,7 @@ static int __compute_metric(const char *name, struct value *vals, runtime_stat__init(&st); /* Parse the metric into metric_events list. */ - err = metricgroup__parse_groups_test(evlist, &map, name, + err = metricgroup__parse_groups_test(evlist, pme_test, name, false, false, &metric_events); if (err) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index a39a2c99ede6..b3cde5f98982 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -272,13 +272,11 @@ static bool is_same(const char *reference, const char *test) return !strcmp(reference, test); } -static const struct pmu_events_map *__test_pmu_get_events_map(void) +static const struct pmu_event *__test_pmu_get_events_table(void) { - const struct pmu_events_map *map; - - for (map = &pmu_events_map[0]; map->cpuid; map++) { + for (const struct pmu_events_map *map = &pmu_events_map[0]; map->cpuid; map++) { if (!strcmp(map->cpuid, "testcpu")) - return map; + return map->table; } pr_err("could not find test events map\n"); @@ -440,8 +438,7 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); - const struct pmu_events_map *map = __test_pmu_get_events_map(); - const struct pmu_event *table; + const struct pmu_event *table = __test_pmu_get_events_table(); int map_events = 0, expected_events; /* ignore 3x sentinels */ @@ -449,10 +446,10 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, ARRAY_SIZE(uncore_events) + ARRAY_SIZE(sys_events) - 3; - if (!map || !sys_event_tables) + if (!table || !sys_event_tables) return -1; - for (table = map->table; table->name; table++) { + for (; table->name; table++) { struct perf_pmu_test_event const **test_event_table; bool found = false; @@ -537,10 +534,10 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) struct perf_pmu *pmu; LIST_HEAD(aliases); int res = 0; - const struct pmu_events_map *map = __test_pmu_get_events_map(); + const struct pmu_event *table = __test_pmu_get_events_table(); struct perf_pmu_alias *a, *tmp; - if (!map) + if (!table) return -1; test_event_table = &core_events[0]; @@ -551,7 +548,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) pmu->name = pmu_name; - pmu_add_cpu_aliases_map(&aliases, pmu, map); + pmu_add_cpu_aliases_map(&aliases, pmu, table); for (; *test_event_table; test_event_table++) { struct perf_pmu_test_event const *test_event = *test_event_table; @@ -590,14 +587,14 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) struct perf_pmu *pmu = &test_pmu->pmu; const char *pmu_name = pmu->name; struct perf_pmu_alias *a, *tmp, *alias; - const struct pmu_events_map *map; + const struct pmu_event *events_table; LIST_HEAD(aliases); int res = 0; - map = __test_pmu_get_events_map(); - if (!map) + events_table = __test_pmu_get_events_table(); + if (!events_table) return -1; - pmu_add_cpu_aliases_map(&aliases, pmu, map); + pmu_add_cpu_aliases_map(&aliases, pmu, events_table); pmu_add_sys_aliases(&aliases, pmu); /* Count how many aliases we generated */ @@ -848,13 +845,9 @@ static int check_parse_fake(const char *id) return ret; } -static void expr_failure(const char *msg, - const struct pmu_events_map *map, - const struct pmu_event *pe) +static void expr_failure(const char *msg, const struct pmu_event *pe) { - pr_debug("%s for map %s %s\n", msg, map->arch, map->cpuid); - pr_debug("On metric %s\n", pe->metric_name); - pr_debug("On expression %s\n", pe->metric_expr); + pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr); } struct metric { @@ -864,7 +857,7 @@ struct metric { static int resolve_metric_simple(struct expr_parse_ctx *pctx, struct list_head *compound_list, - const struct pmu_events_map *map, + const struct pmu_event *map, const char *metric_name) { struct hashmap_entry *cur, *cur_tmp; @@ -925,8 +918,7 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx, static int test__parsing(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_events_map *cpus_map = pmu_events_map__find(); - const struct pmu_events_map *map; + const struct pmu_event *cpus_table = pmu_events_map__find(); const struct pmu_event *pe; int i, j, k; int ret = 0; @@ -940,7 +932,8 @@ static int test__parsing(struct test_suite *test __maybe_unused, } i = 0; for (;;) { - map = &pmu_events_map[i++]; + const struct pmu_events_map *map = &pmu_events_map[i++]; + if (!map->table) break; j = 0; @@ -957,14 +950,14 @@ static int test__parsing(struct test_suite *test __maybe_unused, continue; expr__ctx_clear(ctx); if (expr__find_ids(pe->metric_expr, NULL, ctx) < 0) { - expr_failure("Parse find ids failed", map, pe); + expr_failure("Parse find ids failed", pe); ret++; continue; } - if (resolve_metric_simple(ctx, &compound_list, map, + if (resolve_metric_simple(ctx, &compound_list, map->table, pe->metric_name)) { - expr_failure("Could not resolve metrics", map, pe); + expr_failure("Could not resolve metrics", pe); ret++; goto exit; /* Don't tolerate errors due to severity */ } @@ -979,7 +972,7 @@ static int test__parsing(struct test_suite *test __maybe_unused, expr__add_id_val(ctx, strdup(cur->key), k++); hashmap__for_each_entry(ctx->ids, cur, bkt) { - if (check_parse_cpu(cur->key, map == cpus_map, + if (check_parse_cpu(cur->key, map->table == cpus_table, pe)) ret++; } @@ -999,7 +992,7 @@ static int test__parsing(struct test_suite *test __maybe_unused, hashmap__for_each_entry(ctx->ids, cur, bkt) expr__add_id_val(ctx, strdup(cur->key), k--); if (expr__parse(&result, ctx, pe->metric_expr)) { - expr_failure("Parse failed", map, pe); + expr_failure("Parse failed", pe); ret++; } } @@ -1088,8 +1081,6 @@ static int metric_parse_fake(const char *str) static int test__parsing_fake(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - const struct pmu_events_map *map; - const struct pmu_event *pe; unsigned int i, j; int err = 0; @@ -1101,12 +1092,14 @@ static int test__parsing_fake(struct test_suite *test __maybe_unused, i = 0; for (;;) { - map = &pmu_events_map[i++]; + const struct pmu_events_map *map = &pmu_events_map[i++]; + if (!map->table) break; j = 0; for (;;) { - pe = &map->table[j++]; + const struct pmu_event *pe = &map->table[j++]; + if (!pe->name && !pe->metric_group && !pe->metric_name) break; if (!pe->metric_expr) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8f7baeabc5cf..4d32b4fbf67d 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -539,9 +539,6 @@ static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, void *d void metricgroup__print(bool metrics, bool metricgroups, char *filter, bool raw, bool details, const char *pmu_name) { - const struct pmu_events_map *map = pmu_events_map__find(); - const struct pmu_event *pe; - int i; struct rblist groups; struct rb_node *node, *next; struct strlist *metriclist = NULL; @@ -556,8 +553,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; - for (i = 0; map; i++) { - pe = &map->table[i]; + for (const struct pmu_event *pe = pmu_events_map__find(); pe; pe++) { if (!pe->name && !pe->metric_group && !pe->metric_name) break; @@ -850,7 +846,7 @@ struct metricgroup_add_iter_data { bool metric_no_group; struct metric *root_metric; const struct visited_metric *visited; - const struct pmu_events_map *map; + const struct pmu_event *table; }; static int add_metric(struct list_head *metric_list, @@ -859,7 +855,7 @@ static int add_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_map *map); + const struct pmu_event *table); /** * resolve_metric - Locate metrics within the root metric and recursively add @@ -874,7 +870,7 @@ static int add_metric(struct list_head *metric_list, * metrics. When adding a root this argument is NULL. * @visited: A singly linked list of metric names being added that is used to * detect recursion. - * @map: The map that is searched for metrics, most commonly the table for the + * @table: The table that is searched for metrics, most commonly the table for the * architecture perf is running upon. */ static int resolve_metric(struct list_head *metric_list, @@ -882,7 +878,7 @@ static int resolve_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_map *map) + const struct pmu_event *table) { struct hashmap_entry *cur; size_t bkt; @@ -904,7 +900,7 @@ static int resolve_metric(struct list_head *metric_list, hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) { const struct pmu_event *pe; - pe = metricgroup__find_metric(cur->key, map); + pe = metricgroup__find_metric(cur->key, table); if (pe) { pending = realloc(pending, (pending_cnt + 1) * sizeof(struct to_resolve)); @@ -927,7 +923,7 @@ static int resolve_metric(struct list_head *metric_list, */ for (i = 0; i < pending_cnt; i++) { ret = add_metric(metric_list, pending[i].pe, modifier, metric_no_group, - root_metric, visited, map); + root_metric, visited, table); if (ret) break; } @@ -950,7 +946,7 @@ static int resolve_metric(struct list_head *metric_list, * metrics. When adding a root this argument is NULL. * @visited: A singly linked list of metric names being added that is used to * detect recursion. - * @map: The map that is searched for metrics, most commonly the table for the + * @table: The table that is searched for metrics, most commonly the table for the * architecture perf is running upon. */ static int __add_metric(struct list_head *metric_list, @@ -960,7 +956,7 @@ static int __add_metric(struct list_head *metric_list, int runtime, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_map *map) + const struct pmu_event *table) { const struct visited_metric *vm; int ret; @@ -1032,7 +1028,7 @@ static int __add_metric(struct list_head *metric_list, } else { /* Resolve referenced metrics. */ ret = resolve_metric(metric_list, modifier, metric_no_group, root_metric, - &visited_node, map); + &visited_node, table); } if (ret) { @@ -1045,25 +1041,25 @@ static int __add_metric(struct list_head *metric_list, return ret; } -#define map_for_each_event(__pe, __idx, __map) \ - if (__map) \ - for (__idx = 0, __pe = &__map->table[__idx]; \ +#define table_for_each_event(__pe, __idx, __table) \ + if (__table) \ + for (__idx = 0, __pe = &__table[__idx]; \ __pe->name || __pe->metric_group || __pe->metric_name; \ - __pe = &__map->table[++__idx]) + __pe = &__table[++__idx]) -#define map_for_each_metric(__pe, __idx, __map, __metric) \ - map_for_each_event(__pe, __idx, __map) \ +#define table_for_each_metric(__pe, __idx, __table, __metric) \ + table_for_each_event(__pe, __idx, __table) \ if (__pe->metric_expr && \ (match_metric(__pe->metric_group, __metric) || \ match_metric(__pe->metric_name, __metric))) const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_map *map) + const struct pmu_event *table) { const struct pmu_event *pe; int i; - map_for_each_event(pe, i, map) { + table_for_each_event(pe, i, table) { if (match_metric(pe->metric_name, metric)) return pe; } @@ -1077,7 +1073,7 @@ static int add_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_events_map *map) + const struct pmu_event *table) { int ret = 0; @@ -1085,7 +1081,7 @@ static int add_metric(struct list_head *metric_list, if (!strstr(pe->metric_expr, "?")) { ret = __add_metric(metric_list, pe, modifier, metric_no_group, 0, - root_metric, visited, map); + root_metric, visited, table); } else { int j, count; @@ -1098,7 +1094,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, - root_metric, visited, map); + root_metric, visited, table); } return ret; @@ -1114,7 +1110,7 @@ static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe, return 0; ret = add_metric(d->metric_list, pe, d->modifier, d->metric_no_group, - d->root_metric, d->visited, d->map); + d->root_metric, d->visited, d->table); if (ret) goto out; @@ -1162,13 +1158,13 @@ static int metric_list_cmp(void *priv __maybe_unused, const struct list_head *l, * global. Grouping is the default but due to multiplexing the * user may override. * @metric_list: The list that the metric or metric group are added to. - * @map: The map that is searched for metrics, most commonly the table for the + * @table: The table that is searched for metrics, most commonly the table for the * architecture perf is running upon. */ static int metricgroup__add_metric(const char *metric_name, const char *modifier, bool metric_no_group, struct list_head *metric_list, - const struct pmu_events_map *map) + const struct pmu_event *table) { const struct pmu_event *pe; LIST_HEAD(list); @@ -1179,11 +1175,11 @@ 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. */ - map_for_each_metric(pe, i, map, metric_name) { + table_for_each_metric(pe, i, table, metric_name) { has_match = true; ret = add_metric(&list, pe, modifier, metric_no_group, /*root_metric=*/NULL, - /*visited_metrics=*/NULL, map); + /*visited_metrics=*/NULL, table); if (ret) goto out; } @@ -1198,7 +1194,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier .metric_no_group = metric_no_group, .has_match = &has_match, .ret = &ret, - .map = map, + .table = table, }, }; @@ -1227,12 +1223,12 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier * global. Grouping is the default but due to multiplexing the * user may override. * @metric_list: The list that metrics are added to. - * @map: The map that is searched for metrics, most commonly the table for the + * @table: The table that is searched for metrics, most commonly the table for the * architecture perf is running upon. */ static int metricgroup__add_metric_list(const char *list, bool metric_no_group, struct list_head *metric_list, - const struct pmu_events_map *map) + const struct pmu_event *table) { char *list_itr, *list_copy, *metric_name, *modifier; int ret, count = 0; @@ -1249,7 +1245,7 @@ static int metricgroup__add_metric_list(const char *list, bool metric_no_group, ret = metricgroup__add_metric(metric_name, modifier, metric_no_group, metric_list, - map); + table); if (ret == -EINVAL) pr_err("Cannot find metric or group `%s'\n", metric_name); @@ -1440,7 +1436,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, bool metric_no_merge, struct perf_pmu *fake_pmu, struct rblist *metric_events_list, - const struct pmu_events_map *map) + const struct pmu_event *table) { struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); @@ -1451,7 +1447,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, if (metric_events_list->nr_entries == 0) metricgroup__rblist_init(metric_events_list); ret = metricgroup__add_metric_list(str, metric_no_group, - &metric_list, map); + &metric_list, table); if (ret) goto out; @@ -1586,34 +1582,34 @@ int metricgroup__parse_groups(const struct option *opt, struct rblist *metric_events) { struct evlist *perf_evlist = *(struct evlist **)opt->value; - const struct pmu_events_map *map = pmu_events_map__find(); + const struct pmu_event *table = pmu_events_map__find(); return parse_groups(perf_evlist, str, metric_no_group, - metric_no_merge, NULL, metric_events, map); + metric_no_merge, NULL, metric_events, table); } int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_events_map *map, + const struct pmu_event *table, const char *str, bool metric_no_group, bool metric_no_merge, struct rblist *metric_events) { return parse_groups(evlist, str, metric_no_group, - metric_no_merge, &perf_pmu__fake, metric_events, map); + metric_no_merge, &perf_pmu__fake, metric_events, table); } bool metricgroup__has_metric(const char *metric) { - const struct pmu_events_map *map = pmu_events_map__find(); + const struct pmu_event *table = pmu_events_map__find(); const struct pmu_event *pe; int i; - if (!map) + if (!table) return false; for (i = 0; ; i++) { - pe = &map->table[i]; + pe = &table[i]; if (!pe->name && !pe->metric_group && !pe->metric_name) break; diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 2b42b778d1bf..5a1390e73d25 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -71,9 +71,9 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_merge, struct rblist *metric_events); const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_map *map); + const struct pmu_event *table); int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_events_map *map, + const struct pmu_event *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 d8717c4548a4..f3e3c4a147e9 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -710,9 +710,9 @@ static char *perf_pmu__getcpuid(struct perf_pmu *pmu) return cpuid; } -const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) +const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) { - const struct pmu_events_map *map; + const struct pmu_event *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); int i; @@ -724,22 +724,23 @@ const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) i = 0; for (;;) { - map = &pmu_events_map[i++]; - if (!map->table) { - map = NULL; + const struct pmu_events_map *map = &pmu_events_map[i++]; + + if (!map->table) break; - } - if (!strcmp_cpuid_str(map->cpuid, cpuid)) + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = map->table; break; + } } free(cpuid); - return map; + return table; } -const struct pmu_events_map *__weak pmu_events_map__find(void) +__weak const struct pmu_event *pmu_events_map__find(void) { - return perf_pmu__find_map(NULL); + return perf_pmu__find_table(NULL); } /* @@ -824,7 +825,7 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) * as aliases. */ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - const struct pmu_events_map *map) + const struct pmu_event *table) { int i; const char *name = pmu->name; @@ -834,7 +835,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, i = 0; while (1) { const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu"; - const struct pmu_event *pe = &map->table[i++]; + const struct pmu_event *pe = &table[i++]; const char *pname = pe->pmu ? pe->pmu : cpu_name; if (!pe->name) { @@ -859,13 +860,13 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) { - const struct pmu_events_map *map; + const struct pmu_event *table; - map = perf_pmu__find_map(pmu); - if (!map) + table = perf_pmu__find_table(pmu); + if (!table) return; - pmu_add_cpu_aliases_map(head, pmu, map); + pmu_add_cpu_aliases_map(head, pmu, table); } struct pmu_sys_event_iter_data { diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 7e667eec2a01..015242c83698 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -126,10 +126,10 @@ int perf_pmu__test(void); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - const struct pmu_events_map *map); + const struct pmu_event *map); -const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); -const struct pmu_events_map *pmu_events_map__find(void); +const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu); +const struct pmu_event *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index cd3a34840389..1ecb718fc0eb 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -135,12 +135,12 @@ static int get_counterset_start(int setnr) * the name of this counter. * If no match is found a NULL pointer is returned. */ -static const char *get_counter_name(int set, int nr, const struct pmu_events_map *map) +static const char *get_counter_name(int set, int nr, const struct pmu_event *table) { int rc, event_nr, wanted = get_counterset_start(set) + nr; - if (map) { - const struct pmu_event *evp = map->table; + if (table) { + const struct pmu_event *evp = table; for (; evp->name || evp->event || evp->desc; ++evp) { if (evp->name == NULL || evp->event == NULL) @@ -159,10 +159,10 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) unsigned char *buf = sample->raw_data; const char *color = PERF_COLOR_BLUE; struct cf_ctrset_entry *cep, ce; - const struct pmu_events_map *map; + const struct pmu_event *table; u64 *p; - map = pmu_events_map__find(); + table = pmu_events_map__find(); while (offset < len) { cep = (struct cf_ctrset_entry *)(buf + offset); @@ -180,7 +180,7 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) color_fprintf(stdout, color, " [%#08zx] Counterset:%d" " Counters:%d\n", offset, ce.set, ce.ctr); for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; ++i, ++p) { - const char *ev_name = get_counter_name(ce.set, i, map); + const char *ev_name = get_counter_name(ce.set, i, table); color_fprintf(stdout, color, "\tCounter:%03d %s Value:%#018lx\n", i, From patchwork Fri Jul 29 07:43:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932107 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 39971C19F2A for ; Fri, 29 Jul 2022 07:55:41 +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=RTWR4ipZ/nY2hryyhCCqH9Uz3izTize0mb1Rnwz7Smw=; b=Pc1JHZvnHWrsuN9tGWfTwWJsL3 DrstIO6GVYn6Qi1crHiR68/b01ykAJun/faawlI2vm0doAmMTqfGqykWJviFkDHH2gugEsYhe3nuV viFCiFLLvc2GwVGshxM24GLCpitrm3JA9ilTad3wWNFWG6VCEJKH5EFsg80QBJQTJJSldSuJxP0vd /0EOs0eU5bov3WRpJobUHVOeaay9FPF5a977vr/V8/sburuE7wcbu//X3ELxp8wCwfN2VMB6XbFXN kLodUBIlgJ1VL5+OkGVWayE6D4Kz/9CSZxa90smF180hkRIpOlRQ5wtkkbMbFB9h+n2HwjocqRoFG ce+BxBog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKot-002nqZ-NC; Fri, 29 Jul 2022 07:54:04 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfv-002jL2-Oy for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Tagrozpgrc9vyY8Ly8l/FK550pEPqWVw3iz3s7f6M28=; b=GKDoLQjMpSuP1t/YlSaXpS6JMk ZXkEsKXjeBYsx3whE1dMgeznCdwpJhORv1eSibjptTKdFXN8l0/lXX89w2wCNtmKeJkBr98jDZnLw bDkfUnl13QjcotITasl+Z/8rrgoD8/4eOpxS0B+uIsgtcNMwpnFp4RsshnV+fmspWF0yTb+LrFll5 Cwik+EgzTJk7RPptdmYu9n3AzBlG5UI8q1jJjGouyC7wC7t3sQs8l6ewYs7g/sWLzxgMneP4864PI 5hnLdyrRfy5y1Rk6vU0OFCJJNQ13GXEmnsCswaC2Aph6E1Xea381vjsUd2Y1eFwzA5g4qEvkC5EM1 r8T04Kmw==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfj-001Gh0-RL for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:39 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id r64-20020a254443000000b006707b7c2baeso3297750yba.16 for ; Fri, 29 Jul 2022 00:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Tagrozpgrc9vyY8Ly8l/FK550pEPqWVw3iz3s7f6M28=; b=Hjp50gdbNZXTbvCtvr/MVpzEEICvoH3sczAWbt6RCKyGo+ofw9L/lxPzFwn1gUssGL QH7pDfCB8KgoGEAwcC2wuyZVgzJu0PP2XzGQD8+MwFdcOW+4AjSGDe58xhWaYldJCeuY YxAciG/V6edrXykV3FNIGIW+8VVuJKiT7tTyVP3O/+6L8Wfy6gdaCX1HV+Y4xu0WXuzf lOwP17bGO5pbcUDuSrY4C0gAFyWumgFejogp3zW0GhpyAZhcormuoRKynGqUWofPzUre 7ZYg2KAVFoY/U9bTTZ8BldeTU6Av0QL6xNK172k7dmRvaQ2XMk4IyArleleLtV0DZVnL VprQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Tagrozpgrc9vyY8Ly8l/FK550pEPqWVw3iz3s7f6M28=; b=dFBhbOtxX3i6il/FYQXwvU9TlQU7flVxn42iv947NU1eoy/2PL1zaHY2OjZ5OAaMYe Bn71qQwEcoks285k5q/2bl7Fyb2fh7LK2ItyIRF1YqRU413HulmbXdcT+9g8Z70OtRJc gNUMhE6YZHwpHh/K2ve/Ee/HFDOPqkLQdBNwvB5/zbVA7LAsPvJanogZyoAJJyJ6iT8O NZwUav/KIuJg6YnHmU/HxfACouhVdy0NPBwCDa+TaF5dPzdQN8TbVXwv5xDDx8WsfneT MJHTtXBQGvYTx1QFnQaiedivdn1G0UE90GEgsKjg+pupYbgbS3m9uz1EwJ8l1iY76IQF HcKA== X-Gm-Message-State: ACgBeo1WMSQMoc/xAEmNo/3teayRdwvgINQvWS4CsFr2ldFOBHIn+nV/ 8TtRYzFeFURIp/G1ONvLDjIhoYOF8d57 X-Google-Smtp-Source: AA6agR7KjRxVZzm7xm8PTDacYS2lbXtE3KdJIIOHRJOLsQhqSS2XwZf4DSY97cJT2+iloHCb0wuo7oW2R5Ne X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a05:6902:10c:b0:671:68b7:ab41 with SMTP id o12-20020a056902010c00b0067168b7ab41mr1459964ybh.608.1659080667646; Fri, 29 Jul 2022 00:44:27 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:44 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-11-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 10/17] perf pmu-events: Hide pmu_events_map 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084436_859451_4B4BFA84 X-CRM114-Status: GOOD ( 25.53 ) 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 Move usage of the table to pmu-events.c so it may be hidden. By abstracting the table the implementation can later be changed. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 81 ++++++++- tools/perf/pmu-events/jevents.py | 81 ++++++++- tools/perf/pmu-events/pmu-events.h | 29 +-- tools/perf/tests/pmu-events.c | 218 +++++++++++------------ tools/perf/util/metricgroup.c | 15 +- tools/perf/util/pmu.c | 34 +--- tools/perf/util/pmu.h | 2 +- 7 files changed, 280 insertions(+), 180 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 216ea0482c37..8ef75aff996c 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -6,6 +6,8 @@ * The test cpu/soc is provided for testing. */ #include "pmu-events/pmu-events.h" +#include "util/header.h" +#include "util/pmu.h" #include #include @@ -110,7 +112,26 @@ static const struct pmu_event pme_test_soc_cpu[] = { }, }; -const struct pmu_events_map pmu_events_map[] = { + +/* + * 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. + * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile + * must match the get_cpuid_str() in tools/perf/arch/xxx/util/header.c) + * + * The cpuid can contain any character other than the comma. + */ +struct pmu_events_map { + const char *arch; + const char *cpuid; + const struct pmu_event *table; +}; + +/* + * Global table mapping each known CPU for the architecture to its + * table of PMU events. + */ +static const struct pmu_events_map pmu_events_map[] = { { .arch = "testarch", .cpuid = "testcpu", @@ -162,6 +183,62 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { }, }; +const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) +{ + const struct pmu_event *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->table) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = map->table; + break; + } + } + free(cpuid); + return table; +} + +const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->table; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return tables->table; + } + return NULL; +} + +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->table; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, &tables->table[0], data); + + if (ret) + return ret; + } + } + return 0; +} + const struct pmu_event *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; @@ -181,7 +258,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) for (const struct pmu_event *pe = &tables->table[0]; pe->name || pe->metric_group || pe->metric_name; pe++) { - int ret = fn(pe, data); + int ret = fn(pe, &tables->table[0], data); if (ret) return ret; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index dd21bc9eeeed..e976c5e8e80b 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -333,7 +333,27 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: def print_mapping_table(archs: Sequence[str]) -> None: """Read the mapfile and generate the struct from cpuid string to event table.""" - _args.output_file.write('const struct pmu_events_map pmu_events_map[] = {\n') + _args.output_file.write(""" +/* + * 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. + * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile + * must match the get_cpuid_str() in tools/perf/arch/xxx/util/header.c) + * + * The cpuid can contain any character other than the comma. + */ +struct pmu_events_map { + const char *arch; + const char *cpuid; + const struct pmu_event *table; +}; + +/* + * Global table mapping each known CPU for the architecture to its + * table of PMU events. + */ +const struct pmu_events_map pmu_events_map[] = { +""") for arch in archs: if arch == 'test': _args.output_file.write("""{ @@ -389,6 +409,61 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { \t}, }; +const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) +{ + const struct pmu_event *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->table) + break; + + if (!strcmp_cpuid_str(map->cpuid, cpuid)) { + table = map->table; + break; + } + } + free(cpuid); + return table; +} + +const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid) +{ + for (const struct pmu_events_map *tables = &pmu_events_map[0]; + tables->table; + tables++) { + if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) + return tables->table; + } + return NULL; +} + +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->table; + tables++) { + for (const struct pmu_event *pe = &tables->table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, &tables->table[0], data); + + if (ret) + return ret; + } + } + return 0; +} + const struct pmu_event *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; @@ -408,7 +483,7 @@ int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data) for (const struct pmu_event *pe = &tables->table[0]; pe->name || pe->metric_group || pe->metric_name; pe++) { - int ret = fn(pe, data); + int ret = fn(pe, &tables->table[0], data); if (ret) return ret; @@ -449,6 +524,8 @@ def main() -> None: _args.output_file.write(""" #include "pmu-events/pmu-events.h" +#include "util/header.h" +#include "util/pmu.h" #include #include diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 2386212b1df0..485e730f9922 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -2,6 +2,8 @@ #ifndef PMU_EVENTS_H #define PMU_EVENTS_H +struct perf_pmu; + enum aggr_mode_class { PerChip = 1, PerCore @@ -28,30 +30,15 @@ struct pmu_event { const char *metric_constraint; }; -/* - * - * 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. - * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile - * must match the get_cpuid_str() in tools/perf/arch/xxx/util/header.c) - * - * The cpuid can contain any character other than the comma. - */ -struct pmu_events_map { - const char *arch; - const char *cpuid; - const struct pmu_event *table; -}; +typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, + const struct pmu_event *table, + void *data); -/* - * Global table mapping each known CPU for the architecture to its - * table of PMU events. - */ -extern const struct pmu_events_map pmu_events_map[]; +const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu); +const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid); +int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); const struct pmu_event *find_sys_events_table(const char *name); - -typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, void *data); int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); #endif diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index b3cde5f98982..ea8b41b5c4e3 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -272,18 +272,6 @@ static bool is_same(const char *reference, const char *test) return !strcmp(reference, test); } -static const struct pmu_event *__test_pmu_get_events_table(void) -{ - for (const struct pmu_events_map *map = &pmu_events_map[0]; map->cpuid; map++) { - if (!strcmp(map->cpuid, "testcpu")) - return map->table; - } - - pr_err("could not find test events map\n"); - - return NULL; -} - static int compare_pmu_events(const struct pmu_event *e1, const struct pmu_event *e2) { if (!is_same(e1->name, e2->name)) { @@ -438,7 +426,7 @@ static int test__pmu_event_table(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); - const struct pmu_event *table = __test_pmu_get_events_table(); + const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); int map_events = 0, expected_events; /* ignore 3x sentinels */ @@ -534,7 +522,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) struct perf_pmu *pmu; LIST_HEAD(aliases); int res = 0; - const struct pmu_event *table = __test_pmu_get_events_table(); + const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); struct perf_pmu_alias *a, *tmp; if (!table) @@ -591,7 +579,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) LIST_HEAD(aliases); int res = 0; - events_table = __test_pmu_get_events_table(); + events_table = find_core_events_table("testarch", "testcpu"); if (!events_table) return -1; pmu_add_cpu_aliases_map(&aliases, pmu, events_table); @@ -845,11 +833,6 @@ static int check_parse_fake(const char *id) return ret; } -static void expr_failure(const char *msg, const struct pmu_event *pe) -{ - pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr); -} - struct metric { struct list_head list; struct metric_ref metric_ref; @@ -915,93 +898,100 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx, } -static int test__parsing(struct test_suite *test __maybe_unused, - int subtest __maybe_unused) +static void expr_failure(const char *msg, const struct pmu_event *pe) { - const struct pmu_event *cpus_table = pmu_events_map__find(); - const struct pmu_event *pe; - int i, j, k; - int ret = 0; + pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr); +} + + +struct test__parsing_data { + const struct pmu_event *cpus_table; struct expr_parse_ctx *ctx; + int failures; +}; + +static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_event *table, + void *vdata) +{ + struct test__parsing_data *data = vdata; + struct metric *metric, *tmp; + struct hashmap_entry *cur; + LIST_HEAD(compound_list); + size_t bkt; + int k; double result; - ctx = expr__ctx_new(); - if (!ctx) { - pr_debug("expr__ctx_new failed"); - return TEST_FAIL; + if (!pe->metric_expr) + return 0; + + pr_debug("Found metric '%s'\n", pe->metric_name); + + expr__ctx_clear(data->ctx); + if (expr__find_ids(pe->metric_expr, NULL, data->ctx) < 0) { + expr_failure("Parse find ids failed", pe); + data->failures++; + return 0; } - i = 0; - for (;;) { - const struct pmu_events_map *map = &pmu_events_map[i++]; - if (!map->table) - break; - j = 0; - for (;;) { - struct metric *metric, *tmp; - struct hashmap_entry *cur; - LIST_HEAD(compound_list); - size_t bkt; - - pe = &map->table[j++]; - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - if (!pe->metric_expr) - continue; - expr__ctx_clear(ctx); - if (expr__find_ids(pe->metric_expr, NULL, ctx) < 0) { - expr_failure("Parse find ids failed", pe); - ret++; - continue; - } + if (resolve_metric_simple(data->ctx, &compound_list, table, + pe->metric_name)) { + expr_failure("Could not resolve metrics", pe); + data->failures++; + return TEST_FAIL; /* Don't tolerate errors due to severity */ + } - if (resolve_metric_simple(ctx, &compound_list, map->table, - pe->metric_name)) { - expr_failure("Could not resolve metrics", pe); - ret++; - goto exit; /* Don't tolerate errors due to severity */ - } + /* + * Add all ids with a made up value. The value may trigger divide by + * zero when subtracted and so try to make them unique. + */ + k = 1; + hashmap__for_each_entry(data->ctx->ids, cur, bkt) + expr__add_id_val(data->ctx, strdup(cur->key), k++); - /* - * Add all ids with a made up value. The value may - * trigger divide by zero when subtracted and so try to - * make them unique. - */ - k = 1; - hashmap__for_each_entry(ctx->ids, cur, bkt) - expr__add_id_val(ctx, strdup(cur->key), k++); - - hashmap__for_each_entry(ctx->ids, cur, bkt) { - if (check_parse_cpu(cur->key, map->table == cpus_table, - pe)) - ret++; - } + hashmap__for_each_entry(data->ctx->ids, cur, bkt) { + if (check_parse_cpu(cur->key, table == data->cpus_table, pe)) + data->failures++; + } - list_for_each_entry_safe(metric, tmp, &compound_list, list) { - expr__add_ref(ctx, &metric->metric_ref); - free(metric); - } + list_for_each_entry_safe(metric, tmp, &compound_list, list) { + expr__add_ref(data->ctx, &metric->metric_ref); + free(metric); + } - if (expr__parse(&result, ctx, pe->metric_expr)) { - /* - * Parsing failed, make numbers go from large to - * small which can resolve divide by zero - * issues. - */ - k = 1024; - hashmap__for_each_entry(ctx->ids, cur, bkt) - expr__add_id_val(ctx, strdup(cur->key), k--); - if (expr__parse(&result, ctx, pe->metric_expr)) { - expr_failure("Parse failed", pe); - ret++; - } - } + if (expr__parse(&result, data->ctx, pe->metric_expr)) { + /* + * Parsing failed, make numbers go from large to small which can + * resolve divide by zero issues. + */ + k = 1024; + hashmap__for_each_entry(data->ctx->ids, cur, bkt) + expr__add_id_val(data->ctx, strdup(cur->key), k--); + if (expr__parse(&result, data->ctx, pe->metric_expr)) { + expr_failure("Parse failed", pe); + data->failures++; } } - expr__ctx_free(ctx); - /* TODO: fail when not ok */ -exit: - return ret == 0 ? TEST_OK : TEST_SKIP; + return 0; +} + +static int test__parsing(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + struct test__parsing_data data = { + .cpus_table = pmu_events_map__find(), + .ctx = expr__ctx_new(), + .failures = 0, + }; + + if (!data.ctx) { + pr_debug("expr__ctx_new failed"); + return TEST_FAIL; + } + pmu_for_each_core_event(test__parsing_callback, &data); + pmu_for_each_sys_event(test__parsing_callback, &data); + + expr__ctx_free(data.ctx); + return data.failures == 0 ? TEST_OK : TEST_FAIL; } struct test_metric { @@ -1073,6 +1063,16 @@ static int metric_parse_fake(const char *str) return ret; } +static int test__parsing_fake_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data __maybe_unused) +{ + if (!pe->metric_expr) + return 0; + + return metric_parse_fake(pe->metric_expr); +} + /* * Parse all the metrics for current architecture, * or all defined cpus via the 'fake_pmu' @@ -1081,37 +1081,19 @@ static int metric_parse_fake(const char *str) static int test__parsing_fake(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - unsigned int i, j; int err = 0; - for (i = 0; i < ARRAY_SIZE(metrics); i++) { + for (size_t i = 0; i < ARRAY_SIZE(metrics); i++) { err = metric_parse_fake(metrics[i].str); if (err) return err; } - i = 0; - for (;;) { - const struct pmu_events_map *map = &pmu_events_map[i++]; + err = pmu_for_each_core_event(test__parsing_fake_callback, NULL); + if (err) + return err; - if (!map->table) - break; - j = 0; - for (;;) { - const struct pmu_event *pe = &map->table[j++]; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - if (!pe->metric_expr) - continue; - pr_debug("Found metric '%s' for '%s'\n", pe->metric_name, map->cpuid); - err = metric_parse_fake(pe->metric_expr); - if (err) - return err; - } - } - - return 0; + return pmu_for_each_sys_event(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 4d32b4fbf67d..680f7c63838d 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -502,14 +502,14 @@ struct metricgroup_print_sys_idata { bool details; }; -typedef int (*metricgroup_sys_event_iter_fn)(const struct pmu_event *pe, void *); - struct metricgroup_iter_data { - metricgroup_sys_event_iter_fn fn; + pmu_event_iter_fn fn; void *data; }; -static int metricgroup__sys_event_iter(const struct pmu_event *pe, void *data) +static int metricgroup__sys_event_iter(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data) { struct metricgroup_iter_data *d = data; struct perf_pmu *pmu = NULL; @@ -522,13 +522,15 @@ static int metricgroup__sys_event_iter(const struct pmu_event *pe, void *data) if (!pmu->id || strcmp(pmu->id, pe->compat)) continue; - return d->fn(pe, d->data); + return d->fn(pe, table, d->data); } return 0; } -static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, void *data) +static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data) { struct metricgroup_print_sys_idata *d = data; @@ -1101,6 +1103,7 @@ static int add_metric(struct list_head *metric_list, } static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, void *data) { struct metricgroup_add_iter_data *d = data; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f3e3c4a147e9..5bb03d4e52a3 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -690,7 +690,7 @@ static int is_arm_pmu_core(const char *name) return file_available(path); } -static char *perf_pmu__getcpuid(struct perf_pmu *pmu) +char *perf_pmu__getcpuid(struct perf_pmu *pmu) { char *cpuid; static bool printed; @@ -710,34 +710,6 @@ static char *perf_pmu__getcpuid(struct perf_pmu *pmu) return cpuid; } -const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) -{ - const struct pmu_event *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->table) - break; - - if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = map->table; - break; - } - } - free(cpuid); - return table; -} - __weak const struct pmu_event *pmu_events_map__find(void) { return perf_pmu__find_table(NULL); @@ -874,7 +846,9 @@ struct pmu_sys_event_iter_data { struct perf_pmu *pmu; }; -static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, void *data) +static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data) { struct pmu_sys_event_iter_data *idata = data; struct perf_pmu *pmu = idata->pmu; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 015242c83698..06df99ba2029 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -128,7 +128,7 @@ struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, const struct pmu_event *map); -const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu); +char *perf_pmu__getcpuid(struct perf_pmu *pmu); const struct pmu_event *pmu_events_map__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 Fri Jul 29 07:43:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932106 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 5741AC00144 for ; Fri, 29 Jul 2022 07:53:58 +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=mLLfxGZ1XU4+IwdlsNcAT48378ADXgh/8GasfskLyBA=; b=NIFsKz6VfNR39TKDCZ47ksmYGF 8SvxshANNUdTQUiG8U3wmvJ5uyUqAYfoq2WhKMOVZSeQN4APmAHP+Qidavt/gW0+RbG3emzS06s45 A5cO9Mqx6dTMi4HHMeTE1RwiNFcQ0ddr8eTIAzmf9x/Sw5vKjAerg853Gnxc3etSushx/dKhfFVR2 mHMNfenX3bzvhoyzjPWpoIRXJlUT62aiuvkGn/d8By+WxdJbfAQFW8HE6Ux0fsKRCrFwAetnhRqxw 8bSg+H983Tnst6dQlNjJXZOh0mzUDEoZr9J6v62TJjLNq7EpFuGEZoZzBYgO9JlrfS3f54MBjte3m u24yIGhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKnT-002nAb-9y; Fri, 29 Jul 2022 07:52:37 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfv-002jL2-Bo for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qKMuTgZyBMjnNbHnrNnTfnZV0TLakEyEiZz0dtiihIo=; b=Oz7dc981szDrRAYYRCzuLnpLE3 bOs/Hxy3uaUvberbRP48oBLP2nUC2nMqT4iyOBDElUyPoT5j4RPsHFMyb5fY49I76lcAePabqgXie WhWOI6G0jQpGwojVjL5gnqOnwH/ISM/iOf54MkHNUpwdwZvruCVmP8Kgx4OVTWoCK6q/iX7fO7foD M7nM6Jy/WnsmkP2efuyrmi/Bqo2hMYfE4/zs0p7vsYIrUERHzEps6OKLrB1Qhwo4+NDpp0zk12xNn Mi1BvIieVfFljq8riSLv8ix4zL+q+OmqoX4tDP30ea9UxQuUU/may+M48HoJkEhy2NCsoWtthmdiG 3Qztq9Gg==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfk-001Gh1-ML for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:42 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5668674cso36295187b3.8 for ; Fri, 29 Jul 2022 00:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qKMuTgZyBMjnNbHnrNnTfnZV0TLakEyEiZz0dtiihIo=; b=W+/MAQAoPo1ColXaX7DPgbvMppqd8WzaJUGcRdJ+rV/rNpjPxI2RvziikIaLHJS1D0 Bz+7zHE1W+GXAK2jSfU4XFDsjRZrvCieMRzgakrGVtktRLJlL7twEi6clXX+y+jlmM15 JcpJ9MpKtuzH2obtBphdCnHZE7MFcLzJLVcqV8REQvWpMObO4lqEJlCpDIBhr91hCVEd JXnCvFg/8b1xdVFJk7nvVCYG6+b4IIjm1PqMOZvOt3+CKlGhcxSJ+8yUQ3QvXJpAu6YJ UUmD9qNhne3719pqpnnFKlTlPJ74Jm6O44lj8wrQF7TBEVY6EDywEzS9yMFsx2KoGXC2 a5cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qKMuTgZyBMjnNbHnrNnTfnZV0TLakEyEiZz0dtiihIo=; b=JY/YvWUNdjOkyd1kt//YU12lKxcVudue81AfhPnz8yxBeBBEw1rRiBsxwsX/1FSfOT 13rJeDf5c51rWVtqrezULV/IxlJW3EIv+ydxDyB9QtR2ZN4EMALg4dM4KFAx6zb5hIB0 GP9VhmzieotkIecbfnPE+QTGZ/mauFe8zIjDC20altDsWjowfNXbLX38lI+TnlYnJcsw E0MQtb1Tbjy/z1tVvtPqiHK9Cwvse2VUjlLq75mvE/LG3Gj6ijzQBH0MrLOB6pP+XCZG 1S6ZWMTNlP/ToS/ikfqyedXxGg4UlaodoJZt0BjdZHKc1+e3Z2hXkscK+QEJnH9u9q1t Fadg== X-Gm-Message-State: ACgBeo1BJN54LmqnMAOJnNHLn3fvcPQHPM+9GuB7g9ORUiietRq2kFTg Ny7Scuj3V8C1Tsy/kQ1FWY5BJbEwvPpX X-Google-Smtp-Source: AA6agR6s9LWrQn3K3TqbvVU8RreNq2Lz8BYST7enJeB+eoMvoH8TswmkS1N2q75d/K/F8IptDLZ7FaLrDg6j X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a81:8396:0:b0:322:ed8f:9bdf with SMTP id t144-20020a818396000000b00322ed8f9bdfmr2090644ywf.455.1659080670292; Fri, 29 Jul 2022 00:44:30 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:45 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-12-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 11/17] perf test: Use full metric resolution 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084438_169782_6F53E9F5 X-CRM114-Status: GOOD ( 24.78 ) 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 simple metric resolution doesn't handle recursion properly, switch to use the full resolution as with the parse-metric tests which also increases coverage. Don't set the values for the metric backward as failures to generate a result are ignored. Signed-off-by: Ian Rogers --- tools/perf/tests/pmu-events.c | 222 ++++++++++++---------------------- 1 file changed, 77 insertions(+), 145 deletions(-) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index ea8b41b5c4e3..e8df6bc26ebd 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -9,10 +9,12 @@ #include #include "debug.h" #include "../pmu-events/pmu-events.h" +#include #include "util/evlist.h" #include "util/expr.h" #include "util/parse-events.h" #include "metricgroup.h" +#include "stat.h" struct perf_pmu_test_event { /* used for matching against events from generated pmu-events.c */ @@ -801,27 +803,6 @@ static int check_parse_id(const char *id, struct parse_events_error *error, return ret; } -static int check_parse_cpu(const char *id, bool same_cpu, const struct pmu_event *pe) -{ - struct parse_events_error error; - int ret; - - parse_events_error__init(&error); - ret = check_parse_id(id, &error, NULL); - if (ret && same_cpu) { - pr_warning("Parse event failed metric '%s' id '%s' expr '%s'\n", - pe->metric_name, id, pe->metric_expr); - pr_warning("Error string '%s' help '%s'\n", error.str, - error.help); - } else if (ret) { - pr_debug3("Parse event failed, but for an event that may not be supported by this CPU.\nid '%s' metric '%s' expr '%s'\n", - id, pe->metric_name, pe->metric_expr); - ret = 0; - } - parse_events_error__exit(&error); - return ret; -} - static int check_parse_fake(const char *id) { struct parse_events_error error; @@ -838,160 +819,111 @@ struct metric { struct metric_ref metric_ref; }; -static int resolve_metric_simple(struct expr_parse_ctx *pctx, - struct list_head *compound_list, - const struct pmu_event *map, - const char *metric_name) -{ - struct hashmap_entry *cur, *cur_tmp; - struct metric *metric, *tmp; - size_t bkt; - bool all; - int rc; - - do { - all = true; - hashmap__for_each_entry_safe(pctx->ids, cur, cur_tmp, bkt) { - struct metric_ref *ref; - const struct pmu_event *pe; - - pe = metricgroup__find_metric(cur->key, map); - if (!pe) - continue; - - if (!strcmp(metric_name, (char *)cur->key)) { - pr_warning("Recursion detected for metric %s\n", metric_name); - rc = -1; - goto out_err; - } - - all = false; - - /* The metric key itself needs to go out.. */ - expr__del_id(pctx, cur->key); - - metric = malloc(sizeof(*metric)); - if (!metric) { - rc = -ENOMEM; - goto out_err; - } - - ref = &metric->metric_ref; - ref->metric_name = pe->metric_name; - ref->metric_expr = pe->metric_expr; - list_add_tail(&metric->list, compound_list); - - rc = expr__find_ids(pe->metric_expr, NULL, pctx); - if (rc) - goto out_err; - break; /* The hashmap has been modified, so restart */ - } - } while (!all); - - return 0; - -out_err: - list_for_each_entry_safe(metric, tmp, compound_list, list) - free(metric); - - return rc; - -} - -static void expr_failure(const char *msg, const struct pmu_event *pe) -{ - pr_debug("%s\nOn metric %s\nOn expression %s\n", msg, pe->metric_name, pe->metric_expr); -} - - -struct test__parsing_data { - const struct pmu_event *cpus_table; - struct expr_parse_ctx *ctx; - int failures; -}; - static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_event *table, - void *vdata) + void *data) { - struct test__parsing_data *data = vdata; - struct metric *metric, *tmp; - struct hashmap_entry *cur; - LIST_HEAD(compound_list); - size_t bkt; + int *failures = data; int k; - double result; + struct evlist *evlist; + struct perf_cpu_map *cpus; + struct runtime_stat st; + struct evsel *evsel; + struct rblist metric_events = { + .nr_entries = 0, + }; + int err = 0; if (!pe->metric_expr) return 0; pr_debug("Found metric '%s'\n", pe->metric_name); + (*failures)++; - expr__ctx_clear(data->ctx); - if (expr__find_ids(pe->metric_expr, NULL, data->ctx) < 0) { - expr_failure("Parse find ids failed", pe); - data->failures++; - return 0; + /* + * We need to prepare evlist for stat mode running on CPU 0 + * because that's where all the stats are going to be created. + */ + evlist = evlist__new(); + if (!evlist) + return -ENOMEM; + + cpus = perf_cpu_map__new("0"); + if (!cpus) { + evlist__delete(evlist); + return -ENOMEM; } - if (resolve_metric_simple(data->ctx, &compound_list, table, - pe->metric_name)) { - expr_failure("Could not resolve metrics", pe); - data->failures++; - return TEST_FAIL; /* Don't tolerate errors due to severity */ + perf_evlist__set_maps(&evlist->core, cpus, NULL); + runtime_stat__init(&st); + + err = metricgroup__parse_groups_test(evlist, table, pe->metric_name, + false, false, + &metric_events); + if (err) { + if (!strcmp(pe->metric_name, "M1") || !strcmp(pe->metric_name, "M2") || + !strcmp(pe->metric_name, "M3")) { + (*failures)--; + pr_debug("Expected broken metric %s skipping\n", pe->metric_name); + err = 0; + } + goto out_err; } + err = evlist__alloc_stats(evlist, false); + if (err) + goto out_err; /* * Add all ids with a made up value. The value may trigger divide by * zero when subtracted and so try to make them unique. */ k = 1; - hashmap__for_each_entry(data->ctx->ids, cur, bkt) - expr__add_id_val(data->ctx, strdup(cur->key), k++); - - hashmap__for_each_entry(data->ctx->ids, cur, bkt) { - if (check_parse_cpu(cur->key, table == data->cpus_table, pe)) - data->failures++; + perf_stat__reset_shadow_stats(); + evlist__for_each_entry(evlist, evsel) { + perf_stat__update_shadow_stats(evsel, k, 0, &st); + if (!strcmp(evsel->name, "duration_time")) + update_stats(&walltime_nsecs_stats, k); + k++; } + evlist__for_each_entry(evlist, evsel) { + struct metric_event *me = metricgroup__lookup(&metric_events, evsel, false); - list_for_each_entry_safe(metric, tmp, &compound_list, list) { - expr__add_ref(data->ctx, &metric->metric_ref); - free(metric); - } + if (me != NULL) { + struct metric_expr *mexp; - if (expr__parse(&result, data->ctx, pe->metric_expr)) { - /* - * Parsing failed, make numbers go from large to small which can - * resolve divide by zero issues. - */ - k = 1024; - hashmap__for_each_entry(data->ctx->ids, cur, bkt) - expr__add_id_val(data->ctx, strdup(cur->key), k--); - if (expr__parse(&result, data->ctx, pe->metric_expr)) { - expr_failure("Parse failed", pe); - data->failures++; + list_for_each_entry (mexp, &me->head, nd) { + if (strcmp(mexp->metric_name, pe->metric_name)) + continue; + pr_debug("Result %f\n", test_generic_metric(mexp, 0, &st)); + err = 0; + (*failures)--; + goto out_err; + } } } - return 0; + pr_debug("Didn't find parsed metric %s", pe->metric_name); + err = 1; +out_err: + if (err) + pr_debug("Broken metric %s\n", pe->metric_name); + + /* ... cleanup. */ + metricgroup__rblist_exit(&metric_events); + runtime_stat__exit(&st); + evlist__free_stats(evlist); + perf_cpu_map__put(cpus); + evlist__delete(evlist); + return err; } static int test__parsing(struct test_suite *test __maybe_unused, int subtest __maybe_unused) { - struct test__parsing_data data = { - .cpus_table = pmu_events_map__find(), - .ctx = expr__ctx_new(), - .failures = 0, - }; + int failures = 0; - if (!data.ctx) { - pr_debug("expr__ctx_new failed"); - return TEST_FAIL; - } - pmu_for_each_core_event(test__parsing_callback, &data); - pmu_for_each_sys_event(test__parsing_callback, &data); + pmu_for_each_core_event(test__parsing_callback, &failures); + pmu_for_each_sys_event(test__parsing_callback, &failures); - expr__ctx_free(data.ctx); - return data.failures == 0 ? TEST_OK : TEST_FAIL; + return failures == 0 ? TEST_OK : TEST_FAIL; } struct test_metric { From patchwork Fri Jul 29 07:43:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932102 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 67C62C00144 for ; Fri, 29 Jul 2022 07:50:08 +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=3dzXvCh4t4Og/2QGXVo9ebKkvTherbUJ4qBOZ47WRWs=; b=BMkvaDtwRlG3f2k+BXEhiNc0Py AgNzr6Xa5s7aNl3tRRYnSFZq5Sd3Bn9py9SLntZU+UbYnBCetIrUDBoJa6NGKv48/5Vsr/GcdoNRK rDCdkmyEv2lMgOILmcOEeUNW9418XRJEKJFl+ufUa0/X2fmGMpyfy/faGROXP3fj9ZnnxNnMHWCW/ mCtB/WkxjGHdk1XQ/L2KwuXUwiP+d1Vgm4oVYvwGAtbKs5h5MgCQNzfGYnkplCWRAdSGRrurN3lxu /DMKgS3pD+e9mQxkFr3KZqrNSbRZpUiAXCHCWt4oHTDpuU5B8LsaBIPCD+DaCJtn8hqTI45Is5hCi cP0+0bzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKjn-002lM5-Ca; Fri, 29 Jul 2022 07:48:48 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKft-002jL2-6u for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=1Fnwkxe00fzii+/AdoCdigiKOH/6tox9V/XrXmPYCso=; b=A/aIj6NVp/L1KCQHGXEywioIUV rIv2IRsQ1TeULoNdtjvHwtjkSNRMLoiHoVadOy4HQJA142Y7k5/Qk+kV7lMiY+PkQkMESJu92RB7u rJIp/DdyYiOckMzTiHI8wJdWbrNRRJwEnj8zN5/mJS6H5TtGbir3UZ21KJLDzUMLwko+UKPVjYAdJ XVa+eWhvljOYmlQkDfgVeNV9LG2KXRBHAV0eTEYdP5XG5kHPaTmarXC1j8qAv5Xc9XTbhLkwtn5rZ oMe522MlgOXvkaW2NvCXJ5PhxV1kRM2sSgpae7F19wPkCIDmg7PiBaqSPGUik61ZvrambdN86ujuC j4b9/SZQ==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfj-001GhB-9h for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:40 +0000 Received: by mail-yb1-xb49.google.com with SMTP id m11-20020a5b040b000000b0066fcc60d1a0so3288109ybp.19 for ; Fri, 29 Jul 2022 00:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1Fnwkxe00fzii+/AdoCdigiKOH/6tox9V/XrXmPYCso=; b=KYiw9jpWBj6G9TItyX5toEX3s7SmRCn3h0SsaT9E5DY3Eeb7n+mbNqbpvCOqpDk5Mt DlxxHR8Oftf3ajn7jgtyfT1OYbIjtdkln/z2Ll8LF7AVkCsqsabrRzOV9yzh9frJo2Rt /OM5FyBERW9J9pz8+Hv0dAqRIvTatVBtfOOvGqIJnNeFzOyK54JZQOxLlhPgR1KxQSsx fnlf6A+lKKopZgQ9LTC9dBMrcXnV1ZGS/8DbX6IcQbdprU0hU85XOgJuxVYY3DXAL/qz Vr23ZMuq2pwROKS+bRSb4P+Q5BHCrCBtJOaAeaC2+mex2FPAtW+tfQQecSNzkvD78uiF +EKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1Fnwkxe00fzii+/AdoCdigiKOH/6tox9V/XrXmPYCso=; b=lXxUPDJSi4MibNWGEP+JpnRc1ULwgXXiPHbIv1rqObzhiddoENzdyOInvnKt8r95V6 yee01Mc/o+7YVm2FxyTe2Mj/uPk92g6Fb1zgSo+kNsuKA8KSGyuPXZrYr1DkmqVvcxdJ oNTRcIeQahXg9EKDF68biZL6aTUB/WRQcUD1duviRnI24bo3Hn9GlIFm4ZpGha+fr8NN 2lyCR9yhuW07xZp6fr03t14jUvBIo3v/PmCvR3AfUylncPSlRmUbgYHc2z6lQiid+P3f JVqUkzmWjWCxmpdo8RFIJqcqp6Uc724ZjTIAaORQShKA1ZsNzqINx5llyocxT7WN4fw0 lx/Q== X-Gm-Message-State: ACgBeo3Xtt+M6CU/lEhrVS8fHwd1zM+2s8mls66iJ5tRI7u+jcH8vkIb MQM4qaE07rmSeA3TAtCH9vjAK1P1Ve96 X-Google-Smtp-Source: AA6agR4LYFC6eDgwM7HD1rQOkSGD5tFgKlNRIBx/0KWnLUZpogsWNMU6BPKOQadFEP95olksrb3ofYrq4Bey X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a05:6902:150c:b0:670:af5c:c431 with SMTP id q12-20020a056902150c00b00670af5cc431mr1659343ybu.37.1659080672858; Fri, 29 Jul 2022 00:44:32 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:46 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-13-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 12/17] perf pmu-events: Move test events/metrics to json 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084437_098595_BFF055E6 X-CRM114-Status: GOOD ( 18.54 ) 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 Move arrays of pmu_events into the json code so that it may be regenerated and modified by the jevents.py script. Signed-off-by: Ian Rogers --- .../arch/test/test_soc/cpu/metrics.json | 64 +++++++++++++++++ tools/perf/pmu-events/empty-pmu-events.c | 64 +++++++++++++++++ tools/perf/tests/expand-cgroup.c | 17 +---- tools/perf/tests/parse-metric.c | 68 +------------------ 4 files changed, 132 insertions(+), 81 deletions(-) create mode 100644 tools/perf/pmu-events/arch/test/test_soc/cpu/metrics.json diff --git a/tools/perf/pmu-events/arch/test/test_soc/cpu/metrics.json b/tools/perf/pmu-events/arch/test/test_soc/cpu/metrics.json new file mode 100644 index 000000000000..42d9b5242fd7 --- /dev/null +++ b/tools/perf/pmu-events/arch/test/test_soc/cpu/metrics.json @@ -0,0 +1,64 @@ +[ + { + "MetricExpr": "1 / IPC", + "MetricName": "CPI" + }, + { + "MetricExpr": "inst_retired.any / cpu_clk_unhalted.thread", + "MetricName": "IPC", + "MetricGroup": "group1" + }, + { + "MetricExpr": "idq_uops_not_delivered.core / (4 * (( ( cpu_clk_unhalted.thread / 2 ) * ( 1 + cpu_clk_unhalted.one_thread_active / cpu_clk_unhalted.ref_xclk ) )))", + "MetricName": "Frontend_Bound_SMT" + }, + { + "MetricExpr": "l1d\\-loads\\-misses / inst_retired.any", + "MetricName": "dcache_miss_cpi" + }, + { + "MetricExpr": "l1i\\-loads\\-misses / inst_retired.any", + "MetricName": "icache_miss_cycles" + }, + { + "MetricExpr": "(dcache_miss_cpi + icache_miss_cycles)", + "MetricName": "cache_miss_cycles", + "MetricGroup": "group1" + }, + { + "MetricExpr": "l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit", + "MetricName": "DCache_L2_All_Hits" + }, + { + "MetricExpr": "max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss", + "MetricName": "DCache_L2_All_Miss" + }, + { + "MetricExpr": "dcache_l2_all_hits + dcache_l2_all_miss", + "MetricName": "DCache_L2_All" + }, + { + "MetricExpr": "d_ratio(dcache_l2_all_hits, dcache_l2_all)", + "MetricName": "DCache_L2_Hits" + }, + { + "MetricExpr": "d_ratio(dcache_l2_all_miss, dcache_l2_all)", + "MetricName": "DCache_L2_Misses" + }, + { + "MetricExpr": "ipc + M2", + "MetricName": "M1" + }, + { + "MetricExpr": "ipc + M1", + "MetricName": "M2" + }, + { + "MetricExpr": "1/M3", + "MetricName": "M3" + }, + { + "MetricExpr": "64 * l1d.replacement / 1000000000 / duration_time", + "MetricName": "L1D_Cache_Fill_BW" + } +] diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 8ef75aff996c..028f44efe48d 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -105,6 +105,70 @@ static const struct pmu_event pme_test_soc_cpu[] = { .desc = "L2 BTB Correction", .topic = "branch", }, + { + .metric_expr = "1 / IPC", + .metric_name = "CPI", + }, + { + .metric_expr = "inst_retired.any / cpu_clk_unhalted.thread", + .metric_name = "IPC", + .metric_group = "group1", + }, + { + .metric_expr = "idq_uops_not_delivered.core / (4 * (( ( cpu_clk_unhalted.thread / 2 ) * " + "( 1 + cpu_clk_unhalted.one_thread_active / cpu_clk_unhalted.ref_xclk ) )))", + .metric_name = "Frontend_Bound_SMT", + }, + { + .metric_expr = "l1d\\-loads\\-misses / inst_retired.any", + .metric_name = "dcache_miss_cpi", + }, + { + .metric_expr = "l1i\\-loads\\-misses / inst_retired.any", + .metric_name = "icache_miss_cycles", + }, + { + .metric_expr = "(dcache_miss_cpi + icache_miss_cycles)", + .metric_name = "cache_miss_cycles", + .metric_group = "group1", + }, + { + .metric_expr = "l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit", + .metric_name = "DCache_L2_All_Hits", + }, + { + .metric_expr = "max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + " + "l2_rqsts.pf_miss + l2_rqsts.rfo_miss", + .metric_name = "DCache_L2_All_Miss", + }, + { + .metric_expr = "dcache_l2_all_hits + dcache_l2_all_miss", + .metric_name = "DCache_L2_All", + }, + { + .metric_expr = "d_ratio(dcache_l2_all_hits, dcache_l2_all)", + .metric_name = "DCache_L2_Hits", + }, + { + .metric_expr = "d_ratio(dcache_l2_all_miss, dcache_l2_all)", + .metric_name = "DCache_L2_Misses", + }, + { + .metric_expr = "ipc + M2", + .metric_name = "M1", + }, + { + .metric_expr = "ipc + M1", + .metric_name = "M2", + }, + { + .metric_expr = "1/M3", + .metric_name = "M3", + }, + { + .metric_expr = "64 * l1d.replacement / 1000000000 / duration_time", + .metric_name = "L1D_Cache_Fill_BW", + }, { .name = 0, .event = 0, diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index 411fc578e5a4..e79ee8621a90 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -180,26 +180,13 @@ static int expand_metric_events(void) struct evlist *evlist; struct rblist metric_events; const char metric_str[] = "CPI"; - - struct pmu_event pme_test[] = { - { - .metric_expr = "instructions / cycles", - .metric_name = "IPC", - }, - { - .metric_expr = "1 / IPC", - .metric_name = "CPI", - }, - { - .metric_expr = NULL, - .metric_name = NULL, - }, - }; + const struct pmu_event *pme_test; evlist = evlist__new(); TEST_ASSERT_VAL("failed to get evlist", evlist); rblist__init(&metric_events); + pme_test = find_core_events_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 7aebde7c37ec..30c7091857b8 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -13,72 +13,6 @@ #include "stat.h" #include "pmu.h" -static struct pmu_event pme_test[] = { -{ - .metric_expr = "inst_retired.any / cpu_clk_unhalted.thread", - .metric_name = "IPC", - .metric_group = "group1", -}, -{ - .metric_expr = "idq_uops_not_delivered.core / (4 * (( ( cpu_clk_unhalted.thread / 2 ) * " - "( 1 + cpu_clk_unhalted.one_thread_active / cpu_clk_unhalted.ref_xclk ) )))", - .metric_name = "Frontend_Bound_SMT", -}, -{ - .metric_expr = "l1d\\-loads\\-misses / inst_retired.any", - .metric_name = "dcache_miss_cpi", -}, -{ - .metric_expr = "l1i\\-loads\\-misses / inst_retired.any", - .metric_name = "icache_miss_cycles", -}, -{ - .metric_expr = "(dcache_miss_cpi + icache_miss_cycles)", - .metric_name = "cache_miss_cycles", - .metric_group = "group1", -}, -{ - .metric_expr = "l2_rqsts.demand_data_rd_hit + l2_rqsts.pf_hit + l2_rqsts.rfo_hit", - .metric_name = "DCache_L2_All_Hits", -}, -{ - .metric_expr = "max(l2_rqsts.all_demand_data_rd - l2_rqsts.demand_data_rd_hit, 0) + " - "l2_rqsts.pf_miss + l2_rqsts.rfo_miss", - .metric_name = "DCache_L2_All_Miss", -}, -{ - .metric_expr = "dcache_l2_all_hits + dcache_l2_all_miss", - .metric_name = "DCache_L2_All", -}, -{ - .metric_expr = "d_ratio(dcache_l2_all_hits, dcache_l2_all)", - .metric_name = "DCache_L2_Hits", -}, -{ - .metric_expr = "d_ratio(dcache_l2_all_miss, dcache_l2_all)", - .metric_name = "DCache_L2_Misses", -}, -{ - .metric_expr = "ipc + m2", - .metric_name = "M1", -}, -{ - .metric_expr = "ipc + m1", - .metric_name = "M2", -}, -{ - .metric_expr = "1/m3", - .metric_name = "M3", -}, -{ - .metric_expr = "64 * l1d.replacement / 1000000000 / duration_time", - .metric_name = "L1D_Cache_Fill_BW", -}, -{ - .name = NULL, -} -}; - struct value { const char *event; u64 val; @@ -138,6 +72,7 @@ static int __compute_metric(const char *name, struct value *vals, struct rblist metric_events = { .nr_entries = 0, }; + const struct pmu_event *pme_test; struct perf_cpu_map *cpus; struct runtime_stat st; struct evlist *evlist; @@ -161,6 +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"); err = metricgroup__parse_groups_test(evlist, pme_test, name, false, false, &metric_events); From patchwork Fri Jul 29 07:43:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932105 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 76E38C00144 for ; Fri, 29 Jul 2022 07:52:56 +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=DlpFlcdryLhm8zEBq87jesDt6U6HLCVF0QCSo3dZ9bY=; b=P3qm26WJCJVBBFqApOrbH3133D 49QI5TDFNARLWlacaJFP6ydwzlE/uWLwD8/S+5/syXCshj1NGXhyd0yFsW3qe1XAfTgNqCWUa9J+Y Ow1SFmG+EjAETRGNkPyGGRPjqm6ClWVipoluVztEwA0f84I87wIn8nUK7ev9L7Vj6/2vQ1tyemTEr By60w7fHEoY+w1NDQfYkzYVKwzEIAn8Ei2rx0xXsJU1H+s9e6XyFy7ajmwR0pwoVN0CFtAV9iKBGA 5gy4XXaMKnJmUMCVW+nNnM4eKjUvKi9t8G/RAiiaLNY0LjCnqnhjg/os/vn0kFaQvGtImcZeY8SfY oj7cvXQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKmM-002mcc-6X; Fri, 29 Jul 2022 07:51:26 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfu-002jL2-TY for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Nie16ezqAkT8oDeGxazLBU2pNUTiS13bS4q6/UMs4OA=; b=JycuC/h7OAaa3GF70Q77lNN+1r G767xc1T/sRTN2RFGt007yVlPIQ/BHqstl5W97C5Cv6viMjlCp5FiPFyhMXuimwyaKMqngv4ixK9y kbKSkjE4W2VeLgJSs0AY8cr/wYYe+n7mQEF0iMnPUh0+1RM3KdyKFus7S2bUH1ugnM2RT1ISh59jQ ZLCYmXz36iXrzCtNv77eDb9wBX9kSDhbSIdNBjog89XI5IKwagjPQl17oi03JgBGfzCzMEn4eZblG H9YbqnNxcoocgtMCO7KY79WRNUCojgN3+A8oIMYRIkIm6rI7I0yMjQxrrqnwFl/1NSsZ7KphNkfaT ax9xadZw==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfm-001GhK-0H for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:42 +0000 Received: by mail-yb1-xb49.google.com with SMTP id w3-20020a258503000000b00676bd41edabso219342ybk.5 for ; Fri, 29 Jul 2022 00:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Nie16ezqAkT8oDeGxazLBU2pNUTiS13bS4q6/UMs4OA=; b=I4IQ0hmU15xVKngOlZUJG/64xEoagipU4FfK9PDANYimvs6WrXP4n4rPQKo6nhe1BL rrpFhf+g8Uychwj34RpHHDoeHoei5BLsRZL7eh6p9kA7oKNw0y/YQsqOGBYP3Tbg3kiv WqNpPtHJyR0dzSlwgHwDbJoXcQ22KHAtaarl1LxvQi+gZB0oiswp+E3qDf0dlXqmLM98 TXXAJxITDVTZICDxoD1qqmCctstu07QkByAMkbwtLr7JZKVqYIcL9VXfVK1r3J6fpewz 4efacmwBFk1CO17O4w14ZvA8vlNh0Cmc7vl7W565LdWlDtYlKDnECIPJ26qZdCnELgWc 6oGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Nie16ezqAkT8oDeGxazLBU2pNUTiS13bS4q6/UMs4OA=; b=Q8gUzsrPZB9/BCB8hWN20rY4bBXiSE/q2EmD3GBq2zD9vazquftv7bUsunZALkO52/ BOIVJpfSnXmjeEm7w7lnC/xrBvtUwRp6JpvaslhaC425qMr2nsurX0J7aoi0PBVZY7Gw sJk7H/G7ovaTejEpxdwmXTV0TilYau+O+uS4AtHWMjnwkg4rRXWSWQKqFDba0ZIFdE/D K+zfWxou7n4ssKNt5OxBmI/w5bz1iHuRuqBaUIyzP/3MS3TmsvHrX7GpBTkFxYUqZ+yU 0gPe9ZwaYy4MGf5LXHxJKarpfJTo0Rl/Rno5+3i2x8vIFQJ3fybTmFJfhCM9VOtD/Hd8 /NGg== X-Gm-Message-State: ACgBeo1uGeAcydRi6BzFDJ8G010K33uF/hYeuWTnD69WMHZ9tzoenQ2N f+Kgjq7CNsI94TcqUlC7huvZuUxSuU+A X-Google-Smtp-Source: AA6agR58xrTHINBcIHmygNCoNROVgasw5mDApSTlMhqeU5Yj+vZW9bTi8O7i/Nbl1MEyCviYrFR9sAbwVrCR X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a81:2f8a:0:b0:31e:7c60:5d61 with SMTP id v132-20020a812f8a000000b0031e7c605d61mr2073897ywv.6.1659080675636; Fri, 29 Jul 2022 00:44:35 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:47 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-14-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 13/17] perf pmu-events: Don't assume pmu_event is an array 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084439_198281_3AAF977D X-CRM114-Status: GOOD ( 21.55 ) 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 Current code assumes that a struct pmu_event can be iterated over forward until a NULL pmu_event is encountered. This makes it difficult to refactor pmu_event. Add a loop function taking a callback function that's passed the struct pmu_event. This way the pmu_event is only needed for one element and not an entire array. Switch existing code iterating over the pmu_event arrays to use the new loop function pmu_events_table_for_each_event. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 34 +++-- tools/perf/pmu-events/jevents.py | 34 +++-- tools/perf/pmu-events/pmu-events.h | 3 + tools/perf/tests/pmu-events.c | 136 +++++++++-------- tools/perf/util/metricgroup.c | 181 ++++++++++++++++------- tools/perf/util/pmu.c | 65 ++++---- tools/perf/util/s390-sample-raw.c | 42 ++++-- 7 files changed, 313 insertions(+), 182 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index 028f44efe48d..bee1967baa2b 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -247,6 +247,20 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { }, }; +int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, + void *data) +{ + for (const struct pmu_event *pe = &table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, table, data); + + if (ret) + return ret; + } + return 0; +} + const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) { const struct pmu_event *table = NULL; @@ -291,14 +305,10 @@ 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->table; tables++) { - for (const struct pmu_event *pe = &tables->table[0]; - pe->name || pe->metric_group || pe->metric_name; - pe++) { - int ret = fn(pe, &tables->table[0], data); + int ret = pmu_events_table_for_each_event(tables->table, fn, data); - if (ret) - return ret; - } + if (ret) + return ret; } return 0; } @@ -319,14 +329,10 @@ 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++) { - for (const struct pmu_event *pe = &tables->table[0]; - pe->name || pe->metric_group || pe->metric_name; - pe++) { - int ret = fn(pe, &tables->table[0], data); + int ret = pmu_events_table_for_each_event(tables->table, fn, data); - if (ret) - return ret; - } + if (ret) + return ret; } return 0; } diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index e976c5e8e80b..365c960202b0 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -409,6 +409,20 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { \t}, }; +int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, + void *data) +{ + for (const struct pmu_event *pe = &table[0]; + pe->name || pe->metric_group || pe->metric_name; + pe++) { + int ret = fn(pe, table, data); + + if (ret) + return ret; + } + return 0; +} + const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) { const struct pmu_event *table = NULL; @@ -452,14 +466,10 @@ 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->table; tables++) { - for (const struct pmu_event *pe = &tables->table[0]; - pe->name || pe->metric_group || pe->metric_name; - pe++) { - int ret = fn(pe, &tables->table[0], data); + int ret = pmu_events_table_for_each_event(tables->table, fn, data); - if (ret) - return ret; - } + if (ret) + return ret; } return 0; } @@ -480,14 +490,10 @@ 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++) { - for (const struct pmu_event *pe = &tables->table[0]; - pe->name || pe->metric_group || pe->metric_name; - pe++) { - int ret = fn(pe, &tables->table[0], data); + int ret = pmu_events_table_for_each_event(tables->table, fn, data); - if (ret) - return ret; - } + 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 485e730f9922..70672842f77f 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -34,6 +34,9 @@ typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, const struct pmu_event *table, void *data); +int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, + void *data); + const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu); const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid); int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index e8df6bc26ebd..1c3479e5890e 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -423,84 +423,104 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, return 0; } -/* Verify generated events from pmu-events.c are as expected */ -static int test__pmu_event_table(struct test_suite *test __maybe_unused, - int subtest __maybe_unused) +static int test__pmu_event_table_core_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data) { - const struct pmu_event *sys_event_tables = find_sys_events_table("pme_test_soc_sys"); - const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); - int map_events = 0, expected_events; + int *map_events = data; + struct perf_pmu_test_event const **test_event_table; + bool found = false; - /* ignore 3x sentinels */ - expected_events = ARRAY_SIZE(core_events) + - ARRAY_SIZE(uncore_events) + - ARRAY_SIZE(sys_events) - 3; + if (!pe->name) + return 0; - if (!table || !sys_event_tables) - return -1; + if (pe->pmu) + test_event_table = &uncore_events[0]; + else + test_event_table = &core_events[0]; - for (; table->name; table++) { - struct perf_pmu_test_event const **test_event_table; - bool found = false; + for (; *test_event_table; test_event_table++) { + struct perf_pmu_test_event const *test_event = *test_event_table; + struct pmu_event const *event = &test_event->event; - if (table->pmu) - test_event_table = &uncore_events[0]; - else - test_event_table = &core_events[0]; + if (strcmp(pe->name, event->name)) + continue; + found = true; + (*map_events)++; - for (; *test_event_table; test_event_table++) { - struct perf_pmu_test_event const *test_event = *test_event_table; - struct pmu_event const *event = &test_event->event; + if (compare_pmu_events(pe, event)) + return -1; - if (strcmp(table->name, event->name)) - continue; - found = true; - map_events++; + pr_debug("testing event table %s: pass\n", pe->name); + } + if (!found) { + pr_err("testing event table: could not find event %s\n", pe->name); + return -1; + } + return 0; +} - if (compare_pmu_events(table, event)) - return -1; +static int test__pmu_event_table_sys_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *data) +{ + int *map_events = data; + struct perf_pmu_test_event const **test_event_table; + bool found = false; - pr_debug("testing event table %s: pass\n", table->name); - } + test_event_table = &sys_events[0]; - if (!found) { - pr_err("testing event table: could not find event %s\n", - table->name); - return -1; - } - } + for (; *test_event_table; test_event_table++) { + struct perf_pmu_test_event const *test_event = *test_event_table; + struct pmu_event const *event = &test_event->event; - for (table = sys_event_tables; table->name; table++) { - struct perf_pmu_test_event const **test_event_table; - bool found = false; + if (strcmp(pe->name, event->name)) + continue; + found = true; + (*map_events)++; - test_event_table = &sys_events[0]; + if (compare_pmu_events(pe, event)) + return TEST_FAIL; - for (; *test_event_table; test_event_table++) { - struct perf_pmu_test_event const *test_event = *test_event_table; - struct pmu_event const *event = &test_event->event; + pr_debug("testing sys event table %s: pass\n", pe->name); + } + if (!found) { + pr_debug("testing sys event table: could not find event %s\n", pe->name); + return TEST_FAIL; + } + return TEST_OK; +} - if (strcmp(table->name, event->name)) - continue; - found = true; - map_events++; +/* Verify generated events from pmu-events.c are as expected */ +static int test__pmu_event_table(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + const struct pmu_event *sys_event_table = find_sys_events_table("pme_test_soc_sys"); + const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); + int map_events = 0, expected_events, err; - if (compare_pmu_events(table, event)) - return -1; + /* ignore 3x sentinels */ + expected_events = ARRAY_SIZE(core_events) + + ARRAY_SIZE(uncore_events) + + ARRAY_SIZE(sys_events) - 3; - pr_debug("testing sys event table %s: pass\n", table->name); - } - if (!found) { - pr_debug("testing event table: could not find event %s\n", - table->name); - return -1; - } - } + if (!table || !sys_event_table) + return -1; + + err = pmu_events_table_for_each_event(table, test__pmu_event_table_core_callback, + &map_events); + if (err) + return err; + + err = pmu_events_table_for_each_event(sys_event_table, test__pmu_event_table_sys_callback, + &map_events); + if (err) + return err; if (map_events != expected_events) { pr_err("testing event table: found %d, but expected %d\n", map_events, expected_events); - return -1; + return TEST_FAIL; } return 0; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 680f7c63838d..f702b73a7609 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -538,12 +538,40 @@ static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, d->details, d->groups, d->metriclist); } +struct metricgroup_print_data { + const char *pmu_name; + struct strlist *metriclist; + char *filter; + struct rblist *groups; + bool metricgroups; + bool raw; + bool details; +}; + +static int metricgroup__print_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *vdata) +{ + struct metricgroup_print_data *data = vdata; + + if (!pe->metric_expr) + return 0; + + if (data->pmu_name && perf_pmu__is_hybrid(pe->pmu) && strcmp(data->pmu_name, pe->pmu)) + return 0; + + return metricgroup__print_pmu_event(pe, data->metricgroups, data->filter, + data->raw, data->details, data->groups, + data->metriclist); +} + void metricgroup__print(bool metrics, bool metricgroups, char *filter, bool raw, bool details, const char *pmu_name) { struct rblist groups; struct rb_node *node, *next; struct strlist *metriclist = NULL; + const struct pmu_event *table; if (!metricgroups) { metriclist = strlist__new(NULL, NULL); @@ -555,22 +583,22 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; - for (const struct pmu_event *pe = pmu_events_map__find(); pe; pe++) { + table = pmu_events_map__find(); + if (table) { + struct metricgroup_print_data data = { + .pmu_name = pmu_name, + .metriclist = metriclist, + .metricgroups = metricgroups, + .filter = filter, + .raw = raw, + .details = details, + .groups = &groups, + }; - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - if (!pe->metric_expr) - continue; - if (pmu_name && perf_pmu__is_hybrid(pe->pmu) && - strcmp(pmu_name, pe->pmu)) { - continue; - } - if (metricgroup__print_pmu_event(pe, metricgroups, filter, - raw, details, &groups, - metriclist) < 0) - return; + pmu_events_table_for_each_event(table, + metricgroup__print_callback, + &data); } - { struct metricgroup_iter_data data = { .fn = metricgroup__print_sys_event_iter, @@ -1043,30 +1071,35 @@ static int __add_metric(struct list_head *metric_list, return ret; } -#define table_for_each_event(__pe, __idx, __table) \ - if (__table) \ - for (__idx = 0, __pe = &__table[__idx]; \ - __pe->name || __pe->metric_group || __pe->metric_name; \ - __pe = &__table[++__idx]) +struct metricgroup__find_metric_data { + const char *metric; + const struct pmu_event *pe; +}; + +static int metricgroup__find_metric_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *vdata) +{ + struct metricgroup__find_metric_data *data = vdata; + + if (!match_metric(pe->metric_name, data->metric)) + return 0; -#define table_for_each_metric(__pe, __idx, __table, __metric) \ - table_for_each_event(__pe, __idx, __table) \ - if (__pe->metric_expr && \ - (match_metric(__pe->metric_group, __metric) || \ - match_metric(__pe->metric_name, __metric))) + data->pe = pe; + return -1; +} const struct pmu_event *metricgroup__find_metric(const char *metric, const struct pmu_event *table) { - const struct pmu_event *pe; - int i; + struct metricgroup__find_metric_data data = { + .metric = metric, + .pe = NULL, + }; - table_for_each_event(pe, i, table) { - if (match_metric(pe->metric_name, metric)) - return pe; - } + pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data); - return NULL; + return data.pe; } static int add_metric(struct list_head *metric_list, @@ -1151,6 +1184,33 @@ static int metric_list_cmp(void *priv __maybe_unused, const struct list_head *l, return right_count - left_count; } +struct metricgroup__add_metric_data { + struct list_head *list; + const char *metric_name; + const char *modifier; + bool metric_no_group; + bool has_match; +}; + +static int metricgroup__add_metric_callback(const struct pmu_event *pe, + const struct pmu_event *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))) { + + data->has_match = true; + ret = add_metric(data->list, pe, data->modifier, data->metric_no_group, + /*root_metric=*/NULL, + /*visited_metrics=*/NULL, table); + } + return ret; +} + /** * metricgroup__add_metric - Find and add a metric, or a metric group. * @metric_name: The name of the metric or metric group. For example, "IPC" @@ -1169,24 +1229,29 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier struct list_head *metric_list, const struct pmu_event *table) { - const struct pmu_event *pe; LIST_HEAD(list); - int i, ret; + int ret; bool has_match = false; - /* - * Iterate over all metrics seeing if metric matches either the name or - * group. When it does add the metric to the list. - */ - table_for_each_metric(pe, i, table, metric_name) { - has_match = true; - ret = add_metric(&list, pe, modifier, metric_no_group, - /*root_metric=*/NULL, - /*visited_metrics=*/NULL, table); + { + struct metricgroup__add_metric_data data = { + .list = &list, + .metric_name = metric_name, + .modifier = modifier, + .metric_no_group = metric_no_group, + .has_match = false, + }; + /* + * 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); if (ret) goto out; - } + has_match = data.has_match; + } { struct metricgroup_iter_data data = { .fn = metricgroup__add_metric_sys_event_iter, @@ -1602,26 +1667,30 @@ int metricgroup__parse_groups_test(struct evlist *evlist, metric_no_merge, &perf_pmu__fake, metric_events, table); } +static int metricgroup__has_metric_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *vdata) +{ + const char *metric = vdata; + + if (!pe->metric_expr) + return 0; + + if (match_metric(pe->metric_name, metric)) + return 1; + + return 0; +} + bool metricgroup__has_metric(const char *metric) { const struct pmu_event *table = pmu_events_map__find(); - const struct pmu_event *pe; - int i; if (!table) return false; - for (i = 0; ; i++) { - pe = &table[i]; - - if (!pe->name && !pe->metric_group && !pe->metric_name) - break; - if (!pe->metric_expr) - continue; - if (match_metric(pe->metric_name, metric)) - return true; - } - return false; + return pmu_events_table_for_each_event(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/pmu.c b/tools/perf/util/pmu.c index 5bb03d4e52a3..ab94d672d7bf 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -791,6 +791,36 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) return res; } +struct pmu_add_cpu_aliases_map_data { + struct list_head *head; + const char *name; + const char *cpu_name; + struct perf_pmu *pmu; +}; + +static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, + const struct pmu_event *table __maybe_unused, + void *vdata) +{ + 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; + + if (strcmp(pname, data->name)) + return 0; + +new_alias: + /* need type casts to override 'const' */ + __perf_pmu__new_alias(data->head, NULL, (char *)pe->name, (char *)pe->desc, + (char *)pe->event, pe); + return 0; +} + /* * From the pmu_events_map, find the table of PMU events that corresponds * to the current running CPU. Then, add all PMU events from that table @@ -799,35 +829,14 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, const struct pmu_event *table) { - int i; - const char *name = pmu->name; - /* - * Found a matching PMU events table. Create aliases - */ - i = 0; - while (1) { - const char *cpu_name = is_arm_pmu_core(name) ? name : "cpu"; - const struct pmu_event *pe = &table[i++]; - const char *pname = pe->pmu ? pe->pmu : cpu_name; - - if (!pe->name) { - if (pe->metric_group || pe->metric_name) - continue; - break; - } - - if (pmu->is_uncore && pmu_uncore_alias_match(pname, name)) - goto new_alias; - - if (strcmp(pname, name)) - continue; + struct pmu_add_cpu_aliases_map_data data = { + .head = head, + .name = pmu->name, + .cpu_name = is_arm_pmu_core(pmu->name) ? pmu->name : "cpu", + .pmu = pmu, + }; -new_alias: - /* need type casts to override 'const' */ - __perf_pmu__new_alias(head, NULL, (char *)pe->name, - (char *)pe->desc, (char *)pe->event, - pe); - } + pmu_events_table_for_each_event(table, pmu_add_cpu_aliases_map_callback, &data); } static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index 1ecb718fc0eb..b1c052c176bb 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -129,6 +129,28 @@ static int get_counterset_start(int setnr) } } +struct get_counter_name_data { + int wanted; + const char *result; +}; + +static int get_counter_name_callback(const struct pmu_event *evp, + const struct pmu_event *table __maybe_unused, + void *vdata) +{ + struct get_counter_name_data *data = vdata; + int rc, event_nr; + + if (evp->name == NULL || evp->event == NULL) + return 0; + rc = sscanf(evp->event, "event=%x", &event_nr); + if (rc == 1 && event_nr == data->wanted) { + data->result = evp->name; + return 1; /* Terminate the search. */ + } + return 0; +} + /* Scan the PMU table and extract the logical name of a counter from the * PMU events table. Input is the counter set and counter number with in the * set. Construct the event number and use this as key. If they match return @@ -137,20 +159,16 @@ static int get_counterset_start(int setnr) */ static const char *get_counter_name(int set, int nr, const struct pmu_event *table) { - int rc, event_nr, wanted = get_counterset_start(set) + nr; + struct get_counter_name_data data = { + .wanted = get_counterset_start(set) + nr, + .result = NULL, + }; - if (table) { - const struct pmu_event *evp = table; + if (!table) + return NULL; - for (; evp->name || evp->event || evp->desc; ++evp) { - if (evp->name == NULL || evp->event == NULL) - continue; - rc = sscanf(evp->event, "event=%x", &event_nr); - if (rc == 1 && event_nr == wanted) - return evp->name; - } - } - return NULL; + pmu_events_table_for_each_event(table, get_counter_name_callback, &data); + return data.result; } static void s390_cpumcfdg_dump(struct perf_sample *sample) From patchwork Fri Jul 29 07:43:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932104 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 AB904C00144 for ; Fri, 29 Jul 2022 07:51: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=0kgPehjGr2JDkDmeWki6ygFWinxcp+Czqvri0R1kl+w=; b=f6JOyQrziGkD1z/kSt1XESSSV5 7Lvy8r/Tp0hv+q0b7+kyHuUnXW2Ue37L1RrOwWPFBxYt43smMpC/F7Hn7WLGNNcXWeFpnYSJVTTAT NrkEsrnvKpAVd0AHRX0N2gsQtpKXTnEGOPEXk5g6KNXQeD800WaTYsxafTnJCSCXwPx6oruxpGjZk KyXR0m1PmLE44JUVyK8pts9jOCsPR8ysn0Gtx0gcsA2huG3sl/9eEXQtuZPYIerI2kgs3Un36moAw SFx9DxzX3tvlNopfebU4LY1EQwZ0cm11GUBtO28t7ZyF3FcQt5UAGN3R5t7Xe2Zn0asr6YAayJiNf 2GATENPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKlB-002m3N-PC; Fri, 29 Jul 2022 07:50:15 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfu-002jL2-A4 for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lbJIQr4Vvv60PESxVdDbhAlSw9LRcNbW3R+YO0jcP94=; b=IQfeY2uB9eyCK5yaAT/HhonxdB rQg2bjNhDElEEHN2nl7tNCsoxyHyRcad6XTT/ZDx+MqS+iSBBzvyzYh1VO3gTv3QBo4d3O8iY/CXr KmsREEudIusez+JUsakEFg6RKPdEhf5++RorNmn5SOcsZNZaQEyZzW1ZnrzcpGMrMB9k/uYoq94Pt YnWUvPA4v/dh6eqsueDZJBRTxS0okx/+avO4AQANQWnfkFazszfkaBjGX/agN9IHF5P2epyIfcNZx MbZgMdlEwGkUNfMctFvUgDCx8ykrOKc8CAu03erwwPzum6i0hNoLsJDeNXcwfT2VPbylB48oPrqnV m47mBIUQ==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfo-001GiD-8D for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:43 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j4-20020a5b0304000000b00676ba2ed7e9so324046ybp.23 for ; Fri, 29 Jul 2022 00:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lbJIQr4Vvv60PESxVdDbhAlSw9LRcNbW3R+YO0jcP94=; b=D9qMEmzbxlQLQLAwGUvFbKrXZrI13hZCML9SPqWfSii21m8DoUs6RC3npHkeSMtsq/ d6cuBtd3cZz7GQ/Xl52F8AeU9PMpKhsBJsvFue6yZq5wUlNxhTO2ILN75xIqx1nrQuDl BOsslgMudJqthhMzpYMFwxqWj72Ap4svHXD508+zMwlBSbVpGb4U2qkdaCyFJ26Xmo7a MsXt7W3vm7a9mbsHaX9TDpI1QhP8Kzz9va6qFytW7YLxhpVkAP4m04ivEK0cKY6bPRl1 n1W8fnROKwpLwHiEytAYvUpUE53wc9pTAyjcEHzEjkHKG0wudUVhr/V0ufvH/2TW3yOG tvfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lbJIQr4Vvv60PESxVdDbhAlSw9LRcNbW3R+YO0jcP94=; b=Fl/1Eq8bpZDtkkPluSsLpIPMPmJMNgcfwo4WwjzuxyI1DmOjpGzrmbZCwf/rH9JNdm KWhM+ZMAAib2CNE4oDovhFEmhfzGOhVF7owwW1e9hNtjfDoxbQvIkG1u6HFQNt/UEOon 4MXip1Qm7wb0KRVQpUSYzBREdfbNauuc16wnRmKsvgBMtN7oCvsWcu6Cos5bCGHFigkJ NlgIqqxIyKhAZVOjCnQhPx3KV2RzrPWXqeJUbS6cNN5M+kNVuC0TbCPfBKQ3fOr5QxVA MD8sVG+Dj/CWXSHPVM7nzyLVC8ahM3b09EoGfq8y34DGVwBNqQ3kyVvXTtkHvmqTkick H90Q== X-Gm-Message-State: ACgBeo0Hv66e7O6z+DyORUW+fzHeLl9iWYqxyXXC8uXlJNRMfbZkX/dR Lll7Q6ed7D2bZPpdgTC2C+etq7zm/1/U X-Google-Smtp-Source: AA6agR4A5YraZp8PRsTdxNL289SyXJN9NWrSQQ/0jdTKgviJhWCXvZfR9JtOf+Xdet3koKI6PBTBhyRCuhPH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a05:6902:1082:b0:675:3bca:71fd with SMTP id v2-20020a056902108200b006753bca71fdmr1575028ybu.639.1659080678240; Fri, 29 Jul 2022 00:44:38 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:48 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-15-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 14/17] perf pmu-events: Hide the pmu_events 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084440_346372_5538873A X-CRM114-Status: GOOD ( 22.61 ) 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 Hide that the pmu_event structs are an array with a new wrapper struct. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 2 +- tools/perf/pmu-events/empty-pmu-events.c | 44 ++++++++++++---------- tools/perf/pmu-events/jevents.py | 47 +++++++++++++----------- tools/perf/pmu-events/pmu-events.h | 12 +++--- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 16 ++++---- tools/perf/util/metricgroup.c | 42 ++++++++++----------- tools/perf/util/metricgroup.h | 5 +-- tools/perf/util/pmu.c | 10 ++--- tools/perf/util/pmu.h | 4 +- tools/perf/util/s390-sample-raw.c | 6 +-- 12 files changed, 101 insertions(+), 91 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c index 646af8603227..149fb334b40b 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -3,7 +3,7 @@ #include "../../../util/cpumap.h" #include "../../../util/pmu.h" -const struct pmu_event *pmu_events_map__find(void) +const struct pmu_events_table *pmu_events_map__find(void) { struct perf_pmu *pmu = NULL; diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-events/empty-pmu-events.c index bee1967baa2b..5ed8c0aa4817 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -176,6 +176,10 @@ static const struct pmu_event pme_test_soc_cpu[] = { }, }; +/* Struct used to make the PMU event table implementation opaque to callers. */ +struct pmu_events_table { + const struct pmu_event *entries; +}; /* * Map a CPU to its table of PMU events. The CPU is identified by the @@ -188,7 +192,7 @@ static const struct pmu_event pme_test_soc_cpu[] = { struct pmu_events_map { const char *arch; const char *cpuid; - const struct pmu_event *table; + const struct pmu_events_table table; }; /* @@ -199,12 +203,12 @@ static const struct pmu_events_map pmu_events_map[] = { { .arch = "testarch", .cpuid = "testcpu", - .table = pme_test_soc_cpu, + .table = { pme_test_soc_cpu }, }, { .arch = 0, .cpuid = 0, - .table = 0, + .table = { 0 }, }, }; @@ -234,23 +238,23 @@ static const struct pmu_event pme_test_soc_sys[] = { struct pmu_sys_events { const char *name; - const struct pmu_event *table; + const struct pmu_events_table table; }; static const struct pmu_sys_events pmu_sys_event_tables[] = { { - .table = pme_test_soc_sys, + .table = { pme_test_soc_sys }, .name = "pme_test_soc_sys", }, { - .table = 0 + .table = { 0 } }, }; -int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, +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[0]; + for (const struct pmu_event *pe = &table->entries[0]; pe->name || pe->metric_group || pe->metric_name; pe++) { int ret = fn(pe, table, data); @@ -261,9 +265,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite return 0; } -const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) { - const struct pmu_event *table = NULL; + const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); int i; @@ -277,11 +281,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) for (;;) { const struct pmu_events_map *map = &pmu_events_map[i++]; - if (!map->table) + if (!map->cpuid) break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = map->table; + table = &map->table; break; } } @@ -289,13 +293,13 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) return table; } -const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid) +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]; - tables->table; + tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return tables->table; + return &tables->table; } return NULL; } @@ -303,9 +307,9 @@ const struct pmu_event *find_core_events_table(const char *arch, const char *cpu 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->table; + tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->table, fn, data); if (ret) return ret; @@ -313,13 +317,13 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) return 0; } -const struct pmu_event *find_sys_events_table(const char *name) +const struct pmu_events_table *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; tables->name; tables++) { if (!strcmp(tables->name, name)) - return tables->table; + return &tables->table; } return NULL; } @@ -329,7 +333,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->table, fn, data); if (ret) return ret; diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 365c960202b0..aa8df649025a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -334,6 +334,11 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: def print_mapping_table(archs: Sequence[str]) -> None: """Read the mapfile and generate the struct from cpuid string to event table.""" _args.output_file.write(""" +/* Struct used to make the PMU event table implementation opaque to callers. */ +struct pmu_events_table { + const struct pmu_event *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. @@ -345,7 +350,7 @@ def print_mapping_table(archs: Sequence[str]) -> None: struct pmu_events_map { const char *arch; const char *cpuid; - const struct pmu_event *table; + struct pmu_events_table table; }; /* @@ -359,7 +364,7 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = "testarch", \t.cpuid = "testcpu", -\t.table = pme_test_soc_cpu, +\t.table = { pme_test_soc_cpu }, }, """) else: @@ -374,7 +379,7 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write(f"""{{ \t.arch = "{arch}", \t.cpuid = "{cpuid}", -\t.table = {tblname} +\t.table = {{ {tblname} }} }}, """) first = False @@ -382,7 +387,7 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = 0, \t.cpuid = 0, -\t.table = 0, +\t.table = { 0 }, } }; """) @@ -393,26 +398,26 @@ def print_system_mapping_table() -> None: _args.output_file.write(""" struct pmu_sys_events { \tconst char *name; -\tconst struct pmu_event *table; +\tstruct pmu_events_table table; }; static const struct pmu_sys_events pmu_sys_event_tables[] = { """) for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ -\t\t.table = {tblname}, +\t\t.table = {{ {tblname} }}, \t\t.name = \"{tblname}\", \t}}, """) _args.output_file.write("""\t{ -\t\t.table = 0 +\t\t.table = { 0 } \t}, }; -int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, +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[0]; + for (const struct pmu_event *pe = &table->entries[0]; pe->name || pe->metric_group || pe->metric_name; pe++) { int ret = fn(pe, table, data); @@ -423,9 +428,9 @@ int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_ite return 0; } -const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) +const struct pmu_events_table *perf_pmu__find_table(struct perf_pmu *pmu) { - const struct pmu_event *table = NULL; + const struct pmu_events_table *table = NULL; char *cpuid = perf_pmu__getcpuid(pmu); int i; @@ -438,11 +443,11 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) i = 0; for (;;) { const struct pmu_events_map *map = &pmu_events_map[i++]; - if (!map->table) + if (!map->arch) break; if (!strcmp_cpuid_str(map->cpuid, cpuid)) { - table = map->table; + table = &map->table; break; } } @@ -450,13 +455,13 @@ const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu) return table; } -const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid) +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]; - tables->table; + tables->arch; tables++) { if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid)) - return tables->table; + return &tables->table; } return NULL; } @@ -464,9 +469,9 @@ const struct pmu_event *find_core_events_table(const char *arch, const char *cpu 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->table; + tables->arch; tables++) { - int ret = pmu_events_table_for_each_event(tables->table, fn, data); + int ret = pmu_events_table_for_each_event(&tables->table, fn, data); if (ret) return ret; @@ -474,13 +479,13 @@ int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data) return 0; } -const struct pmu_event *find_sys_events_table(const char *name) +const struct pmu_events_table *find_sys_events_table(const char *name) { for (const struct pmu_sys_events *tables = &pmu_sys_event_tables[0]; tables->name; tables++) { if (!strcmp(tables->name, name)) - return tables->table; + return &tables->table; } return NULL; } @@ -490,7 +495,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->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 70672842f77f..fe343c4d8016 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -30,18 +30,20 @@ struct pmu_event { const char *metric_constraint; }; +struct pmu_events_table; + typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, - const struct pmu_event *table, + const struct pmu_events_table *table, void *data); -int pmu_events_table_for_each_event(const struct pmu_event *table, pmu_event_iter_fn fn, +int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, void *data); -const struct pmu_event *perf_pmu__find_table(struct perf_pmu *pmu); -const struct pmu_event *find_core_events_table(const char *arch, const char *cpuid); +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); -const struct pmu_event *find_sys_events_table(const char *name); +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); #endif diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index e79ee8621a90..51fb5f34c1dd 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_event *pme_test; + const struct pmu_events_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 30c7091857b8..68f5a2a03242 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_event *pme_test; + const struct pmu_events_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 1c3479e5890e..9111725041d0 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -424,7 +424,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, } static int test__pmu_event_table_core_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *data) { int *map_events = data; @@ -461,7 +461,7 @@ static int test__pmu_event_table_core_callback(const struct pmu_event *pe, } static int test__pmu_event_table_sys_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *data) { int *map_events = data; @@ -495,8 +495,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_event *sys_event_table = find_sys_events_table("pme_test_soc_sys"); - const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); + const struct pmu_events_table *sys_event_table = find_sys_events_table("pme_test_soc_sys"); + const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu"); int map_events = 0, expected_events, err; /* ignore 3x sentinels */ @@ -544,7 +544,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) struct perf_pmu *pmu; LIST_HEAD(aliases); int res = 0; - const struct pmu_event *table = find_core_events_table("testarch", "testcpu"); + const struct pmu_events_table *table = find_core_events_table("testarch", "testcpu"); struct perf_pmu_alias *a, *tmp; if (!table) @@ -597,7 +597,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) struct perf_pmu *pmu = &test_pmu->pmu; const char *pmu_name = pmu->name; struct perf_pmu_alias *a, *tmp, *alias; - const struct pmu_event *events_table; + const struct pmu_events_table *events_table; LIST_HEAD(aliases); int res = 0; @@ -839,7 +839,7 @@ struct metric { struct metric_ref metric_ref; }; -static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_event *table, +static int test__parsing_callback(const struct pmu_event *pe, const struct pmu_events_table *table, void *data) { int *failures = data; @@ -1016,7 +1016,7 @@ static int metric_parse_fake(const char *str) } static int test__parsing_fake_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *data __maybe_unused) { if (!pe->metric_expr) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f702b73a7609..8ef44f4b5e9a 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -508,7 +508,7 @@ struct metricgroup_iter_data { }; static int metricgroup__sys_event_iter(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table, void *data) { struct metricgroup_iter_data *d = data; @@ -529,7 +529,7 @@ static int metricgroup__sys_event_iter(const struct pmu_event *pe, } static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *data) { struct metricgroup_print_sys_idata *d = data; @@ -549,7 +549,7 @@ struct metricgroup_print_data { }; static int metricgroup__print_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *vdata) { struct metricgroup_print_data *data = vdata; @@ -571,7 +571,7 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, struct rblist groups; struct rb_node *node, *next; struct strlist *metriclist = NULL; - const struct pmu_event *table; + const struct pmu_events_table *table; if (!metricgroups) { metriclist = strlist__new(NULL, NULL); @@ -876,7 +876,7 @@ struct metricgroup_add_iter_data { bool metric_no_group; struct metric *root_metric; const struct visited_metric *visited; - const struct pmu_event *table; + const struct pmu_events_table *table; }; static int add_metric(struct list_head *metric_list, @@ -885,7 +885,7 @@ static int add_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_event *table); + const struct pmu_events_table *table); /** * resolve_metric - Locate metrics within the root metric and recursively add @@ -908,7 +908,7 @@ static int resolve_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_event *table) + const struct pmu_events_table *table) { struct hashmap_entry *cur; size_t bkt; @@ -986,7 +986,7 @@ static int __add_metric(struct list_head *metric_list, int runtime, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_event *table) + const struct pmu_events_table *table) { const struct visited_metric *vm; int ret; @@ -1077,7 +1077,7 @@ struct metricgroup__find_metric_data { }; static int metricgroup__find_metric_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *vdata) { struct metricgroup__find_metric_data *data = vdata; @@ -1090,7 +1090,7 @@ static int metricgroup__find_metric_callback(const struct pmu_event *pe, } const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_event *table) + const struct pmu_events_table *table) { struct metricgroup__find_metric_data data = { .metric = metric, @@ -1108,7 +1108,7 @@ static int add_metric(struct list_head *metric_list, bool metric_no_group, struct metric *root_metric, const struct visited_metric *visited, - const struct pmu_event *table) + const struct pmu_events_table *table) { int ret = 0; @@ -1136,8 +1136,8 @@ static int add_metric(struct list_head *metric_list, } static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, - void *data) + const struct pmu_events_table *table __maybe_unused, + void *data) { struct metricgroup_add_iter_data *d = data; int ret; @@ -1193,7 +1193,7 @@ struct metricgroup__add_metric_data { }; static int metricgroup__add_metric_callback(const struct pmu_event *pe, - const struct pmu_event *table, + const struct pmu_events_table *table, void *vdata) { struct metricgroup__add_metric_data *data = vdata; @@ -1227,7 +1227,7 @@ static int metricgroup__add_metric_callback(const struct pmu_event *pe, static int metricgroup__add_metric(const char *metric_name, const char *modifier, bool metric_no_group, struct list_head *metric_list, - const struct pmu_event *table) + const struct pmu_events_table *table) { LIST_HEAD(list); int ret; @@ -1296,7 +1296,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, struct list_head *metric_list, - const struct pmu_event *table) + const struct pmu_events_table *table) { char *list_itr, *list_copy, *metric_name, *modifier; int ret, count = 0; @@ -1504,7 +1504,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, bool metric_no_merge, struct perf_pmu *fake_pmu, struct rblist *metric_events_list, - const struct pmu_event *table) + const struct pmu_events_table *table) { struct evlist *combined_evlist = NULL; LIST_HEAD(metric_list); @@ -1650,14 +1650,14 @@ int metricgroup__parse_groups(const struct option *opt, struct rblist *metric_events) { struct evlist *perf_evlist = *(struct evlist **)opt->value; - const struct pmu_event *table = pmu_events_map__find(); + const struct pmu_events_table *table = pmu_events_map__find(); return parse_groups(perf_evlist, str, metric_no_group, metric_no_merge, NULL, metric_events, table); } int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_event *table, + const struct pmu_events_table *table, const char *str, bool metric_no_group, bool metric_no_merge, @@ -1668,7 +1668,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist, } static int metricgroup__has_metric_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *vdata) { const char *metric = vdata; @@ -1684,7 +1684,7 @@ static int metricgroup__has_metric_callback(const struct pmu_event *pe, bool metricgroup__has_metric(const char *metric) { - const struct pmu_event *table = pmu_events_map__find(); + const struct pmu_events_table *table = pmu_events_map__find(); if (!table) return false; diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 5a1390e73d25..f54d170043e9 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -11,7 +11,6 @@ struct evlist; struct evsel; struct option; struct rblist; -struct pmu_events_map; struct cgroup; /** @@ -71,9 +70,9 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_merge, struct rblist *metric_events); const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_event *table); + const struct pmu_events_table *table); int metricgroup__parse_groups_test(struct evlist *evlist, - const struct pmu_event *table, + const struct pmu_events_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 ab94d672d7bf..a84fa532817f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -710,7 +710,7 @@ char *perf_pmu__getcpuid(struct perf_pmu *pmu) return cpuid; } -__weak const struct pmu_event *pmu_events_map__find(void) +__weak const struct pmu_events_table *pmu_events_map__find(void) { return perf_pmu__find_table(NULL); } @@ -799,7 +799,7 @@ struct pmu_add_cpu_aliases_map_data { }; static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *vdata) { struct pmu_add_cpu_aliases_map_data *data = vdata; @@ -827,7 +827,7 @@ static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, * as aliases. */ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - const struct pmu_event *table) + const struct pmu_events_table *table) { struct pmu_add_cpu_aliases_map_data data = { .head = head, @@ -841,7 +841,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) { - const struct pmu_event *table; + const struct pmu_events_table *table; table = perf_pmu__find_table(pmu); if (!table) @@ -856,7 +856,7 @@ struct pmu_sys_event_iter_data { }; static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *data) { struct pmu_sys_event_iter_data *idata = data; diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 06df99ba2029..78f87b46ddf3 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -126,10 +126,10 @@ int perf_pmu__test(void); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - const struct pmu_event *map); + const struct pmu_events_table *map); char *perf_pmu__getcpuid(struct perf_pmu *pmu); -const struct pmu_event *pmu_events_map__find(void); +const struct pmu_events_table *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index b1c052c176bb..fad1e96c74ba 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -135,7 +135,7 @@ struct get_counter_name_data { }; static int get_counter_name_callback(const struct pmu_event *evp, - const struct pmu_event *table __maybe_unused, + const struct pmu_events_table *table __maybe_unused, void *vdata) { struct get_counter_name_data *data = vdata; @@ -157,7 +157,7 @@ static int get_counter_name_callback(const struct pmu_event *evp, * the name of this counter. * If no match is found a NULL pointer is returned. */ -static const char *get_counter_name(int set, int nr, const struct pmu_event *table) +static const char *get_counter_name(int set, int nr, const struct pmu_events_table *table) { struct get_counter_name_data data = { .wanted = get_counterset_start(set) + nr, @@ -177,7 +177,7 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) unsigned char *buf = sample->raw_data; const char *color = PERF_COLOR_BLUE; struct cf_ctrset_entry *cep, ce; - const struct pmu_event *table; + const struct pmu_events_table *table; u64 *p; table = pmu_events_map__find(); From patchwork Fri Jul 29 07:43:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932103 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 49564C00144 for ; Fri, 29 Jul 2022 07:50:58 +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=0XqvJoTIDk5B2j4zP/l3IswlV9VQ+BUZFLSWam0mbAs=; b=Kfn2mMjvbp0v16BeJAMiwvpdHi 4wTvl8gG2uXCn6J8zZ3qUI/MKlO5NqDhffILJdDezn83c0ewOLEFOFYqzSMb4eIFZ6SQ8KwYlvqpy /oznYvYQAZU85nIIKV6u/PZLMqEN7Lm5tPlceGOQYwVinV8UwN4iTd3A99ir+TGukGiq4cYg4icX3 ZdyosNG6O4kHmjlbu7Kd9f1XLCH9G4dBWKKm4Mui3fF4a8BQpHH3vBN/u+YNdp41/qoVLWnEHppj/ k5pMGhRBZIS75Wo30P0sHL/TS7I5maLCKUCRX1b2PIxQII1APd8SedMB60oq1cjvR9iwIWONfHrxC n87PGlYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKkc-002lnt-Vt; Fri, 29 Jul 2022 07:49:39 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKft-002jL2-JN for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 07:44:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Erk4wRaNj75eOg4s5q1IE3PwAROzueG5Y9xXx5fRq5Q=; b=hLuzkf5eIXBXlHUWCg/9RCb10m vxLLAK0dlmuN3lEcbejJ2XWd2zxsEXEy1EXHLjIRXIgVjK+a/R1yZbtl8cyyOlKcxsnRxnpoOv1Iw HGtkGpZT8U35JmcvbQhPLteDF88kQhU7X2MEd5puonOm8B1steFc3Uy+mo1pq7obE7EXksO1lqy8O Tg5sbBB1ghGpWQG73eGqyGdNpjxyzKbuviBbHepP6oIFUcCPSh462GBWlBDN0xjsdYzkExW2QQB3w aOWmBFBh6CHvkjGcQMQWHYlqDqAoO6S0fzywF3XOx5quN6kNV7MfDOxUu9Xhkp5SdpwnTc8ckwNyi 0aUd9l+w==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfq-001Gj5-96 for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:44 +0000 Received: by mail-yb1-xb49.google.com with SMTP id w3-20020a258503000000b00676bd41edabso219463ybk.5 for ; Fri, 29 Jul 2022 00:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Erk4wRaNj75eOg4s5q1IE3PwAROzueG5Y9xXx5fRq5Q=; b=ceYcCHEt7cwQaf9fLFr6VwUHtuxA9NHhZDIFt4KvpdG/SeMYeJPImEw0TanZvYTkSO jxaYirq2ZfEhQN4eL6O7B494n5LDZqNi3ksV3esyIHxLlRwdNuHXt0C7VsHp4kogIIFw d/Id+nA+3IB1S9Yua+EMBvoGJ+VYKvhLZ/LNfHKbURQIO2jtj3BLHo98MOs4o42FrlyD cVgmPQ0brptiV3OAElYPAPf0rQzWbLQDDEivGL/N8NiTvYuD+Z3myQ/FBSGQvZB3twvl Xei2Q34PCWYF7BbzHnwodGeINBAiTH6WeEhnnWqYbi9AMWD3W0+IjeN2SVm5+Ev+JMTM eXFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Erk4wRaNj75eOg4s5q1IE3PwAROzueG5Y9xXx5fRq5Q=; b=gAeZtHsBVogLPi8cK1MyZEHAGzCbIPtjIJlofzj2ifU1zFhudXU4Ud2HfYWIbi2RXT 5ubC1sM8yRaa4Q1bd2hCrQTNdZh80c9VfUQ0x+1oLaDv5d0q6164TkGclmkRR90HX1dm HHumdFDJcVFkYtqFnltZ1jV/J1fnLg8R3YFGYxeXzX6JRxsbNzWKLrjIDJj2xguhI0I3 JG9UVaIZ4gL+P3PEstwyaCng4tJm5mMUoBJvczA8SHu2d1xHWwsCObYB2gd2tYDde6xY Vc0RAbLL8QxU8c17TOKKU/cwuCxgRKFAuKD1Io1FaupAG9UrBDlX9oimrSxex1BT3J/6 NGoA== X-Gm-Message-State: ACgBeo1tptxfC0LFOiArf/pYSfKl/6CUo/UxOqCbs3gmBAUX/dq3zAfx 8dRYWQgOSOj83oXonEXoKMIl5HPzanma X-Google-Smtp-Source: AA6agR6TGWhOWiiJl2Sd9EKoOSeuAgEOCnNPhdEE5jN6zK7mLkK9MFuLjnjdzhv40GzTcEJLgEjZoKdkXIei X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a0d:e004:0:b0:31f:311d:2351 with SMTP id j4-20020a0de004000000b0031f311d2351mr1986253ywe.10.1659080680507; Fri, 29 Jul 2022 00:44:40 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:49 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-16-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 15/17] perf metrics: Copy entire pmu_event in find metric 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084442_522025_29A87DEA X-CRM114-Status: GOOD ( 18.62 ) 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 pmu_event passed to the pmu_events_table_for_each_event is invalid after the loop. Copy the entire struct in metricgroup__find_metric. Reduce the scope of this function to static. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 33 ++++++++++++++++++--------------- tools/perf/util/metricgroup.h | 2 -- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8ef44f4b5e9a..95f4b46dba09 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -879,6 +879,10 @@ struct metricgroup_add_iter_data { const struct pmu_events_table *table; }; +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe); + static int add_metric(struct list_head *metric_list, const struct pmu_event *pe, const char *modifier, @@ -914,7 +918,7 @@ static int resolve_metric(struct list_head *metric_list, size_t bkt; struct to_resolve { /* The metric to resolve. */ - const struct pmu_event *pe; + struct pmu_event pe; /* * The key in the IDs map, this may differ from in case, * etc. from pe->metric_name. @@ -928,16 +932,15 @@ static int resolve_metric(struct list_head *metric_list, * the pending array. */ hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) { - const struct pmu_event *pe; + struct pmu_event pe; - pe = metricgroup__find_metric(cur->key, table); - if (pe) { + if (metricgroup__find_metric(cur->key, table, &pe)) { pending = realloc(pending, (pending_cnt + 1) * sizeof(struct to_resolve)); if (!pending) return -ENOMEM; - pending[pending_cnt].pe = pe; + memcpy(&pending[pending_cnt].pe, &pe, sizeof(pe)); pending[pending_cnt].key = cur->key; pending_cnt++; } @@ -952,7 +955,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].pe, modifier, metric_no_group, root_metric, visited, table); if (ret) break; @@ -1073,7 +1076,7 @@ static int __add_metric(struct list_head *metric_list, struct metricgroup__find_metric_data { const char *metric; - const struct pmu_event *pe; + struct pmu_event *pe; }; static int metricgroup__find_metric_callback(const struct pmu_event *pe, @@ -1085,21 +1088,21 @@ static int metricgroup__find_metric_callback(const struct pmu_event *pe, if (!match_metric(pe->metric_name, data->metric)) return 0; - data->pe = pe; - return -1; + memcpy(data->pe, pe, sizeof(*pe)); + return 1; } -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table) +static bool metricgroup__find_metric(const char *metric, + const struct pmu_events_table *table, + struct pmu_event *pe) { struct metricgroup__find_metric_data data = { .metric = metric, - .pe = NULL, + .pe = pe, }; - pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data); - - return data.pe; + return pmu_events_table_for_each_event(table, metricgroup__find_metric_callback, &data) + ? true : false; } static int add_metric(struct list_head *metric_list, diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index f54d170043e9..016b3b1a289a 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -69,8 +69,6 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_group, bool metric_no_merge, struct rblist *metric_events); -const struct pmu_event *metricgroup__find_metric(const char *metric, - const struct pmu_events_table *table); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_events_table *table, const char *str, From patchwork Fri Jul 29 07:43:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932152 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 21633C00144 for ; Fri, 29 Jul 2022 08:36:40 +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=RWabNScKtnH+u60Zjz3EsHpFmrYP1h1QrcYnUXeKxUs=; b=y0T2yVkG1W1CgmwBB+ZzZv7QRt DcXOjVmYbDQ1CPP1vRKgCpsNKQh/FvNBpa5d4OeCN0RryXSxpw5VrmClLmIHqAiZmA9hizzblT7dm dEYOG9O70O5u3tpu/+mn2JSKrjo/lKK4nN83fB9ysknbausMMyxGLqG0oj0pbwvmy8uiQW1aRFSqh gbzdjXtQ6mebWJ1WCNgG7wwvwJL0bttzytb4EN4iEgtiZiBetECUGA6wDLx7fLwQGORh1Im2j6+L7 Vq5GqmTEqszHXkVCg5d6K+5sxqLPUSeYqYBnpj2iUBwAAiNCcF/xm7lem+Pdk10JDeCjL81AgNNoW Qnrq8ASg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHLSa-003Kjj-Iq; Fri, 29 Jul 2022 08:35:07 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHLEf-0037vW-KC for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 08:20:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LRUf8d+uURXL8SFXLgyV3gEjVEvyagZOOmx5cGvuJJs=; b=aS08GAjmUbVjMJSXwjJmsJKVee fTQ1+8Cc7dI+KcTO0ZCB3Ig7GYXcy5GLv81i7plcSajx8D+kxjbddiwGWbRbeWldddlAEMmxUPLVm lMQtV9mWXkAXWqkhC5uYanehOmljZVE4+dF93i0XsKHP8e/qC2kscOGtv6opg7Dw75TBYAl1G9F5O wXtfP/+MkyMXyeXjlg9QTwf43e2yhSbPwmFeRw8HYYnR3sn4qCOsEqWMBlNvULxkJyotx9AwolXkp i7hjwYkgieOOZciD8v71yQIUeZx91xaOtQCm+XHfO51X2USoGacQGCyOHM72CsutDyF7mtf0kuS0h 41Z6r2Qg==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfs-001Gjn-Rc for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:47 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31f5960500bso36119217b3.14 for ; Fri, 29 Jul 2022 00:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=LRUf8d+uURXL8SFXLgyV3gEjVEvyagZOOmx5cGvuJJs=; b=Gm1u/Sc9Ujk0HD2StHcNwyJbN78keb1bm/Jz1Gi4C2ycVyK3Dlp5nQPpdoOKeAOZ4m Qh4yvrxF53P0gKQmrw8uSfCML/RDQOtisVTMTjH/SBD/10CxQyr4PhAQ1vDAo4aTWvby M5oA0BqwelZuR1cLrEnrTvNsTAJrQ2Z966j2ImqKWFbGey0aDOZfJj8guBTX0wHiJ+dJ /oWZWGGhDyY+L4A1axvbC/hRbA834iaQCRBHVVpTObXKWywlFiEmM5g+xr6PYz46XJcg Bhmb3Kp7tuB8GqRXjmOZDHcvCYivO6JdNJ5qX09+BV+uMg5/3rkDupGTxK0ZV25xvzIU AnFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LRUf8d+uURXL8SFXLgyV3gEjVEvyagZOOmx5cGvuJJs=; b=b07tIqk4UvzU4PKTe6PqtWmxAEiexvUTw+2EWX/MUGq3OhZbAAXDT4tatrLQ+8VQOg mKiSTiN3HL9VBObX5nHOgq3Ez7YCqo/gshlTUmEQJq/gPHKvAehJRE3qLDdkhtpevwox IsYXEvgZ5dYk3xrDkr3dWLXNZlbEFiyMyxmk0eoMG3f1WsYeC7whLgjQ6Bc5NovuOsqO a6EZ6OuoUa81wb/c2a1+CG2rOEN4hvoLBjaoQaN1D+Xv1lb4ozZAnzLew4P7OHyuexUc 61RzjV1qTmqVPygejRW9egUCAeb+tHabHAQyBb4/aZepRIm2GeIH4kUZ6lK2d1ZIEf0F /xMg== X-Gm-Message-State: ACgBeo1FokekjodaURexeQHMx1CGVNdEnOygFkgHDIOWjITVSA1CnNPs UKJFCkQ50E9lvixMyA4IkeKkecypP7pN X-Google-Smtp-Source: AA6agR7iT1NwWyMqAJ1jxVyIPRgvozaMjfN1CoV84qYye7v1G98MN/uWPv1gSNoTb1YPCyqKZj3+NfniwJoH X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a81:5a09:0:b0:31e:77a0:6f45 with SMTP id o9-20020a815a09000000b0031e77a06f45mr2069610ywb.59.1659080682920; Fri, 29 Jul 2022 00:44:42 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:50 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-17-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 16/17] perf jevents: Compress the pmu_events_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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084445_026128_391AE7DB X-CRM114-Status: GOOD ( 31.43 ) 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 pmu_events array requires 15 pointers per entry which in position independent code need relocating. Change the array to be an array of offsets within a big C string. Only the offset of the first variable is required, subsequent variables are stored in order after the \0 terminator (requiring a byte per variable rather than 4 bytes per offset). The file size savings are: no jevents - the same 19,788,464bytes x86 jevents - ~16.7% file size saving 23,744,288bytes vs 28,502,632bytes all jevents - ~19.5% file size saving 24,469,056bytes vs 30,379,920bytes default build options plus NO_LIBBFD=1. For example, the x86 build savings come from .rela.dyn and .data.rel.ro becoming smaller by 3,157,032bytes and 3,042,016bytes respectively. .rodata increases by 1,432,448bytes, giving an overall 4,766,600bytes saving. To make metric strings more shareable, the topic is changed from say 'skx metrics' to just 'metrics'. To try to help with the memory layout the pmu_events are ordered as used by perf qsort comparator functions. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 207 ++++++++++++++++++++++++------- 1 file changed, 162 insertions(+), 45 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index aa8df649025a..a5e162558994 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -6,7 +6,8 @@ import csv import json import os import sys -from typing import (Callable, Optional, Sequence) +from typing import (Callable, Dict, Optional, Sequence, Set, Tuple) +import collections # Global command line arguments. _args = None @@ -20,6 +21,19 @@ _arch_std_events = {} _close_table = False # Events to write out when the table is closed _pending_events = [] +# 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', + # 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' +] def removesuffix(s: str, suffix: str) -> str: @@ -39,6 +53,66 @@ def file_name_to_table_name(parents: Sequence[str], dirname: str) -> str: tblname += '_' + dirname return tblname.replace('-', '_') +def c_len(s: str) -> int: + """Return the length of s a C string + + This doesn't handle all escape characters properly. It first assumes + all \ are for escaping, it then adjusts as it will have over counted + \\. The code uses \000 rather than \0 as a terminator as an adjacent + number would be folded into a string of \0 (ie. "\0" + "5" doesn't + equal a terminator followed by the number 5 but the escape of + \05). The code adjusts for \000 but not properly for all octal, hex + or unicode values. + """ + try: + utf = s.encode(encoding='utf-8',errors='strict') + except: + print(f'broken string {s}') + raise + return len(utf) - utf.count(b'\\') + utf.count(b'\\\\') - (utf.count(b'\\000') * 2) + +class BigCString: + """A class to hold many strings concatenated together. + + Generating a large number of stand-alone C strings creates a large + number of relocations in position independent code. The BigCString + is a helper for this case. It builds a single string which within it + are all the other C strings (to avoid memory issues the string + itself is held as a list of strings). The offsets within the big + string are recorded and when stored to disk these don't need + relocation. + """ + strings: Set[str] + big_string: Sequence[str] + offsets: Dict[str, int] + + def __init__(self): + self.strings = set() + + def add(self, s: str) -> None: + """Called to add to the big string.""" + self.strings.add(s) + + def compute(self) -> None: + """Called once all strings are added to compute the string and offsets.""" + + # big_string_offset is the current location within the C string + # being appended to - comments, etc. don't count. big_string is + # the string contents represented as a list. Strings are immutable + # in Python and so appending to one causes memory issues, while + # lists are mutable. + big_string_offset = 0 + self.big_string = [] + self.offsets = {} + # Emit all strings in a sorted manner. + for s in sorted(self.strings): + self.offsets[s] = big_string_offset + self.big_string.append(f'/* offset={big_string_offset} */ "') + self.big_string.append(s) + self.big_string.append('"\n') + big_string_offset += c_len(s) + +_bcs = BigCString() class JsonEvent: """Representation of an event loaded from a json file dictionary.""" @@ -202,26 +276,18 @@ class JsonEvent: s += f'\t{attr} = {value},\n' return s + '}' + def build_c_string(self) -> str: + s = '' + for attr in _json_event_attributes: + x = getattr(self, attr) + s += f'{x}\\000' if x else '\\000' + return s + def to_c_string(self) -> str: """Representation of the event as a C struct initializer.""" - def attr_string(attr: str, value: str) -> str: - return f'\t.{attr} = \"{value}\",\n' - - def str_if_present(self, attr: str) -> str: - if not getattr(self, attr): - return '' - return attr_string(attr, getattr(self, attr)) - - s = '{\n' - for attr in [ - 'aggr_mode', 'compat', 'deprecated', 'desc', 'event', 'long_desc', - 'metric_constraint', 'metric_expr', 'metric_group', 'metric_name', - 'name', 'perpkg', 'pmu', 'topic', 'unit' - ]: - s += str_if_present(self, attr) - s += '},\n' - return s + s = self.build_c_string() + return f'{{ { _bcs.offsets[s] } }}, /* {s} */\n' def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: @@ -236,7 +302,6 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: event.topic = topic return result - def preprocess_arch_std_files(archpath: str) -> None: """Read in all architecture standard events.""" global _arch_std_events @@ -252,7 +317,7 @@ def print_events_table_prefix(tblname: str) -> None: 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 pmu_event {tblname}[] = {{\n') + _args.output_file.write(f'static const struct compact_pmu_event {tblname}[] = {{\n') _close_table = True @@ -267,13 +332,13 @@ def add_events_table_entries(item: os.DirEntry, topic: str) -> None: def print_events_table_suffix() -> None: """Optionally close events table.""" - def event_cmp_key(j: JsonEvent): - def fix_none(s: str): + def event_cmp_key(j: JsonEvent) -> Tuple[bool, str, str, str, str]: + def fix_none(s: Optional[str]) -> str: if s is None: return '' return s - return (not j.desc is None, fix_none(j.topic), fix_none(j.name), fix_none(j.pmu), + 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 @@ -285,23 +350,37 @@ def print_events_table_suffix() -> None: _args.output_file.write(event.to_c_string()) _pending_events = [] - _args.output_file.write("""{ -\t.name = 0, -\t.event = 0, -\t.desc = 0, -}, -}; -""") + _args.output_file.write('};\n\n') _close_table = False +def get_topic(topic: str) -> str: + if topic.endswith('metrics.json'): + return 'metrics' + return removesuffix(topic, '.json').replace('-', ' ') + +def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None: + + if item.is_dir(): + return + + # base dir or too deep + level = len(parents) + if level == 0 or level > 4: + return + + # Ignore other directories. If the file name does not have a .json + # extension, ignore it. It could be a readme.txt for instance. + if not item.is_file() or not item.name.endswith('.json'): + return + + topic = get_topic(item.name) + for event in read_json_events(item.path, topic): + _bcs.add(event.build_c_string()) def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: """Process a JSON file during the main walk.""" global _sys_event_tables - def get_topic(topic: str) -> str: - return removesuffix(topic, '.json').replace('-', ' ') - def is_leaf_dir(path: str) -> bool: for item in os.scandir(path): if item.is_dir(): @@ -336,7 +415,8 @@ def print_mapping_table(archs: Sequence[str]) -> None: _args.output_file.write(""" /* Struct used to make the PMU event table implementation opaque to callers. */ struct pmu_events_table { - const struct pmu_event *entries; + const struct compact_pmu_event *entries; + size_t length; }; /* @@ -364,7 +444,10 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = "testarch", \t.cpuid = "testcpu", -\t.table = { pme_test_soc_cpu }, +\t.table = { +\t.entries = pme_test_soc_cpu, +\t.length = ARRAY_SIZE(pme_test_soc_cpu), +\t} }, """) else: @@ -379,7 +462,10 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write(f"""{{ \t.arch = "{arch}", \t.cpuid = "{cpuid}", -\t.table = {{ {tblname} }} +\t.table = {{ +\t\t.entries = {tblname}, +\t\t.length = ARRAY_SIZE({tblname}) +\t}} }}, """) first = False @@ -387,7 +473,7 @@ const struct pmu_events_map pmu_events_map[] = { _args.output_file.write("""{ \t.arch = 0, \t.cpuid = 0, -\t.table = { 0 }, +\t.table = { 0, 0 }, } }; """) @@ -405,23 +491,41 @@ static const struct pmu_sys_events pmu_sys_event_tables[] = { """) for tblname in _sys_event_tables: _args.output_file.write(f"""\t{{ -\t\t.table = {{ {tblname} }}, +\t\t.table = {{ +\t\t\t.entries = {tblname}, +\t\t\t.length = ARRAY_SIZE({tblname}) +\t\t}}, \t\t.name = \"{tblname}\", \t}}, """) _args.output_file.write("""\t{ -\t\t.table = { 0 } +\t\t.table = { 0, 0 } \t}, }; -int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn, +static void decompress(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("""} + +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 (size_t i = 0; i < table->length; i++) { + struct pmu_event pe; + int ret; + decompress(table->entries[i].offset, &pe); + ret = fn(&pe, table, data); if (ret) return ret; } @@ -530,7 +634,7 @@ def main() -> None: help='Root of tree containing architecture directories containing json files' ) ap.add_argument( - 'output_file', type=argparse.FileType('w'), nargs='?', default=sys.stdout) + 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout) _args = ap.parse_args() _args.output_file.write(""" @@ -540,6 +644,10 @@ def main() -> None: #include #include +struct compact_pmu_event { + int offset; +}; + """) archs = [] for item in os.scandir(_args.starting_dir): @@ -555,6 +663,15 @@ def main() -> None: for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' preprocess_arch_std_files(arch_path) + ftw(arch_path, [], preprocess_one_file) + + _bcs.compute() + _args.output_file.write('static const char *const big_c_string =\n') + for s in _bcs.big_string: + _args.output_file.write(s) + _args.output_file.write(';\n\n') + for arch in archs: + arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file) print_events_table_suffix() From patchwork Fri Jul 29 07:43:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12932140 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 A1D58C00144 for ; Fri, 29 Jul 2022 08:35:41 +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=nKwizwrKcuxTKaoPYPJ8fm3855N/Yeb9BCb0autEMDQ=; b=IsCCj0rZBsEqQMrTXVYgqbOz5J Fy6qMy4+7wNOIQbZlFa3aEvJUwC6vm9GAPDlOYW0mIZohWfu5DR7m5yYEQXFDi2TEfX09eXHHb8OP W01mLd+HgIKuIuB8mLGD+ipm0RA1ZXsZdqO/MchMgZmGynxInlSYt3rgrMRoZ0vRlQacgTaycH1j2 0lEE/sn6s97CEiw/JvJiaA8j8pckOGYtt3eOAJUdpPdoV8NBTH2QZx/xSkUtj4p1V7sfgFtJiT3ZE XfQJ37Cn3p8DK7HEv4W/QcvpEBGsct0/thmm34KwTZU9gdagx7tcuFWV8cIdruLUyRPdzDgz3y8O3 X1qoMXqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHLRt-003KIU-4u; Fri, 29 Jul 2022 08:34:21 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHLEf-0037vW-3X for linux-arm-kernel@bombadil.infradead.org; Fri, 29 Jul 2022 08:20:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :Cc:To:From:Subject:References:Mime-Version:Message-Id:In-Reply-To:Date: Sender:Reply-To:Content-ID:Content-Description; bh=vsVx0RXggVgT0Vzeq33Ge2ECpCDo8PPDDZprUlFUzbU=; b=LugNCTNth+jr3zDNppzOdix3O8 ulnLvGSwfMXjgQLYbERpALKhv/H4XTgwm1XU+m0x5A3cwRHbFV/nFfF3Nr61jkYbwD5GVQtAQpdfn 4AQzH3ee3/LpkIHWzREt9coHqfh5fv2B3EEZYJW3oAkPsDqxvkPRCk1HLVdIZJCOZo/7kmA/Y+u7W /GEYaBa256bkg/tgrH+w/mntlc9KqTWbbxrHEN+AsdYQJQSlVzhHeY4bHti8wAUR8GRJv0BbcDx5Q +JHowFwk0s6zzs4PCN1CoQe5bO+2YFT2U6Wm9nC9XUsidVfhH82toYMleGcJWDHu0CWinvj6guJmT CNvYP3bQ==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oHKfu-001GhB-6h for linux-arm-kernel@lists.infradead.org; Fri, 29 Jul 2022 07:44:48 +0000 Received: by mail-yb1-xb49.google.com with SMTP id m11-20020a5b040b000000b0066fcc60d1a0so3288500ybp.19 for ; Fri, 29 Jul 2022 00:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=vsVx0RXggVgT0Vzeq33Ge2ECpCDo8PPDDZprUlFUzbU=; b=d7tM7m3wSx+Nl3LsHF3Qkp1URtOSaRrhcRzOpGhMvuDIzsJ6ORKxe9qw5CIL7pLEi+ DV986YF3a/OamH6P50M+iW7ja+NNZIQ7c65kuRHpi7trc7GXOzI0a+4GqbPXR20O63Wp gM5mSRJsf0xkjfsmmhaW0JsdpFPTMIzAi5arSo5Gqmkw4E6NtXmjicsj89vV5RPOzdCs SwnikVqD2c4lL0LQLpfcwfNdvi18dCIFcH/XWMAL9HoYlW1NfWScpIXCpZMC5nROT1Qm rbwloGq+SwztiHqkJfpMc3X2e+GdNcLApSmmAU4H7gRB/zrPyPU5j/YUGapUwZWBlTuA pmTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=vsVx0RXggVgT0Vzeq33Ge2ECpCDo8PPDDZprUlFUzbU=; b=zU+GU1uVFgzqk0ZjqqAwBSwVRM4FDK9zlRENIs8lNqGliszwO6pipczrjGcQ+5dbce IJOa7KdQgaOIcwn7Yb7ycomHFMef8B3TlvTicxFxjBjYZG9x6Kx9UiIdfHlOWBYuxgE0 andqoM7zYLxejQCVlokqfpH+4HwONEdYxFG8dDCbIYz7zUI3QqC+njgPSskbJ9egT2BK 9qNRXQD/TfLIBha0jzj/8VWe4Ny30tuioAFBmXubTGT9D7ZHXGzbInVkVBudSIIlwwbp ZNMAc9pM4Zc47hxnPuKXKNJ43jGXQgDQLEnXB5rvhaygqnQSqFpcYFCMerEhxoSHBSTl G+ew== X-Gm-Message-State: ACgBeo191X7MPQkAnTY+BtOKVUzQFaMlttO4MdbA/sORdXd+PIDW9PcB 3IWSolSYtZGsNuRkk0UgqxRP9DNDXGLu X-Google-Smtp-Source: AA6agR4Gdae2DAr0F8eHUkZlTJOf6KliV4pgoBZPuV2HWpQnhPdzjdAaC/qIhk5RnUThfkaBsRPBs6u1CKjy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:524b:47b4:2aeb:1b49]) (user=irogers job=sendgmr) by 2002:a5b:585:0:b0:671:2b80:9d42 with SMTP id l5-20020a5b0585000000b006712b809d42mr1689021ybp.154.1659080685054; Fri, 29 Jul 2022 00:44:45 -0700 (PDT) Date: Fri, 29 Jul 2022 00:43:51 -0700 In-Reply-To: <20220729074351.138260-1-irogers@google.com> Message-Id: <20220729074351.138260-18-irogers@google.com> Mime-Version: 1.0 References: <20220729074351.138260-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH v3 17/17] perf jevents: Fold strings optimization 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 , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220729_084446_356992_00FB5A03 X-CRM114-Status: GOOD ( 19.87 ) 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 If a shorter string ends a longer string then the shorter string may reuse the longer string at an offset. For example, on x86 the event arith.cycles_div_busy and cycles_div_busy can be folded, even though they have difference names the strings are identical after 6 characters. cycles_div_busy can reuse the arith.cycles_div_busy string at an offset of 6. In pmu-events.c this looks like the following where the 'also:' lists folded strings: /* offset=177541 */ "arith.cycles_div_busy\000\000pipeline\000Cycles the divider is busy\000\000\000event=0x14,period=2000000,umask=0x1\000\000\000\000\000\000\000\000\000" /* also: cycles_div_busy\000\000pipeline\000Cycles the divider is busy\000\000\000event=0x14,period=2000000,umask=0x1\000\000\000\000\000\000\000\000\000 */ As jevents.py combines multiple strings for an event into a larger string, the amount of folding is minimal as all parts of the event must align. Other organizations can benefit more from folding, but lose space by say recording more offsets. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 55 ++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index a5e162558994..e5545758c92d 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -80,7 +80,9 @@ class BigCString: are all the other C strings (to avoid memory issues the string itself is held as a list of strings). The offsets within the big string are recorded and when stored to disk these don't need - relocation. + relocation. To reduce the size of the string further, identical + strings are merged. If a longer string ends-with the same value as a + shorter string, these entries are also merged. """ strings: Set[str] big_string: Sequence[str] @@ -96,6 +98,33 @@ class BigCString: def compute(self) -> None: """Called once all strings are added to compute the string and offsets.""" + folded_strings = {} + # Determine if two strings can be folded, ie. let 1 string use the + # end of another. First reverse all strings and sort them. + sorted_reversed_strings = sorted([x[::-1] for x in self.strings]) + + # Strings 'xyz' and 'yz' will now be [ 'zy', 'zyx' ]. Scan forward + # for each string to see if there is a better candidate to fold it + # into, in the example rather than using 'yz' we can use'xyz' at + # an offset of 1. We record which string can be folded into which + # in folded_strings, we don't need to record the offset as it is + # trivially computed from the string lengths. + for pos,s in enumerate(sorted_reversed_strings): + best_pos = pos + for check_pos in range(pos + 1, len(sorted_reversed_strings)): + if sorted_reversed_strings[check_pos].startswith(s): + best_pos = check_pos + else: + break + if pos != best_pos: + folded_strings[s[::-1]] = sorted_reversed_strings[best_pos][::-1] + + # Compute reverse mappings for debugging. + fold_into_strings = collections.defaultdict(set) + for key, val in folded_strings.items(): + if key != val: + fold_into_strings[val].add(key) + # big_string_offset is the current location within the C string # being appended to - comments, etc. don't count. big_string is # the string contents represented as a list. Strings are immutable @@ -104,13 +133,25 @@ class BigCString: big_string_offset = 0 self.big_string = [] self.offsets = {} - # Emit all strings in a sorted manner. + + # Emit all strings that aren't folded in a sorted manner. for s in sorted(self.strings): - self.offsets[s] = big_string_offset - self.big_string.append(f'/* offset={big_string_offset} */ "') - self.big_string.append(s) - self.big_string.append('"\n') - big_string_offset += c_len(s) + if s not in folded_strings: + self.offsets[s] = big_string_offset + self.big_string.append(f'/* offset={big_string_offset} */ "') + self.big_string.append(s) + self.big_string.append('"') + if s in fold_into_strings: + self.big_string.append(' /* also: ' + ', '.join(fold_into_strings[s]) + ' */') + self.big_string.append('\n') + big_string_offset += c_len(s) + continue + + # Compute the offsets of the folded strings. + for s in folded_strings.keys(): + assert s not in self.offsets + folded_s = folded_strings[s] + self.offsets[s] = self.offsets[folded_s] + c_len(folded_s) - c_len(s) _bcs = BigCString()