public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL V10] irq: next irq tracking
@ 2017-06-12 13:51 Daniel Lezcano
  2017-06-12 13:52 ` [PATCH V10 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Daniel Lezcano
  2017-06-20 11:56 ` [GIT PULL V10] irq: next irq tracking Daniel Lezcano
  0 siblings, 2 replies; 11+ messages in thread
From: Daniel Lezcano @ 2017-06-12 13:51 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel, Vincent Guittot, Peter Zijlstra, Rafael J . Wysocki,
	Nicolas Pitre

Hi Thomas,

this pull request contains the next irq prediction as posted for V10
[1] which takes into account all the commments. It is based on top of
v4.12-rc5.

As previously discussed the code is not enabled by default, hence compiled out.

The first patch adds the IRQF_TIMER flag to the timers which are percpu in
order to discard any timing measurement when the interrupt is coming from a
timer.

The second patch adds a circular buffer and the small routine to store the
local time when an interrupt occurs. The t-uple <irq,timestamp> are encoded
together into a single 64bits as suggested by Nicolas Pitre.

The third patch provides the mathematic to compute the regular intervals. The
rational is in changelog and the math is commented in details in the code.

Thanks.

  -- Daniel

[1] https://www.spinics.net/lists/kernel/msg2509177.html


The following changes since commit 32c1431eea4881a6b17bd7c639315010aeefa452:

  Linux 4.12-rc5 (2017-06-11 16:48:20 -0700)

are available in the git repository at:

  http://git@git.linaro.org/people/daniel.lezcano/linux.git next-irq/4.13

for you to fetch changes up to 1ed971bc878ede444d10f8a24bc9963938f0b7c6:

  irq: Compute the periodic interval for interrupts (2017-06-12 15:06:00 +0200)

----------------------------------------------------------------
Daniel Lezcano (3):
      irq: Allow to pass the IRQF_TIMER flag with percpu irq request
      irq: Track the interrupt timings
      irq: Compute the periodic interval for interrupts

 arch/arm/kernel/smp_twd.c                |   3 +-
 drivers/clocksource/arc_timer.c          |   4 +--
 drivers/clocksource/arm_arch_timer.c     |  20 ++++++++-----
 drivers/clocksource/arm_global_timer.c   |   4 +--
 drivers/clocksource/exynos_mct.c         |   7 +++--
 drivers/clocksource/qcom-timer.c         |   4 +--
 drivers/clocksource/time-armada-370-xp.c |   9 +++---
 drivers/clocksource/timer-nps.c          |   6 ++--
 include/linux/interrupt.h                |  17 ++++++++++-
 kernel/irq/Kconfig                       |   3 ++
 kernel/irq/Makefile                      |   1 +
 kernel/irq/handle.c                      |   2 ++
 kernel/irq/internals.h                   | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/irq/manage.c                      |  18 +++++++----
 kernel/irq/timings.c                     | 366 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 536 insertions(+), 31 deletions(-)
 create mode 100644 kernel/irq/timings.c

