[PATCH v2 06/11] hw/openrisc: Initialize timer time at startup

Stafford Horne posted 11 patches 3 years, 7 months ago
Maintainers: Stafford Horne <shorne@gmail.com>, Jia Liu <proljc@gmail.com>, Anup Patel <anup.patel@wdc.com>, Alistair Francis <Alistair.Francis@wdc.com>
There is a newer version of this series
[PATCH v2 06/11] hw/openrisc: Initialize timer time at startup
Posted by Stafford Horne 3 years, 7 months ago
The last_clk time was initialized at zero, this means when we calculate
the first delta we will calculate 0 vs current time which could cause
unnecessary hops.

Initialize last_clk to the qemu clock on initialization.

Signed-off-by: Stafford Horne <shorne@gmail.com>
---
 hw/openrisc/cputimer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/openrisc/cputimer.c b/hw/openrisc/cputimer.c
index 93268815d8..4dbba3a3d4 100644
--- a/hw/openrisc/cputimer.c
+++ b/hw/openrisc/cputimer.c
@@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)
 
     if (or1k_timer == NULL) {
         or1k_timer = g_new0(OR1KTimerState, 1);
+        or1k_timer->last_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
         vmstate_register(NULL, 0, &vmstate_or1k_timer, or1k_timer);
     }
 }
-- 
2.36.1
Re: [PATCH v2 06/11] hw/openrisc: Initialize timer time at startup
Posted by Richard Henderson 3 years, 7 months ago
On 7/4/22 02:58, Stafford Horne wrote:
> The last_clk time was initialized at zero, this means when we calculate
> the first delta we will calculate 0 vs current time which could cause
> unnecessary hops.
> 
> Initialize last_clk to the qemu clock on initialization.
> 
> Signed-off-by: Stafford Horne <shorne@gmail.com>
> ---
>   hw/openrisc/cputimer.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/openrisc/cputimer.c b/hw/openrisc/cputimer.c
> index 93268815d8..4dbba3a3d4 100644
> --- a/hw/openrisc/cputimer.c
> +++ b/hw/openrisc/cputimer.c
> @@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)
>   
>       if (or1k_timer == NULL) {
>           or1k_timer = g_new0(OR1KTimerState, 1);
> +        or1k_timer->last_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>           vmstate_register(NULL, 0, &vmstate_or1k_timer, or1k_timer);
>       }
>   }

Init doesn't seem right.  Should be in reset?


r~
Re: [PATCH v2 06/11] hw/openrisc: Initialize timer time at startupi
Posted by Stafford Horne 3 years, 7 months ago
On Mon, Jul 04, 2022 at 03:33:26PM +0530, Richard Henderson wrote:
> On 7/4/22 02:58, Stafford Horne wrote:
> > The last_clk time was initialized at zero, this means when we calculate
> > the first delta we will calculate 0 vs current time which could cause
> > unnecessary hops.
> > 
> > Initialize last_clk to the qemu clock on initialization.
> > 
> > Signed-off-by: Stafford Horne <shorne@gmail.com>
> > ---
> >   hw/openrisc/cputimer.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/hw/openrisc/cputimer.c b/hw/openrisc/cputimer.c
> > index 93268815d8..4dbba3a3d4 100644
> > --- a/hw/openrisc/cputimer.c
> > +++ b/hw/openrisc/cputimer.c
> > @@ -140,6 +140,7 @@ void cpu_openrisc_clock_init(OpenRISCCPU *cpu)
> >       if (or1k_timer == NULL) {
> >           or1k_timer = g_new0(OR1KTimerState, 1);
> > +        or1k_timer->last_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> >           vmstate_register(NULL, 0, &vmstate_or1k_timer, or1k_timer);
> >       }
> >   }
> 
> Init doesn't seem right.  Should be in reset?

Good point, I think reset would be better.