From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765850; cv=none; d=zohomail.com; s=zohoarc; b=WT6dNbPe148EttqU27rtUdstuy4dekDYc5Nolu9bPoEjXrqyYwJtTRpVbbL0iC+40IIV1x6HT4jucCk3/uWLzmJwmvJlHeAlLJJl64MlnwNn7C7OP8TYyT7BDfvw/7WZK70Pre2hlxyU69+DlKzZokZDZBtSSUthSwVLXvlstII= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765850; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lU8DGWwiCowI3/H8qxEHgym+pR/PD7+d49EnwTk48c0=; b=jkMZ1/hOJlbkMGKG1CFBt0O8gR3u6P2kFUmnBpSbAThKwpoqaXqRJYFlFnpu2cMpp4hGmAUnXdtDgCHzQXOHZaKESe26FG78yAZR8JiNXu98eKDb3hOSzTXlDA3BYmQvdaCgiLVlAK0Ttc/sZCt1oqw9dfSFDbVrqCWRI96jzk0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765850553408.1709813684529; Wed, 14 Jun 2023 11:04:10 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765852211100003 Content-Type: text/plain; charset="utf-8" For hwp, the standard governors are not usable, and only the internal one is applicable. Add the cpufreq_governor_internal boolean to indicate when an internal governor, like hwp, will be used. This is set during presmp_initcall, 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); =20 +bool __initdata cpufreq_governor_internal; struct cpufreq_governor *__read_mostly cpufreq_opt_governor; LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); =20 @@ -121,6 +122,12 @@ int __init cpufreq_register_governor(struct cpufreq_go= vernor *governor) if (!governor) return -EINVAL; =20 + if (cpufreq_governor_internal && !governor->internal) + return -EINVAL; + + if (!cpufreq_governor_internal && governor->internal) + return -EINVAL; + if (__find_governor(governor->name) !=3D NULL) return -EEXIST; =20 diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 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; }; =20 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; =20 +extern bool cpufreq_governor_internal; + extern struct list_head cpufreq_governor_list; =20 extern int cpufreq_register_governor(struct cpufreq_governor *governor); --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765857; cv=none; d=zohomail.com; s=zohoarc; b=eP3i4AVOeGTdohA4GVON/nk6CrjH1tE6fucBRBaDNEW4CGMaRR65UFAFeiH0UUq0OyTQ1sXZ0tnlkCxr1CqtkWsowO6eDHq/u5hvDplhE3VSIEQB9ZT8hapZTHRJtN/jAUR2cSi+pFnLMAVANlt4DSQnRNqEHxJuy1xWMEV30qA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765857; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o5tkXnrNUw3eHjvmXo8drCoxp1uJZERpOt4e3aBqvlI=; b=hONsudIH4eZCRr5VKpuN4ERp1whEqBkXlVu1LY7GXke9XwZd0x1u0AyTuxdt22T8LrdC698WmIW/qdVUwd14FjTwzgaL7GTarHnyYTWPs81umdtXLi+0W4n+oS/Ll5MAmdwAnKgyjNevNnKt2AHRJGkZAABietjegh1A6G9uvAg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168676585736339.99361966706772; Wed, 14 Jun 2023 11:04:17 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765858716100001 Content-Type: text/plain; charset="utf-8" acpi-cpufreq scales the aperf/mperf measurements by max_freq, but HWP needs to scale by base frequency. Settings max_freq to base_freq "works" but the code is not obvious, and returning values to userspace is tricky. Add an additonal perf_freq member which is used for scaling aperf/mperf measurements. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v3: Add Jan's Ack I don't like this, but it seems the best way to re-use the common aperf/mperf code. The other option would be to add wrappers that then do the acpi vs. hwp scaling. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- xen/drivers/cpufreq/utility.c | 1 + xen/include/acpi/cpufreq/cpufreq.h | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 2e0067fbe5..6c70d04395 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -316,7 +316,7 @@ unsigned int get_measured_perf(unsigned int cpu, unsign= ed int flag) else perf_percent =3D 0; =20 - return policy->cpuinfo.max_freq * perf_percent / 100; + return policy->cpuinfo.perf_freq * perf_percent / 100; } =20 static unsigned int cf_check get_cur_freq_on_cpu(unsigned int cpu) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index 9eb7ecedcd..6831f62851 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -236,6 +236,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_poli= cy *policy, =20 policy->min =3D policy->cpuinfo.min_freq =3D min_freq; policy->max =3D policy->cpuinfo.max_freq =3D max_freq; + policy->cpuinfo.perf_freq =3D max_freq; policy->cpuinfo.second_max_freq =3D second_max_freq; =20 if (policy->min =3D=3D ~0) diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 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 =3D nanosecond= s */ }; --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765849; cv=none; d=zohomail.com; s=zohoarc; b=eLGr6h2Sgse52eM+r+dNHK6Mp4bJv5mu1kx2gB10WAfMoGpmXQZVzIzcKtK9JEcyN2lPGWuoeTvWfLNUOYH6rP7L+H4cBBap20yu29958ovIwHFxmw6G5SOrwbf+osDYOB/7g+3ZFIzCXJWfB/2TbgDE/xKrabHjBKT4o1K6JgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765849; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VlkDpnzBOrYGbDVTZSSMEmRPTHTcziXTR1AlOBlC9P0=; b=HgguFGB0qZzN43Rd0ao2VRyHYYUTQycsVJ4z1BgnvmFMV1CrSVbCiTVy3KNDBXsBM2x28jdU7TYVmxcz/AiLOnJ5zwF9vZZ+0DB+XavRqblP1YrVtJUjLakSKYDmRT2Q2uPtRhmYPxp+swRXtR+59knZzXqOqUvW5Z5d0cdXowg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765849627416.6558758787762; Wed, 14 Jun 2023 11:04:09 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765850788100001 Content-Type: text/plain; charset="utf-8" Export feature_detect as intel_feature_detect so it can be re-used by HWP. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- v4: Add Jan's Ack v3: Remove void * cast when calling intel_feature_detect v2: export intel_feature_detect with typed pointer Move intel_feature_detect to acpi/cpufreq/cpufreq.h since the declaration now contains struct cpufreq_policy *. --- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 ++++++-- xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index 6c70d04395..f1cc473b4f 100644 --- a/xen/arch/x86/acpi/cpufreq/cpufreq.c +++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c @@ -339,9 +339,8 @@ static unsigned int cf_check get_cur_freq_on_cpu(unsign= ed int cpu) return extract_freq(get_cur_val(cpumask_of(cpu)), data); } =20 -static void cf_check feature_detect(void *info) +void intel_feature_detect(struct cpufreq_policy *policy) { - struct cpufreq_policy *policy =3D info; unsigned int eax; =20 eax =3D cpuid_eax(6); @@ -353,6 +352,11 @@ static void cf_check feature_detect(void *info) } } =20 +static void cf_check feature_detect(void *info) +{ + intel_feature_detect(info); +} + static unsigned int check_freqs(const cpumask_t *mask, unsigned int freq, struct acpi_cpufreq_data *data) { diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 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); =20 +void intel_feature_detect(struct cpufreq_policy *policy); + #endif /* __XEN_CPUFREQ_PM_H__ */ --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765863; cv=none; d=zohomail.com; s=zohoarc; b=cn7IQadsc0z76WwCvhCimjy3jY007Pksalq7BkOnzxWs2qlEtb5c7eiz14GOqM537bJCg3huRgThzEYH2e+1n7z2wNhSpEGCpzbIH0jRSHUZF+/OBOCqk11Ej9Wqw3n1U3v+Hvj5xP35kiEslQubE2n6jhwBfYO36DtAYZv2wIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765863; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mnealSDcQ5eD4/BMHbAdAnbMLaUANznTtXLujb813pg=; b=Xk8mVSm3lQbejEWWPULwE92BZ9jWi+6p1gcI0AVDlAzWNj6agtAPDC29piEBWPHP5URvpnrNupQe7j4s6RNYB/UKYF+o+SNUPNdwXsgs7pBQ/d58m7DO7zSbJYa9mVCQIUATcvkb5btBtnmxJl89NYo6aJFc0jl6JnYHEmEvOE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765863620508.43366912958174; Wed, 14 Jun 2023 11:04:23 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765864706100001 Content-Type: text/plain; charset="utf-8" Add a union and struct so that most of the scaling variables of struct xen_get_cpufreq_para are within in a binary-compatible layout. This allows cppc_para to live in the larger union and use uint32_ts - struct xen_cppc_para will be 10 uint32_t's. The new scaling struct is 3 * uint32_t + 16 bytes CPUFREQ_NAME_LEN + 4 * uint32_t for xen_ondemand =3D 11 uint32_t. That means the old size is retained, int32_t turbo_enabled doesn't move and it's binary compatible. 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; =20 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 =3D sys_para->cpuinfo_cur_freq; user_para->cpuinfo_max_freq =3D sys_para->cpuinfo_max_freq; user_para->cpuinfo_min_freq =3D sys_para->cpuinfo_min_freq; - user_para->scaling_cur_freq =3D sys_para->scaling_cur_freq; - user_para->scaling_max_freq =3D sys_para->scaling_max_freq; - user_para->scaling_min_freq =3D sys_para->scaling_min_freq; user_para->turbo_enabled =3D sys_para->turbo_enabled; =20 memcpy(user_para->scaling_driver, sys_para->scaling_driver, CPUFREQ_NAME_LEN); - memcpy(user_para->scaling_governor, - sys_para->scaling_governor, CPUFREQ_NAME_LEN); =20 /* copy to user_para no matter what cpufreq governor */ BUILD_BUG_ON(sizeof(((struct xc_get_cpufreq_para *)0)->u) !=3D diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index 1bb6187e56..ee8ce5d5f2 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -730,39 +730,39 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) printf("scaling_avail_gov : %s\n", p_cpufreq->scaling_available_governors); =20 - printf("current_governor : %s\n", p_cpufreq->scaling_governor); - if ( !strncmp(p_cpufreq->scaling_governor, + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { printf(" userspace specific :\n"); printf(" scaling_setspeed : %u\n", - p_cpufreq->u.userspace.scaling_setspeed); + p_cpufreq->u.s.u.userspace.scaling_setspeed); } - else if ( !strncmp(p_cpufreq->scaling_governor, + else if ( !strncmp(p_cpufreq->u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { printf(" ondemand specific :\n"); printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.ondemand.sampling_rate_max, - p_cpufreq->u.ondemand.sampling_rate_min, - p_cpufreq->u.ondemand.sampling_rate); + p_cpufreq->u.s.u.ondemand.sampling_rate_max, + p_cpufreq->u.s.u.ondemand.sampling_rate_min, + p_cpufreq->u.s.u.ondemand.sampling_rate); printf(" up_threshold : %u\n", - p_cpufreq->u.ondemand.up_threshold); + p_cpufreq->u.s.u.ondemand.up_threshold); } =20 printf("scaling_avail_freq :"); for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D - p_cpufreq->scaling_cur_freq ) + p_cpufreq->u.s.scaling_cur_freq ) printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); else printf(" %d", p_cpufreq->scaling_available_frequencies[i]); printf("\n"); =20 printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->scaling_max_freq, - p_cpufreq->scaling_min_freq, - p_cpufreq->scaling_cur_freq); + p_cpufreq->u.s.scaling_max_freq, + p_cpufreq->u.s.scaling_min_freq, + p_cpufreq->u.s.scaling_cur_freq); =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index 1bae635101..f5a9ac3f1a 100644 --- a/xen/drivers/acpi/pmstat.c +++ b/xen/drivers/acpi/pmstat.c @@ -258,37 +258,38 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *= op) cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; - op->u.get_para.scaling_cur_freq =3D policy->cur; - op->u.get_para.scaling_max_freq =3D policy->max; - op->u.get_para.scaling_min_freq =3D policy->min; + + op->u.get_para.u.s.scaling_cur_freq =3D policy->cur; + op->u.get_para.u.s.scaling_max_freq =3D policy->max; + op->u.get_para.u.s.scaling_min_freq =3D policy->min; =20 if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver,=20 + strlcpy(op->u.get_para.scaling_driver, cpufreq_driver.name, CPUFREQ_NAME_LEN); else strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); =20 if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.scaling_governor,=20 + strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.scaling_governor, "Unknown", CPUFREQ_NAME_L= EN); + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NA= ME_LEN); =20 /* governor specific para */ - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "userspace", CPUFREQ_NAME_LEN) ) { - op->u.get_para.u.userspace.scaling_setspeed =3D policy->cur; + op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cur; } =20 - if ( !strncasecmp(op->u.get_para.scaling_governor, + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, "ondemand", CPUFREQ_NAME_LEN) ) { ret =3D get_cpufreq_ondemand_para( - &op->u.get_para.u.ondemand.sampling_rate_max, - &op->u.get_para.u.ondemand.sampling_rate_min, - &op->u.get_para.u.ondemand.sampling_rate, - &op->u.get_para.u.ondemand.up_threshold); + &op->u.get_para.u.s.u.ondemand.sampling_rate_max, + &op->u.get_para.u.s.u.ondemand.sampling_rate_min, + &op->u.get_para.u.s.u.ondemand.sampling_rate, + &op->u.get_para.u.s.u.ondemand.up_threshold); } op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); =20 diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 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; =20 int32_t turbo_enabled; --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765856; cv=none; d=zohomail.com; s=zohoarc; b=BlMrqoyp+tWiYKvuKY5S2ks81MSa0Td+haZbbdFQsE+xD+0+stDXNTWcatRnAhaF3J+f8CFHs7YZpWnvtABVfizXNnrUWcL1fCdZ12SVpu947ci421KVKYhtofUJTSYHSVYEiFVQcSv5XQbB/7kzZsIrx+84HFUQTeas6QTPnn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765856; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=10pxhvdrn80PyMa9ObI4vzbfbnF6JqsnYlE3+fZTgH4=; b=gLul/rL6FgoOSCPOC/tMz0V7RjokAdWE5CUOzJ33NBO8RRF8tptUDeqTWW1WjB28ZAsfOk8R0zhulr6wx2xNXii7YNvWbkc2smXJJH1fHiUMjTXDVdGIFLMqY9WGE64bXUmJoO4PFOaqA985B6F3u0aIFICvYbh4YoR7guxOhEA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765856782275.5158621462872; Wed, 14 Jun 2023 11:04:16 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765858759100002 Content-Type: text/plain; charset="utf-8" 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_governor= s) ) { errno =3D EINVAL; return -1; @@ -230,12 +230,15 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, goto unlock_1; if ( xc_hypercall_bounce_pre(xch, scaling_available_frequencies) ) goto unlock_2; - if ( xc_hypercall_bounce_pre(xch, scaling_available_governors) ) + if ( user_para->gov_num && + xc_hypercall_bounce_pre(xch, scaling_available_governors) ) goto unlock_3; =20 set_xen_guest_handle(sys_para->affected_cpus, affected_cpus); set_xen_guest_handle(sys_para->scaling_available_frequencies, scal= ing_available_frequencies); - set_xen_guest_handle(sys_para->scaling_available_governors, scalin= g_available_governors); + if ( user_para->gov_num ) + set_xen_guest_handle(sys_para->scaling_available_governors, + scaling_available_governors); } =20 sysctl.cmd =3D XEN_SYSCTL_pm_op; @@ -278,7 +281,8 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, } =20 unlock_4: - xc_hypercall_bounce_post(xch, scaling_available_governors); + if ( user_para->gov_num ) + xc_hypercall_bounce_post(xch, scaling_available_governors); unlock_3: xc_hypercall_bounce_post(xch, scaling_available_frequencies); unlock_2: diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index ee8ce5d5f2..1c474c3b59 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -811,7 +811,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_= handle, int cpuid) ret =3D -ENOMEM; goto out; } - if (!(p_cpufreq->scaling_available_governors =3D + if (p_cpufreq->gov_num && + !(p_cpufreq->scaling_available_governors =3D malloc(p_cpufreq->gov_num * CPUFREQ_NAME_LEN * sizeof(char))= )) { fprintf(stderr, diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c index f5a9ac3f1a..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; =20 + op->u.get_para.cpuinfo_cur_freq =3D + cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; + op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; + op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; + op->u.get_para.turbo_enabled =3D cpufreq_get_turbo_status(op->cpuid); + + if ( cpufreq_driver.name[0] ) + strlcpy(op->u.get_para.scaling_driver, + cpufreq_driver.name, CPUFREQ_NAME_LEN); + else + strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); + if ( !(scaling_available_governors =3D xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) return -ENOMEM; - if ( (ret =3D read_scaling_available_governors(scaling_available_gover= nors, - gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + if ( (ret =3D 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; =20 - op->u.get_para.cpuinfo_cur_freq =3D - cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur; - op->u.get_para.cpuinfo_max_freq =3D policy->cpuinfo.max_freq; - op->u.get_para.cpuinfo_min_freq =3D policy->cpuinfo.min_freq; - op->u.get_para.u.s.scaling_cur_freq =3D policy->cur; op->u.get_para.u.s.scaling_max_freq =3D policy->max; op->u.get_para.u.s.scaling_min_freq =3D policy->min; =20 - if ( cpufreq_driver.name[0] ) - strlcpy(op->u.get_para.scaling_driver, - cpufreq_driver.name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN= ); - if ( policy->governor->name[0] ) strlcpy(op->u.get_para.u.s.scaling_governor, policy->governor->name, CPUFREQ_NAME_LEN); else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", CPUFREQ_NA= ME_LEN); + strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", + CPUFREQ_NAME_LEN); =20 /* governor specific para */ if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, @@ -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 =3D cpufreq_get_turbo_status(op->cpuid); =20 return ret; } --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765873; cv=none; d=zohomail.com; s=zohoarc; b=FZInTFWbcd023gvz7TvTsMAQN3luhcbAaR3vVYMP1h2v726JbNp/mFTeow35Nqy8ClpLaprXc3ErfzwGLZ0hCHIYLlMVVcCmv4WcgsZDZRxcorL1sbeVh4dZuZ+8O4TGQSB6UY5Sxx8oYaWDONqvz2WLwJsYeX9GG19GRHmyzO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765873; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3erQ3Tf88rrl0YLlehZaA13XnubAYvrTZWS6hEHGpfQ=; b=h/aWXE/4YNr1YBGLunCXwUhBVVgnWwA1DAO7/GOXDA1OLk2CdDrUVQfGRzijbCHOfmmGgOB2r2Tw+2zqCw9q0lQIB568sxcVqg3SxM8osELbAbMSESyzwH65H87ex+51LEfVlMT2MaPyQ2MeyHTWj8SB1u/z3VVizogzykH1yJ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765873381773.2747919109165; Wed, 14 Jun 2023 11:04:33 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765874424100001 Content-Type: text/plain; charset="utf-8" From the Intel SDM: "Hardware-Controlled Performance States (HWP), which autonomously selects performance states while utilizing OS supplied performance guidance hints." Enable HWP to run in autonomous mode by poking the correct MSRs. cpufreq=3Dhwp enables and specifying cpufreq=3Dxen would disable it. hdc is a sub-option under hwp (i.e. cpufreq=3Dxen:hwp,hdc=3D0) as is verbose. If cpufreq=3Dhwp is specified, but hardware support is unavailable, Xen fallbacks back to cpufreq=3Dxen. There is no interface to configure - xen_sysctl_pm_op/xenpm will be extended to configure in subsequent patches. It will run with the default values, which should be the default 0x80 (out of 0x0-0xff) energy/performance preference. Unscientific powertop measurement of an mostly idle, customized OpenXT install: A 10th gen 6-core laptop showed battery discharge drop from ~9.x to ~7.x watts. A 8th gen 4-core laptop dropped from ~10 to ~9 Power usage depends on many factors, especially display brightness, but this does show a power saving in balanced mode when CPU utilization is low. HWP isn't compatible with an external governor - it doesn't take explicit frequency requests. Therefore a minimal internal governor, hwp, is also added as a placeholder. While adding to the xen-command-line.pandoc entry, un-nest verbose from minfreq. They are independent. With cpufreq=3Dhwp,verbose, HWP prints processor capabilities that are not used by the code, like HW_FEEDBACK. This is done because otherwise there isn't a convenient way to query the information. 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=3Dxen:hwp - would require resetting the governor if HWP hardware wasn't available. Making cpufreq=3Dhwp a top level option avoids that issue. Falling back from cpufreq=3Dhwp to cpufreq=3Dxen is a more user-friendly choice than disabling cpufreq when HWP is not available. Specifying cpufreq=3Dhwp 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=3Dhwp or cpufreq=3Dnone, but not cpufreq=3Dxen. We can't use parse_boolean() since it requires a single name=3Dval string and cpufreq_handle_common_option is provided two strings. Use parse_bool() and manual handle no-hwp. 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 =3D -1 Fold hwp_read_capabilities into hwp_init_msrs Add command line cpufreq=3Dxen:hwp Add command line cpufreq=3Dxen:hdc Use per_cpu for hwp_drv_data pointers Move hwp_energy_perf_bias call into hwp_write_request energy_perf 0 is valid, so hwp_energy_perf_bias cannot be skipped Ensure we don't generate interrupts Remove Fast Write of Uncore MSR Initialize hwp_drv_data from curr_req Use SPDX line instead of license text in hwp.c v3: Add cf_check to cpufreq_gov_hwp_init() - Marek Print cpuid_level with %#x - Marek v4: Use BIT() for CPUID and MSR bits Move __initdata after type Add __ro_after_init to feature_* Remove aperf/mperf comment Move feature_hwp_energy_perf { to newline Remove _IA32_ infix Use unsigned int & bool for bitfields Require energy perf pref (Remove ENERGY_PERF_BIAS support) Initialize activity_window Return errors on wrmsr failure Change command line to: cpufreq=3Dxen:hwp Move hdc into the hwp-specific handle_options Drop feature_hwp_energy_perf, feature_hwp_pkg_level_ctl & feature_hwp_peci Print features before exiting when energy/performance preference isn't avai= lable Disable HWP MSR on initialization error Change hwp_ print macros to add prefixes Disable HDC when hdc=3D0 - (opt_hdc no longer initdata) Mark hwp governor internal and use "hwp" name Add XEN_HWP_DRIVER Use top-level cpufreq=3Dhwp command line option Document that cpufreq=3Dhwp falls back to cpufreq=3Dxen without hardware Add SPDX suffix GPL-2.0-only --- 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 oprof= ile, rather than detectin available support. =20 ### cpufreq -> `=3D none | {{ | xen } [:[powersave|performance|ondemand|users= pace][,][,[][,[verbose]]]]} | dom0-kernel` +> `=3D none | {{ | xen } { [:[powersave|performance|ondemand|use= rspace][,[]][,[]]] } [,verbose]} | dom0-kernel | hwp[:[][,verbose]]` =20 > Default: `xen` =20 @@ -510,6 +510,13 @@ choice of `dom0-kernel` is deprecated and not supporte= d by all Dom0 kernels. * `` and `` are integers which represent max and min pro= cessor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=3D` +* `hwp` selects Hardware-Controlled Performance States (HWP) on supported = Intel + hardware. HWP is a Skylake+ feature which provides better CPU power + management. The default is disabled. If `hwp` is selected, but hardware + support is not available, Xen will fallback to cpufreq=3Dxen. +* `` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables= the + processor to autonomously force physical package components into idle st= ate. + The default is enabled, but the option only applies when `hwp` is enable= d. =20 ### cpuid (x86) > `=3D List of comma separated booleans` diff --git a/xen/arch/x86/acpi/cpufreq/Makefile b/xen/arch/x86/acpi/cpufreq= /Makefile index f75da9b9ca..db83aa6b14 100644 --- a/xen/arch/x86/acpi/cpufreq/Makefile +++ b/xen/arch/x86/acpi/cpufreq/Makefile @@ -1,2 +1,3 @@ obj-y +=3D cpufreq.o +obj-y +=3D hwp.o obj-y +=3D powernow.o diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufre= q/cpufreq.c index f1cc473b4f..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 =3D cpufreq_register_driver(&acpi_cpufreq_driver); + if ( hwp_available() ) + ret =3D hwp_register_driver(); + else + ret =3D cpufreq_register_driver(&acpi_cpufreq_driver); break; =20 case X86_VENDOR_AMD: diff --git a/xen/arch/x86/acpi/cpufreq/hwp.c b/xen/arch/x86/acpi/cpufreq/hw= p.c new file mode 100644 index 0000000000..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 =3D true; + +union hwp_request +{ + struct + { + unsigned int min_perf:8; + unsigned int max_perf:8; + unsigned int desired:8; + unsigned int energy_perf:8; + unsigned int activity_window:10; + bool package_control:1; + unsigned int 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 =3D=3D NULL ) + return -EINVAL; + + switch ( event ) + { + case CPUFREQ_GOV_START: + case CPUFREQ_GOV_LIMITS: + ret =3D 0; + break; + + case CPUFREQ_GOV_STOP: + default: + ret =3D -EINVAL; + break; + } + + return ret; +} + +static bool hwp_handle_option(const char *s, const char *end) +{ + int ret; + + if ( strncmp(s, "verbose", 7) =3D=3D 0 ) + { + s +=3D 7; + if ( *s =3D=3D '=3D' ) + { + s++; + cpufreq_verbose =3D !!simple_strtoul(s, NULL, 0); + + return true; + } + + if ( end =3D=3D NULL || + (end =3D=3D s && (*end =3D=3D '\0' || *end =3D=3D ',')) ) + { + cpufreq_verbose =3D true; + + return true; + } + + return false; + } + + ret =3D parse_boolean("hdc", s, end); + if ( ret < 0 ) + return false; + + opt_cpufreq_hdc =3D ret; + + return true; +} + +int __init hwp_cmdline_parse(const char *s) +{ + do + { + const char *end =3D strchr(s, ','); + + if ( s && !hwp_handle_option(s, end) ) + { + printk(XENLOG_WARNING "cpufreq/hwp: option '%s' not recognized= \n", + s); + + + return -1; + } + + s =3D end ? ++end : end; + } while ( s ); + + return 0; +} + +static struct cpufreq_governor cpufreq_gov_hwp =3D +{ + .name =3D "hwp", + .governor =3D hwp_governor, + .internal =3D 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 =3D cpuid_eax(CPUID_PM_LEAF); + + hwp_verbose("%d notify: %d act-window: %d energy-perf: %d pkg-level: %= d peci: %d\n", + !!(eax & CPUID6_EAX_HWP), + !!(eax & CPUID6_EAX_HWP_NOTIFICATION), + !!(eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW), + !!(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE), + !!(eax & CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST), + !!(eax & CPUID6_EAX_HWP_PECI)); + + if ( !(eax & CPUID6_EAX_HWP) ) + return false; + + if ( !(eax & CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE) ) + { + hwp_verbose("disabled: No energy/performance preference available"= ); + + return false; + } + + feature_hwp =3D eax & CPUID6_EAX_HWP; + feature_hwp_notification =3D eax & CPUID6_EAX_HWP_NOTIFICATION; + feature_hwp_activity_window =3D eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW; + feature_hdc =3D eax & CPUID6_EAX_HDC; + + hwp_verbose("Hardware Duty Cycling (HDC) %ssupported%s\n", + feature_hdc ? "" : "not ", + feature_hdc ? opt_cpufreq_hdc ? ", enabled" : ", disabled" + : ""); + + hwp_verbose("HW_FEEDBACK %ssupported\n", + (eax & CPUID6_EAX_HW_FEEDBACK) ? "" : "not "); + + cpufreq_governor_internal =3D 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 |=3D PKG_HDC_CTL_HDC_PKG_ENABLE; + else + msr &=3D ~PKG_HDC_CTL_HDC_PKG_ENABLE; + + if ( wrmsr_safe(MSR_PKG_HDC_CTL, msr) ) + { + hwp_err("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 |=3D PM_CTL1_HDC_ALLOW_BLOCK; + else + msr &=3D ~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 =3D base_khz * 1000; + policy->cpuinfo.min_freq =3D base_khz * 1000; + policy->cpuinfo.max_freq =3D max_khz * 1000; + policy->min =3D base_khz * 1000; + policy->max =3D max_khz * 1000; + policy->cur =3D 0; +} + +static void cf_check hwp_init_msrs(void *info) +{ + struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + uint64_t val; + + /* + * Package level MSR, but we don't have a good idea of packages here, = so + * just do it everytime. + */ + if ( rdmsr_safe(MSR_PM_ENABLE, val) ) + { + hwp_err("rdmsr_safe(MSR_PM_ENABLE)\n", policy->cpu); + data->curr_req.raw =3D -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 |=3D 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 =3D -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 =3D -1; + val &=3D ~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 =3D per_cpu(hwp_drv_data, policy->cpu); + + if ( !feature_hwp_activity_window && data->activity_window ) + { + hwp_verbose("HWP activity window not supported\n"); + + return -EINVAL; + } + + return 0; +} + +static void cf_check hwp_write_request(void *info) +{ + const struct cpufreq_policy *policy =3D info; + struct hwp_drv_data *data =3D this_cpu(hwp_drv_data); + union hwp_request hwp_req =3D data->curr_req; + + data->ret =3D 0; + + BUILD_BUG_ON(sizeof(union hwp_request) !=3D 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 =3D -EINVAL; + } +} + +static int cf_check hwp_cpufreq_target(struct cpufreq_policy *policy, + unsigned int target_freq, + unsigned int relation) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + /* Zero everything to ensure reserved bits are zero... */ + union hwp_request hwp_req =3D { .raw =3D 0 }; + + /* .. and update from there */ + hwp_req.min_perf =3D data->minimum; + hwp_req.max_perf =3D data->maximum; + hwp_req.desired =3D data->desired; + hwp_req.energy_perf =3D data->energy_perf; + if ( feature_hwp_activity_window ) + hwp_req.activity_window =3D data->activity_window; + + if ( hwp_req.raw =3D=3D data->curr_req.raw ) + return 0; + + data->curr_req =3D hwp_req; + + 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 =3D policy->cpu; + struct hwp_drv_data *data; + + data =3D 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 defau= lt \"%s\"\n", + cpufreq_opt_governor->name, cpufreq_gov_hwp.name); + policy->governor =3D &cpufreq_gov_hwp; + + per_cpu(hwp_drv_data, cpu) =3D data; + + on_selected_cpus(cpumask_of(cpu), hwp_init_msrs, policy, 1); + + if ( data->curr_req.raw =3D=3D -1 ) + { + hwp_err("Could not initialize HWP properly\n", cpu); + XFREE(per_cpu(hwp_drv_data, cpu)); + return -ENODEV; + } + + data->minimum =3D data->curr_req.min_perf; + data->maximum =3D data->curr_req.max_perf; + data->desired =3D data->curr_req.desired; + data->energy_perf =3D data->curr_req.energy_perf; + data->activity_window =3D data->curr_req.activity_window; + + 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.r= aw); + + 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 l= east + * 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 =3D info; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, policy->cpu); + uint64_t msr; + + data->ret =3D 0; + + if ( rdmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_verbose("CPU%u: error rdmsr_safe(MSR_IA32_MISC_ENABLE)\n", + policy->cpu); + data->ret =3D -EINVAL; + + return; + } + + if ( policy->turbo =3D=3D CPUFREQ_TURBO_ENABLED ) + msr &=3D ~MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + else + msr |=3D MSR_IA32_MISC_ENABLE_TURBO_DISENGAGE; + + if ( wrmsr_safe(MSR_IA32_MISC_ENABLE, msr) ) + { + hwp_verbose("CPU%u: error wrmsr_safe(MSR_IA32_MISC_ENABLE): %016lx= \n", + policy->cpu, msr); + data->ret =3D -EINVAL; + } +} + +static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *p= olicy) +{ + struct hwp_drv_data *data =3D 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 =3D +{ + .name =3D XEN_HWP_DRIVER, + .verify =3D hwp_cpufreq_verify, + .target =3D hwp_cpufreq_target, + .init =3D hwp_cpufreq_cpu_init, + .exit =3D hwp_cpufreq_cpu_exit, + .update =3D hwp_cpufreq_update, +}; + +int __init hwp_register_driver(void) +{ + return cpufreq_register_driver(&hwp_cpufreq_driver); +} diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/a= sm/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); } =20 -#define CPUID_PM_LEAF 6 -#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1 +#define CPUID_PM_LEAF 6 +#define CPUID6_EAX_HWP BIT(7, U) +#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) +#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) +#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) +#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) +#define CPUID6_EAX_HDC BIT(13, U) +#define CPUID6_EAX_HWP_PECI BIT(16, U) +#define CPUID6_EAX_HW_FEEDBACK BIT(19, U) +#define CPUID6_ECX_APERFMPERF_CAPABILITY BIT(0, U) =20 /* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index 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 @@ =20 #define MSR_PKRS 0x000006e1 =20 +#define MSR_PM_ENABLE 0x00000770 +#define PM_ENABLE_HWP_ENABLE BIT(0, ULL) + +#define MSR_HWP_CAPABILITIES 0x00000771 +#define MSR_HWP_INTERRUPT 0x00000773 +#define MSR_HWP_REQUEST 0x00000774 + #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff =20 @@ -165,6 +172,11 @@ #define PASID_PASID_MASK 0x000fffff #define PASID_VALID (_AC(1, ULL) << 31) =20 +#define MSR_PKG_HDC_CTL 0x00000db0 +#define PKG_HDC_CTL_HDC_PKG_ENABLE BIT(0, ULL) +#define MSR_PM_CTL1 0x00000db1 +#define PM_CTL1_HDC_ALLOW_BLOCK BIT(0, ULL) + #define MSR_UARCH_MISC_CTRL 0x00001b01 #define UARCH_CTRL_DOITM (_AC(1, ULL) << 0) =20 @@ -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) =20 #define MSR_IA32_TSC_DEADLINE 0x000006E0 #define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0 diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c index 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 ch= ar *str) return cpufreq_cmdline_parse(arg + 1); } =20 + if ( choice < 0 && !cmdline_strcmp(str, "hwp") ) + { + xen_processor_pmbits |=3D XEN_PROCESSOR_PM_PX; + cpufreq_controller =3D FREQCTL_xen; + opt_cpufreq_hwp =3D 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); =20 void intel_feature_detect(struct cpufreq_policy *policy); =20 +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/c= pufreq/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 @@ =20 #define XEN_PX_INIT 0x80000000 =20 +bool hwp_available(void); +int hwp_register_driver(void); + int powernow_cpufreq_init(void); unsigned int powernow_register_driver(void); unsigned int get_measured_perf(unsigned int cpu, unsigned int flag); diff --git a/xen/include/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; }; =20 +#define XEN_HWP_DRIVER "hwp" /* * cpufreq para name of this structure named * same as sysfs file name of native linux --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765866; cv=none; d=zohomail.com; s=zohoarc; b=aMxLkcmRxd48lMBcKMnfOvq4Eu6asam0/JOOzvnEZC3CqOmqnzcOpshWrbmH00mLwQaD08Cb21TixlgEbB64WBd2ZwShsQqT58eYs6SJLCtlpOnkL5j+VuvIaKkfuPD0hAxXLgt1W1raXnrJKrZ+sPLWGHHuSKrW3DAYhACAMQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765866; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BW3lKTSm5JYkGrQYyurYltq8i3jFBvOnwjMyoQl8MJY=; b=g8F0e2yjOxbUJB5ZKSTM6IGwkigX7pVrq5cA60p2mC2jqDHzCMHnq3eVBgLygqCYbWso89AwYFVqkINPDcKFW7hQIuUi/MV2vxJwuBj5LzNvNg/D1HqBSOWCy780aj/sdJR7d4RQKb+ucOq9CLxOfRAeCKFYGEyCQuLH2EyGrQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 168676586654097.12527347320531; Wed, 14 Jun 2023 11:04:26 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765868271100001 Content-Type: text/plain; charset="utf-8" Qubes testing of HWP support had a report of a laptop, Thinkpad X1 Carbon Gen 4 with a Skylake processor, locking up during boot when HWP is enabled. A user found a kernel bug that seems to be the same issue: https://bugzilla.kernel.org/show_bug.cgi?id=3D110941. That bug was fixed by Linux commit a21211672c9a ("ACPI / processor: Request native thermal interrupt handling via _OSC"). The tl;dr is SMM crashes when it receives thermal interrupts, so Linux calls the ACPI _OSC method to take over interrupt handling. The Linux fix looks at the CPU features to decide whether or not to call _OSC with bit 12 set to take over native interrupt handling. Xen needs some way to communicate HWP to Dom0 for making an equivalent call. Xen exposes modified PDC bits via the platform_op set_pminfo hypercall. Expand that to set bit 12 when HWP is present and in use. Any generated interrupt would be handled by Xen's thermal drive, which clears the status. Bit 12 isn't named in the linux header and is open coded in Linux's usage. 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/hw= p.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 =20 -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; =20 @@ -168,6 +169,11 @@ static int __init cf_check cpufreq_gov_hwp_init(void) } __initcall(cpufreq_gov_hwp_init); =20 +bool hwp_active(void) +{ + return hwp_in_use; +} + bool __init hwp_available(void) { unsigned int eax; @@ -211,7 +217,6 @@ bool __init hwp_available(void) return false; } =20 - feature_hwp =3D eax & CPUID6_EAX_HWP; feature_hwp_notification =3D eax & CPUID6_EAX_HWP_NOTIFICATION; feature_hwp_activity_window =3D eax & CPUID6_EAX_HWP_ACTIVITY_WINDOW; feature_hdc =3D 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 "); =20 - cpufreq_governor_internal =3D feature_hwp; + hwp_in_use =3D eax & CPUID6_EAX_HWP; + cpufreq_governor_internal =3D hwp_in_use; =20 - if ( feature_hwp ) + if ( hwp_in_use ) hwp_info("Using HWP for cpufreq\n"); =20 - return feature_hwp; + return hwp_in_use; } =20 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 =20 +#include + u32 __read_mostly acpi_smi_cmd; u8 __read_mostly acpi_enable_value; u8 __read_mostly acpi_disable_value; @@ -140,5 +142,8 @@ int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *pdc, u32 m= ask) !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) pdc[2] &=3D ~(ACPI_PDC_C_C1_FFH | ACPI_PDC_C_C2C3_FFH); =20 + if (hwp_active()) + pdc[2] |=3D ACPI_PDC_CPPC_NATIVE_INTR; + return 0; } diff --git a/xen/arch/x86/cpu/mcheck/mce_intel.c b/xen/arch/x86/cpu/mcheck/= mce_intel.c index 2f23f02923..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_u= ser_regs *regs) =20 ack_APIC_irq(); =20 + if ( hwp_active() ) + wrmsr_safe(MSR_HWP_STATUS, 0); + if ( NOW() < per_cpu(next, cpu) ) return; =20 diff --git a/xen/arch/x86/include/asm/msr-index.h b/xen/arch/x86/include/as= m/msr-index.h index 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 =20 #define MSR_X2APIC_FIRST 0x00000800 #define MSR_X2APIC_LAST 0x000008ff diff --git a/xen/include/acpi/cpufreq/processor_perf.h b/xen/include/acpi/c= pufreq/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 =20 bool hwp_available(void); +bool hwp_active(void); int hwp_register_driver(void); =20 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) =20 #define ACPI_PDC_EST_CAPABILITY_SMP (ACPI_PDC_SMP_C1PT | \ ACPI_PDC_C_C1_HALT | \ --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765875; cv=none; d=zohomail.com; s=zohoarc; b=OOIUFhRyTobad4rpfUonmz6dfD+OU4TBJmJQOsyRy/y2/szHxNY7oMo3wnMOYEmVPA1iNfsyImOX/EHKYFrpeARQPsjMSYlD9TcoCMaYcLQUgKTlIrTgFblW9T6GgSXgwaXiNscLy0P7bmZP6Z7It+F0XIBxmP608S9Ysxi2Ipc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765875; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fxVGZ+gvz08OKoWjfCFPcTsdFvOXHOS/NxFkI1JhnIY=; b=Xde4NuIgtQF6W5U8vFw1k+zkior1umoyQJKlv6pIhTtkKlEE7UtQY41K6sgO0n1ATZvC/Sn94d1CtxSB0iAD7bRiq3Po84i6Q14oYXqqex3ChLe+SLLEp2YN83BDMcCStcFvZh/i6ZI+4GSmpHDRbolHGm6NdylNXdpRe5RtsFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765875296816.3391092075894; Wed, 14 Jun 2023 11:04:35 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765876294100003 Content-Type: text/plain; charset="utf-8" When using HWP, some of the returned data is not applicable. In that case, we should just omit it to avoid confusing the user. So switch to printing the base and max frequencies since those are relevant to HWP. Similarly, stop printing the CPU frequencies since those do not apply. The scaling fields are also no longer printed. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- 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_cp= ufreq) { + bool hwp =3D strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER) =3D=3D = 0; int i; =20 printf("cpu id : %d\n", cpuid); @@ -720,49 +721,57 @@ static void print_cpufreq_para(int cpuid, struct xc_g= et_cpufreq_para *p_cpufreq) printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); =20 - printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->cpuinfo_max_freq, - p_cpufreq->cpuinfo_min_freq, - p_cpufreq->cpuinfo_cur_freq); + if ( hwp ) + printf("cpuinfo frequency : base [%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); =20 printf("scaling_driver : %s\n", p_cpufreq->scaling_driver); =20 - printf("scaling_avail_gov : %s\n", - p_cpufreq->scaling_available_governors); - - printf("current_governor : %s\n", p_cpufreq->u.s.scaling_governor); - if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - printf(" userspace specific :\n"); - printf(" scaling_setspeed : %u\n", - p_cpufreq->u.s.u.userspace.scaling_setspeed); - } - else if ( !strncmp(p_cpufreq->u.s.scaling_governor, - "ondemand", CPUFREQ_NAME_LEN) ) + if ( !hwp ) { - printf(" ondemand specific :\n"); - printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.u.ondemand.sampling_rate_max, - p_cpufreq->u.s.u.ondemand.sampling_rate_min, - p_cpufreq->u.s.u.ondemand.sampling_rate); - printf(" up_threshold : %u\n", - p_cpufreq->u.s.u.ondemand.up_threshold); - } + printf("scaling_avail_gov : %s\n", + p_cpufreq->scaling_available_governors); =20 - printf("scaling_avail_freq :"); - for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) - if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D - p_cpufreq->u.s.scaling_cur_freq ) - printf(" *%d", p_cpufreq->scaling_available_frequencies[i]); - else - printf(" %d", p_cpufreq->scaling_available_frequencies[i]); - printf("\n"); + printf("current_governor : %s\n", p_cpufreq->u.s.scaling_gover= nor); + if ( !strncmp(p_cpufreq->u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + { + printf(" userspace specific :\n"); + printf(" scaling_setspeed : %u\n", + p_cpufreq->u.s.u.userspace.scaling_setspeed); + } + else if ( !strncmp(p_cpufreq->u.s.scaling_governor, + "ondemand", CPUFREQ_NAME_LEN) ) + { + printf(" ondemand specific :\n"); + printf(" sampling_rate : max [%u] min [%u] cur [%u]\n", + p_cpufreq->u.s.u.ondemand.sampling_rate_max, + p_cpufreq->u.s.u.ondemand.sampling_rate_min, + p_cpufreq->u.s.u.ondemand.sampling_rate); + printf(" up_threshold : %u\n", + p_cpufreq->u.s.u.ondemand.up_threshold); + } + + printf("scaling_avail_freq :"); + for ( i =3D 0; i < p_cpufreq->freq_num; i++ ) + if ( p_cpufreq->scaling_available_frequencies[i] =3D=3D + p_cpufreq->u.s.scaling_cur_freq ) + printf(" *%d", p_cpufreq->scaling_available_frequencies[i]= ); + else + printf(" %d", p_cpufreq->scaling_available_frequencies[i]); + printf("\n"); =20 - printf("scaling frequency : max [%u] min [%u] cur [%u]\n", - p_cpufreq->u.s.scaling_max_freq, - p_cpufreq->u.s.scaling_min_freq, - p_cpufreq->u.s.scaling_cur_freq); + printf("scaling frequency : max [%u] min [%u] cur [%u]\n", + p_cpufreq->u.s.scaling_max_freq, + p_cpufreq->u.s.scaling_min_freq, + p_cpufreq->u.s.scaling_cur_freq); + } =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765869; cv=none; d=zohomail.com; s=zohoarc; b=V4AGxpt31wsKybCDw4boM2FX24XjrQFXbWHgSIFpMO3F8zuscMTeOAxrS9cF4xt1Xb+noyW598/N6bonxo76uRc1i4yHt/KRQgvLiISkEkGBqTm51JlaKkwaY1wLGHzrSMA1rbNnM5alxv06kOABHr28ldMA9URIHXd+EoqfS0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765869; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uF8Wj46GTB4zKmfvuCCfVeswvcmmkhkf2knhpTgohUg=; b=NmS1rw8OeZENUMunhlV66M0d+T3qjNGcUQfYS9HWAFwk0OBcW22gqmOdsqPwCCZBXIAP6nuge6AnKO3qZjXNNdsTSWC7D5cS6VTNm/HtrThQ0MnguGAMCu2RgpA8as5mmL4BMByQzyNS9dDammlTRePWG2xP2lS7+EvJIkVM8t8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765869854253.52390177611153; Wed, 14 Jun 2023 11:04:29 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765870506100001 Content-Type: text/plain; charset="utf-8" Extend xen_get_cpufreq_para to return hwp parameters. HWP is an implementation of ACPI CPPC (Collaborative Processor Performance Control). Use the CPPC name since that might be useful in the future for AMD P-state. We need the features bitmask to indicate fields supported by the actual hardware - this only applies to activity window for the time being. The HWP most_efficient is mapped to CPPC lowest_nonlinear, and guaranteed is mapped to nominal. CPPC has a guaranteed that is optional while nominal is required. ACPI spec says "If this register is not implemented, OSPM assumes guaranteed performance is always equal to nominal performance." 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/hw= p.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 =3D .update =3D hwp_cpufreq_update, }; =20 +int get_hwp_para(const unsigned int cpu, + struct xen_cppc_para *cppc_para) +{ + const struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + + if ( data =3D=3D NULL ) + return -EINVAL; + + cppc_para->features =3D + (feature_hwp_activity_window ? XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW : 0= ); + cppc_para->lowest =3D data->hw.lowest; + cppc_para->lowest_nonlinear =3D data->hw.most_efficient; + cppc_para->nominal =3D data->hw.guaranteed; + cppc_para->highest =3D data->hw.highest; + cppc_para->minimum =3D data->minimum; + cppc_para->maximum =3D data->maximum; + cppc_para->desired =3D data->desired; + cppc_para->energy_perf =3D data->energy_perf; + cppc_para->activity_window =3D data->activity_window; + + return 0; +} + int __init hwp_register_driver(void) { 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= ); =20 - if ( !(scaling_available_governors =3D - xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) - return -ENOMEM; - if ( (ret =3D read_scaling_available_governors( - scaling_available_governors, - gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + if ( !strncasecmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER, + CPUFREQ_NAME_LEN) ) + ret =3D get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para); + else { + if ( !(scaling_available_governors =3D + xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) ) + return -ENOMEM; + if ( (ret =3D read_scaling_available_governors( + scaling_available_governors, + gov_num * CPUFREQ_NAME_LEN * sizeof(char))) ) + { + xfree(scaling_available_governors); + return ret; + } + ret =3D copy_to_guest(op->u.get_para.scaling_available_governors, + scaling_available_governors, gov_num * CPUFREQ_NAME_LE= N); xfree(scaling_available_governors); - return ret; - } - ret =3D copy_to_guest(op->u.get_para.scaling_available_governors, - scaling_available_governors, gov_num * CPUFREQ_NAME_LEN); - xfree(scaling_available_governors); - if ( ret ) - return ret; + if ( ret ) + return ret; =20 - op->u.get_para.u.s.scaling_cur_freq =3D policy->cur; - op->u.get_para.u.s.scaling_max_freq =3D policy->max; - op->u.get_para.u.s.scaling_min_freq =3D policy->min; + op->u.get_para.u.s.scaling_cur_freq =3D policy->cur; + op->u.get_para.u.s.scaling_max_freq =3D policy->max; + op->u.get_para.u.s.scaling_min_freq =3D policy->min; =20 - if ( policy->governor->name[0] ) - strlcpy(op->u.get_para.u.s.scaling_governor, - policy->governor->name, CPUFREQ_NAME_LEN); - else - strlcpy(op->u.get_para.u.s.scaling_governor, "Unknown", - CPUFREQ_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); =20 - /* governor specific para */ - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, - "userspace", CPUFREQ_NAME_LEN) ) - { - op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cur; - } + /* governor specific para */ + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + "userspace", CPUFREQ_NAME_LEN) ) + { + op->u.get_para.u.s.u.userspace.scaling_setspeed =3D policy->cu= r; + } =20 - if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, - "ondemand", CPUFREQ_NAME_LEN) ) - { - ret =3D get_cpufreq_ondemand_para( - &op->u.get_para.u.s.u.ondemand.sampling_rate_max, - &op->u.get_para.u.s.u.ondemand.sampling_rate_min, - &op->u.get_para.u.s.u.ondemand.sampling_rate, - &op->u.get_para.u.s.u.ondemand.up_threshold); + if ( !strncasecmp(op->u.get_para.u.s.scaling_governor, + "ondemand", CPUFREQ_NAME_LEN) ) + { + ret =3D get_cpufreq_ondemand_para( + &op->u.get_para.u.s.u.ondemand.sampling_rate_max, + &op->u.get_para.u.s.u.ondemand.sampling_rate_min, + &op->u.get_para.u.s.u.ondemand.sampling_rate, + &op->u.get_para.u.s.u.ondemand.up_threshold); + } } =20 return ret; diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 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= ); =20 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); =20 #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; }; =20 +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 cons= train + * 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 oper= ation + * calculations, controlling responsiveness. Measured in microseconds + * encoded as: + * + * bits 6:0 - 7bit mantissa + * bits 9:7 - 3bit base-10 exponent + * btis 15:10 - Unused - must be 0 + */ +#define XEN_CPPC_ACT_WINDOW_MANTISSA_MASK 0x07f +#define XEN_CPPC_ACT_WINDOW_EXPONENT_MASK 0x380 + uint32_t activity_window; +}; + #define XEN_HWP_DRIVER "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; =20 int32_t turbo_enabled; --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686766186; cv=none; d=zohomail.com; s=zohoarc; b=fmSCq5ajsMZgm+N65ZJfWWiDFhw7//CiJE+1cnNApHz2DpfiGA2aLilcr2S8vyRQStr9qlfWSI0ejK3Q3KwoxTJ5PX+u4B4qJ60oWYAqU5CI1HKEM2TnLpknNSst3q4o3Q5RtwZeUTKq8q42KOyCqg3UTgnTbnsTeSC4ENdmTjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686766186; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vAh4UqPFdXosdcswDrRJWUQizeR7RUgorIbVDVeVJRs=; b=hSSSdPzs8z+lgPbTyUoLnK+czS1JYI+PvRfPHspRos6jRfkcWVCAFRVwuVfbYorxHig23x0zjVDesWkNjQ8XS5Ya7x5LYCkgghemF7wBQKEtI4VwkWcgEUQTBgKkSGkIP8o+9H3ICkL12+5G+pwMEjgsqCbg3kF86Ba6owqI9VY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686766186088947.1300879119696; Wed, 14 Jun 2023 11:09:46 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686766186666100001 Content-Type: text/plain; charset="utf-8" Expose the cppc_para fields through libxc. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v4: Rename hwp to cppc Add Anthony's Ack --- tools/include/xenctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 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; =20 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; =20 int32_t turbo_enabled; --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765884; cv=none; d=zohomail.com; s=zohoarc; b=MCjnJgkkoPcC2iENATy0AXSrWXa7Oe+bQ9QHkFT8UlPKw4gEpI2XcgspX2EqvksrBRKmiDep/cuK/CH80uU50ry4gFOjTHyFtiFSLJZ6IPc2wDzSTMiY+dHsOd7psM0ZvvNpoTXakGfc6M0z+5DP66gB0Y68YRR/DQkFH1qeS98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765884; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2G+0xPmD9u5kzp6yWDZeh7ZvMy436YMgfg56aXJDM/0=; b=KYgF6vLafum/ah8zA/37WsZ5ZzfG/W3VNEshwXa9eCybqnN7/EQuNU3lX64A7GJAymu2Zrf8o+lSQr2Z6WOC3wWtxG62CAN3uQlVqB570/pp4b/etGywYkjBFzytQTJia1bbDnikJAjaN/Y1/JBTTVuCIjLK+QU9/gqa6Z1w/fg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765884390416.12399973178026; Wed, 14 Jun 2023 11:04:44 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765886328100001 Content-Type: text/plain; charset="utf-8" Print HWP-specific parameters. Some are always present, but others depend on hardware support. Signed-off-by: Jason Andryuk Reviewed-by: Jan Beulich --- 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(); } =20 +static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, + const char **units) +{ + unsigned int mantissa =3D MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + unsigned int exponent =3D MASK_EXTR(cppc->activity_window, + XEN_CPPC_ACT_WINDOW_EXPONENT_MASK); + unsigned int multiplier =3D 1; + unsigned int i; + + /* + * SDM only states a 0 register is hardware selected, and doesn't ment= ion + * a 0 mantissa with a non-0 exponent. Only special case a 0 register. + */ + if ( cppc->activity_window =3D=3D 0 ) + { + *units =3D "hardware selected"; + + return 0; + } + + if ( exponent >=3D 6 ) + { + *units =3D "s"; + exponent -=3D 6; + } + else if ( exponent >=3D 3 ) + { + *units =3D "ms"; + exponent -=3D 3; + } + else + *units =3D "us"; + + for ( i =3D 0; i < exponent; i++ ) + multiplier *=3D 10; + + return mantissa * multiplier; +} + /* print out parameters about cpu frequency */ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cp= ufreq) { @@ -772,6 +812,32 @@ static void print_cpufreq_para(int cpuid, struct xc_ge= t_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 =3D &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 =3D 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"); + } =20 printf("turbo mode : %s\n", p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a"); --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765879; cv=none; d=zohomail.com; s=zohoarc; b=XLn7wBiOn30ben4m3Vaax/U6iFps2GGy/kp3KMOUPgkfgdQKKJBOlFWLv1TQ7VJ42zkcBrcjhJUn0SAno0mVeuvqNQnawlAebL/rqix5N1l2QwBrxXoNMPTirz7GgIwtM8JF/sskrBJbYGRVzqTE4Ax9OhcMSEirx7kZzh51jOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765879; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1GKrKS8MiOO/3IyATz8/1ZuFV/xDUGqEs/80K9twFs0=; b=H8NpwYL8xMIigIJeDIpCt4aTrEElfRhwDl2hMhLRzgFeNZigml12cc2Uhul9SI+xF/yCEfYYVjiG8cWJMSzZ21FgB3fNoV7rICa8U1wH+hU6lCUfKsD50pxC46efKiq6nSeySi6xaiKM+8DowUIH+IRZE8tMOwYl864G2+/n1mY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765879504130.72917710696743; Wed, 14 Jun 2023 11:04:39 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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=20Pau=20Monn=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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765881135100001 Content-Type: text/plain; charset="utf-8" Add SET_CPUFREQ_HWP xen_sysctl_pm_op to set HWP parameters. The sysctl supports setting multiple values simultaneously as indicated by the set_params bits. This allows atomically applying new HWP configuration via a single wrmsr. XEN_SYSCTL_HWP_SET_PRESET_BALANCE/PERFORMANCE/POWERSAVE provide three common presets. Setting them depends on hardware limits which the hypervisor is already caching. So using them allows skipping a hypercall to query the limits (lowest/highest) to then set those same values. The code is organized to allow a preset to be refined with additional 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/hw= p.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 =3D true; =20 +#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 +#define HWP_ENERGY_PERF_BALANCE 0x80 +#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff + union hwp_request { struct @@ -560,6 +564,100 @@ int get_hwp_para(const unsigned int cpu, return 0; } =20 +int set_hwp_para(struct cpufreq_policy *policy, + const struct xen_set_cppc_para *set_cppc) +{ + unsigned int cpu =3D policy->cpu; + struct hwp_drv_data *data =3D per_cpu(hwp_drv_data, cpu); + + if ( data =3D=3D 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 !=3D 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 =3D data->hw.lowest; + data->maximum =3D data->hw.lowest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_MAX_POWERSAVE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE: + data->minimum =3D data->hw.highest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_MAX_PERFORMANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE: + data->minimum =3D data->hw.lowest; + data->maximum =3D data->hw.highest; + data->activity_window =3D 0; + data->energy_perf =3D HWP_ENERGY_PERF_BALANCE; + data->desired =3D 0; + break; + + case XEN_SYSCTL_CPPC_SET_PRESET_NONE: + break; + + default: + return -EINVAL; + } + + /* Further customize presets if needed */ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM ) + data->minimum =3D set_cppc->minimum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ) + data->maximum =3D set_cppc->maximum; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF ) + data->energy_perf =3D set_cppc->energy_perf; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) + data->desired =3D set_cppc->desired; + + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) + data->activity_window =3D set_cppc->activity_window & + XEN_SYSCTL_CPPC_ACT_WINDOW_MASK; + + return hwp_cpufreq_target(policy, 0, 0); +} + int __init hwp_register_driver(void) { 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 *o= p) return ret; } =20 +static int set_cpufreq_cppc(const struct xen_sysctl_pm_op *op) +{ + struct cpufreq_policy *policy =3D per_cpu(cpufreq_cpu_policy, op->cpui= d); + + 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 =3D 0; @@ -474,6 +487,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) break; } =20 + case SET_CPUFREQ_CPPC: + ret =3D set_cpufreq_cppc(op); + break; + case GET_CPUFREQ_AVGFREQ: { op->u.get_avgfreq =3D cpufreq_driver_getavg(op->cpuid, USR_GETAVG); diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/= cpufreq.h index 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); =20 #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; }; =20 +/* + * Set CPPC values. + * + * Configured the parameters for CPPC. Set bits in set_params control whi= ch + * 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) =20 /* 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 --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686766186; cv=none; d=zohomail.com; s=zohoarc; b=AGfbk/VUt4VL0NwwCwKHRb75zSSjCK2Bf9wgy/EzD/gahUZETTjemiz/ClPE/mbEtRbIbJJX3sWD+HjSDADW3yPyAHnRQxMCSZ1MYKvhCczLvbgRbCHaGjB5V6u0UXydbcevRn86eqtPoQHA7+BqtAebw5gTZFqEOS2H2mPKgOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686766186; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XCeW0dYT+v8QEPZf3DSgLima7EAFRRshc9U3zxruA5E=; b=A3gGm1PROCu3ggm/kHBuk+ErfRxZjHeLUQ2he+l6FwxSpD+L0j4jVGkT4HlMMbTIzs0LA+jmLSv+Hytw1d6eyZ8SehlwNuM1HG2z6jcY2FN6C9EPzzua2TFbzac7BbYMHN1LDCNKADJDhmT6QZtm3YHYHcPCGIdTp7FX9MlmLt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686766186721287.3937787347769; Wed, 14 Jun 2023 11:09:46 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686766187342100003 Content-Type: text/plain; charset="utf-8" Add xc_set_cpufreq_cppc to allow calling xen_systctl_pm_op SET_CPUFREQ_CPPC. Signed-off-by: Jason Andryuk Acked-by: Anthony PERARD --- v2: Mark xc_set_hwp_para_t const v4: s/hwp/cppc/ Add Anthony's Ack --- 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; }; =20 +typedef struct xen_set_cppc_para xc_set_cppc_para_t; + int xc_get_cpufreq_para(xc_interface *xch, int cpuid, struct xc_get_cpufreq_para *user_para); int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname); int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value); +int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, + const xc_set_cppc_para_t *set_cppc); int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq); =20 int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value); diff --git a/tools/libs/ctrl/xc_pm.c b/tools/libs/ctrl/xc_pm.c index 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); } =20 +int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid, + const xc_set_cppc_para_t *set_cppc) +{ + DECLARE_SYSCTL; + + if ( !xch ) + { + errno =3D EINVAL; + return -1; + } + sysctl.cmd =3D XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =3D SET_CPUFREQ_CPPC; + sysctl.u.pm_op.cpuid =3D cpuid; + sysctl.u.pm_op.u.set_cppc =3D *set_cppc; + + return xc_sysctl(xch, &sysctl); +} + int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq) { int ret =3D 0; --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686765889; cv=none; d=zohomail.com; s=zohoarc; b=nUOof/RCCPYOEWmqnOSC6VPXU+FAWtQbUdyCUVp6TTqNnfFs4Y8PGl8YQb33efnvNei3cKlwr+z65mtSdz3vBogkRSkvaqh/G2hFcDH/22XbAaGj35Dby74vYuOiOdm8VgYyzaMXcs3qem2AoGiL7inpQuQzBrBR9wrpz560Cdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686765889; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2TAha9GGtbIdxJkaO8y2Wuv/uF0GuXKaVPOMOdxqX78=; b=ky4cGtnVguwKmESWdFLMrgKM/CuwBK1ux/6vdslm+ZDP5RwtIi+DmBwuiDOF+KwMh2KmeWqWfsPO0VEL3Ogk5pFE22lTx6LNDKlLu8KFmApC02gWMWcknVWOapXgVReIQxcppviC5lURDvUCNiWpRGmI9zkE4NuB1KOti8eCk+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686765889464487.00868945371724; Wed, 14 Jun 2023 11:04:49 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686765890942100001 Content-Type: text/plain; charset="utf-8" set-cpufreq-cppc allows setting the Hardware P-State (HWP) parameters. It can be run on all or just a single cpu. There are presets of balance, powersave & performance. Those can be further tweaked by param:val arguments as explained in the usage description. Parameter names are just checked to the first 3 characters to shorten typing. Some options are hardware dependent, and ranges can be found in get-cpufreq-para. Signed-off-by: Jason Andryuk Acked-by: Jan Beulich --- 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 =20 +#include +#include #include #include #include @@ -67,6 +69,30 @@ void show_help(void) " set-max-cstate |'unlimited' [|'unlimited']= \n" " set the C-State limitati= on ( >=3D 0) and\n" " optionally the C-sub-sta= te limitation ( >=3D 0)\n" + " set-cpufreq-cppc [cpuid] [balance|performance|powersave= ] *\n" + " set Hardware P-State (HW= P) parameters\n" + " on CPU or all if= omitted.\n" + " optionally a preset of o= ne of:\n" + " balance|performance|po= wersave\n" + " an optional list of para= m:val arguments\n" + " minimum:N (0-255)\n" + " maximum:N (0-255)\n" + " get-cpufreq-para l= owest/highest\n" + " values are limits = for\n" + " minumum/maximum.\n" + " desired:N (0-255)\n" + " set explicit perfo= rmance target.\n" + " non-zero disables = auto-HWP mode.\n" + " energy-perf:N (0-255)\= n" + " energy/per= formance hint\n" + " lower - fa= vor performance\n" + " higher - f= avor powersave\n" + " 128 - bala= nce\n" + " act-window:N{,m,u}s ra= nge 1us-1270s\n" + " window for interna= l calculations.\n" + " units default to \= "us\" if unspecified.\n" + " truncates un-repre= sentable values.\n" + " 0 lets the hardwar= e decide.\n" " start [seconds] start collect Cx/Px stat= istics,\n" " output after CTRL-C or S= IGINT or several seconds.\n" " enable-turbo-mode [cpuid] enable Turbo Mode for pr= ocessors that support it.\n" @@ -1292,6 +1318,216 @@ void disable_turbo_mode(int argc, char *argv[]) errno, strerror(errno)); } =20 +/* + * Parse activity_window:NNN{us,ms,s} and validate range. + * + * Activity window is a 7bit mantissa (0-127) with a 3bit exponent (0-7) b= ase + * 10 in microseconds. So the range is 1 microsecond to 1270 seconds. A = value + * of 0 lets the hardware autonomously select the window. + * + * Return 0 on success + * -1 on error + */ +static int parse_activity_window(xc_set_cppc_para_t *set_cppc, unsigned lo= ng u, + const char *suffix) +{ + unsigned int exponent =3D 0; + unsigned int multiplier =3D 1; + + if ( suffix && suffix[0] ) + { + if ( strcmp(suffix, "s") =3D=3D 0 ) + { + multiplier =3D 1000 * 1000; + exponent =3D 6; + } + else if ( strcmp(suffix, "ms") =3D=3D 0 ) + { + multiplier =3D 1000; + exponent =3D 3; + } + else if ( strcmp(suffix, "us") !=3D 0 ) + { + fprintf(stderr, "invalid activity window units: \"%s\"\n", suf= fix); + + return -1; + } + } + + /* u * multipler > 1270 * 1000 * 1000 transformed to avoid overflow. */ + if ( u > 1270 * 1000 * 1000 / multiplier ) + { + fprintf(stderr, "activity window is too large\n"); + + return -1; + } + + /* looking for 7 bits of mantissa and 3 bits of exponent */ + while ( u > 127 ) + { + u +=3D 5; /* Round up to mitigate truncation rounding down + e.g. 128 -> 120 vs 128 -> 130. */ + u /=3D 10; + exponent +=3D 1; + } + + set_cppc->activity_window =3D + MASK_INSR(exponent, XEN_CPPC_ACT_WINDOW_EXPONENT_MASK) | + MASK_INSR(u, XEN_CPPC_ACT_WINDOW_MANTISSA_MASK); + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_ACT_WINDOW; + + return 0; +} + +static int parse_cppc_opts(xc_set_cppc_para_t *set_cppc, int *cpuid, + int argc, char *argv[]) +{ + int i =3D 0; + + if ( argc < 1 ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( isdigit(argv[i][0]) ) + { + if ( sscanf(argv[i], "%d", cpuid) !=3D 1 || *cpuid < 0 ) + { + fprintf(stderr, "Could not parse cpuid \"%s\"\n", argv[i]); + return -1; + } + + i++; + } + + if ( i =3D=3D argc ) + { + fprintf(stderr, "Missing arguments\n"); + return -1; + } + + if ( strcasecmp(argv[i], "powersave") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE; + i++; + } + else if ( strcasecmp(argv[i], "performance") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE; + i++; + } + else if ( strcasecmp(argv[i], "balance") =3D=3D 0 ) + { + set_cppc->set_params =3D XEN_SYSCTL_CPPC_SET_PRESET_BALANCE; + i++; + } + + for ( ; i < argc; i++) + { + unsigned long val; + char *param =3D argv[i]; + char *value; + char *suffix; + int ret; + + value =3D strchr(param, ':'); + if ( value =3D=3D NULL ) + { + fprintf(stderr, "\"%s\" is an invalid cppc parameter\n", argv[= i]); + return -1; + } + + value[0] =3D '\0'; + value++; + + errno =3D 0; + val =3D strtoul(value, &suffix, 10); + if ( (errno && val =3D=3D ULONG_MAX) || value =3D=3D suffix ) + { + fprintf(stderr, "Could not parse number \"%s\"\n", value); + return -1; + } + + if ( strncasecmp(param, "act-window", strlen(param)) =3D=3D 0 ) + { + ret =3D parse_activity_window(set_cppc, val, suffix); + if (ret) + return -1; + + continue; + } + + if ( val > 255 ) + { + fprintf(stderr, "\"%s\" value \"%lu\" is out of range\n", para= m, + val); + return -1; + } + + if ( suffix && suffix[0] ) + { + fprintf(stderr, "Suffix \"%s\" is invalid\n", suffix); + return -1; + } + + if ( strncasecmp(param, "minimum", MAX(2, strlen(param))) =3D=3D 0= ) + { + set_cppc->minimum =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_MINIMUM; + } + else if ( strncasecmp(param, "maximum", MAX(2, strlen(param))) =3D= =3D 0 ) + { + set_cppc->maximum =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_MAXIMUM; + } + else if ( strncasecmp(param, "desired", strlen(param)) =3D=3D 0 ) + { + set_cppc->desired =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_DESIRED; + } + else if ( strncasecmp(param, "energy-perf", strlen(param)) =3D=3D = 0 ) + { + set_cppc->energy_perf =3D val; + set_cppc->set_params |=3D XEN_SYSCTL_CPPC_SET_ENERGY_PERF; + } + else + { + fprintf(stderr, "\"%s\" is an invalid parameter\n", param); + return -1; + } + } + + if ( set_cppc->set_params =3D=3D 0 ) + { + fprintf(stderr, "No parameters set in request\n"); + return -1; + } + + return 0; +} + +static void cppc_set_func(int argc, char *argv[]) +{ + xc_set_cppc_para_t set_cppc =3D {}; + int cpuid =3D -1; + int i =3D 0; + + if ( parse_cppc_opts(&set_cppc, &cpuid, argc, argv) ) + exit(EINVAL); + + if ( cpuid !=3D -1 ) + { + i =3D cpuid; + max_cpu_nr =3D i + 1; + } + + for ( ; i < max_cpu_nr; i++ ) + if ( xc_set_cpufreq_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 }, --=20 2.40.1 From nobody Sat May 18 14:25:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686766192; cv=none; d=zohomail.com; s=zohoarc; b=WNkjE0nAwZ+DdIPSonZaDBgNwLOHkREGKKAfD3u9CF/JShx7lESFdWftt+JJg2aoxW586SiWy+efhJuOUOcDIMUnUpnEmNcM7adIE1Pztj70KuQYeSCTHLAmyEAyAi71+cX4DYCJRtN1XOIPJFnSswphH/T9FOLt1R2LQtSlZ18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686766192; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AXCdosE1xzkZrcu7sJ9kEjSlEgbAAlcqZ3LQutJHGBw=; b=bqU953yi9kwbRHmVndLAWKDXXoCLsuZcfG49RwZoIV93kDZWX64PDk2uGsqycJ5AIt98S/svk1CYMCHL3fBB86IvVunG6QY8UHUsfDoe+cdwa7stf7HrJTLxlME2oef5GBQ9P5WPJSK+pvYppQQetD84M2Rp0v8YNMrhnIBgu/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1686766192498853.2706324555783; Wed, 14 Jun 2023 11:09:52 -0700 (PDT) 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 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-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 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 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1686766194599100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jason Andryuk Acked-by: Henry Wang --- v3: Position under existing Added section Add Henry's Ack v2: Add blank line --- CHANGELOG.md | 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://keepach= angelog.com/en/1.0.0/) - xl/libxl can customize SMBIOS strings for HVM guests. - Add support for AVX512-FP16 on x86. - On Arm, Xen supports guests running SVE/SVE2 instructions. (Tech Previe= w) - + - Add Intel Hardware P-States (HWP) cpufreq driver. =20 ## [4.17.0](https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dshortlog;h=3DR= ELEASE-4.17.0) - 2022-12-12 =20 --=20 2.40.1