Skip to contentSkip to conversation

amd-cppc CPU Performance Scaling Driver

PATCH Superseded Penny Zheng 2 participants 72 messages Apr 14, 2025 – Jun 19, 2025

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 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 hints. And 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      2000000 KHz
  Avg freq      2000000 KHz
  Avg freq      2000000 KHz
Setting CPU in performance mode
Sampling and Outputs:
  Avg freq      4640000 KHz
  Avg freq      4220000 KHz
  Avg freq      4640000 KHz

Penny Zheng (15):
xen/cpufreq: move "init" flag into common structure xen/cpufreq: extract _PSD info from "struct xen_processor_performance" xen/x86: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/x86: introduce "cpufreq=amd-cppc" xen cmdline xen/cpufreq: disable px statistic info in amd-cppc mode xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs xen/amd: introduce amd_process_freq() to get processor frequency xen/x86: introduce a new amd cppc driver for cpufreq scaling xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL xen/x86: implement EPP support for the amd-cppc driver in active mode tools/xenpm: Print CPPC parameters for amd-cppc driver tools/xenpm: fix unnecessary scaling_available_frequencies in CPPC
mode
tools/xenpm: remove px_cap dependency check for average frequency xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver

 docs/misc/xen-command-line.pandoc         |  13 +-
 tools/libs/ctrl/xc_pm.c                   |  45 +-
 tools/misc/xenpm.c                        |  20 +-
 xen/arch/x86/acpi/cpufreq/Makefile        |   1 +
 xen/arch/x86/acpi/cpufreq/acpi.c          |  14 +-
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 708 ++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       |  34 +-
 xen/arch/x86/cpu/amd.c                    |  81 ++-
 xen/arch/x86/include/asm/amd.h            |   4 +
 xen/arch/x86/include/asm/msr-index.h      |   6 +
 xen/arch/x86/platform_hypercall.c         |  16 +
 xen/drivers/acpi/pmstat.c                 |  42 +-
 xen/drivers/cpufreq/cpufreq.c             | 306 ++++++++--
 xen/drivers/cpufreq/utility.c             |  14 +
 xen/include/acpi/cpufreq/cpufreq.h        |  22 +-
 xen/include/acpi/cpufreq/processor_perf.h |  11 +-
 xen/include/public/platform.h             |  36 +-
 xen/include/public/sysctl.h               |   2 +
 xen/include/xen/pmstat.h                  |   2 +
 xen/include/xlat.lst                      |   1 +
 20 files changed, 1268 insertions(+), 110 deletions(-)
 create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/15 xen/cpufreq: move "init" flag into common structure

AMD cpufreq cores will be intialized in two modes, legacy P-state mode, and CPPC mode. So "init" flag shall be extracted from specific "struct xen_processor_perf", and placed in the common "struct processor_pminfo".

---
v3 -> v4:
- new commit

---
 xen/drivers/acpi/pmstat.c                 | 4 ++--
 xen/drivers/cpufreq/cpufreq.c             | 8 ++++----
 xen/include/acpi/cpufreq/processor_perf.h | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)
xen/drivers/acpi/pmstat.c +2 -2
index c51b9ca358..767594908c 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:
@@ -463,7 +463,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 4a103c6de9..b01ed8e294 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)
@@ -367,7 +367,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))
@@ -563,7 +563,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;
@@ -572,7 +572,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
#2 lore raw

Re: [PATCH v4 01/15] xen/cpufreq: move "init" flag into common structure

Quoted 4 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 specific "struct xen_processor_perf", and placed in the common "struct processor_pminfo".

The code change is certainly acceptable, as being largely mechanical. However, the above doesn't explain _why_ we need that change. There's probably a little more connection that needs making between that's there and what you mean to add.

Jan

#3 lore raw

RE: [PATCH v4 01/15] xen/cpufreq: move "init" flag into common structure

[Public]

Hi,

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, April 17, 2025 11:12 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 01/15] xen/cpufreq: move "init" flag into common structure

Quoted 4 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 specific "struct xen_processor_perf", and placed in the common "struct processor_pminfo".

Quoted 5 lines

The code change is certainly acceptable, as being largely mechanical. However, the above doesn't explain _why_ we need that change. There's probably a little more connection that needs making between that's there and what you mean to add.

How about complement the following description:

```
Otherwise, later when introducing new sub-hypercall
to propagate CPPC data in commit "xen/x86: introduce new sub-hypercall to
propagate CPPC data", we need to pass irrelevant px-specific
"struct xen_processor_perf" in set_cppc_pminfo() to just set init flag.
```
Quoted 1 line

Jan

#4 lore raw

Re: [PATCH v4 01/15] xen/cpufreq: move "init" flag into common structure

Quoted 23 lines · Zheng

[Public]

Hi,

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, April 17, 2025 11:12 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 01/15] xen/cpufreq: move "init" flag into common structure

Quoted 4 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 specific "struct xen_processor_perf", and placed in the common "struct processor_pminfo".

Quoted 5 lines

The code change is certainly acceptable, as being largely mechanical. However, the above doesn't explain _why_ we need that change. There's probably a little more connection that needs making between that's there and what you mean to add.

Quoted 7 lines

How about complement the following description:

```
Otherwise, later when introducing new sub-hypercall
to propagate CPPC data in commit "xen/x86: introduce new sub-hypercall to
propagate CPPC data", we need to pass irrelevant px-specific
"struct xen_processor_perf" in set_cppc_pminfo() to just set init flag.
```

If spelled out in more abstract terms, in particular without a forward reference to a future commit, whose title may still change, this may then be okay if added.

Jan

#5 lore raw

PATCH v4 2/15 xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

In reply to Penny Zheng

Since we need to re-use _PSD info, containing "shared_type" and "struct xen_psd_package", for CPPC mode, we move all "#define XEN_CPUPERF_SHARED_TYPE_xxx" up as common values, and introduce a new helper check_psd_pminfo() to wrap _PSD info check.

In cpufreq_add/del_cpu(), a new helper get_psd_info() is introduced to extract "shared_type" and "struct xen_psd_package" from "struct xen_processor_performance", and a few indentation get fixed at the same time.

---
v3 -> v4:
- new commit

---
 xen/drivers/cpufreq/cpufreq.c | 107 ++++++++++++++++++++++++----------
 xen/include/public/platform.h |  10 ++--
 2 files changed, 82 insertions(+), 35 deletions(-)
xen/drivers/cpufreq/cpufreq.c +76 -31
index b01ed8e294..b020ccbcf7 100644
@@ -191,9 +191,31 @@ 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(uint32_t init, unsigned int cpu,
+                        uint32_t *shared_type,
+                        struct xen_psd_package *domain_info)
 {
     int ret = 0;
+
+    switch ( init )
+    {
+    case XEN_PX_INIT:
+        if ( shared_type )
+            *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        if ( domain_info )
+            *domain_info = 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 +223,13 @@ 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;
+    struct xen_psd_package 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 +239,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(processor_pminfo[cpu]->init, cpu,
+                       &shared_type, &domain_info);
+    if ( ret )
+        return ret;
+
+    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,20 +270,27 @@ 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;
+        struct xen_psd_package 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(processor_pminfo[firstcpu]->init, firstcpu,
+                           &firstcpu_shared_type, &firstcpu_domain_info);
+        if ( ret )
+            return ret;
+
+        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 +337,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));
         policy->governor = NULL;
 
@@ -354,29 +388,34 @@ 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;
+    struct xen_psd_package 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(processor_pminfo[cpu]->init, cpu,
+                       &shared_type, &domain_info);
+    if ( ret )
+        return ret;
+
+    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) {
@@ -392,8 +431,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);
@@ -458,6 +497,17 @@ static void print_PPC(unsigned int platform_limit)
     printk("\t_PPC: %d\n", platform_limit);
 }
 
