Hi Phil,

On 18:20 Thu 20 Nov     , Philippe Mathieu-Daudé wrote:
> On 7/11/25 11:23, Luc Michel wrote:
> > Add the register_time_change_notifier method to the RISCVCPUTimeSrcIf
> > interface. This method allows the time source user to register a
> > notifier on tick counter asynchronous modification (i.e., a modification
> > that is not due to the monotonic nature of the counter). This can happen
> > if the time source counter is writable, which is the case of the `time'
> > register of the ACLINT.
> > 
> > Use this mechanism in time_helper.c to recompute the sstc timers
> > deadlines.
> > 
> > Signed-off-by: Luc Michel <[email protected]>
> > ---
> >   target/riscv/cpu-qom.h     |  7 +++++++
> >   target/riscv/cpu.h         |  1 +
> >   target/riscv/time_helper.h | 11 +++++++++++
> >   target/riscv/time_helper.c | 13 +++++++++++++
> >   4 files changed, 32 insertions(+)
> 
> 
> > diff --git a/target/riscv/time_helper.h b/target/riscv/time_helper.h
> > index b51fdd96570..074b516f4ad 100644
> > --- a/target/riscv/time_helper.h
> > +++ b/target/riscv/time_helper.h
> > @@ -42,6 +42,17 @@ static inline uint32_t 
> > riscv_cpu_time_src_get_tick_freq(RISCVCPUTimeSrcIf *src)
> > 
> >       g_assert(rctsc->get_tick_freq != NULL);
> >       return rctsc->get_tick_freq(src);
> >   }
> > 
> > +static inline void
> > +riscv_cpu_time_src_register_time_change_notifier(RISCVCPUTimeSrcIf *src,
> > +                                                 Notifier *notifier)
> > +{
> > +    RISCVCPUTimeSrcIfClass *rctsc = RISCV_CPU_TIME_SRC_IF_GET_CLASS(src);
> > +
> > +    if (rctsc->register_time_change_notifier) {
> > +        rctsc->register_time_change_notifier(src, notifier);
> > +    }
> 
> What about some trace event to help developers? I.e.:

I made this method optional in case the time source is read-only. In
this case there is no need for a notifier as it cannot change
asynchronously.

-- 
Luc

> 
>    if (!rctsc->register_time_change_notifier) {
>        trace_riscv_cpu_time_src_register_time_change_without_notifier();
>        return;
>    }
>    rctsc->register_time_change_notifier(src, notifier);
> 
> > +}
> 
> Anyhow:
> Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
> 

-- 

Reply via email to