From: Stephen Hemminger <stephen@networkplumber.org>
To: Daniel Borkmann <dborkman@redhat.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
Hannes Frederic Sowa <hannes@stressinduktion.org>
Subject: Re: [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer
Date: Tue, 12 Nov 2013 15:35:12 -0800 [thread overview]
Message-ID: <20131112153512.68520cca@samsung-9> (raw)
In-Reply-To: <1384296342-3348-2-git-send-email-dborkman@redhat.com>
On Tue, 12 Nov 2013 23:45:42 +0100
Daniel Borkmann <dborkman@redhat.com> wrote:
> Use msecs_to_jiffies, for these calculations as different HZ
> considerations are taken into account for conversion of the timer
> shot, and also it makes the code more readable.
>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> ---
> lib/random32.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/lib/random32.c b/lib/random32.c
> index 4f9d5df..1e5b2df 100644
> --- a/lib/random32.c
> +++ b/lib/random32.c
> @@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
> static void __prandom_timer(unsigned long dontcare)
> {
> u32 entropy;
> + unsigned long expires;
>
> get_random_bytes(&entropy, sizeof(entropy));
> prandom_seed(entropy);
> +
> /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
> - seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
> + expires = 40 + (prandom_u32() % 40);
> + seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
> +
> add_timer(&seed_timer);
> }
>
> static void __init __prandom_start_seed_timer(void)
> {
> set_timer_slack(&seed_timer, HZ);
> - seed_timer.expires = jiffies + 40 * HZ;
> + seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
> add_timer(&seed_timer);
> }
>
Some questions:
1. What is the point of using msecs_to_jiffies? the older code already handled
differing HZ?
2. Why the magic 40-80 sec range? What about platforms with very low entropy
you will end up draining it faster.
3. I prefer using mod_timer rather than setting expires and call add_timer
4. You should also use round_jiffies to save power by making the wakeup on a second
boundary.
next prev parent reply other threads:[~2013-11-12 23:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 22:45 [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer Daniel Borkmann
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
2013-11-12 23:35 ` Stephen Hemminger [this message]
2013-11-12 23:47 ` Hannes Frederic Sowa
2013-11-14 21:07 ` David Miller
2013-11-14 21:06 ` [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131112153512.68520cca@samsung-9 \
--to=stephen@networkplumber.org \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=hannes@stressinduktion.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).