Skip to contentSkip to conversation

simulated interrupts

PATCH Superseded Bartosz Golaszewski 3 participants 9 messages Aug 14, 2017 – Aug 20, 2017

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover simulated interrupts

Some frameworks (e.g. iio, gpiolib) use irq_work to implement simulated interrupts that can be 'fired' from process context when needed and requested just like normal interrupts. This is useful for testing and development purposes.

Currently this code is reimplemented by every user. This series proposes to add a new set of functions that can be used by drivers that want to simulate interrupts without having to duplicate any boilerplate code.

The first patch adds a simple irq simulator framework. The second extends it with resource management. The third uses the new functionality in the gpio-mockup testing driver.

NOTE: The next candidate for using this API would be iio-dummy-evgen.

v1 -> v2:
- added a call to irq_work_sync in irq_sim_fini()

v2 -> v3:
- added the license header to new files
- added Acked-by's and Reviewed-by's

Bartosz Golaszewski (3):
irq/irq_sim: add a simple interrupt simulator framework irq/irq_sim: add a devres variant of irq_sim_init()
gpio: mockup: use irq_sim

 Documentation/driver-model/devres.txt |   1 +
 drivers/gpio/Kconfig                  |   2 +-
 drivers/gpio/gpio-mockup.c            |  77 ++--------------
 include/linux/irq_sim.h               |  48 ++++++++++
 init/Kconfig                          |   4 +
 kernel/Makefile                       |   1 +
 kernel/irq_sim.c                      | 164 ++++++++++++++++++++++++++++++++++
 7 files changed, 226 insertions(+), 71 deletions(-)
 create mode 100644 include/linux/irq_sim.h
 create mode 100644 kernel/irq_sim.c
Signature · 1 line
2.13.2
#1 lore raw

PATCH v3 1/3 irq/irq_sim: add a simple interrupt simulator framework

Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.

---
 include/linux/irq_sim.h |  44 ++++++++++++++++++
 init/Kconfig            |   4 ++
 kernel/Makefile         |   1 +
 kernel/irq_sim.c        | 121 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+)
 create mode 100644 include/linux/irq_sim.h
 create mode 100644 kernel/irq_sim.c
include/linux/irq_sim.h new file +44 -0
new file mode 100644
index 000000000000..9ee1a4f8bd94
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Bartosz Golaszewski <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#ifndef _LINUX_IRQ_SIM_H
+#define _LINUX_IRQ_SIM_H
+
+#include <linux/irq_work.h>
+
+/*
+ * Provides a framework for allocating simulated interrupts which can be
+ * requested like normal irqs and enqueued from process context.
+ */
+
+struct irq_sim_work_ctx {
+	struct irq_work work;
+	int irq;
+};
+
+struct irq_sim_irq_ctx {
+	int irqnum;
+	bool enabled;
+};
+
+struct irq_sim {
+	struct irq_sim_work_ctx work_ctx;
+	int irq_base;
+	unsigned int irq_count;
+	struct irq_sim_irq_ctx *irqs;
+};
+
+int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs);
+void irq_sim_fini(struct irq_sim *sim);
+
+void irq_sim_fire(struct irq_sim *sim, unsigned int offset);
+
+int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset);
+
+#endif /* _LINUX_IRQ_SIM_H */
init/Kconfig +4 -0
index 8514b25db21c..220456599c3f 100644
@@ -23,6 +23,10 @@ config CONSTRUCTORS
 config IRQ_WORK
 	bool
 
+config IRQ_SIM
+	bool
+	select IRQ_WORK
+
 config BUILDTIME_EXTABLE_SORT
 	bool
 
kernel/Makefile +1 -0
index 4cb8e8b23c6e..4472567c5835 100644
@@ -97,6 +97,7 @@ obj-$(CONFIG_TRACE_CLOCK) += trace/
 obj-$(CONFIG_RING_BUFFER) += trace/
 obj-$(CONFIG_TRACEPOINTS) += trace/
 obj-$(CONFIG_IRQ_WORK) += irq_work.o
+obj-$(CONFIG_IRQ_SIM) += irq_sim.o
 obj-$(CONFIG_CPU_PM) += cpu_pm.o
 obj-$(CONFIG_BPF) += bpf/
 
kernel/irq_sim.c new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
2.13.2
#2 lore raw

Re: [PATCH v3 1/3] irq/irq_sim: add a simple interrupt simulator framework

Quoted 6 lines · Bartosz Golaszewski

Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.

Quoted 7 lines
---
 include/linux/irq_sim.h |  44 ++++++++++++++++++
 init/Kconfig            |   4 ++
 kernel/Makefile         |   1 +
 kernel/irq_sim.c        | 121 ++++++++++++++++++++++++++++++++++++++++++++++++

Please move this to kernel/irq/ ... and the config option to kernel/irq/Kconfig.

Thanks,

tglx

#3 lore raw

Re: [PATCH v3 1/3] irq/irq_sim: add a simple interrupt simulator framework

2017-08-14 15:06 GMT+02:00 Thomas Gleixner <[email protected]>:

Quoted 16 lines · Bartosz Golaszewski
Quoted 7 lines

Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.

Quoted 7 lines
---
 include/linux/irq_sim.h |  44 ++++++++++++++++++
 init/Kconfig            |   4 ++
 kernel/Makefile         |   1 +
 kernel/irq_sim.c        | 121 ++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines

Please move this to kernel/irq/ ... and the config option to kernel/irq/Kconfig.

Thanks,

tglx

How about moving irq_work.c there too?

Best regards,
Bartosz Golaszewski

#4 lore raw

Re: [PATCH v3 1/3] irq/irq_sim: add a simple interrupt simulator framework

Quoted 19 lines · Bartosz Golaszewski

2017-08-14 15:06 GMT+02:00 Thomas Gleixner <[email protected]>:

Quoted 18 lines · Bartosz Golaszewski
Quoted 7 lines

Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.

Quoted 7 lines
---
 include/linux/irq_sim.h |  44 ++++++++++++++++++
 init/Kconfig            |   4 ++
 kernel/Makefile         |   1 +
 kernel/irq_sim.c        | 121 ++++++++++++++++++++++++++++++++++++++++++++++++

Please move this to kernel/irq/ ... and the config option to kernel/irq/Kconfig.

Quoted 7 lines
Quoted 5 lines

Thanks,

tglx

How about moving irq_work.c there too?

We could, but irq_work is not really part of the interrupt subsystem, while your interrupt simulator definitely is.

Thanks,

tglx

#5 lore raw

Re: [PATCH v3 1/3] irq/irq_sim: add a simple interrupt simulator framework

2017-08-14 16:48 GMT+02:00 Thomas Gleixner <[email protected]>:

Quoted 22 lines · Bartosz Golaszewski
Quoted 21 lines

2017-08-14 15:06 GMT+02:00 Thomas Gleixner <[email protected]>:

Quoted 20 lines · Bartosz Golaszewski
Quoted 7 lines

Implement a simple, irq_work-based framework for simulating interrupts. Currently the API exposes routines for initializing and deinitializing the simulator object, enqueueing the interrupts and retrieving the allocated interrupt numbers based on the offset of the dummy interrupt in the simulator struct.

Quoted 7 lines
---
 include/linux/irq_sim.h |  44 ++++++++++++++++++
 init/Kconfig            |   4 ++
 kernel/Makefile         |   1 +
 kernel/irq_sim.c        | 121 ++++++++++++++++++++++++++++++++++++++++++++++++

Please move this to kernel/irq/ ... and the config option to kernel/irq/Kconfig.

Thanks,

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

tglx

How about moving irq_work.c there too?

We could, but irq_work is not really part of the interrupt subsystem, while your interrupt simulator definitely is.

Fair enough, let's leave it where it is.

I'll send v4.

Thanks,
Bartosz

#6 lore raw

PATCH v3 2/3 irq/irq_sim: add a devres variant of irq_sim_init()

In reply to Bartosz Golaszewski

Add a resource managed version of irq_sim_init(). This can be conveniently used in device drivers.

---
 Documentation/driver-model/devres.txt |  1 +
 include/linux/irq_sim.h               |  4 ++++
 kernel/irq_sim.c                      | 43 +++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
Documentation/driver-model/devres.txt +1 -0
index 30e04f7a690d..69f08c0f23a8 100644
@@ -312,6 +312,7 @@ IRQ
   devm_irq_alloc_descs_from()
   devm_irq_alloc_generic_chip()
   devm_irq_setup_generic_chip()
+  devm_irq_sim_init()
 
 LED
   devm_led_classdev_register()
include/linux/irq_sim.h +4 -0
index 9ee1a4f8bd94..9ad634fcc662 100644
@@ -11,6 +11,7 @@
 #define _LINUX_IRQ_SIM_H
 
 #include <linux/irq_work.h>
+#include <linux/device.h>
 
 /*
  * Provides a framework for allocating simulated interrupts which can be
@@ -37,6 +38,9 @@ struct irq_sim {
 int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs);
 void irq_sim_fini(struct irq_sim *sim);
 
+int devm_irq_sim_init(struct device *dev,
+		      struct irq_sim *sim, unsigned int num_irqs);
+
 void irq_sim_fire(struct irq_sim *sim, unsigned int offset);
 
 int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset);
kernel/irq_sim.c +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.13.2
#7 lore raw

PATCH v3 3/3 gpio: mockup: use irq_sim

In reply to Bartosz Golaszewski

Shrink the driver by removing the code dealing with dummy interrupts and replacing it with calls to the irq_sim API.

---
 drivers/gpio/Kconfig       |  2 +-
 drivers/gpio/gpio-mockup.c | 77 +++++-----------------------------------------
 2 files changed, 8 insertions(+), 71 deletions(-)
drivers/gpio/Kconfig +1 -1
index 461d6fc3688b..f858faa5731a 100644
@@ -311,7 +311,7 @@ config GPIO_MOCKUP
 	depends on GPIOLIB && SYSFS
 	select GPIO_SYSFS
 	select GPIOLIB_IRQCHIP
-	select IRQ_WORK
+	select IRQ_SIM
 	help
 	  This enables GPIO Testing driver, which provides a way to test GPIO
 	  subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS
drivers/gpio/gpio-mockup.c +7 -70

115 lines not on this page · raw message

Signature · 1 line
2.13.2