Messages in this thread Patch in this message | | | From | Theodore Ts'o <> | Subject | [PATCH, RFC 06/12] random: optimize spinlock use in add_device_randomness() | Date | Sun, 22 Sep 2013 16:38:52 -0400 |
| |
No point taking the spinlock twice for each call to mix_pool_bytes(); better to take it once for each pool where we add entropy.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> --- drivers/char/random.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c index 391b05a..9564144 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -711,10 +711,15 @@ void add_device_randomness(const void *buf, unsigned int size) unsigned long flags; trace_add_device_randomness(size, _RET_IP_); - mix_pool_bytes(&input_pool, buf, size, NULL); - mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); - mix_pool_bytes(&nonblocking_pool, buf, size, NULL); - mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL); + spin_lock_irqsave(&input_pool.lock, flags); + _mix_pool_bytes(&input_pool, buf, size, NULL); + _mix_pool_bytes(&input_pool, &time, sizeof(time), NULL); + spin_unlock_irqrestore(&input_pool.lock, flags); + + spin_lock_irqsave(&nonblocking_pool.lock, flags); + _mix_pool_bytes(&nonblocking_pool, buf, size, NULL); + _mix_pool_bytes(&nonblocking_pool, &time, sizeof(time), NULL); + spin_unlock_irqrestore(&nonblocking_pool.lock, flags); } EXPORT_SYMBOL(add_device_randomness); -- 1.7.12.rc0.22.gcdd159b
| |