* [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq
@ 2020-10-14 9:36 Sumit Gupta
2020-10-27 6:16 ` Sumit Gupta
2020-10-28 6:10 ` Viresh Kumar
0 siblings, 2 replies; 5+ messages in thread
From: Sumit Gupta @ 2020-10-14 9:36 UTC (permalink / raw)
To: rjw, viresh.kumar, sudeep.holla, thierry.reding, jonathanh,
linux-pm, linux-tegra, linux-arm-kernel, linux-kernel
Cc: sumitg, bbasu, ksitaraman
Frequency returned by 'cpuinfo_cur_freq' using counters is not fixed
and keeps changing slightly. This change returns a consistent value
from freq_table. If the reconstructed frequency has acceptable delta
from the last written value, then return the frequency corresponding
to the last written ndiv value from freq_table. Otherwise, print a
warning and return the reconstructed freq.
Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
---
Sending only this patch as other patch not required after the change
to convert 'pr_warn' to 'pr_info' in cpufreq core for unlisted freq.
Changelog
v1[2] -> v3:
- Removed unwanted checks for cpu_online and max cluster number
- Used WARN_ON_ONCE to avoid print flooding.
v1[1] -> v2:
- Minor changes to improve comments and reduce debug prints.
- Get freq table from cluster specific data instead of policy.
[2] https://marc.info/?l=linux-tegra&m=160216218511280&w=2
[1] https://marc.info/?l=linux-arm-kernel&m=160028821117535&w=2
drivers/cpufreq/tegra194-cpufreq.c | 62 ++++++++++++++++++++++++++++++++------
1 file changed, 53 insertions(+), 9 deletions(-)
diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c
index e1d931c..7901587 100644
--- a/drivers/cpufreq/tegra194-cpufreq.c
+++ b/drivers/cpufreq/tegra194-cpufreq.c
@@ -180,9 +180,61 @@ static unsigned int tegra194_get_speed_common(u32 cpu, u32 delay)
return (rate_mhz * KHZ); /* in KHz */
}
+static void get_cpu_ndiv(void *ndiv)
+{
+ u64 ndiv_val;
+
+ asm volatile("mrs %0, s3_0_c15_c0_4" : "=r" (ndiv_val) : );
+
+ *(u64 *)ndiv = ndiv_val;
+}
+
+static void set_cpu_ndiv(void *data)
+{
+ struct cpufreq_frequency_table *tbl = data;
+ u64 ndiv_val = (u64)tbl->driver_data;
+
+ asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val));
+}
+
static unsigned int tegra194_get_speed(u32 cpu)
{
- return tegra194_get_speed_common(cpu, US_DELAY);
+ struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
+ struct cpufreq_frequency_table *pos;
+ unsigned int rate;
+ u64 ndiv;
+ int ret;
+ u32 cl;
+
+ smp_call_function_single(cpu, get_cpu_cluster, &cl, true);
+
+ /* reconstruct actual cpu freq using counters */
+ rate = tegra194_get_speed_common(cpu, US_DELAY);
+
+ /* get last written ndiv value */
+ ret = smp_call_function_single(cpu, get_cpu_ndiv, &ndiv, true);
+ if (WARN_ON_ONCE(ret))
+ return rate;
+
+ /*
+ * If the reconstructed frequency has acceptable delta from
+ * the last written value, then return freq corresponding
+ * to the last written ndiv value from freq_table. This is
+ * done to return consistent value.
+ */
+ cpufreq_for_each_valid_entry(pos, data->tables[cl]) {
+ if (pos->driver_data != ndiv)
+ continue;
+
+ if (abs(pos->frequency - rate) > 115200) {
+ pr_warn("cpufreq: cpu%d,cur:%u,set:%u,set ndiv:%llu\n",
+ cpu, rate, pos->frequency, ndiv);
+ } else {
+ rate = pos->frequency;
+ }
+ break;
+ }
+ return rate;
}
static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
@@ -209,14 +261,6 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
return 0;
}
-static void set_cpu_ndiv(void *data)
-{
- struct cpufreq_frequency_table *tbl = data;
- u64 ndiv_val = (u64)tbl->driver_data;
-
- asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val));
-}
-
static int tegra194_cpufreq_set_target(struct cpufreq_policy *policy,
unsigned int index)
{
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq
2020-10-14 9:36 [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq Sumit Gupta
@ 2020-10-27 6:16 ` Sumit Gupta
2020-10-27 6:58 ` Viresh Kumar
2020-10-28 6:10 ` Viresh Kumar
1 sibling, 1 reply; 5+ messages in thread
From: Sumit Gupta @ 2020-10-27 6:16 UTC (permalink / raw)
To: rjw, viresh.kumar, sudeep.holla, thierry.reding, jonathanh,
linux-pm, linux-tegra, linux-arm-kernel, linux-kernel
Cc: bbasu, ksitaraman, Sumit Gupta
Ping.
>
> Frequency returned by 'cpuinfo_cur_freq' using counters is not fixed
> and keeps changing slightly. This change returns a consistent value
> from freq_table. If the reconstructed frequency has acceptable delta
> from the last written value, then return the frequency corresponding
> to the last written ndiv value from freq_table. Otherwise, print a
> warning and return the reconstructed freq.
>
> Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
> ---
>
> Sending only this patch as other patch not required after the change
> to convert 'pr_warn' to 'pr_info' in cpufreq core for unlisted freq.
> Changelog
> v1[2] -> v3:
> - Removed unwanted checks for cpu_online and max cluster number
> - Used WARN_ON_ONCE to avoid print flooding.
>
> v1[1] -> v2:
> - Minor changes to improve comments and reduce debug prints.
> - Get freq table from cluster specific data instead of policy.
>
> [2] https://marc.info/?l=linux-tegra&m=160216218511280&w=2
> [1] https://marc.info/?l=linux-arm-kernel&m=160028821117535&w=2
>
> drivers/cpufreq/tegra194-cpufreq.c | 62 ++++++++++++++++++++++++++++++++------
> 1 file changed, 53 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c
> index e1d931c..7901587 100644
> --- a/drivers/cpufreq/tegra194-cpufreq.c
> +++ b/drivers/cpufreq/tegra194-cpufreq.c
> @@ -180,9 +180,61 @@ static unsigned int tegra194_get_speed_common(u32 cpu, u32 delay)
> return (rate_mhz * KHZ); /* in KHz */
> }
>
> +static void get_cpu_ndiv(void *ndiv)
> +{
> + u64 ndiv_val;
> +
> + asm volatile("mrs %0, s3_0_c15_c0_4" : "=r" (ndiv_val) : );
> +
> + *(u64 *)ndiv = ndiv_val;
> +}
> +
> +static void set_cpu_ndiv(void *data)
> +{
> + struct cpufreq_frequency_table *tbl = data;
> + u64 ndiv_val = (u64)tbl->driver_data;
> +
> + asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val));
> +}
> +
> static unsigned int tegra194_get_speed(u32 cpu)
> {
> - return tegra194_get_speed_common(cpu, US_DELAY);
> + struct tegra194_cpufreq_data *data = cpufreq_get_driver_data();
> + struct cpufreq_frequency_table *pos;
> + unsigned int rate;
> + u64 ndiv;
> + int ret;
> + u32 cl;
> +
> + smp_call_function_single(cpu, get_cpu_cluster, &cl, true);
> +
> + /* reconstruct actual cpu freq using counters */
> + rate = tegra194_get_speed_common(cpu, US_DELAY);
> +
> + /* get last written ndiv value */
> + ret = smp_call_function_single(cpu, get_cpu_ndiv, &ndiv, true);
> + if (WARN_ON_ONCE(ret))
> + return rate;
> +
> + /*
> + * If the reconstructed frequency has acceptable delta from
> + * the last written value, then return freq corresponding
> + * to the last written ndiv value from freq_table. This is
> + * done to return consistent value.
> + */
> + cpufreq_for_each_valid_entry(pos, data->tables[cl]) {
> + if (pos->driver_data != ndiv)
> + continue;
> +
> + if (abs(pos->frequency - rate) > 115200) {
> + pr_warn("cpufreq: cpu%d,cur:%u,set:%u,set ndiv:%llu\n",
> + cpu, rate, pos->frequency, ndiv);
> + } else {
> + rate = pos->frequency;
> + }
> + break;
> + }
> + return rate;
> }
>
> static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
> @@ -209,14 +261,6 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy)
> return 0;
> }
>
> -static void set_cpu_ndiv(void *data)
> -{
> - struct cpufreq_frequency_table *tbl = data;
> - u64 ndiv_val = (u64)tbl->driver_data;
> -
> - asm volatile("msr s3_0_c15_c0_4, %0" : : "r" (ndiv_val));
> -}
> -
> static int tegra194_cpufreq_set_target(struct cpufreq_policy *policy,
> unsigned int index)
> {
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq
2020-10-27 6:16 ` Sumit Gupta
@ 2020-10-27 6:58 ` Viresh Kumar
2020-10-27 7:05 ` Sumit Gupta
0 siblings, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2020-10-27 6:58 UTC (permalink / raw)
To: Sumit Gupta
Cc: rjw, sudeep.holla, thierry.reding, jonathanh, linux-pm,
linux-tegra, linux-arm-kernel, linux-kernel, bbasu, ksitaraman
On 27-10-20, 11:46, Sumit Gupta wrote:
> Ping.
I was waiting for 5.10-rc1 to be released before I can start applying stuff for
5.11. Now that it is released, I will apply this.
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq
2020-10-27 6:58 ` Viresh Kumar
@ 2020-10-27 7:05 ` Sumit Gupta
0 siblings, 0 replies; 5+ messages in thread
From: Sumit Gupta @ 2020-10-27 7:05 UTC (permalink / raw)
To: Viresh Kumar
Cc: rjw, sudeep.holla, thierry.reding, jonathanh, linux-pm,
linux-tegra, linux-arm-kernel, linux-kernel, bbasu, ksitaraman,
Sumit Gupta
Thank you.
On 27/10/20 12:28 PM, Viresh Kumar wrote:
> External email: Use caution opening links or attachments
>
>
> On 27-10-20, 11:46, Sumit Gupta wrote:
>> Ping.
>
> I was waiting for 5.10-rc1 to be released before I can start applying stuff for
> 5.11. Now that it is released, I will apply this.
>
> --
> viresh
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq
2020-10-14 9:36 [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq Sumit Gupta
2020-10-27 6:16 ` Sumit Gupta
@ 2020-10-28 6:10 ` Viresh Kumar
1 sibling, 0 replies; 5+ messages in thread
From: Viresh Kumar @ 2020-10-28 6:10 UTC (permalink / raw)
To: Sumit Gupta
Cc: rjw, sudeep.holla, thierry.reding, jonathanh, linux-pm,
linux-tegra, linux-arm-kernel, linux-kernel, bbasu, ksitaraman
On 14-10-20, 15:06, Sumit Gupta wrote:
> Frequency returned by 'cpuinfo_cur_freq' using counters is not fixed
> and keeps changing slightly. This change returns a consistent value
> from freq_table. If the reconstructed frequency has acceptable delta
> from the last written value, then return the frequency corresponding
> to the last written ndiv value from freq_table. Otherwise, print a
> warning and return the reconstructed freq.
>
> Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
> ---
>
> Sending only this patch as other patch not required after the change
> to convert 'pr_warn' to 'pr_info' in cpufreq core for unlisted freq.
> Changelog
> v1[2] -> v3:
> - Removed unwanted checks for cpu_online and max cluster number
> - Used WARN_ON_ONCE to avoid print flooding.
>
> v1[1] -> v2:
> - Minor changes to improve comments and reduce debug prints.
> - Get freq table from cluster specific data instead of policy.
>
> [2] https://marc.info/?l=linux-tegra&m=160216218511280&w=2
> [1] https://marc.info/?l=linux-arm-kernel&m=160028821117535&w=2
>
> drivers/cpufreq/tegra194-cpufreq.c | 62 ++++++++++++++++++++++++++++++++------
> 1 file changed, 53 insertions(+), 9 deletions(-)
Applied. Thanks.
--
viresh
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-28 22:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 9:36 [PATCH v3] cpufreq: tegra194: get consistent cpuinfo_cur_freq Sumit Gupta
2020-10-27 6:16 ` Sumit Gupta
2020-10-27 6:58 ` Viresh Kumar
2020-10-27 7:05 ` Sumit Gupta
2020-10-28 6:10 ` Viresh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).