Skip to contentSkip to conversation

amd-cppc CPU Performance Scaling Driver

PATCH Superseded Penny Zheng 3 participants 77 messages May 27, 2025 – Jul 8, 2025

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v5 cover amd-cppc CPU Performance Scaling Driver

amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism on modern AMD APU and CPU series in Xen. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which provides finer grain frequency management than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.

amd_cppc driver has 2 operation modes: autonomous (active) mode, and non-autonomous (passive) mode. We register different CPUFreq driver for different modes, "amd-cppc" for passive mode and "amd-cppc-epp" for active mode.

The passive mode leverages common governors such as *ondemand*, *performance*, etc, to manage the performance tuning. While the active mode uses epp to provides a hint to the hardware if software wants to bias toward performance (0x0) or energy efficiency (0xff). CPPC power algorithm in hardware will automatically calculate the runtime workload and adjust the realtime cpu cores frequency according to the power supply and thermal, core voltage and some other hardware conditions.

amd-cppc is enabled on passive mode with a top-level cpufreq=amd-cppc option, while users add extra active flag to select active mode.

With cpufreq=amd-cppc,active, we did a 60s sampling test to see the CPU frequency change, through tweaking the energy_perf preference from xenpm set-cpufreq-cppc powersave to xenpm set-cpufreq-cppc performance. The outputs are as follows:
```
Setting CPU in powersave mode
Sampling and Outputs:

  Avg freq      580000 KHz
  Avg freq      580000 KHz
  Avg freq      580000 KHz
Setting CPU in performance mode
Sampling and Outputs:
  Avg freq      4640000 KHz
  Avg freq      4220000 KHz
  Avg freq      4640000 KHz

Penny Zheng (18):
xen/cpufreq: guard perf.states[] access with XEN_PX_INIT xen/cpufreq: move "init" flag into common structure xen/cpufreq: extract _PSD info from "struct xen_processor_performance" xen/cpufreq: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/cpufreq: introduce "cpufreq=amd-cppc" xen cmdline xen/cpufreq: disable px statistic info in amd-cppc mode xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs xen/amd: introduce amd_process_freq() to get processor frequency xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling xen/cpufreq: implement EPP support for the amd-cppc driver in active
mode
xen/cpufreq: get performance policy from governor set via xenpm xen/cpufreq: normalize hwp driver check with hwp_active() xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd xen/cpufreq: bypass governor-related para for amd-cppc-epp
tools: drop "has_num" condition check for cppc mode
tools: optimize cpufreq average freq print
xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver

 docs/misc/xen-command-line.pandoc         |  15 +-
 tools/include/xenctrl.h                   |   3 +-
 tools/libs/ctrl/xc_pm.c                   |  71 ++-
 tools/misc/xenpm.c                        | 121 ++--
 xen/arch/x86/acpi/cpufreq/Makefile        |   1 +
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 674 ++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       |  63 +-
 xen/arch/x86/cpu/amd.c                    |  83 ++-
 xen/arch/x86/include/asm/amd.h            |   2 +
 xen/arch/x86/include/asm/msr-index.h      |   6 +
 xen/arch/x86/platform_hypercall.c         |  18 +-
 xen/arch/x86/x86_64/cpufreq.c             |  19 +
 xen/arch/x86/x86_64/platform_hypercall.c  |   3 +
 xen/drivers/acpi/pmstat.c                 |  65 ++-
 xen/drivers/cpufreq/cpufreq.c             | 316 ++++++++--
 xen/drivers/cpufreq/utility.c             |  15 +
 xen/include/acpi/cpufreq/cpufreq.h        |  24 +-
 xen/include/acpi/cpufreq/processor_perf.h |  11 +-
 xen/include/public/platform.h             |  30 +
 xen/include/public/sysctl.h               |  10 +-
 xen/include/xen/pmstat.h                  |   5 +
 xen/include/xlat.lst                      |   1 +
 22 files changed, 1416 insertions(+), 140 deletions(-)
 create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/18 xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Accessing to perf.states[] array shall not be only guarded with user-defined hypercall input, so we add XEN_PX_INIT check to gain safety.

---
v4 -> v5:
- new commit

---
 xen/drivers/acpi/pmstat.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
xen/drivers/acpi/pmstat.c +7 -4
index c51b9ca358..b7fcc02db9 100644
@@ -228,10 +228,13 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    for ( i = 0; i < op->u.get_para.freq_num; i++ )
-        data[i] = pmpt->perf.states[i].core_frequency * 1000;
-    ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
-                         data, op->u.get_para.freq_num);
+    if ( pmpt->perf.init & XEN_PX_INIT )
+    {
+        for ( i = 0; i < op->u.get_para.freq_num; i++ )
+            data[i] = pmpt->perf.states[i].core_frequency * 1000;
+        ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
+                             data, op->u.get_para.freq_num);
+    }
 
     xfree(data);
     if ( ret )
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 2 lines · Penny Zheng

Accessing to perf.states[] array shall not be only guarded with user-defined hypercall input, so we add XEN_PX_INIT check to gain safety.

What is "guarded with user-defined hypercall input"? And what safety are we lacking?

Quoted 7 lines
xen/drivers/acpi/pmstat.c +0 -1
@@ -228,10 +228,13 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    for ( i = 0; i < op->u.get_para.freq_num; i++ )

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 237

Quoted 10 lines
xen/drivers/acpi/pmstat.c +7 -3
-        data[i] = pmpt->perf.states[i].core_frequency * 1000;
-    ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
-                         data, op->u.get_para.freq_num);
+    if ( pmpt->perf.init & XEN_PX_INIT )
+    {
+        for ( i = 0; i < op->u.get_para.freq_num; i++ )
+            data[i] = pmpt->perf.states[i].core_frequency * 1000;
+        ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
+                             data, op->u.get_para.freq_num);
+    }

Going from just the code change: You want to avoid copying out frequency values when none have been reported? But when none have been reported, isn't pmpt->perf.state_count (against which op->u.get_para.freq_num was validated) simply going to be 0? If not, how would callers know that no data was handed back to them?

Jan

#3 lore raw

RE: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

[Public]

Quoted 34 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:20 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 2 lines · Penny Zheng

Accessing to perf.states[] array shall not be only guarded with user-defined hypercall input, so we add XEN_PX_INIT check to gain safety.

What is "guarded with user-defined hypercall input"? And what safety are we lacking?

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op

Quoted 3 lines
xen/drivers/acpi/pmstat.c +0 -0
@@ -228,10 +228,13 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op

*op)

Quoted 4 lines
xen/drivers/acpi/pmstat.c +0 -1
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    for ( i = 0; i < op->u.get_para.freq_num; i++ )

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 237

Quoted 10 lines
xen/drivers/acpi/pmstat.c +7 -3
-        data[i] = pmpt->perf.states[i].core_frequency * 1000;
-    ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
-                         data, op->u.get_para.freq_num);
+    if ( pmpt->perf.init & XEN_PX_INIT )
+    {
+        for ( i = 0; i < op->u.get_para.freq_num; i++ )
+            data[i] = pmpt->perf.states[i].core_frequency * 1000;
+        ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
+                             data, op->u.get_para.freq_num);
+    }
Quoted 5 lines

Going from just the code change: You want to avoid copying out frequency values when none have been reported? But when none have been reported, isn't pmpt-

Quoted 1 line

perf.state_count (against which op->u.get_para.freq_num was

validated) simply going to be 0? If not, how would callers know that no data was handed back to them?

I may misunderstand what you've commented on v4 patch "tools/xenpm: Print CPPC parameters for amd-cppc driver", quoting the discussion there, "
This looks questionable all on its own. Where is it that ->perf.states allocation
is being avoided? I first thought it might be patch 06 which is related, but that
doesn't look to be it. In any event further down from here there is

    for ( i = 0; i < op->u.get_para.freq_num; i++ )
        data[i] = pmpt->perf.states[i].core_frequency * 1000;

i.e. an access to the array solely based on hypercall input.
"
I thought we were indicating a scenario, user accidentally writes the "op->u.get_para.freq_num ", and it leads to accessing out-of-range array slot in CPPC mode. That's the reason why I added this guard

Buit as you said at the very beginning, op->u.get_para.freq_num is validated against pmpt->perf.state_count, so ig the above scenario will not happen, I'll delete this commit.

Quoted 2 lines

Jan

#4 lore raw

Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 48 lines · Zheng

[Public]

Quoted 34 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:20 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 2 lines · Penny Zheng

Accessing to perf.states[] array shall not be only guarded with user-defined hypercall input, so we add XEN_PX_INIT check to gain safety.

What is "guarded with user-defined hypercall input"? And what safety are we lacking?

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op

Quoted 3 lines
xen/drivers/acpi/pmstat.c +0 -0
@@ -228,10 +228,13 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op

*op)

Quoted 4 lines
xen/drivers/acpi/pmstat.c +0 -1
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    for ( i = 0; i < op->u.get_para.freq_num; i++ )

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 237

Quoted 10 lines
xen/drivers/acpi/pmstat.c +7 -3
-        data[i] = pmpt->perf.states[i].core_frequency * 1000;
-    ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
-                         data, op->u.get_para.freq_num);
+    if ( pmpt->perf.init & XEN_PX_INIT )
+    {
+        for ( i = 0; i < op->u.get_para.freq_num; i++ )
+            data[i] = pmpt->perf.states[i].core_frequency * 1000;
+        ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
+                             data, op->u.get_para.freq_num);
+    }
Quoted 5 lines

Going from just the code change: You want to avoid copying out frequency values when none have been reported? But when none have been reported, isn't pmpt-

Quoted 1 line

perf.state_count (against which op->u.get_para.freq_num was

validated) simply going to be 0? If not, how would callers know that no data was handed back to them?

I may misunderstand what you've commented on v4 patch "tools/xenpm: Print CPPC parameters for amd-cppc driver", quoting the discussion there, "
This looks questionable all on its own. Where is it that ->perf.states allocation
is being avoided? I first thought it might be patch 06 which is related, but that
doesn't look to be it. In any event further down from here there is

Quoted 6 lines
    for ( i = 0; i < op->u.get_para.freq_num; i++ )
        data[i] = pmpt->perf.states[i].core_frequency * 1000;

i.e. an access to the array solely based on hypercall input.
"
I thought we were indicating a scenario, user accidentally writes the "op->u.get_para.freq_num ", and it leads to accessing out-of-range array slot in CPPC mode. That's the reason why I added this guard

Well, it's not an out-of-range access, but a NULL deref, but yes, the concern voiced there is related. But that can't be done in an isolated patch, it makes sense only together with the change to the if() that I did comment on. And even then if it is guaranteed that perf.state_count is always 0 when perf.states is NULL, we'd be fine without any change. Yet this latter aspect goes back to the question I had raised
there: "Where is it that ->perf.states allocation is being avoided?"

Quoted 1 line

Buit as you said at the very beginning, op->u.get_para.freq_num is validated against pmpt->perf.state_count, so ig the above scenario will not happen, I'll delete this commit.

Not sure yet whether deleting is the right course of action.

Jan

#5 lore raw

RE: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

[Public]

Quoted 69 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, June 16, 2025 5:16 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 51 lines · Zheng

[Public]

Quoted 35 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:20 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 01/18] xen/pmstat: guard perf.states[] access with XEN_PX_INIT

Quoted 2 lines · Penny Zheng

Accessing to perf.states[] array shall not be only guarded with user-defined hypercall input, so we add XEN_PX_INIT check to gain safety.

What is "guarded with user-defined hypercall input"? And what safety are we lacking?

Quoted 4 lines
xen/drivers/acpi/pmstat.c +0 -0
@@ -228,10 +228,13 @@ static int get_cpufreq_para(struct

xen_sysctl_pm_op

*op)

Quoted 4 lines
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
xen/drivers/acpi/pmstat.c +0 -1
-    for ( i = 0; i < op->u.get_para.freq_num; i++ )

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 237

Quoted 10 lines
xen/drivers/acpi/pmstat.c +7 -3
-        data[i] = pmpt->perf.states[i].core_frequency * 1000;
-    ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
-                         data, op->u.get_para.freq_num);
+    if ( pmpt->perf.init & XEN_PX_INIT )
+    {
+        for ( i = 0; i < op->u.get_para.freq_num; i++ )
+            data[i] = pmpt->perf.states[i].core_frequency * 1000;
+        ret += copy_to_guest(op->u.get_para.scaling_available_frequencies,
+                             data, op->u.get_para.freq_num);
+    }
Quoted 6 lines

Going from just the code change: You want to avoid copying out frequency values when none have been reported? But when none have been reported, isn't pmpt-

Quoted 1 line

perf.state_count (against which op->u.get_para.freq_num was

validated) simply going to be 0? If not, how would callers know that no data was handed back to them?

I may misunderstand what you've commented on v4 patch "tools/xenpm:
Print CPPC parameters for amd-cppc driver", quoting the discussion there, " This looks questionable all on its own. Where is it that ->perf.states allocation is being avoided? I first thought it might be patch 06 which is related, but that doesn't look to be it. In any event further down from here there is

Quoted 8 lines
    for ( i = 0; i < op->u.get_para.freq_num; i++ )
        data[i] = pmpt->perf.states[i].core_frequency * 1000;

i.e. an access to the array solely based on hypercall input. "
I thought we were indicating a scenario, user accidentally writes the "op->u.get_para.freq_num ", and it leads to accessing out-of-range array slot in CPPC mode. That's the reason why I added this guard

Quoted 7 lines

Well, it's not an out-of-range access, but a NULL deref, but yes, the concern voiced there is related. But that can't be done in an isolated patch, it makes sense only together with the change to the if() that I did comment on. And even then if it is guaranteed that perf.state_count is always 0 when perf.states is NULL, we'd be fine without any change. Yet this latter aspect goes back to the question I had raised
there: "Where is it that ->perf.states allocation is being avoided?"

->perf.states is allocated in set_px_pminfo(), which is a px-specific function.
In the caller of set_px_pminfo(), we have assertion "ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC));" to ensure it will not be invoked in CPPC mode.

Answering" And even then if it is guaranteed that perf.state_count is always 0 when perf.states is NULL", maybe we shall add another check in the very beginning of get_cpufreq_para():

```
if ( !pmpt || ((pmpt->init & XEN_PX_INIT) && !pmpt->perf.states) || ((pmpt->init & XEN_CPPC_INIT) && pmpt->perf.state_count))
```

We are ensuring in CPPC mode, ->perf.state_count must be zero, then op->u.get_para.freq_num is validated against it, we will never enter into the loop...

And if we're okay with above change, right, it shall not be done in an isolated patch, and it shall be added only together with the change to the if()

Quoted 7 lines
Quoted 1 line

Buit as you said at the very beginning, op->u.get_para.freq_num is validated

against pmpt->perf.state_count, so ig the above scenario will not happen, I'll delete this commit.

Not sure yet whether deleting is the right course of action.

Jan

#6 lore raw

PATCH v5 2/18 xen/cpufreq: move "init" flag into common structure

In reply to Penny Zheng

AMD cpufreq cores will be intialized in two modes, legacy P-state mode, and CPPC mode. So "init" flag shall be extracted from px-specific "struct xen_processor_perf", and placed in the common
"struct processor_pminfo". Otherwise, later when introducing a new sub-hypercall to propagate CPPC data, we need to pass irrelevant px-specific "struct xen_processor_perf" to just set init flag.

---
v3 -> v4:
- new commit
---
v4 -> v5:
- commit message refactor

---
 xen/drivers/acpi/pmstat.c                 | 6 +++---
 xen/drivers/cpufreq/cpufreq.c             | 8 ++++----
 xen/include/acpi/cpufreq/processor_perf.h | 4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
xen/drivers/acpi/pmstat.c +3 -3
index b7fcc02db9..6a1a900f78 100644
@@ -68,7 +68,7 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)
             return -ENODEV;
         if ( hwp_active() )
             return -EOPNOTSUPP;
-        if ( !pmpt || !(pmpt->perf.init & XEN_PX_INIT) )
+        if ( !pmpt || !(pmpt->init & XEN_PX_INIT) )
             return -EINVAL;
         break;
     default:
@@ -228,7 +228,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    if ( pmpt->perf.init & XEN_PX_INIT )
+    if ( pmpt->init & XEN_PX_INIT )
     {
         for ( i = 0; i < op->u.get_para.freq_num; i++ )
             data[i] = pmpt->perf.states[i].core_frequency * 1000;
@@ -466,7 +466,7 @@ int do_pm_op(struct xen_sysctl_pm_op *op)
     case CPUFREQ_PARA:
         if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
             return -ENODEV;
-        if ( !pmpt || !(pmpt->perf.init & XEN_PX_INIT) )
+        if ( !pmpt || !(pmpt->init & XEN_PX_INIT) )
             return -EINVAL;
         break;
     }
xen/drivers/cpufreq/cpufreq.c +4 -4
index 19e2992335..08d027317c 100644
@@ -209,7 +209,7 @@ int cpufreq_add_cpu(unsigned int cpu)
 
     perf = &processor_pminfo[cpu]->perf;
 
-    if ( !(perf->init & XEN_PX_INIT) )
+    if ( !(processor_pminfo[cpu]->init & XEN_PX_INIT) )
         return -EINVAL;
 
     if (!cpufreq_driver.init)
@@ -373,7 +373,7 @@ int cpufreq_del_cpu(unsigned int cpu)
 
     perf = &processor_pminfo[cpu]->perf;
 
-    if ( !(perf->init & XEN_PX_INIT) )
+    if ( !(processor_pminfo[cpu]->init & XEN_PX_INIT) )
         return -EINVAL;
 
     if (!per_cpu(cpufreq_cpu_policy, cpu))
@@ -569,7 +569,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
         if ( cpufreq_verbose )
             print_PPC(pxpt->platform_limit);
 
-        if ( pxpt->init == XEN_PX_INIT )
+        if ( pmpt->init == XEN_PX_INIT )
         {
             ret = cpufreq_limit_change(cpu);
             goto out;
@@ -578,7 +578,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 
     if ( perf->flags == ( XEN_PX_PCT | XEN_PX_PSS | XEN_PX_PSD | XEN_PX_PPC ) )
     {
-        pxpt->init = XEN_PX_INIT;
+        pmpt->init = XEN_PX_INIT;
 
         ret = cpufreq_cpu_init(cpu);
         goto out;
xen/include/acpi/cpufreq/processor_perf.h +2 -2
index 301104e16f..5f2612b15a 100644
@@ -29,14 +29,14 @@ struct processor_performance {
     struct xen_processor_px *states;
     struct xen_psd_package domain_info;
     uint32_t shared_type;
-
-    uint32_t init;
 };
 
 struct processor_pminfo {
     uint32_t acpi_id;
     uint32_t id;
     struct processor_performance    perf;
+
+    uint32_t init;
 };
 
 extern struct processor_pminfo *processor_pminfo[NR_CPUS];
Signature · 1 line
2.34.1
Acked-by on v5 2/18
#7 lore raw

Re: [PATCH v5 02/18] xen/cpufreq: move "init" flag into common structure

Quoted 8 lines · Penny Zheng

AMD cpufreq cores will be intialized in two modes, legacy P-state mode, and CPPC mode. So "init" flag shall be extracted from px-specific "struct xen_processor_perf", and placed in the common
"struct processor_pminfo". Otherwise, later when introducing a new sub-hypercall to propagate CPPC data, we need to pass irrelevant px-specific "struct xen_processor_perf" to just set init flag.

I'd be happy to put this in right away, but aiui ...

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 234

Quoted 9 lines
xen/drivers/acpi/pmstat.c +1 -1
@@ -228,7 +228,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     ret = copy_to_guest(op->u.get_para.affected_cpus,
                         data, op->u.get_para.cpu_num);
 
-    if ( pmpt->perf.init & XEN_PX_INIT )
+    if ( pmpt->init & XEN_PX_INIT )
     {
         for ( i = 0; i < op->u.get_para.freq_num; i++ )
             data[i] = pmpt->perf.states[i].core_frequency * 1000;

... this hunk needs dropping then, as the modified code is only introduced by patch 1. Which raises the question why you didn't order the patches the other way around, avoiding to immediately need to touch the same (new) code again. Please clarify.

Jan

#8 lore raw

PATCH v5 3/18 xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

In reply to Penny Zheng

_PSD info, consisted of "shared_type" and "struct xen_psd_package", will not only be provided from px-specific "struct xen_processor_performance", but also in CPPC data.

In cpufreq_add/del_cpu(), a new helper get_psd_info() is introduced to extract common _PSD info from px-specific "struct xen_processor_performance", in the meantime, the following style corrections get applied at the same time:
- add extra space before and after bracket of if()
- remove redundant parenthesis
- no need to put brace for printk() at a seperate line

---
v3 -> v4:
- new commit
---
v4 -> v5:
- let check_psd_pminfo() pass in "uint32_t shared_type"
- replace unnessary parameter "uint32_t init" with processor_pminfo[cpu]->init
- replace structure copy with const pointer delivery through "const struct xen_psd_package **"
- blank line between non-fall-through switch-case blocks
- remove unnessary "define XEN_CPUPERF_SHARED_TYPE_xxx" movement

---
 xen/drivers/cpufreq/cpufreq.c | 111 ++++++++++++++++++++++++----------
 1 file changed, 79 insertions(+), 32 deletions(-)
xen/drivers/cpufreq/cpufreq.c +79 -32
index 08d027317c..9567221d97 100644
@@ -191,9 +191,29 @@ int cpufreq_limit_change(unsigned int cpu)
     return __cpufreq_set_policy(data, &policy);
 }
 
-int cpufreq_add_cpu(unsigned int cpu)
+static int get_psd_info(unsigned int cpu, uint32_t *shared_type,
+                        const struct xen_psd_package **domain_info_ptr)
 {
     int ret = 0;
+
+    switch ( processor_pminfo[cpu]->init )
+    {
+    case XEN_PX_INIT:
+        *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        *domain_info_ptr = &processor_pminfo[cpu]->perf.domain_info;
+        break;
+
+    default:
+        ret = -EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
+int cpufreq_add_cpu(unsigned int cpu)
+{
+    int ret;
     unsigned int firstcpu;
     unsigned int dom, domexist = 0;
     unsigned int hw_all = 0;
@@ -201,14 +221,14 @@ int cpufreq_add_cpu(unsigned int cpu)
     struct cpufreq_dom *cpufreq_dom = NULL;
     struct cpufreq_policy new_policy;
     struct cpufreq_policy *policy;
-    struct processor_performance *perf;
+    const struct xen_psd_package *domain_info;
+    const struct xen_psd_package **domain_info_ptr = &domain_info;
+    uint32_t shared_type;
 
     /* to protect the case when Px was not controlled by xen */
     if ( !processor_pminfo[cpu] || !cpu_online(cpu) )
         return -EINVAL;
 
-    perf = &processor_pminfo[cpu]->perf;
-
     if ( !(processor_pminfo[cpu]->init & XEN_PX_INIT) )
         return -EINVAL;
 
@@ -218,10 +238,15 @@ int cpufreq_add_cpu(unsigned int cpu)
     if (per_cpu(cpufreq_cpu_policy, cpu))
         return 0;
 
-    if (perf->shared_type == CPUFREQ_SHARED_TYPE_HW)
+    ret = get_psd_info(cpu, &shared_type, domain_info_ptr);
+    if ( ret )
+        return ret;
+    domain_info = *domain_info_ptr;
+
+    if ( shared_type == CPUFREQ_SHARED_TYPE_HW )
         hw_all = 1;
 
-    dom = perf->domain_info.domain;
+    dom = domain_info->domain;
 
     list_for_each(pos, &cpufreq_dom_list_head) {
         cpufreq_dom = list_entry(pos, struct cpufreq_dom, node);
@@ -244,21 +269,30 @@ int cpufreq_add_cpu(unsigned int cpu)
         cpufreq_dom->dom = dom;
         list_add(&cpufreq_dom->node, &cpufreq_dom_list_head);
     } else {
+        uint32_t firstcpu_shared_type;
+        const struct xen_psd_package *firstcpu_domain_info;
+        const struct xen_psd_package **firstcpu_domain_info_ptr =
+                                                        &firstcpu_domain_info;
+
         /* domain sanity check under whatever coordination type */
         firstcpu = cpumask_first(cpufreq_dom->map);
-        if ((perf->domain_info.coord_type !=
-            processor_pminfo[firstcpu]->perf.domain_info.coord_type) ||
-            (perf->domain_info.num_processors !=
-            processor_pminfo[firstcpu]->perf.domain_info.num_processors)) {
-
+        ret = get_psd_info(firstcpu, &firstcpu_shared_type,
+                           firstcpu_domain_info_ptr);
+        if ( ret )
+            return ret;
+        firstcpu_domain_info = *firstcpu_domain_info_ptr;
+
+        if ( domain_info->coord_type != firstcpu_domain_info->coord_type ||
+             domain_info->num_processors !=
+             firstcpu_domain_info->num_processors )
+        {
             printk(KERN_WARNING "cpufreq fail to add CPU%d:"
                    "incorrect _PSD(%"PRIu64":%"PRIu64"), "
                    "expect(%"PRIu64"/%"PRIu64")\n",
-                   cpu, perf->domain_info.coord_type,
-                   perf->domain_info.num_processors,
-                   processor_pminfo[firstcpu]->perf.domain_info.coord_type,
-                   processor_pminfo[firstcpu]->perf.domain_info.num_processors
-                );
+                   cpu, domain_info->coord_type,
+                   domain_info->num_processors,
+                   firstcpu_domain_info->coord_type,
+                   firstcpu_domain_info->num_processors);
             return -EINVAL;
         }
     }
@@ -304,8 +338,9 @@ int cpufreq_add_cpu(unsigned int cpu)
     if (ret)
         goto err1;
 
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors)) {
+    if ( hw_all || cpumask_weight(cpufreq_dom->map) ==
+                   domain_info->num_processors )
+    {
         memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
 
         /*
@@ -360,29 +395,35 @@ err0:
 
 int cpufreq_del_cpu(unsigned int cpu)
 {
+    int ret;
     unsigned int dom, domexist = 0;
     unsigned int hw_all = 0;
     struct list_head *pos;
     struct cpufreq_dom *cpufreq_dom = NULL;
     struct cpufreq_policy *policy;
-    struct processor_performance *perf;
+    uint32_t shared_type;
+    const struct xen_psd_package *domain_info;
+    const struct xen_psd_package **domain_info_ptr = &domain_info;
 
     /* to protect the case when Px was not controlled by xen */
     if ( !processor_pminfo[cpu] || !cpu_online(cpu) )
         return -EINVAL;
 
-    perf = &processor_pminfo[cpu]->perf;
-
     if ( !(processor_pminfo[cpu]->init & XEN_PX_INIT) )
         return -EINVAL;
 
     if (!per_cpu(cpufreq_cpu_policy, cpu))
         return 0;
 
-    if (perf->shared_type == CPUFREQ_SHARED_TYPE_HW)
+    ret = get_psd_info(cpu, &shared_type, domain_info_ptr);
+    if ( ret )
+        return ret;
+    domain_info = *domain_info_ptr;
+
+    if ( shared_type == CPUFREQ_SHARED_TYPE_HW )
         hw_all = 1;
 
-    dom = perf->domain_info.domain;
+    dom = domain_info->domain;
     policy = per_cpu(cpufreq_cpu_policy, cpu);
 
     list_for_each(pos, &cpufreq_dom_list_head) {
@@ -398,8 +439,8 @@ int cpufreq_del_cpu(unsigned int cpu)
 
     /* for HW_ALL, stop gov for each core of the _PSD domain */
     /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain */
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if ( hw_all || cpumask_weight(cpufreq_dom->map) ==
+                   domain_info->num_processors )
         __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
 
     cpufreq_statistic_exit(cpu);
@@ -464,6 +505,17 @@ static void print_PPC(unsigned int platform_limit)
     printk("\t_PPC: %d\n", platform_limit);
 }
 
+static int check_psd_pminfo(uint32_t shared_type)
+{
+    /* check domain coordination */
+    if ( shared_type != CPUFREQ_SHARED_TYPE_ALL &&
+         shared_type != CPUFREQ_SHARED_TYPE_ANY &&
+         shared_type != CPUFREQ_SHARED_TYPE_HW )
+        return -EINVAL;
+
+    return 0;
+}
+
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 {
     int ret = 0, cpu;
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

xen/drivers/cpufreq/cpufreq.c int cpufreq_add_cpu(unsigned int cpu) · line 225

Quoted 7 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +2 -1
@@ -201,14 +221,14 @@ int cpufreq_add_cpu(unsigned int cpu)
     struct cpufreq_dom *cpufreq_dom = NULL;
     struct cpufreq_policy new_policy;
     struct cpufreq_policy *policy;
-    struct processor_performance *perf;
+    const struct xen_psd_package *domain_info;
+    const struct xen_psd_package **domain_info_ptr = &domain_info;

Why's this latter variable needed? Can't you simply ...

Quoted 12 lines
xen/drivers/cpufreq/cpufreq.c +1 -2
+    uint32_t shared_type;
 
     /* to protect the case when Px was not controlled by xen */
     if ( !processor_pminfo[cpu] || !cpu_online(cpu) )
         return -EINVAL;
 
-    perf = &processor_pminfo[cpu]->perf;
-
     if ( !(processor_pminfo[cpu]->init & XEN_PX_INIT) )
         return -EINVAL;
 

xen/drivers/cpufreq/cpufreq.c int cpufreq_add_cpu(unsigned int cpu) · line 241

Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +1 -1
@@ -218,10 +238,15 @@ int cpufreq_add_cpu(unsigned int cpu)
     if (per_cpu(cpufreq_cpu_policy, cpu))
         return 0;
 
-    if (perf->shared_type == CPUFREQ_SHARED_TYPE_HW)
+    ret = get_psd_info(cpu, &shared_type, domain_info_ptr);

... pass &domain_info here, ...

xen/drivers/cpufreq/cpufreq.c int cpufreq_add_cpu(unsigned int cpu) · line 244

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
+    if ( ret )
+        return ret;
+    domain_info = *domain_info_ptr;

... also eliminating the need for this assignment? (Same again further down.)

xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 510

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
@@ -464,6 +505,17 @@ static void print_PPC(unsigned int platform_limit)
     printk("\t_PPC: %d\n", platform_limit);
 }
 
+static int check_psd_pminfo(uint32_t shared_type)
+{
+    /* check domain coordination */

Nit: Comment style (wants to start with a capital letter). Yes, there are many bad examples in this file (some even visible in patch context here), but in new code style guidelines should be followed.

xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 517

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +7 -0
+    if ( shared_type != CPUFREQ_SHARED_TYPE_ALL &&
+         shared_type != CPUFREQ_SHARED_TYPE_ANY &&
+         shared_type != CPUFREQ_SHARED_TYPE_HW )
+        return -EINVAL;
+
+    return 0;
+}

Looks as if the function would rather want to return a boolean value.

And anyway - I can't really spot the need for this helper, as I also can't spot ...

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +0 -3
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&

xen/drivers/cpufreq/cpufreq.c int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf) · line 605

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +2 -4
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,

... the need for this change. And even if there is a need, a follow-on question would be how this relates to the subject of this patch.

Jan

#10 lore raw

RE: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:34 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +2 -7
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct
 xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
Quoted 6 lines
Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,

... the need for this change. And even if there is a need, a follow-on question would be how this relates to the subject of this patch.

I extracted this snippet out for sharing the same checking logic both in Px and later CPPC. They both need _PSD info I could change title to "xen/cpufreq: make _PSD info common" and also add description in commit message for introducing check_psd_pminfo()

Quoted 1 line

Jan

#11 lore raw

Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 27 lines · Zheng

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:34 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +2 -7
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct
 xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,

... the need for this change. And even if there is a need, a follow-on question would be how this relates to the subject of this patch.

I extracted this snippet out for sharing the same checking logic both in Px and later CPPC. They both need _PSD info

Right, and that (iirc) becomes visible later in the series. But it needs saying here. As it stands the description talks of only get_psd_info() right now. And the change above is also unrelated to the "extract" mentioned in the title.

Quoted 2 lines

I could change title to "xen/cpufreq: make _PSD info common" and also add description in commit message for introducing check_psd_pminfo()

The title was probably fine; it's the description which was lacking. In fact I'd deem "make ... common" misleading when there's no 2nd user (yet).

Jan

#12 lore raw

RE: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

[Public]

Quoted 49 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, June 16, 2025 5:51 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 27 lines · Zheng

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:34 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +2 -7
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct
 xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,

... the need for this change. And even if there is a need, a follow-on question would be how this relates to the subject of this patch.

I extracted this snippet out for sharing the same checking logic both in Px and later CPPC. They both need _PSD info

Right, and that (iirc) becomes visible later in the series. But it needs saying here. As it stands the description talks of only get_psd_info() right now. And the change above is also unrelated to the "extract" mentioned in the title.

Quoted 6 lines
Quoted 2 lines

I could change title to "xen/cpufreq: make _PSD info common" and also add description in commit message for introducing check_psd_pminfo()

The title was probably fine; it's the description which was lacking. In fact I'd deem "make ... common" misleading when there's no 2nd user (yet).

How about:
"
Title: xen/cpufreq: export _PSD info and checking

_PSD info, consisted of "shared_type" and "struct xen_psd_package", will not only be provided from px-specific "struct xen_processor_performance", but also in CPPC data.

In cpufreq_add/del_cpu(), a new helper get_psd_info() is introduced to export _PSD info. While in set_px_pminfo(), check_psd_pminfo() is also introduced to export _PSD value checking.
in the meantime, the following style corrections get applied at the same time: ........ ```

