Skip to contentSkip to conversation

irq: Track the interrupt timings

PATCH Superseded Daniel Lezcano 3 participants 12 messages Jun 14, 2016 – Jun 23, 2016 IRQ

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 irq: Track the interrupt timings

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

---
V5:
- Changed comment about 'deterministic' as the comment is confusing
- Added license comment in the header
- Replaced irq_timings_get/put by irq_timings_enable/disable
- Moved IRQS_TIMINGS check in the handle_timings inline function
- Dropped 'if !prev' as it is pointless
- Stored time interval in nsec basis with u64 instead of u32
- Removed redundant store
- Removed the math
V4:
- Added a static key
- Added more comments for irq_timings_get_next()
- Unified some function names to be prefixed by 'irq_timings_...'
- Fixed a rebase error
V3:
- Replaced ktime_get() by local_clock()
- Shared irq are not handled
- Simplified code by adding the timing in the irqdesc struct
- Added a function to browse the irq timings
V2:
- Fixed kerneldoc comment
- Removed data field from the struct irq timing
- Changed the lock section comment
- Removed semi-colon style with empty stub
- Replaced macro by static inline
- Fixed static functions declaration
RFC:
- initial posting

---
 include/linux/interrupt.h |  17 ++++++++
 include/linux/irqdesc.h   |   4 ++
 kernel/irq/Kconfig        |   3 ++
 kernel/irq/Makefile       |   1 +
 kernel/irq/handle.c       |   2 +
 kernel/irq/internals.h    |  61 +++++++++++++++++++++++++++
 kernel/irq/irqdesc.c      |   6 +++
 kernel/irq/manage.c       |   3 ++
 kernel/irq/timings.c      | 104 ++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 201 insertions(+)
 create mode 100644 kernel/irq/timings.c
include/linux/interrupt.h +17 -0
index 9fcabeb..9b0983a 100644
@@ -675,6 +675,23 @@ static inline void init_irq_proc(void)
 }
 #endif
 
+#ifdef CONFIG_IRQ_TIMINGS
+
+#define IRQ_TIMINGS_SHIFT	3
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timings {
+	u64 values[IRQ_TIMINGS_SIZE];	/* our circular buffer */
+	u64 timestamp;			/* latest timestamp */
+	unsigned int w_index;		/* current buffer index */
+};
+
+struct irq_timings *irq_timings_get_next(int *irq);
+void irq_timings_enable(void);
+void irq_timings_disable(void);
+#endif
+
 struct seq_file;
 int show_interrupts(struct seq_file *p, void *v);
 int arch_show_interrupts(struct seq_file *p, int prec);
include/linux/irqdesc.h +4 -0
index b51beeb..a21ddbbe 100644
@@ -12,6 +12,7 @@ struct proc_dir_entry;
 struct module;
 struct irq_desc;
 struct irq_domain;
