From patchwork Wed Aug 10 19:29:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 551E6C00140 for ; Wed, 10 Aug 2022 19:30:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383873.619088 (Exim 4.92) (envelope-from ) id 1oLrPB-00067l-Ls; Wed, 10 Aug 2022 19:30:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383873.619088; Wed, 10 Aug 2022 19:30:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPB-00067c-Gh; Wed, 10 Aug 2022 19:30:13 +0000 Received: by outflank-mailman (input) for mailman id 383873; Wed, 10 Aug 2022 19:30:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPA-00067E-Ho for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:12 +0000 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [2607:f8b0:4864:20::72c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d96c44f9-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:11 +0200 (CEST) Received: by mail-qk1-x72c.google.com with SMTP id d8so7300982qkk.1 for ; Wed, 10 Aug 2022 12:30:11 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:09 -0700 (PDT) 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: d96c44f9-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=YaQ1M6q3D+VE5TezIjwSsQPtyAvIE/tK9UYnMBK9ZTE=; b=JafKEHlefrPqEr6Vw+WOV8AkmEJGsfaqWtuIVzIELQET9cW8F7T//nvxxEdwYnETg7 TMVXBTx4O3/K6+7PNozKjbfQu+TgTqj3hQ8AcGIdafm8GpZYY25mcZLUtNrmGaFNwDpU bvh5uvV56jG3p+Kai1GKr++Ucjdh2DZKhkpnRiaKwNQPxkk2eTpHS6KUtu0pRkqOr9Uc v6t1Ey8vN97/BDEegj8AsoixIKlynaczmTnK/9TVKjEQxMIKxZNgz+S9hWPelG8khq2U pjp5x1O/sJv6Fn3nk6tH3PgGrBwT5EIzuvJo5LC63qmBbZy8tXJV8o+HMDHZ7hEseyz+ MmTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=YaQ1M6q3D+VE5TezIjwSsQPtyAvIE/tK9UYnMBK9ZTE=; b=3o8e+dC0VJeonJgWqAKidW1swLSD8zYh610ogYoauEo9Lvcj8/6wZMJo+GhRpGZMKm kTpbIrmSkkRMs+4/9Kxuhg7KWdHZ1yZDjxyxBbhwLQJPNghBE5vlzO3FJzJQCWMVoCvK doI6pbWn8GO0mOuzsOq0YPbbXParaH5dzUVV7n8g4uus57VjgYD8qajQHsLepeIGpCJL XkObAVN91aN4cGuPK6mUi9jstmkhhmTPVmMFtE70EuiGUqOW6mIMssinGszFRSocML5g p+1uNKego5e/BFapvrGeDCdzZVdziDx9uvTiVq2pI7BL4dueQd/ZAVQ17m+yco6GjDSN zm8A== X-Gm-Message-State: ACgBeo2hyEpH1aopmzwAsI85WKjhqRQ3QPKGRDsXQYxhFCgzoUj1EC7Y hsQ5SIGzXQNy7uzhTPunu9OQOSsuzNA= X-Google-Smtp-Source: AA6agR7W1Sl4o/sOM/mI6Q51UBYQMCUa9K2ffX72dCl9qcAu7Eu53VT2O/s3Y9lPL4/anajxNG4HTQ== X-Received: by 2002:a05:620a:1597:b0:6b9:57d2:8aa0 with SMTP id d23-20020a05620a159700b006b957d28aa0mr11223268qkk.485.1660159809965; Wed, 10 Aug 2022 12:30:09 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich Subject: [PATCH v2 01/13] cpufreq: Allow restricting to internal governors only Date: Wed, 10 Aug 2022 15:29:32 -0400 Message-Id: <20220810192944.102135-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 Acked-by: Jan Beulich --- v2: Switch to "-internal" Add blank line in header --- xen/drivers/cpufreq/cpufreq.c | 5 +++++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index a94520ee57..1fdd63d7b5 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,10 @@ 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 35dcf21e8f..0da32ef519 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -114,6 +114,8 @@ 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; extern int cpufreq_register_governor(struct cpufreq_governor *governor); From patchwork Wed Aug 10 19:29:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 95286C25B06 for ; Wed, 10 Aug 2022 19:30:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383875.619099 (Exim 4.92) (envelope-from ) id 1oLrPF-0006R1-Sy; Wed, 10 Aug 2022 19:30:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383875.619099; Wed, 10 Aug 2022 19:30:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPF-0006Qc-OX; Wed, 10 Aug 2022 19:30:17 +0000 Received: by outflank-mailman (input) for mailman id 383875; Wed, 10 Aug 2022 19:30:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPE-0005rf-4p for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:16 +0000 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [2607:f8b0:4864:20::72e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dbcba058-18e2-11ed-bd2e-47488cf2e6aa; Wed, 10 Aug 2022 21:30:15 +0200 (CEST) Received: by mail-qk1-x72e.google.com with SMTP id i13so4078099qkm.8 for ; Wed, 10 Aug 2022 12:30:15 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:13 -0700 (PDT) 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: dbcba058-18e2-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=SxZKnNNwTrIDOU+tEEO3VrrnwPCkxQYa2L8+Nx13qkY=; b=bl/eoNSd9YwaRcoCzH/e8sfTl5jrA4sJRaO9jVDs7GEFnRKcXPl3okgUWs/N4rLDrO X1VAgxTO2BH17pqV/CCgpbhL9rHI0Alz/4SB/mGoNhrM83rsinigCgQ/xJpG9Q5WsIJK hN5iInEvZIpGsTvImIYIEwyk7++1Tgd6NX6W/zYNzgFGG1tFWDCBXiX6eN4Cr5uWiosL NXETEiYUVteyYRsMR+QcHusjzUTXtURteUC6CAVR/4cnKwpoPEsFKaXF5UHj4vRRfjZ5 3vnz7fzR7//O7vYUhqXA1FODyGLJOVThfRAsc/Z9vkSsAsfI8u3JxG/WXEXGQV3Lnw4f R6TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SxZKnNNwTrIDOU+tEEO3VrrnwPCkxQYa2L8+Nx13qkY=; b=4EC1h+2k0H03Y3Dnol123qpnlNLZgrIBQ7Pjxh/6Z/mVUEHvS4oruJD+YOxHkIpYM0 7nKqVKlIXWYc+YGyad5wdXsHrE4uyx/O2D4LIIXnt16QHjtH0WXNJEJzWLX+IvSC+Hpy M6656N0GhCEmwCzh7QtUPxIXBZSeIenH9U29x34JTUKSzrf62O7V42CKgu7o8dCO4gLb JnTyIQ3WduQWh295Eqa6ISc9iM6D6YuYsxMeQf0UDvIAiflmSCVDf3T5JO4fXOPbuA7A zkD0e5qsgefgLUh2WgfZROGj4Dj1lsRB3d3EJfJAhtk7bVdihTuEnuES6y/fRNjO1sdC YC5g== X-Gm-Message-State: ACgBeo3KeOikdAq+KvfJrWNnRPh53wcDB5KNmbA5W0UngzqLSh4UnVK6 /Qk+g4LngPxkCUlOepPnf6T2NjGYSiU= X-Google-Smtp-Source: AA6agR5A7InDlBEvaDBVp0c4YGz2tHxYW8f1DEBshjdpKSaPdcxbMaJFD9d4YbR4LPypMIzjxLH9Bw== X-Received: by 2002:a37:9247:0:b0:6b9:78ef:56 with SMTP id u68-20020a379247000000b006b978ef0056mr6732765qkd.364.1660159814067; Wed, 10 Aug 2022 12:30:14 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 02/13] cpufreq: Add perf_freq to cpuinfo Date: Wed, 10 Aug 2022 15:29:33 -0400 Message-Id: <20220810192944.102135-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 Acked-by: Jan Beulich --- 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 c27cbb2304..ded0150b3b 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 cf_check get_cur_freq_on_cpu(unsigned int cpu) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index 9eb7ecedcd..6831f62851 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -236,6 +236,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_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 0da32ef519..a06aa92f62 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 Wed Aug 10 19:29:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 94088C00140 for ; Wed, 10 Aug 2022 19:30:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383876.619110 (Exim 4.92) (envelope-from ) id 1oLrPJ-0006kp-5I; Wed, 10 Aug 2022 19:30:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383876.619110; Wed, 10 Aug 2022 19:30:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPJ-0006ki-28; Wed, 10 Aug 2022 19:30:21 +0000 Received: by outflank-mailman (input) for mailman id 383876; Wed, 10 Aug 2022 19:30:19 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPG-0005rf-SD for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:18 +0000 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [2607:f8b0:4864:20::735]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd77d49b-18e2-11ed-bd2e-47488cf2e6aa; Wed, 10 Aug 2022 21:30:18 +0200 (CEST) Received: by mail-qk1-x735.google.com with SMTP id u24so4284861qku.2 for ; Wed, 10 Aug 2022 12:30:18 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:16 -0700 (PDT) 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: dd77d49b-18e2-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=9qPwuueNZm/jcjcA5mRF9P33JC4lKfZl/P5JBTr94o4=; b=qKAG0HqqmzibDAPGZjBSA0kiIYuYzdmb0zZoads/iQdBG8A7PgXzYHhfh+j7zdqdVz xbuER1rOhoCSA0laa2+APXLTU0JDx4Q8uoyUHrAyYhqliCotvf7lXYzIUQSBvO0tu6vB OBSPsoi+QsUaRNl8WL5RoA+Bp086yIeGBOrD8Bz/vNr55psf6aQ9j73T7KlXHRaVyoYa NV84Cthd10uBB9KuNhzz4gwUo34bx3BA3piAwbyK8vg+7CMUwVpW8fVykseeg7RlETKR QOHkCXNFhRCpt6xdcZ5gzyMnlFa5dctWq8QCo5KI75CD/t5F4wzVBQG4ycdqYkMCf60R 9l2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=9qPwuueNZm/jcjcA5mRF9P33JC4lKfZl/P5JBTr94o4=; b=qya7G7ijhkyGqBnVK327LyZuTY65TB9EtDDV4P/bfr+4T5QVMvXMLIba4BsBEcdZAq z5s576RAcwiS4ZSwBeS09Qs1u7yttdA+oCiYNK0hRatfQzljtEzqK3JqGISwieLggyAT h7XHBJzpzz2w7YLOjAgEMqkV7gK8/4/FNN7ArN3t9ztAHZ3a5A4E18J3rkietURQN3LL iRfGtbsy6GUqHV5Ru/gjq0W6nCdIfUrpa6IMsufV0S5z+9irdJ0YiIvNkhBQN9urI35b Nz1WJP3AkGSotGBZT3mRD+oJA9N9qoOygfsPAUzNePnQpn+llMH92bnKQh0LCGfLDSZE bqTA== X-Gm-Message-State: ACgBeo3JF0eytFm73jeH1GJdRCyfj+cZSv3m/JZXtUA+iFoi4XRCC/Ii h5PZdAuouZG3pJAR2/6rIsFWLaxrK10= X-Google-Smtp-Source: AA6agR6/Et9og/kzf2RoDfeBn3P2dcpIpHBiLBAQgPI/jBOOhd5bkU4Ij8/0yxxVzB/1wSNVwe/n2A== X-Received: by 2002:a05:620a:1026:b0:6b9:7884:1a6c with SMTP id a6-20020a05620a102600b006b978841a6cmr6868039qkk.664.1660159816780; Wed, 10 Aug 2022 12:30:16 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 03/13] cpufreq: Export intel_feature_detect Date: Wed, 10 Aug 2022 15:29:34 -0400 Message-Id: <20220810192944.102135-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 --- v2 export intel_feature_detect with typed pointer Move intel_feature_detect to acpi/cpufreq/cpufreq.h since the declaration now contains struct cpufreq_policy *. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++-- xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index ded0150b3b..b5eb869227 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -340,9 +340,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } -static void cf_check feature_detect(void *info) +void intel_feature_detect(struct cpufreq_policy *policy) { - struct cpufreq_policy *policy = info; unsigned int eax; eax = cpuid_eax(6); @@ -354,6 +353,11 @@ static void cf_check feature_detect(void *info) } } +static void cf_check feature_detect(void *info) +{ + intel_feature_detect((struct cpufreq_policy *)info); +} + static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq, struct acpi_cpufreq_data *data) { diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index a06aa92f62..0f334d2a43 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -243,4 +243,6 @@ int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq); void cpufreq_dbs_timer_suspend(void); void cpufreq_dbs_timer_resume(void); +void intel_feature_detect(struct cpufreq_policy *policy); + #endif /* __XEN_CPUFREQ_PM_H__ */ From patchwork Wed Aug 10 19:29:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8A3E4C25B07 for ; Wed, 10 Aug 2022 19:30:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383878.619121 (Exim 4.92) (envelope-from ) id 1oLrPM-00075d-GK; Wed, 10 Aug 2022 19:30:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383878.619121; Wed, 10 Aug 2022 19:30:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPM-00075J-C3; Wed, 10 Aug 2022 19:30:24 +0000 Received: by outflank-mailman (input) for mailman id 383878; Wed, 10 Aug 2022 19:30:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPL-0005rf-3O for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:23 +0000 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [2607:f8b0:4864:20::829]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id df53c7b2-18e2-11ed-bd2e-47488cf2e6aa; Wed, 10 Aug 2022 21:30:21 +0200 (CEST) Received: by mail-qt1-x829.google.com with SMTP id y18so1880286qtv.5 for ; Wed, 10 Aug 2022 12:30:21 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:18 -0700 (PDT) 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: df53c7b2-18e2-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=jO9XMqeKcSpPkx9F4IM717CUVIYEi9EqWDYU/rzhTS0=; b=QOt7cUYBZJqmsFGp43FBhVtWSxsRzBGDfC0NCp3LaYlJaqBn6hg1noBnX1U3AYcZjm oKxhLSyaCEVChpMvOETi8inV53A7YyVyJ5RoOl+Kq3qMAuWSJJ5HjNAXw+JTgssB0xT5 qvoS5pjOWTrpq1AD7+VpgHVIvQVw3lfDloJRCOPwlYLjgD8EWmb6JTpPvI/aUPTBRJIo 6Z8EPor0LV4+/bw/bNc3Zt2nyhauicslcUC1gfjUsSW4O+L8cij29Nv45SwSCwZBRQEi LYftu7P3bUU50vkiLHxkzdYBMxSydSUcx6rreWA0TgiPuY1c1zghVJIc0XO2o+jdHlnY WPSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=jO9XMqeKcSpPkx9F4IM717CUVIYEi9EqWDYU/rzhTS0=; b=yuQny7KM8MffoopI/wS25hQv7cfFdqPUTQKCFTLnrKhB3T6N9ZVDz5DmLc6WYNXUJX zCoxIQKmO7JflXsFg25F14kUjVw6ujZSf+0FiAcG4lLC8nO7J7uhu1pbOI4uT1LlwUTH W0S12n6OjGJ+nolttlG5xmNQCPGtSs+WiHTc8cOphJnMHukSBgOu/6Ly35Hc5Bny866f Gvo0D5wEoq7HPdVF9Ou4VAuBfn+TZIadhqAzsXd7nyIgbvYdmeOVz6EMGWJb7pk5ep2i fFchg/ZcRER9X9CQwgHbwrjRgD1haWttwqwYhd6/TNCUopMRjB9ewGOqU8LjGpQQuYLX 66OA== X-Gm-Message-State: ACgBeo1eXyrahYBNc+TA2dQvx+VRLbhbvrp8BZjU/IpOMETsfylkFefj /sf3KS8bIHL7GgJNG6qLwZgcB5BxN6U= X-Google-Smtp-Source: AA6agR7BmVnnkfyVRD6UMjBOIf0t8Vc9ybTPqd1ruaxG78toIKqZz1xc/qDhT+xKuwCGNS6D8C+CJQ== X-Received: by 2002:ac8:5a16:0:b0:342:f905:bdf2 with SMTP id n22-20020ac85a16000000b00342f905bdf2mr13956377qta.364.1660159819512; Wed, 10 Aug 2022 12:30:19 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 04/13] cpufreq: Add Hardware P-State (HWP) driver Date: Wed, 10 Aug 2022 15:29:35 -0400 Message-Id: <20220810192944.102135-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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. cpufreq=xen:hwp enables and cpufreq=xen:hwp=0 disables. The same for hdc. There is no interface to configure - xen_sysctl_pm_op/xenpm will be to be extended to configure in subsequent patches. It will run with the default values, which should be the default 0x80 (out of 0x0-0xff) energy/performance preference. Unscientific powertop measurement of an mostly idle, customized OpenXT install: A 10th gen 6-core laptop showed battery discharge drop from ~9.x to ~7.x watts. A 8th gen 4-core laptop dropped from ~10 to ~9 Power usage depends on many factors, especially display brightness, but this does show 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. While adding to the xen-command-line.pandoc entry, un-nest verbose from minfreq. They are independent. 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. My 8th & 10th gen test systems both report: (XEN) HWP: 1 notify: 1 act_window: 1 energy_perf: 1 pkg_level: 0 peci: 0 (XEN) HWP: Hardware Duty Cycling (HDC) supported (XEN) HWP: HW_FEEDBACK not supported IA32_ENERGY_PERF_BIAS has not been tested. For cpufreq=xen:hwp, placing the option inside the governor wouldn't work. Users would have to select the hwp-internal governor to turn off hwp support. hwp-internal isn't usable without hwp, and users wouldn't be able to select a different governor. That doesn't matter while hwp defaults off, but it would if or when hwp defaults to enabled. We can't use parse_boolean() since it requires a single name=val string and cpufreq_handle_common_option is provided two strings. Use parse_bool() and manual handle no-hwp. Write to disable the interrupt - the linux pstate driver does this. We don't use the interrupts, so we can just turn them off. We aren't ready to handle them, so we don't want any. Unclear if this is necessary. SDM says it's default disabled. FAST_IA32_HWP_REQUEST was removed in v2. The check in v1 was wrong, it's a model specific feature and the CPUID bit is only available after enabling via the MSR. Support was untested since I don't have hardware with the feature. Writes are expected to be infrequent, so just leave it out. --- v2: Alphabetize headers Re-work driver registration name hwp_drv_data anonymous union "hw" Drop hwp_verbose_cont style cleanups Condense hwp_governor switch hwp_cpufreq_target remove .raw from hwp_req assignment Use typed-pointer in a few functions Pass type to xzalloc Add HWP_ENERGY_PERF_BALANCE/IA32_ENERGY_BIAS_BALANCE defines Add XEN_HWP_GOVERNOR define for "hwp-internal" Capitalize CPUID and MSR defines Change '_' to '-' for energy-perf & act-window Read-modify-write MSRs updates Use FAST_IA32_HWP_REQUEST_MSR_ENABLE define constify pointer in hwp_set_misc_turbo Add space after non-fallthrough break in governor switch Add IA32_ENERGY_BIAS_MASK define Check CPUID_PM_LEAK for energy bias when needed Fail initialization with curr_req = -1 Fold hwp_read_capabilities into hwp_init_msrs Add command line cpufreq=xen:hwp Add command line cpufreq=xen:hdc Use per_cpu for hwp_drv_data pointers Move hwp_energy_perf_bias call into hwp_write_request energy_perf 0 is valid, so hwp_energy_perf_bias cannot be skipped Ensure we don't generate interrupts Remove Fast Write of Uncore MSR Initialize hwp_drv_data from curr_req Use SPDX line instead of license text in hwp.c --- docs/misc/xen-command-line.pandoc | 8 +- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 5 +- xen/arch/x86/acpi/cpufreq/hwp.c | 506 ++++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 13 +- xen/arch/x86/include/asm/msr-index.h | 13 + xen/drivers/cpufreq/cpufreq.c | 32 ++ xen/include/acpi/cpufreq/cpufreq.h | 3 + xen/include/acpi/cpufreq/processor_perf.h | 3 + xen/include/public/sysctl.h | 1 + 10 files changed, 581 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 fa56e880b3..2ac5b8f5aa 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -492,7 +492,7 @@ If set, force use of the performance counters for oprofile, rather than detectin available support. ### cpufreq -> `= none | {{ | xen } [:[powersave|performance|ondemand|userspace][,][,[][,[verbose]]]]} | dom0-kernel` +> `= none | {{ | xen } [:[powersave|performance|ondemand|userspace][,][,[]][,[]][,[]][,[verbose]]]} | dom0-kernel` > Default: `xen` @@ -503,6 +503,12 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. * `` and `` are integers which represent max and min processor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=` +* `` is a boolean to enable Hardware-Controlled Performance States (HWP) + on supported Intel hardware. HWP is a Skylake+ feature which provides better + CPU power management. The default is disabled. +* `` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables the + processor to autonomously force physical package components into idle state. + The default is enabled, but the option only applies when `` is enabled. ### cpuid (x86) > `= List of comma separated booleans` diff --git a/xen/arch/x86/acpi/cpufreq/Makefile b/xen/arch/x86/acpi/cpufreq/Makefile index f75da9b9ca..db83aa6b14 100644 --- a/xen/arch/x86/acpi/cpufreq/Makefile +++ b/xen/arch/x86/acpi/cpufreq/Makefile @@ -1,2 +1,3 @@ obj-y += 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 b5eb869227..baafaf9b90 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -643,7 +643,10 @@ static int __init cf_check cpufreq_driver_init(void) switch ( boot_cpu_data.x86_vendor ) { case X86_VENDOR_INTEL: - ret = cpufreq_register_driver(&acpi_cpufreq_driver); + if ( hwp_available() ) + ret = hwp_register_driver(); + else + ret = cpufreq_register_driver(&acpi_cpufreq_driver); break; case X86_VENDOR_AMD: diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c new file mode 100644 index 0000000000..405cbae334 --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -0,0 +1,506 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * hwp.c cpufreq driver to run Intel Hardware P-States (HWP) + * + * Copyright (C) 2021 Jason Andryuk + */ + +#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; + +__initdata bool opt_cpufreq_hwp = false; +__initdata bool opt_cpufreq_hdc = true; + +#define HWP_ENERGY_PERF_BALANCE 0x80 +#define IA32_ENERGY_BIAS_BALANCE 0x7 +#define IA32_ENERGY_BIAS_MAX_POWERSAVE 0xf +#define IA32_ENERGY_BIAS_MASK 0xf + +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 highest:8; + uint64_t guaranteed:8; + uint64_t most_efficient:8; + uint64_t lowest:8; + uint64_t reserved:32; + } hw; + }; + union hwp_request curr_req; + uint16_t activity_window; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; +DEFINE_PER_CPU_READ_MOSTLY(struct hwp_drv_data *, hwp_drv_data); + +#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__); \ +}) + +static int cf_check hwp_governor(struct cpufreq_policy *policy, + unsigned int event) +{ + int ret; + + if ( policy == NULL ) + return -EINVAL; + + switch ( event ) + { + case CPUFREQ_GOV_START: + case CPUFREQ_GOV_LIMITS: + ret = 0; + break; + + case CPUFREQ_GOV_STOP: + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static struct cpufreq_governor hwp_cpufreq_governor = +{ + .name = XEN_HWP_GOVERNOR, + .governor = hwp_governor, +}; + +static int __init cpufreq_gov_hwp_init(void) +{ + return cpufreq_register_governor(&hwp_cpufreq_governor); +} +__initcall(cpufreq_gov_hwp_init); + +bool __init hwp_available(void) +{ + unsigned int eax, ecx, unused; + 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; + } + + 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; + } + + cpuid(CPUID_PM_LEAF, &eax, &unused, &ecx, &unused); + + if ( !(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE) && + !(ecx & CPUID6_ECX_IA32_ENERGY_PERF_BIAS) ) + { + hwp_verbose("HWP disabled: No energy/performance preference available"); + return false; + } + + 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 ) + return false; + + feature_hdc = eax & CPUID6_EAX_HDC; + + hwp_verbose("HWP: Hardware Duty Cycling (HDC) %ssupported%s\n", + feature_hdc ? "" : "not ", + feature_hdc ? opt_cpufreq_hdc ? ", enabled" : ", disabled" + : ""); + + feature_hdc = feature_hdc && opt_cpufreq_hdc; + + hwp_verbose("HWP: HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + use_hwp = feature_hwp && opt_cpufreq_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; + } + + if ( val ) + msr |= IA32_PKG_HDC_CTL_HDC_PKG_ENABLE; + else + msr &= ~IA32_PKG_HDC_CTL_HDC_PKG_ENABLE; + + 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; + } + + if ( val ) + msr |= IA32_PM_CTL1_HDC_ALLOW_BLOCK; + else + msr &= ~IA32_PM_CTL1_HDC_ALLOW_BLOCK; + + if ( wrmsr_safe(MSR_IA32_PM_CTL1, msr) ) + hwp_err("error wrmsr_safe(MSR_IA32_PM_CTL1): %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 cf_check hwp_init_msrs(void *info) +{ + struct cpufreq_policy *policy = info; + struct hwp_drv_data *data = this_cpu(hwp_drv_data); + uint64_t val; + + /* + * Package level MSR, but we don't have a good idea of packages here, so + * just do it everytime. + */ + if ( rdmsr_safe(MSR_IA32_PM_ENABLE, val) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_PM_ENABLE)\n", policy->cpu); + data->curr_req.raw = -1; + return; + } + + /* Ensure we don't generate interrupts */ + if ( feature_hwp_notification ) + wrmsr_safe(MSR_IA32_HWP_INTERRUPT, 0); + + 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); + data->curr_req.raw = -1; + return; + } + } + + if ( rdmsr_safe(MSR_IA32_HWP_CAPABILITIES, data->hwp_caps) ) + { + hwp_err("CPU%u: error rdmsr_safe(MSR_IA32_HWP_CAPABILITIES)\n", + policy->cpu); + data->curr_req.raw = -1; + 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); + data->curr_req.raw = -1; + return; + } + + if ( !feature_hwp_energy_perf ) { + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, val) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + data->curr_req.raw = -1; + + return; + } + + data->energy_perf = val & IA32_ENERGY_BIAS_MASK; + } + + /* + * 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); + } + + hwp_get_cpu_speeds(policy); +} + +static int cf_check hwp_cpufreq_verify(struct cpufreq_policy *policy) +{ + struct hwp_drv_data *data = per_cpu(hwp_drv_data, policy->cpu); + + if ( !feature_hwp_energy_perf && data->energy_perf ) + { + if ( data->energy_perf > IA32_ENERGY_BIAS_MAX_POWERSAVE ) + { + 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(const struct hwp_drv_data *data) +{ + uint64_t msr; + uint8_t val = data->energy_perf; + + ASSERT(val <= IA32_ENERGY_BIAS_MAX_POWERSAVE); + + if ( rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS, msr) ) + { + hwp_err("error rdmsr_safe(MSR_IA32_ENERGY_PERF_BIAS)\n"); + + return; + } + + msr &= ~IA32_ENERGY_BIAS_MASK; + 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 cf_check hwp_write_request(void *info) +{ + struct cpufreq_policy *policy = info; + struct hwp_drv_data *data = this_cpu(hwp_drv_data); + 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); + } + + if ( !feature_hwp_energy_perf ) + hwp_energy_perf_bias(data); + +} + +static int cf_check hwp_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + unsigned int cpu = policy->cpu; + struct hwp_drv_data *data = per_cpu(hwp_drv_data, cpu); + /* Zero everything to ensure reserved bits are zero... */ + union hwp_request 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 = hwp_req; + + hwp_verbose("CPU%u: wrmsr HWP_REQUEST %016lx\n", cpu, hwp_req.raw); + on_selected_cpus(cpumask_of(cpu), hwp_write_request, policy, 1); + + return 0; +} + +static int cf_check hwp_cpufreq_cpu_init(struct cpufreq_policy *policy) +{ + unsigned int cpu = policy->cpu; + struct hwp_drv_data *data; + + data = xzalloc(struct hwp_drv_data); + if ( !data ) + return -ENOMEM; + + 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; + + per_cpu(hwp_drv_data, cpu) = data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + if ( data->curr_req.raw == -1 ) + { + hwp_err("CPU%u: Could not initialize HWP properly\n", cpu); + XFREE(per_cpu(hwp_drv_data, cpu)); + return -ENODEV; + } + + data->minimum = data->curr_req.min_perf; + data->maximum = data->curr_req.max_perf; + data->desired = data->curr_req.desired; + /* the !feature_hwp_energy_perf case was handled in hwp_init_msrs(). */ + if ( feature_hwp_energy_perf ) + data->energy_perf = data->curr_req.energy_perf; + + 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 cf_check hwp_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ + XFREE(per_cpu(hwp_drv_data, policy->cpu)); + + 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 cf_check hwp_set_misc_turbo(void *info) +{ + const 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 cf_check 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 __init hwp_register_driver(void) +{ + return cpufreq_register_driver(&hwp_cpufreq_driver); +} diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/asm/cpufeature.h index f2c6f255ac..1aebf3f750 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -22,8 +22,17 @@ #define cpu_has(c, bit) test_bit(bit, (c)->x86_capability) #define boot_cpu_has(bit) test_bit(bit, boot_cpu_data.x86_capability) -#define CPUID_PM_LEAF 6 -#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#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_HW_FEEDBACK (_AC(1, U) << 19) +#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID6_ECX_IA32_ENERGY_PERF_BIAS 0x8 /* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/asm/msr-index.h index 1a928ea6af..3961bac614 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -147,6 +147,13 @@ #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_INTERRUPT 0x00000773 +#define MSR_IA32_HWP_REQUEST 0x00000774 + #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff @@ -161,6 +168,11 @@ #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_UARCH_MISC_CTRL 0x00001b01 #define UARCH_CTRL_DOITM (_AC(1, ULL) << 0) @@ -496,6 +508,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 diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 1fdd63d7b5..634f0a8a49 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -563,6 +563,38 @@ static void cpufreq_cmdline_common_para(struct cpufreq_policy *new_policy) static int __init cpufreq_handle_common_option(const char *name, const char *val) { + if (!strcmp(name, "hdc")) { + if (val) { + int ret = parse_bool(val, NULL); + if (ret != -1) { + opt_cpufreq_hdc = ret; + return 1; + } + } else { + opt_cpufreq_hdc = true; + return 1; + } + } else if (!strcmp(name, "no-hdc")) { + opt_cpufreq_hdc = false; + return 1; + } + + if (!strcmp(name, "hwp")) { + if (val) { + int ret = parse_bool(val, NULL); + if (ret != -1) { + opt_cpufreq_hwp = ret; + return 1; + } + } else { + opt_cpufreq_hwp = true; + return 1; + } + } else if (!strcmp(name, "no-hwp")) { + opt_cpufreq_hwp = false; + return 1; + } + if (!strcmp(name, "maxfreq") && val) { usr_max_freq = simple_strtoul(val, NULL, 0); return 1; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index 0f334d2a43..29a712a4f1 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -245,4 +245,7 @@ void cpufreq_dbs_timer_resume(void); void intel_feature_detect(struct cpufreq_policy *policy); +extern bool opt_cpufreq_hwp; +extern bool opt_cpufreq_hdc; + #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/cpufreq/processor_perf.h index d8a1ba68a6..b751ca4937 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -7,6 +7,9 @@ #define XEN_PX_INIT 0x80000000 +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/public/sysctl.h b/xen/include/public/sysctl.h index 5672906729..3d6dd14377 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -316,6 +316,7 @@ struct xen_ondemand { uint32_t up_threshold; }; +#define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named * same as sysfs file name of native linux From patchwork Wed Aug 10 19:29:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 53ABDC00140 for ; Wed, 10 Aug 2022 19:30:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383879.619127 (Exim 4.92) (envelope-from ) id 1oLrPN-00079n-0S; Wed, 10 Aug 2022 19:30:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383879.619127; Wed, 10 Aug 2022 19:30:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPM-00078l-NM; Wed, 10 Aug 2022 19:30:24 +0000 Received: by outflank-mailman (input) for mailman id 383879; Wed, 10 Aug 2022 19:30:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPL-00067E-IQ for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:23 +0000 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [2607:f8b0:4864:20::f2c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e03a6b5e-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:22 +0200 (CEST) Received: by mail-qv1-xf2c.google.com with SMTP id l18so11710839qvt.13 for ; Wed, 10 Aug 2022 12:30:22 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:20 -0700 (PDT) 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: e03a6b5e-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=rqMgcE4Oac0416vvAOiMSA4SrnvTMeuV9YAjTBvnyLM=; b=c1RoHlkCEWondmxQPEyoI0ZUa88s/sfMV7IFD3o1eO5ibI6vDW5UOqB3+rR29Vfd9X uJOnOE31Idn+uWnR1eh5ApWDAcJvn9ZzwN5x4yABO7IlUMRo88Xv27SDhelVOgI0fyt7 7XTcf5DI2/I0kWo91UVcH/bin5EOk6bOi4krcpPMx0lFSEwct2LqbCSgvPx+W9sfGOpB 6EnHlHR0lVGhWJyGGAdNRCjzgEcg/Mv4Y9z9IapK2gqTmtWn/J0dtC+rUIw/ZTg6E5eA preSsXc2WFKBuAflenTeDF9l9B226naJ8VRClCsM4TySxAQyRwZvG5IDbvPGQ7Rq5r3R npOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=rqMgcE4Oac0416vvAOiMSA4SrnvTMeuV9YAjTBvnyLM=; b=FRguijjFv2UqmPW1j2vPuF4ueIXaV617lcUn6/gVxRjRvf4dFYEkr/z2/LrqS3ekgc 1kggzxGzIkpXn6GHJpnk0kNZtvR3p/FZyaybzwHrDT91tvByXMDEU//q4EthB/JrnnvV UTPyQGBoXvIj273479hW08pJTL7A1O9iIAE3iK1LIjLNdRBQSHgo7SfOxc0FUFP/LUfg X1AMlQMHg4jjDYk84qMS7OZ8y2NJEMkw/5d+o3lImtNFquTxVqR9tvfMbVceMlOKZXtV KDw+s+U2Xb5YBfquP3nCMJTz/nwUNYuvs0ejlCDXiYhye2AgZsqfJVg1p+iolNO5o7ut C2BA== X-Gm-Message-State: ACgBeo0NTuazqNdu09y2TY7KjlJP1mKYVBfKesING7QVdbP6YMW8qk4m XWgSIMQyzZUETMdUTwPfFuFFJExTLgE= X-Google-Smtp-Source: AA6agR5zmnvx/9hysTrDH3OmwaYLu83NMOvLqj3obI+NldcUtFs6ywO20hZPDCPlhkSSiaQROmmtTQ== X-Received: by 2002:a05:6214:23ca:b0:474:8c8:4fdf with SMTP id hr10-20020a05621423ca00b0047408c84fdfmr25321370qvb.89.1660159821373; Wed, 10 Aug 2022 12:30:21 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v2 05/13] xenpm: Change get-cpufreq-para output for internal Date: Wed, 10 Aug 2022 15:29:36 -0400 Message-Id: <20220810192944.102135-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 --- v2: Use full governor name XEN_HWP_GOVERNOR to change output Style fixes --- tools/misc/xenpm.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 4f8cde690a..179f9f1f96 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, XEN_HWP_GOVERNOR); int i; printf("cpu id : %d\n", cpuid); @@ -720,10 +721,15 @@ 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 +756,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 Wed Aug 10 19:29:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7DC81C00140 for ; Wed, 10 Aug 2022 19:30:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383880.619142 (Exim 4.92) (envelope-from ) id 1oLrPO-0007bm-J4; Wed, 10 Aug 2022 19:30:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383880.619142; Wed, 10 Aug 2022 19:30:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPO-0007aE-D0; Wed, 10 Aug 2022 19:30:26 +0000 Received: by outflank-mailman (input) for mailman id 383880; Wed, 10 Aug 2022 19:30:25 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPN-00067E-NL for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:25 +0000 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [2607:f8b0:4864:20::f2a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e16f4b30-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:24 +0200 (CEST) Received: by mail-qv1-xf2a.google.com with SMTP id j11so11706649qvt.10 for ; Wed, 10 Aug 2022 12:30:24 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:22 -0700 (PDT) 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: e16f4b30-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=oNA3OUefEtpoG+cuOAW7lfiq629QCTVrL+PJWqyEDAU=; b=h9zUJXTkGdYO0GMd0SimjPJDn7vqpELKtdImO3vNhMX2MuY3hszB5Pj+J+F6px5kiB gbZK9cmbdGiKNXFm5HK9dRKj+56l1VGVmd8Z/ilIPtluoUYsec9RGNCiPZf44PlCiRad jzFaM7xNGCWwF4oKBtpCcySFNRm/gd4tXayiROi6bZrOAtxRPTIyQypXGbQ8fE1boVEg H9AZ/Lx563a5xujFzbMMf5nEWaD4caQntveXCsmNFkLlhfRXt0vRGWbLHbwirU2KJ5Qu LpDbVzwBmnfAbFKDUMjgkScgzUDJKSGhDdWzDifMV9SE5/beAbP+luLNpKlxNNzC8c/J XtXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=oNA3OUefEtpoG+cuOAW7lfiq629QCTVrL+PJWqyEDAU=; b=21VdFZWkqMPvZBgf/rHpDPB81eohaADlWDSB87UK6WU1icC9ZXtNhh6F3HsocuwpDD 5lMuddt7a5pBzJFBrzf+Hhyl7SWVQ/9MLs8/THGf8fT/38ZBy6k7uvSNDwbbnw6uIEaM YgUU8Om1TKlloyuefOuxKnMW1iAsg/bZIcJFp2LTIVIUw4Up9Bg0zlcM8B2G/AVCvC7F OEAendKe9kXx1a6BK+wK/EMNTe/RFlEQJsxDdHA8/F1XbYCWdNoI0Q821/aRZIK/Agoa Cz4dngM9z7ghw+tm7oULiX1ojbiTKoaMua1WJa9WSeW4HCzKHo+QHcixNWX0mO0Unc9w A39A== X-Gm-Message-State: ACgBeo2DnWrS7vNVaLk4yrE5NSTwt2O2Yq6vPAFyLrBho6xx9mOiXsIo mbjlr2FMf1uMqObvKboSXsH5JwMguac= X-Google-Smtp-Source: AA6agR597Y3Z1Db2tIHP+bgACUqju5yRmkN2rOmAbGPHe4lw+QIIFKOWssCXmwUtFYFyMKFYspglmw== X-Received: by 2002:a05:6214:e41:b0:473:915c:3efe with SMTP id o1-20020a0562140e4100b00473915c3efemr25215103qvc.10.1660159823436; Wed, 10 Aug 2022 12:30:23 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v2 06/13] cpufreq: Export HWP parameters to userspace Date: Wed, 10 Aug 2022 15:29:37 -0400 Message-Id: <20220810192944.102135-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 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. Signed-off-by: Jason Andryuk --- v2: Style fixes Don't bump XEN_SYSCTL_INTERFACE_VERSION Drop cpufreq.h comment divider Expand xen_hwp_para comment Add HWP activity window mantissa/exponent defines Handle union rename Add const to get_hwp_para Remove hw_ prefix from xen_hwp_para members Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 25 +++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 5 +++++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ xen/include/public/sysctl.h | 26 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c index 405cbae334..233089b6c9 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -500,6 +500,31 @@ static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver = .update = hwp_cpufreq_update, }; +int get_hwp_para(const struct cpufreq_policy *policy, + struct xen_hwp_para *hwp_para) +{ + unsigned int cpu = policy->cpu; + const struct hwp_drv_data *data = per_cpu(hwp_drv_data, cpu); + + if ( data == NULL ) + return -EINVAL; + + hwp_para->features = + (feature_hwp_activity_window ? XEN_SYSCTL_HWP_FEAT_ACT_WINDOW : 0) | + (feature_hwp_energy_perf ? XEN_SYSCTL_HWP_FEAT_ENERGY_PERF : 0); + hwp_para->lowest = data->hw.lowest; + hwp_para->most_efficient = data->hw.most_efficient; + hwp_para->guaranteed = data->hw.guaranteed; + hwp_para->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 __init hwp_register_driver(void) { return cpufreq_register_driver(&hwp_cpufreq_driver); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 1bae635101..67fd9dabd4 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -290,6 +290,11 @@ 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 ( !strncasecmp(op->u.get_para.scaling_governor, XEN_HWP_GOVERNOR, + 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 29a712a4f1..92b4c7e79c 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -247,5 +247,7 @@ void intel_feature_detect(struct cpufreq_policy *policy); extern bool opt_cpufreq_hwp; extern bool opt_cpufreq_hdc; +int get_hwp_para(const 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 3d6dd14377..12a7a7db29 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -316,6 +316,31 @@ struct xen_ondemand { uint32_t up_threshold; }; +struct xen_hwp_para { + /* + * bits 6:0 - 7bit mantissa + * bits 9:7 - 3bit base-10 exponent + * btis 15:10 - Unused - must be 0 + */ +#define HWP_ACT_WINDOW_MANTISSA_MASK 0x7f +#define HWP_ACT_WINDOW_EXPONENT_MASK 0x7 +#define HWP_ACT_WINDOW_EXPONENT_SHIFT 7 + uint16_t activity_window; + /* energy_perf range 0-255 if 1. Otherwise 0-15 */ +#define XEN_SYSCTL_HWP_FEAT_ENERGY_PERF (1 << 0) + /* activity_window supported if 1 */ +#define XEN_SYSCTL_HWP_FEAT_ACT_WINDOW (1 << 1) + uint8_t features; /* bit flags for features */ + uint8_t lowest; + uint8_t most_efficient; + uint8_t guaranteed; + uint8_t highest; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; + #define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named @@ -348,6 +373,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 Wed Aug 10 19:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6A5EBC00140 for ; Wed, 10 Aug 2022 19:30:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383883.619154 (Exim 4.92) (envelope-from ) id 1oLrPS-00087D-4B; Wed, 10 Aug 2022 19:30:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383883.619154; Wed, 10 Aug 2022 19:30:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPR-00086e-UP; Wed, 10 Aug 2022 19:30:29 +0000 Received: by outflank-mailman (input) for mailman id 383883; Wed, 10 Aug 2022 19:30:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPQ-00067E-92 for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:28 +0000 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [2607:f8b0:4864:20::732]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e3184711-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:27 +0200 (CEST) Received: by mail-qk1-x732.google.com with SMTP id c28so2850004qko.9 for ; Wed, 10 Aug 2022 12:30:27 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:25 -0700 (PDT) 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: e3184711-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=NQrN8k420cCh2Whj4lm6iBK+XOd3RM9/GZQ5kCWEzI8=; b=HLdIwGXHmwGnGDAJ3JX6fFs+egLvXpMNZxno9hqkr3M9GrcC6pDbmkbvmuqhXJdUvp OKAr4LmY9KMODQZwk83Ru7V7yJz0GqBdl9m8us6RPwhEYhBFM1UkBhxrH5PuTW9VVZeA hj8ZOkfHn8IW5ij8or1eoAAmnER25KcIBzxG0/3KuVgR2akhp9Tr1iEN5bznvhsVPfEP wGDFdpAT/0v4JPjz1eh/JW3A5fSwqnaVNg+cEW8dhoPyGREYv8rjcTrBBFWcgHr0xeBF eWE3XyMqBj0u6SoJC2+rCIeaK+LeE3Lc30OznZ62v96BWRmQvcsUnh9upvUJQqQLM/tR 5xtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=NQrN8k420cCh2Whj4lm6iBK+XOd3RM9/GZQ5kCWEzI8=; b=GtgZ1t6xvy+ZG7U8A0gGYPM4cMtuDarmj6BjUHSwIrwpEYOShOXvWbOx3agvOYIfEX lgVFL96g2dLgWidM0X3fwmjeeQYHvm9NlEWgz3I5JVymRQH1DtrjOEZEuVyqn1dVKyv9 j+1HWw/nm8y3+50qwdmBz/pzuUQzjyImotilF88pcdDE5kAQNcNHKtoh1gtPD6sQUG6K M+DwHLD5Z/AHr8CxZVOzjcFqB9xEgoJzE3iSAMWP2NRdCaQFuZsWgqXPcYNc0vn6eskq wJB7klE/gj6M2GS6LXRCUJeb3AmvXu81nK3AW1KtF0NBM2nCaVwxLbxpahzkia7qRGe7 0DUg== X-Gm-Message-State: ACgBeo0Nz8HSQ4rqeOvYbonDNbNRRSK7S1Ja0b9KP7VArI2OG93vlINT ed0UFU3Z1xO177yPk1qasedS5/yee6I= X-Google-Smtp-Source: AA6agR4/b6vChHirTVxjRR7Za7Z/b8B31vpq4Bd4hDp1FXSpeyAGg/EYyp8Url+AwzrsWgXO8lIzTA== X-Received: by 2002:a05:620a:2451:b0:6b9:ab33:64c3 with SMTP id h17-20020a05620a245100b006b9ab3364c3mr2581738qkn.565.1660159826228; Wed, 10 Aug 2022 12:30:26 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v2 07/13] libxc: Include hwp_para in definitions Date: Wed, 10 Aug 2022 15:29:38 -0400 Message-Id: <20220810192944.102135-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 0c8b4c3aa7..9586eca4c0 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1900,6 +1900,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 */ @@ -1927,6 +1928,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 Wed Aug 10 19:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2E811C25B07 for ; Wed, 10 Aug 2022 19:30:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383888.619165 (Exim 4.92) (envelope-from ) id 1oLrPU-00004u-G1; Wed, 10 Aug 2022 19:30:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383888.619165; Wed, 10 Aug 2022 19:30:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPU-0008WK-BC; Wed, 10 Aug 2022 19:30:32 +0000 Received: by outflank-mailman (input) for mailman id 383888; Wed, 10 Aug 2022 19:30:30 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPS-00067E-86 for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:30 +0000 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [2607:f8b0:4864:20::82d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e434f504-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:29 +0200 (CEST) Received: by mail-qt1-x82d.google.com with SMTP id u12so12038470qtk.0 for ; Wed, 10 Aug 2022 12:30:29 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:27 -0700 (PDT) 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: e434f504-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=7bEttMh9VcsUlhPn8Yy1aX7Mn4PrqipA69uGmY68abY=; b=BwZyp+rsgJfUcUV4cG+PUd6wrTbHzbvEVC0JAen+uOJRCo6WANJLf5J/fDiwzm1pfE U7HTa5ToaHo1WKZVt2lb69gzA2NU3p1kzQ3NTDGainYHzWlly1gsAQFQEnaOc/vQ9wgR p5O/fOtrkxXTjTsMcsOdShFLjtAZRUfxdnOS1tVpqwdfA4QNvLhQZ7el1C1O2/zywO4p IKamJOf5E8nopP4EV8hXbgh7RmIkFOZbx6wKL3e62zHMrhY2/lizXG4guKiGp/9jQmSv ioHoMqM4t3owkdDyJrnS+njzmuVtMzkctSuRb0hiz+PlqNS/YiybrqLsV8H+vClWIjMH wldA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=7bEttMh9VcsUlhPn8Yy1aX7Mn4PrqipA69uGmY68abY=; b=sta73nWEni/3JAe5lbJXyqzOtZs91g9smzPQyk4cF5klsOwYWaVObQBJRQLgJflgYq x/RbhNQ38SoKJ1X/coZRJsufuj0KwyifgLh8xwE3Ig36HdhIMo0g2Zp6LQMKcL1rhnxy npBGRLsvrzJ9d9FPWpKBtJMw6/M45Y45So5A6CdpX2uTK0aVdQpYfUL5Ye2ipZcPV1SG UQ3bKf++UGHiGkXMVf5ZODAInD7VSpmxjySgB34RhlxFuUqWi3cE22fY8+6PwmE4Fl5P ZpCO/q8+Mw5H7/rtX537gbQrP8aybGAt+1CKAMTigB36RY4sUIpYnOtKw8u3netjNRXX WAeg== X-Gm-Message-State: ACgBeo0bFj4HnDm8sNkmY73utSf7QjNI00AB3Zn6SJG55ZrSiyHT8sGA rw0xn9AhZKXjk0W615ueB4dGVjSdyU8= X-Google-Smtp-Source: AA6agR7R3cf12ooaUePc+sYsLFBnL4fRmb64u+qopKpUNVUQB+R8UbRr+vZ8vPmykcmAvFjs44e5YA== X-Received: by 2002:ac8:5882:0:b0:343:648d:5a00 with SMTP id t2-20020ac85882000000b00343648d5a00mr285819qta.636.1660159828163; Wed, 10 Aug 2022 12:30:28 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v2 08/13] xenpm: Print HWP parameters Date: Wed, 10 Aug 2022 15:29:39 -0400 Message-Id: <20220810192944.102135-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 --- v2: Style fixes Declare i outside loop Replace repearted hardware/configured limits with spaces Fixup for hw_ removal Use XEN_HWP_GOVERNOR Use HWP_ACT_WINDOW_EXPONENT_* Remove energy_perf hw autonomous - 0 doesn't mean autonomous --- tools/misc/xenpm.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 179f9f1f96..610a516213 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -708,6 +708,44 @@ 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 & HWP_ACT_WINDOW_MANTISSA_MASK; + unsigned int exponent = + (hwp->activity_window >> HWP_ACT_WINDOW_EXPONENT_SHIFT) & + HWP_ACT_WINDOW_EXPONENT_MASK; + unsigned int multiplier = 1; + unsigned int i; + + 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 ( 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) { @@ -773,6 +811,33 @@ 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, XEN_HWP_GOVERNOR) == 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->lowest, hwp->most_efficient); + printf(" : guaranteed [%u] highest [%u]\n", + hwp->guaranteed, hwp->highest); + printf(" configured limits : min [%u] max [%u] energy_perf [%u]\n", + hwp->minimum, hwp->maximum, hwp->energy_perf); + + if ( hwp->features & XEN_SYSCTL_HWP_FEAT_ACT_WINDOW ) + { + unsigned int activity_window; + const char *units; + + calculate_hwp_activity_window(hwp, &activity_window, &units); + printf(" : activity_window [%u %s]\n", + activity_window, units); + } + + printf(" : 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 Wed Aug 10 19:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8D796C25B06 for ; Wed, 10 Aug 2022 19:30:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383893.619176 (Exim 4.92) (envelope-from ) id 1oLrPW-0000W7-TI; Wed, 10 Aug 2022 19:30:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383893.619176; Wed, 10 Aug 2022 19:30: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 1oLrPW-0000Vk-Os; Wed, 10 Aug 2022 19:30:34 +0000 Received: by outflank-mailman (input) for mailman id 383893; Wed, 10 Aug 2022 19:30:34 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPW-0005rf-2A for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:34 +0000 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [2607:f8b0:4864:20::82d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e5bcb100-18e2-11ed-bd2e-47488cf2e6aa; Wed, 10 Aug 2022 21:30:32 +0200 (CEST) Received: by mail-qt1-x82d.google.com with SMTP id e28so3916602qts.1 for ; Wed, 10 Aug 2022 12:30:32 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:29 -0700 (PDT) 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: e5bcb100-18e2-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=P4DHnPs04M49UGm1RCAoIcdB9bRr1CaBP0xbsg4cF5o=; b=Crxk3M5J3ets7+XOb0sdwE4VxWh+gUIf5a5ZaidWk5CZSxln7toj7dp0umjDEpKpks dOPXniPalO0SHN6wYHQKdXTCSOtROqdJF6Exqvnfr0OaiZ9Hhp/MiBe3007fGv/GkM8l O5EOR+yQRcXk+NQoUy8IOovBd3aofkjY64XGAhkZoGICTnkiPMMrlnRmdHjFWrMcLo5L KkLCoxT/7rxCAvPLmKLWZhXcKR2j5AXmpw7WoiXsXnm8BJ/BmYmBSysKSxUr/Dscd0Gx YtkIAMijb6sShds5pfCCKU45o6IaxiddHikym8t5huzhXrS2UXKL8lcLdIh+5as4kgA1 ggow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=P4DHnPs04M49UGm1RCAoIcdB9bRr1CaBP0xbsg4cF5o=; b=4JWL0PYOCMTeLTn5dXS0SZRh3lrJ36FC3QEFKHzGXqemc4ond8p0GQVPrsBmEKuu5s dMEhaWFfvbF1NmfNwUZsrvbadQUx+K4thijHArJ28kt7q97QTEDsLCwFQ/D671AYOV0R anUXXgYRaUs2CRhnyYU1/Vq/z49O2+umH6EdhvoJi52scH6TFLl51UX9p9tG9DjaSl/n FyprvqT1/EdGIGEuxf45XgL3sefgZzLH6h+xdNDBeF8isyoe8Jc/0WG4sDzswbdrZzCJ rLehUW1cv+BI2dh0SIqNCEtl1iDZMICAJWNfsg91r8sNEr6z04dNfP+vJYt7woCLYn6n uTSw== X-Gm-Message-State: ACgBeo2tO/FCVQefoOPJpxeVZMJ3UQh1A2URwOfSOXI2Z5AXlv0rRx/O ufkS7JYqrw9upw0sOgx5FVVkqjE/lY0= X-Google-Smtp-Source: AA6agR5mPFEwjA1NEpP4R+XOX2tCYNEaGu2dx5jNneksQstJ1gm4udxvsXelcDD/YAp3dmZr/MnL/A== X-Received: by 2002:a05:622a:174e:b0:343:202:4e55 with SMTP id l14-20020a05622a174e00b0034302024e55mr11569015qtk.81.1660159830572; Wed, 10 Aug 2022 12:30:30 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [PATCH v2 09/13] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op Date: Wed, 10 Aug 2022 15:29:40 -0400 Message-Id: <20220810192944.102135-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 (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 --- v2: Update for naming anonymous union Drop hwp_err for invalid input in set_hwp_para() Drop uint16_t cast in XEN_SYSCTL_HWP_SET_PARAM_MASK Drop parens for HWP_SET_PRESET defines Reference activity_window format comment Place SET_CPUFREQ_HWP after SET_CPUFREQ_PARA Add {HWP,IA32}_ENERGY_PERF_MAX_{PERFORMANCE,POWERSAVE} defines Order defines before fields in sysctl.h Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 96 ++++++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 23 +++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 30 ++++++++++ 4 files changed, 151 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c index 233089b6c9..2466933407 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -25,7 +25,9 @@ static bool feature_hdc; __initdata bool opt_cpufreq_hwp = false; __initdata bool opt_cpufreq_hdc = true; +#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 #define HWP_ENERGY_PERF_BALANCE 0x80 +#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff #define IA32_ENERGY_BIAS_BALANCE 0x7 #define IA32_ENERGY_BIAS_MAX_POWERSAVE 0xf #define IA32_ENERGY_BIAS_MASK 0xf @@ -525,6 +527,100 @@ int get_hwp_para(const struct cpufreq_policy *policy, 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 = per_cpu(hwp_drv_data, cpu); + + if ( data == NULL ) + return -EINVAL; + + /* Validate all parameters first */ + if ( set_hwp->set_params & ~XEN_SYSCTL_HWP_SET_PARAM_MASK ) + return -EINVAL; + + if ( set_hwp->activity_window & ~XEN_SYSCTL_HWP_ACT_WINDOW_MASK ) + return -EINVAL; + + if ( !feature_hwp_energy_perf && + (set_hwp->set_params & XEN_SYSCTL_HWP_SET_ENERGY_PERF) && + set_hwp->energy_perf > IA32_ENERGY_BIAS_MAX_POWERSAVE ) + return -EINVAL; + + 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) ) + 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 = HWP_ENERGY_PERF_MAX_POWERSAVE; + else + data->energy_perf = IA32_ENERGY_BIAS_MAX_POWERSAVE; + 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 = HWP_ENERGY_PERF_MAX_PERFORMANCE; + 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; + if ( feature_hwp_energy_perf ) + data->energy_perf = HWP_ENERGY_PERF_BALANCE; + else + data->energy_perf = IA32_ENERGY_BIAS_BALANCE; + data->desired = 0; + break; + + case XEN_SYSCTL_HWP_SET_PRESET_NONE: + break; + + default: + 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 __init hwp_register_driver(void) { return cpufreq_register_driver(&hwp_cpufreq_driver); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 67fd9dabd4..55e2b285b5 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -398,6 +398,25 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op) return ret; } +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 ( strncasecmp(policy->governor->name, XEN_HWP_GOVERNOR, + CPUFREQ_NAME_LEN) ) + return -EINVAL; + + return set_hwp_para(policy, &op->u.set_hwp); +} + int do_pm_op(struct xen_sysctl_pm_op *op) { int ret = 0; @@ -470,6 +489,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } + case SET_CPUFREQ_HWP: + ret = set_cpufreq_hwp(op); + break; + case GET_CPUFREQ_AVGFREQ: { op->u.get_avgfreq = cpufreq_driver_getavg(op->cpuid, USR_GETAVG); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index 92b4c7e79c..b8831b2cd3 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -249,5 +249,7 @@ extern bool opt_cpufreq_hwp; extern bool opt_cpufreq_hdc; int get_hwp_para(const 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 12a7a7db29..08e25e15a6 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -341,6 +341,34 @@ struct xen_hwp_para { uint8_t energy_perf; }; +/* set multiple values simultaneously when set_args bit is set */ +struct xen_set_hwp_para { +#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 ( \ + 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 set_params; /* bitflags for valid values */ +#define XEN_SYSCTL_HWP_ACT_WINDOW_MASK 0x03ff + uint16_t activity_window; /* See comment in struct xen_hwp_para */ + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; /* 0-255 or 0-15 depending on HW support */ +}; + #define XEN_HWP_GOVERNOR "hwp-internal" /* * cpufreq para name of this structure named @@ -403,6 +431,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 @@ -429,6 +458,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 Wed Aug 10 19:29:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id AB15FC25B0C for ; Wed, 10 Aug 2022 19:30:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383895.619186 (Exim 4.92) (envelope-from ) id 1oLrPY-0000si-Kq; Wed, 10 Aug 2022 19:30:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383895.619186; Wed, 10 Aug 2022 19:30:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPY-0000rS-E7; Wed, 10 Aug 2022 19:30:36 +0000 Received: by outflank-mailman (input) for mailman id 383895; Wed, 10 Aug 2022 19:30:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPW-00067E-Sh for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:35 +0000 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [2607:f8b0:4864:20::f2c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e770febe-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:34 +0200 (CEST) Received: by mail-qv1-xf2c.google.com with SMTP id l18so11711228qvt.13 for ; Wed, 10 Aug 2022 12:30:34 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:32 -0700 (PDT) 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: e770febe-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=dLajvGFi/Mcq6cLyHR7My8Hc/MEdmzVTbkF+UN7LfEg=; b=pB5xf/YEQ3P8NLS7h8SXbF4V4sYUUeMsGEYPIFenPb8paOjgeZ/0QBPFHSpO2t0H6a HJ3d1q+KGpQMvuMOao+B4AIIRF921ShjneEBM4WOMdDQG9btDQC9zGyX/eU1wyiLxjNt VENBx0xjLF8/tE2KXCg9QR9L7j6NSmHsubPxm17B+0upYRHaBjfYLYQa98yHMZvC1rXL TnDC3YdQhApMTPHH8jsQp1do6ucwo7nGHI46z+/NqtRuIQFOvJc7sZOqEtp7fk5w2Lh1 PkfAO4Ssupm5OIuXCPS3YfE/405aKoRtXXUHFn354CMHzckx54tsNQxQRiCGxn8KSyQx GZpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=dLajvGFi/Mcq6cLyHR7My8Hc/MEdmzVTbkF+UN7LfEg=; b=wvJv/T7eZ03Jg1QjVs0/zOhEStMWt9V8cUBZCMiJ5xet4nPFhK1BGtYunUrEGFDvhY 3ekr1oj6IJVIzZz5Dl64ova4Sru81wujbByvZdlaVu6i0ElB6rMuy1y4SUPag2Igj+8+ OzH9UPzoCe+4T/0CFqMGk/7Ib5nRu13e6Ln/spwxIIQhXKNv9D+wwzpXPNPqZNX8MdTn a0OgfyjeW5mYqh9Zu8G1Rojx4jXFbf8A4V4kNc21u3afWElX965jzTVVEYzZLEwqQMHd PP/XopEHVAyqw0pqOgugmsxQX2KiDwjRCxwZjO+ESaXY5R/mi6t10bjNYe8kmOpYhHvB uiKw== X-Gm-Message-State: ACgBeo3bdKAgCp3RBc5bk04Z+jjHJK+ZzzEJ04b4xvmtkhVaTXQ5uBOJ 01ysIrSqupbx0Xq9Yot2PDNPUnf2V+k= X-Google-Smtp-Source: AA6agR6AHSo2l4SyRfTLy7dPfWFwKCM7w+4fegiPz5bnDR7LfriyWsMdrF8su5Ldpt6aKhrNUxADLQ== X-Received: by 2002:a05:6214:c25:b0:476:eb9c:fc7b with SMTP id a5-20020a0562140c2500b00476eb9cfc7bmr24850012qvd.108.1660159833498; Wed, 10 Aug 2022 12:30:33 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v2 10/13] libxc: Add xc_set_cpufreq_hwp Date: Wed, 10 Aug 2022 15:29:41 -0400 Message-Id: <20220810192944.102135-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 --- v2: Mark xc_set_hwp_para_t const --- 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 9586eca4c0..2d6c112d44 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1934,11 +1934,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, + const 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..87c636f820 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, + const 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 Wed Aug 10 19:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 59043C00140 for ; Wed, 10 Aug 2022 19:30:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383898.619195 (Exim 4.92) (envelope-from ) id 1oLrPa-0001FW-IZ; Wed, 10 Aug 2022 19:30:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383898.619195; Wed, 10 Aug 2022 19:30: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 1oLrPa-0001DW-20; Wed, 10 Aug 2022 19:30:38 +0000 Received: by outflank-mailman (input) for mailman id 383898; Wed, 10 Aug 2022 19:30:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPY-0005rf-LI for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:36 +0000 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [2607:f8b0:4864:20::82d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id e8749938-18e2-11ed-bd2e-47488cf2e6aa; Wed, 10 Aug 2022 21:30:36 +0200 (CEST) Received: by mail-qt1-x82d.google.com with SMTP id e28so3916803qts.1 for ; Wed, 10 Aug 2022 12:30:35 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:34 -0700 (PDT) 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: e8749938-18e2-11ed-bd2e-47488cf2e6aa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=y+vBMXcv/4DGDDmvZsPT8uzCrAOnCtue/wVF+VShjKg=; b=PPGXS1dOZqj42VzObj0IdiHNnLxQmcwh/dsSPcpXr3rOsqcxlHLsH3hHXmBW9TPyvC estethndHVfIg1qXWb9+T7HqGO4xe0bD6FkJmweoZXrFmPD7D6BtteubqJikkSnXVPrY P4HtAel+xPintYU2didWBR/a0EaaQJOLHAAWHCUZLIWHuI5qPRhFiARFAU4Bb7TzWayB /2WXKlhs/fGa8Os71/LCOmhkQWyHJfiSd3iqvvi+v+abqtGgDq9jDZWytvHaFjaoMUao rIIaPncGXFJuyEtkfXPklW/Y+z7q2Jrk61g+XhrHk0K1sABhLEcM27zvWt5z9qxjiUR6 FmQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=y+vBMXcv/4DGDDmvZsPT8uzCrAOnCtue/wVF+VShjKg=; b=pndWOd0mWhTvIg48dTsWNvtbpIV9Ivtxg4bJq4nBX5KjI90AkBpKVEwTNVo+CeCOxm s6H1xawSWXjujlzLo0MUwCQ3d++wPalC/VnFGP+xrltBRxtovaGoZvQglqBw4FM9e5oy yIgZ3fXHE5AXy2cjxYUJy1udVheuzZENUDvYJkIp8MrGWFIhungG45o+GEZv85H+45Of Kelvda4Ql5Lh416S/QNEIuz4Q99pnS0X/GB88aDzGhasDivDi7dEa7CwzucJpubCdGPg 0dKv3zPSbFkzp04u4tRTOXf5trEcKtX4bPbiXuGP2B59UsxJOX67bL6KY/kM/BpFmVO/ hCOg== X-Gm-Message-State: ACgBeo1SermSt+TSIKfarL6XsjXZ+BEki7bi7anLj8sBGNHeF4aDGKh/ AbZJ8rzb0JvXUxW+l1PctjkL49rJDDo= X-Google-Smtp-Source: AA6agR7XoRUtZkLiJlHkCmpGAOHqOTXlBzuTjfVIEO0YRFkRRBuKdvoOHMPunC0xVX3Ku0XJQJxE+A== X-Received: by 2002:a05:622a:190f:b0:343:5aa8:5538 with SMTP id w15-20020a05622a190f00b003435aa85538mr3286410qtc.445.1660159835258; Wed, 10 Aug 2022 12:30:35 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v2 11/13] xenpm: Factor out a non-fatal cpuid_parse variant Date: Wed, 10 Aug 2022 15:29:42 -0400 Message-Id: <20220810192944.102135-12-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-1-jandryuk@gmail.com> MIME-Version: 1.0 Allow cpuid_parse to be re-used without terminating xenpm. HWP will re-use it to optionally parse a cpuid. Unlike other uses of cpuid_parse, parse_hwp_opts will take a variable number of arguments and cannot just check argc. Signed-off-by: Jason Andryuk --- v2: Retained because cpuid_parse handles numeric cpu numbers and "all". --- 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 610a516213..5b28e2f6dd 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 Wed Aug 10 19:29:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E7BE7C25B06 for ; Wed, 10 Aug 2022 19:30:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383902.619208 (Exim 4.92) (envelope-from ) id 1oLrPd-0001pr-Ub; Wed, 10 Aug 2022 19:30:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383902.619208; Wed, 10 Aug 2022 19:30:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPd-0001ph-R4; Wed, 10 Aug 2022 19:30:41 +0000 Received: by outflank-mailman (input) for mailman id 383902; Wed, 10 Aug 2022 19:30:40 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPb-00067E-QT for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:40 +0000 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [2607:f8b0:4864:20::f32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9c12b20-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:38 +0200 (CEST) Received: by mail-qv1-xf32.google.com with SMTP id d10so6167281qvn.8 for ; Wed, 10 Aug 2022 12:30:38 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:36 -0700 (PDT) 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: e9c12b20-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=pJCyh+ArYcfa4uMep711UzFy3W8Uwd/8EjcLTHkoO0k=; b=RgcwESKdKg3z7te/avieu5S7kOxrYSbl//vn16Ja9ML2kcugPK8P7HczGrxGXMDQj3 8Q51iyYO86N+ToneiJbarkoU6m4fEvT/x+NpwwiYetoS//NQtVfITVRcK8FCSL/k7yBz 7yoxhcoqNZiGBIRuqeX9+GHYHC+htN4HPXh/97dWsl/89ETBOCOMVnMg8HVU9Q8NSESW TBEcafrE5Uzn1vRvikdzvf9BLRL42et1sTS5UIh22wuxcdEYK49JXKF6Yj6Bx4g8puO0 4kwjhG0r1KV9u3yKKcWB2kTIjVl2Tlul4FXMd/FpKylocq5G7xyc2bm0AejG1mSI1RiU /1Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=pJCyh+ArYcfa4uMep711UzFy3W8Uwd/8EjcLTHkoO0k=; b=19lOOBGt2VDPEW0nfO96wFe/+QX1UrIAzvBLAZ0gfrEM9Pa9BWQcjExh1ml2dWlAHA TLzpYtB0YXwXWOvPkDWG3PD+eUlU6LjM+7W5Ag5gUfdQfExApEK/8kzf6Ch+ZAhcmP+9 ZRkKyix/TV2gZbQNNMugS8m16ur7bYZeU+NlcyBUzvPrR5nQ0EapJARamFmVm4tviwmk ewN7lV5TEGbP0oJPVSimz6l6tXO//gW5ZHItpGD+Sz0qeRPsK6ZepY5GuqftaR7f9Pq4 7FmmS0jjnpynqs6J7GGmXA32l4XWGETFK2BiyqD7nDIan5DxkWGXbcVs3ameFeyfnV0D 6RtQ== X-Gm-Message-State: ACgBeo0pzg9TJI3Jytm1ALJhlshQ5micFr5J7TRdtimQayphbZ9ACA39 YXm8C9uvwtM+rZ75Q/P3EkrjZ75b18k= X-Google-Smtp-Source: AA6agR5MyhpdcuvfjPzDeyzHfF6vS/9egzV5yEl3CSLOvMPNmrpBJ2P4FeUmZb6SJV9ydYGADLnQSA== X-Received: by 2002:a0c:f20f:0:b0:474:9593:ef67 with SMTP id h15-20020a0cf20f000000b004749593ef67mr25280406qvk.8.1660159837348; Wed, 10 Aug 2022 12:30:37 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v2 12/13] xenpm: Add set-cpufreq-hwp subcommand Date: Wed, 10 Aug 2022 15:29:43 -0400 Message-Id: <20220810192944.102135-13-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-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 single cpu. There are presets of balance, powersave & performance. Those can be further tweaked by param:val arguments as explained in the usage description. Parameter names are just checked to the first 3 characters to shorten typing. Some options are hardware dependent, and ranges can be found in get-cpufreq-para. Signed-off-by: Jason Andryuk --- v2: Compare provided parameter name and not just 3 characters. Use "-" in parameter names Remove hw_ Replace sscanf with strchr & strtoul. Remove toplevel error message with lower level ones. Help text s/127/128/ Help text mention truncation. Avoid some truncation rounding down by adding 5 before division. Help test mention default microseconds Also comment the limit check written to avoid overflow. --- tools/misc/xenpm.c | 230 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 5b28e2f6dd..c66ba7c959 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -16,6 +16,7 @@ */ #define MAX_NR_CPU 512 +#include #include #include #include @@ -67,6 +68,27 @@ 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 lowest ... highest\n" + " maximum:N lowest ... highest\n" + " desired:N lowest ... 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" + " 128 (or 7) - balance\n" + " act-window:N{,m,u}s range 1us-1270s\n" + " window for internal calculations.\n" + " Defaults to us without units.\n" + " Truncates un-representable values.\n" + " 0 lets the hardware decide.\n" + " get-cpufreq-para returns 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" @@ -1299,6 +1321,213 @@ 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 + */ +static int parse_activity_window(xc_set_hwp_para_t *set_hwp, unsigned long u, + const char *suffix) +{ + unsigned int exponent = 0; + unsigned int multiplier = 1; + + if ( suffix && suffix[0] ) + { + 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); + + return -1; + } + } + + /* u * multipler > 1270 * 1000 * 1000 transformed to avoid overflow. */ + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window is too large\n"); + + return -1; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u += 5; /* Round up to mitigate truncation rounding down + e.g. 128 -> 120 vs 128 -> 130. */ + u /= 10; + exponent += 1; + } + + set_hwp->activity_window = (exponent & HWP_ACT_WINDOW_EXPONENT_MASK) << + HWP_ACT_WINDOW_EXPONENT_SHIFT | + (u & HWP_ACT_WINDOW_MANTISSA_MASK); + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_ACT_WINDOW; + + return 0; +} + +static int parse_hwp_opts(xc_set_hwp_para_t *set_hwp, int *cpuid, + int argc, char *argv[]) +{ + int i = 0; + + if ( argc < 1 ) { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( parse_cpuid_non_fatal(argv[i], cpuid) == 0 ) + { + i++; + } + + if ( i == argc ) { + fprintf(stderr, "Missing arguments\n"); + 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 long val; + char *param = argv[i]; + char *value; + char *suffix; + int ret; + + value = strchr(param, ':'); + if ( value == NULL ) + { + fprintf(stderr, "\"%s\" is an invalid hwp parameter\n", argv[i]); + return -1; + } + + value[0] = '\0'; + value++; + + errno = 0; + val = strtoul(value, &suffix, 10); + if ( (errno && val == ULONG_MAX) || value == suffix ) + { + fprintf(stderr, "Could not parse number \"%s\"\n", value); + return -1; + } + + if ( strncasecmp(param, "act-window", strlen(param)) == 0 ) + { + ret = parse_activity_window(set_hwp, val, suffix); + if (ret) + return -1; + + continue; + } + + if ( val > 255 ) + { + fprintf(stderr, "\"%s\" value \"%lu\" is out of range\n", param, + val); + return -1; + } + + if ( suffix && suffix[0] ) + { + fprintf(stderr, "Suffix \"%s\" is invalid\n", suffix); + return -1; + } + + if ( strncasecmp(param, "minimum", MAX(2, strlen(param))) == 0 ) + { + set_hwp->minimum = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_MINIMUM; + } + else if ( strncasecmp(param, "maximum", MAX(2, strlen(param))) == 0 ) + { + set_hwp->maximum = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_MAXIMUM; + } + else if ( strncasecmp(param, "desired", strlen(param)) == 0 ) + { + set_hwp->desired = val; + set_hwp->set_params |= XEN_SYSCTL_HWP_SET_DESIRED; + } + else if ( strncasecmp(param, "energy-perf", strlen(param)) == 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; + } + } + + if ( set_hwp->set_params == 0 ) + { + fprintf(stderr, "No parameters set in request\n"); + return -1; + } + + 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) ) + 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[]); @@ -1309,6 +1538,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 }, From patchwork Wed Aug 10 19:29:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 12940956 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B105DC25B07 for ; Wed, 10 Aug 2022 19:39:48 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.383962.619230 (Exim 4.92) (envelope-from ) id 1oLrYJ-0005mf-8c; Wed, 10 Aug 2022 19:39:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 383962.619230; Wed, 10 Aug 2022 19:39:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrYJ-0005mY-5a; Wed, 10 Aug 2022 19:39:39 +0000 Received: by outflank-mailman (input) for mailman id 383962; Wed, 10 Aug 2022 19:39:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oLrPg-00067E-6s for xen-devel@lists.xenproject.org; Wed, 10 Aug 2022 19:30:44 +0000 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [2607:f8b0:4864:20::736]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id eabc46a6-18e2-11ed-924f-1f966e50362f; Wed, 10 Aug 2022 21:30:40 +0200 (CEST) Received: by mail-qk1-x736.google.com with SMTP id i24so11901699qkg.13 for ; Wed, 10 Aug 2022 12:30:40 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:289e:b898:c7de:df6c]) by smtp.gmail.com with ESMTPSA id v6-20020a05620a0f0600b006af10bd3635sm537231qkl.57.2022.08.10.12.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 12:30:38 -0700 (PDT) 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: eabc46a6-18e2-11ed-924f-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ZVyxx+81E7lUFgUdbheKS4DtvqtlloOOvzDpUFkNgHU=; b=b9SSycSXr2T/kBrMVg2g6/0gFR08Le8iiib9o0Jy6q5p9CL7Z+wDLFDWdxGzPyzFGL xTHyT8f17772PdU1IbuULI9EiLekKrC70SL0nsH9O8mjUHVt9uW73dSBeF9yU0iwcqWq +vCsZpEjBOckf0HODXM3UuL1Xoyiwz/XYB8DOntsK8XCS8yMr0w8/lUnEJiXI3q4gxNa CRHGOJVw9bNySb2mL3nmcL7sdUzgeazQO6il2XnEkWSlI17/FWAgt3Y9IviaUyfljpkQ 1UDqMIJHfALZ6fBXI+CMp+TMC2It2mlTKoeX3hv7h+G5efB8IehCk41dGjAeldwzW2mb MbhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ZVyxx+81E7lUFgUdbheKS4DtvqtlloOOvzDpUFkNgHU=; b=l4Ms4t662R5HWbROilCAFl7+lkBRbaUy61VNC93QEfMBfPTa2uD+fN6FYHGThuXCdM fhaikAkuCjXwA/xnK4J0OCmcTiAAUDQ4DC6OMhAizodxEDsXPwFcasUqAxAVxZVtRStz 0bJr6YY50RdiIpve1uQcGo9PiMa0sRAofqWmeSPmkOFM5D8rseSIu6QaXWWltXHCxGCs aJ61ifgNxKF+za3RLfrFyg4cRJgTL3+scOQQHnOUQmt2ZUNqdpkdqfmdz0FJFvQqTVmN 2vVZvxojIM4klY/Bv0KW5+WuP0P5vHfuQMoNuY/czbROHEn7h8YW0ZvIhstdIf3dinVY mKsA== X-Gm-Message-State: ACgBeo2EqvZPMb4aSyI9vlqwrsSOfCPUmq1dQFuA5khiB+evM+Q6RO5e tbXkKbMNLHzXg06RVRzRjL7TGPEOVDs= X-Google-Smtp-Source: AA6agR7r32NDisgo1x2kSfxJb5FUC7I8Dh9FaL30qP+g8vq30mkw/k7TEbsBhxNG/n/TC8Ac+c2AAg== X-Received: by 2002:a05:620a:2b8b:b0:6b9:43ca:4a6 with SMTP id dz11-20020a05620a2b8b00b006b943ca04a6mr12469847qkb.346.1660159839109; Wed, 10 Aug 2022 12:30:39 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Henry Wang , Community Manager Subject: [PATCH v2 13/13] CHANGELOG: Add Intel HWP entry Date: Wed, 10 Aug 2022 15:29:44 -0400 Message-Id: <20220810192944.102135-14-jandryuk@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810192944.102135-1-jandryuk@gmail.com> References: <20220810192944.102135-1-jandryuk@gmail.com> MIME-Version: 1.0 Signed-off-by: Jason Andryuk Acked-by: Henry Wang --- v2: Add blank line --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a87a193e15..3d982bf96b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [unstable UNRELEASED](https://xenbits.xen.org/gitweb/?p=xen.git;a=shortlog;h=staging) - TBD +### Added + - Intel Hardware P-States (HWP) cpufreq driver + ### Changed - On x86 "vga=current" can now be used together with GrUB2's gfxpayload setting. Note that this requires use of "multiboot2" (and "module2") as the GrUB commands loading Xen.