amd-cppc CPU Performance Scaling Driver
v3 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: introduces XEN_PM_PSD for solely delivery of _PSD xen/x86: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/cpufreq: move XEN_PROCESSOR_PM_xxx to internal header 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: export processor max frequency value
xen/x86: introduce a new amd cppc driver for cpufreq scaling xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL xen/cpufreq: abstract Energy Performance Preference value xen/x86: implement EPP support for the amd-cppc driver in active mode tools/xenpm: Print CPPC parameters for amd-cppc driver xen/xenpm: Adapt cpu frequency monitor in xenpm xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver
docs/misc/xen-command-line.pandoc | 27 +- tools/libs/ctrl/xc_pm.c | 12 +- tools/misc/xenpm.c | 23 +- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/acpi.c | 14 +- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 681 ++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 34 +- xen/arch/x86/acpi/cpufreq/hwp.c | 10 +- xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/cpu/amd.c | 37 +- xen/arch/x86/include/asm/amd.h | 1 + xen/arch/x86/include/asm/msr-index.h | 5 + xen/arch/x86/platform_hypercall.c | 25 + xen/arch/x86/pv/dom0_build.c | 1 - xen/arch/x86/setup.c | 1 + xen/arch/x86/x86_64/cpufreq.c | 4 + xen/common/domain.c | 1 + xen/drivers/acpi/pmstat.c | 54 +- xen/drivers/cpufreq/cpufreq.c | 258 +++++--- xen/drivers/cpufreq/cpufreq_ondemand.c | 2 +- xen/drivers/cpufreq/utility.c | 18 + xen/include/acpi/cpufreq/cpufreq.h | 31 + xen/include/acpi/cpufreq/processor_perf.h | 18 +- xen/include/public/platform.h | 38 +- xen/include/public/sysctl.h | 2 + xen/include/public/xen.h | 1 - xen/include/xen/pmstat.h | 4 + xen/include/xlat.lst | 3 +- 28 files changed, 1160 insertions(+), 148 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
Signature · 1 line
2.34.1
PATCH v3 1/15 xen/cpufreq: introduces XEN_PM_PSD for solely delivery of _PSD
_PSD(P-State Dependency) provides performance control, no matter legacy P-state or CPPC, logical processor dependency information to OSPM.
In order to re-use it for CPPC, this commit extracts the delivery of _PSD info from set_px_pminfo() and wrap it with a new sub-hypercall XEN_PM_PSD.
---
v2 -> v3:
- new commit
--- xen/arch/x86/acpi/cpufreq/acpi.c | 2 +- xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/platform_hypercall.c | 11 ++ xen/arch/x86/x86_64/cpufreq.c | 2 + xen/drivers/cpufreq/cpufreq.c | 122 +++++++++++++--------- xen/drivers/cpufreq/cpufreq_ondemand.c | 2 +- xen/include/acpi/cpufreq/processor_perf.h | 4 +- xen/include/public/platform.h | 17 +-- xen/include/xen/pmstat.h | 2 + xen/include/xlat.lst | 2 +- 10 files changed, 103 insertions(+), 63 deletions(-)
xen/arch/x86/acpi/cpufreq/acpi.c +1 -1
@@ -393,7 +393,7 @@ static int cf_check acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) data->acpi_data = &processor_pminfo[cpu]->perf; perf = data->acpi_data; - policy->shared_type = perf->shared_type; + policy->shared_type = processor_pminfo[cpu]->shared_type;switch (perf->control_register.space_id) {case ACPI_ADR_SPACE_SYSTEM_IO :
xen/arch/x86/acpi/cpufreq/powernow.c +1 -1
@@ -218,7 +218,7 @@ static int cf_check powernow_cpufreq_cpu_init(struct cpufreq_policy *policy) data->acpi_data = &processor_pminfo[cpu]->perf; info.perf = perf = data->acpi_data; - policy->shared_type = perf->shared_type; + policy->shared_type = processor_pminfo[cpu]->shared_type;if (policy->shared_type ==CPUFREQ_SHARED_TYPE_ALL || policy->shared_type ==CPUFREQ_SHARED_TYPE_ANY ) {
xen/arch/x86/platform_hypercall.c +11 -0
@@ -571,6 +571,17 @@ ret_t do_platform_op( ret =acpi_set_pdc_bits (op->u.set_pminfo.id, pdc);break ; } +case XEN_PM_PSD : +if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) + { + ret = -EOPNOTSUPP ; +break ; + } + + ret =set_psd_pminfo (op->u.set_pminfo.id, + op->u.set_pminfo.shared_type, + &op->u.set_pminfo.u.domain_info); +break ;default : ret = -EINVAL ;
xen/arch/x86/x86_64/cpufreq.c +2 -0
@@ -28,6 +28,8 @@ CHECK_processor_px; +CHECK_psd_package; +DEFINE_XEN_GUEST_HANDLE (compat_processor_px_t); int compat_set_px_pminfo(uint32_t acpi_id,
xen/drivers/cpufreq/cpufreq.c +73 -49
217 lines not on this page · raw message
xen/drivers/cpufreq/cpufreq_ondemand.c +1 -1
@@ -194,7 +194,7 @@ static void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)set_timer (&per_cpu (dbs_timer, dbs_info->cpu),NOW ()+dbs_tuners_ins.sampling_rate); -if ( processor_pminfo[dbs_info->cpu]->perf.shared_type +if ( processor_pminfo[dbs_info->cpu]->shared_type ==CPUFREQ_SHARED_TYPE_HW ) { dbs_info->stoppable =1 ;
xen/include/acpi/cpufreq/processor_perf.h +2 -2
@@ -27,8 +27,6 @@ struct processor_performance {struct xen_pct_register status_register;uint32_t state_count;struct xen_processor_px *states; -struct xen_psd_package domain_info; -uint32_t shared_type;uint32_t init; };
@@ -36,6 +34,8 @@ struct processor_performance {struct processor_pminfo {uint32_t acpi_id;uint32_t id; +struct xen_psd_package domain_info; +uint32_t shared_type;struct processor_performance perf; };
xen/include/public/platform.h +9 -8
@@ -363,12 +363,12 @@ 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_PSD 4/* Px sub info type */ #define XEN_PX_PCT 1#define XEN_PX_PSS 2#define XEN_PX_PPC 4 -#define XEN_PX_PSD 8struct xen_power_register {uint32_t space_id;
@@ -439,6 +439,7 @@ struct xen_psd_package {uint64_t coord_type;uint64_t num_processors; }; +typedef struct xen_psd_package xen_psd_package_t ;struct xen_processor_performance {uint32_t flags;/* flag for Px sub info type */
@@ -447,12 +448,6 @@ struct xen_processor_performance {struct xen_pct_register status_register;uint32_t state_count;/* total available performance states */ 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; };typedef struct xen_processor_performance xen_processor_performance_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t);
@@ -463,9 +458,15 @@ struct xenpf_set_processor_pminfo {uint32_t type;/* {XEN_PM_CX, XEN_PM_PX} */ union {struct xen_processor_power power;/* Cx: _CST/_CSD */ -struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/_PSD */ +xen_psd_package_t domain_info;/* _PSD */ +struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/ */ XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ } u; +/* 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; };typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t ;DEFINE_XEN_GUEST_HANDLE (xenpf_set_processor_pminfo_t);
xen/include/xen/pmstat.h +2 -0
@@ -5,6 +5,8 @@#include <public/platform.h> /* for struct xen_processor_power */ #include <public/sysctl.h> /* for struct pm_cx_stat */ +int set_psd_pminfo (uint32_t acpi_id,uint32_t shared_type, +const struct xen_psd_package *psd_data);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);
xen/include/xlat.lst +1 -1
@@ -168,7 +168,7 @@ ! processor_performance platform.h ! processor_power platform.h ? processor_px platform.h -! psd_package platform.h +? psd_package platform.h ? xenpf_enter_acpi_sleep platform.h ? xenpf_pcpu_version platform.h ? xenpf_pcpuinfo platform.h
Signature · 1 line
2.34.1
Re: [PATCH v3 01/15] xen/cpufreq: introduces XEN_PM_PSD for solely delivery of _PSD
Quoted 44 lines · Penny Zheng
xen/include/public/platform.h +4
-8@@ -363,12 +363,12 @@ 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_PSD 4/* Px sub info type */ #define XEN_PX_PCT 1#define XEN_PX_PSS 2#define XEN_PX_PPC 4 -#define XEN_PX_PSD 8struct xen_power_register {uint32_t space_id;@@ -439,6 +439,7 @@ struct xen_psd_package {uint64_t coord_type;uint64_t num_processors; }; +typedef struct xen_psd_package xen_psd_package_t ;struct xen_processor_performance {uint32_t flags;/* flag for Px sub info type */ @@ -447,12 +448,6 @@ struct xen_processor_performance {struct xen_pct_register status_register;uint32_t state_count;/* total available performance states */ 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; };typedef struct xen_processor_performance xen_processor_performance_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t);@@ -463,9 +458,15 @@ struct xenpf_set_processor_pminfo {uint32_t type;/* {XEN_PM_CX, XEN_PM_PX} */ union {struct xen_processor_power power;/* Cx: _CST/_CSD */ -struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/_PSD */ +xen_psd_package_t domain_info;/* _PSD */ +struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/ */
xen/include/public/platform.h struct xenpf_set_processor_pminfo { · line 472
Quoted 10 lines
xen/include/public/platform.h +5
-0XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ } u; +/* 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; };typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t ;DEFINE_XEN_GUEST_HANDLE (xenpf_set_processor_pminfo_t);
With this change to stable hypercall structures, how is an older Dom0 kernel going to be able to properly upload the necessary data? IOW: No, you can't alter existing stable hypercall structures like this.
Jan
RE: [PATCH v3 01/15] xen/cpufreq: introduces XEN_PM_PSD for solely delivery of _PSD
[Public]
Hi,
Quoted 77 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 10:09 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 v3 01/15] xen/cpufreq: introducesXEN_PM_PSDfor solely delivery of_PSDxen/include/public/platform.h
Quoted 3 lines · Penny Zheng
xen/include/public/platform.h +0
-0@@ -363,12 +363,12 @@
DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);Quoted 22 lines
xen/include/public/platform.h +2
-1#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_PSD 4/* Px sub info type */ #define XEN_PX_PCT 1#define XEN_PX_PSS 2#define XEN_PX_PPC 4 -#define XEN_PX_PSD 8struct xen_power_register {uint32_t space_id;@@ -439,6 +439,7 @@ struct xen_psd_package {uint64_t coord_type;uint64_t num_processors; }; +typedef struct xen_psd_package xen_psd_package_t ;struct xen_processor_performance {uint32_t flags;/* flag for Px sub info type */ xen/include/public/platform.h struct xen_processor_performance { · line 452
Quoted 6 lines
xen/include/public/platform.h +0
-3@@ -447,12 +448,6 @@ struct xen_processor_performance {struct xen_pct_register status_register;uint32_t state_count;/* total available performance states */ 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_ANY3 /* Freq can be setfrom any dependent CPU */
xen/include/public/platform.h struct xenpf_set_processor_pminfo { · line 466
Quoted 9 lines
-
uint32_tshared_type;
};
typedef structxen_processor_performancexen_processor_performance_t;DEFINE_XEN_GUEST_HANDLE(xen_processor_performance_t);xen/include/public/platform.h +0
-1@@ -463,9 +458,15 @@ struct xenpf_set_processor_pminfo {uint32_t type;/* {XEN_PM_CX, XEN_PM_PX} */ union {struct xen_processor_power power;/* Cx: _CST/_CSD */ -struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/_PSD */
xen/include/public/platform.h struct xenpf_set_processor_pminfo {
Quoted 6 lines
xen/include/public/platform.h +4
-0+xen_psd_package_t domain_info;/* _PSD */ +struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/ */ XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ } u; +/* Coordination type of this processor */ +#define XEN_CPUPERF_SHARED_TYPE_HW 1/* HW does needed coordination */
xen/include/public/platform.h struct xenpf_set_processor_pminfo { · line 467
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 xenpf_set_processor_pminfo { · line 468
Quoted 1 line
xen/include/public/platform.h +1
-0+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
-0+uint32_t shared_type; };typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t ;
DEFINE_XEN_GUEST_HANDLE(xenpf_set_processor_pminfo_t);
Quoted 4 lines
With this change to stable hypercall structures, how is an older Dom0 kernel going to be able to properly upload the necessary data? IOW: No, you can't alter existing stable hypercall structures like this.
Understood.
I'll expand the newly added "struct xen_processor_cppc", to let it also include _PSD info and shared type
```
+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;
```Quoted 1 line
Jan
PATCH v3 2/15 xen/x86: introduce new sub-hypercall to propagate CPPC data
In reply to Penny ZhengIn order to provide backward compatibility with existing governors that represent performance as frequencies, 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, this commit introduces a new sub-hypercall to propagate required CPPC data from dom0 kernel.
If the platform supports CPPC, the _CPC object must exist under all processor objects. That is, Xen is not expected to support mixed mode (CPPC & legacy PSS, _PCT, _PPC) operation, either advanced CPPC, or legacy P-states.
This commit also introduces a new flag XEN_PM_CPPC to reflect processor initialised in CPPC 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
--- xen/arch/x86/platform_hypercall.c | 5 +++ xen/arch/x86/x86_64/cpufreq.c | 2 + xen/drivers/acpi/pmstat.c | 4 +- xen/drivers/cpufreq/cpufreq.c | 53 +++++++++++++++++++++-- xen/include/acpi/cpufreq/processor_perf.h | 8 ++-- xen/include/public/platform.h | 16 +++++++ xen/include/xen/pmstat.h | 2 + xen/include/xlat.lst | 1 + 8 files changed, 82 insertions(+), 9 deletions(-)
xen/arch/x86/platform_hypercall.c +5 -0
@@ -583,6 +583,11 @@ ret_t do_platform_op( &op->u.set_pminfo.u.domain_info);break ; +case XEN_PM_CPPC : + ret =set_cppc_pminfo (op->u.set_pminfo.id, + &op->u.set_pminfo.u.cppc_data); +break ; +default : ret = -EINVAL ;break ;
xen/arch/x86/x86_64/cpufreq.c +2 -0
@@ -26,6 +26,8 @@#include <xen/pmstat.h> #include <compat/platform.h> +CHECK_processor_cppc; + CHECK_processor_px; CHECK_psd_package;
xen/drivers/acpi/pmstat.c +2 -2
@@ -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 :
@@ -467,7 +467,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 |XEN_CPPC_INIT )) )return -EINVAL ;break ; }
xen/drivers/cpufreq/cpufreq.c +49 -4
89 lines not on this page · raw message
xen/include/acpi/cpufreq/processor_perf.h +5 -3
@@ -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 0x80000000Uunsigned int powernow_register_driver (void );unsigned int get_measured_perf (unsigned int cpu,unsigned int flag);
@@ -27,8 +28,6 @@ struct processor_performance {struct xen_pct_register status_register;uint32_t state_count;struct xen_processor_px *states; - -uint32_t init; };struct processor_pminfo {
@@ -37,6 +36,9 @@ struct processor_pminfo {struct xen_psd_package domain_info;uint32_t shared_type;struct processor_performance perf; +struct xen_processor_cppc cppc_data; + +uint32_t init; };extern struct processor_pminfo *processor_pminfo[NR_CPUS ];
xen/include/public/platform.h +16 -0
@@ -364,6 +364,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_TX 2#define XEN_PM_PDC 3#define XEN_PM_PSD 4 +#define XEN_PM_CPPC 5/* Px sub info type */ #define XEN_PX_PCT 1
@@ -432,6 +433,20 @@ struct xen_processor_px {typedef struct xen_processor_px xen_processor_px_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_px_t); +/* +* Subset _CPC fields useful for CPPC-compatible cpufreq +* driver's initialization +*/ +struct xen_processor_cppc { +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; +}; +typedef struct xen_processor_cppc xen_processor_cppc_t ; +struct xen_psd_package {uint64_t num_entries;uint64_t revision;
@@ -461,6 +476,7 @@ struct xenpf_set_processor_pminfo {xen_psd_package_t domain_info;/* _PSD */ struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/ */ XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ +xen_processor_cppc_t cppc_data;/*_CPC */ } u;/* Coordination type of this processor */ #define XEN_CPUPERF_SHARED_TYPE_HW 1/* HW does needed coordination */
xen/include/xen/pmstat.h +2 -0
@@ -8,6 +8,8 @@int set_psd_pminfo (uint32_t acpi_id,uint32_t shared_type,const struct xen_psd_package *psd_data);int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf); +int set_cppc_pminfo (uint32_t acpi_id, +const struct xen_processor_cppc *cppc_data);long set_cx_pminfo (uint32_t acpi_id,struct xen_processor_power *power);#ifdef CONFIG_COMPAT
xen/include/xlat.lst +1 -0
@@ -162,6 +162,7 @@ ! pct_register platform.h ! power_register platform.h +? processor_cppc platform.h ? processor_csd platform.h ! processor_cx platform.h ! processor_flags platform.h
Signature · 1 line
2.34.1
Re: [PATCH v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC data
Quoted 10 lines · Penny Zheng
In order to provide backward compatibility with existing governors that represent performance as frequencies, like ondemand, the
_CPCtable 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, this commit introduces a new sub-hypercall to propagate required CPPC data from dom0 kernel.
Nit: Here and ...
Quoted 7 lines
If the platform supports CPPC, the
_CPCobject must exist under all processor objects. That is, Xen is not expected to support mixed mode (CPPC & legacy PSS,_PCT,_PPC) operation, either advanced CPPC, or legacy P-states.This commit also introduces a new flag
XEN_PM_CPPCto reflect processor initialised in CPPC mode.
... here and elsewhere: Please avoid "this commit", "this patch", or anything alike in patch descriptions.
Apart from this I'm not sure how useful review here is going to be, as there apparently is a dependency on the problematic aspect in patch 1. Therefore I'll give only a few independent comments.
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c +5
-0@@ -606,6 +616,41 @@ int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type,return ret; } +int set_cppc_pminfo (uint32_t acpi_id, +const struct xen_processor_cppc *cppc_data) +{ +int ret =0 , cpuid; +struct processor_pminfo *pm_info;
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 633
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10
-0+ + cpuid =get_cpu_id (acpi_id); +if ( cpuid <0 || !cppc_data ) + { + ret = -EINVAL ; + goto out; + } +if ( cpufreq_verbose ) +printk ("Set CPU acpi_id(%d) cpuid(%d) CPPC State info:\n" , + acpi_id, cpuid);
Nit: %d isn't appropriate for a variable/parameter of type uint32_t. In turn I don't think the parameter needs to be of a fixed-width type; unsigned int will be quite fine there, I expect. See ./CODING_STYLE.
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 647
Quoted 13 lines
xen/drivers/cpufreq/cpufreq.c +13
-0+ pm_info = processor_pminfo[cpuid]; +/* Must already allocated in set_psd_pminfo */ +if ( !pm_info ) + { + ret = -EINVAL ; + goto out; + } + pm_info->cppc_data = *cppc_data; + +if ( cpufreq_verbose ) +print_CPPC (&pm_info->cppc_data); + + pm_info->init =XEN_CPPC_INIT ;
That is - whichever Dom0 invoked last will have data recorded, and the other effectively is discarded? I think a warning (perhaps a one-time one) is minimally needed to diagnose the case where one type of data replaces the other.
With this it also remains unclear to me how fallback to the legacy driver is intended to be working. Both taken together are a strong suggestion that important information on the model that is being implemented is missing from the description.
Quoted 10 lines
xen/include/acpi/cpufreq/processor_perf.h +0
-2@@ -27,8 +28,6 @@ struct processor_performance {struct xen_pct_register status_register;uint32_t state_count;struct xen_processor_px *states; - -uint32_t init; };struct processor_pminfo {
xen/include/acpi/cpufreq/processor_perf.h struct processor_pminfo { · line 42
Quoted 7 lines
xen/include/acpi/cpufreq/processor_perf.h +3
-0@@ -37,6 +36,9 @@ struct processor_pminfo {struct xen_psd_package domain_info;uint32_t shared_type;struct processor_performance perf; +struct xen_processor_cppc cppc_data; + +uint32_t init; };
This moving of the "init" field and the mechanical changes coming with it can likely be split out to a separate patch? Provided of course the movement is still wanted/needed with patch 1 re-worked or dropped.
Jan
RE: [PATCH v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC data
[Public]
Hi,
Quoted 22 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 10:28 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 v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC dataQuoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ pm_info = processor_pminfo[cpuid]; +/* Must already allocated in set_psd_pminfo */ +if ( !pm_info ) + { + ret = -EINVAL ; + goto out; + } + pm_info->cppc_data = *cppc_data; +
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 647
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4
-0+if ( cpufreq_verbose ) +print_CPPC (&pm_info->cppc_data); + + pm_info->init =XEN_CPPC_INIT ;That is - whichever Dom0 invoked last will have data recorded, and the other effectively is discarded? I think a warning (perhaps a one-time one) is minimally needed to diagnose the case where one type of data replaces the other.
In last v2 discussion, we are discussing that either set_px_pminfo or set_cppc_pminfo shall be invoked, which means either PX data is recorded, or CPPC data is recorded.
Current logic is that, cpufreq cmdline logic will set the XEN_PROCESSOR_PM_PX/CPPC
flag to reflect user preference, if user defines the fallback option, like "cpufreq=amd-cppc,xen", we will have both
XEN_PROCESSOR_PM_PX | XEN_PROCESSOR_PM_CPPC set in the beginning.
Later in cpufreq driver register logic, as only one register could be registered , if amd-cppc being registered successfully, it will clear the XEN_PROCESSOR_PM_PX flag bit.
But if it fails to register, fallback scheme kicks off, we will try the legacy P-states, in the mean time, clearing the XEN_PROCESSOR_PM_CPPC.
We are trying to make XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC exclusive
values after driver registration, which will ensure us that either set_px_pminfo or set_cppc_pminfo is taken in the runtime.
Quoted 27 lines
With this it also remains unclear to me how fallback to the legacy driver is intended to be working. Both taken together are a strong suggestion that important information on the model that is being implemented is missing from the description.
Quoted 10 lines
xen/include/acpi/cpufreq/processor_perf.h +0
-2@@ -27,8 +28,6 @@ struct processor_performance {struct xen_pct_register status_register;uint32_t state_count;struct xen_processor_px *states; - -uint32_t init; };struct processor_pminfo {xen/include/acpi/cpufreq/processor_perf.h struct processor_pminfo { · line 42
Quoted 7 lines
xen/include/acpi/cpufreq/processor_perf.h +3
-0@@ -37,6 +36,9 @@ struct processor_pminfo {struct xen_psd_package domain_info;uint32_t shared_type;struct processor_performance perf; +struct xen_processor_cppc cppc_data; + +uint32_t init; };This moving of the "init" field and the mechanical changes coming with it can likely be split out to a separate patch? Provided of course the movement is still wanted/needed with patch 1 re-worked or dropped.
Jan
Re: [PATCH v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC data
Quoted 24 lines · Zheng
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 10:28 PMQuoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ pm_info = processor_pminfo[cpuid]; +/* Must already allocated in set_psd_pminfo */ +if ( !pm_info ) + { + ret = -EINVAL ; + goto out; + } + pm_info->cppc_data = *cppc_data; +Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 647
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4
-0+if ( cpufreq_verbose ) +print_CPPC (&pm_info->cppc_data); + + pm_info->init =XEN_CPPC_INIT ;That is - whichever Dom0 invoked last will have data recorded, and the other effectively is discarded? I think a warning (perhaps a one-time one) is minimally needed to diagnose the case where one type of data replaces the other.
Quoted 12 lines
In last v2 discussion, we are discussing that either
set_px_pminfoorset_cppc_pminfoshall be invoked, which means either PX data is recorded, or CPPC data is recorded.
Current logic is that, cpufreq cmdline logic will set the XEN_PROCESSOR_PM_PX/CPPC
flag to reflect user preference, if user defines the fallback option, like "cpufreq=amd-cppc,xen", we will have both
XEN_PROCESSOR_PM_PX|XEN_PROCESSOR_PM_CPPCset in the beginning.
Later in cpufreq driver register logic, as only one register could be registered , if amd-cppc being registered successfully, it will clear theXEN_PROCESSOR_PM_PXflag bit.
But if it fails to register, fallback scheme kicks off, we will try the legacy P-states, in the mean time, clearing theXEN_PROCESSOR_PM_CPPC.
We are trying to makeXEN_PROCESSOR_PM_PXandXEN_PROCESSOR_PM_CPPCexclusive
values after driver registration, which will ensure us that eitherset_px_pminfoorset_cppc_pminfois taken in the runtime.
Yet you realize that this implies Dom0 to know what configuration Xen uses, in order to know which data to upload. The best approach might be to have Dom0 upload all data it has, with us merely ignoring what we can't make use of. The order of uploading (CPPC first or CPPC last) shouldn't matter. Then (and only then, and - ftaod - only when uploading of the "wrong" kind of data doesn't result in an error) things can go without warning.
Jan
RE: [PATCH v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC data
[Public]
Hi,
Quoted 52 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 3:54 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 v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC dataQuoted 14 lines · Zheng
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 10:28 PMQuoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ pm_info = processor_pminfo[cpuid]; +/* Must already allocated in set_psd_pminfo */ +if ( !pm_info ) + { + ret = -EINVAL ; + goto out; + } + pm_info->cppc_data = *cppc_data; +Quoted 8 lines
Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 647
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4
-0+if ( cpufreq_verbose ) +print_CPPC (&pm_info->cppc_data); + + pm_info->init =XEN_CPPC_INIT ;That is - whichever Dom0 invoked last will have data recorded, and the other effectively is discarded? I think a warning (perhaps a one-time one) is minimally needed to diagnose the case where one type of
data replaces the other.
Quoted 4 lines
Quoted 1 line
In last v2 discussion, we are discussing that either
set_px_pminfoorset_cppc_pminfoshall be invoked, which means either PX data is recorded, orCPPC data is recorded.
Quoted 3 lines
Current logic is that, cpufreq cmdline logic will set the XEN_PROCESSOR_PM_PX/CPPC flag to reflect user preference, if user defines the fallback option, like "cpufreq=amd-cppc,xen", we will have both
XEN_PROCESSOR_PM_PX|XEN_PROCESSOR_PM_CPPCset in the beginning.Quoted 2 lines
Later in cpufreq driver register logic, as only one register could be registered , if amd-cppc being registered successfully, it will clear the
XEN_PROCESSOR_PM_PXflag bit.Quoted 2 lines
But if it fails to register, fallback scheme kicks off, we will try the legacy P-states, in the mean time, clearing the
XEN_PROCESSOR_PM_CPPC.
Quoted 8 lines
Quoted 1 line
We are trying to make
XEN_PROCESSOR_PM_PXand
XEN_PROCESSOR_PM_CPPCQuoted 2 lines
exclusive values after driver registration, which will ensure us that either
set_px_pminfoorset_cppc_pminfois taken in the runtime.Yet you realize that this implies Dom0 to know what configuration Xen uses, in order to know which data to upload. The best approach might be to have Dom0 upload all data it has, with us merely ignoring what we can't make use of.
PLZ correct me if I understand you wrongly:
Right now, I was letting DOM0 upload all data it has, and in the Xen:
```
case XEN_PM_CPPC:
if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) )
{
ret = -EOPNOTSUPPED;
break;
}
ret = set_cppc_pminfo(op->u.set_pminfo.id,
&op->u.set_pminfo.u.cppc_data);
break;
case XEN_PM_PX:
if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
{
ret = -EOPNOTSUPPED;
break;
}
ret = set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);
break;
```I relied on flag XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX to choose which info we shall record.
Firstly, we shall not return -EOPNOTSUPPED error above there.
Quoted 3 lines
The order of uploading (CPPC first or CPPC last) shouldn't matter. Then (and only then, and - ftaod - only when uploading of the "wrong" kind of data doesn't result in an error) things can go without warning.
Then in
```
pm_info->init = XEN_CPPC_INIT;
ret = cpufreq_cpu_init(cpuid);
```We shall add warning here to clarify no fallback scheme to replace now, when ret is not zero.
Quoted 2 lines
Jan
Re: [PATCH v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC data
Quoted 87 lines · Zheng
[Public]
Hi,
Quoted 52 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 3:54 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 v3 02/15] xen/x86: introduce new sub-hypercall to propagate CPPC dataQuoted 14 lines · Zheng
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 10:28 PMQuoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ pm_info = processor_pminfo[cpuid]; +/* Must already allocated in set_psd_pminfo */ +if ( !pm_info ) + { + ret = -EINVAL ; + goto out; + } + pm_info->cppc_data = *cppc_data; +Quoted 8 lines
Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c int set_psd_pminfo(uint32_t acpi_id, uint32_t shared_type, · line 647
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4
-0+if ( cpufreq_verbose ) +print_CPPC (&pm_info->cppc_data); + + pm_info->init =XEN_CPPC_INIT ;That is - whichever Dom0 invoked last will have data recorded, and the other effectively is discarded? I think a warning (perhaps a one-time one) is minimally needed to diagnose the case where one type of
data replaces the other.
Quoted 4 lines
Quoted 1 line
In last v2 discussion, we are discussing that either
set_px_pminfoorset_cppc_pminfoshall be invoked, which means either PX data is recorded, orCPPC data is recorded.
Quoted 3 lines
Current logic is that, cpufreq cmdline logic will set the XEN_PROCESSOR_PM_PX/CPPC flag to reflect user preference, if user defines the fallback option, like "cpufreq=amd-cppc,xen", we will have both
XEN_PROCESSOR_PM_PX|XEN_PROCESSOR_PM_CPPCset in the beginning.Quoted 2 lines
Later in cpufreq driver register logic, as only one register could be registered , if amd-cppc being registered successfully, it will clear the
XEN_PROCESSOR_PM_PXflag bit.Quoted 2 lines
But if it fails to register, fallback scheme kicks off, we will try the legacy P-states, in the mean time, clearing the
XEN_PROCESSOR_PM_CPPC.Quoted 8 lines
Quoted 1 line
We are trying to make
XEN_PROCESSOR_PM_PXand
XEN_PROCESSOR_PM_CPPCQuoted 2 lines
exclusive values after driver registration, which will ensure us that either
set_px_pminfoorset_cppc_pminfois taken in the runtime.Yet you realize that this implies Dom0 to know what configuration Xen uses, in order to know which data to upload. The best approach might be to have Dom0 upload all data it has, with us merely ignoring what we can't make use of.
PLZ correct me if I understand you wrongly:
Right now, I was letting DOM0 upload all data it has, and in the Xen:``` case XEN_PM_CPPC: if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_CPPC) ) { ret = -EOPNOTSUPPED; break; } ret = set_cppc_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.cppc_data); break; case XEN_PM_PX: if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) ) { ret = -EOPNOTSUPPED; break; } ret = set_px_pminfo(op->u.set_pminfo.id, &op->u.set_pminfo.u.perf); break; ```
Quoted 3 lines
I relied on flag
XEN_PROCESSOR_PM_CPPCandXEN_PROCESSOR_PM_PXto choose which info we shall record.
Firstly, we shall not return-EOPNOTSUPPEDerror above there.
Yes.
Quoted 10 lines
Quoted 3 lines
The order of uploading (CPPC first or CPPC last) shouldn't matter. Then (and only then, and - ftaod - only when uploading of the "wrong" kind of data doesn't result in an error) things can go without warning.
Then in
``` pm_info->init = XEN_CPPC_INIT; ret = cpufreq_cpu_init(cpuid); ```We shall add warning here to clarify no fallback scheme to replace now, when ret is not zero.
Maybe. In the earlier reply I said with certain conditions fulfilled a warning may not be necessary. Yet perhaps initially having a warning there (maybe just for debug builds) may make sense.
Jan
PATCH v3 3/15 xen/cpufreq: refactor cmdline "cpufreq=xxx"
In reply to Penny ZhengThis commit includes the following modification:
- Introduce helper function cpufreq_cmdline_parse_xen and cpufreq_cmdline_parse_hwp to tidy the different parsing path
- Add helper cpufreq_opts_contain to ignore user redundant setting, like "cpufreq=hwp;hwp;xen"
- Doc refinement
---
v2 -> v3:
- new commit
--- docs/misc/xen-command-line.pandoc | 3 +- xen/drivers/cpufreq/cpufreq.c | 64 ++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 19 deletions(-)
docs/misc/xen-command-line.pandoc +2 -1
@@ -535,7 +535,8 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. processor to autonomously force physical package components into idle state. The default is enabled, but the option only applies when `hwp` is enabled. -There is also support for `;`-separated fallback options: +User could use `;`-separated options to support universal options which they +would like to try on any agnostic platform, *but* under priority order, like `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if unavailable. Note: The `verbose` suboption is handled globally. Setting it for either the primary or fallback option applies to both irrespective of where
xen/drivers/cpufreq/cpufreq.c +46 -18
77 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
Quoted 6 lines · Penny Zheng
This commit includes the following modification:
- Introduce helper functioncpufreq_cmdline_parse_xenandcpufreq_cmdline_parse_hwpto tidy the different parsing path
- Add helpercpufreq_opts_containto ignore user redundant setting, like "cpufreq=hwp;hwp;xen"
- Doc refinement
See my earlier comment as to wording to avoid. In descriptions and comments it would also be nice if function names could be followed by () (and array names then be followed by []) to clearly identify the nature of such identifiers.
docs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. · line 542
Quoted 12 lines
docs/misc/xen-command-line.pandoc +2
-1@@ -535,7 +535,8 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. processor to autonomously force physical package components into idle state. The default is enabled, but the option only applies when `hwp` is enabled. -There is also support for `;`-separated fallback options: +User could use `;`-separated options to support universal options which they +would like to try on any agnostic platform, *but* under priority order, like `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if unavailable. Note: The `verbose` suboption is handled globally. Setting it for either the primary or fallback option applies to both irrespective of where
What does "support" here mean? I fear I can't even suggest what else to use, as I don't follow what additional information you mean to add here. Is a change here really needed?
Quoted 17 lines
xen/drivers/cpufreq/cpufreq.c +11
-0@@ -71,6 +71,46 @@ 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 94
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10
-0+} + +static int __init cpufreq_cmdline_parse_xen (const char *arg,const char *end) +{ +int ret =0 ; + + xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_xen; + ret =0 ;
ret was already set to 0 by the initializer.
Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +8
-0+if ( arg[0 ] && arg[1 ] ) + ret =cpufreq_cmdline_parse (arg +1 , end); + +return ret; +} + +static int __init cpufreq_cmdline_parse_hwp (const char *arg,const char *end) +{
xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 112
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10
-0+int ret =0 ; + + xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp; +if ( arg[0 ] && arg[1 ] ) + ret =hwp_cmdline_parse (arg +1 , end); + +return ret; +}
For both of the helpers may I suggest s/parse/process/ or some such ("handle" might be another possible term to use), as themselves they don't do any parsing?
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Quoted 21 lines
xen/drivers/cpufreq/cpufreq.c +3
-13@@ -112,25 +152,13 @@ static int __init cf_check setup_cpufreq_option(const char *str)if ( cpufreq_xen_cnt ==ARRAY_SIZE (cpufreq_xen_opts) )return -E2BIG ; -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 ; -if ( arg[0 ] && arg[1 ] ) - ret =cpufreq_cmdline_parse (arg +1 , end); - } +if ( (choice >0 || !cmdline_strcmp (str,"xen" )) && + !cpufreq_opts_contain (CPUFREQ_xen) ) + ret =cpufreq_cmdline_parse_xen (arg, end); else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 && - !cmdline_strcmp (str,"hwp" ) ) - { - xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; - cpufreq_controller = FREQCTL_xen;
xen/drivers/cpufreq/cpufreq.c static int __init cf_check setup_cpufreq_option(const char *str) · line 163
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +3
-5- cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp; - ret =0 ; -if ( arg[0 ] && arg[1 ] ) - ret =hwp_cmdline_parse (arg +1 , end); - } + !cmdline_strcmp(str, "hwp") && + !cpufreq_opts_contain(CPUFREQ_hwp) ) + ret =cpufreq_cmdline_parse_hwp (arg, end); else ret = -EINVAL ;
Hmm, if I'm not mistaken the example "cpufreq=hwp;hwp;xen" would lead us to this -EINVAL then. That's not quite "ignore" as the description says.
Jan
RE: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
[Public]
Hi,
Quoted 19 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:01 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 v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"docs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported
Quoted 3 lines · Penny Zheng
docs/misc/xen-command-line.pandoc +0
-0@@ -535,7 +535,8 @@ choice of `dom0-kernel` is deprecated and not supportedby all Dom0 kernels.
Quoted 3 lines
docs/misc/xen-command-line.pandoc +0
-0processor to autonomously force physical package components into idle state. The default is enabled, but the option only applies when `hwp` is enabled.
Quoted 13 lines
Quoted 8 lines
docs/misc/xen-command-line.pandoc +3
-1-There is also support for `;`-separated fallback options: +User could use `;`-separated options to support universal options +which they would like to try on any agnostic platform, *but* under +priority order, like `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to
xenif unavailable. Note: Theverbosesuboption is handled globally. Setting it for either the primary or fallback option applies to both irrespective of whereWhat does "support" here mean? I fear I can't even suggest what else to use, as I don't follow what additional information you mean to add here. Is a change here really needed?
There are two changes I'd like to address:
1) ";" is not designed for fallback options anymore, like we discussed before, we would
like to support something like "cpufreq=hwp;amd-cppc;xen" for users to define all universal options
they would like to try.
2) Must under *priority* order. As in cpufreq_driver_init(), we are using loop to decide which driver to
try firstly. If user defines "cpufreq=xen;amd-cppc", which leads legacy P-state set before amd-cppc in cpufreq_xen_opts[], then in the loop, we will try to register legacy P-state firstly, once it gets registered successfully, we will not try to register amd-cppc at all.
Quoted 15 lines
Quoted 15 lines
xen/drivers/cpufreq/cpufreq.c +13
-0+if ( arg[0 ] && arg[1 ] ) + ret =cpufreq_cmdline_parse (arg +1 , end); + +return ret; +} + +static int __init cpufreq_cmdline_parse_hwp (const char *arg,const +char *end) { +int ret =0 ; + + xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp;
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 112
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5
-0+if ( arg[0 ] && arg[1 ] ) + ret =hwp_cmdline_parse (arg +1 , end); + +return ret; +}For both of the helpers may I suggest s/parse/process/ or some such ("handle" might be another possible term to use), as themselves they don't do any parsing?
Maybe I mis-understood the previous comment you said
```
> else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 &&
> ```
For the rest of this, I guess I'd prefer to see this in context. Also with
regard to the helper function's name.
```
I thought you suggested to introduce helper function to wrap the conditional codes...
Or may you were suggesting something like:
```
#ifdef CONFIG_INTEL
else if ( choice < 0 && !cmdline_strcmp(str, "hwp") )
{
xen_processor_pmbits |= XEN_PROCES
...
}
#endif
```Quoted 5 lines
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Jan
Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
Quoted 25 lines · Zheng
Quoted 12 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:01 PMdocs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported
Quoted 3 lines · Penny Zheng
docs/misc/xen-command-line.pandoc +0
-0@@ -535,7 +535,8 @@ choice of `dom0-kernel` is deprecated and not supportedby all Dom0 kernels.
Quoted 3 lines
docs/misc/xen-command-line.pandoc +0
-0processor to autonomously force physical package components into idle state. The default is enabled, but the option only applies when `hwp` is enabled.Quoted 12 lines
Quoted 8 lines
docs/misc/xen-command-line.pandoc +3
-1-There is also support for `;`-separated fallback options: +User could use `;`-separated options to support universal options +which they would like to try on any agnostic platform, *but* under +priority order, like `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to
xenif unavailable. Note: Theverbosesuboption is handled globally. Setting it for either the primary or fallback option applies to both irrespective of whereWhat does "support" here mean? I fear I can't even suggest what else to use, as I don't follow what additional information you mean to add here. Is a change here really needed?
Quoted 4 lines
There are two changes I'd like to address:
1) ";" is not designed for fallback options anymore, like we discussed before, we would like to support something like "cpufreq=hwp;amd-cppc;xen" for users to define all universal options they would like to try.
Why would the meaning of ; change? There's no difference between having a single fallback option from hwp, or two of them from amd-cppc.
Quoted 3 lines
2) Must under *priority* order. As in
cpufreq_driver_init(), we are using loop to decide which driver to
try firstly. If user defines "cpufreq=xen;amd-cppc", which leads legacy P-state set before amd-cppc in cpufreq_xen_opts[], then in the loop, we will try to register legacy P-state firstly, once it gets registered successfully, we will not try to register amd-cppc at all.
This in-order aspect also doesn't change.
Overall I fear I don't feel my question was answered.
Quoted 36 lines
Quoted 15 lines
Quoted 15 lines
xen/drivers/cpufreq/cpufreq.c +13
-0+if ( arg[0 ] && arg[1 ] ) + ret =cpufreq_cmdline_parse (arg +1 , end); + +return ret; +} + +static int __init cpufreq_cmdline_parse_hwp (const char *arg,const +char *end) { +int ret =0 ; + + xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp;Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 112
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5
-0+if ( arg[0 ] && arg[1 ] ) + ret =hwp_cmdline_parse (arg +1 , end); + +return ret; +}For both of the helpers may I suggest s/parse/process/ or some such ("handle" might be another possible term to use), as themselves they don't do any parsing?
Maybe I mis-understood the previous comment you said
``` > else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 && > ``` For the rest of this, I guess I'd prefer to see this in context. Also with regard to the helper function's name. ``` I thought you suggested to introduce helper function to wrap the conditional codes... Or may you were suggesting something like: ```
Quoted 8 lines
#ifdef CONFIG_INTEL
else if ( choice < 0 && !cmdline_strcmp(str, "hwp") )
{
xen_processor_pmbits |= XEN_PROCES
...
}
#endif
```Was this reply of yours misplaced? It doesn't fit with the part of my reply in context above. Or maybe I'm not understanding what you mean to say.
Quoted 2 lines
Quoted 2 lines
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Instead it feels as if this response of yours was to this part of my comment. Indeed iirc I was suggesting to introduce a helper function. Note, however, the singular here as well as in your response above.
Jan
RE: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
[Public]
Hi
Quoted 39 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6: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]>; [email protected]
Subject: Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"Quoted 5 lines · Zheng
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:01 PMOn 06.03.2025 09:39, Penny Zheng wrote:
Quoted 8 lines
Maybe I mis-understood the previous comment you said ```
> else if (IS_ENABLED(CONFIG_INTEL)&& choice < 0 &&
> ```For the rest of this, I guess I'd prefer to see this in context. Also with regard to the helper function's name.
```
I thought you suggested to introduce helper function to wrap the conditionalcodes...
Quoted 9 lines
Or may you were suggesting something like:
``` #ifdef CONFIG_INTEL else if ( choice < 0 && !cmdline_strcmp(str, "hwp") ) { xen_processor_pmbits |= XEN_PROCES ... } #endif ```Was this reply of yours misplaced? It doesn't fit with the part of my reply in context above. Or maybe I'm not understanding what you mean to say.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Instead it feels as if this response of yours was to this part of my comment. Indeed iirc I was suggesting to introduce a helper function. Note, however, the singular here as well as in your response above.
Correct if I understood wrongly, you are suggesting that we shall use one single helper function here to cover all scenarios, maybe as follows:
```
+static int __init handle_cpufreq_cmdline(const char *arg, const char *end,
+ enum cpufreq_xen_opt option)
+{
+ int ret;
+
+ 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_processor_pmbits |= XEN_PROCESSOR_PM_PX;
+ cpufreq_controller = FREQCTL_xen;
+ cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
+ switch ( option )
+ {
+ case CPUFREQ_hwp:
+ if ( arg[0] && arg[1] )
+ ret = hwp_cmdline_parse(arg + 1, end);
+ case CPUFREQ_xen:
+ if ( arg[0] && arg[1] )
+ ret = cpufreq_cmdline_parse(arg + 1, end);
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
```Quoted 1 line
Jan
Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
Quoted 73 lines · Zheng
[Public]
Hi
Quoted 39 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6: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]>; [email protected]
Subject: Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"Quoted 5 lines · Zheng
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:01 PMOn 06.03.2025 09:39, Penny Zheng wrote:
Quoted 8 lines
Maybe I mis-understood the previous comment you said ```
> else if (IS_ENABLED(CONFIG_INTEL)&& choice < 0 &&
> ```For the rest of this, I guess I'd prefer to see this in context. Also with regard to the helper function's name.
```
I thought you suggested to introduce helper function to wrap the conditionalcodes...
Quoted 9 lines
Or may you were suggesting something like:
``` #ifdef CONFIG_INTEL else if ( choice < 0 && !cmdline_strcmp(str, "hwp") ) { xen_processor_pmbits |= XEN_PROCES ... } #endif ```Was this reply of yours misplaced? It doesn't fit with the part of my reply in context above. Or maybe I'm not understanding what you mean to say.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Instead it feels as if this response of yours was to this part of my comment. Indeed iirc I was suggesting to introduce a helper function. Note, however, the singular here as well as in your response above.
Correct if I understood wrongly, you are suggesting that we shall use one single helper function here to cover all scenarios, maybe as follows:
```(quoted diff) +19
-0+static int __init handle_cpufreq_cmdline(const char *arg, const char *end, + enum cpufreq_xen_opt option) +{ + int ret; + + 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_processor_pmbits |= XEN_PROCESSOR_PM_PX; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = option; + switch ( option )
Review
Quoted 10 lines
(quoted diff) +10
-0+ { + case CPUFREQ_hwp: + if ( arg[0] && arg[1] ) + ret = hwp_cmdline_parse(arg + 1, end); + case CPUFREQ_xen: + if ( arg[0] && arg[1] ) + ret = cpufreq_cmdline_parse(arg + 1, end); + default: + ret = -EINVAL; + }
Apart from the switch() missing all break statements, the helper I was thinking of would end right before the switch(). The <xyz>_cmdline_parse() calls would remain at the call sites of the helper.
Jan
RE: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"
[Public]
Quoted 94 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, April 1, 2025 2:38 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 v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"Quoted 82 lines · Zheng
[Public]
Hi
Quoted 41 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6: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]>; [email protected]
Subject: Re: [PATCH v3 03/15] xen/cpufreq: refactor cmdline "cpufreq=xxx"Quoted 9 lines · Zheng
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:01 PMOn 06.03.2025 09:39, Penny Zheng wrote:
Maybe I mis-understood the previous comment you said ```
> else if (IS_ENABLED(CONFIG_INTEL)&& choice < 0 &&
> ```Quoted 5 lines
For the rest of this, I guess I'd prefer to see this in context. Also with regard to the helper function's name.
```
I thought you suggested to introduce helper function to wrap the conditionalcodes...
Quoted 9 lines
Or may you were suggesting something like:
``` #ifdef CONFIG_INTEL else if ( choice < 0 && !cmdline_strcmp(str, "hwp") ) { xen_processor_pmbits |= XEN_PROCES ... } #endif ```Was this reply of yours misplaced? It doesn't fit with the part of my reply in context above. Or maybe I'm not understanding what you mean to say.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
In the end I'm also not entirely convinced that we need these two almost identical helpers (with a 3rd likely appearing in a later patch).
Instead it feels as if this response of yours was to this part of my comment. Indeed iirc I was suggesting to introduce a helper function. Note, however, the singular here as well as in your response above.
Correct if I understood wrongly, you are suggesting that we shall use one single helper function here to cover all scenarios, maybe as follows:
```(quoted diff) +26
-0+static int __init handle_cpufreq_cmdline(const char *arg, const char *end, + enum cpufreq_xen_opt option) +{ + int ret; + + 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_processor_pmbits |= XEN_PROCESSOR_PM_PX; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = option; + switch ( option ) + { + case CPUFREQ_hwp: + if ( arg[0] && arg[1] ) + ret = hwp_cmdline_parse(arg + 1, end); + case CPUFREQ_xen: + if ( arg[0] && arg[1] )
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c unsigned int __initdata cpufreq_xen_cnt = 1; · line 99
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +4
-0+ ret =cpufreq_cmdline_parse (arg +1 , end); +default : + ret = -EINVAL ; + }Apart from the
switch()missing all break statements, the helper I was thinking of would end right before theswitch(). The <xyz>_cmdline_parse() calls would remain at the call sites of the helper.
Understood!
Quoted 1 line
Jan
PATCH v3 4/15 xen/cpufreq: move XEN_PROCESSOR_PM_xxx to internal header
In reply to Penny ZhengXEN_PROCESSOR_PM_xxx are used to set xen_processor_pmbits only, which is a Xen-internal variable only. Although PV Dom0 passed these bits in si->flags, they haven't been used anywhere.
So this commit moves XEN_PROCESSOR_PM_xxx back to internal header "acpi/cpufreq/processor_perf.h"
---
v2 -> v3:
- new commit
--- xen/arch/x86/pv/dom0_build.c | 1 - xen/arch/x86/setup.c | 1 + xen/common/domain.c | 1 + xen/include/acpi/cpufreq/processor_perf.h | 5 +++++ xen/include/public/platform.h | 5 ----- xen/include/public/xen.h | 1 - 6 files changed, 7 insertions(+), 7 deletions(-)
xen/arch/x86/pv/dom0_build.c +0 -1
@@ -886,7 +886,6 @@ static int __init dom0_construct(struct boot_info *bi, struct domain *d) si->flags =SIF_PRIVILEGED |SIF_INITDOMAIN ;if ( !vinitrd_start && initrd_len ) si->flags |=SIF_MOD_START_PFN ; - si->flags |=MASK_INSR (xen_processor_pmbits,SIF_PM_MASK ); si->pt_base = vpt_start; si->nr_pt_frames = nr_pt_pages; si->mfn_list = vphysmap_start;
xen/arch/x86/setup.c +1 -0
@@ -62,6 +62,7 @@#include <asm/prot-key.h> #include <asm/pv/domain.h> #include <asm/trampoline.h> +#include <acpi/cpufreq/cpufreq.h> /* opt_nosmp: If true, secondary processors are ignored. */ static bool __initdata opt_nosmp;
xen/common/domain.c +1 -0
@@ -43,6 +43,7 @@#include <xsm/xsm.h> #include <xen/trace.h> #include <asm/setup.h> +#include <acpi/cpufreq/cpufreq.h> #ifdef CONFIG_X86 #include <asm/guest.h>
xen/include/acpi/cpufreq/processor_perf.h +5 -0
@@ -5,6 +5,11 @@#include <public/sysctl.h> #include <xen/acpi.h> +/* ability bits */ +#define XEN_PROCESSOR_PM_CX 1 +#define XEN_PROCESSOR_PM_PX 2 +#define XEN_PROCESSOR_PM_TX 4 +#define XEN_CPPC_INIT 0x40000000U#define XEN_PX_INIT 0x80000000U
xen/include/public/platform.h +0 -5
@@ -353,11 +353,6 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XENPF_set_processor_pminfo 54 -/* ability bits */ -#define XEN_PROCESSOR_PM_CX 1 -#define XEN_PROCESSOR_PM_PX 2 -#define XEN_PROCESSOR_PM_TX 4 -/* cmd type */ #define XEN_PM_CX 0#define XEN_PM_PX 1
xen/include/public/xen.h +0 -1
@@ -877,7 +877,6 @@ typedef struct start_info start_info_t;#define SIF_MOD_START_PFN (1<<3)/* Is mod_start a PFN? */ #define SIF_VIRT_P2M_4TOOLS (1<<4)/* Do Xen tools understand a virt. mapped */ /* P->M making the 3 level tree obsolete? */ -#define SIF_PM_MASK (0xFF<<8)/* reserve 1 byte for xen-pm options */ /* * A multiboot module is a package containing modules very similar to a
Signature · 1 line
2.34.1
Re: [PATCH v3 04/15] xen/cpufreq: move XEN_PROCESSOR_PM_xxx to internal header
Quoted 3 lines · Penny Zheng
XEN_PROCESSOR_PM_xxxare used to setxen_processor_pmbitsonly, which is a Xen-internal variable only. Although PV Dom0 passed these bits insi->flags, they haven't been used anywhere.
Please be careful with "not used anywhere". See e.g.
https://xenbits.xen.org/gitweb/?p=legacy/linux-2.6.18-xen.git;a=blob;f=arch/i386/kernel/acpi/processor_extcntl_xen.c;h=eb6a53e9572c137da505a7d4970b1a5b7e1c522d;hb=HEAD#l193
Quoted 2 lines
So this commit moves
XEN_PROCESSOR_PM_xxxback to internal header "acpi/cpufreq/processor_perf.h"
Essentially you're again altering the stable public ABI in a way that's not acceptable.
Jan
RE: [PATCH v3 04/15] xen/cpufreq: move XEN_PROCESSOR_PM_xxx to internal header
[Public]
Hi
Quoted 22 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:12 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 v3 04/15] xen/cpufreq: moveXEN_PROCESSOR_PM_xxxto internal headerQuoted 3 lines · Penny Zheng
XEN_PROCESSOR_PM_xxxare used to setxen_processor_pmbitsonly, which is a Xen-internal variable only. Although PV Dom0 passed these bits insi->flags, they haven't been used anywhere.Please be careful with "not used anywhere". See e.g.
https://xenbits.xen.org/gitweb/?p=legacy/linux-2.6.18-
xen.git;a=blob;f=arch/i386/kernel/acpi/processor_extcntl_xen.c;h=eb6a53e9572c13 7da505a7d4970b1a5b7e1c522d;hb=HEAD#l193
Quoted 5 lines
Quoted 2 lines
So this commit moves
XEN_PROCESSOR_PM_xxxback to internal header "acpi/cpufreq/processor_perf.h"Essentially you're again altering the stable public ABI in a way that's not acceptable.
Understood...
I misunderstood the previous comment again...
I'll only move the new XEN_PROCESSOR_PM_CPPC into the internal header
Quoted 1 line
Jan
PATCH v3 5/15 xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
In reply to Penny ZhengUsers 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. Actual implmentation will be introduced in the following commits.
Xen is not expected to support both or mixed mode (CPPC & legacy PSS, _PCT, _PPC) operations, 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
--- docs/misc/xen-command-line.pandoc | 16 +++-- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/acpi.c | 12 +++- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 78 +++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 34 +++++++++- xen/arch/x86/platform_hypercall.c | 11 +++- xen/drivers/cpufreq/cpufreq.c | 17 +++++ xen/include/acpi/cpufreq/cpufreq.h | 4 ++ xen/include/acpi/cpufreq/processor_perf.h | 7 +- xen/include/public/sysctl.h | 1 + 10 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
docs/misc/xen-command-line.pandoc +10 -6
@@ -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,13 +534,17 @@ 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. User could use `;`-separated options to support universal options which they would like to try on any agnostic platform, *but* under priority order, like -`cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if -unavailable. Note: The `verbose` suboption is handled globally. Setting it -for either the primary or fallback option applies to both irrespective of where -it is specified. +`cpufreq=hwp;amd-cppc;xen,verbose`. This first tries `hwp` on Intel, or +`amd-cppc` on AMD, and it will fall back to `xen` if unavailable. Note: +The `verbose` suboption is handled globally. Setting it for either the +primary or fallback option applies to both irrespective of where it is +specified. Note: grub2 requires to escape or quote ';', so `"cpufreq=hwp;xen"` should be specified within double quotes inside grub.cfg. Refer to the grub2
xen/arch/x86/acpi/cpufreq/Makefile +1 -0
@@ -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 +11 -1
@@ -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,14 @@ 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; + +if (IS_ENABLED (CONFIG_AMD ) ) + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ; + +return ret; }
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +78 -0
78 lines not on this page · raw message
xen/arch/x86/acpi/cpufreq/cpufreq.c +33 -1
@@ -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\n" ); +break ; + } + +if ( ret != -ENODEV ) +break ; + }break ; } }
xen/arch/x86/platform_hypercall.c +10 -1
@@ -542,6 +542,7 @@ ret_t do_platform_op( ret = -ENOSYS ;break ; } +ASSERT (!(xen_processor_pmbits &XEN_PROCESSOR_PM_CPPC )); ret =set_px_pminfo (op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);break ;
@@ -572,7 +573,8 @@ ret_t do_platform_op(break ; }case XEN_PM_PSD : -if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) +if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX | +XEN_PROCESSOR_PM_CPPC )) ) { ret = -EOPNOTSUPP ;break ;
@@ -584,6 +586,13 @@ ret_t do_platform_op(break ;case XEN_PM_CPPC : +if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_CPPC ) ) + { + ret = -EOPNOTSUPP ; +break ; + } +ASSERT (!(xen_processor_pmbits &XEN_PROCESSOR_PM_PX )); + ret =set_cppc_pminfo (op->u.set_pminfo.id, &op->u.set_pminfo.u.cppc_data);break ;
xen/drivers/cpufreq/cpufreq.c +17 -0
@@ -111,6 +111,19 @@ static int __init cpufreq_cmdline_parse_hwp(const char *arg, const char *end)return ret; } +static int __init cpufreq_cmdline_parse_cppc (const char *arg,const char *end) +{ +int ret =0 ; + + xen_processor_pmbits |=XEN_PROCESSOR_PM_CPPC ; + cpufreq_controller = FREQCTL_xen; + cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_amd_cppc; +if ( arg[0 ] && arg[1 ] ) + ret =amd_cppc_cmdline_parse (arg +1 , end); + +return ret; +} + static int __init cf_check setup_cpufreq_option(const char *str) {const char *arg =strpbrk (str,",:;" );
@@ -159,6 +172,10 @@ static int __init cf_check setup_cpufreq_option(const char *str) !cmdline_strcmp(str, "hwp") && !cpufreq_opts_contain(CPUFREQ_hwp) ) ret =cpufreq_cmdline_parse_hwp (arg, end); + else if ( IS_ENABLED(CONFIG_AMD) && choice < 0 && + !cmdline_strcmp(str, "amd-cppc") && + !cpufreq_opts_contain(CPUFREQ_amd_cppc) ) + ret = cpufreq_cmdline_parse_cppc(arg, end); else ret = -EINVAL ;
xen/include/acpi/cpufreq/cpufreq.h +4 -0
@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];extern unsigned int cpufreq_xen_cnt;
@@ -267,4 +268,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 +4 -3
@@ -6,9 +6,10 @@#include <xen/acpi.h> /* ability bits */ -#define XEN_PROCESSOR_PM_CX 1 -#define XEN_PROCESSOR_PM_PX 2 -#define XEN_PROCESSOR_PM_TX 4 +#define XEN_PROCESSOR_PM_CX 1 +#define XEN_PROCESSOR_PM_PX 2 +#define XEN_PROCESSOR_PM_TX 4 +#define XEN_PROCESSOR_PM_CPPC 8#define XEN_CPPC_INIT 0x40000000U#define XEN_PX_INIT 0x80000000U
xen/include/public/sysctl.h +1 -0
@@ -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
Re: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 525
Quoted 13 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/acpi.c +8
-1@@ -514,5 +515,14 @@ 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; + +if (IS_ENABLED (CONFIG_AMD ) ) + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ;
What's the purpose of the if() here?
Quoted 18 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +13
-1@@ -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 ();
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 186
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10
-0+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\n" );
What about Hygon?
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];
I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Jan
RE: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
[Public]
Hi,
Quoted 15 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:26 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 v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdlineQuoted 2 lines · Penny Zheng
(quoted diff) +0
-0@@ -514,5 +515,14 @@ acpi_cpufreq_driver = {
Quoted 12 lines
xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 525
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/acpi.c +8
-1int __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; + +if (IS_ENABLED (CONFIG_AMD ) ) + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ;What's the purpose of the
if()here?
After cpufreq driver properly registered, I'd like XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC
being exclusive value to represent the actual underlying registered driver.
As users could define something like "cpufreq=amd-cppc,xen", which implies both XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC got set in parsing logic. With amd-cppc failing to register, we are falling back to legacy ones. Then XEN_PROCESSOR_PM_CPPC needs to clear.
Quoted 35 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,7 +161,35 @@ static int __init cf_checkcpufreq_driver_init (void ) case X86_VENDOR_AMD:case X86_VENDOR_HYGON : - ret = IS_ENABLED(CONFIG_AMD) ? powernow_register_driver() : -ENODEV;
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+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 ;xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void)
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10
-0+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\n");What about Hygon?
Quoted 13 lines
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Hmmm, but the CPUFREQ_hwp and CPUFREQ_amd_cppc are incompatible options.
I thought cpufreq_xen_opts[] shall reflect available choices on their hardware. Even if users define "cpufreq=hwp;amd-cppc;xen", in Intel platform, cpufreq_xen_opts[] shall contain CPUFREQ_hwp and CPUFREQ_xen, while in amd platform, cpufreq_xen_opts[] shall contain CPUFREQ_amd_cppc and CPUFREQ_xen
Quoted 1 line
Jan
Re: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
Quoted 20 lines · Zheng
Quoted 7 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:26 PMQuoted 2 lines · Penny Zheng
(quoted diff) +0
-0@@ -514,5 +515,14 @@ acpi_cpufreq_driver = {Quoted 12 lines
xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 525
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/acpi.c +8
-1int __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; + +if (IS_ENABLED (CONFIG_AMD ) ) + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ;What's the purpose of the
if()here?
Quoted 4 lines
After cpufreq driver properly registered, I'd like
XEN_PROCESSOR_PM_PXandXEN_PROCESSOR_PM_CPPC
being exclusive value to represent the actual underlying registered driver.
As users could define something like "cpufreq=amd-cppc,xen", which implies bothXEN_PROCESSOR_PM_PXandXEN_PROCESSOR_PM_CPPCgot set in parsing logic. With amd-cppc failing to register, we are falling back to legacy ones. ThenXEN_PROCESSOR_PM_CPPCneeds to clear.
Looks like you try to explain the &= when my question was about the if(). I understand the purpose of the &=. What I don't understand is why it needs to be conditional.
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none,Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Quoted 5 lines
Hmmm, but the
CPUFREQ_hwpandCPUFREQ_amd_cppcare incompatible options.
I thought cpufreq_xen_opts[] shall reflect available choices on their hardware. Even if users define "cpufreq=hwp;amd-cppc;xen", in Intel platform, cpufreq_xen_opts[] shall containCPUFREQ_hwpandCPUFREQ_xen, while in amd platform, cpufreq_xen_opts[] shall containCPUFREQ_amd_cppcandCPUFREQ_xen
Maybe I misread the code, but the impression I got was that "cpufreq=hwp;amd-cppc;xen" would populate 3 slots of the array (with one of "hwp" and "amd-cppc" necessarily not working, leading to the next one to be tried).
Jan
RE: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
[Public]
Hi,
Quoted 36 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6:55 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 v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdlineQuoted 20 lines · Zheng
Quoted 7 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:26 PMQuoted 2 lines · Penny Zheng
(quoted diff) +0
-0@@ -514,5 +515,14 @@ acpi_cpufreq_driver = {Quoted 12 lines
xen/arch/x86/acpi/cpufreq/acpi.c acpi_cpufreq_driver = { · line 525
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/acpi.c +8
-1int __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; + +if (IS_ENABLED (CONFIG_AMD ) ) + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ;What's the purpose of the
if()here?Quoted 2 lines
After cpufreq driver properly registered, I'd like
XEN_PROCESSOR_PM_PXandXEN_PROCESSOR_PM_CPPCbeing exclusive value to represent theactual underlying registered driver.
Quoted 9 lines
Quoted 2 lines
As users could define something like "cpufreq=amd-cppc,xen", which implies both
XEN_PROCESSOR_PM_PXandXEN_PROCESSOR_PM_CPPCgot set in parsing logic. With amd-cppc failing to register, we are falling back to legacy ones. Then
XEN_PROCESSOR_PM_CPPCneeds to clear.Looks like you try to explain the &= when my question was about the
if(). I understand the purpose of the &=. What I don't understand is why it needs to be conditional.
Oh, I got your concern, and I'll remove.
Quoted 16 lines
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none,Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Quoted 1 line
Hmmm, but the
CPUFREQ_hwpandCPUFREQ_amd_cppcare incompatibleoptions.
Quoted 8 lines
Quoted 5 lines
I thought cpufreq_xen_opts[] shall reflect available choices on their hardware. Even if users define "cpufreq=hwp;amd-cppc;xen", in Intel platform, cpufreq_xen_opts[] shall contain
CPUFREQ_hwpandCPUFREQ_xen, while in amd platform, cpufreq_xen_opts[] shall containCPUFREQ_amd_cppcandCPUFREQ_xenMaybe I misread the code, but the impression I got was that "cpufreq=hwp;amd- cppc;xen"
My bad. In my platform, I haven't enabled the CONFIG_INTEL. I previously assumed that CONFIG_INTEL and CONFIG_AMD are incompatible options, which leads to the following code
```
else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 &&
!cmdline_strcmp(str, "hwp") )
{
xen_processor_pmbits |= XEN_PROCESSOR_PM_PX;
cpufreq_controller = FREQCTL_xen;
```shall not be working in AMD platform...
May I ask why not make them incompatible pair? I assumed it each wraps vendor-specific feature, like vmx vs svm...
Quoted 4 lines
would populate 3 slots of the array (with one of "hwp" and "amd-cppc" necessarily not working, leading to the next one to be tried).
Jan
Re: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
Quoted 44 lines · Zheng
Quoted 26 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6:55 PMQuoted 19 lines · Zheng
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:26 PMOn 06.03.2025 09:39, Penny Zheng wrote:
Quoted 13 lines
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Quoted 1 line
Hmmm, but the
CPUFREQ_hwpandCPUFREQ_amd_cppcare incompatibleoptions.
Quoted 8 lines
Quoted 5 lines
I thought cpufreq_xen_opts[] shall reflect available choices on their hardware. Even if users define "cpufreq=hwp;amd-cppc;xen", in Intel platform, cpufreq_xen_opts[] shall contain
CPUFREQ_hwpandCPUFREQ_xen, while in amd platform, cpufreq_xen_opts[] shall containCPUFREQ_amd_cppcandCPUFREQ_xenMaybe I misread the code, but the impression I got was that "cpufreq=hwp;amd- cppc;xen"
My bad. In my platform, I haven't enabled the
CONFIG_INTEL. I previously assumed thatCONFIG_INTELandCONFIG_AMDare incompatible options, which leads to the following code``` else if ( IS_ENABLED(CONFIG_INTEL) && choice < 0 && !cmdline_strcmp(str, "hwp") ) { xen_processor_pmbits |= XEN_PROCESSOR_PM_PX; cpufreq_controller = FREQCTL_xen; ```
Quoted 2 lines
shall not be working in AMD platform...
May I ask why not make them incompatible pair? I assumed it each wraps vendor-specific feature, like vmx vs svm...
I'm sorry to say this, but that seems like a pretty odd question to ask. Distros quite clearly want to build one single hypervisor which can be used on both Intel and AMD hardware. CONFIG_* are build-time constants after all, not runtime values. We use them in if() where possible (instead of in #if / #ifdef) simply to expose as much code as possible to at least syntax and alike checking by the compiler, irrespective of configuration used by a particular individual. This way we limit the risk of bit-rotting and unexpected build failures at least some.
Jan
RE: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
[Public]
Hi,
Quoted 60 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, March 27, 2025 3:48 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 v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdlineQuoted 39 lines · Zheng
Quoted 26 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, March 26, 2025 6:55 PMQuoted 19 lines · Zheng
Quoted 5 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:26 PMOn 06.03.2025 09:39, Penny Zheng wrote:
Quoted 13 lines
xen/include/acpi/cpufreq/cpufreq.h enum cpufreq_xen_opt { · line 33
Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +1
-0@@ -28,6 +28,7 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, };extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ];I'm pretty sure I pointed out before that this array needs to grow, now that you add a 3rd kind of handling.
Quoted 1 line
Hmmm, but the
CPUFREQ_hwpandCPUFREQ_amd_cppcare incompatibleoptions.
Quoted 8 lines
Quoted 5 lines
I thought cpufreq_xen_opts[] shall reflect available choices on their hardware. Even if users define "cpufreq=hwp;amd-cppc;xen", in Intel platform, cpufreq_xen_opts[] shall contain
CPUFREQ_hwpandCPUFREQ_xen, while in amd platform, cpufreq_xen_opts[] shall containCPUFREQ_amd_cppcandCPUFREQ_xenMaybe I misread the code, but the impression I got was that "cpufreq=hwp;amd- cppc;xen"
My bad. In my platform, I haven't enabled the
CONFIG_INTEL. I previously assumed thatCONFIG_INTELandCONFIG_AMDare incompatible options, which leads to the following code ``` else if (IS_ENABLED(CONFIG_INTEL)&& choice < 0 &&Quoted 6 lines
!cmdline_strcmp(str, "hwp") ) { xen_processor_pmbits |= XEN_PROCESSOR_PM_PX; cpufreq_controller = FREQCTL_xen;```
shall not be working in AMD platform...
May I ask why not make them incompatible pair? I assumed it each wrapsvendor-specific feature, like vmx vs svm...
Quoted 8 lines
I'm sorry to say this, but that seems like a pretty odd question to ask. Distros quite clearly want to build one single hypervisor which can be used on both Intel and AMD hardware. CONFIG_* are build-time constants after all, not runtime values. We use them in
if()where possible (instead of in #if / #ifdef) simply to expose as much code as possible to at least syntax and alike checking by the compiler, irrespective of configuration used by a particular individual. This way we limit the risk of bit-rotting and unexpected build failures at least some.
Thanks for the detailed explanation, understood!
Quoted 1 line
Jan
Re: [PATCH v3 05/15] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline
In reply to Penny Zhengxen/arch/x86/acpi/cpufreq/amd-cppc.c line 58
Quoted 5 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +5
-0+static const struct cpufreq_driver __initconst_cf_clobber +amd_cppc_cpufreq_driver = +{ + .name =XEN_AMD_CPPC_DRIVER_NAME , +};
Because of the hook pointers not being set right here, ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c line 72
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +13
-0+int __init amd_cppc_register_driver (void ) +{ +int ret; + +if ( !cpu_has_cppc ) + { + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ; +return -ENODEV ; + } + + ret =cpufreq_register_driver (&amd_cppc_cpufreq_driver); +if ( ret ) +return ret;
... this - afaict - will fail up until patch 09. This may want mentioning in the description here. (Initially I thought you'd leave NULL derefs around for several patches, until I checked cpufreq_register_driver().)
Jan
PATCH v3 6/15 xen/cpufreq: disable px statistic info in amd-cppc mode
In reply to Penny ZhengBypass cnstruction and deconstruction for px statistic info( cpufreq_statistic_init and cpufreq_statistic_exit) in cpufreq CPPC mode.
---
v2 -> v3:
- new commit
--- xen/drivers/cpufreq/utility.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/drivers/cpufreq/utility.c +7 -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);
@@ -147,8 +150,12 @@ int cpufreq_statistic_init(unsigned int cpu)void cpufreq_statistic_exit (unsigned int cpu) {struct pm_px *pxpt; +const struct processor_pminfo *pmpt = processor_pminfo[cpu];spinlock_t *cpufreq_statistic_lock = &per_cpu (cpufreq_statistic_lock, cpu); +if ( !(pmpt->init &XEN_PX_INIT ) ) +return ; +spin_lock (cpufreq_statistic_lock); pxpt =per_cpu (cpufreq_statistic_data, cpu);
Signature · 1 line
2.34.1
Re: [PATCH v3 06/15] xen/cpufreq: disable px statistic info in amd-cppc mode
Quoted 3 lines · Penny Zheng
Bypass cnstruction and deconstruction for px statistic
info( cpufreq_statistic_init and cpufreq_statistic_exit)in cpufreq CPPC mode.
You say what you do, but not why.
xen/drivers/cpufreq/utility.c int cpufreq_statistic_init(unsigned int cpu) · line 102
Quoted 8 lines
xen/drivers/cpufreq/utility.c +2
-0@@ -98,6 +98,9 @@ int cpufreq_statistic_init(unsigned int cpu)if ( !pmpt )return -EINVAL ; +if ( !(pmpt->init &XEN_PX_INIT ) ) +return 0 ;
I understand this is needed if statistics really are of no interest for this driver (which needs to be clarified in the description). However, ...
xen/drivers/cpufreq/utility.c int cpufreq_statistic_init(unsigned int cpu) · line 161
Quoted 13 lines
xen/drivers/cpufreq/utility.c +4
-0@@ -147,8 +150,12 @@ int cpufreq_statistic_init(unsigned int cpu)void cpufreq_statistic_exit (unsigned int cpu) {struct pm_px *pxpt; +const struct processor_pminfo *pmpt = processor_pminfo[cpu];spinlock_t *cpufreq_statistic_lock = &per_cpu (cpufreq_statistic_lock, cpu); +if ( !(pmpt->init &XEN_PX_INIT ) ) +return ; +spin_lock (cpufreq_statistic_lock); pxpt =per_cpu (cpufreq_statistic_data, cpu);
... why's this needed, when below here there already is:
if (!pxpt) {
spin_unlock(cpufreq_statistic_lock);
return;
}?
Jan
PATCH v3 7/15 xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
In reply to Penny ZhengThis commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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
---
v2 -> v3:
- new commit
--- xen/arch/x86/cpu/amd.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
xen/arch/x86/cpu/amd.c +20 -7
@@ -572,12 +572,24 @@ static void amd_get_topology(struct cpuinfo_x86 *c) : c->cpu_core_id); } +static uint64_t amd_parse_freq (const struct cpuinfo_x86 *c,uint64_t value) +{ +ASSERT (c->x86 <=0x1A ); + +if (c->x86 <0x17 ) +return (((value &0x3f ) +0x10 ) *100 ) >> ((value >>6 ) &7 ); +else if (c->x86 <=0x19 ) +return ((value &0xff ) *25 *8 ) / ((value >>8 ) &0x3f ); +else +return (value &0xfff ) *5 ; +} +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 ;
@@ -658,19 +670,20 @@ 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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, 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, lo),amd_parse_freq (c, 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, lo)); } void cf_check early_init_amd(struct cpuinfo_x86 *c)
Signature · 1 line
2.34.1
Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
Quoted 4 lines · Penny Zheng
This commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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:
Why 1Ah+? In the code you correctly limit to just 1Ah.
Quoted 7 lines
xen/arch/x86/cpu/amd.c +1
-0@@ -572,12 +572,24 @@ static void amd_get_topology(struct cpuinfo_x86 *c) : c->cpu_core_id); } +static uint64_t amd_parse_freq (const struct cpuinfo_x86 *c,uint64_t value)
xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 585
Quoted 10 lines
xen/arch/x86/cpu/amd.c +10
-0+{ +ASSERT (c->x86 <=0x1A ); + +if (c->x86 <0x17 ) +return (((value &0x3f ) +0x10 ) *100 ) >> ((value >>6 ) &7 ); +else if (c->x86 <=0x19 ) +return ((value &0xff ) *25 *8 ) / ((value >>8 ) &0x3f ); +else +return (value &0xfff ) *5 ; +}
Could I talk you into omitting the unnecessary "else" in cases like this one? (This may also make sense to express as switch().)
Quoted 4 lines
xen/arch/x86/cpu/amd.c +0
-0@@ -658,19 +670,20 @@ void amd_log_freq(const struct cpuinfo_x86 *c)if (!(lo >>63 ))return ;
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 679
Quoted 10 lines
xen/arch/x86/cpu/amd.c +3
-3-#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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, hi));
I fear Misra won't like multiple function calls to evaluate the parameters to pass to another function. Iirc smp_process_id() has special exception, so that's okay here. This may be possible to alleviate by marking the new helper pure or even const (see gcc doc as to caveats with passing pointers to const functions). Cc-ing Nicola for possible clarification or correction.
Jan
Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Penny Zheng
This commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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 24 lines
Quoted 7 lines
xen/arch/x86/cpu/amd.c +0
-1@@ -658,19 +670,20 @@ 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 ) \xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 681
Quoted 10 lines
xen/arch/x86/cpu/amd.c +3
-2- : (((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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, hi));I fear Misra won't like multiple function calls to evaluate the parameters to pass to another function. Iirc
smp_process_id()has special exception, so that's okay here. This may be possible to alleviate by marking the new helper pure or even const (see gcc doc as to caveats with passing pointers to const functions). Cc-ing Nicola for possible clarification or correction.
Quoted 1 line
Jan
Yes, it would help. Currently there is only a property for smp_processor_id(), though there has been some discussion in the past about adding a formal deviation. Not a big problem either way since currently the rule is non-blocking, but definitely an attribute would help any future work on making that clean.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
RE: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
In reply to Jan Beulich[Public]
Hi,
Quoted 25 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:48 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]; Nicola Vetrini <[email protected]>
Subject: Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUsQuoted 5 lines · Penny Zheng
This commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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:Why 1Ah+? In the code you correctly limit to just 1Ah.
Quoted 6 lines
xen/arch/x86/cpu/amd.c +0
-0@@ -572,12 +572,24 @@ static void amd_get_topology(struct cpuinfo_x86 *c) : c->cpu_core_id); }
Quoted 15 lines
xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 585
Quoted 11 lines
xen/arch/x86/cpu/amd.c +11
-0+static uint64_t amd_parse_freq (const struct cpuinfo_x86 *c,uint64_t +value) { +ASSERT (c->x86 <=0x1A ); + +if (c->x86 <0x17 ) +return (((value &0x3f ) +0x10 ) *100 ) >> ((value >>6 ) &7 ); +else if (c->x86 <=0x19 ) +return ((value &0xff ) *25 *8 ) / ((value >>8 ) &0x3f ); +else +return (value &0xfff ) *5 ; +}Could I talk you into omitting the unnecessary "else" in cases like this one? (This may also make sense to express as
switch().)
Sorry, bad habit... will change it to switch
Quoted 16 lines
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 661
Quoted 5 lines
xen/arch/x86/cpu/amd.c +0
-1@@ -658,19 +670,20 @@ 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) \
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 679
Quoted 9 lines
xen/arch/x86/cpu/amd.c +3
-2- : (((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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, hi));
Quoted 6 lines
I fear Misra won't like multiple function calls to evaluate the parameters to pass to another function. Iirc
smp_process_id()has special exception, so that's okay here. This may be possible to alleviate by marking the new helper pure or even const (see gcc doc as to caveats with passing pointers to const functions). Cc-ing Nicola for possible clarification or correction.
Maybe we shall declare the function __pure. Having checked the gcc doc, ``
a function that has pointer arguments must not be declared const ``
Otherwise we store the "c->x86" value to avoid using the pointer
Quoted 1 line
Jan
Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
Quoted 70 lines · Zheng
[Public]
Hi,
Quoted 25 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:48 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]; Nicola Vetrini <[email protected]>
Subject: Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUsQuoted 5 lines · Penny Zheng
This commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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:Why 1Ah+? In the code you correctly limit to just 1Ah.
Quoted 6 lines
xen/arch/x86/cpu/amd.c +0
-0@@ -572,12 +572,24 @@ static void amd_get_topology(struct cpuinfo_x86 *c) : c->cpu_core_id); }Quoted 15 lines
xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 585
Quoted 11 lines
xen/arch/x86/cpu/amd.c +11
-0+static uint64_t amd_parse_freq (const struct cpuinfo_x86 *c,uint64_t +value) { +ASSERT (c->x86 <=0x1A ); + +if (c->x86 <0x17 ) +return (((value &0x3f ) +0x10 ) *100 ) >> ((value >>6 ) &7 ); +else if (c->x86 <=0x19 ) +return ((value &0xff ) *25 *8 ) / ((value >>8 ) &0x3f ); +else +return (value &0xfff ) *5 ; +}Could I talk you into omitting the unnecessary "else" in cases like this one? (This may also make sense to express as
switch().)Sorry, bad habit... will change it to switch
Quoted 16 lines
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 661
Quoted 5 lines
xen/arch/x86/cpu/amd.c +0
-1@@ -658,19 +670,20 @@ 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) \
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 679
Quoted 9 lines
xen/arch/x86/cpu/amd.c +3
-2- : (((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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, hi));Quoted 6 lines
I fear Misra won't like multiple function calls to evaluate the parameters to pass to another function. Iirc
smp_process_id()has special exception, so that's okay here. This may be possible to alleviate by marking the new helper pure or even const (see gcc doc as to caveats with passing pointers to const functions). Cc-ing Nicola for possible clarification or correction.
Quoted 6 lines
Maybe we shall declare the function
__pure. Having checked the gcc doc, ``
a function that has pointer arguments must not be declared const ``
Otherwise we store the "c->x86" value to avoid using the pointer
Either way could work. ECLAIR will automatically pick up __attribute__((pure)) or __attribute__((const)) from the declaration. Maybe it could be const, as from a cursory look I don't think the gcc restriction on pointer arguments applies, as the pointee is not modified between successive calls, but I might be mistaken.
Quoted 1 line
Quoted 1 line
Jan
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH v3 07/15] xen/cpufreq: fix core frequency calculation for AMD Family 1Ah CPUs
Quoted 72 lines · Nicola Vetrini
Quoted 65 lines · Zheng
Quoted 19 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:48 PMQuoted 5 lines · Penny Zheng
This commit fixes core frequency calculation for AMD Family 1Ah CPUs, 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:Why 1Ah+? In the code you correctly limit to just 1Ah.
Quoted 6 lines
xen/arch/x86/cpu/amd.c +0
-0@@ -572,12 +572,24 @@ static void amd_get_topology(struct cpuinfo_x86 *c) : c->cpu_core_id); }Quoted 16 lines
xen/arch/x86/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 585
Quoted 11 lines
xen/arch/x86/cpu/amd.c +11
-0+static uint64_t amd_parse_freq (const struct cpuinfo_x86 *c,uint64_t +value) { +ASSERT (c->x86 <=0x1A ); + +if (c->x86 <0x17 ) +return (((value &0x3f ) +0x10 ) *100 ) >> ((value >>6 ) &7 ); +else if (c->x86 <=0x19 ) +return ((value &0xff ) *25 *8 ) / ((value >>8 ) &0x3f ); +else +return (value &0xfff ) *5 ; +}Could I talk you into omitting the unnecessary "else" in cases like this one?
(This may also make sense to express asswitch().)Sorry, bad habit... will change it to switch
Quoted 16 lines
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 661
Quoted 5 lines
xen/arch/x86/cpu/amd.c +0
-1@@ -658,19 +670,20 @@ 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) \
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 679
Quoted 9 lines
xen/arch/x86/cpu/amd.c +3
-2- : (((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, val), +amd_parse_freq (c, lo),amd_parse_freq (c, hi));Quoted 10 lines
I fear Misra won't like multiple function calls to evaluate the parameters to pass to
another function. Iircsmp_process_id()has special exception, so that's okay here.
This may be possible to alleviate by marking the new helper pure or even const
(see gcc doc as to caveats with passing pointers to const functions). Cc-ing Nicola
for possible clarification or correction.Quoted 5 lines
Maybe we shall declare the function
__pure. Having checked the gcc doc, ``
a function that has pointer arguments must not be declared const ``
Otherwise we store the "c->x86" value to avoid using the pointer
Quoted 5 lines
Either way could work. ECLAIR will automatically pick up __attribute__((pure)) or __attribute__((const)) from the declaration. Maybe it could be const, as from a cursory look I don't think the gcc restriction on pointer arguments applies, as the pointee is not modified between successive calls, but I might be mistaken.
Indeed this matches my reading of it. Yet things are somewhat delicate here, so I like to always leave room for being proven wrong.
Jan
PATCH v3 8/15 xen/amd: export processor max frequency value
In reply to Penny ZhengWhen _CPC table could not provide processor frequency range values for Xen governor, we need to read processor max frequency as anchor point.
For AMD processors, we export max frequency value from amd_log_freq()
---
v1 -> v2:
- new commit
---
xen/amd: export processor max frequency value
When _CPC table could not provide processor frequency range values for Xen governor, we need to read processor max frequency as anchor point.
For AMD processors, we export max frequency value from amd_log_freq()
---
v1 -> v2:
- new commit
---
v2 -> v3:
- Replace per_cpu with this_cpu
- Add amd_ prefix for AMD-only variable
--- xen/arch/x86/cpu/amd.c | 10 +++++++++- xen/arch/x86/include/asm/amd.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/cpu/amd.c +9 -1
@@ -56,6 +56,8 @@ bool __initdata amd_virt_spec_ctrl;static bool __read_mostly fam17_c6_disabled; +DEFINE_PER_CPU_READ_MOSTLY (uint64_t, amd_max_freq_mhz); +static inline int rdmsr_amd_safe (unsigned int msr,unsigned int *lo,unsigned int *hi) {
@@ -681,9 +683,15 @@ void amd_log_freq(const struct cpuinfo_x86 *c)printk ("CPU%u: %lu ... %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo),amd_parse_freq (c, hi)); - else + else {printk ("CPU%u: %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo)); +return ; + } + +/* Store max frequency for amd-cppc cpufreq driver */ +if (hi >>63 ) +this_cpu (amd_max_freq_mhz) =amd_parse_freq (c, hi); } void cf_check early_init_amd(struct cpuinfo_x86 *c)
xen/arch/x86/include/asm/amd.h +1 -0
@@ -174,4 +174,5 @@ bool amd_setup_legacy_ssbd(void);void amd_set_legacy_ssbd (bool enable);void amd_set_cpuid_user_dis (bool enable); +DECLARE_PER_CPU (uint64_t, amd_max_freq_mhz);#endif /* __AMD_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v3 08/15] xen/amd: export processor max frequency value
Quoted 16 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +2
-1@@ -56,6 +56,8 @@ bool __initdata amd_virt_spec_ctrl;static bool __read_mostly fam17_c6_disabled; +DEFINE_PER_CPU_READ_MOSTLY (uint64_t, amd_max_freq_mhz); +static inline int rdmsr_amd_safe (unsigned int msr,unsigned int *lo,unsigned int *hi) {@@ -681,9 +683,15 @@ void amd_log_freq(const struct cpuinfo_x86 *c)printk ("CPU%u: %lu ... %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo),amd_parse_freq (c, hi)); - else
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 695
Quoted 10 lines
xen/arch/x86/cpu/amd.c +7
-0+else {printk ("CPU%u: %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo)); +return ; + } + +/* Store max frequency for amd-cppc cpufreq driver */ +if (hi >>63 ) +this_cpu (amd_max_freq_mhz) =amd_parse_freq (c, hi); }
As before - typically only the BSP will make it here, due to the conditional at the top of the function. IOW you'll observe zeros in the per-CPU data for all other CPUs.
xen/arch/x86/include/asm/amd.h bool amd_setup_legacy_ssbd(void); · line 178
Quoted 8 lines
xen/arch/x86/include/asm/amd.h +1
-0@@ -174,4 +174,5 @@ bool amd_setup_legacy_ssbd(void);void amd_set_legacy_ssbd (bool enable);void amd_set_cpuid_user_dis (bool enable); +DECLARE_PER_CPU (uint64_t, amd_max_freq_mhz);#endif /* __AMD_H__ */
I'm also pretty sure that I did ask before to maintain a blank line ahead of the #endif. Please may I ask that you thoroughly address earlier review comments, before submitting a new version?
Jan
RE: [PATCH v3 08/15] xen/amd: export processor max frequency value
[Public]
Hi,
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, March 24, 2025 11:52 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 v3 08/15] xen/amd: export processor max frequency valueQuoted 21 lines · Penny Zheng
xen/arch/x86/cpu/amd.c +5
-1@@ -56,6 +56,8 @@ bool __initdata amd_virt_spec_ctrl;static bool __read_mostly fam17_c6_disabled; +DEFINE_PER_CPU_READ_MOSTLY (uint64_t, amd_max_freq_mhz); +static inline int rdmsr_amd_safe (unsigned int msr,unsigned int *lo,unsigned int *hi) {@@ -681,9 +683,15 @@ void amd_log_freq(const struct cpuinfo_x86 *c)printk ("CPU%u: %lu ... %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo),amd_parse_freq (c, hi)); - else + else {printk ("CPU%u: %lu MHz\n" ,smp_processor_id (),amd_parse_freq (c, lo)); +return ; + }
Quoted 9 lines
xen/arch/x86/cpu/amd.c void amd_log_freq(const struct cpuinfo_x86 *c) · line 695
Quoted 5 lines
xen/arch/x86/cpu/amd.c +4
-0+ +/* Store max frequency for amd-cppc cpufreq driver */ +if (hi >>63 ) +this_cpu (amd_max_freq_mhz) =amd_parse_freq (c, hi); }As before - typically only the BSP will make it here, due to the conditional at the top of the function. IOW you'll observe zeros in the per-CPU data for all other CPUs.
I'll extract the processing frequency logic into a new helper, maybe amd_process_freq()
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/include/asm/amd.h +0
-0@@ -174,4 +174,5 @@ bool amd_setup_legacy_ssbd(void); void
amd_set_legacy_ssbd(bool enable); voidamd_set_cpuid_user_dis(bool enable);
Quoted 7 lines
Quoted 2 lines
+DECLARE_PER_CPU(uint64_t,
amd_max_freq_mhz);
#endif /*__AMD_H__*/I'm also pretty sure that I did ask before to maintain a blank line ahead of the #endif. Please may I ask that you thoroughly address earlier review comments, before submitting a new version?
Sorry, I'll be more careful.
Quoted 1 line
Jan
PATCH v3 9/15 xen/x86: introduce a new amd cppc driver for cpufreq scaling
In reply to Penny Zhengamd-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
--- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 370 +++++++++++++++++++++++++++ xen/arch/x86/include/asm/msr-index.h | 5 + 2 files changed, 375 insertions(+)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +370 -0
@@ -14,7 +14,50 @@#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(fmt, args...) \ + printk(XENLOG_WARNING "AMD_CPPC: CPU%u warning: " fmt, cpu, ## args) +#define amd_cppc_verbose(fmt, args...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "AMD_CPPC: " fmt, ## 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);static bool __init amd_cppc_handle_option (const char *s,const char *end) {
@@ -51,10 +94,337 @@ 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->nominal_mhz *1000 ) ) + { + *perf = data->caps.nominal_perf; +return 0 ; + } + +if ( freq == (cppc_data->lowest_mhz *1000 ) ) + { + *perf = data->caps.lowest_perf; +return 0 ; + } + +if ( cppc_data->lowest_mhz && cppc_data->nominal_mhz ) + { + mul = data->caps.nominal_perf - data->caps.lowest_perf; + div = cppc_data->nominal_mhz - cppc_data->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. +*/ + div = div ?:1 ; + offset = data->caps.nominal_perf - + (mul * cppc_data->nominal_mhz) / div; + } +else + { +/* Read Processor Max Speed(mhz) as anchor point */ + mul = data->caps.highest_perf; + div =this_cpu (amd_max_freq_mhz); +if ( !div ) +return -EINVAL ; + } + + res = offset + (mul * freq) / (div *1000 ); +if ( res >UINT8_MAX ) + { +printk_once (XENLOG_WARNING +"Perf value exceeds maximum value 255: %d\n" , res); + *perf =0xff ; +return 0 ; + } + *perf = (uint8_t )res; + +return 0 ; +} + +#define amd_get_freq (name) \ + static int amd_get_##name##_freq(const struct amd_cppc_drv_data *data, \ + unsigned int *freq) \ + { \ + const struct xen_processor_cppc *cppc_data = data->cppc_data; \ + uint64_t mul, div, res; \ + \ + if ( cppc_data->name##_mhz ) \ + { \ +/* Switch to khz */ \ + *freq = cppc_data->name##_mhz * 1000; \ +return 0 ; \ + } \ + \ +/* Read Processor Max Speed(mhz) as anchor point */ \ + mul =this_cpu (amd_max_freq_mhz); \ +if ( !mul ) \ +return -EINVAL ; \ + div = data->caps.highest_perf; \ + res = (mul * data->caps.name##_perf * 1000) / div; \ +if ( res >UINT_MAX ) \ + { \ +printk (XENLOG_ERR \ +"Frequeny exceeds maximum value UINT_MAX: %lu\n" , res); \ +return -EINVAL ; \ + } \ + *freq = (unsigned int )res; \ + \ +return 0 ; \ + } \ + +amd_get_freq (lowest); +amd_get_freq (nominal); + +static int amd_get_max_freq (const struct amd_cppc_drv_data *data, +unsigned int *max_freq) +{ +unsigned int nom_freq, boost_ratio; +int res; + + res =amd_get_nominal_freq (data, &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 amd_cppc_write_request_msrs (void *info) +{ +struct amd_cppc_drv_data *data = info; + +if (wrmsr_safe (MSR_AMD_CPPC_REQ , data->req.raw) ) + { + data->err = -EINVAL ; +return ; + } +} + +static int cf_check 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 0 ; + + data->err =0 ; +on_selected_cpus (cpumask_of (cpu), amd_cppc_write_request_msrs, data,1 ); + +return data->err; +} + +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; + +return amd_cppc_write_request (policy->cpu, data->caps.lowest_nonlinear_perf, + des_perf, data->caps.highest_perf); +} + +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, nominal_freq, max_freq; + +/* Package level MSR */ +if (rdmsr_safe (MSR_AMD_CPPC_ENABLE , val) ) + { +amd_cppc_err (policy->cpu,"rdmsr_safe(MSR_AMD_CPPC_ENABLE)\n" ); + goto err; + } + +/* +* 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 ; +if (wrmsr_safe (MSR_AMD_CPPC_ENABLE , val) ) + { +amd_cppc_err (policy->cpu, +"wrmsr_safe(MSR_AMD_CPPC_ENABLE, %lx)\n" , val); + goto err; + } + } + +if (rdmsr_safe (MSR_AMD_CPPC_CAP1 , data->caps.raw) ) + { +amd_cppc_err (policy->cpu,"rdmsr_safe(MSR_AMD_CPPC_CAP1)\n" ); + goto err; + } + +if ( data->caps.highest_perf ==0 || data->caps.lowest_perf ==0 || + data->caps.nominal_perf ==0 || data->caps.lowest_nonlinear_perf ==0 ) + { +amd_cppc_err (policy->cpu, +"Platform malfunction, read CPPC highest_perf: %u, lowest_perf: %u, nominal_perf: %u, lowest_nonlinear_perf: %u zero value\n" , + data->caps.highest_perf, data->caps.lowest_perf, + data->caps.nominal_perf, data->caps.lowest_nonlinear_perf); + goto err; + } + + data->err =amd_get_lowest_freq (data, &min_freq); +if ( data->err ) +return ; + + data->err =amd_get_nominal_freq (data, &nominal_freq); +if ( data->err ) +return ; + + data->err =amd_get_max_freq (data, &max_freq); +if ( data->err ) +return ; + +if ( min_freq > max_freq || nominal_freq > max_freq || + nominal_freq < min_freq ) + { +amd_cppc_err (policy->cpu, +"min_freq(%u), or max_freq(%u), or nominal_freq(%u) 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: + data->err = -EINVAL ; +} + +/* +* The new 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 ); + +/* +* 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 nevertheless we specifies fall back option in cmdline. +*/ +if ( data->err ) + { +amd_cppc_err (cpu,"Could not initialize AMD CPPC MSR properly\n" ); +amd_cppc_cpufreq_cpu_exit (policy); +return -ENODEV ; + } + + policy->governor = cpufreq_opt_governor ? :CPUFREQ_DEFAULT_GOVERNOR ; + +amd_cppc_boost_init (policy, data); + +amd_cppc_verbose ("CPU %u initialized with amd-cppc passive mode\n" , + policy->cpu); + +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
@@ -238,6 +238,11 @@#define MSR_AMD_CSTATE_CFG 0xc0010296U +#define MSR_AMD_CPPC_CAP1 0xc00102b0 +#define MSR_AMD_CPPC_ENABLE 0xc00102b1 +#define AMD_CPPC_ENABLE (_AC(1, ULL) << 0) +#define MSR_AMD_CPPC_REQ 0xc00102b3 +/* * Legacy MSR constants in need of cleanup. No new MSRs below this comment. */
Signature · 1 line
2.34.1
Re: [PATCH v3 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling
Quoted 6 lines · Penny Zheng
v2 -> v3:
- Move all MSR-definations tomsr-index.hand 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 whenamd_max_freq_mhzisn't set
Given the issue with the patch filling amd_max_freq_mhz I wonder how you successfully tested this patch here.
Quoted 1 line
- Introduce
amd_get_freq(name)macro to decrease redundancy
Hmm, that's not quite what I was hoping for. I'll comment there in more detail.
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0@@ -14,7 +14,50 @@#include <xen/domain.h> #include <xen/init.h> #include <xen/param.h> +#include <xen/percpu.h> +#include <xen/xvmalloc.h> #include <acpi/cpufreq/cpufreq.h> +#include <asm/amd.h> +#include <asm/msr-index.h>
xen/arch/x86/acpi/cpufreq/amd-cppc.c line 31
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ +#define amd_cppc_err(cpu, fmt, args...) \ + printk(XENLOG_ERR "AMD_CPPC: CPU%u error: " fmt, cpu, ## args) +#define amd_cppc_warn(fmt, args...) \ + printk(XENLOG_WARNING "AMD_CPPC: CPU%u warning: " fmt, cpu, ## args) +#define amd_cppc_verbose(fmt, args...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "AMD_CPPC: " fmt, ## args); \ +})
Why would warning and error come with a CPU number at all times, but not the verbose construct?
Quoted 18 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +18
-0+struct amd_cppc_drv_data +{ + const struct xen_processor_cppc *cppc_data; + union { + uint64_t raw; + struct { + unsigned int lowest_perf:8; + unsigned int lowest_nonlinear_perf:8; + unsigned int nominal_perf:8; + unsigned int highest_perf:8; + unsigned int :32; + }; + } caps; + union { + uint64_t raw; + struct { + unsigned int max_perf:8; + unsigned int min_perf:8;
xen/arch/x86/acpi/cpufreq/amd-cppc.c line 60
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ 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);
Nit: Line length. I wonder what "Sort overlong lines throughout the series" is meant to say in the revision log.
Quoted 26 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +22
-0@@ -51,10 +94,337 @@ 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->nominal_mhz *1000 ) ) + { + *perf = data->caps.nominal_perf; +return 0 ; + } + +if ( freq == (cppc_data->lowest_mhz *1000 ) ) + {
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 128
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ *perf = data->caps.lowest_perf; +return 0 ; + } + +if ( cppc_data->lowest_mhz && cppc_data->nominal_mhz ) + { + mul = data->caps.nominal_perf - data->caps.lowest_perf; + div = cppc_data->nominal_mhz - cppc_data->lowest_mhz; +/* +* We don't need to convert to KHz for computing offset and can
Nit: kHz (i.e. unlike MHz)
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 132
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+* directly use nominal_mhz and lowest_mhz as the division +* will remove the frequency unit. +*/ + div = div ?:1 ;
Imo the cppc_data->lowest_mhz >= cppc_data->nominal_mhz case better wouldn't make it here, but use the fallback path below. Or special- case cppc_data->lowest_mhz == cppc_data->nominal_mhz: mul would (hopefully) be zero (i.e. there would be the expectation that data->caps.nominal_perf == data->caps.lowest_perf, yet no guarantee without checking), and hence ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 134
Quoted 2 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2
-0+ offset = data->caps.nominal_perf - + (mul * cppc_data->nominal_mhz) / div;
... offset = data->caps.nominal_perf regardless of "div" (as long as that's not zero). I.e. the "equal" case may still be fine to take this path.
Or is there a check somewhere that lowest_mhz <= nominal_mhz and lowest_perf <= nominal_perf, which I'm simply overlooking?
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 146
Quoted 12 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +12
-0+ } +else + { +/* Read Processor Max Speed(mhz) as anchor point */ + mul = data->caps.highest_perf; + div =this_cpu (amd_max_freq_mhz); +if ( !div ) +return -EINVAL ; + } + + res = offset + (mul * freq) / (div *1000 ); +if ( res >UINT8_MAX )
I can't quite convince myself that res can't end up negative here, in which case ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 153
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0+ { +printk_once (XENLOG_WARNING +"Perf value exceeds maximum value 255: %d\n" , res); + *perf =0xff ; +return 0 ; + } + *perf = (uint8_t )res;
... a bogus value would be stored here.
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 158
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+return 0 ; +} + +#define amd_get_freq (name) \
The macro parameter is used just ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 159
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+ static int amd_get_##name##_freq(const struct amd_cppc_drv_data *data, \
... here, ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 168
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+ unsigned int *freq) \ + { \ +const struct xen_processor_cppc *cppc_data = data->cppc_data; \ +uint64_t mul, div, res; \ + \ + if ( cppc_data->name##_mhz ) \ + { \ +/* Switch to khz */ \ + *freq = cppc_data->name##_mhz * 1000; \
... twice here forthe MHz value, and ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 177
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+return 0 ; \ + } \ + \ +/* Read Processor Max Speed(mhz) as anchor point */ \ + mul =this_cpu (amd_max_freq_mhz); \ +if ( !mul ) \ +return -EINVAL ; \ + div = data->caps.highest_perf; \ + res = (mul * data->caps.name##_perf * 1000) / div; \
... here for the respective perf indicator. Why does it take ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 190
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+if ( res >UINT_MAX ) \ + { \ +printk (XENLOG_ERR \ +"Frequeny exceeds maximum value UINT_MAX: %lu\n" , res); \ +return -EINVAL ; \ + } \ + *freq = (unsigned int )res; \ + \ +return 0 ; \ + } \ + +amd_get_freq (lowest); +amd_get_freq (nominal);
... two almost identical functions, when one (with two extra input parameters) would suffice?
In amd_cppc_khz_to_perf() you have a check to avoid division by zero. Why not the same safeguarding here?
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 203
Quoted 12 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +12
-0+static int amd_get_max_freq (const struct amd_cppc_drv_data *data, +unsigned int *max_freq) +{ +unsigned int nom_freq, boost_ratio; +int res; + + res =amd_get_nominal_freq (data, &nom_freq); +if ( res ) +return res; + + boost_ratio = (unsigned int )(data->caps.highest_perf / + data->caps.nominal_perf);
Similarly here - I can't spot what would prevent division by zero.
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 204
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+ *max_freq = nom_freq * boost_ratio;
Nor is it clear to me why (with bogus MSR contents) boost_ratio couldn't end up being zero, and hence we'd report back ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 203
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+return 0 ;
... success with a frequency of 0.
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-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 amd_cppc_write_request_msrs (void *info) +{ +struct amd_cppc_drv_data *data = info;
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 229
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ +if (wrmsr_safe (MSR_AMD_CPPC_REQ , data->req.raw) ) + { + data->err = -EINVAL ; +return ; + } +} + +static int cf_check amd_cppc_write_request(unsigned int cpu, uint8_t min_perf, +uint8_t des_perf,uint8_t max_perf)
The cf_check looks to be misplaced here, and rather wants to go to amd_cppc_write_request_msrs() because of ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 242
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+{ +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 0 ; + + data->err =0 ; +on_selected_cpus (cpumask_of (cpu), amd_cppc_write_request_msrs, data,1 );
... this use of a function pointer here.
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+return data->err; +} + +static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 257
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ 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 ;
Checking other *_cpufreq_target() functions, none would silently ignore a zero input. (HWP's ignores the input altogether though; Cc-ing Jason for possible clarification: I would have expected this driver here and the HWP one to be similar in this regard.)
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 264
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+ res =amd_cppc_khz_to_perf (data, target_freq, &des_perf); +if ( res ) +return res; + +return amd_cppc_write_request (policy->cpu, data->caps.lowest_nonlinear_perf, + des_perf, data->caps.highest_perf);
As before: the use of the "non-linear" value here wants to come with a (perhaps brief) comment.
Quoted 33 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +33
-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, nominal_freq, max_freq; + +/* Package level MSR */ +if (rdmsr_safe (MSR_AMD_CPPC_ENABLE , val) ) + { +amd_cppc_err (policy->cpu,"rdmsr_safe(MSR_AMD_CPPC_ENABLE)\n" ); + goto err; + } + +/* +* 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 ; +if (wrmsr_safe (MSR_AMD_CPPC_ENABLE , val) ) + { +amd_cppc_err (policy->cpu, +"wrmsr_safe(MSR_AMD_CPPC_ENABLE, %lx)\n" , val); + goto err; + } + } + +if (rdmsr_safe (MSR_AMD_CPPC_CAP1 , data->caps.raw) )
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 307
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ { +amd_cppc_err (policy->cpu,"rdmsr_safe(MSR_AMD_CPPC_CAP1)\n" ); + goto err; + } + +if ( data->caps.highest_perf ==0 || data->caps.lowest_perf ==0 || + data->caps.nominal_perf ==0 || data->caps.lowest_nonlinear_perf ==0 ) + { + amd_cppc_err(policy->cpu, + "Platform malfunction, read CPPC highest_perf: %u, lowest_perf: %u, nominal_perf: %u, lowest_nonlinear_perf: %u zero value\n",
I don't think the _perf suffixes are overly relevant in the log message.
Quoted 12 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +12
-0+ data->caps.highest_perf, data->caps.lowest_perf, + data->caps.nominal_perf, data->caps.lowest_nonlinear_perf); + goto err; + } + + data->err =amd_get_lowest_freq (data, &min_freq); +if ( data->err ) +return ; + + data->err =amd_get_nominal_freq (data, &nominal_freq); +if ( data->err ) +return ;
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 329
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ + data->err =amd_get_max_freq (data, &max_freq); +if ( data->err ) +return ; + +if ( min_freq > max_freq || nominal_freq > max_freq || + nominal_freq < min_freq ) + { + amd_cppc_err(policy->cpu, + "min_freq(%u), or max_freq(%u), or nominal_freq(%u) value is incorrect\n",
Along the lines of the above, while it wants making clear here it's frequencies, I question the use of identifier names to express that. E.g.
"min (%u), or max (%u), or nominal (%u) freq value is incorrect\n"?
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ 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;
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 349
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+/* +* 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: + data->err = -EINVAL ;
Is we make it here after having set the enable bit, we're hosed (afaict). We can't fall back to another driver, and we also can't get this driver to work. I think I did ask before that this be explained in a comment here. (The only thing the user can do is, aiui, to change the command line option and reboot.)
Oh, I see you have such a comment at the use site of this function. Please have a brief comment here then, to refer there.
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 353
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+} + +/* +* The new AMD CPPC driver is different than legacy ACPI hardware P-State,
Please omit "new" - that'll be stale rather sooner than later.
Quoted 39 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +39
-0+* 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);
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 402
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+return -EOPNOTSUPP ; + } + +on_selected_cpus (cpumask_of (cpu), amd_cppc_init_msrs, policy,1 ); + +/* +* 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 nevertheless we specifies fall back option in cmdline. +*/
Nit: I'm not a native speaker, but I don't think "nevertheless" can be used here. Maybe "... but we also cannot fall back to the legacy driver, irrespective of the command line specifying a fallback option"?
Plus I think it would help to also explain why here, i.e. that the enable bit is sticky.
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 407
Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5
-0+if ( data->err ) + { +amd_cppc_err (cpu,"Could not initialize AMD CPPC MSR properly\n" ); +amd_cppc_cpufreq_cpu_exit (policy); +return -ENODEV ;
Why do you not use data->err here?
xen/arch/x86/include/asm/msr-index.h line 244
Quoted 10 lines
xen/arch/x86/include/asm/msr-index.h +4
-0@@ -238,6 +238,11 @@#define MSR_AMD_CSTATE_CFG 0xc0010296U +#define MSR_AMD_CPPC_CAP1 0xc00102b0 +#define MSR_AMD_CPPC_ENABLE 0xc00102b1 +#define AMD_CPPC_ENABLE (_AC(1, ULL) << 0) +#define MSR_AMD_CPPC_REQ 0xc00102b3
As you can see from the pre-existing #define in context, there are U suffixes missing here.
Jan
Re: [PATCH v3 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling
Quoted 18 lines · Jan Beulich
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 257
Quoted 11 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation) +{ +unsigned int cpu = policy->cpu; +const struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, cpu); +uint8_t des_perf; +int res; + +if (unlikely (!target_freq) ) +return 0 ;Checking other
*_cpufreq_target()functions, none would silently ignore a zero input. (HWP's ignores the input altogether though; Cc-ing Jason for possible clarification: I would have expected this driver here and the HWP one to be similar in this regard.)
Yes, for HWP, the target and relation are ignored. All control is done by writing MSR_HWP_REQUEST which are "continuous, abstract, unit-less performance scale" values. Those are applied by set_hwp_para() from xenpm set-cpufreq-cppc.
I think the difference is that this CPPC driver supports both autonomous and active mode. The HWP driver I wrote only supports the equivalent of autonomous mode - write the MSR and let the processor figure it out.
I think Penny's implementation also uses the existing governors, whereas HWP only uses the dedicated hwp_governor.
Hopefully that gives some context.
Regards,
Jason
RE: [PATCH v3 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling
In reply to Jan Beulich[Public]
Quoted 15 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 5:58 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Roger Pau Monné <[email protected]>; xen- [email protected]; Jason Andryuk <[email protected]>
Subject: Re: [PATCH v3 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scalingxen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 132
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+* directly use nominal_mhz and lowest_mhz as the division +* will remove the frequency unit. +*/ + div = div ?:1 ;
Quoted 6 lines
Imo the
cppc_data->lowest_mhz>=cppc_data->nominal_mhzcase better wouldn't make it here, but use the fallback path below. Or special- casecppc_data->lowest_mhz==cppc_data->nominal_mhz: mul would (hopefully) be zero (i.e. there would be the expectation thatdata->caps.nominal_perf==data->caps.lowest_perf, yet no guarantee without checking), and hence ...
Okay, I'll drop the " div = div ?: 1", to strict the if() to
```
if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz &&
(cppc_data->cpc.lowest_mhz != cppc_data->cpc.nominal_mhz) )
```Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 134
Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2
-0+ offset = data->caps.nominal_perf - + (mul * cppc_data->nominal_mhz) / div;... offset =
data->caps.nominal_perfregardless of "div" (as long as that's not zero). I.e. the "equal" case may still be fine to take this path.Or is there a check somewhere that
lowest_mhz<=nominal_mhzandlowest_perf<=nominal_perf, which I'm simply overlooking?
Yes. I overlooked the scenario that lowest_mhz > nominal_mhz and lowest_perf > nominal_perf and I'll add the check on first read
Quoted 33 lines
Quoted 1 line
+#define
amd_get_freq(name)\The macro parameter is used just ...
Quoted 2 lines
+ static int amd_get_##name##_freq(const struct
amd_cppc_drv_data
+ *data, \... here, ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 168
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+ unsigned int *freq) \ + { \ +const struct xen_processor_cppc *cppc_data = data->cppc_data; \ +uint64_t mul, div, res; \ + \ + if ( cppc_data->name##_mhz ) \ + { \ +/* Switch to khz */ \ + *freq = cppc_data->name##_mhz * 1000; \... twice here forthe MHz value, and ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 177
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+return 0 ; \ + } \ + \ +/* Read Processor Max Speed(mhz) as anchor point */ \ + mul =this_cpu (amd_max_freq_mhz); \ +if ( !mul ) \ +return -EINVAL ; \ + div = data->caps.highest_perf; \ + res = (mul * data->caps.name##_perf * 1000) / div; \... here for the respective perf indicator. Why does it take ...
Quoted 17 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 190
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+if ( res >UINT_MAX ) \ + { \ +printk (XENLOG_ERR \ +"Frequeny exceeds maximum value UINT_MAX: %lu\n" , res); \ +return -EINVAL ; \ + } \ + *freq = (unsigned int )res; \ + \ +return 0 ; \ + } \ + +amd_get_freq (lowest); +amd_get_freq (nominal);... two almost identical functions, when one (with two extra input parameters) would suffice?
I had a draft fix here, If it doesn't what you hope for, plz let me know
```
static int amd_get_lowest_and_nominal_freq(const struct amd_cppc_drv_data *data,
unsigned int *lowest_freq,
unsigned int *nominal_freq)
{
const struct xen_processor_cppc *cppc_data = data->cppc_data;
uint64_t mul, div, res;
uint8_t perf;
if ( !lowest_freq && !nominal_freq )
return -EINVAL;
if ( lowest_freq && cppc_data->cpc.lowest_mhz )
/* Switch to khz */
*lowest_freq = cppc_data->cpc.lowest_mhz * 1000;
if ( nominal_freq && cppc_data->cpc.nominal_mhz )
/* Switch to khz */
*nominal_freq = cppc_data->cpc.nominal_mhz * 1000;
/* Still have unresolved frequency */
if ( (lowest_freq && !(*lowest_freq)) ||
(nominal_freq && !(*nominal_freq)) )
{
do {
/* Calculate lowest frequency firstly if need */
if ( lowest_freq && !(*lowest_freq) )
perf = data->caps.lowest_perf;
else
perf = data->caps.nominal_perf;
/* 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;
}
if ( lowest_freq && !(*lowest_freq) )
*lowest_freq = (unsigned int)res;
else
*nominal_freq = (unsigned int)res;
} while ( nominal_freq && !(*nominal_freq) );
}
return 0;
}
```Quoted 3 lines
In
amd_cppc_khz_to_perf()you have a check to avoid division by zero. Why not the same safeguarding here?
div = data->caps.highest_perf; For highest_perf non-zero check, it is already added in amd_cppc_init_msrs()
Quoted 5 lines
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, boost_ratio; +int 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 203
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+ res =amd_get_nominal_freq (data, &nom_freq); +if ( res ) +return res; + + boost_ratio = (unsigned int )(data->caps.highest_perf / + data->caps.nominal_perf);Similarly here - I can't spot what would prevent division by zero.
In amd_cppc_init_msrs(), before calculating the frequency, we have checked all caps.xxx_perf info shall not be zero.
I'll complement check to avoid "highest_perf < nominal_perf", to ensure that the calculation result of boost_ratio must not be zero.
```
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 )
```Quoted 2 lines
Jan
Re: [PATCH v3 09/15] xen/x86: introduce a new amd cppc driver for cpufreq scaling
Quoted 55 lines · Zheng
Quoted 37 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 5:58 PMQuoted 1 line
+#define
amd_get_freq(name)\The macro parameter is used just ...
Quoted 2 lines
+ static int amd_get_##name##_freq(const struct
amd_cppc_drv_data
+ *data, \... here, ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 168
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+ unsigned int *freq) \ + { \ +const struct xen_processor_cppc *cppc_data = data->cppc_data; \ +uint64_t mul, div, res; \ + \ + if ( cppc_data->name##_mhz ) \ + { \ +/* Switch to khz */ \ + *freq = cppc_data->name##_mhz * 1000; \... twice here forthe MHz value, and ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 177
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+return 0 ; \ + } \ + \ +/* Read Processor Max Speed(mhz) as anchor point */ \ + mul =this_cpu (amd_max_freq_mhz); \ +if ( !mul ) \ +return -EINVAL ; \ + div = data->caps.highest_perf; \ + res = (mul * data->caps.name##_perf * 1000) / div; \... here for the respective perf indicator. Why does it take ...
Quoted 17 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 190
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+if ( res >UINT_MAX ) \ + { \ +printk (XENLOG_ERR \ +"Frequeny exceeds maximum value UINT_MAX: %lu\n" , res); \ +return -EINVAL ; \ + } \ + *freq = (unsigned int )res; \ + \ +return 0 ; \ + } \ + +amd_get_freq (lowest); +amd_get_freq (nominal);... two almost identical functions, when one (with two extra input parameters) would suffice?
Quoted 5 lines
I had a draft fix here, If it doesn't what you hope for, plz let me know ```
static int amd_get_lowest_and_nominal_freq(const structamd_cppc_drv_data*data,
unsigned int*lowest_freq, unsigned int*nominal_freq)
Why two outputs now when there was just one in the macro-ized form? I was rather expecting new inputs to appear, to account for the prior uses of the macro parameter. (As a result the function is now also quite a bit more complex than it was before. In particular there was no ...
Quoted 44 lines
{
const struct xen_processor_cppc *cppc_data = data->cppc_data;
uint64_t mul, div, res;
uint8_t perf;
if ( !lowest_freq && !nominal_freq )
return -EINVAL;
if ( lowest_freq && cppc_data->cpc.lowest_mhz )
/* Switch to khz */
*lowest_freq = cppc_data->cpc.lowest_mhz * 1000;
if ( nominal_freq && cppc_data->cpc.nominal_mhz )
/* Switch to khz */
*nominal_freq = cppc_data->cpc.nominal_mhz * 1000;
/* Still have unresolved frequency */
if ( (lowest_freq && !(*lowest_freq)) ||
(nominal_freq && !(*nominal_freq)) )
{
do {
/* Calculate lowest frequency firstly if need */
if ( lowest_freq && !(*lowest_freq) )
perf = data->caps.lowest_perf;
else
perf = data->caps.nominal_perf;
/* 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);Quoted 8 lines
return -EINVAL;
}
if ( lowest_freq && !(*lowest_freq) )
*lowest_freq = (unsigned int)res;
else
*nominal_freq = (unsigned int)res;
} while ( nominal_freq && !(*nominal_freq) );... loop there.)
Jan
Quoted 5 lines
} return 0; }```
PATCH v3 10/15 xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL
In reply to Penny ZhengFrom: Penny Zheng <[email protected]>
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.
--- xen/drivers/cpufreq/cpufreq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/drivers/cpufreq/cpufreq.c +7 -1
@@ -353,7 +353,13 @@ int cpufreq_add_cpu(unsigned int cpu)if (hw_all || (cpumask_weight (cpufreq_dom->map) == pmpt->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
Re: [PATCH v3 10/15] xen/cpufreq: only set gov NULL when cpufreq_driver.setpolicy is NULL
Quoted 6 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +0
-0@@ -353,7 +353,13 @@ int cpufreq_add_cpu(unsigned int cpu)if (hw_all || (cpumask_weight (cpufreq_dom->map) == pmpt->domain_info.num_processors)) {memcpy (&new_policy, policy,sizeof (struct cpufreq_policy ));
xen/drivers/cpufreq/cpufreq.c int cpufreq_add_cpu(unsigned int cpu) · line 364
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +7
-1- 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);
Indentation looks off-by-1 here.
Also (I may have asked this before, but couldn't find an indication in this submission, including in the cover letter): Is this independent of all earlier patches in the series, and could hence go in right away?
Jan
PATCH v3 11/15 xen/cpufreq: abstract Energy Performance Preference value
In reply to Penny ZhengIntel's hwp Energy Performance Preference value is compatible with CPPC's Energy Performance Preference value, so this commit abstracts the value and re-place it in common header file cpufreq.h, to be used not only for hwp in the future.
--- xen/arch/x86/acpi/cpufreq/hwp.c | 10 +++------- xen/include/acpi/cpufreq/cpufreq.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-)
xen/arch/x86/acpi/cpufreq/hwp.c +3 -7
@@ -21,10 +21,6 @@ static bool __ro_after_init feature_hdc;static bool __ro_after_init opt_cpufreq_hdc = true; -#define HWP_ENERGY_PERF_MAX_PERFORMANCE 0 -#define HWP_ENERGY_PERF_BALANCE 0x80 -#define HWP_ENERGY_PERF_MAX_POWERSAVE 0xff -union hwp_request { struct
@@ -597,7 +593,7 @@ int set_hwp_para(struct cpufreq_policy *policy, data->minimum = data->hw.lowest; data->maximum = data->hw.lowest; data->activity_window =0 ; - data->energy_perf =HWP_ENERGY_PERF_MAX_POWERSAVE ; + data->energy_perf =CPPC_ENERGY_PERF_MAX_POWERSAVE ; data->desired =0 ;break ;
@@ -605,7 +601,7 @@ int set_hwp_para(struct cpufreq_policy *policy, data->minimum = data->hw.highest; data->maximum = data->hw.highest; data->activity_window =0 ; - data->energy_perf =HWP_ENERGY_PERF_MAX_PERFORMANCE ; + data->energy_perf =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; data->desired =0 ;break ;
@@ -613,7 +609,7 @@ int set_hwp_para(struct cpufreq_policy *policy, data->minimum = data->hw.lowest; data->maximum = data->hw.highest; data->activity_window =0 ; - data->energy_perf =HWP_ENERGY_PERF_BALANCE ; + data->energy_perf =CPPC_ENERGY_PERF_BALANCE ; data->desired =0 ;break ;
xen/include/acpi/cpufreq/cpufreq.h +10 -0
@@ -253,6 +253,16 @@ void cpufreq_dbs_timer_resume(void);void intel_feature_detect (struct cpufreq_policy *policy); +/* +* If Energy Performance Preference(epp) is supported in the platform, +* OSPM may write a range of values from 0(performance preference) +* to 0xFF(energy efficiency perference) to control the platform's +* energy efficiency and performance optimization policies +*/ +#define CPPC_ENERGY_PERF_MAX_PERFORMANCE 0 +#define CPPC_ENERGY_PERF_BALANCE 0x80 +#define CPPC_ENERGY_PERF_MAX_POWERSAVE 0xff +int hwp_cmdline_parse (const char *s,const char *e);int hwp_register_driver (void );#ifdef CONFIG_INTEL
Signature · 1 line
2.34.1
Re: [PATCH v3 11/15] xen/cpufreq: abstract Energy Performance Preference value
Quoted 7 lines · Penny Zheng
Intel's hwp Energy Performance Preference value is compatible with CPPC's Energy Performance Preference value, so this commit abstracts the value and re-place it in common header file
cpufreq.h, to be used not only for hwp in the future.Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>
Hmm, this had gone in already before you sent v3. Why was it nevertheless included here?
Jan
PATCH v3 12/15 xen/x86: implement EPP support for the amd-cppc driver in active mode
In reply to Penny Zhengamd-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.
This commit implements one new AMD CPU frequency driver amd-cppc-epp for active mode. It also introduce active tag for users to explicitly select active mode and a new variable opt_active_mode to keep track of which mode is currently enabled.
---
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
--- docs/misc/xen-command-line.pandoc | 8 +- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 119 +++++++++++++++++++++++++-- xen/drivers/cpufreq/utility.c | 11 +++ xen/include/acpi/cpufreq/cpufreq.h | 12 +++ xen/include/public/sysctl.h | 1 + 5 files changed, 145 insertions(+), 6 deletions(-)
docs/misc/xen-command-line.pandoc +7 -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`
@@ -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 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 + the realtime cores frequency automatically according to the power supply and + thermal, core voltage and some other hardware conditions. User could use `;`-separated options to support universal options which they would like to try on any agnostic platform, *but* under priority order, like
xen/arch/x86/acpi/cpufreq/amd-cppc.c +114 -5
185 lines not on this page · raw message
xen/drivers/cpufreq/utility.c +11 -0
@@ -491,3 +491,14 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,return __cpufreq_governor (data,CPUFREQ_GOV_LIMITS ); } + +unsigned int cpufreq_parse_policy (const struct cpufreq_governor *gov) +{ +if ( !strncasecmp (gov->name,"performance" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_PERFORMANCE ; + +if ( !strncasecmp (gov->name,"powersave" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_POWERSAVE ; + +return CPUFREQ_POLICY_UNKNOWN ; +}
xen/include/acpi/cpufreq/cpufreq.h +12 -0
@@ -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_parse_policy (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
@@ -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
Re: [PATCH v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active mode
Quoted 10 lines · 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.
So this is the other way around from "perf" values, where aiui 0xff is "highest"?
docs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. · line 544
Quoted 9 lines
docs/misc/xen-command-line.pandoc +5
-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 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 + the realtime cores frequency automatically according to the power supply and
What are "the realtime cores"?
docs/misc/xen-command-line.pandoc choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. · line 545
Quoted 1 line
docs/misc/xen-command-line.pandoc +1
-0+ thermal, core voltage and some other hardware conditions.
I think there better would be only one "and" in the enumeration of conditions.
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-1@@ -261,7 +276,20 @@ static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy,return res; return amd_cppc_write_request(policy->cpu, data->caps.lowest_nonlinear_perf, - des_perf, data->caps.highest_perf); + des_perf, data->caps.highest_perf,
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, · line 289
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+/* Pre-defined BIOS value for passive mode */ + per_cpu(epp_init, policy->cpu)); +} + +static int read_epp_init (void ) +{ +uint64_t val; + +if (rdmsr_safe (MSR_AMD_CPPC_REQ , val) ) +return -EINVAL ;
I'm unconvinced of using rdmsr_safe() everywhere (i.e. this also goes for earlier patches). Unless you can give a halfway reasonable scenario under which by the time we get here there's still a chance that the MSR isn't implemented in the next lower layer (hardware or another hypervisor, just to explain what's meant, without me assuming that the driver should come into play in the first place when we run virtualized ourselves).
Furthermore you call this function unconditionally, i.e. if there was a chance for the MSR read to fail, CPU init would needlessly fail when in passive mode.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, · line 290
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+this_cpu (epp_init) = (val >>24 ) &0xFF ;
Please can you #define a suitable mask constant in msr-index.h, such that you can use MASK_EXTR() here?
Quoted 30 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +20
-0@@ -411,12 +441,78 @@ 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 ("CPU %u initialized with amd-cppc passive mode\n" , policy->cpu);return 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_parse_policy (policy->governor);
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 479
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ +amd_cppc_verbose ("CPU %u initialized with amd-cppc active mode\n" , policy->cpu); + +return 0 ; +} + +static int amd_cppc_epp_update_limit (const struct cpufreq_policy *policy) +{ +const struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, + policy->cpu);
Nit: Indentation is off by one here.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 491
Quoted 12 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +12
-0+uint8_t max_perf, min_perf, epp; + +/* Initial min/max values for CPPC Performance Controls Register */ +/* +* Continuous CPPC performance scale in active mode is [lowest_perf, +* highest_perf] +*/ + max_perf = data->caps.highest_perf; + min_perf = data->caps.lowest_perf; + + epp =per_cpu (epp_init, policy->cpu); +if ( policy->policy ==CPUFREQ_POLICY_PERFORMANCE )
This may want to be switch() instead.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 502
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+ { +/* Force the epp value to be zero for performance policy */ + epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; + min_perf = max_perf; + } + else if ( policy->policy == CPUFREQ_POLICY_POWERSAVE ) +/* Force the epp value to be 0xff for powersave policy */ +/* +* If set max_perf = min_perf = lowest_perf, we are putting +* cpu cores in idle. +*/
Nit: Such two successive comments want combining. (Same near the top of the function, as I notice only now.)
Furthermore I'm in trouble with interpreting this comment: To me "lowest" doesn't mean "doing nothing" but "doing things as efficiently in terms of power use as possible". IOW that's not idle. Yet the comment reads as if it was meant to be an explanation of why we can't set max_perf from min_perf here. That is, not matter what's meant to be said, I think this needs re- wording (and possibly using subjunctive mood).
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 507
Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5
-0+ epp =CPPC_ENERGY_PERF_MAX_POWERSAVE ; + + return amd_cppc_write_request(policy->cpu, min_perf, + /* des_perf = 0 for epp mode */ + 0,
The comment could do with putting on the same line as the 0, e.g. (slightly adjusted)
return amd_cppc_write_request(policy->cpu, min_perf,
0 /* no des_perf for epp mode */,
max_perf, epp);xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 514
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) +{ +return amd_cppc_epp_update_limit (policy); +}
So the purpose of this wrapper is solely to have the actual function's parameter be pointer-to-const? I don't think that's worth it; I also don't think we do such elsewhere.
Quoted 7 lines
xen/drivers/cpufreq/utility.c +1
-0@@ -491,3 +491,14 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,return __cpufreq_governor (data,CPUFREQ_GOV_LIMITS ); } +
xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy *data, · line 504
Quoted 10 lines
xen/drivers/cpufreq/utility.c +10
-0+unsigned int cpufreq_parse_policy (const struct cpufreq_governor *gov) +{ +if ( !strncasecmp (gov->name,"performance" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_PERFORMANCE ; + +if ( !strncasecmp (gov->name,"powersave" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_POWERSAVE ; + +return CPUFREQ_POLICY_UNKNOWN ; +}
Hmm, this isn't really parsing (in the sense of dealing with e.g. command line elements). Maybe cpufreq_get_policy() or, more explicitly, cpufreq_policy_from_governor()? Or something along these lines?
I also don't see why the more expensive case-insensitive comparison routine needs using here.
Jan
RE: [PATCH v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active mode
[Public]
Hi,
Quoted 24 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 6:49 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 v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active modeQuoted 10 lines · 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.
Quoted 2 lines
So this is the other way around from "perf" values, where aiui
0xffis "highest"?
Yes, it is not the perf value. It is an arbitrary value on a scale from 0 to 255
Quoted 16 lines
Review static int cf_check amd_cppc_cpufreq_target(struct
Quoted 1 line
(quoted diff) +0
-0@@ -261,7 +276,20 @@ static int cf_check amd_cppc_cpufreq_target(struct
cpufreq_policy*policy,Quoted 14 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-1return res;return amd_cppc_write_request (policy->cpu, data- caps.lowest_nonlinear_perf, - des_perf, data->caps.highest_perf); + des_perf, data->caps.highest_perf, +/* Pre-defined BIOS value for passive mode */ +per_cpu (epp_init, policy->cpu)); } + +static int read_epp_init (void ) +{ +uint64_t val; + +if (rdmsr_safe (MSR_AMD_CPPC_REQ , val) )
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, · line 289
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+return -EINVAL ;I'm unconvinced of using
rdmsr_safe()everywhere (i.e. this also goes for earlier patches). Unless you can give a halfway reasonable scenario under which by the time we get here there's still a chance that the MSR isn't implemented in the next lower layer (hardware or another hypervisor, just to explain what's meant, without me assuming that the driver should come into play in the first place when we run virtualized ourselves).
Correct me if I understand wrongly, we are concerning that the driver may not always have the privilege to directly access the MSR in all scenarios, so rdmsr_safe with exception handling isn't always suitable. Then maybe I shall switch them all into rdmsrl() ?
Quoted 3 lines
Furthermore you call this function unconditionally, i.e. if there was a chance for the MSR read to fail, CPU init would needlessly fail when in passive mode.
The reason why I also run read_epp_init() for passive mode is to avoid setting epp with zero value
for MSR_AMD_CPPC_REQ in passive mode. I want to give it pre-defined BIOS value in passive mode.
If we wrap read_epp_init() with active mode check, maybe we shall add extra read before setting request register MSR_AMD_CPPC_REQ, introducing MSR_AMD_CPPC_EPP_MASK to reserve original value for epp in passive mode, or any better suggestion?
Quoted 15 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 502
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+ { +/* Force the epp value to be zero for performance policy */ + epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; + min_perf = max_perf; + } + else if ( policy->policy == CPUFREQ_POLICY_POWERSAVE ) +/* Force the epp value to be 0xff for powersave policy */ +/* +* If set max_perf = min_perf = lowest_perf, we are putting +* cpu cores in idle. +*/ Nit: Such two successive comments want combining. (Same near the top of the function, as I notice only now.)
Quoted 7 lines
Furthermore I'm in trouble with interpreting this comment: To me "lowest" doesn't mean "doing nothing" but "doing things as efficiently in terms of power use as possible". IOW that's not idle. Yet the comment reads as if it was meant to be an explanation of why we can't set
max_perffrommin_perfhere. That is, not matter what's meant to be said, I think this needs re- wording (and possibly using subjunctive mood).
How about:
The lowest non-linear perf is equivalent as P2 frequency. Reducing performance below this point does not lead to total energy savings for a given computation (although it reduces momentary power). So we are not suggesting to set max_perf smaller than lowest non-linear perf, or even the lowest perf.
Quoted 1 line
Jan
Re: [PATCH v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active mode
Quoted 31 lines · Zheng
Quoted 21 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 6:49 PMReview static int cf_check amd_cppc_cpufreq_target(struct
Quoted 1 line · Penny Zheng
(quoted diff) +0
-0@@ -261,7 +276,20 @@ static int cf_check amd_cppc_cpufreq_target(struct
cpufreq_policy*policy,Quoted 14 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-1return res;return amd_cppc_write_request (policy->cpu, data- caps.lowest_nonlinear_perf, - des_perf, data->caps.highest_perf); + des_perf, data->caps.highest_perf, +/* Pre-defined BIOS value for passive mode */ +per_cpu (epp_init, policy->cpu)); } + +static int read_epp_init (void ) +{ +uint64_t val; + +if (rdmsr_safe (MSR_AMD_CPPC_REQ , val) )Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, · line 289
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+return -EINVAL ;I'm unconvinced of using
rdmsr_safe()everywhere (i.e. this also goes for earlier patches). Unless you can give a halfway reasonable scenario under which by the time we get here there's still a chance that the MSR isn't implemented in the next lower layer (hardware or another hypervisor, just to explain what's meant, without me assuming that the driver should come into play in the first place when we run virtualized ourselves).
Quoted 3 lines
Correct me if I understand wrongly, we are concerning that the driver may not always have the privilege to directly access the MSR in all scenarios, so
rdmsr_safewith exception handling isn't always suitable. Then maybe I shall switch them all intordmsrl()?
There's no privilege question here - we're running at the highest possible privilege level. The only question in MSR access can concern the existence of these MSRs (on bare hardware) or improper emulation of MSRs by an underlying hypervisor. The latter case I think we can pretty much exclude for a driver like this one - the driver simply has no (real) use when running virtualized. Which leaves errata on hardware. Those would better be dealt with by checking once up front (and then disabling the driver if need be). IOW except for perhaps a single probing access early in driver init, I think these better would all be plain accesses. And even such an early probing access would likely only need switching to when a relevant erratum becomes known.
Quoted 8 lines
Quoted 3 lines
Furthermore you call this function unconditionally, i.e. if there was a chance for the MSR read to fail, CPU init would needlessly fail when in passive mode.
The reason why I also run
read_epp_init()for passive mode is to avoid setting epp with zero value
forMSR_AMD_CPPC_REQin passive mode. I want to give it pre-defined BIOS value in passive mode.
If we wrapread_epp_init()with active mode check, maybe we shall add extra read before setting request registerMSR_AMD_CPPC_REQ, introducingMSR_AMD_CPPC_EPP_MASKto reserve original value for epp in passive mode, or any better suggestion?
Well, not using rdmsr_safe() here would make the function impossible to fail, and hence the question itself would be moot. Otherwise my suggestion would be to ignore the error (perhaps associated with a warning) in passive mode.
Quoted 22 lines
Quoted 15 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 502
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+ { +/* Force the epp value to be zero for performance policy */ + epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; + min_perf = max_perf; + } + else if ( policy->policy == CPUFREQ_POLICY_POWERSAVE ) +/* Force the epp value to be 0xff for powersave policy */ +/* +* If set max_perf = min_perf = lowest_perf, we are putting +* cpu cores in idle. +*/ Nit: Such two successive comments want combining. (Same near the top of the function, as I notice only now.)
Quoted 6 lines
Furthermore I'm in trouble with interpreting this comment: To me "lowest" doesn't mean "doing nothing" but "doing things as efficiently in terms of power use as possible". IOW that's not idle. Yet the comment reads as if it was meant to be an explanation of why we can't set
max_perffrommin_perfhere. That is, not matter what's meant to be said, I think this needs re- wording (and possibly using subjunctive mood).
Quoted 4 lines
How about:
The lowest non-linear perf is equivalent as P2 frequency. Reducing performance below this point does not lead to total energy savings for a given computation (although it reduces momentary power). So we are not suggesting to setmax_perfsmaller than lowest non-linear perf, or even the lowest perf.
In an abstract way I think I can follow this. In the context of the code being commented, however, I'm afraid I still can't make sense of it. Main point being that the code commented doesn't use any of the *_perf values. It only sets the "epp" local variable. Maybe the point of the comment is to explain why non of the *_perf are used here, but I can't read this out of either of the proposed texts.
Jan
RE: [PATCH v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active mode
[Public]
Hi,
Quoted 45 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Friday, March 28, 2025 3:18 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 v3 12/15] xen/x86: implement EPP support for the amd-cppc driver in active modeQuoted 28 lines · Zheng
Quoted 21 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Tuesday, March 25, 2025 6:49 PMxen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 502
Quoted 11 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+ { +/* Force the epp value to be zero for performance policy */ + epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; + min_perf = max_perf; + } + else if ( policy->policy == CPUFREQ_POLICY_POWERSAVE ) +/* Force the epp value to be 0xff for powersave policy */ +/* +* If set max_perf = min_perf = lowest_perf, we are putting +* cpu cores in idle. +*/ Nit: Such two successive comments want combining. (Same near the top of the function, as I notice only now.)
Quoted 6 lines
Furthermore I'm in trouble with interpreting this comment: To me "lowest" doesn't mean "doing nothing" but "doing things as efficiently in terms of power use as possible". IOW that's not idle. Yet the comment reads as if it was meant to be an explanation of why we can't set
max_perffrommin_perfhere. That is, not matter what's meant to be said, I think this needs re- wording (and possibly using subjunctive mood).Quoted 3 lines
How about:
The lowest non-linear perf is equivalent as P2 frequency. Reducing performance below this point does not lead to total energy savings for a givencomputation (although it reduces momentary power).
Quoted 9 lines
Quoted 1 line
So we are not suggesting to set
max_perfsmaller than lowest non-linear perf, oreven the lowest perf.
In an abstract way I think I can follow this. In the context of the code being commented, however, I'm afraid I still can't make sense of it. Main point being that the code commented doesn't use any of the
*_perfvalues. It only sets the "epp" local variable. Maybe the point of the comment is to explain why non of the*_perfare used here, but I can't read this out of either of the proposed texts.
I've checked some internal test suites for CPPC in windows. Maybe setting max_perf = nominal_perf is a fair option for powersave mode
Quoted 1 line
Jan
PATCH v3 13/15 tools/xenpm: Print CPPC parameters for amd-cppc driver
In reply to Penny ZhengFrom: Penny Zheng <[email protected]>
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.
--- tools/misc/xenpm.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
tools/misc/xenpm.c +14 -4
@@ -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 ) {printf ("scaling_avail_gov : %s\n" , p_cpufreq->scaling_available_governors);
Signature · 1 line
2.34.1
PATCH v3 14/15 xen/xenpm: Adapt cpu frequency monitor in xenpm
In reply to Penny ZhengMake xenpm get-cpureq-para/set-cpufreq-para available in CPPC mode. Also, In xenpm get-cpufreq-para <cpuid>, para scaling_available_frequencies only has meaningful value when cpufreq driver in legacy P-states. So we loosen "has_num" condition to bypass scaling_available_frequencies check in CPPC mode.
Also, in xenpm get-cpyfreq-para start, the monitor of average frequency shall not depend on the existence of legacy P-states.
---
v2 -> v3:
- new commit
--- tools/libs/ctrl/xc_pm.c | 12 +++++++----- tools/misc/xenpm.c | 5 +++-- xen/drivers/acpi/pmstat.c | 30 +++++++++++++++++------------- 3 files changed, 27 insertions(+), 20 deletions(-)
tools/libs/ctrl/xc_pm.c +7 -5
@@ -214,13 +214,12 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, 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 && user_para->gov_num;if ( has_num ) {if ( (!user_para->affected_cpus) || - (!user_para->scaling_available_frequencies) || + (user_para->freq_num && !user_para->scaling_available_frequencies) || (user_para->gov_num && !user_para->scaling_available_governors) ) { errno =EINVAL ;
@@ -228,14 +227,16 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, }if (xc_hypercall_bounce_pre (xch, affected_cpus) ) goto unlock_1; -if (xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) +if ( user_para->freq_num && +xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) goto unlock_2;if ( user_para->gov_num &&xc_hypercall_bounce_pre (xch, scaling_available_governors) ) goto unlock_3;set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); -set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies); +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);
@@ -301,7 +302,8 @@ unlock_4:if ( user_para->gov_num )xc_hypercall_bounce_post (xch, scaling_available_governors); unlock_3: -xc_hypercall_bounce_post (xch, scaling_available_frequencies); +if ( user_para->freq_num ) +xc_hypercall_bounce_post (xch, scaling_available_frequencies); unlock_2:xc_hypercall_bounce_post (xch, affected_cpus); unlock_1:
tools/misc/xenpm.c +3 -2
@@ -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]); }
@@ -926,7 +926,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) ret = -ENOMEM ; goto out; } -if (!(p_cpufreq->scaling_available_frequencies = +if (p_cpufreq->freq_num && + !(p_cpufreq->scaling_available_frequencies =malloc (p_cpufreq->freq_num *sizeof (uint32_t )))) { fprintf(stderr,
xen/drivers/acpi/pmstat.c +17 -13
@@ -202,7 +202,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 ;
@@ -229,17 +229,20 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)if ( ret )return ret; -if ( !(scaling_available_frequencies = -xzalloc_array (uint32_t, op->u.get_para.freq_num)) ) -return -ENOMEM ; -for ( i =0 ; i < op->u.get_para.freq_num; i++ ) - scaling_available_frequencies[i] = - pmpt->perf.states[i].core_frequency *1000 ; - ret =copy_to_guest (op->u.get_para.scaling_available_frequencies, - scaling_available_frequencies, op->u.get_para.freq_num); -xfree (scaling_available_frequencies); -if ( ret ) -return ret; +if ( op->u.get_para.freq_num ) + { +if ( !(scaling_available_frequencies = +xzalloc_array (uint32_t, op->u.get_para.freq_num)) ) +return -ENOMEM ; +for ( i =0 ; i < op->u.get_para.freq_num; i++ ) + scaling_available_frequencies[i] = + pmpt->perf.states[i].core_frequency *1000 ; + ret =copy_to_guest (op->u.get_para.scaling_available_frequencies, + scaling_available_frequencies, op->u.get_para.freq_num); +xfree (scaling_available_frequencies); +if ( ret ) +return ret; + } op->u.get_para.cpuinfo_cur_freq = cpufreq_driver.get ? alternative_call(cpufreq_driver.get, op->cpuid)
@@ -465,7 +468,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)switch ( op->cmd &PM_PARA_CATEGORY_MASK ) {case CPUFREQ_PARA : -if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) +if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX | +XEN_PROCESSOR_PM_CPPC )) )return -ENODEV ;if ( !pmpt || !(pmpt->init & (XEN_PX_INIT |XEN_CPPC_INIT )) )return -EINVAL ;
Signature · 1 line
2.34.1
Re: [PATCH v3 14/15] xen/xenpm: Adapt cpu frequency monitor in xenpm
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 219
Quoted 11 lines · Penny Zheng
Make
xenpm get-cpureq-para/set-cpufreq-paraavailable in CPPC mode.tools/libs/ctrl/xc_pm.c +0
-1@@ -214,13 +214,12 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, 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 && user_para->gov_num;if ( has_num )
Something looks wrong here already before your patch: With how has_num is set and with this conditional, ...
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 223
Quoted 5 lines
tools/libs/ctrl/xc_pm.c +1
-1{if ( (!user_para->affected_cpus) || - (!user_para->scaling_available_frequencies) || + (user_para->freq_num && !user_para->scaling_available_frequencies) || (user_para->gov_num && !user_para->scaling_available_governors) )
... this ->gov_num check, ...
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 233
Quoted 11 lines
tools/libs/ctrl/xc_pm.c +2
-1{ errno =EINVAL ;@@ -228,14 +227,16 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, }if (xc_hypercall_bounce_pre (xch, affected_cpus) ) goto unlock_1; -if (xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) +if ( user_para->freq_num && +xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) goto unlock_2; if ( user_para->gov_num &&
... this one, and ...
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 239
Quoted 7 lines
tools/libs/ctrl/xc_pm.c +2
-1xc_hypercall_bounce_pre(xch, scaling_available_governors) ) goto unlock_3;set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); -set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies); +if ( user_para->freq_num ) +set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies);
(Nit: Yet another overly long line. It was too long already before, yes, but
that's no excuse to make it even longer. The more that there is better formatting right in context below.)
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 240
Quoted 1 line
tools/libs/ctrl/xc_pm.c +0
-0if ( user_para->gov_num )
... this one are all dead code. Jason? I expect the has_num variable simply wants dropping altogether, thus correcting the earlier anomaly and getting the intended new behavior at the same time.
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 242
Quoted 2 lines
tools/libs/ctrl/xc_pm.c +0
-0set_xen_guest_handle (sys_para->scaling_available_governors, scaling_available_governors);
This is the piece of context I'm referring to in the nit above.
tools/libs/ctrl/xc_pm.c unlock_4: · line 309
Quoted 10 lines
tools/libs/ctrl/xc_pm.c +2
-1@@ -301,7 +302,8 @@ unlock_4:if ( user_para->gov_num )xc_hypercall_bounce_post (xch, scaling_available_governors); unlock_3: -xc_hypercall_bounce_post (xch, scaling_available_frequencies); +if ( user_para->freq_num ) +xc_hypercall_bounce_post (xch, scaling_available_frequencies); unlock_2:xc_hypercall_bounce_post (xch, affected_cpus); unlock_1:
I'm also puzzled by the function's inconsistent return value - Anthony, can you explain / spot why things are the way they are?
tools/misc/xenpm.c static void signal_int_handler(int signo) · line 544
Quoted 10 lines
tools/misc/xenpm.c +1
-1@@ -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]); }
I wonder whether this shouldn't be an independent change (which then could go in rather sooner).
tools/misc/xenpm.c static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) · line 933
Quoted 10 lines
tools/misc/xenpm.c +2
-1@@ -926,7 +926,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) ret = -ENOMEM ; goto out; } -if (!(p_cpufreq->scaling_available_frequencies = +if (p_cpufreq->freq_num && + !(p_cpufreq->scaling_available_frequencies =malloc (p_cpufreq->freq_num *sizeof (uint32_t )))) { fprintf(stderr,
Can someone explain to me how the pre-existing logic here works? All three ->*_num start out as zero. Hence respective allocations (of zero size) may conceivably return NULL (the behavior there is implementation defined after all). Yet then we'd bail from the loop, and hence from the function. IOW adding a ->freq_num check and also a ->cpu_num one (along with the ->gov_num one that apparently was added during HWP development) would once again look like an independent (latent) bugfix to me.
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 207
Quoted 10 lines
xen/drivers/acpi/pmstat.c +1
-1@@ -202,7 +202,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 ;
Wouldn't this change better belong in the earlier patch, where the code in context of the last hunk below was adjusted?
Quoted 13 lines
xen/drivers/acpi/pmstat.c +0
-9@@ -229,17 +229,20 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)if ( ret )return ret; -if ( !(scaling_available_frequencies = -xzalloc_array (uint32_t, op->u.get_para.freq_num)) ) -return -ENOMEM ; -for ( i =0 ; i < op->u.get_para.freq_num; i++ ) - scaling_available_frequencies[i] = - pmpt->perf.states[i].core_frequency *1000 ; - ret =copy_to_guest (op->u.get_para.scaling_available_frequencies, - scaling_available_frequencies, op->u.get_para.freq_num); -xfree (scaling_available_frequencies);
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 239
Quoted 10 lines
xen/drivers/acpi/pmstat.c +8
-2-if ( ret ) -return ret; +if ( op->u.get_para.freq_num ) + { +if ( !(scaling_available_frequencies = +xzalloc_array (uint32_t, op->u.get_para.freq_num)) ) +return -ENOMEM ; +for ( i =0 ; i < op->u.get_para.freq_num; i++ ) + scaling_available_frequencies[i] = + pmpt->perf.states[i].core_frequency *1000 ;
Nit: Indentation was bogus here and ...
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 241
Quoted 2 lines
xen/drivers/acpi/pmstat.c +2
-0+ ret =copy_to_guest (op->u.get_para.scaling_available_frequencies, + scaling_available_frequencies, op->u.get_para.freq_num);
... here before, and sadly continues to be bogus now.
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 245
Quoted 4 lines
xen/drivers/acpi/pmstat.c +4
-0+xfree (scaling_available_frequencies); +if ( ret ) +return ret; + }
While (beyond the nit above) I'm okay with this simple change, I think the code here would benefit from folding the two allocations into one. There simply is no reason to pay the price of the allocation overhead twice, when we need a uint32_t[max(.cpu_num, .freq_num)] array anyway. That way the churn introduced here would then also be smaller.
xen/drivers/acpi/pmstat.c int do_pm_op(struct xen_sysctl_pm_op *op) · line 475
Quoted 10 lines
xen/drivers/acpi/pmstat.c +2
-1@@ -465,7 +468,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)switch ( op->cmd &PM_PARA_CATEGORY_MASK ) {case CPUFREQ_PARA : -if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) +if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX | +XEN_PROCESSOR_PM_CPPC )) )return -ENODEV ;if ( !pmpt || !(pmpt->init & (XEN_PX_INIT |XEN_CPPC_INIT )) )return -EINVAL ;
(This is the hunk I'm referring to further up.)
Jan
Re: [PATCH v3 14/15] xen/xenpm: Adapt cpu frequency monitor in xenpm
Quoted 48 lines · Jan Beulich
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 219
Quoted 11 lines · Penny Zheng
Make
xenpm get-cpureq-para/set-cpufreq-paraavailable in CPPC mode.tools/libs/ctrl/xc_pm.c +0
-1@@ -214,13 +214,12 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, 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 && user_para->gov_num;if ( has_num )Something looks wrong here already before your patch: With how
has_numis set and with this conditional, ...tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 223
Quoted 5 lines
tools/libs/ctrl/xc_pm.c +1
-1{if ( (!user_para->affected_cpus) || - (!user_para->scaling_available_frequencies) || + (user_para->freq_num && !user_para->scaling_available_frequencies) || (user_para->gov_num && !user_para->scaling_available_governors) )... this ->gov_num check, ...>> {
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 233
Quoted 10 lines
tools/libs/ctrl/xc_pm.c +2
-1errno =EINVAL ;@@ -228,14 +227,16 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, }if (xc_hypercall_bounce_pre (xch, affected_cpus) ) goto unlock_1; -if (xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) +if ( user_para->freq_num && +xc_hypercall_bounce_pre (xch, scaling_available_frequencies) ) goto unlock_2; if ( user_para->gov_num &&... this one, and ...
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 239
Quoted 7 lines
tools/libs/ctrl/xc_pm.c +2
-1xc_hypercall_bounce_pre(xch, scaling_available_governors) ) goto unlock_3;set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); -set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies); +if ( user_para->freq_num ) +set_xen_guest_handle (sys_para->scaling_available_frequencies, scaling_available_frequencies);(Nit: Yet another overly long line. It was too long already before, yes, but
that's no excuse to make it even longer. The more that there is better formatting right in context below.)
Quoted 5 lines
tools/libs/ctrl/xc_pm.c int xc_get_cpufreq_para(xc_interface *xch, int cpuid, · line 240
Quoted 1 line
tools/libs/ctrl/xc_pm.c +0
-0if ( user_para->gov_num )... this one are all dead code. Jason? I expect the
has_numvariable simply wants dropping altogether, thus correcting the earlier anomaly and getting the intended new behavior at the same time.
Hmmm. The sysctl is executed twice - first to query the assorted *_num values and a second time to retrieve the results with sized arrays.
get_hwp_para() does not populate scaling_available_governors, so the intention was to be able to skip allocating the buffer for it.
pmstat&xenpm: Re-arrage for cpufreq union
Rearrange code now that xen_sysctl_pm_op's get_para fields has the nested union and struct. In particular, the scaling governor information like scaling_available_governors is inside the union, so it is not always available. Move those fields (op->u.get_para.u.s.u.*) together as well as the common fields (ones outside the union like op->u.get_para.turbo_enabled).
With that, gov_num may be 0, so bounce buffer handling needs to be modified.
scaling_governor and other fields inside op->u.get_para.u.s.u.*
won't be
used for hwp, so this will simplify the change when hwp support is introduced and re-indents these lines all together.
I noted that gov_num may be 0. But that may have been before hwp had its own internal governor. But, yes, the has_num handling looks wrong for gov_num == 0. I don't have a machine with hwp to verify.
Quoted 11 lines
tools/libs/ctrl/xc_pm.c static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) · line 933
Quoted 10 lines
tools/libs/ctrl/xc_pm.c +2
-1@@ -926,7 +926,8 @@ static int show_cpufreq_para_by_cpuid(xc_interface *xc_handle, int cpuid) ret = -ENOMEM ; goto out; } -if (!(p_cpufreq->scaling_available_frequencies = +if (p_cpufreq->freq_num && + !(p_cpufreq->scaling_available_frequencies =malloc (p_cpufreq->freq_num *sizeof (uint32_t )))) { fprintf(stderr,
Quoted 7 lines
Can someone explain to me how the pre-existing logic here works? All three ->*_num start out as zero. Hence respective allocations (of zero size) may conceivably return NULL (the behavior there is implementation defined after all). Yet then we'd bail from the loop, and hence from the function. IOW adding a ->freq_num check and also a ->cpu_num one (along with the ->gov_num one that apparently was added during HWP development) would once again look like an independent (latent) bugfix to me.
I guess we rely on glibc providing non-NULL? But also they are ignored for the initial query of *_num values.
Regards,
Jason
Re: [PATCH v3 14/15] xen/xenpm: Adapt cpu frequency monitor in xenpm
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 9 lines · Penny Zheng
Make
xenpm get-cpureq-para/set-cpufreq-paraavailable in CPPC mode.tools/libs/ctrl/xc_pm.c +0
-1@@ -214,13 +214,12 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,@@ -301,7 +302,8 @@ unlock_4:if ( user_para->gov_num )xc_hypercall_bounce_post (xch, scaling_available_governors); unlock_3: -xc_hypercall_bounce_post (xch, scaling_available_frequencies);
Quoted 8 lines
tools/libs/ctrl/xc_pm.c unlock_4: · line 309
Quoted 5 lines
tools/libs/ctrl/xc_pm.c +2
-0+if ( user_para->freq_num ) +xc_hypercall_bounce_post (xch, scaling_available_frequencies); unlock_2:xc_hypercall_bounce_post (xch, affected_cpus); unlock_1:I'm also puzzled by the function's inconsistent return value - Anthony, can you explain / spot why things are the way they are?
Looks like 73367cf3b4b4 ("libxc: Fix xc_pm API calls to return negative error and stash error in errno.") made some changes, and fixed some return value to be like described in "xenctrl.h", but I guess failed to also change the "ret = -errno".
Cheers,
Signature · 5 lines
Anthony Perard | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH v3 15/15 xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
In reply to Penny ZhengIntroduce 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()
--- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 124 +++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 20 ++++- xen/include/acpi/cpufreq/cpufreq.h | 5 ++ 3 files changed, 145 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +124 -0
@@ -32,6 +32,7 @@static bool __ro_after_init opt_active_mode; static DEFINE_PER_CPU_READ_MOSTLY(uint8_t, epp_init); +static bool __ro_after_init amd_cppc_in_use;struct amd_cppc_drv_data {
@@ -513,6 +514,123 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)return amd_cppc_epp_update_limit (policy); } +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_PRESET_POWERSAVE/PERFORMANCE/BALANCE are +* for amd-cppc in active mode, min_perf could be set with lowest_perf +* representing the T-state range of performance levels, while +* XEN_SYSCTL_CPPC_SET_PRESET_NONE is for amd-cppc in passive mode, it +* depends on governor to do performance scaling, setting with +* lowest_nonlinear_perf to ensures performance in P-state range. +*/ +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; + max_perf = data->caps.highest_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 ; + 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; + +return amd_cppc_write_request (cpu, min_perf, des_perf, max_perf, epp); +} + + static const struct cpufreq_driver __initconst_cf_clobber amd_cppc_cpufreq_driver = {
@@ -533,6 +651,11 @@ amd_cppc_epp_driver = .exit = amd_cppc_cpufreq_cpu_exit, }; +bool amd_cppc_active (void ) +{ +return amd_cppc_in_use; +} +int __init amd_cppc_register_driver (void ) {int ret;
@@ -552,6 +675,7 @@ int __init amd_cppc_register_driver(void)/* Remove possible fallback option */ xen_processor_pmbits &= ~XEN_PROCESSOR_PM_PX ; + amd_cppc_in_use = true;return ret; }
xen/drivers/acpi/pmstat.c +16 -4
@@ -261,7 +261,16 @@ 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 )) )
@@ -417,10 +426,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 (amd_cppc_active () ) +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 +5 -0
@@ -292,5 +292,10 @@ int acpi_cpufreq_register(void);int amd_cppc_cmdline_parse (const char *s,const char *e);int amd_cppc_register_driver (void ); +bool amd_cppc_active (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
Re: [PATCH v3 15/15] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
Quoted 85 lines · Penny Zheng
Introduce helper
set_amd_cppc_paraandget_amd_cppc_parato SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()--- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 124 +++++++++++++++++++++++++++ xen/drivers/acpi/pmstat.c | 20 ++++- xen/include/acpi/cpufreq/cpufreq.h | 5 ++ 3 files changed, 145 insertions(+), 4 deletions(-)xen/arch/x86/acpi/cpufreq/amd-cppc.c +56
-0@@ -32,6 +32,7 @@static bool __ro_after_init opt_active_mode; static DEFINE_PER_CPU_READ_MOSTLY(uint8_t, epp_init); +static bool __ro_after_init amd_cppc_in_use;struct amd_cppc_drv_data {@@ -513,6 +514,123 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)return amd_cppc_epp_update_limit (policy); } +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 ; +
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 581
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ epp =per_cpu (epp_init, cpu); +/* Apply presets */ +/* +* XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/BALANCE are +* for amd-cppc in active mode, min_perf could be set with lowest_perf +* representing the T-state range of performance levels, while +* XEN_SYSCTL_CPPC_SET_PRESET_NONE is for amd-cppc in passive mode, it +* depends on governor to do performance scaling, setting with +* lowest_nonlinear_perf to ensures performance in P-state range. +*/
Nit: There are again two consecutive comments here.
The active / passive mode distinction mentioned in the comment isn't reflected anywhere in the code. It's the XEN_SYSCTL_CPPC_SET_DESIRED which distinguishes them, yet that flag isn't mentioned in the comment.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 588
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-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; + max_perf = data->caps.highest_perf;
These are still not not both ".lowest_perf", and I still don't understand
- due to the lack of a comment - why that is.
Quoted 30 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +30
-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 ; + 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 )
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 628
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ 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;
Considering these I even less understand what the comment further up is about.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 633
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+return amd_cppc_write_request (cpu, min_perf, des_perf, max_perf, epp); +} + +
Nit (not for the first time, I think): No double blank lines please.
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5
-0@@ -533,6 +651,11 @@ amd_cppc_epp_driver = .exit = amd_cppc_cpufreq_cpu_exit, }; +bool amd_cppc_active (void ) +{ +return amd_cppc_in_use; +} +int __init amd_cppc_register_driver (void ) {int ret;
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_register_driver(void) · line 678
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0@@ -552,6 +675,7 @@ int __init amd_cppc_register_driver(void)/* Remove possible fallback option */ xen_processor_pmbits &= ~XEN_PROCESSOR_PM_PX ; + amd_cppc_in_use = true;
Is this separate flag really needed? Can't you go from xen_processor_pmbits?
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 266
Quoted 10 lines
xen/drivers/acpi/pmstat.c +3
-1@@ -261,7 +261,16 @@ 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,
Overlong line again.
Jan