genirq: Use rcu in kstat_irqs_usr()

Jeremy Dorfman identified mutex contention when multiple threads
parse /proc/stat concurrently.

Since commit 425a5072dc ("genirq: Free irq_desc with rcu"),
kstat_irqs_usr() can be switched to rcu locking, which removes this mutex
contention.

show_interrupts() case will be handled in a separate patch.

Reported-by: Jeremy Dorfman <jdorfman@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Willem de Bruijn <willemb@google.com>
Link: https://lkml.kernel.org/r/20180618125612.155057-1-edumazet@google.com
This commit is contained in:
Eric Dumazet 2018-06-18 05:56:12 -07:00 committed by Thomas Gleixner
parent 9ffc59d572
commit 4a5f4d2f89

View File

@ -443,6 +443,7 @@ static void free_desc(unsigned int irq)
* We free the descriptor, masks and stat fields via RCU. That * We free the descriptor, masks and stat fields via RCU. That
* allows demultiplex interrupts to do rcu based management of * allows demultiplex interrupts to do rcu based management of
* the child interrupts. * the child interrupts.
* This also allows us to use rcu in kstat_irqs_usr().
*/ */
call_rcu(&desc->rcu, delayed_free_desc); call_rcu(&desc->rcu, delayed_free_desc);
} }
@ -928,17 +929,17 @@ unsigned int kstat_irqs(unsigned int irq)
* kstat_irqs_usr - Get the statistics for an interrupt * kstat_irqs_usr - Get the statistics for an interrupt
* @irq: The interrupt number * @irq: The interrupt number
* *
* Returns the sum of interrupt counts on all cpus since boot for * Returns the sum of interrupt counts on all cpus since boot for @irq.
* @irq. Contrary to kstat_irqs() this can be called from any * Contrary to kstat_irqs() this can be called from any context.
* preemptible context. It's protected against concurrent removal of * It uses rcu since a concurrent removal of an interrupt descriptor is
* an interrupt descriptor when sparse irqs are enabled. * observing an rcu grace period before delayed_free_desc()/irq_kobj_release().
*/ */
unsigned int kstat_irqs_usr(unsigned int irq) unsigned int kstat_irqs_usr(unsigned int irq)
{ {
unsigned int sum; unsigned int sum;
irq_lock_sparse(); rcu_read_lock();
sum = kstat_irqs(irq); sum = kstat_irqs(irq);
irq_unlock_sparse(); rcu_read_unlock();
return sum; return sum;
} }