2014-04-02 19:04:00

by Aaro Koskinen

[permalink] [raw]
Subject: [PATCH] MIPS/loongson2_cpufreq: fix CPU clock rate setting

Loongson2 has been using (incorrectly) kHz for cpu_clk rate. This has
been unnoticed, as loongson2_cpufreq was the only place where the rate
was set/get. After commit 652ed95d5fa6074b3c4ea245deb0691f1acb6656
(cpufreq: introduce cpufreq_generic_get() routine) things however broke,
and now loops_per_jiffy adjustments are incorrect (1000 times too long).
The patch fixes this by changing cpu_clk rate to Hz.

Signed-off-by: Aaro Koskinen <[email protected]>
Cc: [email protected]
---
arch/mips/loongson/lemote-2f/clock.c | 7 +++++--
drivers/cpufreq/loongson2_cpufreq.c | 4 ++--
2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/mips/loongson/lemote-2f/clock.c b/arch/mips/loongson/lemote-2f/clock.c
index aed32b8..699f388 100644
--- a/arch/mips/loongson/lemote-2f/clock.c
+++ b/arch/mips/loongson/lemote-2f/clock.c
@@ -91,6 +91,7 @@ EXPORT_SYMBOL(clk_put);

int clk_set_rate(struct clk *clk, unsigned long rate)
{
+ unsigned int rate_khz;
int ret = 0;
int regval;
int i;
@@ -106,15 +107,17 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
propagate_rate(clk);

+ rate_khz = rate / 1000;
+
for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END;
i++) {
if (loongson2_clockmod_table[i].frequency ==
CPUFREQ_ENTRY_INVALID)
continue;
- if (rate == loongson2_clockmod_table[i].frequency)
+ if (rate_khz == loongson2_clockmod_table[i].frequency)
break;
}
- if (rate != loongson2_clockmod_table[i].frequency)
+ if (rate_khz != loongson2_clockmod_table[i].frequency)
return -ENOTSUPP;

clk->rate = rate;
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index b6581ab..807d006 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -62,7 +62,7 @@ static int loongson2_cpufreq_target(struct cpufreq_policy *policy,
set_cpus_allowed_ptr(current, &cpus_allowed);

/* setting the cpu frequency */
- clk_set_rate(policy->clk, freq);
+ clk_set_rate(policy->clk, freq * 1000);

return 0;
}
@@ -92,7 +92,7 @@ static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
i++)
loongson2_clockmod_table[i].frequency = (rate * i) / 8;

- ret = clk_set_rate(cpuclk, rate);
+ ret = clk_set_rate(cpuclk, rate * 1000);
if (ret) {
clk_put(cpuclk);
return ret;
--
1.9.0


2014-04-03 04:21:45

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH] MIPS/loongson2_cpufreq: fix CPU clock rate setting

On 3 April 2014 00:37, Aaro Koskinen <[email protected]> wrote:
> Loongson2 has been using (incorrectly) kHz for cpu_clk rate. This has
> been unnoticed, as loongson2_cpufreq was the only place where the rate
> was set/get. After commit 652ed95d5fa6074b3c4ea245deb0691f1acb6656
> (cpufreq: introduce cpufreq_generic_get() routine) things however broke,
> and now loops_per_jiffy adjustments are incorrect (1000 times too long).
> The patch fixes this by changing cpu_clk rate to Hz.
>
> Signed-off-by: Aaro Koskinen <[email protected]>
> Cc: [email protected]
> ---
> arch/mips/loongson/lemote-2f/clock.c | 7 +++++--
> drivers/cpufreq/loongson2_cpufreq.c | 4 ++--
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/arch/mips/loongson/lemote-2f/clock.c b/arch/mips/loongson/lemote-2f/clock.c
> index aed32b8..699f388 100644
> --- a/arch/mips/loongson/lemote-2f/clock.c
> +++ b/arch/mips/loongson/lemote-2f/clock.c
> @@ -91,6 +91,7 @@ EXPORT_SYMBOL(clk_put);
>
> int clk_set_rate(struct clk *clk, unsigned long rate)
> {
> + unsigned int rate_khz;

Initialize rate_khz here only instead of doing it separately..

> int ret = 0;
> int regval;
> int i;
> @@ -106,15 +107,17 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
> if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
> propagate_rate(clk);
>
> + rate_khz = rate / 1000;
> +

>From here:

> for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END;
> i++) {
> if (loongson2_clockmod_table[i].frequency ==
> CPUFREQ_ENTRY_INVALID)
> continue;
> - if (rate == loongson2_clockmod_table[i].frequency)
> + if (rate_khz == loongson2_clockmod_table[i].frequency)
> break;
> }
> - if (rate != loongson2_clockmod_table[i].frequency)
> + if (rate_khz != loongson2_clockmod_table[i].frequency)
> return -ENOTSUPP;

To here:

All this code is junk and not required anymore as rate is guaranteed
to be in loongson2_clockmod_table[].. Probably you need value of
'i' here and you can pass that directly from loongson2_cpufreq_target().

2014-04-03 18:35:12

by Aaro Koskinen

[permalink] [raw]
Subject: Re: [PATCH] MIPS/loongson2_cpufreq: fix CPU clock rate setting

Hi,

On Thu, Apr 03, 2014 at 09:51:41AM +0530, Viresh Kumar wrote:
> On 3 April 2014 00:37, Aaro Koskinen <[email protected]> wrote:
> > Loongson2 has been using (incorrectly) kHz for cpu_clk rate. This has
> > been unnoticed, as loongson2_cpufreq was the only place where the rate
> > was set/get. After commit 652ed95d5fa6074b3c4ea245deb0691f1acb6656
> > (cpufreq: introduce cpufreq_generic_get() routine) things however broke,
> > and now loops_per_jiffy adjustments are incorrect (1000 times too long).
> > The patch fixes this by changing cpu_clk rate to Hz.
> >
> > Signed-off-by: Aaro Koskinen <[email protected]>
> > Cc: [email protected]
> > ---
> > arch/mips/loongson/lemote-2f/clock.c | 7 +++++--
> > drivers/cpufreq/loongson2_cpufreq.c | 4 ++--
> > 2 files changed, 7 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/mips/loongson/lemote-2f/clock.c b/arch/mips/loongson/lemote-2f/clock.c
> > index aed32b8..699f388 100644
> > --- a/arch/mips/loongson/lemote-2f/clock.c
> > +++ b/arch/mips/loongson/lemote-2f/clock.c
> > @@ -91,6 +91,7 @@ EXPORT_SYMBOL(clk_put);
> >
> > int clk_set_rate(struct clk *clk, unsigned long rate)
> > {
> > + unsigned int rate_khz;
>
> Initialize rate_khz here only instead of doing it separately..

Ok.

> From here:
>
> > for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END;
> > i++) {
> > if (loongson2_clockmod_table[i].frequency ==
> > CPUFREQ_ENTRY_INVALID)
> > continue;
> > - if (rate == loongson2_clockmod_table[i].frequency)
> > + if (rate_khz == loongson2_clockmod_table[i].frequency)
> > break;
> > }
> > - if (rate != loongson2_clockmod_table[i].frequency)
> > + if (rate_khz != loongson2_clockmod_table[i].frequency)
> > return -ENOTSUPP;
>
> To here:
>
> All this code is junk and not required anymore as rate is guaranteed
> to be in loongson2_clockmod_table[].. Probably you need value of
> 'i' here and you can pass that directly from loongson2_cpufreq_target().

But then we couldn't use clk_set_rate()? Anyway I think that should
be done with separate patch(es), which probably would not qualify
for 3.14-stable or 3.15-rc.

A.