-- 

 <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

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH V10 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request
@ 2017-05-16 19:44 Daniel Lezcano
  2017-05-17 10:36 ` Mark Rutland
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel Lezcano @ 2017-05-16 19:44 UTC (permalink / raw)
  To: tglx
  Cc: Mark Rutland, Vineet Gupta, Marc Zyngier, Patrice Chotard,
	Kukjin Kim, Javier Martinez Canillas, Christoffer Dall,
	Paolo Bonzini, Radim Krčmář, Krzysztof Kozlowski,
	Russell King, Carlo Caione, Richard Cochran, Christoph Hellwig,
	Jens Axboe, Hannes Reinecke, moderated list:ARM PORT, open list,
	open list:SYNOPSYS ARC ARCH..., open list:ARM/STI ARCHITECTURE,
	moderated list:ARM/SAMSUNG EXYNO...

In the next changes, we track when the interrupts occur in order to
statistically compute when is supposed to happen the next interrupt.

In all the interruptions, it does not make sense to store the timer interrupt
occurences and try to predict the next interrupt as when know the expiration
time.

The request_irq() has a irq flags parameter and the timer drivers use it to
pass the IRQF_TIMER flag, letting us know the interrupt is coming from a timer.
Based on this flag, we can discard these interrupts when tracking them.

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

Add a function request_percpu_irq_flags() where we can specify the flags. The
request_percpu_irq() function is changed to be a wrapper to
request_percpu_irq_flags() passing a zero flag parameter.

Change the timers using request_percpu_irq() to use request_percpu_irq_flags()
instead with the IRQF_TIMER flag set.

For now, in order to prevent a misusage of this parameter, only the IRQF_TIMER
flag (or zero) is a valid parameter to be passed to the
request_percpu_irq_flags() function.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Javier Martinez Canillas <javier@osg.samsung.com>
Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Acked-by: Krzysztof Kozlowski <krzk@kernel.org>
---
Changelog:

   V10:
	- Drop the change for arch arm virtual timer
	  https://lkml.org/lkml/2017/4/25/184
   V9:
	- Clarified the patch description
	- Fixed EXPORT_SYMBOL_GPL(request_percpu_irq_flags)
---
 arch/arm/kernel/smp_twd.c                |  3 ++-
 drivers/clocksource/arc_timer.c          |  4 ++--
 drivers/clocksource/arm_arch_timer.c     | 20 ++++++++++++--------
 drivers/clocksource/arm_global_timer.c   |  4 ++--
 drivers/clocksource/exynos_mct.c         |  7 ++++---
 drivers/clocksource/qcom-timer.c         |  4 ++--
 drivers/clocksource/time-armada-370-xp.c |  9 +++++----
 drivers/clocksource/timer-nps.c          |  6 +++---
 include/linux/interrupt.h                | 11 ++++++++++-
 kernel/irq/manage.c                      | 15 ++++++++++-----
 10 files changed, 52 insertions(+), 31 deletions(-)

diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index 895ae51..ce9fdcf 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -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_flags(twd_ppi, twd_handler, IRQF_TIMER, "twd",
+				       twd_evt);
 	if (err) {
 		pr_err("twd: can't register interrupt %d (%d)\n", twd_ppi, err);
 		goto out_free;
diff --git a/drivers/clocksource/arc_timer.c b/drivers/clocksource/arc_timer.c
index 2164973..66f2632 100644
--- a/drivers/clocksource/arc_timer.c
+++ b/drivers/clocksource/arc_timer.c
@@ -301,8 +301,8 @@ 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,
-				 "Timer0 (per-cpu-tick)", evt);
+	ret = request_percpu_irq_flags(arc_timer_irq, timer_irq_handler, IRQF_TIMER,
+				       "Timer0 (per-cpu-tick)", evt);
 	if (ret) {
 		pr_err("clockevent: unable to request irq\n");
 		return ret;
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 4bed671..22646b5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -980,25 +980,29 @@ static int __init arch_timer_register(void)
 	ppi = arch_timer_ppi[arch_timer_uses_ppi];
 	switch (arch_timer_uses_ppi) {
 	case ARCH_TIMER_VIRT_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_virt,
-					 "arch_timer", arch_timer_evt);
+		err = request_percpu_irq_flags(ppi, arch_timer_handler_virt,
+					       IRQF_TIMER, "arch_timer",
+					       arch_timer_evt);
 		break;
 	case ARCH_TIMER_PHYS_SECURE_PPI:
 	case ARCH_TIMER_PHYS_NONSECURE_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_phys,
-					 "arch_timer", arch_timer_evt);
+		err = request_percpu_irq_flags(ppi, arch_timer_handler_phys,
+					       IRQF_TIMER, "arch_timer",
+					       arch_timer_evt);
 		if (!err && arch_timer_has_nonsecure_ppi()) {
 			ppi = arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI];
-			err = request_percpu_irq(ppi, arch_timer_handler_phys,
-						 "arch_timer", arch_timer_evt);
+			err = request_percpu_irq_flags(ppi, arch_timer_handler_phys,
+						       IRQF_TIMER, "arch_timer",
+						       arch_timer_evt);
 			if (err)
 				free_percpu_irq(arch_timer_ppi[ARCH_TIMER_PHYS_SECURE_PPI],
 						arch_timer_evt);
 		}
 		break;
 	case ARCH_TIMER_HYP_PPI:
-		err = request_percpu_irq(ppi, arch_timer_handler_phys,
-					 "arch_timer", arch_timer_evt);
+		err = request_percpu_irq_flags(ppi, arch_timer_handler_phys,
+					       IRQF_TIMER, "arch_timer",
+					       arch_timer_evt);
 		break;
 	default:
 		BUG();
diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c
index 123ed20..5a72ec1 100644
--- a/drivers/clocksource/arm_global_timer.c
+++ b/drivers/clocksource/arm_global_timer.c
@@ -302,8 +302,8 @@ static int __init global_timer_of_register(struct device_node *np)
 		goto out_clk;
 	}
 
-	err = request_percpu_irq(gt_ppi, gt_clockevent_interrupt,
-				 "gt", gt_evt);
+	err = request_percpu_irq_flags(gt_ppi, gt_clockevent_interrupt,
+				       IRQF_TIMER, "gt", gt_evt);
 	if (err) {
 		pr_warn("global-timer: can't register interrupt %d (%d)\n",
 			gt_ppi, err);
diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c
index 670ff0f..a48ca0f 100644
--- a/drivers/clocksource/exynos_mct.c
+++ b/drivers/clocksource/exynos_mct.c
@@ -524,9 +524,10 @@ 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],
-					 exynos4_mct_tick_isr, "MCT",
-					 &percpu_mct_tick);
+		err = request_percpu_irq_flags(mct_irqs[MCT_L0_IRQ],
+					       exynos4_mct_tick_isr,
+					       IRQF_TIMER, "MCT",
+					       &percpu_mct_tick);
 		WARN(err, "MCT: can't request IRQ %d (%d)\n",
 		     mct_irqs[MCT_L0_IRQ], err);
 	} else {
diff --git a/drivers/clocksource/qcom-timer.c b/drivers/clocksource/qcom-timer.c
index ee358cd..8e876fc 100644
--- a/drivers/clocksource/qcom-timer.c
+++ b/drivers/clocksource/qcom-timer.c
@@ -174,8 +174,8 @@ static int __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,
 	}
 
 	if (percpu)
-		res = request_percpu_irq(irq, msm_timer_interrupt,
-					 "gp_timer", msm_evt);
+		res = request_percpu_irq_flags(irq, msm_timer_interrupt,
+					       IRQF_TIMER, "gp_timer", msm_evt);
 
 	if (res) {
 		pr_err("request_percpu_irq failed\n");
diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c
index aea4380..fea81ad 100644
--- a/drivers/clocksource/time-armada-370-xp.c
+++ b/drivers/clocksource/time-armada-370-xp.c
@@ -309,10 +309,11 @@ 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,
-				armada_370_xp_timer_interrupt,
-				"armada_370_xp_per_cpu_tick",
-				armada_370_xp_evt);
+	res = request_percpu_irq_flags(armada_370_xp_clkevt_irq,
+				       armada_370_xp_timer_interrupt,
+				       IRQF_TIMER,
+				       "armada_370_xp_per_cpu_tick",
+				       armada_370_xp_evt);
 	/* Immediately configure the timer on the boot CPU */
 	if (res) {
 		pr_err("Failed to request percpu irq\n");
diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c
index e74ea17..a83b6a4 100644
--- a/drivers/clocksource/timer-nps.c
+++ b/drivers/clocksource/timer-nps.c
@@ -256,9 +256,9 @@ 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,
-				 "Timer0 (per-cpu-tick)",
-				 &nps_clockevent_device);
+	ret = request_percpu_irq_flags(nps_timer0_irq, timer_irq_handler,
+				       IRQF_TIMER, "Timer0 (per-cpu-tick)",
+				       &nps_clockevent_device);
 	if (ret) {
 		pr_err("Couldn't request irq\n");
 		clk_disable_unprepare(clk);
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a6fba48..89defd5 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -152,8 +152,17 @@ request_any_context_irq(unsigned int irq, irq_handler_t handler,
 			unsigned long flags, const char *name, void *dev_id);
 
 extern int __must_check
+request_percpu_irq_flags(unsigned int irq, irq_handler_t handler,
+			 unsigned long flags, const char *devname,
+			 void __percpu *percpu_dev_id);
+
+static inline int __must_check
 request_percpu_irq(unsigned int irq, irq_handler_t handler,
-		   const char *devname, void __percpu *percpu_dev_id);
+		   const char *devname, void __percpu *percpu_dev_id)
+{
+	return request_percpu_irq_flags(irq, handler, 0,
+					devname, percpu_dev_id);
+}
 
 extern const void *free_irq(unsigned int, void *);
 extern void free_percpu_irq(unsigned int, void __percpu *);
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 070be98..057fde8 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1958,9 +1958,10 @@ int setup_percpu_irq(unsigned int irq, struct irqaction *act)
 }
 
 /**
- *	request_percpu_irq - allocate a percpu interrupt line
+ *	request_percpu_irq_flags - allocate a percpu interrupt line
  *	@irq: Interrupt line to allocate
  *	@handler: Function to be called when the IRQ occurs.
+ *	@flags: Interrupt type flags (IRQF_TIMER only)
  *	@devname: An ascii name for the claiming device
  *	@dev_id: A percpu cookie passed back to the handler function
  *
@@ -1973,8 +1974,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_flags(unsigned int irq, irq_handler_t handler,
+			     unsigned long flags, const char *devname,
+			     void __percpu *dev_id)
 {
 	struct irqaction *action;
 	struct irq_desc *desc;
@@ -1988,12 +1990,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;
 
@@ -2014,7 +2019,7 @@ int request_percpu_irq(unsigned int irq, irq_handler_t handler,
 
 	return retval;
 }
-EXPORT_SYMBOL_GPL(request_percpu_irq);
+EXPORT_SYMBOL_GPL(request_percpu_irq_flags);
 
 /**
  *	irq_get_irqchip_state - returns the irqchip state of a interrupt.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-06-20 20:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 13:51 [GIT PULL V10] irq: next irq tracking Daniel Lezcano
2017-06-12 13:52 ` [PATCH V10 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Daniel Lezcano
2017-06-12 13:52   ` [PATCH V10 2/3] irq: Track the interrupt timings Daniel Lezcano
2017-06-12 13:52   ` [PATCH V10 3/3] irq: Compute the periodic interval for interrupts Daniel Lezcano
2017-06-20 14:05   ` [PATCH V10 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Thomas Gleixner
2017-06-20 20:25     ` Daniel Lezcano
2017-06-20 20:29       ` Thomas Gleixner
2017-06-20 20:30         ` Daniel Lezcano
2017-06-20 11:56 ` [GIT PULL V10] irq: next irq tracking Daniel Lezcano
  -- strict thread matches above, loose matches on Subject: below --
2017-05-16 19:44 [PATCH V10 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Daniel Lezcano
2017-05-17 10:36 ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox