[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 2/4 gnumach] Add HPET timer for small accurate delays
From: |
Samuel Thibault |
Subject: |
Re: [PATCH v2 2/4 gnumach] Add HPET timer for small accurate delays |
Date: |
Tue, 6 Feb 2024 21:52:42 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Damien Zammit, le mar. 06 févr. 2024 03:06:20 +0000, a ecrit:
> + us = (us * NSEC_PER_USEC) / hpet_period_nsec;
> +
> + start = HPET32(HPET_COUNTER);
> +
> + while (1) {
> + now = HPET32(HPET_COUNTER);
> +
> + if (now < start) {
> + /* handle timer overflow within 32 bits */
You don't need to do anything fancy. Even when now < start, thanks to
unsigned 32bit wrap-around, now - start will still be correct. In this:
> + if ((0xffffffff - start) + now + 1 > us)
> + break;
The 0xffffffff + 1 piece just wraps-around.
So *all* you need really is
> + if (now - start > us)
> + break;
Samuel