Quoted 1 line

Jan

#13 lore raw

Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 54 lines · Zheng

[Public]

Quoted 52 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, June 16, 2025 5:51 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 27 lines · Zheng

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, June 11, 2025 11:34 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 03/18] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +2 -7
@@ -545,14 +597,9 @@ int set_px_pminfo(uint32_t acpi_id, struct
 xen_processor_performance *perf)
 
     if ( perf->flags & XEN_PX_PSD )
     {
-        /* check domain coordination */
-        if ( perf->shared_type != CPUFREQ_SHARED_TYPE_ALL &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_ANY &&
-             perf->shared_type != CPUFREQ_SHARED_TYPE_HW )
-        {
-            ret = -EINVAL;
+        ret = check_psd_pminfo(perf->shared_type);
+        if ( ret )
             goto out;
-        }
 
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,

... the need for this change. And even if there is a need, a follow-on question would be how this relates to the subject of this patch.

I extracted this snippet out for sharing the same checking logic both in Px and later CPPC. They both need _PSD info

Right, and that (iirc) becomes visible later in the series. But it needs saying here. As it stands the description talks of only get_psd_info() right now. And the change above is also unrelated to the "extract" mentioned in the title.

Quoted 2 lines

I could change title to "xen/cpufreq: make _PSD info common" and also add description in commit message for introducing check_psd_pminfo()

Quoted 7 lines
Quoted 3 lines

The title was probably fine; it's the description which was lacking. In fact I'd deem "make ... common" misleading when there's no 2nd user (yet).

How about:
"
Title: xen/cpufreq: export _PSD info and checking

As said, the original title was probably fine. In the new title (and also in the text suggested below), I wonder what "export" means.

Quoted 7 lines

_PSD info, consisted of "shared_type" and "struct xen_psd_package", will not only be provided from px-specific "struct xen_processor_performance", but also in CPPC data.

In cpufreq_add/del_cpu(), a new helper get_psd_info() is introduced to export _PSD info. While in set_px_pminfo(), check_psd_pminfo() is also introduced to export _PSD value checking.

How about "Two new helper functions are introduced to deal with _PSD. They will later be re-used for handling the same data for CPPC."

Jan

Quoted 4 lines

in the meantime, the following style corrections get applied at the same time: ........ ```

Quoted 1 line

Jan

#14 lore raw

PATCH v5 4/18 xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

In reply to Penny Zheng

In order to provide backward compatibility with existing governors that represent performance as frequency, like ondemand, the _CPC table can optionally provide processor frequency range values, Lowest frequency and Nominal frequency, to let OS use Lowest Frequency/ Performance and Nominal Frequency/Performance as anchor points to create linear mapping of CPU frequency to CPPC performance.

As Xen is uncapable of parsing the ACPI dynamic table, we'd like to introduce a new sub-hypercall "XEN_PM_CPPC" to propagate required CPPC data from dom0 kernel to Xen.
In the according handler set_cppc_pminfo(), we do _CPC and _PSD sanitization check, as both _PSD and _CPC info are necessary for correctly initializing cpufreq cores in CPPC mode.
Users shall be warned that if we failed at this point,
no fallback scheme, like legacy P-state could be switched to.

A new flag "XEN_CPPC_INIT" is also introduced to differentiate cpufreq core initialised in Px mode. Then all .init flag checking shall be updated to consider "XEN_CPPC_INIT" too.

---
v1 -> v2:
- Remove unnecessary figure braces
- Pointer-to-const for print_CPPC and set_cppc_pminfo
- Structure allocation shall use xvzalloc()
- Unnecessary memcpy(), and change it to a (type safe) structure assignment
- Add comment for struct xen_processor_cppc, and keep the chosen fields in the order _CPC has them
- Obey to alphabetic sorting, and prefix compat structures with ? instead of !
---
v2 -> v3:
- Trim too long line
- Re-place set_cppc_pminfo() past set_px_pminfo()
- Fix Misra violations: Declaration and definition ought to agree in parameter names
- Introduce a new flag XEN_PM_CPPC to reflect processor initialised in CPPC mode
---
v3 -> v4:
- Refactor commit message
- make "acpi_id" unsigned int
- Add warning message when cpufreq_cpu_init() failed only under debug mode
- Expand "struct xen_processor_cppc" to include _PSD and shared type
- add sanity check for ACPI CPPC data
---
v4 -> v5:
- remove the ordering check between lowest_nonlinear_perf and lowest_perf
- use printk_once() for cppc perf value warning
- complement comment for cppc perf value check
- remove redundant check and pointless parenthesizing
- use dprintk() for warning under #ifndef NDEBUG
- refactor warning message when having non-zero ret of cpufreq_cpu_init()
- With introduction of "struct xen_psd_package" in "struct xen_processor_cppc", use ! and the respective XLAT_* macro(s) to wrap.

---
 xen/arch/x86/platform_hypercall.c         |   5 +
 xen/arch/x86/x86_64/cpufreq.c             |  19 ++++
 xen/arch/x86/x86_64/platform_hypercall.c  |   3 +
 xen/drivers/acpi/pmstat.c                 |   4 +-
 xen/drivers/cpufreq/cpufreq.c             | 128 +++++++++++++++++++++-
 xen/include/acpi/cpufreq/processor_perf.h |   4 +-
 xen/include/public/platform.h             |  30 +++++
 xen/include/xen/pmstat.h                  |   5 +
 xen/include/xlat.lst                      |   1 +
 9 files changed, 194 insertions(+), 5 deletions(-)
xen/arch/x86/platform_hypercall.c +5 -0
index 90abd3197f..49717e9ca9 100644
@@ -572,6 +572,11 @@ ret_t do_platform_op(
             break;
         }
 
+        case XEN_PM_CPPC:
+            ret = set_cppc_pminfo(op->u.set_pminfo.id,
+                                  &op->u.set_pminfo.u.cppc_data);
+            break;
+
         default:
             ret = -EINVAL;
             break;
xen/arch/x86/x86_64/cpufreq.c +19 -0
index e4f3d5b436..8d57f67c2e 100644
@@ -54,3 +54,22 @@ int compat_set_px_pminfo(uint32_t acpi_id,
 
     return set_px_pminfo(acpi_id, xen_perf);
 }
+
+int compat_set_cppc_pminfo(unsigned int acpi_id,
+                           const struct compat_processor_cppc *cppc_data)
+
+{
+    struct xen_processor_cppc *xen_cppc;
+    unsigned long xlat_page_current;
+
+    xlat_malloc_init(xlat_page_current);
+
+    xen_cppc = xlat_malloc_array(xlat_page_current,
+                                 struct xen_processor_cppc, 1);
+    if ( unlikely(xen_cppc == NULL) )
+        return -EFAULT;
+
+    XLAT_processor_cppc(xen_cppc, cppc_data);
+
+    return set_cppc_pminfo(acpi_id, xen_cppc);
+}
xen/arch/x86/x86_64/platform_hypercall.c +3 -0
index 9ab631c17f..0288f68df9 100644
@@ -14,6 +14,9 @@ EMIT_FILE;
 #define efi_get_info        efi_compat_get_info
 #define efi_runtime_call(x) efi_compat_runtime_call(x)
 
+#define xen_processor_cppc  compat_processor_cppc
+#define set_cppc_pminfo     compat_set_cppc_pminfo
+
 #define xen_processor_performance compat_processor_performance
 #define set_px_pminfo       compat_set_px_pminfo
 
xen/drivers/acpi/pmstat.c +2 -2
index 6a1a900f78..f7351f219d 100644
@@ -201,7 +201,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     pmpt = processor_pminfo[op->cpuid];
     policy = per_cpu(cpufreq_cpu_policy, op->cpuid);
 
-    if ( !pmpt || !pmpt->perf.states ||
+    if ( !pmpt || ((pmpt->init & XEN_PX_INIT) && !pmpt->perf.states) ||
          !policy || !policy->governor )
         return -EINVAL;
 
@@ -466,7 +466,7 @@ int do_pm_op(struct xen_sysctl_pm_op *op)
     case CPUFREQ_PARA:
         if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
             return -ENODEV;
-        if ( !pmpt || !(pmpt->init & XEN_PX_INIT) )
+        if ( !pmpt || !(pmpt->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
             return -EINVAL;
         break;
     }
xen/drivers/cpufreq/cpufreq.c +126 -2

158 lines not on this page · raw message

xen/include/acpi/cpufreq/processor_perf.h +3 -1
index 5f2612b15a..f1f4f3138d 100644
@@ -5,7 +5,8 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
-#define XEN_PX_INIT 0x80000000U
+#define XEN_CPPC_INIT 0x40000000U
+#define XEN_PX_INIT   0x80000000U
 
 unsigned int powernow_register_driver(void);
 unsigned int get_measured_perf(unsigned int cpu, unsigned int flag);
@@ -35,6 +36,7 @@ struct processor_pminfo {
     uint32_t acpi_id;
     uint32_t id;
     struct processor_performance    perf;
+    struct xen_processor_cppc cppc_data;
 
     uint32_t init;
 };
xen/include/public/platform.h +30 -0
index 2725b8d104..0bf7543fff 100644
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
 #define XEN_PM_PX   1
 #define XEN_PM_TX   2
 #define XEN_PM_PDC  3
+#define XEN_PM_CPPC 4
 
 /* Px sub info type */
 #define XEN_PX_PCT   1
@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
 #define XEN_PX_PPC   4
 #define XEN_PX_PSD   8
 
+/* CPPC sub info type */
+#define XEN_CPPC_PSD   1
+#define XEN_CPPC_CPC   2
+
 struct xen_power_register {
     uint32_t     space_id;
     uint32_t     bit_width;
@@ -457,6 +462,30 @@ struct xen_processor_performance {
 typedef struct xen_processor_performance xen_processor_performance_t;
 DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);
 
+struct xen_processor_cppc {
+    uint8_t flags; /* flag for CPPC sub info type */
+    uint8_t pad[3]; /* padding and must be zero */
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization
+     */
+    struct {
+        uint32_t highest_perf;
+        uint32_t nominal_perf;
+        uint32_t lowest_nonlinear_perf;
+        uint32_t lowest_perf;
+        uint32_t lowest_mhz;
+        uint32_t nominal_mhz;
+    } cpc;
+    /* Coordination type of this processor */
+#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed coordination */
+#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs should set freq */
+#define XEN_CPUPERF_SHARED_TYPE_ANY  3 /* Freq can be set from any dependent CPU */
+    uint32_t shared_type;
+    struct xen_psd_package domain_info; /* _PSD */
+};
+typedef struct xen_processor_cppc xen_processor_cppc_t;
+
 struct xenpf_set_processor_pminfo {
     /* IN variables */
     uint32_t id;    /* ACPI CPU ID */
@@ -465,6 +494,7 @@ struct xenpf_set_processor_pminfo {
         struct xen_processor_power          power;/* Cx: _CST/_CSD */
         struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS/_PSD */
         XEN_GUEST_HANDLE(uint32)            pdc;  /* _PDC */
+        xen_processor_cppc_t                cppc_data; /* _CPC and _PSD */
     } u;
 };
 typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t;
xen/include/xen/pmstat.h +5 -0
index 8350403e95..1f21f43a13 100644
@@ -7,8 +7,13 @@
 
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf);
 long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power);
+int set_cppc_pminfo(unsigned int acpi_id,
+                    const struct xen_processor_cppc *cppc_data);
 
 #ifdef CONFIG_COMPAT
+struct compat_processor_cppc;
+int compat_set_cppc_pminfo(unsigned int acpi_id,
+                           const struct compat_processor_cppc *cppc_data);
 struct compat_processor_performance;
 int compat_set_px_pminfo(uint32_t acpi_id, struct compat_processor_performance *perf);
 struct compat_processor_power;
xen/include/xlat.lst +1 -0
index 3c7b6c6830..a800671f2f 100644
@@ -168,6 +168,7 @@
 !	processor_performance		platform.h
 !	processor_power			platform.h
 ?	processor_px			platform.h
+!	processor_cppc			platform.h
 !	psd_package			platform.h
 ?	xenpf_enter_acpi_sleep		platform.h
 ?	xenpf_pcpu_version		platform.h
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

Quoted 12 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +8 -0
@@ -635,6 +641,124 @@ out:
     return ret;
 }
 
+static void print_CPPC(const struct xen_processor_cppc *cppc_data)
+{
+    printk("\t_CPC: highest_perf=%u, lowest_perf=%u, "
+           "nominal_perf=%u, lowest_nonlinear_perf=%u, "
+           "nominal_mhz=%uMHz, lowest_mhz=%uMHz\n",
+           cppc_data->cpc.highest_perf, cppc_data->cpc.lowest_perf,
+           cppc_data->cpc.nominal_perf, cppc_data->cpc.lowest_nonlinear_perf,
+           cppc_data->cpc.nominal_mhz, cppc_data->cpc.lowest_mhz);

xen/drivers/cpufreq/cpufreq.c out: · line 661

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+}
+
+int set_cppc_pminfo(unsigned int acpi_id,
+                    const struct xen_processor_cppc *cppc_data)
+{
+    int ret = 0, cpuid;
+    struct processor_pminfo *pm_info;
+
+    cpuid = get_cpu_id(acpi_id);
+    if ( cpuid < 0 || !cppc_data )

The !cppc_data part isn't really needed, is it?

Quoted 84 lines
xen/drivers/cpufreq/cpufreq.c +84 -0
+    {
+        ret = -EINVAL;
+        goto out;
+    }
+
+    if ( cppc_data->pad[0] || cppc_data->pad[1] || cppc_data->pad[2] )
+    {
+        ret = -EINVAL;
+        goto out;
+    }
+
+    if ( cpufreq_verbose )
+        printk("Set CPU acpi_id(%u) cpuid(%d) CPPC State info:\n",
+               acpi_id, cpuid);
+
+    pm_info = processor_pminfo[cpuid];
+    if ( !pm_info )
+    {
+        pm_info = xvzalloc(struct processor_pminfo);
+        if ( !pm_info )
+        {
+            ret = -ENOMEM;
+            goto out;
+        }
+        processor_pminfo[cpuid] = pm_info;
+    }
+    pm_info->acpi_id = acpi_id;
+    pm_info->id = cpuid;
+    pm_info->cppc_data = *cppc_data;
+
+    if ( cppc_data->flags & XEN_CPPC_PSD )
+    {
+        ret = check_psd_pminfo(cppc_data->shared_type);
+        if ( ret )
+            goto out;
+    }
+
+    if ( cppc_data->flags & XEN_CPPC_CPC )
+    {
+        if ( cppc_data->cpc.highest_perf == 0 ||
+             cppc_data->cpc.highest_perf > UINT8_MAX ||
+             cppc_data->cpc.nominal_perf == 0 ||
+             cppc_data->cpc.nominal_perf > UINT8_MAX ||
+             cppc_data->cpc.lowest_nonlinear_perf == 0 ||
+             cppc_data->cpc.lowest_nonlinear_perf > UINT8_MAX ||
+             cppc_data->cpc.lowest_perf == 0 ||
+             cppc_data->cpc.lowest_perf > UINT8_MAX ||
+             cppc_data->cpc.lowest_perf >
+                cppc_data->cpc.nominal_perf ||
+             cppc_data->cpc.lowest_nonlinear_perf >
+                cppc_data->cpc.nominal_perf ||
+             cppc_data->cpc.nominal_perf > cppc_data->cpc.highest_perf )
+            /*
+             * Right now, Xen doesn't actually use highest_perf/nominal_perf/
+             * lowest_nonlinear_perf/lowest_perf values read from ACPI _CPC
+             * table. Xen reads CPPC capability MSR to get these four values.
+             * So warning is enough.
+             */
+            printk_once(XENLOG_WARNING
+                        "Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u), nominal(%u), highest(%u)\n",
+                        cppc_data->cpc.lowest_perf,
+                        cppc_data->cpc.lowest_nonlinear_perf,
+                        cppc_data->cpc.nominal_perf,
+                        cppc_data->cpc.highest_perf);
+
+        /* lowest_mhz and nominal_mhz are optional value */
+        if ( cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )
+        {
+            printk_once(XENLOG_WARNING
+                        "Broken CPPC freq values: lowest(%u), nominal(%u)\n",
+                        cppc_data->cpc.lowest_mhz,
+                        cppc_data->cpc.nominal_mhz);
+            /* Re-set with zero values, instead of keeping invalid values */
+            pm_info->cppc_data.cpc.nominal_mhz = 0;
+            pm_info->cppc_data.cpc.lowest_mhz = 0;
+        }
+    }
+
+    if ( cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC) )
+    {
+        if ( cpufreq_verbose )
+        {
+            print_PSD(&pm_info->cppc_data.domain_info);
+            print_CPPC(&pm_info->cppc_data);

xen/drivers/cpufreq/cpufreq.c out: · line 755

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+        }
+
+        pm_info->init = XEN_CPPC_INIT;
+        ret = cpufreq_cpu_init(cpuid);
+#ifndef NDEBUG
+        if ( ret )
+            dprintk(XENLOG_WARNING,
+                    "CPU %u failed to be initialized with amd-cppc mode, and users could only reboot and re-define cmdline with \"cpufreq=xen\"",
+                    cpuid);
+#endif

What use if the #ifdef here? The more that NDEBUG controls behavior of ASSERT(), not that of (debug) logging.

Quoted 22 lines
xen/include/public/platform.h +5 -0
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
 #define XEN_PM_PX   1
 #define XEN_PM_TX   2
 #define XEN_PM_PDC  3
+#define XEN_PM_CPPC 4
 
 /* Px sub info type */
 #define XEN_PX_PCT   1
@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
 #define XEN_PX_PPC   4
 #define XEN_PX_PSD   8
 
+/* CPPC sub info type */
+#define XEN_CPPC_PSD   1
+#define XEN_CPPC_CPC   2
+
 struct xen_power_register {
     uint32_t     space_id;
     uint32_t     bit_width;

xen/include/public/platform.h struct xen_processor_performance { · line 466

Quoted 5 lines
xen/include/public/platform.h +2 -0
@@ -457,6 +462,30 @@ struct xen_processor_performance {
 typedef struct xen_processor_performance xen_processor_performance_t;
 DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);
 
+struct xen_processor_cppc {
+    uint8_t flags; /* flag for CPPC sub info type */

A common way of commenting on such would be /* XEN_CPPC_... */.

In any event, here and ...

xen/include/public/platform.h struct xen_processor_performance { · line 467

Quoted 1 line
xen/include/public/platform.h +1 -0
+    uint8_t pad[3]; /* padding and must be zero */

... here (and of course anywhere else) - please adhere to designated comment style.

Quoted 6 lines
xen/include/public/platform.h +6 -0
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization
+     */
+    struct {
+        uint32_t highest_perf;

xen/include/public/platform.h struct xen_processor_performance { · line 483

Quoted 10 lines
xen/include/public/platform.h +10 -0
+        uint32_t nominal_perf;
+        uint32_t lowest_nonlinear_perf;
+        uint32_t lowest_perf;
+        uint32_t lowest_mhz;
+        uint32_t nominal_mhz;
+    } cpc;
+    /* Coordination type of this processor */
+#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed coordination */
+#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs should set freq */
+#define XEN_CPUPERF_SHARED_TYPE_ANY  3 /* Freq can be set from any dependent CPU */

What's this? The exact same #define-s already exist in struct xen_processor_performance, unless I'm missing a hard to notice spelling difference. You can simply ...

xen/include/public/platform.h struct xen_processor_performance { · line 484

Quoted 1 line
xen/include/public/platform.h +1 -0
+    uint32_t shared_type;

... use the comment suggestion from above here as well.

xen/include/xen/pmstat.h line 11

Quoted 8 lines
xen/include/xen/pmstat.h +2 -0
@@ -7,8 +7,13 @@
 
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf);
 long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power);
+int set_cppc_pminfo(unsigned int acpi_id,
+                    const struct xen_processor_cppc *cppc_data);

Nit: Relative ordering would be nice to be consistent between this group and ...

xen/include/xen/pmstat.h line 19

Quoted 7 lines
xen/include/xen/pmstat.h +3 -0
 #ifdef CONFIG_COMPAT
+struct compat_processor_cppc;
+int compat_set_cppc_pminfo(unsigned int acpi_id,
+                           const struct compat_processor_cppc *cppc_data);
 struct compat_processor_performance;
 int compat_set_px_pminfo(uint32_t acpi_id, struct compat_processor_performance *perf);
 struct compat_processor_power;

... this one. (Personally I dislike additions at the top of any group, as this gives the impression that the new stuff is "more important" than what has been there already. See also how in a number of places we simply sort alphabetically, to avoid the common "insert at top" and "insert at bottom" patterns.)

xen/include/xlat.lst line 174

Quoted 10 lines
xen/include/xlat.lst +1 -0
@@ -168,6 +168,7 @@
 !	processor_performance		platform.h
 !	processor_power			platform.h
 ?	processor_px			platform.h
+!	processor_cppc			platform.h
 !	psd_package			platform.h
 ?	xenpf_enter_acpi_sleep		platform.h
 ?	xenpf_pcpu_version		platform.h

Please obey to sorting in this file.

Jan

#16 lore raw

RE: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

[Public]

Quoted 26 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 12:10 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

Quoted 13 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9 -0
@@ -635,6 +641,124 @@ out:
     return ret;
 }
 
+static void print_CPPC(const struct xen_processor_cppc *cppc_data) {
+    printk("\t_CPC: highest_perf=%u, lowest_perf=%u, "
+           "nominal_perf=%u, lowest_nonlinear_perf=%u, "
+           "nominal_mhz=%uMHz, lowest_mhz=%uMHz\n",
+           cppc_data->cpc.highest_perf, cppc_data->cpc.lowest_perf,
+           cppc_data->cpc.nominal_perf, cppc_data->cpc.lowest_nonlinear_perf,
+           cppc_data->cpc.nominal_mhz, cppc_data->cpc.lowest_mhz); }
+
+int set_cppc_pminfo(unsigned int acpi_id,
Quoted 8 lines

xen/drivers/cpufreq/cpufreq.c out: · line 661

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+                    const struct xen_processor_cppc *cppc_data) {
+    int ret = 0, cpuid;
+    struct processor_pminfo *pm_info;
+
+    cpuid = get_cpu_id(acpi_id);
+    if ( cpuid < 0 || !cppc_data )

The !cppc_data part isn't really needed, is it?

I added it because set_cppc_pminfo() is an external function, and maybe we shall validate each input for any external functions? Or maybe not. I'm not sure if it is a MUST?

Quoted 6 lines

xen/drivers/cpufreq/cpufreq.c out:

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +5 -0
+        pm_info->init = XEN_CPPC_INIT;
+        ret = cpufreq_cpu_init(cpuid); #ifndef NDEBUG
+        if ( ret )
+            dprintk(XENLOG_WARNING,
+                    "CPU %u failed to be initialized with amd-cppc mode, and users
Quoted 7 lines

could only reboot and re-define cmdline with \"cpufreq=xen\"",

xen/drivers/cpufreq/cpufreq.c out: · line 755

Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +2 -0
+                    cpuid);
+#endif

What use if the #ifdef here? The more that NDEBUG controls behavior of ASSERT(), not that of (debug) logging.

Understood. Maybe I shall use one-time printk_once()

Quoted 2 lines

Jan

#17 lore raw

Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

Quoted 37 lines · Zheng

[Public]

Quoted 26 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 12:10 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

Quoted 13 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9 -0
@@ -635,6 +641,124 @@ out:
     return ret;
 }
 
+static void print_CPPC(const struct xen_processor_cppc *cppc_data) {
+    printk("\t_CPC: highest_perf=%u, lowest_perf=%u, "
+           "nominal_perf=%u, lowest_nonlinear_perf=%u, "
+           "nominal_mhz=%uMHz, lowest_mhz=%uMHz\n",
+           cppc_data->cpc.highest_perf, cppc_data->cpc.lowest_perf,
+           cppc_data->cpc.nominal_perf, cppc_data->cpc.lowest_nonlinear_perf,
+           cppc_data->cpc.nominal_mhz, cppc_data->cpc.lowest_mhz); }
+
+int set_cppc_pminfo(unsigned int acpi_id,
Quoted 8 lines

xen/drivers/cpufreq/cpufreq.c out: · line 661

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+                    const struct xen_processor_cppc *cppc_data) {
+    int ret = 0, cpuid;
+    struct processor_pminfo *pm_info;
+
+    cpuid = get_cpu_id(acpi_id);
+    if ( cpuid < 0 || !cppc_data )

The !cppc_data part isn't really needed, is it?

Quoted 2 lines

I added it because set_cppc_pminfo() is an external function, and maybe we shall validate each input for any external functions? Or maybe not. I'm not sure if it is a MUST?

It's not. If look through code globally, it is rare that we have such checks. Many of them are imo pointless (and thus giving bad examples). In certain cases they're meaningful to have.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5 -0
+        pm_info->init = XEN_CPPC_INIT;
+        ret = cpufreq_cpu_init(cpuid); #ifndef NDEBUG
+        if ( ret )
+            dprintk(XENLOG_WARNING,
+                    "CPU %u failed to be initialized with amd-cppc mode, and users
Quoted 8 lines
Quoted 6 lines

could only reboot and re-define cmdline with \"cpufreq=xen\"",

xen/drivers/cpufreq/cpufreq.c out: · line 755

Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +2 -0
+                    cpuid);
+#endif

What use if the #ifdef here? The more that NDEBUG controls behavior of ASSERT(), not that of (debug) logging.

Understood. Maybe I shall use one-time printk_once()

Perhaps, also considering that the action to take is relevant also in release builds. However, "users could only" is once again odd wording for a log message. How about "CPU%u failed amd-cppc mode init; use \"cpufreq=xen\" instead"?

Jan

#18 lore raw

RE: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

In reply to Jan Beulich

[Public]

Quoted 22 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 12:10 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

xen/include/public/platform.h DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); · line 364

Quoted 6 lines · Penny Zheng
(quoted diff) +0 -0
@@ -635,6 +641,124 @@ out:
xen/include/public/platform.h +2 -0
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
+struct xen_processor_cppc {
+    uint8_t flags; /* flag for CPPC sub info type */

A common way of commenting on such would be /* XEN_CPPC_... */.

Quoted 7 lines

In any event, here and ...

xen/include/public/platform.h struct xen_processor_performance { · line 467

Quoted 1 line
xen/include/public/platform.h +1 -0
+    uint8_t pad[3]; /* padding and must be zero */

... here (and of course anywhere else) - please adhere to designated comment style.

Apart from Capital for the first letter, do designated comment style include format like: IN/OUT: xxx?

Quoted 2 lines

Jan

#19 lore raw

Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

Quoted 26 lines · Zheng

[Public]

Quoted 24 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 12:10 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 04/18] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data

xen/include/public/platform.h DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); · line 364

Quoted 6 lines · Penny Zheng
(quoted diff) +0 -0
@@ -635,6 +641,124 @@ out:
xen/include/public/platform.h +2 -0
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
+struct xen_processor_cppc {
+    uint8_t flags; /* flag for CPPC sub info type */

A common way of commenting on such would be /* XEN_CPPC_... */.

In any event, here and ...

Quoted 7 lines
Quoted 4 lines

xen/include/public/platform.h struct xen_processor_performance { · line 467

Quoted 1 line
xen/include/public/platform.h +1 -0
+    uint8_t pad[3]; /* padding and must be zero */

... here (and of course anywhere else) - please adhere to designated comment style.

Apart from Capital for the first letter, do designated comment style include format like: IN/OUT: xxx?

Comment style applies everywhere; the IN/OUT annotations in public headers are generally desirable to have imo, yet for a padding field I'm not quite seeing a need for such (if the caller passes in zeroes, the field will stay zeroed unless the hypervisor actively altered the contents; IOW such fields simply need to be zero at all times).

Jan

#20 lore raw

PATCH v5 5/18 xen/cpufreq: refactor cmdline "cpufreq=xxx"

In reply to Penny Zheng

A helper function handle_cpufreq_cmdline() is introduced to tidy different handling pathes.
We also add a new helper cpufreq_opts_contain() to ignore and warn user redundant setting, like "cpufreq=hwp;hwp;xen"

---
v2 -> v3:
- new commit
---
v3 -> v4:
- add one single helper to do the tidy work
- ignore and warn user redundant setting
---
v4 -> v5:
- make "cpufreq_opts_str" static and the string literals end up in .init.rodata.
- use "CPUFREQ_xxx" as array slot index
- blank line between non-fall-through case blocks

---
 xen/drivers/cpufreq/cpufreq.c | 57 ++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 8 deletions(-)
xen/drivers/cpufreq/cpufreq.c +49 -8
index d6b6c844d8..d1b51c8dd0 100644
@@ -69,8 +69,55 @@ enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen,
                                                         CPUFREQ_none };
 unsigned int __initdata cpufreq_xen_cnt = 1;
 
+static const char __initconst cpufreq_opts_str[][5] = {
+    [CPUFREQ_none] = "none",
+    [CPUFREQ_xen] = "xen",
+    [CPUFREQ_hwp] = "hwp",
+};
+
 static int __init cpufreq_cmdline_parse(const char *s, const char *e);
 
+static bool __init cpufreq_opts_contain(enum cpufreq_xen_opt option)
+{
+    unsigned int count = cpufreq_xen_cnt;
+
+    while ( count )
+    {
+        if ( cpufreq_xen_opts[--count] == option )
+            return true;
+    }
+
+    return false;
+}
+
+static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
+{
+    int ret = 0;
+
+    if ( cpufreq_opts_contain(option) )
+    {
+        printk(XENLOG_WARNING "Duplicate cpufreq driver option: %s\n",
+               cpufreq_opts_str[option]);
+        return 0;
+    }
+
+    cpufreq_controller = FREQCTL_xen;
+    cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
+    switch ( option )
+    {
+    case CPUFREQ_hwp:
+    case CPUFREQ_xen:
+        xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
+        break;
+
+    default:
+        ret = -EINVAL;
+        break;
+    }
+
+    return ret;
+}
+
 static int __init cf_check setup_cpufreq_option(const char *str)
 {
     const char *arg = strpbrk(str, ",:;");
@@ -114,20 +161,14 @@ static int __init cf_check setup_cpufreq_option(const char *str)
 
         if ( choice > 0 || !cmdline_strcmp(str, "xen") )
         {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_xen;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_xen);
             if ( arg[0] && arg[1] )
                 ret = cpufreq_cmdline_parse(arg + 1, end);
         }
         else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 &&
                   !cmdline_strcmp(str, "hwp") )
         {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_hwp);
             if ( arg[0] && arg[1] )
                 ret = hwp_cmdline_parse(arg + 1, end);
         }
Signature · 1 line
2.34.1
#21 lore raw

Re: [PATCH v5 05/18] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Hi Penny,

Quoted 8 lines · Penny Zheng

A helper function handle_cpufreq_cmdline() is introduced to tidy different handling pathes.
We also add a new helper cpufreq_opts_contain() to ignore and warn user redundant setting, like "cpufreq=hwp;hwp;xen"

xen/drivers/cpufreq/cpufreq.c static int __init cf_check setup_cpufreq_option(const char *str) · line 164

Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +1 -4
@@ -114,20 +161,14 @@ static int __init cf_check setup_cpufreq_option(const char *str)
 
          if ( choice > 0 || !cmdline_strcmp(str, "xen") )
          {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_xen;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_xen);

Do we need to check ret and error out? (and below)

Thanks,
Jason

Quoted 14 lines
xen/drivers/cpufreq/cpufreq.c +1 -4
              if ( arg[0] && arg[1] )
                  ret = cpufreq_cmdline_parse(arg + 1, end);
          }
          else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 &&
                    !cmdline_strcmp(str, "hwp") )
          {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_hwp);
              if ( arg[0] && arg[1] )
                  ret = hwp_cmdline_parse(arg + 1, end);
          }
#22 lore raw

RE: [PATCH v5 05/18] xen/cpufreq: refactor cmdline "cpufreq=xxx"

[Public]

Quoted 20 lines

-----Original Message-----
From: Jason Andryuk <[email protected]>
Sent: Wednesday, June 11, 2025 4:03 PM
To: Penny, Zheng <[email protected]>; [email protected]
Cc: Huang, Ray <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [PATCH v5 05/18] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Hi Penny,

Quoted 10 lines · Penny Zheng

A helper function handle_cpufreq_cmdline() is introduced to tidy different handling pathes.
We also add a new helper cpufreq_opts_contain() to ignore and warn user redundant setting, like "cpufreq=hwp;hwp;xen"

(quoted diff) +0 -0
@@ -114,20 +161,14 @@ static int __init cf_check
 setup_cpufreq_option(const char *str)
 
Quoted 10 lines

xen/drivers/cpufreq/cpufreq.c static int __init cf_check setup_cpufreq_option(const char *str) · line 164

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +1 -4
          if ( choice > 0 || !cmdline_strcmp(str, "xen") )
          {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_xen;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_xen);

Do we need to check ret and error out? (and below)

Right, we need, thanks, will fix

Quoted 17 lines

Thanks,
Jason

Quoted 14 lines
xen/drivers/cpufreq/cpufreq.c +1 -4
              if ( arg[0] && arg[1] )
                  ret = cpufreq_cmdline_parse(arg + 1, end);
          }
          else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 &&
                    !cmdline_strcmp(str, "hwp") )
          {
-            xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
-            cpufreq_controller = FREQCTL_xen;
-            cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp;
-            ret = 0;
+            ret = handle_cpufreq_cmdline(CPUFREQ_hwp);
              if ( arg[0] && arg[1] )
                  ret = hwp_cmdline_parse(arg + 1, end);
          }
#23 lore raw

Re: [PATCH v5 05/18] xen/cpufreq: refactor cmdline "cpufreq=xxx"

In reply to Penny Zheng
Quoted 11 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +5 -0
@@ -69,8 +69,55 @@ enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen,
                                                         CPUFREQ_none };
 unsigned int __initdata cpufreq_xen_cnt = 1;
 
+static const char __initconst cpufreq_opts_str[][5] = {
+    [CPUFREQ_none] = "none",
+    [CPUFREQ_xen] = "xen",
+    [CPUFREQ_hwp] = "hwp",
+};

xen/drivers/cpufreq/cpufreq.c enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen, · line 86

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +8 -0
+
 static int __init cpufreq_cmdline_parse(const char *s, const char *e);
 
+static bool __init cpufreq_opts_contain(enum cpufreq_xen_opt option)
+{
+    unsigned int count = cpufreq_xen_cnt;
+
+    while ( count )
+    {
+        if ( cpufreq_xen_opts[--count] == option )

Instead of this, "while ( count-- )" would likely be slightly better; less risk of an edit to the loop body (however unlikely that may seem right now) then bypassing the decrement.

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+            return true;
+    }
+
+    return false;

xen/drivers/cpufreq/cpufreq.c enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen, · line 100

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+}
+
+static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
+{
+    int ret = 0;
+
+    if ( cpufreq_opts_contain(option) )
+    {
+        printk(XENLOG_WARNING "Duplicate cpufreq driver option: %s\n",
+               cpufreq_opts_str[option]);

Do we really need such a warning?

xen/drivers/cpufreq/cpufreq.c enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen, · line 105

Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5 -0
+        return 0;
+    }
+
+    cpufreq_controller = FREQCTL_xen;
+    cpufreq_xen_opts[cpufreq_xen_cnt++] = option;

This could do with (at least) an assertion that we indeed don't overrun the array.

Jan

#24 lore raw

PATCH v5 6/18 xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

In reply to Penny Zheng

Users need to set "cpufreq=amd-cppc" in xen cmdline to enable amd-cppc driver, which selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide a finer grained frequency control mechanism.
verbose option can also be included to support verbose print.

When users setting "cpufreq=amd-cppc", a new amd-cppc driver shall be registered and used. All hooks for amd-cppc driver are transiently missing and will be implemented in the ongoing commits.

New xen-pm internal flag XEN_PROCESSOR_PM_CPPC is introduced, to be differentiated with legacy XEN_PROCESSOR_PM_PX. We define XEN_PROCESSOR_PM_CPPC 0x100, as it is the next value to use after 8-bits wide public xen-pm options. All xen-pm flag checking involving XEN_PROCESSOR_PM_PX shall also be updated to consider XEN_PROCESSOR_PM_CPPC now.

Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT, _PPC) operations, so only one cpufreq driver gets registerd, either amd-cppc or legacy P-states driver, which is reflected and asserted by the incompatible flags XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC.

---
v1 -> v2:
- Obey to alphabetic sorting and also strict it with CONFIG_AMD
- Remove unnecessary empty comment line
- Use __initconst_cf_clobber for pre-filled structure cpufreq_driver
- Make new switch-case code apply to Hygon CPUs too
- Change ENOSYS with EOPNOTSUPP
- Blanks around binary operator
- Change all amd_/-pstate defined values to amd_/-cppc
---
v2 -> v3
- refactor too long lines
- Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC incompatible flags after cpufreq register registrantion
---
v3 -> v4:
- introduce XEN_PROCESSOR_PM_CPPC in xen internal header
- complement "Hygon" in log message
- remove unnecessary if()
- grow cpufreq_xen_opts[] array
---
v4 -> v5:
- remove XEN_PROCESSOR_PM_xxx flag sanitization from individual driver
- prefer ! over "== 0" in purely boolean contexts
- Blank line between non-fall-through case blocks
- add build-time checking between internal and public XEN_PROCESSOR_PM_* values
- define XEN_PROCESSOR_PM_CPPC with 0x100, as it is the next value to use after public interface, and public mask SIF_PM_MASK is 8 bits wide.
- as Dom0 will send the CPPC/Px data whenever it could, the return value shall be 0 instead of -ENOSYS/EOPNOTSUP when platform doesn't require these data.

---
 docs/misc/xen-command-line.pandoc         |  7 ++-
 xen/arch/x86/acpi/cpufreq/Makefile        |  1 +
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 68 +++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       | 63 ++++++++++++++++++++-
 xen/arch/x86/platform_hypercall.c         | 13 ++++-
 xen/drivers/acpi/pmstat.c                 |  3 +-
 xen/drivers/cpufreq/cpufreq.c             | 18 +++++-
 xen/include/acpi/cpufreq/cpufreq.h        |  6 +-
 xen/include/acpi/cpufreq/processor_perf.h |  3 +
 xen/include/public/sysctl.h               |  1 +
 10 files changed, 175 insertions(+), 8 deletions(-)
 create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
docs/misc/xen-command-line.pandoc +5 -2
index 89db6e83be..9ef847a336 100644
@@ -515,7 +515,7 @@ If set, force use of the performance counters for oprofile, rather than detectin
 available support.
 
 ### cpufreq
-> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]]`
+> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[verbose]]`
 
 > Default: `xen`
 
@@ -526,7 +526,7 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels.
 * `<maxfreq>` and `<minfreq>` are integers which represent max and min processor frequencies
   respectively.
 * `verbose` option can be included as a string or also as `verbose=<integer>`
-  for `xen`.  It is a boolean for `hwp`.
+  for `xen`.  It is a boolean for `hwp` and `amd-cppc`.
 * `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
