From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A161C4307F; Wed, 16 Aug 2023 12:10:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EEC3B4325B; Wed, 16 Aug 2023 12:10:20 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by mails.dpdk.org (Postfix) with ESMTP id 268AC40EF0 for ; Wed, 16 Aug 2023 12:10:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eu6nj2VeUjiXIy4QE1HF2v3//13uHJfX21hsGM+vqPL8YYUZS4PD5eztfFqk53+K+FlUcKJP+w6pCHPVLaI5NlT3PPN1MagtysfPusl+xosgLpBaBJYmK8ozCc5YTCYvJ1uxr16ynWligBECP6Yt81KQrixAR5gbl5jRDnn7rLhr/Qa8DaaYYWqFZpkelzPX7rtIEJVwKej2FupsfmrYHEOxAIQTsAD2YJdV2ESr84x0DEY6k/uC9kh/WWJMs2Dr3cSmMW43pxWetKNiyv8QLIsVut6H+fujZe4y7KbQHQvSjtkUKGmmGaRi8BKP/ap4F09OGGqgVpeOkVEvWVX+6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dUxWIkZesCFFUggEOXRl703rIqw+miz4HjVCeP0eGrk=; b=lIBBWqeoxHTENBxW0ZBhESA9gzO0fZ+VRZvdUdy7YUkOypghDhNgvI1UiVulThdIjk7T0ShCoynKFyutgCjcpw2gr9DoFAN1jCYgcrpbSkyCqNDm6F2HiWVCt6irmJmMFMBv033wjQJE6FNvAHEInh0xz/MeNLbSWpGA8f3z1/kge+SDvL8TJ6FpffYk8/AmVeUJAYYXxHuGGFey7T9HBGdNa62fXLXhnDQzp1C+btbf3ePFMl+Osu4e6ofDKHI+ufyHPqJRCKecdv3BjnpaDAIjbL9Q0YzeTXKmKlZhQX3QQ1J8/hUpdcTF0AdI6PWtojr0Ol8GC/gEmKqKiqYIjA== 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 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=dUxWIkZesCFFUggEOXRl703rIqw+miz4HjVCeP0eGrk=; b=zNlk1EG13EPtJcHuTrfrKLtrtJk6E8aMVC21+kYYIeiePffyVOblhW+vaMr5jTd+0b+dAQlG94TCtMGKo0lsVDUL5dBjNyhmcayHaNQzRgl1lDLWZ5s32I8ZePWxiqAXOzyL6fFtM8K7CcovrxSm2FAF2xhYy8FMGEPbaQif0rM= Received: from DM6PR11CA0027.namprd11.prod.outlook.com (2603:10b6:5:190::40) by SN7PR12MB7912.namprd12.prod.outlook.com (2603:10b6:806:341::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 10:10:14 +0000 Received: from CY4PEPF0000EE31.namprd05.prod.outlook.com (2603:10b6:5:190:cafe::47) by DM6PR11CA0027.outlook.office365.com (2603:10b6:5:190::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Wed, 16 Aug 2023 10:10:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE31.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Wed, 16 Aug 2023 10:10:13 +0000 Received: from telco-siena.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.27; Wed, 16 Aug 2023 05:10:12 -0500 From: Sivaprasad Tummala To: , , CC: Subject: [PATCH v2 2/2] power: refactor uncore power management implementation Date: Wed, 16 Aug 2023 03:09:58 -0700 Message-ID: <20230816100958.1022206-2-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816100958.1022206-1-sivaprasad.tummala@amd.com> References: <20230811102534.491000-1-sivaprasad.tummala@amd.com> <20230816100958.1022206-1-sivaprasad.tummala@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE31:EE_|SN7PR12MB7912:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ab32d2f-6cbd-4e5c-53b3-08db9e40fb87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j+7Uz+HaY8bvH4/qw9rWRVxxG6/5chtWUuiFedRSXzG+fr9dVbcu/MJj+679dGFgzpP99yJ0ChsmPrG57q7PQiVJMF4nqmoCd9EHE/ireSZc6l87hCJdYzJrXBaKufNwvrCjWTpR3ea5lZ80XkaWag0ZQZWTSm/AZmXwBs/9BfqwKY9cEmxHVJfMio5jHRF/ZwRNY0IqO0ugkwZnLJlu8i+oZuNlIbrC72xdNbILkTHZLzuEa6MBzhQjOUUWXnAQ5FbN69yxs5tb+EGEO1udqGDADi/7euuWaOyw1Ue3mA3ToOdSAW84Yep4to36rwf79ApXCLBj3inOlJyNM0JDQr0FInyvaaPpI750Kb7xgJ+e+eLSCxVcUmAGPSHNazqjTSJN++q9wmo80lnuxGUTwaNijk+JmDT0y9Rhes3S02lGbBxjGb5fjT7UG8k2f0YYCCmJ1FAd/fg/x53VfymNt2PNrSgBeKlQ4ukuDeJsolFhiMH8XO/3rEqr4b5BxLkU84TZXbWbdDtQ94lOU6oLVM9gId9OPMqKJgeyuPJ7sQi/J+Z+2zA8CAgnL2Hi8ojMMa6QllbqQDFoCrTeF/snzUx/fcnLQUkeqWS/rjJfpiuyMdPA4weIN6gWoi+EZmWamBPASdlGsxz5QRAGm1tET5Cqk4SnYbW1408AsN3/eoxQ3iqkb3McEVhnDpsglGB24qtZ1OR1zsTesKMX/asEUF4AobsbzNgXGyBCVwPOqh8BJYUHkZ36/JI+fX9q2bBLh1KGFmR/XmazTa5Zy+76QQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(376002)(346002)(136003)(396003)(39860400002)(1800799009)(451199024)(82310400011)(186009)(46966006)(36840700001)(40470700004)(2906002)(30864003)(40460700003)(83380400001)(86362001)(40480700001)(478600001)(336012)(426003)(7696005)(36756003)(2616005)(6666004)(1076003)(26005)(16526019)(5660300002)(44832011)(41300700001)(36860700001)(6636002)(82740400003)(356005)(316002)(81166007)(70206006)(70586007)(110136005)(8676002)(8936002)(4326008)(47076005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 10:10:13.7165 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ab32d2f-6cbd-4e5c-53b3-08db9e40fb87 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: CY4PEPF0000EE31.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7912 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 currently the uncore power management implementation is vendor specific. Added new vendor agnostic uncore power management implementation similar to rte_power and rename specific implementations ("rte_power_intel_uncore") to "power_intel_uncore" along with functions. Signed-off-by: Sivaprasad Tummala --- app/test/test_power_intel_uncore.c | 10 +- config/rte_config.h | 1 + examples/l3fwd-power/main.c | 2 +- lib/power/meson.build | 5 +- ...er_intel_uncore.c => power_intel_uncore.c} | 51 +++-- ...er_intel_uncore.h => power_intel_uncore.h} | 66 +++--- lib/power/rte_power_uncore.c | 189 ++++++++++++++++++ lib/power/rte_power_uncore.h | 32 +++ lib/power/version.map | 6 + 9 files changed, 313 insertions(+), 49 deletions(-) rename lib/power/{rte_power_intel_uncore.c => power_intel_uncore.c} (90%) rename lib/power/{rte_power_intel_uncore.h => power_intel_uncore.h} (77%) create mode 100644 lib/power/rte_power_uncore.c diff --git a/app/test/test_power_intel_uncore.c b/app/test/test_power_intel_uncore.c index 31163af84e..27f4684f76 100644 --- a/app/test/test_power_intel_uncore.c +++ b/app/test/test_power_intel_uncore.c @@ -14,7 +14,7 @@ test_power_intel_uncore(void) } #else -#include +#include #include #define MAX_UNCORE_FREQS 32 @@ -246,11 +246,15 @@ test_power_intel_uncore(void) { int ret; + ret = rte_power_set_uncore_env(UNCORE_PM_ENV_INTEL_UNCORE); + if (ret < 0) + goto fail_all; + ret = rte_power_uncore_get_num_pkgs(); if (ret == 0) { printf("Uncore frequency management not supported/enabled on this kernel. " - "Please enable CONFIG_INTEL_UNCORE_FREQ_CONTROL if on x86 with linux kernel" - " >= 5.6\n"); + "Please enable CONFIG_INTEL_UNCORE_FREQ_CONTROL if on intel x86 with " + "linux kernel >= 5.6\n"); return TEST_SKIPPED; } diff --git a/config/rte_config.h b/config/rte_config.h index 400e44e3cf..ccca68b4f3 100644 --- a/config/rte_config.h +++ b/config/rte_config.h @@ -87,6 +87,7 @@ /* rte_power defines */ #define RTE_MAX_LCORE_FREQS 64 +#define RTE_MAX_UNCORE_FREQS 64 /* rte_graph defines */ #define RTE_GRAPH_BURST_SIZE 256 diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index 3f01cbd9e2..a34a7958f0 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include "perf_core.h" #include "main.h" diff --git a/lib/power/meson.build b/lib/power/meson.build index 1ce8b7c07d..9693c3ba7d 100644 --- a/lib/power/meson.build +++ b/lib/power/meson.build @@ -18,13 +18,14 @@ sources = files( 'power_cppc_cpufreq.c', 'power_kvm_vm.c', 'power_pstate_cpufreq.c', + 'power_intel_uncore.c', 'rte_power.c', - 'rte_power_intel_uncore.c', + 'rte_power_uncore.c', 'rte_power_pmd_mgmt.c', ) headers = files( 'rte_power.h', - 'rte_power_intel_uncore.h', + 'rte_power_uncore.h', 'rte_power_pmd_mgmt.h', 'rte_power_guest_channel.h', ) diff --git a/lib/power/rte_power_intel_uncore.c b/lib/power/power_intel_uncore.c similarity index 90% rename from lib/power/rte_power_intel_uncore.c rename to lib/power/power_intel_uncore.c index 3b8724385f..258cf78dff 100644 --- a/lib/power/rte_power_intel_uncore.c +++ b/lib/power/power_intel_uncore.c @@ -8,7 +8,7 @@ #include -#include "rte_power_intel_uncore.h" +#include "power_intel_uncore.h" #include "power_common.h" #define MAX_UNCORE_FREQS 32 @@ -246,7 +246,7 @@ static int check_pkg_die_values(unsigned int pkg, unsigned int die) { unsigned int max_pkgs, max_dies; - max_pkgs = rte_power_uncore_get_num_pkgs(); + max_pkgs = power_intel_uncore_get_num_pkgs(); if (max_pkgs == 0) return -1; if (pkg >= max_pkgs) { @@ -255,7 +255,7 @@ check_pkg_die_values(unsigned int pkg, unsigned int die) return -1; } - max_dies = rte_power_uncore_get_num_dies(pkg); + max_dies = power_intel_uncore_get_num_dies(pkg); if (max_dies == 0) return -1; if (die >= max_dies) { @@ -268,7 +268,7 @@ check_pkg_die_values(unsigned int pkg, unsigned int die) } int -rte_power_uncore_init(unsigned int pkg, unsigned int die) +power_intel_uncore_init(unsigned int pkg, unsigned int die) { struct uncore_power_info *ui; @@ -298,7 +298,7 @@ rte_power_uncore_init(unsigned int pkg, unsigned int die) } int -rte_power_uncore_exit(unsigned int pkg, unsigned int die) +power_intel_uncore_exit(unsigned int pkg, unsigned int die) { struct uncore_power_info *ui; @@ -333,7 +333,7 @@ rte_power_uncore_exit(unsigned int pkg, unsigned int die) } uint32_t -rte_power_get_uncore_freq(unsigned int pkg, unsigned int die) +power_get_intel_uncore_freq(unsigned int pkg, unsigned int die) { int ret = check_pkg_die_values(pkg, die); if (ret < 0) @@ -343,7 +343,7 @@ rte_power_get_uncore_freq(unsigned int pkg, unsigned int die) } int -rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index) +power_set_intel_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index) { int ret = check_pkg_die_values(pkg, die); if (ret < 0) @@ -353,7 +353,7 @@ rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index) } int -rte_power_uncore_freq_max(unsigned int pkg, unsigned int die) +power_intel_uncore_freq_max(unsigned int pkg, unsigned int die) { int ret = check_pkg_die_values(pkg, die); if (ret < 0) @@ -364,7 +364,7 @@ rte_power_uncore_freq_max(unsigned int pkg, unsigned int die) int -rte_power_uncore_freq_min(unsigned int pkg, unsigned int die) +power_intel_uncore_freq_min(unsigned int pkg, unsigned int die) { int ret = check_pkg_die_values(pkg, die); if (ret < 0) @@ -376,7 +376,32 @@ rte_power_uncore_freq_min(unsigned int pkg, unsigned int die) } int -rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die) +power_intel_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) { + RTE_LOG(ERR, POWER, "NULL buffer supplied\n"); + return 0; + } + + ui = &uncore_info[pkg][die]; + if (num < ui->nb_freqs) { + RTE_LOG(ERR, POWER, "Buffer size is not enough\n"); + return 0; + } + rte_memcpy(freqs, ui->freqs, ui->nb_freqs * sizeof(uint32_t)); + + return ui->nb_freqs; +} + +int +power_intel_uncore_get_num_freqs(unsigned int pkg, unsigned int die) { int ret = check_pkg_die_values(pkg, die); if (ret < 0) @@ -386,7 +411,7 @@ rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die) } unsigned int -rte_power_uncore_get_num_pkgs(void) +power_intel_uncore_get_num_pkgs(void) { DIR *d; struct dirent *dir; @@ -416,14 +441,14 @@ rte_power_uncore_get_num_pkgs(void) } unsigned int -rte_power_uncore_get_num_dies(unsigned int pkg) +power_intel_uncore_get_num_dies(unsigned int pkg) { DIR *d; struct dirent *dir; unsigned int count = 0, max_pkgs; char filter[FILTER_LENGTH]; - max_pkgs = rte_power_uncore_get_num_pkgs(); + max_pkgs = power_intel_uncore_get_num_pkgs(); if (max_pkgs == 0) return 0; if (pkg >= max_pkgs) { diff --git a/lib/power/rte_power_intel_uncore.h b/lib/power/power_intel_uncore.h similarity index 77% rename from lib/power/rte_power_intel_uncore.h rename to lib/power/power_intel_uncore.h index 0bd9f193a1..32d6b1f7a4 100644 --- a/lib/power/rte_power_intel_uncore.h +++ b/lib/power/power_intel_uncore.h @@ -2,8 +2,8 @@ * Copyright(c) 2022 Intel Corporation */ -#ifndef RTE_POWER_INTEL_UNCORE_H -#define RTE_POWER_INTEL_UNCORE_H +#ifndef POWER_INTEL_UNCORE_H +#define POWER_INTEL_UNCORE_H /** * @file @@ -12,6 +12,7 @@ #include #include "rte_power.h" +#include "rte_power_uncore.h" #ifdef __cplusplus extern "C" { @@ -34,9 +35,7 @@ extern "C" { * - 0 on success. * - Negative on error. */ -__rte_experimental -int -rte_power_uncore_init(unsigned int pkg, unsigned int die); +int power_intel_uncore_init(unsigned int pkg, unsigned int die); /** * Exit uncore frequency management on a specific die on a package. @@ -56,9 +55,7 @@ rte_power_uncore_init(unsigned int pkg, unsigned int die); * - 0 on success. * - Negative on error. */ -__rte_experimental -int -rte_power_uncore_exit(unsigned int pkg, unsigned int die); +int power_intel_uncore_exit(unsigned int pkg, unsigned int die); /** * Return the current index of available frequencies of a specific die on a package. @@ -77,9 +74,7 @@ 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)'. */ -__rte_experimental -uint32_t -rte_power_get_uncore_freq(unsigned int pkg, unsigned int die); +uint32_t power_get_intel_uncore_freq(unsigned int pkg, unsigned int die); /** * Set minimum and maximum uncore frequency for specified die on a package @@ -102,9 +97,7 @@ rte_power_get_uncore_freq(unsigned int pkg, unsigned int die); * - 0 on success without frequency changed. * - Negative on error. */ -__rte_experimental -int -rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index); +int power_set_intel_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index); /** * Set minimum and maximum uncore frequency for specified die on a package @@ -125,9 +118,7 @@ rte_power_set_uncore_freq(unsigned int pkg, unsigned int die, uint32_t index); * - 0 on success without frequency changed. * - Negative on error. */ -__rte_experimental -int -rte_power_uncore_freq_max(unsigned int pkg, unsigned int die); +int power_intel_uncore_freq_max(unsigned int pkg, unsigned int die); /** * Set minimum and maximum uncore frequency for specified die on a package @@ -148,9 +139,30 @@ rte_power_uncore_freq_max(unsigned int pkg, unsigned int die); * - 0 on success without frequency changed. * - Negative on error. */ -__rte_experimental -int -rte_power_uncore_freq_min(unsigned int pkg, unsigned int die); +int power_intel_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_intel_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. @@ -168,9 +180,7 @@ rte_power_uncore_freq_min(unsigned int pkg, unsigned int die); * - The number of available index's in frequency array. * - Negative on error. */ -__rte_experimental -int -rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die); +int power_intel_uncore_get_num_freqs(unsigned int pkg, unsigned int die); /** * Return the number of packages (CPUs) on a system @@ -182,9 +192,7 @@ rte_power_uncore_get_num_freqs(unsigned int pkg, unsigned int die); * - Zero on error. * - Number of package on system on success. */ -__rte_experimental -unsigned int -rte_power_uncore_get_num_pkgs(void); +unsigned int power_intel_uncore_get_num_pkgs(void); /** * Return the number of dies for pakckages (CPUs) specified @@ -200,12 +208,10 @@ rte_power_uncore_get_num_pkgs(void); * - Zero on error. * - Number of dies for package on sucecss. */ -__rte_experimental -unsigned int -rte_power_uncore_get_num_dies(unsigned int pkg); +unsigned int power_intel_uncore_get_num_dies(unsigned int pkg); #ifdef __cplusplus } #endif -#endif /* RTE_POWER_INTEL_UNCORE_H */ +#endif /* POWER_INTEL_UNCORE_H */ diff --git a/lib/power/rte_power_uncore.c b/lib/power/rte_power_uncore.c new file mode 100644 index 0000000000..79303ebb3a --- /dev/null +++ b/lib/power/rte_power_uncore.c @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + * Copyright(c) 2023 AMD Corporation + */ + +#include + +#include +#include + +#include "rte_power_uncore.h" +#include "power_intel_uncore.h" + +enum uncore_power_mgmt_env default_uncore_env = UNCORE_PM_ENV_NOT_SET; + +static rte_spinlock_t global_env_cfg_lock = RTE_SPINLOCK_INITIALIZER; + +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; +} + +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) +{ + return 0; +} + +static unsigned int +power_dummy_uncore_get_num_pkgs(void) +{ + return 0; +} + +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 uncore_power_mgmt_env env) +{ + rte_spinlock_lock(&global_env_cfg_lock); + + if (default_uncore_env != UNCORE_PM_ENV_NOT_SET) { + RTE_LOG(ERR, POWER, "Uncore Power Management Env already set.\n"); + rte_spinlock_unlock(&global_env_cfg_lock); + return -1; + } + + int ret = 0; + + if (env == 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 { + RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n", + env); + ret = -1; + goto out; + } + + default_uncore_env = env; +out: + rte_spinlock_unlock(&global_env_cfg_lock); + return ret; +} + +void +rte_power_unset_uncore_env(void) +{ + rte_spinlock_lock(&global_env_cfg_lock); + default_uncore_env = UNCORE_PM_ENV_NOT_SET; + reset_power_uncore_function_ptrs(); + rte_spinlock_unlock(&global_env_cfg_lock); +} + +enum uncore_power_mgmt_env +rte_power_get_uncore_env(void) +{ + return default_uncore_env; +} + +int +rte_power_uncore_init(unsigned int pkg, unsigned int die) +{ + int ret = -1; + + switch (default_uncore_env) { + case UNCORE_PM_ENV_INTEL_UNCORE: + return power_intel_uncore_init(pkg, die); + default: + RTE_LOG(INFO, POWER, "Uncore Env isn't set yet!\n"); + } + + /* Auto detect Environment */ + RTE_LOG(INFO, POWER, "Attempting to initialise Intel Uncore power mgmt...\n"); + ret = power_intel_uncore_init(pkg, die); + if (ret == 0) { + rte_power_set_uncore_env(UNCORE_PM_ENV_INTEL_UNCORE); + goto out; + } + + if (default_uncore_env == UNCORE_PM_ENV_NOT_SET) { + RTE_LOG(ERR, POWER, "Unable to set Power Management Environment " + "for package %u Die %u\n", pkg, die); + ret = 0; + } +out: + return ret; +} + +int +rte_power_uncore_exit(unsigned int pkg, unsigned int die) +{ + switch (default_uncore_env) { + case UNCORE_PM_ENV_INTEL_UNCORE: + return power_intel_uncore_exit(pkg, die); + default: + RTE_LOG(ERR, POWER, "Uncore Env has not been set," + "unable to exit gracefully\n"); + } + return -1; + +} diff --git a/lib/power/rte_power_uncore.h b/lib/power/rte_power_uncore.h index e27f483eae..a43346b186 100644 --- a/lib/power/rte_power_uncore.h +++ b/lib/power/rte_power_uncore.h @@ -22,6 +22,38 @@ extern "C" { enum uncore_power_mgmt_env { UNCORE_PM_ENV_NOT_SET, UNCORE_PM_ENV_INTEL_UNCORE, UNCORE_PM_ENV_AMD_HSMP}; +/** + * Set the default uncore power management implementation. If this is not called prior + * to rte_power_uncore_init(), then auto-detect of the environment will take place. + * It is thread safe. New env can be set only in uninitialized state + * (thus rte_power_unset_uncore_env must be called if different env was already set). + * + * @param env + * env. The environment in which to initialise Uncore Power Management for. + * + * @return + * - 0 on success. + * - Negative on error. + */ +__rte_experimental +int rte_power_set_uncore_env(enum uncore_power_mgmt_env env); + +/** + * Unset the global uncore environment configuration. + * This can only be called after all threads have completed. + */ +__rte_experimental +void rte_power_unset_uncore_env(void); + +/** + * Get the default uncore power management implementation. + * + * @return + * power_management_env The configured environment. + */ +__rte_experimental +enum uncore_power_mgmt_env rte_power_get_uncore_env(void); + /** * Initialize uncore frequency management for specific die on a package. * It will get the available frequencies and prepare to set new die frequencies. diff --git a/lib/power/version.map b/lib/power/version.map index b8b54f768e..c22813e89a 100644 --- a/lib/power/version.map +++ b/lib/power/version.map @@ -52,4 +52,10 @@ EXPERIMENTAL { rte_power_uncore_get_num_freqs; rte_power_uncore_get_num_pkgs; rte_power_uncore_init; + + # added in 23.11 + rte_power_uncore_freqs; + rte_power_set_uncore_env; + rte_power_unset_uncore_env; + rte_power_get_uncore_env; }; -- 2.34.1