+struct irq_timings;
 struct pt_regs;
 
 /**
@@ -51,6 +52,9 @@ struct irq_desc {
 	struct irq_data		irq_data;
 	unsigned int __percpu	*kstat_irqs;
 	irq_flow_handler_t	handle_irq;
+#ifdef CONFIG_IRQ_TIMINGS
+	struct irq_timings __percpu *timings;
+#endif
 #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
 	irq_preflow_handler_t	preflow_handler;
 #endif
kernel/irq/Kconfig +3 -0
index 3bbfd6a..38e551d 100644
@@ -81,6 +81,9 @@ config GENERIC_MSI_IRQ_DOMAIN
 config HANDLE_DOMAIN_IRQ
 	bool
 
+config IRQ_TIMINGS
+	bool
+
 config IRQ_DOMAIN_DEBUG
 	bool "Expose hardware/virtual IRQ mapping via debugfs"
 	depends on IRQ_DOMAIN && DEBUG_FS
kernel/irq/Makefile +1 -0
index 2ee42e9..e1debaa9 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
 obj-$(CONFIG_PM_SLEEP) += pm.o
 obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
 obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o
+obj-$(CONFIG_IRQ_TIMINGS) += timings.o
kernel/irq/handle.c +2 -0
index a15b548..cd37536 100644
@@ -138,6 +138,8 @@ irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
 	unsigned int flags = 0, irq = desc->irq_data.irq;
 	struct irqaction *action;
 
+	handle_timings(desc);
+
 	for_each_action_of_desc(desc, action) {
 		irqreturn_t res;
 
kernel/irq/internals.h +61 -0

70 lines not on this page · raw message

kernel/irq/irqdesc.c +6 -0
index 8731e1c..2c3ce74 100644
@@ -174,6 +174,9 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 	if (alloc_masks(desc, gfp, node))
 		goto err_kstat;
 
+	if (alloc_timings(desc))
+		goto err_mask;
+
 	raw_spin_lock_init(&desc->lock);
 	lockdep_set_class(&desc->lock, &irq_desc_lock_class);
 	init_rcu_head(&desc->rcu);
@@ -182,6 +185,8 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 
 	return desc;
 
+err_mask:
+	free_masks(desc);
 err_kstat:
 	free_percpu(desc->kstat_irqs);
 err_desc:
@@ -193,6 +198,7 @@ static void delayed_free_desc(struct rcu_head *rhp)
 {
 	struct irq_desc *desc = container_of(rhp, struct irq_desc, rcu);
 
+	free_timings(desc);
 	free_masks(desc);
 	free_percpu(desc->kstat_irqs);
 	kfree(desc);
kernel/irq/manage.c +3 -0
index 00cfc85..7a9f460 100644
@@ -1350,6 +1350,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
 		__enable_irq(desc);
 	}
 
+	setup_timings(desc, new);
+
 	raw_spin_unlock_irqrestore(&desc->lock, flags);
 
 	/*
@@ -1480,6 +1482,7 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
 		irq_settings_clr_disable_unlazy(desc);
 		irq_shutdown(desc);
 		irq_release_resources(desc);
+		remove_timings(desc);
 	}
 
 #ifdef CONFIG_SMP
kernel/irq/timings.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

On Tue, 14 Jun 2016, Daniel Lezcano wrote:

[...]

Quoted 11 lines
kernel/irq/timings.c new file +11 -0
+void __handle_timings(struct irq_desc *desc)
+{
+	struct irq_timings *timings;
+	u64 prev, now, diff;
+
+	timings = this_cpu_ptr(desc->timings);
+	now = local_clock();
+	prev = timings->timestamp;
+	timings->timestamp = now;
+
+	/*

kernel/irq/timings.c line 60

Quoted 10 lines
kernel/irq/timings.c new file +10 -0
+	 * In case it is the first time this function is called, the
+	 * 'prev' variable will be zero which reflects the time origin
+	 * when the system booted.
+	 */
+	diff = now - prev;
+
+	/* The oldest value corresponds to the next index. */
+	timings->w_index = (timings->w_index + 1) & IRQ_TIMINGS_MASK;
+	timings->values[timings->w_index] = diff;
+}

What about simply this:

void __handle_timings(struct irq_desc *desc)

{
	struct irq_timings *timings = this_cpu_ptr(desc->timings);
	timings->w_index = (timings->w_index + 1) & IRQ_TIMINGS_MASK;
	timings->values[timings->w_index] = local_clock();
}

?

Then you could s/__handle_timings/__record_irq_time/ to better represent what it does. And both the difference and the summing of squares could be done upon entering idle instead.

Nicolas

#2 lore raw
Quoted 9 lines · Nicolas Pitre

What about simply this:

void __handle_timings(struct irq_desc *desc)

{
	struct irq_timings *timings = this_cpu_ptr(desc->timings);
	timings->w_index = (timings->w_index + 1) & IRQ_TIMINGS_MASK;
	timings->values[timings->w_index] = local_clock();
}
Quoted 5 lines

?

Then you could s/__handle_timings/__record_irq_time/ to better represent what it does. And both the difference and the summing of squares could be done upon entering idle instead.

And make it part of the handle_timings() inline to avoid the function call.

Thanks,

tglx

#3 lore raw
Quoted 10 lines · Thomas Gleixner
Quoted 9 lines · Nicolas Pitre

What about simply this:

void __handle_timings(struct irq_desc *desc)

{
	struct irq_timings *timings = this_cpu_ptr(desc->timings);
	timings->w_index = (timings->w_index + 1) & IRQ_TIMINGS_MASK;
	timings->values[timings->w_index] = local_clock();
}
Quoted 7 lines
Quoted 5 lines

?

Then you could s/__handle_timings/__record_irq_time/ to better represent what it does. And both the difference and the summing of squares could be done upon entering idle instead.

And make it part of the handle_timings() inline to avoid the function call.

Ah yes, nice !

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#4 lore raw

PATCH v6 1/1 irq: Track the interrupt timings

In reply to Thomas Gleixner

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

---
V6:
- Renamed handle_irq_timings to record_irq_time
- Stored the event time instead of the interval time
- Removed the 'timestamp' field from the timings structure
- Moved _handle_irq_timings content inside record_irq_time
V5:
- Changed comment about 'deterministic' as the comment is confusing
- Added license comment in the header
- Replaced irq_timings_get/put by irq_timings_enable/disable
- Moved IRQS_TIMINGS check in the handle_timings inline function
- Dropped 'if !prev' as it is pointless
- Stored time interval in nsec basis with u64 instead of u32
- Removed redundant store
- Removed the math
V4:
- Added a static key
- Added more comments for irq_timings_get_next()
- Unified some function names to be prefixed by 'irq_timings_...'
- Fixed a rebase error
V3:
- Replaced ktime_get() by local_clock()
- Shared irq are not handled
- Simplified code by adding the timing in the irqdesc struct
- Added a function to browse the irq timings
V2:
- Fixed kerneldoc comment
- Removed data field from the struct irq timing
- Changed the lock section comment
- Removed semi-colon style with empty stub
- Replaced macro by static inline
- Fixed static functions declaration
RFC:
- initial posting

---
 include/linux/interrupt.h | 16 +++++++++++
 include/linux/irqdesc.h   |  4 +++
 kernel/irq/Kconfig        |  3 ++
 kernel/irq/Makefile       |  1 +
 kernel/irq/handle.c       |  2 ++
 kernel/irq/internals.h    | 62 ++++++++++++++++++++++++++++++++++++++++
 kernel/irq/irqdesc.c      |  6 ++++
 kernel/irq/manage.c       |  3 ++
 kernel/irq/timings.c      | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 170 insertions(+)
 create mode 100644 kernel/irq/timings.c
include/linux/interrupt.h +16 -0
index 9fcabeb..5ff1d3a 100644
@@ -675,6 +675,22 @@ static inline void init_irq_proc(void)
 }
 #endif
 
+#ifdef CONFIG_IRQ_TIMINGS
+
+#define IRQ_TIMINGS_SHIFT	3
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timings {
+	u64 values[IRQ_TIMINGS_SIZE];	/* our circular buffer */
+	unsigned int w_index;		/* current buffer index */
+};
+
+struct irq_timings *irq_timings_get_next(int *irq);
+void irq_timings_enable(void);
+void irq_timings_disable(void);
+#endif
+
 struct seq_file;
 int show_interrupts(struct seq_file *p, void *v);
 int arch_show_interrupts(struct seq_file *p, int prec);
include/linux/irqdesc.h +4 -0
index b51beeb..a21ddbbe 100644
@@ -12,6 +12,7 @@ struct proc_dir_entry;
 struct module;
 struct irq_desc;
 struct irq_domain;
