[PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters

Penny Zheng posted 19 patches 3 months, 3 weeks ago
Only 18 patches received!
There is a newer version of this series
[PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
Posted by Penny Zheng 3 months, 3 weeks ago
New helpers print_cppc_para() and get_cpufreq_cppc() are introduced to deal
with CPPC-related parameters, in order to be re-used when later exporting new
sub-op "get-cpufreq-cppc".

Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
v5 -> v6:
- new commit
---
 tools/misc/xenpm.c       | 53 +++++++++++++++++++++-------------------
 xen/drivers/acpi/pm-op.c | 16 +++++++++---
 2 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index 55b0b0c482..120e9eae22 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -799,6 +799,33 @@ static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,
     return mantissa * multiplier;
 }
 
+/* print out parameters about cpu cppc */
+static void print_cppc_para(unsigned int cpuid,
+                            const xc_cppc_para_t *cppc)
+{
+    printf("cppc variables       :\n");
+    printf("  hardware limits    : lowest [%"PRIu32"] lowest nonlinear [%"PRIu32"]\n",
+           cppc->lowest, cppc->lowest_nonlinear);
+    printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
+           cppc->nominal, cppc->highest);
+    printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy perf [%"PRIu32"]\n",
+           cppc->minimum, cppc->maximum, cppc->energy_perf);
+
+    if ( cppc->features & XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW )
+    {
+        unsigned int activity_window;
+        const char *units;
+
+        activity_window = calculate_activity_window(cppc, &units);
+        printf("                     : activity_window [%"PRIu32" %s]\n",
+               activity_window, units);
+    }
+
+    printf("                     : desired [%"PRIu32"%s]\n",
+           cppc->desired,
+           cppc->desired ? "" : " hw autonomous");
+}
+
 /* print out parameters about cpu frequency */
 static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
 {
@@ -825,31 +852,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
     printf("scaling_driver       : %s\n", p_cpufreq->scaling_driver);
 
     if ( hwp )
-    {
-        const xc_cppc_para_t *cppc = &p_cpufreq->u.cppc_para;
-
-        printf("cppc variables       :\n");
-        printf("  hardware limits    : lowest [%"PRIu32"] lowest nonlinear [%"PRIu32"]\n",
-               cppc->lowest, cppc->lowest_nonlinear);
-        printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
-               cppc->nominal, cppc->highest);
-        printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy perf [%"PRIu32"]\n",
-               cppc->minimum, cppc->maximum, cppc->energy_perf);
-
-        if ( cppc->features & XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW )
-        {
-            unsigned int activity_window;
-            const char *units;
-
-            activity_window = calculate_activity_window(cppc, &units);
-            printf("                     : activity_window [%"PRIu32" %s]\n",
-                   activity_window, units);
-        }
-
-        printf("                     : desired [%"PRIu32"%s]\n",
-               cppc->desired,
-               cppc->desired ? "" : " hw autonomous");
-    }
+        print_cppc_para(cpuid, &p_cpufreq->u.cppc_para);
     else
     {
         if ( p_cpufreq->gov_num )
diff --git a/xen/drivers/acpi/pm-op.c b/xen/drivers/acpi/pm-op.c
index e616c3316a..acaa33561f 100644
--- a/xen/drivers/acpi/pm-op.c
+++ b/xen/drivers/acpi/pm-op.c
@@ -77,6 +77,17 @@ static int read_scaling_available_governors(char *scaling_available_governors,
     return 0;
 }
 
+static int get_cpufreq_cppc(unsigned int cpu,
+                            struct xen_get_cppc_para *cppc_para)
+{
+    int ret = -ENODEV;
+
+    if ( hwp_active() )
+        ret = get_hwp_para(cpu, cppc_para);
+
+    return ret;
+}
+
 static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
 {
     uint32_t ret = 0;
@@ -141,9 +152,8 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     else
         strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN);
 
-    if ( hwp_active() )
-        ret = get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para);
-    else
+    ret = get_cpufreq_cppc(op->cpuid, &op->u.get_para.u.cppc_para);
+    if ( ret == -ENODEV )
     {
         if ( !(scaling_available_governors =
                xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )
-- 
2.34.1
Re: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
Posted by Jan Beulich 3 months, 1 week ago
On 11.07.2025 05:51, Penny Zheng wrote:
> New helpers print_cppc_para() and get_cpufreq_cppc() are introduced to deal
> with CPPC-related parameters, in order to be re-used when later exporting new
> sub-op "get-cpufreq-cppc".
> 
> Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

I once again wonder whether this can go in right away, ahead of everything
that wants re-submitting.

Jan
RE: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
Posted by Penny, Zheng 2 months, 2 weeks ago
[Public]

> -----Original Message-----
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Wednesday, July 23, 2025 11:56 PM
> To: Penny, Zheng <penny.zheng@amd.com>
> Cc: Huang, Ray <Ray.Huang@amd.com>; Anthony PERARD
> <anthony.perard@vates.tech>; xen-devel@lists.xenproject.org
> Subject: Re: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-
> related parameters
>
> On 11.07.2025 05:51, Penny Zheng wrote:
> > New helpers print_cppc_para() and get_cpufreq_cppc() are introduced to
> > deal with CPPC-related parameters, in order to be re-used when later
> > exporting new sub-op "get-cpufreq-cppc".
> >
> > Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
>
> Acked-by: Jan Beulich <jbeulich@suse.com>
>
> I once again wonder whether this can go in right away, ahead of everything that
> wants re-submitting.

Thx, it could.

>
> Jan
RE: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
Posted by Penny, Zheng 2 months, 2 weeks ago
[Public]

> -----Original Message-----
> From: Penny, Zheng
> Sent: Tuesday, August 12, 2025 5:56 PM
> To: Jan Beulich <jbeulich@suse.com>
> Cc: Huang, Ray <Ray.Huang@amd.com>; Anthony PERARD
> <anthony.perard@vates.tech>; xen-devel@lists.xenproject.org
> Subject: RE: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-
> related parameters
>
>
>
> > -----Original Message-----
> > From: Jan Beulich <jbeulich@suse.com>
> > Sent: Wednesday, July 23, 2025 11:56 PM
> > To: Penny, Zheng <penny.zheng@amd.com>
> > Cc: Huang, Ray <Ray.Huang@amd.com>; Anthony PERARD
> > <anthony.perard@vates.tech>; xen-devel@lists.xenproject.org
> > Subject: Re: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal
> > with CPPC- related parameters
> >
> > On 11.07.2025 05:51, Penny Zheng wrote:
> > > New helpers print_cppc_para() and get_cpufreq_cppc() are introduced
> > > to deal with CPPC-related parameters, in order to be re-used when
> > > later exporting new sub-op "get-cpufreq-cppc".
> > >
> > > Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
> >
> > Acked-by: Jan Beulich <jbeulich@suse.com>
> >
> > I once again wonder whether this can go in right away, ahead of
> > everything that wants re-submitting.
>
> Thx, it could.
>

Sorry, I just read the next commit review. This commit may still be needed, but the commit message needs rewording, as no new sub-cmd "get-cpufreq-cppc" will be introduced.

> >
> > Jan