From nobody Thu May 7 20:22:21 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 F02D1C433EF for ; Thu, 19 May 2022 10:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236446AbiESKEN (ORCPT ); Thu, 19 May 2022 06:04:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235895AbiESKEK (ORCPT ); Thu, 19 May 2022 06:04:10 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44A6B9C2C7; Thu, 19 May 2022 03:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FG8mdo8lBsTxJTsrO9vmUg/MCZHLPoZuJ4zSttd3GQ5IMs2uXSzoVp0hvaB0gNVJMVUAeMChQO/J0z4tLim5QrKjqFL3ULoCMw9wZy9QevzY7haQU1xExjqei94EbvwxY61yy1NGYJ9yFUUXmrT/j7iWMR1SyISJ3ldmS6Bcotnwmsk1s31TfdsSPIdP4ZDEwFJUy5SoSrydtXYE1DcFVH91i1nk3k7ExI8Y2wRDykiHG9fpB46qkJKik4Q7LIgojnt5m8QSJB7pom0X8liWJ0g2wPDyLb1qX+l0XUnUqvy+0SKESGrXCK2dAXIWR1/aLH/38aCmj5uxJOrsrCoyQg== 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=4+sNLBwxgzJbKyfEFGPAwlsHQ3w4xhNl4bUfSNwxI84=; b=V/fv5Mnew9BtxUkwOa1ybkFfbLwoQgSQYgsVdBVRV6tNEdJ5YpQerhv5cYf3OA7cXAucHO0Um4ZlO+Edge7uvYoyOcLYQrS66qsKiupJ5j+qjzl8TV6cDUcG/BZzVWa9gHyAKxGaDaAq9ld0+Yw2WuEXBFz8yHM1HTKgFgGnyqANXYbEtHgsKumTg+v//IgVkMQSW76wx+W0bO/aNr0JuzP466mmSGX8OSFOB+c+0+UfgZLKHc2ebUAbKQCFXnQYURVh8zHGdpjLr6axSKITAyFkoUbpNN6nQdVmIM4rLbFq7AqzZB1bx3HOFhi8EfYiLKjeO+5HaxCPcNIXg0UFtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=4+sNLBwxgzJbKyfEFGPAwlsHQ3w4xhNl4bUfSNwxI84=; b=fRYbLIO/Ud+wArzOArWASGcMu4+HiM5wtmu8/0R2RFi9jeazE4OYq5wsk3s6LcYNRerXVKuAN5V4KaD7cWqStnUWHyoahzUpw4wlB1cXQEBS1n1OwJjTJ7DsU8KQpNrcdkhznpv5SAX/wldtCAD81k4XyliVrbL3ktXhmpZsggo= Received: from DS7PR05CA0085.namprd05.prod.outlook.com (2603:10b6:8:56::15) by CH2PR12MB4199.namprd12.prod.outlook.com (2603:10b6:610:a7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.13; Thu, 19 May 2022 10:04:07 +0000 Received: from DM6NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:8:56:cafe::3) by DS7PR05CA0085.outlook.office365.com (2603:10b6:8:56::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.7 via Frontend Transport; Thu, 19 May 2022 10:04: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 DM6NAM11FT028.mail.protection.outlook.com (10.13.173.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:04:06 +0000 Received: from sindhu.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.24; Thu, 19 May 2022 05:04:01 -0500 From: Sandipan Das To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH 1/5] perf/x86/amd/uncore: Use dynamic events array Date: Thu, 19 May 2022 15:33:30 +0530 Message-ID: <21eea0cb6de9d14f78d52d1d62637ae02bc900f5.1652954372.git.sandipan.das@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 88390489-fc49-4a9d-088e-08da397ee963 X-MS-TrafficTypeDiagnostic: CH2PR12MB4199: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: M1gTD/JhA5IjM8JdkyjqF6dSdvnFwbiwAEcwQHltB5ng/2v+ZhFqAJyrbQDlNtVtGGAIvRE0w6FpDaCNxgdJmSZkr8ShZWp3mgjTjq6lMxio+CPFtib7avmNjSTZNbQ/Y0HL9F4O72gIu1fNLJnjpUdXOfTRjPKmXddogDF2fQdOFeiLtQsUDLHrqMhTeDpZq3iPwISSxgwHA4HXCiUQIb0YziINKdU56tChNtWdGx+MZg5L2gWwyRgh5eCvp526yjVXGWEZFVsV30+SWcvCiamLviDmpWZ95hQQut6BXc5LQyniqEZ0rqeRhacSCrVrd435uEnfWLNeCzO2Q/OHZpS6r+IqxhjEWfK+m1PnATRXMiY8yIhvzfYV2umatwOrdu9Z9iqpCZ9SvEL10UmRZXXuyrlm+9n/UglzgEEkO4UqH9keAsUNJpBE3v1bGrMW6KiB6RCHCD7gSQraWNDE4RXlREgdYv8NioYDAvPP3oUKgqCOTIfrlB34oRYhfRKucFwGh/MN9uKp1wWz1hSmdPQ3j/9J6Wg1aEi24Irgf/7P3edy4brdrv/YqAQ6L8rzPBOVQ5527V7J3m1USTqOqbsoVgF/x9gmZln8c2JjgDTZYqusIEP2hdBm0ZIm6WdM7N9qee1N9+Vdjo1jKNLueDd3/5bFFrDoXO/XN4nZwpa9BvPrxuXHhFp9DJI0Ds0LcRLVyeVjjxP/2ezjF/c5yA== 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)(46966006)(40470700004)(36840700001)(508600001)(426003)(83380400001)(6666004)(336012)(8936002)(36860700001)(7416002)(2616005)(5660300002)(44832011)(86362001)(82310400005)(110136005)(40460700003)(70206006)(16526019)(81166007)(186003)(47076005)(36756003)(70586007)(54906003)(316002)(2906002)(4326008)(356005)(26005)(8676002)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 10:04:06.9496 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88390489-fc49-4a9d-088e-08da397ee963 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: DM6NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4199 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, the number of available counters for a given uncore PMU may not be fixed across families and models and has to be determined at runtime. The per-cpu uncore PMU data currently uses a fixed-sized array for event information. Make it dynamic based on the number of available counters. Signed-off-by: Sandipan Das --- arch/x86/events/amd/uncore.c | 38 +++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 0d04414b97d2..8dfcf93711ab 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -21,7 +21,6 @@ #define NUM_COUNTERS_NB 4 #define NUM_COUNTERS_L2 4 #define NUM_COUNTERS_L3 6 -#define MAX_COUNTERS 6 =20 #define RDPMC_BASE_NB 6 #define RDPMC_BASE_LLC 10 @@ -46,7 +45,7 @@ struct amd_uncore { u32 msr_base; cpumask_t *active_mask; struct pmu *pmu; - struct perf_event *events[MAX_COUNTERS]; + struct perf_event **events; struct hlist_node node; }; =20 @@ -370,11 +369,19 @@ static struct amd_uncore *amd_uncore_alloc(unsigned i= nt cpu) cpu_to_node(cpu)); } =20 +static inline struct perf_event ** +amd_uncore_events_alloc(unsigned int num, unsigned int cpu) +{ + return kzalloc_node(sizeof(struct perf_event *) * num, GFP_KERNEL, + cpu_to_node(cpu)); +} + static int amd_uncore_cpu_up_prepare(unsigned int cpu) { - struct amd_uncore *uncore_nb =3D NULL, *uncore_llc; + struct amd_uncore *uncore_nb =3D NULL, *uncore_llc =3D NULL; =20 if (amd_uncore_nb) { + *per_cpu_ptr(amd_uncore_nb, cpu) =3D NULL; uncore_nb =3D amd_uncore_alloc(cpu); if (!uncore_nb) goto fail; @@ -384,11 +391,15 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) uncore_nb->msr_base =3D MSR_F15H_NB_PERF_CTL; uncore_nb->active_mask =3D &amd_nb_active_mask; uncore_nb->pmu =3D &amd_nb_pmu; + uncore_nb->events =3D amd_uncore_events_alloc(num_counters_nb, cpu); + if (!uncore_nb->events) + goto fail; uncore_nb->id =3D -1; *per_cpu_ptr(amd_uncore_nb, cpu) =3D uncore_nb; } =20 if (amd_uncore_llc) { + *per_cpu_ptr(amd_uncore_llc, cpu) =3D NULL; uncore_llc =3D amd_uncore_alloc(cpu); if (!uncore_llc) goto fail; @@ -398,6 +409,9 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) uncore_llc->msr_base =3D MSR_F16H_L2I_PERF_CTL; uncore_llc->active_mask =3D &amd_llc_active_mask; uncore_llc->pmu =3D &amd_llc_pmu; + uncore_llc->events =3D amd_uncore_events_alloc(num_counters_llc, cpu); + if (!uncore_llc->events) + goto fail; uncore_llc->id =3D -1; *per_cpu_ptr(amd_uncore_llc, cpu) =3D uncore_llc; } @@ -405,9 +419,16 @@ static int amd_uncore_cpu_up_prepare(unsigned int cpu) return 0; =20 fail: - if (amd_uncore_nb) - *per_cpu_ptr(amd_uncore_nb, cpu) =3D NULL; - kfree(uncore_nb); + if (uncore_nb) { + kfree(uncore_nb->events); + kfree(uncore_nb); + } + + if (uncore_llc) { + kfree(uncore_llc->events); + kfree(uncore_llc); + } + return -ENOMEM; } =20 @@ -540,8 +561,11 @@ static void uncore_dead(unsigned int cpu, struct amd_u= ncore * __percpu *uncores) if (cpu =3D=3D uncore->cpu) cpumask_clear_cpu(cpu, uncore->active_mask); =20 - if (!--uncore->refcnt) + if (!--uncore->refcnt) { + kfree(uncore->events); kfree(uncore); + } + *per_cpu_ptr(uncores, cpu) =3D NULL; } =20 --=20 2.34.1 From nobody Thu May 7 20:22:21 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 3B18DC433F5 for ; Thu, 19 May 2022 10:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236462AbiESKEd (ORCPT ); Thu, 19 May 2022 06:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236439AbiESKE3 (ORCPT ); Thu, 19 May 2022 06:04:29 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2046.outbound.protection.outlook.com [40.107.94.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D261395DD9; Thu, 19 May 2022 03:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QKT0yDa3/3z71z6CHy8elNsHdPuxD8UGFDdhGMl/pdGXsU5/Ibku2kaq/sG8NaC6jo662a5WPvORCfUcQlBm305amvYQiNyanVU7axBRrSuWe58/cBbPulOxa5kxn5Hundm0Qko1KpXhge2tbh5PrM8EGVRp0iIfIasS/hepRREvEPV2jAmzvlth3V4fRxKelt2V/keNDMIPesxNlGf4d6Dtf9DDNHtqPTDUFRF9JbtjWBQzqew4ay+U7SlidAB7dJxHU1pa5Iy/wlu8OH15l/u7VaMC9wiG/rJ2zbUK0mY6vTDT1JfvbcipWAp7acJHcu6obIG/niLG27KOehSlHA== 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=WLbFxQDW36DZNUzI7RgBV10Zs9DfVPkAulLWWcmGO9g=; b=dMkuGRhkQEM/tFaA63nCU9YwuQukJhdmwdzyYaJbuDllrAlpfKOpGyLSMJcuRJ+Fg8wKUSgi939TMGQAHKcl/RJ4vSZbblAsolyzkW3YxBD9f356vQrSx+Zkrj/mfZ0xjL4TrqKFgN/tW8lLRJ/AerEx8YFIwtIaE3EextvPUgLkSFtcEs30qLdCQEWcIFB97FpkmuC4nj6tybvfWs4liuq4ZCBR4Sm6YtDASiNMLxO3apdR9vl7IzeOSDJPzmcfHwcRWlojgR7qMtISTQtK767jcSJf/Fb5noxCQnbduWTjJ0Er/6Yl1RvlF9yOeU/wmnrE9HR9wPzsTOiXqPIWqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=WLbFxQDW36DZNUzI7RgBV10Zs9DfVPkAulLWWcmGO9g=; b=kp4WN6nJy2Da0sZhbQmUy3X6IIY5IA3LgiEICX0Ry0TvUAxfq0/LvxFGptnWYISLZTqDh3k0/bSHci41Jlt9tM8BJdXiJZkK3KEtPRCOtBFHPP8V32UKC83GCJjptf4IOY3HC8VeZVQF+/YXRvBa/PUaaPQWAz/tyg3H13HaGEI= Received: from DS7PR03CA0281.namprd03.prod.outlook.com (2603:10b6:5:3ad::16) by DM4PR12MB5916.namprd12.prod.outlook.com (2603:10b6:8:69::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.16; Thu, 19 May 2022 10:04:25 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3ad:cafe::e) by DS7PR03CA0281.outlook.office365.com (2603:10b6:5:3ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:04:25 +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 DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:04:25 +0000 Received: from sindhu.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.24; Thu, 19 May 2022 05:04:19 -0500 From: Sandipan Das To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH 2/5] perf/x86/amd/uncore: Use attr_update for format attributes Date: Thu, 19 May 2022 15:33:31 +0530 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 5716fcc2-be81-48c7-c580-08da397ef434 X-MS-TrafficTypeDiagnostic: DM4PR12MB5916: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: LGIRdUU4ZI1jxblHbcztqW7M44WLCiaS2Ef+s2wcgHNszasTP2GjoN3bBdC3ky/cQM5HUPtDB7MCDA6kf7CapubSqFIbdNwfIHPtsyuUJRDY0OaxfFUfO4OQJY24S+ug+idT7XSOf2w7aCeLkgcY0OCpVMHk5qGx8W++wxWwyWh3xUaBisSQzNbbs3n8HRy4myy/jYAiY6TDtRlFIi9U3L8csSxI2//ttUrjkJlYB8+5My5q7k6M1e80BEMjSE7+c/sO0Z5i8Vtl+KBnzPyWs5LtpZdpZmemt3Pkst5GvIlNWl+srCnO4TXodkCh/D1C+YjBrftlB482HmEcWexeAS/4P7zfgVWL2gljKfCX3RcQYsl/DKpMJAsOTtUKP7hFHoIW/y3DoESUv2a/q7OahFeyfLztvgP+12lV/wAKYPr6qidW+RipOt46qAZbu2X6NsM5LOgfG5De0UKHcJf7+SKKqm2A6J6YwDi1Dfk+SKVec5p2KvLXiQERvKOoVF/j96+M8fG0rO+JfLCep/pVkj4ll/00W265o0fjHdjVyQTgk81dhImrYRpl+8HNQCokQ2ceqGY+CuDjH4AJfvx5XxvNC6FMgw0BgHO6gd4rvrN7M3+BRwT2i0hhZCU+V6bpIdez0z/ZkvuosHTMNHTC0Ar9myXAMSIjXBcej5aA0WDX+VT9OObE69pRR5aCHarGCtQT8AggWv7TQoGWuWI1Mw== 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)(40470700004)(46966006)(54906003)(7416002)(7696005)(5660300002)(8936002)(336012)(44832011)(110136005)(508600001)(2906002)(6666004)(186003)(16526019)(426003)(47076005)(83380400001)(4326008)(70206006)(70586007)(8676002)(81166007)(26005)(36756003)(86362001)(356005)(82310400005)(36860700001)(316002)(2616005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 10:04:25.1014 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5716fcc2-be81-48c7-c580-08da397ef434 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: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5916 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the update_attrs attribute group introduced by commit f3a3a8257e5a ("perf/core: Add attr_groups_update into struct pmu") and the is_visible() callback to populate the family specifc attributes for uncore events. The changes apply to attributes that are unique to families such as slicemask for Family 17h and coreid for Family 19h. The addition of common attributes such as event and umask, whose formats change across families, remain unchanged. Signed-off-by: Sandipan Das --- arch/x86/events/amd/uncore.c | 68 ++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 8dfcf93711ab..c3e218dccf6e 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -246,6 +246,19 @@ static int amd_uncore_event_init(struct perf_event *ev= ent) return 0; } =20 +static umode_t +amd_f17h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, i= nt i) +{ + return boot_cpu_data.x86 >=3D 0x17 && boot_cpu_data.x86 < 0x19 ? + attr->mode : 0; +} + +static umode_t +amd_f19h_uncore_is_visible(struct kobject *kobj, struct attribute *attr, i= nt i) +{ + return boot_cpu_data.x86 >=3D 0x19 ? attr->mode : 0; +} + static ssize_t amd_uncore_attr_show_cpumask(struct device *dev, struct device_attribute *attr, char *buf) @@ -296,20 +309,33 @@ DEFINE_UNCORE_FORMAT_ATTR(enallslices, enallslices, "= config:46"); /* F19h L3 DEFINE_UNCORE_FORMAT_ATTR(enallcores, enallcores, "config:47"); /* F19= h L3 */ DEFINE_UNCORE_FORMAT_ATTR(sliceid, sliceid, "config:48-50"); /* F19h L3= */ =20 +/* Common DF and NB attributes */ static struct attribute *amd_uncore_df_format_attr[] =3D { - &format_attr_event12.attr, /* event14 if F17h+ */ - &format_attr_umask.attr, + &format_attr_event12.attr, /* event */ + &format_attr_umask.attr, /* umask */ NULL, }; =20 +/* Common L2 and L3 attributes */ static struct attribute *amd_uncore_l3_format_attr[] =3D { - &format_attr_event12.attr, /* event8 if F17h+ */ - &format_attr_umask.attr, - NULL, /* slicemask if F17h, coreid if F19h */ - NULL, /* threadmask8 if F17h, enallslices if F19h */ - NULL, /* enallcores if F19h */ - NULL, /* sliceid if F19h */ - NULL, /* threadmask2 if F19h */ + &format_attr_event12.attr, /* event */ + &format_attr_umask.attr, /* umask */ + NULL, /* threadmask */ + NULL, +}; + +/* F17h unique L3 attributes */ +static struct attribute *amd_f17h_uncore_l3_format_attr[] =3D { + &format_attr_slicemask.attr, /* slicemask */ + NULL, +}; + +/* F19h unique L3 attributes */ +static struct attribute *amd_f19h_uncore_l3_format_attr[] =3D { + &format_attr_coreid.attr, /* coreid */ + &format_attr_enallslices.attr, /* enallslices */ + &format_attr_enallcores.attr, /* enallcores */ + &format_attr_sliceid.attr, /* sliceid */ NULL, }; =20 @@ -323,6 +349,18 @@ static struct attribute_group amd_uncore_l3_format_gro= up =3D { .attrs =3D amd_uncore_l3_format_attr, }; =20 +static struct attribute_group amd_f17h_uncore_l3_format_group =3D { + .name =3D "format", + .attrs =3D amd_f17h_uncore_l3_format_attr, + .is_visible =3D amd_f17h_uncore_is_visible, +}; + +static struct attribute_group amd_f19h_uncore_l3_format_group =3D { + .name =3D "format", + .attrs =3D amd_f19h_uncore_l3_format_attr, + .is_visible =3D amd_f19h_uncore_is_visible, +}; + static const struct attribute_group *amd_uncore_df_attr_groups[] =3D { &amd_uncore_attr_group, &amd_uncore_df_format_group, @@ -335,6 +373,12 @@ static const struct attribute_group *amd_uncore_l3_att= r_groups[] =3D { NULL, }; =20 +static const struct attribute_group *amd_uncore_l3_attr_update[] =3D { + &amd_f17h_uncore_l3_format_group, + &amd_f19h_uncore_l3_format_group, + NULL, +}; + static struct pmu amd_nb_pmu =3D { .task_ctx_nr =3D perf_invalid_context, .attr_groups =3D amd_uncore_df_attr_groups, @@ -352,6 +396,7 @@ static struct pmu amd_nb_pmu =3D { static struct pmu amd_llc_pmu =3D { .task_ctx_nr =3D perf_invalid_context, .attr_groups =3D amd_uncore_l3_attr_groups, + .attr_update =3D amd_uncore_l3_attr_update, .name =3D "amd_l2", .event_init =3D amd_uncore_event_init, .add =3D amd_uncore_add, @@ -632,15 +677,10 @@ static int __init amd_uncore_init(void) if (boot_cpu_data.x86 >=3D 0x19) { *l3_attr++ =3D &format_attr_event8.attr; *l3_attr++ =3D &format_attr_umask.attr; - *l3_attr++ =3D &format_attr_coreid.attr; - *l3_attr++ =3D &format_attr_enallslices.attr; - *l3_attr++ =3D &format_attr_enallcores.attr; - *l3_attr++ =3D &format_attr_sliceid.attr; *l3_attr++ =3D &format_attr_threadmask2.attr; } else if (boot_cpu_data.x86 >=3D 0x17) { *l3_attr++ =3D &format_attr_event8.attr; *l3_attr++ =3D &format_attr_umask.attr; - *l3_attr++ =3D &format_attr_slicemask.attr; *l3_attr++ =3D &format_attr_threadmask8.attr; } =20 --=20 2.34.1 From nobody Thu May 7 20:22:21 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 AFB4FC433FE for ; Thu, 19 May 2022 10:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236472AbiESKEw (ORCPT ); Thu, 19 May 2022 06:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236439AbiESKEs (ORCPT ); Thu, 19 May 2022 06:04:48 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2074.outbound.protection.outlook.com [40.107.101.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9019B994F8; Thu, 19 May 2022 03:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D7vUAi5MXHxXxdN6J2aBieuzq0I24VCNbRpIyap/zKpC+FTZw85G7NsMqgfY1nYZ4XdKpQ2nfK7BVuBfanFoRopFx6QwGPXfDhazM8ldT4fxg9i+VhmmPQLOwwD90UA+ptSBEagb/pVFigpQLKBlyWw4GSFvgfGylJpKmo9CV5OpQbfp0LlMIgMxnnkYDhda9wUsfzV2CZbQ+xq/E+ipmvfC2Rx4zIIknrJY3NCYTj8/tVKcRfaX561n6dPSCRCVsHhM0sELvzNHLeJ/7nU0g1ti4rUKBLUAyyGDvakdU7Jm9RFWU0cteNTF1bszOy/nVjaZKjymVSGUVkGbULCjJA== 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=+OVvWqCB30ygs1JPU3twVNjPAE6gC/B7+P7tcX0QU40=; b=jV+esA2VL3rvCNMV2+6FwXObQOJvaOtphyaKtZ4awq+7oNgPp0y3vn76uEUefuaxRPDvLLqwZtYx/cbUu4iThKmmd4VM1tVsAsSfYZWaiGBWFnKDo1kqSvc26e+ELfg4m5DJ+oo6OFAHpsd6TAFJqoHdr1YhBte0AqJd12sA/DZuAu4mwOfcPK4dnOkPMk/16aj3JtMPytPe41v2QSgaDU/ZTQz5wOtZaKZprKwCcyfCI04wY1p3b2mydWjf/cD4GwESdDaOYWlRDP3nmWYghEyxukN54qMGoP2fjuJI8HHAbxwQTbsH1dYucM682FfYz/rUpuvSe0o9Q/CXseEw5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=+OVvWqCB30ygs1JPU3twVNjPAE6gC/B7+P7tcX0QU40=; b=b7/xJnlHcfIz8nc0nSU3GInnX9R20Z/8pM9mQiWmeVEUoFNe2PCu5LgYJoHMuOLgvWAddr2f5b915FduiP0BvcZ/fzsmvSChBqRe43xAk0je65ISGeHkKCND/evzioPA7Omx9zL8eDbTtX7YD/ui3foR+cznkIRftuiRY5JN5RI= Received: from DM5PR18CA0068.namprd18.prod.outlook.com (2603:10b6:3:22::30) by MWHPR12MB1934.namprd12.prod.outlook.com (2603:10b6:300:109::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.15; Thu, 19 May 2022 10:04:43 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:3:22:cafe::a) by DM5PR18CA0068.outlook.office365.com (2603:10b6:3:22::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.26 via Frontend Transport; Thu, 19 May 2022 10:04: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 DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:04:43 +0000 Received: from sindhu.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.24; Thu, 19 May 2022 05:04:37 -0500 From: Sandipan Das To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH 3/5] perf/x86/amd/uncore: Detect available DF counters Date: Thu, 19 May 2022 15:33:32 +0530 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 5bb69846-bfc7-49e4-db80-08da397eff18 X-MS-TrafficTypeDiagnostic: MWHPR12MB1934: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: mkkwGfUuBJcUKAcPe2W6OgNtnQszm58dRvrO7767qicCOy64T4weaWXddEVGHk9NILTtGD21NsOEm5BcbpdcdHG5e3/xcD+rZqZDBhOwhGWMEoLB/rzH/scTLas4Ta+RfNpXbGathxnhKYlqk+WjDEo+04G4h0IJFvIL6jB+vEuhhlTwQGntxH/zL1glVY2hShOV7cgOpUfjgok0BBo9k3ssPrW5ddw2iI0IX+OCoa7KzLP62jpgGmhdx94EUh4f36mTM4DAeu0d7qF1HdgnLEycJpclWrVuKFfCnxuIESK//Lqldh9VBA768+niYVzv6ThquiX3iI7qzDvayt+VO9PHZ+psvnwtN8wJbUoJAAt6i3vPiVjn9twW+Q/kT45gI+j4eeaMRHYdXy0lHq83ARnHBOZkZVTwGEdqH3rkW/LzJYqEN39Z/LnZgkn/GvJvZIToTyt+PM+By0RwhhHdWeKCJlPKToRH2i8cqbYYpOACTVEFph4/oMSB24YEz4bPccbVxlWHZwAb+ySgXiS0ZGbhu/1em6fX1A2ik2xDKcSTtg3/RbCdlhPRZTKyGBggXwPAzJ63Zv0RBBzP77+LBRxZMgshYEOccVt9pRiy39P/TaDBeXU7RqBGSIyARkuvbYBk21Ocuy+ID0MXs/+ZsaEBRUhF3wUe+Yiqh72LyYkCd0v/aqiUc5RqgIrPiGzymM3rXlBJHwJ74whF3qh8cw== 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)(2906002)(508600001)(86362001)(54906003)(110136005)(44832011)(316002)(7416002)(81166007)(356005)(8936002)(5660300002)(26005)(70206006)(8676002)(82310400005)(83380400001)(36756003)(2616005)(40460700003)(47076005)(426003)(7696005)(336012)(186003)(16526019)(4326008)(70586007)(6666004)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 10:04:43.3734 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5bb69846-bfc7-49e4-db80-08da397eff18 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: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1934 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, use CPUID leaf 0x80000022 EBX to detect the number of Data Fabric (DF) PMCs. This offers more flexibility if the counts change in later processor families. Signed-off-by: Sandipan Das --- arch/x86/events/amd/uncore.c | 10 ++++++++++ arch/x86/include/asm/perf_event.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index c3e218dccf6e..233dd405dd06 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -30,6 +30,7 @@ #undef pr_fmt #define pr_fmt(fmt) "amd_uncore: " fmt =20 +static int pmu_version; static int num_counters_llc; static int num_counters_nb; static bool l3_mask; @@ -629,6 +630,7 @@ static int __init amd_uncore_init(void) { struct attribute **df_attr =3D amd_uncore_df_format_attr; struct attribute **l3_attr =3D amd_uncore_l3_format_attr; + union cpuid_0x80000022_ebx ebx; int ret =3D -ENODEV; =20 if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && @@ -638,6 +640,9 @@ static int __init amd_uncore_init(void) if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) return -ENODEV; =20 + if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) + pmu_version =3D 2; + num_counters_nb =3D NUM_COUNTERS_NB; num_counters_llc =3D NUM_COUNTERS_L2; if (boot_cpu_data.x86 >=3D 0x17) { @@ -666,6 +671,11 @@ static int __init amd_uncore_init(void) if (ret) goto fail_nb; =20 + if (pmu_version >=3D 2) { + ebx.full =3D cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); + num_counters_nb =3D ebx.split.num_df_pmc; + } + pr_info("%d %s %s counters detected\n", num_counters_nb, boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON ? "HYGON" : "", amd_nb_pmu.name); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 409725e86f42..af157aa74f4e 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -194,6 +194,9 @@ union cpuid_0x80000022_ebx { struct { /* Number of Core Performance Counters */ unsigned int num_core_pmc:4; + unsigned int reserved:6; + /* Number of Data Fabric Counters */ + unsigned int num_df_pmc:6; } split; unsigned int full; }; --=20 2.34.1 From nobody Thu May 7 20:22:21 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 7D2B9C433F5 for ; Thu, 19 May 2022 10:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236476AbiESKFK (ORCPT ); Thu, 19 May 2022 06:05:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbiESKFI (ORCPT ); Thu, 19 May 2022 06:05:08 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2084.outbound.protection.outlook.com [40.107.92.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98CB9BAC6; Thu, 19 May 2022 03:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ikisLBrMlVo3Pf6wJeaj+j1RRie/Aba4RWCQUjcDxPXOogeWclN3Kqy0kfzgFOE3Vp/gXVMxAut0IYGOzfRvdrLb1KQo3LX1DHvV5+0J5ewNywOrcIAQBsn018toNDpm00mnTeSjcq6qCoM6Gj0fa64v7+t+6sq+msrzs2xjRTgdi8/cXqlAuQsWiLgC2oGAIRQ/8DAFGF3r5Q9lMzqX6H5C3+RmU/3PUZLgTK756P7t5BlOMtcRrTAiBFx55nbbmNJuuv0fieWYWc6AiyVwKOBMgeay6K0dSFNMT0qdRH39E9eu2i5K7zvOptjgfLMPLsPF4Bta+BtFQw+uxYr84g== 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=Qcam57OPjUwwohv50Om0NpMgDKA0h4Ajs7CIW9S1emM=; b=Mn2YULPz3AaTr3NyQ8JSFZrbn5xV1T4gd4decKRMeuCIpLyCYd+rcBfHcsuYe2+0vTRzPg3Z+m7a16nZJiD7/izJz42BnBOgG8YV/YHhfEhmihyCcyISx7Z25CQseizJ2Cq9YUftjUqFwFnIr1lmukXyEqyaIiqYRCC5sEZxOK9pY+vIhvgGBnLXs1/8V3u6JXv3p19oA/J187KbELJeInuxmFi4ihRi7dqWHsHygMxqP7IiLfyi6lm0l+PTZFwuN83XSalkPeLHfi6mliafh/iOcuc1bPAV+YNxeUKA903hbLbOp/RBR61U88+zAE0uPZ0YV+dSx2FmTOuAvhb5lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=Qcam57OPjUwwohv50Om0NpMgDKA0h4Ajs7CIW9S1emM=; b=zg/affJ6N2SRf3a8pKpYmKXRFSfuD5Fykr5oQA8Sxpx0BIiB3kp/mn3wTW1ZBoh8uQK/8yQ2Dc6l8Tis+a/QxXPM7krhKTeGWVk2pNI//G3/sis33uthMLCSSQVbXLwF7EeHtWpcjkwzJ3lMtbzGPTTy/Omzzjz0lZ9msvmLFUk= Received: from DS7PR03CA0101.namprd03.prod.outlook.com (2603:10b6:5:3b7::16) by MW2PR12MB2363.namprd12.prod.outlook.com (2603:10b6:907:f::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Thu, 19 May 2022 10:05:02 +0000 Received: from DM6NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b7:cafe::31) by DS7PR03CA0101.outlook.office365.com (2603:10b6:5:3b7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.13 via Frontend Transport; Thu, 19 May 2022 10:05:01 +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 DM6NAM11FT032.mail.protection.outlook.com (10.13.173.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:05:01 +0000 Received: from sindhu.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.24; Thu, 19 May 2022 05:04:55 -0500 From: Sandipan Das To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH 4/5] perf/x86/amd/uncore: Add PerfMonV2 DF event format Date: Thu, 19 May 2022 15:33:33 +0530 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 2b2f5ca5-f2c5-4c8d-bde6-08da397f0a0f X-MS-TrafficTypeDiagnostic: MW2PR12MB2363: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: /XkkMHA66kGOwAepisjImiLWx2VYBSHlJHpGG83ps0qOv1ktjLUYh58PX0qxntbPWM7Hr06WTp/nUKMydtkmlhXnQvoEEy3arfj8pZU+DpKUtCRrmNkWvJtoeb2vkMCBVsXgc0S5avilZ45bfYnIzVERiaVBY3SXwt7xQFahBiYX1ePzN2XIcZ8wvoA4ZbNgmWwiUdK519kUPs7HefX05EB8Hmo2AaPeiANEYMZHAldEMNoFyjQrvR3/LYUrbxMX+hHglslYJ/WEhitPn37VvxAGJgW0fpd4KPGJxT2DjP+ffo/UOpVm0GmNfEuCRQiB3me4C6rSjYltx+bZ3ObyccZgXTDznSYW4MKMYKPHjEEDqbdlLGy2v8+sPpIoEJxRkk1idmQyh1emOUSGwI+URefHcjtKBT4x7zotwvZp34rYFIV9pOXb0EBa49jyum7xE1Rrestly2Qgbiu7rixQ+3wWHkjXxTYp8gY6rclx1dWkFDAb8e9B3eRPe1VzetUhuyaiHonzII2tC6K2uShHJT7Zv8WIqNaKy2uwJGUSKMVyxyy28nSt6/NBYNlnYajxTS8HdVB7yn6qEulXCfZBeUovUBX2rcw1B9aR0T8c+vuOOsMzCkkVV24ILUx5uvs1WELxdKxcEdf0y/oqaOyIQSgVDDh+uLOMxZBU5rh9veJt+cjjfWPC3B3LlfHNplWAtDIoWZKvMd5w22BVNGU9pg== 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)(46966006)(40470700004)(36840700001)(82310400005)(8676002)(6666004)(356005)(4326008)(36860700001)(5660300002)(26005)(7696005)(36756003)(40460700003)(86362001)(316002)(8936002)(2616005)(16526019)(186003)(2906002)(54906003)(508600001)(83380400001)(7416002)(110136005)(70206006)(70586007)(44832011)(81166007)(426003)(336012)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 10:05:01.7686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b2f5ca5-f2c5-4c8d-bde6-08da397f0a0f 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: DM6NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2363 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, use bits 0-7, 32-37 as EventSelect and bits 8-15, 24-27 as UnitMask for Data Fabric (DF) events. Signed-off-by: Sandipan Das --- arch/x86/events/amd/uncore.c | 24 +++++++++++++++++------- arch/x86/include/asm/perf_event.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 233dd405dd06..ff4238eff087 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -209,10 +209,14 @@ static int amd_uncore_event_init(struct perf_event *e= vent) { struct amd_uncore *uncore; struct hw_perf_event *hwc =3D &event->hw; + u64 event_mask =3D AMD64_RAW_EVENT_MASK_NB; =20 if (event->attr.type !=3D event->pmu->type) return -ENOENT; =20 + if (pmu_version >=3D 2 && is_nb_event(event)) + event_mask =3D AMD64_PERFMON_V2_RAW_EVENT_MASK_NB; + /* * NB and Last level cache counters (MSRs) are shared across all cores * that share the same NB / Last level cache. On family 16h and below, @@ -221,7 +225,7 @@ static int amd_uncore_event_init(struct perf_event *eve= nt) * out. So we do not support sampling and per-thread events via * CAP_NO_INTERRUPT, and we do not enable counter overflow interrupts: */ - hwc->config =3D event->attr.config & AMD64_RAW_EVENT_MASK_NB; + hwc->config =3D event->attr.config & event_mask; hwc->idx =3D -1; =20 if (event->cpu < 0) @@ -300,8 +304,10 @@ static struct device_attribute format_attr_##_var =3D = \ =20 DEFINE_UNCORE_FORMAT_ATTR(event12, event, "config:0-7,32-35"); DEFINE_UNCORE_FORMAT_ATTR(event14, event, "config:0-7,32-35,59-60"); /* F= 17h+ DF */ +DEFINE_UNCORE_FORMAT_ATTR(event14v2, event, "config:0-7,32-37"); /* Pe= rfMonV2 DF */ DEFINE_UNCORE_FORMAT_ATTR(event8, event, "config:0-7"); /* F17h+ L3 */ -DEFINE_UNCORE_FORMAT_ATTR(umask, umask, "config:8-15"); +DEFINE_UNCORE_FORMAT_ATTR(umask8, umask, "config:8-15"); +DEFINE_UNCORE_FORMAT_ATTR(umask12, umask, "config:8-15,24-27"); /* Per= fMonV2 DF */ DEFINE_UNCORE_FORMAT_ATTR(coreid, coreid, "config:42-44"); /* F19h L3 = */ DEFINE_UNCORE_FORMAT_ATTR(slicemask, slicemask, "config:48-51"); /* F17= h L3 */ DEFINE_UNCORE_FORMAT_ATTR(threadmask8, threadmask, "config:56-63"); /* = F17h L3 */ @@ -313,14 +319,14 @@ DEFINE_UNCORE_FORMAT_ATTR(sliceid, sliceid, "config:4= 8-50"); /* F19h L3 */ /* Common DF and NB attributes */ static struct attribute *amd_uncore_df_format_attr[] =3D { &format_attr_event12.attr, /* event */ - &format_attr_umask.attr, /* umask */ + &format_attr_umask8.attr, /* umask */ NULL, }; =20 /* Common L2 and L3 attributes */ static struct attribute *amd_uncore_l3_format_attr[] =3D { &format_attr_event12.attr, /* event */ - &format_attr_umask.attr, /* umask */ + &format_attr_umask8.attr, /* umask */ NULL, /* threadmask */ NULL, }; @@ -659,8 +665,12 @@ static int __init amd_uncore_init(void) } =20 if (boot_cpu_has(X86_FEATURE_PERFCTR_NB)) { - if (boot_cpu_data.x86 >=3D 0x17) + if (pmu_version >=3D 2) { + *df_attr++ =3D &format_attr_event14v2.attr; + *df_attr++ =3D &format_attr_umask12.attr; + } else if (boot_cpu_data.x86 >=3D 0x17) { *df_attr =3D &format_attr_event14.attr; + } =20 amd_uncore_nb =3D alloc_percpu(struct amd_uncore *); if (!amd_uncore_nb) { @@ -686,11 +696,11 @@ static int __init amd_uncore_init(void) if (boot_cpu_has(X86_FEATURE_PERFCTR_LLC)) { if (boot_cpu_data.x86 >=3D 0x19) { *l3_attr++ =3D &format_attr_event8.attr; - *l3_attr++ =3D &format_attr_umask.attr; + *l3_attr++ =3D &format_attr_umask8.attr; *l3_attr++ =3D &format_attr_threadmask2.attr; } else if (boot_cpu_data.x86 >=3D 0x17) { *l3_attr++ =3D &format_attr_event8.attr; - *l3_attr++ =3D &format_attr_umask.attr; + *l3_attr++ =3D &format_attr_umask8.attr; *l3_attr++ =3D &format_attr_threadmask8.attr; } =20 diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index af157aa74f4e..34348ae41cdb 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -89,6 +89,19 @@ #define AMD64_RAW_EVENT_MASK_NB \ (AMD64_EVENTSEL_EVENT | \ ARCH_PERFMON_EVENTSEL_UMASK) + +#define AMD64_PERFMON_V2_EVENTSEL_EVENT_NB \ + (AMD64_EVENTSEL_EVENT | \ + GENMASK_ULL(37, 36)) + +#define AMD64_PERFMON_V2_EVENTSEL_UMASK_NB \ + (ARCH_PERFMON_EVENTSEL_UMASK | \ + GENMASK_ULL(27, 24)) + +#define AMD64_PERFMON_V2_RAW_EVENT_MASK_NB \ + (AMD64_PERFMON_V2_EVENTSEL_EVENT_NB | \ + AMD64_PERFMON_V2_EVENTSEL_UMASK_NB) + #define AMD64_NUM_COUNTERS 4 #define AMD64_NUM_COUNTERS_CORE 6 #define AMD64_NUM_COUNTERS_NB 4 --=20 2.34.1 From nobody Thu May 7 20:22:21 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 3728AC433EF for ; Thu, 19 May 2022 10:05:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236492AbiESKF1 (ORCPT ); Thu, 19 May 2022 06:05:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236484AbiESKFX (ORCPT ); Thu, 19 May 2022 06:05:23 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2055.outbound.protection.outlook.com [40.107.243.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F0A9C2DA; Thu, 19 May 2022 03:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NrdofBs+XsSKjNMaOXI0P6lHpc0Qb88I7OGOAfU1yBzDVbhivI5QNVknnitt2MOgGZsdLIX/1qtXz7vYL/kfUSkFgL+LL5ACoViUU+qg75BBTLhDplDTDhbzEX+0TW+geZN9x57on2IDYhs1nUQ9urTevqASspwUyBIvK1CXNvDcbKqzRhr5iBsIEy/bvHOzpXX7j1G+ZA+wPwEjG3PKjBw54fZWvbByQh7cTyPgVrE36jWIv4Fh4gSUhjS4kwJvVwK225IuJOXZAEssLaVIIs+Rcn+vuvQ+jFoXX7CvxokKn7vhMbO1dQAjDYh8warAKMiPq0Dg5UOxgbMKg9op/A== 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=gaf3HW/o/CxmEyfR+WtiJD5CGcdgyg1ZD7c3GTV/aEw=; b=cY1J1mhakbYfxGBPfjHMHhW+wkjxWzZs5Fr8tCcgLW32XTLYNcnXxCz3C+WWt3d9guaSMNrbL6FOYGrsStegAA35jEqKSs78gZ0PXtMgqFChIRr4YGMeZrrU/GV2WGrvrLVueRSN5CxBG10UMzHAW1fyQbLJXqlKA08xY4p6kFd9Bx0rvILXotmp9A/vLN8ePPHdcR1dqlPf33fUw/E+olhgPUKSkvI9ZncFTv/3bj4f6Ud/rqPFMgkAtytv9bOz7qrPACz1wI3WAftWcr0PjF0v298YIDS+zMLj4lvMQboCJAQUgYnLuQiLSCBl7rFwt1D+RT7JRgxhcMD91VpKsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.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=gaf3HW/o/CxmEyfR+WtiJD5CGcdgyg1ZD7c3GTV/aEw=; b=2iDTYbdmgl7PWQPIzepQSI2lownfAnyEDMtkTmN8+UIUKH1brLJiuc1yQBqz+EfViNdXAeKaE/8zNDDRtnEKSQ1e5ogcg75APQQx80Vwz1mU0u/8sgyULYwyvnqLFHzK4RIqzAL8a2yZetMCsErPb5Z1uWYG7CGa2tai4xuQg7Y= Received: from DM6PR07CA0118.namprd07.prod.outlook.com (2603:10b6:5:330::31) by CO6PR12MB5427.namprd12.prod.outlook.com (2603:10b6:5:358::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Thu, 19 May 2022 10:05:20 +0000 Received: from DM6NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:5:330:cafe::2c) by DM6PR07CA0118.outlook.office365.com (2603:10b6:5:330::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.15 via Frontend Transport; Thu, 19 May 2022 10:05: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 DM6NAM11FT013.mail.protection.outlook.com (10.13.173.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Thu, 19 May 2022 10:05:20 +0000 Received: from sindhu.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.24; Thu, 19 May 2022 05:05:13 -0500 From: Sandipan Das To: , , CC: , , , , , , , , , , , , , , Subject: [PATCH 5/5] perf/x86/amd/uncore: Add PerfMonV2 RDPMC assignments Date: Thu, 19 May 2022 15:33:34 +0530 Message-ID: <1359379ef34da760f108b075ac138ab082caa3ba.1652954372.git.sandipan.das@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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: 843369f2-e746-4809-ff66-08da397f14f7 X-MS-TrafficTypeDiagnostic: CO6PR12MB5427: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: HlEymHUI1JvPw7GGNbSNtxHNFq0DUsdJBR1NngmykXOiVEXFuZ9tRDgJ+gblqaN9cCohlnJJd8xj6zCqr/iNnf2vXeLUIe2Whydn2gXGZX+3MCFnCz5Ggg/GK52Xgm0ZHOZGKMVihXiW1sV+ept1pXtcA9mb2tdQPlH0dvFedkVc6oQFl4dbaPB/EpnXbwIAL2gDG6hoOmRtVc4lgaW4f6FgV+fq9ZATerSoIRah+kfMs78rm8viPJZ1ALlaVGCfkFI5Elw0pFbB83PfYwhwdp7QLahXIU0sCgJ1PYl1WzkSzdb3SP6VhqoujRlvesWrCg+8tTVzX4KX+fkWPwYNUBontDJyuTCmKOUhkZn5UUPuhs6gygTQdPKcsMdRNjrxE8XSZQc6Pkkgs+pDRGh77m0OBlvyTfBFa6vxiij3OQjpiPXpQ+appPock+yy5mtFvvS6x6rgG8glHwTJxQYM+41NnZvSn97pNT18H1oct4nAA+mavoEi9D+1Oofec8AbBi/JuHyQZbQEV56Ck7A8dMQ2B1z/S87hdhg4x2OgTM8RXQVEOzupPINGPH/xdRERzlGaSfT2xORfe5Mqy8lBt5HjRKjNWnPJH02CU2kiF7ekx0pSVbSbEycyCpTJnuI/zTqFcbbmAI7FES/uJLFldcvBLLE4qqpKoqwm2vmrj1f962sz6Hl1qfQzJJ1sL6JLBAQLg2KgLrlNlusVpqK9OA== 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)(36756003)(5660300002)(86362001)(8936002)(82310400005)(2906002)(40460700003)(7416002)(110136005)(54906003)(44832011)(316002)(81166007)(4326008)(70586007)(70206006)(8676002)(356005)(47076005)(508600001)(6666004)(26005)(36860700001)(186003)(16526019)(7696005)(426003)(2616005)(83380400001)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 10:05:20.0835 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 843369f2-e746-4809-ff66-08da397f14f7 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: DM6NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5427 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The current RDPMC assignment scheme maps four DF PMCs and six L3 PMCs from index 6 to 15. If AMD Performance Monitoring Version 2 (PerfMonV2) is supported, there may be additional DF counters available which are mapped starting from index 16 i.e. just after the L3 counters. Update the RDPMC assignments accordingly. Signed-off-by: Sandipan Das --- arch/x86/events/amd/uncore.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index ff4238eff087..d568afc705d2 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -158,6 +158,16 @@ static int amd_uncore_add(struct perf_event *event, in= t flags) hwc->event_base_rdpmc =3D uncore->rdpmc_base + hwc->idx; hwc->state =3D PERF_HES_UPTODATE | PERF_HES_STOPPED; =20 + /* + * The first four DF counters are accessible via RDPMC index 6 to 9 + * followed by the L3 counters from index 10 to 15. For processors + * with more than four DF counters, the DF RDPMC assignments become + * discontiguous as the additional counters are accessible starting + * from index 16. + */ + if (is_nb_event(event) && hwc->idx >=3D NUM_COUNTERS_NB) + hwc->event_base_rdpmc +=3D NUM_COUNTERS_L3; + if (flags & PERF_EF_START) amd_uncore_start(event, PERF_EF_RELOAD); =20 --=20 2.34.1