Skip to contentSkip to conversation

irq: Add flags to request_percpu_irq function

PATCH Superseded Daniel Lezcano 7 participants 20 messages Mar 23, 2017 – Mar 27, 2017

Subsystems (16)
lore
Share & tools
lore
#0 lore raw

PATCH v8 1/3 irq: Add flags to request_percpu_irq function

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

But, the API request_percpu_irq does not allow to pass a flag, hence specifying if the interrupt type is a timer.

Solve this by passing a 'flags' parameter to the function and change all the callers to pass IRQF_TIMER when the interrupt is a timer interrupt, zero otherwise.

For now, in order to prevent a misusage of this parameter, only the IRQF_TIMER flag is a valid parameter to be passed to the request_percpu_irq function.

---
 arch/arc/kernel/perf_event.c             |  2 +-
 arch/arc/kernel/smp.c                    |  2 +-
 arch/arm/kernel/smp_twd.c                |  3 ++-
 arch/arm/xen/enlighten.c                 |  2 +-
 drivers/clocksource/arc_timer.c          |  2 +-
 drivers/clocksource/arm_arch_timer.c     | 15 +++++++++------
 drivers/clocksource/arm_global_timer.c   |  2 +-
 drivers/clocksource/exynos_mct.c         |  2 +-
 drivers/clocksource/qcom-timer.c         |  2 +-
 drivers/clocksource/time-armada-370-xp.c |  2 +-
 drivers/clocksource/timer-nps.c          |  2 +-
 drivers/net/ethernet/marvell/mvneta.c    |  2 +-
 drivers/perf/arm_pmu.c                   |  2 +-
 include/linux/interrupt.h                |  5 +++--
 kernel/irq/manage.c                      | 11 ++++++++---
 virt/kvm/arm/arch_timer.c                |  5 +++--
 virt/kvm/arm/vgic/vgic-init.c            |  2 +-
 17 files changed, 37 insertions(+), 26 deletions(-)
arch/arc/kernel/perf_event.c +1 -1
index 2ce24e7..2a90c7a 100644
@@ -525,7 +525,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev)
 		arc_pmu->irq = irq;
 
 		/* intc map function ensures irq_set_percpu_devid() called */
-		request_percpu_irq(irq, arc_pmu_intr, "ARC perf counters",
+		request_percpu_irq(irq, 0, arc_pmu_intr, "ARC perf counters",
 				   this_cpu_ptr(&arc_pmu_cpu));
 
 		on_each_cpu(arc_cpu_pmu_irq_init, &irq, 1);
arch/arc/kernel/smp.c +1 -1
index f462671..5cdd3c9 100644
@@ -381,7 +381,7 @@ int smp_ipi_irq_setup(int cpu, irq_hw_number_t hwirq)
 	if (!cpu) {
 		int rc;
 
-		rc = request_percpu_irq(virq, do_IPI, "IPI Interrupt", dev);
+		rc = request_percpu_irq(virq, 0, do_IPI, "IPI Interrupt", dev);
 		if (rc)
 			panic("Percpu IRQ request failed for %u\n", virq);
 	}
arch/arm/kernel/smp_twd.c +2 -1
index 895ae51..988f9b9 100644
@@ -332,7 +332,8 @@ static int __init twd_local_timer_common_register(struct device_node *np)
 		goto out_free;
 	}
 
