aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-09-12 14:27:22 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-10-10 14:32:17 -0400
commit3ef4cb2d65ee13d84140cbede8e1980c6ae49ffd (patch)
tree676c6f18c9b75350b92cec558919b6d19a5e5298
parent5910895f0e868d4f70303922ed00ccdc328b3c30 (diff)
random: optimize spinlock use in add_device_randomness()
The add_device_randomness() function calls mix_pool_bytes() twice for the input pool and the non-blocking pool, for a total of four times. By using _mix_pool_byte() and taking the spinlock in add_device_randomness(), we can halve the number of times we need take each pool's spinlock. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--drivers/char/random.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 80b58774e891..89eb5a8dec82 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -710,12 +710,18 @@ struct timer_rand_state {
710void add_device_randomness(const void *buf, unsigned int size) 710void add_device_randomness(const void *buf, unsigned int size)
711{ 711{
712 unsigned long time = random_get_entropy() ^ jiffies; 712 unsigned long time = random_get_entropy() ^ jiffies;
713 unsigned long flags;
713 714
714 trace_add_device_randomness(size, _RET_IP_); 715 trace_add_device_randomness(size, _RET_IP_);
715 mix_pool_bytes(&input_pool, buf, size, NULL); 716 spin_lock_irqsave(&input_pool.lock, flags);
716 mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); 717 _mix_pool_bytes(&input_pool, buf, size, NULL);
717 mix_pool_bytes(&nonblocking_pool, buf, size, NULL); 718 _mix_pool_bytes(&input_pool, &time, sizeof(time), NULL);
718 mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL); 719 spin_unlock_irqrestore(&input_pool.lock, flags);
720
721 spin_lock_irqsave(&nonblocking_pool.lock, flags);
722 _mix_pool_bytes(&nonblocking_pool, buf, size, NULL);
723 _mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL);
724 spin_unlock_irqrestore(&nonblocking_pool.lock, flags);
719} 725}
720EXPORT_SYMBOL(add_device_randomness); 726EXPORT_SYMBOL(add_device_randomness);
721 727