From patchwork Tue Oct 8 17:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tummala, Sivaprasad" X-Patchwork-Id: 145483 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1E42D45AE3; Tue, 8 Oct 2024 19:43:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0AEA440BA5; Tue, 8 Oct 2024 19:43:38 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2056.outbound.protection.outlook.com [40.107.212.56]) by mails.dpdk.org (Postfix) with ESMTP id BB0EA4025C for ; Tue, 8 Oct 2024 19:43:36 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CyI8BXr/AiLaCa1r2L5FRBUKZu+qIdGyxd8UZut4LPYJcVyIb06dYLt4EpkNEUTp59gpA0KkAli8GPC8IVYBaGyWsc262Zh39DHUda1wpWH1bqiBpEICZn7d2yVHXNNW3YovT10RqcJHQYy0yJaOSwgV/tjEdSaEasmifHQCWudG1U36Gy/6oewSjkjgoFrSxRGSW94qnLym9yi58AXQwkvgnhk7Kx1Zqo6qOllWsyfsSy5TkG0f6fXV8HOZnd1qfdBz8iCd4+YjFpEYwBN8MiZZWany6SlQvJq+rcFRSIArgokbBI2FZ2PT0S8nTFSFAigh7iAXTNuYk3Z9kYPsfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=CBfxMi7FrvweKWz2d49DUBr4QyT5cVXueSB5FnG5+Z8=; b=WC2ESheTm2Xfhmlt1fKgo051G2vmP9Mb6YS05ebw8dmoLUAgty3vZdfSOludkDnMWYvD06NfQuTSEKVJmV7n14MSwVscAmOl71RPKyxZ9g0ciIpP46vJlzSWsTc18Au/D27LrBOz1//vw/Ektd01RTYnFl9AnxjoIs/HTriiz9okHbI88nJJ+d1U98PUnNJYpwvSQ9xNnaDBW1Wqp5pZJq34HwPeCK/uVIWi+zk+mA4gb1kqJ80RU77WzTHaochaSADvV6jf94ivSiwYthf1d1jCHv8DFenLoZnoHQH6QSVwDUHRSCFgYSu9yjt21D/yMDFBjKjE32VNac18zzLEPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=CBfxMi7FrvweKWz2d49DUBr4QyT5cVXueSB5FnG5+Z8=; b=zfFRtAi8kILxKiKIJh8YzMovZTFE6Qgi+VJ+kj307L+FVH4VWoZ4Kn/i2RIPd8KIzhCplL+V/zM1OP4jWcJIhduhYJJiwigodnQmniRJUDcL7u5IbYyJE9wH1rmga8P/626KWHdW1S5HkY5BTbs4BLB/BUWAh9JUQG6ghkpc3wc= Received: from BN0PR04CA0055.namprd04.prod.outlook.com (2603:10b6:408:e8::30) by CH2PR12MB4231.namprd12.prod.outlook.com (2603:10b6:610:7d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Tue, 8 Oct 2024 17:43:31 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:408:e8:cafe::ed) by BN0PR04CA0055.outlook.office365.com (2603:10b6:408:e8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.24 via Frontend Transport; Tue, 8 Oct 2024 17:43:30 +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 BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.0 via Frontend Transport; Tue, 8 Oct 2024 17:43:29 +0000 Received: from jfw9ny3-os.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; Tue, 8 Oct 2024 12:43:25 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v3 1/5] power: refactor core power management library Date: Tue, 8 Oct 2024 17:43:04 +0000 Message-ID: <20241008174309.1133051-2-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008174309.1133051-1-sivaprasad.tummala@amd.com> References: <20241008172719.902619-1-sivaprasad.tummala@amd.com> <20241008174309.1133051-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN3PEPF0000B372:EE_|CH2PR12MB4231:EE_ X-MS-Office365-Filtering-Correlation-Id: 440a8ee9-488f-487b-802f-08dce7c0b888 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: RX5Y9px6qYegRkEnoEePA2C4CfThM8R95HE5+hm9vT87zkSiNQdHMAXRLn2FYyb+3MsVpU7GEVMV1+gUdxf/rdS97VD+QXnUaUpCwBIg3Pd/K3ecFI589L/ON5gwAjVEMjLnCAS5UG0bMco5UYPqRRiqWMwNdNR/aFUefNfUPpfPf7+eb/9zSSasmNib0FfOofrVu2/d8ZT2bOxKpYQeL+T8/f8Shk/z/IioQ7UL5/JZXU5w05jZ6rdTBtxzwJOHu7WWL9RqYJMFiQ0Iqc6RPBbHQqFsCkVxQSg4PeDL3WJynag62oY1AujafrdhdHFgjqqPABi32wrNGvUvxhwWGSFmaSLbms5ehiTo5H+tt+XZM1UIEVo/87IGZSYeBZNBXgYSECUXvsUmooB0wVHIrKsvhbom4zOH+VYDgelJx3IdwsEpKFkweb2cP4Yek4ZELHu0uwSpt0/Nk0IGLNltgBRuGvLMiHt39qD4Q4N4pWz4MxtTvWlsYMr2iWjdrW86EPjffIRwQ4Kwqu8HJRD9/PBbfvqZf5vqSPTxZQcvjmE8aODOH1ZwYJDp7yuudg2c6HF57uszPZ7hWQ6NETgLGw/zqYwLwAxjxb1tbI8GxuOC/tzJugMTL0TyP0Gj/VqrQgalPLpg4KjMAORrfeqW7VS4jsfKBlD4n+vsAbmMzQPHXBEGFqgANhi9xE4zfsylA3mxK3n2N5x4gnxMf0JH1G4LnO6NNMM7Hp8CxbOAK4dQgQbqe+Xjg0uLasLmSYjTMkVBuxBaiL/97YLLYzPyjoPEQCStPUlIKKsPQyIKq9Ih3RoO2uWsMkofNjLik51cVm/g0bYZTTXTj8jZD9OeubU1IfBmvSzaAIAVohg2wjOWfwdoD8eAPeIa+eERlt7836YUfEz5ByD+U8Ph9in4ObQZ0AP6RfuQN6vXc3wpR5deROHx6zE0CFxG9If14vs4A7IQDdZmvp2bBxlI63V+nMUIN1JQNDC3JLHDCW9CV42YeKnN7WSvozklL9vwYINam1oUl2ugEEUomLr7ZJi5UCuxNyy/SzT85Qjbt77ZOgQ/4k//zrXr1+tTRCOvakoPKflR4AlIkKgEqDPdBJRaJW1+c1iUxr6Y8KmiAzaY9EU82zSc8PZk/2SxhFBAYx08Cxc507Za5Wf83HiL3vGe+hzPfQuSgka/TgrCIMpMkkT1NYovvYbxS612d6ydHlQaKM7LPmMJkqIAIXw3M9fUSAU6dqNpCM4z1Yv/wtULG57OF3qugEm7dLKRJJymreknl9UT/jIQLZOn0IsCtgu7Xiazn5i4MsKI4qxVRNG7lM3SC+tLQYBF0wwFftIGPNoOAnhfNodDrCvcjWt/auQweekLhStsJ2ce/H2pxSCGz05y002cErfsIQIQI7/ILPsU 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:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 17:43:29.4833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 440a8ee9-488f-487b-802f-08dce7c0b888 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: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4231 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch introduces a comprehensive refactor to the core power management library. The primary focus is on improving modularity and organization by relocating specific driver implementations from the 'lib/power' directory to dedicated directories within 'drivers/power/core/*'. The adjustment of meson.build files enables the selective activation of individual drivers. These changes contribute to a significant enhancement in code organization, providing a clearer structure for driver implementations. The refactor aims to improve overall code clarity and boost maintainability. Additionally, it establishes a foundation for future development, allowing for more focused work on individual drivers and seamless integration of forthcoming enhancements. v3: - renamed rte_power_core_ops.h as rte_power_cpufreq_api.h - re-worked on auto detection logic v2: - added NULL check for global_core_ops in rte_power_get_core_ops Signed-off-by: Sivaprasad Tummala --- drivers/meson.build | 1 + .../power/acpi/acpi_cpufreq.c | 22 +- .../power/acpi/acpi_cpufreq.h | 6 +- drivers/power/acpi/meson.build | 10 + .../power/amd_pstate/amd_pstate_cpufreq.c | 24 +- .../power/amd_pstate/amd_pstate_cpufreq.h | 8 +- drivers/power/amd_pstate/meson.build | 10 + .../power/cppc/cppc_cpufreq.c | 22 +- .../power/cppc/cppc_cpufreq.h | 8 +- drivers/power/cppc/meson.build | 10 + .../power/kvm_vm}/guest_channel.c | 0 .../power/kvm_vm}/guest_channel.h | 0 .../power/kvm_vm/kvm_vm.c | 22 +- .../power/kvm_vm/kvm_vm.h | 6 +- drivers/power/kvm_vm/meson.build | 16 + drivers/power/meson.build | 12 + drivers/power/pstate/meson.build | 10 + .../power/pstate/pstate_cpufreq.c | 22 +- .../power/pstate/pstate_cpufreq.h | 6 +- lib/power/meson.build | 7 +- lib/power/power_common.c | 2 +- lib/power/power_common.h | 16 +- lib/power/rte_power.c | 286 ++++++------------ lib/power/rte_power.h | 139 ++++++--- lib/power/rte_power_cpufreq_api.h | 208 +++++++++++++ lib/power/version.map | 14 + 26 files changed, 618 insertions(+), 269 deletions(-) rename lib/power/power_acpi_cpufreq.c => drivers/power/acpi/acpi_cpufreq.c (95%) rename lib/power/power_acpi_cpufreq.h => drivers/power/acpi/acpi_cpufreq.h (98%) create mode 100644 drivers/power/acpi/meson.build rename lib/power/power_amd_pstate_cpufreq.c => drivers/power/amd_pstate/amd_pstate_cpufreq.c (95%) rename lib/power/power_amd_pstate_cpufreq.h => drivers/power/amd_pstate/amd_pstate_cpufreq.h (97%) create mode 100644 drivers/power/amd_pstate/meson.build rename lib/power/power_cppc_cpufreq.c => drivers/power/cppc/cppc_cpufreq.c (95%) rename lib/power/power_cppc_cpufreq.h => drivers/power/cppc/cppc_cpufreq.h (97%) create mode 100644 drivers/power/cppc/meson.build rename {lib/power => drivers/power/kvm_vm}/guest_channel.c (100%) rename {lib/power => drivers/power/kvm_vm}/guest_channel.h (100%) rename lib/power/power_kvm_vm.c => drivers/power/kvm_vm/kvm_vm.c (82%) rename lib/power/power_kvm_vm.h => drivers/power/kvm_vm/kvm_vm.h (98%) create mode 100644 drivers/power/kvm_vm/meson.build create mode 100644 drivers/power/meson.build create mode 100644 drivers/power/pstate/meson.build rename lib/power/power_pstate_cpufreq.c => drivers/power/pstate/pstate_cpufreq.c (96%) rename lib/power/power_pstate_cpufreq.h => drivers/power/pstate/pstate_cpufreq.h (98%) create mode 100644 lib/power/rte_power_cpufreq_api.h diff --git a/drivers/meson.build b/drivers/meson.build index 66931d4241..9d77e0deab 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -29,6 +29,7 @@ subdirs = [ 'event', # depends on common, bus, mempool and net. 'baseband', # depends on common and bus. 'gpu', # depends on common and bus. + 'power', # depends on common (in future). ] if meson.is_cross_build() diff --git a/lib/power/power_acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c similarity index 95% rename from lib/power/power_acpi_cpufreq.c rename to drivers/power/acpi/acpi_cpufreq.c index 81996e1c13..8637c69703 100644 --- a/lib/power/power_acpi_cpufreq.c +++ b/drivers/power/acpi/acpi_cpufreq.c @@ -10,7 +10,7 @@ #include #include -#include "power_acpi_cpufreq.h" +#include "acpi_cpufreq.h" #include "power_common.h" #define STR_SIZE 1024 @@ -577,3 +577,23 @@ int power_acpi_get_capabilities(unsigned int lcore_id, return 0; } + +static struct rte_power_core_ops acpi_ops = { + .name = "acpi", + .init = power_acpi_cpufreq_init, + .exit = power_acpi_cpufreq_exit, + .check_env_support = power_acpi_cpufreq_check_supported, + .get_avail_freqs = power_acpi_cpufreq_freqs, + .get_freq = power_acpi_cpufreq_get_freq, + .set_freq = power_acpi_cpufreq_set_freq, + .freq_down = power_acpi_cpufreq_freq_down, + .freq_up = power_acpi_cpufreq_freq_up, + .freq_max = power_acpi_cpufreq_freq_max, + .freq_min = power_acpi_cpufreq_freq_min, + .turbo_status = power_acpi_turbo_status, + .enable_turbo = power_acpi_enable_turbo, + .disable_turbo = power_acpi_disable_turbo, + .get_caps = power_acpi_get_capabilities +}; + +RTE_POWER_REGISTER_OPS(acpi_ops); diff --git a/lib/power/power_acpi_cpufreq.h b/drivers/power/acpi/acpi_cpufreq.h similarity index 98% rename from lib/power/power_acpi_cpufreq.h rename to drivers/power/acpi/acpi_cpufreq.h index 682fd9278c..c685008fb5 100644 --- a/lib/power/power_acpi_cpufreq.h +++ b/drivers/power/acpi/acpi_cpufreq.h @@ -2,15 +2,15 @@ * Copyright(c) 2010-2014 Intel Corporation */ -#ifndef _POWER_ACPI_CPUFREQ_H -#define _POWER_ACPI_CPUFREQ_H +#ifndef _ACPI_CPUFREQ_H +#define _ACPI_CPUFREQ_H /** * @file * RTE Power Management via userspace ACPI cpufreq */ -#include "rte_power.h" +#include "rte_power_cpufreq_api.h" /** * Check if ACPI power management is supported. diff --git a/drivers/power/acpi/meson.build b/drivers/power/acpi/meson.build new file mode 100644 index 0000000000..f5afc893ce --- /dev/null +++ b/drivers/power/acpi/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +if not is_linux + build = false + reason = 'only supported on Linux' +endif +sources = files('acpi_cpufreq.c') + +deps += ['power'] diff --git a/lib/power/power_amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c similarity index 95% rename from lib/power/power_amd_pstate_cpufreq.c rename to drivers/power/amd_pstate/amd_pstate_cpufreq.c index 090a0d96cb..f571f4184a 100644 --- a/lib/power/power_amd_pstate_cpufreq.c +++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2021 Intel Corporation * Copyright(c) 2021 Arm Limited - * Copyright(c) 2023 Amd Limited + * Copyright(c) 2024 Advanced Micro Devices, Inc. */ #include @@ -9,7 +9,7 @@ #include #include -#include "power_amd_pstate_cpufreq.h" +#include "amd_pstate_cpufreq.h" #include "power_common.h" /* macros used for rounding frequency to nearest 1000 */ @@ -700,3 +700,23 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id, return 0; } + +static struct rte_power_core_ops amd_pstate_ops = { + .name = "amd-pstate", + .init = power_amd_pstate_cpufreq_init, + .exit = power_amd_pstate_cpufreq_exit, + .check_env_support = power_amd_pstate_cpufreq_check_supported, + .get_avail_freqs = power_amd_pstate_cpufreq_freqs, + .get_freq = power_amd_pstate_cpufreq_get_freq, + .set_freq = power_amd_pstate_cpufreq_set_freq, + .freq_down = power_amd_pstate_cpufreq_freq_down, + .freq_up = power_amd_pstate_cpufreq_freq_up, + .freq_max = power_amd_pstate_cpufreq_freq_max, + .freq_min = power_amd_pstate_cpufreq_freq_min, + .turbo_status = power_amd_pstate_turbo_status, + .enable_turbo = power_amd_pstate_enable_turbo, + .disable_turbo = power_amd_pstate_disable_turbo, + .get_caps = power_amd_pstate_get_capabilities +}; + +RTE_POWER_REGISTER_OPS(amd_pstate_ops); diff --git a/lib/power/power_amd_pstate_cpufreq.h b/drivers/power/amd_pstate/amd_pstate_cpufreq.h similarity index 97% rename from lib/power/power_amd_pstate_cpufreq.h rename to drivers/power/amd_pstate/amd_pstate_cpufreq.h index b02f9f98e4..17bd8e2eaf 100644 --- a/lib/power/power_amd_pstate_cpufreq.h +++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.h @@ -1,18 +1,18 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2021 Intel Corporation * Copyright(c) 2021 Arm Limited - * Copyright(c) 2023 Amd Limited + * Copyright(c) 2024 Advanced Micro Devices, Inc. */ -#ifndef _POWER_AMD_PSTATE_CPUFREQ_H -#define _POWER_AMD_PSTATE_CPUFREQ_H +#ifndef _AMD_PSTATE_CPUFREQ_H +#define _AMD_PSTATE_CPUFREQ_H /** * @file * RTE Power Management via userspace AMD pstate cpufreq */ -#include "rte_power.h" +#include "rte_power_cpufreq_api.h" /** * Check if amd p-state power management is supported. diff --git a/drivers/power/amd_pstate/meson.build b/drivers/power/amd_pstate/meson.build new file mode 100644 index 0000000000..acaf20b388 --- /dev/null +++ b/drivers/power/amd_pstate/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +if not is_linux + build = false + reason = 'only supported on Linux' +endif +sources = files('amd_pstate_cpufreq.c') + +deps += ['power'] diff --git a/lib/power/power_cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c similarity index 95% rename from lib/power/power_cppc_cpufreq.c rename to drivers/power/cppc/cppc_cpufreq.c index 32aaacb948..775b8f4434 100644 --- a/lib/power/power_cppc_cpufreq.c +++ b/drivers/power/cppc/cppc_cpufreq.c @@ -8,7 +8,7 @@ #include #include -#include "power_cppc_cpufreq.h" +#include "cppc_cpufreq.h" #include "power_common.h" /* macros used for rounding frequency to nearest 100000 */ @@ -685,3 +685,23 @@ power_cppc_get_capabilities(unsigned int lcore_id, return 0; } + +static struct rte_power_core_ops cppc_ops = { + .name = "cppc", + .init = power_cppc_cpufreq_init, + .exit = power_cppc_cpufreq_exit, + .check_env_support = power_cppc_cpufreq_check_supported, + .get_avail_freqs = power_cppc_cpufreq_freqs, + .get_freq = power_cppc_cpufreq_get_freq, + .set_freq = power_cppc_cpufreq_set_freq, + .freq_down = power_cppc_cpufreq_freq_down, + .freq_up = power_cppc_cpufreq_freq_up, + .freq_max = power_cppc_cpufreq_freq_max, + .freq_min = power_cppc_cpufreq_freq_min, + .turbo_status = power_cppc_turbo_status, + .enable_turbo = power_cppc_enable_turbo, + .disable_turbo = power_cppc_disable_turbo, + .get_caps = power_cppc_get_capabilities +}; + +RTE_POWER_REGISTER_OPS(cppc_ops); diff --git a/lib/power/power_cppc_cpufreq.h b/drivers/power/cppc/cppc_cpufreq.h similarity index 97% rename from lib/power/power_cppc_cpufreq.h rename to drivers/power/cppc/cppc_cpufreq.h index f4121b237e..64a766145a 100644 --- a/lib/power/power_cppc_cpufreq.h +++ b/drivers/power/cppc/cppc_cpufreq.h @@ -3,15 +3,15 @@ * Copyright(c) 2021 Arm Limited */ -#ifndef _POWER_CPPC_CPUFREQ_H -#define _POWER_CPPC_CPUFREQ_H +#ifndef _CPPC_CPUFREQ_H +#define _CPPC_CPUFREQ_H /** * @file * RTE Power Management via userspace CPPC cpufreq */ -#include "rte_power.h" +#include "rte_power_cpufreq_api.h" /** * Check if CPPC power management is supported. @@ -215,4 +215,4 @@ int power_cppc_disable_turbo(unsigned int lcore_id); int power_cppc_get_capabilities(unsigned int lcore_id, struct rte_power_core_capabilities *caps); -#endif /* _POWER_CPPC_CPUFREQ_H */ +#endif /* _CPPC_CPUFREQ_H */ diff --git a/drivers/power/cppc/meson.build b/drivers/power/cppc/meson.build new file mode 100644 index 0000000000..f1948cd424 --- /dev/null +++ b/drivers/power/cppc/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +if not is_linux + build = false + reason = 'only supported on Linux' +endif +sources = files('cppc_cpufreq.c') + +deps += ['power'] diff --git a/lib/power/guest_channel.c b/drivers/power/kvm_vm/guest_channel.c similarity index 100% rename from lib/power/guest_channel.c rename to drivers/power/kvm_vm/guest_channel.c diff --git a/lib/power/guest_channel.h b/drivers/power/kvm_vm/guest_channel.h similarity index 100% rename from lib/power/guest_channel.h rename to drivers/power/kvm_vm/guest_channel.h diff --git a/lib/power/power_kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c similarity index 82% rename from lib/power/power_kvm_vm.c rename to drivers/power/kvm_vm/kvm_vm.c index f15be8fac5..a1342dcd8b 100644 --- a/lib/power/power_kvm_vm.c +++ b/drivers/power/kvm_vm/kvm_vm.c @@ -9,7 +9,7 @@ #include "rte_power_guest_channel.h" #include "guest_channel.h" #include "power_common.h" -#include "power_kvm_vm.h" +#include "kvm_vm.h" #define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent" @@ -137,3 +137,23 @@ int power_kvm_vm_get_capabilities(__rte_unused unsigned int lcore_id, POWER_LOG(ERR, "rte_power_get_capabilities is not implemented for Virtual Machine Power Management"); return -ENOTSUP; } + +static struct rte_power_core_ops kvm_vm_ops = { + .name = "kvm-vm", + .init = power_kvm_vm_init, + .exit = power_kvm_vm_exit, + .check_env_support = power_kvm_vm_check_supported, + .get_avail_freqs = power_kvm_vm_freqs, + .get_freq = power_kvm_vm_get_freq, + .set_freq = power_kvm_vm_set_freq, + .freq_down = power_kvm_vm_freq_down, + .freq_up = power_kvm_vm_freq_up, + .freq_max = power_kvm_vm_freq_max, + .freq_min = power_kvm_vm_freq_min, + .turbo_status = power_kvm_vm_turbo_status, + .enable_turbo = power_kvm_vm_enable_turbo, + .disable_turbo = power_kvm_vm_disable_turbo, + .get_caps = power_kvm_vm_get_capabilities +}; + +RTE_POWER_REGISTER_OPS(kvm_vm_ops); diff --git a/lib/power/power_kvm_vm.h b/drivers/power/kvm_vm/kvm_vm.h similarity index 98% rename from lib/power/power_kvm_vm.h rename to drivers/power/kvm_vm/kvm_vm.h index 303fcc041b..8b92054076 100644 --- a/lib/power/power_kvm_vm.h +++ b/drivers/power/kvm_vm/kvm_vm.h @@ -2,15 +2,15 @@ * Copyright(c) 2010-2014 Intel Corporation */ -#ifndef _POWER_KVM_VM_H -#define _POWER_KVM_VM_H +#ifndef _KVM_VM_H +#define _KVM_VM_H /** * @file * RTE Power Management KVM VM */ -#include "rte_power.h" +#include "rte_power_cpufreq_api.h" /** * Check if KVM power management is supported. diff --git a/drivers/power/kvm_vm/meson.build b/drivers/power/kvm_vm/meson.build new file mode 100644 index 0000000000..405524ce7c --- /dev/null +++ b/drivers/power/kvm_vm/meson.build @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(C) 2024 Advanced Micro Devices, Inc. +# + +if not is_linux + build = false + reason = 'only supported on Linux' + subdir_done() +endif + +sources = files( + 'guest_channel.c', + 'kvm_vm.c', +) + +deps += ['power'] diff --git a/drivers/power/meson.build b/drivers/power/meson.build new file mode 100644 index 0000000000..8c7215c639 --- /dev/null +++ b/drivers/power/meson.build @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +drivers = [ + 'acpi', + 'amd_pstate', + 'cppc', + 'kvm_vm', + 'pstate' +] + +std_deps = ['power'] diff --git a/drivers/power/pstate/meson.build b/drivers/power/pstate/meson.build new file mode 100644 index 0000000000..9cd47833fb --- /dev/null +++ b/drivers/power/pstate/meson.build @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +if not is_linux + build = false + reason = 'only supported on Linux' +endif +sources = files('pstate_cpufreq.c') + +deps += ['power'] diff --git a/lib/power/power_pstate_cpufreq.c b/drivers/power/pstate/pstate_cpufreq.c similarity index 96% rename from lib/power/power_pstate_cpufreq.c rename to drivers/power/pstate/pstate_cpufreq.c index 2343121621..c32b1adabc 100644 --- a/lib/power/power_pstate_cpufreq.c +++ b/drivers/power/pstate/pstate_cpufreq.c @@ -15,7 +15,7 @@ #include #include "rte_power_pmd_mgmt.h" -#include "power_pstate_cpufreq.h" +#include "pstate_cpufreq.h" #include "power_common.h" /* macros used for rounding frequency to nearest 100000 */ @@ -888,3 +888,23 @@ int power_pstate_get_capabilities(unsigned int lcore_id, return 0; } + +static struct rte_power_core_ops pstate_ops = { + .name = "pstate", + .init = power_pstate_cpufreq_init, + .exit = power_pstate_cpufreq_exit, + .check_env_support = power_pstate_cpufreq_check_supported, + .get_avail_freqs = power_pstate_cpufreq_freqs, + .get_freq = power_pstate_cpufreq_get_freq, + .set_freq = power_pstate_cpufreq_set_freq, + .freq_down = power_pstate_cpufreq_freq_down, + .freq_up = power_pstate_cpufreq_freq_up, + .freq_max = power_pstate_cpufreq_freq_max, + .freq_min = power_pstate_cpufreq_freq_min, + .turbo_status = power_pstate_turbo_status, + .enable_turbo = power_pstate_enable_turbo, + .disable_turbo = power_pstate_disable_turbo, + .get_caps = power_pstate_get_capabilities +}; + +RTE_POWER_REGISTER_OPS(pstate_ops); diff --git a/lib/power/power_pstate_cpufreq.h b/drivers/power/pstate/pstate_cpufreq.h similarity index 98% rename from lib/power/power_pstate_cpufreq.h rename to drivers/power/pstate/pstate_cpufreq.h index 7bf64a518c..5fddb40280 100644 --- a/lib/power/power_pstate_cpufreq.h +++ b/drivers/power/pstate/pstate_cpufreq.h @@ -2,15 +2,15 @@ * Copyright(c) 2018 Intel Corporation */ -#ifndef _POWER_PSTATE_CPUFREQ_H -#define _POWER_PSTATE_CPUFREQ_H +#ifndef _PSTATE_CPUFREQ_H +#define _PSTATE_CPUFREQ_H /** * @file * RTE Power Management via Intel Pstate driver */ -#include "rte_power.h" +#include "rte_power_cpufreq_api.h" /** * Check if pstate power management is supported. diff --git a/lib/power/meson.build b/lib/power/meson.build index b8426589b2..d6b86ea19c 100644 --- a/lib/power/meson.build +++ b/lib/power/meson.build @@ -12,20 +12,15 @@ if not is_linux reason = 'only supported on Linux' endif sources = files( - 'guest_channel.c', - 'power_acpi_cpufreq.c', - 'power_amd_pstate_cpufreq.c', 'power_common.c', - 'power_cppc_cpufreq.c', - 'power_kvm_vm.c', 'power_intel_uncore.c', - 'power_pstate_cpufreq.c', 'rte_power.c', 'rte_power_uncore.c', 'rte_power_pmd_mgmt.c', ) headers = files( 'rte_power.h', + 'rte_power_cpufreq_api.h', 'rte_power_guest_channel.h', 'rte_power_pmd_mgmt.h', 'rte_power_uncore.h', diff --git a/lib/power/power_common.c b/lib/power/power_common.c index 590986d5ef..6c06411e8b 100644 --- a/lib/power/power_common.c +++ b/lib/power/power_common.c @@ -12,7 +12,7 @@ #include "power_common.h" -RTE_LOG_REGISTER_DEFAULT(power_logtype, INFO); +RTE_LOG_REGISTER_DEFAULT(rte_power_logtype, INFO); #define POWER_SYSFILE_SCALING_DRIVER \ "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver" diff --git a/lib/power/power_common.h b/lib/power/power_common.h index 83f742f42a..767686ee12 100644 --- a/lib/power/power_common.h +++ b/lib/power/power_common.h @@ -6,12 +6,13 @@ #define _POWER_COMMON_H_ #include +#include #include #define RTE_POWER_INVALID_FREQ_INDEX (~0) -extern int power_logtype; -#define RTE_LOGTYPE_POWER power_logtype +extern int rte_power_logtype; +#define RTE_LOGTYPE_POWER rte_power_logtype #define POWER_LOG(level, ...) \ RTE_LOG_LINE(level, POWER, "" __VA_ARGS__) @@ -23,13 +24,24 @@ extern int power_logtype; #endif /* check if scaling driver matches one we want */ +__rte_internal int cpufreq_check_scaling_driver(const char *driver); + +__rte_internal int power_set_governor(unsigned int lcore_id, const char *new_governor, char *orig_governor, size_t orig_governor_len); + +__rte_internal int open_core_sysfs_file(FILE **f, const char *mode, const char *format, ...) __rte_format_printf(3, 4); + +__rte_internal int read_core_sysfs_u32(FILE *f, uint32_t *val); + +__rte_internal int read_core_sysfs_s(FILE *f, char *buf, unsigned int len); + +__rte_internal int write_core_sysfs_s(FILE *f, const char *str); #endif /* _POWER_COMMON_H_ */ diff --git a/lib/power/rte_power.c b/lib/power/rte_power.c index 36c3f3da98..fbee9033f2 100644 --- a/lib/power/rte_power.c +++ b/lib/power/rte_power.c @@ -8,153 +8,86 @@ #include #include "rte_power.h" -#include "power_acpi_cpufreq.h" -#include "power_cppc_cpufreq.h" #include "power_common.h" -#include "power_kvm_vm.h" -#include "power_pstate_cpufreq.h" -#include "power_amd_pstate_cpufreq.h" -enum power_management_env global_default_env = PM_ENV_NOT_SET; +static enum power_management_env global_default_env = PM_ENV_NOT_SET; +static struct rte_power_core_ops *global_power_core_ops; static rte_spinlock_t global_env_cfg_lock = RTE_SPINLOCK_INITIALIZER; +static RTE_TAILQ_HEAD(, rte_power_core_ops) core_ops_list = + TAILQ_HEAD_INITIALIZER(core_ops_list); -/* function pointers */ -rte_power_freqs_t rte_power_freqs = NULL; -rte_power_get_freq_t rte_power_get_freq = NULL; -rte_power_set_freq_t rte_power_set_freq = NULL; -rte_power_freq_change_t rte_power_freq_up = NULL; -rte_power_freq_change_t rte_power_freq_down = NULL; -rte_power_freq_change_t rte_power_freq_max = NULL; -rte_power_freq_change_t rte_power_freq_min = NULL; -rte_power_freq_change_t rte_power_turbo_status; -rte_power_freq_change_t rte_power_freq_enable_turbo; -rte_power_freq_change_t rte_power_freq_disable_turbo; -rte_power_get_capabilities_t rte_power_get_capabilities; - -static void -reset_power_function_ptrs(void) + +const char *power_env_str[] = { + "not set", + "acpi", + "kvm-vm", + "pstate", + "cppc", + "amd-pstate" +}; + +/* register the ops struct in rte_power_core_ops, return 0 on success. */ +int +rte_power_register_ops(struct rte_power_core_ops *driver_ops) { - rte_power_freqs = NULL; - rte_power_get_freq = NULL; - rte_power_set_freq = NULL; - rte_power_freq_up = NULL; - rte_power_freq_down = NULL; - rte_power_freq_max = NULL; - rte_power_freq_min = NULL; - rte_power_turbo_status = NULL; - rte_power_freq_enable_turbo = NULL; - rte_power_freq_disable_turbo = NULL; - rte_power_get_capabilities = NULL; + if (!driver_ops->init || !driver_ops->exit || + !driver_ops->check_env_support || !driver_ops->get_avail_freqs || + !driver_ops->get_freq || !driver_ops->set_freq || + !driver_ops->freq_up || !driver_ops->freq_down || + !driver_ops->freq_max || !driver_ops->freq_min || + !driver_ops->turbo_status || !driver_ops->enable_turbo || + !driver_ops->disable_turbo || !driver_ops->get_caps) { + POWER_LOG(ERR, "Missing callbacks while registering power ops"); + return -EINVAL; + } + + TAILQ_INSERT_TAIL(&core_ops_list, driver_ops, next); + + return 0; } int rte_power_check_env_supported(enum power_management_env env) { - switch (env) { - case PM_ENV_ACPI_CPUFREQ: - return power_acpi_cpufreq_check_supported(); - case PM_ENV_PSTATE_CPUFREQ: - return power_pstate_cpufreq_check_supported(); - case PM_ENV_KVM_VM: - return power_kvm_vm_check_supported(); - case PM_ENV_CPPC_CPUFREQ: - return power_cppc_cpufreq_check_supported(); - case PM_ENV_AMD_PSTATE_CPUFREQ: - return power_amd_pstate_cpufreq_check_supported(); - default: - rte_errno = EINVAL; - return -1; - } + struct rte_power_core_ops *ops; + + if (env >= RTE_DIM(power_env_str)) + return 0; + + RTE_TAILQ_FOREACH(ops, &core_ops_list, next) + if (strncmp(ops->name, power_env_str[env], + RTE_POWER_DRIVER_NAMESZ) == 0) + return ops->check_env_support(); + + return 0; } int rte_power_set_env(enum power_management_env env) { + struct rte_power_core_ops *ops; + int ret = -1; + rte_spinlock_lock(&global_env_cfg_lock); if (global_default_env != PM_ENV_NOT_SET) { POWER_LOG(ERR, "Power Management Environment already set."); - rte_spinlock_unlock(&global_env_cfg_lock); - return -1; - } - - int ret = 0; - - if (env == PM_ENV_ACPI_CPUFREQ) { - rte_power_freqs = power_acpi_cpufreq_freqs; - rte_power_get_freq = power_acpi_cpufreq_get_freq; - rte_power_set_freq = power_acpi_cpufreq_set_freq; - rte_power_freq_up = power_acpi_cpufreq_freq_up; - rte_power_freq_down = power_acpi_cpufreq_freq_down; - rte_power_freq_min = power_acpi_cpufreq_freq_min; - rte_power_freq_max = power_acpi_cpufreq_freq_max; - rte_power_turbo_status = power_acpi_turbo_status; - rte_power_freq_enable_turbo = power_acpi_enable_turbo; - rte_power_freq_disable_turbo = power_acpi_disable_turbo; - rte_power_get_capabilities = power_acpi_get_capabilities; - } else if (env == PM_ENV_KVM_VM) { - rte_power_freqs = power_kvm_vm_freqs; - rte_power_get_freq = power_kvm_vm_get_freq; - rte_power_set_freq = power_kvm_vm_set_freq; - rte_power_freq_up = power_kvm_vm_freq_up; - rte_power_freq_down = power_kvm_vm_freq_down; - rte_power_freq_min = power_kvm_vm_freq_min; - rte_power_freq_max = power_kvm_vm_freq_max; - rte_power_turbo_status = power_kvm_vm_turbo_status; - rte_power_freq_enable_turbo = power_kvm_vm_enable_turbo; - rte_power_freq_disable_turbo = power_kvm_vm_disable_turbo; - rte_power_get_capabilities = power_kvm_vm_get_capabilities; - } else if (env == PM_ENV_PSTATE_CPUFREQ) { - rte_power_freqs = power_pstate_cpufreq_freqs; - rte_power_get_freq = power_pstate_cpufreq_get_freq; - rte_power_set_freq = power_pstate_cpufreq_set_freq; - rte_power_freq_up = power_pstate_cpufreq_freq_up; - rte_power_freq_down = power_pstate_cpufreq_freq_down; - rte_power_freq_min = power_pstate_cpufreq_freq_min; - rte_power_freq_max = power_pstate_cpufreq_freq_max; - rte_power_turbo_status = power_pstate_turbo_status; - rte_power_freq_enable_turbo = power_pstate_enable_turbo; - rte_power_freq_disable_turbo = power_pstate_disable_turbo; - rte_power_get_capabilities = power_pstate_get_capabilities; - - } else if (env == PM_ENV_CPPC_CPUFREQ) { - rte_power_freqs = power_cppc_cpufreq_freqs; - rte_power_get_freq = power_cppc_cpufreq_get_freq; - rte_power_set_freq = power_cppc_cpufreq_set_freq; - rte_power_freq_up = power_cppc_cpufreq_freq_up; - rte_power_freq_down = power_cppc_cpufreq_freq_down; - rte_power_freq_min = power_cppc_cpufreq_freq_min; - rte_power_freq_max = power_cppc_cpufreq_freq_max; - rte_power_turbo_status = power_cppc_turbo_status; - rte_power_freq_enable_turbo = power_cppc_enable_turbo; - rte_power_freq_disable_turbo = power_cppc_disable_turbo; - rte_power_get_capabilities = power_cppc_get_capabilities; - } else if (env == PM_ENV_AMD_PSTATE_CPUFREQ) { - rte_power_freqs = power_amd_pstate_cpufreq_freqs; - rte_power_get_freq = power_amd_pstate_cpufreq_get_freq; - rte_power_set_freq = power_amd_pstate_cpufreq_set_freq; - rte_power_freq_up = power_amd_pstate_cpufreq_freq_up; - rte_power_freq_down = power_amd_pstate_cpufreq_freq_down; - rte_power_freq_min = power_amd_pstate_cpufreq_freq_min; - rte_power_freq_max = power_amd_pstate_cpufreq_freq_max; - rte_power_turbo_status = power_amd_pstate_turbo_status; - rte_power_freq_enable_turbo = power_amd_pstate_enable_turbo; - rte_power_freq_disable_turbo = power_amd_pstate_disable_turbo; - rte_power_get_capabilities = power_amd_pstate_get_capabilities; - } else { - POWER_LOG(ERR, "Invalid Power Management Environment(%d) set", - env); - ret = -1; + goto out; } - if (ret == 0) - global_default_env = env; - else { - global_default_env = PM_ENV_NOT_SET; - reset_power_function_ptrs(); - } + RTE_TAILQ_FOREACH(ops, &core_ops_list, next) + if (strncmp(ops->name, power_env_str[env], + RTE_POWER_DRIVER_NAMESZ) == 0) { + global_power_core_ops = ops; + global_default_env = env; + ret = 0; + goto out; + } + POWER_LOG(ERR, "Invalid Power Management Environment(%d) set", + env); +out: rte_spinlock_unlock(&global_env_cfg_lock); return ret; } @@ -164,94 +97,65 @@ rte_power_unset_env(void) { rte_spinlock_lock(&global_env_cfg_lock); global_default_env = PM_ENV_NOT_SET; - reset_power_function_ptrs(); + global_power_core_ops = NULL; rte_spinlock_unlock(&global_env_cfg_lock); } enum power_management_env -rte_power_get_env(void) { +rte_power_get_env(void) +{ return global_default_env; } +struct rte_power_core_ops * +rte_power_get_core_ops(void) +{ + RTE_ASSERT(global_power_core_ops != NULL); + + return global_power_core_ops; +} + int rte_power_init(unsigned int lcore_id) { - int ret = -1; + struct rte_power_core_ops *ops; + uint8_t env; - switch (global_default_env) { - case PM_ENV_ACPI_CPUFREQ: - return power_acpi_cpufreq_init(lcore_id); - case PM_ENV_KVM_VM: - return power_kvm_vm_init(lcore_id); - case PM_ENV_PSTATE_CPUFREQ: - return power_pstate_cpufreq_init(lcore_id); - case PM_ENV_CPPC_CPUFREQ: - return power_cppc_cpufreq_init(lcore_id); - case PM_ENV_AMD_PSTATE_CPUFREQ: - return power_amd_pstate_cpufreq_init(lcore_id); - default: - POWER_LOG(INFO, "Env isn't set yet!"); - } + if (global_default_env != PM_ENV_NOT_SET) + return global_power_core_ops->init(lcore_id); - /* Auto detect Environment */ - POWER_LOG(INFO, "Attempting to initialise ACPI cpufreq power management..."); - ret = power_acpi_cpufreq_init(lcore_id); - if (ret == 0) { - rte_power_set_env(PM_ENV_ACPI_CPUFREQ); - goto out; - } + POWER_LOG(INFO, "Env isn't set yet!"); - POWER_LOG(INFO, "Attempting to initialise PSTAT power management..."); - ret = power_pstate_cpufreq_init(lcore_id); - if (ret == 0) { - rte_power_set_env(PM_ENV_PSTATE_CPUFREQ); - goto out; + /* Auto detect Environment */ + RTE_TAILQ_FOREACH(ops, &core_ops_list, next) { + POWER_LOG(INFO, + "Attempting to initialise %s cpufreq power management...", + ops->name); + for (env = 0; env < RTE_DIM(power_env_str); env++) { + if ((strncmp(ops->name, power_env_str[env], + RTE_POWER_DRIVER_NAMESZ) == 0) && + (ops->init(lcore_id) == 0)) { + rte_power_set_env(env); + return 0; + } + } } - POWER_LOG(INFO, "Attempting to initialise AMD PSTATE power management..."); - ret = power_amd_pstate_cpufreq_init(lcore_id); - if (ret == 0) { - rte_power_set_env(PM_ENV_AMD_PSTATE_CPUFREQ); - goto out; - } + POWER_LOG(ERR, + "Unable to set Power Management Environment for lcore %u", + lcore_id); - POWER_LOG(INFO, "Attempting to initialise CPPC power management..."); - ret = power_cppc_cpufreq_init(lcore_id); - if (ret == 0) { - rte_power_set_env(PM_ENV_CPPC_CPUFREQ); - goto out; - } - - POWER_LOG(INFO, "Attempting to initialise VM power management..."); - ret = power_kvm_vm_init(lcore_id); - if (ret == 0) { - rte_power_set_env(PM_ENV_KVM_VM); - goto out; - } - POWER_LOG(ERR, "Unable to set Power Management Environment for lcore " - "%u", lcore_id); -out: - return ret; + return -1; } int rte_power_exit(unsigned int lcore_id) { - switch (global_default_env) { - case PM_ENV_ACPI_CPUFREQ: - return power_acpi_cpufreq_exit(lcore_id); - case PM_ENV_KVM_VM: - return power_kvm_vm_exit(lcore_id); - case PM_ENV_PSTATE_CPUFREQ: - return power_pstate_cpufreq_exit(lcore_id); - case PM_ENV_CPPC_CPUFREQ: - return power_cppc_cpufreq_exit(lcore_id); - case PM_ENV_AMD_PSTATE_CPUFREQ: - return power_amd_pstate_cpufreq_exit(lcore_id); - default: - POWER_LOG(ERR, "Environment has not been set, unable to exit gracefully"); + if (global_default_env != PM_ENV_NOT_SET) + return global_power_core_ops->exit(lcore_id); - } - return -1; + POWER_LOG(ERR, + "Environment has not been set, unable to exit gracefully"); + return -1; } diff --git a/lib/power/rte_power.h b/lib/power/rte_power.h index 4fa4afe399..d77d285c18 100644 --- a/lib/power/rte_power.h +++ b/lib/power/rte_power.h @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2014 Intel Corporation + * Copyright(c) 2024 Advanced Micro Devices, Inc. */ #ifndef _RTE_POWER_H @@ -14,14 +15,21 @@ #include #include +#include "rte_power_cpufreq_api.h" + #ifdef __cplusplus extern "C" { #endif /* Power Management Environment State */ -enum power_management_env {PM_ENV_NOT_SET, PM_ENV_ACPI_CPUFREQ, PM_ENV_KVM_VM, - PM_ENV_PSTATE_CPUFREQ, PM_ENV_CPPC_CPUFREQ, - PM_ENV_AMD_PSTATE_CPUFREQ}; +enum power_management_env { + PM_ENV_NOT_SET = 0, + PM_ENV_ACPI_CPUFREQ, + PM_ENV_KVM_VM, + PM_ENV_PSTATE_CPUFREQ, + PM_ENV_CPPC_CPUFREQ, + PM_ENV_AMD_PSTATE_CPUFREQ +}; /** * Check if a specific power management environment type is supported on a @@ -66,6 +74,15 @@ void rte_power_unset_env(void); */ enum power_management_env rte_power_get_env(void); +/** + * @internal Get the power ops struct from its index. + * + * @return + * The pointer to the ops struct in the table if registered. + */ +struct rte_power_core_ops * +rte_power_get_core_ops(void); + /** * Initialize power management for a specific lcore. If rte_power_set_env() has * not been called then an auto-detect of the environment will start and @@ -108,10 +125,13 @@ int rte_power_exit(unsigned int lcore_id); * @return * The number of available frequencies. */ -typedef uint32_t (*rte_power_freqs_t)(unsigned int lcore_id, uint32_t *freqs, - uint32_t num); +static inline uint32_t +rte_power_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t n) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); -extern rte_power_freqs_t rte_power_freqs; + return ops->get_avail_freqs(lcore_id, freqs, n); +} /** * Return the current index of available frequencies of a specific lcore. @@ -124,9 +144,13 @@ extern rte_power_freqs_t rte_power_freqs; * @return * The current index of available frequencies. */ -typedef uint32_t (*rte_power_get_freq_t)(unsigned int lcore_id); +static inline uint32_t +rte_power_get_freq(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); -extern rte_power_get_freq_t rte_power_get_freq; + return ops->get_freq(lcore_id); +} /** * Set the new frequency for a specific lcore by indicating the index of @@ -144,82 +168,101 @@ extern rte_power_get_freq_t rte_power_get_freq; * - 0 on success without frequency changed. * - Negative on error. */ -typedef int (*rte_power_set_freq_t)(unsigned int lcore_id, uint32_t index); - -extern rte_power_set_freq_t rte_power_set_freq; +static inline uint32_t +rte_power_set_freq(unsigned int lcore_id, uint32_t index) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); -/** - * Function pointer definition for generic frequency change functions. Review - * each environments specific documentation for usage. - * - * @param lcore_id - * lcore id. - * - * @return - * - 1 on success with frequency changed. - * - 0 on success without frequency changed. - * - Negative on error. - */ -typedef int (*rte_power_freq_change_t)(unsigned int lcore_id); + return ops->set_freq(lcore_id, index); +} /** * Scale up the frequency of a specific lcore according to the available * frequencies. * Review each environments specific documentation for usage. */ -extern rte_power_freq_change_t rte_power_freq_up; +static inline int +rte_power_freq_up(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->freq_up(lcore_id); +} /** * Scale down the frequency of a specific lcore according to the available * frequencies. * Review each environments specific documentation for usage. */ -extern rte_power_freq_change_t rte_power_freq_down; +static inline int +rte_power_freq_down(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->freq_down(lcore_id); +} /** * Scale up the frequency of a specific lcore to the highest according to the * available frequencies. * Review each environments specific documentation for usage. */ -extern rte_power_freq_change_t rte_power_freq_max; +static inline int +rte_power_freq_max(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->freq_max(lcore_id); +} /** * Scale down the frequency of a specific lcore to the lowest according to the * available frequencies. * Review each environments specific documentation for usage.. */ -extern rte_power_freq_change_t rte_power_freq_min; +static inline int +rte_power_freq_min(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->freq_min(lcore_id); +} /** * Query the Turbo Boost status of a specific lcore. * Review each environments specific documentation for usage.. */ -extern rte_power_freq_change_t rte_power_turbo_status; +static inline int +rte_power_turbo_status(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->turbo_status(lcore_id); +} /** * Enable Turbo Boost for this lcore. * Review each environments specific documentation for usage.. */ -extern rte_power_freq_change_t rte_power_freq_enable_turbo; +static inline int +rte_power_freq_enable_turbo(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); + + return ops->enable_turbo(lcore_id); +} /** * Disable Turbo Boost for this lcore. * Review each environments specific documentation for usage.. */ -extern rte_power_freq_change_t rte_power_freq_disable_turbo; +static inline int +rte_power_freq_disable_turbo(unsigned int lcore_id) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); -/** - * Power capabilities summary. - */ -struct rte_power_core_capabilities { - union { - uint64_t capabilities; - struct { - uint64_t turbo:1; /**< Turbo can be enabled. */ - uint64_t priority:1; /**< SST-BF high freq core */ - }; - }; -}; + return ops->disable_turbo(lcore_id); +} /** * Returns power capabilities for a specific lcore. @@ -235,10 +278,14 @@ struct rte_power_core_capabilities { * - 0 on success. * - Negative on error. */ -typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id, - struct rte_power_core_capabilities *caps); +static inline int +rte_power_get_capabilities(unsigned int lcore_id, + struct rte_power_core_capabilities *caps) +{ + struct rte_power_core_ops *ops = rte_power_get_core_ops(); -extern rte_power_get_capabilities_t rte_power_get_capabilities; + return ops->get_caps(lcore_id, caps); +} #ifdef __cplusplus } diff --git a/lib/power/rte_power_cpufreq_api.h b/lib/power/rte_power_cpufreq_api.h new file mode 100644 index 0000000000..526372e0d4 --- /dev/null +++ b/lib/power/rte_power_cpufreq_api.h @@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + * Copyright(c) 2024 Advanced Micro Devices, Inc. + */ + +#ifndef _RTE_POWER_CPUFREQ_API_H +#define _RTE_POWER_CPUFREQ_API_H + +/** + * @file + * RTE Power Management + */ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RTE_POWER_DRIVER_NAMESZ 24 + +/** + * Initialize power management for a specific lcore. If rte_power_set_env() has + * not been called then an auto-detect of the environment will start and + * initialise the corresponding resources. + * + * @param lcore_id + * lcore id. + * + * @return + * - 0 on success. + * - Negative on error. + */ +typedef int (*rte_power_cpufreq_init_t)(unsigned int lcore_id); + +/** + * Exit power management on a specific lcore. This will call the environment + * dependent exit function. + * + * @param lcore_id + * lcore id. + * + * @return + * - 0 on success. + * - Negative on error. + */ +typedef int (*rte_power_cpufreq_exit_t)(unsigned int lcore_id); + +/** + * Check if a specific power management environment type is supported on a + * currently running system. + * + * @return + * - 1 if supported + * - 0 if unsupported + * - -1 if error, with rte_errno indicating reason for error. + */ +typedef int (*rte_power_check_env_support_t)(void); + +/** + * Get the available frequencies of a specific lcore. + * Function pointer definition. Review each environments + * specific documentation for usage. + * + * @param lcore_id + * lcore id. + * @param freqs + * The buffer array to save the frequencies. + * @param num + * The number of frequencies to get. + * + * @return + * The number of available frequencies. + */ +typedef uint32_t (*rte_power_freqs_t)(unsigned int lcore_id, uint32_t *freqs, + uint32_t num); + +/** + * Return the current index of available frequencies of a specific lcore. + * Function pointer definition. Review each environments + * specific documentation for usage. + * + * @param lcore_id + * lcore id. + * + * @return + * The current index of available frequencies. + */ +typedef uint32_t (*rte_power_get_freq_t)(unsigned int lcore_id); + +/** + * Set the new frequency for a specific lcore by indicating the index of + * available frequencies. + * Function pointer definition. Review each environments + * specific documentation for usage. + * + * @param lcore_id + * lcore id. + * @param index + * The index of available frequencies. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +typedef int (*rte_power_set_freq_t)(unsigned int lcore_id, uint32_t index); + +/** + * Function pointer definition for generic frequency change functions. Review + * each environments specific documentation for usage. + * + * @param lcore_id + * lcore id. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +typedef int (*rte_power_freq_change_t)(unsigned int lcore_id); + +/** + * Function pointer definition for generic frequency change functions. Review + * each environments specific documentation for usage. + * + * @param lcore_id + * lcore id. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ + +/** + * Power capabilities summary. + */ +struct rte_power_core_capabilities { + union { + uint64_t capabilities; + struct { + uint64_t turbo:1; /**< Turbo can be enabled. */ + uint64_t priority:1; /**< SST-BF high freq core */ + }; + }; +}; + +typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id, + struct rte_power_core_capabilities *caps); + +/** Structure defining core power operations structure */ +struct rte_power_core_ops { + RTE_TAILQ_ENTRY(rte_power_core_ops) next; /**< Next in list. */ + char name[RTE_POWER_DRIVER_NAMESZ]; /**< power mgmt driver. */ + rte_power_cpufreq_init_t init; /**< Initialize power management. */ + rte_power_cpufreq_exit_t exit; /**< Exit power management. */ + rte_power_check_env_support_t check_env_support;/**< verify env is supported. */ + rte_power_freqs_t get_avail_freqs; /**< Get the available frequencies. */ + rte_power_get_freq_t get_freq; /**< Get frequency index. */ + rte_power_set_freq_t set_freq; /**< Set frequency index. */ + rte_power_freq_change_t freq_up; /**< Scale up frequency. */ + rte_power_freq_change_t freq_down; /**< Scale down frequency. */ + rte_power_freq_change_t freq_max; /**< Scale up frequency to highest. */ + rte_power_freq_change_t freq_min; /**< Scale up frequency to lowest. */ + rte_power_freq_change_t turbo_status; /**< Get Turbo status. */ + rte_power_freq_change_t enable_turbo; /**< Enable Turbo. */ + rte_power_freq_change_t disable_turbo; /**< Disable Turbo. */ + rte_power_get_capabilities_t get_caps; /**< power capabilities. */ +}; + +/** + * Register power cpu frequency operations. + * + * @param ops + * Pointer to an ops structure to register. + * @return + * - >=0: Success; return the index of the ops struct in the table. + * - -EINVAL - error while registering ops struct. + */ +__rte_internal +int rte_power_register_ops(struct rte_power_core_ops *ops); + +/** + * Macro to statically register the ops of a cpufreq driver. + */ +#define RTE_POWER_REGISTER_OPS(ops) \ +RTE_INIT(power_hdlr_init_##ops) \ +{ \ + rte_power_register_ops(&ops); \ +} + +/** + * @internal Get the power ops struct from its index. + * + * @return + * The pointer to the ops struct in the table if registered. + */ +struct rte_power_core_ops * +rte_power_get_core_ops(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/power/version.map b/lib/power/version.map index c9a226614e..a46dd8adbf 100644 --- a/lib/power/version.map +++ b/lib/power/version.map @@ -51,4 +51,18 @@ EXPERIMENTAL { rte_power_set_uncore_env; rte_power_uncore_freqs; rte_power_unset_uncore_env; + # added in 24.11 + rte_power_logtype; +}; + +INTERNAL { + global: + + rte_power_register_ops; + cpufreq_check_scaling_driver; + power_set_governor; + open_core_sysfs_file; + read_core_sysfs_u32; + read_core_sysfs_s; + write_core_sysfs_s; }; From patchwork Tue Oct 8 17:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tummala, Sivaprasad" X-Patchwork-Id: 145485 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D7A0E45AE3; Tue, 8 Oct 2024 19:43:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FFE640E31; Tue, 8 Oct 2024 19:43:43 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) by mails.dpdk.org (Postfix) with ESMTP id 6920440E31 for ; Tue, 8 Oct 2024 19:43:39 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P90PZkLtLETGGP8Wt4djSeOUofcIoQbPzmWZIZN3KBMCJL/ws2XjJ/iVwUyBGMNqLgWx4wJJ8hgcK2Pm8B3NPB1IBUuU8JJ07Fy4oLTkicZ2L+Nx+Rt9UxY5zCgnBe3oDtzx1goVXHW3LUnUavnqqZS9BQjxDadbJ0iQpVNGvp1QWfza8C7bDDut+Apm3CnHE3ssa3tSz+bHsmurj75bh3YkWzttV34WggJZS66KGxk7twlVW702skU3/MSGiSAOaDJsgemEr1WE13NluuAUd72tT4V4BEx8JA37zLSh6Jc+NQlfd1b9L4dCoRr8YlON5f/Ah+DdtEIKegCyuMqPGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=zw+IXN9njfV55vw83YoiVXfgCA2kPCOTiToDf5BzxWc=; b=nYYmEfcoZ0HMICU43BWxQH8Ss29M6xaiKubfxbQbeu1mlLof2ePujjxrtoh/8R1g3RtivOFpN+PlolMelMgmpeyy2oaaUiYD11LVCQyL3dubeb0FvA2m8Ix0Qm3J6iLJkXvRqkjymKJVyGYyL0wWXi/jNG+N5ClyswkVCnWftigY4GQmbMXoClng6edzwJRRdyzekYRAv1by9tDPcytyYMm65DO4Xi3jSmG7Eq5krmVy30dEo50vU21Nf6Dg1YSZM2Hs4c7ppVoXvGgO7qGyjzG719RaKYAyxMNlMNDKDwHX+RddrCeeb1m/zwIzqNFJFJMieDL7bS2DkPVSFRjTmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=zw+IXN9njfV55vw83YoiVXfgCA2kPCOTiToDf5BzxWc=; b=UXskPj+P1wRLrtsuUkOPl+/Kz/epYVhAHrYLAgS4QtwmwR9ZT6+ZAvb4G4Os2Pe+QSwjSyFHCgxLJVDVmIWkxuILSGwoHnl6qcQzc6NpLYPsM5lj1WDnZMw0KFRhIkd86oSV4+4pnlhvlA2hI43In9CtBPgqZvkKhnlZCBANsdk= Received: from BN0PR04CA0047.namprd04.prod.outlook.com (2603:10b6:408:e8::22) by MW4PR12MB7237.namprd12.prod.outlook.com (2603:10b6:303:22a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Tue, 8 Oct 2024 17:43:33 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:408:e8:cafe::a6) by BN0PR04CA0047.outlook.office365.com (2603:10b6:408:e8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23 via Frontend Transport; Tue, 8 Oct 2024 17:43: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 BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.0 via Frontend Transport; Tue, 8 Oct 2024 17:43:32 +0000 Received: from jfw9ny3-os.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; Tue, 8 Oct 2024 12:43:29 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v3 2/5] power: refactor uncore power management library Date: Tue, 8 Oct 2024 17:43:05 +0000 Message-ID: <20241008174309.1133051-3-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008174309.1133051-1-sivaprasad.tummala@amd.com> References: <20241008172719.902619-1-sivaprasad.tummala@amd.com> <20241008174309.1133051-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN3PEPF0000B372:EE_|MW4PR12MB7237:EE_ X-MS-Office365-Filtering-Correlation-Id: 444348e7-a4ba-4ea2-f4ea-08dce7c0ba62 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: E+hWqF43HUtgzRqjvtUOieZeDPIBVbm9gMnAw0ROY//6Kra+fFf4NtlZqnQD9kv/s/iRekql7kO4iyd3kV2zzw86hYMIVQAvNgEU4XGeEo9UPsl3b1bSAvP4l50frOsWg76Pc2xEnZxwgqphNr8q/HwrFiwGERtz+n6mEZQTMvhSm9f8Uo2L6aIkjN7R3OuyLaTU6HMgecOf2YD9F3uDknfaNdZA4CRe1mSetUPvXa+wzVSlxiKZeq4n3cdgZ9aoQGk50Ztd6CdaFYTIw54p8QKFrW1G89TgLYufd9rMa0aDOUwj+zqO1tz3VJ5w9BMVN2hCybhjcKxSesB1fuQhk9xGOdlmB8MdYXph0PAL/HBh4DNlrPpz+pVWhKD0Ows/M2UU1BQWHj0kV9uAISZL8Fh9mRAIMjtpwQ2BbHkESBQo9W0/JzlpP0WtaLVpKLQqNCiaWWe1w8wny1/Qg75GhJJmXHbIGUpOoEP2uMlsfCtXIcerOyHC2139795uk9H8nUz1olK6J3VlPGiGYoUe+y2U9Qcd4wAh8Y+e21vIHlP8A/n5QnayboTYtTl9JyTXyIwwqs3v6NpZrAil507aTSueRFmgRVOBk4kbsJE8Ao/acB0SMsnxZ7PB7gAagqMJTDGGfZ6rru/qoYQZ39IMYaq/8YnKwLPfl6H80X324uSUNGtXNYsYIqGnU1buXDU/5yckivRLRtcrgSYXAfqu8TrTLmBhApuLptzm969iHkM5ubPUv11UJYM8gmkV3oHZeg/HFDTHQ7JFePm8qNeTq3z0dXekzBEhJaR58/abntuN7Tsjqv4w8baWdl73UPgjfSdRBU01ABfQsCseWtWMX4NBa/yX3JbL0eGBxBWfz92SC98oeQPQaiSZImDosmOwWgk1las/DofiZgh0x1IaFZACpkZn/YDJXrqFSOl9rqTQy6vA+GUwytib3Pax2RZiZiMOq+GZyOLDpOERAKWHfCoIZeU74/pjue5QcWohVG6REORyzlSDHKbVn1P26H8piHYbqZY/vpS+Q0RVaO+vVIFxSYaQITklFGjHUkBTKVKb2uIjeoGbHrwIaxdnF4U1vfNewlWLPWBbAuT0/KiICBB/LuSUUT0W/OvbBBojiWlIJ6AxgIWa+W+7orWwysvF9X3fIN80YADoZaKhB7xGYe27aB0CU4/Ow15aQNcdfeRZ6JCoKYLOW6/0Fxn3ZMwyLKvZgy/m17SYcUaYiFs2K5Hc7+cU72uhx+iKhEH7gjxoAVqi+7taz5N7m2vNxm0daR4hZnXnwxFgJ58/olT+D705zoM1sC7dYSyZn9hcbjh+SUXXvWRspLVn8uQI4ogK/c7928+FPUPiIMbm8TFUGKJGMTz3TMAgl6lzPtGhv3q3x6thpLKlMKWdRn5ak+17 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:(13230040)(376014)(36860700013)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 17:43:32.5927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 444348e7-a4ba-4ea2-f4ea-08dce7c0ba62 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: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7237 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch refactors the power management library, addressing uncore power management. The primary changes involve the creation of dedicated directories for each driver within 'drivers/power/uncore/*'. The adjustment of meson.build files enables the selective activation of individual drivers. This refactor significantly improves code organization, enhances clarity and boosts maintainability. It lays the foundation for more focused development on individual drivers and facilitates seamless integration of future enhancements, particularly the AMD uncore driver. v3: - fixed typo in header file inclusion Signed-off-by: Sivaprasad Tummala --- .../power/intel_uncore/intel_uncore.c | 18 +- .../power/intel_uncore/intel_uncore.h | 8 +- drivers/power/intel_uncore/meson.build | 6 + drivers/power/meson.build | 3 +- lib/power/meson.build | 2 +- lib/power/rte_power_uncore.c | 206 ++++++--------- lib/power/rte_power_uncore.h | 87 ++++--- lib/power/rte_power_uncore_ops.h | 239 ++++++++++++++++++ lib/power/version.map | 1 + 9 files changed, 405 insertions(+), 165 deletions(-) rename lib/power/power_intel_uncore.c => drivers/power/intel_uncore/intel_uncore.c (95%) rename lib/power/power_intel_uncore.h => drivers/power/intel_uncore/intel_uncore.h (97%) create mode 100644 drivers/power/intel_uncore/meson.build create mode 100644 lib/power/rte_power_uncore_ops.h diff --git a/lib/power/power_intel_uncore.c b/drivers/power/intel_uncore/intel_uncore.c similarity index 95% rename from lib/power/power_intel_uncore.c rename to drivers/power/intel_uncore/intel_uncore.c index 4eb9c5900a..804ad5d755 100644 --- a/lib/power/power_intel_uncore.c +++ b/drivers/power/intel_uncore/intel_uncore.c @@ -8,7 +8,7 @@ #include -#include "power_intel_uncore.h" +#include "intel_uncore.h" #include "power_common.h" #define MAX_NUMA_DIE 8 @@ -475,3 +475,19 @@ power_intel_uncore_get_num_dies(unsigned int pkg) return count; } + +static struct rte_power_uncore_ops intel_uncore_ops = { + .name = "intel-uncore", + .init = power_intel_uncore_init, + .exit = power_intel_uncore_exit, + .get_avail_freqs = power_intel_uncore_freqs, + .get_num_pkgs = power_intel_uncore_get_num_pkgs, + .get_num_dies = power_intel_uncore_get_num_dies, + .get_num_freqs = power_intel_uncore_get_num_freqs, + .get_freq = power_get_intel_uncore_freq, + .set_freq = power_set_intel_uncore_freq, + .freq_max = power_intel_uncore_freq_max, + .freq_min = power_intel_uncore_freq_min, +}; + +RTE_POWER_REGISTER_UNCORE_OPS(intel_uncore_ops); diff --git a/lib/power/power_intel_uncore.h b/drivers/power/intel_uncore/intel_uncore.h similarity index 97% rename from lib/power/power_intel_uncore.h rename to drivers/power/intel_uncore/intel_uncore.h index 20a3ba8ebe..f2ce2f0c66 100644 --- a/lib/power/power_intel_uncore.h +++ b/drivers/power/intel_uncore/intel_uncore.h @@ -2,8 +2,8 @@ * Copyright(c) 2022 Intel Corporation */ -#ifndef POWER_INTEL_UNCORE_H -#define POWER_INTEL_UNCORE_H +#ifndef INTEL_UNCORE_H +#define INTEL_UNCORE_H /** * @file @@ -11,7 +11,7 @@ */ #include "rte_power.h" -#include "rte_power_uncore.h" +#include "rte_power_uncore_ops.h" #ifdef __cplusplus extern "C" { @@ -223,4 +223,4 @@ power_intel_uncore_get_num_dies(unsigned int pkg); } #endif -#endif /* POWER_INTEL_UNCORE_H */ +#endif /* INTEL_UNCORE_H */ diff --git a/drivers/power/intel_uncore/meson.build b/drivers/power/intel_uncore/meson.build new file mode 100644 index 0000000000..876df8ad14 --- /dev/null +++ b/drivers/power/intel_uncore/meson.build @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2017 Intel Corporation +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +sources = files('intel_uncore.c') +deps += ['power'] diff --git a/drivers/power/meson.build b/drivers/power/meson.build index 8c7215c639..c83047af94 100644 --- a/drivers/power/meson.build +++ b/drivers/power/meson.build @@ -6,7 +6,8 @@ drivers = [ 'amd_pstate', 'cppc', 'kvm_vm', - 'pstate' + 'pstate', + 'intel_uncore' ] std_deps = ['power'] diff --git a/lib/power/meson.build b/lib/power/meson.build index d6b86ea19c..63616e60fd 100644 --- a/lib/power/meson.build +++ b/lib/power/meson.build @@ -13,7 +13,6 @@ if not is_linux endif sources = files( 'power_common.c', - 'power_intel_uncore.c', 'rte_power.c', 'rte_power_uncore.c', 'rte_power_pmd_mgmt.c', @@ -24,6 +23,7 @@ headers = files( 'rte_power_guest_channel.h', 'rte_power_pmd_mgmt.h', 'rte_power_uncore.h', + 'rte_power_uncore_ops.h', ) if cc.has_argument('-Wno-cast-qual') cflags += '-Wno-cast-qual' diff --git a/lib/power/rte_power_uncore.c b/lib/power/rte_power_uncore.c index 48c75a5da0..0f0b212a90 100644 --- a/lib/power/rte_power_uncore.c +++ b/lib/power/rte_power_uncore.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2014 Intel Corporation * Copyright(c) 2023 AMD Corporation + * Copyright(c) 2024 Advanced Micro Devices, Inc. */ #include @@ -10,100 +11,51 @@ #include "power_common.h" #include "rte_power_uncore.h" -#include "power_intel_uncore.h" -enum rte_uncore_power_mgmt_env default_uncore_env = RTE_UNCORE_PM_ENV_NOT_SET; +static enum rte_uncore_power_mgmt_env global_uncore_env = RTE_UNCORE_PM_ENV_NOT_SET; +static struct rte_power_uncore_ops *global_uncore_ops; static rte_spinlock_t global_env_cfg_lock = RTE_SPINLOCK_INITIALIZER; +static RTE_TAILQ_HEAD(, rte_power_uncore_ops) uncore_ops_list = + TAILQ_HEAD_INITIALIZER(uncore_ops_list); -static uint32_t -power_get_dummy_uncore_freq(unsigned int pkg __rte_unused, - unsigned int die __rte_unused) -{ - return 0; -} - -static int -power_set_dummy_uncore_freq(unsigned int pkg __rte_unused, - unsigned int die __rte_unused, uint32_t index __rte_unused) -{ - return 0; -} +const char *uncore_env_str[] = { + "not set", + "auto-detect", + "intel-uncore", + "amd-hsmp" +}; -static int -power_dummy_uncore_freq_max(unsigned int pkg __rte_unused, - unsigned int die __rte_unused) -{ - return 0; -} - -static int -power_dummy_uncore_freq_min(unsigned int pkg __rte_unused, - unsigned int die __rte_unused) -{ - return 0; -} - -static int -power_dummy_uncore_freqs(unsigned int pkg __rte_unused, unsigned int die __rte_unused, - uint32_t *freqs __rte_unused, uint32_t num __rte_unused) -{ - return 0; -} - -static int -power_dummy_uncore_get_num_freqs(unsigned int pkg __rte_unused, - unsigned int die __rte_unused) +/* register the ops struct in rte_power_uncore_ops, return 0 on success. */ +int +rte_power_register_uncore_ops(struct rte_power_uncore_ops *driver_ops) { - return 0; -} + if (!driver_ops->init || !driver_ops->exit || !driver_ops->get_num_pkgs || + !driver_ops->get_num_dies || !driver_ops->get_num_freqs || + !driver_ops->get_avail_freqs || !driver_ops->get_freq || + !driver_ops->set_freq || !driver_ops->freq_max || + !driver_ops->freq_min) { + POWER_LOG(ERR, "Missing callbacks while registering power ops"); + return -1; + } + if (driver_ops->cb) + driver_ops->cb(); -static unsigned int -power_dummy_uncore_get_num_pkgs(void) -{ - return 0; -} + TAILQ_INSERT_TAIL(&uncore_ops_list, driver_ops, next); -static unsigned int -power_dummy_uncore_get_num_dies(unsigned int pkg __rte_unused) -{ return 0; } - -/* function pointers */ -rte_power_get_uncore_freq_t rte_power_get_uncore_freq = power_get_dummy_uncore_freq; -rte_power_set_uncore_freq_t rte_power_set_uncore_freq = power_set_dummy_uncore_freq; -rte_power_uncore_freq_change_t rte_power_uncore_freq_max = power_dummy_uncore_freq_max; -rte_power_uncore_freq_change_t rte_power_uncore_freq_min = power_dummy_uncore_freq_min; -rte_power_uncore_freqs_t rte_power_uncore_freqs = power_dummy_uncore_freqs; -rte_power_uncore_get_num_freqs_t rte_power_uncore_get_num_freqs = power_dummy_uncore_get_num_freqs; -rte_power_uncore_get_num_pkgs_t rte_power_uncore_get_num_pkgs = power_dummy_uncore_get_num_pkgs; -rte_power_uncore_get_num_dies_t rte_power_uncore_get_num_dies = power_dummy_uncore_get_num_dies; - -static void -reset_power_uncore_function_ptrs(void) -{ - rte_power_get_uncore_freq = power_get_dummy_uncore_freq; - rte_power_set_uncore_freq = power_set_dummy_uncore_freq; - rte_power_uncore_freq_max = power_dummy_uncore_freq_max; - rte_power_uncore_freq_min = power_dummy_uncore_freq_min; - rte_power_uncore_freqs = power_dummy_uncore_freqs; - rte_power_uncore_get_num_freqs = power_dummy_uncore_get_num_freqs; - rte_power_uncore_get_num_pkgs = power_dummy_uncore_get_num_pkgs; - rte_power_uncore_get_num_dies = power_dummy_uncore_get_num_dies; -} - int rte_power_set_uncore_env(enum rte_uncore_power_mgmt_env env) { - int ret; + int ret = -1; + struct rte_power_uncore_ops *ops; rte_spinlock_lock(&global_env_cfg_lock); - if (default_uncore_env != RTE_UNCORE_PM_ENV_NOT_SET) { + if (global_uncore_env != RTE_UNCORE_PM_ENV_NOT_SET) { POWER_LOG(ERR, "Uncore Power Management Env already set."); - rte_spinlock_unlock(&global_env_cfg_lock); - return -1; + goto out; } if (env == RTE_UNCORE_PM_ENV_AUTO_DETECT) @@ -113,23 +65,20 @@ rte_power_set_uncore_env(enum rte_uncore_power_mgmt_env env) */ env = RTE_UNCORE_PM_ENV_INTEL_UNCORE; - ret = 0; - if (env == RTE_UNCORE_PM_ENV_INTEL_UNCORE) { - rte_power_get_uncore_freq = power_get_intel_uncore_freq; - rte_power_set_uncore_freq = power_set_intel_uncore_freq; - rte_power_uncore_freq_min = power_intel_uncore_freq_min; - rte_power_uncore_freq_max = power_intel_uncore_freq_max; - rte_power_uncore_freqs = power_intel_uncore_freqs; - rte_power_uncore_get_num_freqs = power_intel_uncore_get_num_freqs; - rte_power_uncore_get_num_pkgs = power_intel_uncore_get_num_pkgs; - rte_power_uncore_get_num_dies = power_intel_uncore_get_num_dies; - } else { - POWER_LOG(ERR, "Invalid Power Management Environment(%d) set", env); - ret = -1; - goto out; - } + if (env <= RTE_DIM(uncore_env_str)) { + RTE_TAILQ_FOREACH(ops, &uncore_ops_list, next) + if (strncmp(ops->name, uncore_env_str[env], + RTE_POWER_UNCORE_DRIVER_NAMESZ) == 0) { + global_uncore_env = env; + global_uncore_ops = ops; + ret = 0; + goto out; + } + POWER_LOG(ERR, "Power Management (%s) not supported", + uncore_env_str[env]); + } else + POWER_LOG(ERR, "Invalid Power Management Environment"); - default_uncore_env = env; out: rte_spinlock_unlock(&global_env_cfg_lock); return ret; @@ -139,15 +88,22 @@ void rte_power_unset_uncore_env(void) { rte_spinlock_lock(&global_env_cfg_lock); - default_uncore_env = RTE_UNCORE_PM_ENV_NOT_SET; - reset_power_uncore_function_ptrs(); + global_uncore_env = RTE_UNCORE_PM_ENV_NOT_SET; rte_spinlock_unlock(&global_env_cfg_lock); } enum rte_uncore_power_mgmt_env rte_power_get_uncore_env(void) { - return default_uncore_env; + return global_uncore_env; +} + +struct rte_power_uncore_ops * +rte_power_get_uncore_ops(void) +{ + RTE_ASSERT(global_uncore_ops != NULL); + + return global_uncore_ops; } int @@ -155,27 +111,29 @@ rte_power_uncore_init(unsigned int pkg, unsigned int die) { int ret = -1; - switch (default_uncore_env) { - case RTE_UNCORE_PM_ENV_INTEL_UNCORE: - return power_intel_uncore_init(pkg, die); - default: - POWER_LOG(INFO, "Uncore Env isn't set yet!"); - break; - } - - /* Auto detect Environment */ - POWER_LOG(INFO, "Attempting to initialise Intel Uncore power mgmt..."); - ret = power_intel_uncore_init(pkg, die); - if (ret == 0) { - rte_power_set_uncore_env(RTE_UNCORE_PM_ENV_INTEL_UNCORE); - goto out; - } - - if (default_uncore_env == RTE_UNCORE_PM_ENV_NOT_SET) { - POWER_LOG(ERR, "Unable to set Power Management Environment " - "for package %u Die %u", pkg, die); - ret = 0; - } + struct rte_power_uncore_ops *ops; + uint8_t env; + + if ((global_uncore_env != RTE_UNCORE_PM_ENV_NOT_SET) && + (global_uncore_env != RTE_UNCORE_PM_ENV_AUTO_DETECT)) + return global_uncore_ops->init(pkg, die); + + /* Auto Detect Environment */ + RTE_TAILQ_FOREACH(ops, &uncore_ops_list, next) + if (ops) { + POWER_LOG(INFO, + "Attempting to initialise %s power management...", + ops->name); + ret = ops->init(pkg, die); + if (ret == 0) { + for (env = 0; env < RTE_DIM(uncore_env_str); env++) + if (strncmp(ops->name, uncore_env_str[env], + RTE_POWER_UNCORE_DRIVER_NAMESZ) == 0) { + rte_power_set_uncore_env(env); + goto out; + } + } + } out: return ret; } @@ -183,12 +141,12 @@ rte_power_uncore_init(unsigned int pkg, unsigned int die) int rte_power_uncore_exit(unsigned int pkg, unsigned int die) { - switch (default_uncore_env) { - case RTE_UNCORE_PM_ENV_INTEL_UNCORE: - return power_intel_uncore_exit(pkg, die); - default: - POWER_LOG(ERR, "Uncore Env has not been set, unable to exit gracefully"); - break; - } + if ((global_uncore_env != RTE_UNCORE_PM_ENV_NOT_SET) && + global_uncore_ops) + return global_uncore_ops->exit(pkg, die); + + POWER_LOG(ERR, + "Uncore Env has not been set, unable to exit gracefully"); + return -1; } diff --git a/lib/power/rte_power_uncore.h b/lib/power/rte_power_uncore.h index 99859042dd..c9fba02568 100644 --- a/lib/power/rte_power_uncore.h +++ b/lib/power/rte_power_uncore.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2022 Intel Corporation * Copyright(c) 2023 AMD Corporation + * Copyright(c) 2024 Advanced Micro Devices, Inc. */ #ifndef RTE_POWER_UNCORE_H @@ -11,8 +12,7 @@ * RTE Uncore Frequency Management */ -#include -#include "rte_power.h" +#include "rte_power_uncore_ops.h" #ifdef __cplusplus extern "C" { @@ -116,9 +116,13 @@ rte_power_uncore_exit(unsigned int pkg, unsigned int die); * The current index of available frequencies. * If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'. */ -typedef uint32_t (*rte_power_get_uncore_freq_t)(unsigned int pkg, unsigned int die); +static inline uint32_t +rte_power_get_uncore_freq(unsigned int pkg, unsigned int die) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -extern rte_power_get_uncore_freq_t rte_power_get_uncore_freq; + return ops->get_freq(pkg, die); +} /** * Set minimum and maximum uncore frequency for specified die on a package @@ -141,26 +145,13 @@ extern rte_power_get_uncore_freq_t rte_power_get_uncore_freq; * - 0 on success without frequency changed. * - Negative on error. */ -typedef int (*rte_power_set_uncore_freq_t)(unsigned int pkg, unsigned int die, uint32_t index); - -extern rte_power_set_uncore_freq_t rte_power_set_uncore_freq; +static inline uint32_t +rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -/** - * Function pointer definition for generic frequency change functions. - * - * @param pkg - * Package number. - * Each physical CPU in a system is referred to as a package. - * @param die - * Die number. - * Each package can have several dies connected together via the uncore mesh. - * - * @return - * - 1 on success with frequency changed. - * - 0 on success without frequency changed. - * - Negative on error. - */ -typedef int (*rte_power_uncore_freq_change_t)(unsigned int pkg, unsigned int die); + return ops->set_freq(pkg, die, index); +} /** * Set minimum and maximum uncore frequency for specified die on a package @@ -169,7 +160,13 @@ typedef int (*rte_power_uncore_freq_change_t)(unsigned int pkg, unsigned int die * * This function should NOT be called in the fast path. */ -extern rte_power_uncore_freq_change_t rte_power_uncore_freq_max; +static inline uint32_t +rte_power_uncore_freq_max(unsigned int pkg, unsigned int die) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); + + return ops->freq_max(pkg, die); +} /** * Set minimum and maximum uncore frequency for specified die on a package @@ -178,7 +175,13 @@ extern rte_power_uncore_freq_change_t rte_power_uncore_freq_max; * * This function should NOT be called in the fast path. */ -extern rte_power_uncore_freq_change_t rte_power_uncore_freq_min; +static inline uint32_t +rte_power_uncore_freq_min(unsigned int pkg, unsigned int die) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); + + return ops->freq_min(pkg, die); +} /** * Return the list of available frequencies in the index array. @@ -200,10 +203,14 @@ extern rte_power_uncore_freq_change_t rte_power_uncore_freq_min; * - The number of available index's in frequency array. * - Negative on error. */ -typedef int (*rte_power_uncore_freqs_t)(unsigned int pkg, unsigned int die, - uint32_t *freqs, uint32_t num); +static inline uint32_t +rte_power_uncore_freqs(unsigned int pkg, unsigned int die, + uint32_t *freqs, uint32_t num) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -extern rte_power_uncore_freqs_t rte_power_uncore_freqs; + return ops->get_avail_freqs(pkg, die, freqs, num); +} /** * Return the list length of available frequencies in the index array. @@ -221,9 +228,13 @@ extern rte_power_uncore_freqs_t rte_power_uncore_freqs; * - The number of available index's in frequency array. * - Negative on error. */ -typedef int (*rte_power_uncore_get_num_freqs_t)(unsigned int pkg, unsigned int die); +static inline int +rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -extern rte_power_uncore_get_num_freqs_t rte_power_uncore_get_num_freqs; + return ops->get_num_freqs(pkg, die); +} /** * Return the number of packages (CPUs) on a system @@ -235,9 +246,13 @@ extern rte_power_uncore_get_num_freqs_t rte_power_uncore_get_num_freqs; * - Zero on error. * - Number of package on system on success. */ -typedef unsigned int (*rte_power_uncore_get_num_pkgs_t)(void); +static inline unsigned int +rte_power_uncore_get_num_pkgs(void) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -extern rte_power_uncore_get_num_pkgs_t rte_power_uncore_get_num_pkgs; + return ops->get_num_pkgs(); +} /** * Return the number of dies for pakckages (CPUs) specified @@ -253,9 +268,13 @@ extern rte_power_uncore_get_num_pkgs_t rte_power_uncore_get_num_pkgs; * - Zero on error. * - Number of dies for package on sucecss. */ -typedef unsigned int (*rte_power_uncore_get_num_dies_t)(unsigned int pkg); +static inline unsigned int +rte_power_uncore_get_num_dies(unsigned int pkg) +{ + struct rte_power_uncore_ops *ops = rte_power_get_uncore_ops(); -extern rte_power_uncore_get_num_dies_t rte_power_uncore_get_num_dies; + return ops->get_num_dies(pkg); +} #ifdef __cplusplus } diff --git a/lib/power/rte_power_uncore_ops.h b/lib/power/rte_power_uncore_ops.h new file mode 100644 index 0000000000..d0bbffcbf9 --- /dev/null +++ b/lib/power/rte_power_uncore_ops.h @@ -0,0 +1,239 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + * Copyright(c) 2024 Advanced Micro Devices, Inc. + */ + +#ifndef RTE_POWER_UNCORE_OPS_H +#define RTE_POWER_UNCORE_OPS_H + +/** + * @file + * RTE Uncore Frequency Management + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RTE_POWER_UNCORE_DRIVER_NAMESZ 24 + +/** + * Initialize uncore frequency management for specific die on a package. + * It will get the available frequencies and prepare to set new die frequencies. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 0 on success. + * - Negative on error. + */ +typedef int (*rte_power_uncore_init_t)(unsigned int pkg, unsigned int die); + +/** + * Exit uncore frequency management on a specific die on a package. + * It will restore uncore min and* max values to previous values + * before initialization of API. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 0 on success. + * - Negative on error. + */ +typedef int (*rte_power_uncore_exit_t)(unsigned int pkg, unsigned int die); + +/** + * Return the current index of available frequencies of a specific die on a package. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * The current index of available frequencies. + * If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'. + */ +typedef uint32_t (*rte_power_get_uncore_freq_t)(unsigned int pkg, unsigned int die); + +/** + * Set minimum and maximum uncore frequency for specified die on a package + * to specified index value. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * @param index + * The index of available frequencies. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +typedef int (*rte_power_set_uncore_freq_t)(unsigned int pkg, unsigned int die, uint32_t index); + +/** + * Return the list length of available frequencies in the index array. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - The number of available index's in frequency array. + * - Negative on error. + */ +typedef int (*rte_power_uncore_get_num_freqs_t)(unsigned int pkg, unsigned int die); + +/** + * Return the list of available frequencies in the index array. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * @param freqs + * The buffer array to save the frequencies. + * @param num + * The number of frequencies to get. + * + * @return + * - The number of available index's in frequency array. + * - Negative on error. + */ +typedef int (*rte_power_uncore_freqs_t)(unsigned int pkg, unsigned int die, + uint32_t *freqs, uint32_t num); +/** + * Function pointers for generic frequency change functions. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +typedef int (*rte_power_uncore_freq_change_t)(unsigned int pkg, unsigned int die); + +/** + * Return the number of packages (CPUs) on a system + * by parsing the uncore sysfs directory. + * + * This function should NOT be called in the fast path. + * + * @return + * - Zero on error. + * - Number of package on system on success. + */ +typedef unsigned int (*rte_power_uncore_get_num_pkgs_t)(void); + +/** + * Return the number of dies for pakckages (CPUs) specified + * from parsing the uncore sysfs directory. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * + * @return + * - Zero on error. + * - Number of dies for package on sucecss. + */ +typedef unsigned int (*rte_power_uncore_get_num_dies_t)(unsigned int pkg); +typedef void (*rte_power_uncore_driver_cb_t)(void); + +/** Structure defining uncore power operations structure */ +struct rte_power_uncore_ops { + RTE_TAILQ_ENTRY(rte_power_uncore_ops) next; /**< Next in list. */ + char name[RTE_POWER_UNCORE_DRIVER_NAMESZ]; /**< power mgmt driver. */ + rte_power_uncore_driver_cb_t cb; /**< Driver specific callbacks. */ + rte_power_uncore_init_t init; /**< Initialize power management. */ + rte_power_uncore_exit_t exit; /**< Exit power management. */ + rte_power_uncore_get_num_pkgs_t get_num_pkgs; + rte_power_uncore_get_num_dies_t get_num_dies; + rte_power_uncore_get_num_freqs_t get_num_freqs; /**< Number of available frequencies. */ + rte_power_uncore_freqs_t get_avail_freqs; /**< Get the available frequencies. */ + rte_power_get_uncore_freq_t get_freq; /**< Get frequency index. */ + rte_power_set_uncore_freq_t set_freq; /**< Set frequency index. */ + rte_power_uncore_freq_change_t freq_max; /**< Scale up frequency to highest. */ + rte_power_uncore_freq_change_t freq_min; /**< Scale up frequency to lowest. */ +}; + +/** + * Register power uncore frequency operations. + * @param ops + * Pointer to an ops structure to register. + * @return + * - >=0: Success; return the index of the ops struct in the table. + * - -EINVAL - error while registering ops struct. + */ +__rte_internal +int rte_power_register_uncore_ops(struct rte_power_uncore_ops *ops); + +/** + * Macro to statically register the ops of an uncore driver. + */ +#define RTE_POWER_REGISTER_UNCORE_OPS(ops) \ +RTE_INIT(power_hdlr_init_uncore_##ops) \ +{ \ + rte_power_register_uncore_ops(&ops); \ +} + +/** + * @internal Get the power uncore ops struct from its index. + * + * @return + * The pointer to the ops struct in the table if registered. + */ +struct rte_power_uncore_ops * +rte_power_get_uncore_ops(void); + +#ifdef __cplusplus +} +#endif + +#endif /* RTE_POWER_UNCORE_OPS_H */ diff --git a/lib/power/version.map b/lib/power/version.map index a46dd8adbf..7c9aece813 100644 --- a/lib/power/version.map +++ b/lib/power/version.map @@ -59,6 +59,7 @@ INTERNAL { global: rte_power_register_ops; + rte_power_register_uncore_ops; cpufreq_check_scaling_driver; power_set_governor; open_core_sysfs_file; From patchwork Tue Oct 8 17:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tummala, Sivaprasad" X-Patchwork-Id: 145484 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4D3E745AE3; Tue, 8 Oct 2024 19:43:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8C6040E09; Tue, 8 Oct 2024 19:43:41 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) by mails.dpdk.org (Postfix) with ESMTP id 3488740DF6 for ; Tue, 8 Oct 2024 19:43:39 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ORyi/VASwLKLhHS2FwBkN3mRSTm6OdKZi/tq45CKfDjUpcW1/9qSnRFIbeCu2981XZ+c3x3nLgS2ZST4b/SNBNfkym+qlIQhz6FALnbctge0g3XCLmMIr638KqFY3zp362baJJbK0HezS8e16ZM6LQZvxnkJDO3ZJW8fog/v04avZxTKJ4slbQiV+HgvN3tzgOPbAahJcUfJxqRRCrrrzQRGEblSk5txVETZpqXpqS7uq7y0drLo2aFkDrbokEUJqWcmz7RjmNcveeddFE6kdNlG+E/eqR/br58Tpz+j5wa2TROZq/tWo0xKfcWOSzKMDgC0uewKfUaTbM6Dj2gJTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=l9CAsKWfalPHzN4JTj01lLBSxrkkNvX4zoltm9rUe2Y=; b=a/l11avgersTT3lgH8yZeIOS4QEgd7Mi8qn2DVnmhx4W3V6DisF2lzc59XUPJUU9gEYw60xupvctfP2KHiHK4zOswjWq3T1yhSBs1Q71gH/czEI/jw6lLHM9Z3u9/C9hbnt8exZk8n23W75FODoQV6JvK+4uFgR7Y37G4JdK/fdQ/uA83axnS1M6feTgcqFT5V8iGbXwfiveSa/IVXgo+2oSteMY92u9H1/8NdIW2ou7lQ3JApPAM8GQ+IhUsLTEzHQHSR/e5oM3ogCKv+cC32GFn6yYoapGHp7qH1zpFMLGuavHKPxL/+o12gGutSV8krXPiww5481BUsg3EktYeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=l9CAsKWfalPHzN4JTj01lLBSxrkkNvX4zoltm9rUe2Y=; b=Nh0b99ZInfnqAvfHPCBFd40tMf3ryanxzBsRuILMwUE531S6nC0cxMfttvI0K2iDpMgPzQj34gSxNeEsDGcyq87tQi5xJqVCDBMir71dIhTrXqkbKftX25AWs0cO1QeGn6xWUryBKORTcEQc5XVmDqaL9l6oWlQOlDlO2ip1sFM= Received: from BN1PR12CA0012.namprd12.prod.outlook.com (2603:10b6:408:e1::17) by IA1PR12MB6457.namprd12.prod.outlook.com (2603:10b6:208:3ab::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Tue, 8 Oct 2024 17:43:35 +0000 Received: from BN3PEPF0000B371.namprd21.prod.outlook.com (2603:10b6:408:e1:cafe::db) by BN1PR12CA0012.outlook.office365.com (2603:10b6:408:e1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.24 via Frontend Transport; Tue, 8 Oct 2024 17:43:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B371.mail.protection.outlook.com (10.167.243.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.0 via Frontend Transport; Tue, 8 Oct 2024 17:43:35 +0000 Received: from jfw9ny3-os.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; Tue, 8 Oct 2024 12:43:32 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v3 3/5] test/power: removed function pointer validations Date: Tue, 8 Oct 2024 17:43:06 +0000 Message-ID: <20241008174309.1133051-4-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008174309.1133051-1-sivaprasad.tummala@amd.com> References: <20241008172719.902619-1-sivaprasad.tummala@amd.com> <20241008174309.1133051-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN3PEPF0000B371:EE_|IA1PR12MB6457:EE_ X-MS-Office365-Filtering-Correlation-Id: 71a6c4d3-7372-4bca-4dbc-08dce7c0bc04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: RIADHU+vyFpdJHNCIghNffA1pRgXNJSPet9jvdVu0d6EUFLwMlCEkXyflWUpquSmcV1i/AfYSMqQe+diuF8kNZdB4QQ6RF4K8Smr4JLZYIGrIklo6mXkUrNKF9EMrCYqVIZzonFyRyFyCnZpsV4R8K3h9smwp/iXsLSv3TKbG57UiLRRxwSBLTRyUdqxWU/ISeFiMX7lmL1015ltrc6bMRc0+qKd/kK4rSQ9gs27BiwFUdz7aLTjx2AkTG/5nYSsugQoNSlRtnHs6O/O7BsBHMFIEFJgTbANE8ppfIZZV2ack9j/La/07FXCssSx1L8odUCfvSUeH46+PhnE5V/qMrpqXSBTzOgvNcBwBSkYgwuiSIsQjykAPH4rZQ28jeF8CckvT/hZ9j4lzstJltTYluItbxwb1a3COVR1Mj9pAZXOGqmV7K3zttM+vza0nM8t95K86aTyPutXXNh0Q0lW/xYNN5dX50l9LUw2mDJ06c1XxgbNWfGf18Wny2apFKqwj+lVPZJg2aQwgJkkpJBOHn7D5NeSeDEB3bmi/41W0m0l5Rk5wm9VbkSA/sokmcSX+qS7kVswLbszS9vVsRpisdv61m6lSm5Lk5OFHxURS+Ofvk/9TV36yz3Ts43LiUq1UOFU1L862cWGumQWdOadL86HFsAsCAR+N2iSRLFn/vmBvqe6E8hHYv5tWBLAuyn6Cd6TT/BbVXj10VZiG0WMFdBi1B7fJH2ChZgtrKcZCDLEyJz+tI8wbQeYiIO7V2FVJgd6AdxO5TboXpxCI4bJvx1F6FrhkjnA5t2kjs3cy/kjuRa604uMZa63EC/ZaPgZnP6KM3o2lPR1e//pAtUmN1uxHWRjhYulYukB4L/mojWB0p4nsWqjs7adE/7fMJeRg/ID1SH4GdeIzW/920ynXL73j0oBxBSBCAKHneDcsZFG6TLJKNbi93a43/KfJO5ko2ECoONE//VxTAa960oLy4Qwyxr1S18cOBU2FypOv+MYR8dYG69QsE6MNzMhJS07Hwz6T6UtJMh2LTT1auED1CBuVUcfRQTSZCWpilVeHTK0wpSYaWtYKdGJABA6XMjyv/SuG1CxUS/ZmCUNKwNzzM7R403ACF+rq5TlKm50wInmkDU18mT6u+4JWP03eQf7jqWeiklVBbZckbM1Y/MCGxUYIBuP777xhp7MmVdjH1vmpUUT/cG/iuk5w/ko9PBgGdjZb981m+RpsjJESzGltq90tFbg/l/VQVIbfP9THLHID0CgX6bGGQvzsxKzqMFVFj8ETMI3OWqfUkb2cZLG9VmtqZ1+eINrKXafPGi6ZQxX+CUW9Skbf1j7Jge+DdIJ5ryoXvYkYuzMjdC0Fb2/nqOB36kcQ4rmvVmJRPX8deXKUUm/TAdnj3KkVMmUaKSY 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:(13230040)(36860700013)(1800799024)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 17:43:35.3122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71a6c4d3-7372-4bca-4dbc-08dce7c0bc04 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: BN3PEPF0000B371.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6457 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org After refactoring the power library, power management operations are now consistently supported regardless of the operating environment, making function pointer checks unnecessary and thus removed from applications. v2: - removed function pointer validation in l3fwd-power app. Signed-off-by: Sivaprasad Tummala --- app/test/test_power.c | 95 ----------------------------------- app/test/test_power_cpufreq.c | 52 ------------------- app/test/test_power_kvm_vm.c | 36 ------------- examples/l3fwd-power/main.c | 12 ++--- 4 files changed, 4 insertions(+), 191 deletions(-) diff --git a/app/test/test_power.c b/app/test/test_power.c index 403adc22d6..5df5848c70 100644 --- a/app/test/test_power.c +++ b/app/test/test_power.c @@ -24,86 +24,6 @@ test_power(void) #include -static int -check_function_ptrs(void) -{ - enum power_management_env env = rte_power_get_env(); - - const bool not_null_expected = !(env == PM_ENV_NOT_SET); - - const char *inject_not_string1 = not_null_expected ? " not" : ""; - const char *inject_not_string2 = not_null_expected ? "" : " not"; - - if ((rte_power_freqs == NULL) == not_null_expected) { - printf("rte_power_freqs should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_get_freq == NULL) == not_null_expected) { - printf("rte_power_get_freq should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_set_freq == NULL) == not_null_expected) { - printf("rte_power_set_freq should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_up == NULL) == not_null_expected) { - printf("rte_power_freq_up should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_down == NULL) == not_null_expected) { - printf("rte_power_freq_down should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_max == NULL) == not_null_expected) { - printf("rte_power_freq_max should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_min == NULL) == not_null_expected) { - printf("rte_power_freq_min should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_turbo_status == NULL) == not_null_expected) { - printf("rte_power_turbo_status should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_enable_turbo == NULL) == not_null_expected) { - printf("rte_power_freq_enable_turbo should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_freq_disable_turbo == NULL) == not_null_expected) { - printf("rte_power_freq_disable_turbo should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - if ((rte_power_get_capabilities == NULL) == not_null_expected) { - printf("rte_power_get_capabilities should%s be NULL, environment has%s been " - "initialised\n", inject_not_string1, - inject_not_string2); - return -1; - } - - return 0; -} - static int test_power(void) { @@ -124,10 +44,6 @@ test_power(void) return -1; } - /* Verify that function pointers are NULL */ - if (check_function_ptrs() < 0) - goto fail_all; - rte_power_unset_env(); /* Perform tests for valid environments.*/ @@ -154,22 +70,11 @@ test_power(void) return -1; } - /* Verify that function pointers are NOT NULL */ - if (check_function_ptrs() < 0) - goto fail_all; - rte_power_unset_env(); - /* Verify that function pointers are NULL */ - if (check_function_ptrs() < 0) - goto fail_all; - } return 0; -fail_all: - rte_power_unset_env(); - return -1; } #endif diff --git a/app/test/test_power_cpufreq.c b/app/test/test_power_cpufreq.c index 619b2811c6..8cb67e662c 100644 --- a/app/test/test_power_cpufreq.c +++ b/app/test/test_power_cpufreq.c @@ -519,58 +519,6 @@ test_power_cpufreq(void) goto fail_all; } - /* verify that function pointers are not NULL */ - if (rte_power_freqs == NULL) { - printf("rte_power_freqs should not be NULL, environment has not been " - "initialised\n"); - goto fail_all; - } - if (rte_power_get_freq == NULL) { - printf("rte_power_get_freq should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_set_freq == NULL) { - printf("rte_power_set_freq should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_up == NULL) { - printf("rte_power_freq_up should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_down == NULL) { - printf("rte_power_freq_down should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_max == NULL) { - printf("rte_power_freq_max should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_min == NULL) { - printf("rte_power_freq_min should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_turbo_status == NULL) { - printf("rte_power_turbo_status should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_enable_turbo == NULL) { - printf("rte_power_freq_enable_turbo should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - if (rte_power_freq_disable_turbo == NULL) { - printf("rte_power_freq_disable_turbo should not be NULL, environment has not " - "been initialised\n"); - goto fail_all; - } - ret = rte_power_exit(TEST_POWER_LCORE_ID); if (ret < 0) { printf("Cannot exit power management for lcore %u\n", diff --git a/app/test/test_power_kvm_vm.c b/app/test/test_power_kvm_vm.c index 464e06002e..a7d104e973 100644 --- a/app/test/test_power_kvm_vm.c +++ b/app/test/test_power_kvm_vm.c @@ -47,42 +47,6 @@ test_power_kvm_vm(void) return -1; } - /* verify that function pointers are not NULL */ - if (rte_power_freqs == NULL) { - printf("rte_power_freqs should not be NULL, environment has not been " - "initialised\n"); - return -1; - } - if (rte_power_get_freq == NULL) { - printf("rte_power_get_freq should not be NULL, environment has not " - "been initialised\n"); - return -1; - } - if (rte_power_set_freq == NULL) { - printf("rte_power_set_freq should not be NULL, environment has not " - "been initialised\n"); - return -1; - } - if (rte_power_freq_up == NULL) { - printf("rte_power_freq_up should not be NULL, environment has not " - "been initialised\n"); - return -1; - } - if (rte_power_freq_down == NULL) { - printf("rte_power_freq_down should not be NULL, environment has not " - "been initialised\n"); - return -1; - } - if (rte_power_freq_max == NULL) { - printf("rte_power_freq_max should not be NULL, environment has not " - "been initialised\n"); - return -1; - } - if (rte_power_freq_min == NULL) { - printf("rte_power_freq_min should not be NULL, environment has not " - "been initialised\n"); - return -1; - } /* Test initialisation of an out of bounds lcore */ ret = rte_power_init(TEST_POWER_VM_LCORE_OUT_OF_BOUNDS); if (ret != -1) { diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index 2bb6b092c3..6bd76515e6 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -440,8 +440,7 @@ power_timer_cb(__rte_unused struct rte_timer *tim, * check whether need to scale down frequency a step if it sleep a lot. */ if (sleep_time_ratio >= SCALING_DOWN_TIME_RATIO_THRESHOLD) { - if (rte_power_freq_down) - rte_power_freq_down(lcore_id); + rte_power_freq_down(lcore_id); } else if ( (unsigned)(stats[lcore_id].nb_rx_processed / stats[lcore_id].nb_iteration_looped) < MAX_PKT_BURST) { @@ -449,8 +448,7 @@ power_timer_cb(__rte_unused struct rte_timer *tim, * scale down a step if average packet per iteration less * than expectation. */ - if (rte_power_freq_down) - rte_power_freq_down(lcore_id); + rte_power_freq_down(lcore_id); } /** @@ -1344,11 +1342,9 @@ main_legacy_loop(__rte_unused void *dummy) } if (lcore_scaleup_hint == FREQ_HIGHEST) { - if (rte_power_freq_max) - rte_power_freq_max(lcore_id); + rte_power_freq_max(lcore_id); } else if (lcore_scaleup_hint == FREQ_HIGHER) { - if (rte_power_freq_up) - rte_power_freq_up(lcore_id); + rte_power_freq_up(lcore_id); } } else { /** From patchwork Tue Oct 8 17:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tummala, Sivaprasad" X-Patchwork-Id: 145486 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9C21B45AE3; Tue, 8 Oct 2024 19:44:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DD18140E72; Tue, 8 Oct 2024 19:43:44 +0200 (CEST) Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2040.outbound.protection.outlook.com [40.107.100.40]) by mails.dpdk.org (Postfix) with ESMTP id DF40640E09 for ; Tue, 8 Oct 2024 19:43:40 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tq8I2qsGqScSy1UKdWiBwFJ7Gd0BAhlT4LcLAjnhYZX5plUlHioPGNyVKVRK2wWbGABpxozd9JQgezTCQEaTlVeXipVTHEk9Rh8SQ6/+/Kjwpc4zKn29CJG9EdeO8QWQjUn3ehQKDFcNLt+fzM+qVSrMpP2RHHkKjd3rnkEnkdKUqAIJehCtsdJCfc0KY8pIj4k6zQLYjYsDEYexDWr3FDvYzofd/m8NxeR/Fd/wnTLOz/rTV919HaVkADvSnpCHGclwc6s41oMsjoJG8LR6B+Z0HXmsgZiaqv25/V1slFofDDe3Z6kl418Aetga+zHlVcmlwk4TZ+mo24sl9+pMbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=npUphsXEQgYWZ4OC39eMsZ4CeK+kCOf8colD135v1hc=; b=ZKKSEZdbD+W7KRw9SzJLTOLm4c59E6ikwC3urevuWo98EVK44uYcN9t39CVQGW9weNWU0j6JTO8BhTNLJZ6BrbCa7bK+pAHsjmQtDYv3tu0SJRdnbFqy8SpH+QVac+T11b0GrRRnrxLz6/SX0khRfFfim3igZ4iFjH1nt/0yykIf3T+AY+Ap2lhRPpMkvEfQ2WbEwusPkb0f7tgp+3sk6Fe2WbzwPPxhcwtUff/GTgLkKZDhoB790ddju64OHXwlwrK/pGGYX4WMfpqMHera4YFBNNwwJvWcQgcljyKIyOfddYQF2vLHCt2ID1ZrE1Tx+rIAsy1bK/UpYT3m+uSD7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=npUphsXEQgYWZ4OC39eMsZ4CeK+kCOf8colD135v1hc=; b=UHOQf6sZ6H6S8KdTBFWFPYEFAxNnxb7ef2COUsfZNJyX+9eRyQK/ljMq3nVC4ceuy2wNKTmjmGhNKOKCXAlDMJRP4FpJDMTaYiqkoBfNuoDyu4c/wSZtTEx8QljMBAI0FDeJJTeq3Ev7D1TlAyZmTpwGu3Y77uO8rL488W5F5ak= Received: from BN0PR04CA0040.namprd04.prod.outlook.com (2603:10b6:408:e8::15) by LV3PR12MB9167.namprd12.prod.outlook.com (2603:10b6:408:196::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Tue, 8 Oct 2024 17:43:38 +0000 Received: from BN3PEPF0000B372.namprd21.prod.outlook.com (2603:10b6:408:e8:cafe::df) by BN0PR04CA0040.outlook.office365.com (2603:10b6:408:e8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Tue, 8 Oct 2024 17:43:38 +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 BN3PEPF0000B372.mail.protection.outlook.com (10.167.243.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.0 via Frontend Transport; Tue, 8 Oct 2024 17:43:38 +0000 Received: from jfw9ny3-os.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; Tue, 8 Oct 2024 12:43:35 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v3 4/5] power/amd_uncore: uncore support for AMD EPYC processors Date: Tue, 8 Oct 2024 17:43:07 +0000 Message-ID: <20241008174309.1133051-5-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008174309.1133051-1-sivaprasad.tummala@amd.com> References: <20241008172719.902619-1-sivaprasad.tummala@amd.com> <20241008174309.1133051-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN3PEPF0000B372:EE_|LV3PR12MB9167:EE_ X-MS-Office365-Filtering-Correlation-Id: 51131759-686c-40af-6d69-08dce7c0bda5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: RTCYKemYhOyy0O1ELh5wdwbYYiQmq2r9a4BvEdKo3b9dbfuiZLb8HH7BP9J40iStWwLLgf3zRQv+BGqEcgcIHBBA00kBxpDiKIEwo7z0iYKhYcPr3osVNbFDAbjBVj3QS7cGeqT1G6f2WG+A9yPoOafLeVt+rxdMlNddFen9RbLbw15ZLLbO1IqrDN5nAC2veZ3VJVCejt97lHdxA9F2EIyUHPueX2SuYOslwU3yqzFo6X4rry2g6bvcJox38qL2zHjrb8KBQ/NyIskYECJQecRteUE9WKkUSWMTqfySoAp+NAsZaLoV3FzjhqQTS+6dzoqpJN5Um8V3137a6PKTAG8k85XZ26p0t7DH5u494xJCmDEnaUi636+/WMqlRz/RJkdqf4gP5LAIoCXw7Gz+3HnSjVuRwLrP2RCmNDjQlclW/rUyVr76dwzjuz7eblJtu99pmK/GhnBvJK9DmAukQ4Y5bq++ad8y3vdvpX2WtyLM+ghfamEg/nopLV4gI9Wyob5huB4yDWPO21uqv4QMhirNqVIcV4mYvicOzRH+jA7f61WZLTmCVSxze+fdVtQxFaxllePNx+SYMKlpb0c7JACzydMRrxHNRXsGhJmew20HUn2TntR+CREu9xbMSQrvDjoPa9AKW41xRKkzzcQvSneyJWjEYUV09nh+C1KjlT11/4My7mEs6Q1ekWyVaYsu3dusDtvLoJc/AfEOtyo5lpPp81akVKVcbITQds9y1OZPpX9p9pX5UrcsXKk2ex0w2riRMO9SrvqmkhWK4ZLF0ESVL+kIUXA2feQyfiJ+SEKdR1EUvlD8xAYODFqujrVLcHZbmGN/mDYXPtxZi75nEcMHWp9eDr7NrmkxhzZWZWN+6lwG5QbbbbDRf0VUpXCK3T1yBT3ydId2A46tCqhUAsVgdx5zb3NIJRW0/biBjyAsQafwSVGdYzC1S0PiyIuFNiEKawXHTzCyLKRbIP1NjKn+tgBieEvt0cSQlwZAEOWJwtbcfdo4cN6gcaL6uQ8+OMOXwT622ATTqyKA1k3u/B6SbW0MNQ41BceB40PTobrKpuTcCit62DCU9+CmIcKB+0bmI1T8paWcuMwTH6i0UxXmn9ew3hMqay4BPeC7jqk7LZioVemHMhMNWDYvnaZDIN+OElHaIh77wTHqjIkf2U5mpAUWJChpeSSC8bshzV3M7nyZ2mqunmNK/sf+IOyDvwYF+UfWyH7G27IYViFyqjT3fyZUCc4aaEyNOs1pUlaX0DKHnR+TdJ4bfQt884j2FylneVXQZbUkoKlxCnmeoxYoj3gNsBcA5DLY1/dv9ufmFeWTdwaOPGYpuHq6G5VPW831eokVDZzOkuH67f6UgzGyKp8AEDpstpzxcjzqxWUnZlLiT0HldYKoe9fvZvcV 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:(13230040)(36860700013)(82310400026)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 17:43:38.0458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 51131759-686c-40af-6d69-08dce7c0bda5 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: BN3PEPF0000B372.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9167 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch introduces driver support for power management of uncore components in AMD EPYC processors. v2: - fixed typo in comments section. - added fabric frequency get support for legacy platforms. Signed-off-by: Sivaprasad Tummala --- drivers/power/amd_uncore/amd_uncore.c | 329 ++++++++++++++++++++++++++ drivers/power/amd_uncore/amd_uncore.h | 226 ++++++++++++++++++ drivers/power/amd_uncore/meson.build | 20 ++ drivers/power/meson.build | 1 + 4 files changed, 576 insertions(+) create mode 100644 drivers/power/amd_uncore/amd_uncore.c create mode 100644 drivers/power/amd_uncore/amd_uncore.h create mode 100644 drivers/power/amd_uncore/meson.build diff --git a/drivers/power/amd_uncore/amd_uncore.c b/drivers/power/amd_uncore/amd_uncore.c new file mode 100644 index 0000000000..c3e95cdc08 --- /dev/null +++ b/drivers/power/amd_uncore/amd_uncore.c @@ -0,0 +1,329 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Advanced Micro Devices, Inc. + */ + +#include +#include +#include + +#include + +#include "amd_uncore.h" +#include "power_common.h" +#include "e_smi/e_smi.h" + +#define MAX_NUMA_DIE 8 + +struct __rte_cache_aligned uncore_power_info { + unsigned int die; /* Core die id */ + unsigned int pkg; /* Package id */ + uint32_t freqs[RTE_MAX_UNCORE_FREQS]; /* Frequency array */ + uint32_t nb_freqs; /* Number of available freqs */ + uint32_t curr_idx; /* Freq index in freqs array */ + uint32_t max_freq; /* System max uncore freq */ + uint32_t min_freq; /* System min uncore freq */ +}; + +static struct uncore_power_info uncore_info[RTE_MAX_NUMA_NODES][MAX_NUMA_DIE]; +static int esmi_initialized; +static unsigned int hsmp_proto_ver; + +static int +set_uncore_freq_internal(struct uncore_power_info *ui, uint32_t idx) +{ + int ret; + + if (idx >= RTE_MAX_UNCORE_FREQS || idx >= ui->nb_freqs) { + POWER_LOG(DEBUG, "Invalid uncore frequency index %u, which " + "should be less than %u", idx, ui->nb_freqs); + return -1; + } + + ret = esmi_apb_disable(ui->pkg, idx); + if (ret != ESMI_SUCCESS) { + POWER_LOG(ERR, "DF P-state '%u' set failed for pkg %02u", + idx, ui->pkg); + return -1; + } + + POWER_DEBUG_LOG("DF P-state '%u' to be set for pkg %02u die %02u", + idx, ui->pkg, ui->die); + + /* write the minimum value first if the target freq is less than current max */ + ui->curr_idx = idx; + + return 0; +} + +static int +power_init_for_setting_uncore_freq(struct uncore_power_info *ui) +{ + switch (hsmp_proto_ver) { + case HSMP_PROTO_VER5: + ui->max_freq = 1800000; /* Hz */ + ui->min_freq = 1200000; /* Hz */ + break; + case HSMP_PROTO_VER2: + default: + ui->max_freq = 1600000; /* Hz */ + ui->min_freq = 1200000; /* Hz */ + } + + return 0; +} + +/* + * Get the available uncore frequencies of the specific die. + */ +static int +power_get_available_uncore_freqs(struct uncore_power_info *ui) +{ + ui->nb_freqs = 3; + if (ui->nb_freqs >= RTE_MAX_UNCORE_FREQS) { + POWER_LOG(ERR, "Too many available uncore frequencies: %d", + ui->nb_freqs); + return -1; + } + + /* Generate the uncore freq bucket array. */ + switch (hsmp_proto_ver) { + case HSMP_PROTO_VER5: + ui->freqs[0] = 1800000; + ui->freqs[1] = 1440000; + ui->freqs[2] = 1200000; + break; + case HSMP_PROTO_VER2: + default: + ui->freqs[0] = 1600000; + ui->freqs[1] = 1333000; + ui->freqs[2] = 1200000; + } + + POWER_DEBUG_LOG("%d frequency(s) of pkg %02u die %02u are available", + ui->num_uncore_freqs, ui->pkg, ui->die); + + return 0; +} + +static int +check_pkg_die_values(unsigned int pkg, unsigned int die) +{ + unsigned int max_pkgs, max_dies; + max_pkgs = power_amd_uncore_get_num_pkgs(); + if (max_pkgs == 0) + return -1; + if (pkg >= max_pkgs) { + POWER_LOG(DEBUG, "Package number %02u can not exceed %u", + pkg, max_pkgs); + return -1; + } + + max_dies = power_amd_uncore_get_num_dies(pkg); + if (max_dies == 0) + return -1; + if (die >= max_dies) { + POWER_LOG(DEBUG, "Die number %02u can not exceed %u", + die, max_dies); + return -1; + } + + return 0; +} + +static void +power_amd_uncore_esmi_init(void) +{ + if (esmi_init() == ESMI_SUCCESS) { + if (esmi_hsmp_proto_ver_get(&hsmp_proto_ver) == + ESMI_SUCCESS) + esmi_initialized = 1; + } +} + +int +power_amd_uncore_init(unsigned int pkg, unsigned int die) +{ + struct uncore_power_info *ui; + int ret; + + if (!esmi_initialized) { + ret = esmi_init(); + if (ret != ESMI_SUCCESS) { + POWER_LOG(DEBUG, "ESMI Not initialized, drivers not found"); + return -1; + } + ret = esmi_hsmp_proto_ver_get(&hsmp_proto_ver); + if (ret != ESMI_SUCCESS) { + POWER_LOG(DEBUG, "HSMP Proto Version Get failed with " + "error %s", esmi_get_err_msg(ret)); + esmi_exit(); + return -1; + } + esmi_initialized = 1; + } + + ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + ui = &uncore_info[pkg][die]; + ui->die = die; + ui->pkg = pkg; + + /* Init for setting uncore die frequency */ + if (power_init_for_setting_uncore_freq(ui) < 0) { + POWER_LOG(DEBUG, "Cannot init for setting uncore frequency for " + "pkg %02u die %02u", pkg, die); + return -1; + } + + /* Get the available frequencies */ + if (power_get_available_uncore_freqs(ui) < 0) { + POWER_LOG(DEBUG, "Cannot get available uncore frequencies of " + "pkg %02u die %02u", pkg, die); + return -1; + } + + return 0; +} + +int +power_amd_uncore_exit(unsigned int pkg, unsigned int die) +{ + struct uncore_power_info *ui; + + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + ui = &uncore_info[pkg][die]; + ui->nb_freqs = 0; + + if (esmi_initialized) { + esmi_exit(); + esmi_initialized = 0; + } + + return 0; +} + +uint32_t +power_get_amd_uncore_freq(unsigned int pkg, unsigned int die) +{ + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + return uncore_info[pkg][die].curr_idx; +} + +int +power_set_amd_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index) +{ + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + return set_uncore_freq_internal(&(uncore_info[pkg][die]), index); +} + +int +power_amd_uncore_freq_max(unsigned int pkg, unsigned int die) +{ + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + return set_uncore_freq_internal(&(uncore_info[pkg][die]), 0); +} + + +int +power_amd_uncore_freq_min(unsigned int pkg, unsigned int die) +{ + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + struct uncore_power_info *ui = &uncore_info[pkg][die]; + + return set_uncore_freq_internal(&(uncore_info[pkg][die]), ui->nb_freqs - 1); +} + +int +power_amd_uncore_freqs(unsigned int pkg, unsigned int die, uint32_t *freqs, uint32_t num) +{ + struct uncore_power_info *ui; + + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + if (freqs == NULL) { + POWER_LOG(ERR, "NULL buffer supplied"); + return 0; + } + + ui = &uncore_info[pkg][die]; + if (num < ui->nb_freqs) { + POWER_LOG(ERR, "Buffer size is not enough"); + return 0; + } + rte_memcpy(freqs, ui->freqs, ui->nb_freqs * sizeof(uint32_t)); + + return ui->nb_freqs; +} + +int +power_amd_uncore_get_num_freqs(unsigned int pkg, unsigned int die) +{ + int ret = check_pkg_die_values(pkg, die); + if (ret < 0) + return -1; + + return uncore_info[pkg][die].nb_freqs; +} + +unsigned int +power_amd_uncore_get_num_pkgs(void) +{ + uint32_t num_pkgs = 0; + int ret; + + if (esmi_initialized) { + ret = esmi_number_of_sockets_get(&num_pkgs); + if (ret != ESMI_SUCCESS) { + POWER_LOG(ERR, "Failed to get number of sockets"); + num_pkgs = 0; + } + } + return num_pkgs; +} + +unsigned int +power_amd_uncore_get_num_dies(unsigned int pkg) +{ + if (pkg >= power_amd_uncore_get_num_pkgs()) { + POWER_LOG(ERR, "Invalid package ID"); + return 0; + } + + return 1; +} + +static struct rte_power_uncore_ops amd_uncore_ops = { + .name = "amd-hsmp", + .cb = power_amd_uncore_esmi_init, + .init = power_amd_uncore_init, + .exit = power_amd_uncore_exit, + .get_avail_freqs = power_amd_uncore_freqs, + .get_num_pkgs = power_amd_uncore_get_num_pkgs, + .get_num_dies = power_amd_uncore_get_num_dies, + .get_num_freqs = power_amd_uncore_get_num_freqs, + .get_freq = power_get_amd_uncore_freq, + .set_freq = power_set_amd_uncore_freq, + .freq_max = power_amd_uncore_freq_max, + .freq_min = power_amd_uncore_freq_min, +}; + +RTE_POWER_REGISTER_UNCORE_OPS(amd_uncore_ops); diff --git a/drivers/power/amd_uncore/amd_uncore.h b/drivers/power/amd_uncore/amd_uncore.h new file mode 100644 index 0000000000..60e0e64d27 --- /dev/null +++ b/drivers/power/amd_uncore/amd_uncore.h @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 Advanced Micro Devices, Inc. + */ + +#ifndef POWER_AMD_UNCORE_H +#define POWER_AMD_UNCORE_H + +/** + * @file + * RTE AMD Uncore Frequency Management + */ + +#include "rte_power.h" +#include "rte_power_uncore.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Initialize uncore frequency management for specific die on a package. + * It will get the available frequencies and prepare to set new die frequencies. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int +power_amd_uncore_init(unsigned int pkg, unsigned int die); + +/** + * Exit uncore frequency management on a specific die on a package. + * It will restore uncore min and* max values to previous values + * before initialization of API. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 0 on success. + * - Negative on error. + */ +int +power_amd_uncore_exit(unsigned int pkg, unsigned int die); + +/** + * Return the current index of available frequencies of a specific die on a package. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * The current index of available frequencies. + * If error, it will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)'. + */ +uint32_t +power_get_amd_uncore_freq(unsigned int pkg, unsigned int die); + +/** + * Set minimum and maximum uncore frequency for specified die on a package + * to specified index value. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * @param index + * The index of available frequencies. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +int +power_set_amd_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index); + +/** + * Set minimum and maximum uncore frequency for specified die on a package + * to maximum value according to the available frequencies. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +int +power_amd_uncore_freq_max(unsigned int pkg, unsigned int die); + +/** + * Set minimum and maximum uncore frequency for specified die on a package + * to minimum value according to the available frequencies. + * It should be protected outside of this function for threadsafe. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - 1 on success with frequency changed. + * - 0 on success without frequency changed. + * - Negative on error. + */ +int +power_amd_uncore_freq_min(unsigned int pkg, unsigned int die); + +/** + * Return the list of available frequencies in the index array. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * @param freqs + * The buffer array to save the frequencies. + * @param num + * The number of frequencies to get. + * + * @return + * - The number of available index's in frequency array. + * - Negative on error. + */ +int +power_amd_uncore_freqs(unsigned int pkg, unsigned int die, + unsigned int *freqs, unsigned int num); + +/** + * Return the list length of available frequencies in the index array. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * @param die + * Die number. + * Each package can have several dies connected together via the uncore mesh. + * + * @return + * - The number of available index's in frequency array. + * - Negative on error. + */ +int +power_amd_uncore_get_num_freqs(unsigned int pkg, unsigned int die); + +/** + * Return the number of packages (CPUs) on a system + * by parsing the uncore sysfs directory. + * + * This function should NOT be called in the fast path. + * + * @return + * - Zero on error. + * - Number of package on system on success. + */ +unsigned int +power_amd_uncore_get_num_pkgs(void); + +/** + * Return the number of dies for pakckages (CPUs) specified + * from parsing the uncore sysfs directory. + * + * This function should NOT be called in the fast path. + * + * @param pkg + * Package number. + * Each physical CPU in a system is referred to as a package. + * + * @return + * - Zero on error. + * - Number of dies for package on sucecss. + */ +unsigned int +power_amd_uncore_get_num_dies(unsigned int pkg); + +#ifdef __cplusplus +} +#endif + +#endif /* POWER_INTEL_UNCORE_H */ diff --git a/drivers/power/amd_uncore/meson.build b/drivers/power/amd_uncore/meson.build new file mode 100644 index 0000000000..8cbab47b01 --- /dev/null +++ b/drivers/power/amd_uncore/meson.build @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Advanced Micro Devices, Inc. + +if not is_linux + build = false + reason = 'only supported on Linux' + subdir_done() +endif + +ESMI_header = '#include' +lib = cc.find_library('e_smi64', required: false) +if not lib.found() + build = false + reason = 'missing dependency, "libe_smi"' +else + ext_deps += lib +endif + +sources = files('amd_uncore.c') +deps += ['power'] diff --git a/drivers/power/meson.build b/drivers/power/meson.build index c83047af94..4ba5954e13 100644 --- a/drivers/power/meson.build +++ b/drivers/power/meson.build @@ -7,6 +7,7 @@ drivers = [ 'cppc', 'kvm_vm', 'pstate', + 'amd_uncore', 'intel_uncore' ] From patchwork Tue Oct 8 17:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tummala, Sivaprasad" X-Patchwork-Id: 145487 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1683145AE3; Tue, 8 Oct 2024 19:44:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2B02340ED9; Tue, 8 Oct 2024 19:43:46 +0200 (CEST) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2070.outbound.protection.outlook.com [40.107.223.70]) by mails.dpdk.org (Postfix) with ESMTP id 7022740E48 for ; Tue, 8 Oct 2024 19:43:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KuLXLG/TrTfd6vR10cJZRZ0OyQKtmtt47CAt10Wezo0eypwNIjIcHq5rItEvjeM3bVD4vBC6euzX2TsjcAhFjB6iqr/dmpQpOBPgeJhj6XkKpyPoaACJS1rJlfWKwvxLSLbW4aFL+jwJLw6ApsQz3XoOyYn1t85lsJ07QJhF8hMH+OppEKW9fzy6WLOkrC3yd1C1U6e7waqQKnz+jjMdGxpdVoluzBi0NaO5p/aGfTrM/1+Ddy4VXO1lslV6f2uTHRHHr+KVNuzjBQqYra1eOgZc5otfAQMyvcWZvm7UNO0PW2AIawbjkmJ2iLvP0lzErpcq5as4K9t+F0YvZKGDsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=VUypoKs/iUvouqpT0Zce1fkTCXVfFf3Ra4bNgO/dCRA=; b=wnDBnlZNto8Tjhrur232s3KqvcWLIEfO94ofNfrb30D1kQvcd7ekSlJfwEmuMzi1CTNwMxv3uxrWy5IPITpqrvZLRGunfB5Kf0QfKR+nl7dhC6N4jMx3+cZA67Q7jN/EaG5R8ggyMspwyPvXIfHNj1AKJjYV+ArWhP13HqaevpL5A8ZX1/2uUitlYQw7xKrVZwakKN8Cgk3/kFh186PbWCzl0OYYEzjM4ysHg1r27arPb/8Ku2ydLHWUHFx/5M+WjEfX0XXx6kKvyfbpSGZafCwl4CcLIxYct6x4kj7IIInE3rruVXXQeVmW5Lbb1nUdBGfbvG4M5qkJZgU4iw/RSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=VUypoKs/iUvouqpT0Zce1fkTCXVfFf3Ra4bNgO/dCRA=; b=G9CqYku7wKqgMi9xwqgVbrugD017bRmzAnlsXCmhNXOxOOmFxgyy9tUz65BB1OMr1CeizP4PCeYEd5bpftE4Od5x8IqYNo4YPtWB4nMPxpdZJiO7heYZy6svaUGo9H1ZODx8MwEtuFOSMWOe4nkESx5MieE63g4PbfbZYdWSCnw= Received: from MN2PR08CA0003.namprd08.prod.outlook.com (2603:10b6:208:239::8) by PH8PR12MB6986.namprd12.prod.outlook.com (2603:10b6:510:1bd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Tue, 8 Oct 2024 17:43:41 +0000 Received: from BN3PEPF0000B370.namprd21.prod.outlook.com (2603:10b6:208:239:cafe::38) by MN2PR08CA0003.outlook.office365.com (2603:10b6:208:239::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23 via Frontend Transport; Tue, 8 Oct 2024 17:43:40 +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 BN3PEPF0000B370.mail.protection.outlook.com (10.167.243.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.0 via Frontend Transport; Tue, 8 Oct 2024 17:43:40 +0000 Received: from jfw9ny3-os.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; Tue, 8 Oct 2024 12:43:37 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v3 5/5] maintainers: update for drivers/power Date: Tue, 8 Oct 2024 17:43:08 +0000 Message-ID: <20241008174309.1133051-6-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008174309.1133051-1-sivaprasad.tummala@amd.com> References: <20241008172719.902619-1-sivaprasad.tummala@amd.com> <20241008174309.1133051-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: BN3PEPF0000B370:EE_|PH8PR12MB6986:EE_ X-MS-Office365-Filtering-Correlation-Id: 2df84c6f-fe61-41a1-e94d-08dce7c0bf51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: 9HaHOg6YhAO0EkH6MkT7bpyfiaUqELGAXJBl/b82EtTHcMTE/Dk40iimEVT+Gn0cgS8V9qRgoJ+7Dm2WA5avZRdoUUcB7mBQgJPoluJNkvNGFFXEwNXRkP5KSVsVq5pLNCzX+2EOs2oq0GFJYNP88Sqd02V7gtrJxX8kxFUJls47Fx/npXdXbN8ejstRt9LJ2EWYJmEDiECmnTm9tfB28BASVdy58224G33jvNxZ3+8bQUjOg85gGWC+F9Ngl4QFUTzWj3kzdjxh15C7Uhtzns+Im+0/ThrekRZQaeNdsfWC8wrta+vleZgB79Yd3ZJSvxbJX229LTqxzjEJYzlws4Bfa17GscQH4mO1QUfSQJLi5pt9SqP19+NjufrtgC1c2kVCEj8s+eTT8junZmbMTYxU8j9OeGXz8C/90MrSyHFrWgSp//+OxKIhIfSL0IeAGSuFMBxoDEzpgYXiEk5vr10LA3VVc4FHa2TsyW9Q4YEacmq6y8pVBp463fxrSJVpsT0wmEQXCBxPhjaxqxrye9pC0f6pmLGLiHBQe8y9MM+PMHtFU6qne2NrhpIIyXzOa18d9H2KenGbn9x5wLFJ5P4tNUNFeTajoWmpAFofQfgKD7h6BeXUsBtfxkL360jd2SPLNCAUTLVZtAB6zORyOunrMztNSOhHI/dYjBU+5x9suaJ5gQOFR54zKGtjlomgY9NoZky+9vSaKborO+/nhy6vs/Jlw6WDz8kNzQSr7Kpb+V/wgvFg3+XVRli8hqMgHXVijmLtgj4ukhCaPc6VLjjn0uiPxihfvnVP3ALV5Onh1cGdqGWphaPkaRNJ8ZXG4IYZ1E+wUyDBENMCNPz8DLkRKR/Jck4YakvCE7OY5MiVKNhvMlMOsuMaWEj8ifXYprbdsatUjhWd1LlQSAMMfeAbVTmg3O9QhIiyAMlKwCvadlQ09hzTXJVqIbs7aj6P8p7cwmTCo8hj5VFkM2Ab4gvJOyvZkkT/i3V92snuWi+1B1oCPeiIHWH+YVWNqQMPzRccdP9eMnCZBQ3fKSJFARmKIAPVTwxlmXUaZwtEN2N8WvERgWyfIzi3xwjeeJJFmSHb6mcx9Rpz4Wr0apJAt0oyf9gPIToGGJBMKOpZ/js5aidBgbTZ0XyhoyMejVTW+mw8xIavYJWc/2qm0B4pf94iQC7mTn/f0Q5z8kzq31g3EhAIVqrZlired+JpL/jIiQOElwTDV7GYJyg9+Rk/HH7un2xCisfcMTHWCme0TJ+1eq8K9XTgIQBS1X0l+AdihLYC5RgdlZTWpiJdDY/k60xrch4tYqHVuoWaZeWu1FBAfOKuGD2X82etdYIIEDtbBlRzI1TYh1FIANDs/kuOAekVik0i/DiD6NM9fu4as6dM/hH9jWDuW+PRi8niy1MC 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:(13230040)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 17:43:40.8540 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2df84c6f-fe61-41a1-e94d-08dce7c0bf51 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: BN3PEPF0000B370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6986 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Update maintainers for drivers/power/*. Signed-off-by: Sivaprasad Tummala --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 812463fe9f..7d2868fe30 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1737,6 +1737,7 @@ M: Anatoly Burakov M: David Hunt M: Sivaprasad Tummala F: lib/power/ +F: drivers/power/* F: doc/guides/prog_guide/power_man.rst F: app/test/test_power* F: examples/l3fwd-power/