@@ -534,6 +534,9 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels.
 * `<hdc>` is a boolean to enable Hardware Duty Cycling (HDC).  HDC enables the
   processor to autonomously force physical package components into idle state.
   The default is enabled, but the option only applies when `hwp` is enabled.
+* `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC)
+  on supported AMD hardware to provide finer grained frequency control
+  mechanism. The default is disabled.
 
 There is also support for `;`-separated fallback options:
 `cpufreq=hwp;xen,verbose`.  This first tries `hwp` and falls back to `xen` if
xen/arch/x86/acpi/cpufreq/Makefile +1 -0
index e7dbe434a8..a2ba34bda0 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_INTEL) += acpi.o
+obj-$(CONFIG_AMD) += amd-cppc.o
 obj-y += cpufreq.o
 obj-$(CONFIG_INTEL) += hwp.o
 obj-$(CONFIG_AMD) += powernow.o
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +68 -0

68 lines not on this page · raw message

xen/arch/x86/acpi/cpufreq/cpufreq.c +62 -1

75 lines not on this page · raw message

xen/arch/x86/platform_hypercall.c +12 -1
index 49717e9ca9..231912ed27 100644
@@ -539,9 +539,12 @@ ret_t do_platform_op(
         case XEN_PM_PX:
             if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
             {
-                ret = -ENOSYS;
+                ret = 0;
                 break;
             }
+            /* Xen doesn't support mixed mode */
+            ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC));
+
             ret = set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);
             break;
  
@@ -573,6 +576,14 @@ ret_t do_platform_op(
         }
 
         case XEN_PM_CPPC:
+            if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
+            {
+                ret = 0;
+                break;
+            }
+            /* Xen doesn't support mixed mode */
+            ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_PX));
+
             ret = set_cppc_pminfo(op->u.set_pminfo.id,
                                   &op->u.set_pminfo.u.cppc_data);
             break;
xen/drivers/acpi/pmstat.c +2 -1
index f7351f219d..330bc3a1c2 100644
@@ -464,7 +464,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)
     switch ( op->cmd & PM_PARA_CATEGORY_MASK )
     {
     case CPUFREQ_PARA:
-        if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
+        if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX |
+                                       XEN_PROCESSOR_PM_CPPC)) )
             return -ENODEV;
         if ( !pmpt || !(pmpt->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
             return -EINVAL;
xen/drivers/cpufreq/cpufreq.c +16 -2
index d1b51c8dd0..fe55720afd 100644
@@ -65,14 +65,15 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);
 /* set xen as default cpufreq */
 enum cpufreq_controller cpufreq_controller = FREQCTL_xen;
 
-enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2] = { CPUFREQ_xen,
+enum cpufreq_xen_opt __initdata cpufreq_xen_opts[3] = { CPUFREQ_xen,
                                                         CPUFREQ_none };
 unsigned int __initdata cpufreq_xen_cnt = 1;
 
-static const char __initconst cpufreq_opts_str[][5] = {
+static const char __initconst cpufreq_opts_str[][9] = {
     [CPUFREQ_none] = "none",
     [CPUFREQ_xen] = "xen",
     [CPUFREQ_hwp] = "hwp",
+    [CPUFREQ_amd_cppc] = "amd-cppc",
 };
 
 static int __init cpufreq_cmdline_parse(const char *s, const char *e);
@@ -94,6 +95,8 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
 {
     int ret = 0;
 
+    /* Do not occupy bits reserved for public xen-pm */
+    BUILD_BUG_ON(MASK_INSR(XEN_PROCESSOR_PM_CPPC, SIF_PM_MASK));
     if ( cpufreq_opts_contain(option) )
     {
         printk(XENLOG_WARNING "Duplicate cpufreq driver option: %s\n",
@@ -105,6 +108,10 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
     cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
     switch ( option )
     {
+    case CPUFREQ_amd_cppc:
+        xen_processor_pmbits |= XEN_PROCESSOR_PM_CPPC;
+        break;
+
     case CPUFREQ_hwp:
     case CPUFREQ_xen:
         xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
@@ -172,6 +179,13 @@ static int __init cf_check setup_cpufreq_option(const char *str)
             if ( arg[0] && arg[1] )
                 ret = hwp_cmdline_parse(arg + 1, end);
         }
+        else if ( IS_ENABLED(CONFIG_AMD) && choice < 0 &&
+                  !cmdline_strcmp(str, "amd-cppc") )
+        {
+            ret = handle_cpufreq_cmdline(CPUFREQ_amd_cppc);
+            if ( arg[0] && arg[1] )
+                ret = amd_cppc_cmdline_parse(arg + 1, end);
+        }
         else
             ret = -EINVAL;
 
xen/include/acpi/cpufreq/cpufreq.h +5 -1
index a3c84143af..83050c58b2 100644
@@ -28,8 +28,9 @@ enum cpufreq_xen_opt {
     CPUFREQ_none,
     CPUFREQ_xen,
     CPUFREQ_hwp,
+    CPUFREQ_amd_cppc,
 };
-extern enum cpufreq_xen_opt cpufreq_xen_opts[2];
+extern enum cpufreq_xen_opt cpufreq_xen_opts[3];
 extern unsigned int cpufreq_xen_cnt;
 struct cpufreq_governor;
 
@@ -277,4 +278,7 @@ int set_hwp_para(struct cpufreq_policy *policy,
 
 int acpi_cpufreq_register(void);
 
+int amd_cppc_cmdline_parse(const char *s, const char *e);
+int amd_cppc_register_driver(void);
+
 #endif /* __XEN_CPUFREQ_PM_H__ */
xen/include/acpi/cpufreq/processor_perf.h +3 -0
index f1f4f3138d..9b6466e705 100644
@@ -5,6 +5,9 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
+/* Internal ability bits */
+#define XEN_PROCESSOR_PM_CPPC   0x100
+
 #define XEN_CPPC_INIT 0x40000000U
 #define XEN_PX_INIT   0x80000000U
 
xen/include/public/sysctl.h +1 -0
index b0fec271d3..42997252ef 100644
@@ -423,6 +423,7 @@ struct xen_set_cppc_para {
     uint32_t activity_window;
 };
 
+#define XEN_AMD_CPPC_DRIVER_NAME "amd-cppc"
 #define XEN_HWP_DRIVER_NAME "hwp"
 
 /*
Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 53 lines · Penny Zheng

Users need to set "cpufreq=amd-cppc" in xen cmdline to enable amd-cppc driver, which selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide a finer grained frequency control mechanism.
verbose option can also be included to support verbose print.

When users setting "cpufreq=amd-cppc", a new amd-cppc driver shall be registered and used. All hooks for amd-cppc driver are transiently missing and will be implemented in the ongoing commits.

New xen-pm internal flag XEN_PROCESSOR_PM_CPPC is introduced, to be differentiated with legacy XEN_PROCESSOR_PM_PX. We define XEN_PROCESSOR_PM_CPPC 0x100, as it is the next value to use after 8-bits wide public xen-pm options. All xen-pm flag checking involving XEN_PROCESSOR_PM_PX shall also be updated to consider XEN_PROCESSOR_PM_CPPC now.

Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT, _PPC) operations, so only one cpufreq driver gets registerd, either amd-cppc or legacy P-states driver, which is reflected and asserted by the incompatible flags XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC.

---
v1 -> v2:
- Obey to alphabetic sorting and also strict it with CONFIG_AMD
- Remove unnecessary empty comment line
- Use __initconst_cf_clobber for pre-filled structure cpufreq_driver
- Make new switch-case code apply to Hygon CPUs too
- Change ENOSYS with EOPNOTSUPP
- Blanks around binary operator
- Change all amd_/-pstate defined values to amd_/-cppc
---
v2 -> v3
- refactor too long lines
- Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC incompatible flags after cpufreq register registrantion
---
v3 -> v4:
- introduce XEN_PROCESSOR_PM_CPPC in xen internal header
- complement "Hygon" in log message
- remove unnecessary if()
- grow cpufreq_xen_opts[] array
---
v4 -> v5:
- remove XEN_PROCESSOR_PM_xxx flag sanitization from individual driver
- prefer ! over "== 0" in purely boolean contexts
- Blank line between non-fall-through case blocks
- add build-time checking between internal and public XEN_PROCESSOR_PM_* values
- define XEN_PROCESSOR_PM_CPPC with 0x100, as it is the next value to use after public interface, and public mask SIF_PM_MASK is 8 bits wide.
- as Dom0 will send the CPPC/Px data whenever it could, the return value shall be 0 instead of -ENOSYS/EOPNOTSUP when platform doesn't require these data.

Quoted 13 lines
---
 docs/misc/xen-command-line.pandoc         |  7 ++-
 xen/arch/x86/acpi/cpufreq/Makefile        |  1 +
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 68 +++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       | 63 ++++++++++++++++++++-
 xen/arch/x86/platform_hypercall.c         | 13 ++++-
 xen/drivers/acpi/pmstat.c                 |  3 +-
 xen/drivers/cpufreq/cpufreq.c             | 18 +++++-
 xen/include/acpi/cpufreq/cpufreq.h        |  6 +-
 xen/include/acpi/cpufreq/processor_perf.h |  3 +
 xen/include/public/sysctl.h               |  1 +
 10 files changed, 175 insertions(+), 8 deletions(-)
 create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c

This patch does quite a bit more than what the subject suggests it means to do; please consider adjusting.

xen/arch/x86/acpi/cpufreq/amd-cppc.c line 67

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +9 -0
+int __init amd_cppc_register_driver(void)
+{
+    if ( !cpu_has_cppc )
+    {
+        xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+        return -ENODEV;
+    }
+
+    return cpufreq_register_driver(&amd_cppc_cpufreq_driver);

Isn't this premature? I fear in particular that some of the hooks, which are still all NULL, might have a way of getting invoked.

Quoted 28 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +23 -1
@@ -157,7 +162,63 @@ static int __init cf_check cpufreq_driver_init(void)
 
         case X86_VENDOR_AMD:
         case X86_VENDOR_HYGON:
-            ret = IS_ENABLED(CONFIG_AMD) ? powernow_register_driver() : -ENODEV;
+            unsigned int i;
+
+            if ( !IS_ENABLED(CONFIG_AMD) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+            ret = -ENOENT;
+
+            for ( i = 0; i < cpufreq_xen_cnt; i++ )
+            {
+                switch ( cpufreq_xen_opts[i] )
+                {
+                case CPUFREQ_xen:
+                    ret = powernow_register_driver();
+                    break;
+
+                case CPUFREQ_amd_cppc:
+                    ret = amd_cppc_register_driver();
+                    break;
+
+                case CPUFREQ_none:
+                    ret = 0;

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 197

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10 -0
+                    break;
+
+                default:
+                    printk(XENLOG_WARNING
+                           "Unsupported cpufreq driver for vendor AMD or Hygon\n");
+                    break;
+                }
+
+                if ( ret != -ENODEV )
+                    break;

This, I think, needs some commenting. It's not quite clear why we shouldn't try the next option if registration failed with other than -ENODEV.

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10 -0
+            }
+
+            /*
+             * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
+             * and XEN_PROCESSOR_PM_PX shall become exclusive flags.
+             */
+            if ( !ret && i < cpufreq_xen_cnt )
+            {
+                switch ( cpufreq_xen_opts[i] )
+                {

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 217

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10 -0
+                case CPUFREQ_amd_cppc:
+                    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_PX;
+                    break;
+
+                case CPUFREQ_xen:
+                    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+                    break;
+
+                case CPUFREQ_none:
+                default:

What's the point of the separate "case" label here?

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 194

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +3 -0
+                    break;
+                }
+            }

Why does this pruning of xen_processor_pmbits sit in the AMD-only code path? Iirc earlier on you had it in the *_register_driver() themselves, and my request was to put it in a central, generic place. It's central now, but not generic (and this way it could as well have remained in *_register_driver()).

Quoted 5 lines
xen/arch/x86/platform_hypercall.c +0 -0
@@ -539,9 +539,12 @@ ret_t do_platform_op(
         case XEN_PM_PX:
             if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )

xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 549

Quoted 10 lines
xen/arch/x86/platform_hypercall.c +4 -1
             {
-                ret = -ENOSYS;
+                ret = 0;
                 break;
             }
+            /* Xen doesn't support mixed mode */
+            ASSERT(!(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC));
+
             ret = set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);
             break;

I don't see how this change relates to the purpose of the patch. From the description (and in the absence of a code comment) it also doesn't become clear at all why that change of return value would be needed (and would be correct to do). From comments I gave on earlier versions of this series, I think I can guess what this is about, but such shouldn't be slipped in silently.

xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 583

Quoted 9 lines
xen/arch/x86/platform_hypercall.c +5 -0
@@ -573,6 +576,14 @@ ret_t do_platform_op(
         }
 
         case XEN_PM_CPPC:
+            if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
+            {
+                ret = 0;
+                break;
+            }

As per above, this yielding success needs justifying.

xen/arch/x86/platform_hypercall.c static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) · line 99

Quoted 6 lines
xen/arch/x86/platform_hypercall.c +2 -0
@@ -94,6 +95,8 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
 {
     int ret = 0;
 
+    /* Do not occupy bits reserved for public xen-pm */
+    BUILD_BUG_ON(MASK_INSR(XEN_PROCESSOR_PM_CPPC, SIF_PM_MASK));

This looks like an abuse of MASK_INSR(). Why not simply

    BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC & SIF_PM_MASK);

?

Also please separate this by a blank line from what follows, or perhaps even better ...

xen/arch/x86/platform_hypercall.c static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) · line 113

Quoted 7 lines
xen/arch/x86/platform_hypercall.c +3 -0
@@ -105,6 +108,10 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
     cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
     switch ( option )
     {
+    case CPUFREQ_amd_cppc:
+        xen_processor_pmbits |= XEN_PROCESSOR_PM_CPPC;
+        break;

... move it here.

xen/arch/x86/platform_hypercall.c static int __init cf_check setup_cpufreq_option(const char *str) · line 188

Quoted 11 lines
xen/arch/x86/platform_hypercall.c +7 -0
@@ -172,6 +179,13 @@ static int __init cf_check setup_cpufreq_option(const char *str)
             if ( arg[0] && arg[1] )
                 ret = hwp_cmdline_parse(arg + 1, end);
         }
+        else if ( IS_ENABLED(CONFIG_AMD) && choice < 0 &&
+                  !cmdline_strcmp(str, "amd-cppc") )
+        {
+            ret = handle_cpufreq_cmdline(CPUFREQ_amd_cppc);
+            if ( arg[0] && arg[1] )
+                ret = amd_cppc_cmdline_parse(arg + 1, end);
+        }

See Jason's comment on the earlier patch.

xen/include/acpi/cpufreq/processor_perf.h line 9

Quoted 8 lines
xen/include/acpi/cpufreq/processor_perf.h +2 -0
@@ -5,6 +5,9 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
+/* Internal ability bits */
+#define XEN_PROCESSOR_PM_CPPC   0x100

The comment wants extending, to have a reference to the other XEN_PROCESSOR_PM_* bits and perhaps also to SIF_PM_MASK. In fact the BUILD_BUG_ON() that I commented on above could be replaced by

#if XEN_PROCESSOR_PM_CPPC & SIF_PM_MASK

# error "..."
#endif

right here.

Jan

#26 lore raw

RE: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

[Public]

Quoted 120 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 6:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 10 lines · Penny Zheng

Users need to set "cpufreq=amd-cppc" in xen cmdline to enable amd-cppc driver, which selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide a finer grained frequency control mechanism.
verbose option can also be included to support verbose print.

When users setting "cpufreq=amd-cppc", a new amd-cppc driver shall be registered and used. All hooks for amd-cppc driver are transiently missing and will be implemented in the ongoing commits.

Quoted 5 lines

New xen-pm internal flag XEN_PROCESSOR_PM_CPPC is introduced, to be differentiated with legacy XEN_PROCESSOR_PM_PX. We define XEN_PROCESSOR_PM_CPPC 0x100, as it is the next value to use after 8-bits wide public xen-pm options. All xen-pm flag checking involving XEN_PROCESSOR_PM_PX shall also be updated to consider

XEN_PROCESSOR_PM_CPPC now.

Quoted 6 lines

Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT,
_PPC) operations, so only one cpufreq driver gets registerd, either amd-cppc or legacy P-states driver, which is reflected and asserted by the incompatible flags XEN_PROCESSOR_PM_PX and

XEN_PROCESSOR_PM_CPPC.

Quoted 15 lines

---
v1 -> v2:
- Obey to alphabetic sorting and also strict it with CONFIG_AMD
- Remove unnecessary empty comment line
- Use __initconst_cf_clobber for pre-filled structure cpufreq_driver
- Make new switch-case code apply to Hygon CPUs too
- Change ENOSYS with EOPNOTSUPP
- Blanks around binary operator
- Change all amd_/-pstate defined values to amd_/-cppc
---
v2 -> v3
- refactor too long lines
- Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC

incompatible

Quoted 10 lines

flags after cpufreq register registrantion
---
v3 -> v4:
- introduce XEN_PROCESSOR_PM_CPPC in xen internal header
- complement "Hygon" in log message
- remove unnecessary if()
- grow cpufreq_xen_opts[] array
---
v4 -> v5:
- remove XEN_PROCESSOR_PM_xxx flag sanitization from individual driver

Quoted 8 lines

- prefer ! over "== 0" in purely boolean contexts
- Blank line between non-fall-through case blocks
- add build-time checking between internal and public XEN_PROCESSOR_PM_* values
- define XEN_PROCESSOR_PM_CPPC with 0x100, as it is the next value to use after public interface, and public mask SIF_PM_MASK is 8 bits wide.
- as Dom0 will send the CPPC/Px data whenever it could, the return value shall be 0 instead of -ENOSYS/EOPNOTSUP when platform doesn't require

these data.

Quoted 15 lines
---
 docs/misc/xen-command-line.pandoc         |  7 ++-
 xen/arch/x86/acpi/cpufreq/Makefile        |  1 +
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 68 +++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       | 63 ++++++++++++++++++++-
 xen/arch/x86/platform_hypercall.c         | 13 ++++-
 xen/drivers/acpi/pmstat.c                 |  3 +-
 xen/drivers/cpufreq/cpufreq.c             | 18 +++++-
 xen/include/acpi/cpufreq/cpufreq.h        |  6 +-
 xen/include/acpi/cpufreq/processor_perf.h |  3 +
 xen/include/public/sysctl.h               |  1 +
 10 files changed, 175 insertions(+), 8 deletions(-)  create mode

100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0 -1
@@ -157,7 +162,63 @@ static int __init cf_check
 cpufreq_driver_init(void)
 
         case X86_VENDOR_AMD:
         case X86_VENDOR_HYGON:
-            ret = IS_ENABLED(CONFIG_AMD) ? powernow_register_driver() : -

ENODEV;

Quoted 28 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +28 -0
+            unsigned int i;
+
+            if ( !IS_ENABLED(CONFIG_AMD) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+            ret = -ENOENT;
+
+            for ( i = 0; i < cpufreq_xen_cnt; i++ )
+            {
+                switch ( cpufreq_xen_opts[i] )
+                {
+                case CPUFREQ_xen:
+                    ret = powernow_register_driver();
+                    break;
+
+                case CPUFREQ_amd_cppc:
+                    ret = amd_cppc_register_driver();
+                    break;
+
+                case CPUFREQ_none:
+                    ret = 0;
+                    break;
+
+                default:
+                    printk(XENLOG_WARNING
+                           "Unsupported cpufreq driver for vendor AMD or Hygon\n");
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 197

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +5 -0
+                    break;
+                }
+
+                if ( ret != -ENODEV )
+                    break;

This, I think, needs some commenting. It's not quite clear why we shouldn't try the next option if registration failed with other than -ENODEV.

I followed the original logic.
Now, I'm trying to understand the reason. I read the related code, there are two code path erroring out other than -ENODEV
In cpufreq_register_driver(), either the driver itself is broken, like missing mandatory hooks, etc, yet in which case, IMO we shall try the fallback option, or repeated registration, TBH, which seems unlikely to me. cpufreq_driver_init() is a presmp call, so repeated registration doesn't come from racing. Then if we successfully registered a driver, we will immediately exit the loop. How come we will register twice?
Or am I missing something for this error path:

```
        if ( cpufreq_driver.init )
                return -EBUSY;