+static int check_psd_pminfo(const struct xen_processor_performance *perf)
+{
+    /* 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 )
+        return -EINVAL;
+
+    return 0;
+}
+
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 {
     int ret = 0, cpu;
@@ -539,14 +589,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);
+        if ( ret )
             goto out;
-        }
 
         pxpt->shared_type = perf->shared_type;
         memcpy(&pxpt->domain_info, &perf->domain_info,
xen/include/public/platform.h +6 -4
index 2725b8d104..67cf5eeabd 100644
@@ -440,6 +440,11 @@ struct xen_psd_package {
     uint64_t num_processors;
 };
 
+/* Coordination type value */
+#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 */
+
 struct xen_processor_performance {
     uint32_t flags;     /* flag for Px sub info type */
     uint32_t platform_limit;  /* Platform limitation on freq usage */
@@ -449,10 +454,7 @@ struct xen_processor_performance {
     XEN_GUEST_HANDLE(xen_processor_px_t) states;
     struct xen_psd_package domain_info;
     /* 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;
+    uint32_t shared_type; /* XEN_CPUPERF_SHARED_TYPE_xxx */
 };
 typedef struct xen_processor_performance xen_processor_performance_t;
 DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 194

Quoted 8 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +1 -1
@@ -191,9 +191,31 @@ 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(uint32_t init, unsigned int cpu,

The 1st parameter seems unnecessary: You access processor_pminfo[cpu] below anyway, so you could as well use ...

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 200

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+                        uint32_t *shared_type,
+                        struct xen_psd_package *domain_info)
 {
     int ret = 0;
+
+    switch ( init )

... processor_pminfo[cpu]->init here.

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 206

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+    case XEN_PX_INIT:
+        if ( shared_type )
+            *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        if ( domain_info )
+            *domain_info = processor_pminfo[cpu]->perf.domain_info;

Does this need to be a structure copy? Can't you hand back just a pointer, with the function parameter being const struct xen_psd_package **?

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 208

Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +2 -0
+        break;
+    default:

Nit: Blank line please between non-fall-through case blocks.

Quoted 16 lines
xen/include/public/platform.h +5 -0
@@ -440,6 +440,11 @@ struct xen_psd_package {
     uint64_t num_processors;
 };
 
+/* Coordination type value */
+#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 */
+
 struct xen_processor_performance {
     uint32_t flags;     /* flag for Px sub info type */
     uint32_t platform_limit;  /* Platform limitation on freq usage */
@@ -449,10 +454,7 @@ struct xen_processor_performance {
     XEN_GUEST_HANDLE(xen_processor_px_t) states;

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

Quoted 10 lines
xen/include/public/platform.h +1 -4
     struct xen_psd_package domain_info;
     /* 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;
+    uint32_t shared_type; /* XEN_CPUPERF_SHARED_TYPE_xxx */
 };
 typedef struct xen_processor_performance xen_processor_performance_t;
 DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);

What's this movement about? In the public interface nothing changes?

Jan

#7 lore raw

RE: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

[Public]

Hi,

Quoted 40 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 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]>; [email protected]
Subject: Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

xen/include/public/platform.h struct xen_psd_package { · line 444

Quoted 8 lines · Penny Zheng
xen/include/public/platform.h +2 -0
@@ -440,6 +440,11 @@ struct xen_psd_package {
     uint64_t num_processors;
 };
 
+/* Coordination type value */
+#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed

coordination */

xen/include/public/platform.h struct xen_psd_package { · line 445

Quoted 1 line
xen/include/public/platform.h +1 -0
+#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs

should

xen/include/public/platform.h struct xen_psd_package { · line 446

Quoted 1 line
xen/include/public/platform.h +1 -0
+set freq */ #define XEN_CPUPERF_SHARED_TYPE_ANY  3 /* Freq can be

set

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

Quoted 10 lines
xen/include/public/platform.h +2 -1
+from any dependent CPU */
+
 struct xen_processor_performance {
     uint32_t flags;     /* flag for Px sub info type */
     uint32_t platform_limit;  /* Platform limitation on freq usage */
@@ -449,10 +454,7 @@ struct xen_processor_performance {
     XEN_GUEST_HANDLE(xen_processor_px_t) states;
     struct xen_psd_package domain_info;
     /* Coordination type of this processor */
-#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed

coordination */

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

Quoted 1 line
xen/include/public/platform.h +0 -1
-#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs

should

Quoted 1 line

set freq */ -#define XEN_CPUPERF_SHARED_TYPE_ANY 3 /* Freq can be set

Quoted 9 lines

from any dependent CPU */

Quoted 5 lines
xen/include/public/platform.h +1 -1
-    uint32_t shared_type;
+    uint32_t shared_type; /* XEN_CPUPERF_SHARED_TYPE_xxx */
 };
 typedef struct xen_processor_performance xen_processor_performance_t;

DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);

What's this movement about? In the public interface nothing changes?

As we will have shared type in "struct xen_processor_cppc" too, maybe the definition would like to live
at more common place, then it could be shared?
Living inside "struct xen_processor_performance" looks like internal values for internal field.
If it breaks the public interface some way, I'll change it back and duplicate the definition in "struct xen_processor_cppc" too

Quoted 1 line

Jan

#8 lore raw

Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 51 lines · Zheng

[Public]

Hi,

Quoted 47 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 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]>; [email protected]
Subject: Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

xen/include/public/platform.h struct xen_psd_package { · line 444

Quoted 8 lines · Penny Zheng
xen/include/public/platform.h +2 -0
@@ -440,6 +440,11 @@ struct xen_psd_package {
     uint64_t num_processors;
 };
 
+/* Coordination type value */
+#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed

coordination */

xen/include/public/platform.h struct xen_psd_package { · line 445

Quoted 1 line
xen/include/public/platform.h +1 -0
+#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs

should

xen/include/public/platform.h struct xen_psd_package { · line 446

Quoted 1 line
xen/include/public/platform.h +1 -0
+set freq */ #define XEN_CPUPERF_SHARED_TYPE_ANY  3 /* Freq can be

set

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

Quoted 10 lines
xen/include/public/platform.h +2 -1
+from any dependent CPU */
+
 struct xen_processor_performance {
     uint32_t flags;     /* flag for Px sub info type */
     uint32_t platform_limit;  /* Platform limitation on freq usage */
@@ -449,10 +454,7 @@ struct xen_processor_performance {
     XEN_GUEST_HANDLE(xen_processor_px_t) states;
     struct xen_psd_package domain_info;
     /* Coordination type of this processor */
-#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed

coordination */

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

Quoted 1 line
xen/include/public/platform.h +0 -1
-#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs

should

Quoted 1 line

set freq */ -#define XEN_CPUPERF_SHARED_TYPE_ANY 3 /* Freq can be set

from any dependent CPU */

Quoted 5 lines
xen/include/public/platform.h +1 -1
-    uint32_t shared_type;
+    uint32_t shared_type; /* XEN_CPUPERF_SHARED_TYPE_xxx */
 };
 typedef struct xen_processor_performance xen_processor_performance_t;

DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);

Quoted 6 lines
Quoted 1 line

What's this movement about? In the public interface nothing changes?

As we will have shared type in "struct xen_processor_cppc" too, maybe the definition would like to live
at more common place, then it could be shared?
Living inside "struct xen_processor_performance" looks like internal values for internal field.
If it breaks the public interface some way, I'll change it back and duplicate the definition in "struct xen_processor_cppc" too

I don't think it would break anything, but I also don't see any need for the movement. And generally we prefer to avoid unnecessary code churn.

Jan

#9 lore raw

RE: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

[Public]

Hi

Quoted 72 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 12, 2025 11:43 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 v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 54 lines · Zheng

[Public]

Hi,

Quoted 50 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 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]>; [email protected]
Subject: Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

xen/include/public/platform.h struct xen_psd_package { · line 444

Quoted 8 lines · Penny Zheng
xen/include/public/platform.h +2 -0
@@ -440,6 +440,11 @@ struct xen_psd_package {
     uint64_t num_processors;
 };
 
+/* Coordination type value */
+#define XEN_CPUPERF_SHARED_TYPE_HW   1 /* HW does needed

coordination */

xen/include/public/platform.h struct xen_psd_package { · line 445

Quoted 1 line
xen/include/public/platform.h +1 -0
+#define XEN_CPUPERF_SHARED_TYPE_ALL  2 /* All dependent CPUs

should

xen/include/public/platform.h struct xen_psd_package { · line 446

Quoted 1 line
xen/include/public/platform.h +1 -0
+set freq */ #define XEN_CPUPERF_SHARED_TYPE_ANY  3 /* Freq can be

set

Quoted 10 lines
xen/include/public/platform.h +2 -0
+from any dependent CPU */
+
 struct xen_processor_performance {
     uint32_t flags;     /* flag for Px sub info type */
     uint32_t platform_limit;  /* Platform limitation on freq usage
*/ @@ -449,10 +454,7 @@ struct xen_processor_performance {
     XEN_GUEST_HANDLE(xen_processor_px_t) states;
     struct xen_psd_package domain_info;
     /* Coordination type of this processor */

-#define XEN_CPUPERF_SHARED_TYPE_HW 1 /* HW does needed

coordination */

Quoted 1 line

-#define XEN_CPUPERF_SHARED_TYPE_ALL 2 /* All dependent CPUs

should

Quoted 2 lines

set freq */ -#define XEN_CPUPERF_SHARED_TYPE_ANY 3 /* Freq can be set

from any dependent CPU */

Quoted 6 lines
xen/include/public/platform.h +1 -1
-    uint32_t shared_type;
+    uint32_t shared_type; /* XEN_CPUPERF_SHARED_TYPE_xxx */
 };
 typedef struct xen_processor_performance

xen_processor_performance_t; DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);

Quoted 5 lines
Quoted 1 line

What's this movement about? In the public interface nothing changes?

As we will have shared type in "struct xen_processor_cppc" too, maybe the definition would like to live at more common place, then it could be shared? Living inside "struct xen_processor_performance" looks like internal values for

Quoted 6 lines

internal field.

Quoted 2 lines

If it breaks the public interface some way, I'll change it back and duplicate the definition in "struct xen_processor_cppc" too

I don't think it would break anything, but I also don't see any need for the movement. And generally we prefer to avoid unnecessary code churn.

Understood, then I'll delete this change.

Quoted 2 lines

Jan

#10 lore raw

RE: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

In reply to Jan Beulich

[Public]

Hi,

Quoted 13 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 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]>; [email protected]
Subject: Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

On 14.04.2025 09:40, Penny Zheng wrote:

Quoted 12 lines

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 206

Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+    case XEN_PX_INIT:
+        if ( shared_type )
+            *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        if ( domain_info )
+            *domain_info = processor_pminfo[cpu]->perf.domain_info;

Does this need to be a structure copy? Can't you hand back just a pointer, with the function parameter being const struct xen_psd_package **?

I've considered handing backing a pointer, then maybe we need to allocate space for "struct xen_psd_package **domain_info = xvzalloc(struct xen_psd_package *);", and XVFREE(xxx) it in each exit, especially cpufreq_add_cpu() has a lot exits, which could be a few code churn. So I chose the struct copy to have the smallest change.

Quoted 3 lines

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 208

Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +2 -0
+        break;
+    default:

Jan

#11 lore raw

Re: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 18 lines · Zheng
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 PM

On 14.04.2025 09:40, Penny Zheng wrote:

Quoted 12 lines

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 206

Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+    case XEN_PX_INIT:
+        if ( shared_type )
+            *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        if ( domain_info )
+            *domain_info = processor_pminfo[cpu]->perf.domain_info;

Does this need to be a structure copy? Can't you hand back just a pointer, with the function parameter being const struct xen_psd_package **?

Quoted 4 lines

I've considered handing backing a pointer, then maybe we need to allocate space for "struct xen_psd_package **domain_info = xvzalloc(struct xen_psd_package *);", and XVFREE(xxx) it in each exit, especially cpufreq_add_cpu() has a lot exits, which could be a few code churn. So I chose the struct copy to have the smallest change.

I fear I don't see why such allocations (of space holding a single pointer) would be necessary. Afaict all you need is a local variable of the specific (pointer) type, the address of which you pass into here.

Jan

#12 lore raw

RE: [PATCH v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

[Public]

Quoted 34 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 12, 2025 11:45 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 v4 02/15] xen/cpufreq: extract _PSD info from "struct xen_processor_performance"

Quoted 18 lines · Zheng
Quoted 5 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:32 PM

On 14.04.2025 09:40, Penny Zheng wrote:

Quoted 12 lines

xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 206

Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+    case XEN_PX_INIT:
+        if ( shared_type )
+            *shared_type = processor_pminfo[cpu]->perf.shared_type;
+        if ( domain_info )
+            *domain_info = processor_pminfo[cpu]->perf.domain_info;

Does this need to be a structure copy? Can't you hand back just a pointer, with the function parameter being const struct xen_psd_package **?

Quoted 3 lines

I've considered handing backing a pointer, then maybe we need to allocate space for "struct xen_psd_package **domain_info = xvzalloc(struct xen_psd_package *);", and XVFREE(xxx) it in each exit,

Quoted 7 lines

especially cpufreq_add_cpu() has a lot exits, which could be a few code churn.

Quoted 1 line

So I chose the struct copy to have the smallest change.

I fear I don't see why such allocations (of space holding a single pointer) would be necessary. Afaict all you need is a local variable of the specific (pointer) type, the address of which you pass into here.

```
        struct xen_psd_package *domain_info;
        struct xen_psd_package **domain_info_ptr = &domain_info;
```

Oh, right, I could create a local variable to avoid nullptr initialization.

Quoted 1 line

Jan

#13 lore raw

PATCH v4 3/15 xen/x86: 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 Norminal frequency, to let OS use Lowest Frequency/ Performance and Nominal Frequency/Performance as anchor points to create linear mapping of CPPC abstract performance to CPU frequency.

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.

---
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

---
 xen/arch/x86/platform_hypercall.c         |   5 +
 xen/drivers/cpufreq/cpufreq.c             | 131 ++++++++++++++++++++--
 xen/include/acpi/cpufreq/processor_perf.h |   4 +-
 xen/include/public/platform.h             |  26 +++++
 xen/include/xen/pmstat.h                  |   2 +
 xen/include/xlat.lst                      |   1 +
 6 files changed, 161 insertions(+), 8 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/drivers/cpufreq/cpufreq.c +124 -7

175 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 +26 -0
index 67cf5eeabd..0e18a86ab4 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;
@@ -459,6 +464,26 @@ 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 */
+    /*
+     * 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;
+    struct xen_psd_package domain_info; /* _PSD */
+    /* Coordination type of this processor */
+    uint32_t shared_type;
+};
+typedef struct xen_processor_cppc xen_processor_cppc_t;
+
 struct xenpf_set_processor_pminfo {
     /* IN variables */
     uint32_t id;    /* ACPI CPU ID */
@@ -467,6 +492,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 +2 -0
index 8350403e95..f30286d48e 100644
@@ -7,6 +7,8 @@
 
 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_performance;
xen/include/xlat.lst +1 -0
index 3c7b6c6830..d3f87c7cc2 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
#14 lore raw

Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

Quoted 4 lines · 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 Norminal frequency, to let OS use Lowest Frequency/

Nit: Nominal

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
@@ -497,12 +504,19 @@ static void print_PPC(unsigned int platform_limit)
     printk("\t_PPC: %d\n", platform_limit);
 }
 

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

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +8 -1
-static int check_psd_pminfo(const struct xen_processor_performance *perf)
+static int check_psd_pminfo(const struct xen_processor_performance *perf,
+                            const struct xen_processor_cppc *cppc_data)
 {
+    uint32_t shared_type;
+
+    if ( !perf && !cppc_data )
+        return -EINVAL;
+
+    shared_type = perf ? perf->shared_type : cppc_data->shared_type;

Why don't you have the caller pass in shared_type? The two pointers aren't used ...

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

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +3 -3
     /* 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 )
+    if ( shared_type != CPUFREQ_SHARED_TYPE_ALL &&
+         shared_type != CPUFREQ_SHARED_TYPE_ANY &&
+         shared_type != CPUFREQ_SHARED_TYPE_HW )
         return -EINVAL;
 
     return 0;

... for anything else.

Quoted 53 lines
xen/drivers/cpufreq/cpufreq.c +49 -0
@@ -627,6 +641,109 @@ 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,
+                    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 )
+    {
+        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;
+
+    if ( cppc_data->flags & XEN_CPPC_PSD )
+    {
+        ret = check_psd_pminfo(NULL, cppc_data);
+        if ( ret )
+            goto out;
+    }
+
+    if ( cppc_data->flags & XEN_CPPC_CPC )
+    {

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

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+        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.lowest_nonlinear_perf ||

Where's this ordering spelled out in the spec?

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

Quoted 13 lines
xen/drivers/cpufreq/cpufreq.c +13 -0
+             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 perf values
+             * in ACPI _CPC table, warning is enough.
+             */
+            printk(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);

If this warning was to ever surface, it would likely surface for every CPU. That's unnecessarily verbose, I guess. Please consider using printk_once() here.

Also, is "right now" (as the comment says) still going to be true by the end of the series? Didn't I see you use the values in earlier versions?

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

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
+        /* lowest_mhz and nominal_mhz are optional value */
+        if ( (cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz) &&
+             cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )

The 1st of the three checks is redundant with the 3rd one. There's also no point parenthesizing one && against another.

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

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +7 -0
+            printk(XENLOG_WARNING
+                   "Broken CPPC freq values: lowest(%u), nominal(%u)\n",
+                   cppc_data->cpc.lowest_mhz,
+                   cppc_data->cpc.nominal_mhz);
+    }
+
+    if ( cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC) )

If either flag may be clear, ...

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

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+        pm_info->cppc_data = *cppc_data;
+        if ( cpufreq_verbose )
+        {
+            print_PSD(&pm_info->cppc_data.domain_info);
+            print_CPPC(&pm_info->cppc_data);

... why unconditionally loog both?

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

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
+        }
+
+        pm_info->init = XEN_CPPC_INIT;

Plus is it correct to set this flag if either of the incoming flags was clear?

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

Quoted 2 lines
xen/drivers/cpufreq/cpufreq.c +2 -0
+        ret = cpufreq_cpu_init(cpuid);
+#ifndef NDEBUG

Instead of this, ...

Review out: · line 738

Quoted 2 lines
(quoted diff) +2 -0
+        if ( ret )
+            printk(XENLOG_WARNING "No fallback scheme could be replaced now");

... did you perhaps mean to use dprintk()? Also, the wording isn't meaningful at all. Seeing the message, about everyone will need to go and find the text in source code in order to stand a chance of gaining even basic understanding of what's going on.

Quoted 9 lines
xen/include/public/platform.h +5 -0
@@ -459,6 +464,26 @@ 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 */
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization

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

Quoted 10 lines
xen/include/public/platform.h +10 -0
+     */
+    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;
+    struct xen_psd_package domain_info; /* _PSD */

This being a member of the new type, ...

xen/include/xlat.lst line 171

Quoted 7 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

... how can it be ? here when it's ...

xen/include/xlat.lst line 172

Quoted 1 line
xen/include/xlat.lst +0 -0
 !	psd_package			platform.h

... ! here? And with it being ?, you're lacking a place where you invoke the resulting checking macro (which I assume would cause a build failure).

Also when laying out struct xen_processor_cppc, please avoid unnecessary gaps or tail padding - it looks like "shared_type" would better move up. I think it would also be a good idea to make padding fields explicit, and check them to be zero. This way they can be assigned meaning later (if need be) without breaking backwards compatibility.

Jan

#15 lore raw

RE: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

[Public]

HI

Quoted 26 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:57 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]>; [email protected]
Subject: Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

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

Quoted 12 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +12 -0
+    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.lowest_nonlinear_perf ||
Quoted 2 lines

Where's this ordering spelled out in the spec?

Clip a snippet from description on lowest performance[1], we may deduce that

```
Selecting a performance level lower than the lowest nonlinear performance level may actually cause an efficiency penalty,
but should reduce the instantaneous power consumption of the processor
```

lowest is smaller than lowest nonlinear

Quoted 9 lines

xen/drivers/cpufreq/cpufreq.c out:

Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c +9 -0
+             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 perf values
+             * in ACPI _CPC table, warning is enough.
+             */
+            printk(XENLOG_WARNING
+                   "Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u),
Quoted 9 lines

nominal(%u), highest(%u)\n",

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

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+                   cppc_data->cpc.lowest_perf,
+                   cppc_data->cpc.lowest_nonlinear_perf,
+                   cppc_data->cpc.nominal_perf,
+                   cppc_data->cpc.highest_perf);

If this warning was to ever surface, it would likely surface for every CPU. That's unnecessarily verbose, I guess. Please consider using printk_once() here.

Understood

Quoted 3 lines

Also, is "right now" (as the comment says) still going to be true by the end of the series? Didn't I see you use the values in earlier versions?

The reason why I added this comment is that in current implementation, we actually don't use values read from ACPI _CPC table for lowest_perf, lowest_nonlinear_perf, nominal_perf, and highest_perf.
We read CPPC capability MSR to get these four values.
What we actually use is the following optional lowest_mhz and nominal_mhz. We read these two values for perf_to_khz transition.

There are two ways to read CPPC capability info, one is from MSR register, and the other is from _CPC table. Only in very few hardware, MSR is not supported, and we must switch to use ACPI _CPC Such scenario is not covered in this patch serie. I've mentioned it in the cover letter. The difficulty actually is that when we try to use ACPI _CPC to do CPPC performance monitoring, some control registers are probably implemented in the Platform Communications Channel (PCC) interface, which is not supported in Xen.

Quoted 12 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    if ( cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC) )

If either flag may be clear, ...

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

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+        pm_info->cppc_data = *cppc_data;
+        if ( cpufreq_verbose )
+        {
+            print_PSD(&pm_info->cppc_data.domain_info);
+            print_CPPC(&pm_info->cppc_data);
Quoted 8 lines

... why unconditionally loog both?

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

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
+        }
+
+        pm_info->init = XEN_CPPC_INIT;

Plus is it correct to set this flag if either of the incoming flags was clear?

Hmm, I may not understand what you mean here...
I log and set this flag only when both flags are set (cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC)) _PSD entry and _CPC entry are both mandatory
Did you suggest that we shall give warning message when either flag is clear?

Quoted 1 line

Jan

[1] https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html?highlight=cppc#lowest-performance

#16 lore raw

Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

Quoted 21 lines · Zheng
Quoted 18 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:57 PM

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

Quoted 12 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +12 -0
+    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.lowest_nonlinear_perf ||
Quoted 2 lines

Where's this ordering spelled out in the spec?

Quoted 6 lines

Clip a snippet from description on lowest performance[1], we may deduce that

```
Selecting a performance level lower than the lowest nonlinear performance level may actually cause an efficiency penalty,
but should reduce the instantaneous power consumption of the processor
```

lowest is smaller than lowest nonlinear

I can't imply that from the quoted sentence. It describes what happens in that situation, but it doesn't exclude the opposite relationship (in which case the described situation simply can't occur).

Quoted 21 lines
Quoted 9 lines

xen/drivers/cpufreq/cpufreq.c out:

Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c +9 -0
+             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 perf values
+             * in ACPI _CPC table, warning is enough.
+             */
+            printk(XENLOG_WARNING
+                   "Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u),
Quoted 9 lines

nominal(%u), highest(%u)\n",

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

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+                   cppc_data->cpc.lowest_perf,
+                   cppc_data->cpc.lowest_nonlinear_perf,
+                   cppc_data->cpc.nominal_perf,
+                   cppc_data->cpc.highest_perf);

If this warning was to ever surface, it would likely surface for every CPU. That's unnecessarily verbose, I guess. Please consider using printk_once() here.

Understood

Quoted 8 lines
Quoted 3 lines

Also, is "right now" (as the comment says) still going to be true by the end of the series? Didn't I see you use the values in earlier versions?

The reason why I added this comment is that in current implementation, we actually don't use values read from ACPI _CPC table for lowest_perf, lowest_nonlinear_perf, nominal_perf, and highest_perf.
We read CPPC capability MSR to get these four values.

Oh, okay. Could you slightly extend that comment to include this detail?

Quoted 17 lines
Quoted 17 lines
Quoted 1 line

+ if ( cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC) )

If either flag may be clear, ...

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

Quoted 6 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+    {
+        pm_info->cppc_data = *cppc_data;
+        if ( cpufreq_verbose )
+        {
+            print_PSD(&pm_info->cppc_data.domain_info);
+            print_CPPC(&pm_info->cppc_data);

... why unconditionally loog both?

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +3 -0
+        }
+
+        pm_info->init = XEN_CPPC_INIT;
Quoted 6 lines
Quoted 1 line

Plus is it correct to set this flag if either of the incoming flags was clear?

Hmm, I may not understand what you mean here...
I log and set this flag only when both flags are set (cppc_data->flags == (XEN_CPPC_PSD | XEN_CPPC_CPC)) _PSD entry and _CPC entry are both mandatory
Did you suggest that we shall give warning message when either flag is clear?

Oh, sorry - I read & where you have == actually. Hence why I thought only one of the flags may be set. Please disregard those comments of mine.

Jan

#17 lore raw

RE: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

In reply to Jan Beulich

[Public]

Hi,

Quoted 47 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:57 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]>; [email protected]
Subject: Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

Quoted 9 lines · Penny Zheng
xen/include/public/platform.h +5 -0
@@ -459,6 +464,26 @@ 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 */
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization

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

Quoted 10 lines
xen/include/public/platform.h +10 -0
+     */
+    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;
+    struct xen_psd_package domain_info; /* _PSD */

This being a member of the new type, ...

xen/include/xlat.lst line 171

Quoted 7 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

... how can it be ? here when it's ...

xen/include/xlat.lst line 172

Quoted 1 line
xen/include/xlat.lst +0 -0
 !  psd_package                     platform.h
Quoted 9 lines

... ! here? And with it being ?, you're lacking a place where you invoke the resulting checking macro (which I assume would cause a build failure).

Also when laying out struct xen_processor_cppc, please avoid unnecessary gaps or tail padding - it looks like "shared_type" would better move up. I think it would also be a good idea to make padding fields explicit, and check them to be zero. This way they can be assigned meaning later (if need
be) without breaking backwards compatibility.

Understood, I'll re-construct into increasing order and add explicit padding:

```
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 */
    uint32_t shared_type;
    struct xen_psd_package domain_info; /* _PSD */
};
```
Quoted 1 line

Jan

#18 lore raw

RE: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

In reply to Jan Beulich

[Public]

Hi

Quoted 45 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:57 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]>; [email protected]
Subject: Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

Quoted 9 lines · Penny Zheng
xen/include/public/platform.h +5 -0
@@ -459,6 +464,26 @@ 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 */
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization

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

Quoted 10 lines
xen/include/public/platform.h +10 -0
+     */
+    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;
+    struct xen_psd_package domain_info; /* _PSD */

This being a member of the new type, ...

xen/include/xlat.lst line 171

Quoted 7 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

... how can it be ? here when it's ...

Quoted 5 lines

xen/include/xlat.lst line 172

Quoted 1 line
xen/include/xlat.lst +0 -0
 !  psd_package                     platform.h

... ! here? And with it being ?, you're lacking a place where you invoke the resulting checking macro (which I assume would cause a build failure).

Understood, I see it automatically generates CHECK_psd_package. I shall change psd_package with ? too In order to avoid causing build failure, I add "typedef struct xen_psd_package xen_psd_package_t;" I'm not familiar with the compat framework, if it isn't the right way to fix, plz let me know

Quoted 7 lines

Also when laying out struct xen_processor_cppc, please avoid unnecessary gaps or tail padding - it looks like "shared_type" would better move up. I think it would also be a good idea to make padding fields explicit, and check them to be zero. This way they can be assigned meaning later (if need
be) without breaking backwards compatibility.

Jan

#19 lore raw

Re: [PATCH v4 03/15] xen/x86: introduce new sub-hypercall to propagate CPPC data

Quoted 37 lines · Zheng
Quoted 37 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, April 28, 2025 11:57 PM

Quoted 9 lines · Penny Zheng
xen/include/public/platform.h +5 -0
@@ -459,6 +464,26 @@ 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 */
+    /*
+     * Subset _CPC fields useful for CPPC-compatible cpufreq
+     * driver's initialization

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

Quoted 10 lines
xen/include/public/platform.h +10 -0
+     */
+    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;
+    struct xen_psd_package domain_info; /* _PSD */

This being a member of the new type, ...

xen/include/xlat.lst line 171

Quoted 7 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

... how can it be ? here when it's ...

Quoted 4 lines
Quoted 4 lines

xen/include/xlat.lst line 172

Quoted 1 line
xen/include/xlat.lst +0 -0
 !  psd_package                     platform.h

... ! here? And with it being ?, you're lacking a place where you invoke the resulting checking macro (which I assume would cause a build failure).

I guess this wasn't clear enough then: Aiui you cannot "check" these, because the native and compat ones are going to be different. You'll need to use ! here, and then use the respective XLAT_* macro(s). IOW ...

Quoted 3 lines

Understood, I see it automatically generates CHECK_psd_package. I shall change psd_package with ? too In order to avoid causing build failure, I add "typedef struct xen_psd_package xen_psd_package_t;" I'm not familiar with the compat framework, if it isn't the right way to fix, plz let me know

... I expect this isn't the correct way of dealing with it.

Jan

#20 lore raw

PATCH v4 4/15 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

---
 xen/drivers/cpufreq/cpufreq.c | 53 +++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 8 deletions(-)
xen/drivers/cpufreq/cpufreq.c +45 -8
index e01acc0c2d..79c6444116 100644
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };
+
+        printk(XENLOG_WARNING
+               "Duplicate cpufreq driver option: %s",
+               cpufreq_opts_str[option - 1]);
+        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 +157,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
Reviewed-by on v4 4/15
#21 lore raw

Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +10 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;
+    }
+

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 93

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+    return false;
+}
+
+static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
+{
+    int ret = 0;
+
+    if ( cpufreq_opts_contain(option) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };

(line wrapped suitably, of course) Or maybe even better

        const char __initconst cpufreq_opts_str[][12] = { "CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

However, the CPUFREQ_ prefixes want dropping, as they're an internal of the implementation, and ...

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 97

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+
+        printk(XENLOG_WARNING
+               "Duplicate cpufreq driver option: %s",
+               cpufreq_opts_str[option - 1]);

... aren't necessarily meaningful when presented this way to the user; the user specified "xen" or "hwp", after all.

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 109

Quoted 12 lines
xen/drivers/cpufreq/cpufreq.c +12 -0
+        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:

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

With all of the adjustments:

Jan

#22 lore raw

Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 30 lines · Jan Beulich
Quoted 16 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +10 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;
+    }
+

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 93

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -0
+    return false;
+}
+
+static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
+{
+    int ret = 0;
+
+    if ( cpufreq_opts_contain(option) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };
Quoted 5 lines

(line wrapped suitably, of course) Or maybe even better

        const char __initconst cpufreq_opts_str[][12] = { "CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

Actually, it didn't even occur to me that there might be a "static" missing here, too. Plus I'm missing any arrangement for the array slots to remain in sync with the corresponding enumerators. With that ...

Quoted 2 lines

With all of the adjustments:

I'm sorry, but I need to take this back. There are just too many issues.

Jan

#23 lore raw

RE: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

[Public]

Hi,

Quoted 41 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 7:47 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 33 lines · Jan Beulich
Quoted 18 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +11 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 95

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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen",
+ "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

Quoted 8 lines
Quoted 6 lines

(line wrapped suitably, of course) Or maybe even better

        const char __initconst cpufreq_opts_str[][12] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

Actually, it didn't even occur to me that there might be a "static" missing here, too.

Sorry, I may need more explanation, what is the "static" missing you are referring?

Quoted 3 lines

Plus I'm missing any arrangement for the array slots to remain in sync with the corresponding enumerators. With that ...

Thanks for the detailed instructions, learned and I'll change it to

        const char __initconst cpufreq_opts_str[][4] = { "xen", "hwp" };
And for in sync with the corresponding enumerators, maybe we shall add comment here,
        /* The order of cpufreq string literal must be in sync with  the order in "enum cpufreq_xen_opt" */
Quoted 6 lines
Quoted 2 lines

With all of the adjustments:

I'm sorry, but I need to take this back. There are just too many issues.

Jan

#24 lore raw

Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 47 lines · Zheng

[Public]

Hi,

Quoted 43 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 7:47 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 35 lines · Jan Beulich
Quoted 18 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +11 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 95

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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen",
+ "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

(line wrapped suitably, of course) Or maybe even better

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
        const char __initconst cpufreq_opts_str[][12] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

Actually, it didn't even occur to me that there might be a "static" missing here, too.

Sorry, I may need more explanation, what is the "static" missing you are referring?

In your code cpufreq_opts_str[] is an automatic variable, which the compiler needs to emit code for in order to instantiate it on the stack. This can be avoided if you make the array a static variable, as then all construction occurs at build time.

Quoted 8 lines
Quoted 3 lines

Plus I'm missing any arrangement for the array slots to remain in sync with the corresponding enumerators. With that ...

Thanks for the detailed instructions, learned and I'll change it to

        const char __initconst cpufreq_opts_str[][4] = { "xen", "hwp" };
And for in sync with the corresponding enumerators, maybe we shall add comment here,
        /* The order of cpufreq string literal must be in sync with  the order in "enum cpufreq_xen_opt" */

Instead of a comment I has rather hoping for some use of dedicated array slot initializers.

Jan

#25 lore raw

RE: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

[Public]

Hi,

Quoted 76 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 12, 2025 11:58 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 53 lines · Zheng

[Public]

Hi,

Quoted 49 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 7:47 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 31 lines · Jan Beulich
Quoted 18 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +11 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 95

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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen",
+ "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = {
Quoted 8 lines

"CPUFREQ_xen", "CPUFREQ_hwp" };

(line wrapped suitably, of course) Or maybe even better

        const char __initconst cpufreq_opts_str[][12] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

Actually, it didn't even occur to me that there might be a "static" missing here,

too.

Quoted 2 lines

Sorry, I may need more explanation, what is the "static" missing you are referring?

In your code cpufreq_opts_str[] is an automatic variable, which the compiler needs to emit code for in order to instantiate it on the stack. This can be avoided if you make the array a static variable, as then all construction occurs at build time.

Quoted 7 lines
Quoted 3 lines

Plus I'm missing any arrangement for the array slots to remain in sync with the corresponding enumerators. With that ...

Thanks for the detailed instructions, learned and I'll change it to

        const char __initconst cpufreq_opts_str[][4] = { "xen", "hwp"
}; And for in sync with the corresponding enumerators, maybe we shall add
Quoted 6 lines

comment here,

Quoted 2 lines
        /* The order of cpufreq string literal must be in sync with

the order in "enum cpufreq_xen_opt" */

Instead of a comment I has rather hoping for some use of dedicated array slot initializers.

Understood. I'll use "CPUFREQ_xxx" as array slot index.

        static const char __initconst cpufreq_opts_str[][5] = {
                [CPUFREQ_none] = "none",
                [CPUFREQ_xen] = "xen",
                [CPUFREQ_hwp] = "hwp",
        };
Quoted 2 lines

Jan

#26 lore raw

Re: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 71 lines · Zheng
Quoted 64 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 12, 2025 11:58 PM

Quoted 37 lines · Zheng
Quoted 37 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 7:47 PM

Quoted 33 lines · Jan Beulich
Quoted 18 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +11 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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;

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 95

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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen",
+ "CPUFREQ_hwp" };
        const char *const __initconstrel cpufreq_opts_str[] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

