All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
To: Mario Limonciello <mario.limonciello@amd.com>,
	gautham.shenoy@amd.com, perry.yuan@amd.com, rafael@kernel.org,
	viresh.kumar@linaro.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] cpufreq/amd-pstate: Set the initial min_freq to lowest_nonlinear_freq
Date: Thu, 17 Oct 2024 10:02:33 +0530	[thread overview]
Message-ID: <db3f2bfd-803b-4725-8e8a-3ca24d4149db@amd.com> (raw)
In-Reply-To: <f54901f7-fdf9-409a-bbd6-6b08db00e125@amd.com>

Hello Mario,

On 10/16/2024 8:27 PM, Mario Limonciello wrote:
> On 10/16/2024 09:46, Dhananjay Ugwekar wrote:
>> According to the AMD architectural programmer's manual volume 2 [1], in
>> section "17.6.4.1 CPPC_CAPABILITY_1" lowest_nonlinear_perf is described
>> as "Reports the most energy efficient performance level (in terms of
>> performance per watt). Above this threshold, lower performance levels
>> generally result in increased energy efficiency. Reducing performance
>> below this threshold does not result in total energy savings for a given
>> computation, although it reduces instantaneous power consumption". So
>> lowest_nonlinear_perf is the most power efficient performance level, and
>> going below that would lead to a worse performance/watt.
>>
>> Also, setting the minimum frequency to lowest_nonlinear_freq (instead of
>> lowest_freq) allows the CPU to idle at a higher frequency which leads
>> to more time being spent in a deeper idle state (as trivial idle tasks
>> are completed sooner). This has shown a power benefit in some systems,
>> in other systems, power consumption has increased but so has the
>> throughput/watt.
>>
>> Modify the initial policy_data->min passed by cpufreq core to
>> lowest_nonlinear_freq, in the ->verify() callback. Also set the
>> qos_request cpudata->req[0] to FREQ_QOS_MIN_DEFAULT_VALUE (i.e. 0),
>> so that it also gets overridden by the check in verify function.
>>
>> Link: https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf [1]
>>
>> Signed-off-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
>> ---
>>   drivers/cpufreq/amd-pstate.c | 14 +++++++++++++-
>>   1 file changed, 13 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
>> index fa16d72d6058..117ad5988e8e 100644
>> --- a/drivers/cpufreq/amd-pstate.c
>> +++ b/drivers/cpufreq/amd-pstate.c
>> @@ -529,8 +529,20 @@ static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,
>>     static int amd_pstate_verify(struct cpufreq_policy_data *policy_data)
>>   {
>> +    struct cpufreq_policy *policy = cpufreq_cpu_get(policy_data->cpu);
>> +    struct amd_cpudata *cpudata = policy->driver_data;
> 
> This /could/ be a NULL pointer de-reference.  It should have been initialized after the "if (!policy)" check.
> 
> It's a one line change though to initialize at the right place so I'll do some testing on the series though with that manually fixed up and if there are no other problems I'll take it.

Thanks for catching it!, last minute changes led to this oversight. As we 
discussed will put out a v3 with this fixed and a comment to explain the rationale.

Thanks,
Dhananjay

> 
> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
>> +
>> +    if (!policy)
>> +        return -EINVAL;
>> +
>> +    if (policy_data->min == FREQ_QOS_MIN_DEFAULT_VALUE)
>> +        policy_data->min = cpudata->lowest_nonlinear_freq;
>> +
>>       cpufreq_verify_within_cpu_limits(policy_data);
>>       pr_debug("policy_max =%d, policy_min=%d\n", policy_data->max, policy_data->min);
>> +
>> +    cpufreq_cpu_put(policy);
>> +
>>       return 0;
>>   }
>>   @@ -996,7 +1008,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
>>           policy->fast_switch_possible = true;
>>         ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0],
>> -                   FREQ_QOS_MIN, policy->cpuinfo.min_freq);
>> +                   FREQ_QOS_MIN, FREQ_QOS_MIN_DEFAULT_VALUE);
>>       if (ret < 0) {
>>           dev_err(dev, "Failed to add min-freq constraint (%d)\n", ret);
>>           goto free_cpudata1;
> 

  reply	other threads:[~2024-10-17  4:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 14:46 [PATCH v2 0/2] cpufreq/amd-pstate: Set initial min_freq to lowest_nonlinear_freq Dhananjay Ugwekar
2024-10-16 14:46 ` [PATCH v2 1/2] cpufreq/amd-pstate: Remove the redundant verify() function Dhananjay Ugwekar
2024-10-16 14:57   ` Mario Limonciello
2024-10-17  3:47   ` Gautham R. Shenoy
2024-10-16 14:46 ` [PATCH v2 2/2] cpufreq/amd-pstate: Set the initial min_freq to lowest_nonlinear_freq Dhananjay Ugwekar
2024-10-16 14:57   ` Mario Limonciello
2024-10-17  4:32     ` Dhananjay Ugwekar [this message]
2024-10-17  3:56   ` Gautham R. Shenoy
2024-10-17  4:29     ` Dhananjay Ugwekar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db3f2bfd-803b-4725-8e8a-3ca24d4149db@amd.com \
    --to=dhananjay.ugwekar@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    --cc=rafael@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.