From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89DA7C433EF for ; Wed, 1 Jun 2022 03:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349189AbiFAD1v (ORCPT ); Tue, 31 May 2022 23:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349394AbiFAD1m (ORCPT ); Tue, 31 May 2022 23:27:42 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061.outbound.protection.outlook.com [40.107.243.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA40A193D9; Tue, 31 May 2022 20:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PM9ZO7x6Pws5Xo6kDVMMYLkcsXQWGNbn3Dd2O8PKETQaoGn+geTab5gzhaSF7kib0/gS9ootsRPLXwpMKYDSRYD7edRJI4JSUr8P7WAI5DcqY2PRhXTs5PcamYs/W3AjDygNREEYZfUWJKThUcxFUiLg1adyW+52IiHhNqwPPLSPdSRjLTq8aaA2Mb2Yz16n7LHzqWzOhgJBCljTtutmXE6c0UTn5tyXd9I+Zy8YYraBSK0g1YZZlXg19SpnQV6N5Sdl6onzKVj3qSEEQWD0o8OggYe1pfN4NVPxNYZZ3fF5ZO4MWWg9z/T8BFr2SMudqmL37WcxB/nMbmeUaLOjsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0cM8N53tSbFDfbKPHpxAdrzs3Ux75peOuqDcEUZOUWw=; b=JVZHWzRJ2EP42WUk2lI+aq+m0VjmNt4zLMOrdSSyhFPgX2lPKLZwaJP03z3QKl/U8i0fXNZK/ZXKcobwIN8Lns3AsgvZAA3sDdCS/3CFvAe3NRrTcPlvFnAret6gQKrLaVqXEr1ZgG8yixwutrp0L8sG8CSqp5ekaI7FtOwGOVWYPXAQbLH/MMQmOki/dxyaAwrWKZZeRY5CnCX/Pk6Z+pusqndrRf3vU8MPzM5vhKSXtT7mvNpsEPJUo1idu0+y+vRE6m6YLsOmFVhTnU1e1shGxcZbl5o5ooB1OQjp1qHcawTQEayK7FDY431v2TGV/jzQ7PPXKQ740jqLzF87nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0cM8N53tSbFDfbKPHpxAdrzs3Ux75peOuqDcEUZOUWw=; b=AXK9udNebPaKmA8md7D4qInLoBaxxZ+Wl5/wsn316CRL1pXQwAq5JDIYn15s49+emevVWL0beIHD4r07yItBO4lSI1Gn1jjnxZTe0oA6LppBL35aKAuC9FgRkFl2tKiX1i6iv/l1qDB+gMupnIC7wk4fZgf+e1V+k4jWTimyHTE= Received: from MWHPR10CA0052.namprd10.prod.outlook.com (2603:10b6:300:2c::14) by MN2PR12MB4389.namprd12.prod.outlook.com (2603:10b6:208:262::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:27:33 +0000 Received: from CO1NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:300:2c:cafe::73) by MWHPR10CA0052.outlook.office365.com (2603:10b6:300:2c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:27:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT026.mail.protection.outlook.com (10.13.175.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:27:33 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:27:21 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 1/8] perf record ibs: Warn about sampling period skew Date: Wed, 1 Jun 2022 08:56:01 +0530 Message-ID: <20220601032608.1034-2-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8bcda395-e4a3-4e60-c21e-08da437eaa9b X-MS-TrafficTypeDiagnostic: MN2PR12MB4389:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ntkM2kidzYuDevGiEcW5TXn9JvgGed1Hl4DSCWIDoLoo6vjew9bmWatIQMZy3hDftYEaReuBnjU3PqEl51QbNsj3pUSBr3v/2TsYnXNg7xyybQZ2Qzo6VFfE//mNcsN+wHpD77L8yv8N1746ojEHLYW6bYkMXdS4+yAX8imF0oMctr91XFqTh+bTsTKIOU9ZfRdca7kT7vWDDC6IsNzORvcaPG6PkpxyhiycPq9fHfTrc7OzHreXtwI7U8teXkxKZgvOOmo76Qk8/YgpskouKnPE0QjOgaQ1vuWKkUuiJX4mdTbKHxO6eKO38mMPNK+E0z24H3udXHg6GQi0uq0PwZ08+TudB25P6niIa+H17QloRzGYBm04A00Vdj23pVfGaw9/Hky7pQusu88AQVE4xScdLxg5CUh7Td6CDzPLFEkSlUJ+Sd/lShvsxct+JJXqmKXG6EZfJsnBsjp0/X+F71TSAdG63ZnWjUpZ4RV2E5WPVRRBuGPqMHfg40XzhUJW5EpRh6X0KEpGIB6xXdPQ6PeafVcFrlJe7hI3KJ+eqpiy8U/B0DPqrdbGA3vTUGAdFryL+En1qXlSv1Y3CPsKoyhNVUUkj8vT6c6ogm9MPKoV2yH0XTeA2COTxhrUN17MKaHgWoEF+G3HuHEJaO1nveokg5LxzKO8ArcDYKIgLWkjOIX3J660A4klNjgD8poy0icSBeALwVidciXf8RTfaA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2616005)(336012)(1076003)(508600001)(186003)(16526019)(26005)(7696005)(83380400001)(36860700001)(6666004)(82310400005)(47076005)(70206006)(356005)(70586007)(8676002)(426003)(8936002)(4326008)(5660300002)(316002)(44832011)(86362001)(7416002)(36756003)(2906002)(54906003)(40460700003)(110136005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:27:33.1433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8bcda395-e4a3-4e60-c21e-08da437eaa9b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4389 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Samples without an L3 miss are discarded and counter is reset with random value (between 1-15 for fetch pmu and 1-127 for op pmu) when IBS L3 miss filtering is enabled. This causes a sampling period skew but there is no way to reconstruct aggregated sampling period. So print a warning at perf record if user sets l3missonly=3D1. Ex: # perf record -c 10000 -C 0 -e ibs_op/l3missonly=3D1/ WARNING: Hw internally resets sampling period when L3 Miss Filtering is e= nabled and tagged operation does not cause L3 Miss. This causes sampling period = skew. Signed-off-by: Ravi Bangoria Acked-by: Ian Rogers --- tools/perf/arch/x86/util/evsel.c | 49 ++++++++++++++++++++++++++++++++ tools/perf/util/evsel.c | 7 +++++ tools/perf/util/evsel.h | 1 + 3 files changed, 57 insertions(+) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/ev= sel.c index 88306183d629..fceb904902ab 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -5,6 +5,7 @@ #include "util/env.h" #include "util/pmu.h" #include "linux/string.h" +#include "util/debug.h" =20 void arch_evsel__set_sample_weight(struct evsel *evsel) { @@ -60,3 +61,51 @@ bool arch_evsel__must_be_in_group(const struct evsel *ev= sel) (!strcasecmp(evsel->name, "slots") || strcasestr(evsel->name, "topdown")); } + +static void ibs_l3miss_warn(void) +{ + pr_warning( +"WARNING: Hw internally resets sampling period when L3 Miss Filtering is e= nabled\n" +"and tagged operation does not cause L3 Miss. This causes sampling period = skew.\n"); +} + +void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *= attr) +{ + struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu; + static int warned_once; + /* 0: Uninitialized, 1: Yes, -1: No */ + static int is_amd; + + if (warned_once || is_amd =3D=3D -1) + return; + + if (!is_amd) { + struct perf_env *env =3D evsel__env(evsel); + + if (!perf_env__cpuid(env) || !env->cpuid || + !strstarts(env->cpuid, "AuthenticAMD")) { + is_amd =3D -1; + return; + } + is_amd =3D 1; + } + + evsel_pmu =3D evsel__find_pmu(evsel); + if (!evsel_pmu) + return; + + ibs_fetch_pmu =3D perf_pmu__find("ibs_fetch"); + ibs_op_pmu =3D perf_pmu__find("ibs_op"); + + if (ibs_fetch_pmu && ibs_fetch_pmu->type =3D=3D evsel_pmu->type) { + if (attr->config & (1ULL << 59)) { + ibs_l3miss_warn(); + warned_once =3D 1; + } + } else if (ibs_op_pmu && ibs_op_pmu->type =3D=3D evsel_pmu->type) { + if (attr->config & (1ULL << 16)) { + ibs_l3miss_warn(); + warned_once =3D 1; + } + } +} diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ce499c5da8d7..8fea51a9cd90 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1091,6 +1091,11 @@ void __weak arch_evsel__fixup_new_cycles(struct perf= _event_attr *attr __maybe_un { } =20 +void __weak arch__post_evsel_config(struct evsel *evsel __maybe_unused, + struct perf_event_attr *attr __maybe_unused) +{ +} + static void evsel__set_default_freq_period(struct record_opts *opts, struct perf_event_attr *attr) { @@ -1366,6 +1371,8 @@ void evsel__config(struct evsel *evsel, struct record= _opts *opts, */ if (evsel__is_dummy_event(evsel)) evsel__reset_sample_bit(evsel, BRANCH_STACK); + + arch__post_evsel_config(evsel, attr); } =20 int evsel__set_filter(struct evsel *evsel, const char *filter) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 73ea48e94079..92bed8e2f7d8 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -297,6 +297,7 @@ void evsel__set_sample_id(struct evsel *evsel, bool use= _sample_identifier); =20 void arch_evsel__set_sample_weight(struct evsel *evsel); void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr); +void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *= attr); =20 int evsel__set_filter(struct evsel *evsel, const char *filter); int evsel__append_tp_filter(struct evsel *evsel, const char *filter); --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95904C433EF for ; Wed, 1 Jun 2022 03:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349401AbiFAD14 (ORCPT ); Tue, 31 May 2022 23:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349406AbiFAD1s (ORCPT ); Tue, 31 May 2022 23:27:48 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2066.outbound.protection.outlook.com [40.107.102.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 296EB20F5D; Tue, 31 May 2022 20:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h+AqI46LnTGhc0sRxIMTUi1uwzAXo6D1bfnHQA4S3eQiifTeqVWKtapzR4N/wt6gI8UcYrbwz+qzkYsVtLCFn1fKbu2Qpq1eiz5PBsOBT4rF5m4VER4y+5AAHmKU/pNIzA+lH4VRTy2x7XS+yi38sb3oJgjk0b2DmFBkLK101UB0dcA84al6r81mSKdLbnCS5bluVMBTgOihVa7XlHCJplI1sKn3q2cSgH66bRcEx9T/CQsw12BQ/K3HKkxQloENnVs+oTHFtP45lXUQSw6spOQAFdsnsfxDZtn+TNhE9UDKIk8mTfV4prp+QfMxOTm5qW3UyQ6aiT2n0jbWM44COg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+SfqAfhu+nR9MuPJLjVOmETEtBJwbZgOuF3dLwJcUP0=; b=i5UE5wzRnqOkO29mVz82xz8QZPGBOSGKAp5wcl4wWStSXfhCGRRYGB7vBlDTI9VboEODTkEphSy1A2m78jmzjSy7shY4rZ7g3HmMom/RNBO1NwqDqSi1dbTxOoY/AIxDJbH8WZKSvU0f6/XEK43t7WDrUHBXc9gC9+djfZEQrKZ0UP1thdX3xAwAOg+7HAaNfVl5P3iY0oi8W8FOpBlQVlGtCWd81/6MJuC5jxyFJnaKCsUaSN1U5VEeKCqUjN4FdONgQeknFrTpmXFrAcBLZeGktLtEadXfp+PFw2U+z5/C7mz2hlWv00kDSvqOd4O4ygShQmQg3myhqS9k9T5OXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+SfqAfhu+nR9MuPJLjVOmETEtBJwbZgOuF3dLwJcUP0=; b=HC8dE80ECU3LNdG4bkTXKoLd1LBnK/HC9u8swz1YdGmOh3JORgHEMeSfKXh9Y4WdYV2miE6ra94CQzid/lV9X76abxlZbmbhDcrlLUmSV4GIBjkxeVO49SsoHMEqrs5e0pFcPyh6aIP911bQOsafayUN1jGrgR4wjeGNFkBav+4= Received: from MW4PR04CA0039.namprd04.prod.outlook.com (2603:10b6:303:6a::14) by BN9PR12MB5289.namprd12.prod.outlook.com (2603:10b6:408:102::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:27:43 +0000 Received: from CO1NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::d5) by MW4PR04CA0039.outlook.office365.com (2603:10b6:303:6a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:27:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT028.mail.protection.outlook.com (10.13.175.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:27:43 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:27:32 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 2/8] perf tool: Parse pmu caps sysfs only once Date: Wed, 1 Jun 2022 08:56:02 +0530 Message-ID: <20220601032608.1034-3-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6d791dc-3ca0-4208-a001-08da437eb08c X-MS-TrafficTypeDiagnostic: BN9PR12MB5289:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lv5VTFORWbFHkUzSxJ8SXPh9m/w9fTFk5KYCD2t4uFbJVhJ7dHiU+cUJl7sb6V3r3nWZbRTiEvGyxxmIQT0r/qPf9waBwe+xAY06p3ar/VjvGqhCM8gW54XgtPuBe0/BZZmqgChHYCLI79Eh84L3HML0sgTQ5VU9XUyOiTb3bOCRjRpdGWFITzspaSZmJbKw/MTv1n152kTDwkxGkrOT8wdc54IDK7kY6PUyQkmew86SelSBo3btB4AExjm4oyR5Dny70i1hFJcSHSrCG3O8wSC2JuhbAVqodAsZrVTsatnFhXTEJbjvwzpuevdkkJt4iFXCD7FzS8pjIPGEsKk2xZ+ZU5quv6WGaYgupNBZoCo3DZNdr2v7UJ9lLaIl0f5hIuBjwzJ1zbetiOFBB97/SeW6PuEzxf+cRY/CbSAeAU5py/OcqrYt3RrKQdzvPx9TqaTPpWYS1PYdqICmRP+ixDAX8bVzjMh8IYAqz7UoIgGsTISvENNKkMHpXk81uyuPjIQlm6pqa9rvNx4y5YVCgnNhxyj+i3eFSUUyiyNlvg6eJZ72M+QR6BPEHTSmuOIioNtoqAtOnBUxSNY1HZXAvjULZfJrIMwjiNBqW5Q3V21eMQJu7sMHlFCP0ZGSmb+Rh1IFaIZ8XSI8WFuXeZSLU+cmROVtezHPFZGh1552vXc0+0Fg9ymwKCYTsu3WJ/L6Q5RerKc5J2Y91CI4DVKcqg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(86362001)(8936002)(5660300002)(2906002)(44832011)(7416002)(40460700003)(4326008)(8676002)(356005)(70586007)(81166007)(70206006)(426003)(336012)(47076005)(186003)(16526019)(83380400001)(26005)(508600001)(82310400005)(1076003)(36756003)(2616005)(36860700001)(110136005)(6666004)(54906003)(7696005)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:27:43.1418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6d791dc-3ca0-4208-a001-08da437eb08c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5289 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In addition to returning nr_caps, cache it locally in struct perf_pmu. Similarly, cache status of whether caps sysfs has already been parsed or not. These will help to avoid parsing sysfs every time the function gets called. Signed-off-by: Ravi Bangoria Reviewed-by: Kan Liang --- tools/perf/util/pmu.c | 15 +++++++++++---- tools/perf/util/pmu.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 9a1c7e63e663..0112e1c36418 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1890,7 +1890,11 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) const char *sysfs =3D sysfs__mountpoint(); DIR *caps_dir; struct dirent *evt_ent; - int nr_caps =3D 0; + + if (pmu->caps_initialized) + return pmu->nr_caps; + + pmu->nr_caps =3D 0; =20 if (!sysfs) return -1; @@ -1898,8 +1902,10 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) snprintf(caps_path, PATH_MAX, "%s" EVENT_SOURCE_DEVICE_PATH "%s/caps", sysfs, pmu->name); =20 - if (stat(caps_path, &st) < 0) + if (stat(caps_path, &st) < 0) { + pmu->caps_initialized =3D true; return 0; /* no error if caps does not exist */ + } =20 caps_dir =3D opendir(caps_path); if (!caps_dir) @@ -1926,13 +1932,14 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) continue; } =20 - nr_caps++; + pmu->nr_caps++; fclose(file); } =20 closedir(caps_dir); =20 - return nr_caps; + pmu->caps_initialized =3D true; + return pmu->nr_caps; } =20 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 541889fa9f9c..4b45fd8da5a3 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -46,6 +46,8 @@ struct perf_pmu { struct perf_cpu_map *cpus; struct list_head format; /* HEAD struct perf_pmu_format -> list */ struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ + bool caps_initialized; + u32 nr_caps; struct list_head caps; /* HEAD struct perf_pmu_caps -> list */ struct list_head list; /* ELEM */ struct list_head hybrid_list; --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98BABC433F5 for ; Wed, 1 Jun 2022 03:28:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349424AbiFAD2I (ORCPT ); Tue, 31 May 2022 23:28:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349328AbiFAD17 (ORCPT ); Tue, 31 May 2022 23:27:59 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2083.outbound.protection.outlook.com [40.107.101.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE019193E2; Tue, 31 May 2022 20:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SIxsizeTR3pb4+TdsmHyPo3pSKxtz3z88QT4gDbzFcGbOcbCwoJFmdbsLBj2DFij+NIsQL/mC6z9g8hYLaEBNfWVGhJFb8Rm85iEvRNEb+yx5Na7V4HiCviQ6WIAwD2JZVFfgaKK8XxiRosL7dWNxugvVRfcdRTiluLM2pJFb9IwA7bX3/xEHwNtSSxevN68EBsjM+rTLRjOI7NjrNGNzBC++lgQ7/Zod60ZP/IzCfXKPPkyFn9S4FvqNN+PEgUeYZIfUHi/3Ry0CpAaZSLBekco16qVecRGdPCYxJTYJyN8FZ7DHRFT2pGqz+gtmiS0qXh7XCofey+DCXNpEJgpAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mkt/tynDsKaNxQoqRpnUZFfiCYS1vypKIPWHBe1XsPk=; b=bO0xW8jqKEv3SCa9YN+GIP53Ui4aN9/iWm59hSvE3/gq7VzbLxacOiCVIhpsl4M5tbmCCQc0bnGPhvWsQOkxwy3WFVCeqX+481+H8qgHE/t6nBmrLljg0VaGrlG19yfekeCrwkf3TD8VafVuV/d+x3GCRjw3V+8CjoxnT7MRBNZRps56HCkfwRpFQrrNkBI3qnmP0hgDE53RdTTkHwHlyspXYENZlQ6yjskKksKvMnuOEI63+zlBGDjQHnsebe5x7ZgaBCnqDB5mGmHFy00RpLGIEwXp4OswSR7RpY7Wd5H2YQvjlQ8en6BaLjd2fALEqaWxXJrOUOdQN5vbDKpuTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mkt/tynDsKaNxQoqRpnUZFfiCYS1vypKIPWHBe1XsPk=; b=Le8jorbaIKW1vvlDkuduDPSX9BjVnusCaEpHbI1f6Don/6zYl1kZPT+BD1DFL44R4RYdehG+BahhqEbMGkPTcZGG0kxy1t4UyJOiEYhbZodc2QFxHcYNWea2Qh6WgPjkunhvHiMb8HzYVoegwERb0bgO2FKgidExUB0tFlKimqA= Received: from MW4P222CA0029.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::34) by SA0PR12MB4432.namprd12.prod.outlook.com (2603:10b6:806:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:27:56 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::21) by MW4P222CA0029.outlook.office365.com (2603:10b6:303:114::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Wed, 1 Jun 2022 03:27:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:27:55 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:27:42 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 3/8] perf headers: Pass "cpu" pmu name while printing caps Date: Wed, 1 Jun 2022 08:56:03 +0530 Message-ID: <20220601032608.1034-4-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 80f3d44c-0963-4938-f854-08da437eb7fd X-MS-TrafficTypeDiagnostic: SA0PR12MB4432:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u/o/2V5XJFgGJ/JxVnhqDOrTbn1ng6RA+0YgglFMSVlEvmcBPLsXJ4ttfRooJb06VaDJmoDdYjtcgYQRwNE8B8p1Tyylt72NoKDr+88eUMicCEBTdC1SRUCO/W4rqV5bTogaGcvXh2Ljis+Dtirx39eIdbNfQFPqrCSr6t5bJ7RS8oKMYTM9zSmXU5shUA/rCymEHkfeT7s/YtyVXRr06qGzAZ3onNasaBT39bN8sUQ0RmCklb7/5NGbEMSZp0ZsgP5IswAkNWG6pEyG7gEWCn8lP2IJduvHzwk3rSitebc9dp5jnGEvnWvmd6nGDqn0YUlva5dEqOC9ql0F1qlQ1audIpFbqP2IdRa5Aejea1ikupYkK6+svz3ACZFKTCNF4RztVNYx0osuFgnz67wBnnYARoXnv8X1DwOTu4e9+NkSmCc1viQGqJYHbp4q1jGUjIOV4znaOnUN6Ai2VDRSv0v+XJ84LnPtYVARu0ZJDcxUO0QllK2/krK64D+OXp3j/m5RCYYiexj8yMbrmnJ2Dq/1WgUsCBDcQZg8vRtMYny7ou0WrZS4H56LO3zoJJ9y3di9AruDC+7eYeYdY6u9did9UJiq550+uyItB87wx6XQxYAvCiKooZrX7kE3nJYIjOK0s/Qi9J8tQLsLX9jBZdVHH61MxhvWxAQmV5jeomzSCSPGIgldwhFQEkjFszRXEZi+49k0m1I5FJRbxZOfjQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(36860700001)(5660300002)(7416002)(82310400005)(36756003)(316002)(81166007)(2906002)(356005)(8936002)(44832011)(110136005)(54906003)(26005)(7696005)(508600001)(6666004)(4326008)(8676002)(70206006)(70586007)(2616005)(336012)(16526019)(83380400001)(426003)(1076003)(47076005)(40460700003)(186003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:27:55.5661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80f3d44c-0963-4938-f854-08da437eb7fd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4432 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Avoid unnecessary conditional code to check if pmu name is NULL or not by passing "cpu" pmu name to the printing function. Signed-off-by: Ravi Bangoria Reviewed-by: Kan Liang --- tools/perf/util/header.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 53332da100e8..ee7ccd94e272 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2058,17 +2058,11 @@ static void print_per_cpu_pmu_caps(FILE *fp, int nr= _caps, char *cpu_pmu_caps, char *str, buf[128]; =20 if (!nr_caps) { - if (!pmu_name) - fprintf(fp, "# cpu pmu capabilities: not available\n"); - else - fprintf(fp, "# %s pmu capabilities: not available\n", pmu_name); + fprintf(fp, "# %s pmu capabilities: not available\n", pmu_name); return; } =20 - if (!pmu_name) - scnprintf(buf, sizeof(buf), "# cpu pmu capabilities: "); - else - scnprintf(buf, sizeof(buf), "# %s pmu capabilities: ", pmu_name); + scnprintf(buf, sizeof(buf), "# %s pmu capabilities: ", pmu_name); =20 delimiter =3D buf; =20 @@ -2085,7 +2079,7 @@ static void print_per_cpu_pmu_caps(FILE *fp, int nr_c= aps, char *cpu_pmu_caps, static void print_cpu_pmu_caps(struct feat_fd *ff, FILE *fp) { print_per_cpu_pmu_caps(fp, ff->ph->env.nr_cpu_pmu_caps, - ff->ph->env.cpu_pmu_caps, NULL); + ff->ph->env.cpu_pmu_caps, (char *)"cpu"); } =20 static void print_hybrid_cpu_pmu_caps(struct feat_fd *ff, FILE *fp) --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 234F2C433EF for ; Wed, 1 Jun 2022 03:28:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349336AbiFAD2W (ORCPT ); Tue, 31 May 2022 23:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349440AbiFAD2P (ORCPT ); Tue, 31 May 2022 23:28:15 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2077.outbound.protection.outlook.com [40.107.94.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204FE36328; Tue, 31 May 2022 20:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FURpJN5B1yvxZpFUDdenk6/qS7izB/pnoGSSbjHaIX1kxyEFG/CKHtQ5Px/ZxUMK6wEN9kJkDGYdHTOqCMfHUorJ6EVtIIPqYbivizNm/BwgRr7MjUjDzF6MkpmGrsIyATZDYqbcPZWrSnj85QxzrSzxhe2tv0N4yEN92fqetUSL0UYmuRep+XFueza/bizlbyZncb4BhTDKDapKqA3BDDhD/uKkdI5M2W7MjJqLHPJgf2q6xXGVYTJDtlWkuYj+Sgy660IFOgMEFRnR9nsnJgUvnpEkzGt6Cf6oZfefsIN9boWstoPRGlu6du7Jhvzd2f65n0yjCwR1fYlXRpeJqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TNmzjOJZ1pq+w3hldaiG/m1QiouuoF7/Y5w8Xl3I0xo=; b=QINKlTDU/EP2GutP+K6vMSheDrUByBeYatnWuFFNMngYcKHBuVMbXZyo3nsK0dBnEVSufgmtbfFwXZ6JhovN+xN68xczSFBgOHy4aBmeAB6MwP8uDNqmdYBzNn/Xth8ksvxIbkQqd+BSEEY0hwrQyfYH2/Z8su5jshySqpTPZ7cfCH/NXS0bYvfDPD9+e0b1m0sh1sHlmLy1mo7Vte1a02a1ugBG+wTCgDSGVWlgTRFOsnreeJzQoJLskBY2X54yT1OUGiM87yl3nrXb8AhXan/xR/SXLtzE/QT7UgFU/UcqXcSk1RlNJqyAK0ALeTV/syiiRYDFdS1cAE/EiulGtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TNmzjOJZ1pq+w3hldaiG/m1QiouuoF7/Y5w8Xl3I0xo=; b=Hi/I6y4I9aK7/1Jp/4FoV8A8yQzvJb+Yyo5y+es1Z/SDFHmQQmH9UfaVD+rVUoVxjSpbvujHn+PbSFlAMzBxyVtQmhsRYKtrz5soDUR2U8rGkZZpyT5K1/UxcgihJIiVZQZov1vynU3DZ+Kx8ldTbtE814YsmzNN/nuxvgpnO7g= Received: from MWHPR10CA0016.namprd10.prod.outlook.com (2603:10b6:301::26) by CY5PR12MB6622.namprd12.prod.outlook.com (2603:10b6:930:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.19; Wed, 1 Jun 2022 03:28:07 +0000 Received: from CO1NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:301:0:cafe::37) by MWHPR10CA0016.outlook.office365.com (2603:10b6:301::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:28:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT008.mail.protection.outlook.com (10.13.175.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:28:07 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:27:54 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 4/8] perf headers: Store pmu caps in an array of strings Date: Wed, 1 Jun 2022 08:56:04 +0530 Message-ID: <20220601032608.1034-5-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6134f06-38f8-4ab3-75c9-08da437ebef2 X-MS-TrafficTypeDiagnostic: CY5PR12MB6622:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +F3U6iUl/Ere5zRGdaxIVantd3u1MAkSMJbReene8pdiCvS6h/9nA76fwxoivEvHVYO/NQ1lgfVS3ejAVXvhIc/JCsRJojGIbcP+kQEV8DqpqkRT/KT3m/JZ+D4uZGeogTDNqDviOSpSBfxW4EfqRB+oUUpT9j4bBVW7FCmH8LLCzwdYU/dl2J91nwEuKzJbvW+eqzjTfWrVpv+LP6WlGBG5I58FAhEbSW5LKcHDUDKJinCc6Nz5bX0+ThLVTzQAH/jZkm76BX4/iChTTU4fNbXpZIQxl/B9HIsYI2kKxYDyt0yyuHTwu0NGkuP5itB+T7uvCtYQzyBqGCBkP8KvEo1uZMJmWTS+9bk6nY2ESnLTl2wdKxl1i8fa4UjTB3rkG/Yw7Gi4G75/CSXsAichcSsYCS7go5P5xYJaW08G6zFxnEKPsr/nyl4RQfsdJ3wJuK+8vaijCxcnhcMKRSnSLKemGNimZzQTtoId1Vy/awv2jApgLnjM+xnsco0ALAX0H5peh/5+Mfx6Ttbef84mmgeWlqFENSJh0rUggSIMHzzgZmN618fi3t8ajGlM0p4XRjGH/CwOw2NOXflJHthBuTWYvTr7e0LwfHhONhigPnZ7AJWFavlREIJ4UHfjMXQw1J8elBwAKECsmHvgDqX7l5lVqcr2vZfgwJlnn2UgBJT+Jm+OAdW/1a/AWRMjrjdOjmNNOVs7y1VSsDEngQPXUA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(44832011)(2616005)(82310400005)(36860700001)(81166007)(356005)(110136005)(47076005)(36756003)(83380400001)(316002)(336012)(426003)(7696005)(2906002)(6666004)(54906003)(40460700003)(186003)(7416002)(86362001)(8936002)(5660300002)(4326008)(8676002)(508600001)(70586007)(70206006)(1076003)(26005)(16526019)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:28:07.2972 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6134f06-38f8-4ab3-75c9-08da437ebef2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6622 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently all capabilities are stored in a single string separated by NULL character. Instead, store them in an array which makes searching of capability easier. Signed-off-by: Ravi Bangoria Reviewed-by: Kan Liang --- tools/perf/util/env.c | 6 +++- tools/perf/util/env.h | 4 +-- tools/perf/util/header.c | 70 +++++++++++++++++++++++----------------- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 579e44c59914..7d3aeb2e4622 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -179,7 +179,7 @@ static void perf_env__purge_bpf(struct perf_env *env __= maybe_unused) =20 void perf_env__exit(struct perf_env *env) { - int i; + int i, j; =20 perf_env__purge_bpf(env); perf_env__purge_cgroups(env); @@ -196,6 +196,8 @@ void perf_env__exit(struct perf_env *env) zfree(&env->sibling_threads); zfree(&env->pmu_mappings); zfree(&env->cpu); + for (i =3D 0; i < env->nr_cpu_pmu_caps; i++) + zfree(&env->cpu_pmu_caps[i]); zfree(&env->cpu_pmu_caps); zfree(&env->numa_map); =20 @@ -218,6 +220,8 @@ void perf_env__exit(struct perf_env *env) zfree(&env->hybrid_nodes); =20 for (i =3D 0; i < env->nr_hybrid_cpc_nodes; i++) { + for (j =3D 0; j < env->hybrid_cpc_nodes[i].nr_cpu_pmu_caps; j++) + zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps[j]); zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps); zfree(&env->hybrid_cpc_nodes[i].pmu_name); } diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index a3541f98e1fc..43aab59f7322 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -46,7 +46,7 @@ struct hybrid_node { struct hybrid_cpc_node { int nr_cpu_pmu_caps; unsigned int max_branches; - char *cpu_pmu_caps; + char **cpu_pmu_caps; char *pmu_name; }; =20 @@ -81,7 +81,7 @@ struct perf_env { char *sibling_dies; char *sibling_threads; char *pmu_mappings; - char *cpu_pmu_caps; + char **cpu_pmu_caps; struct cpu_topology_map *cpu; struct cpu_cache_level *caches; int caches_cnt; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index ee7ccd94e272..a1e4ec53333d 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2051,26 +2051,21 @@ static void print_compressed(struct feat_fd *ff, FI= LE *fp) ff->ph->env.comp_level, ff->ph->env.comp_ratio); } =20 -static void print_per_cpu_pmu_caps(FILE *fp, int nr_caps, char *cpu_pmu_ca= ps, +static void print_per_cpu_pmu_caps(FILE *fp, int nr_caps, char **cpu_pmu_c= aps, char *pmu_name) { - const char *delimiter; - char *str, buf[128]; + const char *delimiter =3D ""; + int i; =20 if (!nr_caps) { fprintf(fp, "# %s pmu capabilities: not available\n", pmu_name); return; } =20 - scnprintf(buf, sizeof(buf), "# %s pmu capabilities: ", pmu_name); - - delimiter =3D buf; - - str =3D cpu_pmu_caps; - while (nr_caps--) { - fprintf(fp, "%s%s", delimiter, str); + fprintf(fp, "# %s pmu capabilities: ", pmu_name); + for (i =3D 0; i < nr_caps; i++) { + fprintf(fp, "%s%s", delimiter, cpu_pmu_caps[i]); delimiter =3D ", "; - str +=3D strlen(str) + 1; } =20 fprintf(fp, "\n"); @@ -3202,27 +3197,27 @@ static int process_compressed(struct feat_fd *ff, } =20 static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_ca= ps, - char **cpu_pmu_caps, + char ***cpu_pmu_caps, unsigned int *max_branches) { - char *name, *value; - struct strbuf sb; - u32 nr_caps; + int name_size, value_size; + char *name, *value, *ptr; + u32 nr_caps, i; + + *nr_cpu_pmu_caps =3D 0; + *cpu_pmu_caps =3D NULL; =20 if (do_read_u32(ff, &nr_caps)) return -1; =20 - if (!nr_caps) { - pr_debug("cpu pmu capabilities not available\n"); + if (!nr_caps) return 0; - } - - *nr_cpu_pmu_caps =3D nr_caps; =20 - if (strbuf_init(&sb, 128) < 0) + *cpu_pmu_caps =3D zalloc(sizeof(char *) * nr_caps); + if (!*cpu_pmu_caps) return -1; =20 - while (nr_caps--) { + for (i =3D 0; i < nr_caps; i++) { name =3D do_read_string(ff); if (!name) goto error; @@ -3231,12 +3226,16 @@ static int process_per_cpu_pmu_caps(struct feat_fd = *ff, int *nr_cpu_pmu_caps, if (!value) goto free_name; =20 - if (strbuf_addf(&sb, "%s=3D%s", name, value) < 0) + name_size =3D strlen(name); + value_size =3D strlen(value); + ptr =3D zalloc(sizeof(char) * (name_size + value_size + 2)); + if (!ptr) goto free_value; =20 - /* include a NULL character at the end */ - if (strbuf_add(&sb, "", 1) < 0) - goto free_value; + memcpy(ptr, name, name_size); + ptr[name_size] =3D '=3D'; + memcpy(ptr + name_size + 1, value, value_size); + (*cpu_pmu_caps)[i] =3D ptr; =20 if (!strcmp(name, "branches")) *max_branches =3D atoi(value); @@ -3244,7 +3243,7 @@ static int process_per_cpu_pmu_caps(struct feat_fd *f= f, int *nr_cpu_pmu_caps, free(value); free(name); } - *cpu_pmu_caps =3D strbuf_detach(&sb, NULL); + *nr_cpu_pmu_caps =3D nr_caps; return 0; =20 free_value: @@ -3252,16 +3251,24 @@ static int process_per_cpu_pmu_caps(struct feat_fd = *ff, int *nr_cpu_pmu_caps, free_name: free(name); error: - strbuf_release(&sb); + for (; i > 0; i--) + free((*cpu_pmu_caps)[i - 1]); + free(*cpu_pmu_caps); + *cpu_pmu_caps =3D NULL; + *nr_cpu_pmu_caps =3D 0; return -1; } =20 static int process_cpu_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) { - return process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps, + int ret =3D process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps, &ff->ph->env.cpu_pmu_caps, &ff->ph->env.max_branches); + + if (!ret && !ff->ph->env.cpu_pmu_caps) + pr_debug("cpu pmu capabilities not available\n"); + return ret; } =20 static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff, @@ -3270,6 +3277,7 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd= *ff, struct hybrid_cpc_node *nodes; u32 nr_pmu, i; int ret; + int j; =20 if (do_read_u32(ff, &nr_pmu)) return -1; @@ -3297,6 +3305,8 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd= *ff, ret =3D -1; goto err; } + if (!n->nr_cpu_pmu_caps) + pr_debug("%s pmu capabilities not available\n", n->pmu_name); } =20 ff->ph->env.nr_hybrid_cpc_nodes =3D nr_pmu; @@ -3305,6 +3315,8 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd= *ff, =20 err: for (i =3D 0; i < nr_pmu; i++) { + for (j =3D 0; j < nodes[i].nr_cpu_pmu_caps; j++) + free(nodes[i].cpu_pmu_caps[j]); free(nodes[i].cpu_pmu_caps); free(nodes[i].pmu_name); } --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0ABEC433F5 for ; Wed, 1 Jun 2022 03:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345493AbiFAD3n (ORCPT ); Tue, 31 May 2022 23:29:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238153AbiFAD3k (ORCPT ); Tue, 31 May 2022 23:29:40 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2073.outbound.protection.outlook.com [40.107.236.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89A3965410; Tue, 31 May 2022 20:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VKmQMykzxsUC1XwGgrCLn/8oL0ZRsY+SQkDGBxXUBGxBBw2qvfYlUEgP+QKoCELgBw18fKC1v8+/atbumTCEBxKHvGjw5VtMsiNO/N6HOedDj/e5LrhYMtJW5QJHOGVJ0xVeiY0P1EnuEcPcZHiIT4a5PIo4Unr6RGj5paOELKZo/K4Xfkwz34wi4SJtR4Kib0B4n1PbRL0BQldGcZLiOuO5gn7736wdcokmVp1+d1NM3wE4neJTuNeabjWyqdsLuLvS10z5EznCb6MhqP4EI/hDdq9UCxir3b59sV184FwGQRAPswkiH2DZXtAkcbQDxwJB4l9ZvklngJRA5c5K8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V7xwJr+2j+9Bz4l8HMhBWEMPVNUunwwcSpq/De6BvsU=; b=Z8L8VU39i/0dDj5HApK7r3626ceTfj4t/y0LRXCmCoq6dUr8soMwgWzakZ3M8B4vnQx8Eiy5uko3pZ8RjlnFOtknWP9sVitBAGlFuAAvQLOAD6HcgAJ8zqVJEpjj78gIaYjwYcm7I6+nPjBwsEfPlXBBzTqnFTGpQmop2Wj3tPnuM7Hn+rVQZfELE/CNoQnqkA1pFkcwrvXhmYikNeTEhzit+KUoISYM4LLPa8WrQkpSZVTiAgmEnIWjs5JpswWIy1Lv22XSjmcBzUKgPxudioFGmHZRfdwTV500G77SZtU/KwLT50kOzth+mPXpkQfj9u6gbKI1LCe2bnsLZfTqQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V7xwJr+2j+9Bz4l8HMhBWEMPVNUunwwcSpq/De6BvsU=; b=4fJ1iSNna3zMvk8BVufzJRnZdUCkxVz/XFh1KUAFLU3brt8ERxS1nXbY2PU7lp2B69ojb86p+ALTh9cIprl1xxPs+kVUsNkmQpm7vzKFMsYqruaW+Mk+OYzz7HPO1czAl1MZkQnNxEcTshRjfHlZEwOGv2hclR4qaFdMk6Plo3M= Received: from MW2PR16CA0013.namprd16.prod.outlook.com (2603:10b6:907::26) by BN9PR12MB5098.namprd12.prod.outlook.com (2603:10b6:408:137::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Wed, 1 Jun 2022 03:29:36 +0000 Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com (2603:10b6:907:0:cafe::40) by MW2PR16CA0013.outlook.office365.com (2603:10b6:907::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:29:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:29:35 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:28:05 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 5/8] perf headers: Record non-cpu pmu capabilities Date: Wed, 1 Jun 2022 08:56:05 +0530 Message-ID: <20220601032608.1034-6-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6cc20d4b-25a0-4dc2-1227-08da437ef390 X-MS-TrafficTypeDiagnostic: BN9PR12MB5098:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pdXYllgx4kGG9U7sFLbWDRjqzvtsvg2Ji5eNnp854RkxBosRuOm22EBBVwfFCNJfTAFNKtPOE3yCH9Ix9UednqKulaIN/PHTGBCy1DWuGT4ybH39QBfzxw65Js33sHy7215Hu1MPh7rSlsPXJ29GN5Gw3UegETFmOxIUC7/pz0VMU8FB0PS6jXUTn5DAAQaxOZfWuYPefj08ZpieTS9ActaT07yFKCuQOO7Mjwk+yA5Ru4HcWutFDpKk6XC+tGdLoyj/+Aci7I2a4EGZUFAGcqwrJXNgyK+8GLY3L1yL9Tgckb8yF1q1cRKl9TLHzVgtIWWNlKeJTphD3b1hXDK3u7jlBpZIvw93xlQbkhE7KO5E3G8oCXIRLYlXf3H6joKU9TRYHfuH9Ap8JakwrVfxRUq7US7bHO1jEyCm8p8HKYR+FxWbaVR0pkO8apqInHhh/z0li91Wdknb6smcEAgTuHw0k6vbE//+qxw4S8d2FDeW8Lkz/TXFzBQ8KGz4hGPiJV2NAqHgoU86UBQw+A1XUyRJXuk+IhN1dwhLbM2bntAet333OxgF/aQeXxEsV9bbwRvfVDqyfrTEufw0hMqr/EMvzN0705t7GgQwTItUYWw82ejnFzxYhD+YysbiNHCf060uYJDB6StGvCGlwbXDvd7Ss+Jnhj8UnUbB6ELFk0b2bx1LovXQeEKJvcwondlVHePWD3deL687YIm+Yj1XEw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(70206006)(508600001)(70586007)(40460700003)(7696005)(426003)(86362001)(26005)(5660300002)(16526019)(1076003)(47076005)(186003)(44832011)(54906003)(2616005)(7416002)(8936002)(30864003)(2906002)(83380400001)(8676002)(82310400005)(36756003)(36860700001)(81166007)(4326008)(316002)(110136005)(356005)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:29:35.5873 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6cc20d4b-25a0-4dc2-1227-08da437ef390 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5098 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Pmus advertise their capabilities via sysfs attribute files but perf tool currently parses only core(cpu) or hybrid core pmu capabilities. Add support of recording non-core pmu capabilities int perf.data header. Note that a newly proposed HEADER_PMU_CAPS is replacing existing HEADER_HYBRID_CPU_PMU_CAPS. Special care is taken for hybrid core pmus by writing their capabilities first in the perf.data header to make sure new perf.data file being read by old perf tool does not break. Signed-off-by: Ravi Bangoria --- .../Documentation/perf.data-file-format.txt | 10 +- tools/perf/builtin-inject.c | 2 +- tools/perf/util/env.c | 60 ++++++- tools/perf/util/env.h | 12 +- tools/perf/util/header.c | 160 ++++++++++-------- tools/perf/util/header.h | 2 +- 6 files changed, 158 insertions(+), 88 deletions(-) diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/per= f/Documentation/perf.data-file-format.txt index f56d0e0fbff6..2233534e508a 100644 --- a/tools/perf/Documentation/perf.data-file-format.txt +++ b/tools/perf/Documentation/perf.data-file-format.txt @@ -419,18 +419,20 @@ Example: cpu_core cpu list : 0-15 cpu_atom cpu list : 16-23 =20 - HEADER_HYBRID_CPU_PMU_CAPS =3D 31, + HEADER_PMU_CAPS =3D 31, =20 - A list of hybrid CPU PMU capabilities. + List of pmu capabilities (except cpu pmu which is already + covered by HEADER_CPU_PMU_CAPS). Note that hybrid cpu pmu + capabilities are also stored here. =20 struct { u32 nr_pmu; struct { - u32 nr_cpu_pmu_caps; + u32 nr_caps; { char name[]; char value[]; - } [nr_cpu_pmu_caps]; + } [nr_caps]; char pmu_name[]; } [nr_pmu]; }; diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a75bf11585b5..05bc0cfccf83 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -809,7 +809,7 @@ static bool keep_feat(int feat) case HEADER_CPU_PMU_CAPS: case HEADER_CLOCK_DATA: case HEADER_HYBRID_TOPOLOGY: - case HEADER_HYBRID_CPU_PMU_CAPS: + case HEADER_PMU_CAPS: return true; /* Information that can be updated */ case HEADER_BUILD_ID: diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 7d3aeb2e4622..5b8cf6a421a4 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -219,13 +219,13 @@ void perf_env__exit(struct perf_env *env) } zfree(&env->hybrid_nodes); =20 - for (i =3D 0; i < env->nr_hybrid_cpc_nodes; i++) { - for (j =3D 0; j < env->hybrid_cpc_nodes[i].nr_cpu_pmu_caps; j++) - zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps[j]); - zfree(&env->hybrid_cpc_nodes[i].cpu_pmu_caps); - zfree(&env->hybrid_cpc_nodes[i].pmu_name); + for (i =3D 0; i < env->nr_pmus_with_caps; i++) { + for (j =3D 0; j < env->pmu_caps[i].nr_caps; j++) + zfree(&env->pmu_caps[i].caps[j]); + zfree(&env->pmu_caps[i].caps); + zfree(&env->pmu_caps[i].pmu_name); } - zfree(&env->hybrid_cpc_nodes); + zfree(&env->pmu_caps); } =20 void perf_env__init(struct perf_env *env) @@ -531,3 +531,51 @@ int perf_env__numa_node(struct perf_env *env, struct p= erf_cpu cpu) =20 return cpu.cpu >=3D 0 && cpu.cpu < env->nr_numa_map ? env->numa_map[cpu.c= pu] : -1; } + +char *perf_env__find_pmu_cap(struct perf_env *env, const char *pmu_name, + const char *cap) +{ + char *cap_eq; + int cap_size; + char **ptr; + int i, j; + + if (!pmu_name || !cap) + return NULL; + + cap_size =3D strlen(cap); + cap_eq =3D zalloc(cap_size + 2); + if (!cap_eq) + return NULL; + + memcpy(cap_eq, cap, cap_size); + cap_eq[cap_size] =3D '=3D'; + + if (!strcmp(pmu_name, "cpu")) { + for (i =3D 0; i < env->nr_cpu_pmu_caps; i++) { + if (!strncmp(env->cpu_pmu_caps[i], cap_eq, cap_size + 1)) { + free(cap_eq); + return &env->cpu_pmu_caps[i][cap_size + 1]; + } + } + goto out; + } + + for (i =3D 0; i < env->nr_pmus_with_caps; i++) { + if (strcmp(env->pmu_caps[i].pmu_name, pmu_name)) + continue; + + ptr =3D env->pmu_caps[i].caps; + + for (j =3D 0; j < env->pmu_caps[i].nr_caps; j++) { + if (!strncmp(ptr[j], cap_eq, cap_size + 1)) { + free(cap_eq); + return &ptr[j][cap_size + 1]; + } + } + } + +out: + free(cap_eq); + return NULL; +} diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 43aab59f7322..4566c51f2fd9 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -43,10 +43,10 @@ struct hybrid_node { char *cpus; }; =20 -struct hybrid_cpc_node { - int nr_cpu_pmu_caps; +struct pmu_caps { + int nr_caps; unsigned int max_branches; - char **cpu_pmu_caps; + char **caps; char *pmu_name; }; =20 @@ -74,7 +74,7 @@ struct perf_env { int nr_groups; int nr_cpu_pmu_caps; int nr_hybrid_nodes; - int nr_hybrid_cpc_nodes; + int nr_pmus_with_caps; char *cmdline; const char **cmdline_argv; char *sibling_cores; @@ -94,7 +94,7 @@ struct perf_env { struct memory_node *memory_nodes; unsigned long long memory_bsize; struct hybrid_node *hybrid_nodes; - struct hybrid_cpc_node *hybrid_cpc_nodes; + struct pmu_caps *pmu_caps; #ifdef HAVE_LIBBPF_SUPPORT /* * bpf_info_lock protects bpf rbtrees. This is needed because the @@ -172,4 +172,6 @@ bool perf_env__insert_btf(struct perf_env *env, struct = btf_node *btf_node); struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id); =20 int perf_env__numa_node(struct perf_env *env, struct perf_cpu cpu); +char *perf_env__find_pmu_cap(struct perf_env *env, const char *pmu_name, + const char *cap); #endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index a1e4ec53333d..67bf897e8f89 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -1512,18 +1512,13 @@ static int write_compressed(struct feat_fd *ff __ma= ybe_unused, return do_write(ff, &(ff->ph->env.comp_mmap_len), sizeof(ff->ph->env.comp= _mmap_len)); } =20 -static int write_per_cpu_pmu_caps(struct feat_fd *ff, struct perf_pmu *pmu, - bool write_pmu) +static int __write_pmu_caps(struct feat_fd *ff, struct perf_pmu *pmu, + bool write_pmu) { struct perf_pmu_caps *caps =3D NULL; - int nr_caps; int ret; =20 - nr_caps =3D perf_pmu__caps_parse(pmu); - if (nr_caps < 0) - return nr_caps; - - ret =3D do_write(ff, &nr_caps, sizeof(nr_caps)); + ret =3D do_write(ff, &pmu->nr_caps, sizeof(pmu->nr_caps)); if (ret < 0) return ret; =20 @@ -1550,33 +1545,60 @@ static int write_cpu_pmu_caps(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { struct perf_pmu *cpu_pmu =3D perf_pmu__find("cpu"); + int ret; =20 if (!cpu_pmu) return -ENOENT; =20 - return write_per_cpu_pmu_caps(ff, cpu_pmu, false); + ret =3D perf_pmu__caps_parse(cpu_pmu); + if (ret < 0) + return ret; + + return __write_pmu_caps(ff, cpu_pmu, false); } =20 -static int write_hybrid_cpu_pmu_caps(struct feat_fd *ff, - struct evlist *evlist __maybe_unused) +static int write_pmu_caps(struct feat_fd *ff, + struct evlist *evlist __maybe_unused) { - struct perf_pmu *pmu; - u32 nr_pmu =3D perf_pmu__hybrid_pmu_num(); + struct perf_pmu *pmu =3D NULL; + int nr_pmu =3D 0; int ret; =20 - if (nr_pmu =3D=3D 0) - return -ENOENT; + while ((pmu =3D perf_pmu__scan(pmu))) { + if (!pmu->name || !strcmp(pmu->name, "cpu") || + perf_pmu__caps_parse(pmu) <=3D 0) + continue; + nr_pmu++; + } =20 ret =3D do_write(ff, &nr_pmu, sizeof(nr_pmu)); if (ret < 0) return ret; =20 + if (!nr_pmu) + return 0; + + /* + * Write hybrid pmu caps first to maintain compatibility with + * older perf tool. + */ + pmu =3D NULL; perf_pmu__for_each_hybrid_pmu(pmu) { - ret =3D write_per_cpu_pmu_caps(ff, pmu, true); + ret =3D __write_pmu_caps(ff, pmu, true); if (ret < 0) return ret; } =20 + pmu =3D NULL; + while ((pmu =3D perf_pmu__scan(pmu))) { + if (!pmu->name || !strcmp(pmu->name, "cpu") || + !pmu->nr_caps || perf_pmu__is_hybrid(pmu->name)) + continue; + + ret =3D __write_pmu_caps(ff, pmu, true); + if (ret < 0) + return ret; + } return 0; } =20 @@ -2051,8 +2073,7 @@ static void print_compressed(struct feat_fd *ff, FILE= *fp) ff->ph->env.comp_level, ff->ph->env.comp_ratio); } =20 -static void print_per_cpu_pmu_caps(FILE *fp, int nr_caps, char **cpu_pmu_c= aps, - char *pmu_name) +static void __print_pmu_caps(FILE *fp, int nr_caps, char **caps, char *pmu= _name) { const char *delimiter =3D ""; int i; @@ -2064,7 +2085,7 @@ static void print_per_cpu_pmu_caps(FILE *fp, int nr_c= aps, char **cpu_pmu_caps, =20 fprintf(fp, "# %s pmu capabilities: ", pmu_name); for (i =3D 0; i < nr_caps; i++) { - fprintf(fp, "%s%s", delimiter, cpu_pmu_caps[i]); + fprintf(fp, "%s%s", delimiter, caps[i]); delimiter =3D ", "; } =20 @@ -2073,19 +2094,18 @@ static void print_per_cpu_pmu_caps(FILE *fp, int nr= _caps, char **cpu_pmu_caps, =20 static void print_cpu_pmu_caps(struct feat_fd *ff, FILE *fp) { - print_per_cpu_pmu_caps(fp, ff->ph->env.nr_cpu_pmu_caps, - ff->ph->env.cpu_pmu_caps, (char *)"cpu"); + __print_pmu_caps(fp, ff->ph->env.nr_cpu_pmu_caps, + ff->ph->env.cpu_pmu_caps, (char *)"cpu"); } =20 -static void print_hybrid_cpu_pmu_caps(struct feat_fd *ff, FILE *fp) +static void print_pmu_caps(struct feat_fd *ff, FILE *fp) { - struct hybrid_cpc_node *n; + struct pmu_caps *pmu_caps; =20 - for (int i =3D 0; i < ff->ph->env.nr_hybrid_cpc_nodes; i++) { - n =3D &ff->ph->env.hybrid_cpc_nodes[i]; - print_per_cpu_pmu_caps(fp, n->nr_cpu_pmu_caps, - n->cpu_pmu_caps, - n->pmu_name); + for (int i =3D 0; i < ff->ph->env.nr_pmus_with_caps; i++) { + pmu_caps =3D &ff->ph->env.pmu_caps[i]; + __print_pmu_caps(fp, pmu_caps->nr_caps, pmu_caps->caps, + pmu_caps->pmu_name); } } =20 @@ -3196,28 +3216,27 @@ static int process_compressed(struct feat_fd *ff, return 0; } =20 -static int process_per_cpu_pmu_caps(struct feat_fd *ff, int *nr_cpu_pmu_ca= ps, - char ***cpu_pmu_caps, - unsigned int *max_branches) +static int __process_pmu_caps(struct feat_fd *ff, int *nr_caps, + char ***caps, unsigned int *max_branches) { int name_size, value_size; char *name, *value, *ptr; - u32 nr_caps, i; + u32 nr_pmu_caps, i; =20 - *nr_cpu_pmu_caps =3D 0; - *cpu_pmu_caps =3D NULL; + *nr_caps =3D 0; + *caps =3D NULL; =20 - if (do_read_u32(ff, &nr_caps)) + if (do_read_u32(ff, &nr_pmu_caps)) return -1; =20 - if (!nr_caps) + if (!nr_pmu_caps) return 0; =20 - *cpu_pmu_caps =3D zalloc(sizeof(char *) * nr_caps); - if (!*cpu_pmu_caps) + *caps =3D zalloc(sizeof(char *) * nr_pmu_caps); + if (!*caps) return -1; =20 - for (i =3D 0; i < nr_caps; i++) { + for (i =3D 0; i < nr_pmu_caps; i++) { name =3D do_read_string(ff); if (!name) goto error; @@ -3235,7 +3254,7 @@ static int process_per_cpu_pmu_caps(struct feat_fd *f= f, int *nr_cpu_pmu_caps, memcpy(ptr, name, name_size); ptr[name_size] =3D '=3D'; memcpy(ptr + name_size + 1, value, value_size); - (*cpu_pmu_caps)[i] =3D ptr; + (*caps)[i] =3D ptr; =20 if (!strcmp(name, "branches")) *max_branches =3D atoi(value); @@ -3243,7 +3262,7 @@ static int process_per_cpu_pmu_caps(struct feat_fd *f= f, int *nr_cpu_pmu_caps, free(value); free(name); } - *nr_cpu_pmu_caps =3D nr_caps; + *nr_caps =3D nr_pmu_caps; return 0; =20 free_value: @@ -3252,29 +3271,28 @@ static int process_per_cpu_pmu_caps(struct feat_fd = *ff, int *nr_cpu_pmu_caps, free(name); error: for (; i > 0; i--) - free((*cpu_pmu_caps)[i - 1]); - free(*cpu_pmu_caps); - *cpu_pmu_caps =3D NULL; - *nr_cpu_pmu_caps =3D 0; + free((*caps)[i - 1]); + free(*caps); + *caps =3D NULL; + *nr_caps =3D 0; return -1; } =20 static int process_cpu_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) { - int ret =3D process_per_cpu_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps, - &ff->ph->env.cpu_pmu_caps, - &ff->ph->env.max_branches); + int ret =3D __process_pmu_caps(ff, &ff->ph->env.nr_cpu_pmu_caps, + &ff->ph->env.cpu_pmu_caps, + &ff->ph->env.max_branches); =20 if (!ret && !ff->ph->env.cpu_pmu_caps) pr_debug("cpu pmu capabilities not available\n"); return ret; } =20 -static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff, - void *data __maybe_unused) +static int process_pmu_caps(struct feat_fd *ff, void *data __maybe_unused) { - struct hybrid_cpc_node *nodes; + struct pmu_caps *pmu_caps; u32 nr_pmu, i; int ret; int j; @@ -3283,45 +3301,45 @@ static int process_hybrid_cpu_pmu_caps(struct feat_= fd *ff, return -1; =20 if (!nr_pmu) { - pr_debug("hybrid cpu pmu capabilities not available\n"); + pr_debug("pmu capabilities not available\n"); return 0; } =20 - nodes =3D zalloc(sizeof(*nodes) * nr_pmu); - if (!nodes) + pmu_caps =3D zalloc(sizeof(*pmu_caps) * nr_pmu); + if (!pmu_caps) return -ENOMEM; =20 for (i =3D 0; i < nr_pmu; i++) { - struct hybrid_cpc_node *n =3D &nodes[i]; - - ret =3D process_per_cpu_pmu_caps(ff, &n->nr_cpu_pmu_caps, - &n->cpu_pmu_caps, - &n->max_branches); + ret =3D __process_pmu_caps(ff, &pmu_caps[i].nr_caps, + &pmu_caps[i].caps, + &pmu_caps[i].max_branches); if (ret) goto err; =20 - n->pmu_name =3D do_read_string(ff); - if (!n->pmu_name) { + pmu_caps[i].pmu_name =3D do_read_string(ff); + if (!pmu_caps[i].pmu_name) { ret =3D -1; goto err; } - if (!n->nr_cpu_pmu_caps) - pr_debug("%s pmu capabilities not available\n", n->pmu_name); + if (!pmu_caps[i].nr_caps) { + pr_debug("%s pmu capabilities not available\n", + pmu_caps[i].pmu_name); + } } =20 - ff->ph->env.nr_hybrid_cpc_nodes =3D nr_pmu; - ff->ph->env.hybrid_cpc_nodes =3D nodes; + ff->ph->env.nr_pmus_with_caps =3D nr_pmu; + ff->ph->env.pmu_caps =3D pmu_caps; return 0; =20 err: for (i =3D 0; i < nr_pmu; i++) { - for (j =3D 0; j < nodes[i].nr_cpu_pmu_caps; j++) - free(nodes[i].cpu_pmu_caps[j]); - free(nodes[i].cpu_pmu_caps); - free(nodes[i].pmu_name); + for (j =3D 0; j < pmu_caps[i].nr_caps; j++) + free(pmu_caps[i].caps[j]); + free(pmu_caps[i].caps); + free(pmu_caps[i].pmu_name); } =20 - free(nodes); + free(pmu_caps); return ret; } =20 @@ -3387,7 +3405,7 @@ const struct perf_header_feature_ops feat_ops[HEADER_= LAST_FEATURE] =3D { FEAT_OPR(CPU_PMU_CAPS, cpu_pmu_caps, false), FEAT_OPR(CLOCK_DATA, clock_data, false), FEAT_OPN(HYBRID_TOPOLOGY, hybrid_topology, true), - FEAT_OPR(HYBRID_CPU_PMU_CAPS, hybrid_cpu_pmu_caps, false), + FEAT_OPR(PMU_CAPS, pmu_caps, false), }; =20 struct header_print_data { diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 08563c1f1bff..5790bf556b90 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -46,7 +46,7 @@ enum { HEADER_CPU_PMU_CAPS, HEADER_CLOCK_DATA, HEADER_HYBRID_TOPOLOGY, - HEADER_HYBRID_CPU_PMU_CAPS, + HEADER_PMU_CAPS, HEADER_LAST_FEATURE, HEADER_FEAT_BITS =3D 256, }; --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6890C433F5 for ; Wed, 1 Jun 2022 03:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349427AbiFADae (ORCPT ); Tue, 31 May 2022 23:30:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349465AbiFADaX (ORCPT ); Tue, 31 May 2022 23:30:23 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2085.outbound.protection.outlook.com [40.107.220.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCEC772E3A; Tue, 31 May 2022 20:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LhwkVgOlhrGFPh4jycXofzMQSsSIKjUGEIF/Spocbc3XZJx/JJL2AihrOurpKAY4bHUAp6NYC9+NZGR8ig5S3HHyL4oeH9caela108MsPqYglytIpWr12QrtGiaqpyzD9IIus8Mqqt+j0h31tY7ZuIgcGVd4Q2MGJvI6sYkStuq9IbgMgm0XuzvTea1wgthGl0vUXNJfnfIPUPF9lOJtVeAaMzfX5eyqTj7XTMBIF+QAfI36BI0v6Fkl6zdClOCNt1FPzaFOv2FNF+JS+TIYJBfkrtcKS8zTWVillbcm5XZa2Sx0IFQ1/m5y9KMFYLEPCXE7p0p5nJcik9r/NQehrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=58OUnmftGccIflpVRC3kry/dTTF/1fMLkNTsUzjZkiY=; b=I0cg9U/Tyj6myHuvSJtKWgrvQXR9eKk/W6tqDpuOAgzOeJCFdXi1XYeewohXZecihTkt+1yCUafYKBSL1Uq3PEj/1mSiy1t3FOmwFQ7gvheP6DDs0sB9JulZodMSFQ8EmBdOzoAUUaw9saV32DcSGC7fzzkuitnWqpqEjfgO7OExwRdsd1XkB2z2vnLhM/wSZZNuupYlr90Gl9bq+KFUwkrUjNtGZ5R/+RofFoYS1ZA0OY4hBoG1O6SSLRpkxCjPhFi3I1Rrw3n2HP6a3Kq2mpjsqe0uamx8KsRp+Bk135S+nhHwRrX3QBvUTY5EVcd1hGkviPACswRbESEVjZdw6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=58OUnmftGccIflpVRC3kry/dTTF/1fMLkNTsUzjZkiY=; b=sPcdTg9885QkGpvLuf12NOiTPwjUdLh5vzYLNwjlLVa1OqoNYnzNFq44dIhVbcxChHE8G9hX4y24IZgoDWAYDvAShDhNXwmNdZLM38Vf+b91ioQcflII/unNeRrMcQBkSuJfDBsd6gJTdr+aldRDrvNV50fqz+olin0ClchDFDY= Received: from BN6PR11CA0067.namprd11.prod.outlook.com (2603:10b6:404:f7::29) by DM6PR12MB4121.namprd12.prod.outlook.com (2603:10b6:5:220::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Wed, 1 Jun 2022 03:30:20 +0000 Received: from BN8NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:404:f7:cafe::89) by BN6PR11CA0067.outlook.office365.com (2603:10b6:404:f7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Wed, 1 Jun 2022 03:30:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT054.mail.protection.outlook.com (10.13.177.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:30:20 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:29:32 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 6/8] perf/x86/ibs: Add new IBS register bits into header Date: Wed, 1 Jun 2022 08:56:06 +0530 Message-ID: <20220601032608.1034-7-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6bfb2dd0-2baf-47d6-7242-08da437f0e63 X-MS-TrafficTypeDiagnostic: DM6PR12MB4121:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZZY5w1KQBH0wnLxDyDkjCMTCe9skLl4O0qAF3zgxRwDzJ68uMcjyoT3Boit3X5to7+9RbXfed7fjWPp7TivMpiPuItY+yCka84hRSl8x9Zs8z+fq0gmDsnL8XSeCR0ZJ96jWks4JmpfOobmn27qe+/rDE8N/8CyLKWSKkh8Q4u3QSkkPos7zbm3RJ9HRbNWv5WgTW3ihVI38us+M5+fXT3PIBfCNnj7IxNC2PLK7Lk9rNq3TVOU7gUL1BsG1GOycfbbihxFvhfNA4J3wThS4ajfIqnQz2UHIRd4eZslOSwYB1DH65O3iTuzQx8aYhTcsXfQO0K3C25sYN5gTbdyYyS4aY51JK9nxR/Fe8FobZ/+G97i9aePa90zw6Cl+yOL4WDisBbARo8tl4wmM31NfCmzqmBibv5/lnSrlDEePBl3TIIxnR8QSMGTZlh/j1WOmoZBijnAMLHwtf5NcxVfHNqaH2uLKBnlH7VaDRrTGxXE/fvALHStpepSiQfFlpQwA1CJH88uVbiEVID3Oj51I8STyaQFD1dgn71Zpy8nKS5/q24/Jo8OaTQRYP8qRQj+OU0BPVStpjpfRWFu9TW/BxLb2TpENXU4ee+Xr/qdjYIDb4FocSBOxxw7+6fOx8UkMtdxTv1jJaPeRK/dD1b4q/StgPHZjNpXXEU8TZWNOlfyObXFgm97AxqaVPXWGCPxcv3DvPTZ7xf0GUTbyf28O/Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(186003)(6666004)(86362001)(16526019)(40460700003)(336012)(81166007)(70206006)(7416002)(7696005)(5660300002)(1076003)(70586007)(4326008)(8936002)(36756003)(426003)(83380400001)(316002)(44832011)(2616005)(54906003)(8676002)(2906002)(110136005)(26005)(82310400005)(508600001)(47076005)(36860700001)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:30:20.7027 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6bfb2dd0-2baf-47d6-7242-08da437f0e63 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4121 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" IBS support has been enhanced with two new features in upcoming uarch: 1. DataSrc extension and 2. L3 miss filtering. Additional set of bits has been introduced in IBS registers to exploit these features. Define these new bits into arch/x86/ header. Signed-off-by: Ravi Bangoria Acked-by: Ian Rogers --- arch/x86/include/asm/amd-ibs.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/amd-ibs.h b/arch/x86/include/asm/amd-ibs.h index aabdbb5ab920..f3eb098d63d4 100644 --- a/arch/x86/include/asm/amd-ibs.h +++ b/arch/x86/include/asm/amd-ibs.h @@ -29,7 +29,10 @@ union ibs_fetch_ctl { rand_en:1, /* 57: random tagging enable */ fetch_l2_miss:1,/* 58: L2 miss for sampled fetch * (needs IbsFetchComp) */ - reserved:5; /* 59-63: reserved */ + l3_miss_only:1, /* 59: Collect L3 miss samples only */ + fetch_oc_miss:1,/* 60: Op cache miss for the sampled fetch */ + fetch_l3_miss:1,/* 61: L3 cache miss for the sampled fetch */ + reserved:2; /* 62-63: reserved */ }; }; =20 @@ -38,14 +41,14 @@ union ibs_op_ctl { __u64 val; struct { __u64 opmaxcnt:16, /* 0-15: periodic op max. count */ - reserved0:1, /* 16: reserved */ + l3_miss_only:1, /* 16: Collect L3 miss samples only */ op_en:1, /* 17: op sampling enable */ op_val:1, /* 18: op sample valid */ cnt_ctl:1, /* 19: periodic op counter control */ opmaxcnt_ext:7, /* 20-26: upper 7 bits of periodic op maximum count */ - reserved1:5, /* 27-31: reserved */ + reserved0:5, /* 27-31: reserved */ opcurcnt:27, /* 32-58: periodic op counter current count */ - reserved2:5; /* 59-63: reserved */ + reserved1:5; /* 59-63: reserved */ }; }; =20 @@ -71,11 +74,12 @@ union ibs_op_data { union ibs_op_data2 { __u64 val; struct { - __u64 data_src:3, /* 0-2: data source */ + __u64 data_src_lo:3, /* 0-2: data source low */ reserved0:1, /* 3: reserved */ rmt_node:1, /* 4: destination node */ cache_hit_st:1, /* 5: cache hit state */ - reserved1:57; /* 5-63: reserved */ + data_src_hi:2, /* 6-7: data source high */ + reserved1:56; /* 8-63: reserved */ }; }; =20 --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76CDEC433F5 for ; Wed, 1 Jun 2022 03:31:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349426AbiFADbP (ORCPT ); Tue, 31 May 2022 23:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349448AbiFADbM (ORCPT ); Tue, 31 May 2022 23:31:12 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2042.outbound.protection.outlook.com [40.107.237.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A57639CF62; Tue, 31 May 2022 20:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jhcm/nHNE6pyyOKCkGXYGplDxVafDixSPWGd9sKm348IWxL7FO2vnU0UUxS1YBLpXNYeWapP/2CDseQa7jrExvGPwxi0bNZUBEZmAheyAtKlHgpomng8H+ftjnsJA0cZlpdHBONDmBGPMU7NxQAL+y3r/ykyBQA696mXrOVbmdp0QD33WsHmFH9HTFbeuzdgUtFSTuFYKJWnxYjVbGoWNmRcy4tig8oHenyJudOUCVB55emVJT/FhhzC48viYqquDaVBX3f3bhKsO7H6Ag28WEVxro2rXmd14uVgmXtopVvovAfgGjyV1hQnTGMBlNh2VENZliTgzWQtZY0rW0uHdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ENgn8+omoEhMK3iILyBQxGAX+iDfdi2Upi/IMDFWqgw=; b=m+uO9INE5Xlsh0M2sl9a8jRGRFBqKGCGgJma0yim9lXN+M3oqt9EifVa0pYVRGv/YA9S3JmtGErqpw6nKZsDn2B5wIC9CbSOYCcQp7+KMn5Z5F0+vCOL1M3faAspuIZ94zXF0Z6UKqOS84JZjYgfTXvH9H5QAQXqlBZwHjFesAz5mtnWOqj7qR2aMZSN21ce6QM+o8TjnObr+rpijOC9ryD7loalH4TpPXyfnBkVDbWA0+uUMWorW5NXVALvveY8nFMAgn9UMmGZ4TrO03ttbwvZUt9s80bkLMS4h1XCqGJgau+24tO5d6XfLvAiNsHOb7MUaqC8r5+Ynf8+8L4vnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ENgn8+omoEhMK3iILyBQxGAX+iDfdi2Upi/IMDFWqgw=; b=uhw/RHmltdQH84jKBw55jVdKfvtZGg0A8dl9/PQKtJTuMGIhXUBL2OQDhDD2wk05wdhk7mLnxF9UIJH8r3aSXiiVikBDtkaKx9cE/t5Fn0C1Bw1oNTwqHs/q8Ko9q2LGiM+Q+dZC1oIwzrVODHwTlaxuTEsHSOUnqhW/WehCSJs= Received: from MW4PR03CA0360.namprd03.prod.outlook.com (2603:10b6:303:dc::35) by DM6PR12MB4548.namprd12.prod.outlook.com (2603:10b6:5:2a1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:31:06 +0000 Received: from CO1NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dc:cafe::9e) by MW4PR03CA0360.outlook.office365.com (2603:10b6:303:dc::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:31:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT046.mail.protection.outlook.com (10.13.174.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:31:06 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:30:20 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 7/8] perf tool ibs: Sync amd ibs header file Date: Wed, 1 Jun 2022 08:56:07 +0530 Message-ID: <20220601032608.1034-8-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b0194db5-179d-4666-8a4e-08da437f297f X-MS-TrafficTypeDiagnostic: DM6PR12MB4548:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IgifHaTsyrVitUoVRcwAeH3rNm+IrHg0PjuMLMsaqi7giHWnWwaFWPE3OgG2hgpKKEChwDX06LkVDR4/fmCYzdyodbpuwbLLcF7gGKG8jdWK7MzqV89IBFcWLYxXjDnDu+1zgVQm5FiMpPibETlvu7T7vE+oa8fDlMq0tEzLkO+qcnT17ZwiVkc/5t6OEj/EzTkBAda/kclCdg3zIfXAmVLKVxv5GQhPN6ryRk4Xq4vCc96JmKPnzyiHini2Ph4XKq5auRQnqjebMaWiGJctuGFuTk6r7yA5PZbgbBwbhGIUdYKYQJEeSHbYk6KifgUkyx0BAbHVe8vDhX9vO6YrvqoFrL9dIYROKbSysSHqoBvBTnkNAw70q4i6IGcsChXoJ/AmdBA3ocYaT+a3FmFIn/xYmJwaTVMM5adDUVyFU3+H5V/wBLKN1W4pLDviHuwHBL+mIecuMo0Q+SSJR5OVvNhpvfTsWEvttaCY9NZvbOwQQT80bC+VxkC02I0wZSMk2DlhSGvegsBKhVZ5di5S4dSoI8AQrdEQPdh5XQdYOkq5b3M/TlZDphmm1oBQk8ViQtyoMwMBIi/RbAZBMViIHrIMeOqLgcQKIRYib0dPT6g8th8yESnPMSfsgPP1ZOWwYIvdn5UxD5rPHlSFhmsKj/ilhgCjc8/tflJnVc/6Mo9PwHLZgoFn57snVRHozqooG1YpnFaRYn94vneJj13afA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2906002)(54906003)(82310400005)(6666004)(5660300002)(7416002)(508600001)(44832011)(47076005)(8936002)(1076003)(2616005)(86362001)(83380400001)(336012)(40460700003)(426003)(36860700001)(7696005)(26005)(16526019)(186003)(356005)(36756003)(316002)(70586007)(81166007)(4326008)(70206006)(8676002)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:31:06.0759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0194db5-179d-4666-8a4e-08da437f297f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4548 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" IBS support has been enhanced with two new features in upcoming uarch: 1. DataSrc extension and 2. L3 miss filtering. Additional set of bits has been introduced in IBS registers to exploit these features. New bits are already defining in arch/x86/ header. Sync it with tools header file. Also rename existing ibs_op_data field 'data_src' to 'data_src_lo'. Signed-off-by: Ravi Bangoria --- tools/arch/x86/include/asm/amd-ibs.h | 16 ++++++++++------ tools/perf/util/amd-sample-raw.c | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/arch/x86/include/asm/amd-ibs.h b/tools/arch/x86/include/= asm/amd-ibs.h index 765e9e752d03..9a3312e12e2e 100644 --- a/tools/arch/x86/include/asm/amd-ibs.h +++ b/tools/arch/x86/include/asm/amd-ibs.h @@ -29,7 +29,10 @@ union ibs_fetch_ctl { rand_en:1, /* 57: random tagging enable */ fetch_l2_miss:1,/* 58: L2 miss for sampled fetch * (needs IbsFetchComp) */ - reserved:5; /* 59-63: reserved */ + l3_miss_only:1, /* 59: Collect L3 miss samples only */ + fetch_oc_miss:1,/* 60: Op cache miss for the sampled fetch */ + fetch_l3_miss:1,/* 61: L3 cache miss for the sampled fetch */ + reserved:2; /* 62-63: reserved */ }; }; =20 @@ -38,14 +41,14 @@ union ibs_op_ctl { __u64 val; struct { __u64 opmaxcnt:16, /* 0-15: periodic op max. count */ - reserved0:1, /* 16: reserved */ + l3_miss_only:1, /* 16: Collect L3 miss samples only */ op_en:1, /* 17: op sampling enable */ op_val:1, /* 18: op sample valid */ cnt_ctl:1, /* 19: periodic op counter control */ opmaxcnt_ext:7, /* 20-26: upper 7 bits of periodic op maximum count */ - reserved1:5, /* 27-31: reserved */ + reserved0:5, /* 27-31: reserved */ opcurcnt:27, /* 32-58: periodic op counter current count */ - reserved2:5; /* 59-63: reserved */ + reserved1:5; /* 59-63: reserved */ }; }; =20 @@ -71,11 +74,12 @@ union ibs_op_data { union ibs_op_data2 { __u64 val; struct { - __u64 data_src:3, /* 0-2: data source */ + __u64 data_src_lo:3, /* 0-2: data source low */ reserved0:1, /* 3: reserved */ rmt_node:1, /* 4: destination node */ cache_hit_st:1, /* 5: cache hit state */ - reserved1:57; /* 5-63: reserved */ + data_src_hi:2, /* 6-7: data source high */ + reserved1:56; /* 8-63: reserved */ }; }; =20 diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-= raw.c index d19d765195c5..3b623ea6ee7e 100644 --- a/tools/perf/util/amd-sample-raw.c +++ b/tools/perf/util/amd-sample-raw.c @@ -98,9 +98,9 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg) }; =20 printf("ibs_op_data2:\t%016llx %sRmtNode %d%s\n", reg.val, - reg.data_src =3D=3D 2 ? (reg.cache_hit_st ? "CacheHitSt 1=3DO-Stat= e " + reg.data_src_lo =3D=3D 2 ? (reg.cache_hit_st ? "CacheHitSt 1=3DO-S= tate " : "CacheHitSt 0=3DM-state ") : "", - reg.rmt_node, data_src_str[reg.data_src]); + reg.rmt_node, data_src_str[reg.data_src_lo]); } =20 static void pr_ibs_op_data3(union ibs_op_data3 reg) --=20 2.31.1 From nobody Thu Apr 30 09:50:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62E9AC433EF for ; Wed, 1 Jun 2022 03:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349458AbiFADc1 (ORCPT ); Tue, 31 May 2022 23:32:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349457AbiFADcY (ORCPT ); Tue, 31 May 2022 23:32:24 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2049.outbound.protection.outlook.com [40.107.236.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09B3F255BD; Tue, 31 May 2022 20:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nFJUUKoWEdMz7Owy1rp7rKoJBnpw4usAS0T8273cV5qaU7uPDLzhpaFJXMvBYUf1brWpwQRo20l/9yBCZiLt0rkOxgdszczVYpwpmnoe9t3nkhk2YzWF3l08ygNs5S5c7K+1i2nMpFakvVydUMcdgYZSVzOtWeqcsbGFnzmdOlC+7Dnjl7YSgaBrJDKORQkJflyT/Owde/pPREh/3prpGHS49fnSA1ulr/3a0mkpHCUqGBYAHRCQzAX1Op8DwO5dYvB4CPY51tuxchuE+R1ISDW2QPGkCy06qnqD7ixiJdXM16B9doTC+znpBtecxLRDhBdYiJVHnLylv6+jWd9Zgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rDr3Aud2f3bEWRA5lYEAheLaXurwbvIRmVzaryhpqQQ=; b=Ik4f+c8lPCa32HkLttmlbbZsEs5ERYmqZXhMkdf3TGcMKZHoR+8Go4mkbgT1omzmCq1y/WfkENIvNaToRo9ifzrB6fJZPzF1DfcRZgCs5FVFZq/k/x4KM02a+IUU00bdjZ5swJHvFUgg/sypjrxLQRm8HEZ0HTT9T8CGAAeCiYRmdJEMbTzIlbR0eq1YWXm3aYAceDmtAKzIZeVgy3UIlGCkrW81Nczadv0uTxkDq1uhNuqe4iHXLqonmyMQ7rdj3TPqnZYqxVPyFT+Rjyp8l/N6Lqps7zd/IpQjRiVue4sV8Rsae+Pkbi0+5aF5c7Q0HyUxZ4eG6m7zulhJ/uokZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rDr3Aud2f3bEWRA5lYEAheLaXurwbvIRmVzaryhpqQQ=; b=Mg1iva7gy/Ib6rj49SYnTs+vVheX7Kuyx2LPpmFvo8gblRtRcn00k8r57Ujjo3u/hqThMBijMp9p3dzNaAJNgd1k4n9dK51bsTFtNyA0+7KSZuZtMiw/FCS2CGrhy3XH6hx04jlCBaTtTsSce1rcG5FR7sJ71SgVrt33schw0ZY= Received: from CO2PR05CA0054.namprd05.prod.outlook.com (2603:10b6:102:2::22) by BN8PR12MB3570.namprd12.prod.outlook.com (2603:10b6:408:4a::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Wed, 1 Jun 2022 03:32:17 +0000 Received: from CO1NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:102:2:cafe::8d) by CO2PR05CA0054.outlook.office365.com (2603:10b6:102:2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:32:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT068.mail.protection.outlook.com (10.13.175.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5314.12 via Frontend Transport; Wed, 1 Jun 2022 03:32:16 +0000 Received: from BLR-5CG113396H.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 31 May 2022 22:31:05 -0500 From: Ravi Bangoria To: , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 8/8] perf script ibs: Support new IBS bits in raw trace dump Date: Wed, 1 Jun 2022 08:56:08 +0530 Message-ID: <20220601032608.1034-9-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601032608.1034-1-ravi.bangoria@amd.com> References: <20220601032608.1034-1-ravi.bangoria@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb70098c-44d9-4f10-7da0-08da437f53c4 X-MS-TrafficTypeDiagnostic: BN8PR12MB3570:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4D8kvjawopgIu3E+9XJ/zSXe/fLyVyBwDTp4cG3hR5LOC/0hOt7zD+c7laXzXcP5YsK4cAGqwQRg9dIioGRAUp9tYbKphLZu8pl5jEplvWwrzuhUonLgAq5hyh4FHwde/slXMqbfGY3kcysjqtqePnJDwNS2mSgyt6a33ECyovBOeDDeCkyIDAnyJsxKPQAa4jUTKX5p3hdmHEiP7A9OPBIMoqAbgXB+AJanwOnVK+t9FDNz17/wHA8a6Kh941QK7ZrAFDu3U1lnwV0Ix4Eqt4aV4H1Qd0B3eh+yYkezf/AYAjOEfjy3opYSMBqes+6TYjhC1dZd9wYer1hiTBFvA2m1LQjcKclEiVII2OOFm7nf59R2TqPnAH50x9Vj8Il7yJ32ghrEyAGm/MxMcFj1EGGyPx6oQANVpPRFdBuNcj7hla6ym4IN3fnAzXkl7PVcVIgaq7gdl/4r8JGaLnLwIzhYL0Rj+UmStzXKAO8mDO98D7y9lLXr8ovn4fWgJ2ZwXQan7vDCQzBFWLpJ3vhiO8LAS2FP3LZ0iaD21ThNpLwML+TWyf10S8Z/xtFwv7HPSWX51szpVv5xK0/CtM3S8Jq3aqYuHrBGaTB/nYEaeqOrBabfNn6Vx6jrmwYQnU4TYz38dBUJzL9FdMFAQuOaHLV1c0FrSj0P6ZJGfRzjQttO6WIwCIhXnTV+1RA3VNFCrNBt7RIiKZRHGoVi5tbdRg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(44832011)(36860700001)(7416002)(47076005)(82310400005)(81166007)(356005)(5660300002)(508600001)(8936002)(40460700003)(186003)(83380400001)(1076003)(16526019)(2906002)(26005)(426003)(336012)(86362001)(7696005)(2616005)(4326008)(8676002)(316002)(70206006)(70586007)(54906003)(110136005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2022 03:32:16.9765 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb70098c-44d9-4f10-7da0-08da437f53c4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3570 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Interpret Additional set of IBS register bits while doing perf report/script raw dump. IBS op pmu ex: $ sudo ./perf record -c 130 -a -e ibs_op/l3missonly=3D1/ --raw-samples $ sudo ./perf report -D ... ibs_op_ctl: 0000004500070008 MaxCnt 128 L3MissOnly 1 En 1 Val 1 CntCtl 0=3Dcycles CurCnt 69 ibs_op_data: 0000000000710002 CompToRetCtr 2 TagToRetCtr 113 BrnRet 0 RipInvalid 0 BrnFuse 0 Microcode 0 ibs_op_data2: 0000000000000002 CacheHitSt 0=3DM-state RmtNode 0 DataSrc 2=3DA peer cache in a near CCX ibs_op_data3: 000000681d1700a1 LdOp 1 StOp 0 DcL1TlbMiss 0 DcL2TlbMiss 0 DcL1TlbHit2M 0 DcL1TlbHit1G 1 DcL2TlbHit2M 0 DcMiss 1 DcMisAcc 0 DcWcMemAcc 0 DcUcMemAcc 0 DcLockedOp 0 DcMissNoMabAlloc 1 DcLinAddrValid 1 DcPhyAddrValid 1 DcL2TlbHit1G 0 L2Miss 1 SwPf 0 OpMemWidth 8 bytes OpDcMissOpenMemReqs 7 DcMissLat 104 TlbRefillLat 0 IBS Fetch pmu ex: $ sudo ./perf record -c 130 -a -e ibs_fetch/l3missonly=3D1/ --raw-samples $ sudo ./perf report -D ... ibs_fetch_ctl: 3c1f00c700080008 MaxCnt 128 Cnt 128 Lat 199 En 1 Val 1 Comp 1 IcMiss 1 PhyAddrValid 1 L1TlbPgSz 4KB L1TlbMiss 0 L2TlbMiss 0 RandEn 0 L2Miss 1 L3MissOnly 1 FetchOcMiss 1 FetchL3Miss 1 With the DataSrc extensions, the source of data can be decoded among: - Local L3 or other L1/L2 in CCX. - A peer cache in a near CCX. - Data returned from DRAM. - A peer cache in a far CCX. - DRAM address map with "long latency" bit set. - Data returned from MMIO/Config/PCI/APIC. - Extension Memory (S-Link, GenZ, etc - identified by the CS target and/or address map at DF's choice). - Peer Agent Memory. Signed-off-by: Ravi Bangoria --- tools/perf/util/amd-sample-raw.c | 64 +++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-= raw.c index 3b623ea6ee7e..238305868644 100644 --- a/tools/perf/util/amd-sample-raw.c +++ b/tools/perf/util/amd-sample-raw.c @@ -18,6 +18,7 @@ #include "pmu-events/pmu-events.h" =20 static u32 cpu_family, cpu_model, ibs_fetch_type, ibs_op_type; +static bool zen4_ibs_extensions; =20 static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) { @@ -39,6 +40,7 @@ static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) }; const char *ic_miss_str =3D NULL; const char *l1tlb_pgsz_str =3D NULL; + char l3_miss_str[sizeof(" L3MissOnly _ FetchOcMiss _ FetchL3Miss _")] =3D= ""; =20 if (cpu_family =3D=3D 0x19 && cpu_model < 0x10) { /* @@ -53,12 +55,19 @@ static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) ic_miss_str =3D ic_miss_strs[reg.ic_miss]; } =20 + if (zen4_ibs_extensions) { + snprintf(l3_miss_str, sizeof(l3_miss_str), + " L3MissOnly %d FetchOcMiss %d FetchL3Miss %d", + reg.l3_miss_only, reg.fetch_oc_miss, reg.fetch_l3_miss); + } + printf("ibs_fetch_ctl:\t%016llx MaxCnt %7d Cnt %7d Lat %5d En %d Val %d C= omp %d%s " - "PhyAddrValid %d%s L1TlbMiss %d L2TlbMiss %d RandEn %d%s\n", + "PhyAddrValid %d%s L1TlbMiss %d L2TlbMiss %d RandEn %d%s%s\n", reg.val, reg.fetch_maxcnt << 4, reg.fetch_cnt << 4, reg.fetch_lat, reg.fetch_en, reg.fetch_val, reg.fetch_comp, ic_miss_str ? : "", reg.phy_addr_valid, l1tlb_pgsz_str ? : "", reg.l1tlb_miss, reg.l2tlb_mis= s, - reg.rand_en, reg.fetch_comp ? (reg.fetch_l2_miss ? " L2Miss 1" : " L2Mis= s 0") : ""); + reg.rand_en, reg.fetch_comp ? (reg.fetch_l2_miss ? " L2Miss 1" : " L2Mis= s 0") : "", + l3_miss_str); } =20 static void pr_ic_ibs_extd_ctl(union ic_ibs_extd_ctl reg) @@ -68,9 +77,15 @@ static void pr_ic_ibs_extd_ctl(union ic_ibs_extd_ctl reg) =20 static void pr_ibs_op_ctl(union ibs_op_ctl reg) { - printf("ibs_op_ctl:\t%016llx MaxCnt %9d En %d Val %d CntCtl %d=3D%s CurCn= t %9d\n", - reg.val, ((reg.opmaxcnt_ext << 16) | reg.opmaxcnt) << 4, reg.op_en= , reg.op_val, - reg.cnt_ctl, reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt); + char l3_miss_only[sizeof(" L3MissOnly _")] =3D ""; + + if (zen4_ibs_extensions) + snprintf(l3_miss_only, sizeof(l3_miss_only), " L3MissOnly %d", reg.l3_mi= ss_only); + + printf("ibs_op_ctl:\t%016llx MaxCnt %9d%s En %d Val %d CntCtl %d=3D%s Cur= Cnt %9d\n", + reg.val, ((reg.opmaxcnt_ext << 16) | reg.opmaxcnt) << 4, l3_miss_only, + reg.op_en, reg.op_val, reg.cnt_ctl, + reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt); } =20 static void pr_ibs_op_data(union ibs_op_data reg) @@ -84,7 +99,34 @@ static void pr_ibs_op_data(union ibs_op_data reg) reg.op_brn_ret, reg.op_rip_invalid, reg.op_brn_fuse, reg.op_microcode); } =20 -static void pr_ibs_op_data2(union ibs_op_data2 reg) +static void pr_ibs_op_data2_extended(union ibs_op_data2 reg) +{ + static const char * const data_src_str[] =3D { + "", + " DataSrc 1=3DLocal L3 or other L1/L2 in CCX", + " DataSrc 2=3DA peer cache in a near CCX", + " DataSrc 3=3DData returned from DRAM", + " DataSrc 4=3D(reserved)", + " DataSrc 5=3DA peer cache in a far CCX", + " DataSrc 6=3DDRAM address map with \"long latency\" bit set", + " DataSrc 7=3DData returned from MMIO/Config/PCI/APIC", + " DataSrc 8=3DExtension Memory (S-Link, GenZ, etc)", + " DataSrc 9=3D(reserved)", + " DataSrc 10=3D(reserved)", + " DataSrc 11=3D(reserved)", + " DataSrc 12=3DPeer Agent Memory", + /* 13 to 31 are reserved. Avoid printing them. */ + }; + int data_src =3D (reg.data_src_hi << 3) | reg.data_src_lo; + + printf("ibs_op_data2:\t%016llx %sRmtNode %d%s\n", reg.val, + (data_src =3D=3D 1 || data_src =3D=3D 2 || data_src =3D=3D 5) ? + (reg.cache_hit_st ? "CacheHitSt 1=3DO-State " : "CacheHitSt 0=3DM-state= ") : "", + reg.rmt_node, + data_src < (int)ARRAY_SIZE(data_src_str) ? data_src_str[data_src] : ""); +} + +static void pr_ibs_op_data2_default(union ibs_op_data2 reg) { static const char * const data_src_str[] =3D { "", @@ -103,6 +145,13 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg) reg.rmt_node, data_src_str[reg.data_src_lo]); } =20 +static void pr_ibs_op_data2(union ibs_op_data2 reg) +{ + if (zen4_ibs_extensions) + return pr_ibs_op_data2_extended(reg); + pr_ibs_op_data2_default(reg); +} + static void pr_ibs_op_data3(union ibs_op_data3 reg) { char l2_miss_str[sizeof(" L2Miss _")] =3D ""; @@ -279,6 +328,9 @@ bool evlist__has_amd_ibs(struct evlist *evlist) pmu_mapping +=3D strlen(pmu_mapping) + 1 /* '\0' */; } =20 + if (perf_env__find_pmu_cap(env, "ibs_op", "zen4_ibs_extensions")) + zen4_ibs_extensions =3D 1; + if (ibs_fetch_type || ibs_op_type) { if (!cpu_family) parse_cpuid(env); --=20 2.31.1