Enhanced autonomous selection and improvements
Subsystems (7)
Sumit Gupta
reviewerv3 cover Enhanced autonomous selection and improvements
This patch series enhances the ACPI CPPC CPUFREQ driver with comprehensive support for autonomous performance selection, expanded runtime control interfaces and improvements.
It adds support for below:
- Expose sysfs to read/write the Mininum/Maximum Performance Register and update the policy min/max accordingly. /sys/.../cpufreq/policy*/min_perf and max_perf
- Expose sysfs to read/write the Performance Limited Register.
/sys/.../cpufreq/policy*/perf_limited
- When toggling autonomous selection, synchronize the policy limits by updating the policy min/max.
- System-wide autonomous mode configuration via 'auto_sel_mode' boot parameter. Mode can be switched dynamically on individual CPUs.
- Generic sysfs helper functions to reduce code duplication.
The patches are grouped as below:
- Patch 1, 2 & 3: Improvements. Can be applied independently.
- Patch 4: Sysfs to update min/max_perf. Can be applied independently.
- Patch 5: Sysfs to update perf_limited. Can be applied independently.
- Patch 6: add syfs documentation. Depends on 'Patch 4 and 5'.
- Patch 7: sync policy min/max with auto_select. Depends on 'Patch 4'.
- Patch 8: Boot Parameter Support. Depends on 'Patch 4 and 7'.
---
v2[2] -> v3:
- drop changes to rename exisiting APIs.
- add new 'patch 1' with generic helpers for sysfs show/store.
- used guard(mutex)() in place of mutex_lock/unlock.
- update kernel-parameters text to 'enable if supported by hardware'.
- disable auto_sel for all cpus if one fails in auto_sel_mode.
- use min/max_perf values if set from bootloader.
- general code improvements, error handling and reduced redundancies.
v1[1] -> v2:
- Move CPC register set sysfs from acpi_cppc to cpufreq directory.
- No sysfs to set auto_sel and epp. They were merged from diff series.
- Remove 'cppc_cpufreq_epp' instance of the 'cppc_cpufreq' driver.
- Synchronize perf_min/max with policy min/max.
- Update policy min/max Toggling auto_select.
- add sysfs to update the perf_limited register.
Sumit Gupta (8):
cpufreq: CPPC: Add generic helpers for sysfs show/store
ACPI: CPPC: Add cppc_get_perf() API to read performance controls
ACPI: CPPC: extend APIs to support auto_sel and epp
ACPI: CPPC: add APIs and sysfs interface for min/max_perf
ACPI: CPPC: add APIs and sysfs interface for perf_limited register
cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
cpufreq: CPPC: update policy min/max when toggling auto_select
cpufreq: CPPC: add autonomous mode boot parameter support
.../ABI/testing/sysfs-devices-system-cpu | 43 ++ .../admin-guide/kernel-parameters.txt | 12 + drivers/acpi/cppc_acpi.c | 184 +++++++- drivers/cpufreq/cppc_cpufreq.c | 392 ++++++++++++++++-- include/acpi/cppc_acpi.h | 39 +- 5 files changed, 629 insertions(+), 41 deletions(-)
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 1/8 cpufreq: CPPC: Add generic helpers for sysfs show/store
Add generic show/store helper functions for u64 sysfs attributes:
- cppc_cpufreq_sysfs_show_u64()
- cppc_cpufreq_sysfs_store_u64()
Refactor auto_act_window and energy_performance_preference_val attributes to use these helpers, eliminating code duplication.
No functional changes.
--- drivers/cpufreq/cppc_cpufreq.c | 87 ++++++++++++++-------------------- 1 file changed, 35 insertions(+), 52 deletions(-)
drivers/cpufreq/cppc_cpufreq.c +35 -52
@@ -781,6 +781,36 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)return 0 ; } +static ssize_t cppc_cpufreq_sysfs_show_u64 (unsigned int cpu,int (*get_func)(int ,u64 *),char *buf) +{ +u64 val; +int ret =get_func (cpu, &val); + +if (ret == -EOPNOTSUPP ) +return sysfs_emit (buf,"<unsupported>\n" ); +if (ret) +return ret; + +return sysfs_emit (buf,"%llu\n" , val); +} + +static ssize_t cppc_cpufreq_sysfs_store_u64 (const char *buf,size_t count, +int (*set_func)(int ,u64 ),unsigned int cpu) +{ +u64 val; +int ret; + +if (!buf || !set_func) +return -EINVAL ; + + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =set_func ((int )cpu, val); +return ret ? ret : count; +} +static ssize_t show_freqdomain_cpus (struct cpufreq_policy *policy,char *buf) {struct cppc_cpudata *cpu_data = policy->driver_data;
@@ -824,70 +854,23 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,static ssize_t show_auto_act_window (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_auto_act_window (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_auto_act_window, buf); } -static ssize_t store_auto_act_window (struct cpufreq_policy *policy, -const char *buf,size_t count) +static ssize_t store_auto_act_window (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 usec; -int ret; - - ret =kstrtou64 (buf,0 , &usec); -if (ret) -return ret; - - ret =cppc_set_auto_act_window (policy->cpu, usec); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_auto_act_window, policy->cpu); }static ssize_t show_energy_performance_preference_val (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_epp_perf (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_epp_perf, buf); }static ssize_t store_energy_performance_preference_val (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 val; -int ret; - - ret =kstrtou64 (buf,0 , &val); -if (ret) -return ret; - - ret =cppc_set_epp (policy->cpu, val); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_epp, policy->cpu); }cpufreq_freq_attr_ro (freqdomain_cpus);
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 3/8 ACPI: CPPC: extend APIs to support auto_sel and epp
In reply to Sumit Gupta- Add auto_sel read support in cppc_get_perf_caps().
- Add write of both auto_sel and energy_perf in cppc_set_epp_perf().
- Remove redundant energy_perf field from 'struct cppc_perf_caps' as the same is available in 'struct cppc_perf_ctrls' which is used.
--- drivers/acpi/cppc_acpi.c | 30 ++++++++++++++++++++++++++---- include/acpi/cppc_acpi.h | 1 - 2 files changed, 26 insertions(+), 5 deletions(-)
drivers/acpi/cppc_acpi.c +26 -4
@@ -1344,8 +1344,8 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpunum);struct cpc_register_resource *highest_reg, *lowest_reg, *lowest_non_linear_reg, *nominal_reg, *guaranteed_reg, - *low_freq_reg =NULL , *nom_freq_reg =NULL ; -u64 high, low, guaranteed, nom, min_nonlinear, low_f =0 , nom_f =0 ; + *low_freq_reg =NULL , *nom_freq_reg =NULL , *auto_sel_reg =NULL ; +u64 high, low, guaranteed, nom, min_nonlinear, low_f =0 , nom_f =0 , auto_sel =0 ;int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpunum);struct cppc_pcc_data *pcc_ss_data =NULL ;int ret =0 , regs_in_pcc =0 ;
@@ -1362,11 +1362,12 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps) low_freq_reg = &cpc_desc->cpc_regs[LOWEST_FREQ ]; nom_freq_reg = &cpc_desc->cpc_regs[NOMINAL_FREQ ]; guaranteed_reg = &cpc_desc->cpc_regs[GUARANTEED_PERF ]; + auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ];/* Are any of the regs PCC ?*/ if (CPC_IN_PCC (highest_reg) ||CPC_IN_PCC (lowest_reg) ||CPC_IN_PCC (lowest_non_linear_reg) ||CPC_IN_PCC (nominal_reg) || -CPC_IN_PCC (low_freq_reg) ||CPC_IN_PCC (nom_freq_reg)) { +CPC_IN_PCC (low_freq_reg) ||CPC_IN_PCC (nom_freq_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id\n" );return -ENODEV ;
@@ -1414,6 +1415,9 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps) perf_caps->lowest_freq = low_f; perf_caps->nominal_freq = nom_f; +if (CPC_SUPPORTED (auto_sel_reg)) +cpc_read (cpunum, auto_sel_reg, &auto_sel); + perf_caps->auto_sel = (bool )auto_sel; out_err:if (regs_in_pcc)
@@ -1555,6 +1559,8 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)struct cpc_register_resource *auto_sel_reg;struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool autosel_support_in_ffh_or_sysmem; +bool epp_support_in_ffh_or_sysmem;int ret;if (!cpc_desc) {
@@ -1565,6 +1571,11 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ]; epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; + epp_support_in_ffh_or_sysmem =CPC_SUPPORTED (epp_set_reg) && + (CPC_IN_FFH (epp_set_reg) ||CPC_IN_SYSTEM_MEMORY (epp_set_reg)); + autosel_support_in_ffh_or_sysmem =CPC_SUPPORTED (auto_sel_reg) && + (CPC_IN_FFH (auto_sel_reg) ||CPC_IN_SYSTEM_MEMORY (auto_sel_reg)); +if (CPC_IN_PCC (epp_set_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);
@@ -1590,8 +1601,19 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) ret =send_pcc_cmd (pcc_ss_id,CMD_WRITE );up_write (&pcc_ss_data->pcc_lock); }else if (osc_cpc_flexible_adr_space_confirmed && -CPC_SUPPORTED (epp_set_reg) &&CPC_IN_FFH (epp_set_reg)) { + epp_support_in_ffh_or_sysmem && autosel_support_in_ffh_or_sysmem) { + ret =cpc_write (cpu, auto_sel_reg, enable); +if (ret) { +pr_debug ("Failed to write auto_sel=%d for CPU:%d\n" , enable, cpu); +return ret; + } + ret =cpc_write (cpu, epp_set_reg, perf_ctrls->energy_perf); +if (ret) { +pr_debug ("Failed to write energy_perf=%u for CPU:%d\n" , + perf_ctrls->energy_perf, cpu); +return ret; + } }else { ret = -ENOTSUPP ;pr_debug ("_CPC in PCC and _CPC in FFH are not supported\n" );
include/acpi/cppc_acpi.h +0 -1
@@ -119,7 +119,6 @@ struct cppc_perf_caps {u32 lowest_nonlinear_perf;u32 lowest_freq;u32 nominal_freq; -u32 energy_perf;bool auto_sel; };
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 4/8 ACPI: CPPC: add APIs and sysfs interface for min/max_perf
In reply to Sumit GuptaCPPC allows platforms to specify minimum and maximum performance limits that constrain the operating range for CPU performance scaling when Autonomous Selection is enabled. These limits can be dynamically adjusted to implement power management policies or workload-specific optimizations.
Add cppc_get_min_perf() and cppc_set_min_perf() functions to read and write the MIN_PERF register, allowing dynamic adjustment of the minimum performance floor.
Add cppc_get_max_perf() and cppc_set_max_perf() functions to read and write the MAX_PERF register, enabling dynamic ceiling control for maximum performance.
Expose these capabilities through cpufreq sysfs attributes:
- /sys/.../cpufreq/policy*/min_perf: Read/write min performance limit
- /sys/.../cpufreq/policy*/max_perf: Read/write max performance limit
Also update EPP constants for better clarity:
- Rename CPPC_ENERGY_PERF_MAX to CPPC_EPP_ENERGY_EFFICIENCY_PREF
- Add CPPC_EPP_PERFORMANCE_PREF for the performance-oriented setting
--- drivers/acpi/cppc_acpi.c | 55 +++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 115 +++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 23 ++++++- 3 files changed, 191 insertions(+), 2 deletions(-)
drivers/acpi/cppc_acpi.c +54 -1
@@ -1630,7 +1630,7 @@ EXPORT_SYMBOL_GPL(cppc_set_epp_perf);*/ int cppc_set_epp (int cpu,u64 epp_val) { -if (epp_val >CPPC_ENERGY_PERF_MAX ) +if (epp_val >CPPC_EPP_ENERGY_EFFICIENCY_PREF )return -EINVAL ;return cppc_set_reg_val (cpu,ENERGY_PERF , epp_val);
@@ -1753,6 +1753,59 @@ int cppc_set_enable(int cpu, bool enable)return cppc_set_reg_val (cpu,ENABLE , enable); }EXPORT_SYMBOL_GPL (cppc_set_enable); + +/** +* cppc_get_min_perf - Get the min performance register value. +* @cpu: CPU from which to get min performance. +* @min_perf: Return address. +* +* Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if not supported. +*/ +int cppc_get_min_perf (int cpu,u64 *min_perf) +{ +return cppc_get_reg_val (cpu,MIN_PERF , min_perf); +} +EXPORT_SYMBOL_GPL (cppc_get_min_perf); + +/** +* cppc_set_min_perf() - Write the min performance register. +* @cpu: CPU on which to write register. +* @min_perf: Value to write to the MIN_PERF register. +* +* Return: 0 for success, -EIO otherwise. +*/ +int cppc_set_min_perf (int cpu,u64 min_perf) +{ +return cppc_set_reg_val (cpu,MIN_PERF , min_perf); +} +EXPORT_SYMBOL_GPL (cppc_set_min_perf); + +/** +* cppc_get_max_perf - Get the max performance register value. +* @cpu: CPU from which to get max performance. +* @max_perf: Return address. +* +* Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if not supported. +*/ +int cppc_get_max_perf (int cpu,u64 *max_perf) +{ +return cppc_get_reg_val (cpu,MAX_PERF , max_perf); +} +EXPORT_SYMBOL_GPL (cppc_get_max_perf); + +/** +* cppc_set_max_perf() - Write the max performance register. +* @cpu: CPU on which to write register. +* @max_perf: Value to write to the MAX_PERF register. +* +* Return: 0 for success, -EIO otherwise. +*/ +int cppc_set_max_perf (int cpu,u64 max_perf) +{ +return cppc_set_reg_val (cpu,MAX_PERF , max_perf); +} +EXPORT_SYMBOL_GPL (cppc_set_max_perf); +/** * cppc_get_perf - Get a CPU's performance controls. * @cpu: CPU for which to get performance controls.
drivers/cpufreq/cppc_cpufreq.c +115 -0
149 lines not on this page · raw message
include/acpi/cppc_acpi.h +22 -1
@@ -39,7 +39,8 @@/* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */ #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129 -#define CPPC_ENERGY_PERF_MAX (0xFF) +#define CPPC_EPP_PERFORMANCE_PREF 0x00 +#define CPPC_EPP_ENERGY_EFFICIENCY_PREF 0xFF/* Each register has the folowing format. */ struct cpc_reg {
@@ -172,6 +173,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);extern int cppc_set_auto_act_window (int cpu,u64 auto_act_window);extern int cppc_get_auto_sel (int cpu,bool *enable);extern int cppc_set_auto_sel (int cpu,bool enable); +extern int cppc_get_min_perf (int cpu,u64 *min_perf); +extern int cppc_set_min_perf (int cpu,u64 min_perf); +extern int cppc_get_max_perf (int cpu,u64 *max_perf); +extern int cppc_set_max_perf (int cpu,u64 max_perf);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf);extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator);extern int amd_detect_prefcore (bool *detected);
@@ -264,6 +269,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enable) {return -EOPNOTSUPP ; } +static inline int cppc_get_min_perf (int cpu,u64 *min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_min_perf (int cpu,u64 min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_get_max_perf (int cpu,u64 *max_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_max_perf (int cpu,u64 max_perf) +{ +return -EOPNOTSUPP ; +}static inline int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf) {return -ENODEV ;
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 6/8 cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
In reply to Sumit GuptaAdd sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the cppc_cpufreq driver.
--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)
Documentation/ABI/testing/sysfs-devices-system-cpu +43 -0
@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 7/8 cpufreq: CPPC: update policy min/max when toggling auto_select
In reply to Sumit GuptaWhen CPPC autonomous selection (auto_select) is enabled or disabled, the policy min/max frequency limits should be updated appropriately to reflect the new operating mode.
Currently, toggling auto_select only changes the hardware register but doesn't update the cpufreq policy constraints, which can lead to inconsistent behavior between the hardware state and the policy limits visible to userspace and other kernel components.
When auto_select is enabled, preserve the current min/max performance values to maintain user-configured limits. When disabled, the hardware operates in a default mode where the OS directly controls performance, so update the policy limits accordingly.
--- drivers/cpufreq/cppc_cpufreq.c | 65 ++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-)
drivers/cpufreq/cppc_cpufreq.c +62 -3
@@ -639,6 +639,26 @@ static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64 val,#define cppc_cpufreq_set_max_perf (policy, val, update_reg, update_policy) \ cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, false) +static int cppc_cpufreq_update_autosel_val (struct cpufreq_policy *policy,bool auto_sel) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +unsigned int cpu = policy->cpu; +int ret; + +pr_debug ("cpu%d, auto_sel curr:%u, new:%d\n" , cpu, cpu_data->perf_caps.auto_sel, auto_sel); + +guard (mutex)(&cppc_cpufreq_update_autosel_config_lock); + + ret =cppc_set_auto_sel (cpu, auto_sel); +if (ret) { +pr_warn ("Failed to set auto_sel=%d for CPU%d (%d)\n" , auto_sel, cpu, ret); +return ret; + } + cpu_data->perf_caps.auto_sel = auto_sel; + +return 0 ; +} +static int cppc_cpufreq_cpu_init (struct cpufreq_policy *policy) {unsigned int cpu = policy->cpu;
@@ -902,8 +922,47 @@ static ssize_t show_auto_select(struct cpufreq_policy *policy, char *buf)return sysfs_emit (buf,"%d\n" , val); } -static ssize_t store_auto_select (struct cpufreq_policy *policy, -const char *buf,size_t count) +/** +* cppc_cpufreq_update_auto_select - Update autonomous selection config for policy->cpu +* @policy: cpufreq policy +* @enable: enable/disable autonomous selection +*/ +static int cppc_cpufreq_update_auto_select (struct cpufreq_policy *policy,bool enable) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +struct cppc_perf_caps *caps = &cpu_data->perf_caps; +u64 min_perf = caps->lowest_nonlinear_perf; +u64 max_perf = caps->nominal_perf; +int ret; + +if (enable) { +if (cpu_data->perf_ctrls.min_perf) + min_perf = cpu_data->perf_ctrls.min_perf; +if (cpu_data->perf_ctrls.max_perf) + max_perf = cpu_data->perf_ctrls.max_perf; + } + +/* +* Set min/max performance registers and update policy constraints. +* When enabling: update both registers and policy. +* When disabling: update policy only. +*/ + ret =cppc_cpufreq_set_min_perf (policy, min_perf, enable, true); +if (ret) +return ret; + + ret =cppc_cpufreq_set_max_perf (policy, max_perf, enable, true); +if (ret) +return ret; + + ret =cppc_cpufreq_update_autosel_val (policy, enable); +if (ret) +return ret; + +return 0 ; +} + +static ssize_t store_auto_select (struct cpufreq_policy *policy,const char *buf,size_t count) {bool val;int ret;
@@ -912,7 +971,7 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,if (ret)return ret; - ret =cppc_set_auto_sel (policy->cpu, val); + ret =cppc_cpufreq_update_auto_select (policy, val);if (ret)return ret;
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 5/8 ACPI: CPPC: add APIs and sysfs interface for perf_limited register
In reply to Sumit GuptaAdd sysfs interface to read/write the Performance Limited register.
The Performance Limited register indicates to the OS that an unpredictable event (like thermal throttling) has limited processor performance. This register is sticky and remains set until reset or OS clears it by writing 0.
The interface is exposed as:
/sys/devices/system/cpu/cpuX/cpufreq/perf_limited
--- drivers/acpi/cppc_acpi.c | 26 ++++++++++++++++++++++++++ drivers/cpufreq/cppc_cpufreq.c | 12 ++++++++++++ include/acpi/cppc_acpi.h | 10 ++++++++++ 3 files changed, 48 insertions(+)
drivers/acpi/cppc_acpi.c +26 -0
@@ -1806,6 +1806,32 @@ int cppc_set_max_perf(int cpu, u64 max_perf) }EXPORT_SYMBOL_GPL (cppc_set_max_perf); +/** +* cppc_get_perf_limited - Get the Performance Limited register value. +* @cpu: CPU from which to get Performance Limited register. +* @perf_limited: Pointer to store the Performance Limited value. +* +* Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if not supported. +*/ +int cppc_get_perf_limited (int cpu,u64 *perf_limited) +{ +return cppc_get_reg_val (cpu,PERF_LIMITED , perf_limited); +} +EXPORT_SYMBOL_GPL (cppc_get_perf_limited); + +/** +* cppc_set_perf_limited() - Write the Performance Limited register. +* @cpu: CPU on which to write register. +* @perf_limited: Value to write to the perf_limited register. +* +* Return: 0 for success, -EIO on register access failure, -EOPNOTSUPP if not supported. +*/ +int cppc_set_perf_limited (int cpu,u64 perf_limited) +{ +return cppc_set_reg_val (cpu,PERF_LIMITED , perf_limited); +} +EXPORT_SYMBOL_GPL (cppc_set_perf_limited); +/** * cppc_get_perf - Get a CPU's performance controls. * @cpu: CPU for which to get performance controls.
drivers/cpufreq/cppc_cpufreq.c +12 -0
@@ -984,12 +984,23 @@ static ssize_t store_max_perf(struct cpufreq_policy *policy, const char *buf, sireturn count; } +static ssize_t show_perf_limited (struct cpufreq_policy *policy,char *buf) +{ +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_perf_limited, buf); +} + +static ssize_t store_perf_limited (struct cpufreq_policy *policy,const char *buf,size_t count) +{ +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_perf_limited, policy->cpu); +} +cpufreq_freq_attr_ro (freqdomain_cpus);cpufreq_freq_attr_rw (auto_select);cpufreq_freq_attr_rw (auto_act_window);cpufreq_freq_attr_rw (energy_performance_preference_val);cpufreq_freq_attr_rw (min_perf);cpufreq_freq_attr_rw (max_perf); +cpufreq_freq_attr_rw (perf_limited);static struct freq_attr *cppc_cpufreq_attr[] = { &freqdomain_cpus,
@@ -998,6 +1009,7 @@ static struct freq_attr *cppc_cpufreq_attr[] = { &energy_performance_preference_val, &min_perf, &max_perf, + &perf_limited, NULL, };
include/acpi/cppc_acpi.h +10 -0
@@ -177,6 +177,8 @@ extern int cppc_get_min_perf(int cpu, u64 *min_perf);extern int cppc_set_min_perf (int cpu,u64 min_perf);extern int cppc_get_max_perf (int cpu,u64 *max_perf);extern int cppc_set_max_perf (int cpu,u64 max_perf); +extern int cppc_get_perf_limited (int cpu,u64 *perf_limited); +extern int cppc_set_perf_limited (int cpu,u64 perf_limited);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf);extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator);extern int amd_detect_prefcore (bool *detected);
@@ -285,6 +287,14 @@ static inline int cppc_set_max_perf(int cpu, u64 max_perf) {return -EOPNOTSUPP ; } +static inline int cppc_get_perf_limited (int cpu,u64 *perf_limited) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_perf_limited (int cpu,u64 perf_limited) +{ +return -EOPNOTSUPP ; +}static inline int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf) {return -ENODEV ;
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 2/8 ACPI: CPPC: Add cppc_get_perf() API to read performance controls
In reply to Sumit GuptaAdd cppc_get_perf() function to read values of performance control registers including desired_perf, min_perf, max_perf, and energy_perf.
This provides a read interface to complement the existing cppc_set_perf() write interface for performance control registers.
--- drivers/acpi/cppc_acpi.c | 73 ++++++++++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 5 +++ 2 files changed, 78 insertions(+)
drivers/acpi/cppc_acpi.c +73 -0
@@ -1731,6 +1731,79 @@ int cppc_set_enable(int cpu, bool enable)return cppc_set_reg_val (cpu,ENABLE , enable); }EXPORT_SYMBOL_GPL (cppc_set_enable); +/** +* cppc_get_perf - Get a CPU's performance controls. +* @cpu: CPU for which to get performance controls. +* @perf_ctrls: ptr to cppc_perf_ctrls. See cppc_acpi.h +* +* Return: 0 for success with perf_ctrls, -ERRNO otherwise. +*/ +int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) +{ +struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu); +struct cpc_register_resource *desired_perf_reg, *min_perf_reg, *max_perf_reg, + *energy_perf_reg; +u64 desired_perf =0 , min =0 , max =0 , energy_perf =0 ; +int pcc_ss_id =per_cpu (cpu_pcc_subspace_idx, cpu); +struct cppc_pcc_data *pcc_ss_data =NULL ; +int ret =0 , regs_in_pcc =0 ; + +if (!cpc_desc) { +pr_debug ("No CPC descriptor for CPU:%d\n" , cpu); +return -ENODEV ; + } + +if (!perf_ctrls) { +pr_debug ("Invalid perf_ctrls pointer\n" ); +return -EINVAL ; + } + + desired_perf_reg = &cpc_desc->cpc_regs[DESIRED_PERF ]; + min_perf_reg = &cpc_desc->cpc_regs[MIN_PERF ]; + max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF ]; + energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; + +/* Are any of the regs PCC ?*/ +if (CPC_IN_PCC (desired_perf_reg) ||CPC_IN_PCC (min_perf_reg) || +CPC_IN_PCC (max_perf_reg) ||CPC_IN_PCC (energy_perf_reg)) { +if (pcc_ss_id <0 ) { +pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu); +return -ENODEV ; + } + pcc_ss_data = pcc_data[pcc_ss_id]; + regs_in_pcc =1 ; +down_write (&pcc_ss_data->pcc_lock); +/* Ring doorbell once to update PCC subspace */ +if (send_pcc_cmd (pcc_ss_id,CMD_READ ) <0 ) { +pr_debug ("Failed to send PCC command for CPU:%d, ret:%d\n" , cpu, ret); + ret = -EIO ; + goto out_err; + } + } + +/* Read optional elements if present */ +if (CPC_SUPPORTED (max_perf_reg)) +cpc_read (cpu, max_perf_reg, &max); + perf_ctrls->max_perf = max; + +if (CPC_SUPPORTED (min_perf_reg)) +cpc_read (cpu, min_perf_reg, &min); + perf_ctrls->min_perf = min; + +if (CPC_SUPPORTED (desired_perf_reg)) +cpc_read (cpu, desired_perf_reg, &desired_perf); + perf_ctrls->desired_perf = desired_perf; + +if (CPC_SUPPORTED (energy_perf_reg)) +cpc_read (cpu, energy_perf_reg, &energy_perf); + perf_ctrls->energy_perf = energy_perf; + +out_err: +if (regs_in_pcc) +up_write (&pcc_ss_data->pcc_lock); +return ret; +} +EXPORT_SYMBOL_GPL (cppc_get_perf);/** * cppc_set_perf - Set a CPU's performance controls.
include/acpi/cppc_acpi.h +5 -0
@@ -151,6 +151,7 @@ extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf);extern int cppc_get_nominal_perf (int cpunum,u64 *nominal_perf);extern int cppc_get_highest_perf (int cpunum,u64 *highest_perf);extern int cppc_get_perf_ctrs (int cpu,struct cppc_perf_fb_ctrs *perf_fb_ctrs); +extern int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls);extern int cppc_set_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls);extern int cppc_set_enable (int cpu,bool enable);extern int cppc_get_perf_caps (int cpu,struct cppc_perf_caps *caps);
@@ -192,6 +193,10 @@ static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ {return -EOPNOTSUPP ; } +static inline int cppc_get_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) +{ +return -EOPNOTSUPP ; +}static inline int cppc_set_perf (int cpu,struct cppc_perf_ctrls *perf_ctrls) {return -EOPNOTSUPP ;
Signature · 1 line
2.34.1
Sumit Gupta
reviewerPATCH v3 8/8 cpufreq: CPPC: add autonomous mode boot parameter support
In reply to Sumit GuptaAdd kernel boot parameter 'cppc_cpufreq.auto_sel_mode' to enable CPPC autonomous performance selection at system startup. When autonomous mode is enabled, the hardware automatically adjusts CPU performance based on workload demands using Energy Performance Preference (EPP) hints.
This parameter allows to configure the autonomous mode on all CPUs without requiring runtime sysfs manipulation if the 'auto_sel' register is present.
When auto_sel_mode=1:
- All CPUs are configured for autonomous operation during module init
- EPP is set to performance preference (0x0) by default
- Min/max performance bounds use defaults
- CPU frequency scaling is handled by hardware instead of OS governor
For Documentation/:
--- .../admin-guide/kernel-parameters.txt | 12 + drivers/cpufreq/cppc_cpufreq.c | 205 +++++++++++++++--- 2 files changed, 192 insertions(+), 25 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +12 -0
@@ -911,6 +911,18 @@ Format: <first_slot>,<last_slot>,<port>,<enum_bit>[,<debug>] + cppc_cpufreq.auto_sel_mode= + [CPU_FREQ] Enable ACPI CPPC autonomous performance selection. + When enabled, hardware automatically adjusts CPU frequency + on all CPUs based on workload demands. In Autonomous mode, + Energy Performance Preference(EPP) hints guide hardware + toward performance(0x0) or energy efficiency (0xff). + Requires ACPI CPPC autonomous selection register support. + Format: <bool> + Default: 0 (disabled) + 0: use cpufreq governors + 1: enable if supoorted by hardware + cpuidle.off=1 [CPU_IDLE] disable the cpuidle sub-system
drivers/cpufreq/cppc_cpufreq.c +180 -25
281 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
In reply to Sumit Gupta+linux-doc
Quoted 14 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +0
-0
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 331
Quoted 5 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +2
-0@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025
These dates will need to push out since this isn't 6.17 material.
That being said I have a general question to linux-doc.
Why is this is date based? I would expect a date is meaningless to anyone reads this documentation. People who want to know if an interface is available would normally look at their kernel version to tell.
So wouldn't it make more sense for this field to be something like:
Version: 6.19
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 338
Quoted 7 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance],
How will a user discover the lowest -> highest range?
IE I think you should document how to lookup those caps too.
Quoted 37 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +34
-0+ inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008
Sumit Gupta
reviewerRe: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
Quoted 21 lines · Mario Limonciello
External email: Use caution opening links or attachments
+linux-doc
Quoted 15 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>---
.../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +0
-0@@ -327,6 +327,49 @@ Description: Energy performance preference
Quoted 6 lines
Documentation/ABI/testing/sysfs-devices-system-cpu
Quoted 4 lines
This file is only present if the cppc-cpufreq driver is in use.
Documentation/ABI/testing/sysfs-devices-system-cpu +2
-0+What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025These dates will need to push out since this isn't 6.17 material.
Sure.
Quoted 23 lines
That being said I have a general question to linux-doc.
Why is this is date based? I would expect a date is meaningless to anyone reads this documentation. People who want to know if an interface is available would normally look at their kernel version to tell.
So wouldn't it make more sense for this field to be something like:
Version: 6.19
Quoted 9 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +5
-0+Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which theplatform
+ may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance],How will a user discover the lowest -> highest range?
Quoted 1 line
IE I think you should document how to lookup those caps too.
Ok, will add the info about these nodes as below.
Minimum performance may be set to any performance value in the range [Lowest Performance, Highest Performance], inclusive but must be set to a value that is less than or equal to that specified by the Maximum Performance Register. The range can be checked from nodes:
/sys/devices/system/cpu/cpuX/acpi_cppc/highest_perf /sys/devices/system/cpu/cpuX/acpi_cppc/lowest_perf
Thank you,
Sumit
Quoted 51 lines
Quoted 50 lines
+ inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register.
+
+ Writing to this file only has meaning when Autonomous Selection
+ is enabled.
+
+ This file is only present if the cppc-cpufreq driver is in use.Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This fileconveys
+ the maximum performance level at which the platform may run.
+ Maximum performance may be set to any performance value in the
+ range [Lowest Performance, Highest Performance], inclusive.
+
+ Writing to this file only has meaning when Autonomous Selection is
+ enabled.
+
+ This file is only present if the cppc-cpufreq driver is in use.Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This fileindicates
+ to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than
+ desired/minimum performance.
+
+ This file is only present if the cppc-cpufreq driver is in use.What:
/sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1}Date: August 2008
Jie Zhan
reviewerRe: [PATCH v3 1/8] cpufreq: CPPC: Add generic helpers for sysfs show/store
In reply to Sumit GuptaHi Sumit,
Quoted 10 lines · Sumit Gupta
Add generic show/store helper functions for u64 sysfs attributes:
-cppc_cpufreq_sysfs_show_u64()
-cppc_cpufreq_sysfs_store_u64()Refactor
auto_act_windowandenergy_performance_preference_valattributes to use these helpers, eliminating code duplication.No functional changes.
Signed-off-by Sumit Gupta <[email protected]>
Nice cleanup in general. Some minor bits inline.
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 784
Quoted 13 lines
--- drivers/cpufreq/cppc_cpufreq.c | 87 ++++++++++++++-------------------- 1 file changed, 35 insertions(+), 52 deletions(-)drivers/cpufreq/cppc_cpufreq.c +1
-0@@ -781,6 +781,36 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)return 0 ; } +static ssize_t cppc_cpufreq_sysfs_show_u64 (unsigned int cpu,int (*get_func)(int ,u64 *),char *buf)
Wrap a bit into 80 chars?
BTW, trivial but I would prefer a symmetric param order, like:show(buf, get_func, cpu)store(buf, count, set_func, cpu)
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+{ +u64 val; +int ret =get_func (cpu, &val); + +if (ret == -EOPNOTSUPP ) +return sysfs_emit (buf,"<unsupported>\n" ); +if (ret) +return ret; + +return sysfs_emit (buf,"%llu\n" , val);
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 804
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+} + +static ssize_t cppc_cpufreq_sysfs_store_u64 (const char *buf,size_t count, +int (*set_func)(int ,u64 ),unsigned int cpu) +{ +u64 val; +int ret; + +if (!buf || !set_func) +return -EINVAL ;
No need.
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 811
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +7
-0+ + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =set_func ((int )cpu, val); +return ret ? ret : count;
I suppose it's preferred to avoid using ternary operators like this.
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 813
Quoted 2 lines
drivers/cpufreq/cppc_cpufreq.c +2
-0+} +
Would be nicer to move cppc_cpufreq_sysfs_show/store_u64() to just above where they are used, i.e. just before show_auto_act_window().
Quoted 79 lines
drivers/cpufreq/cppc_cpufreq.c +5
-52static ssize_t show_freqdomain_cpus (struct cpufreq_policy *policy,char *buf) {struct cppc_cpudata *cpu_data = policy->driver_data;@@ -824,70 +854,23 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,static ssize_t show_auto_act_window (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_auto_act_window (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_auto_act_window, buf); } -static ssize_t store_auto_act_window (struct cpufreq_policy *policy, -const char *buf,size_t count) +static ssize_t store_auto_act_window (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 usec; -int ret; - - ret =kstrtou64 (buf,0 , &usec); -if (ret) -return ret; - - ret =cppc_set_auto_act_window (policy->cpu, usec); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_auto_act_window, policy->cpu); }static ssize_t show_energy_performance_preference_val (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_epp_perf (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_epp_perf, buf); }static ssize_t store_energy_performance_preference_val (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 val; -int ret; - - ret =kstrtou64 (buf,0 , &val); -if (ret) -return ret; - - ret =cppc_set_epp (policy->cpu, val); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_epp, policy->cpu); }cpufreq_freq_attr_ro (freqdomain_cpus);
Jie Zhan
reviewerRe: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
In reply to Sumit GuptaQuoted 28 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +11
-0@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register.
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 350
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ + Writing to this file only has meaning when Autonomous Selection + is enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance
Not adapted
Quoted 5 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +5
-0+ + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive.
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 365
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance
Not adapted
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008
Sumit Gupta
reviewerRe: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
Quoted 35 lines · Jie Zhan
External email: Use caution opening links or attachments
Quoted 31 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +14
-0@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled.
Quoted 8 lines
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 350
Quoted 7 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum PerformanceNot adapted
Sorry, i missed this. Will update here and below.
Thank you,
Sumit
Quoted 8 lines
Quoted 8 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +8
-0+ + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled.
Quoted 8 lines
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 365
Quoted 7 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum PerformanceNot adapted
Ack.
Quoted 10 lines
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +7
-0+ + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008
Sumit Gupta
reviewerRe: [PATCH v3 1/8] cpufreq: CPPC: Add generic helpers for sysfs show/store
In reply to Jie ZhanQuoted 29 lines · Jie Zhan
External email: Use caution opening links or attachments
Hi Sumit,
Quoted 10 lines · Sumit Gupta
Add generic show/store helper functions for u64 sysfs attributes:
-cppc_cpufreq_sysfs_show_u64()
-cppc_cpufreq_sysfs_store_u64()Refactor
auto_act_windowandenergy_performance_preference_valattributes to use these helpers, eliminating code duplication.No functional changes.
Signed-off-by Sumit Gupta <[email protected]>Nice cleanup in general. Some minor bits inline.
Quoted 12 lines
--- drivers/cpufreq/cppc_cpufreq.c | 87 ++++++++++++++-------------------- 1 file changed, 35 insertions(+), 52 deletions(-)drivers/cpufreq/cppc_cpufreq.c +0
-0@@ -781,6 +781,36 @@ static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state)return 0 ; }
Quoted 2 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 784
Quoted 1 line
drivers/cpufreq/cppc_cpufreq.c +1
-0+static ssize_t cppc_cpufreq_sysfs_show_u64 (unsigned int cpu,int (*get_func)(int ,u64 *),char *buf)Wrap a bit into 80 chars?
Wrapped line length to 100 as per the max limit.
$ grep "max_line_length =" scripts/checkpatch.pl my $max_line_length = 100;
Quoted 4 lines
BTW, trivial but I would prefer a symmetric param order, like:
show(buf, get_func, cpu)store(buf, count, set_func, cpu)
Sure, will change the param order.
Quoted 13 lines
Quoted 13 lines
drivers/cpufreq/cppc_cpufreq.c +13
-0+{ +u64 val; +int ret =get_func (cpu, &val); + +if (ret == -EOPNOTSUPP ) +return sysfs_emit (buf,"<unsupported>\n" ); +if (ret) +return ret; + +return sysfs_emit (buf,"%llu\n" , val); +} + +static ssize_t cppc_cpufreq_sysfs_store_u64(const char *buf, size_t count,
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 804
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +7
-0+ int (*set_func)(int, u64), unsigned int cpu) +{ +u64 val; +int ret; + +if (!buf || !set_func) +return -EINVAL ;No need.
Ok.
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 811
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +7
-0+ + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =set_func ((int )cpu, val); +return ret ? ret : count;I suppose it's preferred to avoid using ternary operators like this.
These are commonly use. e.g. within cpufreq:
$ grep -inr "return ret ?" drivers/cpufreq/* drivers/cpufreq/amd-pstate.c:1184: return ret ? ret : count; drivers/cpufreq/cpufreq.c:839: return ret ? ret : count; drivers/cpufreq/intel_pstate.c:897: return ret ?: count;
Quoted 4 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_set_boost(struct cpufreq_policy *policy, int state) · line 813
Quoted 2 lines
drivers/cpufreq/cppc_cpufreq.c +2
-0+} +Would be nicer to move cppc_cpufreq_sysfs_show/store_u64() to just above where they are used, i.e. just before
show_auto_act_window().
Sure.
Thank you,
Sumit
Quoted 79 lines
Quoted 79 lines
drivers/cpufreq/cppc_cpufreq.c +5
-52static ssize_t show_freqdomain_cpus (struct cpufreq_policy *policy,char *buf) {struct cppc_cpudata *cpu_data = policy->driver_data;@@ -824,70 +854,23 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,static ssize_t show_auto_act_window (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_auto_act_window (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_auto_act_window, buf); } -static ssize_t store_auto_act_window (struct cpufreq_policy *policy, -const char *buf,size_t count) +static ssize_t store_auto_act_window (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 usec; -int ret; - - ret =kstrtou64 (buf,0 , &usec); -if (ret) -return ret; - - ret =cppc_set_auto_act_window (policy->cpu, usec); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_auto_act_window, policy->cpu); }static ssize_t show_energy_performance_preference_val (struct cpufreq_policy *policy,char *buf) { -u64 val; -int ret; - - ret =cppc_get_epp_perf (policy->cpu, &val); - -/* show "<unsupported>" when this register is not supported by cpc */ -if (ret == -EOPNOTSUPP ) -return sysfs_emit (buf,"<unsupported>\n" ); - -if (ret) -return ret; - -return sysfs_emit (buf,"%llu\n" , val); +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_epp_perf, buf); }static ssize_t store_energy_performance_preference_val (struct cpufreq_policy *policy,const char *buf,size_t count) { -u64 val; -int ret; - - ret =kstrtou64 (buf,0 , &val); -if (ret) -return ret; - - ret =cppc_set_epp (policy->cpu, val); -if (ret) -return ret; - -return count; +return cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_epp, policy->cpu); }cpufreq_freq_attr_ro (freqdomain_cpus);
Re: [PATCH v3 3/8] ACPI: CPPC: extend APIs to support auto_sel and epp
In reply to Sumit GuptaHi Sumit,
Quoted 7 lines · Sumit Gupta
- Add
auto_selread support incppc_get_perf_caps().
- Add write of bothauto_selandenergy_perfincppc_set_epp_perf().
- Remove redundantenergy_perffield from 'structcppc_perf_caps' as the same is available in 'structcppc_perf_ctrls' which is used.Signed-off-by Sumit Gupta <[email protected]>---
[..]
Quoted 22 lines
drivers/acpi/cppc_acpi.c +7
-0@@ -1555,6 +1559,8 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)struct cpc_register_resource *auto_sel_reg;struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool autosel_support_in_ffh_or_sysmem; +bool epp_support_in_ffh_or_sysmem;int ret;if (!cpc_desc) {@@ -1565,6 +1571,11 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ]; epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; + epp_support_in_ffh_or_sysmem =CPC_SUPPORTED (epp_set_reg) && + (CPC_IN_FFH (epp_set_reg) ||CPC_IN_SYSTEM_MEMORY (epp_set_reg)); + autosel_support_in_ffh_or_sysmem =CPC_SUPPORTED (auto_sel_reg) && + (CPC_IN_FFH (auto_sel_reg) ||CPC_IN_SYSTEM_MEMORY (auto_sel_reg)); +if (CPC_IN_PCC (epp_set_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);
drivers/acpi/cppc_acpi.c int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) · line 1604
Quoted 5 lines
drivers/acpi/cppc_acpi.c +1
-1@@ -1590,8 +1601,19 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) ret =send_pcc_cmd (pcc_ss_id,CMD_WRITE );up_write (&pcc_ss_data->pcc_lock); }else if (osc_cpc_flexible_adr_space_confirmed && -CPC_SUPPORTED (epp_set_reg) &&CPC_IN_FFH (epp_set_reg)) { + epp_support_in_ffh_or_sysmem && autosel_support_in_ffh_or_sysmem) {
Isn't this problematic for when auto-select is an integer set to 1 or it's not present at all? In those cases the EPP register won't be written and -ENOTSUPP will be returned.
I suppose for the case when auto-select is not present at all in _CPC (it's an optional attribute) it's not very clear what one should do regarding writing the EPP register. The specification mentions that "Writes to this register only have meaning when Autonomous Selection is enabled.". From my perspective the OS should not block writes to the EPP register for this case, as autonomous selection might still be enabled but not exposed to the OS.
Thanks,
Ionela.
Quoted 15 lines
drivers/acpi/cppc_acpi.c +11
-0+ ret =cpc_write (cpu, auto_sel_reg, enable); +if (ret) { +pr_debug ("Failed to write auto_sel=%d for CPU:%d\n" , enable, cpu); +return ret; + } + ret =cpc_write (cpu, epp_set_reg, perf_ctrls->energy_perf); +if (ret) { +pr_debug ("Failed to write energy_perf=%u for CPU:%d\n" , + perf_ctrls->energy_perf, cpu); +return ret; + } }else { ret = -ENOTSUPP ;pr_debug ("_CPC in PCC and _CPC in FFH are not supported\n" );
[..]
Re: [PATCH v3 4/8] ACPI: CPPC: add APIs and sysfs interface for min/max_perf
In reply to Sumit GuptaQuoted 29 lines · Sumit Gupta
CPPC allows platforms to specify minimum and maximum performance limits that constrain the operating range for CPU performance scaling when Autonomous Selection is enabled. These limits can be dynamically adjusted to implement power management policies or workload-specific optimizations.
Add
cppc_get_min_perf()andcppc_set_min_perf()functions to read and write theMIN_PERFregister, allowing dynamic adjustment of the minimum performance floor.Add
cppc_get_max_perf()andcppc_set_max_perf()functions to read and write theMAX_PERFregister, enabling dynamic ceiling control for maximum performance.Expose these capabilities through cpufreq sysfs attributes:
-/sys/.../cpufreq/policy*/min_perf: Read/write min performance limit
-/sys/.../cpufreq/policy*/max_perf: Read/write max performance limitAlso update EPP constants for better clarity:
- RenameCPPC_ENERGY_PERF_MAXtoCPPC_EPP_ENERGY_EFFICIENCY_PREF
- AddCPPC_EPP_PERFORMANCE_PREFfor the performance-oriented settingSigned-off-by Sumit Gupta <[email protected]>--- drivers/acpi/cppc_acpi.c | 55 +++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 115 +++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 23 ++++++- 3 files changed, 191 insertions(+), 2 deletions(-)
[..]
Quoted 13 lines
drivers/cpufreq/cppc_cpufreq.c +1
-0@@ -23,6 +23,7 @@#include <uapi/linux/sched/types.h> #include <linux/unaligned.h> +#include <linux/cleanup.h> #include <acpi/cppc_acpi.h>
drivers/cpufreq/cppc_cpufreq.c static enum { · line 42
Quoted 4 lines
drivers/cpufreq/cppc_cpufreq.c +1
-0@@ -38,6 +39,8 @@ static enum {module_param (fie_disabled, int,0444 );MODULE_PARM_DESC (fie_disabled,"Disable Frequency Invariance Engine (FIE)" ); +static DEFINE_MUTEX (cppc_cpufreq_update_autosel_config_lock);
Should this be under CONFIG_ACPI_CPPC_CPUFREQ_FIE?
Quoted 29 lines
drivers/cpufreq/cppc_cpufreq.c +22
-0+/* Frequency invariance support */ struct cppc_freq_invariance {int cpu;@@ -572,6 +575,70 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy) policy->driver_data =NULL ; } +/** +* cppc_cpufreq_set_mperf_limit - Generic function to set min/max performance limit +* @policy: cpufreq policy +* @val: performance value to set +* @update_reg: whether to update hardware register +* @update_policy: whether to update policy constraints +* @is_min: true for min_perf, false for max_perf +*/ +static int cppc_cpufreq_set_mperf_limit (struct cpufreq_policy *policy,u64 val, +bool update_reg,bool update_policy,bool is_min) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +struct cppc_perf_caps *caps = &cpu_data->perf_caps; +unsigned int cpu = policy->cpu; +struct freq_qos_request *req; +unsigned int freq; +u32 perf; +int ret; + + perf =clamp (val, caps->lowest_perf, caps->highest_perf); + freq =cppc_perf_to_khz (caps, perf);
drivers/cpufreq/cppc_cpufreq.c static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy) · line 608
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+ +pr_debug ("cpu%d, %s_perf:%llu, update_reg:%d, update_policy:%d\n" , cpu, + is_min ?"min" :"max" , (u64 )perf, update_reg, update_policy); + +guard (mutex)(&cppc_cpufreq_update_autosel_config_lock); + +if (update_reg) { + ret = is_min ?cppc_set_min_perf (cpu, perf) :cppc_set_max_perf (cpu, perf); +if (ret == -EOPNOTSUPP ) +return 0 ;
Should we return success here? The user will have no feedback that setting min/max performance limits is not supported.
Quoted 68 lines
drivers/cpufreq/cppc_cpufreq.c +61
-0+if (ret) { +pr_warn ("Failed to set %s_perf (%llu) on CPU%d (%d)\n" , + is_min ?"min" :"max" , (u64 )perf, cpu, ret); +return ret; + } + +/* Update cached value only on success */ +if (is_min) + cpu_data->perf_ctrls.min_perf = perf; +else + cpu_data->perf_ctrls.max_perf = perf; + } + +if (update_policy) { + req = is_min ? policy->min_freq_req : policy->max_freq_req; + + ret =freq_qos_update_request (req, freq); +if (ret <0 ) { +pr_warn ("Failed to update %s_freq constraint for CPU%d: %d\n" , + is_min ?"min" :"max" , cpu, ret); +return ret; + } + } + +return 0 ; +} + +#define cppc_cpufreq_set_min_perf (policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, true) + +#define cppc_cpufreq_set_max_perf (policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, false) +static int cppc_cpufreq_cpu_init (struct cpufreq_policy *policy) {unsigned int cpu = policy->cpu;@@ -873,16 +940,64 @@ static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *poreturn cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_epp, policy->cpu); } +static ssize_t show_min_perf (struct cpufreq_policy *policy,char *buf) +{ +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_min_perf, buf); +} + +static ssize_t store_min_perf (struct cpufreq_policy *policy,const char *buf,size_t count) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +u64 val; +int ret; + + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =cppc_cpufreq_set_min_perf (policy, val, true, cpu_data->perf_caps.auto_sel); +if (ret) +return ret; + +return count; +} + +static ssize_t show_max_perf (struct cpufreq_policy *policy,char *buf) +{ +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_max_perf, buf); +} + +static ssize_t store_max_perf (struct cpufreq_policy *policy,const char *buf,size_t count)
drivers/cpufreq/cppc_cpufreq.c static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *po · line 980
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+{ +struct cppc_cpudata *cpu_data = policy->driver_data; +u64 val; +int ret; + + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =cppc_cpufreq_set_max_perf (policy, val, true, cpu_data->perf_caps.auto_sel);
These "work" on the performance scale, so the values read are performance values and the values that should be provided should be performance values as well. How is the user supposed to know what that scale is and what is the range of values it can provide? All of the other sysfs interfaces work on the "frequency" scale and the lowest and highest performance values are never exposed to the user.
Thanks,
Ionela.
Quoted 75 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+if (ret) +return ret; + +return count; +} +cpufreq_freq_attr_ro (freqdomain_cpus);cpufreq_freq_attr_rw (auto_select);cpufreq_freq_attr_rw (auto_act_window);cpufreq_freq_attr_rw (energy_performance_preference_val); +cpufreq_freq_attr_rw (min_perf); +cpufreq_freq_attr_rw (max_perf);static struct freq_attr *cppc_cpufreq_attr[] = { &freqdomain_cpus, &auto_select, &auto_act_window, &energy_performance_preference_val, + &min_perf, + &max_perf,NULL , };include/acpi/cppc_acpi.h +22
-1@@ -39,7 +39,8 @@/* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */ #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129 -#define CPPC_ENERGY_PERF_MAX (0xFF) +#define CPPC_EPP_PERFORMANCE_PREF 0x00 +#define CPPC_EPP_ENERGY_EFFICIENCY_PREF 0xFF/* Each register has the folowing format. */ struct cpc_reg {@@ -172,6 +173,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);extern int cppc_set_auto_act_window (int cpu,u64 auto_act_window);extern int cppc_get_auto_sel (int cpu,bool *enable);extern int cppc_set_auto_sel (int cpu,bool enable); +extern int cppc_get_min_perf (int cpu,u64 *min_perf); +extern int cppc_set_min_perf (int cpu,u64 min_perf); +extern int cppc_get_max_perf (int cpu,u64 *max_perf); +extern int cppc_set_max_perf (int cpu,u64 max_perf);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf);extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator);extern int amd_detect_prefcore (bool *detected);@@ -264,6 +269,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enable) {return -EOPNOTSUPP ; } +static inline int cppc_get_min_perf (int cpu,u64 *min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_min_perf (int cpu,u64 min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_get_max_perf (int cpu,u64 *max_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_max_perf (int cpu,u64 max_perf) +{ +return -EOPNOTSUPP ; +}static inline int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf) {return -ENODEV ;Signature · 1 line
2.34.1
Re: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
In reply to Sumit GuptaHi,
Quoted 21 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +4
-0@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance
Documentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 343
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled.
In the ACPI specification I don't see a clear dependency between the minimum and maximum performance registers and autonomous selection. There's nothing to say that min and max do not have meaning with autonomous selection is disabled.
Thanks,
Ionela.
Quoted 36 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +29
-0+ + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008Signature · 1 line
2.34.1
Sumit Gupta
reviewerRe: [PATCH v3 3/8] ACPI: CPPC: extend APIs to support auto_sel and epp
In reply to Ionela VoinescuHi Ionela,
Thank you for the comments.
Quoted 53 lines · Ionela Voinescu
External email: Use caution opening links or attachments
Hi Sumit,
Quoted 7 lines · Sumit Gupta
- Add
auto_selread support incppc_get_perf_caps().
- Add write of bothauto_selandenergy_perfincppc_set_epp_perf().
- Remove redundantenergy_perffield from 'structcppc_perf_caps' as the same is available in 'structcppc_perf_ctrls' which is used.Signed-off-by Sumit Gupta <[email protected]>---
[..]
Quoted 22 lines
drivers/acpi/cppc_acpi.c +7
-0@@ -1555,6 +1559,8 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)struct cpc_register_resource *auto_sel_reg;struct cpc_desc *cpc_desc =per_cpu (cpc_desc_ptr, cpu);struct cppc_pcc_data *pcc_ss_data =NULL ; +bool autosel_support_in_ffh_or_sysmem; +bool epp_support_in_ffh_or_sysmem;int ret;if (!cpc_desc) {@@ -1565,6 +1571,11 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE ]; epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF ]; + epp_support_in_ffh_or_sysmem =CPC_SUPPORTED (epp_set_reg) && + (CPC_IN_FFH (epp_set_reg) ||CPC_IN_SYSTEM_MEMORY (epp_set_reg)); + autosel_support_in_ffh_or_sysmem =CPC_SUPPORTED (auto_sel_reg) && + (CPC_IN_FFH (auto_sel_reg) ||CPC_IN_SYSTEM_MEMORY (auto_sel_reg)); +if (CPC_IN_PCC (epp_set_reg) ||CPC_IN_PCC (auto_sel_reg)) {if (pcc_ss_id <0 ) {pr_debug ("Invalid pcc_ss_id for CPU:%d\n" , cpu);drivers/acpi/cppc_acpi.c int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) · line 1604
Quoted 5 lines
drivers/acpi/cppc_acpi.c +1
-1@@ -1590,8 +1601,19 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) ret =send_pcc_cmd (pcc_ss_id,CMD_WRITE );up_write (&pcc_ss_data->pcc_lock); }else if (osc_cpc_flexible_adr_space_confirmed && -CPC_SUPPORTED (epp_set_reg) &&CPC_IN_FFH (epp_set_reg)) { + epp_support_in_ffh_or_sysmem && autosel_support_in_ffh_or_sysmem) {Isn't this problematic for when auto-select is an integer set to 1 or it's not present at all? In those cases the EPP register won't be written and
-ENOTSUPPwill be returned.I suppose for the case when auto-select is not present at all in
_CPC(it's an optional attribute) it's not very clear what one should do regarding writing the EPP register. The specification mentions that "Writes to this register only have meaning when Autonomous Selection is enabled.". From my perspective the OS should not block writes to the EPP register for this case, as autonomous selection might still be enabled but not exposed to the OS.
Quoted 2 lines
Thanks,
Ionela.
Will change in v4 to write them independently as below.
-------------
} else if (osc_cpc_flexible_adr_space_confirmed) {
if (!epp_support_in_ffh_or_sysmem && !autosel_support_in_ffh_or_sysmem) { ret = -ENOTSUPP;
} else {
if (autosel_support_in_ffh_or_sysmem) {
ret = cpc_write(cpu, auto_sel_reg, enable); if (ret)
return ret;
}
if (epp_support_in_ffh_or_sysmem) {
ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf); if (ret)
return ret;
}
}
} else {
ret = -ENOTSUPP;
}
if (ret == -ENOTSUPP)
pr_debug("_CPC in PCC and _CPC in FFH are not supported\n");
-------------
Thank you,
Sumit Gupta
Quoted 16 lines
Quoted 15 lines
drivers/acpi/cppc_acpi.c +11
-0+ ret =cpc_write (cpu, auto_sel_reg, enable); +if (ret) { +pr_debug ("Failed to write auto_sel=%d for CPU:%d\n" , enable, cpu); +return ret; + } + ret =cpc_write (cpu, epp_set_reg, perf_ctrls->energy_perf); +if (ret) { +pr_debug ("Failed to write energy_perf=%u for CPU:%d\n" , + perf_ctrls->energy_perf, cpu); +return ret; + } }else { ret = -ENOTSUPP ;pr_debug ("_CPC in PCC and _CPC in FFH are not supported\n" );[..]
Sumit Gupta
reviewerRe: [PATCH v3 4/8] ACPI: CPPC: add APIs and sysfs interface for min/max_perf
In reply to Ionela VoinescuQuoted 44 lines · Ionela Voinescu
External email: Use caution opening links or attachments
Quoted 29 lines · Sumit Gupta
CPPC allows platforms to specify minimum and maximum performance limits that constrain the operating range for CPU performance scaling when Autonomous Selection is enabled. These limits can be dynamically adjusted to implement power management policies or workload-specific optimizations.
Add
cppc_get_min_perf()andcppc_set_min_perf()functions to read and write theMIN_PERFregister, allowing dynamic adjustment of the minimum performance floor.Add
cppc_get_max_perf()andcppc_set_max_perf()functions to read and write theMAX_PERFregister, enabling dynamic ceiling control for maximum performance.Expose these capabilities through cpufreq sysfs attributes:
-/sys/.../cpufreq/policy*/min_perf: Read/write min performance limit
-/sys/.../cpufreq/policy*/max_perf: Read/write max performance limitAlso update EPP constants for better clarity:
- RenameCPPC_ENERGY_PERF_MAXtoCPPC_EPP_ENERGY_EFFICIENCY_PREF
- AddCPPC_EPP_PERFORMANCE_PREFfor the performance-oriented settingSigned-off-by Sumit Gupta <[email protected]>--- drivers/acpi/cppc_acpi.c | 55 +++++++++++++++- drivers/cpufreq/cppc_cpufreq.c | 115 +++++++++++++++++++++++++++++++++ include/acpi/cppc_acpi.h | 23 ++++++- 3 files changed, 191 insertions(+), 2 deletions(-)[..]
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +1
-0@@ -23,6 +23,7 @@#include <uapi/linux/sched/types.h> #include <linux/unaligned.h> +#include <linux/cleanup.h>
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c static enum { · line 42
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +1
-0#include <acpi/cppc_acpi.h> @@ -38,6 +39,8 @@ static enum {module_param (fie_disabled, int,0444 );MODULE_PARM_DESC (fie_disabled,"Disable Frequency Invariance Engine (FIE)" ); +static DEFINE_MUTEX (cppc_cpufreq_update_autosel_config_lock);Should this be under
CONFIG_ACPI_CPPC_CPUFREQ_FIE?
Thank you for catching. Will move it outside in v4.
Quoted 33 lines
Quoted 33 lines
drivers/cpufreq/cppc_cpufreq.c +26
-0+/* Frequency invariance support */ struct cppc_freq_invariance {int cpu;@@ -572,6 +575,70 @@ static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy) policy->driver_data =NULL ; } +/** +* cppc_cpufreq_set_mperf_limit - Generic function to set min/max performance limit +* @policy: cpufreq policy +* @val: performance value to set +* @update_reg: whether to update hardware register +* @update_policy: whether to update policy constraints +* @is_min: true for min_perf, false for max_perf +*/ +static int cppc_cpufreq_set_mperf_limit (struct cpufreq_policy *policy,u64 val, +bool update_reg,bool update_policy,bool is_min) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +struct cppc_perf_caps *caps = &cpu_data->perf_caps; +unsigned int cpu = policy->cpu; +struct freq_qos_request *req; +unsigned int freq; +u32 perf; +int ret; + + perf =clamp (val, caps->lowest_perf, caps->highest_perf); + freq =cppc_perf_to_khz (caps, perf); + +pr_debug ("cpu%d, %s_perf:%llu, update_reg:%d, update_policy:%d\n" , cpu, + is_min ?"min" :"max" , (u64 )perf, update_reg, update_policy); +
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c static void cppc_cpufreq_put_cpu_data(struct cpufreq_policy *policy) · line 608
Quoted 6 lines
drivers/cpufreq/cppc_cpufreq.c +6
-0+guard (mutex)(&cppc_cpufreq_update_autosel_config_lock); + +if (update_reg) { + ret = is_min ?cppc_set_min_perf (cpu, perf) :cppc_set_max_perf (cpu, perf); +if (ret == -EOPNOTSUPP ) +return 0 ;Should we return success here? The user will have no feedback that setting min/max performance limits is not supported.
Will do change in v4 to also return EOPNOTSUPP error code to the caller.
Quoted 85 lines
Quoted 68 lines
drivers/cpufreq/cppc_cpufreq.c +61
-0+if (ret) { +pr_warn ("Failed to set %s_perf (%llu) on CPU%d (%d)\n" , + is_min ?"min" :"max" , (u64 )perf, cpu, ret); +return ret; + } + +/* Update cached value only on success */ +if (is_min) + cpu_data->perf_ctrls.min_perf = perf; +else + cpu_data->perf_ctrls.max_perf = perf; + } + +if (update_policy) { + req = is_min ? policy->min_freq_req : policy->max_freq_req; + + ret =freq_qos_update_request (req, freq); +if (ret <0 ) { +pr_warn ("Failed to update %s_freq constraint for CPU%d: %d\n" , + is_min ?"min" :"max" , cpu, ret); +return ret; + } + } + +return 0 ; +} + +#define cppc_cpufreq_set_min_perf (policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, true) + +#define cppc_cpufreq_set_max_perf (policy, val, update_reg, update_policy) \ + cppc_cpufreq_set_mperf_limit(policy, val, update_reg, update_policy, false) +static int cppc_cpufreq_cpu_init (struct cpufreq_policy *policy) {unsigned int cpu = policy->cpu;@@ -873,16 +940,64 @@ static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *poreturn cppc_cpufreq_sysfs_store_u64 (buf, count, cppc_set_epp, policy->cpu); } +static ssize_t show_min_perf (struct cpufreq_policy *policy,char *buf) +{ +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_min_perf, buf); +} + +static ssize_t store_min_perf (struct cpufreq_policy *policy,const char *buf,size_t count) +{ +struct cppc_cpudata *cpu_data = policy->driver_data; +u64 val; +int ret; + + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =cppc_cpufreq_set_min_perf (policy, val, true, cpu_data->perf_caps.auto_sel); +if (ret) +return ret; + +return count; +} + +static ssize_t show_max_perf (struct cpufreq_policy *policy,char *buf) +{ +return cppc_cpufreq_sysfs_show_u64 (policy->cpu, cppc_get_max_perf, buf); +} + +static ssize_t store_max_perf (struct cpufreq_policy *policy,const char *buf,size_t count)drivers/cpufreq/cppc_cpufreq.c static ssize_t store_energy_performance_preference_val(struct cpufreq_policy *po · line 980
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+{ +struct cppc_cpudata *cpu_data = policy->driver_data; +u64 val; +int ret; + + ret =kstrtou64 (buf,0 , &val); +if (ret) +return ret; + + ret =cppc_cpufreq_set_max_perf (policy, val, true, cpu_data->perf_caps.auto_sel);These "work" on the performance scale, so the values read are performance values and the values that should be provided should be performance values as well. How is the user supposed to know what that scale is and what is the range of values it can provide? All of the other sysfs interfaces work on the "frequency" scale and the lowest and highest performance values are never exposed to the user.
Quoted 2 lines
Thanks,
Ionela.
Can do the change in v4 for these nodes to get min/max freq value from user, convert that to perf with cppc_khz_to_perf() before write to min/max_perf registers and vice-versa. That will keep the scale same as other cpufreq sysfs interfaces.
Quoted 75 lines
Quoted 75 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+if (ret) +return ret; + +return count; +} +cpufreq_freq_attr_ro (freqdomain_cpus);cpufreq_freq_attr_rw (auto_select);cpufreq_freq_attr_rw (auto_act_window);cpufreq_freq_attr_rw (energy_performance_preference_val); +cpufreq_freq_attr_rw (min_perf); +cpufreq_freq_attr_rw (max_perf);static struct freq_attr *cppc_cpufreq_attr[] = { &freqdomain_cpus, &auto_select, &auto_act_window, &energy_performance_preference_val, + &min_perf, + &max_perf,NULL , };include/acpi/cppc_acpi.h +22
-2@@ -39,7 +39,8 @@/* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */ #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129 -#define CPPC_ENERGY_PERF_MAX (0xFF) +#define CPPC_EPP_PERFORMANCE_PREF 0x00 +#define CPPC_EPP_ENERGY_EFFICIENCY_PREF 0xFF/* Each register has the folowing format. */ struct cpc_reg {@@ -172,6 +173,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);extern int cppc_set_auto_act_window (int cpu,u64 auto_act_window);extern int cppc_get_auto_sel (int cpu,bool *enable);extern int cppc_set_auto_sel (int cpu,bool enable); +extern int cppc_get_min_perf (int cpu,u64 *min_perf); +extern int cppc_set_min_perf (int cpu,u64 min_perf); +extern int cppc_get_max_perf (int cpu,u64 *max_perf); +extern int cppc_set_max_perf (int cpu,u64 max_perf);extern int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf);extern int amd_get_boost_ratio_numerator (unsigned int cpu,u64 *numerator);extern int amd_detect_prefcore (bool *detected);@@ -264,6 +269,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enable) {return -EOPNOTSUPP ; } +static inline int cppc_get_min_perf (int cpu,u64 *min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_min_perf (int cpu,u64 min_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_get_max_perf (int cpu,u64 *max_perf) +{ +return -EOPNOTSUPP ; +} +static inline int cppc_set_max_perf (int cpu,u64 max_perf) +{ +return -EOPNOTSUPP ; +}static inline int amd_get_highest_perf (unsigned int cpu,u32 *highest_perf) {return -ENODEV ; --2.34.1
Sumit Gupta
reviewerRe: [PATCH v3 6/8] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited
In reply to Ionela VoinescuQuoted 42 lines · Ionela Voinescu
External email: Use caution opening links or attachments
Hi,
Quoted 21 lines · Sumit Gupta
Add sysfs interfaces for Minimum Performance, Maximum Performance and Performance Limited Register in the
cppc_cpufreqdriver.Reviewed-by Randy Dunlap <[email protected]>Signed-off-by Sumit Gupta <[email protected]>--- .../ABI/testing/sysfs-devices-system-cpu | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)Documentation/ABI/testing/sysfs-devices-system-cpu +4
-0@@ -327,6 +327,49 @@ Description: Energy performance preference This file is only present if the cppc-cpufreq driver is in use. +What: /sys/devices/system/cpu/cpuX/cpufreq/min_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum PerformanceDocumentation/ABI/testing/sysfs-devices-system-cpu Description: Energy performance preference · line 343
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +10
-0+ + Read/write a 32 bits value from/to this file. This file + conveys the minimum performance level at which the platform + may run. Minimum performance may be set to any performance + value in the range [Lowest Performance, Highest Performance], + inclusive but must be set to a value that is less than or + equal to that specified by the Maximum Performance Register. + + Writing to this file only has meaning when Autonomous Selection + is enabled.In the ACPI specification I don't see a clear dependency between the minimum and maximum performance registers and autonomous selection. There's nothing to say that min and max do not have meaning with autonomous selection is disabled.
Quoted 2 lines
Thanks,
Ionela.
Yes, will remove the text about dependency on autonomous selection in v4.
Thank you,
Sumit Gupta
Quoted 36 lines
Quoted 36 lines
Documentation/ABI/testing/sysfs-devices-system-cpu +29
-1+ + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/max_perf +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file conveys + the maximum performance level at which the platform may run. + Maximum performance may be set to any performance value in the + range [Lowest Performance, Highest Performance], inclusive. + + Writing to this file only has meaning when Autonomous Selection is + enabled. + + This file is only present if the cppc-cpufreq driver is in use. + +What: /sys/devices/system/cpu/cpuX/cpufreq/perf_limited +Date: September 2025 +Contact: [email protected] +Description: Minimum Performance + + Read/write a 32 bits value from/to this file. This file indicates + to OSPM that an unpredictable event has limited processor + performance, and the delivered performance may be less than + desired/minimum performance. + + This file is only present if the cppc-cpufreq driver is in use. What: /sys/devices/system/cpu/cpu*/cache/index3/cache_disable_{0,1} Date: August 2008 --2.34.1