From nobody Sat Oct 4 23:49:55 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=1758602389; cv=pass; d=zohomail.com; s=zohoarc; b=MAaKdW0QxsN2wPVQ/qeJzl76vZFQ/uZp85LcdPO3kaBm8GX9rg0A2NqXiyyFM3/smFIaD7lm5dcnYP6Ks4EyO7jSah3KUH6pGLJ1+wdi37u6tNAKt1sjDSMQCdB/AoCp6+DNwwpVDXvL7zqwRcFDDoVwgGhD3n/IaBttpKjhVls= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758602389; 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=UK7p1dxIdAUwnp9/KlnmFuOMlvoXNyC3ltvAs175wZ0=; b=gwaHczB8ZuB+vkO10hbNJpLq+JtGw9CjPwy4yRDp57xj3rlyPjCSJoerCnuWalpF03q39Iyl99wPpq52d4GHjSYXP3lFqacsFlZclwt24Wizb8pyqM8tfu0GHqpbNiTjWbPFxQ8QJ5UGoBRXk4w2JkEBBa5yslsW/oYB5I3t3QY= 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 1758602389510779.60590046693; Mon, 22 Sep 2025 21:39:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1128130.1468643 (Exim 4.92) (envelope-from ) id 1v0uoD-0002HM-Av; Tue, 23 Sep 2025 04:39:21 +0000 Received: by outflank-mailman (output) from mailman id 1128130.1468643; Tue, 23 Sep 2025 04:39:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1v0uoD-0002GV-4N; Tue, 23 Sep 2025 04:39:21 +0000 Received: by outflank-mailman (input) for mailman id 1128130; Tue, 23 Sep 2025 04:39:19 +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 1v0uoA-0000c8-Um for xen-devel@lists.xenproject.org; Tue, 23 Sep 2025 04:39:19 +0000 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazlp17011000f.outbound.protection.outlook.com [2a01:111:f403:c100::f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 42994bca-9837-11f0-9809-7dc792cee155; Tue, 23 Sep 2025 06:39:16 +0200 (CEST) Received: from SJ0PR03CA0379.namprd03.prod.outlook.com (2603:10b6:a03:3a1::24) by SA3PR12MB7829.namprd12.prod.outlook.com (2603:10b6:806:316::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.18; Tue, 23 Sep 2025 04:39:10 +0000 Received: from SJ1PEPF000023DA.namprd21.prod.outlook.com (2603:10b6:a03:3a1:cafe::a0) by SJ0PR03CA0379.outlook.office365.com (2603:10b6:a03:3a1::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.20 via Frontend Transport; Tue, 23 Sep 2025 04:39:09 +0000 Received: from satlexmb07.amd.com (165.204.84.17) by SJ1PEPF000023DA.mail.protection.outlook.com (10.167.244.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9182.0 via Frontend Transport; Tue, 23 Sep 2025 04:39:09 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 22 Sep 2025 21:39:04 -0700 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: 42994bca-9837-11f0-9809-7dc792cee155 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=InkQXB/oYYvDztmGOvNzuq0gdb7wGxCYKAP1vbr33jgjy99yQHsg6ym98vq2uhH03qCwsvclRjgTkxFX+khpKm1c61rM4i5bOuZmUMhZWNVs3o78BrzsdKCdpRwoKzD7EGWwUz3zK99JXjtqdCvE63TgdeQo8Fu0gam3pjJWIfBSwcRLYYCPa0Du+34Ftjhk9goLJT6Pr/DOPnjt3PRLzDwBC+l0zUvONifZxGLPUSqONfB6D8vL8dU27MjAuDJF6CZg95QJFkPU4B0UkbcI54/5QbcDIG2PyJirDkHLex5O3Z0puFt1WmOS+Aj7jYG/debBuN94m8I9XkSWieTKoA== 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=UK7p1dxIdAUwnp9/KlnmFuOMlvoXNyC3ltvAs175wZ0=; b=Hc3iSF9AIsX4PMi+eBB1vom6+2epv2fnDYW/Kst4vqHozLg+CrcG9A3V9H5XXwvoR/xIqMe/2ciNlnG+4vSeVgv2QE2OA8dkGhNE80+xbYYS7WKJtiI9xcOUCqBCw90PRK0/0ASPUZcEJu8g19nOfXplYxTSqkKl4DaJvEbefIjVxsqZehk1gm0Jo9AiNxlijrwoIYXIXhiNzdwdG/eia0QIJ+OAEyv5Ju+LzcqTCrs9gZRSdNmp6gaa4fHmOVjtVeZ54biUdETZQNcEZyTqJxz/G6+9VWhaUIQCqR3AFmKpVWkEPCY1iONwvN6T4Vq4RNxfuBjK88LKR1H/pAcJZA== 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=UK7p1dxIdAUwnp9/KlnmFuOMlvoXNyC3ltvAs175wZ0=; b=t3jvn98Dg337iCtF/PQLDIg5f2ThBJ3bTlGz286X5Qc8xQXCTlaBhhpTjxTAQ2joWfaYnyYSYvcOKuNDvmOBg8CV3ZVCaBwDLmkxWluDX16AXWU4eY04FR5e2RoPuUgb/BNphqDFnQog+xLgDOtJYqAazbwQFQo2eqBAS9ozK1M= 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=satlexmb07.amd.com; pr=C From: Penny Zheng To: CC: , Penny Zheng , Anthony PERARD , Juergen Gross , Andrew Cooper , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Stefano Stabellini" Subject: [PATCH v10 5/8] tools/cpufreq: extract CPPC para from cpufreq para Date: Tue, 23 Sep 2025 12:38:23 +0800 Message-ID: <20250923043826.3831957-6-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250923043826.3831957-1-Penny.Zheng@amd.com> References: <20250923043826.3831957-1-Penny.Zheng@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023DA:EE_|SA3PR12MB7829:EE_ X-MS-Office365-Filtering-Correlation-Id: 54b0e6f0-ac36-448d-8eb8-08ddfa5b236b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?pvOsfUH2VGXNCRGcFkTXkNL8tnMhWyN6MYQoIptQnxJt0rzy4zQ2XtV0h/nO?= =?us-ascii?Q?AJMwxTZhir+QyeAeDa8zND7utCNJaJQ6boug1NMkdx1oKX5jwsa8pdUY0ySq?= =?us-ascii?Q?5vzMS62kRVZn8fpNVhbmrMCEpHmWUzdC4WWh2cR4PCuAdzNQFnY01TVTszsL?= =?us-ascii?Q?tvLGR0xQ4r/L5OOtst6l8wAOstUTd9D0LIokqt74AxMxt7siVNUHJj4qCfg9?= =?us-ascii?Q?UF5mqWf6NCXGKRYuyi5wovocKbbF7gxQcXFp+wF2DdeWqjW7kIOi6yFZq6ha?= =?us-ascii?Q?bR3rcyTTRvXSTY4+f9j0jvwu5v0TLK0YlAiS37KXkq7qO4dMP3lI5G2sJvtH?= =?us-ascii?Q?ENRLx6kpeWNuSKp1SVr6aSz59RbD+udUPebT1UW5stxKVG9rS8ZtOpC/uMq4?= =?us-ascii?Q?OyObK0ILOr1d3WXWunTJYVRDTRplb/xIGEbjKmRDHniGzuvwEc3KhKFUHQi4?= =?us-ascii?Q?m0TbE/QnKI5cyLAqOibDnOcDn0RWMHRMAsXv9QJNnIFnKYwN0FnIfBSruThl?= =?us-ascii?Q?VO25dDwuqVzgDKHr65i1aFUKzT8Pz0M14PULyfMIJNV8Hq6c/nYWE9zh1VCE?= =?us-ascii?Q?FmPV6/m62T6NmGXpEcHNZ82Spt8jJUuZaC3usRhTI0OayUg1YDwGDcO+fTaf?= =?us-ascii?Q?SPxh6vwZHa3NrIC1enV8oPVJPZ6ar4aHALYVnktnCoWyvOy5am1lPnEdJg6c?= =?us-ascii?Q?FQ0BNISDtpZwnG9jPC+WRUCGt2JkWp4tRNSBSPyzpZAtt6X/6xdOD+GtKer0?= =?us-ascii?Q?wQ4WK2CEXtaONvQWmwDPxMt50hpfgWeIi+2LkLIDAo53nPBhEYpq55fVnpD2?= =?us-ascii?Q?hoW1iTGqgkKFFy7YYxixKHM28HD1PRPyI3TRSeHOSzEdZgtoFSYaLl8oqOrY?= =?us-ascii?Q?2QMwLRwVNc/YXS/IjzhCCiAVsSpzmM386ojfptyQGFsCuo187VXByEF+NA3N?= =?us-ascii?Q?I0rNL4a/fFUvzvaxVLV4OvAUX2+yCmr27ijht4Qp1Y23hnybtEDrnocKi5Q1?= =?us-ascii?Q?INh10mntjSsHQYWufgqeafKe7sdR1tt5gMOfXxNRbA4Fp9oI9/YiMonVBLRC?= =?us-ascii?Q?RfQFziTVAbo2Tv3sqD2zuMSp3uTMfyM1y9zxMSGD3atJAIE0K0ctpDVm+2xh?= =?us-ascii?Q?0IqFCah+BhNZYw16BRUdcNFrvJF99xDYs6y/Oxq5g0Ali1XeDvoxS1Q3HNij?= =?us-ascii?Q?fEgx2lkfBxXn+yOimrIq90Dfszj1Vk200qVH1AaVwacmUnX5eAlpSSDfkRK7?= =?us-ascii?Q?M8wdNnZwoIGO9zKDKoSOqWIHTLbaGaHr2YLmSipfSDVts50w48sprvFhMC44?= =?us-ascii?Q?B/UTRi6e2IFid75BX1vrc/j41VUuSs/AW91oqXFfnNsZJruHR2brox9G1yjq?= =?us-ascii?Q?byNr5Vu0YjvCQbSpCwnuIN+2D3jOmBAuaDfH7p44RMaQfZ1SiSN1iP3HJhqs?= =?us-ascii?Q?I8xDScut4yJ2e6rv570FOn3eWxPW3l2Rypj6xDjC3detar6DvWP6r1JbmAle?= =?us-ascii?Q?Fh9ItOAlWO/TR2kgIWhBI0a4WHt8nfmtpmot?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2025 04:39:09.8346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 54b0e6f0-ac36-448d-8eb8-08ddfa5b236b 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF000023DA.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7829 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1758602391473116600 Content-Type: text/plain; charset="utf-8" We extract cppc info from "struct xen_get_cpufreq_para", where it acts as a member of union, and share the space with governor info. However, it may fail in amd-cppc passive mode, in which governor info and CPPC info could co-exist, and both need to be printed together via xenpm to= ol. If we tried to still put it in "struct xen_get_cpufreq_para" (e.g. just move out of union), "struct xen_get_cpufreq_para" will enlarge too much to furth= er make xen_sysctl.u exceed 128 bytes. So we introduce a new sub-field GET_CPUFREQ_CPPC to dedicatedly acquire CPPC-related para, and make get-cpufreq-para invoke GET_CPUFREQ_CPPC if available. New helpers print_cppc_para() and get_cpufreq_cppc() are introduced to extract CPPC-related parameters process from cpufreq para. Signed-off-by: Penny Zheng Acked-by: Jan Beulich # hypervisor Acked-by: Anthony PERARD --- v4 -> v5: - new commit --- v5 -> v6: - remove the changes for get-cpufreq-para --- v6 -> v7: - make get-cpufreq-para invoke GET_CPUFREQ_CPPC --- v7 -> v8: - use structure assignment as it is a alias - add errno info to the error print --- v9 -> v10 - drop the outer union --- tools/include/xenctrl.h | 27 +++++----- tools/libs/ctrl/xc_pm.c | 47 +++++++++++----- tools/misc/xenpm.c | 103 ++++++++++++++++++++++-------------- xen/drivers/acpi/pm-op.c | 43 +++++++++------ xen/include/public/sysctl.h | 31 ++++++----- 5 files changed, 155 insertions(+), 96 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 965d3b585a..c14ecd66aa 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1924,22 +1924,19 @@ struct xc_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - union { - struct { - uint32_t scaling_cur_freq; + struct { + uint32_t scaling_cur_freq; =20 - char scaling_governor[CPUFREQ_NAME_LEN]; - uint32_t scaling_max_freq; - uint32_t scaling_min_freq; + char scaling_governor[CPUFREQ_NAME_LEN]; + uint32_t scaling_max_freq; + uint32_t scaling_min_freq; =20 - /* for specific governor */ - union { - xc_userspace_t userspace; - xc_ondemand_t ondemand; - } u; - } s; - xc_cppc_para_t cppc_para; - } u; + /* for specific governor */ + union { + xc_userspace_t userspace; + xc_ondemand_t ondemand; + } u; + } s; =20 int32_t turbo_enabled; }; @@ -1953,6 +1950,8 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value); int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, xc_set_cppc_para_t *set_cppc); +int xc_get_cppc_para(xc_interface *xch, unsigned int cpuid, + xc_cppc_para_t *cppc_para); int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq); =20 int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value); diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index 6fda973f1f..5b4e489acf 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -274,25 +274,24 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, /* * Copy to user_para no matter what cpufreq driver/governor. * - * First sanity check layout of the union subject to memcpy() belo= w. + * First sanity check layout of the struct subject to memcpy() bel= ow. */ - BUILD_BUG_ON(sizeof(user_para->u) !=3D sizeof(sys_para->u)); + BUILD_BUG_ON(sizeof(user_para->s) !=3D sizeof(sys_para->s)); =20 #define CHK_FIELD(fld) \ - BUILD_BUG_ON(offsetof(typeof(user_para->u), fld) !=3D \ - offsetof(typeof(sys_para->u), fld)) + BUILD_BUG_ON(offsetof(typeof(user_para->s), fld) !=3D \ + offsetof(typeof(sys_para->s), fld)) =20 - CHK_FIELD(s.scaling_cur_freq); - CHK_FIELD(s.scaling_governor); - CHK_FIELD(s.scaling_max_freq); - CHK_FIELD(s.scaling_min_freq); - CHK_FIELD(s.u.userspace); - CHK_FIELD(s.u.ondemand); - CHK_FIELD(cppc_para); + CHK_FIELD(scaling_cur_freq); + CHK_FIELD(scaling_governor); + CHK_FIELD(scaling_max_freq); + CHK_FIELD(scaling_min_freq); + CHK_FIELD(u.userspace); + CHK_FIELD(u.ondemand); =20 #undef CHK_FIELD =20 - memcpy(&user_para->u, &sys_para->u, sizeof(sys_para->u)); + memcpy(&user_para->s, &sys_para->s, sizeof(sys_para->s)); } =20 unlock_4: @@ -366,6 +365,30 @@ int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, return ret; } =20 +int xc_get_cppc_para(xc_interface *xch, unsigned int cpuid, + xc_cppc_para_t *cppc_para) +{ + int ret; + struct xen_sysctl sysctl =3D {}; + + if ( !xch || !cppc_para ) + { + errno =3D EINVAL; + return -1; + } + + sysctl.cmd =3D XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =3D GET_CPUFREQ_CPPC; + sysctl.u.pm_op.cpuid =3D cpuid; + + ret =3D xc_sysctl(xch, &sysctl); + if ( ret ) + return ret; + + *cppc_para =3D sysctl.u.pm_op.u.get_cppc; + return ret; +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret =3D 0; diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 6b054b10a4..c7f19cea28 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -801,6 +801,34 @@ static unsigned int calculate_activity_window(const xc= _cppc_para_t *cppc, return mantissa * multiplier; } =20 +/* print out parameters about cpu cppc */ +static void print_cppc_para(unsigned int cpuid, + const xc_cppc_para_t *cppc) +{ + printf("cppc variables :\n"); + printf(" hardware limits : lowest [%"PRIu32"] lowest nonlinear [%"= PRIu32"]\n", + cppc->lowest, cppc->lowest_nonlinear); + printf(" : nominal [%"PRIu32"] highest [%"PRIu32"]= \n", + cppc->nominal, cppc->highest); + printf(" configured limits : min [%"PRIu32"] max [%"PRIu32"] energy = perf [%"PRIu32"]\n", + cppc->minimum, cppc->maximum, cppc->energy_perf); + + if ( cppc->features & XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW ) + { + unsigned int activity_window; + const char *units; + + activity_window =3D calculate_activity_window(cppc, &units); + printf(" : activity_window [%"PRIu32" %s]\n", + activity_window, units); + } + + printf(" : desired [%"PRIu32"%s]\n", + cppc->desired, + cppc->desired ? "" : " hw autonomous"); + printf("\n"); +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { @@ -826,71 +854,45 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) =20 printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); =20 - if ( hwp ) - { - const xc_cppc_para_t *cppc =3D &p_cpufreq->u.cppc_para; - - printf("cppc variables :\n"); - printf(" hardware limits : lowest [%"PRIu32"] lowest nonlinear= [%"PRIu32"]\n", - cppc->lowest, cppc->lowest_nonlinear); - printf(" : nominal [%"PRIu32"] highest [%"PRIu= 32"]\n", - cppc->nominal, cppc->highest); - printf(" configured limits : min [%"PRIu32"] max [%"PRIu32"] ene= rgy perf [%"PRIu32"]\n", - cppc->minimum, cppc->maximum, cppc->energy_perf); - - if ( cppc->features & XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW ) - { - unsigned int activity_window; - const char *units; - - activity_window =3D calculate_activity_window(cppc, &units); - printf(" : activity_window [%"PRIu32" %s]\= n", - activity_window, units); - } - - printf(" : desired [%"PRIu32"%s]\n", - cppc->desired, - cppc->desired ? "" : " hw autonomous"); - } - else + if ( !hwp ) { if ( p_cpufreq->gov_num ) printf("scaling_avail_gov : %s\n", p_cpufreq->scaling_available_governors); =20 - printf("current_governor : %s\n", p_cpufreq->u.s.scaling_gover= nor); - if ( !strncmp(p_cpufreq->u.s.scaling_governor, + printf("current_governor : %s\n", p_cpufreq->s.scaling_governo= r); + if ( !strncmp(p_cpufreq->s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { printf(" userspace specific :\n"); printf(" scaling_setspeed : %u\n", - p_cpufreq->u.s.u.userspace.scaling_setspeed); + p_cpufreq->s.u.userspace.scaling_setspeed); } - else if ( !strncmp(p_cpufreq->u.s.scaling_governor, + else if ( !strncmp(p_cpufreq->s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { printf(" ondemand specific :\n"); printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.u.ondemand.sampling_rate_max, - p_cpufreq->u.s.u.ondemand.sampling_rate_min, - p_cpufreq->u.s.u.ondemand.sampling_rate); + p_cpufreq->s.u.ondemand.sampling_rate_max, + p_cpufreq->s.u.ondemand.sampling_rate_min, + p_cpufreq->s.u.ondemand.sampling_rate); printf(" up_threshold : %u\n", - p_cpufreq->u.s.u.ondemand.up_threshold); + p_cpufreq->s.u.ondemand.up_threshold); } =20 printf("scaling_avail_freq :"); for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D - p_cpufreq->u.s.scaling_cur_freq ) + p_cpufreq->s.scaling_cur_freq ) printf(" *%d", p_cpufreq->scaling_available_frequencies[i]= ); else printf(" %d", p_cpufreq->scaling_available_frequencies[i]); printf("\n"); =20 printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.scaling_max_freq, - p_cpufreq->u.s.scaling_min_freq, - p_cpufreq->u.s.scaling_cur_freq); + p_cpufreq->s.scaling_max_freq, + p_cpufreq->s.scaling_min_freq, + p_cpufreq->s.scaling_cur_freq); } =20 printf("turbo mode : %s\n", @@ -898,6 +900,24 @@ static void print_cpufreq_para(int cpuid, struct xc_ge= t_cpufreq_para *p_cpufreq) printf("\n"); } =20 +/* show cpu cppc parameters information on CPU cpuid */ +static int show_cppc_para_by_cpuid(xc_interface *xc_handle, unsigned int c= puid) +{ + int ret; + xc_cppc_para_t cppc_para; + + ret =3D xc_get_cppc_para(xc_handle, cpuid, &cppc_para); + if ( !ret ) + print_cppc_para(cpuid, &cppc_para); + else if ( errno =3D=3D ENODEV ) + ret =3D 0; /* Ignore unsupported platform */ + else + fprintf(stderr, "[CPU%u] failed to get cppc parameter: %s\n", + cpuid, strerror(errno)); + + return ret; +} + /* show cpu frequency parameters information on CPU cpuid */ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) { @@ -957,7 +977,12 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc= _handle, int cpuid) } while ( ret && errno =3D=3D EAGAIN ); =20 if ( ret =3D=3D 0 ) + { print_cpufreq_para(cpuid, p_cpufreq); + + /* Show CPPC parameters if available */ + ret =3D show_cppc_para_by_cpuid(xc_handle, cpuid); + } else if ( errno =3D=3D ENODEV ) { ret =3D -ENODEV; diff --git a/xen/drivers/acpi/pm-op.c b/xen/drivers/acpi/pm-op.c index a7eaf29c31..f50acd7088 100644 --- a/xen/drivers/acpi/pm-op.c +++ b/xen/drivers/acpi/pm-op.c @@ -77,6 +77,17 @@ static int read_scaling_available_governors(char *scalin= g_available_governors, return 0; } =20 +static int get_cpufreq_cppc(unsigned int cpu, + struct xen_get_cppc_para *cppc_para) +{ + int ret =3D -ENODEV; + + if ( hwp_active() ) + ret =3D get_hwp_para(cpu, cppc_para); + + return ret; +} + static int get_cpufreq_para(struct xen_sysctl_pm_op *op) { uint32_t ret =3D 0; @@ -143,9 +154,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) else strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); =20 - if ( hwp_active() ) - ret =3D get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para); - else + if ( !hwp_active() ) { if ( !(scaling_available_governors =3D xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) @@ -165,29 +174,29 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *= op) if ( ret ) return -EFAULT; =20 - op->u.get_para.u.s.scaling_cur_freq =3D policy->cur; - op->u.get_para.u.s.scaling_max_freq =3D policy->max; - op->u.get_para.u.s.scaling_min_freq =3D policy->min; + op->u.get_para.s.scaling_cur_freq =3D policy->cur; + op->u.get_para.s.scaling_max_freq =3D policy->max; + op->u.get_para.s.scaling_min_freq =3D policy->min; =20 if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.u.s.scaling_governor, + strlcpy(op->u.get_para.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", + strlcpy(op->u.get_para.s.scaling_governor, "Unknown", CPUFREQ_NAME_LEN); =20 /* governor specific para */ - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + if ( !strncasecmp(op->u.get_para.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) - op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cu= r; + op->u.get_para.s.u.userspace.scaling_setspeed =3D policy->cur; =20 - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + if ( !strncasecmp(op->u.get_para.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) ret =3D get_cpufreq_ondemand_para( - &op->u.get_para.u.s.u.ondemand.sampling_rate_max, - &op->u.get_para.u.s.u.ondemand.sampling_rate_min, - &op->u.get_para.u.s.u.ondemand.sampling_rate, - &op->u.get_para.u.s.u.ondemand.up_threshold); + &op->u.get_para.s.u.ondemand.sampling_rate_max, + &op->u.get_para.s.u.ondemand.sampling_rate_min, + &op->u.get_para.s.u.ondemand.sampling_rate, + &op->u.get_para.s.u.ondemand.up_threshold); } =20 return ret; @@ -385,6 +394,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) ret =3D set_cpufreq_para(op); break; =20 + case GET_CPUFREQ_CPPC: + ret =3D get_cpufreq_cppc(op->cpuid, &op->u.get_cppc); + break; + case SET_CPUFREQ_CPPC: ret =3D set_cpufreq_cppc(op); break; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index eb3a23b038..66c9b65465 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -478,22 +478,19 @@ struct xen_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - union { - struct { - uint32_t scaling_cur_freq; - - char scaling_governor[CPUFREQ_NAME_LEN]; - uint32_t scaling_max_freq; - uint32_t scaling_min_freq; - - /* for specific governor */ - union { - struct xen_userspace userspace; - struct xen_ondemand ondemand; - } u; - } s; - struct xen_get_cppc_para cppc_para; - } u; + struct { + uint32_t scaling_cur_freq; + + char scaling_governor[CPUFREQ_NAME_LEN]; + uint32_t scaling_max_freq; + uint32_t scaling_min_freq; + + /* for specific governor */ + union { + struct xen_userspace userspace; + struct xen_ondemand ondemand; + } u; + } s; =20 int32_t turbo_enabled; }; @@ -523,6 +520,7 @@ struct xen_sysctl_pm_op { #define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03) #define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04) #define SET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x05) + #define GET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x06) =20 /* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 @@ -547,6 +545,7 @@ struct xen_sysctl_pm_op { uint32_t cpuid; union { struct xen_get_cpufreq_para get_para; + struct xen_get_cppc_para get_cppc; struct xen_set_cpufreq_gov set_gov; struct xen_set_cpufreq_para set_para; struct xen_set_cppc_para set_cppc; --=20 2.34.1