```
Quoted 10 lines

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 194

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +3 -0
+                    break;
+                }
+            }

Why does this pruning of xen_processor_pmbits sit in the AMD-only code path? Iirc earlier on you had it in the *_register_driver() themselves, and my request was to put it in a central, generic place. It's central now, but not generic (and this way it could as well have remained in *_register_driver()).

True, before, I was wrongly assumed that XEN_PROCESSOR_PM_CPPC could only be initialized in AMD.
We could also provide "cpufreq=amd-cppc" in INTEL platform, yet under which scenario, we shall set ret with -ENODEV errno (right now is -ENOENT, need to fix) to keep looping and try the next option... I’ll move it out of the AMD-only patch, and put it after the whole switch-case

Quoted 2 lines

Jan

#27 lore raw

Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 131 lines · Zheng

[Public]

Quoted 120 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 6:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 10 lines · Penny Zheng

Users need to set "cpufreq=amd-cppc" in xen cmdline to enable amd-cppc driver, which selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide a finer grained frequency control mechanism.
verbose option can also be included to support verbose print.

When users setting "cpufreq=amd-cppc", a new amd-cppc driver shall be registered and used. All hooks for amd-cppc driver are transiently missing and will be implemented in the ongoing commits.

Quoted 5 lines

New xen-pm internal flag XEN_PROCESSOR_PM_CPPC is introduced, to be differentiated with legacy XEN_PROCESSOR_PM_PX. We define XEN_PROCESSOR_PM_CPPC 0x100, as it is the next value to use after 8-bits wide public xen-pm options. All xen-pm flag checking involving XEN_PROCESSOR_PM_PX shall also be updated to consider

XEN_PROCESSOR_PM_CPPC now.

Quoted 6 lines

Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT,
_PPC) operations, so only one cpufreq driver gets registerd, either amd-cppc or legacy P-states driver, which is reflected and asserted by the incompatible flags XEN_PROCESSOR_PM_PX and

XEN_PROCESSOR_PM_CPPC.

Quoted 15 lines

---
v1 -> v2:
- Obey to alphabetic sorting and also strict it with CONFIG_AMD
- Remove unnecessary empty comment line
- Use __initconst_cf_clobber for pre-filled structure cpufreq_driver
- Make new switch-case code apply to Hygon CPUs too
- Change ENOSYS with EOPNOTSUPP
- Blanks around binary operator
- Change all amd_/-pstate defined values to amd_/-cppc
---
v2 -> v3
- refactor too long lines
- Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC

incompatible

Quoted 10 lines

flags after cpufreq register registrantion
---
v3 -> v4:
- introduce XEN_PROCESSOR_PM_CPPC in xen internal header
- complement "Hygon" in log message
- remove unnecessary if()
- grow cpufreq_xen_opts[] array
---
v4 -> v5:
- remove XEN_PROCESSOR_PM_xxx flag sanitization from individual driver

Quoted 8 lines

- prefer ! over "== 0" in purely boolean contexts
- Blank line between non-fall-through case blocks
- add build-time checking between internal and public XEN_PROCESSOR_PM_* values
- define XEN_PROCESSOR_PM_CPPC with 0x100, as it is the next value to use after public interface, and public mask SIF_PM_MASK is 8 bits wide.
- as Dom0 will send the CPPC/Px data whenever it could, the return value shall be 0 instead of -ENOSYS/EOPNOTSUP when platform doesn't require

these data.

Quoted 15 lines
---
 docs/misc/xen-command-line.pandoc         |  7 ++-
 xen/arch/x86/acpi/cpufreq/Makefile        |  1 +
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 68 +++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       | 63 ++++++++++++++++++++-
 xen/arch/x86/platform_hypercall.c         | 13 ++++-
 xen/drivers/acpi/pmstat.c                 |  3 +-
 xen/drivers/cpufreq/cpufreq.c             | 18 +++++-
 xen/include/acpi/cpufreq/cpufreq.h        |  6 +-
 xen/include/acpi/cpufreq/processor_perf.h |  3 +
 xen/include/public/sysctl.h               |  1 +
 10 files changed, 175 insertions(+), 8 deletions(-)  create mode

100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0 -1
@@ -157,7 +162,63 @@ static int __init cf_check
 cpufreq_driver_init(void)
 
         case X86_VENDOR_AMD:
         case X86_VENDOR_HYGON:
-            ret = IS_ENABLED(CONFIG_AMD) ? powernow_register_driver() : -

ENODEV;

Quoted 28 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +28 -0
+            unsigned int i;
+
+            if ( !IS_ENABLED(CONFIG_AMD) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+            ret = -ENOENT;
+
+            for ( i = 0; i < cpufreq_xen_cnt; i++ )
+            {
+                switch ( cpufreq_xen_opts[i] )
+                {
+                case CPUFREQ_xen:
+                    ret = powernow_register_driver();
+                    break;
+
+                case CPUFREQ_amd_cppc:
+                    ret = amd_cppc_register_driver();
+                    break;
+
+                case CPUFREQ_none:
+                    ret = 0;
+                    break;
+
+                default:
+                    printk(XENLOG_WARNING
+                           "Unsupported cpufreq driver for vendor AMD or Hygon\n");
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 197

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +5 -0
+                    break;
+                }
+
+                if ( ret != -ENODEV )
+                    break;

This, I think, needs some commenting. It's not quite clear why we shouldn't try the next option if registration failed with other than -ENODEV.

Quoted 1 line

I followed the original logic.

Which may easily itself be partly bogus.

Quoted 9 lines

Now, I'm trying to understand the reason. I read the related code, there are two code path erroring out other than -ENODEV
In cpufreq_register_driver(), either the driver itself is broken, like missing mandatory hooks, etc, yet in which case, IMO we shall try the fallback option, or repeated registration, TBH, which seems unlikely to me. cpufreq_driver_init() is a presmp call, so repeated registration doesn't come from racing. Then if we successfully registered a driver, we will immediately exit the loop. How come we will register twice?
Or am I missing something for this error path:

```
        if ( cpufreq_driver.init )
                return -EBUSY;
