random: optimize add_interrupt_randomness
authorAndi Kleen <ak@linux.intel.com>
Wed, 28 Feb 2018 21:43:28 +0000 (13:43 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 28 Feb 2018 23:01:16 +0000 (18:01 -0500)
commite8e8a2e47db6bb85bb0cb21e77b5c6aaedf864b4
treef41b73f9f7cde6bc468e7bc0c46c812e4d8205f9
parent25e3fca492035a2e1d4ac6e3b1edd9c1acd48897
random: optimize add_interrupt_randomness

add_interrupt_randomess always wakes up
code blocking on /dev/random. This wake up is done
unconditionally. Unfortunately this means all interrupts
take the wait queue spinlock, which can be rather expensive
on large systems processing lots of interrupts.

We saw 1% cpu time spinning on this on a large macro workload
running on a large system.

I believe it's a recent regression (?)

Always check if there is a waiter on the wait queue
before waking up. This check can be done without
taking a spinlock.

1.06%         10460  [kernel.vmlinux] [k] native_queued_spin_lock_slowpath
         |
         ---native_queued_spin_lock_slowpath
            |
             --0.57%--_raw_spin_lock_irqsave
                       |
                        --0.56%--__wake_up_common_lock
                                  credit_entropy_bits
                                  add_interrupt_randomness
                                  handle_irq_event_percpu
                                  handle_irq_event
                                  handle_edge_irq
                                  handle_irq
                                  do_IRQ
                                  common_interrupt

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
drivers/char/random.c