+struct irq_timings;
 struct pt_regs;
 
 /**
@@ -51,6 +52,9 @@ struct irq_desc {
 	struct irq_data		irq_data;
 	unsigned int __percpu	*kstat_irqs;
 	irq_flow_handler_t	handle_irq;
+#ifdef CONFIG_IRQ_TIMINGS
+	struct irq_timings __percpu *timings;
+#endif
 #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
 	irq_preflow_handler_t	preflow_handler;
 #endif
kernel/irq/Kconfig +3 -0
index 3bbfd6a..38e551d 100644
@@ -81,6 +81,9 @@ config GENERIC_MSI_IRQ_DOMAIN
 config HANDLE_DOMAIN_IRQ
 	bool
 
+config IRQ_TIMINGS
+	bool
+
 config IRQ_DOMAIN_DEBUG
 	bool "Expose hardware/virtual IRQ mapping via debugfs"
 	depends on IRQ_DOMAIN && DEBUG_FS
kernel/irq/Makefile +1 -0
index 2ee42e9..e1debaa9 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
 obj-$(CONFIG_PM_SLEEP) += pm.o
 obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
 obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o
+obj-$(CONFIG_IRQ_TIMINGS) += timings.o
kernel/irq/handle.c +2 -0
index a15b548..335847e 100644
@@ -138,6 +138,8 @@ irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
 	unsigned int flags = 0, irq = desc->irq_data.irq;
 	struct irqaction *action;
 
+	record_irq_time(desc);
+
 	for_each_action_of_desc(desc, action) {
 		irqreturn_t res;
 
kernel/irq/internals.h +62 -0

71 lines not on this page · raw message

kernel/irq/irqdesc.c +6 -0
index 8731e1c..2c3ce74 100644
@@ -174,6 +174,9 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 	if (alloc_masks(desc, gfp, node))
 		goto err_kstat;
 
+	if (alloc_timings(desc))
+		goto err_mask;
+
 	raw_spin_lock_init(&desc->lock);
 	lockdep_set_class(&desc->lock, &irq_desc_lock_class);
 	init_rcu_head(&desc->rcu);
@@ -182,6 +185,8 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 
 	return desc;
 
+err_mask:
+	free_masks(desc);
 err_kstat:
 	free_percpu(desc->kstat_irqs);
 err_desc:
@@ -193,6 +198,7 @@ static void delayed_free_desc(struct rcu_head *rhp)
 {
 	struct irq_desc *desc = container_of(rhp, struct irq_desc, rcu);
 
+	free_timings(desc);
 	free_masks(desc);
 	free_percpu(desc->kstat_irqs);
 	kfree(desc);
kernel/irq/manage.c +3 -0
index 00cfc85..7a9f460 100644
@@ -1350,6 +1350,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
 		__enable_irq(desc);
 	}
 
+	setup_timings(desc, new);
+
 	raw_spin_unlock_irqrestore(&desc->lock, flags);
 
 	/*
@@ -1480,6 +1482,7 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
 		irq_settings_clr_disable_unlazy(desc);
 		irq_shutdown(desc);
 		irq_release_resources(desc);
+		remove_timings(desc);
 	}
 
 #ifdef CONFIG_SMP
kernel/irq/timings.c new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw
Quoted 17 lines · Daniel Lezcano

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

Quoted 8 lines

---
V6:
- Renamed handle_irq_timings to record_irq_time
- Stored the event time instead of the interval time
- Removed the 'timestamp' field from the timings structure
- Moved _handle_irq_timings content inside record_irq_time

Looks fine to me.

Nicolas

#6 lore raw
In reply to Daniel Lezcano
Quoted 23 lines · Daniel Lezcano
kernel/irq/timings.c new file +23 -0
+/**
+ * irqtiming_get_next - return the next irq timing
+ *
+ * @irq: a pointer to an integer representing the interrupt number
+ *
+ * This function allows to browse safely the interrupt descriptors in order
+ * to retrieve the interrupts timings. The parameter gives the interrupt
+ * number to begin with and will return the interrupt timings for the next
+ * allocated irq. This approach gives us the possibility to go through the
+ * different interrupts without having to handle the sparse irq.
+ *
+ * The function changes @irq to the next allocated irq + 1, it should be
+ * passed back again and again until NULL is returned. Usually this function
+ * is called the first time with @irq = 0.
+ *
+ * Returns a struct irq_timings, NULL if we reach the end of the interrupts
+ * list.
+ */
+struct irq_timings *irq_timings_get_next(int *irq)
+{
+	struct irq_desc *desc;
+	int next;
+

kernel/irq/timings.c line 63

Quoted 10 lines
kernel/irq/timings.c new file +10 -0
+again:
+	/* Do a racy lookup of the next allocated irq */
+	next = irq_get_next_irq(*irq);
+	if (next >= nr_irqs)
+		return NULL;
+
+	*irq = next + 1;
+
+	/*
+	 * Now lookup the descriptor. It's RCU protected. This

Please mention in the function description above that this function must be called inside of a rcu_read() locked section.

Thanks,

tglx

#7 lore raw

PATCH v7 1/1 irq: Track the interrupt timings

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

---
V7:
- Mentionned in the irq_timings_get_next() function description, the function must be called inside a rcu read locked section
V6:
- Renamed handle_irq_timings to record_irq_time
- Stored the event time instead of the interval time
- Removed the 'timestamp' field from the timings structure
- Moved _handle_irq_timings content inside record_irq_time
V5:
- Changed comment about 'deterministic' as the comment is confusing
- Added license comment in the header
- Replaced irq_timings_get/put by irq_timings_enable/disable
- Moved IRQS_TIMINGS check in the handle_timings inline function
- Dropped 'if !prev' as it is pointless
- Stored time interval in nsec basis with u64 instead of u32
- Removed redundant store
- Removed the math
V4:
- Added a static key
- Added more comments for irq_timings_get_next()
- Unified some function names to be prefixed by 'irq_timings_...'
- Fixed a rebase error
V3:
- Replaced ktime_get() by local_clock()
- Shared irq are not handled
- Simplified code by adding the timing in the irqdesc struct
- Added a function to browse the irq timings
V2:
- Fixed kerneldoc comment
- Removed data field from the struct irq timing
- Changed the lock section comment
- Removed semi-colon style with empty stub
- Replaced macro by static inline
- Fixed static functions declaration
RFC:
- initial posting

---
 include/linux/interrupt.h | 16 ++++++++++
 include/linux/irqdesc.h   |  4 +++
 kernel/irq/Kconfig        |  3 ++
 kernel/irq/Makefile       |  1 +
 kernel/irq/handle.c       |  2 ++
 kernel/irq/internals.h    | 62 +++++++++++++++++++++++++++++++++++++++
 kernel/irq/irqdesc.c      |  6 ++++
 kernel/irq/manage.c       |  3 ++
 kernel/irq/timings.c      | 75 +++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 172 insertions(+)
 create mode 100644 kernel/irq/timings.c
include/linux/interrupt.h +16 -0
index 9fcabeb..5ff1d3a 100644
@@ -675,6 +675,22 @@ static inline void init_irq_proc(void)
 }
 #endif
 
+#ifdef CONFIG_IRQ_TIMINGS
+
+#define IRQ_TIMINGS_SHIFT	3
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timings {
+	u64 values[IRQ_TIMINGS_SIZE];	/* our circular buffer */
+	unsigned int w_index;		/* current buffer index */
+};
+
+struct irq_timings *irq_timings_get_next(int *irq);
+void irq_timings_enable(void);
+void irq_timings_disable(void);
+#endif
+
 struct seq_file;
 int show_interrupts(struct seq_file *p, void *v);
 int arch_show_interrupts(struct seq_file *p, int prec);