```

Imo this error path is there "just in case".

Jan

#28 lore raw

RE: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

In reply to Jan Beulich

[Public]

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 6:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

xen/arch/x86/platform_hypercall.c static int __init handle_cpufreq_cmdline(enum · line 99

Quoted 8 lines · Penny Zheng
xen/arch/x86/platform_hypercall.c +2 -0
@@ -94,6 +95,8 @@ static int __init handle_cpufreq_cmdline(enum
 cpufreq_xen_opt option)  {
     int ret = 0;
 
+    /* Do not occupy bits reserved for public xen-pm */
+    BUILD_BUG_ON(MASK_INSR(XEN_PROCESSOR_PM_CPPC,

SIF_PM_MASK));

Quoted 5 lines

This looks like an abuse of MASK_INSR(). Why not simply

    BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC & SIF_PM_MASK);

?

Because in SIF_PM_MASK, it's bit 8 to 15 reserved for xen-pm options,
See "
#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
"
So I'm trying to use MASK_INSR() to do the necessary right shift (other than using 8 directly, in case SIF_PM_MASK changes in the future...)

Quoted 2 lines

Jan

#29 lore raw

Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 29 lines · Zheng

[Public]

Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 6:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 06/18] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

xen/arch/x86/platform_hypercall.c static int __init handle_cpufreq_cmdline(enum · line 99

Quoted 8 lines · Penny Zheng
xen/arch/x86/platform_hypercall.c +2 -0
@@ -94,6 +95,8 @@ static int __init handle_cpufreq_cmdline(enum
 cpufreq_xen_opt option)  {
     int ret = 0;
 
+    /* Do not occupy bits reserved for public xen-pm */
+    BUILD_BUG_ON(MASK_INSR(XEN_PROCESSOR_PM_CPPC,

SIF_PM_MASK));

This looks like an abuse of MASK_INSR(). Why not simply

    BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC & SIF_PM_MASK);
Quoted 7 lines
Quoted 1 line

?

Because in SIF_PM_MASK, it's bit 8 to 15 reserved for xen-pm options,
See "
#define SIF_PM_MASK (0xFF<<8) /* reserve 1 byte for xen-pm options */
"
So I'm trying to use MASK_INSR() to do the necessary right shift (other than using 8 directly, in case SIF_PM_MASK changes in the future...)

Oh, right, so my replacement suggestion was wrong. But XEN_PROCESSOR_PM_CPPC isn't contained within the 8 bits. MASK_INSR() could conceivably have a (debug) check that the passed value actually fits the mask.

     BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC & MASK_EXTR(~0, SIF_PM_MASK));

?

Jan

#30 lore raw

PATCH v5 7/18 xen/cpufreq: disable px statistic info in amd-cppc mode

In reply to Penny Zheng

We want to bypass construction of px statistic info, while not bypassing cpufreq_statistic_lock initialization for a good reason, in cpufreq_statistic_init() for amd-cppc mode, as P-states is not necessary there.

---
v3 -> v4:
- remove unnecessary stub for cpufreq_statistic_exit()
---
v4 -> v5:
- refactor commit message

---
 xen/drivers/cpufreq/utility.c | 3 +++
 1 file changed, 3 insertions(+)
xen/drivers/cpufreq/utility.c +3 -0
index e690a484f1..b35e2eb1b6 100644
@@ -98,6 +98,9 @@ int cpufreq_statistic_init(unsigned int cpu)
     if ( !pmpt )
         return -EINVAL;
 
+    if ( !(pmpt->init & XEN_PX_INIT) )
+        return 0;
+
     spin_lock(cpufreq_statistic_lock);
 
     pxpt = per_cpu(cpufreq_statistic_data, cpu);
Signature · 1 line
2.34.1
#31 lore raw

Re: [PATCH v5 07/18] xen/cpufreq: disable px statistic info in amd-cppc mode

Quoted 6 lines · Penny Zheng

We want to bypass construction of px statistic info, while not bypassing cpufreq_statistic_lock initialization for a good reason, in cpufreq_statistic_init() for amd-cppc mode, as P-states is not necessary there.

I was considering to put this in together with patch 02 (if and when you confirmed that it can go in with the one hunk dropped), but then noticed that ...

xen/drivers/cpufreq/utility.c int cpufreq_statistic_init(unsigned int cpu) · line 102

Quoted 8 lines
xen/drivers/cpufreq/utility.c +2 -0
@@ -98,6 +98,9 @@ int cpufreq_statistic_init(unsigned int cpu)
     if ( !pmpt )
         return -EINVAL;
 
+    if ( !(pmpt->init & XEN_PX_INIT) )
+        return 0;

... this check is pointless with how things are right now (the same check living at the top of the sole caller). Hence I think this change should be folded into patch
04. Perhaps to be accompanied by a sentence why cpufreq_statistic_exit() doesn't need a similar guard.

Jan

#32 lore raw

PATCH v5 8/18 xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs

In reply to Penny Zheng

AMD Family 1Ah CPU needs a different COF(Core Operating Frequency) formula, due to a change in the PStateDef MSR layout in AMD Family 1Ah. In AMD Family 1Ah, Core current operating frequency in MHz is calculated as follows:

    CoreCOF = Core::X86::Msr::PStateDef[CpuFid[11:0]] * 5MHz

We introduce a helper amd_parse_freq() to parse COF(Core Operating Frequency) from PstateDef register, to replace the original macro FREQ(v). amd_parse_freq() is declared as const, as it mainly consists of mathematical conputation.

---
v2 -> v3:
- new commit
---
v3 -> v4:
- introduce amd_parse_freq() and declare it as const
- express if-else-arry() as switch()
---
v4 -> v5:
- change title from "fix xxx" to "expand xxx"
- change function parameter type and return type to "unsigned int"
- blank lines between non-fall-through case blocks

---
 xen/arch/x86/cpu/amd.c | 49 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 9 deletions(-)
xen/arch/x86/cpu/amd.c +40 -9
index 37d67dd15c..3770d75150 100644
@@ -583,12 +583,40 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           : c->cpu_core_id);
 }
 
+static unsigned int attr_const amd_parse_freq(unsigned int family,
+					      unsigned int value)
+{
+	unsigned int freq = 0;
+
+	switch (family) {
+	case 0x10 ... 0x16:
+		freq = (((value & 0x3f) + 0x10) * 100) >> ((value >> 6) & 7);
+		break;
+
+	case 0x17 ... 0x19:
+		freq = ((value & 0xff) * 25 * 8) / ((value >> 8) & 0x3f);
+		break;
+
+	case 0x1A:
+		freq = (value & 0xfff) * 5;
+		break;
+
+	default:
+		printk(XENLOG_ERR
+		       "Unsupported cpu family 0x%x on cpufreq parsing",
+		       family);
+		break;
+	}
+
+	return freq;
+}
+
 void amd_log_freq(const struct cpuinfo_x86 *c)
 {
 	unsigned int idx = 0, h;
 	uint64_t hi, lo, val;
 
-	if (c->x86 < 0x10 || c->x86 > 0x19 ||
+	if (c->x86 < 0x10 || c->x86 > 0x1A ||
 	    (c != &boot_cpu_data &&
 	     (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1)))))
 		return;
@@ -669,19 +697,22 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 	if (!(lo >> 63))
 		return;
 
-#define FREQ(v) (c->x86 < 0x17 ? ((((v) & 0x3f) + 0x10) * 100) >> (((v) >> 6) & 7) \
-		                     : (((v) & 0xff) * 25 * 8) / (((v) >> 8) & 0x3f))
 	if (idx && idx < h &&
 	    !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
 	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu (%lu ... %lu) MHz\n",
-		       smp_processor_id(), FREQ(val), FREQ(lo), FREQ(hi));
+		printk("CPU%u: %u (%u ... %u) MHz\n",
+		       smp_processor_id(),
+		       amd_parse_freq(c->x86, val),
+		       amd_parse_freq(c->x86, lo),
+		       amd_parse_freq(c->x86, hi));
 	else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %lu ... %lu MHz\n",
-		       smp_processor_id(), FREQ(lo), FREQ(hi));
+		printk("CPU%u: %u ... %u MHz\n",
+		       smp_processor_id(),
+		       amd_parse_freq(c->x86, lo),
+		       amd_parse_freq(c->x86, hi));
 	else
-		printk("CPU%u: %lu MHz\n", smp_processor_id(), FREQ(lo));
-#undef FREQ
+		printk("CPU%u: %u MHz\n", smp_processor_id(),
+		       amd_parse_freq(c->x86, lo));
 }
 
 void cf_check early_init_amd(struct cpuinfo_x86 *c)
Signature · 1 line
2.34.1
Reviewed-by on v5 8/18
#33 lore raw

Re: [PATCH v5 08/18] xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs

Quoted 18 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +12 -0
@@ -583,12 +583,40 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           : c->cpu_core_id);
 }
 
+static unsigned int attr_const amd_parse_freq(unsigned int family,
+					      unsigned int value)
+{
+	unsigned int freq = 0;
+
+	switch (family) {
+	case 0x10 ... 0x16:
+		freq = (((value & 0x3f) + 0x10) * 100) >> ((value >> 6) & 7);
+		break;
+
+	case 0x17 ... 0x19:
+		freq = ((value & 0xff) * 25 * 8) / ((value >> 8) & 0x3f);

xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 607

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+		break;
+
+	case 0x1A:
+		freq = (value & 0xfff) * 5;
+		break;
+
+	default:
+		printk(XENLOG_ERR
+		       "Unsupported cpu family 0x%x on cpufreq parsing",
+		       family);

I think I requested before (elsewhere) to prefer %#x over 0x%x.

However, why the log message? With ...

xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 619

Quoted 13 lines
xen/arch/x86/cpu/amd.c +7 -1
+		break;
+	}
+
+	return freq;
+}
+
 void amd_log_freq(const struct cpuinfo_x86 *c)
 {
 	unsigned int idx = 0, h;
 	uint64_t hi, lo, val;
 
-	if (c->x86 < 0x10 || c->x86 > 0x19 ||
+	if (c->x86 < 0x10 || c->x86 > 0x1A ||

... this condition, there simply could be ASSERT_UNREACHABLE() there? Happy to adjust while committing, so long as you agree. With the adjustment:

Jan

#34 lore raw

RE: [PATCH v5 08/18] xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs

[Public]

Quoted 54 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, June 12, 2025 9:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 08/18] xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs

Quoted 18 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +12 -0
@@ -583,12 +583,40 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           :
 c->cpu_core_id);  }
 
+static unsigned int attr_const amd_parse_freq(unsigned int family,
+                                         unsigned int value)
+{
+   unsigned int freq = 0;
+
+   switch (family) {
+   case 0x10 ... 0x16:
+           freq = (((value & 0x3f) + 0x10) * 100) >> ((value >> 6) & 7);
+           break;
+
+   case 0x17 ... 0x19:
+           freq = ((value & 0xff) * 25 * 8) / ((value >> 8) & 0x3f);

xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 607

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+           break;
+
+   case 0x1A:
+           freq = (value & 0xfff) * 5;
+           break;
+
+   default:
+           printk(XENLOG_ERR
+                  "Unsupported cpu family 0x%x on cpufreq parsing",
+                  family);

I think I requested before (elsewhere) to prefer %#x over 0x%x.

However, why the log message? With ...

Quoted 10 lines
xen/arch/x86/cpu/amd.c +6 -0
+           break;
+   }
+
+   return freq;
+}
+
 void amd_log_freq(const struct cpuinfo_x86 *c)  {
    unsigned int idx = 0, h;
    uint64_t hi, lo, val;
 
Quoted 7 lines

xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 619

Quoted 2 lines
xen/arch/x86/cpu/amd.c +1 -1
-   if (c->x86 < 0x10 || c->x86 > 0x19 ||
+   if (c->x86 < 0x10 || c->x86 > 0x1A ||

... this condition, there simply could be ASSERT_UNREACHABLE() there? Happy to adjust while committing, so long as you agree. With the adjustment:

Agreed, thx

Quoted 1 line

Jan

#35 lore raw

PATCH v5 9/18 xen/amd: introduce amd_process_freq() to get processor frequency

In reply to Penny Zheng

When _CPC table could not provide processor frequency range values for Xen governor, we need to read processor max frequency as anchor point.
So we extract amd cpu core frequency calculation logic from amd_log_freq(), and wrap it as a new helper amd_process_freq().

---
v1 -> v2:
- new commit
---
v3 -> v4
- introduce amd_process_freq()
---
v4 -> v5:
- make amd_process_freq() static to statisfy Misra demand
- change "low_mhz", "nom_mhz" and "hi_mhz" parameter to unsigned int
- fix order of logged frequencies

---
 xen/arch/x86/cpu/amd.c | 58 +++++++++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/amd.c +40 -18
index 3770d75150..8c985466fa 100644
@@ -611,14 +611,15 @@ static unsigned int attr_const amd_parse_freq(unsigned int family,
 	return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+static void amd_process_freq(const struct cpuinfo_x86 *c,
+			     unsigned int *low_mhz,
+			     unsigned int *nom_mhz,
+			     unsigned int *hi_mhz)
 {
 	unsigned int idx = 0, h;
 	uint64_t hi, lo, val;
 
-	if (c->x86 < 0x10 || c->x86 > 0x1A ||
-	    (c != &boot_cpu_data &&
-	     (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1)))))
+	if (c->x86 < 0x10 || c->x86 > 0x1A)
 		return;
 
 	if (c->x86 < 0x17) {
@@ -699,20 +700,20 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 
 	if (idx && idx < h &&
 	    !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
-	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %u (%u ... %u) MHz\n",
-		       smp_processor_id(),
-		       amd_parse_freq(c->x86, val),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %u ... %u MHz\n",
-		       smp_processor_id(),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else
-		printk("CPU%u: %u MHz\n", smp_processor_id(),
-		       amd_parse_freq(c->x86, lo));
+	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+		if (nom_mhz)
+			*nom_mhz = amd_parse_freq(c->x86, val);
+		if (low_mhz)
+			*low_mhz = amd_parse_freq(c->x86, lo);
+		if (hi_mhz)
+			*hi_mhz = amd_parse_freq(c->x86, hi);
+	} else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+		if (low_mhz)
+			*low_mhz = amd_parse_freq(c->x86, lo);
+		if (hi_mhz)
+			*hi_mhz = amd_parse_freq(c->x86, hi);
+	} else if (low_mhz)
+		*low_mhz = amd_parse_freq(c->x86, lo);
 }
 
 void cf_check early_init_amd(struct cpuinfo_x86 *c)
@@ -723,6 +724,27 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
 	ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)
+{
+	unsigned int low_mhz = 0, nom_mhz = 0, hi_mhz = 0;
+
+	if (c != &boot_cpu_data &&
+	    (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
+		return;
+
+	amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+	if (!low_mhz && !nom_mhz && !hi_mhz)
+		printk("CPU%u: %u (%u ... %u) MHz\n",
+		       smp_processor_id(),
+		       nom_mhz, low_mhz, hi_mhz);
+	else if (!low_mhz && !hi_mhz)
+		printk("CPU%u: %u ... %u MHz\n",
+		       smp_processor_id(), low_mhz, hi_mhz);
+	else if (!low_mhz)
+		printk("CPU%u: %u MHz\n", smp_processor_id(), low_mhz);
+}
+
 void amd_init_lfence(struct cpuinfo_x86 *c)
 {
 	uint64_t value;
Signature · 1 line
2.34.1
Reviewed-by on v5 9/18
#36 lore raw

Re: [PATCH v5 09/18] xen/amd: introduce amd_process_freq() to get processor frequency

Quoted 86 lines · Penny Zheng

When _CPC table could not provide processor frequency range values for Xen governor, we need to read processor max frequency as anchor point.
So we extract amd cpu core frequency calculation logic from amd_log_freq(), and wrap it as a new helper amd_process_freq().

---
v1 -> v2:
- new commit
---
v3 -> v4
- introduce amd_process_freq()
---
v4 -> v5:
- make amd_process_freq() static to statisfy Misra demand
- change "low_mhz", "nom_mhz" and "hi_mhz" parameter to unsigned int
- fix order of logged frequencies

---
 xen/arch/x86/cpu/amd.c | 58 +++++++++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/amd.c +20 -18
index 3770d75150..8c985466fa 100644
@@ -611,14 +611,15 @@ static unsigned int attr_const amd_parse_freq(unsigned int family,
 	return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+static void amd_process_freq(const struct cpuinfo_x86 *c,
+			     unsigned int *low_mhz,
+			     unsigned int *nom_mhz,
+			     unsigned int *hi_mhz)
 {
 	unsigned int idx = 0, h;
 	uint64_t hi, lo, val;
 
-	if (c->x86 < 0x10 || c->x86 > 0x1A ||
-	    (c != &boot_cpu_data &&
-	     (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1)))))
+	if (c->x86 < 0x10 || c->x86 > 0x1A)
 		return;
 
 	if (c->x86 < 0x17) {
@@ -699,20 +700,20 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 
 	if (idx && idx < h &&
 	    !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
-	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %u (%u ... %u) MHz\n",
-		       smp_processor_id(),
-		       amd_parse_freq(c->x86, val),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-		printk("CPU%u: %u ... %u MHz\n",
-		       smp_processor_id(),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else
-		printk("CPU%u: %u MHz\n", smp_processor_id(),
-		       amd_parse_freq(c->x86, lo));
+	    !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+		if (nom_mhz)
+			*nom_mhz = amd_parse_freq(c->x86, val);
+		if (low_mhz)
+			*low_mhz = amd_parse_freq(c->x86, lo);
+		if (hi_mhz)
+			*hi_mhz = amd_parse_freq(c->x86, hi);
+	} else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+		if (low_mhz)
+			*low_mhz = amd_parse_freq(c->x86, lo);
+		if (hi_mhz)
+			*hi_mhz = amd_parse_freq(c->x86, hi);
+	} else if (low_mhz)
+		*low_mhz = amd_parse_freq(c->x86, lo);
 }
 
 void cf_check early_init_amd(struct cpuinfo_x86 *c)
@@ -723,6 +724,27 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
 	ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)

xen/arch/x86/cpu/amd.c void cf_check early_init_amd(struct cpuinfo_x86 *c) · line 737

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+{
+	unsigned int low_mhz = 0, nom_mhz = 0, hi_mhz = 0;
+
+	if (c != &boot_cpu_data &&
+	    (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
+		return;
+
+	amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+	if (!low_mhz && !nom_mhz && !hi_mhz)

With this ...

xen/arch/x86/cpu/amd.c void cf_check early_init_amd(struct cpuinfo_x86 *c) · line 740

Quoted 3 lines
xen/arch/x86/cpu/amd.c +3 -0
+		printk("CPU%u: %u (%u ... %u) MHz\n",
+		       smp_processor_id(),
+		       nom_mhz, low_mhz, hi_mhz);

.. aren't you logging three zeroes here? Considering the earlier mistake of the order of logged frequencies, did you not think of looking at the resulting output in the hypervisor boot log?

Same issue again below then.

With all instances corrected:

Jan

#37 lore raw

PATCH v5 10/18 xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

In reply to Penny Zheng

amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which is a finer grain frequency management than legacy ACPI hardware P-States.
Current AMD CPU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states, while the new amd-cppc allows a more flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.

Default "amd-cppc" driver still leverages Xen governors such as *ondemand*, *performance*, etc, to calculate the performance hints. In the future, we will introduce an advanced active mode to enable autonomous performence level selection.

---
v1 -> v2:
- re-construct union caps and req to have anonymous struct instead
- avoid "else" when the earlier if() ends in an unconditional control flow statement
- Add check to avoid chopping off set bits from cast
- make pointers pointer-to-const wherever possible
- remove noisy log
- exclude families before 0x17 before CPPC-feature MSR op
- remove useless variable helpers
- use xvzalloc and XVFREE
- refactor error handling as ENABLE bit can only be cleared by reset
---
v2 -> v3:
- Move all MSR-definations to msr-index.h and follow the required style
- Refactor opening figure braces for struct/union
- Sort overlong lines throughout the series
- Make offset/res int covering underflow scenario
- Error out when amd_max_freq_mhz isn't set
- Introduce amd_get_freq(name) macro to decrease redundancy
- Supported CPU family checked ahead of smp-function
- Nominal freq shall be checked between the [min, max]
- Use APERF/MPREF to calculate current frequency
- Use amd_cppc_cpufreq_cpu_exit() to tidy error path
---
v3 -> v4:
- verbose print shall come with a CPU number
- deal with res <= 0 in amd_cppc_khz_to_perf()
- introduce a single helper amd_get_lowest_or_nominal_freq() to cover both lowest and nominal scenario
- reduce abuse of wrmsr_safe()/rdmsr_safe() with wrmsrl()/rdmsrl()
- move cf_check from amd_cppc_write_request() to amd_cppc_write_request_msrs()
- add comment to explain why setting non_linear_lowest in passive mode
- add check to ensure perf values in
lowest <= non_linear_lowest <= nominal <= highset
- refactor comment for "data->err != 0" scenario
- use "data->err" instead of -ENODEV
- add U suffixes for all msr macro
---
v4 -> v5:
- all freq-values shall be unsigned int type
- remove shortcuts as it is rarely taken
- checking cpc.nominal_mhz and cpc.lowest_mhz are non-zero values is enough
- drop the explicit type cast
- null pointer check is in no need for internal functions
- change amd_get_lowest_or_nominal_freq() to amd_get_cpc_freq()
- clarifying function-wide that the calculated frequency result is to be in kHz
- use array notation
- with cpu_has_cppc check, no need to do cpu family check

---
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 362 +++++++++++++++++++++++++++
 xen/arch/x86/cpu/amd.c               |   8 +-
 xen/arch/x86/include/asm/amd.h       |   2 +
 xen/arch/x86/include/asm/msr-index.h |   5 +
 4 files changed, 373 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +362 -0
index 9e64bf957a..8f0a30c19d 100644
@@ -14,7 +14,56 @@
 #include <xen/domain.h>
 #include <xen/init.h>
 #include <xen/param.h>
+#include <xen/percpu.h>
+#include <xen/xvmalloc.h>
 #include <acpi/cpufreq/cpufreq.h>
+#include <asm/amd.h>
+#include <asm/msr-index.h>
+
+#define amd_cppc_err(cpu, fmt, args...)                             \
+    printk(XENLOG_ERR "AMD_CPPC: CPU%u error: " fmt, cpu, ## args)
+#define amd_cppc_warn(cpu, fmt, args...)                            \
+    printk(XENLOG_WARNING "AMD_CPPC: CPU%u warning: " fmt, cpu, ## args)
+#define amd_cppc_verbose(cpu, fmt, args...)                         \
+({                                                                  \
+    if ( cpufreq_verbose )                                          \
+        printk(XENLOG_DEBUG "AMD_CPPC: CPU%u " fmt, cpu, ## args);  \
+})
+
+struct amd_cppc_drv_data
+{
+    const struct xen_processor_cppc *cppc_data;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int lowest_perf:8;
+            unsigned int lowest_nonlinear_perf:8;
+            unsigned int nominal_perf:8;
+            unsigned int highest_perf:8;
+            unsigned int :32;
+        };
+    } caps;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int max_perf:8;
+            unsigned int min_perf:8;
+            unsigned int des_perf:8;
+            unsigned int epp:8;
+            unsigned int :32;
+        };
+    } req;
+
+    int err;
+};
+
+static DEFINE_PER_CPU_READ_MOSTLY(struct amd_cppc_drv_data *,
+                                  amd_cppc_drv_data);
+/*
+ * Core max frequency read from PstateDef as anchor point
+ * for freq-to-perf transition
+ */
+static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, pxfreq_mhz);
 
 static bool __init amd_cppc_handle_option(const char *s, const char *end)
 {
@@ -50,10 +99,323 @@ int __init amd_cppc_cmdline_parse(const char *s, const char *e)
     return 0;
 }
 
+/*
+ * If CPPC lowest_freq and nominal_freq registers are exposed then we can
+ * use them to convert perf to freq and vice versa. The conversion is
+ * extrapolated as an linear function passing by the 2 points:
+ *  - (Low perf, Low freq)
+ *  - (Nominal perf, Nominal freq)
+ * Parameter freq is always in kHz.
+ */
+static int amd_cppc_khz_to_perf(const struct amd_cppc_drv_data *data,
+                                unsigned int freq, uint8_t *perf)
+{
+    const struct xen_processor_cppc *cppc_data = data->cppc_data;
+    unsigned int mul, div;
+    int offset = 0, res;
+
+    if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz )
+    {
+        mul = data->caps.nominal_perf - data->caps.lowest_perf;
+        div = cppc_data->cpc.nominal_mhz - cppc_data->cpc.lowest_mhz;
+
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;
+    }
+
+    res = offset + (mul * freq) / (div * 1000);
+    if ( res > UINT8_MAX )
+    {
+        printk_once(XENLOG_WARNING
+                    "Perf value exceeds maximum value 255: %d\n", res);
+        *perf = 0xff;
+        return 0;
+    }
+    if ( res < 0 )
+    {
+        printk_once(XENLOG_WARNING
+                    "Perf value smaller than minimum value 0: %d\n", res);
+        *perf = 0;
+        return 0;
+    }
+    *perf = res;
+
+    return 0;
+}
+
+/*
+ * _CPC may define nominal frequecy and lowest frequency, if not, use
+ * Processor Max Speed as anchor point to calculate.
+ * Output freq stores cpc frequency in kHz
+ */
+static int amd_get_cpc_freq(const struct amd_cppc_drv_data *data,
+                            uint32_t cpc_mhz, uint8_t perf, unsigned int *freq)
+{
+    unsigned int mul, div, res;
+
+    if ( cpc_mhz )
+    {
+        /* Switch to kHz */
+        *freq = cpc_mhz * 1000;
+        return 0;
+    }
+
+    /* Read Processor Max Speed(MHz) as anchor point */
+    mul = this_cpu(pxfreq_mhz);
+    if ( !mul )
+    {
+        printk_once(XENLOG_ERR
+                    "Failed to read valid processor max frequency as anchor point: %u\n",
+                    mul);
+        return -EINVAL;
+    }
+    div = data->caps.highest_perf;
+    res = (mul * perf * 1000) / div;
+    if ( !res )
+        return -EINVAL;
+    *freq = res;
+
+    return 0;
+}
+
+/* Output max_freq stores calculated maximum frequency in kHz */
+static int amd_get_max_freq(const struct amd_cppc_drv_data *data,
+                            unsigned int *max_freq)
+{
+    unsigned int nom_freq = 0;
+    int res;
+
+    res = amd_get_cpc_freq(data, data->cppc_data->cpc.nominal_mhz,
+                           data->caps.nominal_perf, &nom_freq);
+    if ( res )
+        return res;
+
+    *max_freq = (data->caps.highest_perf * nom_freq) / data->caps.nominal_perf;
+
+    return 0;
+}
+
+static int cf_check amd_cppc_cpufreq_verify(struct cpufreq_policy *policy)
+{
+    cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
+                                 policy->cpuinfo.max_freq);
+
+    return 0;
+}
+
+static void cf_check amd_cppc_write_request_msrs(void *info)
+{
+    const struct amd_cppc_drv_data *data = info;
+
+    wrmsrl(MSR_AMD_CPPC_REQ, data->req.raw);
+}
+
+static void amd_cppc_write_request(unsigned int cpu, uint8_t min_perf,
+                                   uint8_t des_perf, uint8_t max_perf)
+{
+    struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint64_t prev = data->req.raw;
+
+    data->req.min_perf = min_perf;
+    data->req.max_perf = max_perf;
+    data->req.des_perf = des_perf;
+
+    if ( prev == data->req.raw )
+        return;
+
+    on_selected_cpus(cpumask_of(cpu), amd_cppc_write_request_msrs, data, 1);
+}
+
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation)
+{
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);
+    return 0;
+}
+
+static void cf_check amd_cppc_init_msrs(void *info)
+{
+    struct cpufreq_policy *policy = info;
+    struct amd_cppc_drv_data *data = this_cpu(amd_cppc_drv_data);
+    uint64_t val;
+    unsigned int min_freq = 0, nominal_freq = 0, max_freq;
+
+    /* Package level MSR */
+    rdmsrl(MSR_AMD_CPPC_ENABLE, val);
+    /*
+     * Only when Enable bit is on, the hardware will calculate the processor’s
+     * performance capabilities and initialize the performance level fields in
+     * the CPPC capability registers.
+     */
+    if ( !(val & AMD_CPPC_ENABLE) )
+    {
+        val |= AMD_CPPC_ENABLE;
+        wrmsrl(MSR_AMD_CPPC_ENABLE, val);
+    }
+
+    rdmsrl(MSR_AMD_CPPC_CAP1, data->caps.raw);
+
+    if ( data->caps.highest_perf == 0 || data->caps.lowest_perf == 0 ||
+         data->caps.nominal_perf == 0 || data->caps.lowest_nonlinear_perf == 0 ||
+         data->caps.lowest_perf > data->caps.nominal_perf ||
+         data->caps.lowest_nonlinear_perf > data->caps.nominal_perf ||
+         data->caps.nominal_perf > data->caps.highest_perf )
+    {
+        amd_cppc_err(policy->cpu,
+                     "Out of range values: highest(%u), lowest(%u), nominal(%u), lowest_nonlinear(%u)\n",
+                     data->caps.highest_perf, data->caps.lowest_perf,
+                     data->caps.nominal_perf, data->caps.lowest_nonlinear_perf);
+        goto err;
+    }
+
+    amd_process_freq(&cpu_data[policy->cpu],
+                     NULL, NULL, &this_cpu(pxfreq_mhz));
+
+    data->err = amd_get_cpc_freq(data, data->cppc_data->cpc.lowest_mhz,
+                                 data->caps.lowest_perf, &min_freq);
+    if ( data->err )
+        return;
+
+    data->err = amd_get_cpc_freq(data, data->cppc_data->cpc.nominal_mhz,
+                                 data->caps.nominal_perf, &nominal_freq);
+    if ( data->err )
+        return;
+
+    data->err = amd_get_max_freq(data, &max_freq);
+    if ( data->err )
+        return;
+
+    if ( min_freq > nominal_freq || nominal_freq > max_freq )
+    {
+        amd_cppc_err(policy->cpu,
+                     "min(%u), or max(%u), or nominal(%u) freq value is incorrect\n",
+                     min_freq, max_freq, nominal_freq);
+        goto err;
+    }
+
+    policy->min = min_freq;
+    policy->max = max_freq;
+
+    policy->cpuinfo.min_freq = min_freq;
+    policy->cpuinfo.max_freq = max_freq;
+    policy->cpuinfo.perf_freq = nominal_freq;
+    /*
+     * Set after policy->cpuinfo.perf_freq, as we are taking
+     * APERF/MPERF average frequency as current frequency.
+     */
+    policy->cur = cpufreq_driver_getavg(policy->cpu, GOV_GETAVG);
+
+    return;
+
+ err:
+    /*
+     * No fallback shceme is available here, see more explanation at call
+     * site in amd_cppc_cpufreq_cpu_init().
+     */
+    data->err = -EINVAL;
+}
+
+/*
+ * AMD CPPC driver is different than legacy ACPI hardware P-State,
+ * which has a finer grain frequency range between the highest and lowest
+ * frequency. And boost frequency is actually the frequency which is mapped on
+ * highest performance ratio. The legacy P0 frequency is actually mapped on
+ * nominal performance ratio.
+ */
+static void amd_cppc_boost_init(struct cpufreq_policy *policy,
+                                const struct amd_cppc_drv_data *data)
+{
+    if ( data->caps.highest_perf <= data->caps.nominal_perf )
+        return;
+
+    policy->turbo = CPUFREQ_TURBO_ENABLED;
+}
+
+static int cf_check amd_cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy)
+{
+    XVFREE(per_cpu(amd_cppc_drv_data, policy->cpu));
+
+    return 0;
+}
+
+static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
+{
+    unsigned int cpu = policy->cpu;
+    struct amd_cppc_drv_data *data;
+
+    data = xvzalloc(struct amd_cppc_drv_data);
+    if ( !data )
+        return -ENOMEM;
+
+    data->cppc_data = &processor_pminfo[cpu]->cppc_data;
+
+    per_cpu(amd_cppc_drv_data, cpu) = data;
+
+    on_selected_cpus(cpumask_of(cpu), amd_cppc_init_msrs, policy, 1);
+
+    /*
+     * The enable bit is sticky, as we need to enable it at the very first
+     * begining, before CPPC capability values sanity check.
+     * If error path takes effective, not only amd-cppc cpufreq core fails
+     * to initialize, but also we could not fall back to legacy P-states
+     * driver, irrespective of the command line specifying a fallback option.
+     */
+    if ( data->err )
+    {
+        amd_cppc_err(cpu, "Could not initialize cpufreq cores in CPPC mode\n");
+        amd_cppc_cpufreq_cpu_exit(policy);
+        return data->err;
+    }
+
+    policy->governor = cpufreq_opt_governor ? : CPUFREQ_DEFAULT_GOVERNOR;
+
+    amd_cppc_boost_init(policy, data);
+
+    amd_cppc_verbose(policy->cpu,
+                     "CPU initialized with amd-cppc passive mode\n");
+
+    return 0;
+}
+
 static const struct cpufreq_driver __initconst_cf_clobber
 amd_cppc_cpufreq_driver =
 {
     .name   = XEN_AMD_CPPC_DRIVER_NAME,
+    .verify = amd_cppc_cpufreq_verify,
+    .target = amd_cppc_cpufreq_target,
+    .init   = amd_cppc_cpufreq_cpu_init,
+    .exit   = amd_cppc_cpufreq_cpu_exit,
 };
 
 int __init amd_cppc_register_driver(void)
xen/arch/x86/cpu/amd.c +4 -4
index 8c985466fa..7ec154e9e7 100644
@@ -611,10 +611,10 @@ static unsigned int attr_const amd_parse_freq(unsigned int family,
 	return freq;
 }
 
-static void amd_process_freq(const struct cpuinfo_x86 *c,
-			     unsigned int *low_mhz,
-			     unsigned int *nom_mhz,
-			     unsigned int *hi_mhz)
+void amd_process_freq(const struct cpuinfo_x86 *c,
+		      unsigned int *low_mhz,
+		      unsigned int *nom_mhz,
+		      unsigned int *hi_mhz)
 {
 	unsigned int idx = 0, h;
 	uint64_t hi, lo, val;
xen/arch/x86/include/asm/amd.h +2 -0
index 9c9599a622..72df42a6f6 100644
@@ -173,5 +173,7 @@ extern bool amd_virt_spec_ctrl;
 bool amd_setup_legacy_ssbd(void);
 void amd_set_legacy_ssbd(bool enable);
 void amd_set_cpuid_user_dis(bool enable);
+void amd_process_freq(const struct cpuinfo_x86 *c, unsigned int *low_mhz,
+                      unsigned int *nom_mhz, unsigned int *hi_mhz);
 
 #endif /* __AMD_H__ */
xen/arch/x86/include/asm/msr-index.h +5 -0
index 22d9e76e55..e4401186c7 100644
@@ -238,6 +238,11 @@
 
 #define MSR_AMD_CSTATE_CFG                  0xc0010296U
 
+#define MSR_AMD_CPPC_CAP1                   0xc00102b0U
+#define MSR_AMD_CPPC_ENABLE                 0xc00102b1U
+#define  AMD_CPPC_ENABLE                    (_AC(1, ULL) << 0)
+#define MSR_AMD_CPPC_REQ                    0xc00102b3U
+
 /*
  * Legacy MSR constants in need of cleanup.  No new MSRs below this comment.
  */
Signature · 1 line
2.34.1
#38 lore raw

Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 11 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4 -0
@@ -14,7 +14,56 @@
 #include <xen/domain.h>
 #include <xen/init.h>
 #include <xen/param.h>
+#include <xen/percpu.h>
+#include <xen/xvmalloc.h>
 #include <acpi/cpufreq/cpufreq.h>
+#include <asm/amd.h>
+#include <asm/msr-index.h>

xen/arch/x86/acpi/cpufreq/amd-cppc.c line 31

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+
+#define amd_cppc_err(cpu, fmt, args...)                             \
+    printk(XENLOG_ERR "AMD_CPPC: CPU%u error: " fmt, cpu, ## args)
+#define amd_cppc_warn(cpu, fmt, args...)                            \
+    printk(XENLOG_WARNING "AMD_CPPC: CPU%u warning: " fmt, cpu, ## args)
+#define amd_cppc_verbose(cpu, fmt, args...)                         \
+({                                                                  \
+    if ( cpufreq_verbose )                                          \
+        printk(XENLOG_DEBUG "AMD_CPPC: CPU%u " fmt, cpu, ## args);  \
+})

Nit: Much like in the file name, would you mind using AMD-CPPC in favor of AMD_CPPC here, too?

Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9 -0
@@ -50,10 +99,323 @@ int __init amd_cppc_cmdline_parse(const char *s, const char *e)
     return 0;
 }
 
+/*
+ * If CPPC lowest_freq and nominal_freq registers are exposed then we can
+ * use them to convert perf to freq and vice versa. The conversion is
+ * extrapolated as an linear function passing by the 2 points:
+ *  - (Low perf, Low freq)
+ *  - (Nominal perf, Nominal freq)
+ * Parameter freq is always in kHz.
+ */
+static int amd_cppc_khz_to_perf(const struct amd_cppc_drv_data *data,

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 120

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+                                unsigned int freq, uint8_t *perf)
+{
+    const struct xen_processor_cppc *cppc_data = data->cppc_data;
+    unsigned int mul, div;
+    int offset = 0, res;
+
+    if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz )
+    {
+        mul = data->caps.nominal_perf - data->caps.lowest_perf;
+        div = cppc_data->cpc.nominal_mhz - cppc_data->cpc.lowest_mhz;

What guarantees both of these values to be non-zero?

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 136

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;

What's wrong about the function arguments in this case? (Same question again on further uses of EINVAL below.)

Quoted 12 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +12 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation)
+{
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9 -0
+static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
+{
+    unsigned int cpu = policy->cpu;
+    struct amd_cppc_drv_data *data;
+
+    data = xvzalloc(struct amd_cppc_drv_data);
+    if ( !data )
+        return -ENOMEM;
+

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 390

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    data->cppc_data = &processor_pminfo[cpu]->cppc_data;
+
+    per_cpu(amd_cppc_drv_data, cpu) = data;
+
+    on_selected_cpus(cpumask_of(cpu), amd_cppc_init_msrs, policy, 1);
+
+    /*
+     * The enable bit is sticky, as we need to enable it at the very first
+     * begining, before CPPC capability values sanity check.
+     * If error path takes effective, not only amd-cppc cpufreq core fails

Nit: "takes effect" or "is taken".

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 396

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6 -0
+     * to initialize, but also we could not fall back to legacy P-states
+     * driver, irrespective of the command line specifying a fallback option.
+     */
+    if ( data->err )
+    {
+        amd_cppc_err(cpu, "Could not initialize cpufreq cores in CPPC mode\n");

Why "cores" (plural)?

Jan

#39 lore raw

RE: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

[Public]

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 12 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 136

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;

What's wrong about the function arguments in this case? (Same question again on further uses of EINVAL below.)

If we could not get processor max frequency, the whole function is useless... Maybe -EOPNOTSUPP is more suitable than -EINVAL;

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +16 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

How about

```
Choose lowest nonlinear performance as the minimum performance level at which the platform may run.
Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved,
Above this threshold, lower performance levels should be generally more energy efficient than higher performance levels.
```
Quoted 2 lines

Jan

#40 lore raw

RE: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

[Public]

Quoted 75 lines

-----Original Message-----
From: Penny, Zheng
Sent: Wednesday, July 2, 2025 5:49 PM
To: Jan Beulich <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: RE: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 12 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 136

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;

What's wrong about the function arguments in this case? (Same question again on further uses of EINVAL below.)

If we could not get processor max frequency, the whole function is useless... Maybe -EOPNOTSUPP is more suitable than -EINVAL;

Quoted 5 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e)

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data,

cpu);

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

Quoted 8 lines

How about

```
Choose lowest nonlinear performance as the minimum performance level at which
the platform may run.
Lowest nonlinear performance is the lowest performance level at which nonlinear
power savings are achieved, Above this threshold, lower performance levels should
be generally more energy efficient than higher performance levels.
```

I'm adding a few more explanation on highest performance too

```
Choose lowest nonlinear performance as the minimum performance level, and highest performance as the maximum performance level.
Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved, Above this threshold, lower
performance levels should be generally more energy efficient than higher performance levels.
And highest performance is the absolute maximum performance an individual processor may reach, assuming ideal conditions.
```
Quoted 2 lines
Quoted 2 lines

Jan

#41 lore raw

Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

In reply to Penny, Zheng
Quoted 27 lines · Zheng
Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>

Quoted 12 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 136

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;

What's wrong about the function arguments in this case? (Same question again on further uses of EINVAL below.)

Quoted 2 lines

If we could not get processor max frequency, the whole function is useless... Maybe -EOPNOTSUPP is more suitable than -EINVAL;

I don't like EOPNOTSUPP very much either for the purpose, but it's surely better than EINVAL.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +16 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

Quoted 6 lines

How about

```
Choose lowest nonlinear performance as the minimum performance level at which the platform may run.
Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved,
Above this threshold, lower performance levels should be generally more energy efficient than higher performance levels.
```

I finally had to go to the ACPI spec to understand what this is about. There looks to be an implication that lowest <= lowest_nonlinear, and states in that range would correspond more to T-states than to P-states. With that I think I agree with the use of lowest_nonlinear here. The comment, however, could do with moving farther away from merely quoting the pretty abstract text in the ACPI spec, as such quoting doesn't help in clarifying terminology used, when that terminology also isn't explained anywhere else in the code base.

Jan

#42 lore raw

RE: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

[Public]

Quoted 74 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 2, 2025 6:48 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 27 lines · Zheng
Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>

Quoted 12 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        /*
+         * We don't need to convert to kHz for computing offset and can
+         * directly use nominal_mhz and lowest_mhz as the division
+         * will remove the frequency unit.
+         */
+        offset = data->caps.nominal_perf -
+                 (mul * cppc_data->cpc.nominal_mhz) / div;
+    }
+    else
+    {
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 136

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+        /* Read Processor Max Speed(MHz) as anchor point */
+        mul = data->caps.highest_perf;
+        div = this_cpu(pxfreq_mhz);
+        if ( !div )
+            return -EINVAL;

What's wrong about the function arguments in this case? (Same question again on further uses of EINVAL below.)

Quoted 2 lines

If we could not get processor max frequency, the whole function is useless... Maybe -EOPNOTSUPP is more suitable than -EINVAL;

I don't like EOPNOTSUPP very much either for the purpose, but it's surely better than EINVAL.

Quoted 5 lines
Quoted 5 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e)

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data,

cpu);

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

Quoted 3 lines

How about
```
Choose lowest nonlinear performance as the minimum performance level at which

the platform may run.

Quoted 8 lines
Quoted 2 lines

Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved, Above this threshold, lower performance

levels should be generally more energy efficient than higher performance levels.

Quoted 1 line

```

I finally had to go to the ACPI spec to understand what this is about. There looks to be an implication that lowest <= lowest_nonlinear, and states in that range would correspond more to T-states than to P-states. With that I think I agree with the use

Yes, It doesn't have definitive conclusion about relation between lowest and lowest_nonlinear In our internal FW designed spec, it always shows lowest_nonlinear corresponds to P2

Quoted 4 lines

of lowest_nonlinear here. The comment, however, could do with moving farther away from merely quoting the pretty abstract text in the ACPI spec, as such quoting doesn't help in clarifying terminology used, when that terminology also isn't explained anywhere else in the code base.

How about we add detailed explanations about each terminology in the beginning declaration , see:

```
+/*
+ * Field highest_perf, nominal_perf, lowest_nonlinear_perf, and lowest_perf
+ * contain the values read from CPPC capability MSR.
+ * Field highest_perf represents highest performance, which is the absolute
+ * maximum performance an individual processor may reach, assuming ideal
+ * conditions
+ * Field nominal_perf represents maximum sustained performance level of the
+ * processor, assuming ideal operating conditions.
+ * Field lowest_nonlinear_perf represents Lowest Nonlinear Performance, which
+ * is the lowest performance level at which nonlinear power savings are
+ * achieved. Above this threshold, lower performance levels should be
+ * generally more energy efficient than higher performance levels.
+ * Field lowest_perf represents the absolute lowest performance level of the
+ * platform.
+ *
+ * Field max_perf, min_perf, des_perf store the values for CPPC request MSR.
+ * Field max_perf conveys the maximum performance level at which the platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive.
+ * Field min_perf conveys the minimum performance level at which the platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive but must be less than or equal to
+ * max_perf.
+ * Field des_perf conveys performance level Xen is requesting. And it may be
+ * set to any performance value in the range [min_perf, max_perf], inclusive.
+ */
+struct amd_cppc_drv_data
+{
+    const struct xen_processor_cppc *cppc_data;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int lowest_perf:8;
+            unsigned int lowest_nonlinear_perf:8;
+            unsigned int nominal_perf:8;
+            unsigned int highest_perf:8;
+            unsigned int :32;
+        };
+    } caps;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int max_perf:8;
+            unsigned int min_perf:8;
+            unsigned int des_perf:8;
+            unsigned int epp:8;
+            unsigned int :32;
+        };
+    } req;
+
+    int err;
+};
``
Then here, we could elaborate the reason why we choose lowest_nonlinear_perf over lowest_perf:
```
+    /*
+     * Having a performance level lower than the lowest nonlinear
+     * performance level, such as, lowest_perf <= perf <= lowest_nonliner_perf,
+     * may actually cause an efficiency penalty, So when deciding the min_perf
+     * value, we prefer lowest nonlinear performance over lowest performance
+     */

+ amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+ des_perf, data->caps.highest_perf);
```

Quoted 2 lines

Jan

#43 lore raw

Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 59 lines · Zheng
Quoted 41 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 2, 2025 6:48 PM

Quoted 11 lines · Zheng
Quoted 11 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>

Quoted 5 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data,

