ACPI spec 6.2 section 8.4.7.1 provide the following two CPC registers.
"Highest performance is the absolute maximum performance an individual
processor may reach, assuming ideal conditions. This performance level
may not be sustainable for long durations, and may only be achievable if
other platform components are in a specific state; for example, it may
require other processors be in an idle state.
Nominal Performance is the maximum sustained performance level of the
processor, assuming ideal operating conditions. In absence of an
external constraint (power, thermal, etc.) this is the performance level
the platform is expected to be able to maintain continuously. All
processors are expected to be able to sustain their nominal performance
state simultaneously."
We can use Highest Performance as the max performance in boost mode and
Nomial Performance as the max performance in non-boost mode. If the
Highest Performance is greater than the Nominal Performance, we assume
SW BOOST is supported.
Xiongfeng Wang (3):
cpufreq: fix the return value in 'cpufreq_boost_set_sw()'
cpufreq: Add SW BOOST support for drivers without frequency table
CPPC: add support for SW BOOST
drivers/cpufreq/cppc_cpufreq.c | 17 +++++++++++++++--
drivers/cpufreq/cpufreq.c | 25 +++++++++++++++++--------
include/linux/cpufreq.h | 2 ++
3 files changed, 34 insertions(+), 10 deletions(-)
--
1.7.12.4
When I try to add SW BOOST support for CPPC, I got the following error:
cpufreq: cpufreq_boost_trigger_state: Cannot enable BOOST
cpufreq: store_boost: Cannot enable BOOST!
It is because return value 1 of 'freq_qos_update_request()' means the
effective constraint value has changed, not a error code on failures.
But for 'cpufreq_driver.set_boost()', a nonzero return value means
failure. So change 'ret' to zero when 'freq_qos_update_request()'
returns a positive value.
Signed-off-by: Xiongfeng Wang <[email protected]>
---
drivers/cpufreq/cpufreq.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 4adac3a..475fb1b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2522,6 +2522,8 @@ static int cpufreq_boost_set_sw(int state)
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
if (ret < 0)
break;
+ else
+ ret = 0;
}
return ret;
--
1.7.12.4
Software-managed BOOST get the boost frequency by check the flag
CPUFREQ_BOOST_FREQ at driver's frequency table. But some cpufreq driver
don't have frequency table and use other methods to get the frequency
range, such CPPC cpufreq driver.
To add SW BOOST support for drivers without frequency table, we add
members in 'cpufreq_policy.cpufreq_cpuinfo' to record the max frequency
of boost mode and non-boost mode. The cpufreq driver initialize these two
members when probing.
Signed-off-by: Xiongfeng Wang <[email protected]>
---
drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
include/linux/cpufreq.h | 2 ++
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 475fb1b..a299426 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2508,15 +2508,22 @@ static int cpufreq_boost_set_sw(int state)
int ret = -EINVAL;
for_each_active_policy(policy) {
- if (!policy->freq_table)
- continue;
-
- ret = cpufreq_frequency_table_cpuinfo(policy,
+ if (policy->freq_table) {
+ ret = cpufreq_frequency_table_cpuinfo(policy,
policy->freq_table);
- if (ret) {
- pr_err("%s: Policy frequency update failed\n",
- __func__);
- break;
+ if (ret) {
+ pr_err("%s: Policy frequency update failed\n",
+ __func__);
+ break;
+ }
+ } else if (policy->cpuinfo.boost_max_freq) {
+ if (state)
+ policy->max = policy->cpuinfo.boost_max_freq;
+ else
+ policy->max = policy->cpuinfo.nonboost_max_freq;
+ policy->cpuinfo.max_freq = policy->max;
+ } else {
+ continue;
}
ret = freq_qos_update_request(policy->max_freq_req, policy->max);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 018dce8..c3449e6 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -43,6 +43,8 @@ enum cpufreq_table_sorting {
struct cpufreq_cpuinfo {
unsigned int max_freq;
unsigned int min_freq;
+ unsigned int boost_max_freq;
+ unsigned int nonboost_max_freq;
/* in 10^(-9) s = nanoseconds */
unsigned int transition_latency;
--
1.7.12.4
On Friday, May 8, 2020 11:11:02 AM CEST Xiongfeng Wang wrote:
> When I try to add SW BOOST support for CPPC, I got the following error:
> cpufreq: cpufreq_boost_trigger_state: Cannot enable BOOST
> cpufreq: store_boost: Cannot enable BOOST!
>
> It is because return value 1 of 'freq_qos_update_request()' means the
> effective constraint value has changed, not a error code on failures.
> But for 'cpufreq_driver.set_boost()', a nonzero return value means
> failure. So change 'ret' to zero when 'freq_qos_update_request()'
> returns a positive value.
>
> Signed-off-by: Xiongfeng Wang <[email protected]>
> ---
> drivers/cpufreq/cpufreq.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 4adac3a..475fb1b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2522,6 +2522,8 @@ static int cpufreq_boost_set_sw(int state)
> ret = freq_qos_update_request(policy->max_freq_req, policy->max);
> if (ret < 0)
> break;
> + else
> + ret = 0;
> }
>
> return ret;
>
I would change cpufreq_boost_trigger_state() to take the 1 into account properly
instead.
Thanks!
On Friday, May 8, 2020 11:11:03 AM CEST Xiongfeng Wang wrote:
> Software-managed BOOST get the boost frequency by check the flag
> CPUFREQ_BOOST_FREQ at driver's frequency table. But some cpufreq driver
> don't have frequency table and use other methods to get the frequency
> range, such CPPC cpufreq driver.
>
> To add SW BOOST support for drivers without frequency table, we add
> members in 'cpufreq_policy.cpufreq_cpuinfo' to record the max frequency
> of boost mode and non-boost mode. The cpufreq driver initialize these two
> members when probing.
>
> Signed-off-by: Xiongfeng Wang <[email protected]>
> ---
> drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
> include/linux/cpufreq.h | 2 ++
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 475fb1b..a299426 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2508,15 +2508,22 @@ static int cpufreq_boost_set_sw(int state)
> int ret = -EINVAL;
>
> for_each_active_policy(policy) {
> - if (!policy->freq_table)
> - continue;
> -
> - ret = cpufreq_frequency_table_cpuinfo(policy,
> + if (policy->freq_table) {
> + ret = cpufreq_frequency_table_cpuinfo(policy,
> policy->freq_table);
> - if (ret) {
> - pr_err("%s: Policy frequency update failed\n",
> - __func__);
> - break;
> + if (ret) {
> + pr_err("%s: Policy frequency update failed\n",
> + __func__);
> + break;
> + }
> + } else if (policy->cpuinfo.boost_max_freq) {
> + if (state)
> + policy->max = policy->cpuinfo.boost_max_freq;
> + else
> + policy->max = policy->cpuinfo.nonboost_max_freq;
> + policy->cpuinfo.max_freq = policy->max;
> + } else {
> + continue;
> }
Why do you need to update this function?
The driver should be able to provide its own ->set_boost callback just fine,
shouldn't it?
>
> ret = freq_qos_update_request(policy->max_freq_req, policy->max);
> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
> index 018dce8..c3449e6 100644
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -43,6 +43,8 @@ enum cpufreq_table_sorting {
> struct cpufreq_cpuinfo {
> unsigned int max_freq;
> unsigned int min_freq;
> + unsigned int boost_max_freq;
> + unsigned int nonboost_max_freq;
>
> /* in 10^(-9) s = nanoseconds */
> unsigned int transition_latency;
>
Hi Rafael,
Thanks for your reply !
On 2020/5/14 21:54, Rafael J. Wysocki wrote:
> On Friday, May 8, 2020 11:11:02 AM CEST Xiongfeng Wang wrote:
>> When I try to add SW BOOST support for CPPC, I got the following error:
>> cpufreq: cpufreq_boost_trigger_state: Cannot enable BOOST
>> cpufreq: store_boost: Cannot enable BOOST!
>>
>> It is because return value 1 of 'freq_qos_update_request()' means the
>> effective constraint value has changed, not a error code on failures.
>> But for 'cpufreq_driver.set_boost()', a nonzero return value means
>> failure. So change 'ret' to zero when 'freq_qos_update_request()'
>> returns a positive value.
>>
>> Signed-off-by: Xiongfeng Wang <[email protected]>
>> ---
>> drivers/cpufreq/cpufreq.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index 4adac3a..475fb1b 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -2522,6 +2522,8 @@ static int cpufreq_boost_set_sw(int state)
>> ret = freq_qos_update_request(policy->max_freq_req, policy->max);
>> if (ret < 0)
>> break;
>> + else
>> + ret = 0;
>> }
>>
>> return ret;
>>
>
> I would change cpufreq_boost_trigger_state() to take the 1 into account properly
> instead.
Thanks for your suggestion. I will change it in the next version.
Thanks,
Xiongfeng
>
> Thanks!
>
>
>
>
> .
>
On 2020/5/14 22:16, Rafael J. Wysocki wrote:
> On Friday, May 8, 2020 11:11:03 AM CEST Xiongfeng Wang wrote:
>> Software-managed BOOST get the boost frequency by check the flag
>> CPUFREQ_BOOST_FREQ at driver's frequency table. But some cpufreq driver
>> don't have frequency table and use other methods to get the frequency
>> range, such CPPC cpufreq driver.
>>
>> To add SW BOOST support for drivers without frequency table, we add
>> members in 'cpufreq_policy.cpufreq_cpuinfo' to record the max frequency
>> of boost mode and non-boost mode. The cpufreq driver initialize these two
>> members when probing.
>>
>> Signed-off-by: Xiongfeng Wang <[email protected]>
>> ---
>> drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
>> include/linux/cpufreq.h | 2 ++
>> 2 files changed, 17 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index 475fb1b..a299426 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -2508,15 +2508,22 @@ static int cpufreq_boost_set_sw(int state)
>> int ret = -EINVAL;
>>
>> for_each_active_policy(policy) {
>> - if (!policy->freq_table)
>> - continue;
>> -
>> - ret = cpufreq_frequency_table_cpuinfo(policy,
>> + if (policy->freq_table) {
>> + ret = cpufreq_frequency_table_cpuinfo(policy,
>> policy->freq_table);
>> - if (ret) {
>> - pr_err("%s: Policy frequency update failed\n",
>> - __func__);
>> - break;
>> + if (ret) {
>> + pr_err("%s: Policy frequency update failed\n",
>> + __func__);
>> + break;
>> + }
>> + } else if (policy->cpuinfo.boost_max_freq) {
>> + if (state)
>> + policy->max = policy->cpuinfo.boost_max_freq;
>> + else
>> + policy->max = policy->cpuinfo.nonboost_max_freq;
>> + policy->cpuinfo.max_freq = policy->max;
>> + } else {
>> + continue;
>> }
>
> Why do you need to update this function?
My original thought is to reuse the current SW BOOST code as possible, but this
seems to change the cpufreq core too much.
>
> The driver should be able to provide its own ->set_boost callback just fine,
> shouldn't it?
Thanks for your advice. This is better. I will provide a '->set_boost' callback
for CPPC driver. But I will need to export 'cpufreq_policy_list' and make the
macro 'for_each_active_policy' public.
Thanks,
Xiongfeng
>
>>
>> ret = freq_qos_update_request(policy->max_freq_req, policy->max);
>> diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
>> index 018dce8..c3449e6 100644
>> --- a/include/linux/cpufreq.h
>> +++ b/include/linux/cpufreq.h
>> @@ -43,6 +43,8 @@ enum cpufreq_table_sorting {
>> struct cpufreq_cpuinfo {
>> unsigned int max_freq;
>> unsigned int min_freq;
>> + unsigned int boost_max_freq;
>> + unsigned int nonboost_max_freq;
>>
>> /* in 10^(-9) s = nanoseconds */
>> unsigned int transition_latency;
>>
>
>
>
>
>
> .
>
Sorry for the delay from my side in replying to this thread.
On 15-05-20, 09:49, Xiongfeng Wang wrote:
> On 2020/5/14 22:16, Rafael J. Wysocki wrote:
> > On Friday, May 8, 2020 11:11:03 AM CEST Xiongfeng Wang wrote:
> >> Software-managed BOOST get the boost frequency by check the flag
> >> CPUFREQ_BOOST_FREQ at driver's frequency table. But some cpufreq driver
> >> don't have frequency table and use other methods to get the frequency
> >> range, such CPPC cpufreq driver.
> >>
> >> To add SW BOOST support for drivers without frequency table, we add
> >> members in 'cpufreq_policy.cpufreq_cpuinfo' to record the max frequency
> >> of boost mode and non-boost mode. The cpufreq driver initialize these two
> >> members when probing.
> >>
> >> Signed-off-by: Xiongfeng Wang <[email protected]>
> >> ---
> >> drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
> >> include/linux/cpufreq.h | 2 ++
> >> 2 files changed, 17 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> >> index 475fb1b..a299426 100644
> >> --- a/drivers/cpufreq/cpufreq.c
> >> +++ b/drivers/cpufreq/cpufreq.c
> >> @@ -2508,15 +2508,22 @@ static int cpufreq_boost_set_sw(int state)
> >> int ret = -EINVAL;
> >>
> >> for_each_active_policy(policy) {
> >> - if (!policy->freq_table)
> >> - continue;
> >> -
> >> - ret = cpufreq_frequency_table_cpuinfo(policy,
> >> + if (policy->freq_table) {
> >> + ret = cpufreq_frequency_table_cpuinfo(policy,
> >> policy->freq_table);
> >> - if (ret) {
> >> - pr_err("%s: Policy frequency update failed\n",
> >> - __func__);
> >> - break;
> >> + if (ret) {
> >> + pr_err("%s: Policy frequency update failed\n",
> >> + __func__);
> >> + break;
> >> + }
> >> + } else if (policy->cpuinfo.boost_max_freq) {
> >> + if (state)
> >> + policy->max = policy->cpuinfo.boost_max_freq;
> >> + else
> >> + policy->max = policy->cpuinfo.nonboost_max_freq;
> >> + policy->cpuinfo.max_freq = policy->max;
> >> + } else {
> >> + continue;
> >> }
> >
> > Why do you need to update this function?
>
> My original thought is to reuse the current SW BOOST code as possible, but this
> seems to change the cpufreq core too much.
>
> Thanks for your advice. This is better. I will provide a '->set_boost' callback
> for CPPC driver. But I will need to export 'cpufreq_policy_list' and make the
> macro 'for_each_active_policy' public.
This can and should be avoided, I will rather move the for-each-policy
loop in cpufreq_boost_trigger_state() and call ->set_boost() for each
policy and pass policy as argument as well. You would be required to
update existing users of sw boost.
--
viresh
Hi Viresh,
Thanks for your reply !
On 2020/5/18 15:53, Viresh Kumar wrote:
> Sorry for the delay from my side in replying to this thread.
>
> On 15-05-20, 09:49, Xiongfeng Wang wrote:
>> On 2020/5/14 22:16, Rafael J. Wysocki wrote:
>>> On Friday, May 8, 2020 11:11:03 AM CEST Xiongfeng Wang wrote:
>>>> Software-managed BOOST get the boost frequency by check the flag
>>>> CPUFREQ_BOOST_FREQ at driver's frequency table. But some cpufreq driver
>>>> don't have frequency table and use other methods to get the frequency
>>>> range, such CPPC cpufreq driver.
>>>>
>>>> To add SW BOOST support for drivers without frequency table, we add
>>>> members in 'cpufreq_policy.cpufreq_cpuinfo' to record the max frequency
>>>> of boost mode and non-boost mode. The cpufreq driver initialize these two
>>>> members when probing.
>>>>
>>>> Signed-off-by: Xiongfeng Wang <[email protected]>
>>>> ---
>>>> drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
>>>> include/linux/cpufreq.h | 2 ++
>>>> 2 files changed, 17 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>>>> index 475fb1b..a299426 100644
>>>> --- a/drivers/cpufreq/cpufreq.c
>>>> +++ b/drivers/cpufreq/cpufreq.c
>>>> @@ -2508,15 +2508,22 @@ static int cpufreq_boost_set_sw(int state)
>>>> int ret = -EINVAL;
>>>>
>>>> for_each_active_policy(policy) {
>>>> - if (!policy->freq_table)
>>>> - continue;
>>>> -
>>>> - ret = cpufreq_frequency_table_cpuinfo(policy,
>>>> + if (policy->freq_table) {
>>>> + ret = cpufreq_frequency_table_cpuinfo(policy,
>>>> policy->freq_table);
>>>> - if (ret) {
>>>> - pr_err("%s: Policy frequency update failed\n",
>>>> - __func__);
>>>> - break;
>>>> + if (ret) {
>>>> + pr_err("%s: Policy frequency update failed\n",
>>>> + __func__);
>>>> + break;
>>>> + }
>>>> + } else if (policy->cpuinfo.boost_max_freq) {
>>>> + if (state)
>>>> + policy->max = policy->cpuinfo.boost_max_freq;
>>>> + else
>>>> + policy->max = policy->cpuinfo.nonboost_max_freq;
>>>> + policy->cpuinfo.max_freq = policy->max;
>>>> + } else {
>>>> + continue;
>>>> }
>>>
>>> Why do you need to update this function?
>>
>> My original thought is to reuse the current SW BOOST code as possible, but this
>> seems to change the cpufreq core too much.
>>
>> Thanks for your advice. This is better. I will provide a '->set_boost' callback
>> for CPPC driver. But I will need to export 'cpufreq_policy_list' and make the
>> macro 'for_each_active_policy' public.
>
> This can and should be avoided, I will rather move the for-each-policy
> loop in cpufreq_boost_trigger_state() and call ->set_boost() for each
> policy and pass policy as argument as well. You would be required to
> update existing users of sw boost.
Thanks for your advice. It's a good idea. I will change it in the next version.
Thanks,
Xiongfeng
>