include/linux/irqdesc.h +4 -0
index b51beeb..a21ddbbe 100644
@@ -12,6 +12,7 @@ struct proc_dir_entry;
 struct module;
 struct irq_desc;
 struct irq_domain;
+struct irq_timings;
 struct pt_regs;
 
 /**
@@ -51,6 +52,9 @@ struct irq_desc {
 	struct irq_data		irq_data;
 	unsigned int __percpu	*kstat_irqs;
 	irq_flow_handler_t	handle_irq;
+#ifdef CONFIG_IRQ_TIMINGS
+	struct irq_timings __percpu *timings;
+#endif
 #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
 	irq_preflow_handler_t	preflow_handler;
 #endif
kernel/irq/Kconfig +3 -0
index 3bbfd6a..38e551d 100644
@@ -81,6 +81,9 @@ config GENERIC_MSI_IRQ_DOMAIN
 config HANDLE_DOMAIN_IRQ
 	bool
 
+config IRQ_TIMINGS
+	bool
+
 config IRQ_DOMAIN_DEBUG
 	bool "Expose hardware/virtual IRQ mapping via debugfs"
 	depends on IRQ_DOMAIN && DEBUG_FS
kernel/irq/Makefile +1 -0
index 2ee42e9..e1debaa9 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o
 obj-$(CONFIG_PM_SLEEP) += pm.o
 obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
 obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o
+obj-$(CONFIG_IRQ_TIMINGS) += timings.o
kernel/irq/handle.c +2 -0
index a15b548..335847e 100644
@@ -138,6 +138,8 @@ irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
 	unsigned int flags = 0, irq = desc->irq_data.irq;
 	struct irqaction *action;
 
+	record_irq_time(desc);
+
 	for_each_action_of_desc(desc, action) {
 		irqreturn_t res;
 
kernel/irq/internals.h +62 -0

71 lines not on this page · raw message

kernel/irq/irqdesc.c +6 -0
index 8731e1c..2c3ce74 100644
@@ -174,6 +174,9 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 	if (alloc_masks(desc, gfp, node))
 		goto err_kstat;
 
+	if (alloc_timings(desc))
+		goto err_mask;
+
 	raw_spin_lock_init(&desc->lock);
 	lockdep_set_class(&desc->lock, &irq_desc_lock_class);
 	init_rcu_head(&desc->rcu);
@@ -182,6 +185,8 @@ static struct irq_desc *alloc_desc(int irq, int node, struct module *owner)
 
 	return desc;
 
+err_mask:
+	free_masks(desc);
 err_kstat:
 	free_percpu(desc->kstat_irqs);
 err_desc:
@@ -193,6 +198,7 @@ static void delayed_free_desc(struct rcu_head *rhp)
 {
 	struct irq_desc *desc = container_of(rhp, struct irq_desc, rcu);
 
+	free_timings(desc);
 	free_masks(desc);
 	free_percpu(desc->kstat_irqs);
 	kfree(desc);
kernel/irq/manage.c +3 -0
index 00cfc85..7a9f460 100644
@@ -1350,6 +1350,8 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
 		__enable_irq(desc);
 	}
 
+	setup_timings(desc, new);
+
 	raw_spin_unlock_irqrestore(&desc->lock, flags);
 
 	/*
@@ -1480,6 +1482,7 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
 		irq_settings_clr_disable_unlazy(desc);
 		irq_shutdown(desc);
 		irq_release_resources(desc);
+		remove_timings(desc);
 	}
 
 #ifdef CONFIG_SMP
kernel/irq/timings.c new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
1.9.1
#8 lore raw
Quoted 8 lines · Daniel Lezcano

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

Quoted 8 lines

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

Before merging this I really have to ask a few more questions. I'm a bit worried about the usage site of this. It's going to iterate over all interrupts in the system to do a next interrupt prediction. On larger machines that's going to be quite some work and you touch a gazillion of cache lines and many of them just to figure out that nothing happened.

Is it really required to do this per interrupt rather than providing per cpu statistics of interrupts which arrived in the last X seconds or whatever timeframe is relevant for this.

Thanks,

tglx

#9 lore raw
Quoted 24 lines · Thomas Gleixner
Quoted 8 lines · Daniel Lezcano

The interrupt framework gives a lot of information about each interrupt.

It does not keep track of when those interrupts occur though.

This patch provides a mean to record the elapsed time between successive interrupt occurrences in a per-IRQ per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

Quoted 8 lines

A new function is added to browse the different interrupts and retrieve the timing information stored in it.

A static key is introduced so when the irq prediction is switched off at runtime, we can reduce the overhead near to zero. The irq timings is supposed to be potentially used by different sub-systems and for this reason the static key is a ref counter, so when the last use releases the irq timings that will result on the effective deactivation of the irq measurement.

Before merging this I really have to ask a few more questions. I'm a bit worried about the usage site of this. It's going to iterate over all interrupts in the system to do a next interrupt prediction. On larger machines that's going to be quite some work and you touch a gazillion of cache lines and many of them just to figure out that nothing happened.

Quoted 3 lines

Is it really required to do this per interrupt rather than providing per cpu statistics of interrupts which arrived in the last X seconds or whatever timeframe is relevant for this.

Perhaps I am misunderstanding but if the statistics are done per cpu without tracking per irq timings, it is not possible to extract a repeating pattern for each irq and have an accurate prediction.

Today, the code stores per cpu and per irq timings and the usage is to compute the next irq event by taking the earliest next irq event on the current cpu.

@@ -51,6 +52,9 @@ struct irq_desc {
        struct irq_data         irq_data;
        unsigned int __percpu   *kstat_irqs;
        irq_flow_handler_t      handle_irq;
+#ifdef CONFIG_IRQ_TIMINGS
+       struct irq_timings __percpu *timings;
+#endif
 #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
        irq_preflow_handler_t   preflow_handler;

#endif

If we step back and look at the potential users of this framework, we have:

- mobile: by nature the interrupt line number is small and the devices
are "slow"

- desktop and laptop : a few interrupts are really interesting us,
ethernet and sdd (the other ones are rare, or ignored like timers or IPI)

- server : the interrupt line number is bigger, but not so much.

- other big system: I don't know

Usually, server and super sized system want full performance and low latency. For this reason the kernel is configured with periodic tick and that makes the next prediction algorithm superfluous, especially when the latency is set to 0. So I don't think the irq timings + next irq event code path will be ever used in this case.

As you mentioned it, there are some parts we can make evolve and optimize like preventing to lookup an empty irq events cpu.

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#10 lore raw
Quoted 8 lines · Daniel Lezcano
Quoted 3 lines · Thomas Gleixner

Is it really required to do this per interrupt rather than providing per cpu statistics of interrupts which arrived in the last X seconds or whatever timeframe is relevant for this.

Perhaps I am misunderstanding but if the statistics are done per cpu without tracking per irq timings, it is not possible to extract a repeating pattern for each irq and have an accurate prediction.

I don't see why you need a repeating pattern for each irq. All you want to know is whether there are repeating patterns of interrupts on a particular cpu.

struct per_cpu_stat {
       u32	    irq;
       u64	    ts;
};

storing 32 entries of the above should give you enough information about patterns etc. If you have a high rate of interrupts on that cpu it does not matter at all whether thats from one or several devices. If you have only a few then this storage is sufficient to get the desired information.

Quoted 7 lines

If we step back and look at the potential users of this framework, we have:

- mobile: by nature the interrupt line number is small and the devices are
"slow"

- desktop and laptop : a few interrupts are really interesting us, ethernet
and sdd (the other ones are rare, or ignored like timers or IPI)

You still walk ALL interrupts. On my laptop that's 22 of them. And you touch every single per cpu storage of each interrupt.

Quoted 1 line

- server : the interrupt line number is bigger, but not so much.

Not so much? 158 interrupts on one of my larger machines.

Quoted 5 lines

Usually, server and super sized system want full performance and low latency. For this reason the kernel is configured with periodic tick and that makes the next prediction algorithm superfluous, especially when the latency is set to
0. So I don't think the irq timings + next irq event code path will be ever used in this case.

Well, if such a machine runs with NOHZ=n then fine. But there are enough machines where NOHZ is enabled so you get better power savings during times where the machine is not loaded, but you want to have performance and low latency if there is work to do.

Quoted 2 lines

As you mentioned it, there are some parts we can make evolve and optimize like preventing to lookup an empty irq events cpu.

You better think about this now.

Thanks,

tglx

#11 lore raw
Quoted 19 lines · Thomas Gleixner
Quoted 8 lines · Daniel Lezcano
Quoted 3 lines · Thomas Gleixner

Is it really required to do this per interrupt rather than providing per cpu statistics of interrupts which arrived in the last X seconds or whatever timeframe is relevant for this.

Perhaps I am misunderstanding but if the statistics are done per cpu without tracking per irq timings, it is not possible to extract a repeating pattern for each irq and have an accurate prediction.

I don't see why you need a repeating pattern for each irq. All you want to know is whether there are repeating patterns of interrupts on a particular cpu.

struct per_cpu_stat {
        u32	    irq;
        u64	    ts;
};
Quoted 4 lines

storing 32 entries of the above should give you enough information about patterns etc. If you have a high rate of interrupts on that cpu it does not matter at all whether thats from one or several devices. If you have only a few then this storage is sufficient to get the desired information.

Mmmh, yes. I will investigate this patchset by replacing the percpu irqdesc's timings field by a per cpu irq event timings array.

Thanks !

-- Daniel

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog