From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434340; cv=none; d=zohomail.com; s=zohoarc; b=KjMOe+VoxfL/WhPdx+RZjWEz5MPB0U8sCMTVmFWbUMg3Md8KRgf9+r+Ewu6IxPWJK8Cs4e7reIwDmzvbLMa7ZkJWmJUH/5W+gG+rPWnz/N5BWpHUEzfD0uS5X3YLnOegttAn8v5DVHfgmvQJrpbo7/4+vBDmdQd/c7c6aTaLV+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434340; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vNQhWJqSLtysm6iaINr+s0i3gnrhiDBqgnXkQD6RBcM=; b=a6JXFOIEjzlqDq8CQav/q+sN0n6Patfb3jKS7/apZFqe0rQdZoqKGMQN98cIHs5f9RjNZUMMSJhobm8++1LoP0xS12xIyQWWPHvq+wM4O2X8k+AMtvj9yj1MGafzbVOvfX0wTF28bNU8Nn8WbJuV+Lm6GfWjsGKr/q52WQ7g9U4= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434340703649.9822150727814; Mon, 7 Aug 2023 11:52:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578787.906466 (Exim 4.92) (envelope-from ) id 1qT5KZ-0004Vf-0Q; Mon, 07 Aug 2023 18:51:51 +0000 Received: by outflank-mailman (output) from mailman id 578787.906466; Mon, 07 Aug 2023 18:51:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5KY-0004VY-TP; Mon, 07 Aug 2023 18:51:50 +0000 Received: by outflank-mailman (input) for mailman id 578787; Mon, 07 Aug 2023 18:51:50 +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 1qT5KY-0004GT-AB for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:51:50 +0000 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [2607:f8b0:4864:20::f32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 76796329-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:51:48 +0200 (CEST) Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-63cf9eddbc6so27013826d6.0 for ; Mon, 07 Aug 2023 11:51:48 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:51:46 -0700 (PDT) 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: 76796329-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434307; x=1692039107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vNQhWJqSLtysm6iaINr+s0i3gnrhiDBqgnXkQD6RBcM=; b=V3bDDlxVvi0tsUCmaHrr4kIxZRNDwH5cDbN2sq75I1MZcutfJ0gvNx9gtMtV5mjPyb donPyty3kc0fEgDAjshZsCWmZ4Bil9mwTLggUFolENijiSmEpu/hYwi6wjRkWvYLmSXK Pbhqj74Qb1WTGwu1iQd0Bs+uZd7L/6w/s2vKXL8c6VRfGY73bJUeslXwgHPkC4UP1ZIL faaaVdlIORfr4kckqu4P3g9aXEI/JxtjpbLdynC4dEFAOz2uyEStr2EuCOTA5RJKtxFY Qhgl0MHicM2Txwy5zvgb371xvT5Bqw7VF/BApMGVeQZu6cZDpRsgOeT4Bk0qCsiXWxME xikA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434307; x=1692039107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vNQhWJqSLtysm6iaINr+s0i3gnrhiDBqgnXkQD6RBcM=; b=aegO1ldYkIjzlULGj2F+wNUJsAMLk8nxSlB8nMdTHpOR/0hhWHp9xLu1BJlo2lCQvn oRDG54o7+GdhMvN2XtWHNqk0hXlQkeYBjqIytVvCNHcfPn5uLMOxHElq3ljiyUVbzr9I qlu5Hms789MWhymnSzDxDe5F+HpXrq2t2C3nAr9bJV+H172JkrvfP9/buiBNaiG8VpJW ACZt/ZWVGScQp2kT3+cPo2QW87Jh1yIYgUUOG5zmdONN+R/qJhZzV02zbt9iegssbQq1 8rhrMZDrgg0ac92gjodx4LmpIXB0F0Fm5amsHc3LxzHw5xYWMKggO4qwZE7t800A77io X33g== X-Gm-Message-State: AOJu0Yz0QMW7x17EeKFkOKFmeST4iSCfWHfVVuPPfCaUhRm3Bvina6Dv MV3WA4alIuixwUQeC9zUay9dGkVbxJs= X-Google-Smtp-Source: AGHT+IGl7Y+1vn0bVef3zX0I0/p0lA+FKwyNiCKLG9/u/GHkJkHhIVMiSSz2y/CABd06pOC5Vny+Kw== X-Received: by 2002:a05:6214:e6b:b0:63f:6ec7:9f7 with SMTP id jz11-20020a0562140e6b00b0063f6ec709f7mr9620469qvb.23.1691434307160; Mon, 07 Aug 2023 11:51:47 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich Subject: [PATCH v8 01/15] cpufreq: Allow restricting to internal governors only Date: Mon, 7 Aug 2023 14:51:05 -0400 Message-ID: <20230807185119.98333-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434341456100001 Content-Type: text/plain; charset="utf-8" For hwp, the standard governors are not usable, and only the internal one is applicable. Add the cpufreq_governor_internal boolean to indicate when an internal governor, like hwp, will be used. This is set during presmp_initcall, and governor registration can be skipped when called during initcall. This way unusable governors are not registered, and only compatible governors are advertised to userspace. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v6: Add Jan's Ack v5: Check cpufreq_governor_internal and skip registration as applicable Remove internal flag v4: Rework to use an internal flag Removed Jan's Ack since the approach is different. v3: Switch to initdata Add Jan Acked-by Commit message s/they/the/ typo Don't register hwp-internal when running non-hwp - Marek v2: Switch to "-internal" Add blank line in header --- xen/drivers/cpufreq/cpufreq.c | 1 + xen/drivers/cpufreq/cpufreq_misc_governors.c | 9 +++++++++ xen/drivers/cpufreq/cpufreq_ondemand.c | 3 +++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 4 files changed, 15 insertions(+) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 2321c7dd07..67a58d409b 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -56,6 +56,7 @@ struct cpufreq_dom { }; static LIST_HEAD_READ_MOSTLY(cpufreq_dom_list_head); =20 +bool __initdata cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); =20 diff --git a/xen/drivers/cpufreq/cpufreq_misc_governors.c b/xen/drivers/cpu= freq/cpufreq_misc_governors.c index f5571f5486..0327fad23b 100644 --- a/xen/drivers/cpufreq/cpufreq_misc_governors.c +++ b/xen/drivers/cpufreq/cpufreq_misc_governors.c @@ -120,6 +120,9 @@ static int __init cf_check cpufreq_gov_userspace_init(v= oid) { unsigned int cpu; =20 + if ( cpufreq_governor_internal ) + return 0; + for_each_online_cpu(cpu) per_cpu(cpu_set_freq, cpu) =3D userspace_cmdline_freq; register_cpu_notifier(&cpufreq_userspace_cpu_nfb); @@ -162,6 +165,9 @@ struct cpufreq_governor cpufreq_gov_performance =3D { =20 static int __init cf_check cpufreq_gov_performance_init(void) { + if ( cpufreq_governor_internal ) + return 0; + return cpufreq_register_governor(&cpufreq_gov_performance); } __initcall(cpufreq_gov_performance_init); @@ -201,6 +207,9 @@ struct cpufreq_governor cpufreq_gov_powersave =3D { =20 static int __init cf_check cpufreq_gov_powersave_init(void) { + if ( cpufreq_governor_internal ) + return 0; + return cpufreq_register_governor(&cpufreq_gov_powersave); } __initcall(cpufreq_gov_powersave_init); diff --git a/xen/drivers/cpufreq/cpufreq_ondemand.c b/xen/drivers/cpufreq/c= pufreq_ondemand.c index fbcd14d6c3..06cfc88d30 100644 --- a/xen/drivers/cpufreq/cpufreq_ondemand.c +++ b/xen/drivers/cpufreq/cpufreq_ondemand.c @@ -360,6 +360,9 @@ struct cpufreq_governor cpufreq_gov_dbs =3D { =20 static int __init cf_check cpufreq_gov_dbs_init(void) { + if ( cpufreq_governor_internal ) + return 0; + return cpufreq_register_governor(&cpufreq_gov_dbs); } __initcall(cpufreq_gov_dbs_init); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 35dcf21e8f..44fc4c58fc 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -116,6 +116,8 @@ extern struct cpufreq_governor cpufreq_gov_powersave; =20 extern struct list_head cpufreq_governor_list; =20 +extern bool cpufreq_governor_internal; + extern int cpufreq_register_governor(struct cpufreq_governor *governor); extern struct cpufreq_governor *__find_governor(const char *governor); #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434347; cv=none; d=zohomail.com; s=zohoarc; b=I7iuOmtzWYXXLg5wpfvnswkumLZ6AKffH4RUTRI4+7ClfVdEZoppoy5JWUl2dPw5XENFxglyZk+9DQ0HF9XbB66dZG9qWk25lS8ekilLxrrIrTWG+ZdmTpzbfoJqGQzBtDjb7A9T/9mh5iieQrpG4g6wwPr0fXV0ctpB7A+jaLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434347; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tj29XCVclI+6QGR1ahwKo+P0a4dIzt4OqPyhJ7hCJ/k=; b=UNh6Iz6DfrMxHNw2vc3UyrACXs0/Z5HpfBcbBAMw0kguEjTOeotmQy42wca4X3z+YFKXmoVM5zBXn9Cfq1Lagz8aov7NxUkLniHDc0iSicHHEoE0RZP2lXui3OHRkm/DQryXV8y3umCl0bR87eELAmoOm7ymfa/M/ua+Vo6gW80= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434347477273.42051200538526; Mon, 7 Aug 2023 11:52:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578788.906475 (Exim 4.92) (envelope-from ) id 1qT5Kc-0004mj-8k; Mon, 07 Aug 2023 18:51:54 +0000 Received: by outflank-mailman (output) from mailman id 578788.906475; Mon, 07 Aug 2023 18:51: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 1qT5Kc-0004ma-5x; Mon, 07 Aug 2023 18:51:54 +0000 Received: by outflank-mailman (input) for mailman id 578788; Mon, 07 Aug 2023 18:51:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kb-0004lg-0s for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:51:53 +0000 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [2607:f8b0:4864:20::729]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7807c4db-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:51:51 +0200 (CEST) Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-7658752ce2fso307674185a.1 for ; Mon, 07 Aug 2023 11:51:51 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:51:49 -0700 (PDT) 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: 7807c4db-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434310; x=1692039110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tj29XCVclI+6QGR1ahwKo+P0a4dIzt4OqPyhJ7hCJ/k=; b=MlsbqQcJyX9jN9lriHM0iDQ7gR5CoydJhp8pi3OdLiGwI71DCySx/z0maO1HF61T83 FpNuso2rFHyFlar631WV906NN1tUBjpxJ0SbSPcSNUga2jI+DOY+Ah5CI4s+gFAhwGPL z/3B1ChBKLay6Eo41f7+XsHNoLpxSWGhvNHMaHPi4rVFHH1qecrz5M2RK2d8MlhmIxXr ijsDkh+bw6EaguEg9c5GSBTQogItxt1YI9o8Ox0whZiczCH1GGSO2IMoSEDXOu5fXREc s3/g/VRmSwrNKl6vQ1IY/wsUTgHlgHDd+ZJpGohCjofBhf3hLo7wtRTomBXrPqXHdfQL ZHTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434310; x=1692039110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tj29XCVclI+6QGR1ahwKo+P0a4dIzt4OqPyhJ7hCJ/k=; b=CffovdcvpOnKxFSj5L5e/F64cxvF2gHh3Byg22CJFyKKCXqki6UqNlIG0NT5qtUn4H FMGBC4/FcF0ToxhwnhjFOI75MPMKL4YqF7i5RxT2xC48hMH6GI6bwFHJBrDhZG2fyolu WUgH5gvepsxjuJKEvcds7K5gzSoAcammJRiC7PsDqAJiBJLGVHWsLHNzW7vK4Xe/5PKG cbx1rADnDRV1HIoI3ttwhQEg5j6vKk/VJFR7rIV6wo5MRcg0qjNy47VVfCx/glFWBmu1 ZhOzrl+wQOhGMqt64MfBYbgRuQnR+jHI22zT2uSvhlN2v3yKwv/hG/+YllMzHF7MVqBY 8rSw== X-Gm-Message-State: AOJu0Yw1y/KOWYI93A2Q57sB9fNCFnjFXBbBmK4BqJrgHdms94qGi9hK NBmw9M3zFh15y69WO5AUAx2/2e1kmlM= X-Google-Smtp-Source: AGHT+IGgGCC4XZiOpihmt9Ail03iR8azEz/pl5MYhM5hiOtjuCf1gBvEFIOfCMwg9A7Dcb2mI3FMoA== X-Received: by 2002:ad4:569a:0:b0:62d:fa7c:6b95 with SMTP id bd26-20020ad4569a000000b0062dfa7c6b95mr8654681qvb.32.1691434309726; Mon, 07 Aug 2023 11:51:49 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v8 02/15] cpufreq: Add perf_freq to cpuinfo Date: Mon, 7 Aug 2023 14:51:06 -0400 Message-ID: <20230807185119.98333-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434348257100003 Content-Type: text/plain; charset="utf-8" acpi-cpufreq scales the aperf/mperf measurements by max_freq, but HWP needs to scale by base frequency. Settings max_freq to base_freq "works" but the code is not obvious, and returning values to userspace is tricky. Add an additonal perf_freq member which is used for scaling aperf/mperf measurements. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v3: Add Jan's Ack I don't like this, but it seems the best way to re-use the common aperf/mperf code. The other option would be to add wrappers that then do the acpi vs. hwp scaling. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/drivers/cpufreq/utility.c | 1 + xen/include/acpi/cpufreq/cpufreq.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 2e0067fbe5..6c70d04395 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -316,7 +316,7 @@ unsigned int get_measured_perf(unsigned int cpu, unsign= ed int flag) else perf_percent =3D 0; =20 - return policy->cpuinfo.max_freq * perf_percent / 100; + return policy->cpuinfo.perf_freq * perf_percent / 100; } =20 static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index 9eb7ecedcd..6831f62851 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -236,6 +236,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_poli= cy *policy, =20 policy->min =3D policy->cpuinfo.min_freq =3D min_freq; policy->max =3D policy->cpuinfo.max_freq =3D max_freq; + policy->cpuinfo.perf_freq =3D max_freq; policy->cpuinfo.second_max_freq =3D second_max_freq; =20 if (policy->min =3D=3D ~0) diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 44fc4c58fc..1f1898d811 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -37,6 +37,9 @@ extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS= ]; struct cpufreq_cpuinfo { unsigned int max_freq; unsigned int second_max_freq; /* P1 if Turbo Mode is on */ + unsigned int perf_freq; /* Scaling freq for aperf/mpref. + acpi-cpufreq uses max_freq, but HWP = uses + base_freq.*/ unsigned int min_freq; unsigned int transition_latency; /* in 10^(-9) s =3D nanosecond= s */ }; --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434341; cv=none; d=zohomail.com; s=zohoarc; b=VMf+tvnilHL5EJqfhcKU1IkrT1CPIGRkIpRXFOdjC7m7EatGKYWvRBfkhepDSlW1a4iK9D3C+ew7quZQnafBikRPs4l3lYPIdQLVV+5BPv+P1819yp1fLQ56oXLnycQMchSgDGNZ+DkomZNGCgSMg5TuAFBCPhjuYpwcCBrCk7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6N7tHO/NpGPoNencisuqLlnFkoHrBAPddvPlzfIc1r8=; b=DCgpsGOX66gstYwHbNxWvyDAYQV21CGvWL6ZjC3RtfvDhvg8dn0h9yt8i0QrH6/CF1nrhIhEGJ/rXmB/5p6ac1E7qa2e4ynpjlKqBeEqanefOKYBvD/EGdXg4F/T/1pLTdgyBbVeyC8hRekRWkcIAh4NPiChWqv8Zx/OfNMqg/A= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434341161227.42424038008983; Mon, 7 Aug 2023 11:52:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578789.906486 (Exim 4.92) (envelope-from ) id 1qT5Kf-000557-L4; Mon, 07 Aug 2023 18:51:57 +0000 Received: by outflank-mailman (output) from mailman id 578789.906486; Mon, 07 Aug 2023 18:51:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kf-00054y-IF; Mon, 07 Aug 2023 18:51:57 +0000 Received: by outflank-mailman (input) for mailman id 578789; Mon, 07 Aug 2023 18:51:55 +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 1qT5Kd-0004GT-Im for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:51:55 +0000 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [2607:f8b0:4864:20::f33]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 799d13b1-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:51:54 +0200 (CEST) Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-63d23473ed5so27492516d6.1 for ; Mon, 07 Aug 2023 11:51:54 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:51:52 -0700 (PDT) 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: 799d13b1-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434312; x=1692039112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6N7tHO/NpGPoNencisuqLlnFkoHrBAPddvPlzfIc1r8=; b=GHeky4+dM2Ufq/m6WeD1ULJqVahBnME1DiWNOJzDfbQD1PUG3us1g1/2H7LH6o6QQg BkOD62dOusGASJtAQOvZQtciJV+jpMFhwOUfcUI67+V+fKxO+SSANhpo5ibeLrmFl4Dp g0kpRNZO9dcRyIpijcDssfa9SiFhHrhHJ85x+UsPINDTllvTdyDKsSYNT4bbPDkMKsPM kisC6aiEFPTxLyU4GMu6H6TyudntoIEq353dFDp67v/04m0pmVKQzKL3LN1l+zi70aux TiTJGKZFPqYfVtxk/j8EOf78rOZFXdifyS0ho/CAm+ll9L/nW0bB/8ra6vkjgPdhDAO+ KBaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434312; x=1692039112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6N7tHO/NpGPoNencisuqLlnFkoHrBAPddvPlzfIc1r8=; b=KmxbmpWW+tjkX1jByVlPgv3xYSatmYJJdjCZCNKZF2gWjytbjyPazmXTyg2JbLMlZp 5DabLxlfKbg66RTCT9TiBHRrZycLnXit586GTPwdSVv9ewIdv0srA/HnYQMHu7n++3f0 fOJB5jp2i4l/WL9sRI+pf6y6aUaZYH7qrJn2Bwgka/lGUbZSL2RZSDGTRJeEdiq0dt7K mbmlxHxcNgZ9cag/t2eIgJgHwXixPziv9ibbJ+GCFF+MlkKKajxWNkPmNbRoNEfvPy/V LEWTnSZKhz3c9dAgVUs5btlWbdBrqRlKiXjmR6pjySPNfzKwlZE5rcmx+kqegik7nv0m w2rg== X-Gm-Message-State: AOJu0YyeN5hXOmX02+lXGFltJj0jD9w7Zc3gFSfpsaF52bvw2T878+pk KvDD43+y9bjLrB2Jgpg3Kpk24e6+lRA= X-Google-Smtp-Source: AGHT+IGqakrWUAr2dflnsyhKPwTjuy2ForGGst/8v7r4iglq0Hh+C70Z74BvEzu6rs7s0s2r73f4oA== X-Received: by 2002:a0c:e494:0:b0:632:15e6:a75e with SMTP id n20-20020a0ce494000000b0063215e6a75emr8976705qvl.46.1691434312492; Mon, 07 Aug 2023 11:51:52 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v8 03/15] cpufreq: Export intel_feature_detect Date: Mon, 7 Aug 2023 14:51:07 -0400 Message-ID: <20230807185119.98333-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434341979100003 Content-Type: text/plain; charset="utf-8" Export feature_detect as intel_feature_detect so it can be re-used by HWP. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v4: Add Jan's Ack v3: Remove void * cast when calling intel_feature_detect v2: export intel_feature_detect with typed pointer Move intel_feature_detect to acpi/cpufreq/cpufreq.h since the declaration now contains struct cpufreq_policy *. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++-- xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 6c70d04395..f1cc473b4f 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -339,9 +339,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(unsign= ed int cpu) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } =20 -static void cf_check feature_detect(void *info) +void intel_feature_detect(struct cpufreq_policy *policy) { - struct cpufreq_policy *policy =3D info; unsigned int eax; =20 eax =3D cpuid_eax(6); @@ -353,6 +352,11 @@ static void cf_check feature_detect(void *info) } } =20 +static void cf_check feature_detect(void *info) +{ + intel_feature_detect(info); +} + static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq, struct acpi_cpufreq_data *data) { diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 1f1898d811..482ea5b0de 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -243,4 +243,6 @@ int write_userspace_scaling_setspeed(unsigned int cpu, = unsigned int freq); void cpufreq_dbs_timer_suspend(void); void cpufreq_dbs_timer_resume(void); =20 +void intel_feature_detect(struct cpufreq_policy *policy); + #endif /* __XEN_CPUFREQ_PM_H__ */ --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434349; cv=none; d=zohomail.com; s=zohoarc; b=GmcKJ3evAsJ1GXvP8LHii9CHCCms7GSXsTDiuG7erh7tGIe2uF4AfWDgmKsvv0KJW5hEh+u2zWpIHuJx3M4CE+f+Tkz2Q8IaSKj2nq/pljwpl+2JUuksDb+sJ/TFDlGf17lzqEKYXy4+z+oRBihlfFkWd3Z4mmWL1ue5X+qFghg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434349; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FlP8mCjQvy+39h7njc8jPJQIVXj0clvvCBaJ9ThAR4E=; b=YigUh2vU6BX6OJqboskAWNDjPpqGUEQsQBRopoSXCrDY7O7AMPY5q69F+TYB3yfYPEEqRDDiH1hwZd3TBo97nOOFeG3UPl6FCuAFeQibAmVQSBceMjvN5rOizWsDXEnW40fLiVl8rSbKzRskfLKshwMZ9vp7f+KZmvWzqumIOnk= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434349156683.4588986595809; Mon, 7 Aug 2023 11:52:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578790.906496 (Exim 4.92) (envelope-from ) id 1qT5Kg-0005LP-V7; Mon, 07 Aug 2023 18:51:58 +0000 Received: by outflank-mailman (output) from mailman id 578790.906496; Mon, 07 Aug 2023 18:51:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kg-0005L9-RL; Mon, 07 Aug 2023 18:51:58 +0000 Received: by outflank-mailman (input) for mailman id 578790; Mon, 07 Aug 2023 18:51:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kg-0004lg-6n for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:51:58 +0000 Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [2607:f8b0:4864:20::a2b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7b7406a7-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:51:57 +0200 (CEST) Received: by mail-vk1-xa2b.google.com with SMTP id 71dfb90a1353d-487442d5e49so485883e0c.2 for ; Mon, 07 Aug 2023 11:51:57 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:51:55 -0700 (PDT) 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: 7b7406a7-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434315; x=1692039115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FlP8mCjQvy+39h7njc8jPJQIVXj0clvvCBaJ9ThAR4E=; b=V+TOtaFMBWDWV6a/gS3v3CLDf7RhwjdgX1K18CoqfTsEPvcOrFn3pDt7C5hNL9GDSG JA5PdYa2aB/7c032kG86/6NMMwsvSZGgQ+1vWoGTiN071xMxA9Sb5XoGo0SDGdvllCYB ncZjtigopOc+aiMWWwjzbGeprk71lT+Hg14e/FtcKVJnGSUQfv7T+vqfaTQRqdWur4Pn O78ra6nL24x+6DigObohZJ1rPfMhh2J6o7xnV4e1ee/17niJoSi+rwDSE4SmnsKs++gj dyK0zGiN03mfUd9hSB4Qi6tp5ezOin3+gvI2nOhTnZ9jowsQY/oHZBGsXq2DuB0pPxI3 JUsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434315; x=1692039115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FlP8mCjQvy+39h7njc8jPJQIVXj0clvvCBaJ9ThAR4E=; b=F9sXhF8O+8oCFkP6z+eN/TXdL90ukj67XM7tkUNtm4CMYaNabvjsNgp4Q1vkx4evY8 oatxaex2BxDo1BpbwGPrIzFiIOuQuJodrNe0oxdE4dmrDorWW7PizbAj9ZnJz8T3ix9N xAVqS19VzL0jQBnu1PW36cTSjJNf1RtbnzFoNJ8X8Ad4lR7zFqOR5SdqiO8cOUJLYpd7 HQdZf2MDulyiXQYp4Ea9OL82cN7ulpsL+qUiw/aFDblM5V0Tpcjd7SwIThTqxazZnJI9 mzlAxHSNQwH/ocgjbbtTb8LxubDQ2732JOrUG5moCucyYn44cRAsOKFX8DzZF4Kpy3o5 pROw== X-Gm-Message-State: AOJu0YyRumdU88gUNmWEC8Pc+4jVA1ftjPy9j2X0nCVhIp76suV1XfR1 jSLiOoNHCBMHz4DppqjH7RgSz02HwmQ= X-Google-Smtp-Source: AGHT+IEHaRR4nFTTcUDmMm0Tal0kvEnQkaJFXt5NiD1DFtILS4ddXasHFdUHsPghHxgzv/S21/+YBA== X-Received: by 2002:a1f:3f03:0:b0:487:16e2:b653 with SMTP id m3-20020a1f3f03000000b0048716e2b653mr4931614vka.13.1691434315620; Mon, 07 Aug 2023 11:51:55 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v8 04/15] xen/sysctl: Nest cpufreq scaling options Date: Mon, 7 Aug 2023 14:51:08 -0400 Message-ID: <20230807185119.98333-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434350926100001 Content-Type: text/plain; charset="utf-8" Add a union and struct so that most of the scaling variables of struct xen_get_cpufreq_para are within in a binary-compatible layout. This allows cppc_para to live in the larger union and use uint32_ts - struct xen_cppc_para will be 10 uint32_t's. The new scaling struct is 3 * uint32_t + 16 bytes CPUFREQ_NAME_LEN + 4 * uint32_t for xen_ondemand =3D 11 uint32_t. That means the old size is retained, int32_t turbo_enabled doesn't move and it's binary compatible. The out-of-context memcpy() in xc_get_cpufreq_para() now handles the copying of the fields removed there. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich Reviewed-by: Anthony PERARD --- v8: Add BUILD_BUG_ON checks for structs xc_get_cpufreq_para & xen_get_cpufreq_p= ara v6: Add Jan's Reviewed-by v5: Expand commit message Change comment to driver/governor --- tools/include/xenctrl.h | 22 ++++++++++-------- tools/libs/ctrl/xc_pm.c | 46 ++++++++++++++++++++++++++++++++----- tools/misc/xenpm.c | 24 +++++++++---------- xen/drivers/acpi/pmstat.c | 27 +++++++++++----------- xen/include/public/sysctl.h | 22 ++++++++++-------- 5 files changed, 92 insertions(+), 49 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index faec1dd824..de03cfb117 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1926,16 +1926,20 @@ struct xc_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - 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 { - xc_userspace_t userspace; - xc_ondemand_t ondemand; + 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 { + xc_userspace_t userspace; + xc_ondemand_t ondemand; + } u; + } s; } u; =20 int32_t turbo_enabled; diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index c3a9864bf7..5ec050982a 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -245,6 +245,45 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, sys_para->freq_num =3D user_para->freq_num; sys_para->gov_num =3D user_para->gov_num; =20 + /* Sanity check struct layout */ + BUILD_BUG_ON(sizeof(*user_para) !=3D sizeof(*sys_para)); + BUILD_BUG_ON(offsetof(typeof(*user_para), cpu_num) !=3D + offsetof(typeof(*sys_para), cpu_num)); + BUILD_BUG_ON(offsetof(typeof(*user_para), freq_num) !=3D + offsetof(typeof(*sys_para), freq_num)); + BUILD_BUG_ON(offsetof(typeof(*user_para), gov_num) !=3D + offsetof(typeof(*sys_para), gov_num)); + BUILD_BUG_ON(offsetof(typeof(*user_para), affected_cpus) !=3D + offsetof(typeof(*sys_para), affected_cpus)); + BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_available_frequencie= s) !=3D + offsetof(typeof(*sys_para), scaling_available_frequencie= s)); + BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_available_governors)= !=3D + offsetof(typeof(*sys_para), scaling_available_governors)= ); + BUILD_BUG_ON(offsetof(typeof(*user_para), scaling_driver) !=3D + offsetof(typeof(*sys_para), scaling_driver)); + BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_cur_freq) !=3D + offsetof(typeof(*sys_para), cpuinfo_cur_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_max_freq) !=3D + offsetof(typeof(*sys_para), cpuinfo_max_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), cpuinfo_min_freq) !=3D + offsetof(typeof(*sys_para), cpuinfo_min_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_cur_freq) !=3D + offsetof(typeof(*sys_para), u.s.scaling_cur_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_governor) !=3D + offsetof(typeof(*sys_para), u.s.scaling_governor)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_max_freq) !=3D + offsetof(typeof(*sys_para), u.s.scaling_max_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.scaling_min_freq) !=3D + offsetof(typeof(*sys_para), u.s.scaling_min_freq)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.u.userspace) !=3D + offsetof(typeof(*sys_para), u.s.u.userspace)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.s.u.ondemand) !=3D + offsetof(typeof(*sys_para), u.s.u.ondemand)); + BUILD_BUG_ON(offsetof(typeof(*user_para), u.cppc_para) !=3D + offsetof(typeof(*sys_para), u.cppc_para)); + BUILD_BUG_ON(offsetof(typeof(*user_para), turbo_enabled) !=3D + offsetof(typeof(*sys_para), turbo_enabled)); + ret =3D xc_sysctl(xch, &sysctl); if ( ret ) { @@ -265,17 +304,12 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, user_para->cpuinfo_cur_freq =3D sys_para->cpuinfo_cur_freq; user_para->cpuinfo_max_freq =3D sys_para->cpuinfo_max_freq; user_para->cpuinfo_min_freq =3D sys_para->cpuinfo_min_freq; - user_para->scaling_cur_freq =3D sys_para->scaling_cur_freq; - user_para->scaling_max_freq =3D sys_para->scaling_max_freq; - user_para->scaling_min_freq =3D sys_para->scaling_min_freq; user_para->turbo_enabled =3D sys_para->turbo_enabled; =20 memcpy(user_para->scaling_driver, sys_para->scaling_driver, CPUFREQ_NAME_LEN); - memcpy(user_para->scaling_governor, - sys_para->scaling_governor, CPUFREQ_NAME_LEN); =20 - /* copy to user_para no matter what cpufreq governor */ + /* copy to user_para no matter what cpufreq driver/governor */ BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) !=3D sizeof(((struct xen_get_cpufreq_para *)0)->u)); =20 diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1bb6187e56..ee8ce5d5f2 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -730,39 +730,39 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) printf("scaling_avail_gov : %s\n", p_cpufreq->scaling_available_governors); =20 - printf("current_governor : %s\n", p_cpufreq->scaling_governor); - if ( !strncmp(p_cpufreq->scaling_governor, + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { printf(" userspace specific :\n"); printf(" scaling_setspeed : %u\n", - p_cpufreq->u.userspace.scaling_setspeed); + p_cpufreq->u.s.u.userspace.scaling_setspeed); } - else if ( !strncmp(p_cpufreq->scaling_governor, + else if ( !strncmp(p_cpufreq->u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { printf(" ondemand specific :\n"); printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.ondemand.sampling_rate_max, - p_cpufreq->u.ondemand.sampling_rate_min, - p_cpufreq->u.ondemand.sampling_rate); + 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); printf(" up_threshold : %u\n", - p_cpufreq->u.ondemand.up_threshold); + p_cpufreq->u.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->scaling_cur_freq ) + p_cpufreq->u.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->scaling_max_freq, - p_cpufreq->scaling_min_freq, - p_cpufreq->scaling_cur_freq); + p_cpufreq->u.s.scaling_max_freq, + p_cpufreq->u.s.scaling_min_freq, + p_cpufreq->u.s.scaling_cur_freq); =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 1bae635101..f5a9ac3f1a 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -258,37 +258,38 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *= op) cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; - op->u.get_para.scaling_cur_freq =3D policy->cur; - op->u.get_para.scaling_max_freq =3D policy->max; - op->u.get_para.scaling_min_freq =3D policy->min; + + 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; =20 if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver,=20 + strlcpy(op->u.get_para.scaling_driver, cpufreq_driver.name, CPUFREQ_NAME_LEN); else strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); =20 if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.scaling_governor,=20 + strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.scaling_governor, "Unknown", CPUFREQ_NAME_L= EN); + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NA= ME_LEN); =20 /* governor specific para */ - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { - op->u.get_para.u.userspace.scaling_setspeed =3D policy->cur; + op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cur; } =20 - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { ret =3D get_cpufreq_ondemand_para( - &op->u.get_para.u.ondemand.sampling_rate_max, - &op->u.get_para.u.ondemand.sampling_rate_min, - &op->u.get_para.u.ondemand.sampling_rate, - &op->u.get_para.u.ondemand.up_threshold); + &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.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); =20 diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index fa7147de47..c11c0b1a6c 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -317,16 +317,20 @@ struct xen_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - 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; + 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; } u; =20 int32_t turbo_enabled; --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434345; cv=none; d=zohomail.com; s=zohoarc; b=dbDhWenj5WB9prNzUlbSN92Z0IqJS6/B9mJKes5PvuQWbR0BQ7T3dIsEsxpxRf+EsDNbxMf6MVY9/9ndKUeCjYuJLt7YD8e9UTBGiK2dFN2fJrSFjN77ePmeGrJDpkJPpVbet0DIq00E4BQgXH6hGd83XAw1iKQ3syAax4Av1tA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434345; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u2cTNXN/aOxyn6yZt8JfTgLQyqiVtZjxkKTytYxVIK0=; b=AxjPGvQLUpivPXKz0WvUsd9oTWEt/f+VJvQltSd7jODQuCznZV42cjk4/XdJpUqnNHxzgX087z65RAdeKYI416b9ERZOC5VsgFHWZehDOeGIqitl9eJQMT/kidT1VArd2be7PYiCTEZ/1RBN/yTIfA62jja5AFV9Ofu3rqXGWOo= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434345530535.3919133709666; Mon, 7 Aug 2023 11:52:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578791.906506 (Exim 4.92) (envelope-from ) id 1qT5Km-0005ku-62; Mon, 07 Aug 2023 18:52:04 +0000 Received: by outflank-mailman (output) from mailman id 578791.906506; Mon, 07 Aug 2023 18:52:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Km-0005ki-2q; Mon, 07 Aug 2023 18:52:04 +0000 Received: by outflank-mailman (input) for mailman id 578791; Mon, 07 Aug 2023 18:52:02 +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 1qT5Kk-0004GT-Sy for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:02 +0000 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [2607:f8b0:4864:20::c33]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7dc665d4-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:01 +0200 (CEST) Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-56d263da4f2so3483467eaf.0 for ; Mon, 07 Aug 2023 11:52:01 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:51:58 -0700 (PDT) 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: 7dc665d4-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434319; x=1692039119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u2cTNXN/aOxyn6yZt8JfTgLQyqiVtZjxkKTytYxVIK0=; b=CnO6HWIQbR2lQMKLHNby+LFi1nw8F/zZ2Cko9PIOtiApG8kgSA1mwtVcBWlprnTTgL FMCvYnLECT+RicsiD1/iWZcSoHpDm8QHW5C+UV/oQnrWZJ/scSvvPBfsUc7ckuARC8aQ n6UD331fi7yxBFRtHLWhx6pDumCMgQmN9w35oXbUykpuSnXhchaZmqaih3lGrgtVAwTM 163tTW8+8qyxYYtGhToNwM5C+h4dbqvxpRh3ETgHsNfyRUSz1GWK8dZUfZG3p033O+w8 Id+yhLAPE89HvqR9TfyfqSZQ9uWw5EkBlU+MlWIveNpX2Zx9TIhUgt4xY8rm/NcKzvV2 qOlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434319; x=1692039119; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u2cTNXN/aOxyn6yZt8JfTgLQyqiVtZjxkKTytYxVIK0=; b=Ws9M7CZYvqm97F1irX/c7UMS/K9hgd+M93pVYiPB2oxNE9pbwVnJLR77JjyYNFQJ+n Xp3y/0XhUKDkiDfz4YDgMYWzZK344FNh9Mz6VE5zugwAlaHKC/TAljSn0ABMhbXebl2y TjxsBLs21Yz3azuVOe2JhqZV7OCYtyxhjIj4vlRGvIvV1kZ2Jm6EedbNlGW0Hui6yWok CcqoSS82P6YfBuGuj3NFlFVc1uoOINHUKxXRvWlGWll/9HqoMPb7Hk0LEz9skNLv8Yll qC2/17OkNvUbAfpUDxDIrrFVmEkHSeYw01nA6RTwtT8bTFQyMqYzsmSq7DLsvi1Lf55M /fxQ== X-Gm-Message-State: AOJu0Yw3lkZTRvHIHz0gbQ+eK/SFqkmY9Atg+m3ywwSgpfFRd785Y77U nCha9OhYEEYd6B8fCrKDE9+4ysJizLo= X-Google-Smtp-Source: AGHT+IGB8zoaL8Wl4i2TbXtiQdNma5QYJIb2GwQ3mLZpI+PHYTazgpS7dKL4y2Cd1STr/leJB1hf1A== X-Received: by 2002:a05:6358:8820:b0:135:3e6b:8430 with SMTP id hv32-20020a056358882000b001353e6b8430mr10912871rwb.5.1691434319201; Mon, 07 Aug 2023 11:51:59 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross , Jan Beulich Subject: [PATCH v8 05/15] pmstat&xenpm: Re-arrage for cpufreq union Date: Mon, 7 Aug 2023 14:51:09 -0400 Message-ID: <20230807185119.98333-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434347070100001 Content-Type: text/plain; charset="utf-8" Rearrange code now that xen_sysctl_pm_op's get_para fields has the nested union and struct. In particular, the scaling governor information like scaling_available_governors is inside the union, so it is not always available. Move those fields (op->u.get_para.u.s.u.*) together as well as the common fields (ones outside the union like op->u.get_para.turbo_enabled). With that, gov_num may be 0, so bounce buffer handling needs to be modified. scaling_governor and other fields inside op->u.get_para.u.s.u.* won't be used for hwp, so this will simplify the change when hwp support is introduced and re-indents these lines all together. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich Acked-by: Anthony PERARD --- v8: Add Anthony's Ack v6: Add Jan's Ack v5: Remove some formatting changes Expand commit message --- tools/libs/ctrl/xc_pm.c | 12 ++++++++---- tools/misc/xenpm.c | 3 ++- xen/drivers/acpi/pmstat.c | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index 5ec050982a..3e969b841f 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -221,7 +221,7 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, { if ( (!user_para->affected_cpus) || (!user_para->scaling_available_frequencies) || - (!user_para->scaling_available_governors) ) + (user_para->gov_num && !user_para->scaling_available_governor= s) ) { errno =3D EINVAL; return -1; @@ -230,12 +230,15 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, goto unlock_1; if ( xc_hypercall_bounce_pre(xch, scaling_available_frequencies) ) goto unlock_2; - if ( xc_hypercall_bounce_pre(xch, scaling_available_governors) ) + if ( user_para->gov_num && + xc_hypercall_bounce_pre(xch, scaling_available_governors) ) goto unlock_3; =20 set_xen_guest_handle(sys_para->affected_cpus, affected_cpus); set_xen_guest_handle(sys_para->scaling_available_frequencies, scal= ing_available_frequencies); - set_xen_guest_handle(sys_para->scaling_available_governors, scalin= g_available_governors); + if ( user_para->gov_num ) + set_xen_guest_handle(sys_para->scaling_available_governors, + scaling_available_governors); } =20 sysctl.cmd =3D XEN_SYSCTL_pm_op; @@ -317,7 +320,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, } =20 unlock_4: - xc_hypercall_bounce_post(xch, scaling_available_governors); + if ( user_para->gov_num ) + xc_hypercall_bounce_post(xch, scaling_available_governors); unlock_3: xc_hypercall_bounce_post(xch, scaling_available_frequencies); unlock_2: diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index ee8ce5d5f2..1c474c3b59 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -811,7 +811,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_= handle, int cpuid) ret =3D -ENOMEM; goto out; } - if (!(p_cpufreq->scaling_available_governors =3D + if (p_cpufreq->gov_num && + !(p_cpufreq->scaling_available_governors =3D malloc(p_cpufreq->gov_num * CPUFREQ_NAME_LEN * sizeof(char))= )) { fprintf(stderr, diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index f5a9ac3f1a..d67d99e62f 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -239,6 +239,18 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *o= p) if ( ret ) return ret; =20 + op->u.get_para.cpuinfo_cur_freq =3D + cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; + op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; + op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; + op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); + + if ( cpufreq_driver.name[0] ) + strlcpy(op->u.get_para.scaling_driver, + cpufreq_driver.name, CPUFREQ_NAME_LEN); + else + strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); + if ( !(scaling_available_governors =3D xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) return -ENOMEM; @@ -254,21 +266,10 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *= op) if ( ret ) return ret; =20 - op->u.get_para.cpuinfo_cur_freq =3D - cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; - op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; - op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; - 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; =20 - if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver, - cpufreq_driver.name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); - if ( policy->governor->name[0] ) strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); @@ -291,7 +292,6 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) &op->u.get_para.u.s.u.ondemand.sampling_rate, &op->u.get_para.u.s.u.ondemand.up_threshold); } - op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); =20 return ret; } --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434357; cv=none; d=zohomail.com; s=zohoarc; b=YPkmQNxCGMvnMeuBTO4KKiAbmBAM8Z0tTtrUG7VZ1LT/akgQlzJ/IvrDJk1P2Wzch5/E5YqORLTMXU7OZqCuT+OYx6gQWo0Ch8F00B4Qh8pElM0WPZ9vWK2oqoQmpanPtbwKfjdZG4+NzFyo+i1k5amDubUONTp2JGs41BlqkpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434357; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gCOuYJf06lhbOIsw/F1/0m49/wq+20s+vXdSNsZE/tM=; b=fhYWwzDquvCWsMN9gLp1uwk91elqguV24GCiPK9VcHn8mHFqbBUFgZ1mtDYkyK0Yhe3fmWZBeeGXEAnGaqltAWns2hPvT0FOAxgreCzLLwuFuz+mMJkcfTym17TRAGvSo7dvsHsJLEcbIBAvdJWK5iYlin4dMITkQEjjmCwn1cA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434357918885.2486872584159; Mon, 7 Aug 2023 11:52:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578795.906516 (Exim 4.92) (envelope-from ) id 1qT5Kr-0006Mi-MF; Mon, 07 Aug 2023 18:52:09 +0000 Received: by outflank-mailman (output) from mailman id 578795.906516; Mon, 07 Aug 2023 18:52:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kr-0006MR-Ie; Mon, 07 Aug 2023 18:52:09 +0000 Received: by outflank-mailman (input) for mailman id 578795; Mon, 07 Aug 2023 18:52:08 +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 1qT5Kp-0004GT-Uc for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:08 +0000 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [2607:f8b0:4864:20::72a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 80641785-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:05 +0200 (CEST) Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-766fd5f9536so290435485a.3 for ; Mon, 07 Aug 2023 11:52:05 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:02 -0700 (PDT) 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: 80641785-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434323; x=1692039123; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gCOuYJf06lhbOIsw/F1/0m49/wq+20s+vXdSNsZE/tM=; b=F1ggc1h5yZl5XIQaGlZN6YoyCsqIh6cNGCed7oczn1Y9oCfoOMNiu2Oa7zMtQDmmaA whxc7xzm9FY7iDnduewdUvkJndU4jGG7+rMMc3p2r07N/ZE4d/grm6tkSNTsJQMiDb1C dnAjFCVv4RCimyeTFRUSGIzmqzGHLCEQkwsCNauLAGWjfScy+RwGoPO8PjldnpWi4OET s4N6TiPNIMVb2sxyK994bMgB5lKfj4YBH4m1Z1rKyMvE7T5WnrQxb6wFZYymhtYDceEp CYlUJdgaOtQbKDsNMKClEwAG+Q3/RfFoJnD1QNOsFzn2Os0frelmM+at/Pe5Q82Mchph ZuLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434323; x=1692039123; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gCOuYJf06lhbOIsw/F1/0m49/wq+20s+vXdSNsZE/tM=; b=C/qHG4tCJNsCdop4peokqhSOSQ5eippXbFm6GGgPmN6M+qteiFNeacz3Po5hBKVx7d /r3wXqyXQxJqeRfCvArku7k6zdNtZVZhuT9CmnEO2ap88FkDic9MLq9A2+1kisDKYIKl Ua1sGvKQl2CJMVPprAhiJIDDkEcZ+THdgp90lxLJ0FtG1BWWQH/PWUwSkjmi7pMrbnMv 5na/FZcrjJylE7xN8z8POZvgmNullVDYq8zoIucWe6sizTtgRJykkAlsP6H3MMzWPqfh cXW1SbUJTWnkngosV/r8fRttUvBvuRIckxEA2GmtckQ4cOrwk6HfZMDnJXkofZoU/iAQ gdaQ== X-Gm-Message-State: AOJu0Yytrfqb6Bl8b8K1x/8PC17u6tXiQYDt6CbkmuCLGJDYXr3GiEf1 4eFmWgMHOC8AGFG4+zSYYd3I7Ji1yps= X-Google-Smtp-Source: AGHT+IHujdpFIqe/Uv0K3AdNjlLtHUsARcy+eS9d8Vl1C+iSYTV5Z8hoxyo/QVYU0TVLguIQFurS2g== X-Received: by 2002:a0c:be87:0:b0:636:afa1:345d with SMTP id n7-20020a0cbe87000000b00636afa1345dmr6374537qvi.17.1691434323398; Mon, 07 Aug 2023 11:52:03 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v8 06/15] cpufreq: Add Hardware P-State (HWP) driver Date: Mon, 7 Aug 2023 14:51:10 -0400 Message-ID: <20230807185119.98333-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434358698100005 Content-Type: text/plain; charset="utf-8" From the Intel SDM: "Hardware-Controlled Performance States (HWP), which autonomously selects performance states while utilizing OS supplied performance guidance hints." Enable HWP to run in autonomous mode by poking the correct MSRs. HWP is disabled by default, and cpufreq=3Dhwp enables it. cpufreq=3D parsing is expanded to allow cpufreq=3Dhwp;xen. This allows trying HWP and falling back to xen if not available. Only hwp and xen are supported for this fallback feature. hdc is a sub-option under hwp (i.e. cpufreq=3Dhwp,hdc=3D0) as is verbose. There is no interface to configure - xen_sysctl_pm_op/xenpm will be extended to configure in subsequent patches. It will run with the default values, which should be the default 0x80 (out of 0x0-0xff) energy/performance preference. Unscientific powertop measurement of an mostly idle, customized OpenXT install: A 10th gen 6-core laptop showed battery discharge drop from ~9.x to ~7.x watts. A 8th gen 4-core laptop dropped from ~10 to ~9 Power usage depends on many factors, especially display brightness, but this does show a power saving in balanced mode when CPU utilization is low. HWP isn't compatible with an external governor - it doesn't take explicit frequency requests. Therefore a minimal internal governor, hwp, is also added as a placeholder. While adding to the xen-command-line.pandoc entry, un-nest verbose from minfreq. They are independent. With cpufreq=3Dhwp,verbose, HWP prints processor capabilities that are not used by the code, like HW_FEEDBACK. This is done because otherwise there isn't a convenient way to query the information. Xen doesn't use the HWP interrupt, so it is disabled like in the Linux pstate driver. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- We disable on cpuid_level < 0x16. cpuid(0x16) is used to get the cpu frequencies for calculating the APERF/MPERF. Without it, things would still work, but the average cpu frequency output would be wrong. My 8th & 10th gen test systems both report: (XEN) HWP: 1 notify: 1 act_window: 1 energy_perf: 1 pkg_level: 0 peci: 0 (XEN) HWP: Hardware Duty Cycling (HDC) supported (XEN) HWP: HW_FEEDBACK not supported We can't use parse_boolean() since it requires a single name=3Dval string and cpufreq_handle_common_option is provided two strings. Use parse_bool() and manual handle no-hwp. FAST_IA32_HWP_REQUEST was removed in v2. The check in v1 was wrong, it's a model specific feature and the CPUID bit is only available after enabling via the MSR. Support was untested since I don't have hardware with the feature. Writes are expected to be infrequent, so just leave it out. --- v2: Alphabetize headers Re-work driver registration name hwp_drv_data anonymous union "hw" Drop hwp_verbose_cont style cleanups Condense hwp_governor switch hwp_cpufreq_target remove .raw from hwp_req assignment Use typed-pointer in a few functions Pass type to xzalloc Add HWP_ENERGY_PERF_BALANCE/IA32_ENERGY_BIAS_BALANCE defines Add XEN_HWP_GOVERNOR define for "hwp-internal" Capitalize CPUID and MSR defines Change '_' to '-' for energy-perf & act-window Read-modify-write MSRs updates Use FAST_IA32_HWP_REQUEST_MSR_ENABLE define constify pointer in hwp_set_misc_turbo Add space after non-fallthrough break in governor switch Add IA32_ENERGY_BIAS_MASK define Check CPUID_PM_LEAK for energy bias when needed Fail initialization with curr_req =3D -1 Fold hwp_read_capabilities into hwp_init_msrs Add command line cpufreq=3Dxen:hwp Add command line cpufreq=3Dxen:hdc Use per_cpu for hwp_drv_data pointers Move hwp_energy_perf_bias call into hwp_write_request energy_perf 0 is valid, so hwp_energy_perf_bias cannot be skipped Ensure we don't generate interrupts Remove Fast Write of Uncore MSR Initialize hwp_drv_data from curr_req Use SPDX line instead of license text in hwp.c v3: Add cf_check to cpufreq_gov_hwp_init() - Marek Print cpuid_level with %#x - Marek v4: Use BIT() for CPUID and MSR bits Move __initdata after type Add __ro_after_init to feature_* Remove aperf/mperf comment Move feature_hwp_energy_perf { to newline Remove _IA32_ infix Use unsigned int & bool for bitfields Require energy perf pref (Remove ENERGY_PERF_BIAS support) Initialize activity_window Return errors on wrmsr failure Change command line to: cpufreq=3Dxen:hwp Move hdc into the hwp-specific handle_options Drop feature_hwp_energy_perf, feature_hwp_pkg_level_ctl & feature_hwp_peci Print features before exiting when energy/performance preference isn't avai= lable Disable HWP MSR on initialization error Change hwp_ print macros to add prefixes Disable HDC when hdc=3D0 - (opt_hdc no longer initdata) Mark hwp governor internal and use "hwp" name Add XEN_HWP_DRIVER Use top-level cpufreq=3Dhwp command line option Document that cpufreq=3Dhwp falls back to cpufreq=3Dxen without hardware Add SPDX suffix GPL-2.0-only v5: Use _AC() macro in MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE definition hwp_err arg re-ordering Use XEN_HWP_DRIVER_NAME Use cpufreq.h for all declarations Clear feature_hdc on failure and print a message Use unnamed bitfields instead of reservered Remove asm/io.h include static DEFINE_PER_CPU_READ_MOSTLY(struct hwp_drv_data Remove some empty newlines Align feature_hdc assignment Remove feature_hwp Remove unnecesary return at end of void hwp_init_msrs() BUILD_BUG_ON member variable Reformat a compound if Clear pre_cpu hwp_drv_data before xfree() Only print HWP capabilities for CPU 0 Specify processor models in turbo comment Use arg[1] in setup_cpufreq_option() Remove some log messages Drop double newline Parse verbose as a boolean instead of the custom parsing. Support cpufreq=3Dhwp;xen fallback Call hwp_available() from hwp_register_driver() Move cpufreq_govenor_internal setting to hwp_register_driver v6: docs: mention verbose applies to both. Use cpufreq=3Dhwp;xen,verbose example with verbose at then end. Declare induction i inside for loop Add CPUFREQ_none Only call cpufreq fallback for -ENODEV Brace on newline fixes hdc_set_pkg_hdc_ctl()/hdc_set_pm_ctl1() return boolean Continue without hdc Consolidate hdc if statement Use hwp_req variable for BUILD_BUG_ON Newline between declarations and statement __initdata for cpufreq_xen_opts/cpufreq_xen_cnt Only print HWP_REQUEST when differing from BSP. Remove MSR_PM_ENABLE printing Move hdc_set_pkg_hdc_ctl(), hdc_set_pm_ctl1(), hwp_get_cpu_speeds(), and hwp_init_msrs() to before their sole caller, hwp_cpufreq_cpu_init() Fix cpufreq=3D parsing without options (set ret=3D0) Drop stray s NULL check Return -EINVAL from hwp_cmdline_parse() Latch first CPU HWP request and print differences Use strpbrk to split on ',' or ':' for arg in xen/hwp do..while Limit hwp parsing error to just current option with %.*s and (end ?: e) - s docs: Expand and clarify the handling of `verbose` with cpufreq fallbacks. v7: s/##_VA_ARGS/## args/ in macros Add __init to hwp_handle_option Add comment for 0 cpuid freqs Reword intel_feature_detect comment. Fix indent for HDC failure Make first_run static and use for first cpu latching hwp_set_misc_turbo() return -EACCES on error s/end/*end/ in setup_cpufreq_option() v8: Annotate first_run as __read_mostly Add Jan's Reviewed-by --- docs/misc/xen-command-line.pandoc | 20 +- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 21 +- xen/arch/x86/acpi/cpufreq/hwp.c | 524 ++++++++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 12 +- xen/arch/x86/include/asm/msr-index.h | 15 +- xen/drivers/cpufreq/cpufreq.c | 59 ++- xen/include/acpi/cpufreq/cpufreq.h | 10 + xen/include/public/sysctl.h | 2 + 9 files changed, 649 insertions(+), 15 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/hwp.c diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 9d66688bd1..abff141590 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -499,7 +499,7 @@ If set, force use of the performance counters for oprof= ile, rather than detectin available support. =20 ### cpufreq -> `=3D none | {{ | xen } [:[powersave|performance|ondemand|users= pace][,][,[][,[verbose]]]]} | dom0-kernel` +> `=3D none | {{ | xen } { [:[powersave|performance|ondemand|use= rspace][,[]][,[]]] } [,verbose]} | dom0-kernel | hwp[:[][,verbose]]` =20 > Default: `xen` =20 @@ -510,6 +510,24 @@ choice of `dom0-kernel` is deprecated and not supporte= d by all Dom0 kernels. * `` and `` are integers which represent max and min pro= cessor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=3D` + for `xen`. It is a boolean for `hwp`. +* `hwp` selects Hardware-Controlled Performance States (HWP) on supported = Intel + hardware. HWP is a Skylake+ feature which provides better CPU power + management. The default is disabled. If `hwp` is selected, but hardware + support is not available, Xen will fallback to cpufreq=3Dxen. +* `` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables= the + processor to autonomously force physical package components into idle st= ate. + The default is enabled, but the option only applies when `hwp` is enable= d. + +There is also support for `;`-separated fallback options: +`cpufreq=3Dhwp;xen,verbose`. This first tries `hwp` and falls back to `xe= n` if +unavailable. Note: The `verbose` suboption is handled globally. Setting = it +for either the primary or fallback option applies to both irrespective of = where +it is specified. + +Note: grub2 requires to escape or quote ';', so `"cpufreq=3Dhwp;xen"` shou= ld be +specified within double quotes inside grub.cfg. Refer to the grub2 +documentation for more information. =20 ### cpuid (x86) > `=3D List of comma separated booleans` diff --git a/xen/arch/x86/acpi/cpufreq/Makefile b/xen/arch/x86/acpi/cpufreq= /Makefile index f75da9b9ca..db83aa6b14 100644 --- a/xen/arch/x86/acpi/cpufreq/Makefile +++ b/xen/arch/x86/acpi/cpufreq/Makefile @@ -1,2 +1,3 @@ obj-y +=3D cpufreq.o +obj-y +=3D hwp.o obj-y +=3D powernow.o diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index f1cc473b4f..61b62c370a 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -642,7 +642,26 @@ static int __init cf_check cpufreq_driver_init(void) switch ( boot_cpu_data.x86_vendor ) { case X86_VENDOR_INTEL: - ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); + ret =3D -ENOENT; + + for ( unsigned int i =3D 0; i < cpufreq_xen_cnt; i++ ) + { + switch ( cpufreq_xen_opts[i] ) + { + case CPUFREQ_xen: + ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); + break; + case CPUFREQ_hwp: + ret =3D hwp_register_driver(); + break; + case CPUFREQ_none: + ret =3D 0; + break; + } + + if ( ret !=3D -ENODEV ) + break; + } break; =20 case X86_VENDOR_AMD: diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c new file mode 100644 index 0000000000..932786ccca --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -0,0 +1,524 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * hwp.c cpufreq driver to run Intel Hardware P-States (HWP) + * + * Copyright (C) 2021 Jason Andryuk + */ + +#include +#include +#include +#include +#include +#include + +static bool __ro_after_init feature_hwp_notification; +static bool __ro_after_init feature_hwp_activity_window; + +static bool __ro_after_init feature_hdc; + +static bool __ro_after_init opt_cpufreq_hdc =3D true; + +union hwp_request +{ + struct + { + unsigned int min_perf:8; + unsigned int max_perf:8; + unsigned int desired:8; + unsigned int energy_perf:8; + unsigned int activity_window:10; + bool package_control:1; + unsigned int :16; + bool activity_window_valid:1; + bool energy_perf_valid:1; + bool desired_valid:1; + bool max_perf_valid:1; + bool min_perf_valid:1; + }; + uint64_t raw; +}; + +struct hwp_drv_data +{ + union + { + uint64_t hwp_caps; + struct + { + unsigned int highest:8; + unsigned int guaranteed:8; + unsigned int most_efficient:8; + unsigned int lowest:8; + unsigned int :32; + } hw; + }; + union hwp_request curr_req; + int ret; + uint16_t activity_window; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; +static DEFINE_PER_CPU_READ_MOSTLY(struct hwp_drv_data *, hwp_drv_data); + +#define hwp_err(cpu, fmt, args...) \ + printk(XENLOG_ERR "HWP: CPU%u error: " fmt, cpu, ## args) +#define hwp_info(fmt, args...) printk(XENLOG_INFO "HWP: " fmt, ## args) +#define hwp_verbose(fmt, args...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "HWP: " fmt, ## args); \ +}) + +static int cf_check hwp_governor(struct cpufreq_policy *policy, + unsigned int event) +{ + int ret; + + if ( policy =3D=3D NULL ) + return -EINVAL; + + switch ( event ) + { + case CPUFREQ_GOV_START: + case CPUFREQ_GOV_LIMITS: + ret =3D 0; + break; + + case CPUFREQ_GOV_STOP: + default: + ret =3D -EINVAL; + break; + } + + return ret; +} + +static bool __init hwp_handle_option(const char *s, const char *end) +{ + int ret; + + ret =3D parse_boolean("verbose", s, end); + if ( ret >=3D 0 ) + { + cpufreq_verbose =3D ret; + return true; + } + + ret =3D parse_boolean("hdc", s, end); + if ( ret >=3D 0 ) + { + opt_cpufreq_hdc =3D ret; + return true; + } + + return false; +} + +int __init hwp_cmdline_parse(const char *s, const char *e) +{ + do + { + const char *end =3D strpbrk(s, ",;"); + + if ( !hwp_handle_option(s, end) ) + { + printk(XENLOG_WARNING "cpufreq/hwp: option '%.*s' not recogniz= ed\n", + (int)((end ?: e) - s), s); + + return -EINVAL; + } + + s =3D end ? ++end : end; + } while ( s && s < e ); + + return 0; +} + +static struct cpufreq_governor cpufreq_gov_hwp =3D +{ + .name =3D "hwp", + .governor =3D hwp_governor, +}; + +static int __init cf_check cpufreq_gov_hwp_init(void) +{ + if ( !cpufreq_governor_internal ) + return 0; + + return cpufreq_register_governor(&cpufreq_gov_hwp); +} +__initcall(cpufreq_gov_hwp_init); + +static bool __init hwp_available(void) +{ + unsigned int eax; + + if ( boot_cpu_data.cpuid_level < CPUID_PM_LEAF ) + { + hwp_verbose("cpuid_level (%#x) lacks HWP support\n", + boot_cpu_data.cpuid_level); + + return false; + } + + if ( boot_cpu_data.cpuid_level < 0x16 ) + { + hwp_info("HWP disabled: cpuid_level %#x < 0x16 lacks CPU freq info= \n", + boot_cpu_data.cpuid_level); + + return false; + } + + eax =3D cpuid_eax(CPUID_PM_LEAF); + + hwp_verbose("%d notify: %d act-window: %d energy-perf: %d pkg-level: %= d peci: %d\n", + !!(eax & CPUID6_EAX_HWP), + !!(eax & CPUID6_EAX_HWP_NOTIFICATION), + !!(eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW), + !!(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE), + !!(eax & CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST), + !!(eax & CPUID6_EAX_HWP_PECI)); + + if ( !(eax & CPUID6_EAX_HWP) ) + return false; + + if ( !(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE) ) + { + hwp_verbose("disabled: No energy/performance preference available"= ); + + return false; + } + + feature_hwp_notification =3D eax & CPUID6_EAX_HWP_NOTIFICATION; + feature_hwp_activity_window =3D eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW; + feature_hdc =3D eax & CPUID6_EAX_HDC; + + hwp_verbose("Hardware Duty Cycling (HDC) %ssupported%s\n", + feature_hdc ? "" : "not ", + feature_hdc ? opt_cpufreq_hdc ? ", enabled" : ", disabled" + : ""); + + hwp_verbose("HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + hwp_info("Using HWP for cpufreq\n"); + + return true; +} + +static int cf_check hwp_cpufreq_verify(struct cpufreq_policy *policy) +{ + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, policy->cpu); + + if ( !feature_hwp_activity_window && data->activity_window ) + { + hwp_verbose("HWP activity window not supported\n"); + + return -EINVAL; + } + + return 0; +} + +static void cf_check hwp_write_request(void *info) +{ + const struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + union hwp_request hwp_req =3D data->curr_req; + + data->ret =3D 0; + + BUILD_BUG_ON(sizeof(hwp_req) !=3D sizeof(hwp_req.raw)); + if ( wrmsr_safe(MSR_HWP_REQUEST, hwp_req.raw) ) + { + hwp_verbose("CPU%u: error wrmsr_safe(MSR_HWP_REQUEST, %lx)\n", + policy->cpu, hwp_req.raw); + rdmsr_safe(MSR_HWP_REQUEST, data->curr_req.raw); + data->ret =3D -EINVAL; + } +} + +static int cf_check hwp_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + /* Zero everything to ensure reserved bits are zero... */ + union hwp_request hwp_req =3D { .raw =3D 0 }; + + /* .. and update from there */ + hwp_req.min_perf =3D data->minimum; + hwp_req.max_perf =3D data->maximum; + hwp_req.desired =3D data->desired; + hwp_req.energy_perf =3D data->energy_perf; + if ( feature_hwp_activity_window ) + hwp_req.activity_window =3D data->activity_window; + + if ( hwp_req.raw =3D=3D data->curr_req.raw ) + return 0; + + data->curr_req =3D hwp_req; + + on_selected_cpus(cpumask_of(cpu), hwp_write_request, policy, 1); + + return data->ret; +} + +static bool hdc_set_pkg_hdc_ctl(unsigned int cpu, bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_PKG_HDC_CTL, msr) ) + { + hwp_err(cpu, "rdmsr_safe(MSR_PKG_HDC_CTL)\n"); + return false; + } + + if ( val ) + msr |=3D PKG_HDC_CTL_HDC_PKG_ENABLE; + else + msr &=3D ~PKG_HDC_CTL_HDC_PKG_ENABLE; + + if ( wrmsr_safe(MSR_PKG_HDC_CTL, msr) ) + { + hwp_err(cpu, "wrmsr_safe(MSR_PKG_HDC_CTL): %016lx\n", msr); + return false; + } + + return true; +} + +static bool hdc_set_pm_ctl1(unsigned int cpu, bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_PM_CTL1, msr) ) + { + hwp_err(cpu, "rdmsr_safe(MSR_PM_CTL1)\n"); + return false; + } + + if ( val ) + msr |=3D PM_CTL1_HDC_ALLOW_BLOCK; + else + msr &=3D ~PM_CTL1_HDC_ALLOW_BLOCK; + + if ( wrmsr_safe(MSR_PM_CTL1, msr) ) + { + hwp_err(cpu, "wrmsr_safe(MSR_PM_CTL1): %016lx\n", msr); + return false; + } + + return true; +} + +static void hwp_get_cpu_speeds(struct cpufreq_policy *policy) +{ + uint32_t base_khz, max_khz, bus_khz, edx; + + cpuid(0x16, &base_khz, &max_khz, &bus_khz, &edx); + + /* + * Zero values are acceptable - they are not used for calculations + * and only returned to userspace. + */ + policy->cpuinfo.perf_freq =3D base_khz * 1000; + policy->cpuinfo.min_freq =3D base_khz * 1000; + policy->cpuinfo.max_freq =3D max_khz * 1000; + policy->min =3D base_khz * 1000; + policy->max =3D max_khz * 1000; + policy->cur =3D 0; +} + +static void cf_check hwp_init_msrs(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + uint64_t val; + + /* + * Package level MSR, but we don't have a good idea of packages here, = so + * just do it everytime. + */ + if ( rdmsr_safe(MSR_PM_ENABLE, val) ) + { + hwp_err(policy->cpu, "rdmsr_safe(MSR_PM_ENABLE)\n"); + data->curr_req.raw =3D -1; + return; + } + + /* Ensure we don't generate interrupts */ + if ( feature_hwp_notification ) + wrmsr_safe(MSR_HWP_INTERRUPT, 0); + + if ( !(val & PM_ENABLE_HWP_ENABLE) ) + { + val |=3D PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_PM_ENABLE, val) ) + { + hwp_err(policy->cpu, "wrmsr_safe(MSR_PM_ENABLE, %lx)\n", val); + data->curr_req.raw =3D -1; + return; + } + } + + if ( rdmsr_safe(MSR_HWP_CAPABILITIES, data->hwp_caps) ) + { + hwp_err(policy->cpu, "rdmsr_safe(MSR_HWP_CAPABILITIES)\n"); + goto error; + } + + if ( rdmsr_safe(MSR_HWP_REQUEST, data->curr_req.raw) ) + { + hwp_err(policy->cpu, "rdmsr_safe(MSR_HWP_REQUEST)\n"); + goto error; + } + + /* Check for turbo support. */ + intel_feature_detect(policy); + + if ( feature_hdc && + (!hdc_set_pkg_hdc_ctl(policy->cpu, opt_cpufreq_hdc) || + !hdc_set_pm_ctl1(policy->cpu, opt_cpufreq_hdc)) ) + { + hwp_err(policy->cpu, "Disabling HDC support\n"); + feature_hdc =3D false; + } + + hwp_get_cpu_speeds(policy); + + return; + + error: + data->curr_req.raw =3D -1; + val &=3D ~PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_PM_ENABLE, val) ) + hwp_err(policy->cpu, "wrmsr_safe(MSR_PM_ENABLE, %lx)\n", val); +} + +static int cf_check hwp_cpufreq_cpu_init(struct cpufreq_policy *policy) +{ + static bool __read_mostly first_run =3D true; + static union hwp_request initial_req; + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data; + + data =3D xzalloc(struct hwp_drv_data); + if ( !data ) + return -ENOMEM; + + policy->governor =3D &cpufreq_gov_hwp; + + per_cpu(hwp_drv_data, cpu) =3D data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + if ( data->curr_req.raw =3D=3D -1 ) + { + hwp_err(cpu, "Could not initialize HWP properly\n"); + per_cpu(hwp_drv_data, cpu) =3D NULL; + xfree(data); + return -ENODEV; + } + + data->minimum =3D data->curr_req.min_perf; + data->maximum =3D data->curr_req.max_perf; + data->desired =3D data->curr_req.desired; + data->energy_perf =3D data->curr_req.energy_perf; + data->activity_window =3D data->curr_req.activity_window; + + if ( first_run ) + { + hwp_verbose("CPU%u: HWP_CAPABILITIES: %016lx\n", cpu, data->hwp_ca= ps); + initial_req =3D data->curr_req; + } + + if ( first_run || data->curr_req.raw !=3D initial_req.raw ) + { + hwp_verbose("CPU%u: rdmsr HWP_REQUEST %016lx\n", cpu, + data->curr_req.raw); + first_run =3D false; + } + + return 0; +} + +static int cf_check hwp_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, policy->cpu); + + per_cpu(hwp_drv_data, policy->cpu) =3D NULL; + xfree(data); + + return 0; +} + +/* + * The SDM reads like turbo should be disabled with MSR_IA32_PERF_CTL and + * PERF_CTL_TURBO_DISENGAGE, but that does not seem to actually work, at l= east + * with testing on i7-10810U and i7-8550U. MSR_MISC_ENABLE and + * MISC_ENABLE_TURBO_DISENGAGE is what Linux uses and seems to work. + */ +static void cf_check hwp_set_misc_turbo(void *info) +{ + const struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, policy->cpu); + uint64_t msr; + + data->ret =3D 0; + + if ( rdmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_verbose("CPU%u: error rdmsr_safe(MSR_IA32_MISC_ENABLE)\n", + policy->cpu); + data->ret =3D -EACCES; + + return; + } + + if ( policy->turbo =3D=3D CPUFREQ_TURBO_ENABLED ) + msr &=3D ~MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + else + msr |=3D MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + + if ( wrmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_verbose("CPU%u: error wrmsr_safe(MSR_IA32_MISC_ENABLE): %016lx= \n", + policy->cpu, msr); + data->ret =3D -EACCES; + } +} + +static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *p= olicy) +{ + on_selected_cpus(cpumask_of(cpuid), hwp_set_misc_turbo, policy, 1); + + return per_cpu(hwp_drv_data, cpuid)->ret; +} + +static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver =3D +{ + .name =3D XEN_HWP_DRIVER_NAME, + .verify =3D hwp_cpufreq_verify, + .target =3D hwp_cpufreq_target, + .init =3D hwp_cpufreq_cpu_init, + .exit =3D hwp_cpufreq_cpu_exit, + .update =3D hwp_cpufreq_update, +}; + +int __init hwp_register_driver(void) +{ + int ret; + + if ( !hwp_available() ) + return -ENODEV; + + ret =3D cpufreq_register_driver(&hwp_cpufreq_driver); + cpufreq_governor_internal =3D (ret =3D=3D 0); + + return ret; +} diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/a= sm/cpufeature.h index 64e1dad225..93466441f5 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -52,8 +52,16 @@ static inline bool boot_cpu_has(unsigned int feat) return cpu_has(&boot_cpu_data, feat); } =20 -#define CPUID_PM_LEAF 6 -#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID_PM_LEAF 6 +#define CPUID6_EAX_HWP BIT(7, U) +#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) +#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) +#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) +#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) +#define CPUID6_EAX_HDC BIT(13, U) +#define CPUID6_EAX_HWP_PECI BIT(16, U) +#define CPUID6_EAX_HW_FEEDBACK BIT(19, U) +#define CPUID6_ECX_APERFMPERF_CAPABILITY BIT(0, U) =20 /* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index 4d41c171d2..2705982d93 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -151,6 +151,13 @@ =20 #define MSR_PKRS 0x000006e1 =20 +#define MSR_PM_ENABLE 0x00000770 +#define PM_ENABLE_HWP_ENABLE BIT(0, ULL) + +#define MSR_HWP_CAPABILITIES 0x00000771 +#define MSR_HWP_INTERRUPT 0x00000773 +#define MSR_HWP_REQUEST 0x00000774 + #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff =20 @@ -165,6 +172,11 @@ #define PASID_PASID_MASK 0x000fffff #define PASID_VALID (_AC(1, ULL) << 31) =20 +#define MSR_PKG_HDC_CTL 0x00000db0 +#define PKG_HDC_CTL_HDC_PKG_ENABLE BIT(0, ULL) +#define MSR_PM_CTL1 0x00000db1 +#define PM_CTL1_HDC_ALLOW_BLOCK BIT(0, ULL) + #define MSR_UARCH_MISC_CTRL 0x00001b01 #define UARCH_CTRL_DOITM (_AC(1, ULL) << 0) =20 @@ -468,7 +480,8 @@ #define MSR_IA32_MISC_ENABLE_MONITOR_ENABLE (1<<18) #define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1<<22) #define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1<<23) -#define MSR_IA32_MISC_ENABLE_XD_DISABLE (_AC(1, ULL) << 34) +#define MSR_IA32_MISC_ENABLE_XD_DISABLE (_AC(1, ULL) << 34) +#define MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE (_AC(1, ULL) << 38) =20 #define MSR_IA32_TSC_DEADLINE 0x000006E0 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 67a58d409b..81bda5df23 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -63,12 +63,19 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); /* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller =3D FREQCTL_xen; =20 -static int __init cpufreq_cmdline_parse(const char *s); +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] =3D { CPUFREQ_xen, + CPUFREQ_none }; +unsigned int __initdata cpufreq_xen_cnt =3D 1; + +static int __init cpufreq_cmdline_parse(const char *s, const char *e); =20 static int __init cf_check setup_cpufreq_option(const char *str) { - const char *arg =3D strpbrk(str, ",:"); + const char *arg =3D strpbrk(str, ",:;"); int choice; + int ret =3D -EINVAL; + + cpufreq_xen_cnt =3D 0; =20 if ( !arg ) arg =3D strchr(str, '\0'); @@ -89,15 +96,45 @@ static int __init cf_check setup_cpufreq_option(const c= har *str) return 0; } =20 - if ( choice > 0 || !cmdline_strcmp(str, "xen") ) + do { - xen_processor_pmbits |=3D XEN_PROCESSOR_PM_PX; - cpufreq_controller =3D FREQCTL_xen; - if ( *arg && *(arg + 1) ) - return cpufreq_cmdline_parse(arg + 1); - } + const char *end =3D strchr(str, ';'); + + if ( end =3D=3D NULL ) + end =3D strchr(str, '\0'); + + arg =3D strpbrk(str, ",:"); + if ( !arg || arg > end ) + arg =3D strchr(str, '\0'); + + if ( cpufreq_xen_cnt =3D=3D ARRAY_SIZE(cpufreq_xen_opts) ) + return -E2BIG; + + 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 cpufreq_cmdline_parse(arg + 1, end); + } + else if ( 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 hwp_cmdline_parse(arg + 1, end); + } + else + ret =3D -EINVAL; + + str =3D *end ? ++end : end; + } while ( choice < 0 && ret =3D=3D 0 && *str ); =20 - return (choice < 0) ? -EINVAL : 0; + return (choice < 0) ? ret : 0; } custom_param("cpufreq", setup_cpufreq_option); =20 @@ -576,7 +613,7 @@ static int __init cpufreq_handle_common_option(const ch= ar *name, const char *val return 0; } =20 -static int __init cpufreq_cmdline_parse(const char *s) +static int __init cpufreq_cmdline_parse(const char *s, const char *e) { static struct cpufreq_governor *__initdata cpufreq_governors[] =3D { @@ -592,6 +629,8 @@ static int __init cpufreq_cmdline_parse(const char *s) int rc =3D 0; =20 strlcpy(buf, s, sizeof(buf)); + if (e - s < sizeof(buf)) + buf[e - s] =3D '\0'; do { char *val, *end =3D strchr(str, ','); unsigned int i; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 482ea5b0de..cfe975814e 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -24,6 +24,13 @@ DECLARE_PER_CPU(spinlock_t, cpufreq_statistic_lock); =20 extern bool_t cpufreq_verbose; =20 +enum cpufreq_xen_opt { + CPUFREQ_none, + CPUFREQ_xen, + CPUFREQ_hwp, +}; +extern enum cpufreq_xen_opt cpufreq_xen_opts[2]; +extern unsigned int cpufreq_xen_cnt; struct cpufreq_governor; =20 struct acpi_cpufreq_data { @@ -245,4 +252,7 @@ void cpufreq_dbs_timer_resume(void); =20 void intel_feature_detect(struct cpufreq_policy *policy); =20 +int hwp_cmdline_parse(const char *s, const char *e); +int hwp_register_driver(void); + #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index c11c0b1a6c..5a30b16fcf 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -296,6 +296,8 @@ struct xen_ondemand { uint32_t up_threshold; }; =20 +#define XEN_HWP_DRIVER_NAME "hwp" + /* * cpufreq para name of this structure named * same as sysfs file name of native linux --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434355; cv=none; d=zohomail.com; s=zohoarc; b=JQ3atSOyzbrJMQKOBbEigBalTjLzLqqgMAQSDb8vk/QZVmE2kOBYYaTDWvPjEQZaoLXCmg5Tl7TvJtcVhZD3LmiGxOSXOCzpeAdQ4rBicPObuPvvdSjpuJubb8uNn9aOvnej/aB2anexWENCo9+aGkbNoH7Hh/XW42o1uHDRklY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434355; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E7GMVxKHH5c0AlSKBRhOVtwdBCMeAlRn7S7x06padXs=; b=SKV1qItrmDzSwjd8fx6WeZCSzm8+ezrXxDmC04bW8SB/12zeW3k2JGP3Gc2VY+InNVfu/xSbxjMtNe6o+qGj7ir4sberUAsdgTWbKpUIx6U/7aWDg/+KBxqeGSgjuKCcJX3MKAHYYv7ynM6hxv/1j+64K5pEKgIUQopKATXMnpc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434355214540.8975294780748; Mon, 7 Aug 2023 11:52:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578797.906522 (Exim 4.92) (envelope-from ) id 1qT5Ks-0006V1-80; Mon, 07 Aug 2023 18:52:10 +0000 Received: by outflank-mailman (output) from mailman id 578797.906522; Mon, 07 Aug 2023 18:52:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Ks-0006TE-1r; Mon, 07 Aug 2023 18:52:10 +0000 Received: by outflank-mailman (input) for mailman id 578797; Mon, 07 Aug 2023 18:52:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kr-0004lg-8b for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:09 +0000 Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [2607:f8b0:4864:20::936]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 820632c1-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:52:08 +0200 (CEST) Received: by mail-ua1-x936.google.com with SMTP id a1e0cc1a2514c-79969c14964so1276083241.2 for ; Mon, 07 Aug 2023 11:52:08 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:06 -0700 (PDT) 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: 820632c1-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434327; x=1692039127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E7GMVxKHH5c0AlSKBRhOVtwdBCMeAlRn7S7x06padXs=; b=XCmwnixDv+P8jXyZGp6Ful597i+goriPcgErFJPTMtTgxeZqY/Q0Ajs9ohD+8PP82e UeUzo3oLKWCHlTsKFS2PMjJ/34ywunH+ptgjru3/jDG2mZCQO3Wd5jT6KuZ6u4Qd4Huq flh8y1KxcEzQPCm5x6TKp/TU9mqqGYrbCC+LMhDqwn0DipM7uNdUzPsmohFbv4uLHjPM lTGLMVvCWDYtJz5M+Wg4kOtZ3hfmJtdEmCK2AMjFHqDhNGadg1M15tVm4OjWHYIjCqCO dtZFc7RxEhF93+nG0lgCDqH83W5Ff6dOPPUrGJIYOA80vfR16wGlBbNCJZ12iGNaTfFg BAwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434327; x=1692039127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7GMVxKHH5c0AlSKBRhOVtwdBCMeAlRn7S7x06padXs=; b=Pfxq1OqRLd00VtPjpOupPacJ3EvercF0mtfdo+YLz+Nm34ldO7JBE9b3yRwcqsEbdx H9ttQB4maFi5H0TtaYbXR49WZXAD9E0QDfAmVIsgIpy2PW3KN8MDLgwKjGUCrgD6GVnI mW341C2+xqA/VRiIYm5zpZYpsz8DOe/xtMWntEXDwaYQnw4tMSQLjYyQnNhaDCEy98of ODOjV1TaCyLWhQl/frfz3pxQuzuGqnTT7onQwqjJ242erw0Gr86EiO+1ap9Udy1njJjX UuZLvxer8MbYRkBRd3zNagc9nFkXia+tn0KZW9tZa9CychpfzfSxueDEmnPBJcxiovFh BisQ== X-Gm-Message-State: AOJu0YzfYANs2DjuDc9gAZ/1YjNvbxpM6iX11NksJLy2NxEgMoJz8oNB +hy11m9zPkCiGAZ4jRkOTcK8bWTuVCU= X-Google-Smtp-Source: AGHT+IGjSLSy/mXFwup5H0qfBTeFN88TKLtyXudtjOyP2AxytZ1td1acQxQ2Ypp14HMXA6Y+BZ2fYQ== X-Received: by 2002:a67:bd01:0:b0:443:65cb:1364 with SMTP id y1-20020a67bd01000000b0044365cb1364mr4946213vsq.6.1691434326778; Mon, 07 Aug 2023 11:52:06 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v8 07/15] xen/x86: Tweak PDC bits when using HWP Date: Mon, 7 Aug 2023 14:51:11 -0400 Message-ID: <20230807185119.98333-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434357207100002 Content-Type: text/plain; charset="utf-8" Qubes testing of HWP support had a report of a laptop, Thinkpad X1 Carbon Gen 4 with a Skylake processor, locking up during boot when HWP is enabled. A user found a kernel bug that seems to be the same issue: https://bugzilla.kernel.org/show_bug.cgi?id=3D110941. That bug was fixed by Linux commit a21211672c9a ("ACPI / processor: Request native thermal interrupt handling via _OSC"). The tl;dr is SMM crashes when it receives thermal interrupts, so Linux calls the ACPI _OSC method to take over interrupt handling. The Linux fix looks at the CPU features to decide whether or not to call _OSC with bit 12 set to take over native interrupt handling. Xen needs some way to communicate HWP to Dom0 for making an equivalent call. Xen exposes modified PDC bits via the platform_op set_pminfo hypercall. Expand that to set bit 12 when HWP is present and in use. Any generated interrupt would be handled by Xen's thermal drive, which clears the status. Bit 12 isn't named in the linux header and is open coded in Linux's usage. Name it ACPI_PDC_CPPC_NATIVE_INTR. This will need a corresponding linux patch to pick up and apply the PDC bits. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- v5: Minor fixup for feature_hwp removal Use cpurfreq.h for declaration v4: Added __ro_after_init s/ACPI_PDC_CPPC_NTV_INT/ACPI_PDC_CPPC_NATIVE_INTR/ Remove _IA32_ Fixup for opt_cpufreq_hwp removal Add Jan Reviewed-by v3: New --- xen/arch/x86/acpi/cpufreq/hwp.c | 9 +++++++++ xen/arch/x86/acpi/lib.c | 5 +++++ xen/arch/x86/cpu/mcheck/mce_intel.c | 6 ++++++ xen/arch/x86/include/asm/msr-index.h | 1 + xen/include/acpi/cpufreq/cpufreq.h | 1 + xen/include/acpi/pdc_intel.h | 1 + 6 files changed, 23 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 932786ccca..9be622f492 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -12,6 +12,8 @@ #include #include =20 +static bool __ro_after_init hwp_in_use; + static bool __ro_after_init feature_hwp_notification; static bool __ro_after_init feature_hwp_activity_window; =20 @@ -152,6 +154,11 @@ static int __init cf_check cpufreq_gov_hwp_init(void) } __initcall(cpufreq_gov_hwp_init); =20 +bool hwp_active(void) +{ + return hwp_in_use; +} + static bool __init hwp_available(void) { unsigned int eax; @@ -204,6 +211,8 @@ static bool __init hwp_available(void) hwp_verbose("HW_FEEDBACK %ssupported\n", (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); =20 + hwp_in_use =3D true; + hwp_info("Using HWP for cpufreq\n"); =20 return true; diff --git a/xen/arch/x86/acpi/lib.c b/xen/arch/x86/acpi/lib.c index 43831b92d1..51cb082ca0 100644 --- a/xen/arch/x86/acpi/lib.c +++ b/xen/arch/x86/acpi/lib.c @@ -26,6 +26,8 @@ #include #include =20 +#include + u32 __read_mostly acpi_smi_cmd; u8 __read_mostly acpi_enable_value; u8 __read_mostly acpi_disable_value; @@ -140,5 +142,8 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 m= ask) !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) pdc[2] &=3D ~(ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH); =20 + if (hwp_active()) + pdc[2] |=3D ACPI_PDC_CPPC_NATIVE_INTR; + return 0; } diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/= mce_intel.c index 2f23f02923..4045c6591d 100644 --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -15,6 +15,9 @@ #include #include #include + +#include + #include "mce.h" #include "x86_mca.h" #include "barrier.h" @@ -64,6 +67,9 @@ static void cf_check intel_thermal_interrupt(struct cpu_u= ser_regs *regs) =20 ack_APIC_irq(); =20 + if ( hwp_active() ) + wrmsr_safe(MSR_HWP_STATUS, 0); + if ( NOW() < per_cpu(next, cpu) ) return; =20 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index 2705982d93..185d3c491e 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -157,6 +157,7 @@ #define MSR_HWP_CAPABILITIES 0x00000771 #define MSR_HWP_INTERRUPT 0x00000773 #define MSR_HWP_REQUEST 0x00000774 +#define MSR_HWP_STATUS 0x00000777 =20 #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index cfe975814e..6737798e25 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -254,5 +254,6 @@ void intel_feature_detect(struct cpufreq_policy *policy= ); =20 int hwp_cmdline_parse(const char *s, const char *e); int hwp_register_driver(void); +bool hwp_active(void); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/acpi/pdc_intel.h b/xen/include/acpi/pdc_intel.h index 4fb719d6f5..abaa098b51 100644 --- a/xen/include/acpi/pdc_intel.h +++ b/xen/include/acpi/pdc_intel.h @@ -17,6 +17,7 @@ #define ACPI_PDC_C_C1_FFH (0x0100) #define ACPI_PDC_C_C2C3_FFH (0x0200) #define ACPI_PDC_SMP_P_HWCOORD (0x0800) +#define ACPI_PDC_CPPC_NATIVE_INTR (0x1000) =20 #define ACPI_PDC_EST_CAPABILITY_SMP (ACPI_PDC_SMP_C1PT | \ ACPI_PDC_C_C1_HALT | \ --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434355; cv=none; d=zohomail.com; s=zohoarc; b=Dq9OjHeZ3i4K9++3w/2Yr/gRBkFmp4KJKc3aRpwsvqiKMd2PhtbQPDx4b3tpvhBuAZBwD5hkIjSvS8PQx1+xgqW8qSmDszoyPl5jhWPaPYApBivSj6qSBnQrvjmG6A3gwVdYpF35jJR08qluasNUVoi8sVTMdIafUTtjHxP+v9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434355; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fPqtnsHma2CfZS2wC9zaYpit9POpmY/2Wfh8kuw75z0=; b=Ukx+M6bwpktaqtbB8qaOaK3SSziPNDAEgvHR/Agc+dPyYfeJRUaZhdM50O8MlaX9JOsKKl5ppPQ56y8TaFaPk4f10evcZp2AS7Ct/1TdNpSE30TuCQV0wwRQlBrbANqR7oRlgwa5xZGel9ORgiW3T57sbpGywGwAsX+WtfU6iC0= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434355790815.093852107775; Mon, 7 Aug 2023 11:52:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578798.906535 (Exim 4.92) (envelope-from ) id 1qT5Kt-0006wZ-Hs; Mon, 07 Aug 2023 18:52:11 +0000 Received: by outflank-mailman (output) from mailman id 578798.906535; Mon, 07 Aug 2023 18:52:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kt-0006vR-DJ; Mon, 07 Aug 2023 18:52:11 +0000 Received: by outflank-mailman (input) for mailman id 578798; Mon, 07 Aug 2023 18:52:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Ks-0004lg-E1 for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:10 +0000 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [2607:f8b0:4864:20::f2f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 82dba3c6-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:52:09 +0200 (CEST) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-63cf69f3c22so34293286d6.3 for ; Mon, 07 Aug 2023 11:52:09 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:07 -0700 (PDT) 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: 82dba3c6-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434328; x=1692039128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fPqtnsHma2CfZS2wC9zaYpit9POpmY/2Wfh8kuw75z0=; b=ppenxGwClsnUAAp2/zqhU27AyvhhEJKfOPrRPJy0jaGfC0ksjWfsyADLYijCgL/r3J 84dBKQ3MElDb1Z+cxwaXMZNQVldi8HR3FTnht9+REg13Lol6xbf8sDINWxhfu/vCY3IT e/1eLY1Ef0I1ZeMOJLBNTTbd2Lhg5GevI+BtGz0BOyWjrOaaLlKn6gQpZA3ZucBiOhPb o47GLfaMPUxTun4GTbW9Xh9vsTONXYwr8h0aCZKnv08ENFNjt5PaSPctEOA6iOrRiw6R Lt69seNe7f5DgzeqmaHUcnDhP6fTSk2zofcHlcgBQz2Xxe/fiO5nPETl3NKb3XxEGXJM RTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434328; x=1692039128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fPqtnsHma2CfZS2wC9zaYpit9POpmY/2Wfh8kuw75z0=; b=UabJVbCVFGnq8GcERK5ppwxVlX0T1SazTfxubLudsGUgh/h59N49Guwv2sQeTHj/jA RuyDx+3ufQylU+lz+1X2lCjWnMcknDf7t8u3u72n74qwTIRTvN37/IIkztsD9H685H8d w9HIwIw+OUPr1MAj7UznEA6Z84Pb90awd+YdMVmWhhIGgOlIQow/f0+2lD7QAwlW6LTU RsJr5U/6ZcEL1pzcSIkfMh1NZMgHr0s1mP1SMUI/ofE9prlrglFQCy/dsS47jkoQ9s+O EtTfnbqgfpuHNx1pYrQ1oaevvGEjCWSD5tRT4SNWRKqZHuD670cmM2GVolsWjKxTW9RA 4aXQ== X-Gm-Message-State: AOJu0YwU/lXJx1MTlAcOMV7YjJdEhq35TU61nZQmyv0WQDvstuau8Jtp azRZGQEpjIsClNKjT82I83G9P1Jc9V0= X-Google-Smtp-Source: AGHT+IEHQ/4/PfxRMgbqK/pM4ZITYqRK+XG5OfVqUINfsLCIhNx8quJd7Iw7hHNL/NJSMP+fVE0CZg== X-Received: by 2002:a0c:ea4f:0:b0:63d:1573:c292 with SMTP id u15-20020a0cea4f000000b0063d1573c292mr9336327qvp.65.1691434328113; Mon, 07 Aug 2023 11:52:08 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Jan Beulich Subject: [PATCH v8 08/15] xenpm: Change get-cpufreq-para output for hwp Date: Mon, 7 Aug 2023 14:51:12 -0400 Message-ID: <20230807185119.98333-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434357178100001 Content-Type: text/plain; charset="utf-8" When using HWP, some of the returned data is not applicable. In that case, we should just omit it to avoid confusing the user. So switch to printing the base and max frequencies since those are relevant to HWP. Similarly, stop printing the CPU frequencies since those do not apply. The scaling fields are also no longer printed. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich Acked-by: Anthony PERARD --- v8: Use %PRIu32 for added hwp printing Add Anthony's Ack v5: Use XEN_HWP_DRIVER_NAME Add Jan's Ack v4: s/turbo/max/ Check for XEN_HWP_DRIVER driver instead of "-internal" v2: Use full governor name XEN_HWP_GOVERNOR to change output Style fixes --- tools/misc/xenpm.c | 83 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1c474c3b59..3f5b2afcea 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -711,6 +711,7 @@ void start_gather_func(int argc, char *argv[]) /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { + bool hwp =3D strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) = =3D=3D 0; int i; =20 printf("cpu id : %d\n", cpuid); @@ -720,49 +721,57 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); =20 - printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->cpuinfo_max_freq, - p_cpufreq->cpuinfo_min_freq, - p_cpufreq->cpuinfo_cur_freq); + if ( hwp ) + printf("cpuinfo frequency : base [%"PRIu32"] max [%"PRIu32"]\n", + p_cpufreq->cpuinfo_min_freq, + p_cpufreq->cpuinfo_max_freq); + else + printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", + p_cpufreq->cpuinfo_max_freq, + p_cpufreq->cpuinfo_min_freq, + p_cpufreq->cpuinfo_cur_freq); =20 printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); =20 - printf("scaling_avail_gov : %s\n", - p_cpufreq->scaling_available_governors); - - printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); - if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - printf(" userspace specific :\n"); - printf(" scaling_setspeed : %u\n", - p_cpufreq->u.s.u.userspace.scaling_setspeed); - } - else if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "ondemand", CPUFREQ_NAME_LEN) ) + if ( !hwp ) { - 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); - printf(" up_threshold : %u\n", - p_cpufreq->u.s.u.ondemand.up_threshold); - } + printf("scaling_avail_gov : %s\n", + p_cpufreq->scaling_available_governors); =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 ) - printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); - else - printf(" %d", p_cpufreq->scaling_available_frequencies[i]); - printf("\n"); + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_gover= nor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + { + printf(" userspace specific :\n"); + printf(" scaling_setspeed : %u\n", + p_cpufreq->u.s.u.userspace.scaling_setspeed); + } + else if ( !strncmp(p_cpufreq->u.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); + printf(" up_threshold : %u\n", + p_cpufreq->u.s.u.ondemand.up_threshold); + } + + 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 ) + 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); + 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); + } =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434362; cv=none; d=zohomail.com; s=zohoarc; b=O8bDluu9TToQaS12HDkMAqbIxoRu4wTcDaIt0kwd3ETmcGPhOzTT1fRyJlHDi+QYi7L7nUZHmm+hq1rWIL10q8SrYqOnqSsR4u8QrNUp0h4FBs4XH4QystqpvdaDZe9RPAwWufnFvSZ5ONpKRphiuWY03cxlaXmj2jQqItnPGX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434362; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ot86e+1Z3pJ5J+fUBDr3w7JqY5k3+M+3EC/DXMV0EvM=; b=gFQzjyaFJYFAbQQuIQQfrE6KE5b/jBT4REUkW8MWHhs8Ay3ExSDREkgRLIEyqxrU/5AYj/OVBhl2pfx02qpo7WHWipXJ+tq+knicmdUmfTiI1xefcP2INcQMdBKl0c8MDhdneejKZoPr5YWklntYfJyT9aSLZNe81RF4ySDHw3Y= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434362490566.0036342198938; Mon, 7 Aug 2023 11:52:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578803.906546 (Exim 4.92) (envelope-from ) id 1qT5L0-0007r1-16; Mon, 07 Aug 2023 18:52:18 +0000 Received: by outflank-mailman (output) from mailman id 578803.906546; Mon, 07 Aug 2023 18:52:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Kz-0007qs-Sh; Mon, 07 Aug 2023 18:52:17 +0000 Received: by outflank-mailman (input) for mailman id 578803; Mon, 07 Aug 2023 18:52:16 +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 1qT5Ky-0004GT-PX for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:16 +0000 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [2607:f8b0:4864:20::e2e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 85d3ef1f-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:14 +0200 (CEST) Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-44768737671so1822833137.2 for ; Mon, 07 Aug 2023 11:52:14 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:12 -0700 (PDT) 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: 85d3ef1f-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434333; x=1692039133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ot86e+1Z3pJ5J+fUBDr3w7JqY5k3+M+3EC/DXMV0EvM=; b=HtIYy/U7KTLyuJuV0H1vcXedshvJr13+x/HNwupdbTBHCpML8gX3OMHFXsIW/PTtS/ 71r8eyohhbhfXtkjpSWuM/rD3Uu6x7NmudzsmRffUMne9cLnWypBbo7EaZ9mihPPYiql qS/hInCcESI4Z+zaTubDyaXedBmKwvxVLbSim0ez5TjvaA/5iWj+XtZIds9ojLbSlx/a TF4+Ck9On7KABj7jHECJPYBnF9oKdqcR+/p6xadqJkjEh9GU7yhIWA7r2YifxKRpO0Y2 Css++JFyxQdFJ2d5EPWOSt7bEv/5kNW/RaBraKWVh7LvKigTy2iocUuUykhUxhUjl1KK VCag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434333; x=1692039133; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ot86e+1Z3pJ5J+fUBDr3w7JqY5k3+M+3EC/DXMV0EvM=; b=R9PE7IyGo0MfcOUGlKvXG5M2DoN+Lf49Z2U2D7oJlM5E1Kn+niS/4jbCUoJRnBo4iD ClRDpkcWp3QvGq4QTJOPIqLSshM2cGvh6s33LQZnb3MiI7tebIUtvAEHiXMkKW/j7PKc mbNpToqi0uKkU/+fdcCWEQn+lQg1JEaBY+0IPw/wOIwju1N3eP6Udwg+0aqjlSiWseqO orMUhTdgc+Y15Eo44tpKsmfEZZQIo2ajCKq6whCe/G2TmV3NliGIvajhJLJXYX2veUxW kv91lHOFeTaTSYfmcosNY+EV2Y5ajNVW9C9cn+pQQ6vttQ3sw9MffBD/voUpuejeEn+z MnIA== X-Gm-Message-State: AOJu0YyPgV6Hj3j9OfDfMNctKfv6P04WzPdCqpNUc5kTS0rYAxn7tnDK xo7Wwq6jvGlvnoe3HZmfJM/kfF0kTqI= X-Google-Smtp-Source: AGHT+IFlZmrC0z7Z7KAEa8M2t7i5Eg40Dh/sDSINoUdzFJZ/87yNrSOiWDPU3XaDWRSaoRzdkMr+Qw== X-Received: by 2002:a67:f619:0:b0:443:7e93:641f with SMTP id k25-20020a67f619000000b004437e93641fmr4748864vso.9.1691434332699; Mon, 07 Aug 2023 11:52:12 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v8 09/15] cpufreq: Export HWP parameters to userspace as CPPC Date: Mon, 7 Aug 2023 14:51:13 -0400 Message-ID: <20230807185119.98333-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434364305100001 Content-Type: text/plain; charset="utf-8" Extend xen_get_cpufreq_para to return hwp parameters. HWP is an implementation of ACPI CPPC (Collaborative Processor Performance Control). Use the CPPC name since that might be useful in the future for AMD P-state. We need the features bitmask to indicate fields supported by the actual hardware - this only applies to activity window for the time being. The HWP most_efficient is mapped to CPPC lowest_nonlinear, and guaranteed is mapped to nominal. CPPC has a guaranteed that is optional while nominal is required. ACPI spec says "If this register is not implemented, OSPM assumes guaranteed performance is always equal to nominal performance." Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v2: Style fixes Don't bump XEN_SYSCTL_INTERFACE_VERSION Drop cpufreq.h comment divider Expand xen_hwp_para comment Add HWP activity window mantissa/exponent defines Handle union rename Add const to get_hwp_para Remove hw_ prefix from xen_hwp_para members Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data v4: Fixup for opt_cpufreq_hwp/hdc removal get_hwp_para() takes cpu as arg XEN_ prefix HWP_ACT_WINDOW_* Drop HWP_ACT_WINDOW_EXPONENT_SHIFT - shift MASK Remove Energy Bias (0-15) EPP fallback Rename xen_hwp_para to xen_cppc_para s/hwp/cppc/ Use scaling driver to switch output v5: Use XEN_HWP_DRIVER_NAME Use cpufreq.h for declarations Fixup some comments Drop const from unsigned int cpu Drop some unnecessary { } Use strncmp Switch sizeof(char) to sizeof(*scaling_available_governors) Reindent copy_to_guest call Add "HWP: " prefix to sysctl comments for cppc->hwp mapping v6: Drop commit message uint8_t paragraph sysctl.h s/They/They're/ Fix indent and add parens for read_scaling_available_governors() args Add Jan's Ack --- xen/arch/x86/acpi/cpufreq/hwp.c | 23 ++++++++++ xen/drivers/acpi/pmstat.c | 74 ++++++++++++++++-------------- xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 56 ++++++++++++++++++++++ 4 files changed, 121 insertions(+), 34 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 9be622f492..92fa01b8ea 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -519,6 +519,29 @@ static const struct cpufreq_driver __initconstrel hwp_= cpufreq_driver =3D .update =3D hwp_cpufreq_update, }; =20 +int get_hwp_para(unsigned int cpu, + struct xen_cppc_para *cppc_para) +{ + const struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + + if ( data =3D=3D NULL ) + return -ENODATA; + + cppc_para->features =3D + (feature_hwp_activity_window ? XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW : 0= ); + cppc_para->lowest =3D data->hw.lowest; + cppc_para->lowest_nonlinear =3D data->hw.most_efficient; + cppc_para->nominal =3D data->hw.guaranteed; + cppc_para->highest =3D data->hw.highest; + cppc_para->minimum =3D data->minimum; + cppc_para->maximum =3D data->maximum; + cppc_para->desired =3D data->desired; + cppc_para->energy_perf =3D data->energy_perf; + cppc_para->activity_window =3D data->activity_window; + + return 0; +} + int __init hwp_register_driver(void) { int ret; diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index d67d99e62f..e4e2df94a7 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -251,46 +251,52 @@ 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 ( !(scaling_available_governors =3D - xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) - return -ENOMEM; - if ( (ret =3D read_scaling_available_governors(scaling_available_gover= nors, - gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + if ( !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME, + CPUFREQ_NAME_LEN) ) + ret =3D get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para); + else { + if ( !(scaling_available_governors =3D + xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) + return -ENOMEM; + if ( (ret =3D read_scaling_available_governors( + scaling_available_governors, + (gov_num * CPUFREQ_NAME_LEN * + sizeof(*scaling_available_governors)))) ) + { + xfree(scaling_available_governors); + return ret; + } + ret =3D copy_to_guest(op->u.get_para.scaling_available_governors, + scaling_available_governors, + gov_num * CPUFREQ_NAME_LEN); xfree(scaling_available_governors); - return ret; - } - ret =3D copy_to_guest(op->u.get_para.scaling_available_governors, - scaling_available_governors, gov_num * CPUFREQ_NAME_LEN); - xfree(scaling_available_governors); - if ( ret ) - return ret; + if ( ret ) + return ret; =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.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; =20 - if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.u.s.scaling_governor, - policy->governor->name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NA= ME_LEN); + if ( policy->governor->name[0] ) + strlcpy(op->u.get_para.u.s.scaling_governor, + policy->governor->name, CPUFREQ_NAME_LEN); + else + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", + CPUFREQ_NAME_LEN); =20 - /* governor specific para */ - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cur; - } + /* governor specific para */ + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cu= r; =20 - if ( !strncasecmp(op->u.get_para.u.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); + if ( !strncasecmp(op->u.get_para.u.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); } =20 return ret; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 6737798e25..f90e9d3a6c 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -255,5 +255,7 @@ void intel_feature_detect(struct cpufreq_policy *policy= ); int hwp_cmdline_parse(const char *s, const char *e); int hwp_register_driver(void); bool hwp_active(void); +int get_hwp_para(unsigned int cpu, + struct xen_cppc_para *cppc_para); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 5a30b16fcf..cf27f8f2f9 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -296,6 +296,61 @@ struct xen_ondemand { uint32_t up_threshold; }; =20 +struct xen_cppc_para { + /* OUT */ + /* activity_window supported if set */ +#define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW (1 << 0) + uint32_t features; /* bit flags for features */ + /* + * See Intel SDM: HWP Performance Range and Dynamic Capabilities + * + * These four are 0-255 hardware-provided values. They're "continuous, + * abstract unit-less, performance" values. Smaller numbers are slower + * and larger ones are faster. + */ + uint32_t lowest; + uint32_t lowest_nonlinear; /* HWP: most_efficient */ + uint32_t nominal; /* HWP: guaranteed */ + uint32_t highest; + /* + * See Intel SDM: IA32_HWP_REQUEST MSR (Address: 774H Logical Processor + * Scope) + * + * These are all hints, and the processor may deviate outside of them. + * Values below are 0-255. + * + * minimum and maximum can be set to the above hardware values to cons= train + * operation. The full range 0-255 is accepted and will be clipped by + * hardware. + */ + uint32_t minimum; + uint32_t maximum; + /* + * An explicit performance hint, disabling hardware selection. + * 0 lets the hardware decide. + */ + uint32_t desired; + /* + * Hint to hardware for energy/performance preference. + * 0: Performance + * 128: Balance (Default) + * 255: Powersaving + */ + uint32_t energy_perf; + /* + * Activity Window is a moving history window for the processor's oper= ation + * calculations, controlling responsiveness. Measured in microseconds + * encoded as: + * + * bits 6:0 - 7bit mantissa + * bits 9:7 - 3bit base-10 exponent + * btis 15:10 - Unused - must be 0 + */ +#define XEN_CPPC_ACT_WINDOW_MANTISSA_MASK 0x07f +#define XEN_CPPC_ACT_WINDOW_EXPONENT_MASK 0x380 + uint32_t activity_window; +}; + #define XEN_HWP_DRIVER_NAME "hwp" =20 /* @@ -333,6 +388,7 @@ struct xen_get_cpufreq_para { struct xen_ondemand ondemand; } u; } s; + struct xen_cppc_para cppc_para; } u; =20 int32_t turbo_enabled; --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434360; cv=none; d=zohomail.com; s=zohoarc; b=byx6dOnfBtCVmMUF259+4ji3SfwK2NGV8pHUhqHHzHvzY6G0TlUcoJ0Q7JbteWLDdfeNlr/dK7EXtINZVAPIc0fhn/yBDJkxzN4dnpcozvwEpQpYcnyLHBL0BoBeFFlpxZR6FwC/uhDT2IOB4H731wjo6x0o5/qQowhtCu6fip0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434360; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8DT7oP40QgonifT7RMQUN+ralNpmx0+TMvzxcNwj95c=; b=cdCBWIiPABZM5A41go/O3E4QOg1l1tb5duqvfTc4ZWJbd8e9z9YI5CKO5Pt9Jv1dBI2c9I3k/0uC/Kw5igS2CfgYqn57PlbZlfi60c0Uu+wygHztdlxYpNgdWMvJWwk1Mi0DTeS0vJNiZV5aK5XWJwUqhtDUZMPTvyFbC51zQlk= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434360470832.925050185191; Mon, 7 Aug 2023 11:52:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578805.906556 (Exim 4.92) (envelope-from ) id 1qT5L1-0008Ar-Ee; Mon, 07 Aug 2023 18:52:19 +0000 Received: by outflank-mailman (output) from mailman id 578805.906556; Mon, 07 Aug 2023 18:52:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5L1-0008Ae-Bn; Mon, 07 Aug 2023 18:52:19 +0000 Received: by outflank-mailman (input) for mailman id 578805; Mon, 07 Aug 2023 18:52:18 +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 1qT5L0-0004GT-Pg for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:18 +0000 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [2607:f8b0:4864:20::f31]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 873a5ef7-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:16 +0200 (CEST) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-63d2b7d77bfso33900716d6.3 for ; Mon, 07 Aug 2023 11:52:16 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:14 -0700 (PDT) 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: 873a5ef7-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434335; x=1692039135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8DT7oP40QgonifT7RMQUN+ralNpmx0+TMvzxcNwj95c=; b=o79SYks5IRvTS4g7YFj3Lu/26R982JYey+le3GNqqQ9vr75f+fceIelAaAy0n1d36i rK/yTGhB7hJSpPR3VQxG/o3k9fFPuc1wQmpjhXNnZ09CsNsAPu7VpGvhoT96iPlhvZ3z FMX9BATYxLRLpjtHVyRSkl9cGWiaitofv5EyDzOpSC/1XjZUDlG9kRDl/TGJK150lJA0 7OEvIYAwZAvLXkOFMxd/6vtr6UP9lcwzqCbqo3YoeD3EFRswCQYfnock849n2/+dgVb9 7N51deTZQNkjCEV62PwG5owEBvj/y6aXb/ExKR7SMkvYFGQ4YpDXMFtnOhejB0+ne+Pr 3PAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434335; x=1692039135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8DT7oP40QgonifT7RMQUN+ralNpmx0+TMvzxcNwj95c=; b=fYANuRHKG/ZBSL1w6D3EZxupuKJl4Vo9Oq1ppvBb6X8cwplzHvdvZW7eyXdUCfdhES eFJc976KPP01dsFzE4YINs27jMEkU497VfDzI0hCC0VWPpzEQ1t/IwfpSHpO7rgOCsg1 ap5as4p3XJpe9uDkf2lEFHPJ5x8G3+74ZRsVBo1c10DhobLgPbvWNwYzz4aJNPzLTjOk roZA+4EYG83V2Ld35ejyvzgZoY//Ugfk6VDF1+dF9TEvDcJtYtTXUoc7R8ngsBFrMnEh j7WC6RQPwEHSucX1Uk9SGbiqtqi2Z32JD7bE4Eno9gRwqQt/LcDdkJ5787JYlcyltmZu jTTw== X-Gm-Message-State: AOJu0YyVQojfsuuT/oCOQyAA91swqX84y9I2RHIbHYAttyzcmZcwgHau U6RQKWzcVCw3kDYljYUD0/XyhGVIcJM= X-Google-Smtp-Source: AGHT+IH6T9fI4HBdZOk6EGgyAMl2tDC+osINgoctgIjiNWPu28mxxHWGK9Mo3xSHhjGMkqPBMVY6yw== X-Received: by 2002:a0c:e549:0:b0:63d:4a9b:b29f with SMTP id n9-20020a0ce549000000b0063d4a9bb29fmr10472878qvm.65.1691434335348; Mon, 07 Aug 2023 11:52:15 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v8 10/15] libxc: Include cppc_para in definitions Date: Mon, 7 Aug 2023 14:51:14 -0400 Message-ID: <20230807185119.98333-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434361959100001 Content-Type: text/plain; charset="utf-8" Expose the cppc_para fields through libxc. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v4: Rename hwp to cppc Add Anthony's Ack --- tools/include/xenctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index de03cfb117..5824394125 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1909,6 +1909,7 @@ int xc_smt_disable(xc_interface *xch); */ typedef struct xen_userspace xc_userspace_t; typedef struct xen_ondemand xc_ondemand_t; +typedef struct xen_cppc_para xc_cppc_para_t; =20 struct xc_get_cpufreq_para { /* IN/OUT variable */ @@ -1940,6 +1941,7 @@ struct xc_get_cpufreq_para { xc_ondemand_t ondemand; } u; } s; + xc_cppc_para_t cppc_para; } u; =20 int32_t turbo_enabled; --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434365; cv=none; d=zohomail.com; s=zohoarc; b=QAp+dpYy1OcD0gjNdSCEdlKUBsI/Bi+mpGYYlnpjtNVA9/ic+l957i5NyCNG+t6GzzaLA+LmeCzSB91bZ/QUMq2nUN2g7cQDYZODAz8aCXd1SmdZwLHKRzl0Ewcbbuirqaq2IBz8kmIKwNqq/ZYH1nIAbuNkpIEyGpnvMNyK3CU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434365; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u8YY0cMbSt93RGcC2b1IS+Yfu6uCEeREtdnIWAGkVWs=; b=I3fgqSRPZ2z1+SQCBozE90HtpfZpDWA/TLfwmeheTI8xCLpKs0dNWBxBpmblcqJQ1ikJa3yDBDxGkL/GzkG1kiw6ToDJfaIw4vB28Kjljp78JlE9rOfKgggpWfgm0q8kZ3K+UmnJBi5b2R+aFkmeXSgV3Z1sb7CTTsXDrKlkOw0= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434365277177.52144794373248; Mon, 7 Aug 2023 11:52:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578806.906566 (Exim 4.92) (envelope-from ) id 1qT5L4-0000IT-PV; Mon, 07 Aug 2023 18:52:22 +0000 Received: by outflank-mailman (output) from mailman id 578806.906566; Mon, 07 Aug 2023 18:52:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5L4-0000Hw-LH; Mon, 07 Aug 2023 18:52:22 +0000 Received: by outflank-mailman (input) for mailman id 578806; Mon, 07 Aug 2023 18:52:21 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5L3-0004lg-Fp for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:21 +0000 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [2607:f8b0:4864:20::c30]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 89533fb3-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:52:20 +0200 (CEST) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-56ca4d7079aso3310667eaf.0 for ; Mon, 07 Aug 2023 11:52:20 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:18 -0700 (PDT) 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: 89533fb3-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434339; x=1692039139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u8YY0cMbSt93RGcC2b1IS+Yfu6uCEeREtdnIWAGkVWs=; b=GYWW5JX4pXnd3+DLhH12t6E5X7ni1FxzUuRMa1pwAj58O14rcveuPnkf8ddsYil1bg /W7kjcE1lJFd1OexBkUESi9KAaguNkDuL9n7WJ0Qj96karMvJ9LsBCvWGl6E5BhqQSTs g/IbyLBh1RC10mAfYXllHqhvKZOGpSlV10BrHRgh3uwo+YwDsN564CHxhD9u+1w/IZ/L qHVqnZaukjwds/uomKxmmITyBQuPEgyuuDm7mXOieVRIGiS8PWZcSJf1v6wv32CTcfHg /Ts3HpaKR8PNoDtOZd0mxvRj4U+xDPX1mI7ZllF8j0EimHiJjelyBL9Klm7GKPT8WBwA wMzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434339; x=1692039139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u8YY0cMbSt93RGcC2b1IS+Yfu6uCEeREtdnIWAGkVWs=; b=MxYWnl1oEYYaSFsh8a595kPrgRf5/fm6a4kYR8O5OXcbx/dpwt39eBuY32Ce/3v9Pq GMVCH8BDSKRompoDOhcHWfMdaZlONa6xQX/GjpyHyeF4ZUztE22qDyk/YxtqJnE4hzB6 o4kSCzlJIWyDFpMc3XMz1Hry8U/nkIXxPECVhjwqtduYe4UaDmM04hVQwP0qm6I6J8Mg TaJSn5CspInEOIad3/q7KVPtrV3fysZ2DCQAP5xhTrUI5Fu0dIS3AF+2D5uexG6iHD3K an/4DPzhwFfhJ4OuETFun5T+kiOvuHoqbs2/F8nO7HxcETRK8tjKqggha0tfGp7qNc6h PTWA== X-Gm-Message-State: AOJu0Yzu40o2i6lxsMYjX3xjIbaewr/TLnpXwGeF9I4A0fHHdMo1f4vK tQKtYLg8nxELO77EvB1m2DARTxwXDzk= X-Google-Smtp-Source: AGHT+IEgaCDlSduv/RvPBK6XMI+y0QAxWUnpQ54azRZXBg+BliJoQMDaz8dLyZ2DSoZcqwCXAbZbdQ== X-Received: by 2002:a05:6358:4285:b0:134:eed0:3bc5 with SMTP id s5-20020a056358428500b00134eed03bc5mr7203855rwc.9.1691434338972; Mon, 07 Aug 2023 11:52:18 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Jan Beulich Subject: [PATCH v8 11/15] xenpm: Print HWP/CPPC parameters Date: Mon, 7 Aug 2023 14:51:15 -0400 Message-ID: <20230807185119.98333-12-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434366004100003 Content-Type: text/plain; charset="utf-8" Print HWP-specific parameters. Some are always present, but others depend on hardware support. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich Reviewed-by: Anthony PERARD --- v2: Style fixes Declare i outside loop Replace repearted hardware/configured limits with spaces Fixup for hw_ removal Use XEN_HWP_GOVERNOR Use HWP_ACT_WINDOW_EXPONENT_* Remove energy_perf hw autonomous - 0 doesn't mean autonomous v4: Return activity_window from calculate_hwp_activity_window Use blanks instead of _ in output Use MASK_EXTR Check XEN_HWP_DRIVER name since governor is no longer returned s/hwp/cppc v5: Add Jan's Reviewed-by v8: Switch from "if ( !hwp )" to "if ( hwp )" and re-org code. Use %PRIu32 instead of %u - this lengthens some strings past 80 chars --- tools/misc/xenpm.c | 68 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 3f5b2afcea..688529b59d 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -708,6 +708,46 @@ void start_gather_func(int argc, char *argv[]) pause(); } =20 +static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, + const char **units) +{ + unsigned int mantissa =3D MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + unsigned int exponent =3D MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_EXPONENT_MASK); + unsigned int multiplier =3D 1; + unsigned int i; + + /* + * SDM only states a 0 register is hardware selected, and doesn't ment= ion + * a 0 mantissa with a non-0 exponent. Only special case a 0 register. + */ + if ( cppc->activity_window =3D=3D 0 ) + { + *units =3D "hardware selected"; + + return 0; + } + + if ( exponent >=3D 6 ) + { + *units =3D "s"; + exponent -=3D 6; + } + else if ( exponent >=3D 3 ) + { + *units =3D "ms"; + exponent -=3D 3; + } + else + *units =3D "us"; + + for ( i =3D 0; i < exponent; i++ ) + multiplier *=3D 10; + + return mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { @@ -733,7 +773,33 @@ static void print_cpufreq_para(int cpuid, struct xc_ge= t_cpufreq_para *p_cpufreq) =20 printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); =20 - if ( !hwp ) + 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 { printf("scaling_avail_gov : %s\n", p_cpufreq->scaling_available_governors); --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434674; cv=none; d=zohomail.com; s=zohoarc; b=PkIAIKbBmBzKyZVAP3Wkxdu0sx2VI8HFGOpz9DC6jkiaWrGxRtaoqHUaEQAMQfUryj6RR4tASYtN1h9WqYimy1/BhUXnZ1cbZJaqUI3Kuqw+W8ds3NmVTuEy+tXgiDukXR0iEfNkpG1QF472asVZPh1So2sE5Fk9E1gDx+2P4F0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434674; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AOfN7Z9EVFLpJCkggYGDmqtmD+BO0lXy28fP8LpUWIs=; b=aXIfX8olUV0SMuqMMB8JcLbjy9JVen6kmlDDLBafEqZrnC1NcVBEQEcoprg9PA/yllSkagqTs8bc6MIycN4iXWCT8edeLJ6lBxG/pgzn2V3yvuKRp+2RxmVViTt3XLlb+R0f3MUd95GuFhLr1V+I7GrJ9YDoLo0BGZiOBPsv7uA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434674254198.55116744896202; Mon, 7 Aug 2023 11:57:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578851.906596 (Exim 4.92) (envelope-from ) id 1qT5Py-0003rl-1g; Mon, 07 Aug 2023 18:57:26 +0000 Received: by outflank-mailman (output) from mailman id 578851.906596; Mon, 07 Aug 2023 18:57:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Px-0003re-Ug; Mon, 07 Aug 2023 18:57:25 +0000 Received: by outflank-mailman (input) for mailman id 578851; Mon, 07 Aug 2023 18:57:25 +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 1qT5L8-0004GT-NT for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:26 +0000 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [2607:f8b0:4864:20::f29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b6ba4ac-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:23 +0200 (CEST) Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-63cf7cce5fbso34440726d6.0 for ; Mon, 07 Aug 2023 11:52:23 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:21 -0700 (PDT) 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: 8b6ba4ac-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434342; x=1692039142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AOfN7Z9EVFLpJCkggYGDmqtmD+BO0lXy28fP8LpUWIs=; b=MiT8Aw+NG79O5MeG4oXEc4pSKAtjJwI8Nu69a04vUx48j5W1BdyxlNDr79683Vp+HR IXjUu8GoYlSl0vZFFUHw8YGdvVn8pr24sF5deCNZgy/KaU0dvdz1dJUoIq8+uvmZibLm GN33UrjmVbV8okClX7zSeAj/PGF8hHLc6UF+1WvyHMGAYjzjdT8xlMqClrbngtKrAxig siMzvNpiKt9HvV+7MmZ/ZhHTfZi6rBkQKK9oza9huO9dYmcM+6rPbjwFYQ9C/21C3cAl axqXCwEeif/qVJuqHBFXKVorarL36RtpZuODXMwV+ER+HlDWFsBmD1k6/4c1Nb95Z6uq Swcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434342; x=1692039142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AOfN7Z9EVFLpJCkggYGDmqtmD+BO0lXy28fP8LpUWIs=; b=S+V+azszrrEwO2rVMNUXAuXGwVMGHZm/lD4wpJ4qAsCgQmaOUXOXCudqOaAMNzZUHe Z5/NN6fzipFNepJ0583+p9Fs7gLrjT68y6k2vHLH1I7ITWYzwke3Ex0cBaRuMaupzWaC oCLSDjzcOmJ6+a6g+CZPP6bfI6sVk1dGG4xlj6gzTN+EcS4ALzZ2QpsI4F3nyOcwUi2e mPnea6dbXeWjXunR7tYZ6ZBySRD0zML0KgvwqTNRhvgqLbtz2Ab6d2Et4ii20JaSFXRN W+v1jC59m7ImGbailTINrSTNuae0a3JoPpW2i/eAntqUR79SWjqlg1QR/1GFj2KmUYQu hTDQ== X-Gm-Message-State: AOJu0YwXD3R08aYUbt6fUvsAktDxpWoGGOYxyAAQguH5EeHxBqkXsi50 1ZIW/niBfjFW/EwJXHIL+O1NA+V0VIM= X-Google-Smtp-Source: AGHT+IFjjVG/Vb02rgE6PdI73vVmx0JX8EBV/Oopw5OaqGQYQCXg/GCuq/s5EL06eGXNzza5MxwhRg== X-Received: by 2002:a05:6214:15cf:b0:632:207d:b834 with SMTP id p15-20020a05621415cf00b00632207db834mr9586248qvz.58.1691434342145; Mon, 07 Aug 2023 11:52:22 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v8 12/15] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op Date: Mon, 7 Aug 2023 14:51:16 -0400 Message-ID: <20230807185119.98333-13-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434674798100001 Content-Type: text/plain; charset="utf-8" Add SET_CPUFREQ_HWP xen_sysctl_pm_op to set HWP parameters. The sysctl supports setting multiple values simultaneously as indicated by the set_params bits. This allows atomically applying new HWP configuration via a single wrmsr. XEN_SYSCTL_HWP_SET_PRESET_BALANCE/PERFORMANCE/POWERSAVE provide three common presets. Setting them depends on hardware limits which the hypervisor is already caching. So using them allows skipping a hypercall to query the limits (lowest/highest) to then set those same values. The code is organized to allow a preset to be refined with additional parameters if desired. "most_efficient" and "guaranteed" could be additional presets in the future, but the are not added now. Those levels can change at runtime, but we don't have code in place to monitor and update for those events. Since activity window may not be supported by all hardware, omit writing it when not supported, and return that fact to userspace by updating set_params. CPPC parameter checking disallows setting reserved bytes and ensure values are only non-zero when the corresponding set_params bit is set. There is no range checking (0-255 is allowed) since hardware is documented to clip internally. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- v7: Fix brace placement Add Jan's R-b v6: Add () around bit test Add U suffix to XEN_SYSCTL_ constants Change -EINVAL returns to -ENOENT/-EOPNOTSUPP Return success for no-op set_hwp_para() v5: Use cpufreq.h for include Add () around bit test Fix Configure typo Drop duplicated energy_perf comment Define XEN_SYSCTL_CPPC_ACT_WINDOW_MASK from *_MANTISSA_MASK and *_EXPONENT_= MASK Re-order XEN_SYSCTL_CPPC_SET_* flags to match field and hardware order. Remove const from set_cppc param to update set_params Skip Activity Window if not supported by hardware and clear set_params Make parameter parsing consistent Add an exit path when there are no parameters to write. Expand the header file to cover the IN/OUT set_params. Remove the "desired" lowest/highest checking as hardware clips internally v4: Remove IA32_ENERGY_BIAS support Validate parameters don't exceed 255 Use CPPC/cppc name set_cppc_para() add const set_cppc_para() return hwp_cpufreq_target() Expand sysctl comments v3: Remove cpufreq_governor_internal from set_cpufreq_hwp v2: Update for naming anonymous union Drop hwp_err for invalid input in set_hwp_para() Drop uint16_t cast in XEN_SYSCTL_HWP_SET_PARAM_MASK Drop parens for HWP_SET_PRESET defines Reference activity_window format comment Place SET_CPUFREQ_HWP after SET_CPUFREQ_PARA Add {HWP,IA32}_ENERGY_PERF_MAX_{PERFORMANCE,POWERSAVE} defines Order defines before fields in sysctl.h Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 102 +++++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 17 +++++ xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 64 ++++++++++++++++++ 4 files changed, 185 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 92fa01b8ea..620149243d 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -21,6 +21,10 @@ static bool __ro_after_init feature_hdc; =20 static bool __ro_after_init opt_cpufreq_hdc =3D true; =20 +#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 +#define HWP_ENERGY_PERF_BALANCE 0x80 +#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff + union hwp_request { struct @@ -542,6 +546,104 @@ int get_hwp_para(unsigned int cpu, return 0; } =20 +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_cppc_para *set_cppc) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + bool cleared_act_window =3D false; + + if ( data =3D=3D NULL ) + return -ENOENT; + + /* Validate all parameters - Disallow reserved bits. */ + if ( set_cppc->minimum > 255 || + set_cppc->maximum > 255 || + set_cppc->desired > 255 || + set_cppc->energy_perf > 255 || + (set_cppc->set_params & ~XEN_SYSCTL_CPPC_SET_PARAM_MASK) || + (set_cppc->activity_window & ~XEN_SYSCTL_CPPC_ACT_WINDOW_MASK) ) + return -EINVAL; + + /* Only allow values if params bit is set. */ + if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) && + set_cppc->desired) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM) && + set_cppc->minimum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) && + set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF) && + set_cppc->energy_perf) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW) && + set_cppc->activity_window) ) + return -EINVAL; + + /* Clear out activity window if lacking HW supported. */ + if ( (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW) && + !feature_hwp_activity_window ) + { + set_cppc->set_params &=3D ~XEN_SYSCTL_CPPC_SET_ACT_WINDOW; + cleared_act_window =3D true; + } + + /* Return if there is nothing to do. */ + if ( set_cppc->set_params =3D=3D 0 ) + return 0; + + /* Apply presets */ + switch ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_PRESET_MASK ) + { + case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE: + data->minimum =3D data->hw.lowest; + data->maximum =3D data->hw.lowest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_MAX_POWERSAVE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE: + data->minimum =3D data->hw.highest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_MAX_PERFORMANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE: + data->minimum =3D data->hw.lowest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_BALANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_NONE: + break; + + default: + return -EINVAL; + } + + /* Further customize presets if needed */ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM ) + data->minimum =3D set_cppc->minimum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ) + data->maximum =3D set_cppc->maximum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF ) + data->energy_perf =3D set_cppc->energy_perf; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) + data->desired =3D set_cppc->desired; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) + data->activity_window =3D set_cppc->activity_window & + XEN_SYSCTL_CPPC_ACT_WINDOW_MASK; + + return hwp_cpufreq_target(policy, 0, 0); +} + int __init hwp_register_driver(void) { int ret; diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index e4e2df94a7..85097d463c 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -400,6 +400,19 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *o= p) return ret; } =20 +static int set_cpufreq_cppc(struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy =3D per_cpu(cpufreq_cpu_policy, op->cpui= d); + + if ( !policy || !policy->governor ) + return -ENOENT; + + if ( !hwp_active() ) + return -EOPNOTSUPP; + + return set_hwp_para(policy, &op->u.set_cppc); +} + int do_pm_op(struct xen_sysctl_pm_op *op) { int ret =3D 0; @@ -472,6 +485,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } =20 + case SET_CPUFREQ_CPPC: + ret =3D set_cpufreq_cppc(op); + break; + case GET_CPUFREQ_AVGFREQ: { op->u.get_avgfreq =3D cpufreq_driver_getavg(op->cpuid, USR_GETAVG); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index f90e9d3a6c..281e3f513d 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -257,5 +257,7 @@ int hwp_register_driver(void); bool hwp_active(void); int get_hwp_para(unsigned int cpu, struct xen_cppc_para *cppc_para); +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_cppc_para *set_cppc); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index cf27f8f2f9..3975050248 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -351,6 +351,68 @@ struct xen_cppc_para { uint32_t activity_window; }; =20 +/* + * Set CPPC values. + * + * Configure the parameters for CPPC. Set bits in set_params control which + * values are applied. If a bit is not set in set_params, the field must = be + * zero. + * + * For HWP specifically, values must be limited to 0-255 or within + * XEN_SYSCTL_CPPC_ACT_WINDOW_MASK for activity window. Set bits outside = the + * range will be returned as -EINVAL. + * + * Activity Window may not be supported by the hardware. In that case, the + * returned set_params will clear XEN_SYSCTL_CPPC_SET_ACT_WINDOW to indica= te + * that it was not applied - though the rest of the values will be applied. + * + * There are a set of presets along with individual fields. Presets are + * applied first, and then individual fields. This allows customizing + * a preset without having to specify every value. + * + * The preset options values are as follows: + * + * preset | minimum | maxium | energy_perf + * ------------+---------+---------+---------------- + * powersave | lowest | lowest | powersave (255) + * ------------+---------+---------+---------------- + * balance | lowest | highest | balance (128) + * ------------+---------+---------+---------------- + * performance | highest | highest | performance (0) + * + * desired and activity_window are set to 0, hardware selected. + */ +struct xen_set_cppc_para { +#define XEN_SYSCTL_CPPC_SET_MINIMUM (1U << 0) +#define XEN_SYSCTL_CPPC_SET_MAXIMUM (1U << 1) +#define XEN_SYSCTL_CPPC_SET_DESIRED (1U << 2) +#define XEN_SYSCTL_CPPC_SET_ENERGY_PERF (1U << 3) +#define XEN_SYSCTL_CPPC_SET_ACT_WINDOW (1U << 4) +#define XEN_SYSCTL_CPPC_SET_PRESET_MASK 0xf0000000U +#define XEN_SYSCTL_CPPC_SET_PRESET_NONE 0x00000000U +#define XEN_SYSCTL_CPPC_SET_PRESET_BALANCE 0x10000000U +#define XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE 0x20000000U +#define XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE 0x30000000U +#define XEN_SYSCTL_CPPC_SET_PARAM_MASK \ + (XEN_SYSCTL_CPPC_SET_PRESET_MASK | \ + XEN_SYSCTL_CPPC_SET_MINIMUM | \ + XEN_SYSCTL_CPPC_SET_MAXIMUM | \ + XEN_SYSCTL_CPPC_SET_DESIRED | \ + XEN_SYSCTL_CPPC_SET_ENERGY_PERF | \ + XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) + /* IN/OUT */ + uint32_t set_params; /* bitflags for valid values */ + /* See comments in struct xen_cppc_para. */ + /* IN */ + uint32_t minimum; + uint32_t maximum; + uint32_t desired; + uint32_t energy_perf; +#define XEN_SYSCTL_CPPC_ACT_WINDOW_MASK (XEN_CPPC_ACT_WINDOW_MANTISSA_MASK= | \ + XEN_CPPC_ACT_WINDOW_EXPONENT_MASK) + uint32_t activity_window; +}; + #define XEN_HWP_DRIVER_NAME "hwp" =20 /* @@ -418,6 +480,7 @@ struct xen_sysctl_pm_op { #define SET_CPUFREQ_GOV (CPUFREQ_PARA | 0x02) #define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03) #define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04) + #define SET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x05) =20 /* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 @@ -444,6 +507,7 @@ struct xen_sysctl_pm_op { struct xen_get_cpufreq_para get_para; struct xen_set_cpufreq_gov set_gov; struct xen_set_cpufreq_para set_para; + struct xen_set_cppc_para set_cppc; uint64_aligned_t get_avgfreq; uint32_t set_sched_opt_smt; #define XEN_SYSCTL_CX_UNLIMITED 0xffffffffU --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434674; cv=none; d=zohomail.com; s=zohoarc; b=ArAmjlkWZ86bU01dvB2l9YT4GsE9LTtfz0LV/CWtz6WRo+xugIXpuxt9D8t0+zmgmQI85j8v4FjQ+AKV92LSxfmx6Oh7pY7JGzIGp6LSHwVCHYwuT6mxkmcBKjPuaVF5w6G6/pFypfxdeiZH+gTFrFnAmExRyy2xBXFU2x1MdKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434674; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8DQkeW1PaXja4KIHBd9qWOWyZUnQRLS9exqlWjIoM/A=; b=Pfoer0bPyyplVILZOOBiWRPIMLNI2vQYHwb8yGWvDzmoV/M20rdUtnHSn80sdwrC6zxhHPyySnGMGed90tm87eO/Qck43uuqaVTpSwATX4X398GEmiuD9ug7ukCIpoT4XFRAQAn24O7Bz/ylLM58tGjTNFGx4G7jWqN+Litu9eM= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434674684826.1851696445806; Mon, 7 Aug 2023 11:57:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578854.906605 (Exim 4.92) (envelope-from ) id 1qT5Q1-00048o-AD; Mon, 07 Aug 2023 18:57:29 +0000 Received: by outflank-mailman (output) from mailman id 578854.906605; Mon, 07 Aug 2023 18:57:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Q1-00048f-6q; Mon, 07 Aug 2023 18:57:29 +0000 Received: by outflank-mailman (input) for mailman id 578854; Mon, 07 Aug 2023 18:57:28 +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 1qT5LA-0004GT-Qa for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:28 +0000 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [2607:f8b0:4864:20::c32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8d4e026d-3553-11ee-8613-37d641c3527e; Mon, 07 Aug 2023 20:52:27 +0200 (CEST) Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-56d0d7300d9so3379268eaf.1 for ; Mon, 07 Aug 2023 11:52:27 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:24 -0700 (PDT) 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: 8d4e026d-3553-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434345; x=1692039145; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8DQkeW1PaXja4KIHBd9qWOWyZUnQRLS9exqlWjIoM/A=; b=Z2lmti/Wer72P5ai8c80vOFC++zaGGpmeGQt/JShbpznCCh/DpVnKzoQu0RpvB7DiT o8UYN3JEP2SSVz+iWIYySnnruPKXAP4vsHf3Y2xelJkyyCchAoRgxoI14SGy6CIxAHxR aYIvyn95Bq/Ux4hAamu+qIkhBYsGyrRZoEwKGvQczYut5xBvn7XyQjRc6Qa9YaUxD1sA WXV0qqBKmTOZ4xxlBkmd5nASkUm5Id4F/F6RZ8xZM6NGok/KfanKxfIvu5TTTVQjcS6d wQNRgzB/VvdTQ/uO4pjAJ7CcPQ+LtL4uSfRNwfrH/r6rjKOLbu/HF9bYXSnAmp1juDpE IQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434345; x=1692039145; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8DQkeW1PaXja4KIHBd9qWOWyZUnQRLS9exqlWjIoM/A=; b=JGh+IY+28h806/n0svjTEShdashWFvLLIcVUbqWU3M3WviqF11LrCiRVgCFcRJNoCG vs+OrP1v2+23Fu7xtQCjSyaiu4PT0es7EZG6xOpXOyjRA8ZpuqTsSrf8FgoN62BhxEzi nevYPHawya7Y+o6orr7HOsMGBxFnxj5KS0HGw2UGGus47scstePodexGlUqn+U6ld2Gr t2XXR6XIHDsKz4WCYnQ5ISWQ6lLpn9mb08Cz/L6AMZpE//gJVvnbgL9jU6UkYORWp7wk Efxvt320CxEsjudbpXSZ2RHfqH3wZ3q5FRgtpDA0t0mgCCqpQlsRUK3LYdLkmZ5FllnL 9oGw== X-Gm-Message-State: AOJu0YzwQwD1m6l9p+Y/VyPPGQC8nJIYO9BLpNJu7mEJPEXJuYvuN0kK nRZy+QooVJv0WunEz0IZ1lE8eIzFniM= X-Google-Smtp-Source: AGHT+IHLRK6B7CKh9F5LEFpo5z6t/O2jdU4MY1VAnFsvimMK3dDFp/U6+2u8F5o7xaDA3yEoXXxK6w== X-Received: by 2002:a05:6358:99a6:b0:139:833c:53f8 with SMTP id j38-20020a05635899a600b00139833c53f8mr9052643rwb.24.1691434345322; Mon, 07 Aug 2023 11:52:25 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v8 13/15] libxc: Add xc_set_cpufreq_cppc Date: Mon, 7 Aug 2023 14:51:17 -0400 Message-ID: <20230807185119.98333-14-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434676675100003 Content-Type: text/plain; charset="utf-8" Add xc_set_cpufreq_cppc to allow calling xen_systctl_pm_op SET_CPUFREQ_CPPC. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v2: Mark xc_set_hwp_para_t const v4: s/hwp/cppc/ Add Anthony's Ack v5: Remove const and copy back result --- tools/include/xenctrl.h | 4 ++++ tools/libs/ctrl/xc_pm.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 5824394125..12dca13b69 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1947,11 +1947,15 @@ struct xc_get_cpufreq_para { int32_t turbo_enabled; }; =20 +typedef struct xen_set_cppc_para xc_set_cppc_para_t; + int xc_get_cpufreq_para(xc_interface *xch, int cpuid, struct xc_get_cpufreq_para *user_para); int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname); 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_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 3e969b841f..6157f4e3d4 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -368,6 +368,29 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, return xc_sysctl(xch, &sysctl); } =20 +int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, + xc_set_cppc_para_t *set_cppc) +{ + DECLARE_SYSCTL; + int ret; + + if ( !xch ) + { + errno =3D EINVAL; + return -1; + } + sysctl.cmd =3D XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =3D SET_CPUFREQ_CPPC; + sysctl.u.pm_op.cpuid =3D cpuid; + sysctl.u.pm_op.u.set_cppc =3D *set_cppc; + + ret =3D xc_sysctl(xch, &sysctl); + + *set_cppc =3D sysctl.u.pm_op.u.set_cppc; + + return ret; +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret =3D 0; --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434373; cv=none; d=zohomail.com; s=zohoarc; b=iJyNwtf4C9uYvtWEokcM8KlgllZMW05DNV3yLkm2FacQ4FqYzBB8+29GznuQi+t/JoWmZPQvtGrbJkAZDhQKaU+sqOirU+J8l8xDHqbuc2st4tAVQe+VX9xYr3iKF/rixKtDDvbhQfVIQkmCM6HVUd7Ob0HQp/J2rOQpY7zhvHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434373; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vy6l55+rICbbuCBbADGaq7cX5z20EMNlyiZQ4cOI23w=; b=StNLZT2s4oSYPiCA1jqduIIqSloRfBhy7qgBUTd8WbEW41XP2Fbe02z1xs84KARSDqVI4DgC7xkGkEVMSG54MJm2VdQhoLukOyt8Cr2+FUryospEgyRZ6pGoW0D48wYN82TH98bW3EEDWLDy1lO4dzu2Qmp6hoJtg5gobRFee2E= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434373805588.2136110403816; Mon, 7 Aug 2023 11:52:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578812.906576 (Exim 4.92) (envelope-from ) id 1qT5LE-0001PL-21; Mon, 07 Aug 2023 18:52:32 +0000 Received: by outflank-mailman (output) from mailman id 578812.906576; Mon, 07 Aug 2023 18:52:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5LD-0001PC-UU; Mon, 07 Aug 2023 18:52:31 +0000 Received: by outflank-mailman (input) for mailman id 578812; Mon, 07 Aug 2023 18:52:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5LC-0004lg-Nm for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:30 +0000 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [2607:f8b0:4864:20::730]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8eea7ef2-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:52:29 +0200 (CEST) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-76cdf055c64so417800685a.3 for ; Mon, 07 Aug 2023 11:52:29 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:27 -0700 (PDT) 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: 8eea7ef2-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434348; x=1692039148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vy6l55+rICbbuCBbADGaq7cX5z20EMNlyiZQ4cOI23w=; b=gnpUvo20i1TFYP99cadluOYvaxMNd5nY7wt+HzhGdEQfwgjkzX3n0qokafBMyYnkYC 2MI25xGHI4+fCYKeBHFj3UlNT3t5Kko9a5kEeZwIFE4U4W1QPMv+xE+7Ew216R5LcMbS D7PDx2N1CdPxYqDXi7rvurW4Du/FPSKCyedzSmbEThpKWHYpZUPo1nIKXX4ZnRfa/9W3 go+0A3zypevobOWqNSvY9PF2w/IKOBJD2IY9xq0Fe7UFGF+oYI4V1YbZWvMJ6cB+mmVa YgrWnwvgBzw526ibKsN67rnrt7Eqf4g0yPZdFwnq04Qr9qoCzvZTngxsdLxX7m8s3K1G 9X3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434348; x=1692039148; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vy6l55+rICbbuCBbADGaq7cX5z20EMNlyiZQ4cOI23w=; b=ALQR2l7wpzmW4XgQ1jycutQ0Aa4gnRUfa7YIxDRJXY2peU0o9GuYz2OAWOIq/w7nPP u7Kjaw3raoCTGgRvZO4YgRS2qc5CRAYuFcAFsonHQ0rcJw7W13wkMxNWIRUZLYssrKkr igrJ+7bCSARkQQYbaUpdPR6geDNxWGDNv34AhXYWHiE05t2ajui5Oqlz9clyPTn4IptD K90YdO46pfJCHHG2rYvpSC02EaG3427sm+0pKN2oGUa1fKb//MA/fOwa/54cGD8IzvyN iqu9Yq1hd3qLyqLP1zrqgChFJVqPAItajMoLckNuIOwsm89uIjWYIhx4ysE8LxQpsZxp WDaA== X-Gm-Message-State: AOJu0YxjjnQRT3uCot9p3gRk1A3cP4FacwHqunboYxPZV8PlpF8JnwaG OTdm3NpY3MoaQmkreGHDVg3NTCh5j3I= X-Google-Smtp-Source: AGHT+IE270NkHftGVb6Bp1YfXQBa81JVmCLv3fKo81pPhZF8LWIBeXSP4vpcU+9V5qDfro0337GIoA== X-Received: by 2002:a0c:e3c3:0:b0:636:47a5:4bc5 with SMTP id e3-20020a0ce3c3000000b0063647a54bc5mr9335668qvl.62.1691434348336; Mon, 07 Aug 2023 11:52:28 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Jan Beulich Subject: [PATCH v8 14/15] xenpm: Add set-cpufreq-cppc subcommand Date: Mon, 7 Aug 2023 14:51:18 -0400 Message-ID: <20230807185119.98333-15-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434374112100001 Content-Type: text/plain; charset="utf-8" set-cpufreq-cppc allows setting the Hardware P-State (HWP) parameters. It can be run on all or just a single cpu. There are presets of balance, powersave & performance. Those can be further tweaked by param:val arguments as explained in the usage description. Parameter names are just checked to the first 3 characters to shorten typing. Some options are hardware dependent, and ranges can be found in get-cpufreq-para. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich Acked-by: Anthony PERARD --- v8: Add Anthony's Ack v5: Make i unsigned int Use local max_cpuid instead of max_cpu_nr Add Jan's Ack Check set_params and print a message if activity window wasn't set v4: Remove energy bias 0-15 & 7 references Use MASK_INSR Fixup { placement Drop extra case in parse_activity_window strcmp suffix Expand help text s/hwp/cppc/ Use isdigit() to check cpuid - otherwise run on all CPUs. v2: Compare provided parameter name and not just 3 characters. Use "-" in parameter names Remove hw_ Replace sscanf with strchr & strtoul. Remove toplevel error message with lower level ones. Help text s/127/128/ Help text mention truncation. Avoid some truncation rounding down by adding 5 before division. Help test mention default microseconds Also comment the limit check written to avoid overflow. --- tools/misc/xenpm.c | 244 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 688529b59d..d982482a3f 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -16,6 +16,8 @@ */ #define MAX_NR_CPU 512 =20 +#include +#include #include #include #include @@ -67,6 +69,30 @@ void show_help(void) " set-max-cstate |'unlimited' [|'unlimited']= \n" " set the C-State limitati= on ( >=3D 0) and\n" " optionally the C-sub-sta= te limitation ( >=3D 0)\n" + " set-cpufreq-cppc [cpuid] [balance|performance|powersave= ] *\n" + " set Hardware P-State (HW= P) parameters\n" + " on CPU or all if= omitted.\n" + " optionally a preset of o= ne of:\n" + " balance|performance|po= wersave\n" + " an optional list of para= m:val arguments\n" + " minimum:N (0-255)\n" + " maximum:N (0-255)\n" + " get-cpufreq-para l= owest/highest\n" + " values are limits = for\n" + " minumum/maximum.\n" + " desired:N (0-255)\n" + " set explicit perfo= rmance target.\n" + " non-zero disables = auto-HWP mode.\n" + " energy-perf:N (0-255)\= n" + " energy/per= formance hint\n" + " lower - fa= vor performance\n" + " higher - f= avor powersave\n" + " 128 - bala= nce\n" + " act-window:N{,m,u}s ra= nge 1us-1270s\n" + " window for interna= l calculations.\n" + " units default to \= "us\" if unspecified.\n" + " truncates un-repre= sentable values.\n" + " 0 lets the hardwar= e decide.\n" " start [seconds] start collect Cx/Px stat= istics,\n" " output after CTRL-C or S= IGINT or several seconds.\n" " enable-turbo-mode [cpuid] enable Turbo Mode for pr= ocessors that support it.\n" @@ -1292,6 +1318,223 @@ void disable_turbo_mode(int argc, char *argv[]) errno, strerror(errno)); } =20 +/* + * Parse activity_window:NNN{us,ms,s} and validate range. + * + * Activity window is a 7bit mantissa (0-127) with a 3bit exponent (0-7) b= ase + * 10 in microseconds. So the range is 1 microsecond to 1270 seconds. A = value + * of 0 lets the hardware autonomously select the window. + * + * Return 0 on success + * -1 on error + */ +static int parse_activity_window(xc_set_cppc_para_t *set_cppc, unsigned lo= ng u, + const char *suffix) +{ + unsigned int exponent =3D 0; + unsigned int multiplier =3D 1; + + if ( suffix && suffix[0] ) + { + if ( strcmp(suffix, "s") =3D=3D 0 ) + { + multiplier =3D 1000 * 1000; + exponent =3D 6; + } + else if ( strcmp(suffix, "ms") =3D=3D 0 ) + { + multiplier =3D 1000; + exponent =3D 3; + } + else if ( strcmp(suffix, "us") !=3D 0 ) + { + fprintf(stderr, "invalid activity window units: \"%s\"\n", suf= fix); + + return -1; + } + } + + /* u * multipler > 1270 * 1000 * 1000 transformed to avoid overflow. */ + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window is too large\n"); + + return -1; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u +=3D 5; /* Round up to mitigate truncation rounding down + e.g. 128 -> 120 vs 128 -> 130. */ + u /=3D 10; + exponent +=3D 1; + } + + set_cppc->activity_window =3D + MASK_INSR(exponent, XEN_CPPC_ACT_WINDOW_EXPONENT_MASK) | + MASK_INSR(u, XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_ACT_WINDOW; + + return 0; +} + +static int parse_cppc_opts(xc_set_cppc_para_t *set_cppc, int *cpuid, + int argc, char *argv[]) +{ + int i =3D 0; + + if ( argc < 1 ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( isdigit(argv[i][0]) ) + { + if ( sscanf(argv[i], "%d", cpuid) !=3D 1 || *cpuid < 0 ) + { + fprintf(stderr, "Could not parse cpuid \"%s\"\n", argv[i]); + return -1; + } + + i++; + } + + if ( i =3D=3D argc ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( strcasecmp(argv[i], "powersave") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_BALANCE; + i++; + } + + for ( ; i < argc; i++) + { + unsigned long val; + char *param =3D argv[i]; + char *value; + char *suffix; + int ret; + + value =3D strchr(param, ':'); + if ( value =3D=3D NULL ) + { + fprintf(stderr, "\"%s\" is an invalid cppc parameter\n", argv[= i]); + return -1; + } + + value[0] =3D '\0'; + value++; + + errno =3D 0; + val =3D strtoul(value, &suffix, 10); + if ( (errno && val =3D=3D ULONG_MAX) || value =3D=3D suffix ) + { + fprintf(stderr, "Could not parse number \"%s\"\n", value); + return -1; + } + + if ( strncasecmp(param, "act-window", strlen(param)) =3D=3D 0 ) + { + ret =3D parse_activity_window(set_cppc, val, suffix); + if (ret) + return -1; + + continue; + } + + if ( val > 255 ) + { + fprintf(stderr, "\"%s\" value \"%lu\" is out of range\n", para= m, + val); + return -1; + } + + if ( suffix && suffix[0] ) + { + fprintf(stderr, "Suffix \"%s\" is invalid\n", suffix); + return -1; + } + + if ( strncasecmp(param, "minimum", MAX(2, strlen(param))) =3D=3D 0= ) + { + set_cppc->minimum =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_MINIMUM; + } + else if ( strncasecmp(param, "maximum", MAX(2, strlen(param))) =3D= =3D 0 ) + { + set_cppc->maximum =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_MAXIMUM; + } + else if ( strncasecmp(param, "desired", strlen(param)) =3D=3D 0 ) + { + set_cppc->desired =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_DESIRED; + } + else if ( strncasecmp(param, "energy-perf", strlen(param)) =3D=3D = 0 ) + { + set_cppc->energy_perf =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_ENERGY_PERF; + } + else + { + fprintf(stderr, "\"%s\" is an invalid parameter\n", param); + return -1; + } + } + + if ( set_cppc->set_params =3D=3D 0 ) + { + fprintf(stderr, "No parameters set in request\n"); + return -1; + } + + return 0; +} + +static void cppc_set_func(int argc, char *argv[]) +{ + xc_set_cppc_para_t set_cppc =3D {}; + unsigned int max_cpuid =3D max_cpu_nr; + int cpuid =3D -1; + unsigned int i =3D 0; + uint32_t set_params; + + if ( parse_cppc_opts(&set_cppc, &cpuid, argc, argv) ) + exit(EINVAL); + + if ( cpuid !=3D -1 ) + { + i =3D cpuid; + max_cpuid =3D i + 1; + } + + set_params =3D set_cppc.set_params; + for ( ; i < max_cpuid; i++ ) { + if ( xc_set_cpufreq_cppc(xc_handle, i, &set_cppc) ) + fprintf(stderr, "[CPU%d] failed to set cppc params (%d - %s)\n= ", + i, errno, strerror(errno)); + } + + if ( (set_params ^ set_cppc.set_params) & XEN_SYSCTL_CPPC_SET_ACT_WIND= OW ) + printf("Activity window not supported and omitted\n"); +} + struct { const char *name; void (*function)(int argc, char *argv[]); @@ -1302,6 +1545,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "set-cpufreq-cppc", cppc_set_func }, { "set-scaling-maxfreq", scaling_max_freq_func }, { "set-scaling-minfreq", scaling_min_freq_func }, { "set-scaling-governor", scaling_governor_func }, --=20 2.41.0 From nobody Sat May 11 08:29:35 2024 Delivered-To: importer@patchew.org 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; 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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691434682; cv=none; d=zohomail.com; s=zohoarc; b=UsfPrRD8r6BOJ/qjoaWssUzcHw6smKQSO0cvWS0Q8ZpgYNXgOptIlp34LzmHRSOb+U/nqZdMZu6/Ig/LMA1FsXe/JKP1q6H18E7o1bgKRYz2cv4esLPIfsQgW+eQ++1F5X9N0wRkDviZs7oChwvW7JgwVf72gqDy+pgnq1rdDUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691434682; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=th66OAkyXfCb+8rqcY7T1oi7fcMyAzOkt6nXPnMYefM=; b=h+vDSHmmZzl4bbqlVKRpToL+GJYyFV37LdoK+NZvlWlEg51XeHbOzQ38IQCVOEzm0bmusIVNya9YfAhFaP8qCWjVycCfDsuPvI/rHQ1albaAYt+TUe43V9Ad+ytEjiGzrkd5PCWmkoM5NBeU72QCFjpqf1FrQwHX5t8bRWMGtlc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1691434682761782.0623807858963; Mon, 7 Aug 2023 11:58:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.578867.906616 (Exim 4.92) (envelope-from ) id 1qT5Q3-0004R3-Ii; Mon, 07 Aug 2023 18:57:31 +0000 Received: by outflank-mailman (output) from mailman id 578867.906616; Mon, 07 Aug 2023 18:57:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5Q3-0004Qs-Er; Mon, 07 Aug 2023 18:57:31 +0000 Received: by outflank-mailman (input) for mailman id 578867; Mon, 07 Aug 2023 18:57:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qT5LH-0004lg-T8 for xen-devel@lists.xenproject.org; Mon, 07 Aug 2023 18:52:35 +0000 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [2607:f8b0:4864:20::f2d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 90970bbb-3553-11ee-b280-6b7b168915f2; Mon, 07 Aug 2023 20:52:32 +0200 (CEST) Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-63d0f62705dso31217936d6.0 for ; Mon, 07 Aug 2023 11:52:32 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id l3-20020a0ce503000000b00635fcd30ff9sm3077278qvm.40.2023.08.07.11.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 11:52:30 -0700 (PDT) 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: 90970bbb-3553-11ee-b280-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691434351; x=1692039151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=th66OAkyXfCb+8rqcY7T1oi7fcMyAzOkt6nXPnMYefM=; b=U0SJXFmwB0QB3rzVbn18YtO4XaHbkLyqGMzTWNUlvx7WCmGcr9FcXhA4ZFd6qpPtzE C80gMNl5jXBBxFflxh3srBkXQIBe0oWgKbRXehv7ikL5aV2s4otKmk8fDbEillzSa2qj PK1Ah+xrGgEcGp5CzaF8z4VhEVva81qNj4pMRHuzTDG23UinMATTrPzg/rCnD7XJ+v/A p3AoK0eW/zRMhX+obmdScIdCMIFM+w31z3LCjyZye4QybbIDbcW2AjJ4d7hu/P9id7vx 0crKCoyjRvT5/bJ3CGv7U/z2qgn4YhEW51seSS//QZJwhcrVz3giwLp9lwWxdQNHp9OP 3IBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691434351; x=1692039151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=th66OAkyXfCb+8rqcY7T1oi7fcMyAzOkt6nXPnMYefM=; b=SaE4VYI/RLxi3ioqGPENhBA6vxxaxZufNV/41w71G2XVMxWIZmCQqe1VEWfOeWtM1X o4wds0YmEF2S2oNINC6N1MuUFK1ILj3M92h461kCFYfRGmQxMZeRSdYPf7rDraapoU3v mRF2dFyQvlL4f7ejgHwajGnPp7X1y9pv3a7qOX62yi28sBagZjwOcrCezEkKUUMSpl+2 nH3RgVSOxVqb6NsNywjecqqLyIWdMMvwdioXibrMwEYP11v3gufmxQ8/E2afN8GdtgJz CU23T1Kbe5haRqJnnWsXXdizVq58cpdRXntgCP9jy1qnhJN5zTCCTB+RX29DKNDXkEa/ xtZQ== X-Gm-Message-State: AOJu0YxSO42XTK2kMn0TwkDCDePSoXU3jgYqBHqfk57NoOrpLm/lD027 Rj7K7Gg1dVpibwfF038qt7mS9DS+RGU= X-Google-Smtp-Source: AGHT+IH5PcmbQONWX0ET0Fwui98yNSXOY56/kwYGUa5lf37rZkMDqWFNhdyH6inHc/5YenFSgksxIA== X-Received: by 2002:a0c:f24d:0:b0:635:dda5:bb88 with SMTP id z13-20020a0cf24d000000b00635dda5bb88mr9308623qvl.53.1691434351205; Mon, 07 Aug 2023 11:52:31 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Henry Wang , Community Manager Subject: [PATCH v8 15/15] CHANGELOG: Add Intel HWP entry Date: Mon, 7 Aug 2023 14:51:19 -0400 Message-ID: <20230807185119.98333-16-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230807185119.98333-1-jandryuk@gmail.com> References: <20230807185119.98333-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691434683596100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jason Andryuk Acked-by: Henry Wang --- v3: Position under existing Added section Add Henry's Ack v2: Add blank line --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e5efcabda..56921db79f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) - xl/libxl can customize SMBIOS strings for HVM guests. - Add support for AVX512-FP16 on x86. - On Arm, Xen supports guests running SVE/SVE2 instructions. (Tech Previe= w) + - Add Intel Hardware P-States (HWP) cpufreq driver. =20 ### Removed - On x86, the "pku" command line option has been removed. It has never --=20 2.41.0