From nobody Sat May 4 05:43:58 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=1615237383; cv=none; d=zohomail.com; s=zohoarc; b=BoNS1w1aHZj8U07jLXj5WC38XutN8G9jbHQasH2d5ps5L06tYGD+ByzQ2898QgXBH2BbVt6gfDSAUbAczPQcr1WJ2WGBpwxEg13WFOORubNjEtOR4T8uxMj85hn55HAg4fKCx8+2SCnvoonlxs4nnAtnMhtQDXLI11sfUU24O1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237383; 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=AfcM/s05qxzInnDElTdSa2MUdrnaUTl8MKM2+TfWCVg=; b=PMYrq1vjj1w/zCuJkMdEk8JmgLpzCudW7IRqwOmWmI+nL2nRSP/03mmblpFsRvR07/sQyPBCJmTS7qpGuKCQxN2kapCIZFKW8tUshudH5pcNh9ZweN1hE7pOOJKbYCk4xsCrxeadY26TC4tK9UmEPXe0JgxgENlJtaoXlfd612U= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237383399966.0968204959106; Mon, 8 Mar 2021 13:03:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95081.179364 (Exim 4.92) (envelope-from ) id 1lJN1J-0006Qc-0A; Mon, 08 Mar 2021 21:02:29 +0000 Received: by outflank-mailman (output) from mailman id 95081.179364; Mon, 08 Mar 2021 21:02:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1I-0006QU-Sv; Mon, 08 Mar 2021 21:02:28 +0000 Received: by outflank-mailman (input) for mailman id 95081; Mon, 08 Mar 2021 21:02:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1H-0006P0-Hx for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:27 +0000 Received: from mail-qv1-xf2f.google.com (unknown [2607:f8b0:4864:20::f2f]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 43aa06a6-76b4-4036-837e-7fcc27eb821d; Mon, 08 Mar 2021 21:02:24 +0000 (UTC) Received: by mail-qv1-xf2f.google.com with SMTP id s17so5311941qvr.12 for ; Mon, 08 Mar 2021 13:02:24 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:23 -0800 (PST) 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: 43aa06a6-76b4-4036-837e-7fcc27eb821d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AfcM/s05qxzInnDElTdSa2MUdrnaUTl8MKM2+TfWCVg=; b=tbMhZo+C/23Qk6OTDzVt4ntvhwQITnUTwcsWvir9zh+CBlzBSXCq/rINAAzPFz88s6 sm65Or2at2PZwM9OyXMQBkwvz8WVbxSIi8kfNdy5sj5TjdAj724obPfg1aOCylj0FKMV 7HU1HUA1MV4DZdfHrDqsj2lX4xt+26nJvNA6K8iAXoZ/yAwryvCAwZXlZ/TY+eHBkMym cADG9C92CEKCTjfN9HXLOPb2B4rgMDImokSiU72PRhEZbKf76RHdH2Bxrsos8D84pzuG oDY4mZQNUJe3nzYoEJkCSQJbl/urs94V8KGdP05uslJ+02VO5KJ2kIFOrMW+NRGYzNTT AwRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AfcM/s05qxzInnDElTdSa2MUdrnaUTl8MKM2+TfWCVg=; b=AF8PJwYNOfQysq/gVqLA2/myFhaxfGnCxo9hld4+TM3NnPh4sMiQ+juhUGBD/i9uaO ecGMt13qk2anGvMu0mQO2XhwuHfIbjc8WFeLtgB7j1MwdZi4Hr5lIHnCSI4/T+JKQjTe VogGNe0s6tOaq8AS/6FM61kNWxo5aynHaL1ebtS07czHWOzDS9v8vEtzGdMvk8kttr2V +DZgioOlhBc2ra7qhU7EJH0cExudecf4v7HgLxfLNUVxd5O0hAWEPoB4L9pjfLPTnP3m iAtsb12HUNfbs8UoKCGJevust8pgoR5Ta5EUfP9MxGgGU+h0I0EvcarsUyIbn4nbAHrf BDxw== X-Gm-Message-State: AOAM5330DHGv78YR4Gqktex82hS0RjLYKh+Slj7yP8kIFaYJSMByfsk/ Eu4wB/r3t5NdaFRd11RR31oIKGFzvA4= X-Google-Smtp-Source: ABdhPJyHuwzAX6BTlMOiuZNdGKVNT28aymiqM3iA/I5EocSfeuPmVcrmGeqzJ7pR7YdpkQMQVDFKsg== X-Received: by 2002:ad4:4c0b:: with SMTP id bz11mr1818565qvb.4.1615237344305; Mon, 08 Mar 2021 13:02:24 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Jan Beulich Subject: [RFC 01/12] cpufreq: Allow restricting to internal governors only Date: Mon, 8 Mar 2021 16:01:59 -0500 Message-Id: <20210308210210.116278-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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-internal, will be used. This is set during presmp_initcall, so that it can suppress governor registration during initcall. Only a governor with a name containing "internal" will be allowed in that case. This way, the unuseable governors are not registered, so they internal one is the only one returned to userspace. This means incompatible governors won't be advertised to userspace. Signed-off-by: Jason Andryuk --- xen/drivers/cpufreq/cpufreq.c | 4 ++++ xen/include/acpi/cpufreq/cpufreq.h | 1 + 2 files changed, 5 insertions(+) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index e630a47419..b1f668b715 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -57,6 +57,7 @@ struct cpufreq_dom { }; static LIST_HEAD_READ_MOSTLY(cpufreq_dom_list_head); =20 +bool __read_mostly cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); =20 @@ -122,6 +123,9 @@ int __init cpufreq_register_governor(struct cpufreq_gov= ernor *governor) if (!governor) return -EINVAL; =20 + if (cpufreq_governor_internal && strstr(governor->name, "internal") = =3D=3D NULL) + return -EINVAL; + if (__find_governor(governor->name) !=3D NULL) return -EEXIST; =20 diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index e88b20bfed..56df5eebed 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -115,6 +115,7 @@ extern struct cpufreq_governor cpufreq_gov_dbs; extern struct cpufreq_governor cpufreq_gov_userspace; extern struct cpufreq_governor cpufreq_gov_performance; extern struct cpufreq_governor cpufreq_gov_powersave; +extern bool cpufreq_governor_internal; =20 extern struct list_head cpufreq_governor_list; =20 --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237384; cv=none; d=zohomail.com; s=zohoarc; b=G+c/VfOegnzfwsHw2U8G4gI8ai8BYuIPol/fm6vH9o7E44yu1bZm5z2Kc+97v0nTjo3uu+M6vRiJ5pPLnEipBOCaZYKLaZmPVo3W9RGMrw0CBqYgMrdPwS9wNPZT9YhDan5JhEKsnlKma+l3Gel1DK5xjnPFxFHG6QPkv9Y7/ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237384; 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=znGoCssIhhTkDoewrJpPluTmjs7zy8iVwjnUtkhYRns=; b=iI/+DwR6D6IDcyE3rtzGlw2Wh7y6nNNzEz1kf+B9j/rsr/5MC+8qrmdlY9p/QhG9QkHvk4xIEQNHfkL3AmNVJP/gcFacjQ6V6ksVACLlHMZTavCtxOsx/33vVpBje1X2fNQBaeLnHcvoReQ2os2jH134JXMbrUjnPSyyRlc6qPw= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237384182898.2917784077631; Mon, 8 Mar 2021 13:03:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95082.179375 (Exim 4.92) (envelope-from ) id 1lJN1O-0006Td-AL; Mon, 08 Mar 2021 21:02:34 +0000 Received: by outflank-mailman (output) from mailman id 95082.179375; Mon, 08 Mar 2021 21:02:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1O-0006TU-6J; Mon, 08 Mar 2021 21:02:34 +0000 Received: by outflank-mailman (input) for mailman id 95082; Mon, 08 Mar 2021 21:02:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1M-0006P0-IW for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:32 +0000 Received: from mail-qv1-xf30.google.com (unknown [2607:f8b0:4864:20::f30]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3317de23-9f88-48da-a58a-9c85b5f562b1; Mon, 08 Mar 2021 21:02:27 +0000 (UTC) Received: by mail-qv1-xf30.google.com with SMTP id 15so5316748qvp.13 for ; Mon, 08 Mar 2021 13:02:27 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:26 -0800 (PST) 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: 3317de23-9f88-48da-a58a-9c85b5f562b1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=znGoCssIhhTkDoewrJpPluTmjs7zy8iVwjnUtkhYRns=; b=VTOGUgDcVBADbGGoC2x8aqI1+ZjoRam9mlpwc+lZv0DsI8vWG2GfhbyGSGGiKsawAQ glSnnJ6zgV9VKQqZnlMfkYl+JfnNw5HuyqiYsNhQuBtAHbxAR2qpOaJ2itLzjL5ygyw9 4yFABH+KHt81zKuH6EyJPKU8Bul+1PmD1+kvXmstiSHSDMwRG9OBpLfdyRCSRlP1mVcT V7OFsTE/8s3TxUZo+q7Otzdxjs3SWrJUzLw9c22ixdVTtWvdIfGQfr8v0iIdCC12/VKf u7uoRsCGS+uWNVKxOGj1fhNpQR92UTD8P4irTiifsHFsZAlDX9iHzqXadSKaJDJUEGGR QRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=znGoCssIhhTkDoewrJpPluTmjs7zy8iVwjnUtkhYRns=; b=leMsvTdfksEpPHvH64Fo4l4TJ8xHDlaoLOdbP0RLiDk8eMf6k5pv9UYuljQrSYKNoj pozcSWn1aAS04FRvZYk29+063LjN4pg0YmkGnWkCf1Ha92XkBbMpenWDBxLqIjHNG3EL DOhKq7SdwcqqoB4Gs3WEm/u+paQwvjyOJ8UL7ReO7Vw/h6ncV+ygll35QtudC7AYEVXD 80KuwWkHifLjBH2xvUzQrkhSBcVzSjWvvlZbFnJhFIYa8bDDud12kmUNuGoE2FEtrFuj YauMAbQyFdHupZWvUpYJWng0VMGU/tnaBFp9/PK4fLlvs40oAoZ10JkGlzWKxn//wix8 vWJg== X-Gm-Message-State: AOAM532MCXJWG6jXJlJOeTxER6F53L6fDIlcyZ6UsoraSHTUQV3jQa2C F75PPwJl18CG/Sed0fYvE4QhIkExiuo= X-Google-Smtp-Source: ABdhPJzKIodUHBfVbf6ctvzIC+8gLg2g3Rmlasu1nuYaIbyh31yXV4Y9g6NRds9nDCx21/VDPIkNWw== X-Received: by 2002:a0c:aece:: with SMTP id n14mr22796843qvd.52.1615237346639; Mon, 08 Mar 2021 13:02:26 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [RFC 02/12] cpufreq: Add perf_freq to cpuinfo Date: Mon, 8 Mar 2021 16:02:00 -0500 Message-Id: <20210308210210.116278-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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 --- 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 f1f3c6923f..5eac2f7321 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -317,7 +317,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 get_cur_freq_on_cpu(unsigned int cpu) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index b93895d4dd..788929e079 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 56df5eebed..b91859ce5d 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.29.2 From nobody Sat May 4 05:43:58 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=1615237383; cv=none; d=zohomail.com; s=zohoarc; b=Gtf+YPg+pRr4dyE/pk+7ZqUlX1Dz7iChn54MNLJbq994BPBsFWV+kWiWXo0Dp0wlQz1SowfHQ7OcYBKNdjuND1YFtxakRKoiPzETElUhzeA7Vpb78FBMQE/kkOpF5j28NxH1ZHbNfE6MzZaRBT/ptIWIBcAnrRhqdD1WZkpN2pc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237383; 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=/v3gx4Dpg1dN3dSgA3Eor7lGHSmiomkDY5L/9HqLLB8=; b=Ed4NTN3vPdPyprxlAWGJivfLHSesnYdKWkNOOovfPtJrzPGDQXPzdq2taUeVEbpNHor0FIwB4bP/sM36NCgTrG5u+VMwYnu8zEASU57j6DM158JVAMm+I15RlJkCuhppssxqX53ED1aUm0blyM7w6iB1rKhU03bznovfcktQ9Xg= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237383409726.670581648141; Mon, 8 Mar 2021 13:03:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95083.179388 (Exim 4.92) (envelope-from ) id 1lJN1S-0006Xb-Nt; Mon, 08 Mar 2021 21:02:38 +0000 Received: by outflank-mailman (output) from mailman id 95083.179388; Mon, 08 Mar 2021 21:02:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1S-0006XQ-Jc; Mon, 08 Mar 2021 21:02:38 +0000 Received: by outflank-mailman (input) for mailman id 95083; Mon, 08 Mar 2021 21:02:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1R-0006P0-IZ for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:37 +0000 Received: from mail-qt1-x82c.google.com (unknown [2607:f8b0:4864:20::82c]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ba2d4011-d9e8-42b6-befe-ff8a00d9df07; Mon, 08 Mar 2021 21:02:29 +0000 (UTC) Received: by mail-qt1-x82c.google.com with SMTP id r24so8632480qtt.8 for ; Mon, 08 Mar 2021 13:02:29 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:28 -0800 (PST) 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: ba2d4011-d9e8-42b6-befe-ff8a00d9df07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/v3gx4Dpg1dN3dSgA3Eor7lGHSmiomkDY5L/9HqLLB8=; b=ccptF4NoVHXSWqJNceo7Twvm2jsdZVS02K7G5ejVkRhfqJyTwyy3QgbkYvCYWy2Ma+ FSyoCOWDLdO5Ama9hIe2ZbbiA2m7Pe8hg9PrZoTu0ffmOSDFhc3oL8GGvVsq7+6yxbFd VQ+/LoyPWBvyFQCDp0XhyKJiRac1b9Mhh9EvLQsERVAqt5t7+4Wn8WwWQSHEgDtz6Yt4 AaeUHDG5FVdncGRec+rK/EHVJpCq2wz+ET4r446T76XLafR4AgXwYQSaLwQIR48iWzwN P1x6xby0t5TzqiWu0owCUYJaq+VUitEr1ZNklw61GZCkvp/4B1Y4KCz4Q9/xQYs2RZaK Tbtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/v3gx4Dpg1dN3dSgA3Eor7lGHSmiomkDY5L/9HqLLB8=; b=CwgkjeeM2Gvy0yfiiYMscCeHU4E790tl2VBFjvbae5NtEBXG7TIMQa+nkbfHv5kXTD RsFcgBsWIxiZndB4v58C1z8EmAyOxdropcdygVg7e7HJBI49+Yj+55N1OhU8Edt3ow+l 8HkIGae4ihhreQShpetm3pIW9jrWOjgzJ4VJGk8cQF3qQp3GZF7rRxzAC0fChVp+J177 NZeXdlqiSd8sy9K5OxzYSnRDPIgZLPZQB85Ry6jbvL1ippM6d5FpGA9a6VZ4vM/kJeVJ qIOwc2Quq9cPyl2liU1g/fp0n+cMgZdyUQdaBS0dBvxzQsNY+2BKwj3OdUDelkSqRRqq 6v9w== X-Gm-Message-State: AOAM5325rX+rT2AeY3/OXRI3vopjDF7pPl1Emp7mWDBcI+dMUdyK2jG1 /3dTgYaPwWB1IFhMUoAB9r5pJEh9deI= X-Google-Smtp-Source: ABdhPJzoDDpMqHHj2eLX8KAJiB9w5fKTdAodr8dsjoDTUw4POva1F7vKcpHCILY2iy2CBc2Q59O3CA== X-Received: by 2002:ac8:47c2:: with SMTP id d2mr22977294qtr.348.1615237348549; Mon, 08 Mar 2021 13:02:28 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [RFC 03/12] cpufreq: Export intel_feature_detect Date: Mon, 8 Mar 2021 16:02:01 -0500 Message-Id: <20210308210210.116278-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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 --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 4 ++-- xen/include/acpi/cpufreq/processor_perf.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 5eac2f7321..8aae9b534d 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -340,7 +340,7 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cp= u) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } =20 -static void feature_detect(void *info) +void intel_feature_detect(void *info) { struct cpufreq_policy *policy =3D info; unsigned int eax; @@ -596,7 +596,7 @@ acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) /* Check for APERF/MPERF support in hardware * also check for boost support */ if (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_level >=3D 6) - on_selected_cpus(cpumask_of(cpu), feature_detect, policy, 1); + on_selected_cpus(cpumask_of(cpu), intel_feature_detect, policy, 1); =20 /* * the first call to ->target() should result in us actually diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/processor_perf.h index d8a1ba68a6..e2c08f0e6d 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -7,6 +7,8 @@ =20 #define XEN_PX_INIT 0x80000000 =20 +void intel_feature_detect(void *info); + int powernow_cpufreq_init(void); unsigned int powernow_register_driver(void); unsigned int get_measured_perf(unsigned int cpu, unsigned int flag); --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237388; cv=none; d=zohomail.com; s=zohoarc; b=a2kCxnHHzHgJfORSpwy/kW8g1CRhklSOR2krqS30AWYRboMYQYAbSxUifqctCQenCb5Wr/ve4ksov2H9ojjUIL2KV+gAjIJ7L+lNclcb/OWkLAE0yswm7DxnaP1n86MyR6lMdg5FE2m1gALEHphRgaZmbTir4RSfzPHBR9mQ1sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237388; 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=BjEhlVDqlccH5BFquh074KTWWcfbnvlNbbrUkEKCX2E=; b=HpSAEOwr8++l/NqkuPVHNTchrkhXjtBXKV2lYq6LqcwucOOKQGfXZ+V6ckmxf+T0gB7WUkcuKD6RZO0oeVCDuxTrJZXH0rsIkgDr2OcVzJ6zrUSqA3iKkBYNdUdEHurdjfR2Jf6U7Ld3Ts/NZmG90j/AAzCwFtHaxbr07yU6oro= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237388980146.41291228360683; Mon, 8 Mar 2021 13:03:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95085.179400 (Exim 4.92) (envelope-from ) id 1lJN1Y-0006cS-3Q; Mon, 08 Mar 2021 21:02:44 +0000 Received: by outflank-mailman (output) from mailman id 95085.179400; Mon, 08 Mar 2021 21:02:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1X-0006cI-VL; Mon, 08 Mar 2021 21:02:43 +0000 Received: by outflank-mailman (input) for mailman id 95085; Mon, 08 Mar 2021 21:02:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1W-0006P0-Id for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:42 +0000 Received: from mail-qt1-x835.google.com (unknown [2607:f8b0:4864:20::835]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b82b9a90-1da7-425f-8d11-867da036625d; Mon, 08 Mar 2021 21:02:32 +0000 (UTC) Received: by mail-qt1-x835.google.com with SMTP id l14so5876405qtr.10 for ; Mon, 08 Mar 2021 13:02:32 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:30 -0800 (PST) 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: b82b9a90-1da7-425f-8d11-867da036625d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BjEhlVDqlccH5BFquh074KTWWcfbnvlNbbrUkEKCX2E=; b=C9zpkcGIjkKcQkJuirZxV8lknSTdXb9TB48gTR1ZFUf2zqkcrudQs1nWFO6zc8qtaJ AT+QHtMTcdxvYz8jvDSK7U274632PbP0nJdl8NApeStie5mL99Pw3A2V34GQ6ykhwqzP urlja47wAkAQHooJF4f31Wpg9nQm0wyQFwU+WB2TBLa9HTE5xS0OxHWiP4Jnsboc00bY zYbKAiEP+iwHa2ZGEE5D1gEc8QpqAGt7oqJ3pVZQ3Zl2fpk1fOP2qSt3nbVadtTMPCpL VXgGIuhQFKZvo40lUELmtD8krrrb4C86ceJsPLpIVQSs7pP80B76rRGbzt1q980gBsnD HiYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BjEhlVDqlccH5BFquh074KTWWcfbnvlNbbrUkEKCX2E=; b=aKItCwWGxfJcUaGbNYrs3sgBEmTbl2ZMIBP7lJvspGacp1qMlBWiHEp8jts/Zw7GnR vapt7MelYXmVHxZ3GJWnjnZlKJWlQm64ublOn6XO3irrQQ5EZdTf1iOWpkVNsa7FHNXn Re9PyK11sLK68ukvOPEaw9IhIC368tkHsNt2yLo2ocovFGMSx1QPvMEF0CBaqSlXB9/h MJ48mCyfPN7CEqOobG5RGeQGJobsdFzYhiOZjHyNBQbOn6wbwSAdNgX97pOrSZZH6b2a 2VJkMBizogOg9ub2bCuobo73PgZajlqPxGmGHpn3r+/tvwnu2rfjRmZ7AcQCFvRRj1Zv JiQQ== X-Gm-Message-State: AOAM532f55AeQ2NHrvGDUSwCK8Wxo2tK5vbFgpMQq6xgNyo8/ummZuk0 KV0r6/S02mRAjrftvQJE3pBSLZOnfPo= X-Google-Smtp-Source: ABdhPJyeTwlanill4YhFzg/NcX9IGS/uaY7Er9nhFijWUKY+H7YHyhE+Pq4TNVu/YBEjonbsvqx64w== X-Received: by 2002:a05:622a:4d3:: with SMTP id q19mr22286878qtx.316.1615237350881; Mon, 08 Mar 2021 13:02:30 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC 04/12] cpufreq: Add Hardware P-State (HWP) driver Date: Mon, 8 Mar 2021 16:02:02 -0500 Message-Id: <20210308210210.116278-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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. There is no interface to configure - it hardcodes the default 0x80 (out of 0x0-0xff) energy/performance preference. xen_sysctl_pm_op/xenpm will be to be extended to configure in subsequent patches. 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 an 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-internal, is also added as a placeholder. Signed-off-by: Jason Andryuk --- 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 averge cpufrequency output would be wrong. If HWP Energy_Performance_Preference isn't supported, the code falls back to IA32_ENERGY_PERF_BIAS. Right now, we don't check CPUID.06H:ECX.SETBH[bit 3] before using that MSR. The SDM reads like it'll be available, and I assume it was available by the time Skylake introduced HWP. 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: FAST_IA32_HWP_REQUEST not supported (XEN) HWP: Hardware Duty Cycling (HDC) supported (XEN) HWP: HW_FEEDBACK not supported So FAST_IA32_HWP_REQUEST and IA32_ENERGY_PERF_BIAS have not been tested. --- docs/misc/xen-command-line.pandoc | 9 + xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 9 +- xen/arch/x86/acpi/cpufreq/hwp.c | 533 ++++++++++++++++++++++ xen/include/acpi/cpufreq/processor_perf.h | 3 + xen/include/asm-x86/cpufeature.h | 11 +- xen/include/asm-x86/msr-index.h | 21 + 7 files changed, 583 insertions(+), 4 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 4737c92bfe..799391a5ab 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1310,6 +1310,15 @@ Specify whether guests are to be given access to phy= sical port 80 (often used for debugging purposes), to override the DMI based detection of systems known to misbehave upon accesses to that port. =20 +### hwp (x86) +> `=3D ` + +> Default: `false` + +Specifies whether Xen uses Hardware-Controlled Performance States (HWP) +on supported Intel hardware. HWP is a Skylake+ feature which provides +better CPU power management. + ### idle_latency_factor (x86) > `=3D ` =20 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 8aae9b534d..966490bda1 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -641,9 +641,12 @@ static int __init cpufreq_driver_init(void) int ret =3D 0; =20 if ((cpufreq_controller =3D=3D FREQCTL_xen) && - (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL)) - ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); - else if ((cpufreq_controller =3D=3D FREQCTL_xen) && + (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL)) { + if (hwp_available()) + ret =3D hwp_register_driver(); + else + ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); + } else if ((cpufreq_controller =3D=3D FREQCTL_xen) && (boot_cpu_data.x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON))) ret =3D powernow_register_driver(); 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..f8e6fdbd41 --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -0,0 +1,533 @@ +/* + * hwp.c cpufreq driver to run Intel Hardware P-States (HWP) + * + * Copyright (C) 2021 Jason Andryuk + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +static bool feature_hwp; +static bool feature_hwp_notification; +static bool feature_hwp_activity_window; +static bool feature_hwp_energy_perf; +static bool feature_hwp_pkg_level_ctl; +static bool feature_hwp_peci; + +static bool feature_hdc; +static bool feature_fast_msr; + +bool opt_hwp =3D true; +boolean_param("hwp", opt_hwp); + +union hwp_request +{ + struct + { + uint64_t min_perf:8; + uint64_t max_perf:8; + uint64_t desired:8; + uint64_t energy_perf:8; + uint64_t activity_window:10; + uint64_t package_control:1; + uint64_t reserved:16; + uint64_t activity_window_valid:1; + uint64_t energy_perf_valid:1; + uint64_t desired_valid:1; + uint64_t max_perf_valid:1; + uint64_t min_perf_valid:1; + }; + uint64_t raw; +}; + +struct hwp_drv_data +{ + union + { + uint64_t hwp_caps; + struct + { + uint64_t hw_highest:8; + uint64_t hw_guaranteed:8; + uint64_t hw_most_efficient:8; + uint64_t hw_lowest:8; + uint64_t hw_reserved:32; + }; + }; + union hwp_request curr_req; + uint16_t activity_window; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; +struct hwp_drv_data *hwp_drv_data[NR_CPUS]; + +#define hwp_err(...) printk(XENLOG_ERR __VA_ARGS__) +#define hwp_info(...) printk(XENLOG_INFO __VA_ARGS__) +#define hwp_verbose(...) \ +({ \ + if ( cpufreq_verbose ) \ + { \ + printk(XENLOG_DEBUG __VA_ARGS__); \ + } \ +}) +#define hwp_verbose_cont(...) \ +({ \ + if ( cpufreq_verbose ) \ + { \ + printk( __VA_ARGS__); \ + } \ +}) + +static int hwp_governor(struct cpufreq_policy *policy, + unsigned int event) +{ + int ret; + + if ( policy =3D=3D NULL ) + return -EINVAL; + + switch (event) + { + case CPUFREQ_GOV_START: + ret =3D 0; + break; + case CPUFREQ_GOV_STOP: + ret =3D -EINVAL; + break; + case CPUFREQ_GOV_LIMITS: + ret =3D 0; + break; + default: + ret =3D -EINVAL; + } + + return ret; +} + +static struct cpufreq_governor hwp_cpufreq_governor =3D +{ + .name =3D "hwp-internal", + .governor =3D hwp_governor, +}; + +static int __init cpufreq_gov_hwp_init(void) +{ + return cpufreq_register_governor(&hwp_cpufreq_governor); +} +__initcall(cpufreq_gov_hwp_init); + +bool hwp_available(void) +{ + uint32_t eax; + uint64_t val; + bool use_hwp; + + if ( boot_cpu_data.cpuid_level < CPUID_PM_LEAF ) + { + hwp_verbose("cpuid_level (%u) lacks HWP support\n", boot_cpu_data.= cpuid_level); + + return false; + } + + eax =3D cpuid_eax(CPUID_PM_LEAF); + feature_hwp =3D !!(eax & CPUID6_EAX_HWP); + feature_hwp_notification =3D !!(eax & CPUID6_EAX_HWP_Notification); + feature_hwp_activity_window =3D !!(eax & CPUID6_EAX_HWP_Activity_Windo= w); + feature_hwp_energy_perf =3D + !!(eax & CPUID6_EAX_HWP_Energy_Performance_Preference); + feature_hwp_pkg_level_ctl =3D + !!(eax & CPUID6_EAX_HWP_Package_Level_Request); + feature_hwp_peci =3D !!(eax & CPUID6_EAX_HWP_PECI); + + hwp_verbose("HWP: %d notify: %d act_window: %d energy_perf: %d pkg_lev= el: %d peci: %d\n", + feature_hwp, feature_hwp_notification, + feature_hwp_activity_window, feature_hwp_energy_perf, + feature_hwp_pkg_level_ctl, feature_hwp_peci); + + if ( !feature_hwp ) + { + hwp_verbose("Hardware does not support HWP\n"); + + 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; + } + + hwp_verbose("HWP: FAST_IA32_HWP_REQUEST %ssupported\n", + eax & CPUID6_EAX_FAST_HWP_MSR ? "" : "not "); + if ( eax & CPUID6_EAX_FAST_HWP_MSR ) + { + if ( rdmsr_safe(MSR_FAST_UNCORE_MSRS_CAPABILITY, val) ) + hwp_err("error rdmsr_safe(MSR_FAST_UNCORE_MSRS_CAPABILITY)\n"); + + hwp_verbose("HWP: MSR_FAST_UNCORE_MSRS_CAPABILITY: %016lx\n", val); + if (val & FAST_IA32_HWP_REQUEST ) + { + hwp_verbose("HWP: FAST_IA32_HWP_REQUEST MSR available\n"); + feature_fast_msr =3D true; + } + } + + feature_hdc =3D !!(eax & CPUID6_EAX_HDC); + + hwp_verbose("HWP: Hardware Duty Cycling (HDC) %ssupported\n", + feature_hdc ? "" : "not "); + + hwp_verbose("HWP: HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + use_hwp =3D feature_hwp && opt_hwp; + cpufreq_governor_internal =3D use_hwp; + + if ( use_hwp ) + hwp_info("Using HWP for cpufreq\n"); + + return use_hwp; +} + +static void hdc_set_pkg_hdc_ctl(bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_PKG_HDC_CTL, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_PKG_HDC_CTL)\n"); + + return; + } + + msr =3D val ? IA32_PKG_HDC_CTL_HDC_PKG_Enable : 0; + + if ( wrmsr_safe(MSR_IA32_PKG_HDC_CTL, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_PKG_HDC_CTL): %016lx\n", msr); +} + +static void hdc_set_pm_ctl1(bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_PM_CTL1, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_PM_CTL1)\n"); + + return; + } + + msr =3D val ? IA32_PM_CTL1_HDC_Allow_Block : 0; + + if ( wrmsr_safe(MSR_IA32_PM_CTL1, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_PM_CTL1): %016lx\n", msr); +} + +static void hwp_fast_uncore_msrs_ctl(bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_FAST_UNCORE_MSRS_CTL, msr) ) + hwp_err("error rdmsr_safe(MSR_FAST_UNCORE_MSRS_CTL)\n"); + + msr =3D val; + + if ( wrmsr_safe(MSR_FAST_UNCORE_MSRS_CTL, msr) ) + hwp_err("error wrmsr_safe(MSR_FAST_UNCORE_MSRS_CTL): %016lx\n", ms= r); +} + +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); + + /* aperf/mperf scales base. */ + 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 hwp_read_capabilities(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D hwp_drv_data[policy->cpu]; + + if ( rdmsr_safe(MSR_IA32_HWP_CAPABILITIES, data->hwp_caps) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_HWP_CAPABILITIES)\n", + policy->cpu); + + return; + } + + if ( rdmsr_safe(MSR_IA32_HWP_REQUEST, data->curr_req.raw) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_HWP_REQUEST)\n", policy-= >cpu); + + return; + } +} + +static void hwp_init_msrs(void *info) +{ + struct cpufreq_policy *policy =3D info; + 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_IA32_PM_ENABLE, val) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_PM_ENABLE)\n", policy->c= pu); + + return; + } + + hwp_verbose("CPU%u: MSR_IA32_PM_ENABLE: %016lx\n", policy->cpu, val); + if ( val !=3D IA32_PM_ENABLE_HWP_ENABLE ) + { + val =3D IA32_PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_IA32_PM_ENABLE, val) ) + hwp_err("CPU%u: error wrmsr_safe(MSR_IA32_PM_ENABLE, %lx)\n", + policy->cpu, val); + } + + hwp_read_capabilities(info); + + /* Check for APERF/MPERF support in hardware + * also check for boost/turbo support */ + intel_feature_detect(policy); + + if ( feature_hdc ) + { + hdc_set_pkg_hdc_ctl(true); + hdc_set_pm_ctl1(true); + } + + if ( feature_fast_msr ) + hwp_fast_uncore_msrs_ctl(true); + + hwp_get_cpu_speeds(policy); +} + +static int hwp_cpufreq_verify(struct cpufreq_policy *policy) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D hwp_drv_data[cpu]; + + if ( !feature_hwp_energy_perf && data->energy_perf ) + { + if ( data->energy_perf > 15 ) + { + hwp_err("energy_perf %d exceeds IA32_ENERGY_PERF_BIAS range 0-= 15\n", + data->energy_perf); + + return -EINVAL; + } + } + + if ( !feature_hwp_activity_window && data->activity_window ) + { + hwp_err("HWP activity window not supported.\n"); + + return -EINVAL; + } + + return 0; +} + +/* val 0 - highest performance, 15 - maximum energy savings */ +static void hwp_energy_perf_bias(void *info) +{ + uint64_t msr; + struct hwp_drv_data *data =3D info; + uint8_t val =3D data->energy_perf; + + ASSERT(val <=3D 15); + + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + + return; + } + + msr &=3D ~(0xf); + msr |=3D val; + + if ( wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS): %016lx\n", m= sr); +} + +static void hwp_write_request(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D hwp_drv_data[policy->cpu]; + union hwp_request hwp_req =3D data->curr_req; + + BUILD_BUG_ON(sizeof(union hwp_request) !=3D sizeof(uint64_t)); + if ( wrmsr_safe(MSR_IA32_HWP_REQUEST, hwp_req.raw) ) + { + hwp_err("CPU%u: error wrmsr_safe(MSR_IA32_HWP_REQUEST, %lx)\n", + policy->cpu, hwp_req.raw); + rdmsr_safe(MSR_IA32_HWP_REQUEST, data->curr_req.raw); + } +} + +static int hwp_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, unsigned int relat= ion) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D hwp_drv_data[cpu]; + union hwp_request hwp_req; + + /* Zero everything to ensure reserved bits are zero... */ + hwp_req.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; + if ( feature_hwp_energy_perf ) + 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.raw =3D hwp_req.raw; + + hwp_verbose("CPU%u: wrmsr HWP_REQUEST %016lx\n", cpu, hwp_req.raw); + on_selected_cpus(cpumask_of(cpu), hwp_write_request, policy, 1); + + if ( !feature_hwp_energy_perf && data->energy_perf ) + { + on_selected_cpus(cpumask_of(cpu), hwp_energy_perf_bias, + data, 1); + } + + return 0; +} + +static int hwp_cpufreq_cpu_init(struct cpufreq_policy *policy) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data; + + if ( cpufreq_opt_governor ) + { + printk(XENLOG_WARNING + "HWP: governor \"%s\" is incompatible with hwp. Using defau= lt \"%s\"\n", + cpufreq_opt_governor->name, hwp_cpufreq_governor.name); + } + policy->governor =3D &hwp_cpufreq_governor; + + data =3D xzalloc(typeof(*data)); + if ( !data ) + return -ENOMEM; + + hwp_drv_data[cpu] =3D data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + data->minimum =3D data->hw_lowest; + data->maximum =3D data->hw_highest; + data->desired =3D 0; /* default to HW autonomous */ + if ( feature_hwp_energy_perf ) + data->energy_perf =3D 0x80; + else + data->energy_perf =3D 7; + + hwp_verbose("CPU%u: IA32_HWP_CAPABILITIES: %016lx\n", cpu, data->hwp_c= aps); + + hwp_verbose("CPU%u: rdmsr HWP_REQUEST %016lx\n", cpu, data->curr_req.r= aw); + + return 0; +} + +static int hwp_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + unsigned int cpu =3D policy->cpu; + + xfree(hwp_drv_data[cpu]); + hwp_drv_data[cpu] =3D NULL; + + 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 my HWP testing. MSR_IA32_MISC_ENABLE and MISC_ENABLE_TURBO_DISENG= AGE + * is what Linux uses and seems to work. */ +static void hwp_set_misc_turbo(void *info) +{ + struct cpufreq_policy *policy =3D info; + uint64_t msr; + + if ( rdmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_MISC_ENABLE)\n", policy-= >cpu); + + 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_err("CPU%u: error wrmsr_safe(MSR_IA32_MISC_ENABLE): %016lx\n", + policy->cpu, msr); +} + +static int hwp_cpufreq_update(int cpuid, struct cpufreq_policy *policy) +{ + on_selected_cpus(cpumask_of(cpuid), hwp_set_misc_turbo, policy, 1); + + return 0; +} + +static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver =3D +{ + .name =3D "hwp-cpufreq", + .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 hwp_register_driver(void) +{ + int ret; + + ret =3D cpufreq_register_driver(&hwp_cpufreq_driver); + + return ret; +} diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/processor_perf.h index e2c08f0e6d..2e67e667e0 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -9,6 +9,9 @@ =20 void intel_feature_detect(void *info); =20 +bool hwp_available(void); +int hwp_register_driver(void); + int powernow_cpufreq_init(void); unsigned int powernow_register_driver(void); unsigned int get_measured_perf(unsigned int cpu, unsigned int flag); diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeat= ure.h index 33b2257888..1900c90f90 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -26,7 +26,16 @@ #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1 #define CPUID5_ECX_INTERRUPT_BREAK 0x2 =20 -#define CPUID_PM_LEAF 6 +#define CPUID_PM_LEAF 6 +#define CPUID6_EAX_HWP (_AC(1, U) << 7) +#define CPUID6_EAX_HWP_Notification (_AC(1, U) << 8) +#define CPUID6_EAX_HWP_Activity_Window (_AC(1, U) << 9) +#define CPUID6_EAX_HWP_Energy_Performance_Preference (_AC(1, U) << 10) +#define CPUID6_EAX_HWP_Package_Level_Request (_AC(1, U) << 11) +#define CPUID6_EAX_HDC (_AC(1, U) << 13) +#define CPUID6_EAX_HWP_PECI (_AC(1, U) << 16) +#define CPUID6_EAX_FAST_HWP_MSR (_AC(1, U) << 18) +#define CPUID6_EAX_HW_FEEDBACK (_AC(1, U) << 19) #define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 =20 /* CPUID level 0x00000001.edx */ diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-inde= x.h index 1f5a5d0e38..6f1f62c0a1 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -101,6 +101,12 @@ #define MSR_RTIT_ADDR_A(n) (0x00000580 + (n) * 2) #define MSR_RTIT_ADDR_B(n) (0x00000581 + (n) * 2) =20 +#define MSR_FAST_UNCORE_MSRS_CTL 0x00000657 +#define FAST_IA32_HWP_REQUEST_MSR_ENABLE (_AC(1, ULL) << 0) + +#define MSR_FAST_UNCORE_MSRS_CAPABILITY 0x0000065f +#define FAST_IA32_HWP_REQUEST (_AC(1, ULL) << 0) + #define MSR_U_CET 0x000006a0 #define MSR_S_CET 0x000006a2 #define CET_SHSTK_EN (_AC(1, ULL) << 0) @@ -112,10 +118,24 @@ #define MSR_PL3_SSP 0x000006a7 #define MSR_INTERRUPT_SSP_TABLE 0x000006a8 =20 +#define MSR_IA32_PM_ENABLE 0x00000770 +#define IA32_PM_ENABLE_HWP_ENABLE (_AC(1, ULL) << 0) +#define MSR_IA32_HWP_CAPABILITIES 0x00000771 +#define MSR_IA32_HWP_REQUEST_PKG 0x00000772 +#define MSR_IA32_HWP_INTERRUPT 0x00000773 +#define MSR_IA32_HWP_REQUEST 0x00000774 +#define MSR_IA32_HWP_PECI_REQUEST_INFO 0x00000775 +#define MSR_IA32_HWP_STATUS 0x00000777 + #define MSR_PASID 0x00000d93 #define PASID_PASID_MASK 0x000fffff #define PASID_VALID (_AC(1, ULL) << 31) =20 +#define MSR_IA32_PKG_HDC_CTL 0x00000db0 +#define IA32_PKG_HDC_CTL_HDC_PKG_Enable (_AC(1, ULL) << 0) +#define MSR_IA32_PM_CTL1 0x00000db1 +#define IA32_PM_CTL1_HDC_Allow_Block (_AC(1, ULL) << 0) + #define MSR_K8_VM_CR 0xc0010114 #define VM_CR_INIT_REDIRECTION (_AC(1, ULL) << 1) #define VM_CR_SVM_DISABLE (_AC(1, ULL) << 4) @@ -458,6 +478,7 @@ #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 (1ULL << 34) +#define MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE (1ULL << 38) =20 #define MSR_IA32_TSC_DEADLINE 0x000006E0 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237391; cv=none; d=zohomail.com; s=zohoarc; b=bT9lLEhkmjcroL74iMb1unKvj0BfaciFywtfnT/WzbPhVd7YyMY+t6q5je4M2IJThtqHjS42NDel+WJL8xkWEHdzeYtOSzrrpgEC1h6Huf67K0CV4EXMZgn9wv+Pe0cEv7ppyZCOaFi8qjidcabX1gPoYaRn/70Su1GYmTWBCzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237391; 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=6huQgq+uDBy8RsFCTHtfKVZpPnrSucaiZ54dJm9nYeI=; b=XwCNRzP+DjgHLcnhwp/1wVCg5Pn5TI32JledeV5lTkvNLHXd8quQxBDEAD0Dr9qqYlzE5wkfspJqKzm83fGt19/W5GJ7+NxCpVn3N3xN5ONtjgfVRK8xGStrhb5yQvSg7OVvIY8BIcI+d5BewQ7qNBehUC6KDV6g7pG30rOXxUY= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237391175603.3941670509666; Mon, 8 Mar 2021 13:03:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95087.179413 (Exim 4.92) (envelope-from ) id 1lJN1c-0006hT-LX; Mon, 08 Mar 2021 21:02:48 +0000 Received: by outflank-mailman (output) from mailman id 95087.179413; Mon, 08 Mar 2021 21:02:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1c-0006hF-FA; Mon, 08 Mar 2021 21:02:48 +0000 Received: by outflank-mailman (input) for mailman id 95087; Mon, 08 Mar 2021 21:02:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1b-0006P0-Ik for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:47 +0000 Received: from mail-qv1-xf2a.google.com (unknown [2607:f8b0:4864:20::f2a]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2f6b2bc0-98ad-43b3-96a3-15221fda3c2c; Mon, 08 Mar 2021 21:02:33 +0000 (UTC) Received: by mail-qv1-xf2a.google.com with SMTP id bh3so5340421qvb.5 for ; Mon, 08 Mar 2021 13:02:33 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:32 -0800 (PST) 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: 2f6b2bc0-98ad-43b3-96a3-15221fda3c2c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6huQgq+uDBy8RsFCTHtfKVZpPnrSucaiZ54dJm9nYeI=; b=Wer6nEDWVkndnvRNgmg4aC8u7FVAcjtZrQLpcbsl3hJ35DWgsPWJKkpRtbyqW2AI71 n3LIDHqn5I6EFGOnAUKMYmr+rsIt08MZ+YcwWvfgRK/Z3UemUKq6S2gHGJWKcYiN+CsF +DjBDXyrr4CVPBKMAoUW5BIMbsrdakM0JhNGiSvIrztIfR89SjEBCHC8Flvofy3Sen2j EqQqIcYFLcmsfUVz6R3kJ6uP081YIti9XfTdTnnKuArSJk82tK21zlJ9tr1/Yn6xbLP2 bWm6qkA5ig+AcpzdnRCC7BJxFL5jV6cgInMLTZ+UNCAydqlI7zdzHCgw7ZHshwAGFcnx 55bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6huQgq+uDBy8RsFCTHtfKVZpPnrSucaiZ54dJm9nYeI=; b=iYr+t2pLqBz4+E4kRJp2k2KiW/0V9WldR1lBtYQCNJ1d+zbrgv8LpglQ2OTGWG/jsn Gq8nNE9KhN0TyzfEGchJQ+X6NrZ/lJ5Z5uoBXy6oArEHrv9Htc0UnBiECxrwAJO73ZtY Kk+ldsnTnZlOPbRPchp3AZHHSquwsmZ/PE81ZaH0ISjicbA/92q9Hl7YgTbdC4eVGKyD +8RGId8q2WWn1UrKCgsvLKvt2EsXEek1MIE3W8UMV/ygMTWpM58buytRL/ve+lrirSwZ VdpTXgLkGCRZLYzG7iLsCZtPUUEVP96hqvaR2Ng8H9HhfQQTByJUW8uP0jPxOtd4lhbY AhbQ== X-Gm-Message-State: AOAM530NHUmdZqkkRrvrysxmOwmpVkjr0Sh/GuoN3raH3eLXactGitSO Bf7Q8GDS3Ygo2t4HSAYzUTo13jtMwr4= X-Google-Smtp-Source: ABdhPJymVRcoQcyP0VqxqnyZsYHb3fWy4qxlrGF/d0o2piukAVzC1HJEvx3QPp+D8QBGx6qRVmTDqA== X-Received: by 2002:a0c:f702:: with SMTP id w2mr776977qvn.0.1615237352617; Mon, 08 Mar 2021 13:02:32 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 05/12] xenpm: Change get-cpufreq-para output for internal Date: Mon, 8 Mar 2021 16:02:03 -0500 Message-Id: <20210308210210.116278-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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 turbo frequencies since those are relevant to HWP. Similarly, stop printing the CPU frequencies since those do not apply. Signed-off-by: Jason Andryuk --- tools/misc/xenpm.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index d0191d4984..35223b98df 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 internal =3D strstr(p_cpufreq->scaling_governor, "internal"); int i; =20 printf("cpu id : %d\n", cpuid); @@ -720,10 +721,19 @@ 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 (internal) + { + printf("cpuinfo frequency : base [%u] turbo [%u]\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 @@ -750,19 +760,22 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) p_cpufreq->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 ) - printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); - else - printf(" %d", p_cpufreq->scaling_available_frequencies[i]); - printf("\n"); + if (!internal) + { + 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 ) + 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); + 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); + } =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237395; cv=none; d=zohomail.com; s=zohoarc; b=epKjmlxgDqlZbWOqlef9CZqGx6aM4Ci1qca91fLyca7GATi1Plb8NCMARrtKsABKg9j+ZrcyCAuBPBGg7bM0PuhVRgDJ59jCQmUS6dI0L+RDXbhBEy3sb15OddcpVHjngUmKa08quo6fz6TDbSAuBLyTBsuYstpgegXTtmrRoGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237395; 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=URsm1yOuvp1SQ/7X/KtWhiPzCJKRQEYt//4KlQf0Bnc=; b=XDTov3//EP7GGHGvPqja8yD4ivqS3mArdNGzPjo+OrOj3936wvuA/2pzisIWpHNu2MlAmBZHbDRBnWZkXXCGRTnyLv9TFN5tLiQY0D/Wk2JcFU9bCdiljfyfoX4DrSvCNYJZmaoELe7NIA8gFVIWb5Atkba9esd0iA9FWtkwJM8= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237395929188.70487678128575; Mon, 8 Mar 2021 13:03:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95089.179424 (Exim 4.92) (envelope-from ) id 1lJN1h-0006mc-UT; Mon, 08 Mar 2021 21:02:53 +0000 Received: by outflank-mailman (output) from mailman id 95089.179424; Mon, 08 Mar 2021 21:02:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1h-0006mV-Qi; Mon, 08 Mar 2021 21:02:53 +0000 Received: by outflank-mailman (input) for mailman id 95089; Mon, 08 Mar 2021 21:02:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1g-0006P0-J2 for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:52 +0000 Received: from mail-qk1-x731.google.com (unknown [2607:f8b0:4864:20::731]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 16c4f119-6cfd-4363-b387-aa9243d33cb4; Mon, 08 Mar 2021 21:02:35 +0000 (UTC) Received: by mail-qk1-x731.google.com with SMTP id l4so10891012qkl.0 for ; Mon, 08 Mar 2021 13:02:35 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:34 -0800 (PST) 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: 16c4f119-6cfd-4363-b387-aa9243d33cb4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=URsm1yOuvp1SQ/7X/KtWhiPzCJKRQEYt//4KlQf0Bnc=; b=eDfuLm1Hvfmvh4pBO+nYR/75TocdTJ81qDRPc7rGYnK8fud2auS2N7XRHOPTk5bg91 6lHO9sYXeVZHQVs/D8e9FWR8IXB3hnUGOsAbNWBZkAJGHRpR2mEilLasmdpjLHQ6F35S gVpqLT0oCysUoOtLQi4OY2LCdE8moGlCKa2vhm4osNA/kpRyHvfqCSoB6v5DVoZDIB7x vEowajRT3a7ztF7YGdFvX+FM9LOB3ARPEapGC5tvTjnEtdA/l2xSX4cxT1+d/aouXE0v WRTo+ZfgTev9qwuY9ZEP5fQMZuUT//H367YyICw9Ue0yEqfFuHmbzNZfn3bHgOWKcalg /hMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=URsm1yOuvp1SQ/7X/KtWhiPzCJKRQEYt//4KlQf0Bnc=; b=pdgkwC2z5g9Xynns4qxum7US5xrYhOMfmw6jrWn5z72jDPziPMX1EaAhBtDfI2NHCx 6vLo59chi6V/VzBj/Y+CmP3ltIjoJ2CPDFw9mh0SkdsAlYy3GWmASl9Pl/XkQMHqcJsh LS7hlvqvBnWH77hRuNLLfPY3Dj74q6vrqPJQPazQMdUzDbzNnez0DK4IBAmoPLJDpQx8 47P1WcQiiOlxuScSvwNsXHdPkt441cGQzIdLwbek4G8q/m3Zc80jgtaiirPov4uXKVZc XRenVxsesJIf8zid5hv7moWzF85nVRcOHd6ZQM565mJQegBryFBSohGr7tJCPs4uRKz0 gb8A== X-Gm-Message-State: AOAM531TcIggsYNrz7aFQP+6W49/su/u6Vm/aOwt08NzXT9Txq3dLjTl A0AVeAB1yJlaEfeLditG0kk9TkHg0UQ= X-Google-Smtp-Source: ABdhPJy5hyPJly4pN5b+0G4ry9ay0NRrqf8uwMD/OcP5ZVaVBeGf/cvkzt//bzPRlZYop2dmt/enOg== X-Received: by 2002:a37:8506:: with SMTP id h6mr22178160qkd.134.1615237354971; Mon, 08 Mar 2021 13:02:34 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini Subject: [RFC 06/12] cpufreq: Export HWP parameters to userspace Date: Mon, 8 Mar 2021 16:02:04 -0500 Message-Id: <20210308210210.116278-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Extend xen_get_cpufreq_para to return hwp parameters. These match the hardware rather closely. We need the hw_features bitmask to indicated fields supported by the actual hardware. The use of uint8_t parameters matches the hardware size. uint32_t entries grows the sysctl_t past the build assertion in setup.c. The uint8_t ranges are supported across multiple generations, so hopefully they won't change. Increment XEN_SYSCTL_INTERFACE_VERSION for the new fields. Signed-off-by: Jason Andryuk --- xen/arch/x86/acpi/cpufreq/hwp.c | 24 ++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 6 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 3 +++ xen/include/public/sysctl.h | 20 +++++++++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index f8e6fdbd41..92222d6d85 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -523,6 +523,30 @@ static const struct cpufreq_driver __initconstrel hwp_= cpufreq_driver =3D .update =3D hwp_cpufreq_update, }; =20 +int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_p= ara) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D hwp_drv_data[cpu]; + + if ( data =3D=3D NULL ) + return -EINVAL; + + hwp_para->hw_feature =3D + feature_hwp_activity_window ? XEN_SYSCTL_HWP_FEAT_ACT_WINDOW : 0 | + feature_hwp_energy_perf ? XEN_SYSCTL_HWP_FEAT_ENERGY_PERF : 0; + hwp_para->hw_lowest =3D data->hw_lowest; + hwp_para->hw_most_efficient =3D data->hw_most_efficient; + hwp_para->hw_guaranteed =3D data->hw_guaranteed; + hwp_para->hw_highest =3D data->hw_highest; + hwp_para->minimum =3D data->minimum; + hwp_para->maximum =3D data->maximum; + hwp_para->energy_perf =3D data->energy_perf; + hwp_para->activity_window =3D data->activity_window; + hwp_para->desired =3D data->desired; + + return 0; +} + int hwp_register_driver(void) { int ret; diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 2f528f9ca3..4c6ae5d768 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -290,6 +290,12 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *o= p) &op->u.get_para.u.ondemand.sampling_rate, &op->u.get_para.u.ondemand.up_threshold); } + + if ( !strnicmp(op->u.get_para.scaling_governor, + "hwp-internal", CPUFREQ_NAME_LEN) ) + { + ret =3D get_hwp_para(policy, &op->u.get_para.u.hwp_para); + } op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); =20 return ret; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index b91859ce5d..42146ca2cf 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -246,4 +246,7 @@ int write_userspace_scaling_setspeed(unsigned int cpu, = unsigned int freq); void cpufreq_dbs_timer_suspend(void); void cpufreq_dbs_timer_resume(void); =20 +/********************** hwp hypercall helper *************************/ +int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_p= ara); + #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 039ccf885c..1a6c6397ea 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -35,7 +35,7 @@ #include "domctl.h" #include "physdev.h" =20 -#define XEN_SYSCTL_INTERFACE_VERSION 0x00000013 +#define XEN_SYSCTL_INTERFACE_VERSION 0x00000014 =20 /* * Read console content from Xen buffer ring. @@ -301,6 +301,23 @@ struct xen_ondemand { uint32_t up_threshold; }; =20 +struct xen_hwp_para { + uint16_t activity_window; /* 7bit mantissa and 3bit exponent */ +#define XEN_SYSCTL_HWP_FEAT_ENERGY_PERF (1 << 0) /* energy_perf range 0-25= 5 if + 1. Otherwise 0-15 */ +#define XEN_SYSCTL_HWP_FEAT_ACT_WINDOW (1 << 1) /* activity_window suppor= ted + if 1 */ + uint8_t hw_feature; /* bit flags for features */ + uint8_t hw_lowest; + uint8_t hw_most_efficient; + uint8_t hw_guaranteed; + uint8_t hw_highest; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; + /* * cpufreq para name of this structure named * same as sysfs file name of native linux @@ -332,6 +349,7 @@ struct xen_get_cpufreq_para { union { struct xen_userspace userspace; struct xen_ondemand ondemand; + struct xen_hwp_para hwp_para; } u; =20 int32_t turbo_enabled; --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237396; cv=none; d=zohomail.com; s=zohoarc; b=I5UfEd+5JwKYVXiLy7KoapP2w2HT6y3dkjfXkkVqyh0tU/EICZNNRDMFtVqvdb13NgUokvvlwavS67M75zg7QDKvvqBNPi7GOyPjtMfcEUKUGbhFC7yTqE9J+sbhu3rjWEnT82EJoAg3M8+AgdCpZH7JoUxpkSBQPHwVwGyDVTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237396; 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=m/HjIThexqCtGTUE+J7vbjJvC1aFn2t5c5WE3e2oBTE=; b=kv8aGZPHX/DHobp/uP/aQS3s4p0j4qcDq5yLFbyxI21U8/pDd/6rFfzXBdI3w5qgbGhgDLTcOb1sD+aETMFiD4ifs9VerQO9NN/FxlnT/G2dlOZmsGjK5HXMlpB0lk0Q7fyWZ8+68/tgaJ2AoEvFuI+LDKDR0rUEI2fLpPWk4lg= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237396716623.8202266778824; Mon, 8 Mar 2021 13:03:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95091.179436 (Exim 4.92) (envelope-from ) id 1lJN1n-0006si-91; Mon, 08 Mar 2021 21:02:59 +0000 Received: by outflank-mailman (output) from mailman id 95091.179436; Mon, 08 Mar 2021 21:02:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1n-0006sZ-4k; Mon, 08 Mar 2021 21:02:59 +0000 Received: by outflank-mailman (input) for mailman id 95091; Mon, 08 Mar 2021 21:02:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1l-0006P0-JQ for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:02:57 +0000 Received: from mail-qk1-x72d.google.com (unknown [2607:f8b0:4864:20::72d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 929150ee-f530-4c37-ad0d-a0a8ea0316b0; Mon, 08 Mar 2021 21:02:37 +0000 (UTC) Received: by mail-qk1-x72d.google.com with SMTP id 130so10828068qkh.11 for ; Mon, 08 Mar 2021 13:02:37 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:36 -0800 (PST) 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: 929150ee-f530-4c37-ad0d-a0a8ea0316b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m/HjIThexqCtGTUE+J7vbjJvC1aFn2t5c5WE3e2oBTE=; b=RCFeNNKi1ZTNaOrIH4J6hj0WjaDml4hOia1YsYTeDXpZWZgN3fsTxvQw3oqU/Uvrxz qpUwpr7j/lnAx4i4nyocPCEU8L3y4WEv9yNS3377HUzVyEGz74+iRb4bMcMcEtFxApQo T14Jd0et8eK22NKvxjPr3FleW6fSp0afabP/vqn+OdJNQDqlyQXqOIE+otd36j6aArpo nrNAr7GU7pGXQ43Hf7anyVoFCzPJUO8aRsOScTPDYxBCpF3go9lth0s7A2P7AlLsjlNi l58BHWsF+FAwUpUOmLaNlQ4lVApDr543D+N65LmsEX/Esl3f+gfKRN6OUBeeLjBxApXk p/0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m/HjIThexqCtGTUE+J7vbjJvC1aFn2t5c5WE3e2oBTE=; b=NlYocIUWStr7R/iGzPJYMlIX3acpRmZmBK8904rVA3t4IgDEgwIgkvbSg/qC3KK6uw n2b08Gh5rM+hZYyr451HRLokcOgCOAuaerQaHFgxy8jkNQTJr8b0qqocbW19YLsJycuF L6WNSPLSml05onl3V3pBSG96dzBQWf4YD4P70fdcHnvaZ0I7unMqerLXk045kiF9G1AX ZWs+sgmGFYXWkShrwmW5QlLux7QSb2s22SAMEyGc6jLh+LWth3JW02IItRbruaYIqHoJ 9G50VA+3zW0pYEZKD1PM67+ZtpQ9vTcQ8mb9VAlM5w7Dzo4codHODkC7+v+DS9rWI6cu wiBA== X-Gm-Message-State: AOAM530NVqYJqSh/GkKUSgZqDk10L1inW/DoOaYqjW0UFRE+RymEM+Qz CDIZvY1sogZrxrIk2J0ulPtUgSkyQe0= X-Google-Smtp-Source: ABdhPJxrrXBf/RUi4dQsnOrnyYQBD4xXTzxBGfDL8KwuxbIZxjqMfhGYeXkknf0j6C+U4kUtqIJGmA== X-Received: by 2002:a37:86c5:: with SMTP id i188mr23385057qkd.325.1615237357093; Mon, 08 Mar 2021 13:02:37 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 07/12] libxc: Include hwp_para in definitions Date: Mon, 8 Mar 2021 16:02:05 -0500 Message-Id: <20210308210210.116278-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Expose the hwp_para fields through libxc. Signed-off-by: Jason Andryuk --- tools/include/xenctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 318920166c..3b0ca62fc7 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1960,6 +1960,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_hwp_para xc_hwp_para_t; =20 struct xc_get_cpufreq_para { /* IN/OUT variable */ @@ -1987,6 +1988,7 @@ struct xc_get_cpufreq_para { union { xc_userspace_t userspace; xc_ondemand_t ondemand; + xc_hwp_para_t hwp_para; } u; =20 int32_t turbo_enabled; --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237396; cv=none; d=zohomail.com; s=zohoarc; b=RB0f/XbZWglcuhzSIvzdy7Rv6BFBa6k0EX/xMw2sRpeBX7SLt9MiZLgur6mZ7k3XkpX0T9FmoRffCTwyZ5F8PKKSuI8EnJ9vrIJZwuCs0yKBXiGYECmkHPvwZH4ts8Z5JbWYBEZVJO5FGsvkyd9wFfp9jzDEBYQpjGOEXZBPvWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237396; 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=N7yhEOqzJ0+x+JlQs3Sjsvl85JThC2zfENNxFodtLhk=; b=mcWigF2QaPAd0GAOihkMRJ4I9eIw1PgZOEK5u/Ex8F0pj900s9fzzqT43DKWUwcuLAnKEQ4SZ8G/B3aB88WDTS++OyC0SbMvLjew+kIJ665RU/7d1nQ8G9f9WrZUjok/vs+2OBik/fqebAasuBEiiLFIf7BpLDidb1wAcUL2Yvg= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237396905622.5983124330984; Mon, 8 Mar 2021 13:03:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95093.179448 (Exim 4.92) (envelope-from ) id 1lJN1s-0006yX-OD; Mon, 08 Mar 2021 21:03:04 +0000 Received: by outflank-mailman (output) from mailman id 95093.179448; Mon, 08 Mar 2021 21:03: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 1lJN1s-0006yB-Ho; Mon, 08 Mar 2021 21:03:04 +0000 Received: by outflank-mailman (input) for mailman id 95093; Mon, 08 Mar 2021 21:03:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1q-0006P0-JW for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:02 +0000 Received: from mail-qt1-x829.google.com (unknown [2607:f8b0:4864:20::829]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id af455b62-6776-4542-b122-5dd34a88e29a; Mon, 08 Mar 2021 21:02:39 +0000 (UTC) Received: by mail-qt1-x829.google.com with SMTP id d11so8625308qtx.9 for ; Mon, 08 Mar 2021 13:02:39 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:38 -0800 (PST) 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: af455b62-6776-4542-b122-5dd34a88e29a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N7yhEOqzJ0+x+JlQs3Sjsvl85JThC2zfENNxFodtLhk=; b=XwM+qLg2re6gp7d448+Z4XdF/EiedVpR0jSynMw3g0qTHhS+Schv8AjGvL+oKpNBcs aEEDdUOtQqtTmnZou2IGTaWScV60rmV3M77Qi4OzeRe5pbz4+3r14j2xh4/ZD9A8M/if pYeBWXijdo3EIVNXKgw1UhHD3YYZJ4iRqcLCl/kKogzReEEQDFU2MfLzprkBCslk1Hwh u7XytJhJSDyx36+Wq6c2Da+mdBXEh+CMID5qDo9/aqpzGx2p5pkUsAvZqHgYGNJvWcxn 3Rrv1pT6jaSyFusmAzGA8N5fuw93FhJBQcvztMZeP5ZS2Cp71fkluy6xbYy4jeYrpiWn IwKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N7yhEOqzJ0+x+JlQs3Sjsvl85JThC2zfENNxFodtLhk=; b=RiHfa1JTGh2w71SVvqDmoYYSL8GrhtlOwV4ZKUZQKs3VHpiBx+QtJPGKNwsNDD/4Ye HbB7Vqn3A8685P5OE3vsn5769Rp6ETIBFNsMNJWhuTN76HDsztu6znLtKTTRXHOg3kEa cS9d0GWmP5vXebkW8hIxzRNDdwys9AzH3oSINR3hQOA5ohW9UwQoZANy6quleycc0/y0 /AyGZs7EvMYVLBwP9pZAW++TnrNmPYST7NeOtZzAEFHtD0AZJOGsM3PrAjWu0TDfF9GU iuJHrgueeXrzeAwg3qPw2maKdX+xPRZjUuzEMlAwpijdx407LJHaDo+YbpTceW+uBq/D bA3Q== X-Gm-Message-State: AOAM532J+447TjJFohYC2dUPkZMr0eHFgRj9SBfr5R5rZZWlu7Ofn2s2 /sdscRf3ByU3mj1Wj0A68MnN1z1kJrM= X-Google-Smtp-Source: ABdhPJwf/dEzlun0+1V5RJMcQcxl6otvf+cIsUSOblP40ak/2X+oSRlaOUr+jhESxrlKhl+kVu61eg== X-Received: by 2002:ac8:6988:: with SMTP id o8mr22523226qtq.24.1615237358791; Mon, 08 Mar 2021 13:02:38 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 08/12] xenpm: Print HWP parameters Date: Mon, 8 Mar 2021 16:02:06 -0500 Message-Id: <20210308210210.116278-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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 --- tools/misc/xenpm.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 35223b98df..9588dac991 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -708,6 +708,43 @@ void start_gather_func(int argc, char *argv[]) pause(); } =20 +static void calculate_hwp_activity_window(const xc_hwp_para_t *hwp, + unsigned int *activity_window, + const char **units) +{ + unsigned int mantissa =3D hwp->activity_window & 0x7f; + unsigned int exponent =3D ( hwp->activity_window >> 7 ) & 0x7; + unsigned int multiplier =3D 1; + + if ( hwp->activity_window =3D=3D 0 ) + { + *units =3D "hardware selected"; + *activity_window =3D 0; + + return; + } + + 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 ( unsigned int i =3D 0; i < exponent; i++ ) + multiplier *=3D 10; + + *activity_window =3D mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { @@ -721,7 +758,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get= _cpufreq_para *p_cpufreq) printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); =20 - if (internal) + if ( internal ) { printf("cpuinfo frequency : base [%u] turbo [%u]\n", p_cpufreq->cpuinfo_min_freq, @@ -760,7 +797,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get= _cpufreq_para *p_cpufreq) p_cpufreq->u.ondemand.up_threshold); } =20 - if (!internal) + if ( !internal ) { printf("scaling_avail_freq :"); for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) @@ -777,6 +814,40 @@ static void print_cpufreq_para(int cpuid, struct xc_ge= t_cpufreq_para *p_cpufreq) p_cpufreq->scaling_cur_freq); } =20 + if ( strcmp(p_cpufreq->scaling_governor, "hwp-internal") =3D=3D 0 ) + { + const xc_hwp_para_t *hwp =3D &p_cpufreq->u.hwp_para; + + printf("hwp variables :\n"); + printf(" hardware limits : lowest [%u] most_efficient [%u]\n", + hwp->hw_lowest, hwp->hw_most_efficient); + printf(" hardware limits : guaranteed [%u] highest [%u]\n", + hwp->hw_guaranteed, hwp->hw_highest); + printf(" configured limits : min [%u] max [%u] energy_perf [%u]\= n", + hwp->minimum, hwp->maximum, hwp->energy_perf); + + if ( hwp->hw_feature & XEN_SYSCTL_HWP_FEAT_ENERGY_PERF ) + { + printf(" configured limits : energy_perf [%u%s]\n", + hwp->energy_perf, + hwp->energy_perf ? "" : " hw autonomous"); + } + + if ( hwp->hw_feature & XEN_SYSCTL_HWP_FEAT_ACT_WINDOW ) + { + unsigned int activity_window; + const char *units; + + calculate_hwp_activity_window(hwp, &activity_window, &units); + printf(" configured limits : activity_window [%u %s]\n", + activity_window, units); + } + + printf(" configured limits : desired [%u%s]\n", + hwp->desired, + hwp->desired ? "" : " hw autonomous"); + } + printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); printf("\n"); --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237400; cv=none; d=zohomail.com; s=zohoarc; b=Yg7Sf4O3pCZ35koNOM0QCAUR71w1EnRd6PNY2oXoET/s9imYu67KBprgjaNFJSeDpnejDe1BAysJ1sEWliIAjUyWibWvrUJwGUfAdyvtsXR3H8RWyTSSIro4KV4daL+i+6+ZRpdH7ce8QXBRo98zr+iZA8fgVsW+m2ga7zyKwbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237400; 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=oqpttayW0aZRbW0lV0dPSojE1v4QDHZLq85y9vWsmqg=; b=nualjIt3czi+lR6TwDFC6uuepRiWglFmnqIA78jhkpJSUNlNkaYIC269j9kNWpIkU/nqDccU2YiPm6ajnKed8THtF/nB2VJaoPvOrXc4cDi2I5AP0iapELSbgfjRm3sbQ0ODKKOmWN2SVI4PJikbeRhw/x4ee08kRBfYYFQeG2U= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237400867721.1188352841949; Mon, 8 Mar 2021 13:03:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95095.179460 (Exim 4.92) (envelope-from ) id 1lJN1x-00073i-1k; Mon, 08 Mar 2021 21:03:09 +0000 Received: by outflank-mailman (output) from mailman id 95095.179460; Mon, 08 Mar 2021 21:03:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1w-00073W-Tq; Mon, 08 Mar 2021 21:03:08 +0000 Received: by outflank-mailman (input) for mailman id 95095; Mon, 08 Mar 2021 21:03:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN1v-0006P0-Ja for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:07 +0000 Received: from mail-qk1-x734.google.com (unknown [2607:f8b0:4864:20::734]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 29c4ded8-0d52-4eb0-bfdd-c476ea12c676; Mon, 08 Mar 2021 21:02:41 +0000 (UTC) Received: by mail-qk1-x734.google.com with SMTP id n79so10866761qke.3 for ; Mon, 08 Mar 2021 13:02:41 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:40 -0800 (PST) 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: 29c4ded8-0d52-4eb0-bfdd-c476ea12c676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oqpttayW0aZRbW0lV0dPSojE1v4QDHZLq85y9vWsmqg=; b=UGXM5D94i40l2yF+567mUWT4APPSKuPbrSXJMkZg5BuwjlTOivLZV1fz9bTrNSSvgG Y8V2o1+yEKAer5QYuFyKFlNTGr6vF0XNtjWCpUvFED2sKYG8aeGFnd3sM7HVzlsHeLFe oJ8ianhNT27nrsSspcoW72aLFh8qeMG9LRK0szHmMUFoX3+Lq/GmY2yXQabpXvitgLzd LE0qBvkIcivh+TrHpbIXFCkNYViEraua5Z8FFMUBuBkC/CT08KmY3rq9AQwBHsCfSoAv 23IoIAimOcZBvsS7CGM86b6Y1A3tJmcQwA44/b9KkQLXSBYonkp3glBlzJx0V+ni6TZw Q5rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oqpttayW0aZRbW0lV0dPSojE1v4QDHZLq85y9vWsmqg=; b=EmDn2PmUx9+2q0ssbdSrpQb5SxkaEdnZriJWF97yXKz6Gi1biHXdMmZJYzLTjdafgz V0csgLAeQ5+eVOHzN4zTz4P3GErMkmC4kvXIrIdUHYC0WBsMJ8R1wCrThipEXD4dF1zt IzjNiNt102/NOh2AL/fqeU9Gc6GMHXgpi3JAOCLRls6fZxY7qowblMRretyEQmqL0atF wMpp3Qi5wtQo5XfxLyUMgVHavpt71vupuGIDriMcK+gWQSbAcLjFMQxlLXCz/xrxmeJ6 /7fXRB3s34apV//ZX/WIMEJBMs1cFmF9XUdJHamzvfElTTxnM3MlC6wCFXheE5vgdk6u ELPQ== X-Gm-Message-State: AOAM530SL2IdIjD4x/h/z+26AhcEwTt7g0/hw1Left7cn3DFRohrBInt yPNdn6t83HA8QKjpHhPew11iT2hFDhE= X-Google-Smtp-Source: ABdhPJyqwDLmfPxTONGiGVA9Gikx8JwFOaXo2DpQOeXb59DhjVX/AiDXt98uOkdo6jfnCJ6vkD0SzA== X-Received: by 2002:a37:a8cd:: with SMTP id r196mr21870295qke.451.1615237361005; Mon, 08 Mar 2021 13:02:41 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 09/12] xenpm: Factor out a non-fatal cpuid_parse variant Date: Mon, 8 Mar 2021 16:02:07 -0500 Message-Id: <20210308210210.116278-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Allow cpuid_prase to be re-used without terminating xenpm. HWP will re-use it to optionally parse a cpuid. Signed-off-by: Jason Andryuk --- tools/misc/xenpm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 9588dac991..a686f8f46e 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -79,17 +79,26 @@ void help_func(int argc, char *argv[]) show_help(); } =20 -static void parse_cpuid(const char *arg, int *cpuid) +static int parse_cpuid_non_fatal(const char *arg, int *cpuid) { if ( sscanf(arg, "%d", cpuid) !=3D 1 || *cpuid < 0 ) { if ( strcasecmp(arg, "all") ) - { - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); - exit(EINVAL); - } + return -1; + *cpuid =3D -1; } + + return 0; +} + +static void parse_cpuid(const char *arg, int *cpuid) +{ + if ( parse_cpuid_non_fatal(arg, cpuid) ) + { + fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); + exit(EINVAL); + } } =20 static void parse_cpuid_and_int(int argc, char *argv[], --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237687; cv=none; d=zohomail.com; s=zohoarc; b=JPpOKomaHFRxtuc7o+fqCHm8zuCjUv9gczYWlgcGtkz8oCxv1oHLVi+lEsX8cJFCBMJZ6QJf0mcE0bNHaLTmJkSjnqocnIwzeAFvuWm85o7+Swum16bbCTa6Ts/EizKVlTUkJmrX10MCIAJLSXyYnzge08e2TAWhsPHi2Qk9f7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237687; 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=DENgrNRtv6VqhXdN7bwMgqWd+ZEOEb0cKD59zRjtD8M=; b=g3Hke2BlgH/cF0BN3OnwPkhRm/HqtN99ZXbHxvJHtCfluYz9OaF/nVokvXD5oNYORcXS0z+RXdyanKX5i5gxCv+AZACR36x/kE7i+UnykBwkuMp8ND2nfk1bi5qRUzvwcUZCJPFi22XEMs1A4yYC1zhKPrVqmydK6u1rAq12BbA= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237687807384.9571200552548; Mon, 8 Mar 2021 13:08:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95113.179490 (Exim 4.92) (envelope-from ) id 1lJN6W-0007eB-Kf; Mon, 08 Mar 2021 21:07:52 +0000 Received: by outflank-mailman (output) from mailman id 95113.179490; Mon, 08 Mar 2021 21:07:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN6W-0007dw-DW; Mon, 08 Mar 2021 21:07:52 +0000 Received: by outflank-mailman (input) for mailman id 95113; Mon, 08 Mar 2021 21:07:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN20-0006P0-Ji for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:12 +0000 Received: from mail-qk1-x736.google.com (unknown [2607:f8b0:4864:20::736]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9253dcf0-30d1-406f-9ad7-c76617ddff7d; Mon, 08 Mar 2021 21:02:43 +0000 (UTC) Received: by mail-qk1-x736.google.com with SMTP id x10so10850799qkm.8 for ; Mon, 08 Mar 2021 13:02:43 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:42 -0800 (PST) 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: 9253dcf0-30d1-406f-9ad7-c76617ddff7d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DENgrNRtv6VqhXdN7bwMgqWd+ZEOEb0cKD59zRjtD8M=; b=UczG4KIoK8rcZkEfAoJEDFB67oT1oBpn6mPTCGAyPZXQMNzbEb16A1xG0qFl81ZfIz dMJKQYrPmnzILSVKr+TQyog/AY1R45POo24dsDz6giY7R/V/q02y35+5bQIGtnFX9/WD 83f8GtB71PPeqwHV7+Q3ReC33EEbgpmgyLN+KrajYRqorIlpOok8CMOpvFnJb/Cdk/i/ DyqAI98bZg/gqWEkjQpyyxf7wckb2UAEKFDGJHYqhacm3KvL5wnE8APYkX9ZaEX5h9uv kNp4Lz+DqmS449E5VXiNl0XOghIlhZoREn5hLwPKKYd5VTpwIWb9V72F20o6+dEKZZJE Hq9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DENgrNRtv6VqhXdN7bwMgqWd+ZEOEb0cKD59zRjtD8M=; b=cwurFsj3NJi0cCkqebxuwZfu4SbUk+4ccxFiV3CoKYIA1toy6iw1yp1NBT8E7dusFU 5AZsb++X6dl7iLOtfuKtwYkLBylqF4ol5wP72TmtwWiGWx3V5dsZZ0D1JTUSTo3k+22W I8oV/nbjfJ+8aanQN0EXGRzkXfH7P7lFuWB5MtIdSJBpe5HfoSA6flJKcrpYb8wLehu4 /4Ms4EOD/nTvWnpr+/ZxUXNv3ZvUyOmnfq1PfIzhc7BnEeTJNlFn0P0k1KhVDfcbXJu8 xyARW2/iBmYnaAoqBzzjJ+tsUTXQjSUBv8rpVAfw3ZpAlUT+t2gOgJxC9WoWgu3B0A+b dJsg== X-Gm-Message-State: AOAM533mEBVq298cwqVr93BE11z4/2jPYFDByr5WLSa7wmUTciXR333S gbx2xrP98dsPt274yFVRk6SbX3nbds4= X-Google-Smtp-Source: ABdhPJx3VChIdkS3wbpj2fKyih2E+kGuiwMbtNbLUgGeP4mAR/bBwF0IIsD8dvTOIbaN9Aj+Hn22jg== X-Received: by 2002:a05:620a:41:: with SMTP id t1mr22741875qkt.322.1615237362911; Mon, 08 Mar 2021 13:02:42 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini Subject: [RFC 10/12] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op Date: Mon, 8 Mar 2021 16:02:08 -0500 Message-Id: <20210308210210.116278-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) 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 (hw_lowest/highest) to then set those same values. The code is organized to allow a preset to be refined with additional stuff 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. Signed-off-by: Jason Andryuk --- xen/arch/x86/acpi/cpufreq/hwp.c | 113 +++++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 24 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 32 ++++++++ 4 files changed, 171 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 92222d6d85..8f4b18d246 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -547,6 +547,119 @@ int get_hwp_para(struct cpufreq_policy *policy, struc= t xen_hwp_para *hwp_para) return 0; } =20 +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D hwp_drv_data[cpu]; + + if ( data =3D=3D NULL ) + return -EINVAL; + + /* Validate all parameters first */ + if ( set_hwp->set_params & ~XEN_SYSCTL_HWP_SET_PARAM_MASK ) + { + hwp_err("Invalid bits in hwp set_params %u\n", + set_hwp->set_params); + + return -EINVAL; + } + + if ( set_hwp->activity_window & ~XEN_SYSCTL_HWP_ACT_WINDOW_MASK ) + { + hwp_err("Invalid bits in activity window %u\n", + set_hwp->activity_window); + + return -EINVAL; + } + + if ( !feature_hwp_energy_perf && + set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF && + set_hwp->energy_perf > 0xf ) + { + hwp_err("energy_perf %u out of range for IA32_ENERGY_PERF_BIAS\n", + set_hwp->energy_perf); + + return -EINVAL; + } + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED && + ( set_hwp->desired < data->hw_lowest || + set_hwp->desired > data->hw_highest ) ) + { + hwp_err("hwp desired %u is out of range (%u ... %u)\n", + set_hwp->desired, data->hw_lowest, data->hw_highest); + + return -EINVAL; + } + + /* + * minimum & maximum are not validated as hardware doesn't seem to care + * and the SDM says CPUs will clip internally. + */ + + /* Apply presets */ + switch ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_PRESET_MASK ) + { + case XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE: + data->minimum =3D data->hw_lowest; + data->maximum =3D data->hw_lowest; + data->activity_window =3D 0; + if ( feature_hwp_energy_perf ) + data->energy_perf =3D 0xff; + else + data->energy_perf =3D 0xf; + data->desired =3D 0; + break; + case XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE: + data->minimum =3D data->hw_highest; + data->maximum =3D data->hw_highest; + data->activity_window =3D 0; + data->energy_perf =3D 0; + data->desired =3D 0; + break; + case XEN_SYSCTL_HWP_SET_PRESET_BALANCE: + data->minimum =3D data->hw_lowest; + data->maximum =3D data->hw_highest; + data->activity_window =3D 0; + data->energy_perf =3D 0x80; + if ( feature_hwp_energy_perf ) + data->energy_perf =3D 0x80; + else + data->energy_perf =3D 0x7; + data->desired =3D 0; + break; + case XEN_SYSCTL_HWP_SET_PRESET_NONE: + break; + default: + printk("HWP: Invalid preset value: %u\n", + set_hwp->set_params & XEN_SYSCTL_HWP_SET_PRESET_MASK); + + return -EINVAL; + } + + /* Further customize presets if needed */ + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_MINIMUM ) + data->minimum =3D set_hwp->minimum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_MAXIMUM ) + data->maximum =3D set_hwp->maximum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF ) + data->energy_perf =3D set_hwp->energy_perf; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED ) + data->desired =3D set_hwp->desired; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ACT_WINDOW ) + data->activity_window =3D set_hwp->activity_window & + XEN_SYSCTL_HWP_ACT_WINDOW_MASK; + + hwp_cpufreq_target(policy, 0, 0); + + return 0; +} + int hwp_register_driver(void) { int ret; diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 4c6ae5d768..860bf4db61 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -318,6 +318,24 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op) return __cpufreq_set_policy(old_policy, &new_policy); } =20 +static int set_cpufreq_hwp(struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy; + + if ( !cpufreq_governor_internal ) + return -EINVAL; + + policy =3D per_cpu(cpufreq_cpu_policy, op->cpuid); + + if ( !policy || !policy->governor ) + return -EINVAL; + + if ( strnicmp(policy->governor->name, "hwp-internal", CPUFREQ_NAME_LEN= ) ) + return -EINVAL; + + return set_hwp_para(policy, &op->u.set_hwp); +} + static int set_cpufreq_para(struct xen_sysctl_pm_op *op) { int ret =3D 0; @@ -465,6 +483,12 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } =20 + case SET_CPUFREQ_HWP: + { + ret =3D set_cpufreq_hwp(op); + break; + } + case SET_CPUFREQ_PARA: { ret =3D set_cpufreq_para(op); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 42146ca2cf..7ff7d0d4bb 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -248,5 +248,7 @@ void cpufreq_dbs_timer_resume(void); =20 /********************** hwp hypercall helper *************************/ int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_p= ara); +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp); =20 #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 1a6c6397ea..3f18a3d522 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -318,6 +318,36 @@ struct xen_hwp_para { uint8_t energy_perf; }; =20 +/* set multiple values simultaneously when set_args bit is set */ +struct xen_set_hwp_para { + uint16_t set_params; /* bitflags for valid values */ +#define XEN_SYSCTL_HWP_SET_DESIRED (1U << 0) +#define XEN_SYSCTL_HWP_SET_ENERGY_PERF (1U << 1) +#define XEN_SYSCTL_HWP_SET_ACT_WINDOW (1U << 2) +#define XEN_SYSCTL_HWP_SET_MINIMUM (1U << 3) +#define XEN_SYSCTL_HWP_SET_MAXIMUM (1U << 4) +#define XEN_SYSCTL_HWP_SET_PRESET_MASK (0xf000) +#define XEN_SYSCTL_HWP_SET_PRESET_NONE (0x0000) +#define XEN_SYSCTL_HWP_SET_PRESET_BALANCE (0x1000) +#define XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE (0x2000) +#define XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE (0x3000) +#define XEN_SYSCTL_HWP_SET_PARAM_MASK ((uint16_t)( \ + XEN_SYSCTL_HWP_SET_PRESET_MASK | \ + XEN_SYSCTL_HWP_SET_DESIRED | \ + XEN_SYSCTL_HWP_SET_ENERGY_PERF | \ + XEN_SYSCTL_HWP_SET_ACT_WINDOW | \ + XEN_SYSCTL_HWP_SET_MINIMUM | \ + XEN_SYSCTL_HWP_SET_MAXIMUM )) + + uint16_t activity_window; /* 7bit mantissa and 3bit exponent */ +#define XEN_SYSCTL_HWP_ACT_WINDOW_MASK (0x03ff) + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; /* 0-255 or 0-15 depending on HW support */ +}; + + /* * cpufreq para name of this structure named * same as sysfs file name of native linux @@ -379,6 +409,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_HWP (CPUFREQ_PARA | 0x05) =20 /* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 @@ -405,6 +436,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_hwp_para set_hwp; uint64_aligned_t get_avgfreq; uint32_t set_sched_opt_smt; #define XEN_SYSCTL_CX_UNLIMITED 0xffffffff --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237691; cv=none; d=zohomail.com; s=zohoarc; b=g2jhV0bPNKV24Z84SJVhoHYT1S1R6QYoFocRe1aTxK6bVLI2MU23Vjrb4XUh2Tr4k7ojnO0cSLim9hvjvyc7w1lkSnH3xH/ldcVZY3zdL19YQeFdNulx7AA/FYGsAjfAttALGMdyac3xb/b2HmbL0kitasBIZ/PyEeEgf2G029E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237691; 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=rVtlX4LAnp5jRUKVkmkEc1GA5I4vbGffEAZm21QjQrM=; b=GYY44KsPtFFUW3k9odn8TAUDxiSKfWI03TcK5fowfaFHbyr7tj8uqdiqqHx8b09eq0SFPhoDNE7EV4tKFBBLxudTDJhTavIUfo7h/gFi+J7VhIPUW2GcQGvIWMtX1HoRBG84zu/CvbdPYa6bCL15jXbUqhk59A/ShlF1z/j35V4= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237691254334.3716413435385; Mon, 8 Mar 2021 13:08:11 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95111.179481 (Exim 4.92) (envelope-from ) id 1lJN6W-0007dG-99; Mon, 08 Mar 2021 21:07:52 +0000 Received: by outflank-mailman (output) from mailman id 95111.179481; Mon, 08 Mar 2021 21:07:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN6W-0007d7-1Z; Mon, 08 Mar 2021 21:07:52 +0000 Received: by outflank-mailman (input) for mailman id 95111; Mon, 08 Mar 2021 21:07:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN25-0006P0-Jk for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:17 +0000 Received: from mail-qt1-x82d.google.com (unknown [2607:f8b0:4864:20::82d]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1a6da784-fe9b-49da-bd27-6060c32b14c3; Mon, 08 Mar 2021 21:02:45 +0000 (UTC) Received: by mail-qt1-x82d.google.com with SMTP id w6so8655624qti.6 for ; Mon, 08 Mar 2021 13:02:45 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:44 -0800 (PST) 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: 1a6da784-fe9b-49da-bd27-6060c32b14c3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVtlX4LAnp5jRUKVkmkEc1GA5I4vbGffEAZm21QjQrM=; b=eH2n4iUAB2+95HjUtKYHsMFrWKuAIs+a2kPamNBPo+kMHSFIyvtZE79ZYIdgEfeK6l y0ni+1qQDOUE+zmAIHmGQEIaYSBkZOWu6HiDcuNY/siQpIsanZpz9t23Bnokwmxxu9DZ K9EMpdGG5FDFfSGtVFLS0tigh4zB9JPK3aQ4kFoHhgXwHoWby7eVhrhawY6kwmHzBoU4 Y6KsI9N80zxxGO723ZShW22iXhz10LlakmRgIFCaU4uEPKjpO9vSc2FA/95V6can/+TL 36y+e3nQ9/Wfk2ngdzo1xuuGnGxRyf9Oocg+v2gaAUvliRQFdoRGNfvwVTGmnJb7KoJW smqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rVtlX4LAnp5jRUKVkmkEc1GA5I4vbGffEAZm21QjQrM=; b=TO4onI8nKQetLFDRtntm7Vp5tMMH56ZY4aItRNOHKnaml4mGpKXjNz9FQRWzOhSa/n CkN83G2P3GUkK+039NOmYqndWdHdIa5EjC1geLY6eFFlBNrxf7/hbFteo9RwEUCJVRF3 eC8cb0hJpwdtY0jvySZeshJmznVzqQYeRx4yQjqT6RjxB0KvZ8buW6gi9+4bnDidBvXN 8fDINwwjBolKnu7F5U82SzVEieBZ8mTr3lj2mJig/pFxV7qvNyrJmwly9EWddQppalqD FQfOZRJcLO8cxHEx763rsW1YfNhzfPmLz9dTFKBs4Zqph790NrQ8M7Tj8LkL92VkRZ23 csTg== X-Gm-Message-State: AOAM5313cVkbMw5doQUjmTL6yndtydkQvd3nX+Dp5GNRgb7PwxbGG6d2 41YKQCIIiw5NuYBT0nI8NirxvL7p8N4= X-Google-Smtp-Source: ABdhPJz7FWHDpj+qhIKakYWL0X3cPsCoqUlVm65leH4sWpU/7lxdScTpjRTxPbVQyd01jeNXSNDKvw== X-Received: by 2002:ac8:4f52:: with SMTP id i18mr22418241qtw.82.1615237364551; Mon, 08 Mar 2021 13:02:44 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu Subject: [RFC 11/12] libxc: Add xc_set_cpufreq_hwp Date: Mon, 8 Mar 2021 16:02:09 -0500 Message-Id: <20210308210210.116278-12-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" Add xc_set_cpufreq_hwp to allow calling xen_systctl_pm_op SET_CPUFREQ_HWP. Signed-off-by: Jason Andryuk --- Am I allowed to do set_hwp =3D *set_hwp struct assignment? --- tools/include/xenctrl.h | 4 ++++ tools/libs/ctrl/xc_pm.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 3b0ca62fc7..dc8e1bb23a 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1994,11 +1994,15 @@ struct xc_get_cpufreq_para { int32_t turbo_enabled; }; =20 +typedef struct xen_set_hwp_para xc_set_hwp_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_hwp(xc_interface *xch, int cpuid, + xc_set_hwp_para_t *set_hwp); 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 76d7eb7f26..407a24d2aa 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -330,6 +330,24 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, return xc_sysctl(xch, &sysctl); } =20 +int xc_set_cpufreq_hwp(xc_interface *xch, int cpuid, + xc_set_hwp_para_t *set_hwp) +{ + DECLARE_SYSCTL; + + if ( !xch ) + { + errno =3D EINVAL; + return -1; + } + sysctl.cmd =3D XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =3D SET_CPUFREQ_HWP; + sysctl.u.pm_op.cpuid =3D cpuid; + sysctl.u.pm_op.u.set_hwp =3D *set_hwp; + + return xc_sysctl(xch, &sysctl); +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret =3D 0; --=20 2.29.2 From nobody Sat May 4 05:43:58 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=1615237687; cv=none; d=zohomail.com; s=zohoarc; b=aTcrYJZYjHyMM4Ht4lNOduYwvu/Gyc+dkjOQi8VpoiA4rP9eMCEljGFlQ28CAeHiRtppbSrRJbWbGdIeSdK6HokivRXQKOypR3o0pJg3EfXvLmRaPfY5Fsf5dCD0w24/YRmgaVTMtywm6XOZJeyUqXdMjuV4oOYF5G/dqL752Ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615237687; 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=PKJr8nrwfa99gzKdxy4i3QfsaQ+/kCEtBoAhhMKOwBc=; b=Y/zlrnPuIX2DHco/5YMaOdXhrnX8/QwWenv4Ga50oHqv53S6HyIfHBG6AuNRd9J8QOav147/rBsVrKFXR+ryH7JQ4gnpVRJLPBJr8kvAb7djymZuA/huJqW6btEGmlIgve0wFVXE0cdMztXnLSr8Nes03eETCKaFkcBYvHX0QqA= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1615237687728594.2913667922672; Mon, 8 Mar 2021 13:08:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.95110.179472 (Exim 4.92) (envelope-from ) id 1lJN6V-0007cp-Sy; Mon, 08 Mar 2021 21:07:51 +0000 Received: by outflank-mailman (output) from mailman id 95110.179472; Mon, 08 Mar 2021 21:07:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN6V-0007ci-Pi; Mon, 08 Mar 2021 21:07:51 +0000 Received: by outflank-mailman (input) for mailman id 95110; Mon, 08 Mar 2021 21:07:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lJN2A-0006P0-Jq for xen-devel@lists.xenproject.org; Mon, 08 Mar 2021 21:03:22 +0000 Received: from mail-qk1-x733.google.com (unknown [2607:f8b0:4864:20::733]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b51513b8-6bfb-48fc-bc0d-6441286aa7d3; Mon, 08 Mar 2021 21:02:47 +0000 (UTC) Received: by mail-qk1-x733.google.com with SMTP id b130so10829284qkc.10 for ; Mon, 08 Mar 2021 13:02:47 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:a33e:daa7:46a1:a7eb]) by smtp.gmail.com with ESMTPSA id r2sm8514070qti.4.2021.03.08.13.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 13:02:46 -0800 (PST) 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: b51513b8-6bfb-48fc-bc0d-6441286aa7d3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PKJr8nrwfa99gzKdxy4i3QfsaQ+/kCEtBoAhhMKOwBc=; b=AGJqFitOs3SR/s3GKDOeCYaFSW2EOleleZyJ/l4r6z+1kV6iswUlvVlUw6jKFMrglP y7wfdqEI0ut4+sU2XdXaOGkaX6RYbehVdbBioKIX2lhOg5TMaQVXWXu1bkiHymevfWIp yqiw6SPbITy5LqVtlOZPNEHn66LgrB08HbB3OgHUKnX5kpatchhOc9aB4WkgI0JhOzxu BF02madFzY0pxaq3sUSmLDYIFNBjB6dLURnd8AJqxwGuOShxklWr3+LIYPyRstVB7LBm bq3c12d7MD5MEsq5G2neE1ai0E1zHYrwzwcAY103D9uIoeQnFz2uvS7qzz492tXf37Fd 3C9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PKJr8nrwfa99gzKdxy4i3QfsaQ+/kCEtBoAhhMKOwBc=; b=Fi4vYFSRSMUleKvffC1xxVcKDl0VSKi5xXuyuoeX8cyMV3qvqhwRskJ+mg9t131wRs kSTndLTbyMUarDGxy7vb3WcgIQKU015PDFkunNXkaude//ldLREccZJY90pbjFc7SK6M 63t0QikTiJz+YAWzpCVwF7O21oVd/QKaM5nO0SNL6YSXtYfr1vRGY4ZXjjq/HQD1/0vU g5CTQ5sKhEyfBSLvTlOFmBqwYLzo728gNmnCU3TOAVULKu8u8l4FD1D2xPQJxQ7V6TES sqKklU2GFWqt3r3VNnjs11k0u2pp7H2/ay3KmM/vLwBTrUtOwkE3g+hyAGuintF2frz1 W+rw== X-Gm-Message-State: AOAM532D2t/PqwO4YhMkcX6PKD4GuJvmS59QIVRztu8vOXosjt6UoEVs 2Ff6kqwWbjS6le8BI3GNMSgH9kV0E0o= X-Google-Smtp-Source: ABdhPJykpZdiAikj/fSZyShWHGRzVySaMqLE1EYhJjnKIDorwAsEFzY0mTfkgnKVTsqakCSIMg/7Tw== X-Received: by 2002:a37:9ed0:: with SMTP id h199mr22916899qke.8.1615237366768; Mon, 08 Mar 2021 13:02:46 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: pawel@invisiblethingslab.com, marmarek@invisiblethingslab.com, Jason Andryuk , Ian Jackson , Wei Liu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [RFC 12/12] xenpm: Add set-cpufreq-hwp subcommand Date: Mon, 8 Mar 2021 16:02:10 -0500 Message-Id: <20210308210210.116278-13-jandryuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210308210210.116278-1-jandryuk@gmail.com> References: <20210308210210.116278-1-jandryuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" set-cpufreq-hwp allows setting the Hardware P-State (HWP) parameters. It can be run on all or just a snigle cpu. There are preset 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 --- tools/misc/xenpm.c | 240 ++++++++++++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/hwp.c | 1 + 2 files changed, 241 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index a686f8f46e..d3bcaf3b58 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -67,6 +67,25 @@ 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-hwp [cpuid] [balance|performance|powersave= ] *\n" + " set Hardware P-State (HW= P) parameters\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 hw_lowest .= .. hw_highest\n" + " maximum:N hw_lowest .= .. hw_highest\n" + " desired:N hw_lowest .= .. hw_highest\n" + " Set explicit perfo= rmance target.\n" + " non-zero disables = auto-HWP mode.\n" + " energy_perf:0-255 (or = 0-15)\n" + " energy/per= formance hint\n" + " lower favo= r performance\n" + " higher fav= or powersave\n" + " 127 (or 7)= balance\n" + " act_window:N{,m,u}s ra= nge 0us-1270s\n" + " window for interna= l calculations.\n" + " 0 lets the hardwar= e decide.\n" + " get-cpufreq-para returns= hw_lowest/highest.\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" @@ -1309,6 +1328,226 @@ 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 + * 1 Not activity_window. i.e. try parsing as another argument + */ +static int parse_activity_window(xc_set_hwp_para_t *set_hwp, char *p) +{ + char *param =3D NULL, *val =3D NULL, *suffix =3D NULL; + unsigned int u; + unsigned int exponent =3D 0; + unsigned int multiplier =3D 1; + int ret; + + ret =3D sscanf(p, "%m[a-z_A-Z]:%ms", ¶m, &val); + if ( ret !=3D 2 ) + { + return -1; + } + + if ( strncasecmp(param, "act", 3) !=3D 0 ) + { + ret =3D 1; + + goto out; + } + + free(param); + param =3D NULL; + + ret =3D sscanf(val, "%u%ms", &u, &suffix); + if ( ret !=3D 1 && ret !=3D 2 ) + { + fprintf(stderr, "invalid activity window: %s\n", val); + + ret =3D -1; + + goto out; + } + + if ( ret =3D=3D 2 && suffix ) + { + if ( strcasecmp(suffix, "s") =3D=3D 0 ) + { + multiplier =3D 1000 * 1000; + exponent =3D 6; + } + else if ( strcasecmp(suffix, "ms") =3D=3D 0 ) + { + multiplier =3D 1000; + exponent =3D 3; + } + else if ( strcasecmp(suffix, "us") =3D=3D 0 ) + { + multiplier =3D 1; + exponent =3D 0; + } + else + { + fprintf(stderr, "invalid activity window units: %s\n", suffix); + + ret =3D -1; + goto out; + } + } + + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window %s too large\n", val); + + ret =3D -1; + goto out; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u /=3D 10; + exponent +=3D 1; + } + + set_hwp->activity_window =3D ( exponent & 0x7 ) << 7 | ( u & 0x7f ); + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_ACT_WINDOW; + + ret =3D 0; + + out: + free(suffix); + free(param); + free(val); + + return ret; +} + +static int parse_hwp_opts(xc_set_hwp_para_t *set_hwp, int *cpuid, + int argc, char *argv[]) +{ + int i =3D 0; + + if ( argc < 1 ) + return -1; + + if ( parse_cpuid_non_fatal(argv[i], cpuid) =3D=3D 0 ) + { + i++; + } + + if ( i =3D=3D argc ) + return -1; + + if ( strcasecmp(argv[i], "powersave") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") =3D=3D 0 ) + { + set_hwp->set_params =3D XEN_SYSCTL_HWP_SET_PRESET_BALANCE; + i++; + } + + for ( ; i < argc; i++) + { + unsigned int val; + char *param; + int ret; + + ret =3D parse_activity_window(set_hwp, argv[i]); + switch ( ret ) + { + case -1: + return -1; + case 0: + continue; + break; + case 1: + /* try other parsing */ + break; + } + + /* sscanf can't handle split on ':' for "%ms:%u' */ + ret =3D sscanf(argv[i], "%m[a-zA-Z_]:%u", ¶m, &val); + if ( ret !=3D 2 ) + { + fprintf(stderr, "%s is an invalid hwp parameter.\n", argv[i]); + return -1; + } + + if ( val > 255 ) + { + fprintf(stderr, "%s value %u is out of range.\n", param, val); + return -1; + } + + if ( strncasecmp(param, "min", 3) =3D=3D 0 ) + { + set_hwp->minimum =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_MINIMUM; + } + else if ( strncasecmp(param, "max", 3) =3D=3D 0 ) + { + set_hwp->maximum =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_MAXIMUM; + } + else if ( strncasecmp(param, "des", 3) =3D=3D 0 ) + { + set_hwp->desired =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_DESIRED; + } + else if ( strncasecmp(param, "ene", 3) =3D=3D 0 ) + { + set_hwp->energy_perf =3D val; + set_hwp->set_params |=3D XEN_SYSCTL_HWP_SET_ENERGY_PERF; + } + else + { + fprintf(stderr, "%s is an invalid parameter\n.", param); + return -1; + } + + free(param); + } + + return 0; +} + +static void hwp_set_func(int argc, char *argv[]) +{ + xc_set_hwp_para_t set_hwp =3D {}; + int cpuid =3D -1; + int i =3D 0; + + if ( parse_hwp_opts(&set_hwp, &cpuid, argc, argv) ) + { + fprintf(stderr, "Missing, excess, or invalid argument(s)\n"); + exit(EINVAL); + } + + if ( cpuid !=3D -1 ) + { + i =3D cpuid; + max_cpu_nr =3D i + 1; + } + + for ( ; i < max_cpu_nr; i++ ) + if ( xc_set_cpufreq_hwp(xc_handle, i, &set_hwp) ) + fprintf(stderr, "[CPU%d] failed to set hwp params (%d - %s)\n", + i, errno, strerror(errno)); +} + struct { const char *name; void (*function)(int argc, char *argv[]); @@ -1319,6 +1558,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "set-cpufreq-hwp", hwp_set_func }, { "set-scaling-maxfreq", scaling_max_freq_func }, { "set-scaling-minfreq", scaling_min_freq_func }, { "set-scaling-governor", scaling_governor_func }, diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c index 8f4b18d246..0fd70d76a8 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -584,6 +584,7 @@ int set_hwp_para(struct cpufreq_policy *policy, } =20 if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED && + set_hwp->desired !=3D 0 && ( set_hwp->desired < data->hw_lowest || set_hwp->desired > data->hw_highest ) ) { --=20 2.29.2