amd-cppc CPU Performance Scaling Driver
v6 cover amd-cppc CPU Performance Scaling Driver
amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism on modern AMD APU and CPU series in Xen. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which provides finer grain frequency management than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.
amd_cppc driver has 2 operation modes: autonomous (active) mode, and non-autonomous (passive) mode. We register different CPUFreq driver for different modes, "amd-cppc" for passive mode and "amd-cppc-epp" for active mode.
The passive mode leverages common governors such as *ondemand*, *performance*, etc, to manage the performance tuning. While the active mode uses epp to provides a hint to the hardware if software wants to bias toward performance (0x0) or energy efficiency (0xff). CPPC power algorithm in hardware will automatically calculate the runtime workload and adjust the realtime cpu cores frequency according to the power supply and thermal, core voltage and some other hardware conditions.
amd-cppc is enabled on passive mode with a top-level cpufreq=amd-cppc option, while users add extra active flag to select active mode.
With cpufreq=amd-cppc,active, we did a 60s sampling test to see the CPU frequency change, through tweaking the energy_perf preference from xenpm set-cpufreq-cppc powersave to xenpm set-cpufreq-cppc performance. The outputs are as follows:
```
Setting CPU in powersave mode
Sampling and Outputs:
Avg freq 580000 KHz Avg freq 580000 KHz Avg freq 580000 KHz Setting CPU in performance mode Sampling and Outputs: Avg freq 4640000 KHz Avg freq 4220000 KHz Avg freq 4640000 KHz
Penny Zheng (19):
xen/amd: introduce amd_process_freq() to get processor frequency
tools: drop "has_num" condition check for cppc mode
tools: optimize cpufreq average freq print
x86/cpufreq: continue looping other than -EBUSY or successful return xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/cpufreq: make _PSD info common
cpufreq: rename "xen_cppc_para" to "xen_get_cppc_para" xen/cpufreq: rename cppc preset name to
"XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND"
xen/cpufreq: neglect unsupported-mode request from DOM0 xen/cpufreq: introduce new sub-hypercall to propagate CPPC data xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver xen/cpufreq: implement amd-cppc driver for CPPC in passive mode xen/x86: implement amd-cppc-epp driver for CPPC in active mode xen/cpufreq: get performance policy from governor set via xenpm tools/cpufreq: introduce helper to deal with CPPC-related parameters xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op xen/cpufreq: introduce helper cpufreq_in_cppc_passive_mode() xen/cpufreq: bypass governor-related para for amd-cppc-epp xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver
docs/misc/xen-command-line.pandoc | 14 +- tools/include/xenctrl.h | 4 +- tools/libs/ctrl/xc_pm.c | 68 +- tools/misc/xenpm.c | 131 +++- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/amd-cppc.c | 777 ++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 74 ++- xen/arch/x86/acpi/cpufreq/hwp.c | 4 +- xen/arch/x86/cpu/amd.c | 58 +- xen/arch/x86/include/asm/amd.h | 2 + xen/arch/x86/include/asm/msr-index.h | 6 + xen/arch/x86/platform_hypercall.c | 26 +- xen/arch/x86/x86_64/cpufreq.c | 19 + xen/arch/x86/x86_64/platform_hypercall.c | 3 + xen/drivers/acpi/pm-op.c | 56 +- xen/drivers/acpi/pmstat.c | 3 + xen/drivers/cpufreq/cpufreq.c | 308 +++++++-- xen/drivers/cpufreq/utility.c | 15 + xen/include/acpi/cpufreq/cpufreq.h | 19 +- xen/include/acpi/cpufreq/processor_perf.h | 14 +- xen/include/public/platform.h | 26 + xen/include/public/sysctl.h | 29 +- xen/include/xen/pmstat.h | 5 + xen/include/xlat.lst | 1 + 24 files changed, 1522 insertions(+), 141 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
Signature · 1 line
2.34.1
PATCH v6 1/19 xen/amd: introduce amd_process_freq() to get processor frequency
When _CPC table could not provide processor frequency range values for Xen governor, we need to read processor max frequency as anchor point.
So we extract amd cpu core frequency calculation logic from amd_log_freq(), and wrap it as a new helper amd_process_freq().
---
v1 -> v2:
- new commit
---
v3 -> v4
- introduce amd_process_freq()
---
v4 -> v5:
- make amd_process_freq() static to statisfy Misra demand
- change "low_mhz", "nom_mhz" and "hi_mhz" parameter to unsigned int
- fix order of logged frequencies
---
v5 -> v6:
- fix bogus non-zero check
--- xen/arch/x86/cpu/amd.c | 58 +++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 18 deletions(-)
xen/arch/x86/cpu/amd.c +40 -18
@@ -613,14 +613,15 @@ static unsigned int attr_const amd_parse_freq(unsigned int family,return freq; } -void amd_log_freq (const struct cpuinfo_x86 *c) +static void amd_process_freq (const struct cpuinfo_x86 *c, +unsigned int *low_mhz, +unsigned int *nom_mhz, +unsigned int *hi_mhz) {unsigned int idx =0 , h;uint64_t hi, lo, val; -if (c->x86 <0x10 || c->x86 >0x1A || - (c != &boot_cpu_data && - (!opt_cpu_info || (c->apicid & (c->x86_num_siblings -1 ))))) +if (c->x86 <0x10 || c->x86 >0x1A )return ;if (c->x86 <0x17 ) {
@@ -701,20 +702,20 @@ void amd_log_freq(const struct cpuinfo_x86 *c)if (idx && idx < h && !rdmsr_safe (0xC0010064 + idx, val) && (val >>63 ) && - !rdmsr_safe (0xC0010064 , hi) && (hi >>63 )) -printk ("CPU%u: %u (%u ... %u) MHz\n" , -smp_processor_id (), -amd_parse_freq (c->x86, val), -amd_parse_freq (c->x86, lo), -amd_parse_freq (c->x86, hi)); -else if (h && !rdmsr_safe (0xC0010064 , hi) && (hi >>63 )) -printk ("CPU%u: %u ... %u MHz\n" , -smp_processor_id (), -amd_parse_freq (c->x86, lo), -amd_parse_freq (c->x86, hi)); -else -printk ("CPU%u: %u MHz\n" ,smp_processor_id (), -amd_parse_freq (c->x86, lo)); + !rdmsr_safe (0xC0010064 , hi) && (hi >>63 )) { +if (nom_mhz) + *nom_mhz =amd_parse_freq (c->x86, val); +if (low_mhz) + *low_mhz =amd_parse_freq (c->x86, lo); +if (hi_mhz) + *hi_mhz =amd_parse_freq (c->x86, hi); + }else if (h && !rdmsr_safe (0xC0010064 , hi) && (hi >>63 )) { +if (low_mhz) + *low_mhz =amd_parse_freq (c->x86, lo); +if (hi_mhz) + *hi_mhz =amd_parse_freq (c->x86, hi); + }else if (low_mhz) + *low_mhz =amd_parse_freq (c->x86, lo); } void cf_check early_init_amd(struct cpuinfo_x86 *c)
@@ -725,6 +726,27 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)ctxt_switch_levelling (NULL ); } +void amd_log_freq (const struct cpuinfo_x86 *c) +{ +unsigned int low_mhz =0 , nom_mhz =0 , hi_mhz =0 ; + +if (c != &boot_cpu_data && + (!opt_cpu_info || (c->apicid & (c->x86_num_siblings -1 )))) +return ; + +amd_process_freq (c, &low_mhz, &nom_mhz, &hi_mhz); + +if (low_mhz && nom_mhz && hi_mhz) +printk ("CPU%u: %u (%u ... %u) MHz\n" , +smp_processor_id (), + nom_mhz, low_mhz, hi_mhz); +else if (low_mhz && hi_mhz) +printk ("CPU%u: %u ... %u MHz\n" , +smp_processor_id (), low_mhz, hi_mhz); +else if (low_mhz) +printk ("CPU%u: %u MHz\n" ,smp_processor_id (), low_mhz); +} +void amd_init_lfence (struct cpuinfo_x86 *c) {uint64_t value;
Signature · 1 line
2.34.1
PATCH v6 2/19 tools: drop "has_num" condition check for cppc mode
In reply to Penny ZhengIn xenpm get-cpufreq-para <cpuid>, ->freq_num and ->cpu_num checking are tied together via variable "has_num", while ->freq_num only has non-zero value when cpufreq driver in legacy P-states mode.
So we drop the "has_num" condition check, and mirror the ->gov_num check for both ->freq_num and ->cpu_num in xc_get_cpufreq_para().
---
v3 -> v4:
- drop the "has_num" condition check
---
v4 -> v5:
- refactor title and commit
- make all three pieces (xc_hypercall_bounce_pre()) be as similar as possible
---
v5 -> v6:
- move set_xen_guest_handle() up to the bottom of the identical conditional
--- tools/libs/ctrl/xc_pm.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-)
tools/libs/ctrl/xc_pm.c +21 -20
@@ -210,33 +210,36 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,DECLARE_NAMED_HYPERCALL_BOUNCE (scaling_available_governors, user_para->scaling_available_governors, user_para->gov_num *CPUFREQ_NAME_LEN *sizeof (char ),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); -bool has_num = user_para->cpu_num && user_para->freq_num; -if ( has_num ) +if ( (user_para->cpu_num && !user_para->affected_cpus) || + (user_para->freq_num && !user_para->scaling_available_frequencies) || + (user_para->gov_num && !user_para->scaling_available_governors) ) + { + errno =EINVAL ; +return -1 ; + } +if ( user_para->cpu_num ) { -if ( (!user_para->affected_cpus) || - (!user_para->scaling_available_frequencies) || - (user_para->gov_num && !user_para->scaling_available_governors) ) - { - errno =EINVAL ; -return -1 ; - } ret =xc_hypercall_bounce_pre (xch, affected_cpus);if ( ret )return ret; +set_xen_guest_handle (sys_para->affected_cpus, affected_cpus); + } +if ( user_para->freq_num ) + { ret =xc_hypercall_bounce_pre (xch, scaling_available_frequencies);if ( ret ) goto unlock_2; -if ( user_para->gov_num ) - ret =xc_hypercall_bounce_pre (xch, scaling_available_governors); +set_xen_guest_handle (sys_para->scaling_available_frequencies, + scaling_available_frequencies); + } +if ( user_para->gov_num ) + { + ret =xc_hypercall_bounce_pre (xch, scaling_available_governors);if ( ret ) 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->gov_num ) -set_xen_guest_handle (sys_para->scaling_available_governors, - scaling_available_governors); +set_xen_guest_handle (sys_para->scaling_available_governors, + scaling_available_governors); } sysctl.cmd = XEN_SYSCTL_pm_op;
@@ -256,9 +259,7 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid, user_para->gov_num = sys_para->gov_num; } -if ( has_num ) - goto unlock_4; -return ret; + goto unlock_4; }else {
Signature · 1 line
2.34.1
Re: [PATCH v6 02/19] tools: drop "has_num" condition check for cppc mode
Quoted 8 lines · Penny Zheng
In
xenpm get-cpufreq-para <cpuid>, ->freq_num and ->cpu_num checking are tied together via variable "has_num", while ->freq_num only has non-zero value when cpufreq driver in legacy P-states mode.So we drop the "
has_num" condition check, and mirror the ->gov_num check for both ->freq_num and ->cpu_num inxc_get_cpufreq_para().Signed-off-by Penny Zheng <[email protected]>
Re: [PATCH v6 02/19] tools: drop "has_num" condition check for cppc mode
In reply to Penny ZhengQuoted 8 lines · Penny Zheng
In
xenpm get-cpufreq-para <cpuid>, ->freq_num and ->cpu_num checking are tied together via variable "has_num", while ->freq_num only has non-zero value when cpufreq driver in legacy P-states mode.So we drop the "
has_num" condition check, and mirror the ->gov_num check for both ->freq_num and ->cpu_num inxc_get_cpufreq_para().Signed-off-by Penny Zheng <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v6 3/19 tools: optimize cpufreq average freq print
In reply to Penny ZhengUnlike Cx/Px states, for which we need an extra loop to summerize residency ( sum_cx[]/sum_px[]), we could call get_avgfreq_by_cpuid() right before printing. Also, with later introduction of CPPC mode, average frequency print shall not depend on the existence of legacy P-states, so we remove "px_cap" dependancy check.
---
v3 -> v4:
- new commit
---
v4 -> v5:
- refactor title and commit message
- call get_avgfreq_by_cpuid() right before printing
---
v5 -> v6:
- remove "Fixes:xxx"
--- tools/misc/xenpm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/misc/xenpm.c +2 -4
@@ -510,9 +510,6 @@ static void signal_int_handler(int signo) pxstat_start[i].pt[j].residency; } -for ( i =0 ; i < max_cpu_nr; i++ ) -get_avgfreq_by_cpuid (xc_handle, i, &avgfreq[i]); -printf ("Elapsed time (ms): %" PRIu64"\n" , (usec_end - usec_start) /1000UL );for ( i =0 ; i < max_cpu_nr; i++ ) {
@@ -553,7 +550,8 @@ static void signal_int_handler(int signo) res / 1000000UL, 100UL * res / (double)sum_px[i]); } } -if ( px_cap && avgfreq[i] ) +get_avgfreq_by_cpuid (xc_handle, i, &avgfreq[i]); +if ( avgfreq[i] )printf (" Avg freq\t%d\tKHz\n" , avgfreq[i]); }
Signature · 1 line
2.34.1
Re: [PATCH v6 03/19] tools: optimize cpufreq average freq print
Quoted 7 lines · Penny Zheng
Unlike Cx/Px states, for which we need an extra loop to summerize residency ( sum_cx[]/sum_px[]), we could call
get_avgfreq_by_cpuid()right before printing. Also, with later introduction of CPPC mode, average frequency print shall not depend on the existence of legacy P-states, so we remove "px_cap" dependancy check.Signed-off-by Penny Zheng <[email protected]>
Anthony PERARD
Acked-byRe: [PATCH v6 03/19] tools: optimize cpufreq average freq print
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Penny Zheng
Unlike Cx/Px states, for which we need an extra loop to summerize residency ( sum_cx[]/sum_px[]), we could call
get_avgfreq_by_cpuid()right before printing. Also, with later introduction of CPPC mode, average frequency print shall not depend on the existence of legacy P-states, so we remove "px_cap" dependancy check.Signed-off-by Penny Zheng <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v6 4/19 x86/cpufreq: continue looping other than -EBUSY or successful return
In reply to Penny ZhengRight now, only when we failed cpufreq driver registration with -ENODEV, we get the chance to try the fallback option.
There are two code path erroring out other than -ENODEV in cpufreq driver
registration: one is when the driver itself is broken, like missing mandatory hooks, cpufreq_register_driver() will fail with -EINVAL, in which we shall be able to try the fallback option, and the other is -EBUSY due to repeated registration, in which we shall just exit the loop.
So in conclusion, when error code is -EBUSY or successful return, both indicating a proper driver is already registered, we shall bail the loop, other than that, we shall continue to try the fallback option.
---
v5 -> v6:
- new commit
--- xen/arch/x86/acpi/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -150,7 +150,7 @@ static int __init cf_check cpufreq_driver_init(void)break ; } -if ( ret != -ENODEV ) +if ( !ret || ret == -EBUSY )break ; }break ;
Signature · 1 line
2.34.1
Re: [PATCH v6 04/19] x86/cpufreq: continue looping other than -EBUSY or successful return
Quoted 8 lines · Penny Zheng
Right now, only when we failed cpufreq driver registration with
-ENODEV, we get the chance to try the fallback option.
There are two code path erroring out other than-ENODEVin cpufreq driver
registration: one is when the driver itself is broken, like missing mandatory hooks,cpufreq_register_driver()will fail with-EINVAL, in which we shall be able to try the fallback option, and the other is-EBUSYdue to repeated registration, in which we shall just exit the loop.
Quoted 5 lines
So in conclusion, when error code is
-EBUSYor successful return, both indicating a proper driver is already registered, we shall bail the loop, other than that, we shall continue to try the fallback option.Signed-off-by Penny Zheng <[email protected]>
(and perhaps also a Reported-by: or Suggested-by: ...)
PATCH v6 5/19 xen/cpufreq: refactor cmdline "cpufreq=xxx"
In reply to Penny ZhengA helper function handle_cpufreq_cmdline() is introduced to tidy different handling pathes.
We also add a new helper cpufreq_opts_contain() to ignore redundant setting, like "cpufreq=hwp;hwp;xen"
---
v2 -> v3:
- new commit
---
v3 -> v4:
- add one single helper to do the tidy work
- ignore and warn user redundant setting
---
v4 -> v5:
- make "cpufreq_opts_str" static and the string literals end up in .init.rodata.
- use "CPUFREQ_xxx" as array slot index
- blank line between non-fall-through case blocks
---
v5 -> v6:
- change to "while ( count-- )"
- remove unnecessary warning
- add an assertion to ensure not overruning the array
- add ASSERT_UNREACHABLE()
- check ret of handle_cpufreq_cmdline() and error out
--- xen/drivers/cpufreq/cpufreq.c | 59 ++++++++++++++++++++++++------ xen/include/acpi/cpufreq/cpufreq.h | 3 +- 2 files changed, 49 insertions(+), 13 deletions(-)
xen/drivers/cpufreq/cpufreq.c +47 -12
@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen; -enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;static int __init cpufreq_cmdline_parse (const char *s,const char *e); +static bool __init cpufreq_opts_contain (enum cpufreq_xen_opt option) +{ +unsigned int count = cpufreq_xen_cnt; + +while ( count-- ) + { +if ( cpufreq_xen_opts[count] == option ) +return true; + } + +return false; +} + +static int __init handle_cpufreq_cmdline (enum cpufreq_xen_opt option) +{ +int ret =0 ; + +if (cpufreq_opts_contain (option) ) +return 0 ; + + cpufreq_controller = FREQCTL_xen; +ASSERT (cpufreq_xen_cnt <NR_CPUFREQ_OPTS ); + cpufreq_xen_opts[cpufreq_xen_cnt++] = option; +switch ( option ) + { +case CPUFREQ_hwp: +case CPUFREQ_xen: + xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; +break ; + +default : +ASSERT_UNREACHABLE (); + ret = -EINVAL ; +break ; + } + +return ret; +} + static int __init cf_check setup_cpufreq_option(const char *str) {const char *arg =strpbrk (str,",:;" );
@@ -113,21 +154,15 @@ static int __init cf_check setup_cpufreq_option(const char *str)if ( choice >0 || !cmdline_strcmp (str,"xen" ) ) { - xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; - cpufreq_controller = FREQCTL_xen; - cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_xen; - ret =0 ; -if ( arg[0 ] && arg[1 ] ) + ret =handle_cpufreq_cmdline (CPUFREQ_xen); +if ( !ret && arg[0 ] && arg[1 ] ) ret =cpufreq_cmdline_parse (arg +1 , end); }else if (IS_ENABLED (CONFIG_INTEL ) && choice <0 && !cmdline_strcmp (str,"hwp" ) ) { - xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; - cpufreq_controller = FREQCTL_xen; - cpufreq_xen_opts[cpufreq_xen_cnt++] = CPUFREQ_hwp; - ret =0 ; -if ( arg[0 ] && arg[1 ] ) + ret =handle_cpufreq_cmdline (CPUFREQ_hwp); +if ( !ret && arg[0 ] && arg[1 ] ) ret =hwp_cmdline_parse (arg +1 , end); }else
xen/include/acpi/cpufreq/cpufreq.h +2 -1
@@ -27,7 +27,8 @@ enum cpufreq_xen_opt { CPUFREQ_xen, CPUFREQ_hwp, }; -extern enum cpufreq_xen_opt cpufreq_xen_opts[2 ]; +#define NR_CPUFREQ_OPTS 2 +extern enum cpufreq_xen_opt cpufreq_xen_opts[NR_CPUFREQ_OPTS ];extern unsigned int cpufreq_xen_cnt;struct cpufreq_governor ;
Signature · 1 line
2.34.1
Re: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 71
Quoted 13 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +4
-2@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen; -enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;
Given this, isn't the array index 1 initializer quite pointless above? Or else, if you really mean to explicitly fill all slots with CPUFREQ_none (despite that deliberately having numeric value 0), why not "[1 ... NR_CPUFREQ_OPTS - 1] = CPUFREQ_none" (or using ARRAY_SIZE(), as per below)?
Quoted 14 lines
xen/drivers/cpufreq/cpufreq.c +12
-0static 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 LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 96
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +10
-0+ +static int __init handle_cpufreq_cmdline (enum cpufreq_xen_opt option) +{ +int ret =0 ; + +if (cpufreq_opts_contain (option) ) +return 0 ; + + cpufreq_controller = FREQCTL_xen; +ASSERT (cpufreq_xen_cnt <NR_CPUFREQ_OPTS );
This would better use ARRAY_SIZE(), at which point NR_CPUFREQ_OPTS can go away again. What's worse, though, is that on release builds ...
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 97
Quoted 1 line
xen/drivers/cpufreq/cpufreq.c +1
-0+ cpufreq_xen_opts[cpufreq_xen_cnt++] = option;
... you then still overrun this array if something's wrong in this regard.
Jan
RE: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"
[Public]
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:01 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"Quoted 6 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +0
-0@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen;
Quoted 14 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 71
Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +4
-2-enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;Given this, isn't the array index 1 initializer quite pointless above? Or else, if you really mean to explicitly fill all slots with
CPUFREQ_none(despite that deliberately having numeric value 0), why not
"[1 ...NR_CPUFREQ_OPTS- 1] =CPUFREQ_none" (or usingARRAY_SIZE(), as per below)?
The cpufreq_xen_cnt initialized as 1 is to have default CPUFREQ_xen value when there is no "cpufreq=xxx" cmdline option I suppose you are pointing out that the macro NR_CPUFREQ_OPTS is pointless, as we could use ARRAY_SIZE().
Quoted 20 lines
Quoted 20 lines
xen/drivers/cpufreq/cpufreq.c +17
-0static int __init cpufreq_cmdline_parse (const char *s,const char *e); +static bool __init cpufreq_opts_contain (enum cpufreq_xen_opt option) +{ +unsigned int count = cpufreq_xen_cnt; + +while ( count-- ) + { +if ( cpufreq_xen_opts[count] == option ) +return true; + } + +return false; +} + +static int __init handle_cpufreq_cmdline (enum cpufreq_xen_opt option) +{ +int ret =0 ; +
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 96
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5
-0+if (cpufreq_opts_contain (option) ) +return 0 ; + + cpufreq_controller = FREQCTL_xen; +ASSERT (cpufreq_xen_cnt <NR_CPUFREQ_OPTS );This would better use
ARRAY_SIZE(), at which pointNR_CPUFREQ_OPTScan go away again. What's worse, though, is that on release builds ...
Understood, will use ARRAY_SIZE(), and will use if() to error out
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 97
Quoted 1 line
xen/drivers/cpufreq/cpufreq.c +1
-0+ cpufreq_xen_opts[cpufreq_xen_cnt++] = option;... you then still overrun this array if something's wrong in this regard.
Jan
Re: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"
Quoted 26 lines · Zheng
Quoted 11 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:01 PMQuoted 6 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +0
-0@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen;Quoted 14 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 71
Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +4
-2-enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;Given this, isn't the array index 1 initializer quite pointless above? Or else, if you really mean to explicitly fill all slots with
CPUFREQ_none(despite that deliberately having numeric value 0), why not
"[1 ...NR_CPUFREQ_OPTS- 1] =CPUFREQ_none" (or usingARRAY_SIZE(), as per below)?
Quoted 2 lines
The
cpufreq_xen_cntinitialized as 1 is to have defaultCPUFREQ_xenvalue when there is no "cpufreq=xxx" cmdline option I suppose you are pointing out that the macroNR_CPUFREQ_OPTSis pointless, as we could useARRAY_SIZE().
That I'm suggesting further down, yes. But here I'm questioning the array
initializer: As said, I think only slot 0 needs explicit initializing. Or else the initializer would need touching again when the array size is grown. Which would be nice to avoid, providing doing so is correct.
Jan
RE: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"
In reply to Jan Beulich[Public]
Quoted 48 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:01 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; [email protected]
Subject: Re: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 71
Quoted 13 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +4
-2@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen; -enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;Given this, isn't the array index 1 initializer quite pointless above? Or else, if you really mean to explicitly fill all slots with
CPUFREQ_none(despite that deliberately having numeric value 0), why not
"[1 ...NR_CPUFREQ_OPTS- 1] =CPUFREQ_none" (or usingARRAY_SIZE(), as per below)?Quoted 20 lines
xen/drivers/cpufreq/cpufreq.c +17
-0static int __init cpufreq_cmdline_parse (const char *s,const char *e); +static bool __init cpufreq_opts_contain (enum cpufreq_xen_opt option) +{ +unsigned int count = cpufreq_xen_cnt; + +while ( count-- ) + { +if ( cpufreq_xen_opts[count] == option ) +return true; + } + +return false; +} + +static int __init handle_cpufreq_cmdline (enum cpufreq_xen_opt option) +{ +int ret =0 ; +
Quoted 9 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 96
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5
-0+if (cpufreq_opts_contain (option) ) +return 0 ; + + cpufreq_controller = FREQCTL_xen; +ASSERT (cpufreq_xen_cnt <NR_CPUFREQ_OPTS );This would better use
ARRAY_SIZE(), at which pointNR_CPUFREQ_OPTScan go away again. What's worse, though, is that on release builds ...
I found that we already have array index check in setup_cpufreq_option(), before calling handle_cpufreq_cmdline() Then maybe there is no need to do it again here
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 97
Quoted 1 line
xen/drivers/cpufreq/cpufreq.c +1
-0+ cpufreq_xen_opts[cpufreq_xen_cnt++] = option;... you then still overrun this array if something's wrong in this regard.
Jan
Re: [PATCH v6 05/19] xen/cpufreq: refactor cmdline "cpufreq=xxx"
Quoted 54 lines · Zheng
Quoted 45 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:01 PMxen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 71
Quoted 13 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +4
-2@@ -64,12 +64,53 @@ LIST_HEAD_READ_MOSTLY(cpufreq_governor_list);/* set xen as default cpufreq */ enum cpufreq_controller cpufreq_controller = FREQCTL_xen; -enum cpufreq_xen_opt __initdata cpufreq_xen_opts[2 ] = { CPUFREQ_xen, - CPUFREQ_none }; +enum cpufreq_xen_opt __initdata cpufreq_xen_opts[NR_CPUFREQ_OPTS ] = { + CPUFREQ_xen, + CPUFREQ_none +};unsigned int __initdata cpufreq_xen_cnt =1 ;Given this, isn't the array index 1 initializer quite pointless above? Or else, if you really mean to explicitly fill all slots with
CPUFREQ_none(despite that deliberately having numeric value 0), why not
"[1 ...NR_CPUFREQ_OPTS- 1] =CPUFREQ_none" (or usingARRAY_SIZE(), as per below)?Quoted 20 lines
xen/drivers/cpufreq/cpufreq.c +17
-0static int __init cpufreq_cmdline_parse (const char *s,const char *e); +static bool __init cpufreq_opts_contain (enum cpufreq_xen_opt option) +{ +unsigned int count = cpufreq_xen_cnt; + +while ( count-- ) + { +if ( cpufreq_xen_opts[count] == option ) +return true; + } + +return false; +} + +static int __init handle_cpufreq_cmdline (enum cpufreq_xen_opt option) +{ +int ret =0 ; +Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c LIST_HEAD_READ_MOSTLY(cpufreq_governor_list); · line 96
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +5
-0+if (cpufreq_opts_contain (option) ) +return 0 ; + + cpufreq_controller = FREQCTL_xen; +ASSERT (cpufreq_xen_cnt <NR_CPUFREQ_OPTS );This would better use
ARRAY_SIZE(), at which pointNR_CPUFREQ_OPTScan go away again. What's worse, though, is that on release builds ...
Quoted 2 lines
I found that we already have array index check in
setup_cpufreq_option(), before callinghandle_cpufreq_cmdline()Then maybe there is no need to do it again here
Well, you will still need to deal with the release build aspect, as per your earlier reply. At which point you can easily place an ASSERT_UNREACHABLE() there as well.
Jan
PATCH v6 6/19 xen/cpufreq: make _PSD info common
In reply to Penny Zheng_PSD info, consisted of "shared_type" and "struct xen_psd_package", will not only be provided from px-specific "struct xen_processor_performance", but also in CPPC data.
Two new helper functions are introduced to deal with _PSD. They will later be re-used for handling the same data for CPPC.
In the meantime, the following style corrections get applied at the same time:
- add extra space before and after bracket of if()
- remove redundant parenthesis
- no need to put brace for printk() at a seperate line
---
v3 -> v4:
- new commit
---
v4 -> v5:
- let check_psd_pminfo() pass in "uint32_t shared_type"
- replace unnessary parameter "uint32_t init" with processor_pminfo[cpu]->init
- replace structure copy with const pointer delivery through "const struct xen_psd_package **"
- blank line between non-fall-through switch-case blocks
- remove unnessary "define XEN_CPUPERF_SHARED_TYPE_xxx" movement
---
v5 -> v6:
- remove redundant local variable "domain_info_ptr"
- change check_psd_pminfo() to bool return
- Comment wants to start with a capital letter
- reword title and commit message
--- xen/drivers/cpufreq/cpufreq.c | 100 ++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 29 deletions(-)
xen/drivers/cpufreq/cpufreq.c +71 -29
@@ -226,9 +226,29 @@ int cpufreq_limit_change(unsigned int cpu)return __cpufreq_set_policy (data, &policy); } -int cpufreq_add_cpu (unsigned int cpu) +static int get_psd_info (unsigned int cpu,uint32_t *shared_type, +const struct xen_psd_package **domain_info) {int ret =0 ; + +switch ( processor_pminfo[cpu]->init ) + { +case XEN_PX_INIT : + *shared_type = processor_pminfo[cpu]->perf.shared_type; + *domain_info = &processor_pminfo[cpu]->perf.domain_info; +break ; + +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +int cpufreq_add_cpu (unsigned int cpu) +{ +int ret;unsigned int firstcpu;unsigned int dom, domexist =0 ;unsigned int hw_all =0 ;
@@ -236,14 +256,13 @@ int cpufreq_add_cpu(unsigned int cpu)struct cpufreq_dom *cpufreq_dom =NULL ;struct cpufreq_policy new_policy;struct cpufreq_policy *policy; -struct processor_performance *perf; +const struct xen_psd_package *domain_info; +uint32_t shared_type;/* to protect the case when Px was not controlled by xen */ if ( !processor_pminfo[cpu] || !cpu_online (cpu) )return -EINVAL ; - perf = &processor_pminfo[cpu]->perf; -if ( !(processor_pminfo[cpu]->init &XEN_PX_INIT ) )return -EINVAL ;
@@ -253,10 +272,14 @@ int cpufreq_add_cpu(unsigned int cpu)if (per_cpu (cpufreq_cpu_policy, cpu))return 0 ; -if (perf->shared_type ==CPUFREQ_SHARED_TYPE_HW ) + ret =get_psd_info (cpu, &shared_type, &domain_info); +if ( ret ) +return ret; + +if ( shared_type ==CPUFREQ_SHARED_TYPE_HW ) hw_all =1 ; - dom = perf->domain_info.domain; + dom = domain_info->domain;list_for_each (pos, &cpufreq_dom_list_head) { cpufreq_dom = list_entry(pos, struct cpufreq_dom, node);
@@ -279,21 +302,27 @@ int cpufreq_add_cpu(unsigned int cpu) cpufreq_dom->dom = dom;list_add (&cpufreq_dom->node, &cpufreq_dom_list_head); }else { +uint32_t firstcpu_shared_type; +const struct xen_psd_package *firstcpu_domain_info; +/* domain sanity check under whatever coordination type */ firstcpu =cpumask_first (cpufreq_dom->map); -if ((perf->domain_info.coord_type != - processor_pminfo[firstcpu]->perf.domain_info.coord_type) || - (perf->domain_info.num_processors != - processor_pminfo[firstcpu]->perf.domain_info.num_processors)) { - + ret =get_psd_info (firstcpu, &firstcpu_shared_type, + &firstcpu_domain_info); +if ( ret ) +return ret; + +if ( domain_info->coord_type != firstcpu_domain_info->coord_type || + domain_info->num_processors != + firstcpu_domain_info->num_processors ) + {printk (KERN_WARNING "cpufreq fail to add CPU%d:" "incorrect _PSD(%" PRIu64":%" PRIu64"), " "expect(%" PRIu64"/%" PRIu64")\n" , - cpu, perf->domain_info.coord_type, - perf->domain_info.num_processors, - processor_pminfo[firstcpu]->perf.domain_info.coord_type, - processor_pminfo[firstcpu]->perf.domain_info.num_processors - ); + cpu, domain_info->coord_type, + domain_info->num_processors, + firstcpu_domain_info->coord_type, + firstcpu_domain_info->num_processors);return -EINVAL ; } }
@@ -339,8 +368,9 @@ int cpufreq_add_cpu(unsigned int cpu)if (ret) goto err1; -if (hw_all || (cpumask_weight (cpufreq_dom->map) == - perf->domain_info.num_processors)) { +if ( hw_all ||cpumask_weight (cpufreq_dom->map) == + domain_info->num_processors ) + {memcpy (&new_policy, policy,sizeof (struct cpufreq_policy ));/*
@@ -395,29 +425,33 @@ err0:int cpufreq_del_cpu (unsigned int cpu) { +int ret;unsigned int dom, domexist =0 ;unsigned int hw_all =0 ;struct list_head *pos;struct cpufreq_dom *cpufreq_dom =NULL ;struct cpufreq_policy *policy; -struct processor_performance *perf; +uint32_t shared_type; +const struct xen_psd_package *domain_info;/* to protect the case when Px was not controlled by xen */ if ( !processor_pminfo[cpu] || !cpu_online (cpu) )return -EINVAL ; - perf = &processor_pminfo[cpu]->perf; -if ( !(processor_pminfo[cpu]->init &XEN_PX_INIT ) )return -EINVAL ;if (!per_cpu (cpufreq_cpu_policy, cpu))return 0 ; -if (perf->shared_type ==CPUFREQ_SHARED_TYPE_HW ) + ret =get_psd_info (cpu, &shared_type, &domain_info); +if ( ret ) +return ret; + +if ( shared_type ==CPUFREQ_SHARED_TYPE_HW ) hw_all =1 ; - dom = perf->domain_info.domain; + dom = domain_info->domain; policy =per_cpu (cpufreq_cpu_policy, cpu);list_for_each (pos, &cpufreq_dom_list_head) {
@@ -433,8 +467,8 @@ int cpufreq_del_cpu(unsigned int cpu)/* for HW_ALL, stop gov for each core of the _PSD domain */ /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain */ -if (hw_all || (cpumask_weight (cpufreq_dom->map) == - perf->domain_info.num_processors)) +if ( hw_all ||cpumask_weight (cpufreq_dom->map) == + domain_info->num_processors )__cpufreq_governor (policy,CPUFREQ_GOV_STOP );cpufreq_statistic_exit (cpu);
@@ -499,6 +533,17 @@ static void print_PPC(unsigned int platform_limit)printk ("\t_PPC: %d\n" , platform_limit); } +static bool check_psd_pminfo (uint32_t shared_type) +{ +/* Check domain coordination */ +if ( shared_type !=CPUFREQ_SHARED_TYPE_ALL && + shared_type !=CPUFREQ_SHARED_TYPE_ANY && + shared_type !=CPUFREQ_SHARED_TYPE_HW ) +return false; + +return true; +} +int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf) {int ret =0 , cpu;
@@ -581,10 +626,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)if ( perf->flags &XEN_PX_PSD ) { -/* check domain coordination */ -if ( perf->shared_type !=CPUFREQ_SHARED_TYPE_ALL && - perf->shared_type !=CPUFREQ_SHARED_TYPE_ANY && - perf->shared_type !=CPUFREQ_SHARED_TYPE_HW ) +if ( !check_psd_pminfo (perf->shared_type) ) { ret = -EINVAL ; goto out;
Signature · 1 line
2.34.1
Re: [PATCH v6 06/19] xen/cpufreq: make _PSD info common
Quoted 4 lines · Penny Zheng
_PSDinfo, consisted of "shared_type" and "structxen_psd_package", will not only be provided from px-specific "structxen_processor_performance", but also in CPPC data.
Quoted 8 lines
Two new helper functions are introduced to deal with
_PSD. They will later be re-used for handling the same data for CPPC.
In the meantime, the following style corrections get applied at the same time:
- add extra space before and after bracket ofif()
- remove redundant parenthesis
- no need to put brace forprintk()at a seperate lineSigned-off-by Penny Zheng <[email protected]>
with one further remark:
xen/drivers/cpufreq/cpufreq.c int cpufreq_limit_change(unsigned int cpu) · line 229
Quoted 8 lines
xen/drivers/cpufreq/cpufreq.c +1
-1@@ -226,9 +226,29 @@ int cpufreq_limit_change(unsigned int cpu)return __cpufreq_set_policy (data, &policy); } -int cpufreq_add_cpu (unsigned int cpu) +static int get_psd_info(unsigned int cpu, uint32_t *shared_type,
Here any below I question the need to use a fixed-width type. "unsigned int" will do fine here, I expect, and that's what ./CODING_STYLE also mandates in such cases. I may take the liberty and change that while committing.
Jan
PATCH v6 7/19 cpufreq: rename "xen_cppc_para" to "xen_get_cppc_para"
In reply to Penny ZhengAs we are going to add "struct xen_cppc_para" in "struct xen_sysctl_pm_op" as a new xenpm sub-op later to specifically dealing with CPPC-info, we need to follow the naming pattern, to change the struct name to "xen_get_cppc_para", which is more suitable than "xen_cppc_para".
---
v5 -> v6:
- new commit
--- tools/include/xenctrl.h | 2 +- xen/arch/x86/acpi/cpufreq/hwp.c | 2 +- xen/include/acpi/cpufreq/cpufreq.h | 2 +- xen/include/public/sysctl.h | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
tools/include/xenctrl.h +1 -1
@@ -1906,7 +1906,7 @@ int xc_smt_disable(xc_interface *xch);*/ typedef struct xen_userspace xc_userspace_t ;typedef struct xen_ondemand xc_ondemand_t ; -typedef struct xen_cppc_para xc_cppc_para_t ; +typedef struct xen_get_cppc_para xc_cppc_para_t ;struct xc_get_cpufreq_para {/* IN/OUT variable */
xen/arch/x86/acpi/cpufreq/hwp.c +1 -1
@@ -525,7 +525,7 @@ hwp_cpufreq_driver = {#ifdef CONFIG_PM_OP int get_hwp_para (unsigned int cpu, -struct xen_cppc_para *cppc_para) +struct xen_get_cppc_para *cppc_para) {const struct hwp_drv_data *data =per_cpu (hwp_drv_data, cpu);
xen/include/acpi/cpufreq/cpufreq.h +1 -1
@@ -267,7 +267,7 @@ static inline bool hwp_active(void) { return false; }#endif int get_hwp_para (unsigned int cpu, -struct xen_cppc_para *cppc_para); +struct xen_get_cppc_para *cppc_para);int set_hwp_para (struct cpufreq_policy *policy,struct xen_set_cppc_para *set_cppc);
xen/include/public/sysctl.h +3 -3
@@ -336,7 +336,7 @@ struct xen_ondemand {uint32_t up_threshold; }; -struct xen_cppc_para { +struct xen_get_cppc_para {/* OUT */ /* activity_window supported if set */ #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW (1 << 0)
@@ -442,7 +442,7 @@ struct xen_set_cppc_para { XEN_SYSCTL_CPPC_SET_ACT_WINDOW )/* IN/OUT */ uint32_t set_params;/* bitflags for valid values */ -/* See comments in struct xen_cppc_para. */ +/* See comments in struct xen_get_cppc_para. */ /* IN */ uint32_t minimum;uint32_t maximum;
@@ -490,7 +490,7 @@ struct xen_get_cpufreq_para {struct xen_ondemand ondemand; } u; } s; -struct xen_cppc_para cppc_para; +struct xen_get_cppc_para cppc_para; } u;int32_t turbo_enabled;
Signature · 1 line
2.34.1
Re: [PATCH v6 07/19] cpufreq: rename "xen_cppc_para" to "xen_get_cppc_para"
Quoted 6 lines · Penny Zheng
As we are going to add "struct
xen_cppc_para" in "structxen_sysctl_pm_op" as a new xenpm sub-op later to specifically dealing with CPPC-info, we need to follow the naming pattern, to change the struct name to "xen_get_cppc_para", which is more suitable than "xen_cppc_para".Signed-off-by Penny Zheng <[email protected]>
Re: [PATCH v6 07/19] cpufreq: rename "xen_cppc_para" to "xen_get_cppc_para"
In reply to Penny ZhengQuoted 6 lines · Penny Zheng
As we are going to add "struct
xen_cppc_para" in "structxen_sysctl_pm_op" as a new xenpm sub-op later to specifically dealing with CPPC-info, we need to follow the naming pattern, to change the struct name to "xen_get_cppc_para", which is more suitable than "xen_cppc_para".Signed-off-by Penny Zheng <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v6 8/19 xen/cpufreq: rename cppc preset name to "XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND"
In reply to Penny Zheng"ondemand" is more suitable to describe a preset in which epp value is set with medium(CPPC_ENERGY_PERF_BALANCE), showing no preference over performance or powersave, minimum with lowest and maximum with highest.
---
v5 -> v6:
- new commit
--- tools/misc/xenpm.c | 4 ++-- xen/arch/x86/acpi/cpufreq/hwp.c | 2 +- xen/include/public/sysctl.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
tools/misc/xenpm.c +2 -2
@@ -1445,9 +1445,9 @@ static int parse_cppc_opts(xc_set_cppc_para_t *set_cppc, int *cpuid, set_cppc->set_params =XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE ; i++; } -else if (strcasecmp (argv[i],"balance" ) ==0 ) +else if (strcasecmp (argv[i],"ondemand" ) ==0 ) { - set_cppc->set_params =XEN_SYSCTL_CPPC_SET_PRESET_BALANCE ; + set_cppc->set_params =XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND ; i++; }
xen/arch/x86/acpi/cpufreq/hwp.c +1 -1
@@ -610,7 +610,7 @@ int set_hwp_para(struct cpufreq_policy *policy, data->desired =0 ;break ; -case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE : +case XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND : data->minimum = data->hw.lowest; data->maximum = data->hw.highest; data->activity_window =0 ;
xen/include/public/sysctl.h +1 -1
@@ -430,7 +430,7 @@ struct xen_set_cppc_para {#define XEN_SYSCTL_CPPC_SET_ACT_WINDOW (1U << 4)#define XEN_SYSCTL_CPPC_SET_PRESET_MASK 0xf0000000U#define XEN_SYSCTL_CPPC_SET_PRESET_NONE 0x00000000U -#define XEN_SYSCTL_CPPC_SET_PRESET_BALANCE 0x10000000U +#define XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND 0x10000000U#define XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE 0x20000000U#define XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE 0x30000000U#define XEN_SYSCTL_CPPC_SET_PARAM_MASK \
Signature · 1 line
2.34.1
Re: [PATCH v6 08/19] xen/cpufreq: rename cppc preset name to "XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND"
Quoted 5 lines · Penny Zheng
"ondemand" is more suitable to describe a preset in which epp value is set with
medium(CPPC_ENERGY_PERF_BALANCE), showing no preference over performance or powersave, minimum with lowest and maximum with highest.Signed-off-by Penny Zheng <[email protected]>
PATCH v6 9/19 xen/cpufreq: neglect unsupported-mode request from DOM0
In reply to Penny ZhengDOM0 could deliever whatever performance statistic (Px, _CPC) it parses, it is Xen's responsibility to decide which one it shall accept.
Xen rely on XEN_PROCESSOR_PM_xxx flag to tell which mode ( Px or CPPC ) current cpufreq driver supports, and accepts relative info. It will neglect unsupported-mode request and yields success.
---
v5 -> v6:
- new commit
--- xen/arch/x86/platform_hypercall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
xen/arch/x86/platform_hypercall.c +6 -1
@@ -539,9 +539,14 @@ ret_t do_platform_op(case XEN_PM_PX :if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) { - ret = -ENOSYS ; +/* +* Neglect Px-info when registered cpufreq driver +* isn't in Px mode +*/ + ret =0 ;break ; } + ret =set_px_pminfo (op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);break ;
Signature · 1 line
2.34.1
Re: [PATCH v6 09/19] xen/cpufreq: neglect unsupported-mode request from DOM0
Quoted 7 lines · Penny Zheng
DOM0 could deliever whatever performance statistic (Px,
_CPC) it parses, it is Xen's responsibility to decide which one it shall accept.
Xen rely onXEN_PROCESSOR_PM_xxxflag to tell which mode ( Px or CPPC ) current cpufreq driver supports, and accepts relative info. It will neglect unsupported-mode request and yields success.Signed-off-by Penny Zheng <[email protected]>
PATCH v6 10/19 xen/cpufreq: 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 frequency, like ondemand, the _CPC table can optionally provide processor frequency range values, Lowest frequency and Nominal frequency, to let OS use Lowest Frequency/ Performance and Nominal Frequency/Performance as anchor points to create linear mapping of CPPC performance to CPU frequency.
As Xen is uncapable of parsing the ACPI dynamic table, we'd like to introduce a new sub-hypercall "XEN_PM_CPPC" to propagate required CPPC data from dom0 kernel to Xen.
In the according handler set_cppc_pminfo(), we do _CPC and _PSD sanitization check, as both _PSD and _CPC info are necessary for correctly initializing cpufreq cores in CPPC mode.
Users shall be warned that if we failed at this point,
no fallback scheme, like legacy P-state could be switched to.
A new flag "XEN_CPPC_INIT" is also introduced for cpufreq core initialised in CPPC mode. Then all .init flag checking shall be updated to consider "XEN_CPPC_INIT" too.
We want to bypass construction of px statistic info in cpufreq_statistic_init() for CPPC mode, while not bypassing cpufreq_statistic_lock initialization for a good reason. The same check is unnecessary for cpufreq_statistic_exit(), since it has already been covered by px statistic variable "cpufreq_statistic_data" check
---
v1 -> v2:
- Remove unnecessary figure braces
- Pointer-to-const for print_CPPC and set_cppc_pminfo
- Structure allocation shall use xvzalloc()
- Unnecessary memcpy(), and change it to a (type safe) structure assignment
- Add comment for struct xen_processor_cppc, and keep the chosen fields in the order _CPC has them
- Obey to alphabetic sorting, and prefix compat structures with ? instead of !
---
v2 -> v3:
- Trim too long line
- Re-place set_cppc_pminfo() past set_px_pminfo()
- Fix Misra violations: Declaration and definition ought to agree in parameter names
- Introduce a new flag XEN_PM_CPPC to reflect processor initialised in CPPC mode
---
v3 -> v4:
- Refactor commit message
- make "acpi_id" unsigned int
- Add warning message when cpufreq_cpu_init() failed only under debug mode
- Expand "struct xen_processor_cppc" to include _PSD and shared type
- add sanity check for ACPI CPPC data
---
v4 -> v5:
- remove the ordering check between lowest_nonlinear_perf and lowest_perf
- use printk_once() for cppc perf value warning
- complement comment for cppc perf value check
- remove redundant check and pointless parenthesizing
- use dprintk() for warning under #ifndef NDEBUG
- refactor warning message when having non-zero ret of cpufreq_cpu_init()
- With introduction of "struct xen_psd_package" in "struct xen_processor_cppc", use ! and the respective XLAT_* macro(s) to wrap.
---
v5 -> v6:
- remove unnecessary input parameter check
- use print_once() instead of dprintk() and reword the log message
- adhere to designated comment style
- relative ordering shall be consistent between different declaration groups
- add alphabetically in xlat.lst
- in get_cpufreq_para(), add must-zero check for ->perf.state_count in CPPC mode
--- xen/arch/x86/platform_hypercall.c | 5 + xen/arch/x86/x86_64/cpufreq.c | 19 ++++ xen/arch/x86/x86_64/platform_hypercall.c | 3 + xen/drivers/acpi/pm-op.c | 5 +- xen/drivers/cpufreq/cpufreq.c | 126 +++++++++++++++++++++- xen/include/acpi/cpufreq/processor_perf.h | 4 +- xen/include/public/platform.h | 26 +++++ xen/include/xen/pmstat.h | 5 + xen/include/xlat.lst | 1 + 9 files changed, 189 insertions(+), 5 deletions(-)
xen/arch/x86/platform_hypercall.c +5 -0
@@ -577,6 +577,11 @@ ret_t do_platform_op(break ; } +case XEN_PM_CPPC : + ret =set_cppc_pminfo (op->u.set_pminfo.id, + &op->u.set_pminfo.u.cppc_data); +break ; +default : ret = -EINVAL ;break ;
xen/arch/x86/x86_64/cpufreq.c +19 -0
@@ -54,3 +54,22 @@ int compat_set_px_pminfo(uint32_t acpi_id,return set_px_pminfo (acpi_id, xen_perf); } + +int compat_set_cppc_pminfo (unsigned int acpi_id, +const struct compat_processor_cppc *cppc_data) + +{ +struct xen_processor_cppc *xen_cppc; +unsigned long xlat_page_current; + +xlat_malloc_init (xlat_page_current); + + xen_cppc =xlat_malloc_array (xlat_page_current, + struct xen_processor_cppc, 1); +if (unlikely (xen_cppc ==NULL ) ) +return -EFAULT ; + +XLAT_processor_cppc (xen_cppc, cppc_data); + +return set_cppc_pminfo (acpi_id, xen_cppc); +}
xen/arch/x86/x86_64/platform_hypercall.c +3 -0
@@ -14,6 +14,9 @@ EMIT_FILE;#define efi_get_info efi_compat_get_info#define efi_runtime_call (x) efi_compat_runtime_call(x) +#define xen_processor_cppc compat_processor_cppc +#define set_cppc_pminfo compat_set_cppc_pminfo +#define xen_processor_performance compat_processor_performance#define set_px_pminfo compat_set_px_pminfo
xen/drivers/acpi/pm-op.c +3 -2
@@ -91,7 +91,8 @@ 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) || + ((pmpt->init &XEN_CPPC_INIT ) && pmpt->perf.state_count) || !policy || !policy->governor )return -EINVAL ;
@@ -351,7 +352,7 @@ int do_pm_op(struct xen_sysctl_pm_op *op)case CPUFREQ_PARA :if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) )return -ENODEV ; -if ( !pmpt || !(pmpt->init &XEN_PX_INIT ) ) +if ( !pmpt || !(pmpt->init & (XEN_PX_INIT |XEN_CPPC_INIT )) )return -EINVAL ;break ; }
xen/drivers/cpufreq/cpufreq.c +124 -2
156 lines not on this page · raw message
xen/include/acpi/cpufreq/processor_perf.h +3 -1
@@ -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);
@@ -43,6 +44,7 @@ struct processor_pminfo {uint32_t acpi_id;uint32_t id;struct processor_performance perf; +struct xen_processor_cppc cppc_data;uint32_t init; };
xen/include/public/platform.h +26 -0
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4/* Px sub info type */ #define XEN_PX_PCT 1
@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PX_PPC 4#define XEN_PX_PSD 8 +/* CPPC sub info type */ +#define XEN_CPPC_PSD 1 +#define XEN_CPPC_CPC 2 +struct xen_power_register {uint32_t space_id;uint32_t bit_width;
@@ -457,6 +462,26 @@ struct xen_processor_performance {typedef struct xen_processor_performance xen_processor_performance_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t); +struct xen_processor_cppc { +uint8_t flags;/* IN: XEN_CPPC_xxx */ +uint8_t pad[3 ]; +/* +* IN: 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; +uint32_t shared_type;/* IN: XEN_CPUPERF_SHARED_TYPE_xxx */ +struct xen_psd_package domain_info;/* IN: _PSD */ +}; +typedef struct xen_processor_cppc xen_processor_cppc_t ; +struct xenpf_set_processor_pminfo {/* IN variables */ uint32_t id;/* ACPI CPU ID */
@@ -465,6 +490,7 @@ struct xenpf_set_processor_pminfo {struct xen_processor_power power;/* Cx: _CST/_CSD */ struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/_PSD */ XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ +xen_processor_cppc_t cppc_data;/* CPPC: _CPC and _PSD */ } u; };typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t ;
xen/include/xen/pmstat.h +5 -0
@@ -7,12 +7,17 @@int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf);long set_cx_pminfo (uint32_t acpi_id,struct xen_processor_power *power); +int set_cppc_pminfo (unsigned int acpi_id, +const struct xen_processor_cppc *cppc_data);#ifdef CONFIG_COMPAT struct compat_processor_performance ;int compat_set_px_pminfo (uint32_t acpi_id,struct compat_processor_performance *perf);struct compat_processor_power ;long compat_set_cx_pminfo (uint32_t acpi_id,struct compat_processor_power *power); +struct compat_processor_cppc ; +int compat_set_cppc_pminfo (unsigned int acpi_id, +const struct compat_processor_cppc *cppc_data);#endif uint32_t pmstat_get_cx_nr (unsigned int cpu);
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 v6 10/19] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data
xen/drivers/acpi/pm-op.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 95
Quoted 9 lines · Penny Zheng
xen/drivers/acpi/pm-op.c +2
-1@@ -91,7 +91,8 @@ 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) || + ((pmpt->init & XEN_CPPC_INIT) && pmpt->perf.state_count) ||
Nit: I think this would be neater if the PX_INIT part was also moved to its own line.
Quoted 25 lines
xen/drivers/acpi/pm-op.c +21
-0@@ -697,6 +703,122 @@ int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc)return ret; } +static void print_CPPC (const struct xen_processor_cppc *cppc_data) +{ +printk ("\t_CPC: highest_perf=%u, lowest_perf=%u, " +"nominal_perf=%u, lowest_nonlinear_perf=%u, " +"nominal_mhz=%uMHz, lowest_mhz=%uMHz\n" , + cppc_data->cpc.highest_perf, cppc_data->cpc.lowest_perf, + cppc_data->cpc.nominal_perf, cppc_data->cpc.lowest_nonlinear_perf, + cppc_data->cpc.nominal_mhz, cppc_data->cpc.lowest_mhz); +} + +int set_cppc_pminfo (unsigned int acpi_id, +const struct xen_processor_cppc *cppc_data) +{ +int ret =0 , cpuid; +struct processor_pminfo *pm_info; + + cpuid =get_cpu_id (acpi_id); +if ( cpuid <0 ) + { + ret = -EINVAL ; + goto out;
xen/drivers/acpi/pm-op.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 736
Quoted 10 lines
xen/drivers/acpi/pm-op.c +10
-0+ } + +if ( cppc_data->pad[0 ] || cppc_data->pad[1 ] || cppc_data->pad[2 ] ) + { + ret = -EINVAL ; + goto out; + } + +if ( cpufreq_verbose ) + printk("Set CPU acpi_id(%u) cpuid(%d) CPPC State info:\n",
May I suggest "Set CPU%d (ACPI ID %u) CPPC state info:\n"
Quoted 9 lines
xen/drivers/acpi/pm-op.c +9
-0+ acpi_id, cpuid); + + pm_info = processor_pminfo[cpuid]; +if ( !pm_info ) + { + pm_info = xvzalloc(struct processor_pminfo); +if ( !pm_info ) + { + ret = -ENOMEM ;
xen/drivers/acpi/pm-op.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 755
Quoted 10 lines
xen/drivers/acpi/pm-op.c +10
-0+ goto out; + } + processor_pminfo[cpuid] = pm_info; + } + pm_info->acpi_id = acpi_id; + pm_info->id = cpuid; + pm_info->cppc_data = *cppc_data; + +if ( cppc_data->flags &XEN_CPPC_PSD ) +if ( !check_psd_pminfo (cppc_data->shared_type) )
Please convert these into a single if().
Quoted 9 lines
xen/drivers/acpi/pm-op.c +9
-0+ { + ret = -EINVAL ; + goto out; + } + +if ( cppc_data->flags &XEN_CPPC_CPC ) + { + if ( cppc_data->cpc.highest_perf == 0 || + cppc_data->cpc.highest_perf > UINT8_MAX ||
xen/drivers/acpi/pm-op.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 774
Quoted 10 lines
xen/drivers/acpi/pm-op.c +10
-0+ cppc_data->cpc.nominal_perf ==0 || + cppc_data->cpc.nominal_perf >UINT8_MAX || + cppc_data->cpc.lowest_nonlinear_perf ==0 || + cppc_data->cpc.lowest_nonlinear_perf >UINT8_MAX || + cppc_data->cpc.lowest_perf ==0 || + cppc_data->cpc.lowest_perf >UINT8_MAX || + cppc_data->cpc.lowest_perf > + cppc_data->cpc.lowest_nonlinear_perf || + cppc_data->cpc.lowest_nonlinear_perf > + cppc_data->cpc.nominal_perf ||
Indentation is a little odd here. Best may be to use parentheses:
cppc_data->cpc.lowest_perf > UINT8_MAX ||
(cppc_data->cpc.lowest_perf >
cppc_data->cpc.lowest_nonlinear_perf) ||
(cppc_data->cpc.lowest_nonlinear_perf >
cppc_data->cpc.nominal_perf) ||Otherwise, strictly speaking, no extra indentation should be used. I can see though that this would hamper readability, so the next best alternative would appear to be to make the extra indentation a proper level (i.e. 4 blanks):
cppc_data->cpc.lowest_perf > UINT8_MAX ||
cppc_data->cpc.lowest_perf >
cppc_data->cpc.lowest_nonlinear_perf ||
cppc_data->cpc.lowest_nonlinear_perf >
cppc_data->cpc.nominal_perf ||Quoted 6 lines
xen/drivers/acpi/pm-op.c +6
-0+ cppc_data->cpc.nominal_perf > cppc_data->cpc.highest_perf ) +/* +* Right now, Xen doesn't actually use highest_perf/nominal_perf/ +* lowest_nonlinear_perf/lowest_perf values read from ACPI _CPC +* table. Xen reads CPPC capability MSR to get these four values. +* So warning is enough.
xen/drivers/acpi/pm-op.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 790
Quoted 10 lines
xen/drivers/acpi/pm-op.c +10
-0+*/ +printk_once (XENLOG_WARNING +"Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u), nominal(%u), highest(%u)\n" , + cppc_data->cpc.lowest_perf, + cppc_data->cpc.lowest_nonlinear_perf, + cppc_data->cpc.nominal_perf, + cppc_data->cpc.highest_perf); + +/* lowest_mhz and nominal_mhz are optional value */ +if ( cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )
If they're optional, what if lowest_mhz is provided but nominal_mhz isn't? Wouldn't the warning needlessly trigger in that case?
Quoted 15 lines
xen/drivers/acpi/pm-op.c +15
-0+ { +printk_once (XENLOG_WARNING +"Broken CPPC freq values: lowest(%u), nominal(%u)\n" , + cppc_data->cpc.lowest_mhz, + cppc_data->cpc.nominal_mhz); +/* Re-set with zero values, instead of keeping invalid values */ + pm_info->cppc_data.cpc.nominal_mhz =0 ; + pm_info->cppc_data.cpc.lowest_mhz =0 ; + } + } + +if ( cppc_data->flags == (XEN_CPPC_PSD |XEN_CPPC_CPC ) ) + { +if ( cpufreq_verbose ) + {
xen/drivers/acpi/pm-op.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 815
Quoted 10 lines
xen/drivers/acpi/pm-op.c +10
-0+print_PSD (&pm_info->cppc_data.domain_info); +print_CPPC (&pm_info->cppc_data); + } + + pm_info->init =XEN_CPPC_INIT ; + ret =cpufreq_cpu_init (cpuid); +if ( ret ) +printk_once (XENLOG_WARNING +"CPU%u failed amd-cppc mode init; use \"cpufreq=xen\" instead" , + cpuid);
cpuid is still int, so wants printing with %d.
Quoted 11 lines
xen/include/public/platform.h +1
-0@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4/* Px sub info type */ #define XEN_PX_PCT 1
xen/include/public/platform.h DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); · line 376
Quoted 6 lines
xen/include/public/platform.h +3
-0@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PX_PPC 4#define XEN_PX_PSD 8 +/* CPPC sub info type */ +#define XEN_CPPC_PSD 1 +#define XEN_CPPC_CPC 2
As per this, ...
xen/include/public/platform.h struct xen_processor_performance { · line 466
Quoted 6 lines
xen/include/public/platform.h +2
-0@@ -457,6 +462,26 @@ struct xen_processor_performance {typedef struct xen_processor_performance xen_processor_performance_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t); +struct xen_processor_cppc { +uint8_t flags;/* IN: XEN_CPPC_xxx */
... it's a type that's living here, not a collection of flags. Any reason the field isn't named "type"?
xen/include/public/platform.h struct xen_processor_performance { · line 479
Quoted 13 lines
xen/include/public/platform.h +13
-0+uint8_t pad[3 ]; +/* +* IN: 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;
What, again, was the reason to wrap these into a sub-struct?
Jan
RE: [PATCH v6 10/19] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data
[Public]
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:39 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 v6 10/19] xen/cpufreq: introduce new sub-hypercall to propagate CPPC dataxen/drivers/cpufreq/cpufreq.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc)
Quoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ cppc_data->cpc.nominal_perf > cppc_data->cpc.highest_perf ) +/* +* Right now, Xen doesn't actually use highest_perf/nominal_perf/ +* lowest_nonlinear_perf/lowest_perf values read from ACPI _CPC +* table. Xen reads CPPC capability MSR to get these four values. +* So warning is enough. +*/ + printk_once(XENLOG_WARNING + "Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u),nominal(%u), highest(%u)\n",
xen/drivers/cpufreq/cpufreq.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 790
Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +7
-0+ cppc_data->cpc.lowest_perf, + cppc_data->cpc.lowest_nonlinear_perf, + cppc_data->cpc.nominal_perf, + cppc_data->cpc.highest_perf); + +/* lowest_mhz and nominal_mhz are optional value */ +if ( cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )
Quoted 3 lines
If they're optional, what if
lowest_mhzis provided butnominal_mhzisn't? Wouldn't the warning needlessly trigger in that case?
Yes, only both are provided, this check is meaningful
+ if ( cppc_data->cpc.nominal_mhz &&
+ cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )
Quoted 24 lines
Quoted 11 lines
xen/include/public/platform.h +1
-0@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4/* Px sub info type */ #define XEN_PX_PCT 1xen/include/public/platform.h DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); · line 376
Quoted 6 lines
xen/include/public/platform.h +3
-0@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PX_PPC 4#define XEN_PX_PSD 8 +/* CPPC sub info type */ +#define XEN_CPPC_PSD 1 +#define XEN_CPPC_CPC 2As per this, ...
Quoted 4 lines
xen/include/public/platform.h +0
-0@@ -457,6 +462,26 @@ struct xen_processor_performance { typedefstruct xen_processor_performance xen_processor_performance_t;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t);
Quoted 6 lines
xen/include/public/platform.h struct xen_processor_performance { · line 466
Quoted 2 lines
xen/include/public/platform.h +2
-0+struct xen_processor_cppc { +uint8_t flags;/* IN: XEN_CPPC_xxx */ ... it's a type that's living here, not a collection of flags. Any reason the field isn't named "type"?
It is a collection of flags. Only when both XEN_CPPC_PSD and XEN_CPPC_CPC are set, we could run cpufreq_cpu_init() to initialize cpufreq core.
Quoted 14 lines
xen/include/public/platform.h struct xen_processor_performance { · line 479
Quoted 13 lines
xen/include/public/platform.h +13
-0+uint8_t pad[3 ]; +/* +* IN: 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;
Quoted 1 line
What, again, was the reason to wrap these into a sub-struct?
I want to make these fields differentiated from the other two (shared_type and domain_info), as sub-struct cpc contains _CPC field info, and the other two contains _PSD info
Quoted 2 lines
Jan
Re: [PATCH v6 10/19] xen/cpufreq: introduce new sub-hypercall to propagate CPPC data
Quoted 65 lines · Zheng
[Public]
Quoted 31 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 16, 2025 11:39 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 v6 10/19] xen/cpufreq: introduce new sub-hypercall to propagate CPPC dataxen/drivers/cpufreq/cpufreq.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc)
Quoted 9 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +9
-0+ cppc_data->cpc.nominal_perf > cppc_data->cpc.highest_perf ) +/* +* Right now, Xen doesn't actually use highest_perf/nominal_perf/ +* lowest_nonlinear_perf/lowest_perf values read from ACPI _CPC +* table. Xen reads CPPC capability MSR to get these four values. +* So warning is enough. +*/ + printk_once(XENLOG_WARNING + "Broken CPPC perf values: lowest(%u), nonlinear_lowest(%u),nominal(%u), highest(%u)\n",
xen/drivers/cpufreq/cpufreq.c int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32) pdc) · line 790
Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +7
-0+ cppc_data->cpc.lowest_perf, + cppc_data->cpc.lowest_nonlinear_perf, + cppc_data->cpc.nominal_perf, + cppc_data->cpc.highest_perf); + +/* lowest_mhz and nominal_mhz are optional value */ +if ( cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )Quoted 3 lines
If they're optional, what if
lowest_mhzis provided butnominal_mhzisn't? Wouldn't the warning needlessly trigger in that case?Yes, only both are provided, this check is meaningful
(quoted diff) +2
-0+ if ( cppc_data->cpc.nominal_mhz && + cppc_data->cpc.lowest_mhz > cppc_data->cpc.nominal_mhz )Quoted 25 lines
Quoted 12 lines
xen/include/public/platform.h +1
-0@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4/* Px sub info type */ #define XEN_PX_PCT 1xen/include/public/platform.h DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t); · line 376
Quoted 6 lines
xen/include/public/platform.h +3
-0@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PX_PPC 4#define XEN_PX_PSD 8 +/* CPPC sub info type */ +#define XEN_CPPC_PSD 1 +#define XEN_CPPC_CPC 2As per this, ...
Quoted 4 lines
xen/include/public/platform.h +0
-0@@ -457,6 +462,26 @@ struct xen_processor_performance { typedefstruct xen_processor_performance xen_processor_performance_t;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t);
Quoted 7 lines
Quoted 5 lines
xen/include/public/platform.h struct xen_processor_performance { · line 466
Quoted 2 lines
xen/include/public/platform.h +2
-0+struct xen_processor_cppc { +uint8_t flags;/* IN: XEN_CPPC_xxx */ ... it's a type that's living here, not a collection of flags. Any reason the field isn't named "type"?
It is a collection of flags. Only when both
XEN_CPPC_PSDandXEN_CPPC_CPCare set, we could runcpufreq_cpu_init()to initialize cpufreq core.
Hmm, right. The next legitimate XEN_CPPC_* value to use would be 4, not 3. That's not visible from how things are defined, though. May I suggest that you use
/* CPPC sub info type */
#define XEN_CPPC_PSD (1U << 0)
#define XEN_CPPC_CPC (1U << 1)
instead then?
Jan
PATCH v6 11/19 xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
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. All hooks for amd-cppc driver are transiently missing, and we temporarily make registration fail with -EOPNOTSUPP here. It will be fixed along with the implementation.
New xen-pm internal flag XEN_PROCESSOR_PM_CPPC is introduced, to stand for cpufreq driver in CPPC mode. We define XEN_PROCESSOR_PM_CPPC 0x100, as it is the next value to use after 8-bits wide public xen-pm options. We also add sanity check on compile time. All XEN_PROCESSOR_PM_xxx checking shall be updated to consider "XEN_PROCESSOR_PM_CPPC" too.
XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX are firstly set when Xen parsed relative driver signature from xen cmdline, and will become exclusive after cpufreq driver registration. It is because that platform could not support both or mixed mode (CPPC & legacy Px) operations, and only one cpufreq driver could be registerd in Xen at one time, such as on AMD, it is either amd-cppc or legacy P-states driver.
Xen rely on XEN_PROCESSOR_PM_CPPC flag to tell current cpufreq driver is in CPPC mode, and accepts relative hypercall. It will neglect Px request and yields success.
---
v1 -> v2:
- Obey to alphabetic sorting and also strict it with CONFIG_AMD
- Remove unnecessary empty comment line
- Use __initconst_cf_clobber for pre-filled structure cpufreq_driver
- Make new switch-case code apply to Hygon CPUs too
- Change ENOSYS with EOPNOTSUPP
- Blanks around binary operator
- Change all amd_/-pstate defined values to amd_/-cppc
---
v2 -> v3
- refactor too long lines
- Make sure XEN_PROCESSOR_PM_PX and XEN_PROCESSOR_PM_CPPC incompatible flags after cpufreq register registrantion
---
v3 -> v4:
- introduce XEN_PROCESSOR_PM_CPPC in xen internal header
- complement "Hygon" in log message
- remove unnecessary if()
- grow cpufreq_xen_opts[] array
---
v4 -> v5:
- remove XEN_PROCESSOR_PM_xxx flag sanitization from individual driver
- prefer ! over "== 0" in purely boolean contexts
- Blank line between non-fall-through case blocks
- add build-time checking between internal and public XEN_PROCESSOR_PM_* values
- define XEN_PROCESSOR_PM_CPPC with 0x100, as it is the next value to use after public interface, and public mask SIF_PM_MASK is 8 bits wide.
- as Dom0 will send the CPPC/Px data whenever it could, the return value shall be 0 instead of -ENOSYS/EOPNOTSUP when platform doesn't require these data.
---
v5 -> v6:
- do not register the driver when all hooks are NULL
- refactor the subject and commit message
- move pruning of xen_processor_pmbits into generic space
- add comment and build-time check for XEN_PROCESSOR_PM_CPPC
--- docs/misc/xen-command-line.pandoc | 7 ++- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/amd-cppc.c | 59 +++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 72 ++++++++++++++++++++++- xen/arch/x86/platform_hypercall.c | 14 +++++ xen/drivers/acpi/pm-op.c | 3 +- xen/drivers/acpi/pmstat.c | 3 + xen/drivers/cpufreq/cpufreq.c | 11 ++++ xen/include/acpi/cpufreq/cpufreq.h | 6 +- xen/include/acpi/cpufreq/processor_perf.h | 10 ++++ 10 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
docs/misc/xen-command-line.pandoc +5 -2
@@ -515,7 +515,7 @@ If set, force use of the performance counters for oprofile, rather than detectin available support. ### cpufreq -> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]]` +> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[verbose]]` > Default: `xen`
@@ -526,7 +526,7 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. * `<maxfreq>` and `<minfreq>` are integers which represent max and min processor frequencies respectively. * `verbose` option can be included as a string or also as `verbose=<integer>` - for `xen`. It is a boolean for `hwp`. + for `xen`. It is a boolean for `hwp` and `amd-cppc`. * `hwp` selects Hardware-Controlled Performance States (HWP) on supported Intel hardware. HWP is a Skylake+ feature which provides better CPU power management. The default is disabled. If `hwp` is selected, but hardware
@@ -534,6 +534,9 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. * `<hdc>` is a boolean to enable Hardware Duty Cycling (HDC). HDC enables the processor to autonomously force physical package components into idle state. The default is enabled, but the option only applies when `hwp` is enabled. +* `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC) + on supported AMD hardware to provide finer grained frequency control + mechanism. The default is disabled. There is also support for `;`-separated fallback options: `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if
xen/arch/x86/acpi/cpufreq/Makefile +1 -0
@@ -1,4 +1,5 @@ obj-$(CONFIG_INTEL) += acpi.o +obj-$(CONFIG_AMD) += amd-cppc.o obj-y += cpufreq.o obj-$(CONFIG_INTEL) += hwp.o obj-$(CONFIG_AMD) += powernow.o
xen/arch/x86/acpi/cpufreq/amd-cppc.c new file +59 -0
59 lines not on this page · raw message
xen/arch/x86/acpi/cpufreq/cpufreq.c +70 -2
97 lines not on this page · raw message
xen/arch/x86/platform_hypercall.c +14 -0
@@ -546,6 +546,8 @@ ret_t do_platform_op( ret =0 ;break ; } +/* Xen doesn't support mixed mode */ +ASSERT (!(xen_processor_pmbits &XEN_PROCESSOR_PM_CPPC )); ret =set_px_pminfo (op->u.set_pminfo.id, &op->u.set_pminfo.u.perf);break ;
@@ -578,6 +580,18 @@ ret_t do_platform_op( }case XEN_PM_CPPC : +if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_CPPC ) ) + { +/* +* Neglect CPPC-info when registered cpufreq driver +* isn't in CPPC mode +*/ + ret =0 ; +break ; + } +/* Xen doesn't support mixed mode */ +ASSERT (!(xen_processor_pmbits &XEN_PROCESSOR_PM_PX )); + ret =set_cppc_pminfo (op->u.set_pminfo.id, &op->u.set_pminfo.u.cppc_data);break ;
xen/drivers/acpi/pm-op.c +2 -1
@@ -350,7 +350,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)switch ( op->cmd &PM_PARA_CATEGORY_MASK ) {case CPUFREQ_PARA : -if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) ) +if ( !(xen_processor_pmbits & (XEN_PROCESSOR_PM_PX | +XEN_PROCESSOR_PM_CPPC )) )return -ENODEV ;if ( !pmpt || !(pmpt->init & (XEN_PX_INIT |XEN_CPPC_INIT )) )return -EINVAL ;
xen/drivers/acpi/pmstat.c +3 -0
@@ -107,6 +107,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);
xen/drivers/cpufreq/cpufreq.c +11 -0
@@ -98,6 +98,10 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) cpufreq_xen_opts[cpufreq_xen_cnt++] = option;switch ( option ) { +case CPUFREQ_amd_cppc: + xen_processor_pmbits |=XEN_PROCESSOR_PM_CPPC ; +break ; +case CPUFREQ_hwp:case CPUFREQ_xen: xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ;
@@ -166,6 +170,13 @@ static int __init cf_check setup_cpufreq_option(const char *str)if ( !ret && arg[0 ] && arg[1 ] ) ret =hwp_cmdline_parse (arg +1 , end); } +else if (IS_ENABLED (CONFIG_AMD ) && choice <0 && + !cmdline_strcmp (str,"amd-cppc" ) ) + { + ret =handle_cpufreq_cmdline (CPUFREQ_amd_cppc); +if ( !ret && arg[0 ] && arg[1 ] ) + ret =amd_cppc_cmdline_parse (arg +1 , end); + }else ret = -EINVAL ;
xen/include/acpi/cpufreq/cpufreq.h +5 -1
@@ -26,8 +26,9 @@ enum cpufreq_xen_opt { CPUFREQ_none, CPUFREQ_xen, CPUFREQ_hwp, + CPUFREQ_amd_cppc, }; -#define NR_CPUFREQ_OPTS 2 +#define NR_CPUFREQ_OPTS 3extern enum cpufreq_xen_opt cpufreq_xen_opts[NR_CPUFREQ_OPTS ];extern unsigned int cpufreq_xen_cnt;struct cpufreq_governor ;
@@ -273,4 +274,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 +10 -0
@@ -5,6 +5,16 @@#include <public/sysctl.h> #include <xen/acpi.h> +/* +* Internal xen-pm options +* They are extension to public xen-pm options (XEN_PROCESSOR_PM_xxx) defined +* in public/platform.h, guarded by SIF_PM_MASK +*/ +#define XEN_PROCESSOR_PM_CPPC 0x100 +#if XEN_PROCESSOR_PM_CPPC &MASK_EXTR (~0 ,SIF_PM_MASK ) +# error "XEN_PROCESSOR_PM_CPPC shall not occupy bits reserved for public xen-pm options" +#endif +#define XEN_CPPC_INIT 0x40000000U#define XEN_PX_INIT 0x80000000U
Signature · 1 line
2.34.1
Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 131
Quoted 7 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_check cpufreq_driver_init(void)if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;
Pointless initializer; both for() loops set i to 0. But also see further down.
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-1@@ -157,9 +164,70 @@ 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 ;
The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver ();
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10
-0+break ; + +case CPUFREQ_none: + ret =0 ; +break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;
... here.
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+ } + +if ( !ret || ret == -EBUSY ) +break ; + } +break ;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 210
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +9
-0} + +/* +* After successful cpufreq driver registeration, XEN_PROCESSOR_PM_CPPC +* and XEN_PROCESSOR_PM_PX shall become exclusive flags. +*/ +if ( !ret ) + { +ASSERT (i < cpufreq_xen_cnt); + switch ( cpufreq_xen_opts[i] )
Hmm, this is using the the initializer of i that I commented on. I think there's another default: case missing, where you simply "return 0" (to retain prior behavior). But again see also yet further down.
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +4
-0+ { +case CPUFREQ_amd_cppc: + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_PX ; +break ;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 224
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +10
-0+ +case CPUFREQ_hwp: +case CPUFREQ_xen: + xen_processor_pmbits &= ~XEN_PROCESSOR_PM_CPPC ; +break ; + +default : +break ; + } + }else if ( ret != -EBUSY )
Nit (style): Closing brace wants to be on its own line.
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 230
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+/* +* No cpufreq driver gets registered, clear both +* XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX +*/ + xen_processor_pmbits &= ~(XEN_PROCESSOR_PM_CPPC | +XEN_PROCESSOR_PM_PX );
Yet more hmm - this path you want to get through for the case mentioned above. But only this code; specifically not the "switch ( cpufreq_xen_opts[i] )", which really is "switch ( cpufreq_xen_opts[0] )" in that case, and that's pretty clearly wrong to evaluate in then.
xen/drivers/acpi/pmstat.c int cpufreq_statistic_init(unsigned int cpu) · line 115
Quoted 12 lines
xen/drivers/acpi/pmstat.c +3
-0@@ -107,6 +107,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);
This change could do with a code comment, I think.
xen/drivers/cpufreq/cpufreq.c static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) · line 107
Quoted 13 lines
xen/drivers/cpufreq/cpufreq.c +4
-0@@ -98,6 +98,10 @@ static int __init handle_cpufreq_cmdline(enum cpufreq_xen_opt option) cpufreq_xen_opts[cpufreq_xen_cnt++] = option;switch ( option ) { +case CPUFREQ_amd_cppc: + xen_processor_pmbits |=XEN_PROCESSOR_PM_CPPC ; +break ; +case CPUFREQ_hwp:case CPUFREQ_xen: xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ;
Unless they're clearly "more important" (tm), please can insertions like this not be done at the top of a switch() (or whatever else it is)? You don't do so ...
xen/drivers/cpufreq/cpufreq.c static int __init cf_check setup_cpufreq_option(const char *str) · line 181
Quoted 13 lines
xen/drivers/cpufreq/cpufreq.c +7
-0@@ -166,6 +170,13 @@ static int __init cf_check setup_cpufreq_option(const char *str)if ( !ret && arg[0 ] && arg[1 ] ) ret =hwp_cmdline_parse (arg +1 , end); } +else if (IS_ENABLED (CONFIG_AMD ) && choice <0 && + !cmdline_strcmp (str,"amd-cppc" ) ) + { + ret =handle_cpufreq_cmdline (CPUFREQ_amd_cppc); +if ( !ret && arg[0 ] && arg[1 ] ) + ret =amd_cppc_cmdline_parse (arg +1 , end); + }else ret = -EINVAL ;
... here, for example.
Jan
RE: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
[Public]
Quoted 55 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 132
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_checkcpufreq_driver_init (void ) if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;Pointless initializer; both
for()loops set i to 0. But also see further down.xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,9 +164,70 @@ 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;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+if ( !IS_ENABLED (CONFIG_AMD ) ) + { + ret = -ENODEV ; +break ; + } + ret = -ENOENT ;The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver (); +break ; + +case CPUFREQ_none: + ret =0 ;
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;... here.
Are we suggesting moving
"
if ( !IS_ENABLED(CONFIG_AMD) )
{
ret = -ENODEV;
break;
}" here? In which case, When CONFIG_AMD=n and users doesn't provide "cpufreq=xxx", we will have cpufreq_xen_cnt initialized as 1 and cpufreq_xen_opts[0] = CPUFREQ_xen. powernow_register_driver() hence gets invoked. The thing is that we don't have stub for it and it is compiled under CONFIG_AMD I suggest to change to use #ifdef CONFIG_AMD code wrapping
Quoted 31 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void)
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +9
-0+ } + +if ( !ret || ret == -EBUSY ) +break ; + } +break ; } + +/* +* After successful cpufreq driver registeration,
XEN_PROCESSOR_PM_CPPCxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 210
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+* and XEN_PROCESSOR_PM_PX shall become exclusive flags. +*/ +if ( !ret ) + { +ASSERT (i < cpufreq_xen_cnt); + switch ( cpufreq_xen_opts[i] )Hmm, this is using the the initializer of i that I commented on. I think there's another default: case missing, where you simply "return 0" (to retain prior behavior). But again see also yet further down.
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 230
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+/* +* No cpufreq driver gets registered, clear both +* XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX +*/ + xen_processor_pmbits &= ~(XEN_PROCESSOR_PM_CPPC | +XEN_PROCESSOR_PM_PX );
Quoted 5 lines
Yet more hmm - this path you want to get through for the case mentioned above. But only this code; specifically not the "switch ( cpufreq_xen_opts[i] )", which really is "switch ( cpufreq_xen_opts[0] )" in that case, and that's pretty clearly wrong to evaluate in then.
Correct me if I understand you wrongly:
The above "case missing" , are we talking about is entering "case CPUFREQ_none" ?
IMO, it may never be entered. If users doesn't provide "cpufreq=xxx", we will have cpufreq_xen_cnt initialized as 1 and cpufreq_xen_opts[0] = CPUFREQ_xen. That is, we will have px states as default driver. Even if we have failed px-driver initialization, with cpufreq_xen_cnt limited to 1, we will not enter CPUFREQ_none. CPUFREQ_none only could be set when users explicitly set "cpufreq=disabled/none/0", but in which case, cpufreq_controller will be set with FREQCTL_none. And the whole cpufreq_driver_init() is under " cpufreq_controller == FREQCTL_xen " condition
Or "case missing" is referring entering default case? In which case, we will have -ENOENT errno. As we have ret=-ENOENT in the very beginning
Quoted 1 line
Jan
Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
Quoted 113 lines · Zheng
[Public]
Quoted 55 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 132
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_checkcpufreq_driver_init (void ) if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;Pointless initializer; both
for()loops set i to 0. But also see further down.xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,9 +164,70 @@ 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;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+if ( !IS_ENABLED (CONFIG_AMD ) ) + { + ret = -ENODEV ; +break ; + } + ret = -ENOENT ;The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver (); +break ; + +case CPUFREQ_none: + ret =0 ;Quoted 9 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;... here.
Are we suggesting moving
"if ( !IS_ENABLED(CONFIG_AMD) ) { ret = -ENODEV; break; }" here? In which case, When
CONFIG_AMD=nand users doesn't provide "cpufreq=xxx", we will havecpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen.powernow_register_driver()hence gets invoked. The thing is that we don't have stub for it and it is compiled underCONFIG_AMDI suggest to change to use #ifdefCONFIG_AMDcode wrappingQuoted 31 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void)
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +9
-0+ } + +if ( !ret || ret == -EBUSY ) +break ; + } +break ; } + +/* +* After successful cpufreq driver registeration,
XEN_PROCESSOR_PM_CPPCxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 210
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+* and XEN_PROCESSOR_PM_PX shall become exclusive flags. +*/ +if ( !ret ) + { +ASSERT (i < cpufreq_xen_cnt); + switch ( cpufreq_xen_opts[i] )Hmm, this is using the the initializer of i that I commented on. I think there's another default: case missing, where you simply "return 0" (to retain prior behavior). But again see also yet further down.
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 230
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+/* +* No cpufreq driver gets registered, clear both +* XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX +*/ + xen_processor_pmbits &= ~(XEN_PROCESSOR_PM_CPPC | +XEN_PROCESSOR_PM_PX );Quoted 4 lines
Yet more hmm - this path you want to get through for the case mentioned above. But only this code; specifically not the "switch ( cpufreq_xen_opts[i] )", which really is "switch ( cpufreq_xen_opts[0] )" in that case, and that's pretty clearly wrong to evaluate in then.
Quoted 5 lines
Correct me if I understand you wrongly:
The above "case missing" , are we talking about is entering "caseCPUFREQ_none" ?
IMO, it may never be entered. If users doesn't provide "cpufreq=xxx", we will havecpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen. That is, we will have px states as default driver. Even if we have failed px-driver initialization, withcpufreq_xen_cntlimited to 1, we will not enterCPUFREQ_none.CPUFREQ_noneonly could be set when users explicitly set "cpufreq=disabled/none/0", but in which case,cpufreq_controllerwill be set withFREQCTL_none. And the wholecpufreq_driver_init()is under "cpufreq_controller==FREQCTL_xen" condition
Or "case missing" is referring entering default case? In which case, we will have-ENOENTerrno. As we have ret=-ENOENT in the very beginning
Sorry, this is hard to follow. Plus I think I made the main requirement quite
clear: You want to "retain prior behavior" for all cases you don't deliberately change to accommodate the new driver. Plus you want to watch out for pre- existing incorrect behavior: Rather than proliferating any, such would want adjusting.
Jan
RE: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
[Public]
Quoted 146 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 4: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]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverQuoted 75 lines · Zheng
[Public]
Quoted 56 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 132
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_checkcpufreq_driver_init (void ) if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;Pointless initializer; both
for()loops set i to 0. But also see further down.xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,9 +164,70 @@ 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;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+if ( !IS_ENABLED (CONFIG_AMD ) ) + { + ret = -ENODEV ; +break ; + } + ret = -ENOENT ;The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver (); +break ; + +case CPUFREQ_none: + ret =0 ;Quoted 9 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;... here.
Are we suggesting moving
"if ( !IS_ENABLED(CONFIG_AMD) ) { ret = -ENODEV; break; }Quoted 28 lines
" here? In which case, When
CONFIG_AMD=nand users doesn't provide "cpufreq=xxx", we will havecpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen.powernow_register_driver()hence gets invoked. The thing is that we don't have stub for it and it is compiled underCONFIG_AMDI suggest to change to use #ifdefCONFIG_AMDcode wrappingQuoted 21 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void)
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +9
-0+ } + +if ( !ret || ret == -EBUSY ) +break ; + } +break ; } + +/* +* After successful cpufreq driver registeration,
XEN_PROCESSOR_PM_CPPCxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 210
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+* and XEN_PROCESSOR_PM_PX shall become exclusive flags. +*/ +if ( !ret ) + { +ASSERT (i < cpufreq_xen_cnt); + switch ( cpufreq_xen_opts[i] )Hmm, this is using the the initializer of i that I commented on. I think there's another default: case missing, where you simply "return 0" (to
retain prior behavior).
Quoted 10 lines
Quoted 10 lines
But again see also yet further down.
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+/* +* No cpufreq driver gets registered, clear both +* XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX +*/ + xen_processor_pmbits &= ~(XEN_PROCESSOR_PM_CPPC | +XEN_PROCESSOR_PM_PX );Quoted 7 lines
Quoted 4 lines
Yet more hmm - this path you want to get through for the case mentioned above. But only this code; specifically not the "switch ( cpufreq_xen_opts[i] )", which really is "switch ( cpufreq_xen_opts[0] )" in that case, and that's pretty clearly wrong to evaluate in then.
Correct me if I understand you wrongly:
The above "case missing" , are we talking about is entering "case
CPUFREQ_none" ?Quoted 1 line
IMO, it may never be entered. If users doesn't provide "cpufreq=xxx", we will
have
cpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen. That is, we will have px states as default driver. Even if we have failed px-driver initialization, withcpufreq_xen_cntlimited to 1, we will not enterCPUFREQ_none.Quoted 6 lines
CPUFREQ_noneonly could be set when users explicitly set "cpufreq=disabled/none/0", but in which case,cpufreq_controllerwill be set withFREQCTL_none. And the wholecpufreq_driver_init()is under "cpufreq_controller==FREQCTL_xen" condition Or "case missing" is referring entering default case? In which case, we will have-ENOENTerrno. As we have ret=-ENOENT in the very beginning
Quoted 5 lines
Sorry, this is hard to follow. Plus I think I made the main requirement quite
clear: You want to "retain prior behavior" for all cases you don't deliberately change to accommodate the new driver. Plus you want to watch out for pre- existing incorrect behavior: Rather than proliferating any, such would want adjusting.
I was trying to follow "there's another default: case missing, where you simply "return 0" (to retain prior behavior ) ",
The missing "default :" is referring the one for "switch ( boot_cpu_data.x86_vendor )"? (I thought it referred " switch ( cpufreq_xen_opts[i] ) " ....) It is a pre- existing incorrect behavior which I shall create a new commit to fix it firstly
I'll add an -ENOENTRY initializer for ret at the very beginning , and complement the missing default: entry with "Unsupported vendor..." error log
Quoted 1 line
Jan
Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
Quoted 154 lines · Zheng
[Public]
Quoted 146 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Monday, August 4, 2025 4: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]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverQuoted 75 lines · Zheng
[Public]
Quoted 56 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 132
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_checkcpufreq_driver_init (void ) if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;Pointless initializer; both
for()loops set i to 0. But also see further down.xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,9 +164,70 @@ 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;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+if ( !IS_ENABLED (CONFIG_AMD ) ) + { + ret = -ENODEV ; +break ; + } + ret = -ENOENT ;The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver (); +break ; + +case CPUFREQ_none: + ret =0 ;Quoted 9 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;... here.
Are we suggesting moving
"if ( !IS_ENABLED(CONFIG_AMD) ) { ret = -ENODEV; break; }Quoted 28 lines
" here? In which case, When
CONFIG_AMD=nand users doesn't provide "cpufreq=xxx", we will havecpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen.powernow_register_driver()hence gets invoked. The thing is that we don't have stub for it and it is compiled underCONFIG_AMDI suggest to change to use #ifdefCONFIG_AMDcode wrappingQuoted 21 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void)
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +9
-0+ } + +if ( !ret || ret == -EBUSY ) +break ; + } +break ; } + +/* +* After successful cpufreq driver registeration,
XEN_PROCESSOR_PM_CPPCxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 210
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+* and XEN_PROCESSOR_PM_PX shall become exclusive flags. +*/ +if ( !ret ) + { +ASSERT (i < cpufreq_xen_cnt); + switch ( cpufreq_xen_opts[i] )Hmm, this is using the the initializer of i that I commented on. I think there's another default: case missing, where you simply "return 0" (to
retain prior behavior).
Quoted 10 lines
Quoted 10 lines
But again see also yet further down.
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+/* +* No cpufreq driver gets registered, clear both +* XEN_PROCESSOR_PM_CPPC and XEN_PROCESSOR_PM_PX +*/ + xen_processor_pmbits &= ~(XEN_PROCESSOR_PM_CPPC | +XEN_PROCESSOR_PM_PX );Quoted 7 lines
Quoted 4 lines
Yet more hmm - this path you want to get through for the case mentioned above. But only this code; specifically not the "switch ( cpufreq_xen_opts[i] )", which really is "switch ( cpufreq_xen_opts[0] )" in that case, and that's pretty clearly wrong to evaluate in then.
Correct me if I understand you wrongly:
The above "case missing" , are we talking about is entering "case
CPUFREQ_none" ?Quoted 1 line
IMO, it may never be entered. If users doesn't provide "cpufreq=xxx", we will
have
cpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen. That is, we will have px states as default driver. Even if we have failed px-driver initialization, withcpufreq_xen_cntlimited to 1, we will not enterCPUFREQ_none.Quoted 6 lines
CPUFREQ_noneonly could be set when users explicitly set "cpufreq=disabled/none/0", but in which case,cpufreq_controllerwill be set withFREQCTL_none. And the wholecpufreq_driver_init()is under "cpufreq_controller==FREQCTL_xen" condition Or "case missing" is referring entering default case? In which case, we will have-ENOENTerrno. As we have ret=-ENOENT in the very beginningQuoted 5 lines
Sorry, this is hard to follow. Plus I think I made the main requirement quite
clear: You want to "retain prior behavior" for all cases you don't deliberately change to accommodate the new driver. Plus you want to watch out for pre- existing incorrect behavior: Rather than proliferating any, such would want adjusting.
Quoted 4 lines
I was trying to follow "there's another default: case missing, where you simply "return 0" (to retain prior behavior ) ",
The missing "default :" is referring the one for "switch ( boot_cpu_data.x86_vendor )"? (I thought it referred " switch ( cpufreq_xen_opts[i] ) " ....) It is a pre- existing incorrect behavior which I shall create a new commit to fix it firstly
I'll add an-ENOENTRYinitializer for ret at the very beginning , and complement the missing default: entry with "Unsupported vendor..." error log
Yes, I was referring to pre-existing code which I think wants adjusting in order to then accommodate your changes there.
Jan
Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driver
In reply to Penny, ZhengQuoted 67 lines · Zheng
[Public]
Quoted 55 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 12:00 AM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 11/19] xen/x86: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc driverxen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 132
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/cpufreq.c +1
-0@@ -128,12 +128,14 @@ static int __init cf_checkcpufreq_driver_init (void ) if ( cpufreq_controller == FREQCTL_xen ) { +unsigned int i =0 ;Pointless initializer; both
for()loops set i to 0. But also see further down.xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check · line 161
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +0
-1@@ -157,9 +164,70 @@ 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;
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 172
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+if ( !IS_ENABLED (CONFIG_AMD ) ) + { + ret = -ENODEV ; +break ; + } + ret = -ENOENT ;The code structure is sufficiently different from the Intel counterpart for this to perhaps better move ...
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +14
-0+for ( i =0 ; i < cpufreq_xen_cnt; i++ ) + { +switch ( cpufreq_xen_opts[i] ) + { +case CPUFREQ_xen: + ret =powernow_register_driver (); +break ; + +case CPUFREQ_amd_cppc: + ret =amd_cppc_register_driver (); +break ; + +case CPUFREQ_none: + ret =0 ;Quoted 9 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c static int __init cf_check cpufreq_driver_init(void) · line 193
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/cpufreq.c +6
-0+break ; + +default : +printk (XENLOG_WARNING +"Unsupported cpufreq driver for vendor AMD or Hygon\n" ); +break ;... here.
Quoted 8 lines
Are we suggesting moving
"if ( !IS_ENABLED(CONFIG_AMD) ) { ret = -ENODEV; break; }" here?
That's what I said, didn't I?
Quoted 2 lines
In which case, When
CONFIG_AMD=nand users doesn't provide "cpufreq=xxx", we will havecpufreq_xen_cntinitialized as 1 and cpufreq_xen_opts[0] =CPUFREQ_xen.powernow_register_driver()hence gets invoked. The thing is that we don't have stub for it and it is compiled underCONFIG_AMDI suggest to change to use #ifdefCONFIG_AMDcode wrapping
Perhaps necessary, yes. As you know, we generally prefer IS_ENABLED() where possible, but when not possible, #ifdef is certainly okay to use.
Jan
PATCH v6 12/19 xen/cpufreq: implement amd-cppc driver for CPPC in passive mode
In reply to Penny Zhengamd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which is a finer grain frequency management than legacy ACPI hardware P-States.
Current AMD CPU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states, while the new amd-cppc allows a more flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.
"amd-cppc" driver is responsible for implementing CPPC in passive mode, which still leverages Xen governors such as *ondemand*, *performance*, etc, to calculate the performance hints. In the future, we will introduce an advanced active mode to enable autonomous performence level selection.
---
v1 -> v2:
- re-construct union caps and req to have anonymous struct instead
- avoid "else" when the earlier if() ends in an unconditional control flow statement
- Add check to avoid chopping off set bits from cast
- make pointers pointer-to-const wherever possible
- remove noisy log
- exclude families before 0x17 before CPPC-feature MSR op
- remove useless variable helpers
- use xvzalloc and XVFREE
- refactor error handling as ENABLE bit can only be cleared by reset
---
v2 -> v3:
- Move all MSR-definations to msr-index.h and follow the required style
- Refactor opening figure braces for struct/union
- Sort overlong lines throughout the series
- Make offset/res int covering underflow scenario
- Error out when amd_max_freq_mhz isn't set
- Introduce amd_get_freq(name) macro to decrease redundancy
- Supported CPU family checked ahead of smp-function
- Nominal freq shall be checked between the [min, max]
- Use APERF/MPREF to calculate current frequency
- Use amd_cppc_cpufreq_cpu_exit() to tidy error path
---
v3 -> v4:
- verbose print shall come with a CPU number
- deal with res <= 0 in amd_cppc_khz_to_perf()
- introduce a single helper amd_get_lowest_or_nominal_freq() to cover both lowest and nominal scenario
- reduce abuse of wrmsr_safe()/rdmsr_safe() with wrmsrl()/rdmsrl()
- move cf_check from amd_cppc_write_request() to amd_cppc_write_request_msrs()
- add comment to explain why setting non_linear_lowest in passive mode
- add check to ensure perf values in
lowest <= non_linear_lowest <= nominal <= highset
- refactor comment for "data->err != 0" scenario
- use "data->err" instead of -ENODEV
- add U suffixes for all msr macro
---
v4 -> v5:
- all freq-values shall be unsigned int type
- remove shortcuts as it is rarely taken
- checking cpc.nominal_mhz and cpc.lowest_mhz are non-zero values is enough
- drop the explicit type cast
- null pointer check is in no need for internal functions
- change amd_get_lowest_or_nominal_freq() to amd_get_cpc_freq()
- clarifying function-wide that the calculated frequency result is to be in kHz
- use array notation
- with cpu_has_cppc check, no need to do cpu family check
---
v5 -> v6
- replace "AMD_CPPC" with "AMD-CPPC" in message
- add equation(mul,div) non-zero check
- replace -EINVAL with -EOPNOTSUPP
- refactor comment
--- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 407 ++++++++++++++++++++++++++- xen/arch/x86/cpu/amd.c | 8 +- xen/arch/x86/include/asm/amd.h | 2 + xen/arch/x86/include/asm/msr-index.h | 5 + xen/include/public/sysctl.h | 1 + 5 files changed, 418 insertions(+), 5 deletions(-)
xen/arch/x86/acpi/cpufreq/amd-cppc.c +406 -1
@@ -14,7 +14,95 @@#include <xen/domain.h> #include <xen/init.h> #include <xen/param.h> +#include <xen/percpu.h> +#include <xen/xvmalloc.h> #include <acpi/cpufreq/cpufreq.h> +#include <asm/amd.h> +#include <asm/msr-index.h> + +#define amd_cppc_err(cpu, fmt, args...) \ + printk(XENLOG_ERR "AMD-CPPC: CPU%u error: " fmt, cpu, ## args) +#define amd_cppc_warn(cpu, fmt, args...) \ + printk(XENLOG_WARNING "AMD-CPPC: CPU%u warning: " fmt, cpu, ## args) +#define amd_cppc_verbose(cpu, fmt, args...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "AMD-CPPC: CPU%u " fmt, cpu, ## args); \ +}) + +/* +* Field highest_perf, nominal_perf, lowest_nonlinear_perf, and lowest_perf +* contain the values read from CPPC capability MSR. They represent the limits +* of managed performance range as well as the dynamic capability, which may +* change during processor operation +* Field highest_perf represents highest performance, which is the absolute +* maximum performance an individual processor may reach, assuming ideal +* conditions. This performance level may not be sustainable for long +* durations and may only be achievable if other platform components +* are in a specific state; for example, it may require other processors be +* in an idle state. This would be equivalent to the highest frequencies +* supported by the processor. +* Field nominal_perf represents maximum sustained performance level of the +* processor, assuming ideal operating conditions. All cores/processors are +* expected to be able to sustain their nominal performance state\ +* simultaneously. +* Field lowest_nonlinear_perf represents Lowest Nonlinear Performance, which +* is the lowest performance level at which nonlinear power savings are +* achieved. Above this threshold, lower performance levels should be +* generally more energy efficient than higher performance levels. So in +* traditional terms, this represents the P-state range of performance levels. +* Field lowest_perf represents the absolute lowest performance level of the +* platform. Selecting it may cause an efficiency penalty but should reduce +* the instantaneous power consumption of the processor. So in traditional +* terms, this represents the T-state range of performance levels. +* +* Field max_perf, min_perf, des_perf store the values for CPPC request MSR. +* Software passes performance goals through these fields. +* Field max_perf conveys the maximum performance level at which the platform +* may run. And it may be set to any performance value in the range +* [lowest_perf, highest_perf], inclusive. +* Field min_perf conveys the minimum performance level at which the platform +* may run. And it may be set to any performance value in the range +* [lowest_perf, highest_perf], inclusive but must be less than or equal to +* max_perf. +* Field des_perf conveys performance level Xen governor is requesting. And it +* may be set to any performance value in the range [min_perf, max_perf], +* inclusive. +*/ +struct amd_cppc_drv_data +{ +const struct xen_processor_cppc *cppc_data; +union { +uint64_t raw; +struct { +unsigned int lowest_perf:8 ; +unsigned int lowest_nonlinear_perf:8 ; +unsigned int nominal_perf:8 ; +unsigned int highest_perf:8 ; + unsigned int :32; + }; + } caps; +union { +uint64_t raw; +struct { +unsigned int max_perf:8 ; +unsigned int min_perf:8 ; +unsigned int des_perf:8 ; +unsigned int epp:8 ; + unsigned int :32; + }; + } req; + +int err; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct amd_cppc_drv_data *, + amd_cppc_drv_data); +/* +* Core max frequency read from PstateDef as anchor point +* for freq-to-perf transition +*/ +static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, pxfreq_mhz);static bool __init amd_cppc_handle_option (const char *s,const char *end) {
@@ -50,10 +138,327 @@ int __init amd_cppc_cmdline_parse(const char *s, const char *e)return 0 ; } +/* +* If CPPC lowest_freq and nominal_freq registers are exposed then we can +* use them to convert perf to freq and vice versa. The conversion is +* extrapolated as an linear function passing by the 2 points: +* - (Low perf, Low freq) +* - (Nominal perf, Nominal freq) +* Parameter freq is always in kHz. +*/ +static int amd_cppc_khz_to_perf (const struct amd_cppc_drv_data *data, +unsigned int freq,uint8_t *perf) +{ +const struct xen_processor_cppc *cppc_data = data->cppc_data; +unsigned int mul, div; +int offset =0 , res; + +if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz && + data->caps.nominal_perf != data->caps.lowest_perf && + cppc_data->cpc.nominal_mhz != cppc_data->cpc.lowest_mhz ) + { + mul = data->caps.nominal_perf - data->caps.lowest_perf; + div = cppc_data->cpc.nominal_mhz - cppc_data->cpc.lowest_mhz; + +/* +* We don't need to convert to kHz for computing offset and can +* directly use nominal_mhz and lowest_mhz as the division +* will remove the frequency unit. +*/ + offset = data->caps.nominal_perf - + (mul * cppc_data->cpc.nominal_mhz) / div; + } +else + { +/* Read Processor Max Speed(MHz) as anchor point */ + mul = data->caps.highest_perf; + div =this_cpu (pxfreq_mhz); +if ( !div ) +return -EOPNOTSUPP ; + } + + res = offset + (mul * freq) / (div *1000 ); +if ( res >UINT8_MAX ) + { +printk_once (XENLOG_WARNING +"Perf value exceeds maximum value 255: %d\n" , res); + *perf =0xff ; +return 0 ; + } +if ( res <0 ) + { +printk_once (XENLOG_WARNING +"Perf value smaller than minimum value 0: %d\n" , res); + *perf =0 ; +return 0 ; + } + *perf = res; + +return 0 ; +} + +/* +* _CPC may define nominal frequecy and lowest frequency, if not, use +* Processor Max Speed as anchor point to calculate. +* Output freq stores cpc frequency in kHz +*/ +static int amd_get_cpc_freq (const struct amd_cppc_drv_data *data, +uint32_t cpc_mhz,uint8_t perf,unsigned int *freq) +{ +unsigned int mul, div, res; + +if ( cpc_mhz ) + { +/* Switch to kHz */ + *freq = cpc_mhz *1000 ; +return 0 ; + } + +/* Read Processor Max Speed(MHz) as anchor point */ + mul =this_cpu (pxfreq_mhz); +if ( !mul ) +return -EOPNOTSUPP ; + div = data->caps.highest_perf; + res = (mul * perf *1000 ) / div; +if (unlikely (!res) ) +return -EOPNOTSUPP ; + +return 0 ; +} + +/* Output max_freq stores calculated maximum frequency in kHz */ +static int amd_get_max_freq (const struct amd_cppc_drv_data *data, +unsigned int *max_freq) +{ +unsigned int nom_freq =0 ; +int res; + + res =amd_get_cpc_freq (data, data->cppc_data->cpc.nominal_mhz, + data->caps.nominal_perf, &nom_freq); +if ( res ) +return res; + + *max_freq = (data->caps.highest_perf * nom_freq) / data->caps.nominal_perf; + +return 0 ; +} + +static int cf_check amd_cppc_cpufreq_verify(struct cpufreq_policy *policy) +{ +cpufreq_verify_within_limits (policy, policy->cpuinfo.min_freq, + policy->cpuinfo.max_freq); + +return 0 ; +} + +static void cf_check amd_cppc_write_request_msrs(void *info) +{ +const struct amd_cppc_drv_data *data = info; + +wrmsrl (MSR_AMD_CPPC_REQ , data->req.raw); +} + +static void amd_cppc_write_request (unsigned int cpu,uint8_t min_perf, +uint8_t des_perf,uint8_t max_perf) +{ +struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, cpu); +uint64_t prev = data->req.raw; + + data->req.min_perf = min_perf; + data->req.max_perf = max_perf; + data->req.des_perf = des_perf; + +if ( prev == data->req.raw ) +return ; + +on_selected_cpus (cpumask_of (cpu), amd_cppc_write_request_msrs, data,1 ); +} + +static int cf_check amd_cppc_cpufreq_target(struct cpufreq_policy *policy, +unsigned int target_freq, +unsigned int relation) +{ +unsigned int cpu = policy->cpu; +const struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, cpu); +uint8_t des_perf; +int res; + +if (unlikely (!target_freq) ) +return 0 ; + + res =amd_cppc_khz_to_perf (data, target_freq, &des_perf); +if ( res ) +return res; + +/* +* Having a performance level lower than the lowest nonlinear +* performance level, such as, lowest_perf <= perf <= lowest_nonliner_perf, +* may actually cause an efficiency penalty, So when deciding the min_perf +* value, we prefer lowest nonlinear performance over lowest performance. +*/ +amd_cppc_write_request (policy->cpu, data->caps.lowest_nonlinear_perf, + des_perf, data->caps.highest_perf); +return 0 ; +} + +static void cf_check amd_cppc_init_msrs(void *info) +{ +struct cpufreq_policy *policy = info; +struct amd_cppc_drv_data *data =this_cpu (amd_cppc_drv_data); +uint64_t val; +unsigned int min_freq =0 , nominal_freq =0 , max_freq; + +/* Package level MSR */ +rdmsrl (MSR_AMD_CPPC_ENABLE , val); +/* +* Only when Enable bit is on, the hardware will calculate the processor’s +* performance capabilities and initialize the performance level fields in +* the CPPC capability registers. +*/ +if ( !(val &AMD_CPPC_ENABLE ) ) + { + val |=AMD_CPPC_ENABLE ; +wrmsrl (MSR_AMD_CPPC_ENABLE , val); + } + +rdmsrl (MSR_AMD_CPPC_CAP1 , data->caps.raw); + +if ( data->caps.highest_perf ==0 || data->caps.lowest_perf ==0 || + data->caps.nominal_perf ==0 || data->caps.lowest_nonlinear_perf ==0 || + data->caps.lowest_perf > data->caps.lowest_nonlinear_perf || + data->caps.lowest_nonlinear_perf > data->caps.nominal_perf || + data->caps.nominal_perf > data->caps.highest_perf ) + { +amd_cppc_err (policy->cpu, +"Out of range values: highest(%u), lowest(%u), nominal(%u), lowest_nonlinear(%u)\n" , + data->caps.highest_perf, data->caps.lowest_perf, + data->caps.nominal_perf, data->caps.lowest_nonlinear_perf); + goto err; + } + +amd_process_freq (&cpu_data[policy->cpu], +NULL ,NULL , &this_cpu (pxfreq_mhz)); + + data->err =amd_get_cpc_freq (data, data->cppc_data->cpc.lowest_mhz, + data->caps.lowest_perf, &min_freq); +if ( data->err ) +return ; + + data->err =amd_get_cpc_freq (data, data->cppc_data->cpc.nominal_mhz, + data->caps.nominal_perf, &nominal_freq); +if ( data->err ) +return ; + + data->err =amd_get_max_freq (data, &max_freq); +if ( data->err ) +return ; + +if ( min_freq > nominal_freq || nominal_freq > max_freq ) + { +amd_cppc_err (policy->cpu, +"min(%u), or max(%u), or nominal(%u) freq value is incorrect\n" , + min_freq, max_freq, nominal_freq); + goto err; + } + + policy->min = min_freq; + policy->max = max_freq; + + policy->cpuinfo.min_freq = min_freq; + policy->cpuinfo.max_freq = max_freq; + policy->cpuinfo.perf_freq = nominal_freq; +/* +* Set after policy->cpuinfo.perf_freq, as we are taking +* APERF/MPERF average frequency as current frequency. +*/ + policy->cur =cpufreq_driver_getavg (policy->cpu,GOV_GETAVG ); + +return ; + + err: +/* +* No fallback shceme is available here, see more explanation at call +* site in amd_cppc_cpufreq_cpu_init(). +*/ + data->err = -EINVAL ; +} + +/* +* AMD CPPC driver is different than legacy ACPI hardware P-State, +* which has a finer grain frequency range between the highest and lowest +* frequency. And boost frequency is actually the frequency which is mapped on +* highest performance ratio. The legacy P0 frequency is actually mapped on +* nominal performance ratio. +*/ +static void amd_cppc_boost_init (struct cpufreq_policy *policy, +const struct amd_cppc_drv_data *data) +{ +if ( data->caps.highest_perf <= data->caps.nominal_perf ) +return ; + + policy->turbo =CPUFREQ_TURBO_ENABLED ; +} + +static int cf_check amd_cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) +{ +XVFREE (per_cpu (amd_cppc_drv_data, policy->cpu)); + +return 0 ; +} + +static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) +{ +unsigned int cpu = policy->cpu; +struct amd_cppc_drv_data *data; + + data = xvzalloc(struct amd_cppc_drv_data); +if ( !data ) +return -ENOMEM ; + + data->cppc_data = &processor_pminfo[cpu]->cppc_data; + +per_cpu (amd_cppc_drv_data, cpu) = data; + +on_selected_cpus (cpumask_of (cpu), amd_cppc_init_msrs, policy,1 ); + +/* +* The enable bit is sticky, as we need to enable it at the very first +* begining, before CPPC capability values sanity check. +* If error path is taken effective, not only amd-cppc cpufreq core fails +* to initialize, but also we could not fall back to legacy P-states +* driver, irrespective of the command line specifying a fallback option. +*/ +if ( data->err ) + { +amd_cppc_err (cpu,"Could not initialize cpufreq core in CPPC mode\n" ); +amd_cppc_cpufreq_cpu_exit (policy); +return data->err; + } + + policy->governor = cpufreq_opt_governor ? :CPUFREQ_DEFAULT_GOVERNOR ; + +amd_cppc_boost_init (policy, data); + +amd_cppc_verbose (policy->cpu, +"CPU initialized with amd-cppc passive mode\n" ); + +return 0 ; +} + +static const struct cpufreq_driver __initconst_cf_clobber +amd_cppc_cpufreq_driver = +{ + .name =XEN_AMD_CPPC_DRIVER_NAME , + .verify = amd_cppc_cpufreq_verify, + .target = amd_cppc_cpufreq_target, + .init = amd_cppc_cpufreq_cpu_init, + .exit = amd_cppc_cpufreq_cpu_exit, +}; +int __init amd_cppc_register_driver (void ) {if ( !cpu_has_cppc )return -ENODEV ; -return -EOPNOTSUPP ; +return cpufreq_register_driver (&amd_cppc_cpufreq_driver); }
xen/arch/x86/cpu/amd.c +4 -4
@@ -613,10 +613,10 @@ static unsigned int attr_const amd_parse_freq(unsigned int family,return freq; } -static void amd_process_freq (const struct cpuinfo_x86 *c, -unsigned int *low_mhz, -unsigned int *nom_mhz, -unsigned int *hi_mhz) +void amd_process_freq (const struct cpuinfo_x86 *c, +unsigned int *low_mhz, +unsigned int *nom_mhz, +unsigned int *hi_mhz) {unsigned int idx =0 , h;uint64_t hi, lo, val;
xen/arch/x86/include/asm/amd.h +2 -0
@@ -173,5 +173,7 @@ extern bool amd_virt_spec_ctrl;bool amd_setup_legacy_ssbd (void );void amd_set_legacy_ssbd (bool enable);void amd_set_cpuid_user_dis (bool enable); +void amd_process_freq (const struct cpuinfo_x86 *c,unsigned int *low_mhz, +unsigned int *nom_mhz,unsigned int *hi_mhz);#endif /* __AMD_H__ */
xen/arch/x86/include/asm/msr-index.h +5 -0
@@ -241,6 +241,11 @@#define MSR_AMD_CSTATE_CFG 0xc0010296U +#define MSR_AMD_CPPC_CAP1 0xc00102b0U +#define MSR_AMD_CPPC_ENABLE 0xc00102b1U +#define AMD_CPPC_ENABLE (_AC(1, ULL) << 0) +#define MSR_AMD_CPPC_REQ 0xc00102b3U +/* * Legacy MSR constants in need of cleanup. No new MSRs below this comment. */
xen/include/public/sysctl.h +1 -0
@@ -453,6 +453,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 v6 12/19] xen/cpufreq: implement amd-cppc driver for CPPC in passive mode
Quoted 27 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +20
-0@@ -14,7 +14,95 @@#include <xen/domain.h> #include <xen/init.h> #include <xen/param.h> +#include <xen/percpu.h> +#include <xen/xvmalloc.h> #include <acpi/cpufreq/cpufreq.h> +#include <asm/amd.h> +#include <asm/msr-index.h> + +#define amd_cppc_err(cpu, fmt, args...) \ + printk(XENLOG_ERR "AMD-CPPC: CPU%u error: " fmt, cpu, ## args) +#define amd_cppc_warn(cpu, fmt, args...) \ + printk(XENLOG_WARNING "AMD-CPPC: CPU%u warning: " fmt, cpu, ## args) +#define amd_cppc_verbose(cpu, fmt, args...) \ +({ \ + if ( cpufreq_verbose ) \ + printk(XENLOG_DEBUG "AMD-CPPC: CPU%u " fmt, cpu, ## args); \ +}) + +/* +* Field highest_perf, nominal_perf, lowest_nonlinear_perf, and lowest_perf +* contain the values read from CPPC capability MSR. They represent the limits +* of managed performance range as well as the dynamic capability, which may +* change during processor operation
xen/arch/x86/acpi/cpufreq/amd-cppc.c line 47
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+* Field highest_perf represents highest performance, which is the absolute +* maximum performance an individual processor may reach, assuming ideal +* conditions. This performance level may not be sustainable for long +* durations and may only be achievable if other platform components +* are in a specific state; for example, it may require other processors be +* in an idle state. This would be equivalent to the highest frequencies +* supported by the processor. +* Field nominal_perf represents maximum sustained performance level of the +* processor, assuming ideal operating conditions. All cores/processors are +* expected to be able to sustain their nominal performance state\
Nit: Stray trailing backslash.
Quoted 73 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +66
-0+* simultaneously. +* Field lowest_nonlinear_perf represents Lowest Nonlinear Performance, which +* is the lowest performance level at which nonlinear power savings are +* achieved. Above this threshold, lower performance levels should be +* generally more energy efficient than higher performance levels. So in +* traditional terms, this represents the P-state range of performance levels. +* Field lowest_perf represents the absolute lowest performance level of the +* platform. Selecting it may cause an efficiency penalty but should reduce +* the instantaneous power consumption of the processor. So in traditional +* terms, this represents the T-state range of performance levels. +* +* Field max_perf, min_perf, des_perf store the values for CPPC request MSR. +* Software passes performance goals through these fields. +* Field max_perf conveys the maximum performance level at which the platform +* may run. And it may be set to any performance value in the range +* [lowest_perf, highest_perf], inclusive. +* Field min_perf conveys the minimum performance level at which the platform +* may run. And it may be set to any performance value in the range +* [lowest_perf, highest_perf], inclusive but must be less than or equal to +* max_perf. +* Field des_perf conveys performance level Xen governor is requesting. And it +* may be set to any performance value in the range [min_perf, max_perf], +* inclusive. +*/ +struct amd_cppc_drv_data +{ +const struct xen_processor_cppc *cppc_data; +union { +uint64_t raw; +struct { +unsigned int lowest_perf:8 ; +unsigned int lowest_nonlinear_perf:8 ; +unsigned int nominal_perf:8 ; +unsigned int highest_perf:8 ; + unsigned int :32; + }; + } caps; +union { +uint64_t raw; +struct { +unsigned int max_perf:8 ; +unsigned int min_perf:8 ; +unsigned int des_perf:8 ; +unsigned int epp:8 ; + unsigned int :32; + }; + } req; + +int err; +}; + +static DEFINE_PER_CPU_READ_MOSTLY(struct amd_cppc_drv_data *, + amd_cppc_drv_data); +/* +* Core max frequency read from PstateDef as anchor point +* for freq-to-perf transition +*/ +static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, pxfreq_mhz);static bool __init amd_cppc_handle_option (const char *s,const char *end) {@@ -50,10 +138,327 @@ int __init amd_cppc_cmdline_parse(const char *s, const char *e)return 0 ; } +/* +* If CPPC lowest_freq and nominal_freq registers are exposed then we can +* use them to convert perf to freq and vice versa. The conversion is +* extrapolated as an linear function passing by the 2 points: +* - (Low perf, Low freq) +* - (Nominal perf, Nominal freq) +* Parameter freq is always in kHz. +*/
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 158
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+static int amd_cppc_khz_to_perf (const struct amd_cppc_drv_data *data, +unsigned int freq,uint8_t *perf) +{ +const struct xen_processor_cppc *cppc_data = data->cppc_data; +unsigned int mul, div; +int offset =0 , res; + +if ( cppc_data->cpc.lowest_mhz && cppc_data->cpc.nominal_mhz && + data->caps.nominal_perf != data->caps.lowest_perf && + cppc_data->cpc.nominal_mhz != cppc_data->cpc.lowest_mhz )
While I understand that required relations are being checked elsewhere, if you used > in place of != here, that would not only serve a doc aspect, but also allow to drop one part:
if ( cppc_data->cpc.lowest_mhz &&
data->caps.nominal_perf > data->caps.lowest_perf &&
cppc_data->cpc.nominal_mhz > cppc_data->cpc.lowest_mhz )Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+ { + mul = data->caps.nominal_perf - data->caps.lowest_perf; + div = cppc_data->cpc.nominal_mhz - cppc_data->cpc.lowest_mhz; + +/* +* We don't need to convert to kHz for computing offset and can +* directly use nominal_mhz and lowest_mhz as the division +* will remove the frequency unit. +*/ + offset = data->caps.nominal_perf - + (mul * cppc_data->cpc.nominal_mhz) / div; + } + else
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 181
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ { +/* Read Processor Max Speed(MHz) as anchor point */ + mul = data->caps.highest_perf; + div =this_cpu (pxfreq_mhz); +if ( !div ) +return -EOPNOTSUPP ; + } + + res = offset + (mul * freq) / (div *1000 ); +if ( res >UINT8_MAX )
Why UINT8_MAX here but ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 185
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+ { +printk_once (XENLOG_WARNING +"Perf value exceeds maximum value 255: %d\n" , res); + *perf =0xff ;
... 0xff here?
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 195
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+return 0 ; + } +if ( res <0 ) + { +printk_once (XENLOG_WARNING +"Perf value smaller than minimum value 0: %d\n" , res); + *perf =0 ; +return 0 ; + } + *perf = res;
Considering that amd_cppc_init_msrs() rejects perf values of 0 as invalid, is 0 actually valid as an output here?
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 206
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0+/* +* _CPC may define nominal frequecy and lowest frequency, if not, use +* Processor Max Speed as anchor point to calculate. +* Output freq stores cpc frequency in kHz +*/ +static int amd_get_cpc_freq (const struct amd_cppc_drv_data *data, +uint32_t cpc_mhz,uint8_t perf,unsigned int *freq)
Once again no need for uint32_t when unsigned int will do.
Jan
RE: [PATCH v6 12/19] xen/cpufreq: implement amd-cppc driver for CPPC in passive mode
[Public]
Quoted 13 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 8:55 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 v6 12/19] xen/cpufreq: implement amd-cppc driver for CPPC in passive modeOn 11.07.2025 05:50, Penny Zheng wrote:
Quoted 14 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c int __init amd_cppc_cmdline_parse(const char *s, const char *e) · line 195
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8
-0+if ( res <0 ) + { +printk_once (XENLOG_WARNING +"Perf value smaller than minimum value 0: %d\n" , res); + *perf =0 ; +return 0 ; + } + *perf = res;Considering that
amd_cppc_init_msrs()rejects perf values of 0 as invalid, is 0 actually valid as an output here?
Yes... we are rejecting 0 in there. Maybe I shall return -ERANGE here instead
Quoted 1 line
Jan
PATCH v6 13/19 xen/x86: implement amd-cppc-epp driver for CPPC in active mode
In reply to Penny Zhengamd-cppc has 2 operation modes: autonomous (active) mode and non-autonomous (passive) mode.
In active mode, we don't need Xen governor to calculate and tune the cpu frequency, while hardware built-in CPPC power algorithm will calculate the runtime workload and adjust cores frequency automatically according to the power supply, thermal, core voltage and some other hardware conditions. In active mode, CPPC ignores requests done in the desired performance field, and takes into account only the values set to the minimum performance, maximum performance, and energy performance preference registers.
A new field EPP (energy performance preference), in CPPC request register, is introduced. It will be used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity, called minimum active frequency, It could contatin a range of values from 0 to 0xff. An EPP of zero sets the min active frequency to maximum frequency, while an EPP of 0xff sets the min active frequency to approxiately Idle frequency.
We implement a new AMD CPU frequency driver amd-cppc-epp for active mode. It requires active tag in Xen cmdline for users to explicitly select active mode.
In driver active-cppc-epp, ->setpolicy() is hooked, not the ->target(), as it does not depend on xen governor to do performance tuning.
We also introduce a new field "policy" (CPUFREQ_POLICY_xxx) to represent performance policy. Right now, it supports three values:CPUFREQ_POLICY_PERFORMANCE as maximum performance, CPUFREQ_POLICY_POWERSAVE as the least power consumption, and CPUFREQ_POLICY_ONDEMAND as no preference, just corresponding to "performance", "powersave" and "ondemand" Xen governor, which benefit users from re-using "governor" in Xen cmdline to deliver which performance policy they want to apply.
---
v1 -> v2:
- Remove redundant epp_mode
- Remove pointless initializer
- Define sole caller read_epp_init_once and epp_init value to read pre-defined BIOS epp value only once
- Combine the commit "xen/cpufreq: introduce policy type when cpufreq_driver->setpolicy exists"
---
v2 -> v3:
- Combined with commit "x86/cpufreq: add "cpufreq=amd-cppc,active" para"
- Refactor doc about "active mode"
- Change opt_cpufreq_active to opt_active_mode
- Let caller pass epp_init when unspecified to allow the function parameter to be of uint8_t
- Make epp_init per-cpu value
---
v3 -> v4:
- doc refinement
- use MASK_EXTR() to get epp value
- fix indentation
- replace if-else() with switch()
- combine successive comments and do refinement
- no need to introduce amd_cppc_epp_update_limit() as a wrapper
- rename cpufreq_parse_policy() with cpufreq_policy_from_governor()
- no need to use case-insensitive comparison
---
v4 -> v5:
- refine doc to state what the default is for "active" sub-option and it's of boolean nature
- excess blank after << for AMD_CPPC_EPP_MASK
- set max_perf with lowest_perf to get utmost powersave
- refine commit message to include description about relation between "policy" and "governor"
---
v5 -> v6:
- expand comment for "epp" field
- let min_perf set with lowest_nonliner_perf, not lowest_perf, to constrain performance tuning in P-states range
- refactor doc and comments
- blank lines between non-fall-through case blocks
- introduce and add entry for "CPUFREQ_POLICY_ONDEMAND"
---
--- docs/misc/xen-command-line.pandoc | 9 +- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 143 ++++++++++++++++++++++++++- xen/arch/x86/include/asm/msr-index.h | 1 + xen/drivers/cpufreq/utility.c | 14 +++ xen/include/acpi/cpufreq/cpufreq.h | 18 ++++ xen/include/public/sysctl.h | 1 + 6 files changed, 180 insertions(+), 6 deletions(-)
docs/misc/xen-command-line.pandoc +8 -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,13 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. * `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide finer grained frequency control mechanism. The default is disabled. +* `active` is a boolean to enable amd-cppc driver in active(autonomous) mode. + In this mode, users don't rely on Xen governor to do performance monitoring + and tuning. Hardware built-in CPPC power algorithm will calculate the runtime + workload and adjust cores frequency automatically according to the power + supply, thermal, core voltage and some other hardware conditions. + The default is disabled, and the option only applies when `amd-cppc` is + enabled. There is also support for `;`-separated fallback options: `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if
xen/arch/x86/acpi/cpufreq/amd-cppc.c +138 -5
216 lines not on this page · raw message
xen/arch/x86/include/asm/msr-index.h +1 -0
@@ -245,6 +245,7 @@#define MSR_AMD_CPPC_ENABLE 0xc00102b1U#define AMD_CPPC_ENABLE (_AC(1, ULL) << 0)#define MSR_AMD_CPPC_REQ 0xc00102b3U +#define AMD_CPPC_EPP_MASK (_AC(0xff, ULL) << 24)/* * Legacy MSR constants in need of cleanup. No new MSRs below this comment.
xen/drivers/cpufreq/utility.c +14 -0
@@ -281,3 +281,17 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,return __cpufreq_governor (data,CPUFREQ_GOV_LIMITS ); } + +unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov) +{ +if ( !strncmp (gov->name,"performance" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_PERFORMANCE ; + +if ( !strncmp (gov->name,"powersave" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_POWERSAVE ; + +if ( !strncmp (gov->name,"ondemand" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_ONDEMAND ; + +return CPUFREQ_POLICY_UNKNOWN ; +}
xen/include/acpi/cpufreq/cpufreq.h +18 -0
@@ -82,6 +82,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);
@@ -132,6 +133,23 @@ 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 +/* +* Performance Policy +* If cpufreq_driver->target() exists, the ->governor decides what frequency +* within the limits is used. If cpufreq_driver->setpolicy() exists, these +* following policies are available: +* CPUFREQ_POLICY_PERFORMANCE represents maximum performance +* CPUFREQ_POLICY_POWERSAVE represents least power consumption +* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or +* powersave +*/ +#define CPUFREQ_POLICY_UNKNOWN 0 +#define CPUFREQ_POLICY_POWERSAVE 1 +#define CPUFREQ_POLICY_PERFORMANCE 2 +#define CPUFREQ_POLICY_ONDEMAND 3 + +unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov); +/* pass a target to the cpufreq driver */ extern int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq,
xen/include/public/sysctl.h +1 -0
@@ -454,6 +454,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 v6 13/19] xen/x86: implement amd-cppc-epp driver for CPPC in active mode
xen/arch/x86/acpi/cpufreq/amd-cppc.c line 70
Quoted 8 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-1@@ -67,7 +67,14 @@* max_perf. * Field des_perf conveys performance level Xen governor is requesting. And it * may be set to any performance value in the range [min_perf, max_perf], -* inclusive. +* inclusive. In active mode, desf_perf must be zero.
Nit (typo): des_perf
Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +0
-1@@ -259,11 +276,18 @@ static void cf_check amd_cppc_write_request_msrs(void *info) } static void amd_cppc_write_request(unsigned int cpu, uint8_t min_perf, -uint8_t des_perf,uint8_t max_perf)
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void cf_check amd_cppc_write_request_msrs(void *info) · line 288
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+ uint8_t des_perf, uint8_t max_perf, + uint8_t epp) { struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu);uint64_t prev = data->req.raw; +if ( !opt_active_mode ) + data->req.des_perf = des_perf; +else + data->req.des_perf =0 ;
In amd_cppc_epp_set_policy() you pass 0 anyway. Why is this needed? With this change dropped, opt_active_mode can become __initdata. (But of course you may want to add an assertion instead, in which case the variable needs to stay where it is at least in debug builds.)
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void cf_check amd_cppc_write_request_msrs(void *info) · line 289
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+ data->req.epp = epp;
Ahead of this patch, aren't you mis-handling this field then, in that you clear it (as you never read the MSR)?
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void cf_check amd_cppc_write_request_msrs(void *info) · line 293
Quoted 3 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +0
-0data->req.min_perf = min_perf; data->req.max_perf = max_perf; data->req.des_perf = des_perf;
Don't you need to delete this line with the addition above, or alternatively change the above to
if ( opt_active_mode )
data->req.des_perf = 0;
?
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void amd_cppc_write_request(unsigned int cpu, uint8_t min_perf, · line 307
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0@@ -274,6 +298,14 @@ static void amd_cppc_write_request(unsigned int cpu, uint8_t min_perf,on_selected_cpus (cpumask_of (cpu), amd_cppc_write_request_msrs, data,1 ); } +static void read_epp_init (void ) +{ +uint64_t val; + +rdmsrl (MSR_AMD_CPPC_REQ , val); +this_cpu (epp_init) =MASK_EXTR (val,AMD_CPPC_EPP_MASK ); +}
I'm unconvinced this is worth a separate function.
Quoted 15 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +15
-0+static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) +{ +const struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, + policy->cpu); +uint8_t max_perf, min_perf, epp; + +/* +* On default, set min_perf with lowest_nonlinear_perf, and max_perf +* with the highest, to ensure performance scaling in P-states range. +*/ + max_perf = data->caps.highest_perf; + min_perf = data->caps.lowest_nonlinear_perf; + +/* +* In policy CPUFREQ_POLICY_PERFORMANCE, increase min_perf to
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 536
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+* highest_perf to achieve ultmost performance. +* In policy CPUFREQ_POLICY_POWERSAVE, decrease max_perf to +* lowest_nonlinear_perf to achieve ultmost power saving. +*/ +switch ( policy->policy ) + { +case CPUFREQ_POLICY_PERFORMANCE : +/* Force the epp value to be zero for performance policy */ + epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; + min_perf = data->caps.highest_perf;
Use the local variable you have, i.e. max_perf?
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 542
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+break ; + +case CPUFREQ_POLICY_POWERSAVE : +/* Force the epp value to be 0xff for powersave policy */ + epp =CPPC_ENERGY_PERF_MAX_POWERSAVE ; + max_perf = data->caps.lowest_nonlinear_perf;
Use the local variable you have, i.e. min_perf?
xen/arch/x86/include/asm/msr-index.h line 248
Quoted 7 lines
xen/arch/x86/include/asm/msr-index.h +1
-0@@ -245,6 +245,7 @@#define MSR_AMD_CPPC_ENABLE 0xc00102b1U#define AMD_CPPC_ENABLE (_AC(1, ULL) << 0)#define MSR_AMD_CPPC_REQ 0xc00102b3U +#define AMD_CPPC_EPP_MASK (_AC(0xff, ULL) << 24)
The reason I noticed the EPP issue in amd_cppc_write_request() is because I wondered why you would need this, when you have the fields defined in struct amd_cppc_drv_data.
Jan
RE: [PATCH v6 13/19] xen/x86: implement amd-cppc-epp driver for CPPC in active mode
[Public]
Quoted 26 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 17, 2025 9:36 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 v6 13/19] xen/x86: implement amd-cppc-epp driver for CPPC in active modeQuoted 13 lines · Penny Zheng
xen/arch/x86/acpi/cpufreq/amd-cppc.c +2
-1@@ -259,11 +276,18 @@ static void cf_check amd_cppc_write_request_msrs(void *info) }static void amd_cppc_write_request (unsigned int cpu,uint8_t min_perf, -uint8_t des_perf,uint8_t max_perf) +uint8_t des_perf,uint8_t max_perf, +uint8_t epp) {struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, cpu);uint64_t prev = data->req.raw;
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void cf_check amd_cppc_write_request_msrs(void *info) · line 288
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +4
-0+if ( !opt_active_mode ) + data->req.des_perf = des_perf; +else + data->req.des_perf =0 ;In
amd_cppc_epp_set_policy()you pass 0 anyway. Why is this needed? With this change dropped,opt_active_modecan become__initdata. (But of course you may want to add an assertion instead, in which case the variable needs to stay where it is at least in debug builds.)
True, the if-else seems redundant. I'll make opt_active_mode __initdata under NDEBUG
```
#ifndef NDEBUG
static bool __ro_after_init opt_active_mode;
#else
static bool __initdata opt_active_mode;
#endif
```Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static void cf_check amd_cppc_write_request_msrs(void *info) · line 289
Quoted 1 line
xen/arch/x86/acpi/cpufreq/amd-cppc.c +1
-0+ data->req.epp = epp;Ahead of this patch, aren't you mis-handling this field then, in that you clear it (as you never read the MSR)?
Yes, It will always be 0 of it in the previous commit. I shall move getting "pre-defined BIOS value" for epp thingy ahead
Quoted 2 lines
Jan
PATCH v6 14/19 xen/cpufreq: get performance policy from governor set via xenpm
In reply to Penny ZhengEven if Xen governor is not used in amd-cppc active mode, we could somehow deduce which performance policy (CPUFREQ_POLICY_xxx) user wants to apply through which governor they choose, such as:
If user chooses performance governor, they want maximum performance, then the policy shall be CPUFREQ_POLICY_PERFORMANCE
If user chooses powersave governor, they want the least power consumption, then the policy shall be CPUFREQ_POLICY_POWERSAVE
Function cpufreq_policy_from_governor() is responsible for above transition, and it shall be also effective when users setting new governor through xenpm.
ondemand and userspace are forbidden choices, and if users specify such options, we shall not only give warning message to suggest using "xenpm set-cpufreq-cppc", but also error out.
---
v4 -> v5:
- new commit
---
v5 -> v6:
- refactor warning message
--- xen/drivers/acpi/pm-op.c | 8 ++++++++ xen/drivers/cpufreq/utility.c | 1 + 2 files changed, 9 insertions(+)
xen/drivers/acpi/pm-op.c +8 -0
@@ -205,6 +205,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)if ( new_policy.governor ==NULL )return -EINVAL ; + new_policy.policy =cpufreq_policy_from_governor (new_policy.governor); +if ( new_policy.policy ==CPUFREQ_POLICY_UNKNOWN ) + { +printk ("Failed to get performance policy from %s, Try \"xenpm set-cpufreq-cppc\"\n" , + new_policy.governor->name); +return -EINVAL ; + } +return __cpufreq_set_policy (old_policy, &new_policy); }
xen/drivers/cpufreq/utility.c +1 -0
@@ -250,6 +250,7 @@ int __cpufreq_set_policy(struct cpufreq_policy *data, data->min = policy->min; data->max = policy->max; data->limits = policy->limits; + data->policy = policy->policy;if (cpufreq_driver.setpolicy)return alternative_call (cpufreq_driver.setpolicy, data);
Signature · 1 line
2.34.1
Re: [PATCH v6 14/19] xen/cpufreq: get performance policy from governor set via xenpm
Quoted 11 lines · Penny Zheng
Even if Xen governor is not used in amd-cppc active mode, we could somehow deduce which performance policy (
CPUFREQ_POLICY_xxx) user wants to apply through which governor they choose, such as:
If user chooses performance governor, they want maximum performance, then the policy shall beCPUFREQ_POLICY_PERFORMANCE
If user chooses powersave governor, they want the least power consumption, then the policy shall beCPUFREQ_POLICY_POWERSAVE
Functioncpufreq_policy_from_governor()is responsible for above transition, and it shall be also effective when users setting new governor through xenpm.ondemand and userspace are forbidden choices, and if users specify
Is this stale? You permit ...
Quoted 20 lines
such options, we shall not only give warning message to suggest using "xenpm set-cpufreq-cppc", but also error out.
Signed-off-by Penny Zheng <[email protected]>---
v4 -> v5:
- new commit
---
v5 -> v6:
- refactor warning message--- xen/drivers/acpi/pm-op.c | 8 ++++++++ xen/drivers/cpufreq/utility.c | 1 + 2 files changed, 9 insertions(+)xen/drivers/acpi/pm-op.c +0
-0
xen/drivers/acpi/pm-op.c static int set_cpufreq_gov(struct xen_sysctl_pm_op *op) · line 209
Quoted 5 lines
xen/drivers/acpi/pm-op.c +2
-0@@ -205,6 +205,14 @@ static int set_cpufreq_gov(struct xen_sysctl_pm_op *op)if ( new_policy.governor ==NULL )return -EINVAL ; + new_policy.policy =cpufreq_policy_from_governor (new_policy.governor); +if ( new_policy.policy ==CPUFREQ_POLICY_UNKNOWN )
... CPUFREQ_POLICY_ONDEMAND here now, aiui (as per patch 13).
xen/drivers/cpufreq/utility.c int __cpufreq_set_policy(struct cpufreq_policy *data, · line 255
Quoted 9 lines
xen/drivers/cpufreq/utility.c +1
-0@@ -250,6 +250,7 @@ int __cpufreq_set_policy(struct cpufreq_policy *data, data->min = policy->min; data->max = policy->max; data->limits = policy->limits; + data->policy = policy->policy;if (cpufreq_driver.setpolicy)return alternative_call (cpufreq_driver.setpolicy, data);
This looks like it would belong in the patch introducing the field. More generally, is the field left uninitialized in certain cases until here? That we will want to avoid.
Jan
PATCH v6 15/19 tools/cpufreq: introduce helper to deal with CPPC-related parameters
In reply to Penny ZhengNew helpers print_cppc_para() and get_cpufreq_cppc() are introduced to deal with CPPC-related parameters, in order to be re-used when later exporting new sub-op "get-cpufreq-cppc".
---
v5 -> v6:
- new commit
--- tools/misc/xenpm.c | 53 +++++++++++++++++++++------------------- xen/drivers/acpi/pm-op.c | 16 +++++++++--- 2 files changed, 41 insertions(+), 28 deletions(-)
tools/misc/xenpm.c +28 -25
@@ -799,6 +799,33 @@ static unsigned int calculate_activity_window(const xc_cppc_para_t *cppc,return mantissa * multiplier; } +/* print out parameters about cpu cppc */ +static void print_cppc_para (unsigned int cpuid, +const xc_cppc_para_t *cppc) +{ +printf ("cppc variables :\n" ); +printf (" hardware limits : lowest [%" PRIu32"] lowest nonlinear [%" PRIu32"]\n" , + cppc->lowest, cppc->lowest_nonlinear); +printf (" : nominal [%" PRIu32"] highest [%" PRIu32"]\n" , + cppc->nominal, cppc->highest); +printf (" configured limits : min [%" PRIu32"] max [%" PRIu32"] energy perf [%" PRIu32"]\n" , + cppc->minimum, cppc->maximum, cppc->energy_perf); + +if ( cppc->features &XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW ) + { +unsigned int activity_window; +const char *units; + + activity_window =calculate_activity_window (cppc, &units); +printf (" : activity_window [%" PRIu32" %s]\n" , + activity_window, units); + } + +printf (" : desired [%" PRIu32"%s]\n" , + cppc->desired, + cppc->desired ?"" :" hw autonomous" ); +} +/* print out parameters about cpu frequency */ static void print_cpufreq_para (int cpuid,struct xc_get_cpufreq_para *p_cpufreq) {
@@ -825,31 +852,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)printf ("scaling_driver : %s\n" , p_cpufreq->scaling_driver);if ( hwp ) - { -const xc_cppc_para_t *cppc = &p_cpufreq->u.cppc_para; - -printf ("cppc variables :\n" ); -printf (" hardware limits : lowest [%" PRIu32"] lowest nonlinear [%" PRIu32"]\n" , - cppc->lowest, cppc->lowest_nonlinear); -printf (" : nominal [%" PRIu32"] highest [%" PRIu32"]\n" , - cppc->nominal, cppc->highest); -printf (" configured limits : min [%" PRIu32"] max [%" PRIu32"] energy perf [%" PRIu32"]\n" , - cppc->minimum, cppc->maximum, cppc->energy_perf); - -if ( cppc->features &XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW ) - { -unsigned int activity_window; -const char *units; - - activity_window =calculate_activity_window (cppc, &units); -printf (" : activity_window [%" PRIu32" %s]\n" , - activity_window, units); - } - -printf (" : desired [%" PRIu32"%s]\n" , - cppc->desired, - cppc->desired ?"" :" hw autonomous" ); - } +print_cppc_para (cpuid, &p_cpufreq->u.cppc_para);else {if ( p_cpufreq->gov_num )
xen/drivers/acpi/pm-op.c +13 -3
@@ -77,6 +77,17 @@ static int read_scaling_available_governors(char *scaling_available_governors,return 0 ; } +static int get_cpufreq_cppc (unsigned int cpu, +struct xen_get_cppc_para *cppc_para) +{ +int ret = -ENODEV ; + +if (hwp_active () ) + ret =get_hwp_para (cpu, cppc_para); + +return ret; +} +static int get_cpufreq_para (struct xen_sysctl_pm_op *op) {uint32_t ret =0 ;
@@ -141,9 +152,8 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)else strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN ); -if (hwp_active () ) - ret =get_hwp_para (policy->cpu, &op->u.get_para.u.cppc_para); -else + ret =get_cpufreq_cppc (op->cpuid, &op->u.get_para.u.cppc_para); +if ( ret == -ENODEV ) {if ( !(scaling_available_governors =xzalloc_array (char, gov_num *CPUFREQ_NAME_LEN )) )
Signature · 1 line
2.34.1
Re: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
Quoted 5 lines · Penny Zheng
New helpers
print_cppc_para()andget_cpufreq_cppc()are introduced to deal with CPPC-related parameters, in order to be re-used when later exporting new sub-op "get-cpufreq-cppc".Signed-off-by Penny Zheng <[email protected]>
I once again wonder whether this can go in right away, ahead of everything that wants re-submitting.
Jan
RE: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
[Public]
Quoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 23, 2025 11:56 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v6 15/19]tools/cpufreq: introduce helper to deal with CPPC- related parametersQuoted 4 lines · Penny Zheng
New helpers
print_cppc_para()andget_cpufreq_cppc()are introduced to deal with CPPC-related parameters, in order to be re-used when later exporting new sub-op "get-cpufreq-cppc".
Quoted 6 lines
Quoted 1 line
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>I once again wonder whether this can go in right away, ahead of everything that wants re-submitting.
Thx, it could.
Quoted 2 lines
Jan
RE: [PATCH v6 15/19] tools/cpufreq: introduce helper to deal with CPPC-related parameters
[Public]
Quoted 25 lines
-----Original Message-----
From: Penny, Zheng
Sent: Tuesday, August 12, 2025 5:56 PM
To: Jan Beulich <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: RE: [PATCH v6 15/19]tools/cpufreq: introduce helper to deal with CPPC- related parametersQuoted 14 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Wednesday, July 23, 2025 11:56 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v6 15/19]tools/cpufreq: introduce helper to deal with CPPC- related parametersQuoted 4 lines · Penny Zheng
New helpers
print_cppc_para()andget_cpufreq_cppc()are introduced to deal with CPPC-related parameters, in order to be re-used when later exporting new sub-op "get-cpufreq-cppc".
Quoted 9 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Penny Zheng <[email protected]>Acked-by Jan Beulich <[email protected]>I once again wonder whether this can go in right away, ahead of everything that wants re-submitting.
Thx, it could.
Sorry, I just read the next commit review. This commit may still be needed, but the commit message needs rewording, as no new sub-cmd "get-cpufreq-cppc" will be introduced.
Quoted 2 lines
Quoted 2 lines
Jan
PATCH v6 16/19 xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op
In reply to Penny ZhengIn amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info need to be printed together via xenpm tool.
If we tried to still put it in "struct xen_get_cpufreq_para" (e.g. just move out of union), "struct xen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes.
So we introduce a new sub-op GET_CPUFREQ_CPPC to specifically print CPPC-related para.
---
v4 -> v5:
- new commit
---
v5 -> v6:
- remove the changes for get-cpufreq-para
--- tools/include/xenctrl.h | 2 ++ tools/libs/ctrl/xc_pm.c | 27 +++++++++++++++++++++ tools/misc/xenpm.c | 47 +++++++++++++++++++++++++++++++++++++ xen/drivers/acpi/pm-op.c | 4 ++++ xen/include/public/sysctl.h | 2 ++ 5 files changed, 82 insertions(+)
tools/include/xenctrl.h +2 -0
@@ -1953,6 +1953,8 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value);int xc_set_cpufreq_cppc (xc_interface *xch,int cpuid,xc_set_cppc_para_t *set_cppc); +int xc_get_cppc_para (xc_interface *xch,unsigned int cpuid, +xc_cppc_para_t *cppc_para);int xc_get_cpufreq_avgfreq (xc_interface *xch,int cpuid,int *avg_freq);int xc_set_sched_opt_smt (xc_interface *xch,uint32_t value);
tools/libs/ctrl/xc_pm.c +27 -0
@@ -366,6 +366,33 @@ int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid,return ret; } +int xc_get_cppc_para (xc_interface *xch,unsigned int cpuid, +xc_cppc_para_t *cppc_para) +{ +int ret; +struct xen_sysctl sysctl = {}; +struct xen_get_cppc_para *sys_cppc_para = &sysctl.u.pm_op.u.get_cppc; + +if ( !xch || !cppc_para ) + { + errno =EINVAL ; +return -1 ; + } + + sysctl.cmd = XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =GET_CPUFREQ_CPPC ; + sysctl.u.pm_op.cpuid = cpuid; + + ret =xc_sysctl (xch, &sysctl); +if ( ret ) +return ret; + +BUILD_BUG_ON (sizeof (*cppc_para) !=sizeof (*sys_cppc_para)); +memcpy (cppc_para, sys_cppc_para,sizeof (*sys_cppc_para)); + +return ret; +} +int xc_get_cpufreq_avgfreq (xc_interface *xch,int cpuid,int *avg_freq) {int ret =0 ;
tools/misc/xenpm.c +47 -0
65 lines not on this page · raw message
xen/drivers/acpi/pm-op.c +4 -0
@@ -390,6 +390,10 @@ int do_pm_op(struct xen_sysctl_pm_op *op) ret =set_cpufreq_para (op);break ; +case GET_CPUFREQ_CPPC : + ret =get_cpufreq_cppc (op->cpuid, &op->u.get_cppc); +break ; +case SET_CPUFREQ_CPPC : ret =set_cpufreq_cppc (op);break ;
xen/include/public/sysctl.h +2 -0
@@ -523,6 +523,7 @@ struct xen_sysctl_pm_op {#define SET_CPUFREQ_PARA (CPUFREQ_PARA | 0x03)#define GET_CPUFREQ_AVGFREQ (CPUFREQ_PARA | 0x04)#define SET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x05) +#define GET_CPUFREQ_CPPC (CPUFREQ_PARA | 0x06)/* set/reset scheduler power saving option */ #define XEN_SYSCTL_pm_op_set_sched_opt_smt 0x21
@@ -547,6 +548,7 @@ struct xen_sysctl_pm_op {uint32_t cpuid;union {struct xen_get_cpufreq_para get_para; +struct xen_get_cppc_para get_cppc;struct xen_set_cpufreq_gov set_gov;struct xen_set_cpufreq_para set_para;struct xen_set_cppc_para set_cppc;
Signature · 1 line
2.34.1
Re: [PATCH v6 16/19] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op
Quoted 141 lines · Penny Zheng
In amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info need to be printed together via xenpm tool.
If we tried to still put it in "struct
xen_get_cpufreq_para" (e.g. just move out of union), "structxen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes.
So we introduce a new sub-opGET_CPUFREQ_CPPCto specifically print CPPC-related para.Signed-off-by Penny Zheng <[email protected]>---
v4 -> v5:
- new commit
---
v5 -> v6:
- remove the changes for get-cpufreq-para--- tools/include/xenctrl.h | 2 ++ tools/libs/ctrl/xc_pm.c | 27 +++++++++++++++++++++ tools/misc/xenpm.c | 47 +++++++++++++++++++++++++++++++++++++ xen/drivers/acpi/pm-op.c | 4 ++++ xen/include/public/sysctl.h | 2 ++ 5 files changed, 82 insertions(+)tools/include/xenctrl.h +2
-0@@ -1953,6 +1953,8 @@ int xc_set_cpufreq_para(xc_interface *xch, int cpuid, int ctrl_type, int ctrl_value);int xc_set_cpufreq_cppc (xc_interface *xch,int cpuid,xc_set_cppc_para_t *set_cppc); +int xc_get_cppc_para (xc_interface *xch,unsigned int cpuid, +xc_cppc_para_t *cppc_para);int xc_get_cpufreq_avgfreq (xc_interface *xch,int cpuid,int *avg_freq);int xc_set_sched_opt_smt (xc_interface *xch,uint32_t value);tools/libs/ctrl/xc_pm.c +27
-0@@ -366,6 +366,33 @@ int xc_set_cpufreq_cppc(xc_interface *xch, int cpuid,return ret; } +int xc_get_cppc_para (xc_interface *xch,unsigned int cpuid, +xc_cppc_para_t *cppc_para) +{ +int ret; +struct xen_sysctl sysctl = {}; +struct xen_get_cppc_para *sys_cppc_para = &sysctl.u.pm_op.u.get_cppc; + +if ( !xch || !cppc_para ) + { + errno =EINVAL ; +return -1 ; + } + + sysctl.cmd = XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd =GET_CPUFREQ_CPPC ; + sysctl.u.pm_op.cpuid = cpuid; + + ret =xc_sysctl (xch, &sysctl); +if ( ret ) +return ret; + +BUILD_BUG_ON (sizeof (*cppc_para) !=sizeof (*sys_cppc_para)); +memcpy (cppc_para, sys_cppc_para,sizeof (*sys_cppc_para)); + +return ret; +} +int xc_get_cpufreq_avgfreq (xc_interface *xch,int cpuid,int *avg_freq) {int ret =0 ;tools/misc/xenpm.c +46
-0@@ -69,6 +69,7 @@ void show_help(void)" set-max-cstate <num>|'unlimited' [<num2>|'unlimited']\n" " set the C-State limitation (<num> >= 0) and\n" " optionally the C-sub-state limitation (<num2> >= 0)\n" +" get-cpufreq-cppc [cpuid] list cpu cppc parameter of CPU <cpuid> or all\n" " set-cpufreq-cppc [cpuid] [balance|performance|powersave] <param:val>*\n" " set Hardware P-State (HWP) parameters\n" " on CPU <cpuid> or all if omitted.\n" @@ -996,6 +997,51 @@ void cpufreq_para_func(int argc, char *argv[])show_cpufreq_para_by_cpuid (xc_handle, cpuid); } +/* show cpu cppc parameters information on CPU cpuid */ +static int show_cppc_para_by_cpuid (xc_interface *xc_handle,unsigned int cpuid) +{ +int ret; +xc_cppc_para_t cppc_para; + + ret =xc_get_cppc_para (xc_handle, cpuid, &cppc_para); +if ( !ret ) + { +printf ("cpu id : %d\n" , cpuid); +print_cppc_para (cpuid, &cppc_para); +printf ("\n" ); + } +else if ( errno ==ENODEV ) + { + ret = -ENODEV ; +fprintf (stderr,"CPPC is not available!\n" ); + } +else +fprintf (stderr,"[CPU%u] failed to get cppc parameter\n" , cpuid); + +return ret; +} + +static void cppc_para_func (int argc,char *argv[]) +{ +int cpuid =-1 ; + +if ( argc >0 ) +parse_cpuid (argv[0 ], &cpuid); + +if ( cpuid <0 ) + { +unsigned int i; + +/* show cpu cppc information on all cpus */ +for ( i =0 ; i < max_cpu_nr; i++ ) +/* Bail out only on unsupported platform */ +if (show_cppc_para_by_cpuid (xc_handle, i) == -ENODEV ) +break ; + } +else +show_cppc_para_by_cpuid (xc_handle, cpuid); +} +void scaling_max_freq_func (int argc,char *argv[]) {int cpuid =-1 , freq =-1 ;
tools/misc/xenpm.c struct { · line 1625
Quoted 4 lines
tools/misc/xenpm.c +1
-0@@ -1576,6 +1622,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "get-cpufreq-cppc", cppc_para_func },
Didn't Jason also suggest that we would better not introduce a new command, but rather make get-cpufreq-para invoke GET_CPUFREQ_CPPC as needed? Considering that as per patch 15 the same information is already printed, I think I'm a little lost with the need for this separate operation (and command), and then also with the need for patch 15.
Jan
Re: [PATCH v6 16/19] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Penny Zheng
In amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info need to be printed together via xenpm tool.
If we tried to still put it in "struct
xen_get_cpufreq_para" (e.g. just move out of union), "structxen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes.
So we introduce a new sub-opGET_CPUFREQ_CPPCto specifically print CPPC-related para.Signed-off-by Penny Zheng <[email protected]>
Quoted 14 lines
tools/misc/xenpm.c struct { · line 1625
Quoted 8 lines
void scaling_max_freq_func(int argc, char *argv[]) { int cpuid = -1, freq = -1;tools/misc/xenpm.c +1
-0@@ -1576,6 +1622,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "get-cpufreq-cppc", cppc_para_func },Didn't Jason also suggest that we would better not introduce a new command, but rather make get-cpufreq-para invoke
GET_CPUFREQ_CPPCas needed? Considering that as per patch 15 the same information is already printed, I think I'm a little lost with the need for this separate operation (and command), and then also with the need for patch 15.
Yes, but I thought I was repeating your suggestion, Jan :)
xenpm's show_cpufreq_para_by_cpuid() would do something like:
show_cpufreq_para_by_cpuid() {
xc_get_cpufreq_para()
hw_auto = HWP || CPPC
if ( hw_auto ) {
xc_get_cppc_para()
print_cppc_para()
} else
print_cpufreq_para()
}Would that work?
That way the single xenpm get-cpufreq-para would return the current cpufreq data without the user needed to know what is running.
Regards,
Jason
Re: [PATCH v6 16/19] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op
Quoted 29 lines · Jason Andryuk
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Penny Zheng
In amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info need to be printed together via xenpm tool.
If we tried to still put it in "struct
xen_get_cpufreq_para" (e.g. just move out of union), "structxen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes.
So we introduce a new sub-opGET_CPUFREQ_CPPCto specifically print CPPC-related para.Signed-off-by Penny Zheng <[email protected]>Quoted 14 lines
tools/misc/xenpm.c struct { · line 1625
Quoted 8 lines
void scaling_max_freq_func(int argc, char *argv[]) { int cpuid = -1, freq = -1;tools/misc/xenpm.c +1
-0@@ -1576,6 +1622,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "get-cpufreq-cppc", cppc_para_func },Didn't Jason also suggest that we would better not introduce a new command, but rather make get-cpufreq-para invoke
GET_CPUFREQ_CPPCas needed? Considering that as per patch 15 the same information is already printed, I think I'm a little lost with the need for this separate operation (and command), and then also with the need for patch 15.
Quoted 1 line
Yes, but I thought I was repeating your suggestion, Jan :)
That's what I tried to express using "also" ;-)
Jan
RE: [PATCH v6 16/19] xen/cpufreq: introduce GET_CPUFREQ_CPPC sub-op
In reply to Jason Andryuk[Public]
Quoted 55 lines
-----Original Message-----
From: Jason Andryuk <[email protected]>
Sent: Thursday, July 24, 2025 10:17 PM
To: Jan Beulich <[email protected]>; Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Juergen Gross <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]
Subject: Re: [PATCH v6 16/19] xen/cpufreq: introduceGET_CPUFREQ_CPPCsub-opQuoted 13 lines · Jan Beulich
Quoted 11 lines · Penny Zheng
In amd-cppc passive mode, it's Xen governor which is responsible for performance tuning, so governor and CPPC could co-exist. That is, both governor-info and CPPC-info need to be printed together via xenpm tool.
If we tried to still put it in "struct
xen_get_cpufreq_para" (e.g. just move out of union), "structxen_get_cpufreq_para" will enlarge too much to further make xen_sysctl.u exceed 128 bytes. So we introduce a new sub-opGET_CPUFREQ_CPPCto specifically print CPPC-related para.Signed-off-by Penny Zheng <[email protected]>Quoted 14 lines
tools/misc/xenpm.c struct { · line 1625
Quoted 8 lines
void scaling_max_freq_func(int argc, char *argv[]) { int cpuid = -1, freq = -1;tools/misc/xenpm.c +1
-0@@ -1576,6 +1622,7 @@ struct { { "get-cpufreq-average", cpufreq_func }, { "start", start_gather_func }, { "get-cpufreq-para", cpufreq_para_func }, + { "get-cpufreq-cppc", cppc_para_func },Didn't Jason also suggest that we would better not introduce a new command, but rather make get-cpufreq-para invoke
GET_CPUFREQ_CPPCas needed? Considering that as per patch 15 the same information is already printed, I think I'm a little lost with the need for this separate operation (and command), and then also with the need for patch 15.Yes, but I thought I was repeating your suggestion, Jan :)
xenpm's
show_cpufreq_para_by_cpuid()would do something like:show_cpufreq_para_by_cpuid() { xc_get_cpufreq_para() hw_auto = HWP || CPPC if ( hw_auto ) { xc_get_cppc_para() print_cppc_para() } else print_cpufreq_para() }
Quoted 2 lines
Would that work?
Understood, I will re-write as you suggests, thx
Quoted 5 lines
That way the single
xenpm get-cpufreq-parawould return the current cpufreq data without the user needed to know what is running.Regards,
Jason
PATCH v6 17/19 xen/cpufreq: introduce helper cpufreq_in_cppc_passive_mode()
In reply to Penny ZhengWhen cpufreq driver in cppc passive mode, it has both cppc and governor info. We need to invoke two sysctl sub-ops ("get-cpufreq-cppc" and "get-cpufreq-para") to produce both info.
A new helper cpufreq_in_cppc_passive_mode() is introduced to tell whether cpufreq driver supports cppc passive mode.
---
v5 -> v6
- new commit
--- xen/drivers/acpi/pm-op.c | 10 +++++++++- xen/drivers/cpufreq/cpufreq.c | 6 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)
xen/drivers/acpi/pm-op.c +9 -1
@@ -152,7 +152,15 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)else strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN ); - ret =get_cpufreq_cppc (op->cpuid, &op->u.get_para.u.cppc_para); +/* +* When cpufreq driver in cppc passive mode, it has both cppc and governor +* info. Users could only rely on "get-cpufreq-cppc" to acquire CPPC info. +* And it returns governor info in "get-cpufreq-para" +*/ +if (cpufreq_in_cppc_passive_mode (op->cpuid) ) + ret = -ENODEV ; +else + ret =get_cpufreq_cppc (op->cpuid, &op->u.get_para.u.cppc_para);if ( ret == -ENODEV ) { if ( !(scaling_available_governors =
xen/drivers/cpufreq/cpufreq.c +6 -0
@@ -962,3 +962,9 @@ int __init cpufreq_register_driver(const struct cpufreq_driver *driver_data)return 0 ; } + +bool cpufreq_in_cppc_passive_mode (unsigned int cpuid) +{ +return processor_pminfo[cpuid]->init &XEN_CPPC_INIT && + cpufreq_driver.target; +}
xen/include/acpi/cpufreq/cpufreq.h +2 -0
@@ -295,4 +295,6 @@ int acpi_cpufreq_register(void);int amd_cppc_cmdline_parse (const char *s,const char *e);int amd_cppc_register_driver (void ); +bool cpufreq_in_cppc_passive_mode (unsigned int cpuid); +#endif /* __XEN_CPUFREQ_PM_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v6 17/19] xen/cpufreq: introduce helper cpufreq_in_cppc_passive_mode()
xen/drivers/acpi/pm-op.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 159
Quoted 12 lines · Penny Zheng
xen/drivers/acpi/pm-op.c +5
-1@@ -152,7 +152,15 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)else strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN ); - ret =get_cpufreq_cppc (op->cpuid, &op->u.get_para.u.cppc_para); +/* +* When cpufreq driver in cppc passive mode, it has both cppc and governor +* info. Users could only rely on "get-cpufreq-cppc" to acquire CPPC info. +* And it returns governor info in "get-cpufreq-para" +*/
Which of the two they need to invoke to obtain a complete picture? Both? I'm confused by you bypassing get_cpufreq_cppc() (i.e. get_hwp_para()) for yet another reason, when - aiui - some information there is relevant in both active and passive modes.
xen/drivers/acpi/pm-op.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 163
Quoted 4 lines
xen/drivers/acpi/pm-op.c +4
-0+if (cpufreq_in_cppc_passive_mode (op->cpuid) ) + ret = -ENODEV ; +else + ret =get_cpufreq_cppc (op->cpuid, &op->u.get_para.u.cppc_para);
Any reason the extra check isn't put in get_cpufreq_cppc(), alongside the hwp_active() one?
xen/drivers/cpufreq/cpufreq.c int __init cpufreq_register_driver(const struct cpufreq_driver *driver_data) · line 968
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +4
-0@@ -962,3 +962,9 @@ int __init cpufreq_register_driver(const struct cpufreq_driver *driver_data)return 0 ; } + +bool cpufreq_in_cppc_passive_mode (unsigned int cpuid) +{ + return processor_pminfo[cpuid]->init & XEN_CPPC_INIT &&
Nit: Please use parentheses when using & and && together.
Also, isn't this function going to become unreachable when PM_OP=n, thus violating Misra rule 2.1?
Jan
PATCH v6 18/19 xen/cpufreq: bypass governor-related para for amd-cppc-epp
In reply to Penny ZhengHWP and amd-cppc-epp are both governor-less driver, so we introduce "hw_auto" flag to together bypass governor-related print in print_cpufreq_para().
In set_cpufreq_para(), a new helper is introduced to help error out when cpufreq core intialized in governor-less mode.
---
v3 -> v4:
- Include validation check fix here
---
v4 -> v5:
- validation check has beem moved to where XEN_PROCESSOR_PM_CPPC and XEN_CPPC_INIT have been firstly introduced
- adding "cpufreq_driver.setpolicy == NULL" check to exclude governor-related para for amd-cppc-epp driver in get/set_cpufreq_para()
---
v5 -> v6:
- add helper cpufreq_is_governorless() to tell whether cpufreq driver is governor-less
--- tools/misc/xenpm.c | 10 +++++++--- xen/drivers/acpi/pm-op.c | 4 ++-- xen/drivers/cpufreq/cpufreq.c | 6 ++++++ xen/include/acpi/cpufreq/cpufreq.h | 1 + 4 files changed, 16 insertions(+), 5 deletions(-)
tools/misc/xenpm.c +7 -3
@@ -830,9 +830,13 @@ static void print_cppc_para(unsigned int cpuid,/* print out parameters about cpu frequency */ static void print_cpufreq_para (int cpuid,struct xc_get_cpufreq_para *p_cpufreq) { -bool hwp =strcmp (p_cpufreq->scaling_driver,XEN_HWP_DRIVER_NAME ) ==0 ; +bool hw_auto = false;int i; +if ( !strcmp (p_cpufreq->scaling_driver,XEN_HWP_DRIVER_NAME ) || + !strcmp (p_cpufreq->scaling_driver,XEN_AMD_CPPC_EPP_DRIVER_NAME ) ) + hw_auto = true; +printf ("cpu id : %d\n" , cpuid);printf ("affected_cpus :" );
@@ -840,7 +844,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);
@@ -852,7 +856,7 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)printf ("scaling_driver : %s\n" , p_cpufreq->scaling_driver); -if ( hwp ) +if ( hw_auto )print_cppc_para (cpuid, &p_cpufreq->u.cppc_para);else {
xen/drivers/acpi/pm-op.c +2 -2
@@ -244,8 +244,8 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)if ( !policy || !policy->governor )return -EINVAL ; -if (hwp_active () ) -return -EOPNOTSUPP ; +if (cpufreq_is_governorless (op->cpuid) ) +return -EOPNOTSUPP ;switch ( op->u.set_para.ctrl_type ) {
xen/drivers/cpufreq/cpufreq.c +6 -0
@@ -968,3 +968,9 @@ bool cpufreq_in_cppc_passive_mode(unsigned int cpuid)return processor_pminfo[cpuid]->init &XEN_CPPC_INIT && cpufreq_driver.target; } + +bool cpufreq_is_governorless (unsigned int cpuid) +{ +return processor_pminfo[cpuid]->init && (hwp_active () || + cpufreq_driver.setpolicy); +}
xen/include/acpi/cpufreq/cpufreq.h +1 -0
@@ -296,5 +296,6 @@ int amd_cppc_cmdline_parse(const char *s, const char *e);int amd_cppc_register_driver (void );bool cpufreq_in_cppc_passive_mode (unsigned int cpuid); +bool cpufreq_is_governorless (unsigned int cpuid);#endif /* __XEN_CPUFREQ_PM_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v6 18/19] xen/cpufreq: bypass governor-related para for amd-cppc-epp
xen/drivers/cpufreq/cpufreq.c bool cpufreq_in_cppc_passive_mode(unsigned int cpuid) · line 976
Quoted 12 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +6
-0@@ -968,3 +968,9 @@ bool cpufreq_in_cppc_passive_mode(unsigned int cpuid)return processor_pminfo[cpuid]->init &XEN_CPPC_INIT && cpufreq_driver.target; } + +bool cpufreq_is_governorless (unsigned int cpuid) +{ +return processor_pminfo[cpuid]->init && (hwp_active () || + cpufreq_driver.setpolicy); +}
The function, by its name, is seemingly generic, yet its implementation is tailored to the HWP and CPPC drivers. I think such needs calling out in a comment.
Seeing the XEN_CPPC_INIT check in context, I also wonder why here you check for ->init just being non-zero.
Jan
RE: [PATCH v6 18/19] xen/cpufreq: bypass governor-related para for amd-cppc-epp
[Public]
Quoted 25 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:09 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; [email protected]
Subject: Re: [PATCH v6 18/19] xen/cpufreq: bypass governor-related para for amd- cppc-eppxen/drivers/cpufreq/cpufreq.c bool cpufreq_in_cppc_passive_mode(unsigned int cpuid) · line 975
Quoted 11 lines · Penny Zheng
xen/drivers/cpufreq/cpufreq.c +5
-0@@ -968,3 +968,9 @@ bool cpufreq_in_cppc_passive_mode(unsigned int cpuid)return processor_pminfo[cpuid]->init &XEN_CPPC_INIT && cpufreq_driver.target; } + +bool cpufreq_is_governorless (unsigned int cpuid) { +return processor_pminfo[cpuid]->init && (hwp_active () || + +cpufreq_driver.setpolicy); }The function, by its name, is seemingly generic, yet its implementation is tailored to the HWP and CPPC drivers. I think such needs calling out in a comment.
Quoted 3 lines
Seeing the
XEN_CPPC_INITcheck in context, I also wonder why here you check for ->init just being non-zero.
Checking ->init being non-zero is to ensure that cpufreq core is initialized successfully, no matter Px mode or CPPC mode. As non-zero cpufreq_driver.setpolicy callback could only verify that registered cpufreq driver is governorless. Maybe I shall add comments to explain
Quoted 1 line
Jan
Re: [PATCH v6 18/19] xen/cpufreq: bypass governor-related para for amd-cppc-epp
In reply to Penny ZhengQuoted 25 lines · Penny Zheng
HWP and amd-cppc-epp are both governor-less driver, so we introduce "
hw_auto" flag to together bypass governor-related print inprint_cpufreq_para().In
set_cpufreq_para(), a new helper is introduced to help error out when cpufreq core intialized in governor-less mode.
---
v3 -> v4:
- Include validation check fix here
---
v4 -> v5:
- validation check has beem moved to whereXEN_PROCESSOR_PM_CPPCandXEN_CPPC_INIThave been firstly introduced
- adding "cpufreq_driver.setpolicy == NULL" check to exclude governor-related para for amd-cppc-epp driver in get/set_cpufreq_para()
---
v5 -> v6:
- add helpercpufreq_is_governorless()to tell whether cpufreq driver is governor-less
---xen/drivers/acpi/pm-op.c +0
-0
xen/drivers/acpi/pm-op.c static int set_cpufreq_para(struct xen_sysctl_pm_op *op) · line 248
Quoted 7 lines
xen/drivers/acpi/pm-op.c +2
-2@@ -244,8 +244,8 @@ static int set_cpufreq_para(struct xen_sysctl_pm_op *op)if ( !policy || !policy->governor )return -EINVAL ; -if (hwp_active () ) -return -EOPNOTSUPP ; +if (cpufreq_is_governorless (op->cpuid) ) +return -EOPNOTSUPP ;
NIT: return indent off by 1.
Regards,
Jason
Quoted 3 lines
xen/drivers/acpi/pm-op.c +0
-0switch ( op->u.set_para.ctrl_type ) {
PATCH v6 19/19 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.
In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init & XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.
Also, a new field "policy" has also been added in "struct xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.
---
v1 -> v2:
- Give the variable des_perf an initializer of 0
- Use the strncmp()s directly in the if()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replace amd_cppc_in_use flag with XEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "struct xen_cppc_para"
- add new performamce policy XEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init & XEN_CPPC_INIT" and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space tools
--- tools/misc/xenpm.c | 11 ++ xen/arch/x86/acpi/cpufreq/amd-cppc.c | 180 +++++++++++++++++++++++++++ xen/drivers/acpi/pm-op.c | 10 +- xen/include/acpi/cpufreq/cpufreq.h | 19 +-- xen/include/public/sysctl.h | 17 +++ 5 files changed, 219 insertions(+), 18 deletions(-)
tools/misc/xenpm.c +11 -0
@@ -38,6 +38,13 @@static xc_interface *xc_handle;static unsigned int max_cpu_nr; +static const char cpufreq_policy_str[][12 ] = { + [CPUFREQ_POLICY_UNKNOWN ] ="unknown" , + [CPUFREQ_POLICY_POWERSAVE ] ="powersave" , + [CPUFREQ_POLICY_PERFORMANCE ] ="performance" , + [CPUFREQ_POLICY_ONDEMAND ] ="ondemand" , +}; +/* help message */ void show_help (void ) {
@@ -825,6 +832,10 @@ static void print_cppc_para(unsigned int cpuid,printf (" : desired [%" PRIu32"%s]\n" , cppc->desired, cppc->desired ?"" :" hw autonomous" ); + +if ( cppc->policy <CPUFREQ_POLICY_END ) +printf (" performance policy : %s\n" , + cpufreq_policy_str[cppc->policy]); }/* print out parameters about cpu frequency */
xen/arch/x86/acpi/cpufreq/amd-cppc.c +180 -0
186 lines not on this page · raw message
xen/drivers/acpi/pm-op.c +7 -3
@@ -84,6 +84,8 @@ static int get_cpufreq_cppc(unsigned int cpu,if (hwp_active () ) ret =get_hwp_para (cpu, cppc_para); +else if ( processor_pminfo[cpu]->init &XEN_CPPC_INIT ) + ret =get_amd_cppc_para (per_cpu (cpufreq_cpu_policy, cpu), cppc_para);return ret; }
@@ -325,10 +327,12 @@ 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); +else if ( processor_pminfo[op->cpuid]->init &XEN_CPPC_INIT ) +return set_amd_cppc_para (policy, &op->u.set_cppc); -return set_hwp_para (policy, &op->u.set_cppc); +return -EOPNOTSUPP ; }int do_pm_op (struct xen_sysctl_pm_op *op)
xen/include/acpi/cpufreq/cpufreq.h +4 -15
@@ -133,21 +133,6 @@ 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 -/* -* Performance Policy -* If cpufreq_driver->target() exists, the ->governor decides what frequency -* within the limits is used. If cpufreq_driver->setpolicy() exists, these -* following policies are available: -* CPUFREQ_POLICY_PERFORMANCE represents maximum performance -* CPUFREQ_POLICY_POWERSAVE represents least power consumption -* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or -* powersave -*/ -#define CPUFREQ_POLICY_UNKNOWN 0 -#define CPUFREQ_POLICY_POWERSAVE 1 -#define CPUFREQ_POLICY_PERFORMANCE 2 -#define CPUFREQ_POLICY_ONDEMAND 3 -unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov);/* pass a target to the cpufreq driver */
@@ -294,6 +279,10 @@ int acpi_cpufreq_register(void);int amd_cppc_cmdline_parse (const char *s,const char *e);int amd_cppc_register_driver (void ); +int get_amd_cppc_para (const struct cpufreq_policy *policy, +struct xen_get_cppc_para *cppc_para); +int set_amd_cppc_para (struct cpufreq_policy *policy, +const struct xen_set_cppc_para *set_cppc);bool cpufreq_in_cppc_passive_mode (unsigned int cpuid);bool cpufreq_is_governorless (unsigned int cpuid);
xen/include/public/sysctl.h +17 -0
@@ -336,8 +336,25 @@ struct xen_ondemand {uint32_t up_threshold; }; +/* +* Performance Policy +* If cpufreq_driver->target() exists, the ->governor decides what frequency +* within the limits is used. If cpufreq_driver->setpolicy() exists, these +* following policies are available: +* CPUFREQ_POLICY_PERFORMANCE represents maximum performance +* CPUFREQ_POLICY_POWERSAVE represents least power consumption +* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or +* powersave +*/ +#define CPUFREQ_POLICY_UNKNOWN 0 +#define CPUFREQ_POLICY_POWERSAVE 1 +#define CPUFREQ_POLICY_PERFORMANCE 2 +#define CPUFREQ_POLICY_ONDEMAND 3 +#define CPUFREQ_POLICY_END 4 +struct xen_get_cppc_para {/* OUT */ +uint32_t policy;/* CPUFREQ_POLICY_xxx */ /* activity_window supported if set */ #define XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW (1 << 0)uint32_t features;/* bit flags for features */
Signature · 1 line
2.34.1
Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
Quoted 7 lines · Penny Zheng
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.
Quoted 5 lines
Also, a new field "policy" has also been added in "struct
xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.
If only they indeed had XEN_ prefixes.
Quoted 17 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &XEN_CPPC_INIT" and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
Quoted 8 lines
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space tools
Please don't; use ARRAY_SIZE() (and if necessary further checking) instead. In fact I think ...
Quoted 17 lines
tools/misc/xenpm.c +7
-0@@ -38,6 +38,13 @@static xc_interface *xc_handle;static unsigned int max_cpu_nr; +static const char cpufreq_policy_str[][12 ] = { + [CPUFREQ_POLICY_UNKNOWN ] ="unknown" , + [CPUFREQ_POLICY_POWERSAVE ] ="powersave" , + [CPUFREQ_POLICY_PERFORMANCE ] ="performance" , + [CPUFREQ_POLICY_ONDEMAND ] ="ondemand" , +}; +/* help message */ void show_help (void ) {
tools/misc/xenpm.c static void print_cppc_para(unsigned int cpuid, · line 838
Quoted 7 lines
tools/misc/xenpm.c +4
-0@@ -825,6 +832,10 @@ static void print_cppc_para(unsigned int cpuid,printf (" : desired [%" PRIu32"%s]\n" , cppc->desired, cppc->desired ?"" :" hw autonomous" ); + +if ( cppc->policy <CPUFREQ_POLICY_END ) +printf (" performance policy : %s\n" , + cpufreq_policy_str[cppc->policy]);
... you would want to print "unknown" in all other cases as well.
It's not clear to me though how the printing is avoided for passive mode.
Quoted 31 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +25
-0@@ -561,6 +561,186 @@ static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)return 0 ; } +int get_amd_cppc_para (const struct cpufreq_policy *policy, +struct xen_get_cppc_para *cppc_para) +{ +const struct amd_cppc_drv_data *data =per_cpu (amd_cppc_drv_data, + policy->cpu); + +if ( data ==NULL ) +return -ENODATA ; + + cppc_para->policy = policy->policy; + cppc_para->lowest = data->caps.lowest_perf; + cppc_para->lowest_nonlinear = data->caps.lowest_nonlinear_perf; + cppc_para->nominal = data->caps.nominal_perf; + cppc_para->highest = data->caps.highest_perf; + cppc_para->minimum = data->req.min_perf; + cppc_para->maximum = data->req.max_perf; + cppc_para->desired = data->req.des_perf; + cppc_para->energy_perf = data->req.epp; + +return 0 ; +} + +int set_amd_cppc_para (struct cpufreq_policy *policy, +const struct xen_set_cppc_para *set_cppc) +{
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 598
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+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; +bool active_mode; + +if ( data ==NULL ) +return -ENOENT ; + +if (cpufreq_is_governorless (cpu) ) + active_mode = true;
Without "else" the variable will be left uninitialized. I'm surprised the compiler allowed you to get away with this. Why is the function call not simply the variable's initializer?
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0+/* Only allow values if params bit is set. */ + if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) && + set_cppc->desired) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM) && + set_cppc->minimum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) && + set_cppc->maximum) ||
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 616
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ (!(set_cppc->set_params &XEN_SYSCTL_CPPC_SET_ENERGY_PERF ) && + set_cppc->energy_perf) ) + return -EINVAL; + +/* +* Validate all parameters +* Maximum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM &&
Nit: Missing parentheses again. Which is particularly odd since in the immediately preceding if() they're there. More of this further down.
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 629
Quoted 13 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +13
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL; +/* +* Minimum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive but must +* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) &&
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM
? set_cppc->maximum
: data->req.max_perf)Which also makes it easier to spot that here you use data->req, when in the minimum check you use data->caps. Why this difference?
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ set_cppc->minimum > data->req.max_perf)) ) +return -EINVAL ; +/* +* Desired performance may be set to any performance value in the range +* [Minimum Performance, Maximum Performance], inclusive. +*/ +if ( set_cppc->set_params &XEN_SYSCTL_CPPC_SET_DESIRED ) + { +if ( active_mode ) +return -EOPNOTSUPP ;
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 649
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ +if ( (set_cppc->set_params &XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->desired > set_cppc->maximum) || + (set_cppc->set_params &XEN_SYSCTL_CPPC_SET_MINIMUM && + set_cppc->desired < set_cppc->minimum) || + (!(set_cppc->set_params &XEN_SYSCTL_CPPC_SET_MAXIMUM ) && + set_cppc->desired > data->req.max_perf) || + (!(set_cppc->set_params &XEN_SYSCTL_CPPC_SET_MINIMUM ) && + set_cppc->desired < data->req.min_perf) ) +return -EINVAL ;
All of the above applies here as well.
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+ } +/* +* Energy Performance Preference may be set with a range of values +* from 0 to 0xFF +*/ +if ( set_cppc->set_params &XEN_SYSCTL_CPPC_SET_ENERGY_PERF ) + { +if ( !active_mode ) +return -EOPNOTSUPP ; + +if ( set_cppc->energy_perf >UINT_MAX )
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 670
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+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 ;
Why did this move so far down (I think it was sitting earlier)? The earlier 5 if()s are all needlessly carried out in this case (unless the compiler can reason about moving this check ahead).
Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +8
-0+ epp =per_cpu (epp_init, cpu); +/* +* Apply presets: +* XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE/PERFORMANCE/ONDEMAND are +* only available when CPPC in active mode +*/ +switch ( set_cppc->set_params &XEN_SYSCTL_CPPC_SET_PRESET_MASK ) + {
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 689
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE : +if ( !active_mode ) +return -EINVAL ; + policy->policy =CPUFREQ_POLICY_POWERSAVE ; + min_perf = data->caps.lowest_nonlinear_perf; +/* +* Lower max_perf to nonlinear_lowest to achieve +* ultmost power saviongs +*/ + max_perf = data->caps.lowest_nonlinear_perf;
Why not use the shorter "min_perf" here?
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 699
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+ epp =CPPC_ENERGY_PERF_MAX_POWERSAVE ; +break ; + +case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE : +if ( !active_mode ) +return -EINVAL ; + policy->policy =CPUFREQ_POLICY_PERFORMANCE ; +/* Increase min_perf to highest to achieve ultmost performance */ + min_perf = data->caps.highest_perf; + max_perf = data->caps.highest_perf;
And "max_perf" here? Furthermore if you moved ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 708
Quoted 9 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +9
-0+ epp =CPPC_ENERGY_PERF_MAX_PERFORMANCE ; +break ; + +case XEN_SYSCTL_CPPC_SET_PRESET_ONDEMAND : +if ( !active_mode ) +return -EINVAL ; + policy->policy =CPUFREQ_POLICY_ONDEMAND ; + min_perf = data->caps.lowest_nonlinear_perf; + max_perf = data->caps.highest_perf;
... these two ahead of the switch(), you could further reduce the number of assignments (overrides) done, including ...
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 719
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +11
-0+/* +* Take medium value to show no preference over +* performance or powersave +*/ + epp =CPPC_ENERGY_PERF_BALANCE ; +break ; + +case XEN_SYSCTL_CPPC_SET_PRESET_NONE : + policy->policy =CPUFREQ_POLICY_UNKNOWN ; + min_perf = data->caps.lowest_nonlinear_perf; + max_perf = data->caps.highest_perf;
... the dropping of these two lines.
Quoted 12 lines
xen/drivers/acpi/pm-op.c +2
-0@@ -84,6 +84,8 @@ static int get_cpufreq_cppc(unsigned int cpu,if (hwp_active () ) ret =get_hwp_para (cpu, cppc_para); +else if ( processor_pminfo[cpu]->init &XEN_CPPC_INIT ) + ret =get_amd_cppc_para (per_cpu (cpufreq_cpu_policy, cpu), cppc_para);return ret; }
xen/drivers/acpi/pm-op.c static int set_cpufreq_cppc(struct xen_sysctl_pm_op *op) · line 332
Quoted 8 lines
xen/drivers/acpi/pm-op.c +3
-2@@ -325,10 +327,12 @@ 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); +else if ( processor_pminfo[op->cpuid]->init &XEN_CPPC_INIT )
As before, please can you avoid the use of "else" in such cases. Strictly speaking that's "dead code" in Misra's nomeclature.
Quoted 41 lines
xen/include/acpi/cpufreq/cpufreq.h +4
-15@@ -133,21 +133,6 @@ 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 -/* -* Performance Policy -* If cpufreq_driver->target() exists, the ->governor decides what frequency -* within the limits is used. If cpufreq_driver->setpolicy() exists, these -* following policies are available: -* CPUFREQ_POLICY_PERFORMANCE represents maximum performance -* CPUFREQ_POLICY_POWERSAVE represents least power consumption -* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or -* powersave -*/ -#define CPUFREQ_POLICY_UNKNOWN 0 -#define CPUFREQ_POLICY_POWERSAVE 1 -#define CPUFREQ_POLICY_PERFORMANCE 2 -#define CPUFREQ_POLICY_ONDEMAND 3 -unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov);/* pass a target to the cpufreq driver */ @@ -294,6 +279,10 @@ int acpi_cpufreq_register(void);int amd_cppc_cmdline_parse (const char *s,const char *e);int amd_cppc_register_driver (void ); +int get_amd_cppc_para (const struct cpufreq_policy *policy, +struct xen_get_cppc_para *cppc_para); +int set_amd_cppc_para (struct cpufreq_policy *policy, +const struct xen_set_cppc_para *set_cppc);bool cpufreq_in_cppc_passive_mode (unsigned int cpuid);bool cpufreq_is_governorless (unsigned int cpuid);xen/include/public/sysctl.h +0
-0@@ -336,8 +336,25 @@ struct xen_ondemand {uint32_t up_threshold; };
xen/include/public/sysctl.h struct xen_ondemand { · line 348
Quoted 10 lines
xen/include/public/sysctl.h +10
-0+/* +* Performance Policy +* If cpufreq_driver->target() exists, the ->governor decides what frequency +* within the limits is used. If cpufreq_driver->setpolicy() exists, these +* following policies are available: +* CPUFREQ_POLICY_PERFORMANCE represents maximum performance +* CPUFREQ_POLICY_POWERSAVE represents least power consumption +* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or +* powersave +*/
I appreciate that you want to retain the comment, but implementation details of the hypervisor imo don't belong in public headers. That internal part may want to move to e.g. the respective (internal) struct field.
Jan
RE: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
[Public]
Quoted 71 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:44 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPCxen_sysctl_pm_opfor amd-cppc driverQuoted 7 lines · Penny Zheng
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.Quoted 5 lines
Also, a new field "policy" has also been added in "struct
xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.If only they indeed had
XEN_prefixes.Quoted 15 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT"Quoted 16 lines
and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space toolsxen/arch/x86/acpi/cpufreq/amd-cppc.c +3
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL;xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 629
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+/* +* Minimum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive but must +* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) &&
Quoted 9 lines
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ? set_cppc->maximum : data->req.max_perf)
Thx, understood!
Quoted 3 lines
Which also makes it easier to spot that here you use
data->req, when in the minimum check you usedata->caps. Why this difference?
minimum check has two boundary check,
left boundary check is against data->caps.lowest_nonlinear_perf. And right boundary check is against data->req.max_perf. As it shall not only not larger than caps.highest_perf , but also req.max_perf. The relation between max_perf and highest_perf is validated in the maximum check. So here, we are only considering max_perf
Quoted 1 line
Jan
Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
Quoted 83 lines · Zheng
[Public]
Quoted 71 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:44 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPCxen_sysctl_pm_opfor amd-cppc driverQuoted 7 lines · Penny Zheng
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.Quoted 5 lines
Also, a new field "policy" has also been added in "struct
xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.If only they indeed had
XEN_prefixes.Quoted 15 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT"Quoted 16 lines
and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space toolsxen/arch/x86/acpi/cpufreq/amd-cppc.c +3
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL;xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy) · line 629
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +10
-0+/* +* Minimum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive but must +* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) &&Quoted 9 lines
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ? set_cppc->maximum : data->req.max_perf)
Quoted 8 lines
Thx, understood!
Quoted 3 lines
Which also makes it easier to spot that here you use
data->req, when in the minimum check you usedata->caps. Why this difference?minimum check has two boundary check,
left boundary check is againstdata->caps.lowest_nonlinear_perf. And right boundary check is againstdata->req.max_perf. As it shall not only not larger than caps.highest_perf , but also req.max_perf. The relation betweenmax_perfandhighest_perfis validated in the maximum check. So here, we are only consideringmax_perf
I still don't get why one check is against capabilities (permitted values) why the other is again what's currently set.
Jan
RE: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
[Public]
Quoted 113 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, August 14, 2025 2:40 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPCxen_sysctl_pm_opfor amd-cppc driverQuoted 13 lines · Zheng
[Public]
Quoted 11 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:44 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: AdaptSET/GET_CPUFREQ_CPPC
Quoted 45 lines
Quoted 45 lines
xen_sysctl_pm_opfor amd-cppc driverQuoted 7 lines · Penny Zheng
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.Quoted 5 lines
Also, a new field "policy" has also been added in "struct
xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.If only they indeed had
XEN_prefixes.Quoted 15 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT"Quoted 11 lines
and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"Quoted 8 lines
Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
Quoted 8 lines
- introduce "
CPUFREQ_POLICY_END" for array overrun check in user space toolsxen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL; +/* +* Minimum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive but must
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0+* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM)&&
Quoted 17 lines
Quoted 10 lines
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ? set_cppc->maximum : data->req.max_perf)Thx, understood!
Quoted 3 lines
Which also makes it easier to spot that here you use
data->req, when in the minimum check you usedata->caps. Why this difference?Quoted 6 lines
minimum check has two boundary check, left boundary check is against
data->caps.lowest_nonlinear_perf. And right boundary check is againstdata->req.max_perf. As it shall not only not larger than caps.highest_perf , but also req.max_perf. The relation betweenmax_perfandhighest_perfis validated in the maximum check. So here, we are only consideringmax_perf
Quoted 2 lines
I still don't get why one check is against capabilities (permitted values) why the other is again what's currently set.
It needs to meet the following two criteria:
1. caps.lowest_nonlinear <= min_perf <= caps.highest_perf
2. min_perf <= max_perf. If users don't set max_perf at the same time, we are using the values stored in req.max_perf, which is the last setting.
Quoted 2 lines
Jan
Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
Quoted 115 lines · Zheng
[Public]
Quoted 113 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, August 14, 2025 2:40 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPCxen_sysctl_pm_opfor amd-cppc driverQuoted 13 lines · Zheng
[Public]
Quoted 11 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:44 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: AdaptSET/GET_CPUFREQ_CPPC
Quoted 45 lines
Quoted 45 lines
xen_sysctl_pm_opfor amd-cppc driverQuoted 7 lines · Penny Zheng
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.Quoted 5 lines
Also, a new field "policy" has also been added in "struct
xen_get_cppc_para" to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants "XEN_CPUFREQ_POLICY_xxx" to public header to let it be used in user space tools. Also add a new anchor "XEN_CPUFREQ_POLICY_xxx" for array overrun check.If only they indeed had
XEN_prefixes.Quoted 15 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT"Quoted 11 lines
and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"Quoted 8 lines
Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
Quoted 8 lines
- introduce "
CPUFREQ_POLICY_END" for array overrun check in user space toolsxen/arch/x86/acpi/cpufreq/amd-cppc.c +6
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL; +/* +* Minimum performance may be set to any performance value in the range +* [Nonlinear Lowest Performance, Highest Performance], inclusive but must
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +7
-0+* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM && + set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM)&&
Quoted 23 lines
Quoted 10 lines
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ? set_cppc->maximum : data->req.max_perf)Thx, understood!
Quoted 3 lines
Which also makes it easier to spot that here you use
data->req, when in the minimum check you usedata->caps. Why this difference?minimum check has two boundary check, left boundary check is against
data->caps.lowest_nonlinear_perf. And right boundary check is againstdata->req.max_perf. As it shall not only not larger than caps.highest_perf , but also req.max_perf. The relation betweenmax_perfandhighest_perfis validated in the maximum check. So here, we are only consideringmax_perf
Quoted 7 lines
Quoted 2 lines
I still don't get why one check is against capabilities (permitted values) why the other is again what's currently set.
It needs to meet the following two criteria:
1. caps.lowest_nonlinear <=
min_perf<= caps.highest_perf
2.min_perf<=max_perf. If users don't setmax_perfat the same time, we are using the values stored in req.max_perf, which is the last setting.
Hmm, I see. Yet then what about the case of max being set without also setting min? Overall I'm expecting full symmetry in the checking that's being done.
Jan
RE: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
[Public]
Quoted 141 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, August 14, 2025 4:30 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPCxen_sysctl_pm_opfor amd-cppc driverQuoted 13 lines · Zheng
[Public]
Quoted 11 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, August 14, 2025 2:40 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>; xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: AdaptSET/GET_CPUFREQ_CPPC
Quoted 21 lines
Quoted 21 lines
xen_sysctl_pm_opfor amd-cppc driverQuoted 14 lines · Zheng
[Public]
Quoted 12 lines
-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: Thursday, July 24, 2025 10:44 PM
To: Penny, Zheng <[email protected]>
Cc: Huang, Ray <[email protected]>; Anthony PERARD <[email protected]>; Andrew Cooper <[email protected]>; Orzel, Michal <[email protected]>; Julien Grall <[email protected]>; Roger Pau Monné <[email protected]>; Stefano Stabellini <[email protected]>;
xen- [email protected]
Subject: Re: [PATCH v6 19/19] xen/cpufreq: AdaptSET/GET_CPUFREQ_CPPC
Quoted 3 lines
Quoted 3 lines
xen_sysctl_pm_opfor amd-cppc driverOn 11.07.2025 05:51, Penny Zheng wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Introduce helper
set_amd_cppc_para()andget_amd_cppc_para()to SET/GET CPPC-related para for amd-cppc/amd-cppc-epp driver.In get_cpufreq_cppc()/set_cpufreq_cppc(), we include "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT" condition check to deal with cpufreq driver in amd-cppc.Also, a new field "policy" has also been added in "struct
xen_get_cppc_para"Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
to describe performance policy in active mode. It gets printed with other cppc paras. Move manifest constants
"
XEN_CPUFREQ_POLICY_xxx"Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 2 lines
to public header to let it be used in user space tools. Also add a new anchor "
XEN_CPUFREQ_POLICY_xxx" for array overrun check.If only they indeed had
XEN_prefixes.Quoted 15 lines
Signed-off-by Penny Zheng <[email protected]>---
v1 -> v2:
- Give the variabledes_perfan initializer of 0
- Use the strncmp()s directly in theif()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replaceamd_cppc_in_useflag withXEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "structxen_cppc_para"
- add new performamce policyXEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init &
XEN_CPPC_INIT"Quoted 10 lines
and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf valuesQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c static int cf_check amd_cppc_epp_set_policy(struct cpufreq_policy *policy)
Quoted 8 lines
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space toolsxen/arch/x86/acpi/cpufreq/amd-cppc.c +5
-0+ (set_cppc->maximum > data->caps.highest_perf || + set_cppc->maximum < data->caps.lowest_nonlinear_perf) ) + return -EINVAL; +/* +* Minimum performance may be set to any performance value in the range
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ * [Nonlinear Lowest Performance, Highest Performance],
+ inclusive butmust
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/acpi/cpufreq/amd-cppc.c +5
-0+* be set to a value that is less than or equal to Maximum Performance. +*/ + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM && + (set_cppc->minimum < data->caps.lowest_nonlinear_perf || + (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM&&
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ set_cppc->minimum > set_cppc->maximum) || + (!(set_cppc->set_params &
XEN_SYSCTL_CPPC_SET_MAXIMUM)Quoted 29 lines
Quoted 28 lines
&&
Quoted 17 lines
Quoted 10 lines
Hmm, I find this confusing to read, and was first thinking the ! was wrong here. Imo such is better expressed with the conditional operator:
set_cppc->minimum > (set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM ? set_cppc->maximum : data->req.max_perf)Thx, understood!
Quoted 3 lines
Which also makes it easier to spot that here you use
data->req, when in the minimum check you usedata->caps. Why this difference?Quoted 7 lines
minimum check has two boundary check, left boundary check is
againstdata->caps.lowest_nonlinear_perf. And right boundary check isdata->againstreq.max_perf. As it shall not only not larger than caps.highest_perf , but also req.max_perf. The relation betweenmax_perfandhighest_perfis validated in the maximum check. So here, we are only consideringmax_perfI still don't get why one check is against capabilities (permitted values) why the other is again what's currently set.
Quoted 9 lines
Quoted 4 lines
It needs to meet the following two criteria:
1. caps.lowest_nonlinear <=
min_perf<= caps.highest_perf 2.min_perf<=max_perf. If users don't setmax_perfat the same time, we are using thevalues stored in req.max_perf, which is the last setting.
Hmm, I see. Yet then what about the case of max being set without also setting min? Overall I'm expecting full symmetry in the checking that's being done.
Oh, True, I forget symmetry scenario, will add.
Quoted 1 line
Jan