From nobody Fri Oct 31 09:48:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1755859989; cv=pass; d=zohomail.com; s=zohoarc; b=jrjZBRo5ZoBWaTB7EwCdWTamQxanrwvKZwn2BmVtO5yG4y8eO7KANF2YE6pli+x0hKakmzP7JxGtXlqIQ5+r9BlknFOEfsBJ5cqvPgGDzOJIkeUTTxF2cN/DbSkifTwU+0dH626okMboui9IWdZ6K3uJMjgMNc6TBn0vYueFNxs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755859989; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D2XK2lTZ2SBex3RziRQL8HeksHeSo3yOclpXyhaZDEU=; b=AhnbwvLRtIqtSirgOtkNV4NAXFQ+YZjX1k7X0J/bxXJy/sKOGLAtaYdma63DLYNEdJIaYPakiB4etQ8s7zblsT3pjQQet7aW28kIJ2UB7qtx6hsyCZihX0LjTQwL8t0xSCcHYvXduEyQO5x0qJlWhJltoabYIJQq+DisANl5agg= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1755859989852210.12448620118664; Fri, 22 Aug 2025 03:53:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1089855.1447355 (Exim 4.92) (envelope-from ) id 1upPOA-0000eD-9G; Fri, 22 Aug 2025 10:52:54 +0000 Received: by outflank-mailman (output) from mailman id 1089855.1447355; Fri, 22 Aug 2025 10:52:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1upPOA-0000e0-5O; Fri, 22 Aug 2025 10:52:54 +0000 Received: by outflank-mailman (input) for mailman id 1089855; Fri, 22 Aug 2025 10:52:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1upPO8-00083s-Fn for xen-devel@lists.xenproject.org; Fri, 22 Aug 2025 10:52:52 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062a.outbound.protection.outlook.com [2a01:111:f403:200a::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 25b228d7-7f46-11f0-b898-0df219b8e170; Fri, 22 Aug 2025 12:52:50 +0200 (CEST) Received: from BN0PR07CA0022.namprd07.prod.outlook.com (2603:10b6:408:141::14) by BN5PR12MB9510.namprd12.prod.outlook.com (2603:10b6:408:2ac::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9052.17; Fri, 22 Aug 2025 10:52:46 +0000 Received: from BN1PEPF00004686.namprd03.prod.outlook.com (2603:10b6:408:141:cafe::ae) by BN0PR07CA0022.outlook.office365.com (2603:10b6:408:141::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9052.18 via Frontend Transport; Fri, 22 Aug 2025 10:52:46 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN1PEPF00004686.mail.protection.outlook.com (10.167.243.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.9052.8 via Frontend Transport; Fri, 22 Aug 2025 10:52:46 +0000 Received: from penny-System-Product-Name.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; Fri, 22 Aug 2025 05:52:44 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 25b228d7-7f46-11f0-b898-0df219b8e170 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nLCkSb2lujBBME2a0xHV/vMaovh0k496xZQGdS4Jy1kwbkqrL0T/KndqpjQm8EKnQZKTw4qonw1rdIa09W7le+G5O40OgsnBUuflFlgihp+zoBlN5baci4lWFkv4pBA9tBybjiPr/W7JD6fGsODE8fual3yYksg4E+zJGMHtH/goeSmpsMvCdhbBJmnvKxSVljyTZLbegT/9v+SyhERmT8ZpXWqMcfPiPgihoW33PZZs9lZOC/wx3GSKYLgXEWNCCqy6L1/smUY1UgxJp+d0xZNrYMTU5lS5WvnQGEP3SOy/TPPqLM6XJXjMiFQJP3+znkuM4RNabVKXgFbh/8Wkew== 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=D2XK2lTZ2SBex3RziRQL8HeksHeSo3yOclpXyhaZDEU=; b=x08bx9z73OwhAwkmYu4CE5j9CZPX+SRU5bN/Q4WYoRCEiqWW28HEmrfo9pGaB9Fq0Ztuz7qMpfDvY3SyBvb0BXvVga/xUxW9wOiUhnnWiZ5PP2DUdJ8X4LrlNTc7EtLLVA39s9V8BK2tP58xFs+gmCgFVH4ij5+JWUqYzk2uMrBIbCnBO3D0wtSAZj182HMLMhVhSdpZYOcyUCbn12V0hdrHpwORF9iIK5eA9CUjeWigY6XaxMqWsgndlnyLbtZqw/aHj2wH+3mQ6J4zLmf2l4N9TSjdWLJvIzv6arombk9vxTIBKzBlRsZzUBTdzN+F/24lN0/o4QIvUE8TpS2RmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D2XK2lTZ2SBex3RziRQL8HeksHeSo3yOclpXyhaZDEU=; b=HU+yZi8klrOUFy9TmiJMhvX+tX1U0WgisgcJMdDg9ZRdbOOh4kgh9IKGLIbfaTIbLfDXOu0EIVYfRAzOIn03LXOMcUpJLlcJYD8QRLK7tU2SnzYA04YD8xd67JyycVHi5yRpJ0h7fHpX/pnOQZJ6AqXjz9kK0C2OxATW/kIC+/I= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 From: Penny Zheng To: CC: , Penny Zheng , Jan Beulich Subject: [PATCH v7 05/13] xen/cpufreq: refactor cmdline "cpufreq=xxx" Date: Fri, 22 Aug 2025 18:52:10 +0800 Message-ID: <20250822105218.3601273-6-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250822105218.3601273-1-Penny.Zheng@amd.com> References: <20250822105218.3601273-1-Penny.Zheng@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: BN1PEPF00004686:EE_|BN5PR12MB9510:EE_ X-MS-Office365-Filtering-Correlation-Id: dd32c5e6-0779-4709-5739-08dde16a0773 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mQu4Z371crSqK/+0ZkgpBKGVTX2tkTzqkNwoQoWurI4pDC9JOCnzizvNSz78?= =?us-ascii?Q?bXI18/+onbRKTBiPghdVlfu41CgYu56jTv5M9B6lnCjKTn66w/DrI0uYVRGX?= =?us-ascii?Q?jzQXvA0COd5ijFmScaa7HfKEKXToKR0bdy+LIzjXOXHlkpSPZJmX69ie37QW?= =?us-ascii?Q?n8i/MjrOkiy5KV/pdFp/6bTqsziCvIxeHrlrsMl0wz7GPJJ7T6rPYuNTtn9q?= =?us-ascii?Q?GQNNx525+lAqQ901vB0wjdPw2Nc02KPQitSQK4p1Nyc7gwabJ+6lCKdRk3/D?= =?us-ascii?Q?xMFkdpnhG/0dYeKMre30mqVrTFOnZCwqUX+jZaeHBCMlvJIgJVd7f8NBRxTb?= =?us-ascii?Q?dWmHbKynJIaSWd368IzzENpYTcmgwPYeMwE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Pc83I3S815fbmQSVp9Tp3Ry3RcdQSLNk6lg7iPM9VbEH4u?= =?us-ascii?Q?is24ulsHjhGF3ksAwrhuszMAjEDUHJ8cPTlYEkd3BZb5oq7Q14ySy5WXhXXY?= =?us-ascii?Q?mAUyIW5WRTIQeuBzWx6BwnObUdctiOJl7gHJ5ePPMjb/+IJWAYu2kg0I3grv?= =?us-ascii?Q?CQ5wvNORy2cUqTScutQROs565kNO+1oEK0Ha6Gc711774GVKgKsx88JkP6Bh?= =?us-ascii?Q?PGD/A+id/H4lqhHPWIS2DEGb2bBegIte1O/9?= 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)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Aug 2025 10:52:46.3841 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd32c5e6-0779-4709-5739-08dde16a0773 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: BN1PEPF00004686.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9510 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1755859997674124101 Content-Type: text/plain; charset="utf-8" A helper function handle_cpufreq_cmdline() is introduced to tidy different handling pathes. We also add a new helper cpufreq_opts_contain() to ignore redundant setting, like "cpufreq=3Dhwp;hwp;xen" As only slot 0 of cpufreq_xen_opts[] needs explicit initializing with non-zero CPUFREQ_xen, dropping full array initializer could avoid touching initializer every time it grows Signed-off-by: Penny Zheng Reviewed-by: Jan Beulich --- v2 -> v3: - new commit --- v3 -> v4: - add one single helper to do the tidy work - ignore and warn user redundant setting --- v4 -> v5: - make "cpufreq_opts_str" static and the string literals end up in .init.rodata. - use "CPUFREQ_xxx" as array slot index - blank line between non-fall-through case blocks --- v5 -> v6: - change to "while ( count-- )" - remove unnecessary warning - add an assertion to ensure not overruning the array - add ASSERT_UNREACHABLE() - check ret of handle_cpufreq_cmdline() and error out --- v6 -> v7: - remove overrun assertion as we already have check in setup_cpufreq_option= () - drop full array initializer --- xen/drivers/cpufreq/cpufreq.c | 55 +++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index efba141418..de17e53708 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -64,12 +64,49 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); /* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller =3D FREQCTL_xen; =20 -enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] =3D { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] =3D { CPUFREQ_xen }; unsigned int __initdata cpufreq_xen_cnt =3D 1; =20 static int __init cpufreq_cmdline_parse(const char *s, const char *e); =20 +static bool __init cpufreq_opts_contain(enum cpufreq_xen_opt option) +{ + unsigned int count =3D cpufreq_xen_cnt; + + while ( count-- ) + { + if ( cpufreq_xen_opts[count] =3D=3D option ) + return true; + } + + return false; +} + +static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) +{ + int ret =3D 0; + + if ( cpufreq_opts_contain(option) ) + return 0; + + cpufreq_controller =3D FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] =3D option; + switch ( option ) + { + case CPUFREQ_hwp: + case CPUFREQ_xen: + xen_processor_pmbits |=3D XEN_PROCESSOR_PM_PX; + break; + + default: + ASSERT_UNREACHABLE(); + ret =3D -EINVAL; + break; + } + + return ret; +} + static int __init cf_check setup_cpufreq_option(const char *str) { const char *arg =3D strpbrk(str, ",:;"); @@ -113,21 +150,15 @@ static int __init cf_check setup_cpufreq_option(const= char *str) =20 if ( choice > 0 || !cmdline_strcmp(str, "xen") ) { - xen_processor_pmbits |=3D XEN_PROCESSOR_PM_PX; - cpufreq_controller =3D FREQCTL_xen; - cpufreq_xen_opts[cpufreq_xen_cnt++] =3D CPUFREQ_xen; - ret =3D 0; - if ( arg[0] && arg[1] ) + ret =3D handle_cpufreq_cmdline(CPUFREQ_xen); + if ( !ret && arg[0] && arg[1] ) ret =3D cpufreq_cmdline_parse(arg + 1, end); } else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 && !cmdline_strcmp(str, "hwp") ) { - xen_processor_pmbits |=3D XEN_PROCESSOR_PM_PX; - cpufreq_controller =3D FREQCTL_xen; - cpufreq_xen_opts[cpufreq_xen_cnt++] =3D CPUFREQ_hwp; - ret =3D 0; - if ( arg[0] && arg[1] ) + ret =3D handle_cpufreq_cmdline(CPUFREQ_hwp); + if ( !ret && arg[0] && arg[1] ) ret =3D hwp_cmdline_parse(arg + 1, end); } else --=20 2.34.1