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 AF20D45B5D; Thu, 17 Oct 2024 13:03:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 695D540279; Thu, 17 Oct 2024 13:03:11 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by mails.dpdk.org (Postfix) with ESMTP id 023CB4021E for ; Thu, 17 Oct 2024 13:03:09 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S6NGmDHUX3AGtvSiI4R317Y6SpGlteGQ/CO3nsGbX/ERHmXDls9SAcG9dnbNX4rqwjScWgiu0CSvI0/TFr2kJPmbaXbRnBwDk7orkT+royU37j7Igw4hSUcDStOXZ5nVNG9+kRQYHTOif0yIc6L0OuXzs+SLruk/ozcoPegDVSgCWZR9HJG3C5IU5bU9jRN1Z7du0Tews9b+4d74jK8VeYSLZst6ruA4caZmRaiKHXToyTLXg143AUu+H7cBvT85Q4PX/AsTX9s99YdErEvseRvnvf5JIop3N5fr4cmGFaAxcGeLqjgNBDDZ8OCF/xoLN2FYoPkXkFuP+XGwxTWpDg== 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=shJLP8qIvRYAuYMeA68JozEIwp+xvtbczTx0dk7wm3M=; b=NlQaaMKzgMISp96PkLCK8pFINLp7HWg62ozgsx6kbEjuJy6muzgOrHznO4Wwlfrvo2vwRz+d5tIouWDT7LD36ezF9F4s+CNT00ArZ/o8uSVX+PyUDftIqE2WFXw911q/ekNdXWqATkmUsm3kzLIvsFRTA72pUdgs7hpwyK+mRfVjHEEOrMDpqanBP3IuXCb1h2nwKMJbNjdpKOxBrBxjTrIyCUGFP+ougLhXXTFCft5DnuHecMxeoHUyLfuZNtHVi+CQAKaMfskE5TOgerPjxqZUPllW8ff4KiMjgMH28iX0tGNVlwEChj3PZly7p+oZ2j/Rdn7t5jAmQwGopFGq1g== 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=shJLP8qIvRYAuYMeA68JozEIwp+xvtbczTx0dk7wm3M=; b=WPzXes9mckzP7OID56kH+Qr6EsnR1VUIJY7LXckBAqi5Vs/p8X9wGL3U99YBxdtecyPWB1f3ZKyBviTRZpJup3/lnmvqnhDXaV06nm8pfDYMaVjlYCKHsGLHItz5ztJkkC0wxI38R10u5dqjZjndJ2lBz+D17klnFgV02QbhShY= Received: from BL1PR13CA0324.namprd13.prod.outlook.com (2603:10b6:208:2c1::29) by PH7PR12MB7455.namprd12.prod.outlook.com (2603:10b6:510:20e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Thu, 17 Oct 2024 11:03:04 +0000 Received: from BL02EPF00021F6C.namprd02.prod.outlook.com (2603:10b6:208:2c1:cafe::2e) by BL1PR13CA0324.outlook.office365.com (2603:10b6:208:2c1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.16 via Frontend Transport; Thu, 17 Oct 2024 11:03:04 +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 BL02EPF00021F6C.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8069.17 via Frontend Transport; Thu, 17 Oct 2024 11:03:04 +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; Thu, 17 Oct 2024 06:03:01 -0500 From: Sivaprasad Tummala To: , , , , , , , CC: Subject: [PATCH v1 1/2] power: fix power library with --lcores Date: Thu, 17 Oct 2024 11:02:46 +0000 Message-ID: <20241017110247.1051770-1-sivaprasad.tummala@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240724130336.1076462-1-sivaprasad.tummala@amd.com> References: <20240724130336.1076462-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: BL02EPF00021F6C:EE_|PH7PR12MB7455:EE_ X-MS-Office365-Filtering-Correlation-Id: 8afec984-e812-404e-3b82-08dcee9b4613 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message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Nvj4/NJeTpUdvc972sae152dfeUqsRa9?= =?us-ascii?Q?waBjr1OQ51W9LSk+jaD+Zbs7sdXAEZuzC68acYOL4K8kRq6MJmnXS42q4j+i?= =?us-ascii?Q?Mlaby9c2bZVuuY/pvbI5wWmutik8cdRsEP5OQxX1HiU/2rw0dn31UgHMPso5?= =?us-ascii?Q?Enf4dbvE4ECXuirkw5L/ffMeiHbqGV5ickFLQeFJefL42q8cxQsKlqUeIQ6i?= =?us-ascii?Q?Bjyl0t0TnEUqrn8yZwEqgjXRYBXGxNZdaLgekTzEaidyE+Oxhc+L6/atClBH?= =?us-ascii?Q?voZ7Al1+x5fpwACIsUAJUcfZrwkwJ4i7udK2xp/8W6hD3iK5kX00lxMXQu21?= =?us-ascii?Q?Zqe8r3mls3VdZDXHegbWQihy3BBt/NrRRGe8pOpAtDyFTfiabUZc9zESQGfN?= =?us-ascii?Q?8s9e2FeQX0Y6C09oigB5EGwR6KbTrdRBBNKaTLcNzfC+T7C0vafj2XQXyBm+?= =?us-ascii?Q?37hmk+fPCWU4lwCpxTRFbBS6Gm7KV3mdZ4DNFyGUOY5Rlcb7ZURAOAZ/H6sw?= =?us-ascii?Q?Ef1/HuqmRJ/vHwXfOlJzl17ZM4a7oOVRXNJaK/PNk6yLQizmCA=3D=3D?= 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)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 11:03:04.2149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8afec984-e812-404e-3b82-08dcee9b4613 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: BL02EPF00021F6C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7455 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 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. Signed-off-by: Sivaprasad Tummala --- lib/power/power_acpi_cpufreq.c | 7 ++++++- lib/power/power_amd_pstate_cpufreq.c | 7 ++++++- lib/power/power_common.c | 23 +++++++++++++++++++++++ lib/power/power_common.h | 2 +- lib/power/power_cppc_cpufreq.c | 7 ++++++- lib/power/power_pstate_cpufreq.c | 7 ++++++- 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufreq.c index 81996e1c13..259bc8a263 100644 --- a/lib/power/power_acpi_cpufreq.c +++ b/lib/power/power_acpi_cpufreq.c @@ -258,7 +258,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id) return -1; } - pi->lcore_id = lcore_id; + if (check_lcore_and_set_cpu(lcore_id, &pi->lcore_id) < 0) { + 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) { POWER_LOG(ERR, "Cannot set governor of lcore %u to " diff --git a/lib/power/power_amd_pstate_cpufreq.c b/lib/power/power_amd_pstate_cpufreq.c index 090a0d96cb..9bfb271bb7 100644 --- a/lib/power/power_amd_pstate_cpufreq.c +++ b/lib/power/power_amd_pstate_cpufreq.c @@ -376,7 +376,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id) return -1; } - pi->lcore_id = lcore_id; + if (check_lcore_and_set_cpu(lcore_id, &pi->lcore_id) < 0) { + 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) { POWER_LOG(ERR, "Cannot set governor of lcore %u to " diff --git a/lib/power/power_common.c b/lib/power/power_common.c index 590986d5ef..a8d5cd1c50 100644 --- a/lib/power/power_common.c +++ b/lib/power/power_common.c @@ -9,6 +9,7 @@ #include #include +#include #include "power_common.h" @@ -204,3 +205,25 @@ power_set_governor(unsigned int lcore_id, const char *new_governor, return ret; } + +int check_lcore_and_set_cpu(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) { + POWER_LOG(ERR, + "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 83f742f42a..c5034104d0 100644 --- a/lib/power/power_common.h +++ b/lib/power/power_common.h @@ -31,5 +31,5 @@ int open_core_sysfs_file(FILE **f, const char *mode, const char *format, ...) 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 check_lcore_and_set_cpu(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 32aaacb948..0a1d723bae 100644 --- a/lib/power/power_cppc_cpufreq.c +++ b/lib/power/power_cppc_cpufreq.c @@ -362,7 +362,12 @@ power_cppc_cpufreq_init(unsigned int lcore_id) return -1; } - pi->lcore_id = lcore_id; + if (check_lcore_and_set_cpu(lcore_id, &pi->lcore_id) < 0) { + 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) { POWER_LOG(ERR, "Cannot set governor of lcore %u to " diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c index 2343121621..116b130be2 100644 --- a/lib/power/power_pstate_cpufreq.c +++ b/lib/power/power_pstate_cpufreq.c @@ -564,7 +564,12 @@ power_pstate_cpufreq_init(unsigned int lcore_id) return -1; } - pi->lcore_id = lcore_id; + if (check_lcore_and_set_cpu(lcore_id, &pi->lcore_id) < 0) { + POWER_LOG(ERR, + "Cannot get cpu id mapped for lcore %u", lcore_id); + return -1; + } + /* Check and set the governor */ if (power_set_governor_performance(pi) < 0) { POWER_LOG(ERR, "Cannot set governor of lcore %u to " -- 2.34.1