[patch] sched: fix latency in random driver

From: Ingo Molnar
Date: Tue Sep 14 2004 - 04:59:18 EST



the attached patch fixes possibly long scheduling latencies in the
/dev/random driver's rekey_seq_generator() function, by moving the
expensive get_random_bytes() function out from under ip_lock.

has been in the -VP patchset for quite some time.

Ingo

the attached patch fixes possibly long scheduling latencies in the
/dev/random driver's rekey_seq_generator() function, by moving the
expensive get_random_bytes() function out from under ip_lock.

has been in the -VP patchset for quite some time.

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>

--- linux/drivers/char/random.c.orig
+++ linux/drivers/char/random.c
@@ -2220,17 +2220,18 @@ static unsigned int ip_cnt;

static void rekey_seq_generator(void *private_)
{
- struct keydata *keyptr;
+ struct keydata *keyptr, tmp;
struct timeval tv;

do_gettimeofday(&tv);
+ get_random_bytes(tmp.secret, sizeof(tmp.secret));

spin_lock_bh(&ip_lock);
keyptr = &ip_keydata[ip_cnt&1];

keyptr = &ip_keydata[1^(ip_cnt&1)];
keyptr->rekey_time = tv.tv_sec;
- get_random_bytes(keyptr->secret, sizeof(keyptr->secret));
+ memcpy(keyptr->secret, tmp.secret, sizeof(keyptr->secret));
keyptr->count = (ip_cnt&COUNT_MASK)<<HASH_BITS;
mb();
ip_cnt++;