-	err = request_percpu_irq(twd_ppi, twd_handler, "twd", twd_evt);
+	err = request_percpu_irq(twd_ppi, IRQF_TIMER, twd_handler, "twd",
+				 twd_evt);
 	if (err) {
 		pr_err("twd: can't register interrupt %d (%d)\n", twd_ppi, err);
 		goto out_free;
arch/arm/xen/enlighten.c +1 -1
index 81e3217..2897f94 100644
@@ -400,7 +400,7 @@ static int __init xen_guest_init(void)
 
 	xen_init_IRQ();
 
-	if (request_percpu_irq(xen_events_irq, xen_arm_callback,
+	if (request_percpu_irq(xen_events_irq, 0, xen_arm_callback,
 			       "events", &xen_vcpu)) {
 		pr_err("Error request IRQ %d\n", xen_events_irq);
 		return -EINVAL;
drivers/clocksource/arc_timer.c +1 -1
index 7517f95..e78e306 100644
@@ -301,7 +301,7 @@ static int __init arc_clockevent_setup(struct device_node *node)
 	}
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
-	ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
+	ret = request_percpu_irq(arc_timer_irq, IRQF_TIMER, timer_irq_handler,
 				 "Timer0 (per-cpu-tick)", evt);
 	if (ret) {
 		pr_err("clockevent: unable to request irq\n");
drivers/clocksource/arm_arch_timer.c +9 -6
index 7a8a411..11398ff 100644
@@ -768,16 +768,19 @@ static int __init arch_timer_register(void)
 	ppi = arch_timer_ppi[arch_timer_uses_ppi];
 	switch (arch_timer_uses_ppi) {
 	case VIRT_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_virt,
-					 "arch_timer", arch_timer_evt);
+		err = request_percpu_irq(ppi, IRQF_TIMER,
+					 arch_timer_handler_virt, "arch_timer",
+					 arch_timer_evt);
 		break;
 	case PHYS_SECURE_PPI:
 	case PHYS_NONSECURE_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_phys,
-					 "arch_timer", arch_timer_evt);
+		err = request_percpu_irq(ppi, IRQF_TIMER,
+					 arch_timer_handler_phys, "arch_timer",
+					 arch_timer_evt);
 		if (!err && arch_timer_ppi[PHYS_NONSECURE_PPI]) {
 			ppi = arch_timer_ppi[PHYS_NONSECURE_PPI];
-			err = request_percpu_irq(ppi, arch_timer_handler_phys,
+			err = request_percpu_irq(ppi, IRQF_TIMER,
+						 arch_timer_handler_phys,
 						 "arch_timer", arch_timer_evt);
 			if (err)
 				free_percpu_irq(arch_timer_ppi[PHYS_SECURE_PPI],
@@ -785,7 +788,7 @@ static int __init arch_timer_register(void)
 		}
 		break;
 	case HYP_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_phys,
+		err = request_percpu_irq(ppi, IRQF_TIMER, arch_timer_handler_phys,
 					 "arch_timer", arch_timer_evt);
 		break;
 	default:
drivers/clocksource/arm_global_timer.c +1 -1
index 123ed20..1262d50 100644
@@ -302,7 +302,7 @@ static int __init global_timer_of_register(struct device_node *np)
 		goto out_clk;
 	}
 
-	err = request_percpu_irq(gt_ppi, gt_clockevent_interrupt,
+	err = request_percpu_irq(gt_ppi, IRQF_TIMER, gt_clockevent_interrupt,
 				 "gt", gt_evt);
 	if (err) {
 		pr_warn("global-timer: can't register interrupt %d (%d)\n",
drivers/clocksource/exynos_mct.c +1 -1
index 670ff0f..6f174bb 100644
@@ -524,7 +524,7 @@ static int __init exynos4_timer_resources(struct device_node *np, void __iomem *
 
 	if (mct_int_type == MCT_INT_PPI) {
 
-		err = request_percpu_irq(mct_irqs[MCT_L0_IRQ],
+		err = request_percpu_irq(mct_irqs[MCT_L0_IRQ], IRQF_TIMER,
 					 exynos4_mct_tick_isr, "MCT",
 					 &percpu_mct_tick);
 		WARN(err, "MCT: can't request IRQ %d (%d)\n",
drivers/clocksource/qcom-timer.c +1 -1
index ee358cd..80dc128 100644
@@ -174,7 +174,7 @@ static int __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,
 	}
 
 	if (percpu)
-		res = request_percpu_irq(irq, msm_timer_interrupt,
+		res = request_percpu_irq(irq, IRQF_TIMER, msm_timer_interrupt,
 					 "gp_timer", msm_evt);
 
 	if (res) {
drivers/clocksource/time-armada-370-xp.c +1 -1
index 4440aef..9643abd 100644
@@ -309,7 +309,7 @@ static int __init armada_370_xp_timer_common_init(struct device_node *np)
 	/*
 	 * Setup clockevent timer (interrupt-driven).
 	 */
-	res = request_percpu_irq(armada_370_xp_clkevt_irq,
+	res = request_percpu_irq(armada_370_xp_clkevt_irq, IRQF_TIMER,
 				armada_370_xp_timer_interrupt,
 				"armada_370_xp_per_cpu_tick",
 				armada_370_xp_evt);
drivers/clocksource/timer-nps.c +1 -1
index da1f798..dbdb622 100644
@@ -256,7 +256,7 @@ static int __init nps_setup_clockevent(struct device_node *node)
 		return ret;
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
-	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler,
+	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler, IRQF_TIMER,
 				 "Timer0 (per-cpu-tick)",
 				 &nps_clockevent_device);
 	if (ret) {
drivers/net/ethernet/marvell/mvneta.c +1 -1
index 61dd446..8004f670 100644
@@ -3517,7 +3517,7 @@ static int mvneta_open(struct net_device *dev)
 		ret = request_irq(pp->dev->irq, mvneta_isr, 0,
 				  dev->name, pp);
 	else
-		ret = request_percpu_irq(pp->dev->irq, mvneta_percpu_isr,
+		ret = request_percpu_irq(pp->dev->irq, 0, mvneta_percpu_isr,
 					 dev->name, pp->ports);
 	if (ret) {
 		netdev_err(pp->dev, "cannot request irq %d\n", pp->dev->irq);
drivers/perf/arm_pmu.c +1 -1
index 9612b84..0f5ab4a 100644
@@ -661,7 +661,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
 
 	irq = platform_get_irq(pmu_device, 0);
 	if (irq > 0 && irq_is_percpu(irq)) {
-		err = request_percpu_irq(irq, handler, "arm-pmu",
+		err = request_percpu_irq(irq, 0, handler, "arm-pmu",
 					 &hw_events->percpu_pmu);
 		if (err) {
 			pr_err("unable to request IRQ%d for ARM PMU counters\n",
include/linux/interrupt.h +3 -2
index 53144e7..bc3b675 100644
@@ -152,8 +152,9 @@ struct irqaction {
 			unsigned long flags, const char *name, void *dev_id);
 
 extern int __must_check
-request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+request_percpu_irq(unsigned int irq, unsigned long flags,
+		   irq_handler_t handler,  const char *devname,
+		   void __percpu *percpu_dev_id);
 
 extern void free_irq(unsigned int, void *);
 extern void free_percpu_irq(unsigned int, void __percpu *);
kernel/irq/manage.c +8 -3
index a4afe5c..c0a23e2 100644
@@ -1951,6 +1951,7 @@ int setup_percpu_irq(unsigned int irq, struct irqaction *act)
 /**
  *	request_percpu_irq - allocate a percpu interrupt line
  *	@irq: Interrupt line to allocate
+ *	@flags: Interrupt type flags (IRQF_TIMER only)
  *	@handler: Function to be called when the IRQ occurs.
  *	@devname: An ascii name for the claiming device
  *	@dev_id: A percpu cookie passed back to the handler function
@@ -1964,8 +1965,9 @@ int setup_percpu_irq(unsigned int irq, struct irqaction *act)
  *	the handler gets called with the interrupted CPU's instance of
  *	that variable.
  */
-int request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		       const char *devname, void __percpu *dev_id)
+int request_percpu_irq(unsigned int irq, unsigned long flags,
+		       irq_handler_t handler, const char *devname,
+		       void __percpu *dev_id)
 {
 	struct irqaction *action;
 	struct irq_desc *desc;
@@ -1979,12 +1981,15 @@ int request_percpu_irq(unsigned int irq, irq_handler_t handler,
 	    !irq_settings_is_per_cpu_devid(desc))
 		return -EINVAL;
 
+	if (flags && flags != IRQF_TIMER)
+		return -EINVAL;
+
 	action = kzalloc(sizeof(struct irqaction), GFP_KERNEL);
 	if (!action)
 		return -ENOMEM;
 
 	action->handler = handler;
-	action->flags = IRQF_PERCPU | IRQF_NO_SUSPEND;
+	action->flags = flags | IRQF_PERCPU | IRQF_NO_SUSPEND;
 	action->name = devname;
 	action->percpu_dev_id = dev_id;
 
virt/kvm/arm/arch_timer.c +3 -2
index 35d7100..54809c8 100644
@@ -523,8 +523,9 @@ int kvm_timer_hyp_init(void)
 		host_vtimer_irq_flags = IRQF_TRIGGER_LOW;
 	}
 
-	err = request_percpu_irq(host_vtimer_irq, kvm_arch_timer_handler,
-				 "kvm guest timer", kvm_get_running_vcpus());
+	err = request_percpu_irq(host_vtimer_irq, IRQF_TIMER,
+				 kvm_arch_timer_handler, "kvm guest timer",
+				 kvm_get_running_vcpus());
 	if (err) {
 		kvm_err("kvm_arch_timer: can't request interrupt %d (%d)\n",
 			host_vtimer_irq, err);
virt/kvm/arm/vgic/vgic-init.c +1 -1
index 276139a..a34d315 100644
@@ -430,7 +430,7 @@ int kvm_vgic_hyp_init(void)
 		return ret;
 
 	kvm_vgic_global_state.maint_irq = gic_kvm_info->maint_irq;
-	ret = request_percpu_irq(kvm_vgic_global_state.maint_irq,
+	ret = request_percpu_irq(kvm_vgic_global_state.maint_irq, 0,
 				 vgic_maintenance_handler,
 				 "vgic", kvm_get_running_vcpus());
 	if (ret) {
Signature · 1 line
1.9.1
#1 lore raw

PATCH v8 2/3 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 timestamp for each interrupt occurrences in a per-CPU circular buffer to help with the prediction of the next occurrence using a statistical model.

Each CPU can store IRQ_TIMINGS_SIZE events <irq, timestamp>, the current value of IRQ_TIMINGS_SIZE is 32.

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.

It results in most of the code in internals.h for inline reason and a very few in the new file timings.c. The latter will contain more in the next patch which will provide the statistical model for the next event prediction.

Note this code is by default *not* compiled in the kernel.

---
V8:
- Replaced percpu field in the irqdesc by a percpu array containing the timings and the associated irq. The function irq_timings_get_next() is no longer needed, so it is removed
- Removed all unused code resulting from the conversion irqdesc->percpu timings storage
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 |  5 ++++
 kernel/irq/Kconfig        |  3 +++
 kernel/irq/Makefile       |  1 +
 kernel/irq/handle.c       |  2 ++
 kernel/irq/internals.h    | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 kernel/irq/manage.c       |  3 +++
 kernel/irq/timings.c      | 30 +++++++++++++++++++++
 7 files changed, 111 insertions(+)
 create mode 100644 kernel/irq/timings.c
include/linux/interrupt.h +5 -0
index bc3b675..c050333 100644
@@ -704,6 +704,11 @@ static inline void init_irq_proc(void)
 }
 #endif
 
+#ifdef CONFIG_IRQ_TIMINGS
+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);
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 1d3ee31..efb5f14 100644
@@ -10,3 +10,4 @@ obj-$(CONFIG_PM_SLEEP) += pm.o
 obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
 obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o
 obj-$(CONFIG_SMP) += affinity.o
+obj-$(CONFIG_IRQ_TIMINGS) += timings.o
kernel/irq/handle.c +2 -0
index d3f2490..eb4d3e8 100644
@@ -138,6 +138,8 @@ irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags
 	unsigned int 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 +67 -0

82 lines not on this page · raw message

kernel/irq/manage.c +3 -0
index c0a23e2..da799d3 100644
@@ -1370,6 +1370,8 @@ static void irq_release_resources(struct irq_desc *desc)
 
 	raw_spin_unlock_irqrestore(&desc->lock, flags);
 
+	setup_timings(desc, new);
+
 	/*
 	 * Strictly no need to wake it up, but hung_task complains
 	 * when no hard interrupt wakes the thread up.
@@ -1498,6 +1500,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 +30 -0
new file mode 100644
index 0000000..21ceca8
@@ -0,0 +1,30 @@
+/*
+ * linux/kernel/irq/timings.c
+ *
+ * Copyright (C) 2016, Linaro Ltd - Daniel Lezcano <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/percpu.h>
+#include <linux/static_key.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+
+#include "internals.h"
+
+DEFINE_STATIC_KEY_FALSE(irq_timing_enabled);
+
+DEFINE_PER_CPU(struct irq_timings, irq_timings);
+
+void irq_timings_enable(void)
+{
+	static_branch_inc(&irq_timing_enabled);
+}
+
+void irq_timings_disable(void)
+{
+	static_branch_dec(&irq_timing_enabled);
+}
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc) · line 279

Quoted 11 lines · Daniel Lezcano
kernel/irq/internals.h +11 -0
+/*
+ * The function record_irq_time is only called in one place in the
+ * interrupts handler. We want this function always inline so the code
+ * inside is embedded in the function and the static key branching
+ * code can act at the higher level. Without the explicit
+ * __always_inline we can end up with a function call and a small
+ * overhead in the hotpath for nothing.
+ */
+static __always_inline void record_irq_time(struct irq_desc *desc)
+{
+	if (static_key_enabled(&irq_timing_enabled)) {

I think you meant to have either static_branch_likely() or static_branch_unlikely() here. Those are runtime code patched, static_key_enabled() generates a regular load and test condition.

Also; if you do something like:

	if (!static_branch_likely(&irq_timing_enabled))
		return;

you can save one level of indent.

Quoted 10 lines
kernel/irq/internals.h +10 -0
+		if (desc->istate & IRQS_TIMINGS) {
+			struct irq_timings *timings = this_cpu_ptr(&irq_timings);
+			unsigned int index = timings->count & IRQ_TIMINGS_MASK;
+
+			timings->values[index].ts = local_clock();
+			timings->values[index].irq = irq_desc_get_irq(desc);
+			timings->count++;
+		}
+	}
+}

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc)

Quoted 10 lines
kernel/irq/internals.h +7 -0
 
 
 
+DEFINE_STATIC_KEY_FALSE(irq_timing_enabled);
+
+DEFINE_PER_CPU(struct irq_timings, irq_timings);
+
+void irq_timings_enable(void)
+{
+	static_branch_inc(&irq_timing_enabled);

Do you really need counting, or do you want static_branch_enable() here?

kernel/irq/timings.c line 29

Quoted 5 lines
kernel/irq/timings.c new file +5 -0
+}
+
+void irq_timings_disable(void)
+{
+	static_branch_dec(&irq_timing_enabled);

idem.

Quoted 4 lines

+}

Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

Quoted 17 lines · Peter Zijlstra

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc) · line 279

Quoted 11 lines · Daniel Lezcano
kernel/irq/internals.h +11 -0
+/*
+ * The function record_irq_time is only called in one place in the
+ * interrupts handler. We want this function always inline so the code
+ * inside is embedded in the function and the static key branching
+ * code can act at the higher level. Without the explicit
+ * __always_inline we can end up with a function call and a small
+ * overhead in the hotpath for nothing.
+ */
+static __always_inline void record_irq_time(struct irq_desc *desc)
+{
+	if (static_key_enabled(&irq_timing_enabled)) {

I think you meant to have either static_branch_likely() or static_branch_unlikely() here. Those are runtime code patched, static_key_enabled() generates a regular load and test condition.

Quoted 6 lines

Also; if you do something like:

	if (!static_branch_likely(&irq_timing_enabled))
		return;

you can save one level of indent.

Ok, thanks for the hint.

Quoted 13 lines
Quoted 10 lines
kernel/irq/internals.h +10 -0
+		if (desc->istate & IRQS_TIMINGS) {
+			struct irq_timings *timings = this_cpu_ptr(&irq_timings);
+			unsigned int index = timings->count & IRQ_TIMINGS_MASK;
+
+			timings->values[index].ts = local_clock();
+			timings->values[index].irq = irq_desc_get_irq(desc);
+			timings->count++;
+		}
+	}
+}
Quoted 9 lines

kernel/irq/timings.c line 24

Quoted 7 lines
kernel/irq/timings.c new file +7 -0
+DEFINE_STATIC_KEY_FALSE(irq_timing_enabled);
+
+DEFINE_PER_CPU(struct irq_timings, irq_timings);
+
+void irq_timings_enable(void)
+{
+	static_branch_inc(&irq_timing_enabled);

Do you really need counting, or do you want static_branch_enable() here?

I put counting in order to let several subsystem to use the irq timings if it is needed.

Quoted 12 lines

kernel/irq/timings.c line 29

Quoted 5 lines
kernel/irq/timings.c new file +5 -0
+}
+
+void irq_timings_disable(void)
+{
+	static_branch_dec(&irq_timing_enabled);

idem.

Quoted 4 lines

+}

Signature · 1 line
1.9.1
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

Re: [PATCH V8 2/3] irq: Track the interrupt timings

Quoted 10 lines · Daniel Lezcano
Quoted 6 lines · Peter Zijlstra

kernel/irq/timings.c line 24

Quoted 3 lines · Daniel Lezcano
kernel/irq/timings.c new file +3 -0
+void irq_timings_enable(void)
+{
+	static_branch_inc(&irq_timing_enabled);

Do you really need counting, or do you want static_branch_enable() here?

I put counting in order to let several subsystem to use the irq timings if it is needed.

Please avoid overengineering. This can easily be changed later if it is needed.

Nicolas

#5 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

In reply to Daniel Lezcano

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc) · line 244

Quoted 11 lines · Daniel Lezcano
kernel/irq/internals.h +11 -0
+#define IRQ_TIMINGS_SHIFT	5
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timing {
+	u32 irq;
+	u64 ts;
+};
+
+struct irq_timings {
+	struct irq_timing values[IRQ_TIMINGS_SIZE]; /* our circular buffer */

This is not very space efficient because of alignment restrictions from the u64 in struct irq_timing. 25% of the memory is wasted.

You could consider having two arrays instead:

	u32 irq_values[IRQ_TIMINGS_SIZE];
	u64 ts_values[IRQ_TIMINGS_SIZE];

Nicolas

#6 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

Quoted 17 lines · Nicolas Pitre

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc) · line 244

Quoted 11 lines · Daniel Lezcano
kernel/irq/internals.h +11 -0
+#define IRQ_TIMINGS_SHIFT	5
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timing {
+	u32 irq;
+	u64 ts;
+};
+
+struct irq_timings {
+	struct irq_timing values[IRQ_TIMINGS_SIZE]; /* our circular buffer */

This is not very space efficient because of alignment restrictions from the u64 in struct irq_timing. 25% of the memory is wasted.

Quoted 4 lines

You could consider having two arrays instead:

	u32 irq_values[IRQ_TIMINGS_SIZE];
	u64 ts_values[IRQ_TIMINGS_SIZE];

For the penalty of dirtying two cachelines instead of one.

Thanks,

tglx

#7 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

Quoted 19 lines · Thomas Gleixner
Quoted 17 lines · Nicolas Pitre

kernel/irq/internals.h static inline int irq_desc_is_chained(struct irq_desc *desc) · line 244

Quoted 11 lines · Daniel Lezcano
kernel/irq/internals.h +11 -0
+#define IRQ_TIMINGS_SHIFT	5
+#define IRQ_TIMINGS_SIZE	(1 << IRQ_TIMINGS_SHIFT)
+#define IRQ_TIMINGS_MASK	(IRQ_TIMINGS_SIZE - 1)
+
+struct irq_timing {
+	u32 irq;
+	u64 ts;
+};
+
+struct irq_timings {
+	struct irq_timing values[IRQ_TIMINGS_SIZE]; /* our circular buffer */

This is not very space efficient because of alignment restrictions from the u64 in struct irq_timing. 25% of the memory is wasted.

Quoted 6 lines
Quoted 4 lines

You could consider having two arrays instead:

	u32 irq_values[IRQ_TIMINGS_SIZE];
	u64 ts_values[IRQ_TIMINGS_SIZE];

For the penalty of dirtying two cachelines instead of one.

Well...

Is there a need for 64 bits of relative time stamps? And 32 bits of IRQ number?

I'd say that 48 bit time stamp and 16 bit IRQ number is way sufficient. Who cares if we mispredict an IRQ after 78 hours of idle time?

Hence:

	u64 value = (ts << 16) | irq;

Nicolas

#8 lore raw

Re: [PATCH V8 2/3] irq: Track the interrupt timings

Quoted 2 lines · Nicolas Pitre

Is there a need for 64 bits of relative time stamps? And 32 bits of IRQ number?

No.

Quoted 6 lines

I'd say that 48 bit time stamp and 16 bit IRQ number is way sufficient. Who cares if we mispredict an IRQ after 78 hours of idle time?

Hence:

	u64 value = (ts << 16) | irq;

Excellent!

#9 lore raw

PATCH v8 3/3 irq: Compute the periodic interval for interrupts

In reply to Daniel Lezcano

An interrupt behaves with a burst of activity with periodic interval of time followed by one or two peaks of longer interval.

As the time intervals are periodic, statistically speaking they follow a normal distribution and each interrupts can be tracked individually.

This patch does statistics on all interrupts, except the timers which are deterministic by essence. The goal is to extract the periodicity for each interrupt, with the last timestamp and sum them, so we have the next event.

Taking the earliest prediction gives the expected wakeup on the system (assuming a timer won't expire before).

As stated in the previous patch, this code is not enabled in the kernel by default.

---
 include/linux/interrupt.h |   1 +
 kernel/irq/internals.h    |  19 +++
 kernel/irq/timings.c      | 344 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 364 insertions(+)
include/linux/interrupt.h +1 -0
index c050333..62bb0c9 100644
@@ -707,6 +707,7 @@ static inline void init_irq_proc(void)
 #ifdef CONFIG_IRQ_TIMINGS
 void irq_timings_enable(void);
 void irq_timings_disable(void);
+u64 irq_timings_next_event(u64 now);
 #endif
 
 struct seq_file;
kernel/irq/internals.h +19 -0
index abaadaa..677c1a2 100644
@@ -247,13 +247,21 @@ struct irq_timings {
 
 DECLARE_PER_CPU(struct irq_timings, irq_timings);
 
+extern void irq_timings_free(int irq);
+extern int irq_timings_alloc(int irq);
+
 static inline void remove_timings(struct irq_desc *desc)
 {
 	desc->istate &= ~IRQS_TIMINGS;
+
+	irq_timings_free(irq_desc_get_irq(desc));
 }
 
 static inline void setup_timings(struct irq_desc *desc, struct irqaction *act)
 {
+	int irq = irq_desc_get_irq(desc);
+	int ret;
+
 	/*
 	 * We don't need the measurement because the idle code already
 	 * knows the next expiry event.
@@ -261,6 +269,17 @@ static inline void setup_timings(struct irq_desc *desc, struct irqaction *act)
 	if (act->flags & __IRQF_TIMER)
 		return;
 
+	/*
+	 * In case the timing allocation fails, we just want to warn,
+	 * not fail, so letting the system boot anyway.
+	 */
+	ret = irq_timings_alloc(irq);
+	if (ret) {
+		pr_warn("Failed to allocate irq timing stats for irq%d (%d)",
+			irq, ret);
+		return;
+	}
+
 	desc->istate |= IRQS_TIMINGS;
 }
 
kernel/irq/timings.c +344 -0

362 lines not on this page · raw message

Signature · 1 line
1.9.1
#10 lore raw

Re: [PATCH V8 3/3] irq: Compute the periodic interval for interrupts

kernel/irq/timings.c void irq_timings_disable(void) · line 167

Quoted 6 lines · Daniel Lezcano
kernel/irq/timings.c +6 -0
+	/*
+	 * Online variance divided by the number of elements if there
+	 * is more than one sample.
+	 */
+	if (likely(irqs->count > 1))
+		variance = div_u64(irqs->variance, irqs->count - 1);

Isn't it mostly likely that irqs->count will be equal to IRQ_TIMINGS_SIZE in most cases? And if so, given that IRQ_TIMINGS_SIZE == 32, we _could_ possibly approximate the division by 31 with a division by 32 without affecting too much the final outcome. Then the very expensive div_u64() could be replaced by:

	variance = irqs->variance >> 5;

Or at least keep a constant divisor that div_u64() is able to optimize with a reciprocal multiplication.

This is even more important by the fact that this function is called in a loop, up to IRQ_TIMINGS_SIZE times.

Quoted 29 lines
kernel/irq/timings.c +29 -0
+	 * The rule of thumb in statistics for the normal distribution
+	 * is having at least 30 samples in order to have the model to
+	 * apply. Values outside the interval are considered as an
+	 * anomaly.
+	 */
+	if ((irqs->count >= 30) && ((diff * diff) > (9 * variance))) {
+		/*
+		 * After three consecutive anomalies, we reset the
+		 * stats as it is no longer stable enough.
+		 */
+		if (irqs->anomalies++ >= 3) {
+			memset(irqs, 0, sizeof(*irqs));
+			irqs->lts = ts;
+			return;
+		}
+	} else {
+		/*
+		 * The anomalies must be consecutives, so at this
+		 * point, we reset the anomalies counter.
+		 */
+		irqs->anomalies = 0;
+	}
+
+	/*
+	 * The interrupt is considered stable enough to try to predict
+	 * the next event on it.
+	 */
+	irqs->valid = 1;
+

kernel/irq/timings.c void irq_timings_disable(void) · line 208

Quoted 10 lines
kernel/irq/timings.c +10 -0
+	/*
+	 * Online average algorithm:
+	 *
+	 *  new_average = average + ((value - average) / count)
+	 *
+	 * The variance computation depends on the new average
+	 * to be computed here first.
+	 *
+	 */
+	irqs->avg = irqs->avg + div_s64(diff, irqs->count);

Why not computing the average outside this function in a loop of its own? This way you'd have only one division to perform instead of 32. The above is also skewed as it gives way more weight to the initial samples when irqs->count is still low.

Nicolas

#11 lore raw

Re: [PATCH V8 3/3] irq: Compute the periodic interval for interrupts

Quoted 15 lines · Nicolas Pitre

kernel/irq/timings.c void irq_timings_disable(void) · line 167

Quoted 6 lines · Daniel Lezcano
kernel/irq/timings.c +6 -0
+	/*
+	 * Online variance divided by the number of elements if there
+	 * is more than one sample.
+	 */
+	if (likely(irqs->count > 1))
+		variance = div_u64(irqs->variance, irqs->count - 1);

Isn't it mostly likely that irqs->count will be equal to IRQ_TIMINGS_SIZE in most cases? And if so, given that IRQ_TIMINGS_SIZE == 32, we _could_ possibly approximate the division by 31 with a division by 32 without affecting too much the final outcome. Then the very expensive div_u64() could be replaced by:

Quoted 7 lines
	variance = irqs->variance >> 5;

Or at least keep a constant divisor that div_u64() is able to optimize with a reciprocal multiplication.

This is even more important by the fact that this function is called in a loop, up to IRQ_TIMINGS_SIZE times.

There is no general rule about that. Depending on the load of the system, the cpu number, etc ... they can be a few or a the max or in between.

Quoted 36 lines
Quoted 36 lines
kernel/irq/timings.c +36 -0
+	 * The rule of thumb in statistics for the normal distribution
+	 * is having at least 30 samples in order to have the model to
+	 * apply. Values outside the interval are considered as an
+	 * anomaly.
+	 */
+	if ((irqs->count >= 30) && ((diff * diff) > (9 * variance))) {
+		/*
+		 * After three consecutive anomalies, we reset the
+		 * stats as it is no longer stable enough.
+		 */
+		if (irqs->anomalies++ >= 3) {
+			memset(irqs, 0, sizeof(*irqs));
+			irqs->lts = ts;
+			return;
+		}
+	} else {
+		/*
+		 * The anomalies must be consecutives, so at this
+		 * point, we reset the anomalies counter.
+		 */
+		irqs->anomalies = 0;
+	}
+
+	/*
+	 * The interrupt is considered stable enough to try to predict
+	 * the next event on it.
+	 */
+	irqs->valid = 1;
+
+	/*
+	 * Online average algorithm:
+	 *
+	 *  new_average = average + ((value - average) / count)
+	 *
+	 * The variance computation depends on the new average
+	 * to be computed here first.
Quoted 8 lines

kernel/irq/timings.c void irq_timings_disable(void) · line 208

Quoted 3 lines
kernel/irq/timings.c +3 -0
+	 *
+	 */
+	irqs->avg = irqs->avg + div_s64(diff, irqs->count);

Why not computing the average outside this function in a loop of its own? This way you'd have only one division to perform instead of 32. The above is also skewed as it gives way more weight to the initial samples when irqs->count is still low.

Actually, stabilizing the math in this function has been the major effort with this patch.

Changing the above won't save us anything because we have to compute the variance each time in order to put apart the new value or not.

I understand a div64 can be scary but, I would like to put in place the framework. Then we can think about optimizing the code.

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
Acked-by on v8 1/3
#12 lore raw
In reply to Daniel Lezcano
Quoted 6 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

But, the API request_percpu_irq does not allow to pass a flag, hence specifying if the interrupt type is a timer.

Quoted 8 lines

Solve this by passing a 'flags' parameter to the function and change all the callers to pass IRQF_TIMER when the interrupt is a timer interrupt, zero otherwise.

For now, in order to prevent a misusage of this parameter, only the IRQF_TIMER flag is a valid parameter to be passed to the request_percpu_irq function.

Acked-by on v8 1/3
#13 lore raw
In reply to Daniel Lezcano
Quoted 6 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

But, the API request_percpu_irq does not allow to pass a flag, hence specifying if the interrupt type is a timer.

Quoted 8 lines

Solve this by passing a 'flags' parameter to the function and change all the callers to pass IRQF_TIMER when the interrupt is a timer interrupt, zero otherwise.

For now, in order to prevent a misusage of this parameter, only the IRQF_TIMER flag is a valid parameter to be passed to the request_percpu_irq function.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

maintainer
#14 lore raw
In reply to Daniel Lezcano

Hi Daniel,

Quoted 2 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

Sorry, but I could not parse this.

[...]

drivers/perf/arm_pmu.c static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) · line 667

Quoted 13 lines
drivers/perf/arm_pmu.c +1 -1
index 9612b84..0f5ab4a 100644
@@ -661,7 +661,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
 
 	irq = platform_get_irq(pmu_device, 0);
 	if (irq > 0 && irq_is_percpu(irq)) {
-		err = request_percpu_irq(irq, handler, "arm-pmu",
+		err = request_percpu_irq(irq, 0, handler, "arm-pmu",
 					 &hw_events->percpu_pmu);
 		if (err) {
 			pr_err("unable to request IRQ%d for ARM PMU counters\n",

Please Cc myself and Will Deacon when modifying the arm_pmu driver, as per MAINTAINERS. I only spotted this patch by chance.

This conflicts with arm_pmu changes I have queued for v4.12 [1].

So, can we leave the prototype of request_percpu_irq() as-is?

Why not add a new request_percpu_irq_flags() function, and leave request_percpu_irq() as a wrapper for that? e.g.

static inline int
request_percpu_irq(unsigned int irq, irq_handler_t handler,
const char *devname, void __percpu *percpu_dev_id)

{
	return request_percpu_irq_flags(irq, handler, devname,
					percpu_dev_id, 0);
}

... that would avoid having to touch any non-timer driver for now.

[...]

drivers/perf/arm_pmu.c

Quoted 6 lines
drivers/perf/arm_pmu.c +3 -2
-request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+request_percpu_irq(unsigned int irq, unsigned long flags,
+		   irq_handler_t handler,  const char *devname,
+		   void __percpu *percpu_dev_id);

Looking at request_irq, the prototype is:

int __must_check
request_irq(unsigned int irq, irq_handler_t handler,

	    unsigned long flags, const char *name,
	    void *dev);

... surely it would be better to share the same argument order? i.e.

int __must_check
request_percpu_irq(unsigned int irq, irq_handler_t handler,

		   unsigned long flags, const char *devname,
		   void __percpu *percpu_dev_id);

Thanks,
Mark.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm/perf/refactoring

#15 lore raw

Hi Mark,

Quoted 7 lines · Mark Rutland

Hi Daniel,

Quoted 2 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

Sorry, but I could not parse this.

I meant we are measuring when are happening the interrupts by getting the local clock in the interrupt handler. But if the interrupts are coming from a timer, it is not necessary to do that because we already know when they will occur.

So, in order to sort out which interrupt we measure, we use the IRQF_TIMER flag.

Unfortunately, this flag is missing when we do a request_percpu_irq. The purpose of this patch is to fix that.

Quoted 6 lines
Quoted 6 lines
drivers/perf/arm_pmu.c +0 -0
index 9612b84..0f5ab4a 100644
@@ -661,7 +661,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
 
Quoted 10 lines

drivers/perf/arm_pmu.c static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) · line 667

Quoted 7 lines
drivers/perf/arm_pmu.c +1 -1
 	irq = platform_get_irq(pmu_device, 0);
 	if (irq > 0 && irq_is_percpu(irq)) {
-		err = request_percpu_irq(irq, handler, "arm-pmu",
+		err = request_percpu_irq(irq, 0, handler, "arm-pmu",
 					 &hw_events->percpu_pmu);
 		if (err) {
 			pr_err("unable to request IRQ%d for ARM PMU counters\n",

Please Cc myself and Will Deacon when modifying the arm_pmu driver, as per MAINTAINERS. I only spotted this patch by chance.

Ah, ok, sorry for that. Thanks for spotting this, you should have been Cc'ed by my cccmd script. I will check that.

Quoted 6 lines

This conflicts with arm_pmu changes I have queued for v4.12 [1].

So, can we leave the prototype of request_percpu_irq() as-is?

Why not add a new request_percpu_irq_flags() function, and leave request_percpu_irq() as a wrapper for that? e.g.

[ ... ]

Quoted 9 lines

static inline int
request_percpu_irq(unsigned int irq, irq_handler_t handler,
const char *devname, void __percpu *percpu_dev_id)

{
	return request_percpu_irq_flags(irq, handler, devname,
					percpu_dev_id, 0);
}

... that would avoid having to touch any non-timer driver for now.

Mmh, yes. That's a good suggestion.

Quoted 16 lines

[...]

drivers/perf/arm_pmu.c

Quoted 6 lines
drivers/perf/arm_pmu.c +3 -2
-request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+request_percpu_irq(unsigned int irq, unsigned long flags,
+		   irq_handler_t handler,  const char *devname,
+		   void __percpu *percpu_dev_id);

Looking at request_irq, the prototype is:

int __must_check
request_irq(unsigned int irq, irq_handler_t handler,

	    unsigned long flags, const char *name,
	    void *dev);
Quoted 7 lines

... surely it would be better to share the same argument order? i.e.

int __must_check
request_percpu_irq(unsigned int irq, irq_handler_t handler,

		   unsigned long flags, const char *devname,
		   void __percpu *percpu_dev_id);

Agree.

Thanks for the review.

-- Daniel

Signature · 9 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
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#16 lore raw
In reply to Mark Rutland

Hi Mark,

Quoted 7 lines · Mark Rutland

Hi Daniel,

Quoted 2 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

Sorry, but I could not parse this.

I meant we are measuring when are happening the interrupts by getting the local clock in the interrupt handler. But if the interrupts are coming from a timer, it is not necessary to do that because we already know when they will occur.

So, in order to sort out which interrupt we measure, we use the IRQF_TIMER flag.

Unfortunately, this flag is missing when we do a request_percpu_irq. The purpose of this patch is to fix that.

Quoted 6 lines
Quoted 6 lines
drivers/perf/arm_pmu.c +0 -0
index 9612b84..0f5ab4a 100644
@@ -661,7 +661,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
 
Quoted 10 lines

drivers/perf/arm_pmu.c static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) · line 667

Quoted 7 lines
drivers/perf/arm_pmu.c +1 -1
 	irq = platform_get_irq(pmu_device, 0);
 	if (irq > 0 && irq_is_percpu(irq)) {
-		err = request_percpu_irq(irq, handler, "arm-pmu",
+		err = request_percpu_irq(irq, 0, handler, "arm-pmu",
 					 &hw_events->percpu_pmu);
 		if (err) {
 			pr_err("unable to request IRQ%d for ARM PMU counters\n",

Please Cc myself and Will Deacon when modifying the arm_pmu driver, as per MAINTAINERS. I only spotted this patch by chance.

Ah, ok, sorry for that. Thanks for spotting this, you should have been Cc'ed by my cccmd script. I will check that.

Quoted 6 lines

This conflicts with arm_pmu changes I have queued for v4.12 [1].

So, can we leave the prototype of request_percpu_irq() as-is?

Why not add a new request_percpu_irq_flags() function, and leave request_percpu_irq() as a wrapper for that? e.g.

[ ... ]

Quoted 9 lines

static inline int
request_percpu_irq(unsigned int irq, irq_handler_t handler,
const char *devname, void __percpu *percpu_dev_id)

{
	return request_percpu_irq_flags(irq, handler, devname,
					percpu_dev_id, 0);
}

... that would avoid having to touch any non-timer driver for now.

Mmh, yes. That's a good suggestion.

Quoted 16 lines

[...]

drivers/perf/arm_pmu.c

Quoted 6 lines
drivers/perf/arm_pmu.c +3 -2
-request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+request_percpu_irq(unsigned int irq, unsigned long flags,
+		   irq_handler_t handler,  const char *devname,
+		   void __percpu *percpu_dev_id);

Looking at request_irq, the prototype is:

int __must_check
request_irq(unsigned int irq, irq_handler_t handler,

	    unsigned long flags, const char *name,
	    void *dev);
Quoted 7 lines

... surely it would be better to share the same argument order? i.e.

int __must_check
request_percpu_irq(unsigned int irq, irq_handler_t handler,

		   unsigned long flags, const char *devname,
		   void __percpu *percpu_dev_id);

Agree.

Thanks for the review.

-- Daniel

Signature · 10 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

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
maintainer
#17 lore raw
In reply to Daniel Lezcano

Hi Daniel,

Quoted 2 lines · Daniel Lezcano

In the next changes, we track the interrupts but we discard the timers as that does not make sense. The next interrupt on a timer is predictable.

Sorry, but I could not parse this.

[...]

drivers/perf/arm_pmu.c static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) · line 667

Quoted 13 lines
drivers/perf/arm_pmu.c +1 -1
index 9612b84..0f5ab4a 100644
@@ -661,7 +661,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
 
 	irq = platform_get_irq(pmu_device, 0);
 	if (irq > 0 && irq_is_percpu(irq)) {
-		err = request_percpu_irq(irq, handler, "arm-pmu",
+		err = request_percpu_irq(irq, 0, handler, "arm-pmu",
 					 &hw_events->percpu_pmu);
 		if (err) {
 			pr_err("unable to request IRQ%d for ARM PMU counters\n",

Please Cc myself and Will Deacon when modifying the arm_pmu driver, as per MAINTAINERS. I only spotted this patch by chance.

This conflicts with arm_pmu changes I have queued for v4.12 [1].

So, can we leave the prototype of request_percpu_irq() as-is?

Why not add a new request_percpu_irq_flags() function, and leave request_percpu_irq() as a wrapper for that? e.g.

static inline int
request_percpu_irq(unsigned int irq, irq_handler_t handler,
const char *devname, void __percpu *percpu_dev_id)

{
	return request_percpu_irq_flags(irq, handler, devname,
					percpu_dev_id, 0);
}

... that would avoid having to touch any non-timer driver for now.

[...]

drivers/perf/arm_pmu.c

Quoted 6 lines
drivers/perf/arm_pmu.c +3 -2
-request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+request_percpu_irq(unsigned int irq, unsigned long flags,
+		   irq_handler_t handler,  const char *devname,
+		   void __percpu *percpu_dev_id);

Looking at request_irq, the prototype is:

int __must_check
request_irq(unsigned int irq, irq_handler_t handler,

	    unsigned long flags, const char *name,
	    void *dev);

... surely it would be better to share the same argument order? i.e.

int __must_check
request_percpu_irq(unsigned int irq, irq_handler_t handler,

		   unsigned long flags, const char *devname,
		   void __percpu *percpu_dev_id);

Thanks,
Mark.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=arm/perf/refactoring

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw
In reply to Daniel Lezcano

drivers/clocksource/timer-nps.c static int __init nps_setup_clockevent(struct device_node *node) · line 261

Quoted 12 lines · Daniel Lezcano
drivers/clocksource/timer-nps.c +1 -1
index da1f798..dbdb622 100644
@@ -256,7 +256,7 @@ static int __init nps_setup_clockevent(struct device_node *node)
 		return ret;
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
-	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler,
+	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler, IRQF_TIMER,
 				 "Timer0 (per-cpu-tick)",
 				 &nps_clockevent_device);

Wrong parameter order here.

drew

#19 lore raw
In reply to Daniel Lezcano

drivers/clocksource/timer-nps.c static int __init nps_setup_clockevent(struct device_node *node) · line 261

Quoted 12 lines · Daniel Lezcano
drivers/clocksource/timer-nps.c +1 -1
index da1f798..dbdb622 100644
@@ -256,7 +256,7 @@ static int __init nps_setup_clockevent(struct device_node *node)
 		return ret;
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
-	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler,
+	ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler, IRQF_TIMER,
 				 "Timer0 (per-cpu-tick)",
 				 &nps_clockevent_device);

Wrong parameter order here.

drew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel