Re: infinite loop in read_hpet from ktime_get_boot_fast_ns

From: Jason A. Donenfeld
Date: Wed Jun 12 2019 - 09:03:14 EST


Hi Peter,

Thanks for the explanation.

On Wed, Jun 12, 2019 at 2:29 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> Either local_clock() or cpu_clock(cpu). The sleep hooks are not
> something the consumer has to worry about.

Alright. Just so long as it *is* tracking sleep, then that's fine. If
it isn't some important aspects of the protocol will be violated.

> If an architecture doesn't provide a sched_clock(), you're on a
> seriously handicapped arch. It wraps in ~500 days, and aside from
> changing jiffies_lock to a latch, I don't think we can do much about it.

Are you sure? The base definition I'm looking at uses jiffies:

unsigned long long __weak sched_clock(void)
{
return (unsigned long long)(jiffies - INITIAL_JIFFIES)
* (NSEC_PER_SEC / HZ);
}

On a CONFIG_HZ_1000 machine, jiffies wraps in ~49.7 days:
>>> ((1<<32)-1)/1000/(60*60*24)
49.710269618055555

Why not just use get_jiffies_64()? The lock is too costly on 32bit?

> (the scheduler too expects sched_clock() to not wrap short of the u64
> and so having those machines online for 500 days will get you 'funny'
> results)

Ahh. So if, on the other hand, the whole machine explodes at the wrap
mark, I guess my silly protocol is the least of concerns, and so this
shouldn't matter?

Jason