Support managed interrupts for platform devices
Subsystems (5)
v3 cover Support managed interrupts for platform devices
So far, managed interrupts are only used for PCI MSIs. This series adds platform device support for managed interrupts. Initially this topic was discussed at [0].
The method to enable managed interrupts is to allocate a group of IRQs for the device, and then switch the interrupts to managed - this is done through new function irq_update_affinity_desc().
Function devm_platform_get_irqs_affinity() is added as a helper to manage this work, such that we don't need to export irq_update_affinity_desc() or irq_create_affinity_masks().
In the devm_platform_get_irqs_affinity() release call a new platform method is used to "put" an irq. The reason for this is that per-irq mapping (and irq_desc) needs to be recreated anew for re-probing the LLDD, such that we don't attempt to reconfigure the managed or any other flag for an irq_desc.
For now, the HiSilicon SAS v2 hw driver is switched over. This is used in the D05 dev board.
Performance gain observed for 6x SAS SSDs is ~357K -> 420K IOPs for fio read.
[0] https://lore.kernel.org/lkml/[email protected]/
Changes since v2:
- Update genirq change as follows:
- Handle when the irq is started, active, or already managed
- Reject update when CONFIG_GENERIC_IRQ_RESERVATION_MODE is set
- Revamp platform.c API as follows:
- Make it devm type
- Add platform_put_irq() and associated change in ACPI code to allow irq resource to be reset
- Unmap irqs for driver removal
- Change API to accept min and max vectors
John Garry (5):
genirq/affinity: Add irq_update_affinity_desc()
ACPI: Make acpi_dev_irqresource_disabled() public driver core: platform: Add platform_put_irq() Driver core: platform: Add devm_platform_get_irqs_affinity()
scsi: hisi_sas: Expose HW queues for v2 hw
drivers/acpi/resource.c | 2 +- drivers/base/platform.c | 126 +++++++++++++++++++++++++ drivers/scsi/hisi_sas/hisi_sas.h | 4 + drivers/scsi/hisi_sas/hisi_sas_main.c | 11 +++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 68 ++++++++++--- include/linux/acpi.h | 5 + include/linux/interrupt.h | 8 ++ include/linux/platform_device.h | 6 ++ kernel/irq/manage.c | 63 +++++++++++++ 9 files changed, 279 insertions(+), 14 deletions(-)
Signature · 1 line
2.26.2
PATCH v3 1/5 genirq/affinity: Add irq_update_affinity_desc()
Add a function to allow the affinity of an interrupt be switched to managed, such that interrupts allocated for platform devices may be managed.
--- include/linux/interrupt.h | 8 +++++ kernel/irq/manage.c | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+)
include/linux/interrupt.h +8 -0
@@ -352,6 +352,8 @@ extern int irq_can_set_affinity(unsigned int irq);extern int irq_select_affinity (unsigned int irq);extern int irq_set_affinity_hint (unsigned int irq,const struct cpumask *m); +extern int irq_update_affinity_desc (unsigned int irq, +struct irq_affinity_desc *affinity);extern int irq_set_affinity_notifier (unsigned int irq,struct irq_affinity_notify *notify);
@@ -387,6 +389,12 @@ static inline int irq_set_affinity_hint(unsigned int irq,return -EINVAL ; } +static inline int irq_update_affinity_desc (unsigned int irq, +struct irq_affinity_desc *affinity) +{ +return -EINVAL ; +} +static inline int irq_set_affinity_notifier (unsigned int irq,struct irq_affinity_notify *notify) {
kernel/irq/manage.c +63 -0
69 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 1/5] genirq/affinity: Add irq_update_affinity_desc()
Hi John,
Quoted 4 lines · John Garry
kernel/irq/manage.c +4
-0+ activated =irqd_is_activated (&desc->irq_data); +if (activated) +irq_domain_deactivate_irq (&desc->irq_data); +
kernel/irq/manage.c int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, · line 430
Quoted 10 lines
kernel/irq/manage.c +10
-0+if (affinity->is_managed) { +irqd_set (&desc->irq_data,IRQD_AFFINITY_MANAGED ); +irqd_set (&desc->irq_data,IRQD_MANAGED_SHUTDOWN ); + } + +cpumask_copy (desc->irq_common_data.affinity, &affinity->mask); + +/* Restore the activation state */ +if (activated) +irq_domain_deactivate_irq (&desc->irq_data);
Shouldn't this be irq_domain_activate_irq() ?
Thanks,
Daniel
Re: [PATCH v3 1/5] genirq/affinity: Add irq_update_affinity_desc()
Hi Daniel,
Quoted 9 lines · John Garry
Quoted 7 lines
kernel/irq/manage.c +7
-0+ activated =irqd_is_activated (&desc->irq_data); +if (activated) +irq_domain_deactivate_irq (&desc->irq_data); + +if (affinity->is_managed) { +irqd_set (&desc->irq_data,IRQD_AFFINITY_MANAGED ); +irqd_set (&desc->irq_data,IRQD_MANAGED_SHUTDOWN );
Quoted 8 lines
kernel/irq/manage.c int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *mask, · line 430
Quoted 7 lines
kernel/irq/manage.c +7
-0+ } + +cpumask_copy (desc->irq_common_data.affinity, &affinity->mask); + +/* Restore the activation state */ +if (activated) +irq_domain_deactivate_irq (&desc->irq_data);Shouldn't this be
irq_domain_activate_irq()?
Yeah, I think so. Blushes.
Cheers,
John
PATCH v3 2/5 ACPI: Make acpi_dev_irqresource_disabled() public
In reply to John GarryTo allow the platform device to "put" an irq, make the function to reset an ACPI companion device irq resource public.
--- drivers/acpi/resource.c | 2 +- include/linux/acpi.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/acpi/resource.c +1 -1
@@ -380,7 +380,7 @@ unsigned int acpi_dev_get_irq_type(int triggering, int polarity) }EXPORT_SYMBOL_GPL (acpi_dev_get_irq_type); -static void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) +void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) { res->start = gsi; res->end = gsi;
include/linux/acpi.h +5 -0
@@ -467,6 +467,7 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, struct resource_win *win);unsigned long acpi_dev_irq_flags (u8 triggering,u8 polarity,u8 shareable);unsigned int acpi_dev_get_irq_type (int triggering,int polarity); +void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi);bool acpi_dev_resource_interrupt (struct acpi_resource *ares,int index,struct resource *res);
@@ -939,6 +940,10 @@ static inline struct acpi_device *acpi_resource_consumer(struct resource *res) return NULL; } +static inline void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) +{ +} +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
Signature · 1 line
2.26.2
Rafael J. Wysocki
maintainerRe: [PATCH v3 2/5] ACPI: Make acpi_dev_irqresource_disabled() public
Quoted 5 lines · John Garry
To allow the platform device to "put" an irq, make the function to reset an ACPI companion device irq resource public.
Signed-off-by John Garry <[email protected]>
I'd rather move it to kernel/resource.c as it is not ACPI-specific and its only connection to ACPI is that it is used in the ACPI resources management code.
Quoted 44 lines
--- drivers/acpi/resource.c | 2 +- include/linux/acpi.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-)drivers/acpi/resource.c +1
-1@@ -380,7 +380,7 @@ unsigned int acpi_dev_get_irq_type(int triggering, int polarity) }EXPORT_SYMBOL_GPL (acpi_dev_get_irq_type); -static void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) +void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) { res->start = gsi; res->end = gsi;include/linux/acpi.h +5
-1@@ -467,6 +467,7 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, struct resource_win *win);unsigned long acpi_dev_irq_flags (u8 triggering,u8 polarity,u8 shareable);unsigned int acpi_dev_get_irq_type (int triggering,int polarity); +void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi);bool acpi_dev_resource_interrupt (struct acpi_resource *ares,int index,struct resource *res);@@ -939,6 +940,10 @@ static inline struct acpi_device *acpi_resource_consumer(struct resource *res) return NULL; } +static inline void acpi_dev_irqresource_disabled (struct resource *res,u32 gsi) +{ +} +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC --2.26.2
Re: [PATCH v3 2/5] ACPI: Make acpi_dev_irqresource_disabled() public
Quoted 9 lines · Rafael J. Wysocki
Quoted 4 lines · John Garry
To allow the platform device to "put" an irq, make the function to reset an ACPI companion device irq resource public.
Signed-off-by John Garry<[email protected]>I'd rather move it to
kernel/resource.cas it is not ACPI-specific and its only connection to ACPI is that it is used in the ACPI resources management code.
Hi Rafael,
That's ok, but we could also just put in include/linux/ioport.h as a static inline as it’s so small. Not so important, I guess.
And I'm not sure how this part could be merged, so maybe I can do as 2x patches now - 1. add resource.c function 2. remove ACPI duplicate. - so we have the option to merge ACPI part later if it makes things easier.
Thanks,
John
Rafael J. Wysocki
maintainerRe: [PATCH v3 2/5] ACPI: Make acpi_dev_irqresource_disabled() public
Quoted 12 lines · John Garry
Quoted 9 lines · Rafael J. Wysocki
Quoted 4 lines · John Garry
To allow the platform device to "put" an irq, make the function to reset an ACPI companion device irq resource public.
Signed-off-by John Garry<[email protected]>I'd rather move it to
kernel/resource.cas it is not ACPI-specific and its only connection to ACPI is that it is used in the ACPI resources management code.
Quoted 8 lines
Hi Rafael,
That's ok, but we could also just put in
include/linux/ioport.has a static inline as it’s so small. Not so important, I guess.And I'm not sure how this part could be merged, so maybe I can do as 2x patches now - 1. add
resource.cfunction 2. remove ACPI duplicate. - so we have the option to merge ACPI part later if it makes things easier.
That would work too.
My point really was that exporting that function from ACPI was rather confusing.
PATCH v3 3/5 driver core: platform: Add platform_put_irq()
In reply to John GarryAdd a function to tear down the work which was done in platform_get_irq() for when the device driver is done with the irq.
For ACPI companion devices the irq resource is set as disabled, as this resource is configured from platform_get_irq()->acpi_irq_get() and requires resetting.
--- drivers/base/platform.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/base/platform.c +14 -0
@@ -289,6 +289,20 @@ int platform_irq_count(struct platform_device *dev) }EXPORT_SYMBOL_GPL (platform_irq_count); +void platform_put_irq (struct platform_device *dev,unsigned int num) +{ +unsigned int virq =platform_get_irq (dev, num); + +irq_dispose_mapping (virq); +if (has_acpi_companion (&dev->dev)) { +struct resource *r =platform_get_resource (dev,IORESOURCE_IRQ , + num); + +if (r) +acpi_dev_irqresource_disabled (r,0 ); + } +} +/** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device
Signature · 1 line
2.26.2
Re: [PATCH v3 3/5] driver core: platform: Add platform_put_irq()
Quoted 17 lines · John Garry
Add a function to tear down the work which was done in
platform_get_irq()for when the device driver is done with the irq.For ACPI companion devices the irq resource is set as disabled, as this resource is configured from platform_get_irq()->acpi_irq_get() and requires resetting.
Signed-off-by John Garry <[email protected]>--- drivers/base/platform.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/base/platform.c +0
-0
drivers/base/platform.c int platform_irq_count(struct platform_device · line 295
Quoted 7 lines
drivers/base/platform.c +3
-0@@ -289,6 +289,20 @@ int platform_irq_count(struct platform_device *dev) }EXPORT_SYMBOL_GPL (platform_irq_count); +void platform_put_irq (struct platform_device *dev,unsigned int num) +{ +unsigned int virq =platform_get_irq (dev, num);
I find it pretty odd to have to recompute the interrupt number, which in turn results in a domain lookup. It things were refcounted (they aren't yet), irq_dispose_mapping() would have no effect.
<pedant>
It also goes against the usual construct where if you obtain an object based on some parameters, the release happens by specifying the object itself, and not the parameters that lead to the object. </pedant>
drivers/base/platform.c int platform_irq_count(struct platform_device *dev) · line 302
Quoted 8 lines
drivers/base/platform.c +8
-0+ +irq_dispose_mapping (virq); +if (has_acpi_companion (&dev->dev)) { +struct resource *r =platform_get_resource (dev,IORESOURCE_IRQ , + num); + +if (r) +acpi_dev_irqresource_disabled (r,0 );
It looks to me that the ACPI thing is what needs to be promoted to a first class function, releasing all the resources that have used by a given device.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 3/5] driver core: platform: Add platform_put_irq()
Quoted 13 lines · Marc Zyngier
Quoted 12 lines · John Garry
Add a function to tear down the work which was done in
platform_get_irq()for when the device driver is done with the irq.For ACPI companion devices the irq resource is set as disabled, as this resource is configured from platform_get_irq()->acpi_irq_get() and requires resetting.
Signed-off-by John Garry <[email protected]>---
drivers/base/platform.c | 14 ++++++++++++++1 file changed, 14 insertions(+)
Quoted 8 lines
drivers/base/platform.c int platform_irq_count(struct platform_device *dev) · line 291
Quoted 8 lines
drivers/base/platform.c +0
-0@@ -289,6 +289,20 @@ int platform_irq_count(struct platform_device *dev) } EXPORT_SYMBOL_GPL(platform_irq_count);
Hi Marc,
Quoted 6 lines
drivers/base/platform.c int platform_irq_count(struct platform_device *dev) · line 294
Quoted 3 lines
drivers/base/platform.c +3
-0+void platform_put_irq (struct platform_device *dev,unsigned int num) +{ + unsigned int virq = platform_get_irq(dev, num);I find it pretty odd to have to recompute the interrupt number, which in turn results in a domain lookup.
Well we do have the virq available, but then we need to pass the virq and device irq index. But maybe I somehow reverse-lookup the ACPI res somehow from virq, such that we don't require the irq device index.
Quoted 8 lines
It things were refcounted
(they aren't yet),irq_dispose_mapping()would have no effect.<pedant>
It also goes against the usual construct where if you obtain an object based on some parameters, the release happens by specifying the object itself, and not the parameters that lead to the object. </pedant>
Yes, ideally we can use virq.
Quoted 13 lines
drivers/base/platform.c int platform_irq_count(struct platform_device *dev) · line 302
Quoted 9 lines
drivers/base/platform.c +8
-0+ + irq_dispose_mapping(virq); + if (has_acpi_companion(&dev->dev)) { + struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, + num); + + if (r) + acpi_dev_irqresource_disabled(r, 0);It looks to me that the ACPI thing is what needs to be promoted to a first class function, releasing all the resources that have used by a given device.
This is just clearing the irq resource flags, but it could be reasonable (to promote).
Thanks,
John
PATCH v3 4/5 Driver core: platform: Add devm_platform_get_irqs_affinity()
In reply to John GarryDrivers for multi-queue platform devices may also want managed interrupts for handling HW queue completion interrupts, so add support.
The function accepts an affinity descriptor pointer, which covers a set of irqs for the device.
The reason a devm method is added - as opposed to non-devm - is because the only current in-tree user will also use devm method for requesting the interrupts; as such, the function is made as devm as it can ensure ordering of freeing the irq and disposing of the mapping.
--- drivers/base/platform.c | 114 +++++++++++++++++++++++++++++++- include/linux/platform_device.h | 6 ++ 2 files changed, 119 insertions(+), 1 deletion(-)
drivers/base/platform.c +113 -1
@@ -15,6 +15,7 @@#include <linux/of_irq.h> #include <linux/module.h> #include <linux/init.h> +#include <linux/interrupt.h> #include <linux/dma-mapping.h> #include <linux/memblock.h> #include <linux/err.h>
@@ -289,7 +290,7 @@ int platform_irq_count(struct platform_device *dev) }EXPORT_SYMBOL_GPL (platform_irq_count); -void platform_put_irq (struct platform_device *dev,unsigned int num) +static void platform_put_irq (struct platform_device *dev,unsigned int num) {unsigned int virq =platform_get_irq (dev, num);
@@ -303,6 +304,117 @@ void platform_put_irq(struct platform_device *dev, unsigned int num) } } +struct irq_affinity_devres { +unsigned int count; +void *dev_id; +unsigned int irq[]; +}; + +static void devm_platform_get_irqs_affinity_release (struct device *dev, +void *res) +{ +struct platform_device *pdev =to_platform_device (dev); +struct irq_affinity_devres *ptr = res; +int i; + +for (i =0 ; i < ptr->count; i++) +platform_put_irq (pdev, i); +} + +/** +* devm_platform_get_irqs_affinity - devm method to get a set of IRQs for a +* device using an interrupt affinity descriptor +* @dev: platform device pointer +* @affd: affinity descriptor +* @minvec: minimum count of interrupt vectors +* @maxvec: maximum count of interrupt vectors +* @irqs: pointer holder for IRQ numbers +* +* Gets a set of IRQs for a platform device, and updates IRQ afffinty according +* to the passed affinity descriptor +* +* Return: Number of vectors on success, negative error number on failure. +*/ +int devm_platform_get_irqs_affinity (struct platform_device *dev, +struct irq_affinity *affd, +unsigned int minvec, +unsigned int maxvec, +int **irqs) +{ +struct irq_affinity_devres *ptr; +struct irq_affinity_desc *desc; +size_t size; +int i, ret, nvec; + +if (!affd) +return -EPERM ; + +if (maxvec < minvec) +return -ERANGE ; + + nvec =platform_irq_count (dev); + +if (nvec < minvec) +return -ENOSPC ; + +if (nvec <= affd->pre_vectors + affd->post_vectors) +return -EIO ; + + nvec =irq_calc_affinity_vectors (minvec, nvec, affd); +if (nvec < minvec) +return -ENOSPC ; + +if (nvec > maxvec) + nvec = maxvec; + + size =sizeof (*ptr) +sizeof (unsigned int ) * nvec; + ptr =devres_alloc (devm_platform_get_irqs_affinity_release, size, +GFP_KERNEL ); +if (!ptr) +return -ENOMEM ; + + ptr->count = nvec; + +for (i =0 ; i < nvec; i++) { +int irq =platform_get_irq (dev, i); +if (irq <0 ) { + ret = irq; + goto err_free_devres; + } + ptr->irq[i] = irq; + } + + desc =irq_create_affinity_masks (nvec, affd); +if (!desc) { + ret = -ENOMEM ; + goto err_free_devres; + } + +for (i =0 ; i < nvec; i++) { + ret =irq_update_affinity_desc (ptr->irq[i], &desc[i]); +if (ret) { +dev_err (&dev->dev,"failed to update irq%d affinity descriptor (%d)\n" , + ptr->irq[i], ret); + goto err_free_desc; + } + } + +devres_add (&dev->dev, ptr); + +kfree (desc); + + *irqs = ptr->irq; + +return nvec; + +err_free_desc: +kfree (desc); +err_free_devres: +devres_free (ptr); +return ret; +} +EXPORT_SYMBOL_GPL (devm_platform_get_irqs_affinity); +/** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device
include/linux/platform_device.h +6 -0
@@ -15,6 +15,7 @@#define PLATFORM_DEVID_NONE (-1)#define PLATFORM_DEVID_AUTO (-2) +struct irq_affinity ;struct mfd_cell ;struct property_entry ;struct platform_device_id ;
@@ -70,6 +71,11 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,extern int platform_get_irq (struct platform_device *,unsigned int );extern int platform_get_irq_optional (struct platform_device *,unsigned int );extern int platform_irq_count (struct platform_device *); +extern int devm_platform_get_irqs_affinity (struct platform_device *dev, +struct irq_affinity *affd, +unsigned int minvec, +unsigned int maxvec, +int **irqs);extern struct resource *platform_get_resource_byname (struct platform_device *,unsigned int ,const char *);
Signature · 1 line
2.26.2
PATCH v3 5/5 scsi: hisi_sas: Expose HW queues for v2 hw
In reply to John GarryAs a performance enhancement, make the completion queue interrupts managed.
In addition, in commit bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline"), CPU hotplug for MQ devices using managed interrupts is made safe. So expose HW queues to blk-mq to take advantage of this.
Flag Scsi_host.host_tagset is also set to ensure that the HBA is not sent more commands than it can handle. However the driver still does not use request tag for IPTT as there are many HW bugs means that special rules apply for IPTT allocation.
--- drivers/scsi/hisi_sas/hisi_sas.h | 4 ++ drivers/scsi/hisi_sas/hisi_sas_main.c | 11 +++++ drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 68 +++++++++++++++++++++----- 3 files changed, 70 insertions(+), 13 deletions(-)
drivers/scsi/hisi_sas/hisi_sas.h +4 -0
@@ -14,6 +14,7 @@#include <linux/debugfs.h> #include <linux/dmapool.h> #include <linux/iopoll.h> +#include <linux/irq.h> #include <linux/lcm.h> #include <linux/libata.h> #include <linux/mfd/syscon.h>
@@ -312,6 +313,7 @@ enum {struct hisi_sas_hw {int (*hw_init)(struct hisi_hba *hisi_hba); +int (*interrupt_preinit)(struct hisi_hba *hisi_hba);void (*setup_itct)(struct hisi_hba *hisi_hba,struct hisi_sas_device *device); int (*slot_index_alloc)(struct hisi_hba *hisi_hba,
@@ -418,6 +420,8 @@ struct hisi_hba {u32 refclk_frequency_mhz;u8 sas_addr[SAS_ADDR_SIZE ]; +int *irq_map;/* v2 hw */ +int n_phy;spinlock_t lock;struct semaphore sem;
drivers/scsi/hisi_sas/hisi_sas_main.c +11 -0
@@ -2614,6 +2614,13 @@ static struct Scsi_Host *hisi_sas_shost_alloc(struct platform_device *pdev,return NULL ; } +static int hisi_sas_interrupt_preinit (struct hisi_hba *hisi_hba) +{ +if (hisi_hba->hw->interrupt_preinit) +return hisi_hba->hw->interrupt_preinit (hisi_hba); +return 0 ; +} +int hisi_sas_probe (struct platform_device *pdev,const struct hisi_sas_hw *hw) {
@@ -2671,6 +2678,10 @@ int hisi_sas_probe(struct platform_device *pdev, sha->sas_port[i] = &hisi_hba->port[i].sas_port; } + rc =hisi_sas_interrupt_preinit (hisi_hba); +if (rc) + goto err_out_ha; + rc =scsi_add_host (shost, &pdev->dev);if (rc) goto err_out_ha;
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +55 -13
129 lines not on this page · raw message
Signature · 1 line
2.26.2