static int64_t __init init_hpet(struct platform_timesource *pts)
{
uint64_t hpet_rate, start;
- uint32_t count, target;
+ uint32_t count, target, elapsed;
if ( hpet_address && strcmp(opt_clocksource, pts->id) &&
cpuidle_using_deep_cstate() )
count = hpet_read32(HPET_COUNTER);
start = rdtsc_ordered();
- target = count + CALIBRATE_VALUE(hpet_rate);
- if ( target < count )
- while ( hpet_read32(HPET_COUNTER) >= count )
- continue;
- while ( hpet_read32(HPET_COUNTER) < target )
+ target = CALIBRATE_VALUE(hpet_rate);
+ while ( (elapsed = hpet_read32(HPET_COUNTER) - count) < target )
continue;
return (rdtsc_ordered() - start) * CALIBRATE_FRAC;
static s64 __init init_pmtimer(struct platform_timesource *pts)
{
- u64 start;
- u32 count, target, mask;
+ uint64_t start;
+ uint32_t count, target, mask, elapsed;
if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
return 0;
pts->counter_bits = pmtmr_width;
mask = 0xffffffff >> (32 - pmtmr_width);
- count = inl(pmtmr_ioport) & mask;
+ count = inl(pmtmr_ioport);
start = rdtsc_ordered();
- target = count + CALIBRATE_VALUE(ACPI_PM_FREQUENCY);
- if ( target < count )
- while ( (inl(pmtmr_ioport) & mask) >= count )
- continue;
- while ( (inl(pmtmr_ioport) & mask) < target )
+ target = CALIBRATE_VALUE(ACPI_PM_FREQUENCY);
+ while ( (elapsed = (inl(pmtmr_ioport) - count) & mask) < target )
continue;
return (rdtsc_ordered() - start) * CALIBRATE_FRAC;