From patchwork Wed Jun 14 18:02:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280278 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 8B549EB64D9 for ; Wed, 14 Jun 2023 18:04:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549112.857458 (Exim 4.92) (envelope-from ) id 1q9UqG-0005LU-VI; Wed, 14 Jun 2023 18:03:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549112.857458; Wed, 14 Jun 2023 18:03: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 1q9UqG-0005LN-SR; Wed, 14 Jun 2023 18:03:36 +0000 Received: by outflank-mailman (input) for mailman id 549112; Wed, 14 Jun 2023 18:03:36 +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 1q9UqF-0005LA-Vw for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:36 +0000 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [2607:f8b0:4864:20::e35]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c7602c19-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:35 +0200 (CEST) Received: by mail-vs1-xe35.google.com with SMTP id ada2fe7eead31-43dc3f77accso1084383137.3 for ; Wed, 14 Jun 2023 11:03:35 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03: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: c7602c19-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765813; x=1689357813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lU8DGWwiCowI3/H8qxEHgym+pR/PD7+d49EnwTk48c0=; b=FTMGhYzyzesu0y8pq13HQGHdOiX37CAuijIjvJWyvNfGq+oJd8YxyBP8kdauoRw4Tg m6uOw5MoYCdf2z+6RHnovjMpq+Qj9okzrUJEMcbdtWDU/lV5BuqY4VkkNKFJb2kKXSC4 WfevBJzJtfMrZvQ4XdszbfQV6G0u2liwKaQTzPXsPCX7UhBQwEvUzPwNsJvqG6iUVUUA snQ9YIvCZ9DxC5LC8NfHt3ywo1lFu1q0gYah2O5/1fK5v5FUEmgymK6iLt/7umElkTv9 VaM/YsCQ30Q5bT/omyUDZbCo5LFpeiJCJZtZmbb+foEwedk8WYXM7IwJ+z4xu4MAeJHP Ya0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765813; x=1689357813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lU8DGWwiCowI3/H8qxEHgym+pR/PD7+d49EnwTk48c0=; b=btMjjmXecfxyfoHZCl+/dO5hXa+vJc1CcSWwcx6REag/xBRmo1JBpdvbPGxg5HACH7 84sEgIK5eEHwbJLYzAwt0svK3nfqPAVYtIrlnHQtaVxGLiv70tl/95Z4/nGXZX/R9AwY ljkQrbHdUDXVwi54fgkmCtJ46JQOZrXvSHUHm3c05SFaPYo5ovV5Aj9w8Hfs+qchjJus GgGf18LYXckPEGhKs6gpuBgQlY7oUpAANN7eWmp+5i/rGMWTKQxoiT7Y9LZA4ckAjS+w vis9b7+F+j03QETWt9G/HD5LpPmo/mf7w79+y5vLvPKqWRorqn6qesSM/CAMNHUTt+9r rYDA== X-Gm-Message-State: AC+VfDyWaGeUdD/+P/Lgw9OS5M5Wr6hcdVhPYCo63fHDSd1yVlZ37aXX bZ827CSE+/cotmtqXYREcXUfOaFHL8Y= X-Google-Smtp-Source: ACHHUZ5d7g8agZ07KEhe8IWu0FQmrugubkYEzKObMy6SSopXNduOyiTa/lcirAy2NwfmmUcx7Np8Jw== X-Received: by 2002:a67:ebda:0:b0:43f:35f5:771a with SMTP id y26-20020a67ebda000000b0043f35f5771amr4569198vso.19.1686765813187; Wed, 14 Jun 2023 11:03:33 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Jan Beulich Subject: [PATCH v4 01/15] cpufreq: Allow restricting to internal governors only Date: Wed, 14 Jun 2023 14:02:39 -0400 Message-Id: <20230614180253.89958-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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, will be used. This is set during presmp_initcall, so that it can suppress governor registration during initcall. Add an internal flag to struct cpufreq_governor to indicate such governors. This way, the unusable governors are not registered, so the internal one is the only one returned to userspace. This means incompatible governors won't be advertised to userspace. Signed-off-by: Jason Andryuk --- v4: Rework to use an internal flag Removed Jan's Ack since the approach is different. v3: Switch to initdata Add Jan Acked-by Commit message s/they/the/ typo Don't register hwp-internal when running non-hwp - Marek v2: Switch to "-internal" Add blank line in header --- xen/drivers/cpufreq/cpufreq.c | 7 +++++++ xen/include/acpi/cpufreq/cpufreq.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 2321c7dd07..cccf9a64c8 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -56,6 +56,7 @@ struct cpufreq_dom { }; static LIST_HEAD_READ_MOSTLY(cpufreq_dom_list_head); +bool __initdata cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); @@ -121,6 +122,12 @@ int __init cpufreq_register_governor(struct cpufreq_governor *governor) if (!governor) return -EINVAL; + if (cpufreq_governor_internal && !governor->internal) + return -EINVAL; + + if (!cpufreq_governor_internal && governor->internal) + 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..1c0872506a 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -106,6 +106,7 @@ struct cpufreq_governor { unsigned int event); bool_t (*handle_option)(const char *name, const char *value); struct list_head governor_list; + bool internal; }; extern struct cpufreq_governor *cpufreq_opt_governor; @@ -114,6 +115,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 Jun 14 18:02:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280280 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 54BEDEB64D8 for ; Wed, 14 Jun 2023 18:04:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549114.857478 (Exim 4.92) (envelope-from ) id 1q9UqM-0005sb-Hu; Wed, 14 Jun 2023 18:03:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549114.857478; Wed, 14 Jun 2023 18:03:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqM-0005sU-Ej; Wed, 14 Jun 2023 18:03:42 +0000 Received: by outflank-mailman (input) for mailman id 549114; Wed, 14 Jun 2023 18:03: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 1q9UqK-0005L9-NB for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03: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 c95a91c6-0add-11ee-8611-37d641c3527e; Wed, 14 Jun 2023 20:03:38 +0200 (CEST) Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-62de651bcf0so20024736d6.2 for ; Wed, 14 Jun 2023 11:03:38 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:35 -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: c95a91c6-0add-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765816; x=1689357816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o5tkXnrNUw3eHjvmXo8drCoxp1uJZERpOt4e3aBqvlI=; b=WfNbPQT1HJVztPPCPFYHumWFQ4f9i6Y6tO82zr5G78mf9uA5aklvR2FPBCyzFESLQv HamDDASz8qUWFCp+If5uMty6mI5slouwmLtdsV+Z/wD3To1tw8w5l+U0yvu1GzWWF7qB omC+MMuiNiqjmlUmT2K1td73nlWj1CyVmUThHbHTtKWcYig5dwjZzL3EUi6PaiJIc85u zRDr1JhCW1j/fvWPRLJU+PFqcmHsNS2e3C9fkTEefjH/tGcPaLvZjhGNnACmDi32l2mj 1LRWuFsoTGiMltuqEXyNOSvA7pn7XOZs6scE45qlGB2NYCYMq1DL0/JgjFMPiE/ofZEo QIBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765816; x=1689357816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o5tkXnrNUw3eHjvmXo8drCoxp1uJZERpOt4e3aBqvlI=; b=iTTK6LDSP6lCQvYnNHHuK2jDEznmdipTrLDOb6MgiHYWzYK3Mve6LELsd4uHGyJq8q 3TOx1qxajdweVizGf3gNBRzhQlGUbCG8sRC9uFzQF0erlRnQf+oWdcyeHr2NQDJ3crXv s4+y6xTHcKby6CGzCH3Z3JjjKq/fDi9Tj9pQbrLMP9YgznS/b6fAS2W8gWGYKKKCkzVO yDBfIzopeus5LhHZwUp4+SSyHKVFNlf8tqbPmkccB8g9N22HgvKvIOSrYNaPg2k2GnJi LyzKr5ZNBNpnD4ACjFtPqeJOHjffg6fe6uEnY7l3rka+w8L8/5lE8Q5b+k8C6E3xObKo NNWA== X-Gm-Message-State: AC+VfDw4JUqDW1ZaXVl8F3qOZsJRbg1p9q+xyFec9MSmaAv8T90BkS71 +uQiKvqujTvp0ad9juPqof1vlEYg/+c= X-Google-Smtp-Source: ACHHUZ7qj8JSis1q8yl+rMlAnzFRNgXrHEu7PaDjBjBcTiPdQNLM8Dlr3ErwVNhse3Hbf2SgHdmbUg== X-Received: by 2002:a05:6214:5016:b0:62f:ebc4:89bd with SMTP id jo22-20020a056214501600b0062febc489bdmr750110qvb.63.1686765816353; Wed, 14 Jun 2023 11:03:36 -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 v4 02/15] cpufreq: Add perf_freq to cpuinfo Date: Wed, 14 Jun 2023 14:02:40 -0400 Message-Id: <20230614180253.89958-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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 --- v3: Add Jan's Ack I don't like this, but it seems the best way to re-use the common aperf/mperf code. The other option would be to add wrappers that then do the acpi vs. hwp scaling. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/drivers/cpufreq/utility.c | 1 + xen/include/acpi/cpufreq/cpufreq.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index 2e0067fbe5..6c70d04395 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -316,7 +316,7 @@ unsigned int get_measured_perf(unsigned int cpu, 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 1c0872506a..e2e03b8bd7 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 Jun 14 18:02:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280277 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 C5C6AEB64D9 for ; Wed, 14 Jun 2023 18:04:01 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549115.857483 (Exim 4.92) (envelope-from ) id 1q9UqM-0005vs-Us; Wed, 14 Jun 2023 18:03:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549115.857483; Wed, 14 Jun 2023 18:03:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqM-0005uo-N9; Wed, 14 Jun 2023 18:03:42 +0000 Received: by outflank-mailman (input) for mailman id 549115; Wed, 14 Jun 2023 18:03:41 +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 1q9UqL-0005LA-5G for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:41 +0000 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [2607:f8b0:4864:20::733]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id caba7099-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:40 +0200 (CEST) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-75eba89e373so136308685a.0 for ; Wed, 14 Jun 2023 11:03:40 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03: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: caba7099-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765819; x=1689357819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VlkDpnzBOrYGbDVTZSSMEmRPTHTcziXTR1AlOBlC9P0=; b=AXnywO9drA3Q8W6DRI1x3EOkjYsJTjm66pGvWIuNfbh9MCYQf9DnHPNj0kPKgBCcJk 5YZwfxOlkJZilJT9HNdET11GHbG2MAW6vGFdnR9GrD3pzwmG8hN6yzA8yoJFniWOICfg 52qEe1JjedvdvS+rPiIeXIi/2ODtHrEjIdjIoCaels7dA/o7U05Y0J+FO0nDGEWyCs8O rs28/5dz/gzyeiOpwZnYJFL+XI1R6dkCMwrDYbaLbJNTs3b4MaGR86DSlO/mbHwi1XbP UYbzL/VTU2qzOLqQjvwj974CBVoGYL+XF1V/pWMR9PQEH/AnKDsnFxF9JyB0DkSjC57+ ic8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765819; x=1689357819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VlkDpnzBOrYGbDVTZSSMEmRPTHTcziXTR1AlOBlC9P0=; b=GHFUF2rWg9kYUr1k33d6f5FaCbUOlsgEM5EKzhUE45XPYOTila4XYqQ6H1Bm3UwE7/ Wn731Pc1OG86oyPMNs3w4y+VhTeKgsH+zy08Yv3pSzC4gk6P0iZWTJGs4VEqHswLz1vX YLxJQ8FxXsmujHZ3mQLo/kOUrSfYB/qter940e7bpGzklyv5QEx/YP3anTlaJVbBzNcB vx8gHjZ6cAiSAwNPee28wzzcDz8MvyF0NvLhqEsVIiFUI7xxjWyetSnIV3PRcKTOeeyZ 4q9jgpjOlPzvIN+ZvminCdI/1hliw53DksPtYXyX0CDx7tD5Ro4ouU3TLMeS/qzpdQ8J KiPQ== X-Gm-Message-State: AC+VfDyrxw+iPWpC8L29E0Nkd0MK0DKjuee+nPjG2cfLqNFyUCTEO9wi kdegYchdPpbSoQ0hMj2gwvSH0QvKPic= X-Google-Smtp-Source: ACHHUZ5R/W/a+GmZ21I2JuypJPX5nA4naO0DoMZMZaZAwUhz2FeSuuwZnCLdEm4hEUjr8RHGi7G6EQ== X-Received: by 2002:a05:620a:4686:b0:75f:828:3c52 with SMTP id bq6-20020a05620a468600b0075f08283c52mr2758989qkb.3.1686765818943; Wed, 14 Jun 2023 11:03:38 -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 v4 03/15] cpufreq: Export intel_feature_detect Date: Wed, 14 Jun 2023 14:02:41 -0400 Message-Id: <20230614180253.89958-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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 Acked-by: Jan Beulich --- v4: Add Jan's Ack v3: Remove void * cast when calling intel_feature_detect v2: export intel_feature_detect with typed pointer Move intel_feature_detect to acpi/cpufreq/cpufreq.h since the declaration now contains struct cpufreq_policy *. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++-- xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c index 6c70d04395..f1cc473b4f 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -339,9 +339,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(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); @@ -353,6 +352,11 @@ static void cf_check feature_detect(void *info) } } +static void cf_check feature_detect(void *info) +{ + intel_feature_detect(info); +} + static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq, struct acpi_cpufreq_data *data) { diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index e2e03b8bd7..a49efd1cb2 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -244,4 +244,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 Jun 14 18:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280281 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 2AD97EB64DB for ; Wed, 14 Jun 2023 18:04:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549117.857498 (Exim 4.92) (envelope-from ) id 1q9UqQ-0006Qc-2c; Wed, 14 Jun 2023 18:03:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549117.857498; Wed, 14 Jun 2023 18:03:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqP-0006QI-Ut; Wed, 14 Jun 2023 18:03:45 +0000 Received: by outflank-mailman (input) for mailman id 549117; Wed, 14 Jun 2023 18:03:44 +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 1q9UqO-0005LA-8E for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:44 +0000 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [2607:f8b0:4864:20::72d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cc7940e3-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:43 +0200 (CEST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-75d528d0811so236863385a.0 for ; Wed, 14 Jun 2023 11:03:43 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:41 -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: cc7940e3-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765822; x=1689357822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mnealSDcQ5eD4/BMHbAdAnbMLaUANznTtXLujb813pg=; b=aNSOaYk5zO1KBg04VlVemwmWTnIt6/wLAeqR1wPh7xYYpSSH4qlOIMdBGatS2sXEh4 OcaVMqXW1jDcyxAdnVyON3c5BI+g0JwYJWyInEKwR4Bta0GBVkiORyxefZTvGQOdLvw6 0Is4l0/lm+JEINReuo51rkoPfx0SZTZl0wJ7wi+PDlKbEpgmHFmpx0yfCcIqFQfo34+G 8KwlXT14II/YNrHVOojLL8NOX9waHB2JlFSQcwWnSGo1j1HdqoTid7IiOzkGD/6BrdzA RxDgez8RXmvmK4HSF5HDeyljzZfyoFSEy1aYInOzwC8J0g9yW00t5OkXRs6eE5+U1jxG pETg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765822; x=1689357822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mnealSDcQ5eD4/BMHbAdAnbMLaUANznTtXLujb813pg=; b=c1eA/CMvfMBuXD4Y6Y0HS8ULr1mNrJpbO+XjzbfOgxJbCbYh8jmOJUyjdfalerCJw7 esfdzzUBNcMxEicqGNpyVl8CAT/k7EZ+vEIJ7hvkUaarRqQed8aIPx529srSL5lva4iD iZAx6ugfiQfskdacZAwn5kELK3vpxPRCDJmbGRJIP1ejAa7PHNnQCMHRkZpm9ir1LIbX Sh9aFu0NO/yPiGlQO3ALnWUwEhXZcei5gq4GN28DG3wT2l654eJHExHBBjzdbFrRNyet ygMrcdEYDfO+zyhDbn/3G12U02N6sEyhHvhAqN7bFPtiH6HwYon+6UOF7zYXD9MzXwVV xcPQ== X-Gm-Message-State: AC+VfDzO+KnP78vnFk8/p6NGPZWwQgmh6JG82AtLzDFymBKBwV+MyImh PFzaf9D/Xd2o9qkiTOH11/36eXP/LtE= X-Google-Smtp-Source: ACHHUZ7Hjc2utKPmJ0Oof45Hh1e1ert+3gNRKB/sSEHZeaA1HRXQM/ADydrx9UXqqd56EnLb+djrXA== X-Received: by 2002:a05:6214:2467:b0:621:17c6:2713 with SMTP id im7-20020a056214246700b0062117c62713mr9796165qvb.49.1686765821615; Wed, 14 Jun 2023 11:03:41 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v4 04/15] xen/sysctl: Nest cpufreq scaling options Date: Wed, 14 Jun 2023 14:02:42 -0400 Message-Id: <20230614180253.89958-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Add a union and struct so that most of the scaling variables of struct xen_get_cpufreq_para are within in a binary-compatible layout. This allows cppc_para to live in the larger union and use uint32_ts - struct xen_cppc_para will be 10 uint32_t's. The new scaling struct is 3 * uint32_t + 16 bytes CPUFREQ_NAME_LEN + 4 * uint32_t for xen_ondemand = 11 uint32_t. That means the old size is retained, int32_t turbo_enabled doesn't move and it's binary compatible. Signed-off-by: Jason Andryuk --- tools/include/xenctrl.h | 22 +++++++++++++--------- tools/libs/ctrl/xc_pm.c | 5 ----- tools/misc/xenpm.c | 24 ++++++++++++------------ xen/drivers/acpi/pmstat.c | 27 ++++++++++++++------------- xen/include/public/sysctl.h | 22 +++++++++++++--------- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index dba33d5d0f..8aedb952a0 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1909,16 +1909,20 @@ struct xc_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - uint32_t scaling_cur_freq; - - char scaling_governor[CPUFREQ_NAME_LEN]; - uint32_t scaling_max_freq; - uint32_t scaling_min_freq; - - /* for specific governor */ union { - xc_userspace_t userspace; - xc_ondemand_t ondemand; + struct { + uint32_t scaling_cur_freq; + + char scaling_governor[CPUFREQ_NAME_LEN]; + uint32_t scaling_max_freq; + uint32_t scaling_min_freq; + + /* for specific governor */ + union { + xc_userspace_t userspace; + xc_ondemand_t ondemand; + } u; + } s; } u; int32_t turbo_enabled; diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index c3a9864bf7..f92542eaf7 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -265,15 +265,10 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, user_para->cpuinfo_cur_freq = sys_para->cpuinfo_cur_freq; user_para->cpuinfo_max_freq = sys_para->cpuinfo_max_freq; user_para->cpuinfo_min_freq = sys_para->cpuinfo_min_freq; - user_para->scaling_cur_freq = sys_para->scaling_cur_freq; - user_para->scaling_max_freq = sys_para->scaling_max_freq; - user_para->scaling_min_freq = sys_para->scaling_min_freq; user_para->turbo_enabled = sys_para->turbo_enabled; memcpy(user_para->scaling_driver, sys_para->scaling_driver, CPUFREQ_NAME_LEN); - memcpy(user_para->scaling_governor, - sys_para->scaling_governor, CPUFREQ_NAME_LEN); /* copy to user_para no matter what cpufreq governor */ BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) != diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1bb6187e56..ee8ce5d5f2 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -730,39 +730,39 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) printf("scaling_avail_gov : %s\n", p_cpufreq->scaling_available_governors); - printf("current_governor : %s\n", p_cpufreq->scaling_governor); - if ( !strncmp(p_cpufreq->scaling_governor, + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { printf(" userspace specific :\n"); printf(" scaling_setspeed : %u\n", - p_cpufreq->u.userspace.scaling_setspeed); + p_cpufreq->u.s.u.userspace.scaling_setspeed); } - else if ( !strncmp(p_cpufreq->scaling_governor, + else if ( !strncmp(p_cpufreq->u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { printf(" ondemand specific :\n"); printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.ondemand.sampling_rate_max, - p_cpufreq->u.ondemand.sampling_rate_min, - p_cpufreq->u.ondemand.sampling_rate); + p_cpufreq->u.s.u.ondemand.sampling_rate_max, + p_cpufreq->u.s.u.ondemand.sampling_rate_min, + p_cpufreq->u.s.u.ondemand.sampling_rate); printf(" up_threshold : %u\n", - p_cpufreq->u.ondemand.up_threshold); + p_cpufreq->u.s.u.ondemand.up_threshold); } 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 ) + p_cpufreq->u.s.scaling_cur_freq ) printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); else printf(" %d", p_cpufreq->scaling_available_frequencies[i]); printf("\n"); printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->scaling_max_freq, - p_cpufreq->scaling_min_freq, - p_cpufreq->scaling_cur_freq); + p_cpufreq->u.s.scaling_max_freq, + p_cpufreq->u.s.scaling_min_freq, + p_cpufreq->u.s.scaling_cur_freq); printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 1bae635101..f5a9ac3f1a 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -258,37 +258,38 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq; op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq; - op->u.get_para.scaling_cur_freq = policy->cur; - op->u.get_para.scaling_max_freq = policy->max; - op->u.get_para.scaling_min_freq = policy->min; + + op->u.get_para.u.s.scaling_cur_freq = policy->cur; + op->u.get_para.u.s.scaling_max_freq = policy->max; + op->u.get_para.u.s.scaling_min_freq = policy->min; if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver, + strlcpy(op->u.get_para.scaling_driver, cpufreq_driver.name, CPUFREQ_NAME_LEN); else strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN); if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.scaling_governor, + strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.scaling_governor, "Unknown", CPUFREQ_NAME_LEN); + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NAME_LEN); /* governor specific para */ - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { - op->u.get_para.u.userspace.scaling_setspeed = policy->cur; + op->u.get_para.u.s.u.userspace.scaling_setspeed = policy->cur; } - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { ret = get_cpufreq_ondemand_para( - &op->u.get_para.u.ondemand.sampling_rate_max, - &op->u.get_para.u.ondemand.sampling_rate_min, - &op->u.get_para.u.ondemand.sampling_rate, - &op->u.get_para.u.ondemand.up_threshold); + &op->u.get_para.u.s.u.ondemand.sampling_rate_max, + &op->u.get_para.u.s.u.ondemand.sampling_rate_min, + &op->u.get_para.u.s.u.ondemand.sampling_rate, + &op->u.get_para.u.s.u.ondemand.up_threshold); } op->u.get_para.turbo_enabled = cpufreq_get_turbo_status(op->cpuid); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 9d06e92d0f..bdcea99d71 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -317,16 +317,20 @@ struct xen_get_cpufreq_para { uint32_t cpuinfo_cur_freq; uint32_t cpuinfo_max_freq; uint32_t cpuinfo_min_freq; - uint32_t scaling_cur_freq; - - char scaling_governor[CPUFREQ_NAME_LEN]; - uint32_t scaling_max_freq; - uint32_t scaling_min_freq; - - /* for specific governor */ union { - struct xen_userspace userspace; - struct xen_ondemand ondemand; + struct { + uint32_t scaling_cur_freq; + + char scaling_governor[CPUFREQ_NAME_LEN]; + uint32_t scaling_max_freq; + uint32_t scaling_min_freq; + + /* for specific governor */ + union { + struct xen_userspace userspace; + struct xen_ondemand ondemand; + } u; + } s; } u; int32_t turbo_enabled; From patchwork Wed Jun 14 18:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280279 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 2D56FEB64D8 for ; Wed, 14 Jun 2023 18:04:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549118.857508 (Exim 4.92) (envelope-from ) id 1q9UqR-0006iS-Ht; Wed, 14 Jun 2023 18:03:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549118.857508; Wed, 14 Jun 2023 18:03:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqR-0006iG-E8; Wed, 14 Jun 2023 18:03:47 +0000 Received: by outflank-mailman (input) for mailman id 549118; Wed, 14 Jun 2023 18:03:46 +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 1q9UqQ-0005LA-HR for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:46 +0000 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [2607:f8b0:4864:20::f30]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cdde8bb2-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:45 +0200 (CEST) Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-62fe188255eso5281316d6.0 for ; Wed, 14 Jun 2023 11:03:45 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:43 -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: cdde8bb2-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765824; x=1689357824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=10pxhvdrn80PyMa9ObI4vzbfbnF6JqsnYlE3+fZTgH4=; b=TBzWEaEpROdu95ng56aLIM+QHArd/59X1K/ZGOGnC4hZg91HGP0VBDadoi6dlKiC5G M4wOQR3uyRbe/5Sf98NHxtDP88ECcoZG+ZTxwL3u4zugE0FVYgilEkXeyHc1Vi9KQyHQ /IbhHAojqOcd1GLW0/8lDPuaJxt9ab+ABWbZcrVjal22utQOPYayh+NggBQpT2YlcS28 U+m7f9yPOPLRvj3p0eglXJXI5Ihb+agUIA0qD77BwLKMkdciIerzGov7ff2YErFwIPl9 FpbyaoS6NgpvOkNuORNTDuk7MdQFG0039TBFg4GdK2QaLpjAf/REs4xtWR4lDevrdcGz sVaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765824; x=1689357824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=10pxhvdrn80PyMa9ObI4vzbfbnF6JqsnYlE3+fZTgH4=; b=NywY+PFhUsYL5IJ1aMXS/Qi/4r83EFHPxIrO1cWW8iTRMWAAbEasH3M6qGAGcoeEmo Egmuos4GD7GcV24yteF4N1C5MWQUIGYwUSefmI8dcpXx+hjWqgJjCwum3JLxaMf1fCr9 /jeRriUhchMS1jr7mp5V65OYpzoJNHu6Qty/emqYPMdLp/tsJhDqNDd2O3Pa8zdeyUXp RBW+frybv2MMVMGnHsAJHeUBsxNelnKmn5jRmLqjTj+e9DsgxbS0kqZJdGlpmTPw2gtB T9mkNAclBTaYgAZyCBBGEhEK5qf95l0FuxuSgvKdODjHjeHiti4NgvZZvwipicm70MGe KCvg== X-Gm-Message-State: AC+VfDzlaL1fw5V+Smun/9AEtwueZZ+d25il3S2INp57w/Z5zHHE+3Gn 1upMvmOv97wjaxFvGfcvvJ4oYqQtLGU= X-Google-Smtp-Source: ACHHUZ6N5eMFhC3uSDSbTWNAHc6p3JmhOkha9gRR1/mxpVow/vsJGC9n9OEZucxBv1K/MibnvmKS+g== X-Received: by 2002:a05:6214:2022:b0:62b:6bc5:7a1b with SMTP id 2-20020a056214202200b0062b6bc57a1bmr3296531qvf.15.1686765824064; Wed, 14 Jun 2023 11:03:44 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross , Jan Beulich Subject: [PATCH v4 05/15] pmstat&xenpm: Re-arrage for cpufreq union Date: Wed, 14 Jun 2023 14:02:43 -0400 Message-Id: <20230614180253.89958-6-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Move some code around now that common xen_sysctl_pm_op get_para fields are together. In particular, the scaling governor information like scaling_available_governors is inside the union, so it is not always available. With that, gov_num may be 0, so bounce buffer handling needs to be modified. scaling_governor won't be filled for hwp, so this will simplify the change when it is introduced. Signed-off-by: Jason Andryuk --- tools/libs/ctrl/xc_pm.c | 12 ++++++++---- tools/misc/xenpm.c | 3 ++- xen/drivers/acpi/pmstat.c | 32 +++++++++++++++++--------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index f92542eaf7..19fe1a79dd 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -221,7 +221,7 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, { if ( (!user_para->affected_cpus) || (!user_para->scaling_available_frequencies) || - (!user_para->scaling_available_governors) ) + (user_para->gov_num && !user_para->scaling_available_governors) ) { errno = EINVAL; return -1; @@ -230,12 +230,15 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, goto unlock_1; if ( xc_hypercall_bounce_pre(xch, scaling_available_frequencies) ) goto unlock_2; - if ( xc_hypercall_bounce_pre(xch, scaling_available_governors) ) + if ( user_para->gov_num && + xc_hypercall_bounce_pre(xch, scaling_available_governors) ) goto unlock_3; set_xen_guest_handle(sys_para->affected_cpus, affected_cpus); set_xen_guest_handle(sys_para->scaling_available_frequencies, scaling_available_frequencies); - set_xen_guest_handle(sys_para->scaling_available_governors, scaling_available_governors); + if ( user_para->gov_num ) + set_xen_guest_handle(sys_para->scaling_available_governors, + scaling_available_governors); } sysctl.cmd = XEN_SYSCTL_pm_op; @@ -278,7 +281,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, } unlock_4: - xc_hypercall_bounce_post(xch, scaling_available_governors); + if ( user_para->gov_num ) + xc_hypercall_bounce_post(xch, scaling_available_governors); unlock_3: xc_hypercall_bounce_post(xch, scaling_available_frequencies); unlock_2: diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index ee8ce5d5f2..1c474c3b59 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -811,7 +811,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) ret = -ENOMEM; goto out; } - if (!(p_cpufreq->scaling_available_governors = + if (p_cpufreq->gov_num && + !(p_cpufreq->scaling_available_governors = malloc(p_cpufreq->gov_num * CPUFREQ_NAME_LEN * sizeof(char)))) { fprintf(stderr, diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index f5a9ac3f1a..57359c21d8 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -239,11 +239,24 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) if ( ret ) return ret; + op->u.get_para.cpuinfo_cur_freq = + cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; + op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq; + op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq; + op->u.get_para.turbo_enabled = cpufreq_get_turbo_status(op->cpuid); + + if ( cpufreq_driver.name[0] ) + strlcpy(op->u.get_para.scaling_driver, + cpufreq_driver.name, CPUFREQ_NAME_LEN); + else + strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN); + if ( !(scaling_available_governors = xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) return -ENOMEM; - if ( (ret = read_scaling_available_governors(scaling_available_governors, - gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + if ( (ret = read_scaling_available_governors( + scaling_available_governors, + gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) { xfree(scaling_available_governors); return ret; @@ -254,26 +267,16 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) if ( ret ) return ret; - op->u.get_para.cpuinfo_cur_freq = - cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; - op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq; - op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq; - op->u.get_para.u.s.scaling_cur_freq = policy->cur; op->u.get_para.u.s.scaling_max_freq = policy->max; op->u.get_para.u.s.scaling_min_freq = policy->min; - if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver, - cpufreq_driver.name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN); - if ( policy->governor->name[0] ) strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NAME_LEN); + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", + CPUFREQ_NAME_LEN); /* governor specific para */ if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, @@ -291,7 +294,6 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) &op->u.get_para.u.s.u.ondemand.sampling_rate, &op->u.get_para.u.s.u.ondemand.up_threshold); } - op->u.get_para.turbo_enabled = cpufreq_get_turbo_status(op->cpuid); return ret; } From patchwork Wed Jun 14 18:02:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280285 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 E368CEB64DB for ; Wed, 14 Jun 2023 18:04:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549121.857517 (Exim 4.92) (envelope-from ) id 1q9UqX-0007EW-QW; Wed, 14 Jun 2023 18:03:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549121.857517; Wed, 14 Jun 2023 18:03:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqX-0007Dc-Mu; Wed, 14 Jun 2023 18:03:53 +0000 Received: by outflank-mailman (input) for mailman id 549121; Wed, 14 Jun 2023 18:03:51 +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 1q9UqV-0005L9-JC for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:51 +0000 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [2607:f8b0:4864:20::f29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cfadfdb6-0add-11ee-8611-37d641c3527e; Wed, 14 Jun 2023 20:03:49 +0200 (CEST) Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-62884fa0e53so21279046d6.0 for ; Wed, 14 Jun 2023 11:03:49 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:46 -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: cfadfdb6-0add-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765827; x=1689357827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3erQ3Tf88rrl0YLlehZaA13XnubAYvrTZWS6hEHGpfQ=; b=gS/cVFi9jkYv4CKeViJ4P01bEvYXsNQkFIcgXdxfBEEKXkB7x/wSglSeWvuFhWYKLs 79D76CW1UlhdZIzF/4JLgPcc2mkUVmrkEEyDOkMopO3jmCENO29cNACJXVUgvU4IJXEM XYGrc94c2LZ7UWrYRcc5ocuvnuuiKEg31EikdTTsX8lErYsB+YVUOyL7JsuRhLlWol0E nMgK8qmUueFenCmyxtrnJH2sc+8Q+O8GVGDHANa4JbaHw6wVFUeLGchkEKMFwTqesEpe VAoTXN4xxkCZmfSWLVGxfEDS5OATyA1PDKQxBZl+czW0UTOpKyH8D/jqUURoHmNpJS63 QUOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765827; x=1689357827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3erQ3Tf88rrl0YLlehZaA13XnubAYvrTZWS6hEHGpfQ=; b=DT1o1AKJes43ZKRiodVwXQukq4+TIW/qPRZ1l8tvWCEPW5E1yxw71lneLU/eK/kDZA oQsRU2thJfusYg5WjFCkoEVPQ7OMIdUwPdSLTcLViGWH1PxjzwGZ1WubJc6KvTXUxAgR av1HwGwyS7bt5ICW8Mels8BPAbli9sLOylGMN41/6MsxdKV9Eh4CXbFE9y91xMHRXnOk o00Qtd7UNg4dT8DpVdDOiObJWAKOlSzhROg1MSYSvCetJKweqdS4WfbkVTN1ZN9zVUyJ oGEewpoVE+RThRBqm8Bs83BWubJdr33q89OQNGVTS+sfKpc17Fzi6EPdIP0r7rQAIQAn DZJA== X-Gm-Message-State: AC+VfDzkq6V0bAE5hpaoiv6rckFtYz7xrtbXS7qimyIzyuTzPDnxu7TT Zx6+wVAMRlnLUpbRSu8lskGfqOnB2L8= X-Google-Smtp-Source: ACHHUZ5rzAXCLx2h0nHG0yNbhhoAs0CJJCNs3ysW4lCrckM6hXceAe4MbAI5w2Ejko589xq745CsNQ== X-Received: by 2002:ad4:5dea:0:b0:62d:f806:7f80 with SMTP id jn10-20020ad45dea000000b0062df8067f80mr6052255qvb.13.1686765826871; Wed, 14 Jun 2023 11:03:46 -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 v4 06/15] cpufreq: Add Hardware P-State (HWP) driver Date: Wed, 14 Jun 2023 14:02:44 -0400 Message-Id: <20230614180253.89958-7-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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=hwp enables and specifying cpufreq=xen would disable it. hdc is a sub-option under hwp (i.e. cpufreq=xen:hwp,hdc=0) as is verbose. If cpufreq=hwp is specified, but hardware support is unavailable, Xen fallbacks back to cpufreq=xen. There is no interface to configure - xen_sysctl_pm_op/xenpm will be extended to configure in subsequent patches. It will run with the default values, which should be the default 0x80 (out of 0x0-0xff) energy/performance preference. Unscientific powertop measurement of an mostly idle, customized OpenXT install: A 10th gen 6-core laptop showed battery discharge drop from ~9.x to ~7.x watts. A 8th gen 4-core laptop dropped from ~10 to ~9 Power usage depends on many factors, especially display brightness, but this does show a power saving in balanced mode when CPU utilization is low. HWP isn't compatible with an external governor - it doesn't take explicit frequency requests. Therefore a minimal internal governor, hwp, is also added as a placeholder. While adding to the xen-command-line.pandoc entry, un-nest verbose from minfreq. They are independent. With cpufreq=hwp,verbose, HWP prints processor capabilities that are not used by the code, like HW_FEEDBACK. This is done because otherwise there isn't a convenient way to query the information. 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 average cpu frequency output would be wrong. My 8th & 10th gen test systems both report: (XEN) HWP: 1 notify: 1 act_window: 1 energy_perf: 1 pkg_level: 0 peci: 0 (XEN) HWP: Hardware Duty Cycling (HDC) supported (XEN) HWP: HW_FEEDBACK not supported Specifying HWP as a fake governor - cpufreq=xen:hwp - would require resetting the governor if HWP hardware wasn't available. Making cpufreq=hwp a top level option avoids that issue. Falling back from cpufreq=hwp to cpufreq=xen is a more user-friendly choice than disabling cpufreq when HWP is not available. Specifying cpufreq=hwp indicates the user wants cpufreq, so, if HWP isn't available, it makes sense to give them the cpufreq that can be supported. i.e. I can't see a user only wanting cpufreq=hwp or cpufreq=none, but not cpufreq=xen. 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 v3: Add cf_check to cpufreq_gov_hwp_init() - Marek Print cpuid_level with %#x - Marek v4: Use BIT() for CPUID and MSR bits Move __initdata after type Add __ro_after_init to feature_* Remove aperf/mperf comment Move feature_hwp_energy_perf { to newline Remove _IA32_ infix Use unsigned int & bool for bitfields Require energy perf pref (Remove ENERGY_PERF_BIAS support) Initialize activity_window Return errors on wrmsr failure Change command line to: cpufreq=xen:hwp Move hdc into the hwp-specific handle_options Drop feature_hwp_energy_perf, feature_hwp_pkg_level_ctl & feature_hwp_peci Print features before exiting when energy/performance preference isn't available Disable HWP MSR on initialization error Change hwp_ print macros to add prefixes Disable HDC when hdc=0 - (opt_hdc no longer initdata) Mark hwp governor internal and use "hwp" name Add XEN_HWP_DRIVER Use top-level cpufreq=hwp command line option Document that cpufreq=hwp falls back to cpufreq=xen without hardware Add SPDX suffix GPL-2.0-only --- docs/misc/xen-command-line.pandoc | 9 +- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/cpufreq.c | 5 +- xen/arch/x86/acpi/cpufreq/hwp.c | 537 ++++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 12 +- xen/arch/x86/include/asm/msr-index.h | 13 + xen/drivers/cpufreq/cpufreq.c | 9 + xen/include/acpi/cpufreq/cpufreq.h | 3 + xen/include/acpi/cpufreq/processor_perf.h | 3 + xen/include/public/sysctl.h | 1 + 10 files changed, 589 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 4060ebdc5d..9d6bdd6d66 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -499,7 +499,7 @@ If set, force use of the performance counters for 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 | hwp[:[][,verbose]]` > Default: `xen` @@ -510,6 +510,13 @@ 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=` +* `hwp` selects Hardware-Controlled Performance States (HWP) on supported Intel + hardware. HWP is a Skylake+ feature which provides better CPU power + management. The default is disabled. If `hwp` is selected, but hardware + support is not available, Xen will fallback to cpufreq=xen. +* `` 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 `hwp` 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 f1cc473b4f..56816b1aee 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -642,7 +642,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..c62345dde7 --- /dev/null +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -0,0 +1,537 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * hwp.c cpufreq driver to run Intel Hardware P-States (HWP) + * + * Copyright (C) 2021 Jason Andryuk + */ + +#include +#include +#include +#include +#include +#include +#include + +static bool __ro_after_init feature_hwp; +static bool __ro_after_init feature_hwp_notification; +static bool __ro_after_init feature_hwp_activity_window; + +static bool __ro_after_init feature_hdc; + +bool __initdata opt_cpufreq_hwp; +static bool __ro_after_init opt_cpufreq_hdc = true; + +union hwp_request +{ + struct + { + unsigned int min_perf:8; + unsigned int max_perf:8; + unsigned int desired:8; + unsigned int energy_perf:8; + unsigned int activity_window:10; + bool package_control:1; + unsigned int reserved:16; + bool activity_window_valid:1; + bool energy_perf_valid:1; + bool desired_valid:1; + bool max_perf_valid:1; + bool min_perf_valid:1; + }; + uint64_t raw; +}; + +struct hwp_drv_data +{ + union + { + uint64_t hwp_caps; + struct + { + unsigned int highest:8; + unsigned int guaranteed:8; + unsigned int most_efficient:8; + unsigned int lowest:8; + unsigned int reserved:32; + } hw; + }; + union hwp_request curr_req; + int ret; + uint16_t activity_window; + uint8_t minimum; + uint8_t maximum; + uint8_t desired; + uint8_t energy_perf; +}; +DEFINE_PER_CPU_READ_MOSTLY(struct hwp_drv_data *, hwp_drv_data); + +#define hwp_err(fmt, cpu, ...) \ + printk(XENLOG_ERR "HWP: CPU%u error: " fmt, cpu, ##__VA_ARGS__) +#define hwp_info(fmt, ...) printk(XENLOG_INFO "HWP: " fmt, ##__VA_ARGS__) +#define hwp_verbose(fmt, ...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "HWP: " fmt, ##__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 bool hwp_handle_option(const char *s, const char *end) +{ + int ret; + + if ( strncmp(s, "verbose", 7) == 0 ) + { + s += 7; + if ( *s == '=' ) + { + s++; + cpufreq_verbose = !!simple_strtoul(s, NULL, 0); + + return true; + } + + if ( end == NULL || + (end == s && (*end == '\0' || *end == ',')) ) + { + cpufreq_verbose = true; + + return true; + } + + return false; + } + + ret = parse_boolean("hdc", s, end); + if ( ret < 0 ) + return false; + + opt_cpufreq_hdc = ret; + + return true; +} + +int __init hwp_cmdline_parse(const char *s) +{ + do + { + const char *end = strchr(s, ','); + + if ( s && !hwp_handle_option(s, end) ) + { + printk(XENLOG_WARNING "cpufreq/hwp: option '%s' not recognized\n", + s); + + + return -1; + } + + s = end ? ++end : end; + } while ( s ); + + return 0; +} + +static struct cpufreq_governor cpufreq_gov_hwp = +{ + .name = "hwp", + .governor = hwp_governor, + .internal = true, +}; + +static int __init cf_check cpufreq_gov_hwp_init(void) +{ + return cpufreq_register_governor(&cpufreq_gov_hwp); +} +__initcall(cpufreq_gov_hwp_init); + +bool __init hwp_available(void) +{ + unsigned int eax; + + if ( !opt_cpufreq_hwp ) + return false; + + if ( boot_cpu_data.cpuid_level < CPUID_PM_LEAF ) + { + hwp_verbose("cpuid_level (%#x) lacks HWP support\n", + boot_cpu_data.cpuid_level); + + return false; + } + + if ( boot_cpu_data.cpuid_level < 0x16 ) + { + hwp_info("HWP disabled: cpuid_level %#x < 0x16 lacks CPU freq info\n", + boot_cpu_data.cpuid_level); + + return false; + } + + eax = cpuid_eax(CPUID_PM_LEAF); + + hwp_verbose("%d notify: %d act-window: %d energy-perf: %d pkg-level: %d peci: %d\n", + !!(eax & CPUID6_EAX_HWP), + !!(eax & CPUID6_EAX_HWP_NOTIFICATION), + !!(eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW), + !!(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE), + !!(eax & CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST), + !!(eax & CPUID6_EAX_HWP_PECI)); + + if ( !(eax & CPUID6_EAX_HWP) ) + return false; + + if ( !(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE) ) + { + hwp_verbose("disabled: No energy/performance preference available"); + + return false; + } + + feature_hwp = eax & CPUID6_EAX_HWP; + feature_hwp_notification = eax & CPUID6_EAX_HWP_NOTIFICATION; + feature_hwp_activity_window = eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW; + feature_hdc = eax & CPUID6_EAX_HDC; + + hwp_verbose("Hardware Duty Cycling (HDC) %ssupported%s\n", + feature_hdc ? "" : "not ", + feature_hdc ? opt_cpufreq_hdc ? ", enabled" : ", disabled" + : ""); + + hwp_verbose("HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + cpufreq_governor_internal = feature_hwp; + + if ( feature_hwp ) + hwp_info("Using HWP for cpufreq\n"); + + return feature_hwp; +} + +static int hdc_set_pkg_hdc_ctl(unsigned int cpu, bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_PKG_HDC_CTL, msr) ) + { + hwp_err("rdmsr_safe(MSR_PKG_HDC_CTL)\n", cpu); + + return -1; + } + + if ( val ) + msr |= PKG_HDC_CTL_HDC_PKG_ENABLE; + else + msr &= ~PKG_HDC_CTL_HDC_PKG_ENABLE; + + if ( wrmsr_safe(MSR_PKG_HDC_CTL, msr) ) + { + hwp_err("wrmsr_safe(MSR_PKG_HDC_CTL): %016lx\n", cpu, msr); + + return -1; + } + + return 0; +} + +static int hdc_set_pm_ctl1(unsigned int cpu, bool val) +{ + uint64_t msr; + + if ( rdmsr_safe(MSR_PM_CTL1, msr) ) + { + hwp_err("rdmsr_safe(MSR_PM_CTL1)\n", cpu); + + return -1; + } + + if ( val ) + msr |= PM_CTL1_HDC_ALLOW_BLOCK; + else + msr &= ~PM_CTL1_HDC_ALLOW_BLOCK; + + if ( wrmsr_safe(MSR_PM_CTL1, msr) ) + { + hwp_err("wrmsr_safe(MSR_PM_CTL1): %016lx\n", cpu, msr); + + return -1; + } + + return 0; +} + +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); + + 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_PM_ENABLE, val) ) + { + hwp_err("rdmsr_safe(MSR_PM_ENABLE)\n", policy->cpu); + data->curr_req.raw = -1; + return; + } + + /* Ensure we don't generate interrupts */ + if ( feature_hwp_notification ) + wrmsr_safe(MSR_HWP_INTERRUPT, 0); + + hwp_verbose("CPU%u: MSR_PM_ENABLE: %016lx\n", policy->cpu, val); + if ( !(val & PM_ENABLE_HWP_ENABLE) ) + { + val |= PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_PM_ENABLE, val) ) + { + hwp_err("wrmsr_safe(MSR_PM_ENABLE, %lx)\n", policy->cpu, val); + data->curr_req.raw = -1; + return; + } + } + + if ( rdmsr_safe(MSR_HWP_CAPABILITIES, data->hwp_caps) ) + { + hwp_err("rdmsr_safe(MSR_HWP_CAPABILITIES)\n", policy->cpu); + goto error; + } + + if ( rdmsr_safe(MSR_HWP_REQUEST, data->curr_req.raw) ) + { + hwp_err("rdmsr_safe(MSR_HWP_REQUEST)\n", policy->cpu); + goto error; + } + + /* + * Check for APERF/MPERF support in hardware + * also check for boost/turbo support + */ + intel_feature_detect(policy); + + if ( feature_hdc ) + { + if ( hdc_set_pkg_hdc_ctl(policy->cpu, opt_cpufreq_hdc) ) + goto error; + if ( hdc_set_pm_ctl1(policy->cpu, opt_cpufreq_hdc) ) + goto error; + } + + hwp_get_cpu_speeds(policy); + + return; + + error: + data->curr_req.raw = -1; + val &= ~PM_ENABLE_HWP_ENABLE; + if ( wrmsr_safe(MSR_PM_ENABLE, val) ) + hwp_err("wrmsr_safe(MSR_PM_ENABLE, %lx)\n", policy->cpu, val); + + return; +} + +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_activity_window && data->activity_window ) + { + hwp_verbose("HWP activity window not supported\n"); + + return -EINVAL; + } + + return 0; +} + +static void cf_check hwp_write_request(void *info) +{ + const struct cpufreq_policy *policy = info; + struct hwp_drv_data *data = this_cpu(hwp_drv_data); + union hwp_request hwp_req = data->curr_req; + + data->ret = 0; + + BUILD_BUG_ON(sizeof(union hwp_request) != sizeof(uint64_t)); + if ( wrmsr_safe(MSR_HWP_REQUEST, hwp_req.raw) ) + { + hwp_verbose("CPU%u: error wrmsr_safe(MSR_HWP_REQUEST, %lx)\n", + policy->cpu, hwp_req.raw); + rdmsr_safe(MSR_HWP_REQUEST, data->curr_req.raw); + data->ret = -EINVAL; + } +} + +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; + 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 data->ret; +} + +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 && strcmp(cpufreq_opt_governor->name, + cpufreq_gov_hwp.name) ) + printk(XENLOG_WARNING + "HWP: governor \"%s\" is incompatible with hwp. Using default \"%s\"\n", + cpufreq_opt_governor->name, cpufreq_gov_hwp.name); + policy->governor = &cpufreq_gov_hwp; + + 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("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; + data->energy_perf = data->curr_req.energy_perf; + data->activity_window = data->curr_req.activity_window; + + hwp_verbose("CPU%u: 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_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; + struct hwp_drv_data *data = per_cpu(hwp_drv_data, policy->cpu); + uint64_t msr; + + data->ret = 0; + + if ( rdmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_verbose("CPU%u: error rdmsr_safe(MSR_IA32_MISC_ENABLE)\n", + policy->cpu); + data->ret = -EINVAL; + + 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_verbose("CPU%u: error wrmsr_safe(MSR_IA32_MISC_ENABLE): %016lx\n", + policy->cpu, msr); + data->ret = -EINVAL; + } +} + +static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *policy) +{ + struct hwp_drv_data *data = per_cpu(hwp_drv_data, cpuid); + on_selected_cpus(cpumask_of(cpuid), hwp_set_misc_turbo, policy, 1); + + return data->ret; +} + +static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver = +{ + .name = XEN_HWP_DRIVER, + .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 ace31e3b1f..00d618483c 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -52,8 +52,16 @@ static inline bool boot_cpu_has(unsigned int feat) return cpu_has(&boot_cpu_data, feat); } -#define CPUID_PM_LEAF 6 -#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID_PM_LEAF 6 +#define CPUID6_EAX_HWP BIT(7, U) +#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) +#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) +#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) +#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) +#define CPUID6_EAX_HDC BIT(13, U) +#define CPUID6_EAX_HWP_PECI BIT(16, U) +#define CPUID6_EAX_HW_FEEDBACK BIT(19, U) +#define CPUID6_ECX_APERFMPERF_CAPABILITY BIT(0, U) /* 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 2749e433d2..47b09a24b5 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -151,6 +151,13 @@ #define MSR_PKRS 0x000006e1 +#define MSR_PM_ENABLE 0x00000770 +#define PM_ENABLE_HWP_ENABLE BIT(0, ULL) + +#define MSR_HWP_CAPABILITIES 0x00000771 +#define MSR_HWP_INTERRUPT 0x00000773 +#define MSR_HWP_REQUEST 0x00000774 + #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff @@ -165,6 +172,11 @@ #define PASID_PASID_MASK 0x000fffff #define PASID_VALID (_AC(1, ULL) << 31) +#define MSR_PKG_HDC_CTL 0x00000db0 +#define PKG_HDC_CTL_HDC_PKG_ENABLE BIT(0, ULL) +#define MSR_PM_CTL1 0x00000db1 +#define PM_CTL1_HDC_ALLOW_BLOCK BIT(0, ULL) + #define MSR_UARCH_MISC_CTRL 0x00001b01 #define UARCH_CTRL_DOITM (_AC(1, ULL) << 0) @@ -503,6 +515,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 cccf9a64c8..b6e6d70ddf 100644 --- a/xen/drivers/cpufreq/cpufreq.c +++ b/xen/drivers/cpufreq/cpufreq.c @@ -97,6 +97,15 @@ static int __init cf_check setup_cpufreq_option(const char *str) return cpufreq_cmdline_parse(arg + 1); } + if ( choice < 0 && !cmdline_strcmp(str, "hwp") ) + { + xen_processor_pmbits |= XEN_PROCESSOR_PM_PX; + cpufreq_controller = FREQCTL_xen; + opt_cpufreq_hwp = true; + if ( *arg && *(arg + 1) ) + return hwp_cmdline_parse(arg + 1); + } + return (choice < 0) ? -EINVAL : 0; } custom_param("cpufreq", setup_cpufreq_option); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index a49efd1cb2..6ec7dbcbbb 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -246,4 +246,7 @@ void cpufreq_dbs_timer_resume(void); void intel_feature_detect(struct cpufreq_policy *policy); +extern bool __initdata opt_cpufreq_hwp; +int hwp_cmdline_parse(const char *s); + #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 bdcea99d71..08fe815329 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -296,6 +296,7 @@ struct xen_ondemand { uint32_t up_threshold; }; +#define XEN_HWP_DRIVER "hwp" /* * cpufreq para name of this structure named * same as sysfs file name of native linux From patchwork Wed Jun 14 18:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280282 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 A01FCEB64D9 for ; Wed, 14 Jun 2023 18:04:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549122.857524 (Exim 4.92) (envelope-from ) id 1q9UqY-0007Jh-AU; Wed, 14 Jun 2023 18:03:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549122.857524; Wed, 14 Jun 2023 18:03:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqY-0007J9-3b; Wed, 14 Jun 2023 18:03:54 +0000 Received: by outflank-mailman (input) for mailman id 549122; Wed, 14 Jun 2023 18:03:52 +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 1q9UqW-0005LA-Ha for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:52 +0000 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [2607:f8b0:4864:20::f35]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d0d6b2f1-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:50 +0200 (CEST) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-62fea2f19d5so3534926d6.0 for ; Wed, 14 Jun 2023 11:03:50 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:48 -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: d0d6b2f1-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765829; x=1689357829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BW3lKTSm5JYkGrQYyurYltq8i3jFBvOnwjMyoQl8MJY=; b=cA4pTGbySBWczEcKbl+TGDjiEJCwYOqs54YBNFgohCp1tgWnET/wQ3X0NTMjRLxbm0 jv5KELZXFxu9x0LtfwV+ocj+4KY3I/0EaeK3YceeIdpG5GUPjw0EzvuFIbO6Zivz17gF WImmEKDXJs8+3jhHATOgOkvXcFqH7m4z5GAL6vfU5CliY40AFLvGcuicSLakqD6wVeJK zmO/MlFGnvA5zgj1vn8iWQ32MuaSjsXE5BdWq/MWmJyp2jnPQtrKN43E+MdYHOBwyfYA 2A1cET9XYwAxnVn6exRs7VRpiRSt7JXQdMQYrF9RDULW2bXGQTSf1jyd88ffcrQ7xcl3 jEmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765829; x=1689357829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BW3lKTSm5JYkGrQYyurYltq8i3jFBvOnwjMyoQl8MJY=; b=bHr1z+Q3qBWHkC8Lr+QllkJVvu6tSdWaBkwxy1P2/lpPgdfk6fFRCD/e6w69Dh0lS7 rTsUBPYQ9dt51UtmXI7ShC8amSiW5v4sKhd1F13QSzEY9JYZL0Ic6smqoAaWYx8mBmjk Q1ti9v0dVJkM0/JDIiDNdh9rNoXgrfICZcD//bZLW/cvEdscKJARCR6ujeL1mutCUwSJ Ao0HTAQEO+BldvQeb50UPDdsYXIuX1uYE2qA9iQA0vz+pss+TIl7/yASuA55PbC3sN+y iPmeTuIxZPueShjoyzaK9HJaMX+WdtS/eDpMoKDgGcWepaqRKnQnci6waiJyuxFHxyk3 pWtw== X-Gm-Message-State: AC+VfDwd+3XRe+v2w9KHoEQnz9gcLNVOaxBWTJ87GH4OgPmOL7gskTsl 10PwUtlwUA9DPYUcoL4V5ooqRczYxzk= X-Google-Smtp-Source: ACHHUZ5Y/layCN4TDLjj5ioxrmoHmf9zUbZhIV64z78tfGT5H4NBF5sm6nLjqCJulx214g7aqajTYQ== X-Received: by 2002:a05:6214:1941:b0:62f:eed1:4781 with SMTP id q1-20020a056214194100b0062feed14781mr225846qvk.21.1686765829046; Wed, 14 Jun 2023 11:03:49 -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 v4 07/15] xen/x86: Tweak PDC bits when using HWP Date: Wed, 14 Jun 2023 14:02:45 -0400 Message-Id: <20230614180253.89958-8-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Qubes testing of HWP support had a report of a laptop, Thinkpad X1 Carbon Gen 4 with a Skylake processor, locking up during boot when HWP is enabled. A user found a kernel bug that seems to be the same issue: https://bugzilla.kernel.org/show_bug.cgi?id=110941. That bug was fixed by Linux commit a21211672c9a ("ACPI / processor: Request native thermal interrupt handling via _OSC"). The tl;dr is SMM crashes when it receives thermal interrupts, so Linux calls the ACPI _OSC method to take over interrupt handling. The Linux fix looks at the CPU features to decide whether or not to call _OSC with bit 12 set to take over native interrupt handling. Xen needs some way to communicate HWP to Dom0 for making an equivalent call. Xen exposes modified PDC bits via the platform_op set_pminfo hypercall. Expand that to set bit 12 when HWP is present and in use. Any generated interrupt would be handled by Xen's thermal drive, which clears the status. Bit 12 isn't named in the linux header and is open coded in Linux's usage. This will need a corresponding linux patch to pick up and apply the PDC bits. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- v4: Added __ro_after_init s/ACPI_PDC_CPPC_NTV_INT/ACPI_PDC_CPPC_NATIVE_INTR/ Remove _IA32_ Fixup for opt_cpufreq_hwp removal Add Jan Reviewed-by v3: New --- xen/arch/x86/acpi/cpufreq/hwp.c | 16 +++++++++++----- xen/arch/x86/acpi/lib.c | 5 +++++ xen/arch/x86/cpu/mcheck/mce_intel.c | 6 ++++++ xen/arch/x86/include/asm/msr-index.h | 1 + xen/include/acpi/cpufreq/processor_perf.h | 1 + xen/include/acpi/pdc_intel.h | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c index c62345dde7..5f210b54ff 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -13,7 +13,8 @@ #include #include -static bool __ro_after_init feature_hwp; +static bool __ro_after_init hwp_in_use; + static bool __ro_after_init feature_hwp_notification; static bool __ro_after_init feature_hwp_activity_window; @@ -168,6 +169,11 @@ static int __init cf_check cpufreq_gov_hwp_init(void) } __initcall(cpufreq_gov_hwp_init); +bool hwp_active(void) +{ + return hwp_in_use; +} + bool __init hwp_available(void) { unsigned int eax; @@ -211,7 +217,6 @@ bool __init hwp_available(void) 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_hdc = eax & CPUID6_EAX_HDC; @@ -224,12 +229,13 @@ bool __init hwp_available(void) hwp_verbose("HW_FEEDBACK %ssupported\n", (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); - cpufreq_governor_internal = feature_hwp; + hwp_in_use = eax & CPUID6_EAX_HWP; + cpufreq_governor_internal = hwp_in_use; - if ( feature_hwp ) + if ( hwp_in_use ) hwp_info("Using HWP for cpufreq\n"); - return feature_hwp; + return hwp_in_use; } static int hdc_set_pkg_hdc_ctl(unsigned int cpu, bool val) diff --git a/xen/arch/x86/acpi/lib.c b/xen/arch/x86/acpi/lib.c index 43831b92d1..1b4710a790 100644 --- a/xen/arch/x86/acpi/lib.c +++ b/xen/arch/x86/acpi/lib.c @@ -26,6 +26,8 @@ #include #include +#include + u32 __read_mostly acpi_smi_cmd; u8 __read_mostly acpi_enable_value; u8 __read_mostly acpi_disable_value; @@ -140,5 +142,8 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 mask) !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) pdc[2] &= ~(ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH); + if (hwp_active()) + pdc[2] |= ACPI_PDC_CPPC_NATIVE_INTR; + return 0; } diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/mce_intel.c index 2f23f02923..c95152ad85 100644 --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -15,6 +15,9 @@ #include #include #include + +#include + #include "mce.h" #include "x86_mca.h" #include "barrier.h" @@ -64,6 +67,9 @@ static void cf_check intel_thermal_interrupt(struct cpu_user_regs *regs) ack_APIC_irq(); + if ( hwp_active() ) + wrmsr_safe(MSR_HWP_STATUS, 0); + if ( NOW() < per_cpu(next, cpu) ) return; diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/asm/msr-index.h index 47b09a24b5..351745f6bc 100644 --- a/xen/arch/x86/include/asm/msr-index.h +++ b/xen/arch/x86/include/asm/msr-index.h @@ -157,6 +157,7 @@ #define MSR_HWP_CAPABILITIES 0x00000771 #define MSR_HWP_INTERRUPT 0x00000773 #define MSR_HWP_REQUEST 0x00000774 +#define MSR_HWP_STATUS 0x00000777 #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/cpufreq/processor_perf.h index b751ca4937..dd8ec36ba7 100644 --- a/xen/include/acpi/cpufreq/processor_perf.h +++ b/xen/include/acpi/cpufreq/processor_perf.h @@ -8,6 +8,7 @@ #define XEN_PX_INIT 0x80000000 bool hwp_available(void); +bool hwp_active(void); int hwp_register_driver(void); int powernow_cpufreq_init(void); diff --git a/xen/include/acpi/pdc_intel.h b/xen/include/acpi/pdc_intel.h index 4fb719d6f5..abaa098b51 100644 --- a/xen/include/acpi/pdc_intel.h +++ b/xen/include/acpi/pdc_intel.h @@ -17,6 +17,7 @@ #define ACPI_PDC_C_C1_FFH (0x0100) #define ACPI_PDC_C_C2C3_FFH (0x0200) #define ACPI_PDC_SMP_P_HWCOORD (0x0800) +#define ACPI_PDC_CPPC_NATIVE_INTR (0x1000) #define ACPI_PDC_EST_CAPABILITY_SMP (ACPI_PDC_SMP_C1PT | \ ACPI_PDC_C_C1_HALT | \ From patchwork Wed Jun 14 18:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280284 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 93D54EB64D9 for ; Wed, 14 Jun 2023 18:04:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549123.857531 (Exim 4.92) (envelope-from ) id 1q9UqZ-0007XO-1F; Wed, 14 Jun 2023 18:03:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549123.857531; Wed, 14 Jun 2023 18:03:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqY-0007U8-PH; Wed, 14 Jun 2023 18:03:54 +0000 Received: by outflank-mailman (input) for mailman id 549123; Wed, 14 Jun 2023 18:03:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9UqX-0005LA-HX for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:53 +0000 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [2607:f8b0:4864:20::732]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d210f1d2-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:52 +0200 (CEST) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-75d528d0811so236879185a.0 for ; Wed, 14 Jun 2023 11:03:52 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:50 -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: d210f1d2-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765831; x=1689357831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fxVGZ+gvz08OKoWjfCFPcTsdFvOXHOS/NxFkI1JhnIY=; b=LKbwpHLzISyP75fjQUXwZsbNJE6lOz2vmOUuNIfFAvKHNACDHK12L9edz0k0+jEQuQ 5VcMUx9ehO3prQURyQvX3P4qfLdifPjLP05pB5PlfymDB5Xlm3TBJC8pReG3rW3dPf77 oMQcoOJNdusMS6kjJ3VjAwzJk1vqimMWMsH/Jei4X5Y2vmHMUqi6KjFTAJ1ISlS9+/Wz WiLrGvUvJOHkkE1JDdSGsBeU7J5PIZdHXH4KBGBJgHRChQbh2FVJTrpy3pocrP2oZsJz fskfk3Ic9tQdWBxMCTmo/H21oF7LaEuZYvCCU/oLyfDqeI1mHO4A4fxsE43I5iOz+/pv luzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765831; x=1689357831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fxVGZ+gvz08OKoWjfCFPcTsdFvOXHOS/NxFkI1JhnIY=; b=cnP88vxKNAS84u4pzwSWivbPNf24tingHwDmSaTOLAf+l3nVr31nMqK1jR9xx7+aoC oLSofrO+VQ9JcF5pd43K6Z0m/YNb2ycBOj2os3ZBWHXTt9VP2EhcCa/KRJgschKOuk0Y rMd2d8fPn8iZUHQJF5fOxEFvS5WiZWzlGQ2trPXw3zs2YFoIeWHgCpEEg9PMbMwjp3QQ v2dBEhCfVE88jKKxzjnpTDTA9dDRbkEcb3Em86F5rR1IGirqQWkJh2C5aID4DJ6+OSa1 QNAuaNsaNfotG6WkxgpEnAicNnJyk3Kzo29atssSjhokTWdUGi5oKnUjHGGY9mhUpsbT q3vg== X-Gm-Message-State: AC+VfDxpzQF3ikyW/Wga6ATx7+iFSgkCWfh/CB/Z/M+y8VdWVP1lwj2f yX/nrzvANUyOPsdgK5U8TuCx9v20rEA= X-Google-Smtp-Source: ACHHUZ5ioKKeef9cH4i55/FDg6yrWqp0eMHgoVA2PeT+JYpLBZc+rS0GufDj17GD9r3/h4y5fhgfgg== X-Received: by 2002:a05:6214:c2c:b0:625:ba46:27e6 with SMTP id a12-20020a0562140c2c00b00625ba4627e6mr21097267qvd.2.1686765831038; Wed, 14 Jun 2023 11:03:51 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v4 08/15] xenpm: Change get-cpufreq-para output for hwp Date: Wed, 14 Jun 2023 14:02:46 -0400 Message-Id: <20230614180253.89958-9-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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 max frequencies since those are relevant to HWP. Similarly, stop printing the CPU frequencies since those do not apply. The scaling fields are also no longer printed. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v2: Use full governor name XEN_HWP_GOVERNOR to change output Style fixes v4: s/turbo/max/ Check for XEN_HWP_DRIVER driver instead of "-internal" --- tools/misc/xenpm.c | 83 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1c474c3b59..4e53e68dc5 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 hwp = strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER) == 0; int i; printf("cpu id : %d\n", cpuid); @@ -720,49 +721,57 @@ 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 ( hwp ) + printf("cpuinfo frequency : base [%u] max [%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); - printf("scaling_avail_gov : %s\n", - p_cpufreq->scaling_available_governors); - - printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); - if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - printf(" userspace specific :\n"); - printf(" scaling_setspeed : %u\n", - p_cpufreq->u.s.u.userspace.scaling_setspeed); - } - else if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "ondemand", CPUFREQ_NAME_LEN) ) + if ( !hwp ) { - printf(" ondemand specific :\n"); - printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.u.ondemand.sampling_rate_max, - p_cpufreq->u.s.u.ondemand.sampling_rate_min, - p_cpufreq->u.s.u.ondemand.sampling_rate); - printf(" up_threshold : %u\n", - p_cpufreq->u.s.u.ondemand.up_threshold); - } + printf("scaling_avail_gov : %s\n", + p_cpufreq->scaling_available_governors); - printf("scaling_avail_freq :"); - for ( i = 0; i < p_cpufreq->freq_num; i++ ) - if ( p_cpufreq->scaling_available_frequencies[i] == - p_cpufreq->u.s.scaling_cur_freq ) - printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); - else - printf(" %d", p_cpufreq->scaling_available_frequencies[i]); - printf("\n"); + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + { + printf(" userspace specific :\n"); + printf(" scaling_setspeed : %u\n", + p_cpufreq->u.s.u.userspace.scaling_setspeed); + } + else if ( !strncmp(p_cpufreq->u.s.scaling_governor, + "ondemand", CPUFREQ_NAME_LEN) ) + { + printf(" ondemand specific :\n"); + printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", + p_cpufreq->u.s.u.ondemand.sampling_rate_max, + p_cpufreq->u.s.u.ondemand.sampling_rate_min, + p_cpufreq->u.s.u.ondemand.sampling_rate); + printf(" up_threshold : %u\n", + p_cpufreq->u.s.u.ondemand.up_threshold); + } + + printf("scaling_avail_freq :"); + for ( i = 0; i < p_cpufreq->freq_num; i++ ) + if ( p_cpufreq->scaling_available_frequencies[i] == + p_cpufreq->u.s.scaling_cur_freq ) + printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); + else + printf(" %d", p_cpufreq->scaling_available_frequencies[i]); + printf("\n"); - printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.scaling_max_freq, - p_cpufreq->u.s.scaling_min_freq, - p_cpufreq->u.s.scaling_cur_freq); + printf("scaling frequency : max [%u] min [%u] cur [%u]\n", + p_cpufreq->u.s.scaling_max_freq, + p_cpufreq->u.s.scaling_min_freq, + p_cpufreq->u.s.scaling_cur_freq); + } printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); From patchwork Wed Jun 14 18:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280283 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 BA9CCEB64D8 for ; Wed, 14 Jun 2023 18:04:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549126.857548 (Exim 4.92) (envelope-from ) id 1q9Uqb-0008E7-DD; Wed, 14 Jun 2023 18:03:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549126.857548; Wed, 14 Jun 2023 18:03:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uqb-0008Dw-9A; Wed, 14 Jun 2023 18:03:57 +0000 Received: by outflank-mailman (input) for mailman id 549126; Wed, 14 Jun 2023 18:03:56 +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 1q9Uqa-0005LA-IC for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:56 +0000 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [2607:f8b0:4864:20::f36]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d34dc8a1-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:55 +0200 (CEST) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-5ed99ebe076so20968856d6.2 for ; Wed, 14 Jun 2023 11:03:55 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:52 -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: d34dc8a1-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765833; x=1689357833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uF8Wj46GTB4zKmfvuCCfVeswvcmmkhkf2knhpTgohUg=; b=IkDKOvKKl5vU1x2uhj2Gw+eeCWbPihqscD/s5K3RdP4VtDf2nyAr9ut6EkAk8mvopn hsx3vrYs5xK5YEU5Xz5BSljnmaeiGIQQzhI5O/++7/T3rWmizocyR44RYkZWPYT6gY13 C99Q8FzB+/GQOVQRHn+JN72uaQsq51oGnNU06TKvhuagzTJI0V8jJqsN6PSzZuQB8tws QJl5Fk62SC5zcuZwsKEeXygAE39w8cimhQMNtAulEUrmBfXTOl+cfyA/BK2QYHIe08pK vZegIsbWgklsyDGnAOOL16tTW1ArKDaQZVshRBBLrfUJLsfhsg8l8GnkhPg0gi+O445L XT3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765833; x=1689357833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uF8Wj46GTB4zKmfvuCCfVeswvcmmkhkf2knhpTgohUg=; b=MT9A+Px6XfJVo3n4jRhjoUW1HQVoAndn8GrbJ7zDkR2cZjlDVChss0YJXqAOwZOoNM 49VFz/ggMk8Lyj9Z6BIYKjVXIQAPTt2B5n73gNcRd6r5VjzqNk+lzs65SQL/VTynS+rf H7wmMVIyKwLjw7AxR062NjQE4U22B0H1SyBK2DnammMLrvd3IYXWeok4Nd6hzTg+J58T 0VB1IfLk2w23cr5RcGwZ31gcEadI/HK/wkm7dRkk8nLTVBs2FrNAsW5Izq78Xc3AjhWH lD2XCcBLuSpG8T6X1RuUY7Oa101n8W8cX96vpZe2w/LHLIYYx3VkX3cshmyxRLcHwxKP xaCw== X-Gm-Message-State: AC+VfDxNjtuWJgyl4jgOA6Uc17PI4v/6lJc1RP92KeCUKgctLCaOzJ5n XK1GguEvCLh0oqWvT37G49w4pxXx6Vs= X-Google-Smtp-Source: ACHHUZ78fPAF59pf1hisnYm84QCHRPh63yXRIYNML21YOpd3hr1AXgZlNoX4wTttmORx4HLvYP0F7A== X-Received: by 2002:ad4:5c41:0:b0:62d:e9d5:336 with SMTP id a1-20020ad45c41000000b0062de9d50336mr14643490qva.41.1686765833314; Wed, 14 Jun 2023 11:03:53 -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 v4 09/15] cpufreq: Export HWP parameters to userspace as CPPC Date: Wed, 14 Jun 2023 14:02:47 -0400 Message-Id: <20230614180253.89958-10-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Extend xen_get_cpufreq_para to return hwp parameters. HWP is an implementation of ACPI CPPC (Collaborative Processor Performance Control). Use the CPPC name since that might be useful in the future for AMD P-state. We need the features bitmask to indicate fields supported by the actual hardware - this only applies to activity window for the time being. The HWP most_efficient is mapped to CPPC lowest_nonlinear, and guaranteed is mapped to nominal. CPPC has a guaranteed that is optional while nominal is required. ACPI spec says "If this register is not implemented, OSPM assumes guaranteed performance is always equal to nominal performance." 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 v4: Fixup for opt_cpufreq_hwp/hdc removal get_hwp_para() takes cpu as arg XEN_ prefix HWP_ACT_WINDOW_* Drop HWP_ACT_WINDOW_EXPONENT_SHIFT - shift MASK Remove Energy Bias (0-15) EPP fallback Rename xen_hwp_para to xen_cppc_para s/hwp/cppc/ Use scaling driver to switch output --- xen/arch/x86/acpi/cpufreq/hwp.c | 23 +++++++++ xen/drivers/acpi/pmstat.c | 78 ++++++++++++++++-------------- xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 56 +++++++++++++++++++++ 4 files changed, 123 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c index 5f210b54ff..86c5793266 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -537,6 +537,29 @@ static const struct cpufreq_driver __initconstrel hwp_cpufreq_driver = .update = hwp_cpufreq_update, }; +int get_hwp_para(const unsigned int cpu, + struct xen_cppc_para *cppc_para) +{ + const struct hwp_drv_data *data = per_cpu(hwp_drv_data, cpu); + + if ( data == NULL ) + return -EINVAL; + + cppc_para->features = + (feature_hwp_activity_window ? XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW : 0); + cppc_para->lowest = data->hw.lowest; + cppc_para->lowest_nonlinear = data->hw.most_efficient; + cppc_para->nominal = data->hw.guaranteed; + cppc_para->highest = data->hw.highest; + cppc_para->minimum = data->minimum; + cppc_para->maximum = data->maximum; + cppc_para->desired = data->desired; + cppc_para->energy_perf = data->energy_perf; + cppc_para->activity_window = data->activity_window; + + 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 57359c21d8..10143c084c 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -251,48 +251,54 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) else strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN); - if ( !(scaling_available_governors = - xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) - return -ENOMEM; - if ( (ret = read_scaling_available_governors( - scaling_available_governors, - gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + if ( !strncasecmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER, + CPUFREQ_NAME_LEN) ) + ret = get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para); + else { + if ( !(scaling_available_governors = + xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) + return -ENOMEM; + if ( (ret = read_scaling_available_governors( + scaling_available_governors, + gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + { + xfree(scaling_available_governors); + return ret; + } + ret = copy_to_guest(op->u.get_para.scaling_available_governors, + scaling_available_governors, gov_num * CPUFREQ_NAME_LEN); xfree(scaling_available_governors); - return ret; - } - ret = copy_to_guest(op->u.get_para.scaling_available_governors, - scaling_available_governors, gov_num * CPUFREQ_NAME_LEN); - xfree(scaling_available_governors); - if ( ret ) - return ret; + if ( ret ) + return ret; - op->u.get_para.u.s.scaling_cur_freq = policy->cur; - op->u.get_para.u.s.scaling_max_freq = policy->max; - op->u.get_para.u.s.scaling_min_freq = policy->min; + op->u.get_para.u.s.scaling_cur_freq = policy->cur; + op->u.get_para.u.s.scaling_max_freq = policy->max; + op->u.get_para.u.s.scaling_min_freq = policy->min; - if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.u.s.scaling_governor, - policy->governor->name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", - CPUFREQ_NAME_LEN); + if ( policy->governor->name[0] ) + strlcpy(op->u.get_para.u.s.scaling_governor, + policy->governor->name, CPUFREQ_NAME_LEN); + else + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", + CPUFREQ_NAME_LEN); - /* governor specific para */ - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - op->u.get_para.u.s.u.userspace.scaling_setspeed = policy->cur; - } + /* governor specific para */ + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + { + op->u.get_para.u.s.u.userspace.scaling_setspeed = policy->cur; + } - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, - "ondemand", CPUFREQ_NAME_LEN) ) - { - ret = get_cpufreq_ondemand_para( - &op->u.get_para.u.s.u.ondemand.sampling_rate_max, - &op->u.get_para.u.s.u.ondemand.sampling_rate_min, - &op->u.get_para.u.s.u.ondemand.sampling_rate, - &op->u.get_para.u.s.u.ondemand.up_threshold); + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + "ondemand", CPUFREQ_NAME_LEN) ) + { + ret = get_cpufreq_ondemand_para( + &op->u.get_para.u.s.u.ondemand.sampling_rate_max, + &op->u.get_para.u.s.u.ondemand.sampling_rate_min, + &op->u.get_para.u.s.u.ondemand.sampling_rate, + &op->u.get_para.u.s.u.ondemand.up_threshold); + } } return ret; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h index 6ec7dbcbbb..fb655fac14 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -248,5 +248,7 @@ void intel_feature_detect(struct cpufreq_policy *policy); extern bool __initdata opt_cpufreq_hwp; int hwp_cmdline_parse(const char *s); +int get_hwp_para(const unsigned int cpu, + struct xen_cppc_para *cppc_para); #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 08fe815329..5c9b60b5d0 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -296,6 +296,61 @@ struct xen_ondemand { uint32_t up_threshold; }; +struct xen_cppc_para { + /* OUT */ + /* activity_window supported if 1 */ +#define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW (1 << 0) + uint32_t features; /* bit flags for features */ + /* + * See Intel SDM: HWP Performance Range and Dynamic Capabilities + * + * These four are 0-255 hardware-provided values. They "continuous, + * abstract unit-less, performance" values. smaller numbers are slower + * and larger ones are faster. + */ + uint32_t lowest; + uint32_t lowest_nonlinear; /* most_efficient */ + uint32_t nominal; /* guaranteed */ + uint32_t highest; + /* + * See Intel SDM: IA32_HWP_REQUEST MSR (Address: 774H Logical Processor + * Scope) + * + * These are all hints, and the processor may deviate outside of them. + * Values below are 0-255. + * + * minimum and maximum can be set to the above hardware values to constrain + * operation. The full range 0-255 is accepted and will be clipped by + * hardware. + */ + uint32_t minimum; + uint32_t maximum; + /* + * Set an explicit performance hint, disabling hardware selection. + * 0 lets the hardware decide. + */ + uint32_t desired; + /* + * Hint to hardware for energy/performance preference. + * 0: Performance + * 128: Balance (Default) + * 255: Powersaving + */ + uint32_t energy_perf; + /* + * Activity Window is a moving history window for the processor's operation + * calculations, controlling responsiveness. Measured in microseconds + * encoded as: + * + * bits 6:0 - 7bit mantissa + * bits 9:7 - 3bit base-10 exponent + * btis 15:10 - Unused - must be 0 + */ +#define XEN_CPPC_ACT_WINDOW_MANTISSA_MASK 0x07f +#define XEN_CPPC_ACT_WINDOW_EXPONENT_MASK 0x380 + uint32_t activity_window; +}; + #define XEN_HWP_DRIVER "hwp" /* * cpufreq para name of this structure named @@ -332,6 +387,7 @@ struct xen_get_cpufreq_para { struct xen_ondemand ondemand; } u; } s; + struct xen_cppc_para cppc_para; } u; int32_t turbo_enabled; From patchwork Wed Jun 14 18:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280360 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 51F33EB64DB for ; Wed, 14 Jun 2023 18:09:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549177.857598 (Exim 4.92) (envelope-from ) id 1q9Uvv-0004hS-Mm; Wed, 14 Jun 2023 18:09:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549177.857598; Wed, 14 Jun 2023 18:09:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uvv-0004hJ-K2; Wed, 14 Jun 2023 18:09:27 +0000 Received: by outflank-mailman (input) for mailman id 549177; Wed, 14 Jun 2023 18:09:25 +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 1q9Uqb-0005LA-IL for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:03:57 +0000 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [2607:f8b0:4864:20::f33]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d478b45e-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:03:57 +0200 (CEST) Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-62df5fbb186so16921436d6.1 for ; Wed, 14 Jun 2023 11:03:57 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:54 -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: d478b45e-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765835; x=1689357835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vAh4UqPFdXosdcswDrRJWUQizeR7RUgorIbVDVeVJRs=; b=X+HlpS06rAtgVCWY0crtm+qx5JIids4vI3b6kS1cielwi9+1KHwe8ZAW7NtcW1Z4dJ xunVSd5e+wrLJ/PVIloMK9NEOtmpqgQc7Tpd4RZMRndpZo71t1uPhD5gECa5aNILl8td 8DwsZ3wa6NMUFTKC1DbUoyU5VXRLm7uIRTBu0feXqtgmXe1pn4bKJDXe8tBjm5opRq6p ifZV5Ljavi/jaXHW47l9Y8PBDtLroLi24LXzi5VUoirojILRHnBli8L3Xryafz7Y6mYl BeTK84ZRr9521JAOZ2i6l4vS01DiBYRXdrkRY2ynvtg9r5tTKgIwM7izEjDbOKRywIAs kd8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765835; x=1689357835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vAh4UqPFdXosdcswDrRJWUQizeR7RUgorIbVDVeVJRs=; b=QTgQ6viuMpTnmCp7J3TQCmu1V4TE2QV6pphYnj7RnIeIDXHh4V4qmpPrvObAMeEOEH xddo5J376fpznFIlnuGLCLDb0OWALJ2AHPUrofxHw9dH3iKElKDJqoddfgxSS01kQIkA EtsqFjME21uSrxXeYf8fzyoW6hXdEEyn+NQboy4vYNEk+k3KDpgOc4RJHcJMFdRQsUWn rc7zZH8/cYX8kvHV15JiywbK0X2Ey/A4T0OqdhQxG0AFgh1XY/eM0f0taoTfwPBJtN9I bkzL8O6xCHJhlfsRiZ6sct221L1Q4yXxKdslCDMhVO8BlauSreS1b5WR+AuHvVLM2vEJ syrA== X-Gm-Message-State: AC+VfDwjLIwbieqYXjbGKslUdsyMMb66jRP2IAxmzrnLoba2VZ6G1jip nFDL/uwkdUcTQEsrW5RQYtn1BjQTK3k= X-Google-Smtp-Source: ACHHUZ4u4u7yyWfrVT40b45uaJ1E5n895mmSlLtzhbqTU3eM3yEL4zsg9xAWfESP7KfaFvF61oAkvA== X-Received: by 2002:a05:6214:daa:b0:62d:f8e7:3047 with SMTP id h10-20020a0562140daa00b0062df8e73047mr6018004qvh.55.1686765835302; Wed, 14 Jun 2023 11:03:55 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 10/15] libxc: Include cppc_para in definitions Date: Wed, 14 Jun 2023 14:02:48 -0400 Message-Id: <20230614180253.89958-11-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Expose the cppc_para fields through libxc. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v4: Rename hwp to cppc Add Anthony's Ack --- tools/include/xenctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 8aedb952a0..2092632296 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1892,6 +1892,7 @@ int xc_smt_disable(xc_interface *xch); */ typedef struct xen_userspace xc_userspace_t; typedef struct xen_ondemand xc_ondemand_t; +typedef struct xen_cppc_para xc_cppc_para_t; struct xc_get_cpufreq_para { /* IN/OUT variable */ @@ -1923,6 +1924,7 @@ struct xc_get_cpufreq_para { xc_ondemand_t ondemand; } u; } s; + xc_cppc_para_t cppc_para; } u; int32_t turbo_enabled; From patchwork Wed Jun 14 18:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280287 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 E30C1EB64D8 for ; Wed, 14 Jun 2023 18:04:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549130.857558 (Exim 4.92) (envelope-from ) id 1q9Uqg-0000PS-VI; Wed, 14 Jun 2023 18:04:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549130.857558; Wed, 14 Jun 2023 18:04:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uqg-0000PH-Qs; Wed, 14 Jun 2023 18:04:02 +0000 Received: by outflank-mailman (input) for mailman id 549130; Wed, 14 Jun 2023 18:04:01 +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 1q9Uqf-0005L9-Cw for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:04:01 +0000 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [2607:f8b0:4864:20::f2d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d61b5b31-0add-11ee-8611-37d641c3527e; Wed, 14 Jun 2023 20:03:59 +0200 (CEST) Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-62de85dd962so18741206d6.0 for ; Wed, 14 Jun 2023 11:03:59 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:57 -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: d61b5b31-0add-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765838; x=1689357838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2G+0xPmD9u5kzp6yWDZeh7ZvMy436YMgfg56aXJDM/0=; b=HFJzrNHYhSAPngEZ+wRb669gxq7uVYIQUwX4ldz3MzimvMKIFT8t83knxO0WaPhlMW BlpJMbxpKr85dkg4lpDWbbe/ceItB8S8VEcWrwPcnQrmvFip/nZaXKTAy1EtTognkWSr SGSdSZB62pmMdcnIWJ17A6BvqfebQU5wipwGbDycElYp67dlTD2u/74NcKg+6LOf9835 9pIvtH+uw8nSDLw+u4oAgMVbSyvlfPWNIa1Ft6jllKH4zyV8/MBUbIoKfMJAwT/JuA9N 0usYC2hGp+OOHfEiozYpIEgiApujrkYvlFd/5+22k+7dAgAMZo3W6taCx3X3DCycfDbd LhgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765838; x=1689357838; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2G+0xPmD9u5kzp6yWDZeh7ZvMy436YMgfg56aXJDM/0=; b=JSWPnyD9UnrQbKuxWpUkl6rxrvaA2b8qPEORGLseUuuU6OTE0NlhsVC8Fq0ETkSLyI fb/i3SsMJERHR1pt6EiZp7oAadPAyHD/JJglrFy0HCyxDwmhsAtoly2PQ1M48QQzk3gD ZF5m1OfzaFdb6hDsxWkJArCjyH4V8TXDDgFgT0AknflPaihHnsR9VAkh1M0NvMkU3U74 PhP5CL0YRiAEMFmcnkW/m68SXDW5H9YKlHfjwegscVWaeETccGbNyEXpYZ+dfmn2/hBs OhwrrNj87ErvT5tb2Hv7rEz7+vYJPoLiqUPN8XfC43rgCUQ10wsCuTxY9i85UGDQg9/O YXZg== X-Gm-Message-State: AC+VfDw83zb/PQe9HK50susQcZzzmr08/vpRJ1Nuz6mIb6pa05FoJQgg LZlCpneX8oQNauCw26RG9EtdO7sJn3o= X-Google-Smtp-Source: ACHHUZ740s5OQ6s/5g9KdK4xRCjO1EnL5dM8aI86KWmOknFw61KSZMzn+Po6mkTlPMwNCiQ5pD7ZMw== X-Received: by 2002:ad4:5dea:0:b0:62d:f8e7:3043 with SMTP id jn10-20020ad45dea000000b0062df8e73043mr5465088qvb.18.1686765837938; Wed, 14 Jun 2023 11:03:57 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v4 11/15] xenpm: Print HWP/CPPC parameters Date: Wed, 14 Jun 2023 14:02:49 -0400 Message-Id: <20230614180253.89958-12-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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 Reviewed-by: Jan Beulich --- v2: Style fixes Declare i outside loop Replace repearted hardware/configured limits with spaces Fixup for hw_ removal Use XEN_HWP_GOVERNOR Use HWP_ACT_WINDOW_EXPONENT_* Remove energy_perf hw autonomous - 0 doesn't mean autonomous v4: Return activity_window from calculate_hwp_activity_window Use blanks instead of _ in output Use MASK_EXTR Check XEN_HWP_DRIVER name since governor is no longer returned s/hwp/cppc --- tools/misc/xenpm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 4e53e68dc5..488797fd20 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -708,6 +708,46 @@ void start_gather_func(int argc, char *argv[]) pause(); } +static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, + const char **units) +{ + unsigned int mantissa = MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + unsigned int exponent = MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_EXPONENT_MASK); + unsigned int multiplier = 1; + unsigned int i; + + /* + * SDM only states a 0 register is hardware selected, and doesn't mention + * a 0 mantissa with a non-0 exponent. Only special case a 0 register. + */ + if ( cppc->activity_window == 0 ) + { + *units = "hardware selected"; + + return 0; + } + + 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; + + return mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) { @@ -772,6 +812,32 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) p_cpufreq->u.s.scaling_min_freq, p_cpufreq->u.s.scaling_cur_freq); } + else + { + const xc_cppc_para_t *cppc = &p_cpufreq->u.cppc_para; + + printf("cppc variables :\n"); + printf(" hardware limits : lowest [%u] lowest nonlinear [%u]\n", + cppc->lowest, cppc->lowest_nonlinear); + printf(" : nominal [%u] highest [%u]\n", + cppc->nominal, cppc->highest); + printf(" configured limits : min [%u] max [%u] energy perf [%u]\n", + cppc->minimum, cppc->maximum, cppc->energy_perf); + + if ( cppc->features & XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW ) + { + unsigned int activity_window; + const char *units; + + activity_window = calculate_activity_window(cppc, &units); + printf(" : activity_window [%u %s]\n", + activity_window, units); + } + + printf(" : desired [%u%s]\n", + cppc->desired, + cppc->desired ? "" : " hw autonomous"); + } printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); From patchwork Wed Jun 14 18:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280286 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 A295CEB64D9 for ; Wed, 14 Jun 2023 18:04:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549131.857568 (Exim 4.92) (envelope-from ) id 1q9Uqk-0000qI-E5; Wed, 14 Jun 2023 18:04:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549131.857568; Wed, 14 Jun 2023 18:04:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uqk-0000q9-5v; Wed, 14 Jun 2023 18:04:06 +0000 Received: by outflank-mailman (input) for mailman id 549131; Wed, 14 Jun 2023 18:04:04 +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 1q9Uqi-0005L9-27 for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:04:04 +0000 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [2607:f8b0:4864:20::72d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d7756023-0add-11ee-8611-37d641c3527e; Wed, 14 Jun 2023 20:04:02 +0200 (CEST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-75da00a1eddso238630185a.3 for ; Wed, 14 Jun 2023 11:04:02 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:03:59 -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: d7756023-0add-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765840; x=1689357840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1GKrKS8MiOO/3IyATz8/1ZuFV/xDUGqEs/80K9twFs0=; b=esf7L9t+l/diomCDY4BXb+pi7Ip3FWjbSJST8nXYCU+g31ySOqGJhpWfw0Tj4cUzDo pVLj0k3qNE5gtEJpHkbERTnJkCQyVrIIdwd4RNmhPECaETgMHB4taCHichGuCHV8Q7HP UjdmEnCOl3+/OjT3pCRXkMhW9fbPGXq/tSOU+lstjLwrXkD7qOH6UKLZVLUqgU1GMvMa S7Rfai24HF5NNjJNh/6PSVrOCVyhPEoTcUwt/GibVbAbwNifahUXmNMijVbu5hcq78OA 88sqCcU8h3Ur3VOEnp9rVpNfgr5UJ3lZ8L6OyDOw9aFU/UN3RjbT835RZgteCtC9sz+q OSzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765840; x=1689357840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1GKrKS8MiOO/3IyATz8/1ZuFV/xDUGqEs/80K9twFs0=; b=g2a8UtZYZwhx6O93mCjnywBfQn3yp0acXp+DwmFxhrRzDnIzMTFtXOM2KxShZc9wUJ pJ6ee8w8k+avj8isqH1tUTjVqvpFnEd0nlydjAYnNJJPSP7s10p7BO6ykb36WhA/RKfq gCFax0pszoPuJpSGUIdFoMJFHJKp8DOjS2GWTwkvqbiae9JAkc7U6j+l+1riZ3xNOMMj aC5SFLmidCh7U2Fg0InV9IFo71GQdId+2Uy3Fe/WTb8kh4L/XludQfyrNn41DhvAdNJ/ EG0BVYxlpVjgRD5F6JWhjVqGN3BtR9sCy05yeoOjUjtqS+0aWbkDp1Osrhk4XDLBBgbK PqgA== X-Gm-Message-State: AC+VfDwMwDO+venoKzwxvRpHviXJrt6K7IoPE2sWyn7thhRwOWRUhbeO 3MkwhCJMIv6EzdhF7wmUoUApPLqvRaU= X-Google-Smtp-Source: ACHHUZ4V73ClCfCNGt+bqS0RlR2jIE8NAYMZmmKlUEAS2C/EcyReY9KwirAaERaWSiv4w7yaIaTAtQ== X-Received: by 2002:a05:6214:21eb:b0:623:9e5c:e625 with SMTP id p11-20020a05621421eb00b006239e5ce625mr16756670qvj.29.1686765840404; Wed, 14 Jun 2023 11:04:00 -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 v4 12/15] xen: Add SET_CPUFREQ_HWP xen_sysctl_pm_op Date: Wed, 14 Jun 2023 14:02:50 -0400 Message-Id: <20230614180253.89958-13-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-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 --- v4: Remove IA32_ENERGY_BIAS support Validate parameters don't exceed 255 Use CPPC/cppc name set_cppc_para() add const set_cppc_para() return hwp_cpufreq_target() Expand sysctl comments v3: Remove cpufreq_governor_internal from set_cpufreq_hwp v2: Update for naming anonymous union Drop hwp_err for invalid input in set_hwp_para() Drop uint16_t cast in XEN_SYSCTL_HWP_SET_PARAM_MASK Drop parens for HWP_SET_PRESET defines Reference activity_window format comment Place SET_CPUFREQ_HWP after SET_CPUFREQ_PARA Add {HWP,IA32}_ENERGY_PERF_MAX_{PERFORMANCE,POWERSAVE} defines Order defines before fields in sysctl.h Use XEN_HWP_GOVERNOR Use per_cpu for hwp_drv_data --- xen/arch/x86/acpi/cpufreq/hwp.c | 98 ++++++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 17 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 + xen/include/public/sysctl.h | 58 ++++++++++++++++++ 4 files changed, 175 insertions(+) diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hwp.c index 86c5793266..3ee046940c 100644 --- a/xen/arch/x86/acpi/cpufreq/hwp.c +++ b/xen/arch/x86/acpi/cpufreq/hwp.c @@ -23,6 +23,10 @@ static bool __ro_after_init feature_hdc; bool __initdata opt_cpufreq_hwp; static bool __ro_after_init opt_cpufreq_hdc = true; +#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 +#define HWP_ENERGY_PERF_BALANCE 0x80 +#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff + union hwp_request { struct @@ -560,6 +564,100 @@ int get_hwp_para(const unsigned int cpu, return 0; } +int set_hwp_para(struct cpufreq_policy *policy, + const struct xen_set_cppc_para *set_cppc) +{ + 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_cppc->set_params & ~XEN_SYSCTL_CPPC_SET_PARAM_MASK ) + return -EINVAL; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW && + !feature_hwp_activity_window ) + return -EINVAL; + + if ( !(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW) && + set_cppc->activity_window ) + return -EINVAL; + + if ( set_cppc->activity_window & ~XEN_SYSCTL_CPPC_ACT_WINDOW_MASK ) + return -EINVAL; + + if ( (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) && + set_cppc->desired != 0 && + (set_cppc->desired < data->hw.lowest || + set_cppc->desired > data->hw.highest) ) + return -EINVAL; + + /* + * minimum & maximum are not validated against lowest or highest as + * hardware doesn't seem to care and the SDM says CPUs will clip + * internally. + */ + if ( set_cppc->minimum > 255 || + set_cppc->maximum > 255 || + set_cppc->energy_perf > 255 ) + return -EINVAL; + + /* Apply presets */ + switch ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_PRESET_MASK ) + { + case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE: + data->minimum = data->hw.lowest; + data->maximum = data->hw.lowest; + data->activity_window = 0; + data->energy_perf = HWP_ENERGY_PERF_MAX_POWERSAVE; + data->desired = 0; + break; + + case XEN_SYSCTL_CPPC_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_CPPC_SET_PRESET_BALANCE: + data->minimum = data->hw.lowest; + data->maximum = data->hw.highest; + data->activity_window = 0; + data->energy_perf = HWP_ENERGY_PERF_BALANCE; + data->desired = 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_NONE: + break; + + default: + return -EINVAL; + } + + /* Further customize presets if needed */ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM ) + data->minimum = set_cppc->minimum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ) + data->maximum = set_cppc->maximum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF ) + data->energy_perf = set_cppc->energy_perf; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) + data->desired = set_cppc->desired; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) + data->activity_window = set_cppc->activity_window & + XEN_SYSCTL_CPPC_ACT_WINDOW_MASK; + + return hwp_cpufreq_target(policy, 0, 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 10143c084c..e4482bcdbc 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -402,6 +402,19 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op) return ret; } +static int set_cpufreq_cppc(const struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_policy, op->cpuid); + + if ( !policy || !policy->governor ) + return -EINVAL; + + if ( !hwp_active() ) + return -EINVAL; + + return set_hwp_para(policy, &op->u.set_cppc); +} + int do_pm_op(struct xen_sysctl_pm_op *op) { int ret = 0; @@ -474,6 +487,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } + case SET_CPUFREQ_CPPC: + ret = set_cpufreq_cppc(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 fb655fac14..d757da2ef4 100644 --- a/xen/include/acpi/cpufreq/cpufreq.h +++ b/xen/include/acpi/cpufreq/cpufreq.h @@ -250,5 +250,7 @@ extern bool __initdata opt_cpufreq_hwp; int hwp_cmdline_parse(const char *s); int get_hwp_para(const unsigned int cpu, struct xen_cppc_para *cppc_para); +int set_hwp_para(struct cpufreq_policy *policy, + const struct xen_set_cppc_para *set_cppc); #endif /* __XEN_CPUFREQ_PM_H__ */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 5c9b60b5d0..96c58eb998 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -351,6 +351,62 @@ struct xen_cppc_para { uint32_t activity_window; }; +/* + * Set CPPC values. + * + * Configured the parameters for CPPC. Set bits in set_params control which + * values are applied. + * + * There are a set of presets along with individual fields. Presets are + * applied first, and then individual fields. This allows customizing + * a preset without having to specify every value. + * + * The preset options values are as follows: + * + * preset | minimum | maxium | energy_perf + * ------------+---------+---------+---------------- + * powersave | lowest | lowest | powersave (255) + * ------------+---------+---------+---------------- + * balance | lowest | highest | balance (128) + * ------------+---------+---------+---------------- + * performance | highest | highest | performance (0) + * + * desired and activity_window are set to 0, hardware selected. + */ +struct xen_set_cppc_para { +#define XEN_SYSCTL_CPPC_SET_DESIRED (1U << 0) +#define XEN_SYSCTL_CPPC_SET_ENERGY_PERF (1U << 1) +#define XEN_SYSCTL_CPPC_SET_ACT_WINDOW (1U << 2) +#define XEN_SYSCTL_CPPC_SET_MINIMUM (1U << 3) +#define XEN_SYSCTL_CPPC_SET_MAXIMUM (1U << 4) +#define XEN_SYSCTL_CPPC_SET_PRESET_MASK 0xf000 +#define XEN_SYSCTL_CPPC_SET_PRESET_NONE 0x0000 +#define XEN_SYSCTL_CPPC_SET_PRESET_BALANCE 0x1000 +#define XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE 0x2000 +#define XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE 0x3000 +#define XEN_SYSCTL_CPPC_SET_PARAM_MASK ( \ + XEN_SYSCTL_CPPC_SET_PRESET_MASK | \ + XEN_SYSCTL_CPPC_SET_DESIRED | \ + XEN_SYSCTL_CPPC_SET_ENERGY_PERF | \ + XEN_SYSCTL_CPPC_SET_ACT_WINDOW | \ + XEN_SYSCTL_CPPC_SET_MINIMUM | \ + XEN_SYSCTL_CPPC_SET_MAXIMUM ) + uint32_t set_params; /* bitflags for valid values */ + /* See comments in struct xen_cppc_para. */ + uint32_t minimum; + uint32_t maximum; + uint32_t desired; + /* + * Hint to hardware for energy/performance preference. + * 0: Performance + * 128: Balance (Default) + * 255: Powersaving + */ + uint32_t energy_perf; +#define XEN_SYSCTL_CPPC_ACT_WINDOW_MASK 0x03ff + uint32_t activity_window; +}; + #define XEN_HWP_DRIVER "hwp" /* * cpufreq para name of this structure named @@ -417,6 +473,7 @@ struct xen_sysctl_pm_op { #define SET_CPUFREQ_GOV (CPUFREQ_PARA | 0x02) #define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03) #define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04) + #define SET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x05) /* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21 @@ -443,6 +500,7 @@ struct xen_sysctl_pm_op { struct xen_get_cpufreq_para get_para; struct xen_set_cpufreq_gov set_gov; struct xen_set_cpufreq_para set_para; + struct xen_set_cppc_para set_cppc; uint64_aligned_t get_avgfreq; uint32_t set_sched_opt_smt; #define XEN_SYSCTL_CX_UNLIMITED 0xffffffff From patchwork Wed Jun 14 18:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280359 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 CDBCDEB64D9 for ; Wed, 14 Jun 2023 18:09:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549175.857588 (Exim 4.92) (envelope-from ) id 1q9Uvu-0004SQ-Ha; Wed, 14 Jun 2023 18:09:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549175.857588; Wed, 14 Jun 2023 18:09: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 1q9Uvu-0004SB-DO; Wed, 14 Jun 2023 18:09:26 +0000 Received: by outflank-mailman (input) for mailman id 549175; Wed, 14 Jun 2023 18:09:25 +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 1q9Uqi-0005LA-Hm for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:04:04 +0000 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [2607:f8b0:4864:20::f2a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d8ae584a-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:04:04 +0200 (CEST) Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-5ed99ebe076so20969846d6.2 for ; Wed, 14 Jun 2023 11:04:04 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:04:01 -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: d8ae584a-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765842; x=1689357842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XCeW0dYT+v8QEPZf3DSgLima7EAFRRshc9U3zxruA5E=; b=ioef9NoqNOhWXzDGhf07TsMCIL+/ArZDW82lXoz5o44kk+HsZ44H7MENnzkDPj/7+g PdclA63C4YtxigRpv5fjwKmEZXwkOtJ4mB0REgQI3lDtKLAUhM2YfOLahLWTPEadTGoP kqVyA43mGoFGz/6gqVESnZiBS7fAS6yFaWLsZmpEQyfmU+dmgs9Rf4qCpgS8Uyv1qb0m Y+Fw7S661t8TCupEDlE9ODvV04zreWC5zul5PfgiRWVZvRpQCF6XXwpC82UD2To+1K5I wA6Bl9dhAw43WhmOBc3nNLP5SQ+8J5wLM7uFAQwdoa2f8LWAnfiwYYzIMk2UxpHx3d7C FQ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765842; x=1689357842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XCeW0dYT+v8QEPZf3DSgLima7EAFRRshc9U3zxruA5E=; b=QOH79vRZZ9kW7m83aL/7nAnaB+Kz5g9lY+Z3T1z4fxP9F5vcPTU45Q+GwTvk5im9Mc W813//hANWz4bEdPdAl9Ltq0CsRV8lqYlVmz7V4wmXfGwYfRUqKPG02iAsrD3VmnlcPt QWKkRc/PgsSi7amNmw9Wl1XoSrEI74n1zad9RuqCgFTHv2RWTScMjCFG4CWDUDtJCB/J QA8jQlTN+YzpJpKhnhqZtg1rjPzqEqZgy0nn9QYRlT1VMqQ4ae6DMPUuMP/4INJdTgqV 3VUTScyCP2sT5SEfEb//RLVhtMN0ptQDPUYlvAzS1xOWNfGTGyNBRMz5IgVXqbiaW03N 6a+g== X-Gm-Message-State: AC+VfDyolF4vCEad//wpcYb4AmVsJUKSXqRKTCYBQMN/iGdwyXyhoIfF XGAbq9nSIgdVzf3dMjq2RRwRp77dVVw= X-Google-Smtp-Source: ACHHUZ5n3c7JJqP1H1zg8yJ4E2XIk4P1BXCK8CNzYiAoIkAiTzgx0S4MhLraMwl1ofebkDHWX4xUEA== X-Received: by 2002:ad4:5de3:0:b0:62f:ea09:7088 with SMTP id jn3-20020ad45de3000000b0062fea097088mr1194311qvb.27.1686765842395; Wed, 14 Jun 2023 11:04:02 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 13/15] libxc: Add xc_set_cpufreq_cppc Date: Wed, 14 Jun 2023 14:02:51 -0400 Message-Id: <20230614180253.89958-14-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Add xc_set_cpufreq_cppc to allow calling xen_systctl_pm_op SET_CPUFREQ_CPPC. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v2: Mark xc_set_hwp_para_t const v4: s/hwp/cppc/ Add Anthony's Ack --- 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 2092632296..c7eb97959a 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1930,11 +1930,15 @@ struct xc_get_cpufreq_para { int32_t turbo_enabled; }; +typedef struct xen_set_cppc_para xc_set_cppc_para_t; + int xc_get_cpufreq_para(xc_interface *xch, int cpuid, struct xc_get_cpufreq_para *user_para); int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname); int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value); +int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, + const xc_set_cppc_para_t *set_cppc); 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 19fe1a79dd..e86045697d 100644 --- a/tools/libs/ctrl/xc_pm.c +++ b/tools/libs/ctrl/xc_pm.c @@ -329,6 +329,24 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, return xc_sysctl(xch, &sysctl); } +int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, + const xc_set_cppc_para_t *set_cppc) +{ + DECLARE_SYSCTL; + + if ( !xch ) + { + errno = EINVAL; + return -1; + } + sysctl.cmd = XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd = SET_CPUFREQ_CPPC; + sysctl.u.pm_op.cpuid = cpuid; + sysctl.u.pm_op.u.set_cppc = *set_cppc; + + return xc_sysctl(xch, &sysctl); +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret = 0; From patchwork Wed Jun 14 18:02:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280288 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 04C20EB64D8 for ; Wed, 14 Jun 2023 18:04:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549134.857577 (Exim 4.92) (envelope-from ) id 1q9Uqn-0001OJ-LC; Wed, 14 Jun 2023 18:04:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549134.857577; Wed, 14 Jun 2023 18:04:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uqn-0001Na-FS; Wed, 14 Jun 2023 18:04:09 +0000 Received: by outflank-mailman (input) for mailman id 549134; Wed, 14 Jun 2023 18:04:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uqm-0005L9-E0 for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:04:08 +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 da0f1f78-0add-11ee-8611-37d641c3527e; Wed, 14 Jun 2023 20:04:06 +0200 (CEST) Received: by mail-qk1-x732.google.com with SMTP id af79cd13be357-75d44cb20a2so228113685a.3 for ; Wed, 14 Jun 2023 11:04:06 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:04:04 -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: da0f1f78-0add-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765845; x=1689357845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2TAha9GGtbIdxJkaO8y2Wuv/uF0GuXKaVPOMOdxqX78=; b=DhcVB+qzfZOk0Tf3YAquvn9Qk0KzgkFeL7oyELAWV6v+8KLFDlIEqNEMaTZnFggGPh Y3TAvf7cXIO940NA3F5WnKWZtKlDwPxz4jNbU3NlKW7ufGX2THKvYjPi3/H5urUNmvHB tbXej7KCWfCL25EjBaIK/LKXXCNIEKbIW9SxuiNQUQvQR4VL/21/fjlavKmsDXOrzF80 06+jm1aypyUb2+1Qk8zLncZsf74p9W6b1WOMlM9jUAird2lETwOunjmhV8jQIJkBpdvT DVENOQ+zniWrtS/huRheitJNTzzyapyrhK9cB2bXSs8fPAUkjh795lk7Occ7nt3lfkTx TMDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765845; x=1689357845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2TAha9GGtbIdxJkaO8y2Wuv/uF0GuXKaVPOMOdxqX78=; b=VifRWYZdT/oNytRLSGUbNTe4zag0VLZFDV+6S0USAvpszKR/bGJ50cg2U1RP1Gisyt DagnLt47xjIFFGYvpQfKKV5kqv0cA90qbruMhWyRzrPyLpXM5KWA+6FyH8oINmEQxrTf hgAlEZYLX2H00ixgsHxPcmD1iTzpm+6buoVHV9kASKBurtWZYNPaPTPtCSDQVaHGh/dR cR1zAYh0J2geiLVV53MN/i3vd1Niru66sxBwS/BsruGSglf7e0I41pOKAecZ7/Ao9Jcq URSjW+EC8x5Wc3oQZJbdPLFTxIpSUpRs5xrUiPyjCtqAcboHA8XXVbL3f8MedqIGxUNn Hb3A== X-Gm-Message-State: AC+VfDxA2FX3jH0R5al2p/jRWO17a/+ykdGP177XQ9CA+gyvggPk8sY/ rEhU7hqCM+CZ5vkglN6W3ge3yhy17cs= X-Google-Smtp-Source: ACHHUZ7sTpaZjatEnLKDG0GeXM4DB6r32bbGsSisKNq+DZoxG62Lk0Nkap5olQC11CqZU7HfU7DArA== X-Received: by 2002:a05:6214:e6b:b0:626:38cc:6497 with SMTP id jz11-20020a0562140e6b00b0062638cc6497mr18507482qvb.5.1686765844607; Wed, 14 Jun 2023 11:04:04 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Wei Liu , Anthony PERARD Subject: [PATCH v4 14/15] xenpm: Add set-cpufreq-cppc subcommand Date: Wed, 14 Jun 2023 14:02:52 -0400 Message-Id: <20230614180253.89958-15-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 set-cpufreq-cppc allows setting the Hardware P-State (HWP) parameters. It can be run on all or just a single cpu. There are presets of balance, powersave & performance. Those can be further tweaked by param:val arguments as explained in the usage description. Parameter names are just checked to the first 3 characters to shorten typing. Some options are hardware dependent, and ranges can be found in get-cpufreq-para. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v4: Remove energy bias 0-15 & 7 references Use MASK_INSR Fixup { placement Drop extra case in parse_activity_window strcmp suffix Expand help text s/hwp/cppc/ Use isdigit() to check cpuid - otherwise run on all CPUs. v2: Compare provided parameter name and not just 3 characters. Use "-" in parameter names Remove hw_ Replace sscanf with strchr & strtoul. Remove toplevel error message with lower level ones. Help text s/127/128/ Help text mention truncation. Avoid some truncation rounding down by adding 5 before division. Help test mention default microseconds Also comment the limit check written to avoid overflow. --- tools/misc/xenpm.c | 237 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 488797fd20..2f2b699794 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -16,6 +16,8 @@ */ #define MAX_NR_CPU 512 +#include +#include #include #include #include @@ -67,6 +69,30 @@ 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-cppc [cpuid] [balance|performance|powersave] *\n" + " set Hardware P-State (HWP) parameters\n" + " on CPU or all if omitted.\n" + " optionally a preset of one of:\n" + " balance|performance|powersave\n" + " an optional list of param:val arguments\n" + " minimum:N (0-255)\n" + " maximum:N (0-255)\n" + " get-cpufreq-para lowest/highest\n" + " values are limits for\n" + " minumum/maximum.\n" + " desired:N (0-255)\n" + " set explicit performance target.\n" + " non-zero disables auto-HWP mode.\n" + " energy-perf:N (0-255)\n" + " energy/performance hint\n" + " lower - favor performance\n" + " higher - favor powersave\n" + " 128 - balance\n" + " act-window:N{,m,u}s range 1us-1270s\n" + " window for internal calculations.\n" + " units default to \"us\" if unspecified.\n" + " truncates un-representable values.\n" + " 0 lets the hardware decide.\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" @@ -1292,6 +1318,216 @@ 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_cppc_para_t *set_cppc, unsigned long u, + const char *suffix) +{ + unsigned int exponent = 0; + unsigned int multiplier = 1; + + if ( suffix && suffix[0] ) + { + if ( strcmp(suffix, "s") == 0 ) + { + multiplier = 1000 * 1000; + exponent = 6; + } + else if ( strcmp(suffix, "ms") == 0 ) + { + multiplier = 1000; + exponent = 3; + } + else if ( strcmp(suffix, "us") != 0 ) + { + 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_cppc->activity_window = + MASK_INSR(exponent, XEN_CPPC_ACT_WINDOW_EXPONENT_MASK) | + MASK_INSR(u, XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + set_cppc->set_params |= XEN_SYSCTL_CPPC_SET_ACT_WINDOW; + + return 0; +} + +static int parse_cppc_opts(xc_set_cppc_para_t *set_cppc, int *cpuid, + int argc, char *argv[]) +{ + int i = 0; + + if ( argc < 1 ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( isdigit(argv[i][0]) ) + { + if ( sscanf(argv[i], "%d", cpuid) != 1 || *cpuid < 0 ) + { + fprintf(stderr, "Could not parse cpuid \"%s\"\n", argv[i]); + return -1; + } + + i++; + } + + if ( i == argc ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( strcasecmp(argv[i], "powersave") == 0 ) + { + set_cppc->set_params = XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") == 0 ) + { + set_cppc->set_params = XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") == 0 ) + { + set_cppc->set_params = XEN_SYSCTL_CPPC_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 cppc 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_cppc, 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_cppc->minimum = val; + set_cppc->set_params |= XEN_SYSCTL_CPPC_SET_MINIMUM; + } + else if ( strncasecmp(param, "maximum", MAX(2, strlen(param))) == 0 ) + { + set_cppc->maximum = val; + set_cppc->set_params |= XEN_SYSCTL_CPPC_SET_MAXIMUM; + } + else if ( strncasecmp(param, "desired", strlen(param)) == 0 ) + { + set_cppc->desired = val; + set_cppc->set_params |= XEN_SYSCTL_CPPC_SET_DESIRED; + } + else if ( strncasecmp(param, "energy-perf", strlen(param)) == 0 ) + { + set_cppc->energy_perf = val; + set_cppc->set_params |= XEN_SYSCTL_CPPC_SET_ENERGY_PERF; + } + else + { + fprintf(stderr, "\"%s\" is an invalid parameter\n", param); + return -1; + } + } + + if ( set_cppc->set_params == 0 ) + { + fprintf(stderr, "No parameters set in request\n"); + return -1; + } + + return 0; +} + +static void cppc_set_func(int argc, char *argv[]) +{ + xc_set_cppc_para_t set_cppc = {}; + int cpuid = -1; + int i = 0; + + if ( parse_cppc_opts(&set_cppc, &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_cppc(xc_handle, i, &set_cppc) ) + fprintf(stderr, "[CPU%d] failed to set cppc params (%d - %s)\n", + i, errno, strerror(errno)); +} + struct { const char *name; void (*function)(int argc, char *argv[]); @@ -1302,6 +1538,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "set-cpufreq-cppc", cppc_set_func }, { "set-scaling-maxfreq", scaling_max_freq_func }, { "set-scaling-minfreq", scaling_min_freq_func }, { "set-scaling-governor", scaling_governor_func }, From patchwork Wed Jun 14 18:02:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 13280361 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 5A9A9EB64D9 for ; Wed, 14 Jun 2023 18:09:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.549192.857608 (Exim 4.92) (envelope-from ) id 1q9Uw3-00053r-W3; Wed, 14 Jun 2023 18:09:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 549192.857608; Wed, 14 Jun 2023 18:09:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q9Uw3-00053k-S8; Wed, 14 Jun 2023 18:09:35 +0000 Received: by outflank-mailman (input) for mailman id 549192; Wed, 14 Jun 2023 18:09:35 +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 1q9Uqn-0005LA-IT for xen-devel@lists.xenproject.org; Wed, 14 Jun 2023 18:04:09 +0000 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [2607:f8b0:4864:20::f35]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id db60b4f6-0add-11ee-b232-6b7b168915f2; Wed, 14 Jun 2023 20:04:08 +0200 (CEST) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-62fe188255eso5285766d6.0 for ; Wed, 14 Jun 2023 11:04:08 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id s5-20020a05621412c500b006262de12a8csm4851613qvv.65.2023.06.14.11.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 11:04:06 -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: db60b4f6-0add-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686765847; x=1689357847; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AXCdosE1xzkZrcu7sJ9kEjSlEgbAAlcqZ3LQutJHGBw=; b=JK5vcixb8Wt41QBAZT/fOy/v5bOsxStCpDCeZkSiQ8PB6fNvhaRF7NiKjBtYrfUOoR YCNpam/Zb0PPQ8iRsGPUpawZ2URLSYcBIjxA3MPP3DNCGsxwvFJuaGCyrNECYN7BU32j hmTtrMmB6y6tswrR737I0CPEaL5T85eglImsljaxHHW2KjcFVLC2Z6GXcvC3wXIcNkn3 JBHtcr9W0TlWXh2nbgrLD1gegF0/BVptSf/eSPWcSEt4c1iqHrBSjFpEXPolSNbanyU1 RTHUKgOJS8N0iFj2LKzAxMKwmwoM9XrhSioFRtl+60uYO8zNMZ764S0hhzWHZfdkbdJd XW0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686765847; x=1689357847; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AXCdosE1xzkZrcu7sJ9kEjSlEgbAAlcqZ3LQutJHGBw=; b=MS+VH31r5vnoifUKzF3RpdWbOSzL6MN1fV53PhCXg9msFTQOOqEg44uiVNQ2ZZwT0K f1yLLa4BtzSSliZQ7YafE05jqlUpbJWrAZ2zhR6nIsrSTsygzEsaitQsMS3yBdlIRIci 0zZRxYdvTJ8RuvpKsn9JcSRmKV6YYeGnyg3EO+BuInhz4A+tDVVFdcP3SfgN2G9Ccb6q 1j4YuVgoz3S7MtBe9Abn+5C5zhcFvyyS4HDQQaFVcUwwXl3exzplV0AbTP84AK4pfe9N yGnqEMgZuxBHs0ovQoKEkz1gEOZe69Ae6PeVl2+d7wwGWHiVsXl6EyAb3OGTVJDNRiQg 4n1A== X-Gm-Message-State: AC+VfDxGJLGk2psHqR0AIiH9FJVLA3iPWVqL/+z8d2253wV5yReOliC6 gsD5Km5Cj5g3S/valWToORNWIFfSkXE= X-Google-Smtp-Source: ACHHUZ46Tf7BnAy/jyT3co960LbUrB7XqzZxSw0x0mXK2jOrH69DJNsDWu7WWv6LxF6h+BEQn0xopw== X-Received: by 2002:a05:6214:27ee:b0:62d:ed66:7ad1 with SMTP id jt14-20020a05621427ee00b0062ded667ad1mr2251672qvb.28.1686765846844; Wed, 14 Jun 2023 11:04:06 -0700 (PDT) From: Jason Andryuk To: xen-devel@lists.xenproject.org Cc: Jason Andryuk , Henry Wang , Community Manager Subject: [PATCH v4 15/15] CHANGELOG: Add Intel HWP entry Date: Wed, 14 Jun 2023 14:02:53 -0400 Message-Id: <20230614180253.89958-16-jandryuk@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614180253.89958-1-jandryuk@gmail.com> References: <20230614180253.89958-1-jandryuk@gmail.com> MIME-Version: 1.0 Signed-off-by: Jason Andryuk Acked-by: Henry Wang --- v3: Position under existing Added section Add Henry's Ack v2: Add blank line --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7e0590f8..8d6e6c3088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - xl/libxl can customize SMBIOS strings for HVM guests. - Add support for AVX512-FP16 on x86. - On Arm, Xen supports guests running SVE/SVE2 instructions. (Tech Preview) - + - Add Intel Hardware P-States (HWP) cpufreq driver. ## [4.17.0](https://xenbits.xen.org/gitweb/?p=xen.git;a=shortlog;h=RELEASE-4.17.0) - 2022-12-12