From: Huang Rui <ray.huang@amd.com>
To: "Yuan, Perry" <Perry.Yuan@amd.com>
Cc: "rafael.j.wysocki@intel.com" <rafael.j.wysocki@intel.com>,
"Limonciello, Mario" <Mario.Limonciello@amd.com>,
"viresh.kumar@linaro.org" <viresh.kumar@linaro.org>,
"Shenoy, Gautham Ranjal" <gautham.shenoy@amd.com>,
"Petkov, Borislav" <Borislav.Petkov@amd.com>,
"Deucher, Alexander" <Alexander.Deucher@amd.com>,
"Huang, Shimmer" <Shimmer.Huang@amd.com>,
"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
"Du, Xiaojian" <Xiaojian.Du@amd.com>,
"Meng, Li (Jassmine)" <Li.Meng@amd.com>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v10 3/8] cpufreq: amd-pstate: Unify computation of {max,min,nominal,lowest_nonlinear}_freq
Date: Mon, 15 Apr 2024 22:54:31 +0800 [thread overview]
Message-ID: <Zh0/p4tzcqxQvnm7@amd.com> (raw)
In-Reply-To: <31e4c97f791837c97c0b2caca61bcdfeabc3f97f.1711335714.git.perry.yuan@amd.com>
On Mon, Mar 25, 2024 at 11:03:23AM +0800, Yuan, Perry wrote:
> Currently the amd_get_{min, max, nominal, lowest_nonlinear}_freq()
> helpers computes the values of min_freq, max_freq, nominal_freq and
> lowest_nominal_freq respectively afresh from
> cppc_get_perf_caps(). This is not necessary as there are fields in
> cpudata to cache these values.
>
> To simplify this, add a single helper function named
> amd_pstate_init_freq() which computes all these frequencies at once, and
> caches it in cpudata.
>
> Use the cached values everywhere else in the code.
>
> Reviewed-by: Li Meng <li.meng@amd.com>
> Tested-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com>
> Co-developed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Perry Yuan <perry.yuan@amd.com>
I am thinking patch 3 and 4 should be squeezed together, because they are
all refining frequencies in cpudata. But I am fine if you want to continue
keep them separately.
> ---
> drivers/cpufreq/amd-pstate.c | 126 ++++++++++++++++-------------------
> 1 file changed, 59 insertions(+), 67 deletions(-)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 2015c9fcc3c9..ba1baa6733e6 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -606,74 +606,22 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
>
> static int amd_get_min_freq(struct amd_cpudata *cpudata)
> {
> - struct cppc_perf_caps cppc_perf;
> -
> - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> - if (ret)
> - return ret;
> -
> - /* Switch to khz */
> - return cppc_perf.lowest_freq * 1000;
> + return READ_ONCE(cpudata->min_freq);
> }
>
> static int amd_get_max_freq(struct amd_cpudata *cpudata)
> {
> - struct cppc_perf_caps cppc_perf;
> - u32 max_perf, max_freq, nominal_freq, nominal_perf;
> - u64 boost_ratio;
> -
> - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> - if (ret)
> - return ret;
> -
> - nominal_freq = cppc_perf.nominal_freq;
> - nominal_perf = READ_ONCE(cpudata->nominal_perf);
> - max_perf = READ_ONCE(cpudata->highest_perf);
> -
> - boost_ratio = div_u64(max_perf << SCHED_CAPACITY_SHIFT,
> - nominal_perf);
> -
> - max_freq = nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT;
> -
> - /* Switch to khz */
> - return max_freq * 1000;
> + return READ_ONCE(cpudata->max_freq);
> }
>
> static int amd_get_nominal_freq(struct amd_cpudata *cpudata)
> {
> - struct cppc_perf_caps cppc_perf;
> -
> - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> - if (ret)
> - return ret;
> -
> - /* Switch to khz */
> - return cppc_perf.nominal_freq * 1000;
> + return READ_ONCE(cpudata->nominal_freq);
> }
>
> static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
> {
> - struct cppc_perf_caps cppc_perf;
> - u32 lowest_nonlinear_freq, lowest_nonlinear_perf,
> - nominal_freq, nominal_perf;
> - u64 lowest_nonlinear_ratio;
> -
> - int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> - if (ret)
> - return ret;
> -
> - nominal_freq = cppc_perf.nominal_freq;
> - nominal_perf = READ_ONCE(cpudata->nominal_perf);
> -
> - lowest_nonlinear_perf = cppc_perf.lowest_nonlinear_perf;
> -
> - lowest_nonlinear_ratio = div_u64(lowest_nonlinear_perf << SCHED_CAPACITY_SHIFT,
> - nominal_perf);
> -
> - lowest_nonlinear_freq = nominal_freq * lowest_nonlinear_ratio >> SCHED_CAPACITY_SHIFT;
> -
> - /* Switch to khz */
> - return lowest_nonlinear_freq * 1000;
> + return READ_ONCE(cpudata->lowest_nonlinear_freq);
> }
>
> static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
> @@ -828,6 +776,53 @@ static void amd_pstate_update_limits(unsigned int cpu)
> mutex_unlock(&amd_pstate_driver_lock);
> }
>
> +/**
> + * amd_pstate_init_freq: Initialize the max_freq, min_freq,
> + * nominal_freq and lowest_nonlinear_freq for
> + * the @cpudata object.
> + *
> + * Requires: highest_perf, lowest_perf, nominal_perf and
> + * lowest_nonlinear_perf members of @cpudata to be
> + * initialized.
> + *
> + * Returns 0 on success, non-zero value on failure.
> + */
> +static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
> +{
> + int ret;
> + u32 min_freq;
> + u32 highest_perf, max_freq;
> + u32 nominal_perf, nominal_freq;
> + u32 lowest_nonlinear_perf, lowest_nonlinear_freq;
> + u32 boost_ratio, lowest_nonlinear_ratio;
> + struct cppc_perf_caps cppc_perf;
> +
> +
> + ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
> + if (ret)
> + return ret;
> +
> + min_freq = cppc_perf.lowest_freq * 1000;
> + nominal_freq = cppc_perf.nominal_freq * 1000;
> + nominal_perf = READ_ONCE(cpudata->nominal_perf);
> +
> + highest_perf = READ_ONCE(cpudata->highest_perf);
> + boost_ratio = div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
> + max_freq = nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT;
> +
> + lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
> + lowest_nonlinear_ratio = div_u64(lowest_nonlinear_perf << SCHED_CAPACITY_SHIFT,
> + nominal_perf);
> + lowest_nonlinear_freq = nominal_freq * lowest_nonlinear_ratio >> SCHED_CAPACITY_SHIFT;
> +
> + WRITE_ONCE(cpudata->min_freq, min_freq);
> + WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
> + WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
> + WRITE_ONCE(cpudata->max_freq, max_freq);
> +
> + return 0;
> +}
> +
> static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
> {
> int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
> @@ -855,6 +850,10 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
> if (ret)
> goto free_cpudata1;
>
> + ret = amd_pstate_init_freq(cpudata);
> + if (ret)
> + goto free_cpudata1;
> +
> min_freq = amd_get_min_freq(cpudata);
> max_freq = amd_get_max_freq(cpudata);
> nominal_freq = amd_get_nominal_freq(cpudata);
> @@ -896,13 +895,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
> goto free_cpudata2;
> }
>
> - /* Initial processor data capability frequencies */
> - cpudata->max_freq = max_freq;
> - cpudata->min_freq = min_freq;
> cpudata->max_limit_freq = max_freq;
> cpudata->min_limit_freq = min_freq;
> - cpudata->nominal_freq = nominal_freq;
> - cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq;
>
> policy->driver_data = cpudata;
>
> @@ -1317,6 +1311,10 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> if (ret)
> goto free_cpudata1;
>
> + ret = amd_pstate_init_freq(cpudata);
> + if (ret)
> + goto free_cpudata1;
> +
> min_freq = amd_get_min_freq(cpudata);
> max_freq = amd_get_max_freq(cpudata);
> nominal_freq = amd_get_nominal_freq(cpudata);
> @@ -1333,12 +1331,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
> /* It will be updated by governor */
> policy->cur = policy->cpuinfo.min_freq;
>
> - /* Initial processor data capability frequencies */
> - cpudata->max_freq = max_freq;
> - cpudata->min_freq = min_freq;
> - cpudata->nominal_freq = nominal_freq;
> - cpudata->lowest_nonlinear_freq = lowest_nonlinear_freq;
> -
> policy->driver_data = cpudata;
>
> cpudata->epp_cached = amd_pstate_get_epp(cpudata, 0);
> --
> 2.34.1
>
next prev parent reply other threads:[~2024-04-15 14:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-25 3:03 [PATCH v10 0/8] AMD Pstate Fixes And Enhancements Perry Yuan
2024-03-25 3:03 ` [PATCH v10 1/8] cpufreq: amd-pstate: Document *_limit_* fields in struct amd_cpudata Perry Yuan
2024-04-15 1:37 ` Huang Rui
2024-04-18 9:17 ` Yuan, Perry
2024-03-25 3:03 ` [PATCH v10 2/8] cpufreq: amd-pstate: Document the units for freq variables in amd_cpudata Perry Yuan
2024-04-15 1:38 ` Huang Rui
2024-03-25 3:03 ` [PATCH v10 3/8] cpufreq: amd-pstate: Unify computation of {max,min,nominal,lowest_nonlinear}_freq Perry Yuan
2024-04-15 14:54 ` Huang Rui [this message]
2024-04-18 9:15 ` Yuan, Perry
2024-03-25 3:03 ` [PATCH v10 4/8] cpufreq: amd-pstate: Remove amd_get_{min,max,nominal,lowest_nonlinear}_freq() Perry Yuan
2024-04-15 14:56 ` Huang Rui
2024-03-25 3:03 ` [PATCH v10 5/8] cpufreq: amd-pstate: Bail out if min/max/nominal_freq is 0 Perry Yuan
2024-04-15 14:59 ` Huang Rui
2024-04-18 9:12 ` Yuan, Perry
2024-03-25 3:03 ` [PATCH v10 6/8] cpufreq: amd-pstate: get transition delay and latency value from ACPI tables Perry Yuan
2024-04-15 15:01 ` Huang Rui
2024-03-25 3:03 ` [PATCH v10 7/8] cppc_acpi: print error message if CPPC is unsupported Perry Yuan
2024-04-15 15:04 ` Huang Rui
2024-03-25 3:03 ` [PATCH v10 8/8] cpufreq: amd-pstate: Add quirk for the pstate CPPC capabilities missing Perry Yuan
2024-04-15 15:16 ` Huang Rui
2024-04-22 9:50 ` Yuan, Perry
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=Zh0/p4tzcqxQvnm7@amd.com \
--to=ray.huang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Borislav.Petkov@amd.com \
--cc=Li.Meng@amd.com \
--cc=Mario.Limonciello@amd.com \
--cc=Perry.Yuan@amd.com \
--cc=Shimmer.Huang@amd.com \
--cc=Xiaojian.Du@amd.com \
--cc=gautham.shenoy@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=oleksandr@natalenko.name \
--cc=rafael.j.wysocki@intel.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox