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 6A0F545DB9 for ; Wed, 27 Nov 2024 18:22:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 623A3402E4; Wed, 27 Nov 2024 18:22:06 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 2DE64402E4 for ; Wed, 27 Nov 2024 18:22:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732728123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k7mQ0z81uuyBvF7AP4z0mc5knDmNxH/4LkoQ40Rifuw=; b=QSmHeXOOLA1iFPvneE1jvJcsQsMt67om+EBlXnD8QBWiMDeBA6L1BJJhQfwYcbtojKSFAX RvuVWwaT/uUyF46p1sYtv51W0FqF7D613C09Kj0ktPkVVmwqWhE8GjvsvpetTe0TkocYVM LjjM0/ud6kYlM2BvLH3X4BQNrbtfU/A= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-xDJ-gIQ2NgihuwoodIfzkw-1; Wed, 27 Nov 2024 12:21:58 -0500 X-MC-Unique: xDJ-gIQ2NgihuwoodIfzkw-1 X-Mimecast-MFC-AGG-ID: xDJ-gIQ2NgihuwoodIfzkw Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7F6D51955F42; Wed, 27 Nov 2024 17:21:57 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.52]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D22AD30001A2; Wed, 27 Nov 2024 17:21:55 +0000 (UTC) From: Kevin Traynor To: Sivaprasad Tummala Cc: Konstantin Ananyev , Huisong Li , dpdk stable Subject: patch 'power: fix mapped lcore ID' has been queued to stable release 21.11.9 Date: Wed, 27 Nov 2024 17:18:16 +0000 Message-ID: <20241127171916.690404-69-ktraynor@redhat.com> In-Reply-To: <20241127171916.690404-1-ktraynor@redhat.com> References: <20241127171916.690404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Ps0JYsHywaBuDLXMIjkHa1FtwO4L__Fm-q2-bujCIGY_1732728117 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 21.11.9 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/02/24. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/939535ca3bed8f1c9013baba9691ca356cca6d3b Thanks. Kevin --- >From 939535ca3bed8f1c9013baba9691ca356cca6d3b Mon Sep 17 00:00:00 2001 From: Sivaprasad Tummala Date: Fri, 18 Oct 2024 03:34:34 +0000 Subject: [PATCH] power: fix mapped lcore ID [ upstream commit 5c9b07eeba55d527025f1f4945e2dbb366f21215 ] This commit fixes an issue in the power library related to using lcores mapped to different physical cores (--lcores option in EAL). Previously, the power library incorrectly accessed CPU sysfs attributes for power management, treating lcore IDs as CPU IDs. e.g. with --lcores '1@128', lcore_id '1' was interpreted as CPU_id instead of '128'. This patch corrects the cpu_id based on lcore and CPU mappings. It also constraints power management support for lcores mapped to multiple physical cores/threads. When multiple lcores are mapped to the same physical core, invoking frequency scaling APIs on any lcore will apply the changes effectively. Fixes: 53e54bf81700 ("eal: new option --lcores for cpu assignment") Signed-off-by: Sivaprasad Tummala Acked-by: Konstantin Ananyev Acked-by: Huisong Li --- app/test/test_power_cpufreq.c | 21 ++++++++++++++++++--- lib/power/power_acpi_cpufreq.c | 6 +++++- lib/power/power_common.c | 23 +++++++++++++++++++++++ lib/power/power_common.h | 1 + lib/power/power_cppc_cpufreq.c | 6 +++++- lib/power/power_pstate_cpufreq.c | 6 +++++- lib/power/rte_power_pmd_mgmt.c | 4 ++-- 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/app/test/test_power_cpufreq.c b/app/test/test_power_cpufreq.c index 4d013cd7bb..051b9036dc 100644 --- a/app/test/test_power_cpufreq.c +++ b/app/test/test_power_cpufreq.c @@ -10,4 +10,5 @@ #include #include +#include #include "test.h" @@ -47,7 +48,8 @@ test_power_caps(void) static uint32_t total_freq_num; static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX]; +static uint32_t cpu_id; static int -check_cur_freq(unsigned int lcore_id, uint32_t idx, bool turbo) +check_cur_freq(__rte_unused unsigned int lcore_id, uint32_t idx, bool turbo) { #define TEST_POWER_CONVERT_TO_DECIMAL 10 @@ -63,5 +65,5 @@ check_cur_freq(unsigned int lcore_id, uint32_t idx, bool turbo) if (snprintf(fullpath, sizeof(fullpath), - TEST_POWER_SYSFILE_CPUINFO_FREQ, lcore_id) < 0) { + TEST_POWER_SYSFILE_CPUINFO_FREQ, cpu_id) < 0) { return 0; } @@ -69,5 +71,5 @@ check_cur_freq(unsigned int lcore_id, uint32_t idx, bool turbo) if (f == NULL) { if (snprintf(fullpath, sizeof(fullpath), - TEST_POWER_SYSFILE_SCALING_FREQ, lcore_id) < 0) { + TEST_POWER_SYSFILE_SCALING_FREQ, cpu_id) < 0) { return 0; } @@ -487,4 +489,17 @@ test_power_cpufreq(void) int ret = -1; enum power_management_env env; + rte_cpuset_t lcore_cpus; + + lcore_cpus = rte_lcore_cpuset(TEST_POWER_LCORE_ID); + if (CPU_COUNT(&lcore_cpus) != 1) { + printf("Power management doesn't support lcore %u mapping to %u CPUs\n", + TEST_POWER_LCORE_ID, + CPU_COUNT(&lcore_cpus)); + return TEST_SKIPPED; + } + for (cpu_id = 0; cpu_id < CPU_SETSIZE; cpu_id++) { + if (CPU_ISSET(cpu_id, &lcore_cpus)) + break; + } /* Test initialisation of a valid lcore */ diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufreq.c index 402ed8c99b..1bb74bdca6 100644 --- a/lib/power/power_acpi_cpufreq.c +++ b/lib/power/power_acpi_cpufreq.c @@ -265,5 +265,9 @@ power_acpi_cpufreq_init(unsigned int lcore_id) } - pi->lcore_id = lcore_id; + if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) { + RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); + return -1; + } + /* Check and set the governor */ if (power_set_governor_userspace(pi) < 0) { diff --git a/lib/power/power_common.c b/lib/power/power_common.c index 1e09facb86..e2a8c33604 100644 --- a/lib/power/power_common.c +++ b/lib/power/power_common.c @@ -10,4 +10,5 @@ #include #include +#include #include "power_common.h" @@ -203,2 +204,24 @@ out: return ret; } + +int power_get_lcore_mapped_cpu_id(uint32_t lcore_id, uint32_t *cpu_id) +{ + rte_cpuset_t lcore_cpus; + uint32_t cpu; + + lcore_cpus = rte_lcore_cpuset(lcore_id); + if (CPU_COUNT(&lcore_cpus) != 1) { + RTE_LOG(ERR, POWER, + "Power library does not support lcore %u mapping to %u CPUs", + lcore_id, CPU_COUNT(&lcore_cpus)); + return -1; + } + + for (cpu = 0; cpu < CPU_SETSIZE; cpu++) { + if (CPU_ISSET(cpu, &lcore_cpus)) + break; + } + *cpu_id = cpu; + + return 0; +} diff --git a/lib/power/power_common.h b/lib/power/power_common.h index 0b264edfa5..5b1ac877e6 100644 --- a/lib/power/power_common.h +++ b/lib/power/power_common.h @@ -29,4 +29,5 @@ int read_core_sysfs_u32(FILE *f, uint32_t *val); int read_core_sysfs_s(FILE *f, char *buf, unsigned int len); int write_core_sysfs_s(FILE *f, const char *str); +int power_get_lcore_mapped_cpu_id(uint32_t lcore_id, uint32_t *cpu_id); #endif /* _POWER_COMMON_H_ */ diff --git a/lib/power/power_cppc_cpufreq.c b/lib/power/power_cppc_cpufreq.c index 3223a6a445..e03de99be8 100644 --- a/lib/power/power_cppc_cpufreq.c +++ b/lib/power/power_cppc_cpufreq.c @@ -361,5 +361,9 @@ power_cppc_cpufreq_init(unsigned int lcore_id) } - pi->lcore_id = lcore_id; + if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) { + RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); + return -1; + } + /* Check and set the governor */ if (power_set_governor_userspace(pi) < 0) { diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c index 86f8a76e46..c249f92e5a 100644 --- a/lib/power/power_pstate_cpufreq.c +++ b/lib/power/power_pstate_cpufreq.c @@ -535,5 +535,9 @@ power_pstate_cpufreq_init(unsigned int lcore_id) } - pi->lcore_id = lcore_id; + if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) { + RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); + return -1; + } + /* Check and set the governor */ if (power_set_governor_performance(pi) < 0) { diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c index d73f450538..ea86ec01c3 100644 --- a/lib/power/rte_power_pmd_mgmt.c +++ b/lib/power/rte_power_pmd_mgmt.c @@ -417,5 +417,5 @@ check_scale(unsigned int lcore) !rte_power_check_env_supported(PM_ENV_PSTATE_CPUFREQ) && !rte_power_check_env_supported(PM_ENV_CPPC_CPUFREQ)) { - POWER_LOG(DEBUG, "Only ACPI, PSTATE, or CPPC modes are supported"); + RTE_LOG(DEBUG, POWER, "Only ACPI, PSTATE, or CPPC modes are supported"); return -ENOTSUP; } @@ -428,5 +428,5 @@ check_scale(unsigned int lcore) if (env != PM_ENV_ACPI_CPUFREQ && env != PM_ENV_PSTATE_CPUFREQ && env != PM_ENV_CPPC_CPUFREQ) { - POWER_LOG(DEBUG, "Unable to initialize ACPI, PSTATE, or CPPC modes"); + RTE_LOG(DEBUG, POWER, "Unable to initialize ACPI, PSTATE, or CPPC modes"); return -ENOTSUP; } -- 2.47.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2024-11-27 17:17:40.435934249 +0000 +++ 0069-power-fix-mapped-lcore-ID.patch 2024-11-27 17:17:38.262269565 +0000 @@ -1 +1 @@ -From 5c9b07eeba55d527025f1f4945e2dbb366f21215 Mon Sep 17 00:00:00 2001 +From 939535ca3bed8f1c9013baba9691ca356cca6d3b Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 5c9b07eeba55d527025f1f4945e2dbb366f21215 ] + @@ -25 +26,0 @@ -Cc: stable@dpdk.org @@ -31,8 +32,8 @@ - app/test/test_power_cpufreq.c | 21 ++++++++++++++++++--- - lib/power/power_acpi_cpufreq.c | 6 +++++- - lib/power/power_amd_pstate_cpufreq.c | 6 +++++- - lib/power/power_common.c | 23 +++++++++++++++++++++++ - lib/power/power_common.h | 1 + - lib/power/power_cppc_cpufreq.c | 6 +++++- - lib/power/power_pstate_cpufreq.c | 6 +++++- - 7 files changed, 62 insertions(+), 7 deletions(-) + app/test/test_power_cpufreq.c | 21 ++++++++++++++++++--- + lib/power/power_acpi_cpufreq.c | 6 +++++- + lib/power/power_common.c | 23 +++++++++++++++++++++++ + lib/power/power_common.h | 1 + + lib/power/power_cppc_cpufreq.c | 6 +++++- + lib/power/power_pstate_cpufreq.c | 6 +++++- + lib/power/rte_power_pmd_mgmt.c | 4 ++-- + 7 files changed, 59 insertions(+), 8 deletions(-) @@ -41 +42 @@ -index 619b2811c6..edbd34424e 100644 +index 4d013cd7bb..051b9036dc 100644 @@ -74 +75 @@ -@@ -498,4 +500,17 @@ test_power_cpufreq(void) +@@ -487,4 +489,17 @@ test_power_cpufreq(void) @@ -93 +94 @@ -index abad53bef1..ae809fbb60 100644 +index 402ed8c99b..1bb74bdca6 100644 @@ -101,16 +102 @@ -+ POWER_LOG(ERR, "Cannot get CPU ID mapped for lcore %u", lcore_id); -+ return -1; -+ } -+ - /* Check and set the governor */ - if (power_set_governor_userspace(pi) < 0) { -diff --git a/lib/power/power_amd_pstate_cpufreq.c b/lib/power/power_amd_pstate_cpufreq.c -index 4809d45a22..2b728eca18 100644 ---- a/lib/power/power_amd_pstate_cpufreq.c -+++ b/lib/power/power_amd_pstate_cpufreq.c -@@ -383,5 +383,9 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id) - } - -- pi->lcore_id = lcore_id; -+ if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) { -+ POWER_LOG(ERR, "Cannot get CPU ID mapped for lcore %u", lcore_id); ++ RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); @@ -123 +109 @@ -index 590986d5ef..b47c63a5f1 100644 +index 1e09facb86..e2a8c33604 100644 @@ -132 +118 @@ -@@ -205,2 +206,24 @@ out: +@@ -203,2 +204,24 @@ out: @@ -143 +129 @@ -+ POWER_LOG(ERR, ++ RTE_LOG(ERR, POWER, @@ -158 +144 @@ -index 83f742f42a..82fb94d0c0 100644 +index 0b264edfa5..5b1ac877e6 100644 @@ -161 +147 @@ -@@ -32,4 +32,5 @@ int read_core_sysfs_u32(FILE *f, uint32_t *val); +@@ -29,4 +29,5 @@ int read_core_sysfs_u32(FILE *f, uint32_t *val); @@ -168 +154 @@ -index e73f4520d0..cc9305bdfe 100644 +index 3223a6a445..e03de99be8 100644 @@ -171 +157 @@ -@@ -369,5 +369,9 @@ power_cppc_cpufreq_init(unsigned int lcore_id) +@@ -361,5 +361,9 @@ power_cppc_cpufreq_init(unsigned int lcore_id) @@ -176 +162 @@ -+ POWER_LOG(ERR, "Cannot get CPU ID mapped for lcore %u", lcore_id); ++ RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); @@ -183 +169 @@ -index 1c2a91a178..4755909466 100644 +index 86f8a76e46..c249f92e5a 100644 @@ -186 +172 @@ -@@ -571,5 +571,9 @@ power_pstate_cpufreq_init(unsigned int lcore_id) +@@ -535,5 +535,9 @@ power_pstate_cpufreq_init(unsigned int lcore_id) @@ -191 +177 @@ -+ POWER_LOG(ERR, "Cannot get CPU ID mapped for lcore %u", lcore_id); ++ RTE_LOG(ERR, POWER, "Cannot get CPU ID mapped for lcore %u", lcore_id); @@ -196,0 +183,18 @@ +diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c +index d73f450538..ea86ec01c3 100644 +--- a/lib/power/rte_power_pmd_mgmt.c ++++ b/lib/power/rte_power_pmd_mgmt.c +@@ -417,5 +417,5 @@ check_scale(unsigned int lcore) + !rte_power_check_env_supported(PM_ENV_PSTATE_CPUFREQ) && + !rte_power_check_env_supported(PM_ENV_CPPC_CPUFREQ)) { +- POWER_LOG(DEBUG, "Only ACPI, PSTATE, or CPPC modes are supported"); ++ RTE_LOG(DEBUG, POWER, "Only ACPI, PSTATE, or CPPC modes are supported"); + return -ENOTSUP; + } +@@ -428,5 +428,5 @@ check_scale(unsigned int lcore) + if (env != PM_ENV_ACPI_CPUFREQ && env != PM_ENV_PSTATE_CPUFREQ && + env != PM_ENV_CPPC_CPUFREQ) { +- POWER_LOG(DEBUG, "Unable to initialize ACPI, PSTATE, or CPPC modes"); ++ RTE_LOG(DEBUG, POWER, "Unable to initialize ACPI, PSTATE, or CPPC modes"); + return -ENOTSUP; + }