On 27/11/2015 09:12, Roman Kagan wrote:
>> > +  n = div64_u64(time_now - stimer->exp_time, stimer->count) + 1;
>> > +  stimer->exp_time += n * stimer->count;
> This is actually just a reminder calculation so I'd rather do it
> directly with div64_u64_rem().

It took me a while to understand why it was a remained. :)  Expanding
Andrey's formula you get

        exp_time = exp_time + count + (time_now - exp_time) / count * count

the remainder, (time_now - exp_time) % count would be

        time_now - exp_time - (time_now - exp_time) / count * count

so -((time_now - exp_time) % count) is

        exp_time - time_now + (time_now - exp_time) / count * count

so Andrey's expression is

        exp_time = time_now + (count - (time_now - exp_time) % count)

Yeah, that looks nice.

Paolo

Reply via email to