From patchwork Thu Jun 20 12:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705444 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2042.outbound.protection.outlook.com [40.107.101.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0831AC44F; Thu, 20 Jun 2024 12:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888396; cv=fail; b=NUs939TmmgMmzT2MDo2SA5x1Tn6/rIU/+lRaEF+a9sJzEsjGyWhiJ4mzNgjm2WuQij/r76sp2cASP6z5JIleLU+QBp/N7sJ4KZ4UWj9Cp4xrDaKeS+q1JCyKspp3m9e6uYRCVA6tMKE+zYRLZCEOCQa9qSDdetTeo8aTEhhfY7s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888396; c=relaxed/simple; bh=8ayQTd/qimBdn61F5QCpbR4M/6gGUQSWoz9lIWUkteY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OQr/R7N8gDVnFvfdyxn8W5ft5+FkySTz7UhJsqGJoBsfULuUz9rE/vtg9hFKhBkbyU4fgeETpPA4059WMahX33B15CYnjngSzR0NauCUgPJbOSA5OZ45p62PQkLPVjtkTgybcUXbobfgez0bV028VIQgQaWG/1G3w0e6QKg3qAE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=H3ZvOfFk; arc=fail smtp.client-ip=40.107.101.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="H3ZvOfFk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TD2yFsz0ieprUoGE/mP96t0N/P+85/pGCyfnZRz3OPyOyKlFl82oEQMW3HrwjW5/GEwFQSqIzxQV3zp0s2xGJsjoX134fF9E9+iTffoSkkyTnU0ocp55Y3Kbl48QY/9nOD5Q6OPAgEmKwgt4FnUipqqWn+o2bW48HhUsI8YL2Gcem5iB4RAjWqNwYO3YrFJlpiObkdIv/VaJO6kJdVuOgr8Uw1AamGted5VKxfwCBDcvSaFwZkcbbCwB8Q6B7wy2GBQh8Z4pOk6RSjh36VlDVWzYUnXkOtqRUMM6EjdFslF4jRp8NGLp/B9dgE/q7nXS7hQNwOkecn9HajR2xWGErQ== 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=z1A1PMXRxwmFPpA2Kipxu5AUpAjeD2dSCqTpe8xo/ZU=; b=NIeZ6wijBQRSrs6gStuEggirbIsDVoSN2sNpwsxVCdxcSkQujLaILBAZSe97CBkivRyMmH6RwR3FeKsQ9J9D2G9cNs2gvoV3L6x5vpuZwSMKAgTGkDuFA/9eAagZz3Vvcckqv5fh8hVfzcjvhGNshOaaNadlrrUkP+lCxuncEHkDiEYOPUNceVwC5lPCDhIMw8oYBZbjqatdFQJ4PYtcCRtyd69Xx3O+VsPP+SMuiF8Yk+0RztY1cd8RzyWNanO2X4ShcClxMbI8stNsniPf3padGhbxufX2yKayEwww5KJidKp+uqe0qa13fOUYrTwsNBVIJUNS5kQR0U14K1vMlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=z1A1PMXRxwmFPpA2Kipxu5AUpAjeD2dSCqTpe8xo/ZU=; b=H3ZvOfFkVyzz9e+ksjMZd7oZrwAuzraZGJ+LbItjZtz4MYLnqibxlA4e3i2k0CkRNbTUr2MMhgHFLeNO2O0a2n8qTGbl+iagfQcUM15Cxn+Rppow+8JRuvUcdV33354/yvim5XnauBycr1TRjbBaOsfF1HhZfcAtC5q7gifOnzY= Received: from SJ0PR03CA0375.namprd03.prod.outlook.com (2603:10b6:a03:3a1::20) by SN7PR12MB6765.namprd12.prod.outlook.com (2603:10b6:806:26b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33; Thu, 20 Jun 2024 12:59:52 +0000 Received: from CO1PEPF000066EC.namprd05.prod.outlook.com (2603:10b6:a03:3a1:cafe::d2) by SJ0PR03CA0375.outlook.office365.com (2603:10b6:a03:3a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 12:59:51 +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 CO1PEPF000066EC.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 12:59:50 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 07:59:42 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 1/9] perf/x86/rapl: Fix the energy-pkg event for AMD CPUs Date: Thu, 20 Jun 2024 12:56:55 +0000 Message-ID: <20240620125703.3297-2-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EC:EE_|SN7PR12MB6765:EE_ X-MS-Office365-Filtering-Correlation-Id: f41eb1b6-0e6c-4080-8966-08dc9128df3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|82310400023|7416011|376011|36860700010|921017; X-Microsoft-Antispam-Message-Info: Eimc6sc/ART3E67Buxe8HJx6+hyadhmSpg/X4XDqktZuhzZ6xcO/Lwg7x8z2y1C0RwymGpB2G35YGJaiImc5ECbgVZ8M4CzCX7KrVL9iGGCiFGkF1PSy8yViZWz20fZtRCzBxDjjhlD9tCfBxKz2Wkz9u3pyfN4+NeqvPfS7EhYHHwHkM6P7VuapGmPqPuiFjiBO4uLcnkmkaagitDscAy4sQk2/HNvSeTsYz0DWu2PBeYDMvjWamh7HLojTOrT0S6tuqLJRKr1/7/OE7FojwQlwjZipzhl7oygLw6aR06syubNGNzKpl0LDvbykRw2PoByZul/MmRTMS0S0Rl8/PavYzAqv7ezdyAqmxA5kkCBVTnE1hKhXMIyEGnGeWYNmI5RYhjM5cqaxZOkR4oQTF05Ui1FUkITcVG8E2nVNwq68l68ZQhpk5sYDAOhllc/xdL7fLuFh7HUNzQdGdBPBcKUoyKC5glxP84f4Virx8bygTo6rwqgWjSTG7hb4H+xj5lhWEPqxhs6rA7bFk40oPOyZk0DmQz85leT9u7Fd9HTdvBrjmo0xtqbzIvp/QIK7SzoIYf7nsOnw2qWF8jDImMbWSb6iDMOkCcCQ2dFleSPvlqil4nYoO6R4dUgiCOL6PiKa2qxgHc1yIAKH7ClXCoWCgJ3M2LiWx/oLrF8b12SRSb2DYWzS3T6R/wmWSbdBhBj17GgzAmVu11jU4B/DfLJmRti+pzPbmRUuDau8/fR7kXVTrXesBdQajr8NOqpA00gZcC7fjMvF6f0EDXg+Jo/Na+5tdGORsldkhcyxPrE/8B8MTp+hgvNTjzlDHWRYMHyvQjOUOfpcwsFLavb9AmQl6YTRoz0oXOGads4J4f9bCKfhUhKDkbWfEFrP9B7xDKRtq33mrChvk7Yoo/5OdyxCMMZjwLEAp2z5cSp3L8D/ErUq7EcDcK+xFBrc8W4i2Cyb2C3DGFrPzXd2eIQYGe8A/UPCCvb5a7dN0x3T2hroi3xZkKHM6fMu4BjATWKTK2PNNFq8hJ0REHnqE96VLunQ9A+XbYMmOWg6Nf/bYLWg6ar/5gVVgvdX+EEz78u0Gh850OzyT89KeTNshn8IHk00AV69blYoIkeTaiyJ9I7KzuUOdPhRqHsNim1gXL5OLS2PIHHt4S3VYreOi3X6hbNzVkmG3pI5D3Ze6upW9jKwePelc090hXMHbwH622dC9nBjztRzHw/3eNf3iIz/ewk+cPb0EfxU+eRl5vXdU6rSRpyZ2/GOzRXOv7gPLqJkjr5MBLbn15Q8Xu8sayyTV0FJNNo5IUscpJ3xYFqtrs0wX4WKswc/cIdtSaEH+xCZLD1A/4tFryR7KCLqrpl73tDxFaQuD+lngou2Np0yvikVcDHih2WBdb6EzNigwwO5EaolKNCqJcFKQ+j03k/IAw6KQ8Dg13fXEfEuLfihiWY= 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:(13230037)(1800799021)(82310400023)(7416011)(376011)(36860700010)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 12:59:50.7833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f41eb1b6-0e6c-4080-8966-08dc9128df3b 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: CO1PEPF000066EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6765 After commit ("x86/cpu/topology: Add support for the AMD 0x80000026 leaf"), on AMD processors that support extended CPUID leaf 0x80000026, the topology_die_cpumask() and topology_logical_die_id() macros, no longer return the package cpumask and package id, instead they return the CCD (Core Complex Die) mask and id respectively. This leads to the energy-pkg event scope to be modified to CCD instead of package. Replacing these macros with their package counterparts fixes the energy-pkg event for AMD CPUs. However due to the difference between the scope of energy-pkg event for Intel and AMD CPUs, we have to replace these macros conditionally only for AMD CPUs. On a 12 CCD 1 Package AMD Zen4 Genoa machine: Before: $ cat /sys/devices/power/cpumask 0,8,16,24,32,40,48,56,64,72,80,88. The expected cpumask here is supposed to be just "0", as it is a package scope event, only one CPU will be collecting the event for all the CPUs in the package. After: $ cat /sys/devices/power/cpumask 0 Signed-off-by: Dhananjay Ugwekar Fixes: 63edbaa48a57 ("x86/cpu/topology: Add support for the AMD 0x80000026 leaf") --- arch/x86/events/rapl.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index b985ca79cf97..73be25e1f4b4 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -103,6 +103,10 @@ static struct perf_pmu_events_attr event_attr_##v = { \ .event_str = str, \ }; +#define rapl_pmu_is_pkg_scope() \ + (boot_cpu_data.x86_vendor == X86_VENDOR_AMD || \ + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) + struct rapl_pmu { raw_spinlock_t lock; int n_active; @@ -140,9 +144,21 @@ static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; +static inline unsigned int get_rapl_pmu_idx(int cpu) +{ + return rapl_pmu_is_pkg_scope() ? topology_logical_package_id(cpu) : + topology_logical_die_id(cpu); +} + +static inline const struct cpumask *get_rapl_pmu_cpumask(int cpu) +{ + return rapl_pmu_is_pkg_scope() ? topology_core_cpumask(cpu) : + topology_die_cpumask(cpu); +} + static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) { - unsigned int rapl_pmu_idx = topology_logical_die_id(cpu); + unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu); /* * The unsigned check also catches the '-1' return value for non @@ -543,6 +559,7 @@ static struct perf_msr amd_rapl_msrs[] = { static int rapl_cpu_offline(unsigned int cpu) { + const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); int target; @@ -552,7 +569,7 @@ static int rapl_cpu_offline(unsigned int cpu) pmu->cpu = -1; /* Find a new cpu to collect rapl events */ - target = cpumask_any_but(topology_die_cpumask(cpu), cpu); + target = cpumask_any_but(rapl_pmu_cpumask, cpu); /* Migrate rapl events to the new target */ if (target < nr_cpu_ids) { @@ -565,6 +582,8 @@ static int rapl_cpu_offline(unsigned int cpu) static int rapl_cpu_online(unsigned int cpu) { + unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu); + const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); int target; @@ -579,14 +598,14 @@ static int rapl_cpu_online(unsigned int cpu) pmu->timer_interval = ms_to_ktime(rapl_timer_ms); rapl_hrtimer_init(pmu); - rapl_pmus->pmus[topology_logical_die_id(cpu)] = pmu; + rapl_pmus->pmus[rapl_pmu_idx] = pmu; } /* * Check if there is an online cpu in the package which collects rapl * events already. */ - target = cpumask_any_and(&rapl_cpu_mask, topology_die_cpumask(cpu)); + target = cpumask_any_and(&rapl_cpu_mask, rapl_pmu_cpumask); if (target < nr_cpu_ids) return 0; @@ -677,6 +696,9 @@ static int __init init_rapl_pmus(void) { int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); + if (rapl_pmu_is_pkg_scope()) + nr_rapl_pmu = topology_max_packages(); + rapl_pmus = kzalloc(struct_size(rapl_pmus, pmus, nr_rapl_pmu), GFP_KERNEL); if (!rapl_pmus) return -ENOMEM; From patchwork Thu Jun 20 12:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705445 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2051.outbound.protection.outlook.com [40.107.220.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B19871AD407; Thu, 20 Jun 2024 13:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888480; cv=fail; b=AsAcQ0MEUho0eUSpvF5/v+878Ha59FnotVpK1RXSltrBpeVmn/AVVJlN5n8BSjwgzxL5mRA10cZCw1PuhHk0z/T9jECdvYjXFpH9khw2KnceL3N7IO6K8Wc7aT9LhaiPenBB4nlpCqQshwQv+suEvLtA2WDxKq91DwW9+B1suR8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888480; c=relaxed/simple; bh=bdHqtKQgt7guqR41b+qTLiClw9pcS6FtJ1Uis4RlDfw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R1pduAbvNtr/Fq7Zn4igbBz3E2W2zTvM4AkOa52yo13IiFszZn1hL3FjutejxUWikNy3kYdjLkfUT550enRrHNLP+jAgWDGCTE2gSykOBLtB0STmBjU7w23mjKYA+KNs2vn8pNHEo4aHCs3LixY10zBbDgdK1BcDrd4dKvWphls= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=lcpQ9Fe+; arc=fail smtp.client-ip=40.107.220.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="lcpQ9Fe+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZ7kc72xw85U0Idb0AJzl7wszjEYls/pwwrkk/jcfMnOQX9QjPb2JMJ0kFbYpFIiHT1ZDavK5yMatl+CHFhkV7MtV1z1gTRjioTKH+gH7kgXr0lbRl9QVNzlo9qr55zFMgMvql61sfbcn96MlSqEyIE7sRred7Kbq5FzyaorKc6NziFV6zCFlLMvfxHEbHmpS/wc81bahAZPQsRDyJVWlaI1Ubh5S+m5mLYL44KPmIJaOTKgAK0DZgLJXQq2qlmNXH1uQD+L3ILC11ea7B1jOvBWlmw1ACTILoRBMtNyRvIHEaLqLsDgshBvtLWEi7CJ/ADtw6AMrgnPJRjWKWz1uQ== 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=8NbjBZFGLCOQPKlMZfmrhLpqA0S8CIGooxpyooHDAQo=; b=bmFhX0NtLG006ouVi9pnG/dHQc3NcRQY5nW+uvLwGhRiDxw28zw5FCjYwLKiGPAarP3Hpeuw1ptlcKZ/1TluzjqExTm0sYcVsJ9BjJnbDcB6dJOa57DfKN0yNSpZBjAW5zC+A4Hh+sJinRZf5WEx5mRdmDSjlDV8YvQ0OXPF81TppLOc0gxGf++/TH2CCaPiSxnn3J2p96JE6GrqONHbRdP2DA6TqOsy8ZZAukSJ9ZMYqw+PyGlRNvs4+RsVH0U4gVwNN3+aphHA6nWZAmle6wdyE42u9FZxxo77ndgYXmhXeJqTmetBuqqJBKiBkOlcXCANJWisKE7j0j4jVNadnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=8NbjBZFGLCOQPKlMZfmrhLpqA0S8CIGooxpyooHDAQo=; b=lcpQ9Fe+p30GPt+6lQrcnF9f637TbI1C76qREEnHMs2SzYhWZCb3y6PhBZ24K/siJ4/Qj8at+bSuIHrbUb6UvNViokI7rbU7d64AmZ+wdyVDSD9kTUB6/3FrE4U7AO0YW8PHWNDccmMLFzQhFvsbAC6nukP+W/mY6OV+KwyQpns= Received: from BLAPR03CA0022.namprd03.prod.outlook.com (2603:10b6:208:32b::27) by SA1PR12MB7318.namprd12.prod.outlook.com (2603:10b6:806:2b3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Thu, 20 Jun 2024 13:01:13 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:32b:cafe::74) by BLAPR03CA0022.outlook.office365.com (2603:10b6:208:32b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.34 via Frontend Transport; Thu, 20 Jun 2024 13:01:13 +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 BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:01:12 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:01:04 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 2/9] perf/x86/rapl: Rename rapl_pmu variables Date: Thu, 20 Jun 2024 12:56:56 +0000 Message-ID: <20240620125703.3297-3-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4E:EE_|SA1PR12MB7318:EE_ X-MS-Office365-Filtering-Correlation-Id: dd8688f8-2127-4d4d-3b08-08dc91291003 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|36860700010|376011|1800799021|82310400023|7416011|921017; X-Microsoft-Antispam-Message-Info: DnSIYI0NS7T43BorBXRcnTY3pYMQRDTg4ulNaJFRFc/rqKVzK6x952C9EmKokM7t29WACmYTCMbxZuCpxgm44KVvf+C9s/9vhEckQ5ynWd8PUmf7YQ3iDp4e4udy0FkHCCBlFoJNabsH5dz7DN9Le7K1A0X4s1WYPY/fydPMKpDxFV3W3FHxK4s5BG5rjjgnyXJz0C7ZaoDsmnVVlAr8ytSJvFOxuZS/YIgRkdCI+ArEWkUIPPnuJq5IPczWaco7FBQF9TnbdHVnrdxoESjbhEvcKwsAi3m/Mm5z3rfEVq+xsXY4z1K1GY9UXFrYNOMXGHwoGO7lBQ/bT90x0OxFe1MEttLyaOQZc3Tid35xAnbOlAdy1iZpGwY6pbUymW0QddIZpeOFmCKQDteF29c1iyBl1qA4+NQ/iywN9rFxuuhZd0McuF+wBGvdqhXR+ymHZ25SMeydR+izpdIniOw+kl0mr78avHyT30UpHGR9WCSHhcQl/2ITvFC0ZMn0vY4kyy8wkuW9cXtntP38pPXwEQwQqYYj5wvQwzaS+QDdYUIyYjnak9i3IDw/Yscya0x/PSy5J/dX8d8Cn/f/tYsYksNgMBkRz5N9e4BD2thJdKfv4yO3XcZ8tS4N8yVKry7v8tIV7CQZ9w3qb4bapYyQJFYjsDqk/44YK/2HHvuiUW+eOW7jABeztH0DxULp6WLuqIPU/Eb57K30G5moiTBWe9IfLFdihp1fmaams1JT/pWpeH8c8fgrl6PA07gfIPUmlRrq8v8CAPUFUslEhvxKLH3DoyyiSh/NwFJli32jUad/k2AAYuVRxjg2TdtVrEucqjo1dyrRp5glSFPmQ+4vI+E3wE4bB3ZIcwG9mbXjJqjlrLLp6vRnNJvJb79PgOLWHQer35qICG0NZJG9tQjBr0klxlqELjM4rQMQuCzYZExJSoqRox3Qdg+rNex7GfnUdMYbb2bLFVEKq0DXKh4cHUvSj8NVPgKwJsEivj39+YOUr3DLaxOPZMxxqJdk7XZ8IpAoucuk/dMzS8QuG4Z4pyIByZWb+TnYwUKr8zbZv1q+9UQbJfB4VcP06GRltKhfdnOx9amD+ags3EcqFOegCnPvaaXs8iO+OvlkM6SR9l82vNCNVgLzu5pxJBP+oqTDt79x8pYRivoUxwDEhTlkYkwDecoKn5YItUNAffvcxtCY3eMAA8I5OCFgDSN28ZRL42mRdNCgYeMbJjRsJcmzhmhoYCUN/YFDTU8ZupPuPE4P3JDcAgmISIcT5kQU2JIF/6fbq1qNbSrZ+pz7BxYWQNrwg7W1fc4qimNlmUP7tLHX4shXBxHXTOAi0wK/NPwe00ucxx86R6bD4haJGl0Z+cl6bv/NCOvuLcnIUpVQlICm4YiFVIJGI5fM1GzASVu57Kt0Pse3Td+0pAACIRUsM+pd5ypg8sUIwWZFOigbQXM= 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:(13230037)(36860700010)(376011)(1800799021)(82310400023)(7416011)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:01:12.7320 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd8688f8-2127-4d4d-3b08-08dc91291003 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7318 Rename struct rapl_pmu variables from "pmu" to "rapl_pmu", to avoid any confusion between the variables of two different structs pmu and rapl_pmu. As rapl_pmu also contains a pointer to struct pmu, which leads to situations in code like pmu->pmu, which is needlessly confusing. Above scenario is replaced with much more readable rapl_pmu->pmu with this change. Also rename "pmus" member in rapl_pmus struct, for same reason. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 104 ++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 73be25e1f4b4..b4e2073a178e 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -120,7 +120,7 @@ struct rapl_pmu { struct rapl_pmus { struct pmu pmu; unsigned int nr_rapl_pmu; - struct rapl_pmu *pmus[] __counted_by(nr_rapl_pmu); + struct rapl_pmu *rapl_pmu[] __counted_by(nr_rapl_pmu); }; enum rapl_unit_quirk { @@ -164,7 +164,7 @@ static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) * The unsigned check also catches the '-1' return value for non * existent mappings in the topology map. */ - return rapl_pmu_idx < rapl_pmus->nr_rapl_pmu ? rapl_pmus->pmus[rapl_pmu_idx] : NULL; + return rapl_pmu_idx < rapl_pmus->nr_rapl_pmu ? rapl_pmus->rapl_pmu[rapl_pmu_idx] : NULL; } static inline u64 rapl_read_counter(struct perf_event *event) @@ -228,34 +228,34 @@ static void rapl_start_hrtimer(struct rapl_pmu *pmu) static enum hrtimer_restart rapl_hrtimer_handle(struct hrtimer *hrtimer) { - struct rapl_pmu *pmu = container_of(hrtimer, struct rapl_pmu, hrtimer); + struct rapl_pmu *rapl_pmu = container_of(hrtimer, struct rapl_pmu, hrtimer); struct perf_event *event; unsigned long flags; - if (!pmu->n_active) + if (!rapl_pmu->n_active) return HRTIMER_NORESTART; - raw_spin_lock_irqsave(&pmu->lock, flags); + raw_spin_lock_irqsave(&rapl_pmu->lock, flags); - list_for_each_entry(event, &pmu->active_list, active_entry) + list_for_each_entry(event, &rapl_pmu->active_list, active_entry) rapl_event_update(event); - raw_spin_unlock_irqrestore(&pmu->lock, flags); + raw_spin_unlock_irqrestore(&rapl_pmu->lock, flags); - hrtimer_forward_now(hrtimer, pmu->timer_interval); + hrtimer_forward_now(hrtimer, rapl_pmu->timer_interval); return HRTIMER_RESTART; } -static void rapl_hrtimer_init(struct rapl_pmu *pmu) +static void rapl_hrtimer_init(struct rapl_pmu *rapl_pmu) { - struct hrtimer *hr = &pmu->hrtimer; + struct hrtimer *hr = &rapl_pmu->hrtimer; hrtimer_init(hr, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hr->function = rapl_hrtimer_handle; } -static void __rapl_pmu_event_start(struct rapl_pmu *pmu, +static void __rapl_pmu_event_start(struct rapl_pmu *rapl_pmu, struct perf_event *event) { if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED))) @@ -263,39 +263,39 @@ static void __rapl_pmu_event_start(struct rapl_pmu *pmu, event->hw.state = 0; - list_add_tail(&event->active_entry, &pmu->active_list); + list_add_tail(&event->active_entry, &rapl_pmu->active_list); local64_set(&event->hw.prev_count, rapl_read_counter(event)); - pmu->n_active++; - if (pmu->n_active == 1) - rapl_start_hrtimer(pmu); + rapl_pmu->n_active++; + if (rapl_pmu->n_active == 1) + rapl_start_hrtimer(rapl_pmu); } static void rapl_pmu_event_start(struct perf_event *event, int mode) { - struct rapl_pmu *pmu = event->pmu_private; + struct rapl_pmu *rapl_pmu = event->pmu_private; unsigned long flags; - raw_spin_lock_irqsave(&pmu->lock, flags); - __rapl_pmu_event_start(pmu, event); - raw_spin_unlock_irqrestore(&pmu->lock, flags); + raw_spin_lock_irqsave(&rapl_pmu->lock, flags); + __rapl_pmu_event_start(rapl_pmu, event); + raw_spin_unlock_irqrestore(&rapl_pmu->lock, flags); } static void rapl_pmu_event_stop(struct perf_event *event, int mode) { - struct rapl_pmu *pmu = event->pmu_private; + struct rapl_pmu *rapl_pmu = event->pmu_private; struct hw_perf_event *hwc = &event->hw; unsigned long flags; - raw_spin_lock_irqsave(&pmu->lock, flags); + raw_spin_lock_irqsave(&rapl_pmu->lock, flags); /* mark event as deactivated and stopped */ if (!(hwc->state & PERF_HES_STOPPED)) { - WARN_ON_ONCE(pmu->n_active <= 0); - pmu->n_active--; - if (pmu->n_active == 0) - hrtimer_cancel(&pmu->hrtimer); + WARN_ON_ONCE(rapl_pmu->n_active <= 0); + rapl_pmu->n_active--; + if (rapl_pmu->n_active == 0) + hrtimer_cancel(&rapl_pmu->hrtimer); list_del(&event->active_entry); @@ -313,23 +313,23 @@ static void rapl_pmu_event_stop(struct perf_event *event, int mode) hwc->state |= PERF_HES_UPTODATE; } - raw_spin_unlock_irqrestore(&pmu->lock, flags); + raw_spin_unlock_irqrestore(&rapl_pmu->lock, flags); } static int rapl_pmu_event_add(struct perf_event *event, int mode) { - struct rapl_pmu *pmu = event->pmu_private; + struct rapl_pmu *rapl_pmu = event->pmu_private; struct hw_perf_event *hwc = &event->hw; unsigned long flags; - raw_spin_lock_irqsave(&pmu->lock, flags); + raw_spin_lock_irqsave(&rapl_pmu->lock, flags); hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED; if (mode & PERF_EF_START) - __rapl_pmu_event_start(pmu, event); + __rapl_pmu_event_start(rapl_pmu, event); - raw_spin_unlock_irqrestore(&pmu->lock, flags); + raw_spin_unlock_irqrestore(&rapl_pmu->lock, flags); return 0; } @@ -343,7 +343,7 @@ static int rapl_pmu_event_init(struct perf_event *event) { u64 cfg = event->attr.config & RAPL_EVENT_MASK; int bit, ret = 0; - struct rapl_pmu *pmu; + struct rapl_pmu *rapl_pmu; /* only look at RAPL events */ if (event->attr.type != rapl_pmus->pmu.type) @@ -373,11 +373,11 @@ static int rapl_pmu_event_init(struct perf_event *event) return -EINVAL; /* must be done before validate_group */ - pmu = cpu_to_rapl_pmu(event->cpu); - if (!pmu) + rapl_pmu = cpu_to_rapl_pmu(event->cpu); + if (!rapl_pmu) return -EINVAL; - event->cpu = pmu->cpu; - event->pmu_private = pmu; + event->cpu = rapl_pmu->cpu; + event->pmu_private = rapl_pmu; event->hw.event_base = rapl_msrs[bit].msr; event->hw.config = cfg; event->hw.idx = bit; @@ -560,22 +560,22 @@ static struct perf_msr amd_rapl_msrs[] = { static int rapl_cpu_offline(unsigned int cpu) { const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); - struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); + struct rapl_pmu *rapl_pmu = cpu_to_rapl_pmu(cpu); int target; /* Check if exiting cpu is used for collecting rapl events */ if (!cpumask_test_and_clear_cpu(cpu, &rapl_cpu_mask)) return 0; - pmu->cpu = -1; + rapl_pmu->cpu = -1; /* Find a new cpu to collect rapl events */ target = cpumask_any_but(rapl_pmu_cpumask, cpu); /* Migrate rapl events to the new target */ if (target < nr_cpu_ids) { cpumask_set_cpu(target, &rapl_cpu_mask); - pmu->cpu = target; - perf_pmu_migrate_context(pmu->pmu, cpu, target); + rapl_pmu->cpu = target; + perf_pmu_migrate_context(rapl_pmu->pmu, cpu, target); } return 0; } @@ -584,21 +584,21 @@ static int rapl_cpu_online(unsigned int cpu) { unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu); const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); - struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); + struct rapl_pmu *rapl_pmu = cpu_to_rapl_pmu(cpu); int target; - if (!pmu) { - pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu)); - if (!pmu) + if (!rapl_pmu) { + rapl_pmu = kzalloc_node(sizeof(*rapl_pmu), GFP_KERNEL, cpu_to_node(cpu)); + if (!rapl_pmu) return -ENOMEM; - raw_spin_lock_init(&pmu->lock); - INIT_LIST_HEAD(&pmu->active_list); - pmu->pmu = &rapl_pmus->pmu; - pmu->timer_interval = ms_to_ktime(rapl_timer_ms); - rapl_hrtimer_init(pmu); + raw_spin_lock_init(&rapl_pmu->lock); + INIT_LIST_HEAD(&rapl_pmu->active_list); + rapl_pmu->pmu = &rapl_pmus->pmu; + rapl_pmu->timer_interval = ms_to_ktime(rapl_timer_ms); + rapl_hrtimer_init(rapl_pmu); - rapl_pmus->pmus[rapl_pmu_idx] = pmu; + rapl_pmus->rapl_pmu[rapl_pmu_idx] = rapl_pmu; } /* @@ -610,7 +610,7 @@ static int rapl_cpu_online(unsigned int cpu) return 0; cpumask_set_cpu(cpu, &rapl_cpu_mask); - pmu->cpu = cpu; + rapl_pmu->cpu = cpu; return 0; } @@ -679,7 +679,7 @@ static void cleanup_rapl_pmus(void) int i; for (i = 0; i < rapl_pmus->nr_rapl_pmu; i++) - kfree(rapl_pmus->pmus[i]); + kfree(rapl_pmus->rapl_pmu[i]); kfree(rapl_pmus); } @@ -699,7 +699,7 @@ static int __init init_rapl_pmus(void) if (rapl_pmu_is_pkg_scope()) nr_rapl_pmu = topology_max_packages(); - rapl_pmus = kzalloc(struct_size(rapl_pmus, pmus, nr_rapl_pmu), GFP_KERNEL); + rapl_pmus = kzalloc(struct_size(rapl_pmus, rapl_pmu, nr_rapl_pmu), GFP_KERNEL); if (!rapl_pmus) return -ENOMEM; From patchwork Thu Jun 20 12:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705461 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2058.outbound.protection.outlook.com [40.107.243.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FFCD1AD9D1; Thu, 20 Jun 2024 13:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888510; cv=fail; b=rkYCJC3Yk/sMHlMo0hla/GeeD3ZoRNc9Hi015ka03lf/GojfqIOTOuYU7YMc9VVSnmIQon3yrSt0fhzAe7mHPIUurvoWoVraqW8RuTg7UOQhYxz/pqpT1riXidTafkzcmXuqnBfUXMi1TH2yGWQ5xDMW/Xg2BatmYMaM8+SCshI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888510; c=relaxed/simple; bh=Gk0eDrWkM4+6BcmWgg9Zn5wMFoL1/BiV+SJ4lOA/JBg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fQR4rZYIEZErkbikqrAZQssMY4wuH70u0UKUrpsaGt52QUTYwVADj9HlkgUFkTaORivyEtAsfMo3lF115uw7QegSRBn/xwkywBrStiKywcP6FvLbcQqOftDVFrrk2SKixxiL8WUw2G0o53I9C6KnkW9ISAc5tJhGgroZNBM4k7E= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=nU91jyQB; arc=fail smtp.client-ip=40.107.243.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="nU91jyQB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lbhMozW83tmHVyY3+Jve9TcLpd4ltsZ+44ewJcIbuLL03WJx/M24K39XWcwys917nojyXbLcN2WHYKauVnfPEtw4MhPhA5UyzwbpgNNAR9svde4FnG/FuyYEt/2qTTEIPQwLLUA4qsJVmdOd7MgUbTTdZBV+rHLiEbNuc7p8SUO7JMqJtM/9clD2PB5vUva41hWsMK+4VMnwgaXx1rK4qIruet7GnO8myFc5l+7pFxGcExaPUCr+ocE/oLCFs7fFnbd7BVnCV2cNbBm3TfvLpVgSUx0Y0wAf1fGfvRqZfmpM/hDcdP4aMYrRuVvaqkxJG0atHzGECb334pKI/xjW0g== 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=3XxBOYQHTq6+VWT/1eEZw5vU3Ql+de6j2SbkY2U/TVY=; b=Erpy1POcfDbJ/icyJml5PRtpC0xxRnTSmGD4wtiEENR8OGW0aWiz6vn+/LwFmj1gD9pKHCKB1x9sM0/znn06jQl2otWiP1muoJNa/iJ1PzQwnwBzDRXyI8nFKyxQqp51eEJ5LWw5Tbp3GNN/wdgieOMABP2KH1IYjn/WMbSVBqDd2uN6NkzNpirvjoCKwVT5Klp6rjPOutCTKr+j+W4HRpOWR1dt9LckP+2glqR2e+mSvcn2ljsDYGsKKJP07woaM4qz6YsKme6rCXGGiYYznHfytkrvL/0vrUk/msdTNTOEmJgEDtjg6an2EP7kl9xe49IkjgRXcDU/tXEnHChnZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=3XxBOYQHTq6+VWT/1eEZw5vU3Ql+de6j2SbkY2U/TVY=; b=nU91jyQBBgyTfyR1oxZZPJyMNZc3bab/bmSoe1z+9TmZ2/JaXBh0VYMms8Yw6cJ+8r+RTvIU4ydI767QtwwZNZJCQn+4u2vOrJY5ORSgPlT2E4xfFX0BEgRdm3q4N/1sFOzZKF+QDDo9oCkYymLlz7yb1oSpe2tCWc5mhXJXBeo= Received: from BLAPR03CA0013.namprd03.prod.outlook.com (2603:10b6:208:32b::18) by IA1PR12MB6435.namprd12.prod.outlook.com (2603:10b6:208:3ad::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.21; Thu, 20 Jun 2024 13:01:35 +0000 Received: from BL6PEPF0001AB4E.namprd04.prod.outlook.com (2603:10b6:208:32b:cafe::94) by BLAPR03CA0013.outlook.office365.com (2603:10b6:208:32b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 13:01:31 +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 BL6PEPF0001AB4E.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:01:31 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:01:23 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 3/9] perf/x86/rapl: Make rapl_model struct global Date: Thu, 20 Jun 2024 12:56:57 +0000 Message-ID: <20240620125703.3297-4-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4E:EE_|IA1PR12MB6435:EE_ X-MS-Office365-Filtering-Correlation-Id: 1222e7ef-1a33-48f4-1655-08dc91291b29 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|82310400023|7416011|376011|36860700010|1800799021|921017; X-Microsoft-Antispam-Message-Info: zkWq7cZaPH2vCRHCCPQcQAIMEBHC168pOi0NtfVYJnmQnBe13meaNNrI+4orM+66Lspj9BGPQRBWGMntpPjWq31gTriPwh61/EhBqEMAv0LuG4ft/EHv5u00lR7BwBvoNCc53ttqm35Fu9jRAF7GkcX9wjr9hd1Jgt+6YVOWZC/fdoPDhhp9CkFmPbxx1kH3iQmV3V53+F/Df4zRljZ/5a9su77n42Oh8po2ANh0c3Eyng6WQm5U+iNJYc3g4sQ278MhyA5APUZ9piq62DxyeFrQyRo1Ahk3oAhiT02Ht4t3eV1TV4DjFIWrjeD5FyhIXSWcT1RLToCyP8qadQqQEajt47SxzZ5pRfmw4cvZizf7PuZsZoaR6VUqFRzK9lePgLdj8QZDgvSDKRFLVStXEhaIPfbKRQXzWAYfdv8Bc/DJudz89oAq8WdQ2GFTgQW5+P73KPUIFfvtm5w7U7iX0/TMeKo2Szm5C6twffOPosRxCchkZVj7Gs4jDuBGA/3+XgdDPF8Zw9mrPfhokvis4aGgY5wGiYr2f9T1jopRi/WNqus1WZZgKo3SLOzWOMvbjekUaxWxdl3/pdvy+90SYOZxlSWzp/nlCvMHkCkTHPEhD1lqSHM7FLPJvROK9ETY3GR5if4HScEiYHITpJwMAWmJfvJk5VrkBxLUFEd9M9OW/fMpGBL7rKGHZr86voC0wbgcbRkASVS9PGHvsXsRhB/wlOCrTeCWxPxxsPev5jikNSK/gcSpq6Gq2EZW2Q8QzQqjMbJUZHknifVnkKv5GzbuTdmr+8Ng1eL3sYVQSUPFalJnYssTQXVCAbvgAMP36zxOMqEWYtHOuRI3Bfs/4stVmO3byZF4K8vecjNTZVi28Xfh4qY1Kr2exQhHbraTDXPDNF2q/WBnMGcwhae/9UfwZcNMDMvYWxSrbnIvAWhBbnr7W41kmt30PcZ80Q0dhgQXCf8YCqXLSwf24tvio1qTu0Szt2V+hs2MwNsFcm9hCNYLeMyVMfxhhlKbZ6cZdhAmn09bHjfQkqcnx2DFBd4dGa6aclYaPaM4XaRKI6cCUWnK+p5MymNEVFsEWnyGEARTS59dOuvBGJjHtC5bdUqfx81FrSQbHApdimQrGBjWcun0usMkVU0Yj6BKBXOAjo3sncuwS+py4cHRpb7XMEBtb5sMWic7Ku+bWRgLB/JYukyT1z0/y5dfBf7W4G433aVQsv4jW3HpSfNkwEF1hvwRk1a43jQ9mU+Ja8CfWd7q+uS4Vufaa2g66FrlkNFM5N2aQHVI+NPUg2LxZ3aNaSY3aHf4IREKXWwU3EUkMEzjAu70Ma4mLi0hcBgGaFsEkf5F4aR7Uy6kJIRO6xEXH3TvXhYwkR3DuE+mAfNHvIiSD6857RX+CgvWiykxDbzj5fAATnDHGnTR+jfP1BeyrHYf449yb2tw9BxgigVCmWU= 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:(13230037)(82310400023)(7416011)(376011)(36860700010)(1800799021)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:01:31.4350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1222e7ef-1a33-48f4-1655-08dc91291b29 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: BL6PEPF0001AB4E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6435 To support AMD's per_core RAPL counter, we will need to check per_core capability of the current rapl_model multiple times in rapl_cpu_online/offline, init_rapl_pmus functions, so cache the matched rapl model in a global variable, to avoid calling x86_match_cpu() multiple times. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index b4e2073a178e..e5e878146542 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -143,6 +143,7 @@ static cpumask_t rapl_cpu_mask; static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; +static struct rapl_model *rapl_model; static inline unsigned int get_rapl_pmu_idx(int cpu) { @@ -614,18 +615,18 @@ static int rapl_cpu_online(unsigned int cpu) return 0; } -static int rapl_check_hw_unit(struct rapl_model *rm) +static int rapl_check_hw_unit(void) { u64 msr_rapl_power_unit_bits; int i; /* protect rdmsrl() to handle virtualization */ - if (rdmsrl_safe(rm->msr_power_unit, &msr_rapl_power_unit_bits)) + if (rdmsrl_safe(rapl_model->msr_power_unit, &msr_rapl_power_unit_bits)) return -1; for (i = 0; i < NR_RAPL_DOMAINS; i++) rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL; - switch (rm->unit_quirk) { + switch (rapl_model->unit_quirk) { /* * DRAM domain on HSW server and KNL has fixed energy unit which can be * different than the unit from power unit MSR. See @@ -839,21 +840,20 @@ MODULE_DEVICE_TABLE(x86cpu, rapl_model_match); static int __init rapl_pmu_init(void) { const struct x86_cpu_id *id; - struct rapl_model *rm; int ret; id = x86_match_cpu(rapl_model_match); if (!id) return -ENODEV; - rm = (struct rapl_model *) id->driver_data; + rapl_model = (struct rapl_model *) id->driver_data; - rapl_msrs = rm->rapl_msrs; + rapl_msrs = rapl_model->rapl_msrs; rapl_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_MAX, - false, (void *) &rm->events); + false, (void *) &rapl_model->events); - ret = rapl_check_hw_unit(rm); + ret = rapl_check_hw_unit(); if (ret) return ret; From patchwork Thu Jun 20 12:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705462 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2076.outbound.protection.outlook.com [40.107.244.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCEB81B0125; Thu, 20 Jun 2024 13:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.76 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888516; cv=fail; b=JFLsS/5iqqaTI1/xcPiBXs94gfjFkrqZgCY6ZVyxA25fnnUvGCZnV1ETI0dtP6Q+ahVeDTxlUR8a9rpYmaXQT+WvVs58AWnPnOIrSedcRV3kdnII2zibyHfTz7ENFWHU0heNKQ7ZzWsDIoNt9CQxTfk+34Ur49r39LDm5ta43gk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888516; c=relaxed/simple; bh=FbVldJAzwBUz/OiIKlBv24FGlyQJ3s39q84DqVs7d1o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JPAIvMQR+UvtuqKxcVFwcHOMTkKADkta+EoKKn852i8epz1QTlOWW97jU//g8qCpYxXQzCygX0iN9WhAIilYJbKHBw+yP7JJNFL5lc6DY/m5vwHLe57DDxfEsAAa873KQJHqzOuHdDYuePD7VDgBQT0XNRfdxZfjCLgrMEQIZmE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=al+3bEEM; arc=fail smtp.client-ip=40.107.244.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="al+3bEEM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nXCw1HR3RtvUTGjbcb6wlkwJotrXSk094QBX4ezJ5+NOvDDTPHXoplmWyhArJc0GR/R8AIuke3xhptNKhOr9DtMGdZ/Wcvi8US40p9EduUIEg/Oh27cyDBR+MiUoQBA2agfAYNHoAhHwtFb7uTmAp+c53Wq9wkVUW9Dbj7j10a/8hLY2rQ507wpoiSHiE9im3yFEA3/lwciKYovn4nxOL+JDFUzoG/iNuzkS38nHjJt3tuGQ2dfAVgB6RB+teFCEzaKueDJmUC0TZdTHIQ7Xd5cpK1uFJ2x7g5mFudnABihbahSH1NDDUYAnJ1uogm9WB5QM0XuglMTP4pcHq9ySXQ== 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=3WSqqtWS5pLK7gm63CqzM301h8Bv9ShBNsN1dNvF7Fg=; b=itSyW2conT+zNmvfYgjWe5vnOlJVRT65+WA268YDL4S7y7TL83Lf2+qP76dyhqDJM56rhVDUQMBVqt1gzmgFWTsQ9kPRgtdQTN2ew5twZClz3zGxS0T8Hyy3At/crcn9Ewakyz3I8xwIrWOzTC1KOMsBlzxQ/36kJDJrrVV2vax8ET/XRxqtixTOpJNqEEWtq5nIxlPAzW5+rj9trN+dryEcGK9RLJHWjUQ3oHX4lPrkxb3/ai3fq/jYa3vvcrv4nA7vrL8tlozsIy3wbBdE8nBLjXY9AJjIDwWopDg4qvA2EuNK05ocorBvRL2Q0xEbmbJxjK4nc7/hZXJlXFrdTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=3WSqqtWS5pLK7gm63CqzM301h8Bv9ShBNsN1dNvF7Fg=; b=al+3bEEMruG5txl6Vt4Rr530awRLP6N5a+HxA5rb7dBx7OM2XBsvt/HqSqwGY1Kk3rmDCnGuHwQPLBCkrruQY8osxfj1sEqbsF7wFykm/zOvVrmHcvp14YZcVVnFrHmReILIPvTae3TnFREMtTQK4eJmOcW8XEX/xnPnNuo7/yQ= Received: from MN2PR10CA0024.namprd10.prod.outlook.com (2603:10b6:208:120::37) by SJ2PR12MB9243.namprd12.prod.outlook.com (2603:10b6:a03:578::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Thu, 20 Jun 2024 13:01:51 +0000 Received: from BL6PEPF0001AB51.namprd04.prod.outlook.com (2603:10b6:208:120:cafe::45) by MN2PR10CA0024.outlook.office365.com (2603:10b6:208:120::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 13:01:51 +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 BL6PEPF0001AB51.mail.protection.outlook.com (10.167.242.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:01:51 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:01:43 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 4/9] perf/x86/rapl: Move cpumask variable to rapl_pmus struct Date: Thu, 20 Jun 2024 12:56:58 +0000 Message-ID: <20240620125703.3297-5-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB51:EE_|SJ2PR12MB9243:EE_ X-MS-Office365-Filtering-Correlation-Id: 155241ba-6da9-4438-e0d4-08dc91292701 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|82310400023|7416011|376011|36860700010|921017; X-Microsoft-Antispam-Message-Info: ddXNMXxIo9KbfPEYjlkvk8nHOpBn439qKmVZ9h1miqmVTBAhMrY3HYL3gA9Hor3A8zv900bgM+UyfhZm2CZGHRhYoPnE5xTL2paklMKHerHlsIxlWMXxwelAN+k3VVHVl/6/lCikx5xsFGddZla0AtZHdq+kA9WUffzw/1Qjh3Z85E3XFovFgnu4Jpnoz/KIs4j+tHJvkdQClmvPJ+U4NG4ps7YXOplX2+v1nQLGOWzFIeu8uZa/ha4z/4fSmhtR1GwAIJi9XH7abuTW2e30/JNoQHnbbBdILAz7KJJ7Q3dulFHph1eVDCka2g315c2m9B4O1iAQH36KQrYPfF7TUURf/AFBn+v0VUQLAFFHoPc8uj+M8E/gnrYvxU+PBVXGwXW4qMErcMQPtPaBqTkYggoI0wDJf+KtcHsIs1ocURWEjkWJVIAsODApGodjhGtWyoW8/e0cnsG1yHructVPoK5dlmWXy2ZXnsBtlGVIrAIBIQ2S5X2e9yDblISO+Ni5+YJ/AbZX5cld4ZZDQSrHH5OVgmGJqLr3CHPRY4viJFz7g1sDqW2ZqLRVnbPMTCNC09fdOkaEOR60KXRrS9gFqtwbHgIBg2Ski+/ytp/9PezQGnChvNCBqbbxeeddlujZUXpZOJzm1bPHyQw+O03fKXJxsvsFS1eDNuNdydWPXNPGD0m+Y5Wg3CQQS/PabEFUWbMUP+n+FJgfsKnORV1SFzGxsqaw3eB4U1aU1e7zZdhZOnuv6Ac2MlLRoOoMAzJ6sA9qq3WkI+NspVd1dj0UTIL6Iwt7RbwPcoXWDk8pmO5N9e42YLlSpE1vl0jnF9gvYvbixoQAynYtuBjK+QpLc9VMY/xCGzT1DMNJS+0DtETbUqcjG0ZTglyIpu8/U2UnPUoUGInMkBMoSxzhOc7G10OZX8I6qIEssGZkwJHG/iHZFFI1IL61bc54ZOnE9KvqXnW5FXVOX/PdfD/ylk3zRKU6Si8A/XW/Y73vNNyzPes3HVQUoRCDA42BskSxIjTEMnCu85xTpLwyzQrsaPYOzuQbS82be5m65y5/xVnCRUF0ldwYLW35FVub+bhJUwQqkr76EqLAeg/wPc7NKb7kr2cIw+/PEiend83dUBYC74wddmv4+72F1McOq40LKdXxd8hGp/tzVu6pirNTiST0fAJT4gf6k5kaPUF01LgZlP7F4cAvILkeJlCQBE/NopJ8vQ24LD27BnOIsMhVyzpUxe6Ur3PFq532pZCTljTNSaRTG8/MhFa77c6FgZvfrTcXii8yEhsxWvixrDM0lPLVnitejF7bLazZbf2CdSsMujf+c7iPZhaOrHwgvXw6Zrbqwv4+ADTYE1c7ZsQzajSBiTgovOVm/aAtGcwFFicO1GLb17aPHo8910OxQMRNoR7y2VXtN7ZDi0FODvcAAc3f7SAmu9sfa4Wr5rLICTEOhJM= 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:(13230037)(1800799021)(82310400023)(7416011)(376011)(36860700010)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:01:51.3263 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 155241ba-6da9-4438-e0d4-08dc91292701 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: BL6PEPF0001AB51.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9243 This patch is in preparation for addition of per-core energy counter support for AMD CPUs. Per-core energy counter PMU will need a separate cpumask. It seems like a better approach to add the cpumask inside the rapl_pmus struct, instead of creating another global cpumask variable for per-core PMU. This way, in future, if there is a need for a new PMU with a different scope (e.g. CCD), adding a new global cpumask variable won't be necessary. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index e5e878146542..be139e9f9ee0 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -119,6 +119,7 @@ struct rapl_pmu { struct rapl_pmus { struct pmu pmu; + cpumask_t cpumask; unsigned int nr_rapl_pmu; struct rapl_pmu *rapl_pmu[] __counted_by(nr_rapl_pmu); }; @@ -139,7 +140,6 @@ struct rapl_model { /* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly; static struct rapl_pmus *rapl_pmus; -static cpumask_t rapl_cpu_mask; static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; @@ -394,7 +394,7 @@ static void rapl_pmu_event_read(struct perf_event *event) static ssize_t rapl_get_attr_cpumask(struct device *dev, struct device_attribute *attr, char *buf) { - return cpumap_print_to_pagebuf(true, buf, &rapl_cpu_mask); + return cpumap_print_to_pagebuf(true, buf, &rapl_pmus->cpumask); } static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL); @@ -565,7 +565,7 @@ static int rapl_cpu_offline(unsigned int cpu) int target; /* Check if exiting cpu is used for collecting rapl events */ - if (!cpumask_test_and_clear_cpu(cpu, &rapl_cpu_mask)) + if (!cpumask_test_and_clear_cpu(cpu, &rapl_pmus->cpumask)) return 0; rapl_pmu->cpu = -1; @@ -574,7 +574,7 @@ static int rapl_cpu_offline(unsigned int cpu) /* Migrate rapl events to the new target */ if (target < nr_cpu_ids) { - cpumask_set_cpu(target, &rapl_cpu_mask); + cpumask_set_cpu(target, &rapl_pmus->cpumask); rapl_pmu->cpu = target; perf_pmu_migrate_context(rapl_pmu->pmu, cpu, target); } @@ -606,11 +606,11 @@ static int rapl_cpu_online(unsigned int cpu) * Check if there is an online cpu in the package which collects rapl * events already. */ - target = cpumask_any_and(&rapl_cpu_mask, rapl_pmu_cpumask); + target = cpumask_any_and(&rapl_pmus->cpumask, rapl_pmu_cpumask); if (target < nr_cpu_ids) return 0; - cpumask_set_cpu(cpu, &rapl_cpu_mask); + cpumask_set_cpu(cpu, &rapl_pmus->cpumask); rapl_pmu->cpu = cpu; return 0; } From patchwork Thu Jun 20 12:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705463 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2064.outbound.protection.outlook.com [40.107.93.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AE391AD9D8; Thu, 20 Jun 2024 13:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888541; cv=fail; b=rz5zyYkxkUdqZkK8AbC/NoLNgN+Ec+KUTz21vCOj74LhETjZrUmHgqTq9For9Hms3HRI4agsvLEg4RHMpDIvurrS2S1ruiQ1wv4ILCCDYXlEVuccmwLAqcGyjhWgPsx41N/nMjVeTXIbNOOIdwisKig/t20PLsmPHcFv8jomNPg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888541; c=relaxed/simple; bh=qS/Wq/wwRZfU17xl+lbRzk7z5HbMg+NLEVu+HvsuOXE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Vk2SVeEHYsHxPHdMnILrq+KFCo1d3BKVrlRd5sjVQLsOZ8vHXNLcK26PQfzQ/RuifqSaNdCXPNA7dca5SOsnB9DmlTjzUK69k+eEQ5T/oX4zRAfYo8j2xHgnn7En8Ole6sItPRdFyjiMGLxv6mVvHAI8GWEN62MVy7twyqJ1zE4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=GIpBb36t; arc=fail smtp.client-ip=40.107.93.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="GIpBb36t" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CxQqFYpE85i6fDbfikDNC8USIapFJYve1g42gZlBl2cPVDMbfodW9Spwdy9/gsef6UWiSM2kB7pRC+ks7QOf+KIYE/X2oPcbA72Se6PYD/H8CtkPY4KF6+9j0nX5fX/GjGhU0QZXzx4uTvMlir8NsU4r6LRgpoC9GGVhnvELLARbxtpd+0ogV63hzj6fTOiwUvbanjlwmT8U576u903HNByPpdn+fyNHERzmRFv0cxVVmure+z8hUGreUhD8nrPRdOHOBdlRwgurn1ARuMkr+/vLWqwWJEOp+bqHrn5XfV3soe8v27JzmxD64v0fq6Wk+Yvpe+JoDfHdrUJAjOmz5Q== 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=j6GYhfZK2/e8rYuOISt+j+ov/9zcEqHtJ6OJpZIqp0w=; b=T+c/J8X33mJT8mm6YPQc80ZBWdypdSgqPh0xxQRcd1kGinS1GWNQvMMA1s3Z2janC6Ss4dNkI+BIw9J93s41xOlbMPDkAXxd99TOufX2NBq7dfo4XulYSKDX33uzXO18vZ/dfdj4Op7ttqYpKYRW5mZiKGzfw/ZUaM3N4v5RmtjacaKhYvH84rM6MNj//UZ4OG6ZYLStmfZoqO4+ZInlWe51p9r8IVNCErn/7NgGK+3yXswi0LDuMjMFypvP894ZKCsRZRjBsajTKtkKMFbC5zqNyCZxpOXladuloTl0zk07WQ7jilqXjeFUpbz01nagjrAerVLutXCbJjQXMzvRuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=j6GYhfZK2/e8rYuOISt+j+ov/9zcEqHtJ6OJpZIqp0w=; b=GIpBb36t8NZK2rxDBinomaxu/ZwVSvYNxAGgqQgf59VI9GH7bZJ95ZdrxXsn3NPBQawFf/6j3xmP4Bhs4+LSHVOtDpQZzhXz+/4oa/OMOyfbk6D+FQdP2tQ05aypUWScXVIXgPy1ytwBH2QkpAn2kLtUDdJ4qrTmyELNVj7Cwcc= Received: from BL0PR0102CA0050.prod.exchangelabs.com (2603:10b6:208:25::27) by DS0PR12MB8453.namprd12.prod.outlook.com (2603:10b6:8:157::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.21; Thu, 20 Jun 2024 13:02:15 +0000 Received: from BL6PEPF0001AB4B.namprd04.prod.outlook.com (2603:10b6:208:25:cafe::d4) by BL0PR0102CA0050.outlook.office365.com (2603:10b6:208:25::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.34 via Frontend Transport; Thu, 20 Jun 2024 13:02:15 +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 BL6PEPF0001AB4B.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:02:15 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:02:03 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 5/9] perf/x86/rapl: Add wrapper for online/offline functions Date: Thu, 20 Jun 2024 12:56:59 +0000 Message-ID: <20240620125703.3297-6-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4B:EE_|DS0PR12MB8453:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f393b00-a11e-4085-c32d-08dc91293575 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|36860700010|82310400023|1800799021|921017; X-Microsoft-Antispam-Message-Info: 1UPhibH1E9egVayvbe1vGrpNUh8wtmdyKxhjxlRGDc4SRKabjGbbmBa+0Tu3O2n1dG3oHu8DRHQogPJQJ7ItaPV0WqNtSjIG0QI6Opre1QkAUXPVtmR9i0PCH5O6qs+xs5F1/x3ZOOvliXnKx7ejX2rYGy28Ugeo7g718VJ/oriDOZ43bEAPZe+gmVmRS39UGJ1JspzSXS1IdoLEmSja5cURA9YyKurgOaJf5AuHf66zJs+Unc6VjcMA2Kg2joW13OSVILl/oJoRpUOACbniezmAp01gtIgjHqEoX8QUkbQuz0j7Uzmq0DDfXVdP0iruOxYjZb9NjwZQuMouIcOT6Y1MG640u4fkd/oBq4x0hSlnB1PmCO5Y5N8y6mn8ACS3BNTReZqpByUUwhw6vWRD1xjIx9iUGqhPpKHoMfRQ9NgFnixwpiChyOMX4jZBn2DnS4LF1njbep3N3TnQpDOyGgc06u9aDXGP8jeqwI7kr2RnxxTEUofqHccYHzqCxmI0QACEVx4Ibw7v4soz6VHjQPeVrgzsFHm/0CvS3SDoYeYZNpCKsTNS+ZK6lCM1kpJGRj4QAfZd9DKfBlshcFqPmdzYeZrZiu68GHVg8EanJiQtpVF4mWtA7MKTrzfg4Qz1bagOnH6DRwPoUTwQleQ9x7ATcY43JnYt10IOzPqe2oX8ZVo7E04k5dYKAwrFXgCOBkAJrchft5/bqxx5y1IHX/F/WPfyGhC0OPlCoqWu2TjCHO6Uc4yBacaGx5Ra2j/ZZ+Qo546xIYYQkVRavdSSaeZTLiVwHd0pk38Q7wV0nOdUI1BpdrPG9jmaPRrmQ6DbdtSpNF6yBqFYuQ+CJi0yiKKBuvFzAxZzCJ/fbegg4R97BWju5gWQSUu9heL/bMBQKSXZqNIMv+3KW51UiaEnX89f14rFY7X8pha6By3rAndxvdgnV2IyeBYig7CeyjFerUWwd2Gp5MIjNNoQohu03KCTwKpbxMY8OysW9um/b9HsaFXt0op5a7r/GsgxAP41UwaNU2Y3HZPR8L9C6uPw23Z3HTeX9wATfl4PbOjwWWgDdtvBSje71Y0AYDy4JwZL2jSMG3I8y0lJ2x3j8m4RAjlciA/3bO5hboW9xvneXwzJ7ocd/xqk+b+2vJgoq3eusfkctithXOwDCLnBZ3TL5bl1/Ji+U0mcH2/ZlNsNlQFJ/K27AUk1VTy0o7rJ6xyZAvNxx124mjXQfjI7goSlm+UGUD7n/beFwXdD4G2FYJUIcXns0Ab+rYkl7CMtu9piIk4dNfG1UyU338lTWqdu9wl35xBA8/U1fGgRIZa9suOsYUnRieWSN352KRNszcaaKsp0MMjh/govHB+SlrfJM6idG/udxUyYfjzOlIvSR6ltJ/Q9tGDbcuiZFo2lD59kwKRsII5DSLVvFszKdx8Kd5+XBLAr9xRdgkbVaByKKoo= 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:(13230037)(376011)(7416011)(36860700010)(82310400023)(1800799021)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:02:15.5583 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f393b00-a11e-4085-c32d-08dc91293575 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: BL6PEPF0001AB4B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8453 This is in preparation for the addition of per-core RAPL counter support for AMD CPUs. The CPU online and offline functions will need to handle the setting up and migration of the new per-core PMU as well. The wrapper functions added below will make it easier to pass the corresponding args for both the PMUs. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index be139e9f9ee0..70c7b35fb4d2 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -558,10 +558,10 @@ static struct perf_msr amd_rapl_msrs[] = { [PERF_RAPL_PSYS] = { 0, &rapl_events_psys_group, NULL, false, 0 }, }; -static int rapl_cpu_offline(unsigned int cpu) +static int __rapl_cpu_offline(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_idx, + const struct cpumask *event_cpumask, unsigned int cpu) { - const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); - struct rapl_pmu *rapl_pmu = cpu_to_rapl_pmu(cpu); + struct rapl_pmu *rapl_pmu = rapl_pmus->rapl_pmu[rapl_pmu_idx]; int target; /* Check if exiting cpu is used for collecting rapl events */ @@ -570,7 +570,7 @@ static int rapl_cpu_offline(unsigned int cpu) rapl_pmu->cpu = -1; /* Find a new cpu to collect rapl events */ - target = cpumask_any_but(rapl_pmu_cpumask, cpu); + target = cpumask_any_but(event_cpumask, cpu); /* Migrate rapl events to the new target */ if (target < nr_cpu_ids) { @@ -581,11 +581,16 @@ static int rapl_cpu_offline(unsigned int cpu) return 0; } -static int rapl_cpu_online(unsigned int cpu) +static int rapl_cpu_offline(unsigned int cpu) { - unsigned int rapl_pmu_idx = get_rapl_pmu_idx(cpu); - const struct cpumask *rapl_pmu_cpumask = get_rapl_pmu_cpumask(cpu); - struct rapl_pmu *rapl_pmu = cpu_to_rapl_pmu(cpu); + return __rapl_cpu_offline(rapl_pmus, get_rapl_pmu_idx(cpu), + get_rapl_pmu_cpumask(cpu), cpu); +} + +static int __rapl_cpu_online(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_idx, + const struct cpumask *event_cpumask, unsigned int cpu) +{ + struct rapl_pmu *rapl_pmu = rapl_pmus->rapl_pmu[rapl_pmu_idx]; int target; if (!rapl_pmu) { @@ -606,7 +611,7 @@ static int rapl_cpu_online(unsigned int cpu) * Check if there is an online cpu in the package which collects rapl * events already. */ - target = cpumask_any_and(&rapl_pmus->cpumask, rapl_pmu_cpumask); + target = cpumask_any_and(&rapl_pmus->cpumask, event_cpumask); if (target < nr_cpu_ids) return 0; @@ -615,6 +620,13 @@ static int rapl_cpu_online(unsigned int cpu) return 0; } +static int rapl_cpu_online(unsigned int cpu) +{ + return __rapl_cpu_online(rapl_pmus, get_rapl_pmu_idx(cpu), + get_rapl_pmu_cpumask(cpu), cpu); +} + + static int rapl_check_hw_unit(void) { u64 msr_rapl_power_unit_bits; From patchwork Thu Jun 20 12:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705464 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2064.outbound.protection.outlook.com [40.107.220.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A83C1AD9D6; Thu, 20 Jun 2024 13:02:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888562; cv=fail; b=OiQ1TsHlqMaxnfUmS9Vb5lVSCSDxxkhAt8hMOt6tjsVjZZ8c5zafJDr4VW/nd6GxzgKXAVePqFm14WnJMvacGlMwn3vi1a85y/t2efjiwnS6XVPMUpcHN9+GKxT8kLPf2ZL6pcF0axvLcB645QVaVuPkrMg1DN071akRSK3mBrs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888562; c=relaxed/simple; bh=SevruLCexV627iM6Dl8XSaoopRtrEYLT3wp2+/RPnLw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m85dpVtsnhBwv7pHn0xJlOaQY36DV1npAjM6WgR6SapAtQKSJpUyewmflY0Oh2zVlF1En9Y4VWkpbaG6CdnkmnU+diMWDl3NdlEUqW8XLDPvvctENHf3ghOD7TjNbkz1s2rKOWKlTrzW/fSmrNgtbft6jI64WNzwERjh1ZMr1Lg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=yN1D4Uzz; arc=fail smtp.client-ip=40.107.220.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="yN1D4Uzz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SssyQWqBlS6Vim7bhm4kOwWJC8mLw13ZGkjQeVDxFOE6VxdihNGsOZUnkhiLUVhPT/XKjQTmpACbXy/5wSHpHO2UYnIR58tBCZpEIWJhuDdzYQbBoLMm9U+TzHmJvLLSDDJS9abdrWIuw2q26sSVGiNSczgSCauZBTFleU8tQ0of8I4lE0QbX0UmJwvl8Y5sAoqEJmwO0NJNfpVHaDN6Ebv2loiwMOr65IWKrXNuciL+k2uBOg/HlITmjpGOC4zZHqWcyQpKA0uF95Q8GPAhwdcNMAn54f1KWH97qMk/w/i/QkDiSkD10lA5hC2TcMFeJmsFqhV450O+t5JtUuadxA== 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=ecZ6mfsQyMQekhKSwNggBHbozRpNVr37hIhIwLMyQH0=; b=UC5Qo6Xr8cogz9K/ut6mh7QyHldBnXmd9vY6BUoaZd9bdqdca6M2txu89Cei7Zt1UM3We4pbUsM0+xPsQyJOnSn/mBg6oXbfwVwFV6lPvek/QcHmTn34gxyEcQCanX7IYYWMqu3J4WHZBIHGTcEdoMGb4qmnrLZSbVCHMkGtFXtSiWfbLZ3C7csnqQHdOMtwXp+82V0CEyXY/J1Q3hzFgmWawbyOLVnIU6wxkPpMu8mZwtYq+1basO8EHsGrsNXj8BC499IGwppRP/o8d7vR2H1/NRAxNubBdFgiQ8tEcJUf6iiPzoUvuEJ9gshIa6w1ayZcbYwhaLpGSKLHCOXGuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=ecZ6mfsQyMQekhKSwNggBHbozRpNVr37hIhIwLMyQH0=; b=yN1D4Uzz62u1x6pnHLdHJqUBvQpk7GQCjEMIYgtmVqnCp4aHBml7o4GXHuaf1h+T9Z/NkPrRfTJhXwhME/VJi9jux/bAiANMWjvtfCHIUoyjXkQy7SQtz7mmnKMnWFXOngLJCmTDuG84GJC0FG5+lQTxjEpxQYVG3/YXgIMyeUg= Received: from BL0PR0102CA0068.prod.exchangelabs.com (2603:10b6:208:25::45) by MN0PR12MB5931.namprd12.prod.outlook.com (2603:10b6:208:37e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Thu, 20 Jun 2024 13:02:32 +0000 Received: from BL6PEPF0001AB4B.namprd04.prod.outlook.com (2603:10b6:208:25:cafe::c) by BL0PR0102CA0068.outlook.office365.com (2603:10b6:208:25::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 13:02:32 +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 BL6PEPF0001AB4B.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:02:32 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:02:23 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 6/9] perf/x86/rapl: Add an argument to the cleanup and init functions Date: Thu, 20 Jun 2024 12:57:00 +0000 Message-ID: <20240620125703.3297-7-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4B:EE_|MN0PR12MB5931:EE_ X-MS-Office365-Filtering-Correlation-Id: 478386b2-bd6b-4728-bf9b-08dc91293f78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|82310400023|1800799021|36860700010|7416011|376011|921017; X-Microsoft-Antispam-Message-Info: /9urNv/0xCbRdfXnhIwnV2ddLFi/XPGC1HVsgPv/+DeuOXsXgVEV69zBWgR34HC/Rp/iOLj8ouGgqy4XgH0DK0JW5Tq6JvthLjz4fa5jGOaTgNqxvbadXAC5WjYRJohPeMeG4pHbIkcTJhoCk8efQD+cJdU/C0sODM5lvBF9GcsXr8hwd/FYWzU6kSgmrw5/yMvkSujQ6Wd3b4HOzZmTpsB0aD2JYCgxFk9LdfDL5ao5AfYzy2LtVbM75a5AoYuqFbOYWyV+l/DtDFm/kHMC4IqEoYDDrDetI4QS4VCcYxLn2IkbNOJb2luEXsOioganrjqWvtR2UmQDfJF4oZNOJcSj7vlykeVTObQKZBrziBtdJk3t2LmitUd/0oT1jf4Gsq9yayM6d/dshVZ9eqp9sinHxiodOdqtVEiplVuxV3PgGnsrTNIiWc8eAcUZuWAws6aX6Fsv2sHQ1oj3n9Se5VMGwSyV8vJd5TA+TIseowzdMNeeFPESeoKJEQA1wa9H2u5jeEZwkulMGFmPEothg+mnucC+WRXLwb2dTalSPU6Z0B6keiBXqLu25dSr1e7+pw+nKnmCk4q5ShG3WWuBxvDveC6ZztJgSpBE0IhfdILmiNLIhWBLSZvRm3yTzK6oHQlpxiCQgDPYE8ZvDtkKeeSyZ+b/D8zus4zPt96pwZO9xxZUotJTMYnWXNknYQzF2qq2Z1Ri9Lz38PAMRyDVyqPnD+QBK2S8DmpLSlfUfTNl2oWs0HxElEDOTkM29+hi3/Bf59IkfBXJ5v431fACCDrpc7tshJn1/Z+9S1sKDQ8iRmPtnCLTlrwGYAJsDdkw4ImZ2p1N2PPU+abUS3SGd/GBvFqd2aZR1jjKY4y+hL9mBbAa8vlvnyQ5mdLwqlIZsSC5rTlXlmEJRarVdPkleiQopzkWORnEnDP+5dCUnaCc7QotTznXbyhuyyFYpPcRkouufHDoLuUmZ525N7EZpVMIkwnqTvbXAYyOsT//KcNMLNTWmzlXSCVW1rynETQiF0tb1lqHXXJMKXokWoGPu8hzBM+UbH/Gd/91UPAyK4GbJ7hTPx0uQi8NP7jOMTGiSI5kgfhqCeUT/3JrVfWFVtKDJHoAKdkajPjepHAiXhcymiOyto4PbZgQpwTNCADM1yX5fx+xtmA+moX/TIuDKPO2Ct2vXAdPxWKe9RxzTvG51vvxv4ORGma2k5TyvDtODo+QUK1TblMkpUx9AM4CpqqrAx7MwVj4ihMCYC5D/OjOCiRyTd0pqjOCQz/IowGKhliqMPpa4eYQrE9RIWwESZ/onwtHYh+NKbQFjcYpJTzFnF/PtY1HwfUCnc06AF8i1eRtJF7QPlWTm9IljPh14sOLngb/uju+SNGq1wX0vorVk4xvHa5WsPZ5U4ol3MJrqUU4sH4xkcW+4DE0SkZJbiB4eL8JWOMXTh6zWXk0tvA= 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:(13230037)(82310400023)(1800799021)(36860700010)(7416011)(376011)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:02:32.2613 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 478386b2-bd6b-4728-bf9b-08dc91293f78 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: BL6PEPF0001AB4B.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5931 Prep for per-core RAPL PMU addition. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 70c7b35fb4d2..f815c60ec551 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -687,7 +687,7 @@ static void __init rapl_advertise(void) } } -static void cleanup_rapl_pmus(void) +static void cleanup_rapl_pmus(struct rapl_pmus *rapl_pmus) { int i; @@ -705,8 +705,10 @@ static const struct attribute_group *rapl_attr_update[] = { NULL, }; -static int __init init_rapl_pmus(void) +static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr) { + struct rapl_pmus *rapl_pmus; + int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); if (rapl_pmu_is_pkg_scope()) @@ -728,6 +730,9 @@ static int __init init_rapl_pmus(void) rapl_pmus->pmu.read = rapl_pmu_event_read; rapl_pmus->pmu.module = THIS_MODULE; rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE; + + *rapl_pmus_ptr = rapl_pmus; + return 0; } @@ -869,7 +874,7 @@ static int __init rapl_pmu_init(void) if (ret) return ret; - ret = init_rapl_pmus(); + ret = init_rapl_pmus(&rapl_pmus); if (ret) return ret; @@ -893,7 +898,7 @@ static int __init rapl_pmu_init(void) cpuhp_remove_state(CPUHP_AP_PERF_X86_RAPL_ONLINE); out: pr_warn("Initialization failed (%d), disabled\n", ret); - cleanup_rapl_pmus(); + cleanup_rapl_pmus(rapl_pmus); return ret; } module_init(rapl_pmu_init); @@ -902,6 +907,6 @@ static void __exit intel_rapl_exit(void) { cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE); perf_pmu_unregister(&rapl_pmus->pmu); - cleanup_rapl_pmus(); + cleanup_rapl_pmus(rapl_pmus); } module_exit(intel_rapl_exit); From patchwork Thu Jun 20 12:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705465 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060.outbound.protection.outlook.com [40.107.244.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBC161B1519; Thu, 20 Jun 2024 13:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888576; cv=fail; b=QYsx3NYRE4x0w225Vb44JFo5pcXU4zA16dy6SPUrGPIXQbSLK0XEXEDTrXVke96W/+IG8L+CLbW1b1COLbCday8MclMNWkpw/rOktkla7HOkHJKvD5e3QdxOOvOzyY9XdOCqfsRT2DNVWlS2grIuHtZrkYwXWWhgYnsCG0LyGHA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888576; c=relaxed/simple; bh=f51elEAnnGY8jcyDm2clri5C8DYL0hi49mwoDWpy6C4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=quO7YvABiEYcP6/JgjEygP3PyqqznbJcezBaDUHkqLgU6YxQDKw5RHOOI10L7x0ZEfi6lj6K8YD8ce/JcHPB0O0qPeyfLn5PNar6BCfBaF9FjkGkM8MK4tCmWn+dGbNss2vFUloafrskoeO6eMswtaCv2bChppP3XFDzCYTrCjU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=tUEjaoVt; arc=fail smtp.client-ip=40.107.244.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="tUEjaoVt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IPKEd7nut0DX0tdxA/8azj+D8MRKYRVSyAIzx7ILhTS9gIv4L6zYGENaBBzTCy8686lZ9UfF6nCaE8V9BuQUHeyvbbehcNaJ1Bq/h31eLiKpeQuJkZJRiPPO8+QR4kb4loRpO1SnN3bkJ7Q8CdB4kFbiibSyf4Op86PmHHWcaEx9aAevUue7ZAj8eGyeD1kTUvDyP64ROKi9EBkr1SLSleWY+l94OF/2u8/uE8j2KQHiSqnvkENz7ROvOr8ngKAo89cgoq+42wdvKBRpBeiu9k52/q3dblAh0DTNqWlch1UlG132Ih5crXNi1AbJJwSCrBoobvak+bNIKRQ0ojbxQA== 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=8mpl5fVfYKHno4hVEKboGWqoDffB6RRgOtt9zFqYIyY=; b=BrAh8yyFPrXNp6siT3YQV58IkgvgwV1ae2M6budUYtVnsLuAwcd9NKIgtuHcGAHMuWfGzRK/c31yQPoflJMWy0GtMQ7LFWMcXlT2qKVR4n04sCb+/NWNRDryYDLo5V0cfTkyKG19Bs6rT/+DIX3YgSBNtF/iSadbpddJVF95oongUdl8idB93+hZnPXnDkVURAYK4xH6TJTsEx3jWQmY0a4JtuznPV9fzo35cqicrjdyHEtlNhMmBc5ITalRVtMSHPWVIhQmXvOfgUYsNALyRf8y1ezPLGeFXaYIj2P93AiHEOUY3ji7eH1Lf+OhXFtH++z5S5W+SxGO2uSEJTNzFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=8mpl5fVfYKHno4hVEKboGWqoDffB6RRgOtt9zFqYIyY=; b=tUEjaoVtiDCf22IjlTCs+2FBJu80Nq86rG7W+SRU/Vlg8TvpECYJVgKbVsLoBVbUrvWOmJFIADMBCMaQ75HiH5hava8vhledTLYxDgh6EkZOqpyOxI4KcP9b8BfgL+D9dzbA3qDPfRKjOnHZ7iz3WWsWMoWK7GHD9xUTx2jNEn4= Received: from MN2PR14CA0025.namprd14.prod.outlook.com (2603:10b6:208:23e::30) by BY5PR12MB4177.namprd12.prod.outlook.com (2603:10b6:a03:201::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Thu, 20 Jun 2024 13:02:51 +0000 Received: from BL6PEPF0001AB50.namprd04.prod.outlook.com (2603:10b6:208:23e:cafe::68) by MN2PR14CA0025.outlook.office365.com (2603:10b6:208:23e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 13:02:50 +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 BL6PEPF0001AB50.mail.protection.outlook.com (10.167.242.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:02:50 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:02:43 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 7/9] perf/x86/rapl: Modify the generic variable names to *_pkg* Date: Thu, 20 Jun 2024 12:57:01 +0000 Message-ID: <20240620125703.3297-8-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB50:EE_|BY5PR12MB4177:EE_ X-MS-Office365-Filtering-Correlation-Id: 8014b579-6a46-4115-4d97-08dc91294a75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|1800799021|82310400023|7416011|376011|36860700010|921017; X-Microsoft-Antispam-Message-Info: mGA3dx2K25ink7GvJN7IGDacM7enbUAlx4WaFC5UhEQVC9cL6LGg81PJa0YV5rGi5RpcZ0n8JNF6q5XclQphQRRli3xNbH0jhpoiBsDCFgjuF86TkkLRpo84ZFizrFgTxmhubX99x+1ac50CJBnw5ZVOP4gWwWNDkc2sFJ1gTQnCpCvHvBRprmR6dZClDvARjv8MGrXXd/y3dpWucT4igap36dfrgxjpTRWxZyI0F5VSvmXoi9FXbg8XltJhq7iXmv2PuhWqNl9NP4X5Iy4Lq2Y2WJPpZRM2zzCL+YPOS5j1i2J9yLHO2UW62RooxWvjSPyGz0DeX9OoJaDOfriVKLUpVL3JhQY7bKqRwuDPnV0JzlS8PzDu/7EkIYRxbGJQ04NZygJxnEL5yEO7P74Y5naS3cr3sk/lQJoYSlxDf2/+1m1RYxCdopatiAMmQpkJuZRzwGgFv6CN1NnO1bUvVbeH7KPFQOyQsCxI6QvMtGBUd4xCw0rajWb6OKDH1PJp8rh+hRNWZc35wcuIeALYOrFPYMvpnqOx2+UqDV+OORZqCS6Jnl1u/x6SIHd7fOXSPLphrMPn8e2emcm3a9jjxoKarjkzKyPA/9fzcqeamoDFlt8au0TwC/KX8vaqSMLbg3bZbs9jPmwpiYGP2pM22Egu5Sz1uViJUllDKdW/+SfdP/5Xyq38mlem0SPb8sQgfuR0CNVsqdGL//9KgSlfbo+jR7AIErFONuD1rsLIwM2OQya0GgW/IYRJat25N33kS7aGFwmodghzUBQhc28RrS7WDQj7kFQKRf/XVPxTLJmLvjE5f5VmwY3qvT2iWu80ut9GV4ItvMhkLu8vnbQKVi3T9jhMw7E/i7s4qEWsYJ9jriYTRW01rpaK/eOlD+fxpC91+3MWnYGdsUoWM2Ux9yrnJs05Gu3FkLdFYvDaonokUl1g+mRAEf4HnsInei1fzIxLavDnkBV0Av14EQ3nXmqLP2mNVZoaolt/tjvO0jrWNFNq/9WDimt5vSGkM1Vj9nYz5mwRBeAHuzzqvx1sDMSHTAtJlPfljLGgHMcDP12ZuOHe0pGVLKJYCZz7j5IfNN4C5D/q4c+9BX7g6aaXeX+o4Nuh9YEWOcZPROG7f/rtH0+Yura+sYCjp5s1pf8u9kGzb9TEySqyFcDEciqC2sJwm2Ed9h/7I1hzTihPUBEP+haNzkyvdcvh/vxF53UFR00TZRKCcNvHATtjlMz1uHoHuYxRSY4Z+fbGj0Icql13sno0qm/I9YEh1QE66jCLS24p6aaERPE3DeutUpt4PLbptNOCwyohdrLtPmJOZBp9zXuiZ4v6+dJLgrX2PSVjGwBGmazqFZO316bIKm0un2QlB/xLadaWAHse6erxgYrpaAasklnHLSJRgaDbpEs/9ggajX2tBJpXUkMTqTld0N+HftSWF32LPtmiIGeCJwE= 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:(13230037)(1800799021)(82310400023)(7416011)(376011)(36860700010)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:02:50.8031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8014b579-6a46-4115-4d97-08dc91294a75 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: BL6PEPF0001AB50.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4177 Prep for addition of power_per_core PMU to handle core scope energy consumption for AMD CPUs. Replace the generic names with *_pkg*, to differentiate between the scopes of the two different PMUs and their variables. No functional change. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 83 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index f815c60ec551..b03b044a390f 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -70,18 +70,18 @@ MODULE_LICENSE("GPL"); /* * RAPL energy status counters */ -enum perf_rapl_events { +enum perf_rapl_pkg_events { PERF_RAPL_PP0 = 0, /* all cores */ PERF_RAPL_PKG, /* entire package */ PERF_RAPL_RAM, /* DRAM */ PERF_RAPL_PP1, /* gpu */ PERF_RAPL_PSYS, /* psys */ - PERF_RAPL_MAX, - NR_RAPL_DOMAINS = PERF_RAPL_MAX, + PERF_RAPL_PKG_EVENTS_MAX, + NR_RAPL_PKG_DOMAINS = PERF_RAPL_PKG_EVENTS_MAX, }; -static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { +static const char *const rapl_pkg_domain_names[NR_RAPL_PKG_DOMAINS] __initconst = { "pp0-core", "package", "dram", @@ -132,15 +132,15 @@ enum rapl_unit_quirk { struct rapl_model { struct perf_msr *rapl_msrs; - unsigned long events; + unsigned long pkg_events; unsigned int msr_power_unit; enum rapl_unit_quirk unit_quirk; }; /* 1/2^hw_unit Joule */ -static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly; -static struct rapl_pmus *rapl_pmus; -static unsigned int rapl_cntr_mask; +static int rapl_hw_unit[NR_RAPL_PKG_DOMAINS] __read_mostly; +static struct rapl_pmus *rapl_pmus_pkg; +static unsigned int rapl_pkg_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; static struct rapl_model *rapl_model; @@ -165,7 +165,8 @@ static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) * The unsigned check also catches the '-1' return value for non * existent mappings in the topology map. */ - return rapl_pmu_idx < rapl_pmus->nr_rapl_pmu ? rapl_pmus->rapl_pmu[rapl_pmu_idx] : NULL; + return rapl_pmu_idx < rapl_pmus_pkg->nr_rapl_pmu ? + rapl_pmus_pkg->rapl_pmu[rapl_pmu_idx] : NULL; } static inline u64 rapl_read_counter(struct perf_event *event) @@ -177,7 +178,7 @@ static inline u64 rapl_read_counter(struct perf_event *event) static inline u64 rapl_scale(u64 v, int cfg) { - if (cfg > NR_RAPL_DOMAINS) { + if (cfg > NR_RAPL_PKG_DOMAINS) { pr_warn("Invalid domain %d, failed to scale data\n", cfg); return v; } @@ -347,7 +348,7 @@ static int rapl_pmu_event_init(struct perf_event *event) struct rapl_pmu *rapl_pmu; /* only look at RAPL events */ - if (event->attr.type != rapl_pmus->pmu.type) + if (event->attr.type != rapl_pmus_pkg->pmu.type) return -ENOENT; /* check only supported bits are set */ @@ -359,14 +360,14 @@ static int rapl_pmu_event_init(struct perf_event *event) event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG; - if (!cfg || cfg >= NR_RAPL_DOMAINS + 1) + if (!cfg || cfg >= NR_RAPL_PKG_DOMAINS + 1) return -EINVAL; - cfg = array_index_nospec((long)cfg, NR_RAPL_DOMAINS + 1); + cfg = array_index_nospec((long)cfg, NR_RAPL_PKG_DOMAINS + 1); bit = cfg - 1; /* check event supported */ - if (!(rapl_cntr_mask & (1 << bit))) + if (!(rapl_pkg_cntr_mask & (1 << bit))) return -EINVAL; /* unsupported modes and filters */ @@ -394,7 +395,7 @@ static void rapl_pmu_event_read(struct perf_event *event) static ssize_t rapl_get_attr_cpumask(struct device *dev, struct device_attribute *attr, char *buf) { - return cpumap_print_to_pagebuf(true, buf, &rapl_pmus->cpumask); + return cpumap_print_to_pagebuf(true, buf, &rapl_pmus_pkg->cpumask); } static DEVICE_ATTR(cpumask, S_IRUGO, rapl_get_attr_cpumask, NULL); @@ -546,11 +547,11 @@ static struct perf_msr intel_rapl_spr_msrs[] = { }; /* - * Force to PERF_RAPL_MAX size due to: - * - perf_msr_probe(PERF_RAPL_MAX) + * Force to PERF_RAPL_PKG_EVENTS_MAX size due to: + * - perf_msr_probe(PERF_RAPL_PKG_EVENTS_MAX) * - want to use same event codes across both architectures */ -static struct perf_msr amd_rapl_msrs[] = { +static struct perf_msr amd_rapl_pkg_msrs[] = { [PERF_RAPL_PP0] = { 0, &rapl_events_cores_group, NULL, false, 0 }, [PERF_RAPL_PKG] = { MSR_AMD_PKG_ENERGY_STATUS, &rapl_events_pkg_group, test_msr, false, RAPL_MSR_MASK }, [PERF_RAPL_RAM] = { 0, &rapl_events_ram_group, NULL, false, 0 }, @@ -583,7 +584,7 @@ static int __rapl_cpu_offline(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu static int rapl_cpu_offline(unsigned int cpu) { - return __rapl_cpu_offline(rapl_pmus, get_rapl_pmu_idx(cpu), + return __rapl_cpu_offline(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), get_rapl_pmu_cpumask(cpu), cpu); } @@ -622,7 +623,7 @@ static int __rapl_cpu_online(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_ static int rapl_cpu_online(unsigned int cpu) { - return __rapl_cpu_online(rapl_pmus, get_rapl_pmu_idx(cpu), + return __rapl_cpu_online(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), get_rapl_pmu_cpumask(cpu), cpu); } @@ -635,7 +636,7 @@ static int rapl_check_hw_unit(void) /* protect rdmsrl() to handle virtualization */ if (rdmsrl_safe(rapl_model->msr_power_unit, &msr_rapl_power_unit_bits)) return -1; - for (i = 0; i < NR_RAPL_DOMAINS; i++) + for (i = 0; i < NR_RAPL_PKG_DOMAINS; i++) rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL; switch (rapl_model->unit_quirk) { @@ -677,12 +678,12 @@ static void __init rapl_advertise(void) int i; pr_info("API unit is 2^-32 Joules, %d fixed counters, %llu ms ovfl timer\n", - hweight32(rapl_cntr_mask), rapl_timer_ms); + hweight32(rapl_pkg_cntr_mask), rapl_timer_ms); - for (i = 0; i < NR_RAPL_DOMAINS; i++) { - if (rapl_cntr_mask & (1 << i)) { + for (i = 0; i < NR_RAPL_PKG_DOMAINS; i++) { + if (rapl_pkg_cntr_mask & (1 << i)) { pr_info("hw unit of domain %s 2^-%d Joules\n", - rapl_domain_names[i], rapl_hw_unit[i]); + rapl_pkg_domain_names[i], rapl_hw_unit[i]); } } } @@ -737,7 +738,7 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr) } static struct rapl_model model_snb = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_PP1), .msr_power_unit = MSR_RAPL_POWER_UNIT, @@ -745,7 +746,7 @@ static struct rapl_model model_snb = { }; static struct rapl_model model_snbep = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .msr_power_unit = MSR_RAPL_POWER_UNIT, @@ -753,7 +754,7 @@ static struct rapl_model model_snbep = { }; static struct rapl_model model_hsw = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM) | BIT(PERF_RAPL_PP1), @@ -762,7 +763,7 @@ static struct rapl_model model_hsw = { }; static struct rapl_model model_hsx = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW, @@ -771,7 +772,7 @@ static struct rapl_model model_hsx = { }; static struct rapl_model model_knl = { - .events = BIT(PERF_RAPL_PKG) | + .pkg_events = BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW, .msr_power_unit = MSR_RAPL_POWER_UNIT, @@ -779,7 +780,7 @@ static struct rapl_model model_knl = { }; static struct rapl_model model_skl = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM) | BIT(PERF_RAPL_PP1) | @@ -789,7 +790,7 @@ static struct rapl_model model_skl = { }; static struct rapl_model model_spr = { - .events = BIT(PERF_RAPL_PP0) | + .pkg_events = BIT(PERF_RAPL_PP0) | BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM) | BIT(PERF_RAPL_PSYS), @@ -799,9 +800,9 @@ static struct rapl_model model_spr = { }; static struct rapl_model model_amd_hygon = { - .events = BIT(PERF_RAPL_PKG), + .pkg_events = BIT(PERF_RAPL_PKG), .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT, - .rapl_msrs = amd_rapl_msrs, + .rapl_msrs = amd_rapl_pkg_msrs, }; static const struct x86_cpu_id rapl_model_match[] __initconst = { @@ -867,14 +868,14 @@ static int __init rapl_pmu_init(void) rapl_msrs = rapl_model->rapl_msrs; - rapl_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_MAX, - false, (void *) &rapl_model->events); + rapl_pkg_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_PKG_EVENTS_MAX, + false, (void *) &rapl_model->pkg_events); ret = rapl_check_hw_unit(); if (ret) return ret; - ret = init_rapl_pmus(&rapl_pmus); + ret = init_rapl_pmus(&rapl_pmus_pkg); if (ret) return ret; @@ -887,7 +888,7 @@ static int __init rapl_pmu_init(void) if (ret) goto out; - ret = perf_pmu_register(&rapl_pmus->pmu, "power", -1); + ret = perf_pmu_register(&rapl_pmus_pkg->pmu, "power", -1); if (ret) goto out1; @@ -898,7 +899,7 @@ static int __init rapl_pmu_init(void) cpuhp_remove_state(CPUHP_AP_PERF_X86_RAPL_ONLINE); out: pr_warn("Initialization failed (%d), disabled\n", ret); - cleanup_rapl_pmus(rapl_pmus); + cleanup_rapl_pmus(rapl_pmus_pkg); return ret; } module_init(rapl_pmu_init); @@ -906,7 +907,7 @@ module_init(rapl_pmu_init); static void __exit intel_rapl_exit(void) { cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE); - perf_pmu_unregister(&rapl_pmus->pmu); - cleanup_rapl_pmus(rapl_pmus); + perf_pmu_unregister(&rapl_pmus_pkg->pmu); + cleanup_rapl_pmus(rapl_pmus_pkg); } module_exit(intel_rapl_exit); From patchwork Thu Jun 20 12:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705466 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2073.outbound.protection.outlook.com [40.107.237.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 238DC1AD9E6; Thu, 20 Jun 2024 13:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888595; cv=fail; b=WTsK45UEWfylUOqGKGAzUIszwBfD9jwOYMGFx2E/XSIRhPpLTJBc4Mp5J10JT5COltaJ0Rnpl/w+AdZeloW2KmeD6Sfj1i3MZIHC5CkoCfdnSdrNN66MUemRfEq795giozWtorAjCcdy1bXYv13flvFzZBGzpPh4I4uunKolzkg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888595; c=relaxed/simple; bh=r3KZn4cY29i3ZVT8o0x7Etz+i2GyJ3TuDpeR2bPZpxY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DQ4dtVSXmv8YZsUr3DNsVnCcNf9PdpjjBzINTCW75rhdxx62Tyhj3lBd9W7NsvzIaF1HVFSOc8X7xmVA8v3W4TgJ0H3kvNzFidOpRSDLR+59Eolsg7yVlVmoJfIax/6HKWCxS4yBxVRoYKjIruZKGzMWoZ4Sjw+LcdFPjjU49WA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=kiZhScS/; arc=fail smtp.client-ip=40.107.237.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="kiZhScS/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gVDtG5zhbnuuiTqxUPH2CRDqqSYxX3r4mbfHoEzgPhIZyYASNqcdVsKFNZO7tMZnDsZSce3XIoaW0dWDyMt5rYT7a0OsM0giPXL98bqXS8tRrhc74cC0KiyPs0mYcYr3De4VBBsQRCpDgsHvRJDjj93PzBFRV/wb9xHZZi7pyW+xkscpVcrqoh0bBAryNKDIYciQ1N01TWNuRMyAVrzDt7eUlKxlajcByG0ggkFoHAVVRFscjT5zRdIT9xGN1C9i7ZlWOrHst4EDtWkBnYGI8iDO1IT54L4soyz9kqezC0azOsWksbJI0D35kxhYxRdzVaVvc0nYz6lM4hT6C76kcQ== 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=EJw2vpL4ySk0o0rEFGGvb5MNBmpk6BRClOy53vqQOIY=; b=V2MjCrIIuUNLOr653IGxT3696NlvvF7FHcdIjDrE3sVzLbaXzPWJVFfNXTInzx1Go6xoJ3yMkmVMabBoj59P9YchB/+ZKvYxHr5gpT1FlzagttLeUjKKiqmkusOqyecH+H1dTZAa18gSzhf+2BEh5TqQ3PiaOqo/7gfy9w0dlTdIA+3Z9rbTgoYw9RyLkFI0AbBowDMJhskYu8ZqhgVROKuYBVPLkPZ2sOwN0G31UPzAKkqv2jXnfh8h6eVHIdE2uZ/c/+BfZT5qGavYkobR7QC52BqpUZftCGo81pMzxG7zPTBRyVF6svXjoznQhMYEJhfeqhNxKlwTjkQZnb7ltw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=EJw2vpL4ySk0o0rEFGGvb5MNBmpk6BRClOy53vqQOIY=; b=kiZhScS/4zSzJBRtTsydZYMkqpei860SoCDCSghlBLQJcw4dtZlWoP54F1jkQuGS7c2ba0C8KMHgq7EWdTbmtB6srttiFYfL/SoCBMI7jNUSMsqi2ZJrqnhqz4tVbv/IIYt6v+X71buNOSQw2AoaFFFafbFCuE7Ax6jFQEQVnRs= Received: from BL0PR0102CA0065.prod.exchangelabs.com (2603:10b6:208:25::42) by IA1PR12MB7520.namprd12.prod.outlook.com (2603:10b6:208:42f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.19; Thu, 20 Jun 2024 13:03:10 +0000 Received: from BL6PEPF0001AB4C.namprd04.prod.outlook.com (2603:10b6:208:25:cafe::8b) by BL0PR0102CA0065.outlook.office365.com (2603:10b6:208:25::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.33 via Frontend Transport; Thu, 20 Jun 2024 13:03:10 +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 BL6PEPF0001AB4C.mail.protection.outlook.com (10.167.242.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:03:10 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:03:03 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 8/9] perf/x86/rapl: Remove the global variable rapl_msrs Date: Thu, 20 Jun 2024 12:57:02 +0000 Message-ID: <20240620125703.3297-9-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4C:EE_|IA1PR12MB7520:EE_ X-MS-Office365-Filtering-Correlation-Id: 6690c4f4-011f-4037-db58-08dc9129562c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|36860700010|82310400023|1800799021|921017; X-Microsoft-Antispam-Message-Info: sv2UPYA5tbxlzZFTLcPrrKXzxnpWvegFTaLO1+sWmDguqJnpt+rcxj7Yeg67UtkH2pD2eaM3pmzo2MJ74r4SFWphCiaFyqh1xRq/v5mbQwZ4JnM8CHipQXFdB51vHPVhBZkyK45P74r4pOIzpmuE5skM9DDREYEas8tmXAQCUTD1Q/hYKzTuC4riao+Ue8Zw1si9hJSd7uuGs9eTsKHtN4cZnopDuPEPFL1dYG7c2Mf8B5dVz5N9uLe446WNmi2xhTSfdaBGBH3pqBMe2hGj7pYpDgx0RewkmdpfdbmaZ57TdnfaKly6hLQFDN6VRddtfiJ9OJyo5fa9/BRtdy2L/2XausOFKHJWXa+9Rnr/sJn1Y03H1toUKct2RrOUPJBjMyU/T8jnX1mbgdN8amECYwObtu3XxKMxk/+AUv8aMqDP7xv+5QzmWvAL00onIrhhyJPoMKpjodFmCeUvP+BQdaHMVb+H0sT/qeGt7Bs/7R8zbHnQvsmP/JBq+FfjynjLw3ex4ej7KKE8wJLMtwyUmADj4jCaiGDx/vherjUryZT7lH2t/YgE9QALdUGS10YEGjLbDJXfE8kPMCnuBx5efCw6b8iudyr40eDr34hMc3NDTZ2/r4K/f9PEDujukuCvdEwSlYor13vqrBcHQtaOt+ZeEEB/QfjJw3Tpvd4HWku92+zoqHLiRFQWISexlkrWGP2+gqG7VqMz1G2SuQsMN0FJ9rqRklzqLiHppwr6B2I4+vljn0nykDGenGLundmCUOVbFVTqGpnqKUSqn5a2RuZyGGtt/BXlfe46LoueTEKckkoNSAdTWwUBs/2EV7Ep1Ga5W+OM17lK+FC97ncKozz3TLUkLjhIa8Vr1nnQZgFj2/6AKf8r5oz4ry6CvHs4R+BgDjUPqPI20+7T1fX7lKYvGnB6IS4W5MP29c1Ao2GXQ77SC9IpLW1yhzPyimMrnn+/6J3sW48httUmk4X34rljJmTShaYp7saXm2DI5yW2ud8DagS+ofGPwHwnrTcoioqqXb12E8fr4zwQVIqrUTnvR0eJ++l1VTfUUndFsEO/HlB7xgxw/rygtjpQoSoDDhmxLDMR7l97SDOLCmMnswTJlQ2c8Qech1qvoFEKza9hDbZCN6hJLrInESfBxmq+U0ZWiyGXJTMlubWekrx0i0yyfiS8hsybiAIgrxl0Q7tET07lnootUZlGHkomgLQkEqpdqTi6PME3OEcz85bc0P/cAegNa/BDY0cxyRLoUCodo8AAcXSzetJXpNITn+O41eq5qWZso8Ir31hIewMmTvQrdQ6MgpTmRq3qbi8XU07bu9k4a3KD/N6qAViQ5akP3vwEGNfBZCnbwU9xG9CQFxChzzfMLZGPvsxaEQ/TIskqhDZet1XFixkFMFd2Ms8PecFkfTR29neVCvhMLANezX6Oz4i/wEob/01f/+AwtE0= 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:(13230037)(376011)(7416011)(36860700010)(82310400023)(1800799021)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:03:10.4609 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6690c4f4-011f-4037-db58-08dc9129562c 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: BL6PEPF0001AB4C.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7520 After making the rapl_model struct global, the rapl_msrs global variable isn't needed, so remove it. Also it will be cleaner when new per-core scope PMU is added. As we will need to maintain two rapl_msrs array(one for per-core scope and one for package scope PMU), inside the rapl_model struct. Signed-off-by: Dhananjay Ugwekar --- arch/x86/events/rapl.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index b03b044a390f..e962209e9e4d 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -142,7 +142,6 @@ static int rapl_hw_unit[NR_RAPL_PKG_DOMAINS] __read_mostly; static struct rapl_pmus *rapl_pmus_pkg; static unsigned int rapl_pkg_cntr_mask; static u64 rapl_timer_ms; -static struct perf_msr *rapl_msrs; static struct rapl_model *rapl_model; static inline unsigned int get_rapl_pmu_idx(int cpu) @@ -380,7 +379,7 @@ static int rapl_pmu_event_init(struct perf_event *event) return -EINVAL; event->cpu = rapl_pmu->cpu; event->pmu_private = rapl_pmu; - event->hw.event_base = rapl_msrs[bit].msr; + event->hw.event_base = rapl_model->rapl_msrs[bit].msr; event->hw.config = cfg; event->hw.idx = bit; @@ -866,9 +865,7 @@ static int __init rapl_pmu_init(void) rapl_model = (struct rapl_model *) id->driver_data; - rapl_msrs = rapl_model->rapl_msrs; - - rapl_pkg_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_PKG_EVENTS_MAX, + rapl_pkg_cntr_mask = perf_msr_probe(rapl_model->rapl_msrs, PERF_RAPL_PKG_EVENTS_MAX, false, (void *) &rapl_model->pkg_events); ret = rapl_check_hw_unit(); From patchwork Thu Jun 20 12:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13705467 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2056.outbound.protection.outlook.com [40.107.237.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B61861AD9EB; Thu, 20 Jun 2024 13:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888617; cv=fail; b=ZXHi3kXDT/Lgq2WnqgB5f6TOVrJAZRltizhW7ESvP10gXgdHIQG0uiwxhOh+tOsg46Wx5HXiDVvdL2luJMZkjuejVagKT89rVQj5EwzEC4K+4Mhg8CgRrd4iSmGSPU/UIgZDMOqUc6MDLiKktE/WMVXCLlnPqLCXGl9+Hjf8kus= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718888617; c=relaxed/simple; bh=Amentt0H3twmUDlPXsddTGxJkRRSZOY2oVtYB6C9o30=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=li39xO47UCIfTiVrH7A3EdS43Cq/QrMc2tMfkkuCfl7Z4EgTplsPX86hKficfMM50MeI+yKUhUv9P7h3MnUcclN4+7aWMlXK38qHhYCqAgT13dv/ywjd771sYgh5rE5TYIw+HfOLG3K0EbWPkWN1P49Im3iJNkTdIIysU1QR+2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=XsRpcGPE; arc=fail smtp.client-ip=40.107.237.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="XsRpcGPE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JmG2kqCWKiC5Du1sYJhx5OWpDwtMugwho5SLqx/GI3OqRTQD9IeXlh/HwAs/kjXs84Ld22XgvoXmkaoWa2tOLZcLPCGSRp6a1L8xaYeMmfAu9XbC/l5iROKpdDn/NZ9Ks3QZSaZOP4wcbVkZ3drQJcd2E4KPF7jEpSkzSOo7f6U5Tp7w98mPw4NKYk8B4kpprXsYElLJ2vOtRHB3HCrQIlUL2udH6enFw+hZrj5r4EEXM0S1cDowbQ9sZza1rbBS6br+9VZ2L++Jh367as10sFTxsPIjeCLk3jXWBmtvfdiB3fmANzHsy0EpmzhiAv+97PTlisYwZk9bWlEzADPaCA== 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=VZXAEwoZw+j6dX9KzhPjof75Yc3UEPdLNIoTHGWVkZU=; b=PulQ+Mn1AliehBXx12GAZTT+5E1qFB6niPwOo55Fa27w3E3LW/MRyMfIaQDkKJ1pZ8UMti9eDoSIbNYYmdsdjutYNfgk4bAcfg9UDGC4p3yoXsUYmv3SiquwnMLh/KgZvwHqER296Sij64D78w+M7lK/CXtYN+Gf9iZawJMqV+bGbuegia8lI2vKb5EeFzmR+VoUPM+HiRtSBsjhAFvZibErR/fjVnUBEJkLJmHHKpkCAn5bwDJldxOoD3aJNe5AMPBWOPFvvW2y22QOlIWAHzfUEi7udbDz3Ev0SBgFxFLjq5t9BeBxQGC5pi9eP0NoudVrewb7d48UtNcnZt18kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.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 (0) 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=VZXAEwoZw+j6dX9KzhPjof75Yc3UEPdLNIoTHGWVkZU=; b=XsRpcGPEXGkNgtojIkZFxIsD0aH4IEU4Wj+Cs62jEjPj8qdVz4hCI892sUNF0ZR/2G2ssLFB3sIJRyRWR69ZFoHJTox6m6MAbq1H/YTQxZ2UH8IjZo49AxWrNEuc4jkdhKOfBzohKVSYq7r2fP0ey4VZo5gBZPIHkDvK3dlyzXg= Received: from BL0PR1501CA0017.namprd15.prod.outlook.com (2603:10b6:207:17::30) by CYYPR12MB8892.namprd12.prod.outlook.com (2603:10b6:930:be::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.21; Thu, 20 Jun 2024 13:03:31 +0000 Received: from BL6PEPF0001AB4D.namprd04.prod.outlook.com (2603:10b6:207:17:cafe::c5) by BL0PR1501CA0017.outlook.office365.com (2603:10b6:207:17::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.31 via Frontend Transport; Thu, 20 Jun 2024 13:03:31 +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 BL6PEPF0001AB4D.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Thu, 20 Jun 2024 13:03:30 +0000 Received: from shatadru.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.2507.39; Thu, 20 Jun 2024 08:03:22 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH v2 9/9] perf/x86/rapl: Add per-core energy counter support for AMD CPUs Date: Thu, 20 Jun 2024 12:57:03 +0000 Message-ID: <20240620125703.3297-10-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> References: <20240620125703.3297-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4D:EE_|CYYPR12MB8892:EE_ X-MS-Office365-Filtering-Correlation-Id: 76755836-7387-4858-36d5-08dc91296264 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|7416011|376011|36860700010|82310400023|1800799021|921017; X-Microsoft-Antispam-Message-Info: STvKLjZFPTC4Zt7egqPu6OPX+YWNrqL0OLIC+9BsxWtQkwisT9J0wDW0H2EoAE9O6F26448CldW/QiALi/Vm+jtyEQm73PM4Iq/6huXBl+MZNnlzhrOffEw/ZIUAS8eVKo4yB8CsVq9E9lD2KbtVVAKoa7JG1V3UAwSrvTbahJ0+5yDL/8ZG1X/1sCXiDyyg7376oN345raHVRBdycugeBI0IYtORfxm8UUIgLC2o3hN4EqysHmL4PjItCJJFuAlFXBQSDqqgyNDA/kTIh8ImURwluwMHrKXcikrs1w08DoMqdr1sCWce5yE1kP4UznP11gIR9/fM29y0E9E8JSDkIVuSFqb/rB5vMuLK5jBNpfAHhQu0+W3hqNX0AjcBhjjrrZ79o7JOTRiP9tioZ52xvXACSnw331vqy82JCVe7B35YYT+H9P8vzXwVEbC/nBXiCR9pOgWFogogselzP5S5J67I1CfzsDlLYP3f4tJcY7XE/fIaiZDy09zRPhXvlXp6HelXLY/b7PsjNaRy+mIWSyHIpuA4SefFqMlwSCfhsThn8H0WIXvjVgj+fk+yF5Y8LR/JUws/6EiKbabljgY7KqXcrzGNICIuHmu7cgtpW1nI08FWLOb95waXErAfTwMnuyN40tS75/eni6veAbt8M/2H/WBAceoJM68dCy8r0Wq/X/qiB0GKF8ZmZJ4DsfQsyVahq9M5qf4/fyCHBt+A3uRozpdxOgFY3PofcF1KUFc2tDnu08baW2d7652eXOJsvOWczmhOuXueGHA/MEQNxrzJQnvwt9Ir+OsmQeiFGaoUYzrrh/S8kXv6vAtWfuY790Yn7AJl7KtmLJnLg8oytw6JnB9eG4occcZwEVZNZFyKtR3MvJGe32LB598UYAKXsiWkyZmDQIOLMg7QD/w7BKQjVMSJPRHpMSymDHDyl5sKrqUGnnlmuqAHnXt5X13Uc8QX98y2dmTUhgh7qWTkHjZVx5RjHFBkEzaUoqQ2VLJK507uc13GNnU0yJphnNwgU4xTXx5smYU5oo4OHrXa/NuKcp8eGF3lzGwF/g3VqUbi90qYuQmsg9tDjAEXx16bH/YExgnKtLRAOYg9qQlm5MC00un8TG8gOAQPqueEeo2dkT/lgtoyI+Rw1HbADnnPKy3UutHcIbz9V6Dhw3A+BixOqLFIDZVgae3nlRfu2nJaXG+/TDiC1sjk8LXsaFumm6ruUENswZ3nHwpRZwBZrY0UOHP8/oBG/ZEDR3G5b0IQq0TdIYJTzMlckLjOl0feqiVv3AGN0If/ozErrIgiuFMsK8lEE3kuSu2UzHUK+zBjp01noWfzwXQbMWXFX0VSiY4VdjrWTGKX6XSuFeV7dLrDnSvxdyUiYIQSLMNq1csSuQK4mdS3zOUqU6s7yrlquHQYYGNYfyRKS+aZk6USyscUbHRd6r/pnCNY7bmoNY= 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:(13230037)(7416011)(376011)(36860700010)(82310400023)(1800799021)(921017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jun 2024 13:03:30.8939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76755836-7387-4858-36d5-08dc91296264 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: BL6PEPF0001AB4D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8892 Add a new "power_per_core" PMU and "energy-per-core" event for monitoring energy consumption by each core. The existing energy-cores event aggregates the energy consumption at the package level. This new event aligns with the AMD's per_core energy counters. Tested the package level and core level PMU counters with workloads pinned to different CPUs. Results with workload pinned to CPU 1 in core 1 on a AMD Zen4 Genoa machine: $ perf stat -a --per-core -e power_per_core/energy-per-core/ sleep 1 Performance counter stats for 'system wide': S0-D0-C0 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C1 1 5.72 Joules power_per_core/energy-per-core/ S0-D0-C2 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C3 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C4 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C5 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C6 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C7 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C8 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C9 1 0.02 Joules power_per_core/energy-per-core/ S0-D0-C10 1 0.02 Joules power_per_core/energy-per-core/ Signed-off-by: Dhananjay Ugwekar --- v2 changes: * Patches 6,7,8 added to split some changes out of the last patch * Use container_of to get the rapl_pmus from event variable (Rui) * Set PERF_EV_CAP_READ_ACTIVE_PKG flag only for pkg scope PMU (Rui) * Use event id 0x1 for energy-per-core event (Rui) * Use PERF_RAPL_PER_CORE bit instead of adding a new flag to check for per-core counter hw support (Rui) --- arch/x86/events/rapl.c | 189 +++++++++++++++++++++++++++++++++++------ 1 file changed, 164 insertions(+), 25 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index e962209e9e4d..b18f76b5242d 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -39,6 +39,10 @@ * event: rapl_energy_psys * perf code: 0x5 * + * per_core counter: consumption of a single physical core + * event: rapl_energy_per_core (power_per_core PMU) + * perf code: 0x1 + * * We manage those counters as free running (read-only). They may be * use simultaneously by other tools, such as turbostat. * @@ -81,6 +85,13 @@ enum perf_rapl_pkg_events { NR_RAPL_PKG_DOMAINS = PERF_RAPL_PKG_EVENTS_MAX, }; +enum perf_rapl_core_events { + PERF_RAPL_PER_CORE = 0, /* per-core */ + + PERF_RAPL_CORE_EVENTS_MAX, + NR_RAPL_CORE_DOMAINS = PERF_RAPL_CORE_EVENTS_MAX, +}; + static const char *const rapl_pkg_domain_names[NR_RAPL_PKG_DOMAINS] __initconst = { "pp0-core", "package", @@ -89,6 +100,10 @@ static const char *const rapl_pkg_domain_names[NR_RAPL_PKG_DOMAINS] __initconst "psys", }; +static const char *const rapl_core_domain_names[NR_RAPL_CORE_DOMAINS] __initconst = { + "per-core", +}; + /* * event code: LSB 8 bits, passed in attr->config * any other bit is reserved @@ -131,8 +146,10 @@ enum rapl_unit_quirk { }; struct rapl_model { - struct perf_msr *rapl_msrs; + struct perf_msr *rapl_pkg_msrs; + struct perf_msr *rapl_core_msrs; unsigned long pkg_events; + unsigned long core_events; unsigned int msr_power_unit; enum rapl_unit_quirk unit_quirk; }; @@ -140,7 +157,9 @@ struct rapl_model { /* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_PKG_DOMAINS] __read_mostly; static struct rapl_pmus *rapl_pmus_pkg; +static struct rapl_pmus *rapl_pmus_core; static unsigned int rapl_pkg_cntr_mask; +static unsigned int rapl_core_cntr_mask; static u64 rapl_timer_ms; static struct rapl_model *rapl_model; @@ -345,9 +364,13 @@ static int rapl_pmu_event_init(struct perf_event *event) u64 cfg = event->attr.config & RAPL_EVENT_MASK; int bit, ret = 0; struct rapl_pmu *rapl_pmu; + struct rapl_pmus *curr_rapl_pmus; /* only look at RAPL events */ - if (event->attr.type != rapl_pmus_pkg->pmu.type) + if (event->attr.type == rapl_pmus_pkg->pmu.type || + (rapl_pmus_core && event->attr.type == rapl_pmus_core->pmu.type)) + curr_rapl_pmus = container_of(event->pmu, struct rapl_pmus, pmu); + else return -ENOENT; /* check only supported bits are set */ @@ -357,7 +380,8 @@ static int rapl_pmu_event_init(struct perf_event *event) if (event->cpu < 0) return -EINVAL; - event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG; + if (curr_rapl_pmus == rapl_pmus_pkg) + event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG; if (!cfg || cfg >= NR_RAPL_PKG_DOMAINS + 1) return -EINVAL; @@ -366,7 +390,8 @@ static int rapl_pmu_event_init(struct perf_event *event) bit = cfg - 1; /* check event supported */ - if (!(rapl_pkg_cntr_mask & (1 << bit))) + if (!(rapl_pkg_cntr_mask & (1 << bit)) && + !(rapl_core_cntr_mask & (1 << bit))) return -EINVAL; /* unsupported modes and filters */ @@ -374,12 +399,18 @@ static int rapl_pmu_event_init(struct perf_event *event) return -EINVAL; /* must be done before validate_group */ - rapl_pmu = cpu_to_rapl_pmu(event->cpu); + if (curr_rapl_pmus == rapl_pmus_core) { + rapl_pmu = curr_rapl_pmus->rapl_pmu[topology_core_id(event->cpu)]; + event->hw.event_base = rapl_model->rapl_core_msrs[bit].msr; + } else { + rapl_pmu = curr_rapl_pmus->rapl_pmu[get_rapl_pmu_idx(event->cpu)]; + event->hw.event_base = rapl_model->rapl_pkg_msrs[bit].msr; + } + if (!rapl_pmu) return -EINVAL; event->cpu = rapl_pmu->cpu; event->pmu_private = rapl_pmu; - event->hw.event_base = rapl_model->rapl_msrs[bit].msr; event->hw.config = cfg; event->hw.idx = bit; @@ -408,17 +439,38 @@ static struct attribute_group rapl_pmu_attr_group = { .attrs = rapl_pmu_attrs, }; +static ssize_t rapl_get_attr_per_core_cpumask(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return cpumap_print_to_pagebuf(true, buf, &rapl_pmus_core->cpumask); +} + +static struct device_attribute dev_attr_per_core_cpumask = __ATTR(cpumask, 0444, + rapl_get_attr_per_core_cpumask, + NULL); + +static struct attribute *rapl_pmu_per_core_attrs[] = { + &dev_attr_per_core_cpumask.attr, + NULL, +}; + +static struct attribute_group rapl_pmu_per_core_attr_group = { + .attrs = rapl_pmu_per_core_attrs, +}; + RAPL_EVENT_ATTR_STR(energy-cores, rapl_cores, "event=0x01"); RAPL_EVENT_ATTR_STR(energy-pkg , rapl_pkg, "event=0x02"); RAPL_EVENT_ATTR_STR(energy-ram , rapl_ram, "event=0x03"); RAPL_EVENT_ATTR_STR(energy-gpu , rapl_gpu, "event=0x04"); RAPL_EVENT_ATTR_STR(energy-psys, rapl_psys, "event=0x05"); +RAPL_EVENT_ATTR_STR(energy-per-core, rapl_per_core, "event=0x01"); RAPL_EVENT_ATTR_STR(energy-cores.unit, rapl_cores_unit, "Joules"); RAPL_EVENT_ATTR_STR(energy-pkg.unit , rapl_pkg_unit, "Joules"); RAPL_EVENT_ATTR_STR(energy-ram.unit , rapl_ram_unit, "Joules"); RAPL_EVENT_ATTR_STR(energy-gpu.unit , rapl_gpu_unit, "Joules"); RAPL_EVENT_ATTR_STR(energy-psys.unit, rapl_psys_unit, "Joules"); +RAPL_EVENT_ATTR_STR(energy-per-core.unit, rapl_per_core_unit, "Joules"); /* * we compute in 0.23 nJ increments regardless of MSR @@ -428,6 +480,7 @@ RAPL_EVENT_ATTR_STR(energy-pkg.scale, rapl_pkg_scale, "2.3283064365386962890 RAPL_EVENT_ATTR_STR(energy-ram.scale, rapl_ram_scale, "2.3283064365386962890625e-10"); RAPL_EVENT_ATTR_STR(energy-gpu.scale, rapl_gpu_scale, "2.3283064365386962890625e-10"); RAPL_EVENT_ATTR_STR(energy-psys.scale, rapl_psys_scale, "2.3283064365386962890625e-10"); +RAPL_EVENT_ATTR_STR(energy-per-core.scale, rapl_per_core_scale, "2.3283064365386962890625e-10"); /* * There are no default events, but we need to create @@ -461,6 +514,13 @@ static const struct attribute_group *rapl_attr_groups[] = { NULL, }; +static const struct attribute_group *rapl_per_core_attr_groups[] = { + &rapl_pmu_per_core_attr_group, + &rapl_pmu_format_group, + &rapl_pmu_events_group, + NULL, +}; + static struct attribute *rapl_events_cores[] = { EVENT_PTR(rapl_cores), EVENT_PTR(rapl_cores_unit), @@ -521,6 +581,18 @@ static struct attribute_group rapl_events_psys_group = { .attrs = rapl_events_psys, }; +static struct attribute *rapl_events_per_core[] = { + EVENT_PTR(rapl_per_core), + EVENT_PTR(rapl_per_core_unit), + EVENT_PTR(rapl_per_core_scale), + NULL, +}; + +static struct attribute_group rapl_events_per_core_group = { + .name = "events", + .attrs = rapl_events_per_core, +}; + static bool test_msr(int idx, void *data) { return test_bit(idx, (unsigned long *) data); @@ -558,6 +630,11 @@ static struct perf_msr amd_rapl_pkg_msrs[] = { [PERF_RAPL_PSYS] = { 0, &rapl_events_psys_group, NULL, false, 0 }, }; +static struct perf_msr amd_rapl_core_msrs[] = { + [PERF_RAPL_PER_CORE] = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_per_core_group, + test_msr, false, RAPL_MSR_MASK }, +}; + static int __rapl_cpu_offline(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_idx, const struct cpumask *event_cpumask, unsigned int cpu) { @@ -583,8 +660,14 @@ static int __rapl_cpu_offline(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu static int rapl_cpu_offline(unsigned int cpu) { - return __rapl_cpu_offline(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), + int ret = __rapl_cpu_offline(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), get_rapl_pmu_cpumask(cpu), cpu); + + if (ret == 0 && rapl_model->core_events) + ret = __rapl_cpu_offline(rapl_pmus_core, topology_core_id(cpu), + topology_sibling_cpumask(cpu), cpu); + + return ret; } static int __rapl_cpu_online(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_idx, @@ -622,8 +705,14 @@ static int __rapl_cpu_online(struct rapl_pmus *rapl_pmus, unsigned int rapl_pmu_ static int rapl_cpu_online(unsigned int cpu) { - return __rapl_cpu_online(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), + int ret = __rapl_cpu_online(rapl_pmus_pkg, get_rapl_pmu_idx(cpu), get_rapl_pmu_cpumask(cpu), cpu); + + if (ret == 0 && rapl_model->core_events) + ret = __rapl_cpu_online(rapl_pmus_core, topology_core_id(cpu), + topology_sibling_cpumask(cpu), cpu); + + return ret; } @@ -677,7 +766,7 @@ static void __init rapl_advertise(void) int i; pr_info("API unit is 2^-32 Joules, %d fixed counters, %llu ms ovfl timer\n", - hweight32(rapl_pkg_cntr_mask), rapl_timer_ms); + hweight32(rapl_pkg_cntr_mask) + hweight32(rapl_core_cntr_mask), rapl_timer_ms); for (i = 0; i < NR_RAPL_PKG_DOMAINS; i++) { if (rapl_pkg_cntr_mask & (1 << i)) { @@ -685,6 +774,13 @@ static void __init rapl_advertise(void) rapl_pkg_domain_names[i], rapl_hw_unit[i]); } } + + for (i = 0; i < NR_RAPL_CORE_DOMAINS; i++) { + if (rapl_core_cntr_mask & (1 << i)) { + pr_info("hw unit of domain %s 2^-%d Joules\n", + rapl_core_domain_names[i], rapl_hw_unit[i]); + } + } } static void cleanup_rapl_pmus(struct rapl_pmus *rapl_pmus) @@ -705,15 +801,16 @@ static const struct attribute_group *rapl_attr_update[] = { NULL, }; -static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr) +static const struct attribute_group *rapl_per_core_attr_update[] = { + &rapl_events_per_core_group, +}; + +static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int nr_rapl_pmu, + const struct attribute_group **rapl_attr_groups, + const struct attribute_group **rapl_attr_update) { struct rapl_pmus *rapl_pmus; - int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); - - if (rapl_pmu_is_pkg_scope()) - nr_rapl_pmu = topology_max_packages(); - rapl_pmus = kzalloc(struct_size(rapl_pmus, rapl_pmu, nr_rapl_pmu), GFP_KERNEL); if (!rapl_pmus) return -ENOMEM; @@ -741,7 +838,7 @@ static struct rapl_model model_snb = { BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_PP1), .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_snbep = { @@ -749,7 +846,7 @@ static struct rapl_model model_snbep = { BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_hsw = { @@ -758,7 +855,7 @@ static struct rapl_model model_hsw = { BIT(PERF_RAPL_RAM) | BIT(PERF_RAPL_PP1), .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_hsx = { @@ -767,7 +864,7 @@ static struct rapl_model model_hsx = { BIT(PERF_RAPL_RAM), .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW, .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_knl = { @@ -775,7 +872,7 @@ static struct rapl_model model_knl = { BIT(PERF_RAPL_RAM), .unit_quirk = RAPL_UNIT_QUIRK_INTEL_HSW, .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_skl = { @@ -785,7 +882,7 @@ static struct rapl_model model_skl = { BIT(PERF_RAPL_PP1) | BIT(PERF_RAPL_PSYS), .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_msrs, + .rapl_pkg_msrs = intel_rapl_msrs, }; static struct rapl_model model_spr = { @@ -795,13 +892,15 @@ static struct rapl_model model_spr = { BIT(PERF_RAPL_PSYS), .unit_quirk = RAPL_UNIT_QUIRK_INTEL_SPR, .msr_power_unit = MSR_RAPL_POWER_UNIT, - .rapl_msrs = intel_rapl_spr_msrs, + .rapl_pkg_msrs = intel_rapl_spr_msrs, }; static struct rapl_model model_amd_hygon = { .pkg_events = BIT(PERF_RAPL_PKG), + .core_events = BIT(PERF_RAPL_PER_CORE), .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT, - .rapl_msrs = amd_rapl_pkg_msrs, + .rapl_pkg_msrs = amd_rapl_pkg_msrs, + .rapl_core_msrs = amd_rapl_core_msrs, }; static const struct x86_cpu_id rapl_model_match[] __initconst = { @@ -858,6 +957,11 @@ static int __init rapl_pmu_init(void) { const struct x86_cpu_id *id; int ret; + int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); + int nr_cores = topology_max_packages() * topology_num_cores_per_package(); + + if (rapl_pmu_is_pkg_scope()) + nr_rapl_pmu = topology_max_packages(); id = x86_match_cpu(rapl_model_match); if (!id) @@ -865,17 +969,34 @@ static int __init rapl_pmu_init(void) rapl_model = (struct rapl_model *) id->driver_data; - rapl_pkg_cntr_mask = perf_msr_probe(rapl_model->rapl_msrs, PERF_RAPL_PKG_EVENTS_MAX, + rapl_pkg_cntr_mask = perf_msr_probe(rapl_model->rapl_pkg_msrs, PERF_RAPL_PKG_EVENTS_MAX, false, (void *) &rapl_model->pkg_events); ret = rapl_check_hw_unit(); if (ret) return ret; - ret = init_rapl_pmus(&rapl_pmus_pkg); + ret = init_rapl_pmus(&rapl_pmus_pkg, nr_rapl_pmu, rapl_attr_groups, rapl_attr_update); if (ret) return ret; + if (rapl_model->core_events) { + rapl_core_cntr_mask = perf_msr_probe(rapl_model->rapl_core_msrs, + PERF_RAPL_CORE_EVENTS_MAX, false, + (void *) &rapl_model->core_events); + + ret = init_rapl_pmus(&rapl_pmus_core, nr_cores, + rapl_per_core_attr_groups, rapl_per_core_attr_update); + if (ret) { + /* + * If initialization of per_core PMU fails, reset per_core + * flag, and continue with power PMU initialization. + */ + pr_warn("Per-core PMU initialization failed (%d)\n", ret); + rapl_model->core_events = 0UL; + } + } + /* * Install callbacks. Core will call them for each online cpu. */ @@ -889,6 +1010,20 @@ static int __init rapl_pmu_init(void) if (ret) goto out1; + if (rapl_model->core_events) { + ret = perf_pmu_register(&rapl_pmus_core->pmu, "power_per_core", -1); + if (ret) { + /* + * If registration of per_core PMU fails, cleanup per_core PMU + * variables, reset the per_core flag and keep the + * power PMU untouched. + */ + pr_warn("Per-core PMU registration failed (%d)\n", ret); + cleanup_rapl_pmus(rapl_pmus_core); + rapl_model->core_events = 0UL; + } + } + rapl_advertise(); return 0; @@ -906,5 +1041,9 @@ static void __exit intel_rapl_exit(void) cpuhp_remove_state_nocalls(CPUHP_AP_PERF_X86_RAPL_ONLINE); perf_pmu_unregister(&rapl_pmus_pkg->pmu); cleanup_rapl_pmus(rapl_pmus_pkg); + if (rapl_model->core_events) { + perf_pmu_unregister(&rapl_pmus_core->pmu); + cleanup_rapl_pmus(rapl_pmus_core); + } } module_exit(intel_rapl_exit);