[PATCH 2/4] target/mips: Don't use clock_get_ns() in clock period calculation

Peter Maydell posted 4 patches 5 years, 2 months ago
Maintainers: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Eduardo Habkost <ehabkost@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>
There is a newer version of this series
[PATCH 2/4] target/mips: Don't use clock_get_ns() in clock period calculation
Posted by Peter Maydell 5 years, 2 months ago
Currently the MIPS code uses the old clock_get_ns() API to
calculate a time length in nanoseconds:
 cpu->cp0_count_rate * clock_get_ns(MIPS_CPU(cpu)->clock)

This relies on the clock having a period which is an exact number
of nanoseconds.

Switch to the new clock_ticks_to_ns() function, which does the
multiplication internally at a higher precision.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/mips/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 76d50b00b42..de15ec6068a 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -147,8 +147,8 @@ static void mips_cp0_period_set(MIPSCPU *cpu)
 {
     CPUMIPSState *env = &cpu->env;
 
-    env->cp0_count_ns = cpu->cp0_count_rate
-                        * clock_get_ns(MIPS_CPU(cpu)->clock);
+    env->cp0_count_ns = clock_ticks_to_ns(MIPS_CPU(cpu)->clock,
+                                          cpu->cp0_count_rate);
     assert(env->cp0_count_ns);
 }
 
-- 
2.20.1


Re: [PATCH 2/4] target/mips: Don't use clock_get_ns() in clock period calculation
Posted by Luc Michel 5 years, 2 months ago
On 12/8/20 7:15 PM, Peter Maydell wrote:
> Currently the MIPS code uses the old clock_get_ns() API to
> calculate a time length in nanoseconds:
>   cpu->cp0_count_rate * clock_get_ns(MIPS_CPU(cpu)->clock)
> 
> This relies on the clock having a period which is an exact number
> of nanoseconds.
> 
> Switch to the new clock_ticks_to_ns() function, which does the
> multiplication internally at a higher precision.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Luc Michel <luc@lmichel.fr>

> ---
>   target/mips/cpu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index 76d50b00b42..de15ec6068a 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -147,8 +147,8 @@ static void mips_cp0_period_set(MIPSCPU *cpu)
>   {
>       CPUMIPSState *env = &cpu->env;
>   
> -    env->cp0_count_ns = cpu->cp0_count_rate
> -                        * clock_get_ns(MIPS_CPU(cpu)->clock);
> +    env->cp0_count_ns = clock_ticks_to_ns(MIPS_CPU(cpu)->clock,
> +                                          cpu->cp0_count_rate);
>       assert(env->cp0_count_ns);
>   }
>   
> 

Re: [PATCH 2/4] target/mips: Don't use clock_get_ns() in clock period calculation
Posted by Richard Henderson 5 years, 2 months ago
On 12/8/20 12:15 PM, Peter Maydell wrote:
> Currently the MIPS code uses the old clock_get_ns() API to
> calculate a time length in nanoseconds:
>  cpu->cp0_count_rate * clock_get_ns(MIPS_CPU(cpu)->clock)
> 
> This relies on the clock having a period which is an exact number
> of nanoseconds.
> 
> Switch to the new clock_ticks_to_ns() function, which does the
> multiplication internally at a higher precision.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target/mips/cpu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~