cpu);

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
+    if ( res )
+        return res;
+
+    /*
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 263

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

Quoted 3 lines

How about
```
Choose lowest nonlinear performance as the minimum performance level at which

the platform may run.

Quoted 8 lines
Quoted 2 lines

Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved, Above this threshold, lower performance

levels should be generally more energy efficient than higher performance levels.

Quoted 1 line

```

I finally had to go to the ACPI spec to understand what this is about. There looks to be an implication that lowest <= lowest_nonlinear, and states in that range would correspond more to T-states than to P-states. With that I think I agree with the use

Yes, It doesn't have definitive conclusion about relation between lowest and lowest_nonlinear In our internal FW designed spec, it always shows lowest_nonlinear corresponds to P2

Quoted 4 lines

of lowest_nonlinear here. The comment, however, could do with moving farther away from merely quoting the pretty abstract text in the ACPI spec, as such quoting doesn't help in clarifying terminology used, when that terminology also isn't explained anywhere else in the code base.

Quoted 15 lines

How about we add detailed explanations about each terminology in the beginning declaration , see:
```
+/*
+ * Field highest_perf, nominal_perf, lowest_nonlinear_perf, and lowest_perf
+ * contain the values read from CPPC capability MSR.
+ * Field highest_perf represents highest performance, which is the absolute
+ * maximum performance an individual processor may reach, assuming ideal
+ * conditions
+ * Field nominal_perf represents maximum sustained performance level of the
+ * processor, assuming ideal operating conditions.
+ * Field lowest_nonlinear_perf represents Lowest Nonlinear Performance, which
+ * is the lowest performance level at which nonlinear power savings are
+ * achieved. Above this threshold, lower performance levels should be
+ * generally more energy efficient than higher performance levels.

Which is still only the vague statement also found in the spec. This says nothing about what happens below that level, or what the relationship to other fields is.

Quoted 51 lines

+ * Field lowest_perf represents the absolute lowest performance level of the
+ * platform.
+ *
+ * Field max_perf, min_perf, des_perf store the values for CPPC request MSR.
+ * Field max_perf conveys the maximum performance level at which the platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive.
+ * Field min_perf conveys the minimum performance level at which the platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive but must be less than or equal to
+ * max_perf.
+ * Field des_perf conveys performance level Xen is requesting. And it may be
+ * set to any performance value in the range [min_perf, max_perf], inclusive.
+ */

xen/arch/x86/acpi/cpufreq/amd-cppc.c +26 -0
+struct amd_cppc_drv_data
+{
+    const struct xen_processor_cppc *cppc_data;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int lowest_perf:8;
+            unsigned int lowest_nonlinear_perf:8;
+            unsigned int nominal_perf:8;
+            unsigned int highest_perf:8;
+            unsigned int :32;
+        };
+    } caps;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int max_perf:8;
+            unsigned int min_perf:8;
+            unsigned int des_perf:8;
+            unsigned int epp:8;
+            unsigned int :32;
+        };
+    } req;
+
+    int err;
+};

``
Then here, we could elaborate the reason why we choose lowest_nonlinear_perf over lowest_perf:
```

xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    /*
+     * Having a performance level lower than the lowest nonlinear
+     * performance level, such as, lowest_perf <= perf <= lowest_nonliner_perf,
+     * may actually cause an efficiency penalty, So when deciding the min_perf
+     * value, we prefer lowest nonlinear performance over lowest performance
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);
Quoted 1 line

```

This reads fine to me.

Question then is though: Is setting lowest_perf as the low boundary a good idea in any of the places? (Iirc it is used in one or two places. Or am I misremembering?)

Jan

#44 lore raw

RE: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

[Public]

Quoted 160 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 2:21 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 76 lines · Zheng
Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 2, 2025 6:48 PM

Quoted 5 lines · Zheng
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>

Quoted 7 lines
Quoted 7 lines · Penny Zheng

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e)

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data =
+per_cpu(amd_cppc_drv_data,

cpu);

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7 -0
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
Quoted 8 lines
Quoted 8 lines

xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e)

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    if ( res )
+        return res;
+
+    /*
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data-

caps.lowest_nonlinear_perf,

Quoted 13 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+ des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

How about
```
Choose lowest nonlinear performance as the minimum performance level at which

the platform may run.

Quoted 3 lines

Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved, Above this threshold, lower performance

Quoted 7 lines

levels should be generally more energy efficient than higher performance levels.

Quoted 1 line

```

I finally had to go to the ACPI spec to understand what this is about. There looks to be an implication that lowest <= lowest_nonlinear, and states in that range would correspond more to T-states than to P-states. With that I think I agree with the use

Yes, It doesn't have definitive conclusion about relation between lowest and lowest_nonlinear In our internal FW designed spec, it always shows lowest_nonlinear corresponds to P2

Quoted 4 lines

of lowest_nonlinear here. The comment, however, could do with moving farther away from merely quoting the pretty abstract text in the ACPI spec, as such quoting doesn't help in clarifying terminology used, when that terminology also isn't explained anywhere else in the code base.

How about we add detailed explanations about each terminology in the beginning declaration , see:
```

(quoted diff) +8 -0
+/*
+ * Field highest_perf, nominal_perf, lowest_nonlinear_perf, and
+lowest_perf
+ * contain the values read from CPPC capability MSR.
+ * Field highest_perf represents highest performance, which is the
+absolute
+ * maximum performance an individual processor may reach, assuming
+ideal

Review

Quoted 10 lines
(quoted diff) +10 -0
+ * conditions
+ * Field nominal_perf represents maximum sustained performance level
+of the
+ * processor, assuming ideal operating conditions.
+ * Field lowest_nonlinear_perf represents Lowest Nonlinear
+Performance, which
+ * is the lowest performance level at which nonlinear power savings
+are
+ * achieved. Above this threshold, lower performance levels should be
+ * generally more energy efficient than higher performance levels.

Which is still only the vague statement also found in the spec. This says nothing about what happens below that level, or what the relationship to other fields is.

Quoted 45 lines

+ * Field lowest_perf represents the absolute lowest performance level

xen/arch/x86/acpi/cpufreq/amd-cppc.c +44 -0
+of the
+ * platform.
+ *
+ * Field max_perf, min_perf, des_perf store the values for CPPC request MSR.
+ * Field max_perf conveys the maximum performance level at which the
+platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive.
+ * Field min_perf conveys the minimum performance level at which the
+platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive but must be less than or
+equal to
+ * max_perf.
+ * Field des_perf conveys performance level Xen is requesting. And it
+may be
+ * set to any performance value in the range [min_perf, max_perf], inclusive.
+ */
+struct amd_cppc_drv_data
+{
+    const struct xen_processor_cppc *cppc_data;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int lowest_perf:8;
+            unsigned int lowest_nonlinear_perf:8;
+            unsigned int nominal_perf:8;
+            unsigned int highest_perf:8;
+            unsigned int :32;
+        };
+    } caps;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int max_perf:8;
+            unsigned int min_perf:8;
+            unsigned int des_perf:8;
+            unsigned int epp:8;
+            unsigned int :32;
+        };
+    } req;
+
+    int err;
+};
Quoted 2 lines

``
Then here, we could elaborate the reason why we choose lowest_nonlinear_perf

over lowest_perf:

Quoted 10 lines

```

xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    /*
+     * Having a performance level lower than the lowest nonlinear
+     * performance level, such as, lowest_perf <= perf <= lowest_nonliner_perf,
+     * may actually cause an efficiency penalty, So when deciding the min_perf
+     * value, we prefer lowest nonlinear performance over lowest performance
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

```

Quoted 5 lines

This reads fine to me.

Question then is though: Is setting lowest_perf as the low boundary a good idea in any of the places? (Iirc it is used in one or two places. Or am I misremembering?)

Yes, in active mode, I choose lowest_perf as min_perf to try to extend the limitation for active(autonomous) mode Maybe it is not a good choice. Maybe cpufreq driver is limited to do performance tuning in P-states range.

Quoted 2 lines

Jan

#45 lore raw

Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 162 lines · Zheng

[Public]

Quoted 160 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 2:21 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 10/18] xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling

Quoted 76 lines · Zheng
Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 2, 2025 6:48 PM

Quoted 5 lines · Zheng
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>

Quoted 7 lines
Quoted 7 lines · Penny Zheng

Review

Quoted 6 lines
(quoted diff) +6 -0
+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
+                                            unsigned int target_freq,
+                                            unsigned int relation) {
+    unsigned int cpu = policy->cpu;
+    const struct amd_cppc_drv_data *data =
+per_cpu(amd_cppc_drv_data,

cpu);

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7 -0
+    uint8_t des_perf;
+    int res;
+
+    if ( unlikely(!target_freq) )
+        return 0;
+
+    res = amd_cppc_khz_to_perf(data, target_freq, &des_perf);
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+    if ( res )
+        return res;
+
+    /*
+     * Setting with "lowest_nonlinear_perf" to ensure governoring
+     * performance in P-state range.
+     */
+    amd_cppc_write_request(policy->cpu, data-

caps.lowest_nonlinear_perf,

Quoted 13 lines
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

+ des_perf, data->caps.highest_perf);

I fear I don't understand the comment, and hence it remains unclear to me why lowest_nonlinear_perf is being used here.

How about
```
Choose lowest nonlinear performance as the minimum performance level at which

the platform may run.

Quoted 3 lines

Lowest nonlinear performance is the lowest performance level at which nonlinear power savings are achieved, Above this threshold, lower performance

Quoted 7 lines

levels should be generally more energy efficient than higher performance levels.

Quoted 1 line

```

I finally had to go to the ACPI spec to understand what this is about. There looks to be an implication that lowest <= lowest_nonlinear, and states in that range would correspond more to T-states than to P-states. With that I think I agree with the use

Yes, It doesn't have definitive conclusion about relation between lowest and lowest_nonlinear In our internal FW designed spec, it always shows lowest_nonlinear corresponds to P2

Quoted 4 lines

of lowest_nonlinear here. The comment, however, could do with moving farther away from merely quoting the pretty abstract text in the ACPI spec, as such quoting doesn't help in clarifying terminology used, when that terminology also isn't explained anywhere else in the code base.

How about we add detailed explanations about each terminology in the beginning declaration , see:
```

(quoted diff) +8 -0
+/*
+ * Field highest_perf, nominal_perf, lowest_nonlinear_perf, and
+lowest_perf
+ * contain the values read from CPPC capability MSR.
+ * Field highest_perf represents highest performance, which is the
+absolute
+ * maximum performance an individual processor may reach, assuming
+ideal

Review

Quoted 10 lines
(quoted diff) +10 -0
+ * conditions
+ * Field nominal_perf represents maximum sustained performance level
+of the
+ * processor, assuming ideal operating conditions.
+ * Field lowest_nonlinear_perf represents Lowest Nonlinear
+Performance, which
+ * is the lowest performance level at which nonlinear power savings
+are
+ * achieved. Above this threshold, lower performance levels should be
+ * generally more energy efficient than higher performance levels.

Which is still only the vague statement also found in the spec. This says nothing about what happens below that level, or what the relationship to other fields is.

Quoted 45 lines

+ * Field lowest_perf represents the absolute lowest performance level

(quoted diff) +44 -0
+of the
+ * platform.
+ *
+ * Field max_perf, min_perf, des_perf store the values for CPPC request MSR.
+ * Field max_perf conveys the maximum performance level at which the
+platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive.
+ * Field min_perf conveys the minimum performance level at which the
+platform
+ * may run. And it may be set to any performance value in the range
+ * [lowest_perf, highest_perf], inclusive but must be less than or
+equal to
+ * max_perf.
+ * Field des_perf conveys performance level Xen is requesting. And it
+may be
+ * set to any performance value in the range [min_perf, max_perf], inclusive.
+ */
+struct amd_cppc_drv_data
+{
+    const struct xen_processor_cppc *cppc_data;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int lowest_perf:8;
+            unsigned int lowest_nonlinear_perf:8;
+            unsigned int nominal_perf:8;
+            unsigned int highest_perf:8;
+            unsigned int :32;
+        };
+    } caps;
+    union {
+        uint64_t raw;
+        struct {
+            unsigned int max_perf:8;
+            unsigned int min_perf:8;
+            unsigned int des_perf:8;
+            unsigned int epp:8;
+            unsigned int :32;
+        };
+    } req;
+
+    int err;
+};
Quoted 2 lines

``
Then here, we could elaborate the reason why we choose lowest_nonlinear_perf

over lowest_perf:

Quoted 10 lines

```

(quoted diff) +8 -0
+    /*
+     * Having a performance level lower than the lowest nonlinear
+     * performance level, such as, lowest_perf <= perf <= lowest_nonliner_perf,
+     * may actually cause an efficiency penalty, So when deciding the min_perf
+     * value, we prefer lowest nonlinear performance over lowest performance
+     */
+    amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf,
+                           des_perf, data->caps.highest_perf);

```

Quoted 8 lines
Quoted 5 lines

This reads fine to me.

Question then is though: Is setting lowest_perf as the low boundary a good idea in any of the places? (Iirc it is used in one or two places. Or am I misremembering?)

Yes, in active mode, I choose lowest_perf as min_perf to try to extend the limitation for active(autonomous) mode Maybe it is not a good choice. Maybe cpufreq driver is limited to do performance tuning in P-states range.

Indeed I think we should limit ourselves to P-state management; management of T-states was never introduced into Xen, so far. But please be sure to make the connection to P- and T-states in the commentary you add.

Jan

#46 lore raw

PATCH v5 11/18 xen/x86: implement EPP support for the amd-cppc driver in active mode

In reply to Penny Zheng

amd-cppc has 2 operation modes: autonomous (active) mode and non-autonomous (passive) mode.
In active mode, we don't need Xen governor to calculate and tune the cpu frequency, while hardware built-in CPPC power algorithm will calculate the runtime workload and adjust cores frequency automatically according to the power supply, thermal, core voltage and some other hardware conditions.

Users could set EPP register to tell hardware their preference ratio toward performance over energy efficiency, which is configured on a scale from 0 to 255 where 0 represents maximum performance and 255 represents maximum efficiency.

We implement a new AMD CPU frequency driver amd-cppc-epp for active mode. It requires active tag for users to explicitly select active mode. In driver active-cppc-epp, ->setpolicy() is hooked, not the ->target(), as it does not depend on xen governor to do performance tuning.

Users could re-use "governor" in Xen cmdline to deliver which performance policy they want to apply, represented by a new field "policy" (CPUFREQ_POLICY_xxx), CPUFREQ_POLICY_PERFORMANCE as maximum performance, CPUFREQ_POLICY_POWERSAVE as the least power consumption. Function cpufreq_policy_from_governor() is responsible for tranforming governor into policy. Right now, only "performance" and "powersave" are considered.

---
v1 -> v2:
- Remove redundant epp_mode
- Remove pointless initializer
- Define sole caller read_epp_init_once and epp_init value to read pre-defined BIOS epp value only once
- Combine the commit "xen/cpufreq: introduce policy type when cpufreq_driver->setpolicy exists"
---
v2 -> v3:
- Combined with commit "x86/cpufreq: add "cpufreq=amd-cppc,active" para"
- Refactor doc about "active mode"
- Change opt_cpufreq_active to opt_active_mode
- Let caller pass epp_init when unspecified to allow the function parameter to be of uint8_t
- Make epp_init per-cpu value
---
v3 -> v4:
- doc refinement
- use MASK_EXTR() to get epp value
- fix indentation
- replace if-else() with switch()
- combine successive comments and do refinement
- no need to introduce amd_cppc_epp_update_limit() as a wrapper
- rename cpufreq_parse_policy() with cpufreq_policy_from_governor()
- no need to use case-insensitive comparison
---
v4 -> v5:
- refine doc to state what the default is for "active" sub-option and it's of boolean nature
- excess blank after << for AMD_CPPC_EPP_MASK
- set max_perf with lowest_perf to get utmost powersave
- refine commit message to include description about relation between "policy" and "governor"

---
 docs/misc/xen-command-line.pandoc    |  10 ++-
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 123 ++++++++++++++++++++++++++-
 xen/arch/x86/include/asm/msr-index.h |   1 +
 xen/drivers/cpufreq/utility.c        |  11 +++
 xen/include/acpi/cpufreq/cpufreq.h   |  12 +++
 xen/include/public/sysctl.h          |   1 +
 6 files changed, 153 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.pandoc +9 -1
index 9ef847a336..23518b2ae4 100644
@@ -515,7 +515,7 @@ If set, force use of the performance counters for oprofile, rather than detectin
 available support.
 
 ### cpufreq
-> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[verbose]]`
+> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[active][,verbose]]`
 
 > Default: `xen`
 
@@ -537,6 +537,14 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels.
 * `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC)
   on supported AMD hardware to provide finer grained frequency control
   mechanism. The default is disabled.
+* `active` is a boolean to enable amd-cppc driver in active(autonomous) mode.
+  In this mode, users could write to energy performance preference
+  register(epp) to tell hardware if they want to bias toward performance or
+  energy efficiency. Built-in CPPC power algorithm will calculate the runtime
+  workload and adjust cores frequency automatically according to the power
+  supply, thermal, core voltage and some other hardware conditions.
+  The default is disabled, and the option only applies when `amd-cppc` is
+  enabled.
 
 There is also support for `;`-separated fallback options:
 `cpufreq=hwp;xen,verbose`.  This first tries `hwp` and falls back to `xen` if
xen/arch/x86/acpi/cpufreq/amd-cppc.c +119 -4

193 lines not on this page · raw message

xen/arch/x86/include/asm/msr-index.h +1 -0
index e4401186c7..3e2522a862 100644
@@ -242,6 +242,7 @@
 #define MSR_AMD_CPPC_ENABLE                 0xc00102b1U
 #define  AMD_CPPC_ENABLE                    (_AC(1, ULL) << 0)
 #define MSR_AMD_CPPC_REQ                    0xc00102b3U
+#define  AMD_CPPC_EPP_MASK                  (_AC(0xff, ULL) << 24)
 
 /*
  * Legacy MSR constants in need of cleanup.  No new MSRs below this comment.
xen/drivers/cpufreq/utility.c +11 -0
index b35e2eb1b6..2617581125 100644
@@ -487,3 +487,14 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,
 
     return __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
 }
+
+unsigned int cpufreq_policy_from_governor(const struct cpufreq_governor *gov)
+{
+    if ( !strncmp(gov->name, "performance", CPUFREQ_NAME_LEN) )
+        return CPUFREQ_POLICY_PERFORMANCE;
+
+    if ( !strncmp(gov->name, "powersave", CPUFREQ_NAME_LEN) )
+        return CPUFREQ_POLICY_POWERSAVE;
+
+    return CPUFREQ_POLICY_UNKNOWN;
+}
xen/include/acpi/cpufreq/cpufreq.h +12 -0
index 83050c58b2..6f31009e82 100644
@@ -83,6 +83,7 @@ struct cpufreq_policy {
     int8_t              turbo;  /* tristate flag: 0 for unsupported
                                  * -1 for disable, 1 for enabled
                                  * See CPUFREQ_TURBO_* below for defines */
+    unsigned int        policy; /* CPUFREQ_POLICY_* */
 };
 DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
 
@@ -133,6 +134,17 @@ extern int cpufreq_register_governor(struct cpufreq_governor *governor);
 extern struct cpufreq_governor *__find_governor(const char *governor);
 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs
 
+#define CPUFREQ_POLICY_UNKNOWN      0
+/*
+ * If cpufreq_driver->target() exists, the ->governor decides what frequency
+ * within the limits is used. If cpufreq_driver->setpolicy() exists, these
+ * two generic policies are available:
+ */
+#define CPUFREQ_POLICY_POWERSAVE    1
+#define CPUFREQ_POLICY_PERFORMANCE  2
+
+unsigned int cpufreq_policy_from_governor(const struct cpufreq_governor *gov);
+
 /* pass a target to the cpufreq driver */
 extern int __cpufreq_driver_target(struct cpufreq_policy *policy,
                                    unsigned int target_freq,
xen/include/public/sysctl.h +1 -0
index 42997252ef..fa431fd983 100644
@@ -424,6 +424,7 @@ struct xen_set_cppc_para {
 };
 
 #define XEN_AMD_CPPC_DRIVER_NAME "amd-cppc"
+#define XEN_AMD_CPPC_EPP_DRIVER_NAME "amd-cppc-epp"
 #define XEN_HWP_DRIVER_NAME "hwp"
 
 /*
Signature · 1 line
2.34.1
#47 lore raw

Re: [PATCH v5 11/18] xen/x86: implement EPP support for the amd-cppc driver in active mode

docs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. · line 543

Quoted 8 lines · Penny Zheng
docs/misc/xen-command-line.pandoc +4 -0
@@ -537,6 +537,14 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels.
 * `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC)
   on supported AMD hardware to provide finer grained frequency control
   mechanism. The default is disabled.
+* `active` is a boolean to enable amd-cppc driver in active(autonomous) mode.
+  In this mode, users could write to energy performance preference
+  register(epp) to tell hardware if they want to bias toward performance or
+  energy efficiency.

Who or what is "users" here? Certainly not the person reading the doc, trying to determine whether to use this command line sub-option. That person can't write to the EPP register. (Or really they maybe can, but they shouldn't.) It's the driver which is supposed to be carrying out such writes, isn't it?

Quoted 24 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +24 -0
+static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
+{
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data,
+                                                   policy->cpu);
+    uint8_t max_perf, min_perf, epp;
+
+    /*
+     * min_perf represents the idle frequency, while max_perf represents
+     * the maximum frequency
+     */
+    max_perf = data->caps.highest_perf;
+    min_perf = data->caps.lowest_perf;
+
+    /*
+     * We set min_perf with highest_perf in performance mode
+     * and max_perf with lowest_perf in powersave mode, to achieve
+     * ultmost performance and power savings.
+     */
+    switch ( policy->policy )
+    {
+    case CPUFREQ_POLICY_PERFORMANCE:
+        /* Force the epp value to be zero for performance policy */
+        epp = CPPC_ENERGY_PERF_MAX_PERFORMANCE;
+        min_perf = data->caps.highest_perf;

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 501

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        break;
+    case CPUFREQ_POLICY_POWERSAVE:
+        /* Force the epp value to be 0xff for powersave policy */
+        epp = CPPC_ENERGY_PERF_MAX_POWERSAVE;
+        max_perf = data->caps.lowest_perf;
+        break;
+    default:
+        epp = per_cpu(epp_init, policy->cpu);
+        break;
+    }

Blank lines please between non-fall-through case blocks.

Jan

#48 lore raw

PATCH v5 12/18 xen/cpufreq: get performance policy from governor set via xenpm

In reply to Penny Zheng

Even if Xen governor is not used in amd-cppc active mode, we could somehow deduce which performance policy (CPUFREQ_POLICY_xxx) user wants to apply through which governor they choose, such as:
If user chooses performance governor, they want maximum performance. If user chooses powersave governor, they want the least power consumption. Function cpufreq_policy_from_governor() is responsible for above transition, and it shall be also effective when users setting new governor through xenpm.

ondemand and userspace are forbidden choices, and if users specify such options, we shall not only give warning message, but also error out.

---
v4 -> v5:
- new commit

---
 xen/drivers/acpi/pmstat.c     | 8 ++++++++
 xen/drivers/cpufreq/utility.c | 1 +
 2 files changed, 9 insertions(+)
xen/drivers/acpi/pmstat.c +8 -0
index 330bc3a1c2..514475cf5c 100644
@@ -319,6 +319,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)
     if (new_policy.governor == NULL)
         return -EINVAL;
 
+    new_policy.policy = cpufreq_policy_from_governor(new_policy.governor);
+    if ( new_policy.policy == CPUFREQ_POLICY_UNKNOWN )
+    {
+        printk("Failed to get performance policy from %s, and users shall write epp values to deliver preference towards performance over efficiency",
+               new_policy.governor->name);
+        return -EINVAL;
+    }
+
     return __cpufreq_set_policy(old_policy, &new_policy);
 }
 
xen/drivers/cpufreq/utility.c +1 -0
index 2617581125..734cd84be1 100644
@@ -456,6 +456,7 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,
     data->min = policy->min;
     data->max = policy->max;
     data->limits = policy->limits;
+    data->policy = policy->policy;
     if (cpufreq_driver.setpolicy)
         return alternative_call(cpufreq_driver.setpolicy, data);
 
Signature · 1 line
2.34.1
#49 lore raw

Re: [PATCH v5 12/18] xen/cpufreq: get performance policy from governor set via xenpm

xen/drivers/acpi/pmstat.c static int set_cpufreq_gov(struct xen_sysctl_pm_op *op) · line 325

Quoted 10 lines · Penny Zheng
xen/drivers/acpi/pmstat.c +4 -0
@@ -319,6 +319,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)
     if (new_policy.governor == NULL)
         return -EINVAL;
 
+    new_policy.policy = cpufreq_policy_from_governor(new_policy.governor);
+    if ( new_policy.policy == CPUFREQ_POLICY_UNKNOWN )
+    {
+        printk("Failed to get performance policy from %s, and users shall write epp values to deliver preference towards performance over efficiency",

This message is excessively long and is lacking a newline (i.e. effectively two:
one in the middle and one at the end; yet better would be to find less verbose wording). What's worse, how would a "user" go about "writing epp values"?

Jan

#50 lore raw

RE: [PATCH v5 12/18] xen/cpufreq: get performance policy from governor set via xenpm

[Public]

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:22 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 12/18] xen/cpufreq: get performance policy from governor set via xenpm

xen/drivers/acpi/pmstat.c static int set_cpufreq_gov(struct xen_sysctl_pm_op

Quoted 3 lines · Penny Zheng
xen/drivers/acpi/pmstat.c +0 -0
@@ -319,6 +319,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op

*op)

xen/drivers/acpi/pmstat.c static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)

Quoted 9 lines
xen/drivers/acpi/pmstat.c +6 -0
     if (new_policy.governor == NULL)
         return -EINVAL;
 
+    new_policy.policy = cpufreq_policy_from_governor(new_policy.governor);
+    if ( new_policy.policy == CPUFREQ_POLICY_UNKNOWN )
+    {
+        printk("Failed to get performance policy from %s, and users
+ shall write epp values to deliver preference towards performance
+ over efficiency",
Quoted 4 lines

This message is excessively long and is lacking a newline (i.e. effectively two:
one in the middle and one at the end; yet better would be to find less verbose wording). What's worse, how would a "user" go about "writing epp values"?

Maybe change it to

```
printk("Failed to get performance policy from %s, Try \"xenpm set-cpufreq-cppc\"\n", ...);
```
Quoted 1 line

Jan

#51 lore raw

Re: [PATCH v5 12/18] xen/cpufreq: get performance policy from governor set via xenpm

Quoted 30 lines · Zheng

[Public]

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 12:22 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v5 12/18] xen/cpufreq: get performance policy from governor set via xenpm

xen/drivers/acpi/pmstat.c static int set_cpufreq_gov(struct xen_sysctl_pm_op

Quoted 3 lines · Penny Zheng
xen/drivers/acpi/pmstat.c +0 -0
@@ -319,6 +319,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op

*op)

xen/drivers/acpi/pmstat.c static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)

Quoted 9 lines
xen/drivers/acpi/pmstat.c +6 -0
     if (new_policy.governor == NULL)
         return -EINVAL;
 
+    new_policy.policy = cpufreq_policy_from_governor(new_policy.governor);
+    if ( new_policy.policy == CPUFREQ_POLICY_UNKNOWN )
+    {
+        printk("Failed to get performance policy from %s, and users
+ shall write epp values to deliver preference towards performance
+ over efficiency",
Quoted 4 lines

This message is excessively long and is lacking a newline (i.e. effectively two:
one in the middle and one at the end; yet better would be to find less verbose wording). What's worse, how would a "user" go about "writing epp values"?

Quoted 4 lines

Maybe change it to

```
printk("Failed to get performance policy from %s, Try \"xenpm set-cpufreq-cppc\"\n", ...);
```

Looks quite a bit better, thanks.

Jan

#52 lore raw

PATCH v5 13/18 xen/cpufreq: normalize hwp driver check with hwp_active()

In reply to Penny Zheng

Instead of using hypercall passing parameter to identify hwp driver, we shall use hwp_active(). Also, we've already used hwp_active() in do_get_pm_info() in the same file to do hwp driver check, it's better syncing with same way.

---
v4 -> v5:
- new commit

---
 xen/drivers/acpi/pmstat.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
xen/drivers/acpi/pmstat.c +1 -3
index 514475cf5c..c09e001ec3 100644
@@ -253,9 +253,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
     else
         strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN);
 
-    if ( IS_ENABLED(CONFIG_INTEL) &&
-         !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
-                  CPUFREQ_NAME_LEN) )
+    if ( hwp_active() )
         ret = get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para);
     else
     {
Signature · 1 line
2.34.1
Acked-by on v5 13/18
#53 lore raw

Re: [PATCH v5 13/18] xen/cpufreq: normalize hwp driver check with hwp_active()

Quoted 6 lines · Penny Zheng

Instead of using hypercall passing parameter to identify hwp driver, we shall use hwp_active(). Also, we've already used hwp_active() in do_get_pm_info() in the same file to do hwp driver check, it's better syncing with same way.

Is this okay to apply ahead of most/all of the earlier patches?

Jan

#54 lore raw

PATCH v5 14/18 xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

In reply to Penny Zheng

In amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info could be printed together via xenpm tool.

To achieve that, "struct xen_cppc_para" needs to be moved out of the union and also "struct xen_get_cpufreq_para". Also if still putting it in "struct xen_get_cpufreq_para" (e.g. just move out of union), "struct xen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes.
We introduce a new sub-cmd GET_CPUFREQ_CPPC to specifically print CPPC-related para and clear cppc print in GET_CPUFREQ_PARA.

---
v4 -> v5:
- new commit

---
 tools/include/xenctrl.h     |  3 +-
 tools/libs/ctrl/xc_pm.c     | 28 ++++++++++-
 tools/misc/xenpm.c          | 97 ++++++++++++++++++++++++++-----------
 xen/drivers/acpi/pmstat.c   | 18 +++++--
 xen/include/public/sysctl.h |  3 +-
 5 files changed, 116 insertions(+), 33 deletions(-)
tools/include/xenctrl.h +2 -1
index 4955981231..79523d2d73 100644
@@ -1938,7 +1938,6 @@ struct xc_get_cpufreq_para {
                 xc_ondemand_t ondemand;
             } u;
         } s;
