Hello,

Almost there!

Samuel

Zhaoming Luo, le dim. 23 mars 2025 18:13:55 +0800, a ecrit:
> +uint32_t
> +hpclock_get_counter_period_nsec(void)
> +{
> +    if (hpet_addr != NULL)
> +     return hpet_period_nsec;
> +    else
> +     return 0;

When hpet_addr is NULL, hpet_period_nsec will already be still 0, so you
can just always return it.

> diff --git a/kern/mach_clock.c b/kern/mach_clock.c
> index 5501b7b8..9bae3439 100644
> --- a/kern/mach_clock.c
> +++ b/kern/mach_clock.c

> @@ -426,6 +438,28 @@ clock_boottime_update(const struct time_value64 
> *new_time)
>       time_value64_add(&clock_boottime_offset, &delta);
>  }
>  
> +/*
> + * Add the time value since last clock interrupt in nanosecond.
> + */
> +static void
> +time_value64_add_hpc(time_value64_t *value)
> +{
> +     uint32_t now = hpclock_read_counter();
> +     /* Time since last clock interrupt in nanosecond.  */
> +     int64_t ns = (now - last_hpc_read) * hpclock_get_counter_period_nsec();
> +
> +     /* Limit the value of ns under the period of a clock interrupt in case
> +        imprecise computation causes ns greater than the clock interrupt
> +        period.  */
> +     if (ns > tick * 1000)

You want >= here.

Otherwise, if for whatever reason ns gets to tick * 1000 at some point,
your return it, and then if ns gets to > tick * 1000 before the clock
interrupt, you return tick * 1000 - 1, i.e. back in time.

> +         /* Let ns stuck at the end of the clock interrupt period when
> +            something bad happens.  */
> +         ns = (tick * 1000) - 1;


> +     time_value64_add_nanos(value, ns);
> +}
> +
> +
>  /*
>   * Record a timestamp in STAMP.  Records values in the boot-time clock
>   * frame.

Reply via email to