Skip to contentSkip to conversation

genirq: use rcu in kstat_irqs_usr()

PATCH New Eric Dumazet 2 participants 2 messages Jun 18, 2018 – Jun 19, 2018 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genirq: use rcu in kstat_irqs_usr()

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

Since Thomas Gleixner commit 425a5072dcd1 ("genirq: Free irq_desc with rcu"), we can easily switch kstat_irqs_usr() to rcu locking and remove this mutex contetion.

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

---
 kernel/irq/irqdesc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
kernel/irq/irqdesc.c +7 -6
index afc7f902d74a3eff5d1f8a5e407159c5d28625f7..a668b7ad8a5d5e3b191e3a1dc8f9f32293658d42 100644
@@ -443,6 +443,7 @@ static void free_desc(unsigned int irq)
 	 * We free the descriptor, masks and stat fields via RCU. That
 	 * allows demultiplex interrupts to do rcu based management of
 	 * the child interrupts.
+	 * This also allows us to use rcu in kstat_irqs_usr().
 	 */
 	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
  * @irq:	The interrupt number
  *
- * Returns the sum of interrupt counts on all cpus since boot for
- * @irq. Contrary to kstat_irqs() this can be called from any
- * preemptible context. It's protected against concurrent removal of
- * an interrupt descriptor when sparse irqs are enabled.
+ * Returns the sum of interrupt counts on all cpus since boot for @irq.
+ * Contrary to kstat_irqs() this can be called from any context.
+ * It uses rcu since a concurrent removal of an interrupt descriptor is
+ * observing an rcu grace period before delayed_free_desc()/irq_kobj_release().
  */
 unsigned int kstat_irqs_usr(unsigned int irq)
 {
 	unsigned int sum;
 
-	irq_lock_sparse();
+	rcu_read_lock();
 	sum = kstat_irqs(irq);
-	irq_unlock_sparse();
+	rcu_read_unlock();
 	return sum;
 }
Signature · 1 line
2.18.0.rc1.244.gcf134e6275-goog
#1 lore raw

[tip:irq/core] genirq: Use rcu in kstat_irqs_usr()

genirq: Use rcu in kstat_irqs_usr()
Commit-ID:  4a5f4d2f891bcff7285b5f7490ed5a7a5d516049
Gitweb:     https://git.kernel.org/tip/4a5f4d2f891bcff7285b5f7490ed5a7a5d516049
Author:     Eric Dumazet <[email protected]>
AuthorDate: Mon, 18 Jun 2018 05:56:12 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Tue, 19 Jun 2018 09:19:40 +0200

genirq: Use rcu in kstat_irqs_usr()

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

Since commit 425a5072dcd1 ("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.

---
 kernel/irq/irqdesc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
kernel/irq/irqdesc.c +7 -6
index afc7f902d74a..578d0e5f1b5b 100644
@@ -443,6 +443,7 @@ static void free_desc(unsigned int irq)
 	 * We free the descriptor, masks and stat fields via RCU. That
 	 * allows demultiplex interrupts to do rcu based management of
 	 * the child interrupts.
+	 * This also allows us to use rcu in kstat_irqs_usr().
 	 */
 	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
  * @irq:	The interrupt number
  *
- * Returns the sum of interrupt counts on all cpus since boot for
- * @irq. Contrary to kstat_irqs() this can be called from any
- * preemptible context. It's protected against concurrent removal of
- * an interrupt descriptor when sparse irqs are enabled.
+ * Returns the sum of interrupt counts on all cpus since boot for @irq.
+ * Contrary to kstat_irqs() this can be called from any context.
+ * It uses rcu since a concurrent removal of an interrupt descriptor is
+ * observing an rcu grace period before delayed_free_desc()/irq_kobj_release().
  */
 unsigned int kstat_irqs_usr(unsigned int irq)
 {
 	unsigned int sum;
 
-	irq_lock_sparse();
+	rcu_read_lock();
 	sum = kstat_irqs(irq);
-	irq_unlock_sparse();
+	rcu_read_unlock();
 	return sum;
 }