-        xc_cppc_para_t cppc_para;
     } u;
 
     int32_t turbo_enabled;
@@ -1953,6 +1952,8 @@ 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,
                         xc_set_cppc_para_t *set_cppc);
+int xc_get_cppc_para(xc_interface *xch, unsigned int cpuid,
+                     xc_cppc_para_t *cppc_para);
 int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq);
 
 int xc_set_sched_opt_smt(xc_interface *xch, uint32_t value);
tools/libs/ctrl/xc_pm.c +27 -1
index ff7b5ada05..3c9e272aee 100644
@@ -289,7 +289,6 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
         CHK_FIELD(s.scaling_min_freq);
         CHK_FIELD(s.u.userspace);
         CHK_FIELD(s.u.ondemand);
-        CHK_FIELD(cppc_para);
 
 #undef CHK_FIELD
 
@@ -367,6 +366,33 @@ int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid,
     return ret;
 }
 
+int xc_get_cppc_para(xc_interface *xch, unsigned int cpuid,
+                     xc_cppc_para_t *cppc_para)
+{
+    int ret;
+    struct xen_sysctl sysctl = {};
+    struct xen_cppc_para *sys_cppc_para = &sysctl.u.pm_op.u.cppc_para;
+
+    if ( !xch  || !cppc_para )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    sysctl.cmd = XEN_SYSCTL_pm_op;
+    sysctl.u.pm_op.cmd = GET_CPUFREQ_CPPC;
+    sysctl.u.pm_op.cpuid = cpuid;
+
+    ret = xc_sysctl(xch, &sysctl);
+    if ( ret )
+        return ret;
+
+    BUILD_BUG_ON(sizeof(*cppc_para) != sizeof(*sys_cppc_para));
+    memcpy(cppc_para, sys_cppc_para, sizeof(*sys_cppc_para));
+
+    return ret;
+}
+
 int xc_get_cpufreq_avgfreq(xc_interface *xch, int cpuid, int *avg_freq)
 {
     int ret = 0;
tools/misc/xenpm.c +70 -27

121 lines not on this page · raw message

xen/drivers/acpi/pmstat.c +15 -3
index c09e001ec3..6e9178ade1 100644
@@ -253,9 +253,7 @@ 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
+    if ( !hwp_active() )
     {
         if ( !(scaling_available_governors =
                xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )
@@ -328,6 +326,16 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)
     return __cpufreq_set_policy(old_policy, &new_policy);
 }
 
+static int get_cpufreq_cppc(struct xen_sysctl_pm_op *op)
+{
+    int ret = -ENODEV;
+
+    if ( hwp_active() )
+        ret = get_hwp_para(op->cpuid, &op->u.cppc_para);
+
+    return ret;
+}
+
 static int set_cpufreq_para(struct xen_sysctl_pm_op *op)
 {
     int ret = 0;
@@ -498,6 +506,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op)
         break;
     }
 
+    case GET_CPUFREQ_CPPC:
+        ret = get_cpufreq_cppc(op);
+        break;
+
     case SET_CPUFREQ_CPPC:
         ret = set_cpufreq_cppc(op);
         break;
xen/include/public/sysctl.h +2 -1
index fa431fd983..29872fe508 100644
@@ -462,7 +462,6 @@ struct xen_get_cpufreq_para {
                 struct  xen_ondemand ondemand;
             } u;
         } s;
-        struct xen_cppc_para cppc_para;
     } u;
 
     int32_t turbo_enabled;
@@ -493,6 +492,7 @@ struct xen_sysctl_pm_op {
     #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
     #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
     #define SET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x05)
+    #define GET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x06)
 
     /* set/reset scheduler power saving option */
     #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21
@@ -517,6 +517,7 @@ struct xen_sysctl_pm_op {
     uint32_t cpuid;
     union {
         struct xen_get_cpufreq_para get_para;
+        struct xen_cppc_para        cppc_para;
         struct xen_set_cpufreq_gov  set_gov;
         struct xen_set_cpufreq_para set_para;
         struct xen_set_cppc_para    set_cppc;
Signature · 1 line
2.34.1
#55 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

Quoted 35 lines · Penny Zheng
tools/misc/xenpm.c +1 -21
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0) and\n"
             "                                     optionally the C-sub-state limitation (<num2> >= 0)\n"
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU <cpuid> or all\n"
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave] <param:val>*\n"
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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);
-        }

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq) · line 819

Quoted 10 lines
tools/misc/xenpm.c +1 -6
-
-        printf("                     : desired [%"PRIu32"%s]\n",
-               cppc->desired,
-               cppc->desired ? "" : " hw autonomous");
-    }
-    else
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )
             printf("scaling_avail_gov    : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 19 lines
xen/include/public/sysctl.h +1 -1
@@ -462,7 +462,6 @@ struct xen_get_cpufreq_para {
                 struct  xen_ondemand ondemand;
             } u;
         } s;
-        struct xen_cppc_para cppc_para;
     } u;
 
     int32_t turbo_enabled;
@@ -493,6 +492,7 @@ struct xen_sysctl_pm_op {
     #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
     #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
     #define SET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x05)
+    #define GET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x06)
 
     /* set/reset scheduler power saving option */
     #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21

xen/include/public/sysctl.h struct xen_sysctl_pm_op { · line 523

Quoted 7 lines
xen/include/public/sysctl.h +1 -0
@@ -517,6 +517,7 @@ struct xen_sysctl_pm_op {
     uint32_t cpuid;
     union {
         struct xen_get_cpufreq_para get_para;
+        struct xen_cppc_para        cppc_para;
         struct xen_set_cpufreq_gov  set_gov;
         struct xen_set_cpufreq_para set_para;
         struct xen_set_cppc_para    set_cppc;

This (tools-only) public interface change, otoh, may be okay to do.

Jan

#56 lore raw

RE: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

[Public]

Quoted 60 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 6 lines · Penny Zheng
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0) and\n"
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct · line 821

Quoted 13 lines
tools/misc/xenpm.c +0 -6
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               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",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow governor filed to output cppc info
However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes. So I'm left to create a new subcmd to specifically deal with CPPC info I could leave above output for get-cpufreq-para unchanged. Then we will have duplicate CPPC info in two commands. Or is it fine to do that?

Quoted 3 lines

Jan

#57 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

Quoted 71 lines · Zheng

[Public]

Quoted 60 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 6 lines · Penny Zheng
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0) and\n"
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct · line 821

Quoted 13 lines
tools/misc/xenpm.c +0 -6
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               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",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 2 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow governor filed to output cppc info
However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq-para" output, so be it I would say.

Quoted 2 lines

So I'm left to create a new subcmd to specifically deal with CPPC info
I could leave above output for get-cpufreq-para unchanged. Then we will have duplicate CPPC info in two commands. Or is it fine to do that?

Duplicate information (in distinct commands) isn't a problem either, imo.

Jason, you did the HWP work here - any thoughts?

Jan

#58 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

Quoted 65 lines · Jan Beulich
Quoted 61 lines · Zheng
Quoted 52 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 6 lines · Penny Zheng
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0) and\n"
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct · line 821

Quoted 13 lines
tools/misc/xenpm.c +0 -6
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               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",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 2 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow governor filed to output cppc info
However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

Quoted 8 lines

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq-para" output, so be it I would say.

Quoted 2 lines

So I'm left to create a new subcmd to specifically deal with CPPC info
I could leave above output for get-cpufreq-para unchanged. Then we will have duplicate CPPC info in two commands. Or is it fine to do that?

Duplicate information (in distinct commands) isn't a problem either, imo.

But, ftaod, duplicate code producing the same information is. Such code would want breaking out into a helper function then. (And yet further ftaod, if the code only produces identical information, but from different input structures, such breaking out of course wouldn't normally be an option.)

Jan

#59 lore raw

RE: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

In reply to Jan Beulich

[Public]

Quoted 90 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 4:33 PM
To: Penny, Zheng <[email protected]>; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 15 lines · Zheng

[Public]

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 6 lines
Quoted 6 lines · Penny Zheng

tools/misc/xenpm.c void show_help(void) · line 70

Quoted 5 lines
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0)

and\n"

Quoted 20 lines
Quoted 20 lines

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 1 line
tools/misc/xenpm.c +0 -0
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, · line 821

Quoted 13 lines
tools/misc/xenpm.c +0 -6
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

Quoted 4 lines
Quoted 4 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               cppc->lowest, cppc->lowest_nonlinear);
-        printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
-               cppc->nominal, cppc->highest);
-        printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy

perf

Quoted 27 lines
Quoted 18 lines

[%"PRIu32"]\n",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 2 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow

Quoted 9 lines

governor filed to output cppc info However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq- para" output, so be it I would say.

Because we are limiting each sysctl-subcmd-struct, such as " struct xen_sysctl_pm_op ", 128 bytes in "struct xen_sysctl",They are all combined as a union. Also, in "struct xen_sysctl_pm_op", its descending sub-op structs, including "struct xen_get_cpufreq_para", are all combined as union too

```
struct xen_sysctl_pm_op {
    ... ...
    union {
        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 0xffffffffU
        uint32_t                    get_max_cstate;
        uint32_t                    set_max_cstate;
    } u;
}
```

It could deduce that "struct xen_get_cpufreq_para" is limited to 128 bytes (I think actual limit is smaller than 128)....

Quoted 9 lines
Quoted 2 lines

So I'm left to create a new subcmd to specifically deal with CPPC info I could leave above output for get-cpufreq-para unchanged. Then we will have

duplicate CPPC info in two commands. Or is it fine to do that?

Duplicate information (in distinct commands) isn't a problem either, imo.

Jason, you did the HWP work here - any thoughts?

Jan

#60 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

Quoted 120 lines · Zheng

[Public]

Quoted 90 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 4:33 PM
To: Penny, Zheng <[email protected]>; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 15 lines · Zheng

[Public]

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 6 lines
Quoted 6 lines · Penny Zheng

tools/misc/xenpm.c void show_help(void) · line 70

Quoted 5 lines
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0)

and\n"

Quoted 20 lines
Quoted 20 lines

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 1 line
tools/misc/xenpm.c +0 -0
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, · line 821

Quoted 13 lines
tools/misc/xenpm.c +0 -6
             "                                     set Hardware P-State (HWP) parameters\n"
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

Quoted 4 lines
Quoted 4 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               cppc->lowest, cppc->lowest_nonlinear);
-        printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
-               cppc->nominal, cppc->highest);
-        printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy

perf

Quoted 27 lines
Quoted 18 lines

[%"PRIu32"]\n",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 2 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow

Quoted 9 lines

governor filed to output cppc info However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq- para" output, so be it I would say.

Because we are limiting each sysctl-subcmd-struct, such as " struct xen_sysctl_pm_op ", 128 bytes in "struct xen_sysctl",They are all combined as a union. Also, in "struct xen_sysctl_pm_op", its descending sub-op structs, including "struct xen_get_cpufreq_para", are all combined as union too

```
struct xen_sysctl_pm_op {
    ... ...
    union {
        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 0xffffffffU
        uint32_t                    get_max_cstate;
        uint32_t                    set_max_cstate;
    } u;
}
```
Quoted 1 line

It could deduce that "struct xen_get_cpufreq_para" is limited to 128 bytes (I think actual limit is smaller than 128)....

And that implies what? In my earlier reply I already said that you may then simply need to invoke more than one sysctl to get all the data you need. (As one of the options, that is.)

Jan

#61 lore raw

RE: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

[Public]

Quoted 141 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 5:46 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Andryuk, Jason <[email protected]>
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 47 lines · Zheng

[Public]

Quoted 45 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 4:33 PM
To: Penny, Zheng <[email protected]>; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 16 lines · Zheng

[Public]

Quoted 14 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC
sub- cmd

Quoted 6 lines
Quoted 6 lines · Penny Zheng

tools/misc/xenpm.c void show_help(void) · line 70

Quoted 5 lines
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
             " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
             "                                     set the C-State limitation (<num> >= 0)

and\n"

Quoted 7 lines
Quoted 7 lines

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 1 line
tools/misc/xenpm.c +0 -0
             "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
             " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

Quoted 1 line
tools/misc/xenpm.c +0 -0
             "                                     set Hardware P-State (HWP)

parameters\n"

Quoted 53 lines
Quoted 53 lines
Quoted 13 lines
Quoted 13 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, · line 821

Quoted 12 lines
tools/misc/xenpm.c +0 -6
             "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

Quoted 4 lines
Quoted 4 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               cppc->lowest, cppc->lowest_nonlinear);
-        printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
-               cppc->nominal, cppc->highest);
-        printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy

perf

Quoted 27 lines
Quoted 18 lines

[%"PRIu32"]\n",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
     {
         if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 3 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow

governor filed to output cppc info However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

Quoted 6 lines
Quoted 4 lines

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq- para" output, so be it I would say.

Because we are limiting each sysctl-subcmd-struct, such as " struct

xen_sysctl_pm_op ", 128 bytes in "struct xen_sysctl",They are all combined as a union.

Quoted 17 lines

Also, in "struct xen_sysctl_pm_op", its descending sub-op structs, including "struct xen_get_cpufreq_para", are all combined as union too

``` struct xen_sysctl_pm_op {
    ... ...
    union {
        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 0xffffffffU
        uint32_t                    get_max_cstate;
        uint32_t                    set_max_cstate;
    } u;
}
```
Quoted 1 line

It could deduce that "struct xen_get_cpufreq_para" is limited to 128 bytes (I think

Quoted 6 lines

actual limit is smaller than 128)....

And that implies what? In my earlier reply I already said that you may then simply need to invoke more than one sysctl to get all the data you need. (As one of the options, that is.)

Okay, I only explained why I couldn't use one command "get-cpufreq-para" to output all info

Quoted 1 line

Jan

#62 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

Quoted 143 lines · Zheng

[Public]

Quoted 141 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 5:46 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Andryuk, Jason <[email protected]>
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 47 lines · Zheng

[Public]

Quoted 45 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, July 4, 2025 4:33 PM
To: Penny, Zheng <[email protected]>; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub- cmd

Quoted 16 lines · Zheng

[Public]

Quoted 14 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:08 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC
sub- cmd

Quoted 6 lines
Quoted 6 lines · Penny Zheng

tools/misc/xenpm.c void show_help(void) · line 70

Quoted 5 lines
tools/misc/xenpm.c +0 -0
@@ -69,6 +69,7 @@ void show_help(void)
              " set-max-cstate        <num>|'unlimited' [<num2>|'unlimited']\n"
              "                                     set the C-State limitation (<num> >= 0)

and\n"

Quoted 7 lines
Quoted 7 lines

tools/misc/xenpm.c void show_help(void) · line 71

Quoted 1 line
tools/misc/xenpm.c +0 -0
              "                                     optionally the C-sub-state limitation

(<num2> >= 0)\n"

tools/misc/xenpm.c void show_help(void) · line 72

Quoted 1 line
tools/misc/xenpm.c +1 -0
+            " get-cpufreq-cppc      [cpuid]       list cpu cppc parameter of CPU

<cpuid> or all\n"

tools/misc/xenpm.c void show_help(void) · line 73

Quoted 1 line
tools/misc/xenpm.c +0 -0
              " set-cpufreq-cppc      [cpuid] [balance|performance|powersave]

<param:val>*\n"

Quoted 1 line
tools/misc/xenpm.c +0 -0
              "                                     set Hardware P-State (HWP)

parameters\n"

Quoted 53 lines
Quoted 53 lines
Quoted 13 lines
Quoted 13 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, · line 821

Quoted 12 lines
tools/misc/xenpm.c +0 -6
              "                                     on CPU <cpuid> or all if omitted.\n"
@@ -812,33 +813,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",

Quoted 4 lines
Quoted 4 lines

tools/misc/xenpm.c static void print_cpufreq_para(int cpuid, · line 825

Quoted 4 lines
tools/misc/xenpm.c +0 -4
-               cppc->lowest, cppc->lowest_nonlinear);
-        printf("                     : nominal [%"PRIu32"] highest [%"PRIu32"]\n",
-               cppc->nominal, cppc->highest);
-        printf("  configured limits  : min [%"PRIu32"] max [%"PRIu32"] energy

perf

Quoted 27 lines
Quoted 18 lines

[%"PRIu32"]\n",

Quoted 17 lines
tools/misc/xenpm.c +0 -17
-               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");
-    }
-    else
Quoted 8 lines
Quoted 4 lines
tools/misc/xenpm.c +1 -0
+    if ( !hwp )
      {
          if ( p_cpufreq->gov_num )

printf("scaling_avail_gov : %s\n",

I'm not sure it is a good idea to alter what is being output for get-cpufreq-para. People may simply miss that output then, without having any indication where it went.

Quoted 3 lines

Hwp is more like amd-cppc in active mode. It also does not rely on Xen governor to do performance tuning, so in previous design, we could borrow

governor filed to output cppc info However after introducing amd-cppc passive mode, we have request to output both governor and CPPC info. And if continuing expanding get-cpufreq-para to include CPPC info, it will make the parent stuct xen_sysctl.u exceed exceed 128 bytes.

Quoted 6 lines
Quoted 4 lines

How is the xenpm command "get-cpufreq-para" related to the sysctl interface struct size? If you need to invoke two sysctl sub-ops to produce all relevant "get-cpufreq- para" output, so be it I would say.

Because we are limiting each sysctl-subcmd-struct, such as " struct

xen_sysctl_pm_op ", 128 bytes in "struct xen_sysctl",They are all combined as a union.

Quoted 18 lines

Also, in "struct xen_sysctl_pm_op", its descending sub-op structs, including "struct xen_get_cpufreq_para", are all combined as union too

``` struct xen_sysctl_pm_op {
     ... ...
     union {
         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 0xffffffffU
         uint32_t                    get_max_cstate;
         uint32_t                    set_max_cstate;
     } u;
}
```

It could deduce that "struct xen_get_cpufreq_para" is limited to 128 bytes (I think

Quoted 8 lines
Quoted 6 lines

actual limit is smaller than 128)....

And that implies what? In my earlier reply I already said that you may then simply need to invoke more than one sysctl to get all the data you need. (As one of the options, that is.)

Okay, I only explained why I couldn't use one command "get-cpufreq-para" to output all info

I think Jan's suggestion to make xenpm get-cpufreq-para keep outputting cppc/hwp information is good. That way users get the cpufreq information without having to know what driver is running. So you will have to issue the additional hypercall as necessary to retrieve the data.

Regards,
Jason

#63 lore raw

Re: [PATCH v5 14/18] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd

In reply to Penny Zheng
Quoted 19 lines · Penny Zheng
xen/include/public/sysctl.h +1 -1
@@ -462,7 +462,6 @@ struct xen_get_cpufreq_para {
                 struct  xen_ondemand ondemand;
             } u;
         } s;
-        struct xen_cppc_para cppc_para;
     } u;
 
     int32_t turbo_enabled;
@@ -493,6 +492,7 @@ struct xen_sysctl_pm_op {
     #define SET_CPUFREQ_PARA           (CPUFREQ_PARA | 0x03)
     #define GET_CPUFREQ_AVGFREQ        (CPUFREQ_PARA | 0x04)
     #define SET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x05)
+    #define GET_CPUFREQ_CPPC           (CPUFREQ_PARA | 0x06)
 
     /* set/reset scheduler power saving option */
     #define XEN_SYSCTL_pm_op_set_sched_opt_smt    0x21

xen/include/public/sysctl.h struct xen_sysctl_pm_op { · line 523

Quoted 7 lines
xen/include/public/sysctl.h +1 -0
@@ -517,6 +517,7 @@ struct xen_sysctl_pm_op {
     uint32_t cpuid;
     union {
         struct xen_get_cpufreq_para get_para;
+        struct xen_cppc_para        cppc_para;
         struct xen_set_cpufreq_gov  set_gov;
         struct xen_set_cpufreq_para set_para;
         struct xen_set_cppc_para    set_cppc;

Imo with the move and new use, the struct wants to become xen_get_cppc_para.

Jan

#64 lore raw

PATCH v5 15/18 xen/cpufreq: bypass governor-related para for amd-cppc-epp

In reply to Penny Zheng

HWP and amd-cppc-epp are both governor-less driver,
so we introduce "hw_auto" flag to together bypass governor-related print in print_cpufreq_para().

In get/set_cpufreq_para(), we are adding "cpufreq_driver.setpolicy == NULL" check to exclude governor-related para for amd-cppc-epp driver.

---
v3 -> v4:
- Include validation check fix here
---
v4 -> v5:
- validation check has beem moved to where XEN_PROCESSOR_PM_CPPC and XEN_CPPC_INIT have been firstly introduced
- adding "cpufreq_driver.setpolicy == NULL" check to exclude governor-related para for amd-cppc-epp driver in get/set_cpufreq_para()

---
 tools/misc/xenpm.c        | 10 +++++++---
 xen/drivers/acpi/pmstat.c |  6 ++++--
 2 files changed, 11 insertions(+), 5 deletions(-)
tools/misc/xenpm.c +7 -3
index 2a87f7ae8a..f173e598ea 100644
@@ -791,9 +791,13 @@ static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,
 /* print out parameters about cpu frequency */
 static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
 {
-    bool hwp = strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) == 0;
+    bool hw_auto = false;
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME) )
+        hw_auto = true;
+
     printf("cpu id               : %d\n", cpuid);
 
     printf("affected_cpus        :");
@@ -801,7 +805,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
         printf(" %d", p_cpufreq->affected_cpus[i]);
     printf("\n");
 
-    if ( hwp )
+    if ( hw_auto )
         printf("cpuinfo frequency    : base [%"PRIu32"] max [%"PRIu32"]\n",
                p_cpufreq->cpuinfo_min_freq,
                p_cpufreq->cpuinfo_max_freq);
@@ -813,7 +817,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 )
+    if ( !hw_auto )
     {
         if ( p_cpufreq->gov_num )
             printf("scaling_avail_gov    : %s\n",
xen/drivers/acpi/pmstat.c +4 -2
index 6e9178ade1..e5f375921a 100644
@@ -253,7 +253,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() )
+    /* bypass hwp and amd-cppc-epp driver */
+    if ( !hwp_active() && cpufreq_driver.setpolicy == NULL )
     {
         if ( !(scaling_available_governors =
                xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )
@@ -346,7 +347,8 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)
     if ( !policy || !policy->governor )
         return -EINVAL;
 
-    if ( hwp_active() )
+    /* bypass hwp and amd-cppc-epp driver */
+    if ( hwp_active() || cpufreq_driver.setpolicy == NULL )
         return -EOPNOTSUPP;
 
     switch(op->u.set_para.ctrl_type)
Signature · 1 line
2.34.1
#65 lore raw

Re: [PATCH v5 15/18] xen/cpufreq: bypass governor-related para for amd-cppc-epp

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 256

Quoted 8 lines · Penny Zheng
xen/drivers/acpi/pmstat.c +1 -1
@@ -253,7 +253,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() )
+    /* bypass hwp and amd-cppc-epp driver */

Nit (comment style): Want to start with a capital letter. See ./CODING_STYLE.

xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 257

Quoted 1 line
xen/drivers/acpi/pmstat.c +1 -0
+    if ( !hwp_active() && cpufreq_driver.setpolicy == NULL )

We generally prefer the shorter "!cpufreq_driver.setpolicy".

And then - is using the presence of that hook really a good criteria to use here (and below)?

xen/drivers/acpi/pmstat.c static int set_cpufreq_para(struct xen_sysctl_pm_op *op) · line 352

Quoted 8 lines
xen/drivers/acpi/pmstat.c +2 -1
@@ -346,7 +347,8 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)
     if ( !policy || !policy->governor )
         return -EINVAL;
 
-    if ( hwp_active() )
+    /* bypass hwp and amd-cppc-epp driver */
+    if ( hwp_active() || cpufreq_driver.setpolicy == NULL )
         return -EOPNOTSUPP;

Isn't this the wrong way round? I.e. don't you mean "!= NULL" (or the equivalent thereof) here?

Jan

#66 lore raw

PATCH v5 16/18 tools: drop "has_num" condition check for cppc mode

In reply to Penny Zheng

In xenpm get-cpufreq-para <cpuid>, ->freq_num and ->cpu_num checking are tied together via variable "has_num", while ->freq_num only has non-zero value when cpufreq driver in legacy P-states mode.

So we drop the "has_num" condition check, and mirror the ->gov_num check for both ->freq_num and ->cpu_num in xc_get_cpufreq_para().

---
v3 -> v4:
- drop the "has_num" condition check
---
v4 -> v5:
- refactor title and commit
- make all three pieces (xc_hypercall_bounce_pre()) be as similar as possible

---
 tools/libs/ctrl/xc_pm.c | 43 +++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 19 deletions(-)
tools/libs/ctrl/xc_pm.c +24 -19
index 3c9e272aee..cdc072e757 100644
@@ -212,34 +212,41 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
     DECLARE_NAMED_HYPERCALL_BOUNCE(scaling_available_governors,
 			 user_para->scaling_available_governors,
 			 user_para->gov_num * CPUFREQ_NAME_LEN * sizeof(char), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
-    bool has_num = user_para->cpu_num && user_para->freq_num;
 
-    if ( has_num )
+    if ( (user_para->cpu_num && !user_para->affected_cpus) ||
+         (user_para->freq_num && !user_para->scaling_available_frequencies) ||
+         (user_para->gov_num && !user_para->scaling_available_governors) )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+    if ( user_para->cpu_num )
     {
-        if ( (!user_para->affected_cpus)                    ||
-             (!user_para->scaling_available_frequencies)    ||
-             (user_para->gov_num && !user_para->scaling_available_governors) )
-        {
-            errno = EINVAL;
-            return -1;
-        }
         ret = xc_hypercall_bounce_pre(xch, affected_cpus);
         if ( ret )
             return ret;
+    }
+    if ( user_para->freq_num )
+    {
         ret = xc_hypercall_bounce_pre(xch, scaling_available_frequencies);
         if ( ret )
             goto unlock_2;
-        if ( user_para->gov_num )
-            ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);
+    }
+    if ( user_para->gov_num )
+    {
+        ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);
         if ( ret )
             goto unlock_3;
+    }
 
+    if ( user_para->cpu_num )
         set_xen_guest_handle(sys_para->affected_cpus, affected_cpus);
-        set_xen_guest_handle(sys_para->scaling_available_frequencies, scaling_available_frequencies);
-        if ( user_para->gov_num )
-            set_xen_guest_handle(sys_para->scaling_available_governors,
-                                 scaling_available_governors);
-    }
+    if ( user_para->freq_num )
+        set_xen_guest_handle(sys_para->scaling_available_frequencies,
+                             scaling_available_frequencies);
+    if ( user_para->gov_num )
+        set_xen_guest_handle(sys_para->scaling_available_governors,
+                             scaling_available_governors);
 
     sysctl.cmd = XEN_SYSCTL_pm_op;
     sysctl.u.pm_op.cmd = GET_CPUFREQ_PARA;
@@ -258,9 +265,7 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
             user_para->gov_num  = sys_para->gov_num;
         }
 
-        if ( has_num )
-            goto unlock_4;
-        return ret;
+        goto unlock_4;
     }
     else
     {
Signature · 1 line
2.34.1
#67 lore raw

Re: [PATCH v5 16/18] tools: drop "has_num" condition check for cppc mode

Quoted 57 lines · Penny Zheng

In xenpm get-cpufreq-para <cpuid>, ->freq_num and ->cpu_num checking are tied together via variable "has_num", while ->freq_num only has non-zero value when cpufreq driver in legacy P-states mode.

So we drop the "has_num" condition check, and mirror the ->gov_num check for both ->freq_num and ->cpu_num in xc_get_cpufreq_para().

---
v3 -> v4:
- drop the "has_num" condition check
---
v4 -> v5:
- refactor title and commit
- make all three pieces (xc_hypercall_bounce_pre()) be as similar as possible

---
 tools/libs/ctrl/xc_pm.c | 43 +++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 19 deletions(-)
tools/libs/ctrl/xc_pm.c +11 -11
index 3c9e272aee..cdc072e757 100644
@@ -212,34 +212,41 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
     DECLARE_NAMED_HYPERCALL_BOUNCE(scaling_available_governors,
 			 user_para->scaling_available_governors,
 			 user_para->gov_num * CPUFREQ_NAME_LEN * sizeof(char), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
-    bool has_num = user_para->cpu_num && user_para->freq_num;
 
-    if ( has_num )
+    if ( (user_para->cpu_num && !user_para->affected_cpus) ||
+         (user_para->freq_num && !user_para->scaling_available_frequencies) ||
+         (user_para->gov_num && !user_para->scaling_available_governors) )
+    {
+        errno = EINVAL;
+        return -1;
+    }
+    if ( user_para->cpu_num )
     {
-        if ( (!user_para->affected_cpus)                    ||
-             (!user_para->scaling_available_frequencies)    ||
-             (user_para->gov_num && !user_para->scaling_available_governors) )
-        {
-            errno = EINVAL;
-            return -1;
-        }
         ret = xc_hypercall_bounce_pre(xch, affected_cpus);
         if ( ret )
             return ret;
+    }
+    if ( user_para->freq_num )
+    {
         ret = xc_hypercall_bounce_pre(xch, scaling_available_frequencies);
         if ( ret )
             goto unlock_2;
-        if ( user_para->gov_num )
-            ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);

tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 243

Quoted 10 lines
tools/libs/ctrl/xc_pm.c +6 -0
+    }
+    if ( user_para->gov_num )
+    {
+        ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);
         if ( ret )
             goto unlock_3;
+    }
 