(line wrapped suitably, of course) Or maybe even better

        const char __initconst cpufreq_opts_str[][12] = {

"CPUFREQ_xen", "CPUFREQ_hwp" };

for the string literals to also end up in .init.rodata.

Actually, it didn't even occur to me that there might be a "static" missing here,

too.

Quoted 2 lines

Sorry, I may need more explanation, what is the "static" missing you are referring?

In your code cpufreq_opts_str[] is an automatic variable, which the compiler needs to emit code for in order to instantiate it on the stack. This can be avoided if you make the array a static variable, as then all construction occurs at build time.

Quoted 7 lines
Quoted 3 lines

Plus I'm missing any arrangement for the array slots to remain in sync with the corresponding enumerators. With that ...

Thanks for the detailed instructions, learned and I'll change it to

        const char __initconst cpufreq_opts_str[][4] = { "xen", "hwp"
}; And for in sync with the corresponding enumerators, maybe we shall add
Quoted 6 lines

comment here,

Quoted 2 lines
        /* The order of cpufreq string literal must be in sync with

the order in "enum cpufreq_xen_opt" */

Instead of a comment I has rather hoping for some use of dedicated array slot initializers.

Quoted 6 lines

Understood. I'll use "CPUFREQ_xxx" as array slot index.

        static const char __initconst cpufreq_opts_str[][5] = {
                [CPUFREQ_none] = "none",
                [CPUFREQ_xen] = "xen",
                [CPUFREQ_hwp] = "hwp",
        };

Provided the "none" entry doesn't cause any anomalies, this way.

Jan

#27 lore raw

RE: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

In reply to Penny Zheng

[Public]

Quoted 59 lines

-----Original Message-----
From: Penny, Zheng <[email protected]>
Sent: Monday, April 14, 2025 3:41 PM
To: [email protected]
Cc: Huang, Ray <[email protected]>; Penny, Zheng <[email protected]>; Jan Beulich <[email protected]>
Subject: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

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

---
 xen/drivers/cpufreq/cpufreq.c | 53 +++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 8 deletions(-)
xen/drivers/cpufreq/cpufreq.c index renamed from xen/drivers/cpufreq/cpufreq.c +0 -0

e01acc0c2d..79c6444116 100644

xen/drivers/cpufreq/cpufreq.c +26 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp"
+ };
+
+        printk(XENLOG_WARNING
+               "Duplicate cpufreq driver option: %s",
+               cpufreq_opts_str[option - 1]);
+        return 0;
+    }
+

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 109

Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10 -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;

I'm thinking since handle_cpufreq_cmdline() is totally internal and has very few caller, maybe ASSERT_UNREACHABLE() is more suitable. Then the function itself could become void return.

Quoted 33 lines
xen/drivers/cpufreq/cpufreq.c +8 -9
+        break;
+    }
+
+    return ret;
+}
+
 static int __init cf_check setup_cpufreq_option(const char *str)  {
     const char *arg = strpbrk(str, ",:;"); @@ -114,20 +157,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);
         }
--

2.34.1

#28 lore raw

RE: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

[Public]

Quoted 78 lines

-----Original Message-----
From: Penny, Zheng
Sent: Thursday, June 19, 2025 3:52 PM
To: [email protected]; Jan Beulich <[email protected]>; Andryuk, Jason <[email protected]>
Cc: Huang, Ray <[email protected]>; Jan Beulich <[email protected]>
Subject: RE: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

Quoted 68 lines

-----Original Message-----
From: Penny, Zheng <[email protected]>
Sent: Monday, April 14, 2025 3:41 PM
To: [email protected]
Cc: Huang, Ray <[email protected]>; Penny, Zheng <[email protected]>; Jan Beulich <[email protected]>
Subject: [PATCH v4 04/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"

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

---
 xen/drivers/cpufreq/cpufreq.c | 53
+++++++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 8 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/cpufreq/cpufreq.c index
e01acc0c2d..79c6444116 100644

xen/drivers/cpufreq/cpufreq.c +32 -0
@@ -71,6 +71,49 @@ unsigned int __initdata cpufreq_xen_cnt = 1;
 
 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) )
+    {
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp"
+ };
+
+        printk(XENLOG_WARNING
+               "Duplicate cpufreq driver option: %s",
+               cpufreq_opts_str[option - 1]);
+        return 0;
+    }
+
+    cpufreq_controller = FREQCTL_xen;
+    cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
+    switch ( option )
+    {
+    case CPUFREQ_hwp:
+    case CPUFREQ_xen:
Quoted 8 lines

xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 110

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4 -0
+        xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
+        break;
+    default:
+        ret = -EINVAL;

I'm thinking since handle_cpufreq_cmdline() is totally internal and has very few caller, maybe ASSERT_UNREACHABLE() is more suitable. Then the function itself could become void return.

Sorry, forgot the release build. I'll add assert and stays with non-void return

Quoted 34 lines
Quoted 34 lines
xen/drivers/cpufreq/cpufreq.c +6 -0
+        break;
+    }
+
+    return ret;
+}
+
 static int __init cf_check setup_cpufreq_option(const char *str)  {
     const char *arg = strpbrk(str, ",:;"); @@ -114,20 +157,14 @@

static int __init cf_check setup_cpufreq_option(const char *str)

         if ( choice > 0 || !cmdline_strcmp(str, "xen") )
         {
xen/drivers/cpufreq/cpufreq.c +2 -9
-            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);
         }
--

2.34.1

#29 lore raw

PATCH v4 5/15 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 missing until commit "xen/x86: introduce a new amd cppc driver for cpufreq scaling"

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

---
 docs/misc/xen-command-line.pandoc         |  7 +-
 xen/arch/x86/acpi/cpufreq/Makefile        |  1 +
 xen/arch/x86/acpi/cpufreq/acpi.c          | 14 +++-
 xen/arch/x86/acpi/cpufreq/amd-cppc.c      | 81 +++++++++++++++++++++++
 xen/arch/x86/acpi/cpufreq/cpufreq.c       | 34 +++++++++-
 xen/arch/x86/platform_hypercall.c         | 11 +++
 xen/drivers/cpufreq/cpufreq.c             | 15 ++++-
 xen/include/acpi/cpufreq/cpufreq.h        |  6 +-
 xen/include/acpi/cpufreq/processor_perf.h |  3 +
 xen/include/public/sysctl.h               |  1 +
 10 files changed, 166 insertions(+), 7 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/acpi.c +13 -1
index 0c25376406..e0cea9425f 100644
@@ -13,6 +13,7 @@
 
 #include <xen/errno.h>
 #include <xen/delay.h>
+#include <xen/domain.h>
 #include <xen/param.h>
 #include <xen/types.h>
 
@@ -514,5 +515,16 @@ acpi_cpufreq_driver = {
 
 int __init acpi_cpufreq_register(void)
 {
-    return cpufreq_register_driver(&acpi_cpufreq_driver);
+    int ret;
+
+    ret = cpufreq_register_driver(&acpi_cpufreq_driver);
+    if ( ret )
+        return ret;
+    /*
+     * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
+     * and XEN_PROCESSOR_PM_PX shall become exclusive flags
+     */
+    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+
+    return ret;
 }
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +81 -0

81 lines not on this page · raw message

xen/arch/x86/acpi/cpufreq/cpufreq.c +33 -1
index 61e98b67bd..eac1c125a3 100644
@@ -148,6 +148,10 @@ static int __init cf_check cpufreq_driver_init(void)
                 case CPUFREQ_none:
                     ret = 0;
                     break;
+                default:
+                    printk(XENLOG_WARNING
+                           "Unsupported cpufreq driver for vendor Intel\n");
+                    break;
                 }
 
                 if ( ret != -ENODEV )
@@ -157,7 +161,35 @@ 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;
+            if ( !IS_ENABLED(CONFIG_AMD) )
+            {
+                ret = -ENODEV;
+                break;
+            }
+            ret = -ENOENT;
+
+            for ( unsigned int 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");
+                    break;
+                }
+
+                if ( ret != -ENODEV )
+                    break;
+            }
             break;
         }
     }
xen/arch/x86/platform_hypercall.c +11 -0
index 49717e9ca9..82663011ad 100644
@@ -542,6 +542,9 @@ ret_t do_platform_op(
                 ret = -ENOSYS;
                 break;
             }
+            /* Xen doesn't support mixed mode */
+            ASSERT((xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) == 0);
+
             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 = -EOPNOTSUPP;
+                break;
+            }
+            /* Xen doesn't support mixed mode */
+            ASSERT((xen_processor_pmbits & XEN_PROCESSOR_PM_PX) == 0);
+
             ret = set_cppc_pminfo(op->u.set_pminfo.id,
                                   &op->u.set_pminfo.u.cppc_data);
             break;
xen/drivers/cpufreq/cpufreq.c +13 -2
index 79c6444116..818668c99c 100644
@@ -65,7 +65,7 @@ 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;
 
