Resend: ACPI/CPUFREQ: Introduce hw_limit per cpu cpufreq sysfs interface
Subsystems (5)
PATCH 1/1 Resend: ACPI/CPUFREQ: Introduce hw_limit per cpu cpufreq sysfs interface
Hi,
I now realized that this patch somewhat clashes with cpufrequtils cpufreq-info --hwlimits command.
IMO "cpufreq-info --hwlimits" is wrong here as it evaluates max_freq sysfs value which could also get limited by the user.
Ideal solution would be to enhance cpufreq-info with:
--hwlimits # evaluate the sysfs entry hwlimits introduced by this patch
--user_limits # evaluate user limits which is not possible with current
# sysfs implementation as max_freq currenlty shows the
# min(hwlimit, thermal_limit, user_limit)
--thermal_limits # evaluate passive cooling triggered limits
# Could/should already be possible by looking at the
# generic thermal sysfs driver exposed limitsThe diff is based on cpufreq next tree.
Thanks,
Thomas
----------
ACPI/CPUFREQ: Introduce hw_limit per cpu cpufreq sysfs interface
Len,Dave: This patch touches acpi and cpufreq subsystems.
What do you think about it?
How could this get pushed without much conflicts,
through the cpufreq tree?
This interface is mainly intended (and implemented) for ACPI _PPC BIOS frequency limitations, but other cpufreq drivers can also use it for similar use-cases.
Why is this needed:
Currently it's not obvious why cpufreq got limited. People see cpufreq/scaling_max_freq reduced, but this could have happened by:
- any userspace prog writing to scaling_max_freq
- thermal limitations
- hardware (_PPC in ACPI case) limitiations
Therefore export hw_limit (in kHz) to:
- Point the user that it's the BIOS (broken or intended) which limits frequency
- Export it as a sysfs interface for userspace progs.
While this was a rarely used feature on laptops, there will appear more and more server implemenations providing "Green IT" features like allowing the service processor to limit the frequency. People want to know about HW/BIOS frequency limitations.
All ACPI P-state driven cpufreq drivers are covered with this patch:
- powernow-k8
- powernow-k7
- acpi-cpufreq
Tested with a patched DSDT which limits the first two cores (_PPC returns 1) via _PPC, exposed by hw_limit:
# echo 2200000 >cpu2/cpufreq/scaling_max_freq # cat cpu*/cpufreq/scaling_max_freq 2600000 2600000 2200000 2200000 # #scaling_max_freq shows general user/thermal/BIOS limitations
# cat cpu*/cpufreq/hw_limit 2600000 2600000 2800000 2800000 # #hw_limit only shows the HW/BIOS limitation
Documentation/cpu-freq/user-guide.txt +11 -0
@@ -203,6 +203,17 @@ scaling_cur_freq : Current frequency of the CPU as determined by the frequency the kernel thinks the CPU runs at. +hw_limit : If the BIOS tells the OS to limit a CPU to + lower frequencies, the user can read out the + maximum available frequency from this file. + This typically can happen through (often not + intended) BIOS settings, restrictions + triggered through a service processor or other + BIOS/HW based implementations. + This does not cover thermal ACPI limitations + which can be detected through the generic + thermal driver. + If you have selected the "userspace" governor which allows you to set the CPU operating frequency to a specific value, you can read out the current frequency in
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c +9 -8
@@ -801,14 +801,15 @@ static struct freq_attr *acpi_cpufreq_attr[] = { };static struct cpufreq_driver acpi_cpufreq_driver = { - .verify = acpi_cpufreq_verify, - .target = acpi_cpufreq_target, - .init = acpi_cpufreq_cpu_init, - .exit = acpi_cpufreq_cpu_exit, - .resume = acpi_cpufreq_resume, - .name ="acpi-cpufreq" , - .owner =THIS_MODULE , - .attr = acpi_cpufreq_attr, + .verify = acpi_cpufreq_verify, + .target = acpi_cpufreq_target, + .hw_limit = acpi_processor_get_bios_limit, + .init = acpi_cpufreq_cpu_init, + .exit = acpi_cpufreq_cpu_exit, + .resume = acpi_cpufreq_resume, + .name ="acpi-cpufreq" , + .owner =THIS_MODULE , + .attr = acpi_cpufreq_attr, };static int __init acpi_cpufreq_init (void )
arch/x86/kernel/cpu/cpufreq/powernow-k7.c +11 -8
@@ -714,14 +714,17 @@ static struct freq_attr *powernow_table_attr[] = { };static struct cpufreq_driver powernow_driver = { - .verify = powernow_verify, - .target = powernow_target, - .get = powernow_get, - .init = powernow_cpu_init, - .exit = powernow_cpu_exit, - .name ="powernow-k7" , - .owner =THIS_MODULE , - .attr = powernow_table_attr, + .verify = powernow_verify, + .target = powernow_target, + .get = powernow_get, +#ifdef CONFIG_X86_POWERNOW_K7_ACPI + .hw_limit = acpi_processor_get_bios_limit, +#endif + .init = powernow_cpu_init, + .exit = powernow_cpu_exit, + .name ="powernow-k7" , + .owner =THIS_MODULE , + .attr = powernow_table_attr, };static int __init powernow_init (void )
arch/x86/kernel/cpu/cpufreq/powernow-k8.c +9 -8
@@ -1413,14 +1413,15 @@ static struct freq_attr *powernow_k8_attr[] = { };static struct cpufreq_driver cpufreq_amd64_driver = { - .verify = powernowk8_verify, - .target = powernowk8_target, - .init = powernowk8_cpu_init, - .exit =__devexit_p (powernowk8_cpu_exit), - .get = powernowk8_get, - .name ="powernow-k8" , - .owner =THIS_MODULE , - .attr = powernow_k8_attr, + .verify = powernowk8_verify, + .target = powernowk8_target, + .hw_limit = acpi_processor_get_bios_limit, + .init = powernowk8_cpu_init, + .exit =__devexit_p (powernowk8_cpu_exit), + .get = powernowk8_get, + .name ="powernow-k8" , + .owner =THIS_MODULE , + .attr = powernow_k8_attr, };/* driver entry point for init */
drivers/acpi/processor_perflib.c +13 -0
@@ -165,6 +165,19 @@ int acpi_processor_ppc_has_changed(struct acpi_processor *pr)return cpufreq_update_policy (pr->id); } +int acpi_processor_get_bios_limit (int cpu,unsigned int *limit) +{ +struct acpi_processor *pr; + + pr =per_cpu (processors, cpu); +if (!pr || !pr->performance || !pr->performance->state_count) +return -ENODEV ; + *limit = pr->performance->states[pr->performance_platform_limit]. + core_frequency *1000 ; +return 0 ; +} +EXPORT_SYMBOL (acpi_processor_get_bios_limit); +void acpi_processor_ppc_init (void ) { if (!cpufreq_register_notifier
drivers/cpufreq/cpufreq.c +17 -0
@@ -727,6 +727,21 @@ static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)return show_cpus (policy->cpus, buf); } +/** +* show_scaling_driver - show the current cpufreq HW/BIOS limitation +*/ +static ssize_t show_hw_limit (struct cpufreq_policy *policy,char *buf) +{ +unsigned int limit; +int ret; +if (cpufreq_driver->hw_limit) { + ret = cpufreq_driver->hw_limit (policy->cpu, &limit); +if (!ret) +return sprintf (buf,"%u\n" , limit); + } +return sprintf (buf,"%u\n" , policy->cpuinfo.max_freq); +} +#define define_one_ro (_name) \ static struct freq_attr _name = \ __ATTR(_name, 0444, show_##_name, NULL)
@@ -744,6 +759,7 @@ define_one_ro(cpuinfo_min_freq);define_one_ro (cpuinfo_max_freq);define_one_ro (cpuinfo_transition_latency);define_one_ro (scaling_cur_freq); +define_one_ro (hw_limit);define_one_ro (related_cpus);define_one_ro (affected_cpus);define_one_rw (scaling_min_freq);
@@ -757,6 +773,7 @@ static struct attribute *default_attrs[] = { &scaling_max_freq.attr, &affected_cpus.attr, &related_cpus.attr, + &hw_limit.attr, &scaling_governor_old.attr, &scaling_driver_old.attr, &scaling_available_governors_old.attr,
include/acpi/processor.h +6 -0
@@ -295,6 +295,7 @@ static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cxvoid acpi_processor_ppc_init (void );void acpi_processor_ppc_exit (void );int acpi_processor_ppc_has_changed (struct acpi_processor *pr); +extern int acpi_processor_get_bios_limit (int cpu,unsigned int *limit);#else static inline void acpi_processor_ppc_init (void ) {
@@ -316,6 +317,11 @@ static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr) }return 0 ; } +int acpi_processor_get_bios_limit (int cpu,unsigned int *limit) +{ +return -ENODEV ; +} +#endif /* CONFIG_CPU_FREQ */ /* in processor_throttling.c */
include/linux/cpufreq.h +2 -1
@@ -226,8 +226,9 @@ struct cpufreq_driver {unsigned int (*get) (unsigned int cpu);/* optional */ -unsigned int (*getavg) (struct cpufreq_policy *policy, +unsigned int (*getavg) (struct cpufreq_policy *policy,unsigned int cpu); +int (*hw_limit) (int cpu,unsigned int *limit);int (*exit) (struct cpufreq_policy *policy);int (*suspend) (struct cpufreq_policy *policy,pm_message_t pmsg);
Hey,
Quoted 4 lines · Thomas Renninger
I now realized that this patch somewhat clashes with cpufrequtils cpufreq-info --hwlimits command.
IMO "cpufreq-info --hwlimits" is wrong here as it evaluatesmax_freqsysfs value which could also get limited by the user.
huh?
brodo@comet:~$ cpufreq-info --hwlimits 800000 2001000 brodo@comet:~$ sudo cpufreq-set --max 1.2G brodo@comet:~$ cpufreq-info --hwlimits 800000 2001000
--hwlimits evaluates cpuinfo_{cur,min,max}_freq which are the hardware limits. Those may be limited further by the BIOS on runtime (firmware limits, so to speak). It seems to me that this is what you want to add with this patch?
Best,
Dominik
Quoted 8 lines · On Thursday 03 September 2009 23:42:31 Dominik Brodowski wrote:
Hey,
Quoted 4 lines · Thomas Renninger
I now realized that this patch somewhat clashes with cpufrequtils cpufreq-info --hwlimits command.
IMO "cpufreq-info --hwlimits" is wrong here as it evaluatesmax_freqsysfs value which could also get limited by the user.
Quoted 7 lines
huh?
brodo@comet:~$ cpufreq-info --hwlimits 800000 2001000 brodo@comet:~$ sudo cpufreq-set --max 1.2G brodo@comet:~$ cpufreq-info --hwlimits 800000 2001000
Ah, I didn't look into cpufreqinfo details where hwlimits is coming from.
But how would one then differ between:
- The max freq the CPU is really capable of
- Whether it's a BIOS limitation
I like to have the _PPC limitation exposed to userspace in a way one can be sure it is a _PPC limitation. cpuinfo.bios_limit?
Another, more intrusive idea (I mainly care about _PPC distinction):
Best also thermal or whatever other limits there could happen. Most generic approach which comes to my mind is something like:
- Introduce
cpufreq_verify_within_limits(policy, min, max) wrapper:
cpufreq_set_limit(char *limit_name, policy, min, max)
Thermal or PPC(processor) driver could then use:
cpufreq_set_limit("bios", policy, min, max)
cpufreq_set_limit("thermal", policy, min, max)
cpufreq core's cpufreq_set_limit function will remember the limit and where it comes from and calls cpufreq_verify_within_limits internally.
thermal, processor and possible other drivers would need to register a cpufreq limit, a sysfs file could then dynamically be created and the limit exposed, e.g. like:
cpu0/cpufreq/limits/thermal
cpu0/cpufreq/limits/bios (or ppc now?) cpu0/cpufreq/limits/...
Any idea of an easier way to achieve this (provide a unique and easy way to show freq limitations and what's the root cause
of it)?
Thomas
Quoted 8 lines
--hwlimits evaluates cpuinfo_{cur,min,max}_freq which are the hardware limits. Those may be limited further by the BIOS on runtime (firmware limits, so to speak). It seems to me that this is what you want to add with this patch?
Best,
Dominik