From patchwork Mon Mar 8 21:01:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28DC8C433E9 for ; Mon, 8 Mar 2021 21:02:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC4EA652B6 for ; Mon, 8 Mar 2021 21:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC4EA652B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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); +bool __read_mostly cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); @@ -122,6 +123,9 @@ int __init cpufreq_register_governor(struct cpufreq_governor *governor) if (!governor) return -EINVAL; + if (cpufreq_governor_internal && strstr(governor->name, "internal") == NULL) + return -EINVAL; + if (__find_governor(governor->name) != NULL) return -EEXIST; 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; extern struct list_head cpufreq_governor_list; From patchwork Mon Mar 8 21:02:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D659C433E0 for ; Mon, 8 Mar 2021 21:02:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D14776528A for ; Mon, 8 Mar 2021 21:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D14776528A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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/cpufreq/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, unsigned int flag) else perf_percent = 0; - return policy->cpuinfo.max_freq * perf_percent / 100; + return policy->cpuinfo.perf_freq * perf_percent / 100; } 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_policy *policy, policy->min = policy->cpuinfo.min_freq = min_freq; policy->max = policy->cpuinfo.max_freq = max_freq; + policy->cpuinfo.perf_freq = max_freq; policy->cpuinfo.second_max_freq = second_max_freq; if (policy->min == ~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 = nanoseconds */ }; From patchwork Mon Mar 8 21:02:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24799C433E6 for ; Mon, 8 Mar 2021 21:02:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC2AA652B5 for ; Mon, 8 Mar 2021 21:02:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC2AA652B5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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/cpufreq/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 cpu) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } -static void feature_detect(void *info) +void intel_feature_detect(void *info) { struct cpufreq_policy *policy = 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 == X86_VENDOR_INTEL && c->cpuid_level >= 6) - on_selected_cpus(cpumask_of(cpu), feature_detect, policy, 1); + on_selected_cpus(cpumask_of(cpu), intel_feature_detect, policy, 1); /* * the first call to ->target() should result in us actually diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/cpufreq/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 @@ #define XEN_PX_INIT 0x80000000 +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); From patchwork Mon Mar 8 21:02:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F976C433E0 for ; Mon, 8 Mar 2021 21:03:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A3AE6528A for ; Mon, 8 Mar 2021 21:03:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A3AE6528A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 physical port 80 (often used for debugging purposes), to override the DMI based detection of systems known to misbehave upon accesses to that port. +### hwp (x86) +> `= ` + +> 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) > `= ` 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 += cpufreq.o +obj-y += hwp.o obj-y += powernow.o diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/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 = 0; if ((cpufreq_controller == FREQCTL_xen) && - (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)) - ret = cpufreq_register_driver(&acpi_cpufreq_driver); - else if ((cpufreq_controller == FREQCTL_xen) && + (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)) { + if (hwp_available()) + ret = hwp_register_driver(); + else + ret = cpufreq_register_driver(&acpi_cpufreq_driver); + } else if ((cpufreq_controller == FREQCTL_xen) && (boot_cpu_data.x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON))) ret = powernow_register_driver(); diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.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 = 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 == NULL ) + return -EINVAL; + + switch (event) + { + case CPUFREQ_GOV_START: + ret = 0; + break; + case CPUFREQ_GOV_STOP: + ret = -EINVAL; + break; + case CPUFREQ_GOV_LIMITS: + ret = 0; + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static struct cpufreq_governor hwp_cpufreq_governor = +{ + .name = "hwp-internal", + .governor = 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 = cpuid_eax(CPUID_PM_LEAF); + feature_hwp = !!(eax & CPUID6_EAX_HWP); + feature_hwp_notification = !!(eax & CPUID6_EAX_HWP_Notification); + feature_hwp_activity_window = !!(eax & CPUID6_EAX_HWP_Activity_Window); + feature_hwp_energy_perf = + !!(eax & CPUID6_EAX_HWP_Energy_Performance_Preference); + feature_hwp_pkg_level_ctl = + !!(eax & CPUID6_EAX_HWP_Package_Level_Request); + feature_hwp_peci = !!(eax & CPUID6_EAX_HWP_PECI); + + hwp_verbose("HWP: %d notify: %d act_window: %d energy_perf: %d pkg_level: %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 = true; + } + } + + feature_hdc = !!(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 = feature_hwp && opt_hwp; + cpufreq_governor_internal = 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 = 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 = 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 = val; + + if ( wrmsr_safe(MSR_FAST_UNCORE_MSRS_CTL, msr) ) + hwp_err("error wrmsr_safe(MSR_FAST_UNCORE_MSRS_CTL): %016lx\n", msr); +} + +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 = base_khz * 1000; + policy->cpuinfo.min_freq = base_khz * 1000; + policy->cpuinfo.max_freq = max_khz * 1000; + policy->min = base_khz * 1000; + policy->max = max_khz * 1000; + policy->cur = 0; +} + +static void hwp_read_capabilities(void *info) +{ + struct cpufreq_policy *policy = info; + struct hwp_drv_data *data = 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 = 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->cpu); + + return; + } + + hwp_verbose("CPU%u: MSR_IA32_PM_ENABLE: %016lx\n", policy->cpu, val); + if ( val != IA32_PM_ENABLE_HWP_ENABLE ) + { + val = 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 = policy->cpu; + struct hwp_drv_data *data = 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 = info; + uint8_t val = data->energy_perf; + + ASSERT(val <= 15); + + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + + return; + } + + msr &= ~(0xf); + msr |= val; + + if ( wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_ENERGY_PERF_BIAS): %016lx\n", msr); +} + +static void hwp_write_request(void *info) +{ + struct cpufreq_policy *policy = info; + struct hwp_drv_data *data = hwp_drv_data[policy->cpu]; + union hwp_request hwp_req = data->curr_req; + + BUILD_BUG_ON(sizeof(union hwp_request) != 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 relation) +{ + unsigned int cpu = policy->cpu; + struct hwp_drv_data *data = hwp_drv_data[cpu]; + union hwp_request hwp_req; + + /* Zero everything to ensure reserved bits are zero... */ + hwp_req.raw = 0; + /* .. and update from there */ + hwp_req.min_perf = data->minimum; + hwp_req.max_perf = data->maximum; + hwp_req.desired = data->desired; + if ( feature_hwp_energy_perf ) + hwp_req.energy_perf = data->energy_perf; + if ( feature_hwp_activity_window ) + hwp_req.activity_window = data->activity_window; + + if ( hwp_req.raw == data->curr_req.raw ) + return 0; + + data->curr_req.raw = 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 = policy->cpu; + struct hwp_drv_data *data; + + if ( cpufreq_opt_governor ) + { + printk(XENLOG_WARNING + "HWP: governor \"%s\" is incompatible with hwp. Using default \"%s\"\n", + cpufreq_opt_governor->name, hwp_cpufreq_governor.name); + } + policy->governor = &hwp_cpufreq_governor; + + data = xzalloc(typeof(*data)); + if ( !data ) + return -ENOMEM; + + hwp_drv_data[cpu] = data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + data->minimum = data->hw_lowest; + data->maximum = data->hw_highest; + data->desired = 0; /* default to HW autonomous */ + if ( feature_hwp_energy_perf ) + data->energy_perf = 0x80; + else + data->energy_perf = 7; + + hwp_verbose("CPU%u: IA32_HWP_CAPABILITIES: %016lx\n", cpu, data->hwp_caps); + + hwp_verbose("CPU%u: rdmsr HWP_REQUEST %016lx\n", cpu, data->curr_req.raw); + + return 0; +} + +static int hwp_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + unsigned int cpu = policy->cpu; + + xfree(hwp_drv_data[cpu]); + hwp_drv_data[cpu] = 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 least + * with my HWP testing. MSR_IA32_MISC_ENABLE and MISC_ENABLE_TURBO_DISENGAGE + * is what Linux uses and seems to work. */ +static void hwp_set_misc_turbo(void *info) +{ + struct cpufreq_policy *policy = 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 == CPUFREQ_TURBO_ENABLED ) + msr &= ~MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + else + msr |= 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 = +{ + .name = "hwp-cpufreq", + .verify = hwp_cpufreq_verify, + .target = hwp_cpufreq_target, + .init = hwp_cpufreq_cpu_init, + .exit = hwp_cpufreq_cpu_exit, + .update = hwp_cpufreq_update, +}; + +int hwp_register_driver(void) +{ + int ret; + + ret = cpufreq_register_driver(&hwp_cpufreq_driver); + + return ret; +} diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/cpufreq/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 @@ void intel_feature_detect(void *info); +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/cpufeature.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 -#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 /* CPUID level 0x00000001.edx */ diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.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) +#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 +#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) +#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) #define MSR_IA32_TSC_DEADLINE 0x000006E0 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 From patchwork Mon Mar 8 21:02:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44820C433E6 for ; Mon, 8 Mar 2021 21:03:05 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 037CE652B2 for ; Mon, 8 Mar 2021 21:03:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 037CE652B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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_cpufreq) { + bool internal = strstr(p_cpufreq->scaling_governor, "internal"); int i; printf("cpu id : %d\n", cpuid); @@ -720,10 +721,19 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); - 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); + } printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); @@ -750,19 +760,22 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) p_cpufreq->u.ondemand.up_threshold); } - printf("scaling_avail_freq :"); - for ( i = 0; i < p_cpufreq->freq_num; i++ ) - if ( p_cpufreq->scaling_available_frequencies[i] == - 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 = 0; i < p_cpufreq->freq_num; i++ ) + if ( p_cpufreq->scaling_available_frequencies[i] == + p_cpufreq->scaling_cur_freq ) + printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); + else + printf(" %d", p_cpufreq->scaling_available_frequencies[i]); + printf("\n"); - 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); + } printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); From patchwork Mon Mar 8 21:02:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAADAC433DB for ; Mon, 8 Mar 2021 21:03:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 91BE56528A for ; Mon, 8 Mar 2021 21:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91BE56528A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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/hwp.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 = .update = hwp_cpufreq_update, }; +int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_para) +{ + unsigned int cpu = policy->cpu; + struct hwp_drv_data *data = hwp_drv_data[cpu]; + + if ( data == NULL ) + return -EINVAL; + + hwp_para->hw_feature = + 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 = data->hw_lowest; + hwp_para->hw_most_efficient = data->hw_most_efficient; + hwp_para->hw_guaranteed = data->hw_guaranteed; + hwp_para->hw_highest = data->hw_highest; + hwp_para->minimum = data->minimum; + hwp_para->maximum = data->maximum; + hwp_para->energy_perf = data->energy_perf; + hwp_para->activity_window = data->activity_window; + hwp_para->desired = 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 *op) &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 = get_hwp_para(policy, &op->u.get_para.u.hwp_para); + } op->u.get_para.turbo_enabled = cpufreq_get_turbo_status(op->cpuid); 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); +/********************** hwp hypercall helper *************************/ +int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_para); + #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" -#define XEN_SYSCTL_INTERFACE_VERSION 0x00000013 +#define XEN_SYSCTL_INTERFACE_VERSION 0x00000014 /* * Read console content from Xen buffer ring. @@ -301,6 +301,23 @@ struct xen_ondemand { uint32_t up_threshold; }; +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-255 if + 1. Otherwise 0-15 */ +#define XEN_SYSCTL_HWP_FEAT_ACT_WINDOW (1 << 1) /* activity_window supported + 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; int32_t turbo_enabled; From patchwork Mon Mar 8 21:02:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B3BDC433E6 for ; Mon, 8 Mar 2021 21:03:11 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 65487652B2 for ; Mon, 8 Mar 2021 21:03:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 65487652B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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; 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; int32_t turbo_enabled; From patchwork Mon Mar 8 21:02:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98E85C433E9 for ; Mon, 8 Mar 2021 21:03:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FB906528A for ; Mon, 8 Mar 2021 21:03:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FB906528A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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(); } +static void calculate_hwp_activity_window(const xc_hwp_para_t *hwp, + unsigned int *activity_window, + const char **units) +{ + unsigned int mantissa = hwp->activity_window & 0x7f; + unsigned int exponent = ( hwp->activity_window >> 7 ) & 0x7; + unsigned int multiplier = 1; + + if ( hwp->activity_window == 0 ) + { + *units = "hardware selected"; + *activity_window = 0; + + return; + } + + if ( exponent >= 6 ) + { + *units = "s"; + exponent -= 6; + } + else if ( exponent >= 3 ) + { + *units = "ms"; + exponent -= 3; + } + else + { + *units = "us"; + } + + for ( unsigned int i = 0; i < exponent; i++ ) + multiplier *= 10; + + *activity_window = mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) { @@ -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"); - 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); } - if (!internal) + if ( !internal ) { printf("scaling_avail_freq :"); for ( i = 0; i < p_cpufreq->freq_num; i++ ) @@ -777,6 +814,40 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) p_cpufreq->scaling_cur_freq); } + if ( strcmp(p_cpufreq->scaling_governor, "hwp-internal") == 0 ) + { + const xc_hwp_para_t *hwp = &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"); From patchwork Mon Mar 8 21:02:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C952C433DB for ; Mon, 8 Mar 2021 21:03:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55927652B2 for ; Mon, 8 Mar 2021 21:03:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55927652B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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(); } -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) != 1 || *cpuid < 0 ) { if ( strcasecmp(arg, "all") ) - { - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); - exit(EINVAL); - } + return -1; + *cpuid = -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); + } } static void parse_cpuid_and_int(int argc, char *argv[], From patchwork Mon Mar 8 21:02:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F827C433DB for ; Mon, 8 Mar 2021 21:08:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E906F64EC0 for ; Mon, 8 Mar 2021 21:08:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E906F64EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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/hwp.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, struct xen_hwp_para *hwp_para) return 0; } +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp) +{ + unsigned int cpu = policy->cpu; + struct hwp_drv_data *data = hwp_drv_data[cpu]; + + if ( data == 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 = data->hw_lowest; + data->maximum = data->hw_lowest; + data->activity_window = 0; + if ( feature_hwp_energy_perf ) + data->energy_perf = 0xff; + else + data->energy_perf = 0xf; + data->desired = 0; + break; + case XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE: + data->minimum = data->hw_highest; + data->maximum = data->hw_highest; + data->activity_window = 0; + data->energy_perf = 0; + data->desired = 0; + break; + case XEN_SYSCTL_HWP_SET_PRESET_BALANCE: + data->minimum = data->hw_lowest; + data->maximum = data->hw_highest; + data->activity_window = 0; + data->energy_perf = 0x80; + if ( feature_hwp_energy_perf ) + data->energy_perf = 0x80; + else + data->energy_perf = 0x7; + data->desired = 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 = set_hwp->minimum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_MAXIMUM ) + data->maximum = set_hwp->maximum; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF ) + data->energy_perf = set_hwp->energy_perf; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED ) + data->desired = set_hwp->desired; + + if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_ACT_WINDOW ) + data->activity_window = 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); } +static int set_cpufreq_hwp(struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy; + + if ( !cpufreq_governor_internal ) + return -EINVAL; + + policy = 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 = 0; @@ -465,6 +483,12 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } + case SET_CPUFREQ_HWP: + { + ret = set_cpufreq_hwp(op); + break; + } + case SET_CPUFREQ_PARA: { ret = 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); /********************** hwp hypercall helper *************************/ int get_hwp_para(struct cpufreq_policy *policy, struct xen_hwp_para *hwp_para); +int set_hwp_para(struct cpufreq_policy *policy, + struct xen_set_hwp_para *set_hwp); #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; }; +/* 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) /* 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 From patchwork Mon Mar 8 21:02:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B97EC433E0 for ; Mon, 8 Mar 2021 21:08:01 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D65064EC0 for ; Mon, 8 Mar 2021 21:08:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D65064EC0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 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 = *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; }; +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); 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); } +int xc_set_cpufreq_hwp(xc_interface *xch, int cpuid, + xc_set_hwp_para_t *set_hwp) +{ + DECLARE_SYSCTL; + + if ( !xch ) + { + errno = EINVAL; + return -1; + } + sysctl.cmd = XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd = SET_CPUFREQ_HWP; + sysctl.u.pm_op.cpuid = cpuid; + sysctl.u.pm_op.u.set_hwp = *set_hwp; + + return xc_sysctl(xch, &sysctl); +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret = 0; From patchwork Mon Mar 8 21:02:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12123415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1D50C433E6 for ; Mon, 8 Mar 2021 21:08:03 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7D57864EEE for ; Mon, 8 Mar 2021 21:08:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D57864EEE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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 limitation ( >= 0) and\n" " optionally the C-sub-state limitation ( >= 0)\n" + " set-cpufreq-hwp [cpuid] [balance|performance|powersave] *\n" + " set Hardware P-State (HWP) parameters\n" + " optionally a preset of one of\n" + " balance|performance|powersave\n" + " an optional list of param: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 performance target.\n" + " non-zero disables auto-HWP mode.\n" + " energy_perf:0-255 (or 0-15)\n" + " energy/performance hint\n" + " lower favor performance\n" + " higher favor powersave\n" + " 127 (or 7) balance\n" + " act_window:N{,m,u}s range 0us-1270s\n" + " window for internal calculations.\n" + " 0 lets the hardware decide.\n" + " get-cpufreq-para returns hw_lowest/highest.\n" " start [seconds] start collect Cx/Px statistics,\n" " output after CTRL-C or SIGINT or several seconds.\n" " enable-turbo-mode [cpuid] enable Turbo Mode for processors that support it.\n" @@ -1309,6 +1328,226 @@ void disable_turbo_mode(int argc, char *argv[]) errno, strerror(errno)); } +/* + * Parse activity_window:NNN{us,ms,s} and validate range. + * + * Activity window is a 7bit mantissa (0-127) with a 3bit exponent (0-7) base + * 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 = NULL, *val = NULL, *suffix = NULL; + unsigned int u; + unsigned int exponent = 0; + unsigned int multiplier = 1; + int ret; + + ret = sscanf(p, "%m[a-z_A-Z]:%ms", ¶m, &val); + if ( ret != 2 ) + { + return -1; + } + + if ( strncasecmp(param, "act", 3) != 0 ) + { + ret = 1; + + goto out; + } + + free(param); + param = NULL; + + ret = sscanf(val, "%u%ms", &u, &suffix); + if ( ret != 1 && ret != 2 ) + { + fprintf(stderr, "invalid activity window: %s\n", val); + + ret = -1; + + goto out; + } + + if ( ret == 2 && suffix ) + { + if ( strcasecmp(suffix, "s") == 0 ) + { + multiplier = 1000 * 1000; + exponent = 6; + } + else if ( strcasecmp(suffix, "ms") == 0 ) + { + multiplier = 1000; + exponent = 3; + } + else if ( strcasecmp(suffix, "us") == 0 ) + { + multiplier = 1; + exponent = 0; + } + else + { + fprintf(stderr, "invalid activity window units: %s\n", suffix); + + ret = -1; + goto out; + } + } + + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window %s too large\n", val); + + ret = -1; + goto out; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u /= 10; + exponent += 1; + } + + set_hwp->activity_window = ( exponent & 0x7 ) << 7 | ( u & 0x7f ); + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_ACT_WINDOW; + + ret = 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 = 0; + + if ( argc < 1 ) + return -1; + + if ( parse_cpuid_non_fatal(argv[i], cpuid) == 0 ) + { + i++; + } + + if ( i == argc ) + return -1; + + if ( strcasecmp(argv[i], "powersave") == 0 ) + { + set_hwp->set_params = XEN_SYSCTL_HWP_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") == 0 ) + { + set_hwp->set_params = XEN_SYSCTL_HWP_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") == 0 ) + { + set_hwp->set_params = XEN_SYSCTL_HWP_SET_PRESET_BALANCE; + i++; + } + + for ( ; i < argc; i++) + { + unsigned int val; + char *param; + int ret; + + ret = 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 = sscanf(argv[i], "%m[a-zA-Z_]:%u", ¶m, &val); + if ( ret != 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) == 0 ) + { + set_hwp->minimum = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_MINIMUM; + } + else if ( strncasecmp(param, "max", 3) == 0 ) + { + set_hwp->maximum = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_MAXIMUM; + } + else if ( strncasecmp(param, "des", 3) == 0 ) + { + set_hwp->desired = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_DESIRED; + } + else if ( strncasecmp(param, "ene", 3) == 0 ) + { + set_hwp->energy_perf = val; + set_hwp->set_params |= 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 = {}; + int cpuid = -1; + int i = 0; + + if ( parse_hwp_opts(&set_hwp, &cpuid, argc, argv) ) + { + fprintf(stderr, "Missing, excess, or invalid argument(s)\n"); + exit(EINVAL); + } + + if ( cpuid != -1 ) + { + i = cpuid; + max_cpu_nr = 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/hwp.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, } if ( set_hwp->set_params & XEN_SYSCTL_HWP_SET_DESIRED && + set_hwp->desired != 0 && ( set_hwp->desired < data->hw_lowest || set_hwp->desired > data->hw_highest ) ) {