+    if ( user_para->cpu_num )
         set_xen_guest_handle(sys_para->affected_cpus, affected_cpus);

Any reason this can't simply move up to the bottom of the identical conditional above?

tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 249

Quoted 11 lines
tools/libs/ctrl/xc_pm.c +6 -5
-        set_xen_guest_handle(sys_para->scaling_available_frequencies, scaling_available_frequencies);
-        if ( user_para->gov_num )
-            set_xen_guest_handle(sys_para->scaling_available_governors,
-                                 scaling_available_governors);
-    }
+    if ( user_para->freq_num )
+        set_xen_guest_handle(sys_para->scaling_available_frequencies,
+                             scaling_available_frequencies);
+    if ( user_para->gov_num )
+        set_xen_guest_handle(sys_para->scaling_available_governors,
+                             scaling_available_governors);

Same for these two then.

Jan

#68 lore raw

PATCH v5 17/18 tools: optimize cpufreq average freq print

In reply to Penny Zheng

Unlike Cx/Px states, for which we need an extra loop to summerize residency ( sum_cx[]/sum_px[]), we could call get_avgfreq_by_cpuid() right before printing. Also, with introduction of CPPC mode, average frequency print shall not depend on the existence of legacy P-states, so we remove "px_cap" dependancy check.

Fixes add6160d7 (Add cpufreq actual average freq information to xenpm tools)

---
v3 -> v4:
- new commit
---
v4 -> v5:
- refactor title and commit message
- call get_avgfreq_by_cpuid() right before printing

---
 tools/misc/xenpm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/misc/xenpm.c +2 -4
index f173e598ea..2864506da4 100644
@@ -497,9 +497,6 @@ static void signal_int_handler(int signo)
                                  pxstat_start[i].pt[j].residency;
     }
 
-    for ( i = 0; i < max_cpu_nr; i++ )
-        get_avgfreq_by_cpuid(xc_handle, i, &avgfreq[i]);
-
     printf("Elapsed time (ms): %"PRIu64"\n", (usec_end - usec_start) / 1000UL);
     for ( i = 0; i < max_cpu_nr; i++ )
     {
@@ -540,7 +537,8 @@ static void signal_int_handler(int signo)
                         res / 1000000UL, 100UL * res / (double)sum_px[i]);
             }
         }
-        if ( px_cap && avgfreq[i] )
+        get_avgfreq_by_cpuid(xc_handle, i, &avgfreq[i]);
+        if ( avgfreq[i] )
             printf("  Avg freq\t%d\tKHz\n", avgfreq[i]);
     }
 
Signature · 1 line
2.34.1
#69 lore raw

Re: [PATCH v5 17/18] tools: optimize cpufreq average freq print

Quoted 7 lines · Penny Zheng

Unlike Cx/Px states, for which we need an extra loop to summerize residency ( sum_cx[]/sum_px[]), we could call get_avgfreq_by_cpuid() right before printing. Also, with introduction of CPPC mode, average frequency print shall not depend on the existence of legacy P-states, so we remove "px_cap" dependancy check.

Fixes add6160d7 (Add cpufreq actual average freq information to xenpm tools)

Unlike in earlier instances, here you have a fixes tag when the title merely says "optimize". I also can't spot any bug that would be fixed here; what you address is indeed an inefficiency.

As and aside: The Fixes: tag wants 12 digits of the hash quoted, and the canonical form also has the title in quotes. You'll find numerous good examples in patches being submitted.

Jan

#70 lore raw

PATCH v5 18/18 xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

In reply to Penny Zheng

Introduce helper set_amd_cppc_para() and get_amd_cppc_para() to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.

In get_cpufreq_cppc()/set_cpufreq_cppc(), we use "processor_pminfo[cpuid]->init & XEN_CPPC_INIT" to identify cpufreq driver is amd-cppc/amd-cppc-epp. Furthermore, using whether ->setpolicy isn't null to tell whether amd-cppc in active mode.

Also, a new field "policy" has also been added in "struct xen_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. A set of public macro XEN_CPUFREQ_POLICY_xxx is introduced to be sync with internal ones CPUFREQ_POLICY_xxx.
A new policy XEN_CPUFREQ_POLICY_BALANCE is introduced, and could be achieved only via xenpm XEN_SYSCTL_CPPC_SET_PRESET_BALANCE preset.

---
v1 -> v2:
- Give the variable des_perf an initializer of 0
- Use the strncmp()s directly in the if()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replace amd_cppc_in_use flag with XEN_PROCESSOR_PM_CPPC
---
- add new field "policy" in "struct xen_cppc_para"
- add new performamce policy XEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init & XEN_CPPC_INIT" and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title

---
 tools/misc/xenpm.c                   |  10 +++
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 129 +++++++++++++++++++++++++++
 xen/drivers/acpi/pmstat.c            |  13 ++-
 xen/include/acpi/cpufreq/cpufreq.h   |  12 ++-
 xen/include/public/sysctl.h          |   5 ++
 5 files changed, 163 insertions(+), 6 deletions(-)
tools/misc/xenpm.c +10 -0
index 2864506da4..2e5975cae4 100644
@@ -38,6 +38,13 @@
 static xc_interface *xc_handle;
 static unsigned int max_cpu_nr;
 
+static const char cpufreq_policy_str[][12] = {
+    [XEN_CPUFREQ_POLICY_UNKNOWN] = "none",
+    [XEN_CPUFREQ_POLICY_POWERSAVE] = "powersave",
+    [XEN_CPUFREQ_POLICY_PERFORMANCE] = "performance",
+    [XEN_CPUFREQ_POLICY_BALANCE] = "balance",
+};
+
 /* help message */
 void show_help(void)
 {
@@ -984,6 +991,9 @@ static void print_cppc_para(unsigned int cpuid,
     printf("                     : desired [%"PRIu32"%s]\n",
            cppc->desired,
            cppc->desired ? "" : " hw autonomous");
+
+    printf("  performance policy : %s\n",
+           cpufreq_policy_str[cppc->policy]);
     printf("\n");
 }
 
xen/arch/x86/acpi/cpufreq/amd-cppc.c +129 -0

135 lines not on this page · raw message

xen/drivers/acpi/pmstat.c +10 -3
index e5f375921a..9e1ed29a0a 100644
@@ -334,6 +334,10 @@ static int get_cpufreq_cppc(struct xen_sysctl_pm_op *op)
     if ( hwp_active() )
         ret = get_hwp_para(op->cpuid, &op->u.cppc_para);
 
+    if ( processor_pminfo[op->cpuid]->init & XEN_CPPC_INIT )
+        ret = get_amd_cppc_para(per_cpu(cpufreq_cpu_policy, op->cpuid),
+                                &op->u.cppc_para);
+
     return ret;
 }
 
@@ -429,10 +433,13 @@ static int set_cpufreq_cppc(struct xen_sysctl_pm_op *op)
     if ( !policy || !policy->governor )
         return -ENOENT;
 
-    if ( !hwp_active() )
-        return -EOPNOTSUPP;
+    if ( hwp_active() )
+        return set_hwp_para(policy, &op->u.set_cppc);
+
+    if ( processor_pminfo[op->cpuid]->init & XEN_CPPC_INIT )
+        return set_amd_cppc_para(policy, &op->u.set_cppc);
 
-    return set_hwp_para(policy, &op->u.set_cppc);
+    return -EOPNOTSUPP;
 }
 
 int do_pm_op(struct xen_sysctl_pm_op *op)
xen/include/acpi/cpufreq/cpufreq.h +9 -3
index 6f31009e82..c542a6e633 100644
@@ -134,14 +134,16 @@ extern int cpufreq_register_governor(struct cpufreq_governor *governor);
 extern struct cpufreq_governor *__find_governor(const char *governor);
 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs
 
-#define CPUFREQ_POLICY_UNKNOWN      0
+#define CPUFREQ_POLICY_UNKNOWN      XEN_CPUFREQ_POLICY_UNKNOWN
 /*
  * If cpufreq_driver->target() exists, the ->governor decides what frequency
  * within the limits is used. If cpufreq_driver->setpolicy() exists, these
  * two generic policies are available:
  */
-#define CPUFREQ_POLICY_POWERSAVE    1
-#define CPUFREQ_POLICY_PERFORMANCE  2
+#define CPUFREQ_POLICY_POWERSAVE    XEN_CPUFREQ_POLICY_POWERSAVE
+#define CPUFREQ_POLICY_PERFORMANCE  XEN_CPUFREQ_POLICY_PERFORMANCE
+/* Achieved only via xenpm XEN_SYSCTL_CPPC_SET_PRESET_BALANCE preset */
+#define CPUFREQ_POLICY_BALANCE      XEN_CPUFREQ_POLICY_BALANCE
 
 unsigned int cpufreq_policy_from_governor(const struct cpufreq_governor *gov);
 
@@ -292,5 +294,9 @@ int acpi_cpufreq_register(void);
 
 int amd_cppc_cmdline_parse(const char *s, const char *e);
 int amd_cppc_register_driver(void);
+int get_amd_cppc_para(const struct cpufreq_policy *policy,
+                      struct xen_cppc_para *cppc_para);
+int set_amd_cppc_para(struct cpufreq_policy *policy,
+                      const struct xen_set_cppc_para *set_cppc);
 
 #endif /* __XEN_CPUFREQ_PM_H__ */
xen/include/public/sysctl.h +5 -0
index 29872fe508..18c38744ae 100644
@@ -308,6 +308,11 @@ struct xen_ondemand {
 
 struct xen_cppc_para {
     /* OUT */
+#define XEN_CPUFREQ_POLICY_UNKNOWN      0
+#define XEN_CPUFREQ_POLICY_POWERSAVE    1
+#define XEN_CPUFREQ_POLICY_PERFORMANCE  2
+#define XEN_CPUFREQ_POLICY_BALANCE      4
+    uint32_t policy;
     /* activity_window supported if set */
 #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW  (1 << 0)
     uint32_t features; /* bit flags for features */
Signature · 1 line
2.34.1
#71 lore raw

Re: [PATCH v5 18/18] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

tools/misc/xenpm.c line 42

Quoted 8 lines · Penny Zheng
tools/misc/xenpm.c +2 -0
@@ -38,6 +38,13 @@
 static xc_interface *xc_handle;
 static unsigned int max_cpu_nr;
 
+static const char cpufreq_policy_str[][12] = {
+    [XEN_CPUFREQ_POLICY_UNKNOWN] = "none",

Why not "unknown"?

Quoted 9 lines
tools/misc/xenpm.c +5 -0
+    [XEN_CPUFREQ_POLICY_POWERSAVE] = "powersave",
+    [XEN_CPUFREQ_POLICY_PERFORMANCE] = "performance",
+    [XEN_CPUFREQ_POLICY_BALANCE] = "balance",
+};
+
 /* help message */
 void show_help(void)
 {

tools/misc/xenpm.c static void print_cppc_para(unsigned int cpuid, · line 996

Quoted 6 lines
tools/misc/xenpm.c +3 -0
@@ -984,6 +991,9 @@ static void print_cppc_para(unsigned int cpuid,
     printf("                     : desired [%"PRIu32"%s]\n",
            cppc->desired,
            cppc->desired ? "" : " hw autonomous");
+
+    printf("  performance policy : %s\n",
+           cpufreq_policy_str[cppc->policy]);

What if for whatever reason the value you get is 4? Please avoid array overruns also in user space tools.

Quoted 43 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +37 -0
@@ -506,6 +506,135 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
     return 0;
 }
 
+int get_amd_cppc_para(const struct cpufreq_policy *policy,
+                      struct xen_cppc_para *cppc_para)
+{
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data,
+                                                   policy->cpu);
+
+    if ( data == NULL )
+        return -ENODATA;
+
+    cppc_para->policy           = policy->policy;
+    cppc_para->lowest           = data->caps.lowest_perf;
+    cppc_para->lowest_nonlinear = data->caps.lowest_nonlinear_perf;
+    cppc_para->nominal          = data->caps.nominal_perf;
+    cppc_para->highest          = data->caps.highest_perf;
+    cppc_para->minimum          = data->req.min_perf;
+    cppc_para->maximum          = data->req.max_perf;
+    cppc_para->desired          = data->req.des_perf;
+    cppc_para->energy_perf      = data->req.epp;
+
+    return 0;
+}
+
+int set_amd_cppc_para(struct cpufreq_policy *policy,
+                      const struct xen_set_cppc_para *set_cppc)
+{
+    unsigned int cpu = policy->cpu;
+    struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t max_perf, min_perf, des_perf = 0, epp;
+
+    if ( data == NULL )
+        return -ENOENT;
+
+    /* Validate all parameters */
+    if ( set_cppc->minimum > UINT8_MAX || set_cppc->maximum > UINT8_MAX ||
+         set_cppc->desired > UINT8_MAX || set_cppc->energy_perf > UINT8_MAX )
+        return -EINVAL;
+

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 555

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    /* Only allow values if params bit is set. */
+    if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) &&
+          set_cppc->desired) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM) &&
+          set_cppc->minimum) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) &&
+          set_cppc->maximum) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF) &&
+          set_cppc->energy_perf) )
+        return -EINVAL;

If the respective flag is set, is the field being zero legitimate? In patch 10 you reject finding zero perf values.

Quoted 38 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +38 -0
+    /* Activity window not supported in MSR */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW )
+        return -EOPNOTSUPP;
+
+    /* Return if there is nothing to do. */
+    if ( set_cppc->set_params == 0 )
+        return 0;
+
+    epp = per_cpu(epp_init, cpu);
+    /*
+     * Apply presets:
+     * XEN_SYSCTL_CPPC_SET_DESIRED reflects whether desired perf is set, which
+     * is also the flag to distinguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen.
+     * when it is not set, CPPC in active mode, three different profile
+     * XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANCE are provided,
+     */
+    switch ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_PRESET_MASK )
+    {
+    case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_POWERSAVE;
+        min_perf = data->caps.lowest_perf;
+        /* Lower max frequency to lowest */
+        max_perf = data->caps.lowest_perf;
+        epp = CPPC_ENERGY_PERF_MAX_POWERSAVE;
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        /* Increase idle frequency to highest */
+        policy->policy = CPUFREQ_POLICY_PERFORMANCE;
+        min_perf = data->caps.highest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_MAX_PERFORMANCE;

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 604

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_BALANCE;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;

Isn't this more line "ondemand"? To me, "balance" would mean tying perf to at least close around the middle of lowest and highest.

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 608

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+    case XEN_SYSCTL_CPPC_SET_PRESET_NONE:
+        /*
+         * In paasive mode, Xen governor is responsible for perfomance tuning.

Nit: passive

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 613

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+         * we shall set lowest_perf with "lowest_nonlinear_perf" to ensure
+         * governoring performance in P-states range.
+         */
+        min_perf = data->caps.lowest_nonlinear_perf;
+        max_perf = data->caps.highest_perf;

As in the earlier patch - I fear I don't understand the comment, and hence why to use lowest-nonlinear here remains unclear to me.

xen/drivers/acpi/pmstat.c static int get_cpufreq_cppc(struct xen_sysctl_pm_op *op) · line 339

Quoted 9 lines
xen/drivers/acpi/pmstat.c +3 -0
@@ -334,6 +334,10 @@ static int get_cpufreq_cppc(struct xen_sysctl_pm_op *op)
     if ( hwp_active() )
         ret = get_hwp_para(op->cpuid, &op->u.cppc_para);
 
+    if ( processor_pminfo[op->cpuid]->init & XEN_CPPC_INIT )
+        ret = get_amd_cppc_para(per_cpu(cpufreq_cpu_policy, op->cpuid),
+                                &op->u.cppc_para);

This is a case where I think you would better use "else if". Otherwise it looks as if both paths could be taken (and "ret" as well as op->u.cppc_para be overwritten BY this second call).

Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +1 -1
@@ -134,14 +134,16 @@ extern int cpufreq_register_governor(struct cpufreq_governor *governor);
 extern struct cpufreq_governor *__find_governor(const char *governor);
 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs
 
-#define CPUFREQ_POLICY_UNKNOWN      0
+#define CPUFREQ_POLICY_UNKNOWN      XEN_CPUFREQ_POLICY_UNKNOWN
 /*

xen/include/acpi/cpufreq/cpufreq.h extern int cpufreq_register_governor(struct cpufreq_governor *governor); · line 146

Quoted 10 lines
xen/include/acpi/cpufreq/cpufreq.h +4 -2
  * If cpufreq_driver->target() exists, the ->governor decides what frequency
  * within the limits is used. If cpufreq_driver->setpolicy() exists, these
  * two generic policies are available:
  */
-#define CPUFREQ_POLICY_POWERSAVE    1
-#define CPUFREQ_POLICY_PERFORMANCE  2
+#define CPUFREQ_POLICY_POWERSAVE    XEN_CPUFREQ_POLICY_POWERSAVE
+#define CPUFREQ_POLICY_PERFORMANCE  XEN_CPUFREQ_POLICY_PERFORMANCE
+/* Achieved only via xenpm XEN_SYSCTL_CPPC_SET_PRESET_BALANCE preset */
+#define CPUFREQ_POLICY_BALANCE      XEN_CPUFREQ_POLICY_BALANCE

We don't need both sets of manifest constants, do we?

Jan

#72 lore raw

RE: [PATCH v5 18/18] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

[Public]

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:38 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 18/18] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

On 27.05.2025 10:48, Penny Zheng wrote:

Quoted 15 lines

tools/misc/xenpm.c

Quoted 11 lines
tools/misc/xenpm.c +9 -0
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_BALANCE;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;

Isn't this more line "ondemand"? To me, "balance" would mean tying perf to at least close around the middle of lowest and highest.

The "balance" word comes from the epp value, it is 127, which is the middle value
In actual hardware algorithm, the value of Energy Performance Preference register(EPP) will be translated to frequency setting,
And it sets the minimum active frequency.
An EPP of zero sets the min active frequency to Fmax, while an EPP of 255 sets the min active frequency to Fmin (~IdleFreq). It is linear scaling, so epp of 127 is calculated to the middle of Fmax and Fmin.
And Fmax corresponds to the highest perf, and Fmin corresponds to the non-linear lowest perf

Quoted 6 lines

tools/misc/xenpm.c

Quoted 3 lines
tools/misc/xenpm.c +3 -0
+    case XEN_SYSCTL_CPPC_SET_PRESET_NONE:
+        /*
+         * In paasive mode, Xen governor is responsible for perfomance tuning.

Nit: passive

Quoted 9 lines

tools/misc/xenpm.c

Quoted 5 lines
tools/misc/xenpm.c +5 -0
+         * we shall set lowest_perf with "lowest_nonlinear_perf" to ensure
+         * governoring performance in P-states range.
+         */
+        min_perf = data->caps.lowest_nonlinear_perf;
+        max_perf = data->caps.highest_perf;

As in the earlier patch - I fear I don't understand the comment, and hence why to use lowest-nonlinear here remains unclear to me.

After previous discussion, I'll use non-linear lowest in all places

Quoted 1 line

Jan

#73 lore raw

Re: [PATCH v5 18/18] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

Quoted 20 lines · Zheng
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:38 PM

On 27.05.2025 10:48, Penny Zheng wrote:

Quoted 14 lines

tools/misc/xenpm.c

Quoted 11 lines
tools/misc/xenpm.c +9 -0
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_BALANCE;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;

Isn't this more line "ondemand"? To me, "balance" would mean tying perf to at least close around the middle of lowest and highest.

Quoted 5 lines

The "balance" word comes from the epp value, it is 127, which is the middle value
In actual hardware algorithm, the value of Energy Performance Preference register(EPP) will be translated to frequency setting,
And it sets the minimum active frequency.
An EPP of zero sets the min active frequency to Fmax, while an EPP of 255 sets the min active frequency to Fmin (~IdleFreq). It is linear scaling, so epp of 127 is calculated to the middle of Fmax and Fmin.
And Fmax corresponds to the highest perf, and Fmin corresponds to the non-linear lowest perf

I'm fine with the EPP value picked here. My question - as to the min_perf and max_perf values that you set - remains, though.

Jan

#74 lore raw

Re: [PATCH v5 18/18] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

In reply to Penny Zheng
Quoted 74 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +74 -0
+int set_amd_cppc_para(struct cpufreq_policy *policy,
+                      const struct xen_set_cppc_para *set_cppc)
+{
+    unsigned int cpu = policy->cpu;
+    struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+    uint8_t max_perf, min_perf, des_perf = 0, epp;
+
+    if ( data == NULL )
+        return -ENOENT;
+
+    /* Validate all parameters */
+    if ( set_cppc->minimum > UINT8_MAX || set_cppc->maximum > UINT8_MAX ||
+         set_cppc->desired > UINT8_MAX || set_cppc->energy_perf > UINT8_MAX )
+        return -EINVAL;
+
+    /* Only allow values if params bit is set. */
+    if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) &&
+          set_cppc->desired) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM) &&
+          set_cppc->minimum) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) &&
+          set_cppc->maximum) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF) &&
+          set_cppc->energy_perf) )
+        return -EINVAL;
+
+    /* Activity window not supported in MSR */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW )
+        return -EOPNOTSUPP;
+
+    /* Return if there is nothing to do. */
+    if ( set_cppc->set_params == 0 )
+        return 0;
+
+    epp = per_cpu(epp_init, cpu);
+    /*
+     * Apply presets:
+     * XEN_SYSCTL_CPPC_SET_DESIRED reflects whether desired perf is set, which
+     * is also the flag to distinguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen.
+     * when it is not set, CPPC in active mode, three different profile
+     * XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANCE are provided,
+     */
+    switch ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_PRESET_MASK )
+    {
+    case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_POWERSAVE;
+        min_perf = data->caps.lowest_perf;
+        /* Lower max frequency to lowest */
+        max_perf = data->caps.lowest_perf;
+        epp = CPPC_ENERGY_PERF_MAX_POWERSAVE;
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        /* Increase idle frequency to highest */
+        policy->policy = CPUFREQ_POLICY_PERFORMANCE;
+        min_perf = data->caps.highest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_MAX_PERFORMANCE;
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE:
+        if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+            return -EINVAL;
+        policy->policy = CPUFREQ_POLICY_BALANCE;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;

xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 614

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_NONE:
+        /*
+         * In paasive mode, Xen governor is responsible for perfomance tuning.
+         * we shall set lowest_perf with "lowest_nonlinear_perf" to ensure
+         * governoring performance in P-states range.
+         */
+        min_perf = data->caps.lowest_nonlinear_perf;
+        max_perf = data->caps.highest_perf;
+        break;

Oh, also - can you really leave policy->policy unaltered here?

Jan

#75 lore raw
In reply to Penny Zheng
Quoted 55 lines · Penny Zheng

amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism on modern AMD APU and CPU series in Xen. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which provides finer grain frequency management than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.

amd_cppc driver has 2 operation modes: autonomous (active) mode, and non-autonomous (passive) mode. We register different CPUFreq driver for different modes, "amd-cppc" for passive mode and "amd-cppc-epp" for active mode.

The passive mode leverages common governors such as *ondemand*, *performance*, etc, to manage the performance tuning. While the active mode uses epp to provides a hint to the hardware if software wants to bias toward performance (0x0) or energy efficiency (0xff). CPPC power algorithm in hardware will automatically calculate the runtime workload and adjust the realtime cpu cores frequency according to the power supply and thermal, core voltage and some other hardware conditions.

amd-cppc is enabled on passive mode with a top-level cpufreq=amd-cppc option, while users add extra active flag to select active mode.

With cpufreq=amd-cppc,active, we did a 60s sampling test to see the CPU frequency change, through tweaking the energy_perf preference from xenpm set-cpufreq-cppc powersave to xenpm set-cpufreq-cppc performance. The outputs are as follows:
```
Setting CPU in powersave mode
Sampling and Outputs:

  Avg freq      580000 KHz
  Avg freq      580000 KHz
  Avg freq      580000 KHz
Setting CPU in performance mode
Sampling and Outputs:
  Avg freq      4640000 KHz
  Avg freq      4220000 KHz
  Avg freq      4640000 KHz

Penny Zheng (18):
xen/cpufreq: guard perf.states[] access with XEN_PX_INIT xen/cpufreq: move "init" flag into common structure xen/cpufreq: extract _PSD info from "struct xen_processor_performance" xen/cpufreq: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/cpufreq: introduce "cpufreq=amd-cppc" xen cmdline xen/cpufreq: disable px statistic info in amd-cppc mode xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs xen/amd: introduce amd_process_freq() to get processor frequency xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling xen/cpufreq: implement EPP support for the amd-cppc driver in active
mode

Quoted 8 lines

xen/cpufreq: get performance policy from governor set via xenpm xen/cpufreq: normalize hwp driver check with hwp_active() xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd xen/cpufreq: bypass governor-related para for amd-cppc-epp
tools: drop "has_num" condition check for cppc mode
tools: optimize cpufreq average freq print
xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver

As indicated in individual replies, three of the patches may be possible to go in before you re-post. Subject to what I said in the replies (patches 02, 08, and 13). Please clarify what (if anything) to do.

Jan

#76 lore raw

[Public]

Quoted 76 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, June 17, 2025 6:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Stefano Stabellini <[email protected]>; Juergen Gross <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v5 00/18] amd-cppc CPU Performance Scaling Driver

Quoted 23 lines · Penny Zheng

amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism on modern AMD APU and CPU series in Xen. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which provides finer grain frequency management than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.

amd_cppc driver has 2 operation modes: autonomous (active) mode, and non-autonomous (passive) mode. We register different CPUFreq driver for different modes, "amd-cppc" for passive mode and "amd-cppc-epp" for active mode.

The passive mode leverages common governors such as *ondemand*, *performance*, etc, to manage the performance tuning. While the active mode uses epp to provides a hint to the hardware if software wants to bias toward performance (0x0) or energy efficiency (0xff). CPPC power algorithm in hardware will automatically calculate the runtime workload and adjust the realtime cpu cores frequency according to the power supply and thermal, core voltage and some other hardware conditions.

Quoted 2 lines

amd-cppc is enabled on passive mode with a top-level cpufreq=amd-cppc option, while users add extra active flag to select active

mode.

Quoted 29 lines

With cpufreq=amd-cppc,active, we did a 60s sampling test to see the CPU frequency change, through tweaking the energy_perf preference from xenpm set-cpufreq-cppc powersave to xenpm set-cpufreq-cppc performance. The outputs are as follows:
```
Setting CPU in powersave mode
Sampling and Outputs:

  Avg freq      580000 KHz
  Avg freq      580000 KHz
  Avg freq      580000 KHz
Setting CPU in performance mode
Sampling and Outputs:
  Avg freq      4640000 KHz
  Avg freq      4220000 KHz
  Avg freq      4640000 KHz

Penny Zheng (18):
xen/cpufreq: guard perf.states[] access with XEN_PX_INIT xen/cpufreq: move "init" flag into common structure xen/cpufreq: extract _PSD info from "struct xen_processor_performance" xen/cpufreq: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/cpufreq: introduce "cpufreq=amd-cppc" xen cmdline xen/cpufreq: disable px statistic info in amd-cppc mode xen/cpu: Expand core frequency calculation for AMD Family 1Ah CPUs xen/amd: introduce amd_process_freq() to get processor frequency xen/cpufreq: introduce a new amd cppc driver for cpufreq scaling xen/cpufreq: implement EPP support for the amd-cppc driver in active

Quoted 8 lines

mode
xen/cpufreq: get performance policy from governor set via xenpm xen/cpufreq: normalize hwp driver check with hwp_active() xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-cmd xen/cpufreq: bypass governor-related para for amd-cppc-epp
tools: drop "has_num" condition check for cppc mode
tools: optimize cpufreq average freq print xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-

Quoted 7 lines

cppc

Quoted 1 line

driver

As indicated in individual replies, three of the patches may be possible to go in before you re-post. Subject to what I said in the replies (patches 02, 08, and 13). Please clarify what (if anything) to do.

For patch 02, the only concern is that it is based on 01, and 01 shall be removed and I'll add extra check for CPPC to ensure ->perf.state_count must be zero in get_cpufreq_para() For patch 08, I already have agreed in individual reply
For patch 13, ok for me too

Quoted 1 line

Jan