@@ -90,7 +90,8 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option)
 
     if ( cpufreq_opts_contain(option) )
     {
-        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp" };
+        const char *cpufreq_opts_str[] = { "CPUFREQ_xen", "CPUFREQ_hwp",
+                                           "CPUFREQ_amd_cppc" };
 
         printk(XENLOG_WARNING
                "Duplicate cpufreq driver option: %s",
@@ -102,6 +103,9 @@ 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;
@@ -168,6 +172,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..1a6591d612 100644
@@ -5,6 +5,9 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
+/* ability bits */
+#define XEN_PROCESSOR_PM_CPPC   8
+
 #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
#30 lore raw

Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/acpi.c +3 -1
@@ -514,5 +515,16 @@ acpi_cpufreq_driver = {
 
 int __init acpi_cpufreq_register(void)
 {
-    return cpufreq_register_driver(&acpi_cpufreq_driver);
+    int ret;
+
+    ret = cpufreq_register_driver(&acpi_cpufreq_driver);

xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 530

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/acpi.c +9 -0
+    if ( ret )
+        return ret;
+    /*
+     * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
+     * and XEN_PROCESSOR_PM_PX shall become exclusive flags
+     */
+    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+
+    return ret;
 }

Why is no similar adjustment needed in powernow_register_driver()? In principle I would have expected that it's not each individual driver which needs to care about this aspect, but that the framework is taking care of this.

Quoted 29 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +26 -0
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * amd-cppc.c - AMD Processor CPPC Frequency Driver
+ *
+ * Copyright (C) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
+ *
+ * Author: Penny Zheng <[email protected]>
+ *
+ * AMD CPPC cpufreq driver introduces a new CPU performance scaling design
+ * for AMD processors using the ACPI Collaborative Performance and Power
+ * Control (CPPC) feature which provides finer grained frequency control range.
+ */
+
+#include <xen/domain.h>
+#include <xen/init.h>
+#include <xen/param.h>
+#include <acpi/cpufreq/cpufreq.h>
+
+static bool __init amd_cppc_handle_option(const char *s, const char *end)
+{
+    int ret;
+
+    ret = parse_boolean("verbose", s, end);
+    if ( ret >= 0 )
+    {
+        cpufreq_verbose = ret;

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +10 -0
+        return true;
+    }
+
+    return false;
+}
+
+int __init amd_cppc_cmdline_parse(const char *s, const char *e)
+{
+    do
+    {

Nit (style): Brace placement is special here, just like it is ...

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

Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +13 -0
+        const char *end = strpbrk(s, ",;");
+
+        if ( !amd_cppc_handle_option(s, end) )
+        {
+            printk(XENLOG_WARNING
+                   "cpufreq/amd-cppc: option '%.*s' not recognized\n",
+                   (int)((end ?: e) - s), s);
+
+            return -EINVAL;
+        }
+
+        s = end ? end + 1 : NULL;
+    } while ( s && s < e );

... here.

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

Quoted 8 lines
xen/arch/x86/platform_hypercall.c +2 -0
@@ -542,6 +542,9 @@ ret_t do_platform_op(
                 ret = -ENOSYS;
                 break;
             }
+            /* Xen doesn't support mixed mode */
+            ASSERT((xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) == 0);

Please prefer ! over "== 0" in such purely boolean contexts.

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 = -EOPNOTSUPP;
+                break;
+            }

While at least you no longer use -ENOSYS here, I question this behavior, including that for the pre-existing cases: How is the caller supposed to know whether to invoke this sub-op? Ignoring errors is generally not a good idea, so it would be better if the caller could blindly issue this request, getting back success unless there really was an issue with the data provided.

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

Quoted 10 lines
xen/arch/x86/platform_hypercall.c +3 -0
@@ -102,6 +103,9 @@ 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;

Here and (about) everywhere else: Blank line please between non-fall-through case blocks. I guess I'm not going to repeat this any further. There are very tiny switch() statements where it is okay to violate this principle, but as a rule of thumb - if in doubt, put a blank line there.

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>
 
+/* ability bits */
+#define XEN_PROCESSOR_PM_CPPC   8

This needs correlating (at least via commentary, better by build-time checking) with the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here would by e.g. 0x100.

Jan

#31 lore raw

RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

[Public]

Hi,

Quoted 26 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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]>; [email protected]
Subject: Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 13 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/acpi.c +9 -1
@@ -514,5 +515,16 @@ acpi_cpufreq_driver = {
 
 int __init acpi_cpufreq_register(void)  {
-    return cpufreq_register_driver(&acpi_cpufreq_driver);
+    int ret;
+
+    ret = cpufreq_register_driver(&acpi_cpufreq_driver);
+    if ( ret )
+        return ret;
+    /*
+     * After cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC
+     * and XEN_PROCESSOR_PM_PX shall become exclusive flags
+     */
Quoted 9 lines

xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 530

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/acpi.c +3 -0
+    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+
+    return ret;
 }

Why is no similar adjustment needed in powernow_register_driver()? In principle I would have expected that it's not each individual driver which needs to care about this aspect, but that the framework is taking care of this.

Then maybe we shall add this here, to extract the codes from each specific driver:

```
diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index eac1c125a3..9276241291 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -190,6 +190,25 @@ static int __init cf_check cpufreq_driver_init(void)
                 if ( ret != -ENODEV )
                     break;
             }
+
+            if ( !ret && i < cpufreq_xen_cnt )
+            {
+                switch ( cpufreq_xen_opts[i] )
+                {
+                case CPUFREQ_amd_cppc:
+                    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_XEN;
+                    break;
+
+                case CPUFREQ_xen:
+                    xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC;
+                    break;
+
+                case CPUFREQ_none:
+                default:
+                    break;
+                }
+            }
+
             break;
         }
     }
```
Quoted 16 lines

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 = -EOPNOTSUPP;
+                break;
+            }

While at least you no longer use -ENOSYS here, I question this behavior, including that for the pre-existing cases: How is the caller supposed to know whether to invoke this sub-op? Ignoring errors is generally not a good idea, so it would be better if the caller could blindly issue this request, getting back success unless there really was an issue with the data provided.

Understood.
I will change it to ret = 0. Do you think we shall add warning info here?
Dom0 will send the CPPC data whenever it could. XEN_PROCESSOR_PM_CPPC
is not set could largely be users choosing not to. In such case, silently getting back success shall be enough.

Quoted 1 line

Jan

#32 lore raw

Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 22 lines · Zheng
Quoted 8 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 PM

Quoted 3 lines · Penny Zheng
(quoted diff) +0 -0
@@ -573,6 +576,14 @@ ret_t do_platform_op(
         }
 
Quoted 13 lines

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

Quoted 6 lines
xen/arch/x86/platform_hypercall.c +5 -0
         case XEN_PM_CPPC:
+            if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
+            {
+                ret = -EOPNOTSUPP;
+                break;
+            }

While at least you no longer use -ENOSYS here, I question this behavior, including that for the pre-existing cases: How is the caller supposed to know whether to invoke this sub-op? Ignoring errors is generally not a good idea, so it would be better if the caller could blindly issue this request, getting back success unless there really was an issue with the data provided.

Quoted 2 lines

Understood.
I will change it to ret = 0. Do you think we shall add warning info here?

No, for precisely ...

Quoted 1 line

Dom0 will send the CPPC data whenever it could.

... this reason.

Jan

Quoted 6 lines

XEN_PROCESSOR_PM_CPPC
is not set could largely be users choosing not to. In such case, silently getting back success shall be enough.

Quoted 1 line

Jan

#33 lore raw

RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

In reply to Jan Beulich

[Public]

Quoted 19 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 6 lines · Penny Zheng
xen/include/acpi/cpufreq/processor_perf.h +0 -0
@@ -5,6 +5,9 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
Quoted 10 lines

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

Quoted 2 lines
xen/include/acpi/cpufreq/processor_perf.h +2 -0
+/* ability bits */
+#define XEN_PROCESSOR_PM_CPPC   8

This needs correlating (at least via commentary, better by build-time checking) with the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here would by e.g. 0x100.

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in public header:

         #define XEN_PROCESSOR_PM_PUBLIC_END    XEN_PROCESSOR_PM_TX
and will do the following build-time checking:
        BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <= XEN_PROCESSOR_PM_PUBLIC_END);
Quoted 1 line

Jan

#34 lore raw

Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 32 lines · Zheng

[Public]

Quoted 19 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 6 lines · Penny Zheng
xen/include/acpi/cpufreq/processor_perf.h +0 -0
@@ -5,6 +5,9 @@
 #include <public/sysctl.h>
 #include <xen/acpi.h>
 
Quoted 10 lines

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

Quoted 2 lines
xen/include/acpi/cpufreq/processor_perf.h +2 -0
+/* ability bits */
+#define XEN_PROCESSOR_PM_CPPC   8

This needs correlating (at least via commentary, better by build-time checking) with the other XEN_PROCESSOR_PM_* values. Otherwise someone adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here would by e.g. 0x100.

Quoted 4 lines

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in public header:

         #define XEN_PROCESSOR_PM_PUBLIC_END    XEN_PROCESSOR_PM_TX
and will do the following build-time checking:
        BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <= XEN_PROCESSOR_PM_PUBLIC_END);

I don't really see why anything would need to be added to the public header (and we really should strive to avoid unnecessary additions).

Jan

#35 lore raw

RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

[Public]

Quoted 50 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 19, 2025 9:19 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 27 lines · Zheng

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

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

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

This needs correlating (at least via commentary, better by build-time checking) with the other XEN_PROCESSOR_PM_* values. Otherwise

someone

Quoted 4 lines
Quoted 4 lines

adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here

would by e.g. 0x100.

Quoted 3 lines
Quoted 1 line

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in

public header:

Quoted 8 lines
Quoted 1 line
         #define XEN_PROCESSOR_PM_PUBLIC_END

XEN_PROCESSOR_PM_TX

Quoted 3 lines

and will do the following build-time checking:
BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
XEN_PROCESSOR_PM_PUBLIC_END);

I don't really see why anything would need to be added to the public header (and we really should strive to avoid unnecessary additions).

If I put such definition
"#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
in internal header, I'm afraid it won't be updated if new ones added in the public in the future. Or any other suggestions to provide build-time checking?

Quoted 2 lines

Jan

#36 lore raw

Re: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 58 lines · Zheng

[Public]

Quoted 56 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 19, 2025 9:19 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 27 lines · Zheng

[Public]

Quoted 25 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

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

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

This needs correlating (at least via commentary, better by build-time checking) with the other XEN_PROCESSOR_PM_* values. Otherwise

someone

Quoted 4 lines
Quoted 4 lines

adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here

would by e.g. 0x100.

Quoted 3 lines
Quoted 1 line

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in

public header:

Quoted 1 line
         #define XEN_PROCESSOR_PM_PUBLIC_END

XEN_PROCESSOR_PM_TX

Quoted 3 lines

and will do the following build-time checking:
BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
XEN_PROCESSOR_PM_PUBLIC_END);

Quoted 7 lines
Quoted 2 lines

I don't really see why anything would need to be added to the public header (and we really should strive to avoid unnecessary additions).

If I put such definition
"#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
in internal header, I'm afraid it won't be updated if new ones added in the public in the future. Or any other suggestions to provide build-time checking?

Imo it's sufficient to check that the new #define doesn't overlap with SIF_PM_MASK.

Jan

#37 lore raw

RE: [PATCH v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

[Public]

Quoted 78 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 20, 2025 5:16 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 65 lines · Zheng

[Public]

Quoted 62 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, May 19, 2025 9:19 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

Quoted 29 lines · Zheng

[Public]

Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 8:52 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 v4 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline

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

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

This needs correlating (at least via commentary, better by build-time
checking) with the other XEN_PROCESSOR_PM_* values. Otherwise

someone

Quoted 5 lines
Quoted 5 lines

adding a new #define in the public header may not (easily) notice a possible conflict. With that in mind I also question whether 8 is actually a good choice: That's the obvious next value to use in the public interface. SIF_PM_MASK is 8 bits wide, so a sensible value to use here

would by e.g. 0x100.

Quoted 3 lines
Quoted 1 line

I've added a public flag anchor "XEN_PROCESSOR_PM_PUBLIC_END" in

public header:

Quoted 1 line
         #define XEN_PROCESSOR_PM_PUBLIC_END

XEN_PROCESSOR_PM_TX

Quoted 3 lines

and will do the following build-time checking:
BUILD_BUG_ON(XEN_PROCESSOR_PM_CPPC <=
XEN_PROCESSOR_PM_PUBLIC_END);

I don't really see why anything would need to be added to the public header (and we really should strive to avoid unnecessary additions).

Quoted 8 lines
Quoted 3 lines

If I put such definition
"#define XEN_PROCESSOR_PM_PUBLIC_END XEN_PROCESSOR_PM_TX"
in internal header, I'm afraid it won't be updated if new ones added in the public in

the future.

Quoted 1 line

Or any other suggestions to provide build-time checking?

Imo it's sufficient to check that the new #define doesn't overlap with SIF_PM_MASK.

Understood!

Quoted 2 lines

Jan

#38 lore raw

PATCH v4 6/15 xen/cpufreq: disable px statistic info in amd-cppc mode

In reply to Penny Zheng

We need to bypass construction of px statistic info in cpufreq_statistic_init() for amd-cppc mode, as P-states is not necessary there.

---
v3 -> v4:
- remove unnecessary stub for cpufreq_statistic_exit()

---
 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
Acked-by on v4 6/15
#39 lore raw

Re: [PATCH v4 06/15] xen/cpufreq: disable px statistic info in amd-cppc mode

Quoted 2 lines · Penny Zheng

We need to bypass construction of px statistic info in cpufreq_statistic_init() for amd-cppc mode, as P-states is not necessary there.

Is it really "need"? What goes wrong if we went through this initialization? For now it feels more like an optimization to me, i.e. "want". Also ...

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

Quoted 12 lines
xen/drivers/cpufreq/utility.c +3 -0
@@ -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);

... you're specifically not bypassing the spin_lock_init(), for a good reason. With respective clarification in the description:

Jan

#40 lore raw

PATCH v4 7/15 xen/cpufreq: fix 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 cpu min/nominal/max core 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()

---
 xen/arch/x86/cpu/amd.c | 43 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)
xen/arch/x86/cpu/amd.c +36 -7
index ce4e1df710..f93dda927e 100644
@@ -56,6 +56,9 @@ bool __initdata amd_virt_spec_ctrl;
 
 static bool __read_mostly fam17_c6_disabled;
 
+static uint64_t attr_const amd_parse_freq(unsigned char c, uint64_t value);
+#define INVAL_FREQ_MHZ  ~(uint64_t)0
+
 static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo,
 				 unsigned int *hi)
 {
@@ -570,12 +573,35 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           : c->cpu_core_id);
 }
 
+static uint64_t amd_parse_freq(unsigned char c, uint64_t value)
+{
+	uint64_t freq = INVAL_FREQ_MHZ;
+
+	switch (c) {
+	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 familly %c on cpufreq parsing", c);
+		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;
@@ -656,19 +682,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));
+		       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));
+		       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: %lu 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
#41 lore raw

Re: [PATCH v4 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs

Quoted 4 lines · 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:

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

We introduce a helper amd_parse_freq() to parse cpu min/nominal/max core 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.

As to the title: I don't think "fix" is appropriate here. Or else I'd expect a Fixes: tag to be there, which I think would be hard for you to fish out (as the earlier changes here weren't broken; information on Fam1A simply wasn't available at the time).

xen/arch/x86/cpu/amd.c bool __initdata amd_virt_spec_ctrl; · line 59

Quoted 7 lines
xen/arch/x86/cpu/amd.c +1 -0
@@ -56,6 +56,9 @@ bool __initdata amd_virt_spec_ctrl;
 
 static bool __read_mostly fam17_c6_disabled;
 
+static uint64_t attr_const amd_parse_freq(unsigned char c, uint64_t value);

Why is this declaration needed?

xen/arch/x86/cpu/amd.c bool __initdata amd_virt_spec_ctrl; · line 60

Quoted 1 line
xen/arch/x86/cpu/amd.c +1 -0
+#define INVAL_FREQ_MHZ  ~(uint64_t)0

This may want to move down, ahead of the function. And the expansion wants to be wrapped in parentheses.

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

Quoted 5 lines
xen/arch/x86/cpu/amd.c +1 -0
@@ -570,12 +573,35 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           : c->cpu_core_id);
 }
 
+static uint64_t amd_parse_freq(unsigned char c, uint64_t value)

Considering how it's used, does "value" need to be any wider than unsigned int? What about the return type?

I also think the first argument would better be unsigned int, and would better be named e.g. "family".

Quoted 4 lines
xen/arch/x86/cpu/amd.c +4 -0
+{
+	uint64_t freq = INVAL_FREQ_MHZ;
+
+	switch (c) {

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

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+	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:

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

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

Quoted 2 lines
xen/arch/x86/cpu/amd.c +2 -0
+		printk(XENLOG_ERR
+		       "Unsupported cpu familly %c on cpufreq parsing", c);

Nit: family

Jan

#42 lore raw

RE: [PATCH v4 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs

[Public]

Hi,

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, April 17, 2025 11:23 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 v4 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs

Quoted 12 lines · 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 cpu min/nominal/max core 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.

Quoted 6 lines
Quoted 1 line

As to the title: I don't think "fix" is appropriate here. Or else I'd expect a Fixes: tag to be there, which I think would be hard for you to fish out (as the earlier changes here weren't broken; information on Fam1A simply wasn't available at the time).

I will change it to "Expand core frequency calculation for AMD Family 1Ah CPUs", or any better suggestion?

Quoted 11 lines

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

Quoted 7 lines
xen/arch/x86/cpu/amd.c +1 -0
@@ -570,12 +573,35 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           :
 c->cpu_core_id);  }
 
+static uint64_t amd_parse_freq(unsigned char c, uint64_t value)

Considering how it's used, does "value" need to be any wider than unsigned int? What about the return type?

Value is the value of 64bit PstateDef MSR, although we are only using the lower 32bit to calculate frequency Maybe its better to leave it as uint64_t ?
I'll change the return type to unsigned int, and do the following check anyhow

        #define INVAL_FREQ_MHZ  (~(unsigned int)0)
        if ( freq >= UINT_MAX )
                return INVAL_FREQ_MHZ;
        else
                return (unsigned int) freq;
Quoted 3 lines

I also think the first argument would better be unsigned int, and would better be named e.g. "family".

Understood

Quoted 1 line

Jan

#43 lore raw

Re: [PATCH v4 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs

Quoted 11 lines · Zheng
Quoted 11 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, April 17, 2025 11:23 PM

Quoted 6 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +0 -0
@@ -570,12 +573,35 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
                                                           :
 c->cpu_core_id);  }
 
Quoted 7 lines
Quoted 4 lines

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

Quoted 1 line
xen/arch/x86/cpu/amd.c +1 -0
+static uint64_t amd_parse_freq(unsigned char c, uint64_t value)

Considering how it's used, does "value" need to be any wider than unsigned int? What about the return type?

Value is the value of 64bit PstateDef MSR, although we are only using the lower 32bit to calculate frequency Maybe its better to leave it as uint64_t ?

