Re: [PATCH 6/7] lib/random32.c: Randomize timeout to the millisecond, not the second

Daniel Borkmann
2014-06-08T12:28:24Z

On 06/08/2014 01:30 PM, George Spelvin wrote:
>> Fine by me this cleanup, although not strictly needed.
>
> Agreed. The timer slack is set to HZ (1 second) anyway.
>
> It just dawned on me that a simpler and more efficient way to do this
> (which I'll do in v2 of this) would be:

Note, when you talk about efficiency here, this is called once every
40+ secs ... ;)

> /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
> - expires = 40 + (prandom_u32() % 40);
> - seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
> + expires = 40*HZ + prandom_u32_max(40*HZ);
> + seed_timer.expires = jiffies + expires;
>
> That avoids calling msecs_to_jiffies entirely.
>