acpi-cpufreq: introduce base_frequency
Subsystems (2)
PATCH v3 1/1 acpi-cpufreq: introduce base_frequency
v3
-Merged Documentation and code patch to one patch.
-Created a common function to read tar which is used init and during read -Documentation and code changed suggested by Viresh
-On unsupported CPUs, user when tries to read base_frequency "Operation not supported" error will be returned.
v2sysfs_create_file on policy->kobj is no longer possible on recent kernel versions. So we can't create selectively create base_frequency attribute on supported policies.
This version creates a base_frequency attribute, if the boot cpu supports as part of cpufreq_driver->attributes. If for some CPUs the TAR can't be read, return error.
v1:
Base version
Srinivas Pandruvada (1):
cpufreq: acpi_cpufreq: base frequency attribute support
Documentation/cpu-freq/acpi-cpufreq.txt | 27 ++++++++++++++++++++ drivers/cpufreq/acpi-cpufreq.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Documentation/cpu-freq/acpi-cpufreq.txt
Signature · 1 line
2.5.0
PATCH v3 1/1 cpufreq: acpi_cpufreq: base frequency attribute support
Currently scaling_available_frequencies displays list of available frequencies which can be used to set max/min or current scaling frequency.
Quoted 1 line
cat
scaling_available_frequencies
2301000 2300000 2200000 2000000 1900000 1800000 1700000 1500000 1400000 1300000 1100000 1000000 900000 800000 600000 500000
Here traditionally it is assumed that only 2301000 is a turbo frequency, which is purely opportunistic, anything else user can request and may get it.
But because of configurable thermal design power implementation in several Intel CPUs, the opportunistic frequency start can be any frequency in this range. For example it can be 2300000 or any lower value.
This change adds an optional new attribute called "base_frequency", which displays the max non-turbo frequency (base frequency). For example:
Quoted 1 line
cat
base_frequency
2200000
This will allow user to choose a certain frequency which is not opportunistic.
--- Documentation/cpu-freq/acpi-cpufreq.txt | 27 ++++++++++++++++++++ drivers/cpufreq/acpi-cpufreq.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Documentation/cpu-freq/acpi-cpufreq.txt
Documentation/cpu-freq/acpi-cpufreq.txt new file +27 -0
@@ -0,0 +1,27 @@ +Additional sysfs attributes for acpi-cpufreq + +acpi-cpufreq sysfs has following sysfs attributes in addition to standard +cpufreq attributes: + +base_frequency : Max non-turbo frequency + For example: + scaling_available_frequencies displays list + of available frequencies. + + >cat scaling_available_frequencies + 2301000 2300000 2200000 2000000 1900000 + 1800000 1700000 1500000 1400000 1300000 + 1100000 1000000 900000 800000 600000 + 500000 + + If the base_frequency attribute is present + and readable, then any frequency above + base_frequency is turbo frequency. For example + + >cat base_frequency + 2200000 + + Then in the above displayed list of + scaling_available_frequencies, 2300000 and + 2301000 are turbo frequencies. +
drivers/cpufreq/acpi-cpufreq.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
2.5.0
Viresh Kumar
maintainerRe: [PATCH v3] cpufreq: acpi_cpufreq: base frequency attribute support
Quoted 15 lines · Srinivas Pandruvada
Currently
scaling_available_frequenciesdisplays list of available frequencies which can be used to set max/min or current scaling frequency.Quoted 1 line
cat
scaling_available_frequencies2301000 2300000 2200000 2000000 1900000 1800000 1700000 1500000 1400000 1300000 1100000 1000000 900000 800000 600000 500000
Here traditionally it is assumed that only 2301000 is a turbo frequency, which is purely opportunistic, anything else user can request and may get it.
But because of configurable thermal design power implementation in several Intel CPUs, the opportunistic frequency start can be any frequency in this range. For example it can be 2300000 or any lower value.
This change adds an optional new attribute called "base_frequency", which displays the max non-turbo frequency (base frequency). For example:
Quoted 4 lines
Quoted 1 line
cat
base_frequency2200000
This will allow user to choose a certain frequency which is not opportunistic.
Add blank line after all paragraphs.
Quoted 2 lines
Signed-off-by Srinivas Pandruvada <[email protected]>---
Instead of the cover-letter, you could have used this space to add all version information or things that you don't want to get committed.
Quoted 12 lines
Documentation/cpu-freq/acpi-cpufreq.txt | 27 ++++++++++++++++++++ drivers/cpufreq/acpi-cpufreq.c | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Documentation/cpu-freq/acpi-cpufreq.txtDocumentation/cpu-freq/acpi-cpufreq.txt new file +1
-0@@ -0,0 +1,27 @@ +Additional sysfs attributes for acpi-cpufreq
Documentation/cpu-freq/acpi-cpufreq.txt line 11
Quoted 10 lines
Documentation/cpu-freq/acpi-cpufreq.txt new file +10
-0+ +acpi-cpufreq sysfs has following sysfs attributes in addition to standard +cpufreq attributes: + +base_frequency : Max non-turbo frequency + For example: + scaling_available_frequencies displays list + of available frequencies. + + >cat scaling_available_frequencies
Maybe s/>/$ / ?
Quoted 40 lines
Documentation/cpu-freq/acpi-cpufreq.txt new file +16
-0+ 2301000 2300000 2200000 2000000 1900000 + 1800000 1700000 1500000 1400000 1300000 + 1100000 1000000 900000 800000 600000 + 500000 + + If the base_frequency attribute is present + and readable, then any frequency above + base_frequency is turbo frequency. For example + + >cat base_frequency + 2200000 + + Then in the above displayed list of + scaling_available_frequencies, 2300000 and + 2301000 are turbo frequencies. +drivers/cpufreq/acpi-cpufreq.c +16
-0@@ -646,6 +646,37 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) }#endif +static int x86_get_turbo_activation_ratio (int cpu,u64 *tar) +{ +u64 plat_info; +int err; + + err =rdmsrl_safe_on_cpu (cpu,MSR_PLATFORM_INFO , &plat_info); +/* Check number of config TDP levels > 0 */ +if (!err && ((plat_info >>33 ) &0x03 ) >0 ) + err =rdmsrl_safe_on_cpu (cpu,MSR_TURBO_ACTIVATION_RATIO , + tar); +else + err = -EOPNOTSUPP ; + +return err; +} +
drivers/cpufreq/acpi-cpufreq.c static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) · line 674
Quoted 10 lines
drivers/cpufreq/acpi-cpufreq.c +10
-0+static ssize_t show_base_frequency (struct cpufreq_policy *policy,char *buf) +{ +u64 tar; +int err; + + err =x86_get_turbo_activation_ratio (policy->cpu, &tar); +if (!err) +/* Refer to IA64, IA32 SDM table 35-20, unit = 100 MHz */ +return sprintf (buf,"%llu\n" , tar *100000 ); +
We normally write code like this:
ret = ...();
if (ret)
return fail;
success-code..
drivers/cpufreq/acpi-cpufreq.c static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) · line 675
Quoted 1 line
drivers/cpufreq/acpi-cpufreq.c +1
-0+return err;
And so you can write your code as:
if (err)
return err;
return sprintf(...);Quoted 25 lines
drivers/cpufreq/acpi-cpufreq.c +11
-0+} + +cpufreq_freq_attr_ro (base_frequency); +static int acpi_cpufreq_cpu_init (struct cpufreq_policy *policy) {unsigned int i;@@ -888,6 +919,7 @@ static struct freq_attr *acpi_cpufreq_attr[] = {#ifdef CONFIG_X86_ACPI_CPUFREQ_CPB &cpb, #endif +NULL ,/* Extra space for base_frequency attr, if required */ NULL, };@@ -971,6 +1003,19 @@ static int __init acpi_cpufreq_init(void) } }#endif + +if (boot_cpu_has (X86_FEATURE_IDA )) { +u64 tar; + +if (!x86_get_turbo_activation_ratio (0 , &tar)) { +struct freq_attr **attr;
drivers/cpufreq/acpi-cpufreq.c static int __init acpi_cpufreq_init(void) · line 1021
Quoted 10 lines
drivers/cpufreq/acpi-cpufreq.c +7
-0+ +for (attr = acpi_cpufreq_attr; *attr; attr++) + ; + *attr = &base_frequency; + } + } +acpi_cpufreq_boost_init (); ret =cpufreq_register_driver (&acpi_cpufreq_driver);
Please see if suggestions from the previous thread are acceptable.
Signature · 1 line
viresh
Re: [PATCH v3] cpufreq: acpi_cpufreq: base frequency attribute support
Quoted 30 lines · Viresh Kumar
Quoted 22 lines · Srinivas Pandruvada
Currently
scaling_available_frequenciesdisplays list of available frequencies which can be used to set max/min or current scaling frequency.Quoted 1 line
cat
scaling_available_frequencies2301000 2300000 2200000 2000000 1900000 1800000 1700000 1500000 1400000
1300000 1100000 1000000 900000 800000 600000 500000Here traditionally it is assumed that only 2301000 is a turbo frequency,
which is purely opportunistic, anything else user can request and may
get it.
But because of configurable thermal design power implementation in several
Intel CPUs, the opportunistic frequency start can be any frequency in this
range. For example it can be 2300000 or any lower value. This change adds an optional new attribute called "base_frequency", which displays the max non-turbo frequency (base frequency). For example:Quoted 4 lines
Quoted 1 line
cat
base_frequency2200000
This will allow user to choose a certain frequency which is not opportunistic.Add blank line after all paragraphs.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Srinivas Pandruvada <[email protected].com>
---Instead of the cover-letter, you could have used this space to add all version
information or things that you don't want to get committed.
Yes. I prefer to do for short version history.
Quoted 103 lines
Quoted 24 lines
Documentation/cpu-freq/acpi-cpufreq.txt | 27 ++++++++++++++++++++ drivers/cpufreq/acpi-cpufreq.c | 45
+++++++++++++++++++++++++++++++++2 files changed, 72 insertions(+)create mode 100644
Documentation/cpu-freq/acpi-cpufreq.txtDocumentation/cpu-freq/acpi-cpufreq.txt new file +3
-0@@ -0,0 +1,27 @@ +Additional sysfs attributes for acpi-cpufreq + +acpi-cpufreq sysfs has following sysfs attributes in addition tostandard
Documentation/cpu-freq/acpi-cpufreq.txt new file +5
-0+cpufreq attributes: + +base_frequency : Max non-turbo frequency + For example: + scaling_available_frequenciesdisplays list
Documentation/cpu-freq/acpi-cpufreq.txt line 11
Quoted 3 lines
Documentation/cpu-freq/acpi-cpufreq.txt new file +3
-0+ of available frequencies. + + >cat scaling_available_frequenciesMaybe s/>/$ / ?
Quoted 62 lines
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ 2301000 2300000 2200000 20000001900000
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ 1800000 1700000 1500000 14000001300000
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ 1100000 1000000 900000 800000600000
Documentation/cpu-freq/acpi-cpufreq.txt new file +3
-0+ 500000 + + If the base_frequency attribute ispresent
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ and readable, then any frequencyabove
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ base_frequency is turbo frequency.For example
Documentation/cpu-freq/acpi-cpufreq.txt new file +5
-0+ + >cat base_frequency + 2200000 + + Then in the above displayed listof
Documentation/cpu-freq/acpi-cpufreq.txt new file +1
-0+ scaling_available_frequencies,2300000 and
Documentation/cpu-freq/acpi-cpufreq.txt new file +2
-0+ 2301000 are turbo frequencies. +drivers/cpufreq/acpi- renamed from drivers/cpufreq/acpi-cpufreq.c +0
-0
cpufreq.c
index 51eef87..0bdd36d 100644drivers/cpufreq/acpi-cpufreq.c +0
-0@@ -646,6 +646,37 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) } #endifdrivers/cpufreq/acpi-cpufreq.c +6
-0+static int x86_get_turbo_activation_ratio (int cpu,u64 *tar) +{ +u64 plat_info; +int err; + + err = rdmsrl_safe_on_cpu(cpu, MSR_PLATFORM_INFO,
&plat_info);drivers/cpufreq/acpi-cpufreq.c +3
-0+/* Check number of config TDP levels > 0 */ +if (!err && ((plat_info >>33 ) &0x03 ) >0 ) + err = rdmsrl_safe_on_cpu(cpu,
MSR_TURBO_ACTIVATION_RATIO,drivers/cpufreq/acpi-cpufreq.c +8
-0+ tar); + else + err = -EOPNOTSUPP ; + +return err; +} + +static ssize_t show_base_frequency(struct cpufreq_policy *policy,char *buf)
drivers/cpufreq/acpi-cpufreq.c +7
-0+{ +u64 tar; +int err; + + err =x86_get_turbo_activation_ratio (policy->cpu, &tar); +if (!err) +/* Refer to IA64, IA32 SDM table 35-20, unit = 100 MHz */
drivers/cpufreq/acpi-cpufreq.c
Quoted 2 lines
drivers/cpufreq/acpi-cpufreq.c +2
-0+return sprintf (buf,"%llu\n" , tar *100000 ); +We normally write code like this:
ret = ...();
if (ret)
return fail;success-code..
Quoted 9 lines
drivers/cpufreq/acpi-cpufreq.c
Quoted 1 line
drivers/cpufreq/acpi-cpufreq.c +1
-0+return err;And so you can write your code as:
if (err)
return err;return sprintf(...);
OK
Quoted 32 lines
Quoted 32 lines
drivers/cpufreq/acpi-cpufreq.c +4
-0+} + +cpufreq_freq_attr_ro (base_frequency); +static int
acpi_cpufreq_cpu_init(struct cpufreq_policy *policy){
unsigned int i;drivers/cpufreq/acpi-cpufreq.c +1
-0@@ -888,6 +919,7 @@ static struct freq_attr *acpi_cpufreq_attr[] = { #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB &cpb, #endif +NULL ,/* Extra space for base_frequency attr, if required */ NULL,};
drivers/cpufreq/acpi-cpufreq.c +10
-0@@ -971,6 +1003,19 @@ static int __init acpi_cpufreq_init(void) } } #endif + +if (boot_cpu_has (X86_FEATURE_IDA )) { +u64 tar; + +if (!x86_get_turbo_activation_ratio (0 , &tar)) { +struct freq_attr **attr; + +for (attr = acpi_cpufreq_attr; *attr; attr++) + ; + *attr = &base_frequency;
Quoted 8 lines
Quoted 6 lines
drivers/cpufreq/acpi-cpufreq.c +3
-0+ } + } + acpi_cpufreq_boost_init();
ret =cpufreq_register_driver(&acpi_cpufreq_driver);Please see if suggestions from the previous thread are acceptable.
I have to change CPB code to do so. This driver has a lot of legacy code, so cleanup should be separate.
Thanks,
Srinivas