I won't insist, but changing to unsigned int will, I think, produce better code (hence why I suggested the change).

Quoted 6 lines

I'll change the return type to unsigned int, and do the following check anyhow

        #define INVAL_FREQ_MHZ  (~(unsigned int)0)
        if ( freq >= UINT_MAX )
                return INVAL_FREQ_MHZ;
        else
                return (unsigned int) freq;

But please avoid such unnecessary "else" (which I think I did ask for before).

Jan

#44 lore raw

PATCH v4 8/15 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()

---
 xen/arch/x86/cpu/amd.c         | 60 +++++++++++++++++++++++-----------
 xen/arch/x86/include/asm/amd.h |  4 +++
 2 files changed, 45 insertions(+), 19 deletions(-)
xen/arch/x86/cpu/amd.c +41 -19
index f93dda927e..e875014de9 100644
@@ -57,7 +57,6 @@ bool __initdata amd_virt_spec_ctrl;
 static bool __read_mostly fam17_c6_disabled;
 
 static uint64_t attr_const amd_parse_freq(unsigned char c, uint64_t value);
-#define INVAL_FREQ_MHZ  ~(uint64_t)0
 
 static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo,
 				 unsigned int *hi)
@@ -596,14 +595,13 @@ static uint64_t amd_parse_freq(unsigned char c, uint64_t value)
 	return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+void amd_process_freq(const struct cpuinfo_x86 *c,
+		      uint64_t *low_mhz, uint64_t *nom_mhz, uint64_t *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) {
@@ -684,20 +682,21 @@ 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: %lu (%lu ... %lu) 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(),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else
-		printk("CPU%u: %lu 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)
@@ -708,6 +707,29 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
 	ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)
+{
+	uint64_t low_mhz, nom_mhz, hi_mhz;
+
+	if (c != &boot_cpu_data &&
+	    (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
+		return;
+
+	low_mhz = nom_mhz = hi_mhz = INVAL_FREQ_MHZ;
+	amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+	if (low_mhz != INVAL_FREQ_MHZ && nom_mhz != INVAL_FREQ_MHZ &&
+	    hi_mhz != INVAL_FREQ_MHZ)
+		printk("CPU%u: %lu (%lu ... %lu) MHz\n",
+		       smp_processor_id(),
+		       low_mhz, nom_mhz, hi_mhz);
+	else if (low_mhz != INVAL_FREQ_MHZ && hi_mhz != INVAL_FREQ_MHZ)
+		printk("CPU%u: %lu ... %lu MHz\n",
+		       smp_processor_id(), low_mhz, hi_mhz);
+	else if (low_mhz != INVAL_FREQ_MHZ)
+		printk("CPU%u: %lu MHz\n", smp_processor_id(), low_mhz);
+}
+
 void amd_init_lfence(struct cpuinfo_x86 *c)
 {
 	uint64_t value;
xen/arch/x86/include/asm/amd.h +4 -0
index 9c9599a622..9dd3592bbb 100644
@@ -174,4 +174,8 @@ bool amd_setup_legacy_ssbd(void);
 void amd_set_legacy_ssbd(bool enable);
 void amd_set_cpuid_user_dis(bool enable);
 
+#define INVAL_FREQ_MHZ  ~(uint64_t)0
+void amd_process_freq(const struct cpuinfo_x86 *c, uint64_t *low_mhz,
+		      uint64_t *nom_mhz, uint64_t *hi_mhz);
+
 #endif /* __AMD_H__ */
Signature · 1 line
2.34.1
#45 lore raw

Re: [PATCH v4 08/15] xen/amd: introduce amd_process_freq() to get processor frequency

Quoted 11 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +0 -1
@@ -57,7 +57,6 @@ bool __initdata amd_virt_spec_ctrl;
 static bool __read_mostly fam17_c6_disabled;
 
 static uint64_t attr_const amd_parse_freq(unsigned char c, uint64_t value);
-#define INVAL_FREQ_MHZ  ~(uint64_t)0
 
 static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo,
 				 unsigned int *hi)

xen/arch/x86/cpu/amd.c static uint64_t amd_parse_freq(unsigned char c, uint64_t value) · line 598

Quoted 5 lines
xen/arch/x86/cpu/amd.c +1 -1
@@ -596,14 +595,13 @@ static uint64_t amd_parse_freq(unsigned char c, uint64_t value)
 	return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+void amd_process_freq(const struct cpuinfo_x86 *c,

Misra demands that functions only used in a single CU be static.

xen/arch/x86/cpu/amd.c static uint64_t amd_parse_freq(unsigned char c, uint64_t value) · line 599

Quoted 1 line
xen/arch/x86/cpu/amd.c +1 -0
+		      uint64_t *low_mhz, uint64_t *nom_mhz, uint64_t *hi_mhz)

See comments on patch 07 as to types used here.

Quoted 22 lines
xen/arch/x86/cpu/amd.c +4 -14
@@ -684,20 +682,21 @@ 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: %lu (%lu ... %lu) 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(),
-		       amd_parse_freq(c->x86, lo),
-		       amd_parse_freq(c->x86, hi));
-	else
-		printk("CPU%u: %lu 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)

xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 698

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+			*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)

Why does this "else if()" extend across two lines?

Quoted 10 lines
xen/arch/x86/cpu/amd.c +6 -0
@@ -708,6 +707,29 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
 	ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)
+{
+	uint64_t low_mhz, nom_mhz, hi_mhz;
+
+	if (c != &boot_cpu_data &&
+	    (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))

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

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+		return;
+
+	low_mhz = nom_mhz = hi_mhz = INVAL_FREQ_MHZ;
+	amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+	if (low_mhz != INVAL_FREQ_MHZ && nom_mhz != INVAL_FREQ_MHZ &&
+	    hi_mhz != INVAL_FREQ_MHZ)
+		printk("CPU%u: %lu (%lu ... %lu) MHz\n",
+		       smp_processor_id(),
+		       low_mhz, nom_mhz, hi_mhz);

This doesn't match the original order of frequencies logged.

Jan

#46 lore raw

PATCH v4 9/15 xen/x86: 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 firstly on AMD Zen based CPU series. 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. The new amd-cppc allows a more flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.

The first version "amd-cppc" could leverage common governors such as *ondemand*, *performance*, etc, to manage 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

---
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 393 +++++++++++++++++++++++++++
 xen/arch/x86/include/asm/msr-index.h |   5 +
 2 files changed, 398 insertions(+)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +393 -0
index 8a081e5523..2fdfd17f59 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(uint64_t, amd_max_pxfreq_mhz);
 
 static bool __init amd_cppc_handle_option(const char *s, const char *end)
 {
@@ -51,10 +100,354 @@ 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)
+ */
+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;
+    uint64_t mul, div;
+    int offset = 0, res;
+
+    if ( freq == (cppc_data->cpc.nominal_mhz * 1000) )
+    {
+        *perf = data->caps.nominal_perf;
+        return 0;
+    }
+
+    if ( freq == (cppc_data->cpc.lowest_mhz * 1000) )
+    {
+        *perf = data->caps.lowest_perf;
+        return 0;
+    }
+
+    if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz &&
+         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(amd_max_pxfreq_mhz);
+        if ( !div || div == INVAL_FREQ_MHZ )
+            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;
+    } else if ( res < 0 )
+    {
+        printk_once(XENLOG_WARNING
+                    "Perf value smaller than minimum value 0: %d\n", res);
+        *perf = 0;
+        return 0;
+    }
+    *perf = (uint8_t)res;
+
+    return 0;
+}
+
+static int amd_get_lowest_or_nominal_freq(const struct amd_cppc_drv_data *data,
+                                          uint32_t cpc_mhz, uint8_t perf,
+                                          unsigned int *freq)
+{
+    uint64_t mul, div, res;
+
+    if ( !freq )
+        return -EINVAL;
+
+    if ( cpc_mhz )
+    {
+        /* Switch to khz */
+        *freq = cpc_mhz * 1000;
+        return 0;
+    }
+
+    /* Read Processor Max Speed(MHz) as anchor point */
+    mul = this_cpu(amd_max_pxfreq_mhz);
+    if ( mul == INVAL_FREQ_MHZ || !mul )
+    {
+        printk(XENLOG_ERR
+               "Failed to read valid processor max frequency as anchor point: %lu\n",
+               mul);
+        return -EINVAL;
+    }
+    div = data->caps.highest_perf;
+    res = (mul * perf * 1000) / div;
+
+    if ( res > UINT_MAX || !res )
+    {
+        printk(XENLOG_ERR
+               "Frequeny exceeds maximum value UINT_MAX or being zero value: %lu\n",
+               res);
+        return -EINVAL;
+    }
+    *freq = (unsigned int)res;
+
+    return 0;
+}
+
+static int amd_get_max_freq(const struct amd_cppc_drv_data *data,
+                            unsigned int *max_freq)
+{
+    unsigned int nom_freq = 0, boost_ratio;
+    int res;
+
+    res = amd_get_lowest_or_nominal_freq(data,
+                                         data->cppc_data->cpc.nominal_mhz,
+                                         data->caps.nominal_perf,
+                                         &nom_freq);
+    if ( res )
+        return res;
+
+    boost_ratio = (unsigned int)(data->caps.highest_perf /
+                                 data->caps.nominal_perf);
+    *max_freq = nom_freq * boost_ratio;
+
+    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.lowest_nonlinear_perf ||
+         data->caps.lowest_nonlinear_perf > data->caps.nominal_perf ||
+         data->caps.nominal_perf > data->caps.highest_perf )
+    {
+        amd_cppc_err(policy->cpu,
+                     "Platform malfunction, read CPPC capability highest(%u), lowest(%u), nominal(%u), lowest_nonlinear(%u) zero value\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(amd_max_pxfreq_mhz));
+
+    data->err = amd_get_lowest_or_nominal_freq(data,
+                                               data->cppc_data->cpc.lowest_mhz,
+                                               data->caps.lowest_perf,
+                                               &min_freq);
+    if ( data->err )
+        return;
+
+    data->err = amd_get_lowest_or_nominal_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;
+    const struct cpuinfo_x86 *c = cpu_data + cpu;
+
+    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;
+
+    /* Feature CPPC is firstly introduced on Zen2 */
+    if ( c->x86 < 0x17 )
+    {
+        printk_once("Unsupported cpu family: %x\n", c->x86);
+        return -EOPNOTSUPP;
+    }
+
+    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 sanity check.
+     * If error path takes effective, not only amd-cppc cpufreq driver 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 AMD CPPC MSR properly\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/include/asm/msr-index.h +5 -0
index 22d9e76e55..3ffa613df0 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
#47 lore raw

Re: [PATCH v4 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling

Quoted 46 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +39 -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>
+
+#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;
+

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    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(uint64_t, amd_max_pxfreq_mhz);

Throughout here (and maybe also further down) - is the amd_ prefix really needed everywhere? Even the cppc part of the identifiers seems excessive in at least some of the cases.

For this last one, also once again see the type related comment on patch 07.

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
@@ -51,10 +100,354 @@ 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)

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+ *  - (Nominal perf, Nominal freq)
+ */
+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;
+    uint64_t mul, div;
+    int offset = 0, res;
+
+    if ( freq == (cppc_data->cpc.nominal_mhz * 1000) )

I'm pretty sure I commented on this before: The expression here _suggests_ that "freq" is in kHz, but that's not being made explicit anywhere.

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    {
+        *perf = data->caps.nominal_perf;
+        return 0;
+    }
+
+    if ( freq == (cppc_data->cpc.lowest_mhz * 1000) )
+    {
+        *perf = data->caps.lowest_perf;
+        return 0;
+    }

How likely is it that these two early return paths are taken, when the incoming "freq" is 25 or 5 MHz granular? IOW - is it relevant to shortcut these two cases?

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+    if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz &&
+         cppc_data->cpc.lowest_mhz < cppc_data->cpc.nominal_mhz )

Along the lines of a comment on an earlier patch, the middle part of the condition here is redundant with the 3rd one. Also, don't you check this relation already during init? IOW isn't it the 3rd part which can be dropped?

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    {
+        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.

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

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(amd_max_pxfreq_mhz);
+        if ( !div || div == INVAL_FREQ_MHZ )

Seeing this - do we need INVAL_FREQ_MHZ at all? Isn't 0 good enough an indicator of "data not available"?

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

Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
+            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;
+    } else if ( res < 0 )

Nit: Style. And no real need for "else" here anyway (or alternatively for the "return 0", with an "else" added below).

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

Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7 -0
+    {
+        printk_once(XENLOG_WARNING
+                    "Perf value smaller than minimum value 0: %d\n", res);
+        *perf = 0;
+        return 0;
+    }
+    *perf = (uint8_t)res;

We don't normally spell out such conversions (i.e. please drop the cast).

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

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4 -0
+    return 0;
+}
+
+static int amd_get_lowest_or_nominal_freq(const struct amd_cppc_drv_data *data,

Nothing in the function looks to limit it to "nominal" or "lowest", so them being in the identifier feels misleading.

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

Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7 -0
+                                          uint32_t cpc_mhz, uint8_t perf,
+                                          unsigned int *freq)
+{
+    uint64_t mul, div, res;
+
+    if ( !freq )
+        return -EINVAL;

Is this needed? It's an internal function.

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    if ( cpc_mhz )
+    {
+        /* Switch to khz */
+        *freq = cpc_mhz * 1000;
+        return 0;
+    }
+
+    /* Read Processor Max Speed(MHz) as anchor point */

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    mul = this_cpu(amd_max_pxfreq_mhz);
+    if ( mul == INVAL_FREQ_MHZ || !mul )
+    {
+        printk(XENLOG_ERR
+               "Failed to read valid processor max frequency as anchor point: %lu\n",
+               mul);
+        return -EINVAL;
+    }
+    div = data->caps.highest_perf;
+    res = (mul * perf * 1000) / div;

While there is a comment further up, clarifying function-wide that the result is to be in kHz would perhaps be better.

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

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4 -0
+    if ( res > UINT_MAX || !res )
+    {
+        printk(XENLOG_ERR
+               "Frequeny exceeds maximum value UINT_MAX or being zero value: %lu\n",

Just "out of range"?

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+               res);
+        return -EINVAL;

And then -ERANGE here?

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+    }
+    *freq = (unsigned int)res;

See above.

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+static int amd_get_max_freq(const struct amd_cppc_drv_data *data,
+                            unsigned int *max_freq)
+{
+    unsigned int nom_freq = 0, boost_ratio;
+    int res;

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+
+    res = amd_get_lowest_or_nominal_freq(data,
+                                         data->cppc_data->cpc.nominal_mhz,
+                                         data->caps.nominal_perf,
+                                         &nom_freq);
+    if ( res )
+        return res;
+
+    boost_ratio = (unsigned int)(data->caps.highest_perf /
+                                 data->caps.nominal_perf);

I may have seen logic ensuring nominal_perf isn't 0, so that part may be fine. What guarantees this division to yield a positive value, though? If it yields zero (say 0xff / 0x80), ...

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

Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1 -0
+    *max_freq = nom_freq * boost_ratio;

... zero will be reported back here. I think you want to scale the calculations here to avoid such.

Quoted 15 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +15 -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) )

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    {
+        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.lowest_nonlinear_perf ||

Same question as asked elsewhere - where is this relation specified?

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

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+         data->caps.lowest_nonlinear_perf > data->caps.nominal_perf ||
+         data->caps.nominal_perf > data->caps.highest_perf )
+    {
+        amd_cppc_err(policy->cpu,
+                     "Platform malfunction, read CPPC capability highest(%u), lowest(%u), nominal(%u), lowest_nonlinear(%u) zero value\n",

The message wants shortening if at all possible, and it wants to not be misleading (saying "zero" when the issue may be something else).

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

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6 -0
+                     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,

&cpu_data[policy->cpu] is generally preferred in such cases.

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -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;
+    const struct cpuinfo_x86 *c = cpu_data + cpu;
+
+    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 415

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;
+
+    /* Feature CPPC is firstly introduced on Zen2 */
+    if ( c->x86 < 0x17 )
+    {
+        printk_once("Unsupported cpu family: %x\n", c->x86);
+        return -EOPNOTSUPP;
+    }

With the cpu_has_cppc check in amd_cppc_register_driver(), is this check really needed?

Jan

#48 lore raw

RE: [PATCH v4 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling

[Public]

Hi,

Quoted 23 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 10:29 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 v4 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling

Quoted 12 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -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)
+ */
+static int amd_cppc_khz_to_perf(const struct amd_cppc_drv_data *data,
+                                unsigned int freq, uint8_t *perf) {
Quoted 9 lines

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

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+    const struct xen_processor_cppc *cppc_data = data->cppc_data;
+    uint64_t mul, div;
+    int offset = 0, res;
+
+    if ( freq == (cppc_data->cpc.nominal_mhz * 1000) )

I'm pretty sure I commented on this before: The expression here _suggests_ that "freq" is in kHz, but that's not being made explicit anywhere.

Sorry, I may overlook, and I'll be more careful.
I have clarified it in the function title, and maybe it's not enough. I'll change the parameter name from "freq" to "freq_khz" to be more explicit.

Quoted 11 lines

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    {
+        *perf = data->caps.nominal_perf;
+        return 0;
+    }
+
+    if ( freq == (cppc_data->cpc.lowest_mhz * 1000) )
+    {
+        *perf = data->caps.lowest_perf;
+        return 0;
+    }
Quoted 3 lines

How likely is it that these two early return paths are taken, when the incoming "freq" is 25 or 5 MHz granular? IOW - is it relevant to shortcut these two cases?

Sorry, I may not understand what you mean here.
Answering " How likely is it that these two early return paths are taken "
It's rare ig.... maybe *ondemand* governor will frequently give frequency around nominal frequency, but the exact value is rare ig.
I'm confused about " when the incoming "freq" is 25 or 5 MHz granular ".
Are we talking about is it worthy to have these two early return paths considering it is rarely taken

Quoted 7 lines

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+    if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz &&
+         cppc_data->cpc.lowest_mhz < cppc_data->cpc.nominal_mhz )

Along the lines of a comment on an earlier patch, the middle part of the condition here is redundant with the 3rd one. Also, don't you check this relation already during init? IOW isn't it the 3rd part which can be dropped?

Yes, you're right. I've checked it in set_cppc_pminfo() already and only gave warnings there.
I shall delete the check here, and besides giving warning message during init, if values are invalid, instead of storing invalid values, we shall set cppc_data->cpc.lowest_mhz / cppc_data->cpc.nominal_mhz them zero... Then wherever we are trying to use them, like here, non-zero values ensures valid values.

Quoted 10 lines
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+static int amd_get_max_freq(const struct amd_cppc_drv_data *data,
+                            unsigned int *max_freq) {
+    unsigned int nom_freq = 0, boost_ratio;
+    int res;
+
+    res = amd_get_lowest_or_nominal_freq(data,
+                                         data->cppc_data->cpc.nominal_mhz,
+                                         data->caps.nominal_perf,
+                                         &nom_freq);
+    if ( 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 225

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4 -0
+        return res;
+
+    boost_ratio = (unsigned int)(data->caps.highest_perf /
+                                 data->caps.nominal_perf);

I may have seen logic ensuring nominal_perf isn't 0, so that part may be fine. What guarantees this division to yield a positive value, though?
If it yields zero (say 0xff / 0x80), ...

I think maybe you were saying 0x80/0xff to yield zero value. For that, we checked that highest_perf must not be smaller than nominal_perf during init, see ...

Quoted 23 lines
Quoted 1 line

+ *max_freq = nom_freq * boost_ratio;

... zero will be reported back here. I think you want to scale the calculations here to avoid such.

Quoted 18 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +18 -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);
+    }
Quoted 11 lines

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

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6 -0
+
+    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.lowest_nonlinear_perf ||

Same question as asked elsewhere - where is this relation specified?

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+         data->caps.lowest_nonlinear_perf > data->caps.nominal_perf ||
+         data->caps.nominal_perf > data->caps.highest_perf )

here ...

Quoted 2 lines

Jan

#49 lore raw

Re: [PATCH v4 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling

Quoted 37 lines · Zheng
Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 29, 2025 10:29 PM

Quoted 22 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +20 -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)
+ */
+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;
+    uint64_t mul, div;
+    int offset = 0, res;
+
+    if ( freq == (cppc_data->cpc.nominal_mhz * 1000) )
+    {
+        *perf = data->caps.nominal_perf;
+        return 0;
+    }
+
Quoted 9 lines

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

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+    if ( freq == (cppc_data->cpc.lowest_mhz * 1000) )
+    {
+        *perf = data->caps.lowest_perf;
+        return 0;
+    }

How likely is it that these two early return paths are taken, when the incoming "freq" is 25 or 5 MHz granular? IOW - is it relevant to shortcut these two cases?

Quoted 6 lines

Sorry, I may not understand what you mean here.
Answering " How likely is it that these two early return paths are taken "
It's rare ig.... maybe *ondemand* governor will frequently give frequency around nominal frequency, but the exact value is rare ig.
I'm confused about " when the incoming "freq" is 25 or 5 MHz granular ".
Are we talking about is it worthy to have these two early return paths considering it is rarely taken

Yes - why have extra code which is expected to be hardly ever used. Things would be different if such shortcuts covered common cases.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+static int amd_get_max_freq(const struct amd_cppc_drv_data *data,
+                            unsigned int *max_freq) {
+    unsigned int nom_freq = 0, boost_ratio;
+    int res;
+
+    res = amd_get_lowest_or_nominal_freq(data,
+                                         data->cppc_data->cpc.nominal_mhz,
+                                         data->caps.nominal_perf,
+                                         &nom_freq);
+    if ( 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 225

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4 -0
+        return res;
+
+    boost_ratio = (unsigned int)(data->caps.highest_perf /
+                                 data->caps.nominal_perf);

I may have seen logic ensuring nominal_perf isn't 0, so that part may be fine. What guarantees this division to yield a positive value, though?
If it yields zero (say 0xff / 0x80), ...

Quoted 2 lines

I think maybe you were saying 0x80/0xff to yield zero value. For that, we checked that highest_perf must not be smaller than nominal_perf during init, see ...

No, I indeed meant 0xff / 0x80, but yes, that will yield 1, not 0. My main point though was about this calculation being pretty far off the real value (rather closer to 2), i.e. in the overall calculation (including ...

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ *max_freq = nom_freq * boost_ratio;

... this multiplication) some scaling may want introducing, or the multiplication may want doing ahead of the division.

Jan

#50 lore raw

PATCH v4 10/15 xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL

In reply to Penny Zheng

amd-cppc on active mode bypasses the scaling governor layer, and provides its own P-state selection algorithms in hardware. Consequently, when it is used, the driver's -> setpolicy() callback is invoked to register per-CPU utilization update callbacks, not the ->target() callback.

So, only when cpufreq_driver.setpolicy is NULL, we need to deliberately set old gov as NULL to trigger the according gov starting.

---
v3 -> v4:
- fix indentation and this commit is independent of all earlier patches

---
 xen/drivers/cpufreq/cpufreq.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/cpufreq/cpufreq.c +7 -1
index 818668c99c..2e392110d8 100644
@@ -396,7 +396,13 @@ int cpufreq_add_cpu(unsigned int cpu)
                     domain_info.num_processors) )
     {
         memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
-        policy->governor = NULL;
+
+        /*
+         * Only when cpufreq_driver.setpolicy == NULL, we need to deliberately
+         * set old gov as NULL to trigger the according gov starting.
+         */
+        if ( cpufreq_driver.setpolicy == NULL )
+            policy->governor = NULL;
 
         cpufreq_cmdline_common_para(&new_policy);
 
Signature · 1 line
2.34.1
#51 lore raw

Re: [PATCH v4 10/15] xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL

Quoted 6 lines · Penny Zheng

amd-cppc on active mode bypasses the scaling governor layer, and provides its own P-state selection algorithms in hardware. Consequently, when it is used, the driver's -> setpolicy() callback is invoked to register per-CPU utilization update callbacks, not the ->target() callback.

Quoted 8 lines

So, only when cpufreq_driver.setpolicy is NULL, we need to deliberately set old gov as NULL to trigger the according gov starting.

---
v3 -> v4:
- fix indentation and this commit is independent of all earlier patches

I've committed this, but had to adjust for fuzz first. Would be nice if such entirely ready (i.e. also independent) patches could be moved to the front of the containing series.

Jan

#52 lore raw

PATCH v4 11/15 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, non-autonomous (passive) mode.
In active mode, platform ignores the requestd done in the Desired Performance Target register and takes into account only the values set to the minimum, maximum and energy performance preference(EPP) registers.
The EPP is used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity. The SOC EPP targets are 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.

---
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

---
 docs/misc/xen-command-line.pandoc    |   8 +-
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 121 ++++++++++++++++++++++++++-
 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, 149 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.pandoc +7 -1
index 9ef847a336..09f5cb452f 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,12 @@ 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 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.
+  Then 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.
 
 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 +117 -4

191 lines not on this page · raw message

xen/arch/x86/include/asm/msr-index.h +1 -0
index 3ffa613df0..d29d1d33aa 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
#53 lore raw

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

Quoted 12 lines · Penny Zheng
docs/misc/xen-command-line.pandoc +1 -1
@@ -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`
 

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

Quoted 9 lines
docs/misc/xen-command-line.pandoc +6 -0
@@ -537,6 +537,12 @@ 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 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.
+  Then 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.

This section of the cmdline doc may not be of the best quality, but may I nevertheless ask that for this new sub-option you make explicit what the default is (and that it's of boolean nature)?

Quoted 20 lines
docs/misc/xen-command-line.pandoc +11 -0
@@ -434,12 +464,82 @@ static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
     amd_cppc_boost_init(policy, data);
 
+    return 0;
+}
+
+static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
+{
+    int ret;
+
+    ret = amd_cppc_cpufreq_init_perf(policy);
+    if ( ret )
+        return ret;
+
     amd_cppc_verbose(policy->cpu,
                      "CPU initialized with amd-cppc passive mode\n");
 
     return 0;
 }

docs/misc/xen-command-line.pandoc static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 492

Quoted 10 lines
docs/misc/xen-command-line.pandoc +9 -0
 
+static int cf_check amd_cppc_epp_cpu_init(struct cpufreq_policy *policy)
+{
+    int ret;
+
+    ret = amd_cppc_cpufreq_init_perf(policy);
+    if ( ret )
+        return ret;
+
+    policy->policy = cpufreq_policy_from_governor(policy->governor);

This is the init part, which is fine. What if the governor is being changed, though? The struct field is new, and there's no other place I can spot where it would be adjusted.

xen/arch/x86/include/asm/msr-index.h line 245

Quoted 7 lines
xen/arch/x86/include/asm/msr-index.h +1 -0
@@ -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)

Nit: Excess blank after << (there's no such issue with AMD_CPPC_ENABLE, ftaod).

Jan

#54 lore raw

RE: [PATCH v4 11/15] xen/x86: implement EPP support for the amd-cppc driver in active mode

[Public]

Hi,

Quoted 35 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 12:39 AM
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]>; [email protected]
Subject: Re: [PATCH v4 11/15] xen/x86: implement EPP support for the amd-cppc driver in active mode

Quoted 22 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
@@ -434,12 +464,82 @@ static int cf_check
 amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
     amd_cppc_boost_init(policy, data);
 
+    return 0;
+}
+
+static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy
+*policy) {
+    int ret;
+
+    ret = amd_cppc_cpufreq_init_perf(policy);
+    if ( ret )
+        return ret;
+
     amd_cppc_verbose(policy->cpu,
                      "CPU initialized with amd-cppc passive mode\n");
 
     return 0;
 }
 
Quoted 14 lines

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

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9 -0
+static int cf_check amd_cppc_epp_cpu_init(struct cpufreq_policy
+*policy) {
+    int ret;
+
+    ret = amd_cppc_cpufreq_init_perf(policy);
+    if ( ret )
+        return ret;
+
+    policy->policy = cpufreq_policy_from_governor(policy->governor);

This is the init part, which is fine. What if the governor is being changed, though? The struct field is new, and there's no other place I can spot where it would be adjusted.

Yes, I've missed the part that user changing governor through "xenpm set-scaling-governor" I'll add a new commit to fix

Quoted 2 lines

Jan

#55 lore raw

PATCH v4 12/15 tools/xenpm: Print CPPC parameters for amd-cppc driver

In reply to Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

Validation check on xenpm get-cpufreq-para shall also consider CPPC scenario.

---
v3 -> v4:
- Include validation check fix here

---
 tools/misc/xenpm.c        | 18 ++++++++++++++----
 xen/drivers/acpi/pmstat.c |  7 ++++---
 2 files changed, 18 insertions(+), 7 deletions(-)
tools/misc/xenpm.c +14 -4
index db658ebadd..29fffebebd 100644
@@ -790,9 +790,18 @@ 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 cppc_mode = false, hw_auto = false;
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME) )
+        cppc_mode = true;
+
+    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        :");
@@ -800,7 +809,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);
@@ -812,7 +821,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 ( cppc_mode )
     {
         const xc_cppc_para_t *cppc = &p_cpufreq->u.cppc_para;
 
@@ -838,7 +847,8 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
                cppc->desired,
                cppc->desired ? "" : " hw autonomous");
     }
-    else
+
+    if ( !hw_auto )
     {
         if ( p_cpufreq->gov_num )
             printf("scaling_avail_gov    : %s\n",
xen/drivers/acpi/pmstat.c +4 -3
index 767594908c..0e90ffcc19 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;
 
@@ -461,9 +461,10 @@ 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) )
+        if ( !pmpt || !(pmpt->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
             return -EINVAL;
         break;
     }
Signature · 1 line
2.34.1
#56 lore raw

Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

Quoted 6 lines · Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

But in the EPP driver you use the information which governor is active.

Quoted 8 lines
tools/misc/xenpm.c +1 -1
@@ -790,9 +790,18 @@ 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 cppc_mode = false, hw_auto = false;

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, · line 803

Quoted 10 lines
tools/misc/xenpm.c +8 -0
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME) )
+        cppc_mode = true;
+
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME) )
+        hw_auto = true;

Please avoid doing the same strcmp()s twice. There are several ways how to, so I'm not going to make a particular suggestion.

Quoted 12 lines
tools/misc/xenpm.c +1 -1
@@ -800,7 +809,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);

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

Quoted 7 lines
xen/drivers/acpi/pmstat.c +1 -1
@@ -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;

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.

Both this and ...

xen/drivers/acpi/pmstat.c int do_pm_op(struct xen_sysctl_pm_op *op) · line 470

Quoted 13 lines
xen/drivers/acpi/pmstat.c +3 -2
@@ -461,9 +461,10 @@ 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) )
+        if ( !pmpt || !(pmpt->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
             return -EINVAL;
         break;
     }

... this hunk also look as if they would belong (partly?) in maybe patch 03? Even more so as per the title this is solely a tool stack (xenpm) change.

Jan

#57 lore raw

RE: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

[Public]

Hi,

Quoted 10 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 9:55 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

On 14.04.2025 09:40, Penny Zheng wrote:

Quoted 9 lines
Quoted 6 lines

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

But in the EPP driver you use the information which governor is active.

We want to have a one-one mapping between governor and epp value, such as,
If users choose performance governor, no matter via "xenpm" or cmdline, users want maximum performance,
We set epp with 0 to meet the expectation.
And if users choose powersave governor, users want the least power consumption, then we shall set
epp with 255 to meet the expectation.
Ondemand is a tricky part, hmmmm, I don't know which value is suitable for it, the medium one? So I neglect it in the first place I'll add above explanation in commit which introduces CPUFREQ_POLICY_POWERSAVE/PERFORMANCE

Quoted 20 lines

tools/misc/xenpm.c static unsigned int · line 794

Quoted 8 lines
tools/misc/xenpm.c +0 -1
@@ -790,9 +790,18 @@ 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;

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,

Quoted 6 lines
tools/misc/xenpm.c +4 -0
+    bool cppc_mode = false, hw_auto = false;
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,

Quoted 4 lines
tools/misc/xenpm.c +4 -0
+        cppc_mode = true;
+
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,
Quoted 6 lines

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, · line 803

Quoted 1 line
tools/misc/xenpm.c +1 -0
+        hw_auto = true;

Please avoid doing the same strcmp()s twice. There are several ways how to, so I'm not going to make a particular suggestion.

Maybe we shall use switch-case() to replace the same strcmp()s
Since it's not easy to switch-case() string value, I had a draft idea to include an new entry in "struct xen_cppc_para", See:

```
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index fa431fd983..b872f1b66a 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -308,6 +308,10 @@ struct xen_ondemand {

 struct xen_cppc_para {
     /* OUT */
+#define XEN_SYSCTL_CPPC_VENDOR_HWP      1
+#define XEN_SYSCTL_CPPC_VENDOR_AMD      2
+#define XEN_SYSCTL_CPPC_VENDOR_AMD_EPP  3
+    uint8_t vendor;
     /* activity_window supported if set */
 #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW  (1 << 0)
     uint32_t features; /* bit flags for features */

```

A new vendor filed in struct xen_cppc_para could help us differ the underlying implementation. Or any better suggestions?

Quoted 23 lines

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

Quoted 1 line
tools/misc/xenpm.c +0 -0
@@ -800,7 +809,7 @@ static void print_cpufreq_para(int cpuid, struct

xc_get_cpufreq_para *p_cpufreq)

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

Quoted 11 lines
tools/misc/xenpm.c +1 -1
         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);
xen/drivers/acpi/pmstat.c +0 -0
@@ -201,7 +201,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op

*op)

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

Quoted 8 lines
xen/drivers/acpi/pmstat.c +2 -1
     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;
Quoted 4 lines

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

->perf.states is allocated in set_px_pminfo()
It is a px-specific function.

Quoted 5 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'll guard it with pmpt->init & XEN_PX_INIT too

Quoted 19 lines

Both this and ...

xen/drivers/acpi/pmstat.c int do_pm_op(struct xen_sysctl_pm_op *op) · line 470

Quoted 13 lines
xen/drivers/acpi/pmstat.c +3 -2
@@ -461,9 +461,10 @@ 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) )
+        if ( !pmpt || !(pmpt->init & (XEN_PX_INIT | XEN_CPPC_INIT)) )
             return -EINVAL;
         break;
     }

... this hunk also look as if they would belong (partly?) in maybe patch 03? Even more so as per the title this is solely a tool stack (xenpm) change.

True, I shall move them to 03, to let this commit being solely a tool stack (xenpm) change

Quoted 1 line

Jan

#58 lore raw

Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

Quoted 12 lines · Zheng
Quoted 12 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 9:55 PM

Quoted 6 lines · Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

Quoted 7 lines
Quoted 1 line

But in the EPP driver you use the information which governor is active.

We want to have a one-one mapping between governor and epp value, such as,
If users choose performance governor, no matter via "xenpm" or cmdline, users want maximum performance, We set epp with 0 to meet the expectation.
And if users choose powersave governor, users want the least power consumption, then we shall set epp with 255 to meet the expectation.

That's all fine, but completely misses the point of my question: If the governor is relevant, why would you bypass respective printing?

Quoted 1 line

Ondemand is a tricky part, hmmmm, I don't know which value is suitable for it, the medium one? So I neglect it in the first place

Medium one may be okay-ish, but it's not really an appropriate fit. We may want to at least consider rejecting the use of ondemand with the EPP driver. That, however, heavily depends on how hardware would behave when using the medium value.

Quoted 46 lines
Quoted 20 lines

tools/misc/xenpm.c static unsigned int · line 794

Quoted 8 lines
tools/misc/xenpm.c +0 -1
@@ -790,9 +790,18 @@ 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;

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,

Quoted 6 lines
tools/misc/xenpm.c +4 -0
+    bool cppc_mode = false, hw_auto = false;
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver, XEN_AMD_CPPC_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,

Quoted 4 lines
tools/misc/xenpm.c +4 -0
+        cppc_mode = true;
+
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,
Quoted 5 lines

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, · line 803

Quoted 1 line
tools/misc/xenpm.c +1 -0
+        hw_auto = true;

Please avoid doing the same strcmp()s twice. There are several ways how to, so I'm not going to make a particular suggestion.

Maybe we shall use switch-case() to replace the same strcmp()s
Since it's not easy to switch-case() string value, I had a draft idea to include an new entry in "struct xen_cppc_para", See:
```

xen/include/public/sysctl.h +4 -0
index fa431fd983..b872f1b66a 100644
@@ -308,6 +308,10 @@ struct xen_ondemand {
 
 struct xen_cppc_para {
     /* OUT */
+#define XEN_SYSCTL_CPPC_VENDOR_HWP      1
+#define XEN_SYSCTL_CPPC_VENDOR_AMD      2
+#define XEN_SYSCTL_CPPC_VENDOR_AMD_EPP  3
+    uint8_t vendor;
     /* activity_window supported if set */
 #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW  (1 << 0)
     uint32_t features; /* bit flags for features */
Quoted 3 lines

```
A new vendor filed in struct xen_cppc_para could help us differ the underlying implementation. Or any better suggestions?

Well, if you set hw_auto first, then you can use that variable plus one more strcmp() to set cppc_mode.

Jan

#59 lore raw

RE: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

[Public]

Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 13, 2025 4:03 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

Quoted 9 lines · Zheng
Quoted 9 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 9:55 PM

Quoted 4 lines · Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

But in the EPP driver you use the information which governor is active.

We want to have a one-one mapping between governor and epp value, such as, If users choose performance governor, no matter via "xenpm" or cmdline, users want maximum performance, We set epp with 0 to meet the

Quoted 7 lines

expectation.

Quoted 2 lines

And if users choose powersave governor, users want the least power consumption, then we shall set epp with 255 to meet the expectation.

That's all fine, but completely misses the point of my question: If the governor is relevant, why would you bypass respective printing?

The only useful info in governor for epp mode, IMO, is its name.
I deduce which performance policy user wants to apply through which governor they choose. If user chooses performance governor, they want maximum performance.
If user chooses powersave governor, they want the least power consumption
I could only provide appropriate epp value in above two scenarios.
ondemand and userspace are forbidden choices, and if users specify such options in cmdline, I shall give warning message to say that amd-cppc in active mode is governor-less, and users could set epp values on runtime to specify bias towards performance or efficiency.

If above is messy, I could also totally forbid governor thing for active mode... wdyt?

Quoted 66 lines
Quoted 2 lines

Ondemand is a tricky part, hmmmm, I don't know which value is suitable for it, the medium one? So I neglect it in the first place

Medium one may be okay-ish, but it's not really an appropriate fit. We may want to at least consider rejecting the use of ondemand with the EPP driver. That, however, heavily depends on how hardware would behave when using the medium value.

Quoted 8 lines
Quoted 8 lines

tools/misc/xenpm.c static unsigned int · line 794

Quoted 8 lines
tools/misc/xenpm.c +0 -1
@@ -790,9 +790,18 @@ 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)

Quoted 6 lines
Quoted 6 lines

== 0;

Quoted 5 lines
tools/misc/xenpm.c +3 -0
+    bool cppc_mode = false, hw_auto = false;
     int i;
 
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,

XEN_AMD_CPPC_DRIVER_NAME) ||

Quoted 33 lines
Quoted 11 lines

tools/misc/xenpm.c static unsigned int · line 799

Quoted 1 line
tools/misc/xenpm.c +1 -0
+         !strcmp(p_cpufreq->scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,

Quoted 4 lines
tools/misc/xenpm.c +4 -0
+        cppc_mode = true;
+
+    if ( !strcmp(p_cpufreq->scaling_driver, XEN_HWP_DRIVER_NAME) ||
+         !strcmp(p_cpufreq->scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME) )

tools/misc/xenpm.c static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc, · line 803

Quoted 1 line
tools/misc/xenpm.c +1 -0
+        hw_auto = true;

Please avoid doing the same strcmp()s twice. There are several ways how to, so I'm not going to make a particular suggestion.

Maybe we shall use switch-case() to replace the same strcmp()s Since it's not easy to switch-case() string value, I had a draft idea to include an new entry in "struct xen_cppc_para",
See:
```

xen/include/public/sysctl.h +4 -0
index fa431fd983..b872f1b66a 100644
@@ -308,6 +308,10 @@ struct xen_ondemand {
 
 struct xen_cppc_para {
     /* OUT */
+#define XEN_SYSCTL_CPPC_VENDOR_HWP      1
+#define XEN_SYSCTL_CPPC_VENDOR_AMD      2
+#define XEN_SYSCTL_CPPC_VENDOR_AMD_EPP  3
+    uint8_t vendor;
     /* activity_window supported if set */  #define
 XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW  (1 << 0)
     uint32_t features; /* bit flags for features */
Quoted 2 lines

```
A new vendor filed in struct xen_cppc_para could help us differ the underlying

implementation.

Quoted 1 line

Or any better suggestions?

Well, if you set hw_auto first, then you can use that variable plus one more strcmp() to set cppc_mode.

Jan

#60 lore raw

Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

Quoted 39 lines · Zheng
Quoted 22 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 13, 2025 4:03 PM

Quoted 9 lines · Zheng
Quoted 9 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 9:55 PM

Quoted 4 lines · Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

But in the EPP driver you use the information which governor is active.

We want to have a one-one mapping between governor and epp value, such as, If users choose performance governor, no matter via "xenpm" or cmdline, users want maximum performance, We set epp with 0 to meet the

Quoted 7 lines

expectation.

Quoted 2 lines

And if users choose powersave governor, users want the least power consumption, then we shall set epp with 255 to meet the expectation.

That's all fine, but completely misses the point of my question: If the governor is relevant, why would you bypass respective printing?

The only useful info in governor for epp mode, IMO, is its name.
I deduce which performance policy user wants to apply through which governor they choose. If user chooses performance governor, they want maximum performance.
If user chooses powersave governor, they want the least power consumption
I could only provide appropriate epp value in above two scenarios.
ondemand and userspace are forbidden choices, and if users specify such options in cmdline, I shall give warning message to say that amd-cppc in active mode is governor-less, and users could set epp values on runtime to specify bias towards performance or efficiency.

Quoted 1 line

If above is messy, I could also totally forbid governor thing for active mode... wdyt?

Then how would one pick between performance and powersave?

Jan

#61 lore raw

RE: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

[Public]

Quoted 50 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 20, 2025 5:18 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v4 12/15] tools/xenpm: Print CPPC parameters for amd-cppc driver

Quoted 27 lines · Zheng
Quoted 27 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, May 13, 2025 4:03 PM

Quoted 12 lines · Zheng
Quoted 12 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 9:55 PM

Quoted 6 lines · Penny Zheng

HWP, amd-cppc, amd-cppc-epp are all the implementation of ACPI CPPC (Collaborative Processor Performace Control), so we introduce cppc_mode flag to print CPPC-related para.

And HWP and amd-cppc-epp are both governor-less driver, so we introduce hw_auto flag to bypass governor-related print.

Quoted 6 lines
Quoted 1 line

But in the EPP driver you use the information which governor is active.

We want to have a one-one mapping between governor and epp value, such as, If users choose performance governor, no matter via "xenpm" or cmdline, users want maximum performance, We set epp with 0 to meet the

expectation.

Quoted 2 lines

And if users choose powersave governor, users want the least power consumption, then we shall set epp with 255 to meet the expectation.

Quoted 6 lines
Quoted 3 lines

That's all fine, but completely misses the point of my question: If the governor is relevant, why would you bypass respective printing?

The only useful info in governor for epp mode, IMO, is its name. I deduce which performance policy user wants to apply through which governor

they choose.

Quoted 6 lines

If user chooses performance governor, they want maximum performance. If user chooses powersave governor, they want the least power consumption I could only provide appropriate epp value in above two scenarios. ondemand and userspace are forbidden choices, and if users specify such options in cmdline, I shall give warning message to say that amd-cppc in active mode is governor-less, and users could set epp values on

Quoted 6 lines

runtime to specify bias towards performance or efficiency.

Quoted 2 lines

If above is messy, I could also totally forbid governor thing for active mode...

wdyt?

Then how would one pick between performance and powersave?

In hwp, we defined
"
#define CPPC_ENERGY_PERF_BALANCE 0x80
"
to provide the balanced value. Users could run "xenpm set-cpufreq-cppc balance" to achieve on runtime Any other specific epp value, users shall run "xenpm set-cpufreq-cppc energy-perf:N" to achieve We didn't provide any options in cmdline, so I tried to re-use the governor to achieve a few. hmmm, now it seems it brings confusion....

Quoted 2 lines

Jan

#62 lore raw

PATCH v4 13/15 tools/xenpm: fix unnecessary scaling_available_frequencies in CPPC mode

In reply to Penny Zheng

In xenpm get-cpufreq-para <cpuid>, para scaling_available_frequencies only has meaningful 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().
In get_cpufreq_para(), add "freq_num" check to avoid copying data to op->u.get_para.scaling_available_frequencies in CPPC mode.

---
v3 -> v4:
- drop the "has_num" condition check

---
 tools/libs/ctrl/xc_pm.c   | 45 +++++++++++++++++++++------------------
 xen/drivers/acpi/pmstat.c | 11 ++++++----
 2 files changed, 31 insertions(+), 25 deletions(-)
tools/libs/ctrl/xc_pm.c +24 -21
index ff7b5ada05..2089aa41b3 100644
@@ -212,34 +212,39 @@ 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 ( ret )
-            goto unlock_3;
+    }
+    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 +263,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
     {
xen/drivers/acpi/pmstat.c +7 -4
index 0e90ffcc19..83cfef398e 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 ( op->u.get_para.freq_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);
+    }
 
     xfree(data);
     if ( ret )
Signature · 1 line
2.34.1
#63 lore raw

Re: [PATCH v4 13/15] tools/xenpm: fix unnecessary scaling_available_frequencies in CPPC mode

Quoted 9 lines · Penny Zheng

In xenpm get-cpufreq-para <cpuid>, para scaling_available_frequencies only has meaningful 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().
In get_cpufreq_para(), add "freq_num" check to avoid copying data to op->u.get_para.scaling_available_frequencies in CPPC mode.

The description doesn't clarify where the bug is that's being fixed (from the word "fix" in the subject). If there was one, surely there would also want to be a Fixes: tag.

Quoted 4 lines
---
 tools/libs/ctrl/xc_pm.c   | 45 +++++++++++++++++++++------------------
 xen/drivers/acpi/pmstat.c | 11 ++++++----
 2 files changed, 31 insertions(+), 25 deletions(-)

xenpm is entirely untouched, unlike suggested by the subject prefix.

Quoted 33 lines
tools/libs/ctrl/xc_pm.c +11 -9
@@ -212,34 +212,39 @@ 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 )

tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 238

Quoted 10 lines
tools/libs/ctrl/xc_pm.c +5 -4
             goto unlock_2;
-        if ( user_para->gov_num )
-            ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);
-        if ( ret )
-            goto unlock_3;
+    }
+    if ( user_para->gov_num )
+        ret = xc_hypercall_bounce_pre(xch, scaling_available_governors);
+    if ( ret )
+        goto unlock_3;

Yes, ret is initialized to 0, so functionally this is okay. But can we please have all three pieces be as similar as possible, to make apparent that they're _expected_ to be similar?

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 ( op->u.get_para.freq_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);
+    }

What's the effect of this change? Without it, the loop will simply have zero iterations, and zero items will be copied to the guest. (As with the previous patch, this would better be a tools-only one anyway.)

Else the question would be why the same isn't done for cpu_num, which is becoming optional now, too (according to the libxc change).

Jan

#64 lore raw

PATCH v4 14/15 tools/xenpm: remove px_cap dependency check for average frequency

In reply to Penny Zheng

In xenpm start command, the monitor of average frequency shall not depend on the existence of legacy P-states, so removing "px_cap" dependancy check.

---
v3 -> v4:
- new commit

---
 tools/misc/xenpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/misc/xenpm.c +1 -1
index 29fffebebd..b823e5c433 100644
@@ -539,7 +539,7 @@ static void signal_int_handler(int signo)
                         res / 1000000UL, 100UL * res / (double)sum_px[i]);
             }
         }
-        if ( px_cap && avgfreq[i] )
+        if ( avgfreq[i] )
             printf("  Avg freq\t%d\tKHz\n", avgfreq[i]);
     }
 
Signature · 1 line
2.34.1
#65 lore raw

Re: [PATCH v4 14/15] tools/xenpm: remove px_cap dependency check for average frequency

Quoted 3 lines · Penny Zheng

In xenpm start command, the monitor of average frequency shall not depend on the existence of legacy P-states, so removing "px_cap" dependancy check.

Well, yes, I agree there. But can you explain to me what the file scope "avgfreq" is good for? Shouldn't we go farther and tidy things more thoroughly? Much like show_cpufreq_by_cpuid(), we could call get_avgfreq_by_cpuid() right before printing. (It escapes me altogether why start_gather_func() would pre-fill the array. Unlike cxstat_start[] and pxstat_start[] that's not incrementally or differentially used data.)

Doing that would make yet more obvious that the px_cap part of the condition was bogus presumably from the very start. (I'm further inclined to say that this change should also have a Fixes: tag.)

Jan

#66 lore raw

RE: [PATCH v4 14/15] tools/xenpm: remove px_cap dependency check for average frequency

[Public]

Hi,

Quoted 14 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 10:42 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v4 14/15] tools/xenpm: remove px_cap dependency check for average frequency

Quoted 3 lines · Penny Zheng

In xenpm start command, the monitor of average frequency shall not depend on the existence of legacy P-states, so removing "px_cap" dependancy check.

Quoted 7 lines

Well, yes, I agree there. But can you explain to me what the file scope "avgfreq" is good for? Shouldn't we go farther and tidy things more thoroughly? Much like show_cpufreq_by_cpuid(), we could call
get_avgfreq_by_cpuid() right before printing. (It escapes me altogether why start_gather_func() would pre-fill the array. Unlike cxstat_start[] and pxstat_start[] that's not incrementally or differentially used data.)

Right, I think avgfreq[] shall be just like cxstat_start[] and pxstat_start[], getting pre-filled in start_gather_func() too, maybe we don't need a avgfreq_start[] to actually record the numbers. What we achieve there is that in get_messured_perf(), we could let per_cpu(usr_perf_pair, cpu) save APERF/MPERF value at start_gather_func() point.

Then, later, in signal_int_handler(), running get_avgfreq_by_cpuid() again could actually let get_messured_perf() calculate APERF/MPERF incrementation happened between xenpm start duration. Right now, we are calculating incrementation between boot time, or last xenpm start command till now

Quoted 5 lines

Doing that would make yet more obvious that the px_cap part of the condition was bogus presumably from the very start. (I'm further inclined to say that this change should also have a Fixes: tag.)

Jan

#67 lore raw

PATCH v4 15/15 xen/xenpm: 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.

---
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

---
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 121 +++++++++++++++++++++++++++
 xen/drivers/acpi/pmstat.c            |  22 ++++-
 xen/include/acpi/cpufreq/cpufreq.h   |   4 +
 3 files changed, 143 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +121 -0
index 3a576fd4be..95d04bf77a 100644
@@ -540,6 +540,127 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
     return 0;
 }
 
+int get_amd_cppc_para(unsigned int cpu,
+                      struct xen_cppc_para *cppc_para)
+{
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+
+    if ( data == NULL )
+        return -ENODATA;
+
+    cppc_para->features         = 0;
+    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(const 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 - Disallow reserved bits. */
+    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 distiguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen, where min_perf =
+     * lowest_nonlinear_perf to ensures performance in P-state range.
+     * when it is not set, CPPC in active mode, three different profile
+     * XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANCE are provided,
+     * where min_perf = lowest_perf having T-state range of performance.
+     */
+    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;
+        min_perf = data->caps.lowest_perf;
+        /* Lower max frequency to nominal */
+        max_perf = data->caps.nominal_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 */
+        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;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_NONE:
+        min_perf = data->caps.lowest_nonlinear_perf;
+        max_perf = data->caps.highest_perf;
+        break;
+
+    default:
+        return -EINVAL;
+    }
+
+    /* Further customize presets if needed */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM )
+        min_perf = set_cppc->minimum;
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM )
+        max_perf = set_cppc->maximum;
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF )
+        epp = set_cppc->energy_perf;
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+        des_perf = set_cppc->desired;
+
+    amd_cppc_write_request(cpu, min_perf, des_perf, max_perf, epp);
+    return 0;
+}
+
 static const struct cpufreq_driver __initconst_cf_clobber
 amd_cppc_cpufreq_driver =
 {
xen/drivers/acpi/pmstat.c +18 -4
index 83cfef398e..876d82036d 100644
@@ -257,7 +257,18 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
          !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
                   CPUFREQ_NAME_LEN) )
         ret = get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para);
-    else
+    else if ( !strncmp(op->u.get_para.scaling_driver,
+                       XEN_AMD_CPPC_DRIVER_NAME,
+                       CPUFREQ_NAME_LEN) ||
+              !strncmp(op->u.get_para.scaling_driver,
+                       XEN_AMD_CPPC_EPP_DRIVER_NAME,
+                       CPUFREQ_NAME_LEN) )
+        ret = get_amd_cppc_para(policy->cpu, &op->u.get_para.u.cppc_para);
+
+    if ( strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) &&
+         strncmp(op->u.get_para.scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) )
     {
         if ( !(scaling_available_governors =
                xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )
@@ -413,10 +424,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 ( xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC )
+        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 +4 -0
index 6f31009e82..4d786ce92b 100644
@@ -292,5 +292,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(unsigned int cpu,
+                      struct xen_cppc_para *cppc_para);
+int set_amd_cppc_para(const struct cpufreq_policy *policy,
+                      const struct xen_set_cppc_para *set_cppc);
 
 #endif /* __XEN_CPUFREQ_PM_H__ */
Signature · 1 line
2.34.1
#68 lore raw

Re: [PATCH v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

Quoted 13 lines · 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.

---
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

Quoted 5 lines
---
 xen/arch/x86/acpi/cpufreq/amd-cppc.c | 121 +++++++++++++++++++++++++++
 xen/drivers/acpi/pmstat.c            |  22 ++++-
 xen/include/acpi/cpufreq/cpufreq.h   |   4 +
 3 files changed, 143 insertions(+), 4 deletions(-)

Along the lines of the remark on an earlier patch: Where's the "xenpm" change here, that the subject prefix kind of makes one expect? Doesn't that want to be "cpufreq:" instead?

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +0 -0
@@ -540,6 +540,127 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
     return 0;
 }

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9 -0
 
+int get_amd_cppc_para(unsigned int cpu,
+                      struct xen_cppc_para *cppc_para)
+{
+    const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);
+
+    if ( data == NULL )
+        return -ENODATA;
+
+    cppc_para->features         = 0;

What's the purpose of the field when you store literal 0 into it?

Quoted 16 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +16 -0
+    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(const struct cpufreq_policy *policy,
+                      const struct xen_set_cppc_para *set_cppc)
+{
+    unsigned int cpu = policy->cpu;

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+    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 - Disallow reserved bits. */
+    if ( set_cppc->minimum > UINT8_MAX || set_cppc->maximum > UINT8_MAX ||
+         set_cppc->desired > UINT8_MAX || set_cppc->energy_perf > UINT8_MAX )
+        return -EINVAL;

Where is what the latter half of the comment says?

Quoted 21 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +21 -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;
+
+    /* 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);
+    /*

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+     * Apply presets:
+     * XEN_SYSCTL_CPPC_SET_DESIRED reflects whether desired perf is set, which
+     * is also the flag to distiguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen, where min_perf =
+     * lowest_nonlinear_perf to ensures performance in P-state range.
+     * when it is not set, CPPC in active mode, three different profile
+     * XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANCE are provided,
+     * where min_perf = lowest_perf having T-state range of performance.
+     */

I fear I'm struggling to parse some of this, making it difficult to suggest possible adjustments (as I can't derive what is meant to be said). Plus where's the term T-state coming from all of the sudden?

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

Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -0
+    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;
+        min_perf = data->caps.lowest_perf;
+        /* Lower max frequency to nominal */
+        max_perf = data->caps.nominal_perf;

This combination is still not really in line with ...

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

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9 -0
+        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 */
+        min_perf = data->caps.highest_perf;
+        max_perf = data->caps.highest_perf;

... this. If "performance" means "always highest", why would "powersave" not mean "always lowest"?

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

Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13 -0
+        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;
+        min_perf = data->caps.lowest_perf;
+        max_perf = data->caps.highest_perf;
+        epp = CPPC_ENERGY_PERF_BALANCE;
+        break;
+
+    case XEN_SYSCTL_CPPC_SET_PRESET_NONE:
+        min_perf = data->caps.lowest_nonlinear_perf;

As before: What's the significance of using the non-linear value here? I asked to add comments for anything that's potentially unexpected to the reader, but here there's still none.

Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13 -0
+        max_perf = data->caps.highest_perf;
+        break;
+
+    default:
+        return -EINVAL;
+    }
+
+    /* Further customize presets if needed */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM )
+        min_perf = set_cppc->minimum;
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM )
+        max_perf = set_cppc->maximum;

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF )
+        epp = set_cppc->energy_perf;
+
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED )
+        des_perf = set_cppc->desired;
+
+    amd_cppc_write_request(cpu, min_perf, des_perf, max_perf, epp);
+    return 0;
+}

Nit (as before): Blank line please ahead of the main "return" of a function.

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

Quoted 13 lines
xen/drivers/acpi/pmstat.c +6 -1
@@ -257,7 +257,18 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
          !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
                   CPUFREQ_NAME_LEN) )
         ret = get_hwp_para(policy->cpu, &op->u.get_para.u.cppc_para);
-    else
+    else if ( !strncmp(op->u.get_para.scaling_driver,
+                       XEN_AMD_CPPC_DRIVER_NAME,
+                       CPUFREQ_NAME_LEN) ||
+              !strncmp(op->u.get_para.scaling_driver,
+                       XEN_AMD_CPPC_EPP_DRIVER_NAME,
+                       CPUFREQ_NAME_LEN) )

How about using e.g. strstr(..., XEN_AMD_CPPC_DRIVER_NAME) here? (It's odd anyway that we need to resort to string comparisons here.)

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

Quoted 9 lines
xen/drivers/acpi/pmstat.c +6 -0
+        ret = get_amd_cppc_para(policy->cpu, &op->u.get_para.u.cppc_para);
+
+    if ( strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) &&
+         strncmp(op->u.get_para.scaling_driver, XEN_AMD_CPPC_EPP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) )
     {
         if ( !(scaling_available_governors =
                xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )

Isn't it the non-EPP driver which is governor-independent?

Jan

#69 lore raw

RE: [PATCH v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

[Public]

Quoted 43 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 11:02 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 v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

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

Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -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) &&

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+          set_cppc->energy_perf) )
+        return -EINVAL;
+
+    /* Activity window not supported in MSR */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW )

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        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

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

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * is also the flag to distiguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen, where

min_perf =

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

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * lowest_nonlinear_perf to ensures performance in P-state range.
+     * when it is not set, CPPC in active mode, three different profile
+     *
Quoted 9 lines

XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANC E are provided,

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+     * where min_perf = lowest_perf having T-state range of performance.
+     */

I fear I'm struggling to parse some of this, making it difficult to suggest possible adjustments (as I can't derive what is meant to be said). Plus where's the term T- state coming from all of the sudden?

Pasting description on "lowest_perf" and "nonlinear_lowest_perf":
"
Lowest Nonlinear Performance is the lowest performance level at which nonlinear power savings are achieved, for example, due to the combined effects of voltage and frequency scaling. Above this threshold, lower performance levels should be generally more energy efficient than higher performance levels. In traditional terms, this represents the P-state range of performance levels.

Lowest Performance is the absolute lowest performance level of the platform. Selecting a performance level lower than the lowest nonlinear performance level may actually cause an efficiency penalty, but should reduce the instantaneous power consumption of the processor. In traditional terms, this represents the T-state range of performance levels. "
IMO, in passive mode, we rely on Xen governor to do performance tuning. And Xen governor is thinking based on P-states. So I take non-linear lowest perf as min_perf
While in active mode, hardware itself is calculating suitable performance/frequency automatically based on workload, thermal, voltage, and etc. So maybe setting min_perf with lowest perf is a better choice?

Quoted 6 lines

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

Quoted 6 lines
xen/drivers/acpi/pmstat.c +6 -0
+        ret = get_amd_cppc_para(policy->cpu,
+ &op->u.get_para.u.cppc_para);
+
+    if ( strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) &&
+         strncmp(op->u.get_para.scaling_driver,
Quoted 8 lines

XEN_AMD_CPPC_EPP_DRIVER_NAME,

Quoted 4 lines

+ CPUFREQ_NAME_LEN) )
{
if ( !(scaling_available_governors =
xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )

Isn't it the non-EPP driver which is governor-independent?

EPP driver is governor-independent, indicating active mode. Hardware itself will automatically calculate and set frequency. User only shall set min_perf, max_perf, and EPP at the beginning. EPP is a preference ratio value towards performance over powersave, on the scale of 0-255, 0 as 100% percentage favoring performance, while 255 as 100% percentage favoring powersave Non-EPP driver is still relying on Xen governor to do the tuning.

Quoted 1 line

Jan

#70 lore raw

Re: [PATCH v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

Quoted 55 lines · Zheng

[Public]

Quoted 43 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 11:02 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 v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

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

Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8 -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) &&

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+          set_cppc->energy_perf) )
+        return -EINVAL;
+
+    /* Activity window not supported in MSR */
+    if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW )

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

Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10 -0
+        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

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

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * is also the flag to distiguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen, where

min_perf =

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

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * lowest_nonlinear_perf to ensures performance in P-state range.
+     * when it is not set, CPPC in active mode, three different profile
+     *
Quoted 9 lines

XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANC E are provided,

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

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+     * where min_perf = lowest_perf having T-state range of performance.
+     */

I fear I'm struggling to parse some of this, making it difficult to suggest possible adjustments (as I can't derive what is meant to be said). Plus where's the term T- state coming from all of the sudden?

Quoted 6 lines

Pasting description on "lowest_perf" and "nonlinear_lowest_perf":
"
Lowest Nonlinear Performance is the lowest performance level at which nonlinear power savings are achieved, for example, due to the combined effects of voltage and frequency scaling. Above this threshold, lower performance levels should be generally more energy efficient than higher performance levels. In traditional terms, this represents the P-state range of performance levels.

Lowest Performance is the absolute lowest performance level of the platform. Selecting a performance level lower than the lowest nonlinear performance level may actually cause an efficiency penalty, but should reduce the instantaneous power consumption of the processor. In traditional terms, this represents the T-state range of performance levels. "

And again "T-state". The only T-ish thing I'm aware of is something that was never implemented in Xen's power management. Hence I fear I continue to be confused. (And btw, I searched PM vol 2 for the term, and it doesn't occur there at all.) As a result ...

Quoted 2 lines

IMO, in passive mode, we rely on Xen governor to do performance tuning. And Xen governor is thinking based on P-states. So I take non-linear lowest perf as min_perf
While in active mode, hardware itself is calculating suitable performance/frequency automatically based on workload, thermal, voltage, and etc. So maybe setting min_perf with lowest perf is a better choice?

...answering this question isn't possible for me (yet).

Quoted 12 lines
Quoted 12 lines

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

Quoted 6 lines
xen/drivers/acpi/pmstat.c +6 -0
+        ret = get_amd_cppc_para(policy->cpu,
+ &op->u.get_para.u.cppc_para);
+
+    if ( strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) &&
+         strncmp(op->u.get_para.scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME,

Quoted 4 lines

+ CPUFREQ_NAME_LEN) )
{
if ( !(scaling_available_governors =
xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )

Quoted 4 lines
Quoted 2 lines

Isn't it the non-EPP driver which is governor-independent?

EPP driver is governor-independent, indicating active mode.

I'm confused here as well then: Early in the series, before the EPP driver is introduced (i.e. as preparation for the non-EPP one) you suppress use and reporting of the governor. Whereas for the EPP driver while you (also) don't use the governor as such, you use the choice of governor to determine the EPP setting. In that sense to me the EPP driver is less governor- independent than the non-EPP one. That's what I tried to express in my earlier reply.

Jan

Quoted 5 lines

Hardware itself will automatically calculate and set frequency. User only shall set min_perf, max_perf, and EPP at the beginning.
EPP is a preference ratio value towards performance over powersave, on the scale of 0-255, 0 as 100% percentage favoring performance, while 255 as 100% percentage favoring powersave Non-EPP driver is still relying on Xen governor to do the tuning.

Quoted 1 line

Jan

#71 lore raw

RE: [PATCH v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

[Public]

Quoted 86 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, May 22, 2025 2:51 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 v4 15/15] xen/xenpm: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver

Quoted 10 lines · Zheng

[Public]

Quoted 8 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, April 30, 2025 11:02 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 v4 15/15] xen/xenpm: Adapt

SET/GET_CPUFREQ_CPPC

Quoted 5 lines
Quoted 5 lines

xen_sysctl_pm_op for amd-cppc driver

Quoted 2 lines · Penny Zheng
(quoted diff) +2 -0
+    /* Only allow values if params bit is set. */
+    if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED)

&&

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+          set_cppc->desired) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM)

&&

Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+          set_cppc->minimum) ||
+         (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM)

&&

Quoted 8 lines
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+          set_cppc->maximum) ||
+         (!(set_cppc->set_params &

XEN_SYSCTL_CPPC_SET_ENERGY_PERF) &&

Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5 -0
+          set_cppc->energy_perf) )
+        return -EINVAL;
+
+    /* Activity window not supported in MSR */
+    if ( set_cppc->set_params &

XEN_SYSCTL_CPPC_SET_ACT_WINDOW )

Quoted 12 lines
Quoted 12 lines

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

Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11 -0
+        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

Quoted 8 lines
Quoted 8 lines

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

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * is also the flag to distiguish between passive mode and active mode.
+     * When it is set, CPPC in passive mode, only
+     * XEN_SYSCTL_CPPC_SET_PRESET_NONE could be chosen, where

min_perf =

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +3 -0
+     * lowest_nonlinear_perf to ensures performance in P-state range.
+     * when it is not set, CPPC in active mode, three different profile
+     *

XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANC

Quoted 4 lines
Quoted 4 lines

E are provided,

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2 -0
+     * where min_perf = lowest_perf having T-state range of performance.
+     */
Quoted 8 lines
Quoted 4 lines

I fear I'm struggling to parse some of this, making it difficult to suggest possible adjustments (as I can't derive what is meant to be said). Plus where's the term T- state coming from all of the sudden?

Pasting description on "lowest_perf" and "nonlinear_lowest_perf":
"
Lowest Nonlinear Performance is the lowest performance level at which nonlinear

power savings are achieved, for example, due to the combined effects of voltage and frequency scaling. Above this threshold, lower performance levels should be generally more energy efficient than higher performance levels. In traditional terms, this represents the P-state range of performance levels.

Quoted 2 lines

Lowest Performance is the absolute lowest performance level of the platform.

Selecting a performance level lower than the lowest nonlinear performance level may actually cause an efficiency penalty, but should reduce the instantaneous power consumption of the processor. In traditional terms, this represents the T-state range of performance levels.

Quoted 7 lines
Quoted 1 line

"

And again "T-state". The only T-ish thing I'm aware of is something that was never implemented in Xen's power management. Hence I fear I continue to be confused. (And btw, I searched PM vol 2 for the term, and it doesn't occur there at all.) As a result ...

Sorry, I didn't add the reference:
https://uefi.org/specs/ACPI/6.5/08_Processor_Configuration_and_Control.html?highlight=cppc#lowest-nonlinear-performance

Quoted 20 lines
Quoted 2 lines

IMO, in passive mode, we rely on Xen governor to do performance tuning. And Xen governor is thinking based on P-states. So I take non-linear

lowest perf as min_perf While in active mode, hardware itself is calculating suitable performance/frequency automatically based on workload, thermal, voltage, and etc. So maybe setting min_perf with lowest perf is a better choice?

...answering this question isn't possible for me (yet).

Quoted 12 lines
Quoted 12 lines

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

Quoted 6 lines
xen/drivers/acpi/pmstat.c +6 -0
+        ret = get_amd_cppc_para(policy->cpu,
+ &op->u.get_para.u.cppc_para);
+
+    if ( strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
+                 CPUFREQ_NAME_LEN) &&
+         strncmp(op->u.get_para.scaling_driver,

XEN_AMD_CPPC_EPP_DRIVER_NAME,

Quoted 4 lines

+ CPUFREQ_NAME_LEN) )
{
if ( !(scaling_available_governors =
xzalloc_array(char, gov_num * CPUFREQ_NAME_LEN)) )

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Isn't it the non-EPP driver which is governor-independent?

EPP driver is governor-independent, indicating active mode.

I'm confused here as well then: Early in the series, before the EPP driver is introduced (i.e. as preparation for the non-EPP one) you suppress use and reporting of the governor. Whereas for the EPP driver while you (also) don't use the

Are you mentioning the commit of " xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL " ?
The commit previously is added before the introduction of amd-cppc in active mode (EPP-mode), and in the commit message, It says " amd-cppc on active mode bypasses the scaling governor layer ...."
IMO, cpufreq driver in Xen inherited from Linux, and in Linux, for hooks in cpufreq driver, we defined ->setpolicy() and ->target(), these two are exclusive to each other. We have " !driver_data->target == !driver_data->setpolicy " checking in cpufreq_register_driver(). ->targe() hook is for cpufreq driver needing Xen governor, and ->setpolicy() is for governor-less cpufreq driver. Although we already defined these hooks, EPP-mode is the first driver which actually implements ->setpolicy hook

Quoted 4 lines

governor as such, you use the choice of governor to determine the EPP setting. In that sense to me the EPP driver is less governor- independent than the non-EPP one. That's what I tried to express in my earlier reply.

Sorry for bringing confusion here.
Like I addressed in previous email, the reason why I tried to build connection between governor and EPP-mode is for those users, who chooses EPP-mode, and tries use governor to deliver their performance policy, such as defining such cpufreq cmdline "cpufreq=performance,amd-cppc,active"
Quoting what I replied in another thread:

The only useful info in governor for epp mode, IMO, is its name.
I deduce which performance policy user wants to apply through which governor they choose.
If user chooses performance governor, they want maximum performance.
If user chooses powersave governor, they want the least power consumption I could only provide appropriate epp value in above two scenarios.
ondemand and userspace are forbidden choices, and if users specify such options in cmdline, I shall give warning message to say that amd-cppc in active mode is governor-less, and users could set epp values on runtime to specify bias towards performance or efficiency.

Quoted 10 lines

Janr

Quoted 1 line

Hardware itself will automatically calculate and set frequency. User only shall set

min_perf, max_perf, and EPP at the beginning.

Quoted 2 lines

EPP is a preference ratio value towards performance over powersave, on the scale of 0-255, 0 as 100% percentage favoring performance, while 255 as

100% percentage favoring powersave Non-EPP driver is still relying on Xen governor to do the tuning.

Quoted 2 lines
Quoted 2 lines

Jan