logo       

PSCHED_GET_TIME related bug: jiffies wraparound: msg#00083

Subject: PSCHED_GET_TIME related bug: jiffies wraparound
Hello Alexey,

I hope the 0xffffffff change will go into pre9. I've another
potential bug for you ;)
The clock watcher uses this code in psched_tick:
    unsigned long now = jiffies;
    psched_time_base = ((u64)now)<<PSCHED_JSCALE;
    psched_time_mark = now;
    psched_timer.expires = now + 60*60*HZ;
    add_timer(&psched_timer);

psched_time_base is then added to jiffies-psched_time_mark in
PSCHED_GET_TIME.
Because on 32bit archs jiffies wraps after 497 days the psched_time_base
and thus PSCHED_GET_TIME's result will wrap too. And PSCHED_TIME_DIFF
will again return huge negative number.

I'd suggest to replace the second line by this one:

-psched_time_base = ((u64)now)<<PSCHED_JSCALE;
+psched_time_base += ((u64)(now-psched_time_mark))<<PSCHED_JSCALE;

Because now-psched_time_mark is done in unsigned arithmetic it should
be imune against jiffies wraparound.
Do you think that the patch is ok ?

best regards,
devik




<Prev in Thread] Current Thread [Next in Thread>