mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Alexander Clouter <alex@digriz.org.uk>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: Re: [PATCHv2] hw_random: add timeriomem-rng driver
Date: Thu, 12 Feb 2009 00:27:22 +1100	[thread overview]
Message-ID: <20090211132722.GA3258@gondor.apana.org.au> (raw)
In-Reply-To: <20090210193904.GT11872@woodchuck>

On Tue, Feb 10, 2009 at 07:39:04PM +0000, Alexander Clouter wrote:
>
> My original code[1] approach, with timer_pending() in there, would have 
> been okay then, right?
> ----
> if (timer_pending(&timeriomem_rng_timer)) {
>   if (!wait)
>     return 0;
> 
>   del_timer_sync(&timeriomem_rng_timer);
>   delay = timeriomem_rng_timer.expires - jiffies;
> 
>   schedule_timeout_uninterruptible(delay);
> }

Yes probably but it is racy.  Also it's better if we can avoid
the expires - jiffies calculation if only because then we won't
have to tell Andrew why it can't be negative :)

> > Instead of deleting the timer above, why not create a rng->present
> > variable which you set to zero here, and the timer sets it to
> > non-zero.  Then you just need to return rng->present in your
> > data_present function.
>
> Sounds fair, better than the timer_pending approach and easier to 
> understand.

Oh I forgot about the blocking case.  We can probably add a
completion object to handle that.  So something like

	if (!wait || rng->present)
		return rng->present;

	wait_for_completion(&rng->completion);
	return 1;

The timer would do

	rng->present = 1;
	complete(&rng->completion);

And the reader would do

	rng->present = 0;
	INIT_COMPLETION(rng->completion);
	add_timer(...)

Note that everything but the timer is completely serialised by
the hwrng mutex so we only need to worry about racing against
the timer.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      parent reply	other threads:[~2009-02-11 13:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-07  9:53 Alexander Clouter
2009-02-10  4:57 ` Herbert Xu
2009-02-10 19:39   ` Alexander Clouter
2009-02-10 19:49     ` Alexander Clouter
2009-02-11 13:27     ` Herbert Xu [this message]

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=20090211132722.GA3258@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=akpm@linux-foundation.org \
    --cc=alex@digriz.org.uk \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®