From patchwork Mon Jun 10 10:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691803 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2075.outbound.protection.outlook.com [40.107.220.75]) (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 EC79575817; Mon, 10 Jun 2024 10:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014141; cv=fail; b=YTb9PnARPmIGjfJsAITxijh6X4gPPnUXKvOBKBpK1i/y0SSyz+5njC0fVcnRfCUGCTLwKhDNR2elJPx1gh8N24UnLgXQk5cK1HxQhiafJ/RVvYAF1LS9Yuz4C7cUtAN9SjIR3TMAlIse7FoMrsOegQLIx0fpqGU5hnUPVgG+nUg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014141; c=relaxed/simple; bh=qn4QSXEBuMAxwSFcshG+xvUo6hiIugyW1ER10YIoyOg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c1hQxMS4BOt0WL/OCe9nUjOH5OM4JxJWau2SoQ2Ewb+tYfqnc6E/XXnSvoNdvwdv7lv/ESM+DmbdqS+6waG18fXLVDuE1Wj2Gwh3JgNxQfUvqR5/pY0a8xpI65eyxbscRtxdY1Zbhy1xHPw5G7pl38dLWOFHfsCo+mXF/9XXiYg= 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=K7AlSc3/; arc=fail smtp.client-ip=40.107.220.75 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="K7AlSc3/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lU0uDis7iXyTzyUsUggvoZhkfHb2kMVtNdAoEsI0PNyRrprN1vqyEj9q55c52qc4Oo3H7KBrJuRh+XNBXqKn9/pXF5IGVeFRfVx6daN61cBf3QnrQE/DdKDV3M+KeK4BPR40ZrbdHgTndnFiu8CTKMvc5LJE5Dpl7gIDRRN78y77AWjI3k7ezkxFzOgnmEc+5mB1aRyZdLiT8OWQH2DWC+o++FdZMJ/J3GlYChglo+GT63LRK3XxzzvFwVJCWGfLF/TLTOPBzfr9JSd94pfY87Mzg3loqrTgF+oA6jHQZqc7kkJ5yjBKd8B4c0++dEh0lB1B2K7jFJzqWoE07ZFlCA== 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=sDPTx32JggWUEdYkSXzvDNA8885xCgOuvVluLwNl/wg=; b=SzP6EdvFg+S8Lysl77YzoEnW4yOmk8yUzgUkPCQXDnGNjvit3N/SC0D6Tiv9arrQMxJhraIS+Ar0V8eWhRTaj5OcgSy2umA/w23UKZUtKM1lXwQ3MZJtVQHTMdv+YxVXyY0OAorFvCSak+E2Hd7L441K/Exssz7fE+0BSJjMaieOt4dLlMNHd3Eoqd8OV+ONFe8Du/aJuo2ErN9P6VpVmBb2DIFzxlC6pckygfHLTpAN3PUFsL8U9cjdFXtp/b0aB8J+1QEUQoNQnteQBZnzCnUztCSRXToPGESmEyXHubgdq1eWHXmDea5AKc7ascGSmLmMTWuz24ejrYNlqdxnjA== 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=sDPTx32JggWUEdYkSXzvDNA8885xCgOuvVluLwNl/wg=; b=K7AlSc3/nisMxS546LsYaag0xwMJyJHpPg3bslFzux55fKdN3HB5157fAzevfv6nWNOVfGHNwBd5q3Nj++T6Vd9DXsvLRCkLKu9anfyU/1x42fOYsrMSm2bQCGfSMdSE2Cwsky1UDZ44WE6Yv6LwabZizwVIz7XltiNmH+89Cfk= Received: from PH2PEPF00003849.namprd17.prod.outlook.com (2603:10b6:518:1::66) by SN7PR12MB7024.namprd12.prod.outlook.com (2603:10b6:806:26e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:08:55 +0000 Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2a01:111:f403:c936::) by PH2PEPF00003849.outlook.office365.com (2603:1036:903:48::3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.21 via Frontend Transport; Mon, 10 Jun 2024 10:08:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.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; Mon, 10 Jun 2024 10:08:55 +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; Mon, 10 Jun 2024 05:08:48 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 1/6] perf/x86/rapl: Fix the energy-pkg event for AMD CPUs Date: Mon, 10 Jun 2024 10:07:46 +0000 Message-ID: <20240610100751.4855-2-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|SN7PR12MB7024:EE_ X-MS-Office365-Filtering-Correlation-Id: 65c093b1-3f63-4455-cc23-08dc89355652 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|36860700004|376005|82310400017|1800799015|921011; X-Microsoft-Antispam-Message-Info: z6jOhSuO/ikK9rtjbT6O8nc+HgLecQvoSc3VIbq9daHlo/T6IAt/VVUof6bIKf45IyEvkHqiIPqQsMAXTCZVAXWf/czSmI+f4dp34BD60poFWK2kS54eHv8dDuFUOX/MyI28nde/674Pgvv9jxt87Sy/LsbVh6ba5PmQjmnju5SwEpxBqZteQsRXowuQ1kJ5ZcQZC44tjvTBEusQ93pbuY9gV8+sUM9TBZqHJ4Gb0nXY7CvTGU1WlDP5Nt4GWhVRD0tlQuHTieQg5wtuR5bVbW6Ngjre64Gdrrzb/3Hhd4mvEvEX/rGVYbDEfoTF8XnptsujxsLWum68+Cre7LA0TEEn0uBvavNb49qMH9sze0FSYcTHnplwahvYSSSBa9ja3HXKOTrFVfp1W557yTFjcgkzT3t07CmDGsc+gDwKJg4AByLAHPcvRWCeRv+ScrUzjYXGToG2OoxUGD0idmvNALFuLoouXiqCryn7+FhtoFjajjL6reH8hc3De/S+gL9liO/KPo0qZPMy3uJzI09mZ0A6899WcZk+Rn1laXwAGz9eM9KKuUFWLTh1JkhBUrwxD7X+5E5gTiTXhbd9lRk4bQqA4yH2a+ikcyzJ2C85qsFY9UKmo1pjLVAmBFRVY7OMwmjkflsVHYvxzbQ3BiDRAkhzMmlKXOxiC+vaRysgBeW+ZK6QnqAnVp/+9v6zYbsFtOykr/It3ynUSoxNZXQ1YW5UR5wFBpB+NZ/ziTXSq7qj/NY6MCocxhcp7wpB8g/2VBJsBUFKXhL+uPgDvnUfXeRQlBDo7i5J6O0gkf/+0uo+Yj0ERou9lIjhZIq/XxQ8bxnz7sIEKJt5Z0zv+XfQcxCrq1CLLCJYStOC+jIUEraTUAYQfQbHI/WPzXW2TbX4U9QkqVLvY9tXq/G363/9zrkSamqGkq6L25aOzHACa1baOJ3vopptMMsW/DQoEdo7sXpfkdKLAOH0nhbmA9y6YrMP/b6nzxUHr/dUS7GIoMC0i2w3pML+dFo0PdJqb250AoHr8+n8fawqtVwPYFWNE5hlhi9VvqsryxxVQhiD2EW3rgtdRnuimqcQ8LqaqdOsxXviPykYp33lyMJJHmwZBlFVvDK13/1DXlBuHnw9PKUg8u8dNPfppOMka6O8wBp2IdIGB3QdmWJcVyuwOKjTge24d248EIE/n1nIiQtlBHPOKPuTsRKkDL+6mhNejDMugYZ0U8z5n6E3OUjoyVSZPRPkQu2HJeq/pfT0wgMMPJyvEXW16GXXFg4W27Uu3GAiFXR/0UbNx8515Rfxz1pQfXtot/1PEdUEAFeIdAoo+Hry+scB7IwI1uZHG1KGbyedzQ23PwrTD9SemqzB8gf0H92JQ/HcnKDHYZmWghIhbxMzvXWEJwLMvaK90vgTU7c0IFOGn+KC6As58Txd59KYJOwKzFnO+xXOhFXpTcfZSnc= 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:(13230031)(7416005)(36860700004)(376005)(82310400017)(1800799015)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:08:55.3056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65c093b1-3f63-4455-cc23-08dc89355652 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7024 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") Reviewed-by: Zhang Rui --- PS: This patch was earlier sent separately(link below), it has not been merged yet, it is necessary for this patchset to work properly, also it fixes the pre-existing energy-pkg event. https://lore.kernel.org/linux-perf-users/20240502095115.177713-1-Dhananjay.Ugwekar@amd.com/ --- 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 Mon Jun 10 10:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691804 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2078.outbound.protection.outlook.com [40.107.236.78]) (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 2D95D75813; Mon, 10 Jun 2024 10:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014164; cv=fail; b=WFGdmQs2XjFqTVvRUI7GMKJ+sxtTuFQorPLA2I23sxCJYAgqb371KVxbXDMmhEpNAbW5SGkO32ny/cjMy8yp0rVLEf4acjA/M+yvMv8rAm/GbGP2LCRk6IvPUiPVy5PeJoK3NSubCmwX9InAESd471apkpdJTp+LAfU3pWhEpDg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014164; c=relaxed/simple; bh=bdHqtKQgt7guqR41b+qTLiClw9pcS6FtJ1Uis4RlDfw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=azkxb/bTYFBhqMr5DJf3xv4bHVPS3mofwEfZ/5npewBNRtgLvi5VhFwWVvJ3zZCH3+PNE9iWf1W79w8tLlcpIZNmbtoCRFxjq7SK7Nf7HGr4jsbgblunMc38hIfqJ8jHesJVNj+2hePLFHRQ/x2gIUaqbSApMEe5YhuL0oTtmi0= 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=ib+um/LO; arc=fail smtp.client-ip=40.107.236.78 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="ib+um/LO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ltstr72i1nORz/Tb9y5utjanmr3k9hz0etY0JsxP/kFW80N2kqULjNbMrDfShknzVY1rkgiaxn/9uPHTqBuq5TkPNEhxJjW6ZPBIWMp96p0DBQJbct9Cy3lxvijJecKd9lEQJTKI+cmGkMnBiSeIklonixeHler3QAYjHTyJhHEnxgsorE5TL5D8KQwNR9TgMc3dtRBrevK/1EvF5sZ20mcRb+PA7bUm9vYGavT9DWQyNxWyfJvlN7L7/ieEgB1mzL8hw4YGVXMTpjRqQC/bnpPF+VP6qsqyw47B2n+ObcN2TYrARm6q60JzUFXg49qpyCg4lVjirWeU7Ede9hHOBg== 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=LStBtHoXOqQKrrLnGr6lIw+V52cmVlX+FUqeeqFum3rlIWaEQL2uCs2RXuB9dJx6kj/nIEWZ2HpEGcxbnjdQ6302q5+BmV0wzziAoBGWeFM/enOzK86x12h9eWRD3h/mKeJU0UU6OPZKNXbDGrg2Ku3zC7ndzwDLyW2odpAhA2Y3F+qT2ojjoO7JRA6SLhnDui5vB+t2fLE4bKbahkpw6rNTi31ypjD+feh0MY1+mBxzY8VQswcSsZgWedVjqn5fRXyBZ4+0RgAMDJ2t4v7GJyBxU+i6DLhGB+5osA3T6uDeAz5uQzQKzXhwMllMSm1hxHiz4iabggZtlewyPja1hQ== 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=ib+um/LOuUFIDWeoZFfxsFLAAkoMs6FPDQw/f+T+TxZwxTKlrV6MnNDO5RUKTvhhxOdBaB9Vaalhm0GO4gMA3ocxocNawrbPwTWAbvJK1Feotp7HYz0P+0svKAW64JEfZvr+yCcnfEVClKARKJrpqu8odNJnWQnr03kedMKtjhk= Received: from PH0PR07CA0010.namprd07.prod.outlook.com (2603:10b6:510:5::15) by DM6PR12MB4044.namprd12.prod.outlook.com (2603:10b6:5:21d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:09:17 +0000 Received: from CY4PEPF0000E9DA.namprd05.prod.outlook.com (2603:10b6:510:5:cafe::fc) by PH0PR07CA0010.outlook.office365.com (2603:10b6:510:5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.23 via Frontend Transport; Mon, 10 Jun 2024 10:09:16 +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 CY4PEPF0000E9DA.mail.protection.outlook.com (10.167.241.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Mon, 10 Jun 2024 10:09:16 +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; Mon, 10 Jun 2024 05:09:09 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 2/6] perf/x86/rapl: Rename rapl_pmu variables Date: Mon, 10 Jun 2024 10:07:47 +0000 Message-ID: <20240610100751.4855-3-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DA:EE_|DM6PR12MB4044:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ffa9faf-ad6d-4fc9-8694-08dc89356310 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|1800799015|376005|82310400017|7416005|921011; X-Microsoft-Antispam-Message-Info: KlrfbBgYdtPqH+eLfD2aKq6GqFauGkZHvOp4OkRnGeezCmp+Kp18HbYYlrEpl8fX5wGUlaIRxjvbbbw+mE6AVHHAvSQFdpfbRnIiMVqN15LcbM0grctbfB7PcDY+nwZhYOyjZnJWyQX6vwgwDZpJlBu+NmqTgxBh6+VxAFsLlhQNvDARKxdYIVZyK/Pp1nGs5hMkKZRgB7Fs05J4KPtVbzz2mRAYoLjkNcal+mxLhFeoE4rH3NO9NUY8BUHjsz2w/mke/InDbPhXBTx6ujvOtzbpBXH4UmD3CQ0mGNXeAMTd8tDsso+Bj1Lj3CelG3q3JPObTqC+OLN0lA07qxQkKjBteTL/FrUtsnGTTsGf9ixpoZ1lugY2AzBNizbwXDhMg9lcYbhmMFm/lcOkiW82c47G0DWjtowaKQp3m3io9mQMgvEUg5qfZAAXev/uxy4C6iYmrNmG/8Jqu/35E350GJKF9sizZXj2mA02fpMdUo6yDeCuXrg2nBXRaR6cXP5oBnWFHHpryegY0AsNj624sbopgfrBLyTrhQuVnBUUB+GhAUrH/dHJqwGhju7sX5V2RaghapmWlO7cEyVBIpj97iKtch0BdWXx5+g0XLKlK1YB5io/P6qheO7wapaxB2zhCvksGoXD0AycU+0Zs3ubBylUqCFmS0ldJp/oNAT1pCUdGRRyW3ub7/i5gdfwkwK40xCWcuLmBDh0qXspw0tBE7Dv+K9giQOVXoXEBm8cQvemZJCljpoRYqkXmDx5Ldxx5c3uGjwJITxpEWHEIN6KI03oupUqidODXBb0hUWy3CAzc5JqSLu8bO5ADpnht1/wtH6L92Zh2uNC+sP88w50nKSZMt+n6bbmzJV29+CX4HqZjZWo0HRhtys7vJFKqJwXe7snRl1tPoR6Sscjq0FNwptol5pp/H0jX9Tom1mH8ByPcSP7GkJ5GlZD0OCR7ed15tfXrOYr1xydt50NJkIi2Ctqw9AUBStiI7QzTl93Mja3LeT30uvX/m0YqSrnqh2S43rVUVzOaSfb+yR6zr50OkgPGbVdfQPA91HRbX4ITfPCAkqoqCYGkgSKZfonEJO+D/p6SzXrqbuteYSYEkm6XRDwBaWSh4ppfLZAxEvxU4jehW0tVJwKzo859vsWlVxZSg6fYLbbtI+Q/KuaMW7JJOgvlNdNsYs4vNQWNcIkv/UWmAbbmyqjTckT/kW3VqSXRTt9041M6LIMiPDZSF40EgU8lW6rwOgmEKw6OKpgecW+vsQvVRm4Ana+9dUHFyJksKYRaJK4NJxy90yW6Y3pSe65DEc+QAcS0KnDaMOrDIPv4j8gEuRY5cx9Z9H3MShm3myev6coShRW3agjaowdwW/tmGvoQl5+JL1Ao7r5qRNm3PtKaY02hmrgHvN3SbqvMxjoWIhJWVFoc0Dg7sdG8MzV2gmutVS9h8wD84L1HQI= 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:(13230031)(36860700004)(1800799015)(376005)(82310400017)(7416005)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:09:16.6817 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ffa9faf-ad6d-4fc9-8694-08dc89356310 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: CY4PEPF0000E9DA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4044 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 Mon Jun 10 10:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691805 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 45E8575813; Mon, 10 Jun 2024 10:09:46 +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=1718014188; cv=fail; b=si0BAccSWBrjnmBAoLEg7+tc1W1Z0QSM+Qh/J2/oFYxIOKua8BBMFKEz4i9XVVqWIa37B36PZAAQ3bonkG2kTuXl/QuGJa/07v+LazrvP+93ODuo/1LwmvBJHLbVNnlBHZAZi5ps+ij/Ix7qNQsVB/XX8bA7b7tR+8KKSZIlve0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014188; c=relaxed/simple; bh=B+Bs1/Sl2/ea1Kh8kgxU+jxLkhgENSqya1IQw4U1OCQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kBwHgbGmaScnJoAxm1KA2zJIw1YYkyJug4LNx+J02Qr5qQb77SrB//1a6D+ocXAh9aJTXmMB3uIxUUw2jqEWwPQqAIe/WE0GERZzC7AUm3n4MdWtZ0ZlrGE87EfqBf0j121/MuZMBn77Ax8uJ13Xb0xrnuU77Ff/LNIPI0J6mEY= 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=Y9zbNXvg; 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="Y9zbNXvg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S+lh+BgrJCroKVaAPQKMQhrAWKd5K4ucc0SK2W8HWZk0/j9DiaArzqXImdgGp/VXsNqy1F6mvng21Fk7v8xGEgOvjhpm/F73SbXq3Ms7xrYIefpTsGX19IsQNyaXdBBBe0wbOmK3i8caMxY4TeIvzB+yyGr504L8Gk05SgVyepSl9mxdf52tuZffjYVx5gLzM3D4hxkhGHhrZSVoQNOOUUfMaSTHX6u/e2RqYJUqy7e3qomgrNgnoG2Gc8WqleG3SHlIPwxEicFr75Wb/xxxGS1Lu1EypHRrzdApyDK/sQKRv+I7J5OXTmqct4RiN/PDBxxKi0OfWoG8cLVMfxgDBQ== 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=Tz63/lqw19/YWE8tF+zAjR0U2gTRn/s3c3BifzvKqB5qS9FxGoFxtwFGxUMBTTtgE/3v9sRBfq5c+TEjsE7/1uk7/xq/duzzULMnaJBSVFl9F8EfqlRf1z46bghuFt1ms3vSXyTYB3pNoCJ1L/uB71WPZANrEqAR1KrrjhbJFgBLZg7fbPhGNgHFmFQzDI7Trq+CLYc5TiRjtdvv85wIpFSKbEL5O33VIMf+NVqTgfwj6rCZ7hSdoDpU6jpPGp0lJ+sBR9E1rrrwrdJ6OaoXUsr5a38FlN2IS5IqKs+kmZ9RXxmhv5w3rk6SFfstz27HIaTJs28rFXv4IY+xx9pPFQ== 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=Y9zbNXvgAbXCkzcwjL2E47LSuhGl3cwWUpmozX5aI01uhLuODivp/hViwwBsl9rypMQelgsiul/+DLx/2VZ+s9onMTOY8+Sy3znTkNA7cez530Qblf/zq4xJDQwMl5BKczsl43ocZPUAjl+44aUi/cheIoZPTk5Og/4zfnQ2KQE= Received: from CY8P220CA0031.NAMP220.PROD.OUTLOOK.COM (2603:10b6:930:47::17) by CY8PR12MB7315.namprd12.prod.outlook.com (2603:10b6:930:51::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:09:42 +0000 Received: from CY4PEPF0000E9D6.namprd05.prod.outlook.com (2603:10b6:930:47:cafe::9) by CY8P220CA0031.outlook.office365.com (2603:10b6:930:47::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.25 via Frontend Transport; Mon, 10 Jun 2024 10:09:42 +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 CY4PEPF0000E9D6.mail.protection.outlook.com (10.167.241.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; Mon, 10 Jun 2024 10:09:41 +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; Mon, 10 Jun 2024 05:09:34 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 3/6] perf/x86/rapl: Make rapl_model struct global Date: Mon, 10 Jun 2024 10:07:48 +0000 Message-ID: <20240610100751.4855-4-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D6:EE_|CY8PR12MB7315:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a44ab45-6914-485c-ff50-08dc89357220 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|7416005|36860700004|376005|82310400017|921011; X-Microsoft-Antispam-Message-Info: HWeJmN7AraNjnXGFO0pSatRzDEoGmRe8bNfUKSv6HR+NDkFyF2/Q7WWQJSTmFf8zqirp5S4/3aVJMdYDudZwuKdybfkok6s+lp+KWUfHeg+kuUcZpgkN8qV7MiAhek0ePi+xyNzxVmz52wxAi3dj8fpx1QC10if6U9GuIY3UJRWXgIH8k8XUZAciQ1FWXcE9+oFLPC0F7sWC4xfSjFx9bafdI+IA8P2G19uSRK58MWjDosIOlODAV55UyMye2uV2CVXa/8XjswgZQ7SuBsZcrIo/f1jY5YixQ3YBetWH972AjEtBa8bAV40M44lkG07VTAZSHqzBgVBWQ5uoGMkg4TUaIQcwV0npTZysZmFFehQCTXjPcc/xZnYDJmkdPUdNEqzD7KgVlObDyRwf7vu8eZRNsnO+XPSaAdtwboezcToe6OzvLmNsBprjGpK3xEEweGKB/4nW0vI33HpNn1+VJ0Fxxwk3u5Px1mIUqesUnfBJsX7V5x/D18CGxsC+lfHcMwfifnPhdYskTzomv/ebwkqLnbB9Dm/Vb39PK5rF27dIc/+AedSyBCx9sYrF91toM43aeLIYulADZRVThtFRXi7ir83HRYIXK3kGH5TFtMCKHWdbjTu7YDWvQTnEe/EN+ZBL65YHoeCv80sQ/KHTw+RhVRcIPwO6WX09M2ajABknv7I+D8Ebl4Ru8GKEBNt9sP+2diQJypIzxuWIigxdMHsXFDjYdmgoyshzjFOyYfbyVuWxr6TPbrvscDTgyWb+aJnfDFU3qHHB5v94+w738CTDqyimQ11sPLLrjiIg5eRS3AzgF9MDXG+S85TbZyCmNJBGPeO5gHTZePQwTPiwN5mga2zRvBeMXOzcfW/sQFCCo3JP2NEwHs3nsr+3N9x+e7wyIxGJgDoRJL/wZnLEiLiCg+R1YTQyaAwv7qWRiWJgPh3jLSn7MBMuz3wv2tUlWih5PtQnvSeCutE34PbSO/aiJ6q2s16b1EboOiY8cUJEmYw0YQJzeeP0rYnB0dTtYg18nuNtZDAwRWuGD/VZb/uXyh9gRvpGpFPs5nA3b7buZq1RSG4UoFpO8CF2pBRVQvqjHNPq+pbZYFe27woBQtMeYXcerAz8nWZHimILfLlTWy1Bn1Hsuy7vHWnZt302LoMYLUNvAgvAke+Gvpt9mEeHhZjlwfSJsnGebMlts5gxLFs/+W0J1UUS0crLCLLdJL1g8uGquCxZ5qKbnD3LV5zBiWRxHVBiXIho+WJ2aE8ugaxXFJ+tAYXJwy9VkS6o8t6bYJe1hT6qImdqvFdUUQBMNq7ltqO4rA5mk5jcfkF3a+8Xov0l3N8FyFp+KUVc05UfMfpWEB69/L3iHlF+0YXq65y5kCFmHQ0AKGxXhckhIQ8g4GINOrvil1zxkvXpLj9WXBQnYmWF5QtvTtADmFhLw6daJgVcrkha+AbCB6c= 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:(13230031)(1800799015)(7416005)(36860700004)(376005)(82310400017)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:09:41.9554 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a44ab45-6914-485c-ff50-08dc89357220 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: CY4PEPF0000E9D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7315 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 Mon Jun 10 10:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691806 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2089.outbound.protection.outlook.com [40.107.92.89]) (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 8FBB775813; Mon, 10 Jun 2024 10:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014210; cv=fail; b=NiZT9pqme8L56ABGzkaeGB6naPhRIyfMwjd8WWHY8tM+zAdbLZ2DnnpC7T3oEaPgtIdOKk53hKaQgde9LgxOb9Ryw+O/37k64/UstmTVz3iVZs8DRK8tg7xzcyZw75iETVF8NISEn2bfh9Xwd4TQqOSLZ/SAFozLw0pgQeXV4RI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014210; c=relaxed/simple; bh=sKa+6Oml3qc2aKAlIW8Xw8a3d8rh2qf9bUcsvD2ryOg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hydq2eEtxTOEc5jueLv/S8bTe2U7ubnBnibtC3Chy1GyhJczjfnLWj+dWBcKdVwKvMRWbHWq7+PoUPwFX73zX2piVwRZuAJD6hrImKo5DYxH6dubvTLcgzGZ5ifT39WmjBVc7ChuSXJQqcr2IhPUWvMnUDe5kC7NIuLmR29jopg= 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=RbloV99+; arc=fail smtp.client-ip=40.107.92.89 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="RbloV99+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FeAPrLYqsNdlpaWpx4MU18WyfXu7E9ENv+scN9sXE8L0eojpzsxITFf6HwxzvsdQQ4BRaRgidcDFouxA1cpGEqHBKKsKxNv9PGf9Kh1KuFEpklEKIZB18wKZMHYOz+K5NH3+qTob13Kue3vp/QpQmGb4+SJ8flYakKgtVqk1VIdBM29QfSIELvlyiHka5muabPFTHVS1ZDSULkkaLx6IMFhuuf6S3bGfgy/ND45bRF/qasyT+2Ns1lsjWWlLPfXZFqKjqzyUUE60MDOkulle2aZbHEcloUNhwipl73pzCziqBaThH6q0JkbI5NhZezxaNinzovR4Yb9xgYOOrhZ7kw== 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=WY8VqnGdrPq2J+1erPP2h4cwKHwAaA3xpfyFLY5wwxM=; b=F6HNInch46zteiMp2GBPM4t1mQpInNCndYbBpD19X+NKgJ/ruVvhPi1yG4+gmqkC+OdF2bdcoC+8lGVTohw2L0MLrf0LdZcX8pJorPZbMExrJG19ZLntmKp1+REhgbapooLgX5Vxlat4sqe0UIH9Fp/cfp6zKTONBMyHjVx8jY5zr6w4iNDMB6Fwq9TPITB2SIOqmkYD44mlnZZSMedzVnheaW8mI1Z3vojE2S24/Bko6fdfeb7W0vk3KxMlRvVvlNr60kDllHpejImXNJnJvlUaTpdcNMZl6wrm1zLWT0XE1HcZANbezjj7FQV9Ioy0iET1Ch0aNnDV/t+qomykIA== 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=WY8VqnGdrPq2J+1erPP2h4cwKHwAaA3xpfyFLY5wwxM=; b=RbloV99+7Ch1dU5D9toYn9jRNqWXD7yIvTinskL6na08LcO9Ow9H6F0t8ugN61ASo6tRrIfs+FGEbJWgRKxiPvt5I1NscWaziv8zlxpHcUzgiAmyr2btH3jRmtQFibR7G0EmzMH62MDmN14b8zK57i60Soetykp0kSfFfnbHt0E= Received: from BL1P223CA0008.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::13) by LV3PR12MB9258.namprd12.prod.outlook.com (2603:10b6:408:1bb::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:10:04 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2c4:cafe::72) by BL1P223CA0008.outlook.office365.com (2603:10b6:208:2c4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.25 via Frontend Transport; Mon, 10 Jun 2024 10:10:03 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Mon, 10 Jun 2024 10:10:03 +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; Mon, 10 Jun 2024 05:09:56 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 4/6] perf/x86/rapl: Move cpumask variable to rapl_pmus struct Date: Mon, 10 Jun 2024 10:07:49 +0000 Message-ID: <20240610100751.4855-5-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E2:EE_|LV3PR12MB9258:EE_ X-MS-Office365-Filtering-Correlation-Id: d17fb615-1163-48a8-ecc8-08dc89357ef8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|7416005|82310400017|376005|36860700004|921011; X-Microsoft-Antispam-Message-Info: LLQur81gOWvjUVOOXrZZs9sqgJLAsvj2oD1AV1mx/4RsTi+UPsP/YEWokYQj4DFwY26hF9Eoca1aE1XdHSi8lEgtfg2Re26VUMSWUb7DTo94cLCP/EypESFdyjGz9jDywci5ceFscGtPPkPPfhAVtybUfG58+oKNOZtRHbN4YMv2hJlyF48C/9i+vH3JjXO1DDMUgSIYbiRv2XnZ27Z2xyHnBD5jA175Jo68wxZ+9d1tVOqnNDQZuFqHgmTfxwcqgUoDp2DxOXz2O1BmWfYft4rwxhkWFtX4LMkB1xcC7C3+FlfCe9KSEZnJ7vlJwHRITj+JEh9BgN/5kzgnCEsXasYLDhVgf8MihfBNivWBXHeB1GJHjhuu3ZS52D20x0lDJHUWadtPHIWWhgRCUht4nD0ueEPo12aWcThsH+esRp2mMI9Pw0cxUAosQlQ2E42C8q6h7qh2+DPFuRyzjiIMMOgHhXOq1rJcxt5y8GoqBy2VhhOKSoEBpCPh+uWYJ7GZ/zPWmZf5ps/rc9/R0cbL/4h3/TI0C4o0ZmE6lRvBsViv0oD0id28T50Tszw720GGQvnntyhj1MwIBYHZlt5fsT8WdWtZ8FJDD7lEPpjYML3oqMIRDO9HMtwGQcxRV3jjYXaQtM2amajedBE6OmTP6VqOv64XqZeQ5UjVctCpWLMq2R16mKl0KLe5P0B9833F+EA2MaRruvs8KWHw0lwIYdxIAguRaGS4nUaOo+vqG696FAdKbv5SexwogLpsMokQr6LuQoXu02xVAWmgj/aS8IYIaQMTbI3qFJbrmkIZcakST/DvhnxpAweQZhygCnOKI12b7XAkSSA+pFd/4lK4aj7k2eXjG8547F1W70mvioU4/GgKdiY6G5oYd2pbl/qsqZG3Q6seXqsskSkg34piK2E2mcj5pBPMsfRpGGwbkebfRGoP8JJR7CBGNpdoIrgXVJ2aaeTOFQiYmIRZnXb55hCaRWN8IdphqbQ+DEBveVXDeCROES30eHmm89MfekAWMWNMKh0Y6SwHYmY5Ut9b08QuyiegeuHr+4WlHmRbb4+w3qsWI3L7QMA5UgP/11wcP63gcVfVbvQLqKrT34H4OyBIfcO88xT6P3jtDuNzUqntTY83uB05AcHOPx4A76E4goqYmlKZ8xyyeua/j6lGuOV+xDRCHd2Yp19zRMDzV8iqSw5IOQBqDopD7svmH/RqIgq+cDif6p6s3WTxlpMSVTnsiH8ZGqqsZS0YvQMlypr27/JHWmZPm9Xj6a8l6zVuZYayVmmPH0Pfj3et4MYmBujF+LlvPULYkr9i/Ay8qW9gZfLkjmmg3xHXj0WCOBpwZkkGOlHcpFpUa47s8twhYL3TyuV4k03jmPwZ7NWIHe9d78nesbJTc6+FKvHcXeHZwFMrdQCLj/jHHS9Q+I4Iudj4okQj2YiPauIhKHUR9XY= 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:(13230031)(1800799015)(7416005)(82310400017)(376005)(36860700004)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:10:03.5501 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d17fb615-1163-48a8-ecc8-08dc89357ef8 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9258 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 Mon Jun 10 10:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691807 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2052.outbound.protection.outlook.com [40.107.93.52]) (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 7EC27770FA; Mon, 10 Jun 2024 10:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014229; cv=fail; b=JHGNNkctNdiSCXg0rQkPlOGlmMIV/nVfLvqiygNms9isdHioXBPxJIp96iot3P+3XIvxPMPveYf1avMrfw/H99r0Sd1mZ51gFgsH2eUGGK8v/HFLa11ATAbLYBbYLI5ibUGEGF6qJP98l6bjWz4rJG0qUodxFsVySc4UVWDoQ3E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014229; c=relaxed/simple; bh=kq/LIQ70NTTP1DzIxY8ZruVQUsJYI61SgluMa5jcpcY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=B/MgDj4keyOhZHM4jwxWg0j2HkyXCZfXBvetuDqW7dm3zHCiwqLjmoEFlbZsOEFoQo/vhkMwUQlnG/4+74RygMwAp7z7iTDx2+JZrAkkydyRqZ+MFJrgRQ+V6j9WbaHkw3Vg4+yIWJf89jMvSPINmRCO6tQ3LmwUspO50gTXPkY= 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=Oz1FbNjd; arc=fail smtp.client-ip=40.107.93.52 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="Oz1FbNjd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bL3CmA8IvUCM6Kw4ryhNDJFvXp1iyz9q1dS41w8XJRZ+E+qvfK3Y8QSmnV5Cv7DbAokIgqdnEcg/g7aI0m6W5evQ4zC0tt2Po4T3eDjF9Sdf5jdvtjMLc2hwM6GAnWLsFYDYiFgLbLAuwB7PmtSpwUSbaPHBmp4wxsg5jRrbDTMBaLl4GvW9auYiuAS+hKHhFx+tFQfzRU1mcDUekky9giBSb5fRto5jocaivcm4EU4OmTpMfgZ2Y3Ik3Pq5RgyAaRMca6edpqw6x45Bjsw9Z5CCnu77UnAx1925o7WA6KJAqEWqk5415G81zHk2aPxcem6Zx4IIBBcNStnqaS6ogg== 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=QQ7GuOWyRd/dmRFSrNXb0/HGJSp0IWMZ/g671dJTjw+/ieJjhJkOWLUejZ1rOacmTxdX3kClnxt8xr3bHHpnZzIKRa90IV1wEMovma+BOiCAF8ZNqE6EKkYppARaCKK/pE1zxqTfoD/yc5UzlxYTpo7uOiUMlQfn6JCN9FWf8/EGsWlj+sMbnokKnWWSIqaoutVtg6gt0wKnTNqqMDmu/QEAfQWQC3JDFjyxzUtqlj6hTPnyTmEYrqdJ2bcYogDWIxDe27+HsoscgF+8qKP8E5nRas5aI1O/4vovxRfRXs0fbBBsDPncKSZ/oK3ntOfQbu1GWFPTW1Mh3rk0Vf3yXA== 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=Oz1FbNjdTlzKovbujdSTAUh9ARL6dN+sl0spMar1wE+QDP+ON98kVgQqyIZt4K8lnUJeHvvnE54Ufq9cAuuYZMqc9DfgQU8mFqek3yrs0y1kGQOmZ91ffnTXuJ3VICvXwLq+PjNKbBOv8eW4YYQ7FB3fxojt7AF17A290zda3lo= Received: from MN2PR15CA0022.namprd15.prod.outlook.com (2603:10b6:208:1b4::35) by CH3PR12MB8657.namprd12.prod.outlook.com (2603:10b6:610:172::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:10:25 +0000 Received: from MN1PEPF0000F0E1.namprd04.prod.outlook.com (2603:10b6:208:1b4:cafe::e1) by MN2PR15CA0022.outlook.office365.com (2603:10b6:208:1b4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.23 via Frontend Transport; Mon, 10 Jun 2024 10:10:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MN1PEPF0000F0E1.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Mon, 10 Jun 2024 10:10:24 +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; Mon, 10 Jun 2024 05:10:18 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 5/6] perf/x86/rapl: Add wrapper for online/offline functions Date: Mon, 10 Jun 2024 10:07:50 +0000 Message-ID: <20240610100751.4855-6-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E1:EE_|CH3PR12MB8657:EE_ X-MS-Office365-Filtering-Correlation-Id: 43262d78-30ba-4e04-9843-08dc89358bb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|82310400017|1800799015|7416005|921011; X-Microsoft-Antispam-Message-Info: 8+OU9Qnl8IjJXoHukJkDrjAkABHqbmOuAK3VVAOlVsSLdOg+eayrx27Eyiejnq/c1hNpmO1MnWCQpe8zJhXWwAR+VK+DF0A0nKXEK7GkSlI1RSf/oYs434+f4RiK5OMLZRbOStf5juzy4N09RTxkV8GEo7bASXdJfbpX5BeuYPsF8pghlgWW6YjegvHQB10nZhJyhbuDyGn7xb7ptKp67o/6Ezuv7kvO1EWw5PAnmp4/AvdgH1SL50WVjYX4YJvafPchLT29yBt4THlXvE5aI6YU+6qhSy4EJapbIP4Bs/b7JuCx1u+CNAfS+d5k2rY1vcwKKS/H+lVgbTbGNgJLnWpQFeFUs8Tfq+dT15z0VYDLbpD0UcjW/lFxhbS4cLCrPpEnyd5n//u33N+auyh6J4UmVhfNX4hYWOFbvIEJLG8kzcZbCkPyNBR70nWTSljCs2qTFdBpNtL+jR76d39MErbKJxVbOKxIvFmnnjOBvg7qmEg1v3ibyJPCRSgp37L+PPiGZ4rkaQts2KifIpDy52Rw+jJ/etqs1k0wVuLFAVS6fH1/RiFvSEHI5S75pgxACJIbBWsAj4K1Op+anubhJj0dZLnqBgXNeqO3K0BJmNQpwpi7MFnMarbejl5Dfmsthuj/BE3oqSqacO5dXEUSXBVH6OPwMi/rJP5Bhm9Qq45RBYBbnaT8pxinEx1ziqGrIZUYW8jPrSazIXRgYDoVIDm37RrBUvfxhfzKzxWF8Hq2fnw9AHBW2jWLi5grHRZ2s/GWydELUc4Cwf5jwIjAq3FRkO8haV9hR6MnpWEMqIJ2Jj2QAVgviDskKT6mWCYdxZm7OgWzwynGaAmUHqbYv5IhlKRZ3Kj9dGljslhWVT9xsCD8jeqL9s5KL94cnvOdIcZnKXTGgi+3rDlrIqg1wvMrBh09omAJ7pK9xJr+e2LwInS4dc58KhY+tZMlk/9KoBAOZtWK40Ho3nSskrPYtooVl7xhnzK56sLIRL8xncftpryyMxu6XrgzWMxmOlhTc7hVFZOsDeYMLo+MgXP3g37EQ+EBfUuIyY0zGl/X1CAZnT5iy7A5gMWjHV9uwRdQYvZ7SfDQwc5ZdE8Bvb6jHIXmS+OFmjIRN1NlUpVLOhyr4nDV9xSWGbjsJ5Gt2M76W6oGI9uowmiG9EOUE94EFaBJkC8TH6Qnh5dy+HE2EpgsFGPpB7oKb1IyNDHuhdtv3/Vbgiuc6wiK0NUmHZf8jE2NZnXOeRTp7k6zWqSaH4ZAJ1hbDj5+E+w/t0nKZ1HbEkMqe+vWAb5onDjpYer3MozVmeGQ8K3dHfrrDKs2BSuL3ElKZwXfT28obDo79f7Zgg629wuqhTtKoN9z36+nRutmqRJTSo7SCILiQERW0lfxC3+jTBLK1uh/E+k8OVb0SBrKTRP8b0V+iAx2xVEmeTeoj1gt/70npT8tXlRCXvA= 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:(13230031)(36860700004)(376005)(82310400017)(1800799015)(7416005)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:10:24.8995 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43262d78-30ba-4e04-9843-08dc89358bb2 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: MN1PEPF0000F0E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8657 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 Mon Jun 10 10:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Ugwekar X-Patchwork-Id: 13691808 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2089.outbound.protection.outlook.com [40.107.223.89]) (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 78FA875813; Mon, 10 Jun 2024 10:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014255; cv=fail; b=YKMYF7UDPzohuGgFWoqjuFp981mnwoWgtxV2heL7xkyM6vvO+u/Mc1dyMn/5I8qXpha2l4Jr/Rye+NMmp1qw3bo9j5Jcr5gglP0CPEr45bNWpxUtnJwnDEeWmMn4Qxp6fuiJmyuebtsLHL+WsPJtG4bcwvUnBH/Wq/S8nNBns5Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718014255; c=relaxed/simple; bh=wyNVrvl4bFRQCFKsoquukftNS508zhi3jzTNqeK5Qdc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xxt4vgsz6kKOjVYQCzx972VJoot//IC7EPvlKRG2gKcKwiEXj1XqtROMpOkWUf3fdSRsNRcYSEnTgcnZnWxlG6FMOigw1pT55cbP+hnE/t68F58zypvAIwSc5tgU5lBMzoNnkv/LKP5+ssTU6LnJMHCPN1MhVMV9m5/JhKAtQm0= 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=X+L09qAh; arc=fail smtp.client-ip=40.107.223.89 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="X+L09qAh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kf5lybA9eixaqT7kbge1ZBNvpcZTQQQ/YbdbAHsqxDBWyBKrTfX/D/4Abz+zoNJbbLeufM3bNSBUIpX2GU7S+KTsGCEeXDRYwEubi4ptKBX8h6HA+lsD0cS1GVk8eUpNnnvBbJFo/OtQOs1cC90iOCH8+xcirtfCCecYDWX3PAkZ1subYh1Nml2R3HA6b+qvoI9qTf3mro5FtC5E7aebMxRxDcTyQVnD93FTnY7PFEqUu0GIBGUvEeKbaGhX1Z0R4Xhk1ASJ3SxlKytMbwosKUrM6t5UgYa8GGWAf5oDE1pTaD7ugiZoQNRVAktAYzF6Xm2nQ0MgvyMWYr8gSz5g2w== 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=kVDHBhXnrtp4ZJIT7K/9SKlFDi/rYyeXMQ8WOy9Rcsw=; b=UH6aKsgpGIcE3H0Om4jvPIWu8RnAabHyJxDOHho06N5oSdxqMP2/WvgE0QA1P/1YRobGcSC/QB2ojj2tNtzu4IURqHInCLa7He/pkaerJgyWgDWWFgLCbttfLGshOQgnFzH04Zz7vVw5QdwYDe5ZDgTJfNUHFnT9+0ABRsknV5XXk2259+QRHULWQsehOjqZxnIIvnyJJtG6/Z/gHJ88OkKzPZ6gItIYI+kJ13axSGwBU5Ev0N5PNTIYWP5xXfQheMZFEM7eNXcOjeqALD24ow9k/mFC94Q8yObLNmddDzJPritWeFDq3pU1KrBz1ATiWbAcCyfW0p8BWIxmtGVnig== 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=kVDHBhXnrtp4ZJIT7K/9SKlFDi/rYyeXMQ8WOy9Rcsw=; b=X+L09qAhB6EZh5QFP6fpBJbKLpWQ5m5xqcgqi20z5dYqbgUQDx6pB77z5xAAJuDlDwEi3FsX3rbZPIh4RmJjymy6Lhvr8dTOps1BvqIKmN2aLiBTMTyTlV2smyi0YzqgqGmmPbcajfWOBpAbTsrjG+5K3JnmlVx6+dRdE1On8FY= Received: from MN2PR08CA0013.namprd08.prod.outlook.com (2603:10b6:208:239::18) by PH8PR12MB6937.namprd12.prod.outlook.com (2603:10b6:510:1bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.36; Mon, 10 Jun 2024 10:10:48 +0000 Received: from MN1PEPF0000F0E4.namprd04.prod.outlook.com (2603:10b6:208:239:cafe::35) by MN2PR08CA0013.outlook.office365.com (2603:10b6:208:239::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.24 via Frontend Transport; Mon, 10 Jun 2024 10:10:47 +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 MN1PEPF0000F0E4.mail.protection.outlook.com (10.167.242.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7677.15 via Frontend Transport; Mon, 10 Jun 2024 10:10:47 +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; Mon, 10 Jun 2024 05:10:40 -0500 From: Dhananjay Ugwekar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , Dhananjay Ugwekar Subject: [PATCH 6/6] perf/x86/rapl: Add per-core energy counter support for AMD CPUs Date: Mon, 10 Jun 2024 10:07:51 +0000 Message-ID: <20240610100751.4855-7-Dhananjay.Ugwekar@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> References: <20240610100751.4855-1-Dhananjay.Ugwekar@amd.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000F0E4:EE_|PH8PR12MB6937:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f97bdf2-2424-42f4-fe6e-08dc8935995b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|82310400017|1800799015|7416005|921011; X-Microsoft-Antispam-Message-Info: HiNqrty3GnTSSuT1YWUXd70KmMe1v7VttzZfbFSjZzsxwyE7b9hEo13L0ehi18B8XXrM12mvwWmXy2dYbYfBMvk7H4JJU3G5MeeVLIJHWAVC6yg4XZ/VjtaS2KKBeElE2Vuii5c8LpZSnMnyph7acRe5eIzg1r1/Kqy/ZXZaYB+VFWxW/VsM/l4tqM1QaUUlb4mshZBZYSJz52OvTKZ3oMZindV7zWlrvL1Y81vYb3ze8SV+MtF9gA95XJez/hcfTTnB3JqP0h/hQCYkWrbWE5SjXM3h45+FZtoYMkg09M+hg3uSTUYOmfqniv2+gDf5dwgX8v5D2wwASwJ2eD93Cf/ydeeJRFJuoQtT+aUM8p/zqsgj8yBHoBV245H9yEzKD4rSs8ySH5qCZdXSXiGM2DIbDd4DVhq45nAbhDh810fA4rlRMzasz+KPDu8U+Zq/w1SuKIJLzM3C7MuA3hLJzgjgXLibBEn2uOyDI1XJs8KuZv+NQ/reknF532AgA8H9Pm0F94Mh3BiFNdAYjocYMWz4f4BPLyxDiE4SoQsDS9hPVE5F1wdptbAt3VQBazxPpE8dEgj86OGMlTYBtAQkTisM1qajlaTgQxGSShRB5vxjTWPldXjoLAzum0iNwd1+Q6JVKwnyFatZNYLPB1BZ5xbA5fwBSrlVD2GGzxht3pJN6SjDy5/Ksg5zk4QrJPSUtG9xMHfHzMBrn4X/vU3bC0GOYSFPB6cqKs2DIcsBjdqrXRY61A3CSaBmFbBMFvWf7uvpB6uDMTVjPdlhTsIdjHGSX7f6i7K/hiTG2SO0f1AbF9107JHwwm9SfGowtWeBpvYlZDkw74UFUWsMyTOsXFDIq/LtfEGZxeYsbCYEpZmWVjwDRsxhZmL+uBbBYz/u1ghYIdS9668FqsLUTy89+kSvnLW7ohNmAw9Df4DJWffcSveA0CohQr/6krOGLW/Xzx1PsK6xcMIF75U4rhQ8X6fjbiUboaatuw/Qyt251bkIT00ISjkPlO+Zn4w/QVBIKaSwNE9ZM2xHj0PBu/HSqGh85K1Uqf95j6EJcA+OW3+zrvh5/HHbtbqcz4y0xadKoKec+x4mAK0LsR6XoI5n0/MD1ng0+VALPxAISzCqak0G4Lhb7FNJ7Oc5W3Rcc4/79eF+SHLuOovT0IBMei7BZJX3ZWGocm84iY/ofnHGSwz8vujNmP20GQcetVtbAn+QS+GbD+N89J4GtbitxykhYrbrWAVafwW6poWo8AZUf0Gob8CXHFutYr3OySQNfqEwmVglbmsGDR0VuGAJV9+qCclqg+64v7L66yZQNQtWkzCgd4P4g/mRNqihQirgaCTjkssNRI0wuamaxoqrdSfZJ81J7LbQOWSdfafzftkzTJD3Wk4OuxlnuzWPO715cPNSfBnr4+gsUMnTkalRNmyxAw5RjRXBQLn1ojh4sczYIVk= 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:(13230031)(376005)(36860700004)(82310400017)(1800799015)(7416005)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2024 10:10:47.4764 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f97bdf2-2424-42f4-fe6e-08dc8935995b 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: MN1PEPF0000F0E4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6937 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 --- arch/x86/events/rapl.c | 155 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 138 insertions(+), 17 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 70c7b35fb4d2..967ecb98748a 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 + * perf code: 0x6 + * * We manage those counters as free running (read-only). They may be * use simultaneously by other tools, such as turbostat. * @@ -76,6 +80,7 @@ enum perf_rapl_events { PERF_RAPL_RAM, /* DRAM */ PERF_RAPL_PP1, /* gpu */ PERF_RAPL_PSYS, /* psys */ + PERF_RAPL_PERCORE, /* per-core */ PERF_RAPL_MAX, NR_RAPL_DOMAINS = PERF_RAPL_MAX, @@ -87,6 +92,7 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = { "dram", "pp1-gpu", "psys", + "per-core", }; /* @@ -135,11 +141,13 @@ struct rapl_model { unsigned long events; unsigned int msr_power_unit; enum rapl_unit_quirk unit_quirk; + bool per_core; }; /* 1/2^hw_unit Joule */ static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly; static struct rapl_pmus *rapl_pmus; +static struct rapl_pmus *rapl_pmus_per_core; static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; static struct perf_msr *rapl_msrs; @@ -345,9 +353,14 @@ 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->pmu.type) + if (event->attr.type == rapl_pmus->pmu.type) + curr_rapl_pmus = rapl_pmus; + else if (rapl_pmus_per_core && event->attr.type == rapl_pmus_per_core->pmu.type) + curr_rapl_pmus = rapl_pmus_per_core; + else return -ENOENT; /* check only supported bits are set */ @@ -374,9 +387,14 @@ 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_per_core) + rapl_pmu = curr_rapl_pmus->rapl_pmu[topology_core_id(event->cpu)]; + else + rapl_pmu = curr_rapl_pmus->rapl_pmu[get_rapl_pmu_idx(event->cpu)]; + if (!rapl_pmu) return -EINVAL; + event->cpu = rapl_pmu->cpu; event->pmu_private = rapl_pmu; event->hw.event_base = rapl_msrs[bit].msr; @@ -408,17 +426,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_per_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=0x06"); 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 +467,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 +501,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 +568,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); @@ -535,6 +594,7 @@ static struct perf_msr intel_rapl_msrs[] = { [PERF_RAPL_RAM] = { MSR_DRAM_ENERGY_STATUS, &rapl_events_ram_group, test_msr, false, RAPL_MSR_MASK }, [PERF_RAPL_PP1] = { MSR_PP1_ENERGY_STATUS, &rapl_events_gpu_group, test_msr, false, RAPL_MSR_MASK }, [PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group, test_msr, false, RAPL_MSR_MASK }, + [PERF_RAPL_PERCORE] = { 0, &rapl_events_per_core_group, NULL, false, 0 }, }; static struct perf_msr intel_rapl_spr_msrs[] = { @@ -543,6 +603,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = { [PERF_RAPL_RAM] = { MSR_DRAM_ENERGY_STATUS, &rapl_events_ram_group, test_msr, false, RAPL_MSR_MASK }, [PERF_RAPL_PP1] = { MSR_PP1_ENERGY_STATUS, &rapl_events_gpu_group, test_msr, false, RAPL_MSR_MASK }, [PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group, test_msr, true, RAPL_MSR_MASK }, + [PERF_RAPL_PERCORE] = { 0, &rapl_events_per_core_group, NULL, false, 0 }, }; /* @@ -556,6 +617,7 @@ static struct perf_msr amd_rapl_msrs[] = { [PERF_RAPL_RAM] = { 0, &rapl_events_ram_group, NULL, false, 0 }, [PERF_RAPL_PP1] = { 0, &rapl_events_gpu_group, NULL, false, 0 }, [PERF_RAPL_PSYS] = { 0, &rapl_events_psys_group, NULL, false, 0 }, + [PERF_RAPL_PERCORE] = { 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, @@ -583,8 +645,16 @@ 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), - get_rapl_pmu_cpumask(cpu), cpu); + int ret; + + ret = __rapl_cpu_offline(rapl_pmus, get_rapl_pmu_idx(cpu), + get_rapl_pmu_cpumask(cpu), cpu); + + if (ret == 0 && rapl_model->per_core) + ret = __rapl_cpu_offline(rapl_pmus_per_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,10 +692,17 @@ 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), - get_rapl_pmu_cpumask(cpu), cpu); -} + int ret; + + ret = __rapl_cpu_online(rapl_pmus, get_rapl_pmu_idx(cpu), + get_rapl_pmu_cpumask(cpu), cpu); + if (ret == 0 && rapl_model->per_core) + ret = __rapl_cpu_online(rapl_pmus_per_core, topology_core_id(cpu), + topology_sibling_cpumask(cpu), cpu); + + return ret; +} static int rapl_check_hw_unit(void) { @@ -687,7 +764,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,12 +782,15 @@ static const struct attribute_group *rapl_attr_update[] = { NULL, }; -static int __init init_rapl_pmus(void) -{ - int nr_rapl_pmu = topology_max_packages() * topology_max_dies_per_package(); +static const struct attribute_group *rapl_per_core_attr_update[] = { + &rapl_events_per_core_group, +}; - if (rapl_pmu_is_pkg_scope()) - nr_rapl_pmu = topology_max_packages(); +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; rapl_pmus = kzalloc(struct_size(rapl_pmus, rapl_pmu, nr_rapl_pmu), GFP_KERNEL); if (!rapl_pmus) @@ -728,6 +808,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; } @@ -794,9 +877,11 @@ static struct rapl_model model_spr = { }; static struct rapl_model model_amd_hygon = { - .events = BIT(PERF_RAPL_PKG), + .events = BIT(PERF_RAPL_PKG) | + BIT(PERF_RAPL_PERCORE), .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT, .rapl_msrs = amd_rapl_msrs, + .per_core = true, }; static const struct x86_cpu_id rapl_model_match[] __initconst = { @@ -853,6 +938,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) @@ -869,10 +959,23 @@ static int __init rapl_pmu_init(void) if (ret) return ret; - ret = init_rapl_pmus(); + ret = init_rapl_pmus(&rapl_pmus, nr_rapl_pmu, rapl_attr_groups, rapl_attr_update); if (ret) return ret; + if (rapl_model->per_core) { + ret = init_rapl_pmus(&rapl_pmus_per_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->per_core = false; + } + } + /* * Install callbacks. Core will call them for each online cpu. */ @@ -886,14 +989,28 @@ static int __init rapl_pmu_init(void) if (ret) goto out1; + if (rapl_model->per_core) { + ret = perf_pmu_register(&rapl_pmus_per_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_per_core); + rapl_model->per_core = false; + } + } rapl_advertise(); + return 0; out1: 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 +1019,10 @@ 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); + if (rapl_model->per_core) { + perf_pmu_unregister(&rapl_pmus_per_core->pmu); + cleanup_rapl_pmus(rapl_pmus_per_core); + } } module_exit(intel_rapl_exit);