Skip to contentSkip to conversation

ACPI,PCI,IRQ: revert penalty calculation for ISA and SCI interrupts

PATCH Superseded Sinan Kaya 4 participants 25 messages Oct 19, 2016 – Oct 24, 2016

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sinan Kaya

author
#0 lore raw

v4 cover ACPI,PCI,IRQ: revert penalty calculation for ISA and SCI interrupts

By the time ACPI gets initialized, this code tries to determine an IRQ number based on penalty values in this array. It will try to locate the IRQ with the least penalty assignment so that interrupt sharing is avoided if possible.

A couple of notes about the external APIs:
1. These API can be called before the ACPI is started. Therefore, one cannot assume that the PCI link objects are initialized for calculating penalties.
2. The polarity and trigger information passed via the acpi_penalize_sci_irq from the BIOS may not match what the IRQ subsystem is reporting as the call might have been placed before the IRQ is registered by the interrupt subsystem.

The reverted changes were in the direction to remove these external API and try to calculate the penalties at runtime for the ISA, SCI as well as PCI IRQS.
This didn't work out well with the existing platforms.

V4:
* Drop ACPI, PCI IRQ: add PCI_USING penalty for ISA interrupts
* A new patch to isolate early boot ISA penalty calculations from dynamic penalty calculation by directly modifying the array members in ("ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages")
* Now that we isolated both SCI and ISA interrupts, revert commit ("Revert "ACPI,PCI,IRQ: separate ISA penalty calculation"") and commit ("487cf917ed0d
(Revert "ACPI, PCI, IRQ: remove redundant code in acpi_irq_penalty_init()") to share code between ISA and PCI penalties as originally intended.

V3:
http://www.spinics.net/lists/arm-kernel/msg536208.html
* drop patch #1 as discussed with Bjorn
* add patch #3 to track SCI irq and penalty separately

V2: https://lkml.org/lkml/2016/10/1/106
* Commit message updates

V1:
http://lists-archives.com/linux-kernel/28673954-revert-acpi-pci-irq-reduce-static-irq-array-size-to-16.html
* initial implementation

Sinan Kaya (3):
ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages Revert "ACPI,PCI,IRQ: remove SCI penalize function" Revert "ACPI,PCI,IRQ: separate ISA penalty calculation"

 arch/x86/kernel/acpi/boot.c |  1 +
 arch/x86/pci/acpi.c         |  1 -
 drivers/acpi/pci_link.c     | 72 ++++++++++++---------------------------------
 include/acpi/acpi_drivers.h |  1 -
 include/linux/acpi.h        |  1 +
 5 files changed, 21 insertions(+), 55 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v4 1/3 ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

The penalty determination of ISA IRQ goes through 4 paths.
1. assign PCI_USING during power up via acpi_irq_penalty_init.
2. update the penalty with acpi_penalize_isa_irq function based on the active parameter.
3. kernel command line penalty update via acpi_irq_penalty_update function.
4. increment the penalty as USING right after the IRQ is assign to PCI.

acpi_penalize_isa_irq and acpi_irq_penalty_update functions get called before the ACPI subsystem is started.

These API need to bypass the acpi_irq_get_penalty function.

---
 drivers/acpi/pci_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/pci_link.c +2 -2
index c983bf7..4f37938 100644
@@ -849,7 +849,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 			continue;
 
 		if (used)
-			new_penalty = acpi_irq_get_penalty(irq) +
+			new_penalty = acpi_isa_irq_penalty[irq] +
 					PIRQ_PENALTY_ISA_USED;
 		else
 			new_penalty = 0;
@@ -871,7 +871,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 void acpi_penalize_isa_irq(int irq, int active)
 {
 	if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
-		acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) +
+		acpi_isa_irq_penalty[irq] = acpi_isa_irq_penalty[irq] +
 		  (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
 }
 
Signature · 1 line
1.9.1
author
#10 lore raw

PATCH v4 2/3 Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Sinan Kaya

The SCI penalize function was removed in two steps (first refactor and then remove) and these changes are reverted here in one go.

The commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements") refactored the original code so that SCI penalty is calculated dynamically by the time get_penalty function is called. That change is partially reverted here, specifically for the SCI IRQ alone.

The SCI penalize function was finally dropped by commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") that replaced the old SCI penalty API with penalty calculation carried out dynamically and based on the acpi_gbl_FADT.sci_interrupt value.

However, that new algorithm relies on the accurate setting of IRQ types and that doesn't happen early enough on some platforms which leads to incorrect penalty assignments for PCI IRQs. In those cases, irq_get_trigger_type() returns incorrect values for the IRQs in question, because they have not been registered yet by the time the penalties are calculated.

To fix this problem, we only need to fix the penalty for the SCI interrupt. It seems better to add a single "sci_penalty" variable, set it to PIRQ_PENALTY_PCI_USING if it's level/low or PIRQ_PENALTY_ISA_ALWAYS otherwise, and add "sci_penalty" in when appropriate. That should fix it for *any* SCI IRQ, not just those less than 256, and we don't have to add these extra penalty table entries that are all unused (except possibly for one entry if we have an SCI in the 16-255 range).

For this reason, revert commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") completely to restore the correct behavior.

Fixes commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")
Fixes commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function")
---
 arch/x86/kernel/acpi/boot.c |  1 +
 drivers/acpi/pci_link.c     | 30 +++++++++++++++---------------
 include/linux/acpi.h        |  1 +
 3 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -0
index 90d84c3..0ffd26e 100644
@@ -453,6 +453,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
 		polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
 	mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
+	acpi_penalize_sci_irq(bus_irq, trigger, polarity);
 
 	/*
 	 * stash over-ride to indicate we've been here
drivers/acpi/pci_link.c +15 -15
index 4f37938..294b190 100644
@@ -87,6 +87,7 @@ struct acpi_pci_link {
 
 static LIST_HEAD(acpi_link_list);
 static DEFINE_MUTEX(acpi_link_lock);
+static int sci_irq = -1, sci_penalty;
 
 /* --------------------------------------------------------------------------
                             PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
 {
 	int penalty = 0;
 
-	/*
-	* Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict
-	* with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
-	* use for PCI IRQs.
-	*/
-	if (irq == acpi_gbl_FADT.sci_interrupt) {
-		u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
-
-		if (type != IRQ_TYPE_LEVEL_LOW)
-			penalty += PIRQ_PENALTY_ISA_ALWAYS;
-		else
-			penalty += PIRQ_PENALTY_PCI_USING;
-	}
+	if (irq == sci_irq)
+		penalty += sci_penalty;
 
 	if (irq < ACPI_MAX_ISA_IRQS)
 		return penalty + acpi_isa_irq_penalty[irq];
 
-	penalty += acpi_irq_pci_sharing_penalty(irq);
-	return penalty;
+	return penalty + acpi_irq_pci_sharing_penalty(irq);
 }
 
 int __init acpi_irq_penalty_init(void)
@@ -881,6 +870,17 @@ bool acpi_isa_irq_available(int irq)
 		    acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
 }
 
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
+{
+	sci_irq = irq;
+
+	if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
+	    polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
+		sci_penalty = PIRQ_PENALTY_PCI_USING;
+	else
+		sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
+}
+
 /*
  * Over-ride default table to reserve additional IRQs for use by ISA
  * e.g. acpi_irq_isa=5
include/linux/acpi.h +1 -0
index c5eaf2f..67d1d3e 100644
@@ -318,6 +318,7 @@ struct pci_dev;
 int acpi_pci_irq_enable (struct pci_dev *dev);
 void acpi_penalize_isa_irq(int irq, int active);
 bool acpi_isa_irq_available(int irq);
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
 void acpi_pci_irq_disable (struct pci_dev *dev);
 
 extern int ec_read(u8 addr, u8 *val);
Signature · 1 line
1.9.1
author
#19 lore raw

PATCH v4 3/3 Revert "ACPI,PCI,IRQ: separate ISA penalty calculation"

In reply to Sinan Kaya

This reverts commit f7eca374f000 ("ACPI,PCI,IRQ: separate ISA penalty calculation") and commit 487cf917ed0d ("revert "ACPI, PCI, IRQ: remove redundant code in acpi_irq_penalty_init()"").

Now that we understand the real issue (SCI and ISA penalty getting calculated before ACPI start), there is no need for special handling for ISA interrupts.

Let's try to simplify the code one more time to share code.

---
 arch/x86/pci/acpi.c         |  1 -
 drivers/acpi/pci_link.c     | 44 +++++---------------------------------------
 include/acpi/acpi_drivers.h |  1 -
 3 files changed, 5 insertions(+), 41 deletions(-)
arch/x86/pci/acpi.c +0 -1
index 3cd6983..b2a4e2a 100644
@@ -396,7 +396,6 @@ int __init pci_acpi_init(void)
 		return -ENODEV;
 
 	printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
-	acpi_irq_penalty_init();
 	pcibios_enable_irq = acpi_pci_irq_enable;
 	pcibios_disable_irq = acpi_pci_irq_disable;
 	x86_init.pci.init_irq = x86_init_noop;
drivers/acpi/pci_link.c +5 -39

57 lines not on this page · raw message

include/acpi/acpi_drivers.h +0 -1
index 29c6912..797ae2e 100644
@@ -78,7 +78,6 @@
 
 /* ACPI PCI Interrupt Link (pci_link.c) */
 
-int acpi_irq_penalty_init(void);
 int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
 			       int *polarity, char **name);
 int acpi_pci_link_free_irq(acpi_handle handle);
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH V4 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Sinan Kaya
Quoted 31 lines · Sinan Kaya

The penalty determination of ISA IRQ goes through 4 paths.
1. assign PCI_USING during power up via acpi_irq_penalty_init.
2. update the penalty with acpi_penalize_isa_irq function based on the active parameter.
3. kernel command line penalty update via acpi_irq_penalty_update function.
4. increment the penalty as USING right after the IRQ is assign to PCI.

acpi_penalize_isa_irq and acpi_irq_penalty_update functions get called before the ACPI subsystem is started.

These API need to bypass the acpi_irq_get_penalty function.

---
 drivers/acpi/pci_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/pci_link.c +1 -1
index c983bf7..4f37938 100644
@@ -849,7 +849,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
                        continue;
 
                if (used)
-                       new_penalty = acpi_irq_get_penalty(irq) +
+                       new_penalty = acpi_isa_irq_penalty[irq] +
                                        PIRQ_PENALTY_ISA_USED;
                else
                        new_penalty = 0;

drivers/acpi/pci_link.c static int __init acpi_irq_penalty_update(char *str, int used) · line 874

Quoted 5 lines
drivers/acpi/pci_link.c +1 -1
@@ -871,7 +871,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 void acpi_penalize_isa_irq(int irq, int active)
 {
        if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
-               acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) +
+               acpi_isa_irq_penalty[irq] = acpi_isa_irq_penalty[irq] +

This looks slightly odd. What about

+ acpi_isa_irq_penalty[irq] +=

drivers/acpi/pci_link.c static int __init acpi_irq_penalty_update(char *str, int used) · line 877

Quoted 3 lines
drivers/acpi/pci_link.c +0 -0
                  (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
 }
 

Thanks,
Rafael

Acked-by on v4 1/3
#4 lore raw

Re: [PATCH V4 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Sinan Kaya
Quoted 11 lines · Sinan Kaya

The penalty determination of ISA IRQ goes through 4 paths.
1. assign PCI_USING during power up via acpi_irq_penalty_init.
2. update the penalty with acpi_penalize_isa_irq function based on the active parameter.
3. kernel command line penalty update via acpi_irq_penalty_update function.
4. increment the penalty as USING right after the IRQ is assign to PCI.

acpi_penalize_isa_irq and acpi_irq_penalty_update functions get called before the ACPI subsystem is started.

These API need to bypass the acpi_irq_get_penalty function.

I don't mind this patch, but the changelog doesn't tell me what's broken and why we need this fix. Apparently acpi_irq_get_penalty() doesn't work before ACPI is initialized, but I don't see *why* it wouldn't work.

However, I see one bug it *does* fix: we do not store the SCI penalty in the acpi_isa_irq_penalty[] table because acpi_isa_irq_penalty[] only holds ISA IRQ penalties, and there's no guarantee that the SCI is an ISA IRQ. But prior to this patch, we added in the SCI penalty to the acpi_isa_irq_penalty[] entry when the SCI was an ISA IRQ, which makes acpi_irq_get_penalty() return the wrong thing. Consider:

  Initially     acpi_isa_irq_penalty[9] = 0.
  Assume        sci_interrupt = 9.
  Then          acpi_irq_get_penalty(9) returns X.
  If we call    acpi_penalize_isa_irq(9, 1),
  it sets       acpi_isa_irq_penalty[9] = X,
  and now       acpi_irq_get_penalty(9) returns X + X.

I'd propose a changelog like this:

We do not want to store the SCI penalty in the acpi_isa_irq_penalty[] table because acpi_isa_irq_penalty[] only holds ISA IRQ penalties and there's no guarantee that the SCI is an ISA IRQ. We add in the SCI penalty as a special case in acpi_irq_get_penalty().

But if we called acpi_penalize_isa_irq() or acpi_irq_penalty_update() for an SCI that happened to be an ISA IRQ, they stored the SCI penalty (part of the acpi_irq_get_penalty() return value) in acpi_isa_irq_penalty[]. Subsequent calls to acpi_irq_get_penalty() returned a penalty that included *two* SCI penalties.

If this actually fixes a worse problem related to ACPI initialization, of course you should detail that.

Quoted 35 lines
---
 drivers/acpi/pci_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/pci_link.c +2 -2
index c983bf7..4f37938 100644
@@ -849,7 +849,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 			continue;
 
 		if (used)
-			new_penalty = acpi_irq_get_penalty(irq) +
+			new_penalty = acpi_isa_irq_penalty[irq] +
 					PIRQ_PENALTY_ISA_USED;
 		else
 			new_penalty = 0;
@@ -871,7 +871,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 void acpi_penalize_isa_irq(int irq, int active)
 {
 	if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
-		acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) +
+		acpi_isa_irq_penalty[irq] = acpi_isa_irq_penalty[irq] +
 		  (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
 }
 
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Acked-by on v4 2/3
#11 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Sinan Kaya
Quoted 28 lines · Sinan Kaya

The SCI penalize function was removed in two steps (first refactor and then remove) and these changes are reverted here in one go.

The commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements") refactored the original code so that SCI penalty is calculated dynamically by the time get_penalty function is called. That change is partially reverted here, specifically for the SCI IRQ alone.

The SCI penalize function was finally dropped by commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") that replaced the old SCI penalty API with penalty calculation carried out dynamically and based on the acpi_gbl_FADT.sci_interrupt value.

However, that new algorithm relies on the accurate setting of IRQ types and that doesn't happen early enough on some platforms which leads to incorrect penalty assignments for PCI IRQs. In those cases, irq_get_trigger_type() returns incorrect values for the IRQs in question, because they have not been registered yet by the time the penalties are calculated.

To fix this problem, we only need to fix the penalty for the SCI interrupt. It seems better to add a single "sci_penalty" variable, set it to PIRQ_PENALTY_PCI_USING if it's level/low or PIRQ_PENALTY_ISA_ALWAYS otherwise, and add "sci_penalty" in when appropriate. That should fix it for *any* SCI IRQ, not just those less than 256, and we don't have to add these extra penalty table entries that are all unused (except possibly for one entry if we have an SCI in the 16-255 range).

Quoted 2 lines

For this reason, revert commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") completely to restore the correct behavior.

I like this patch fine, except for the changelog. I don't think it's useful to describe this as a revert and give all the historical details. I think the important part is something like this:

We previously used irq_get_trigger_type(irq) to help compute the penalty for the SCI, but that depends on the SCI having been registered already. Add acpi_penalize_sci_irq() so platforms can tell us the SCI IRQ, trigger, and polarity so we can compute the penalty even before the SCI has been registered.

Quoted 4 lines
Fixes commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")
Fixes commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function")

"commit" is redundant; it's sufficient to say:

Fixes 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")

In fact, I don't think you really need to include "commit" in the reference to 9e5ed6d1fb87 above either.

Quoted 97 lines
---
 arch/x86/kernel/acpi/boot.c |  1 +
 drivers/acpi/pci_link.c     | 30 +++++++++++++++---------------
 include/linux/acpi.h        |  1 +
 3 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -0
index 90d84c3..0ffd26e 100644
@@ -453,6 +453,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
 		polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
 	mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
+	acpi_penalize_sci_irq(bus_irq, trigger, polarity);
 
 	/*
 	 * stash over-ride to indicate we've been here
drivers/acpi/pci_link.c +15 -15
index 4f37938..294b190 100644
@@ -87,6 +87,7 @@ struct acpi_pci_link {
 
 static LIST_HEAD(acpi_link_list);
 static DEFINE_MUTEX(acpi_link_lock);
+static int sci_irq = -1, sci_penalty;
 
 /* --------------------------------------------------------------------------
                             PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
 {
 	int penalty = 0;
 
-	/*
-	* Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict
-	* with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
-	* use for PCI IRQs.
-	*/
-	if (irq == acpi_gbl_FADT.sci_interrupt) {
-		u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
-
-		if (type != IRQ_TYPE_LEVEL_LOW)
-			penalty += PIRQ_PENALTY_ISA_ALWAYS;
-		else
-			penalty += PIRQ_PENALTY_PCI_USING;
-	}
+	if (irq == sci_irq)
+		penalty += sci_penalty;
 
 	if (irq < ACPI_MAX_ISA_IRQS)
 		return penalty + acpi_isa_irq_penalty[irq];
 
-	penalty += acpi_irq_pci_sharing_penalty(irq);
-	return penalty;
+	return penalty + acpi_irq_pci_sharing_penalty(irq);
 }
 
 int __init acpi_irq_penalty_init(void)
@@ -881,6 +870,17 @@ bool acpi_isa_irq_available(int irq)
 		    acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
 }
 
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
+{
+	sci_irq = irq;
+
+	if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
+	    polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
+		sci_penalty = PIRQ_PENALTY_PCI_USING;
+	else
+		sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
+}
+
 /*
  * Over-ride default table to reserve additional IRQs for use by ISA
  * e.g. acpi_irq_isa=5
include/linux/acpi.h +1 -0
index c5eaf2f..67d1d3e 100644
@@ -318,6 +318,7 @@ struct pci_dev;
 int acpi_pci_irq_enable (struct pci_dev *dev);
 void acpi_penalize_isa_irq(int irq, int active);
 bool acpi_isa_irq_available(int irq);
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
 void acpi_pci_irq_disable (struct pci_dev *dev);
 
 extern int ec_read(u8 addr, u8 *val);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#20 lore raw

Re: [PATCH V4 3/3] Revert "ACPI, PCI, IRQ: separate ISA penalty calculation"

In reply to Sinan Kaya
Quoted 9 lines · Sinan Kaya

This reverts commit f7eca374f000 ("ACPI,PCI,IRQ: separate ISA penalty calculation") and commit 487cf917ed0d ("revert "ACPI, PCI, IRQ: remove redundant code in acpi_irq_penalty_init()"").

Now that we understand the real issue (SCI and ISA penalty getting calculated before ACPI start), there is no need for special handling for ISA interrupts.

Let's try to simplify the code one more time to share code.

I'm sort of OK with this, but it's not exactly a revert of the above (the commits you mention don't check "link->irq.initialized == 1".

Previously acpi_irq_penalty_init() looked at _PRS info ("possible" IRQs), but now we won't. Maybe that's good; I dunno. But it should be mentioned.

And I don't think it fixes a user-visible problem, so it doesn't need to be applied immediately. I'm not sure this is worth doing by itself; maybe it should wait until we can do more cleanup and think about all these issues together?

Quoted 102 lines
---
 arch/x86/pci/acpi.c         |  1 -
 drivers/acpi/pci_link.c     | 44 +++++---------------------------------------
 include/acpi/acpi_drivers.h |  1 -
 3 files changed, 5 insertions(+), 41 deletions(-)
arch/x86/pci/acpi.c +0 -1
index 3cd6983..b2a4e2a 100644
@@ -396,7 +396,6 @@ int __init pci_acpi_init(void)
 		return -ENODEV;
 
 	printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
-	acpi_irq_penalty_init();
 	pcibios_enable_irq = acpi_pci_irq_enable;
 	pcibios_disable_irq = acpi_pci_irq_disable;
 	x86_init.pci.init_irq = x86_init_noop;
drivers/acpi/pci_link.c +5 -39
index 294b190..dd14d78 100644
@@ -478,7 +478,8 @@ static int acpi_irq_pci_sharing_penalty(int irq)
 		 * If a link is active, penalize its IRQ heavily
 		 * so we try to choose a different IRQ.
 		 */
-		if (link->irq.active && link->irq.active == irq)
+		if ((link->irq.active && link->irq.active == irq) &&
+				(link->irq.initialized == 1))
 			penalty += PIRQ_PENALTY_PCI_USING;
 
 		/*
@@ -501,45 +502,10 @@ static int acpi_irq_get_penalty(int irq)
 		penalty += sci_penalty;
 
 	if (irq < ACPI_MAX_ISA_IRQS)
-		return penalty + acpi_isa_irq_penalty[irq];
+		penalty += acpi_isa_irq_penalty[irq];
 
-	return penalty + acpi_irq_pci_sharing_penalty(irq);
-}
-
-int __init acpi_irq_penalty_init(void)
-{
-	struct acpi_pci_link *link;
-	int i;
-
-	/*
-	 * Update penalties to facilitate IRQ balancing.
-	 */
-	list_for_each_entry(link, &acpi_link_list, list) {
-
-		/*
-		 * reflect the possible and active irqs in the penalty table --
-		 * useful for breaking ties.
-		 */
-		if (link->irq.possible_count) {
-			int penalty =
-			    PIRQ_PENALTY_PCI_POSSIBLE /
-			    link->irq.possible_count;
-
-			for (i = 0; i < link->irq.possible_count; i++) {
-				if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS)
-					acpi_isa_irq_penalty[link->irq.
-							 possible[i]] +=
-					    penalty;
-			}
-
-		} else if (link->irq.active &&
-				(link->irq.active < ACPI_MAX_ISA_IRQS)) {
-			acpi_isa_irq_penalty[link->irq.active] +=
-			    PIRQ_PENALTY_PCI_POSSIBLE;
-		}
-	}
-
-	return 0;
+	penalty += acpi_irq_pci_sharing_penalty(irq);
+	return penalty;
 }
 
 static int acpi_irq_balance = -1;	/* 0: static, 1: balance */
include/acpi/acpi_drivers.h +0 -1
index 29c6912..797ae2e 100644
@@ -78,7 +78,6 @@
 
 /* ACPI PCI Interrupt Link (pci_link.c) */
 
-int acpi_irq_penalty_init(void);
 int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
 			       int *polarity, char **name);
 int acpi_pci_link_free_irq(acpi_handle handle);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#21 lore raw

Re: [PATCH V4 3/3] Revert "ACPI, PCI, IRQ: separate ISA penalty calculation"

Quoted 3 lines · Bjorn Helgaas
Quoted 1 line

Let's try to simplify the code one more time to share code.

I'm sort of OK with this, but it's not exactly a revert of the above (the commits you mention don't check "link->irq.initialized == 1".

I can split the initialized bit. If I remove it from this commit, it can break the git bisect. That's why, I folded it into this review. I briefly mentioned about it in the cover letter. It might not be quiet clear.

Quoted 4 lines

Previously acpi_irq_penalty_init() looked at _PRS info ("possible" IRQs), but now we won't. Maybe that's good; I dunno. But it should be mentioned.

I'm directing all IRQs to acpi_irq_pci_sharing_penalty function. acpi_irq_pci_sharing_penalty checks for the possible values here from _PRS.

/*
* penalize the IRQs PCI might use, but not as severely. */
for (i = 0; i < link->irq.possible_count; i++)

	if (link->irq.possible[i] == irq)
		penalty += PIRQ_PENALTY_PCI_POSSIBLE /
			link->irq.possible_count;
Quoted 6 lines

And I don't think it fixes a user-visible problem, so it doesn't need to be applied immediately. I'm not sure this is worth doing by itself; maybe it should wait until we can do more cleanup and think about all these issues together?

It does fix the PCI_USING penalty assignment.

                if (link->irq.active && link->irq.active == irq)
                         penalty += PIRQ_PENALTY_PCI_USING;

If we drop this patch, then we need
[PATCH V3 1/3] ACPI, PCI IRQ: add PCI_USING penalty for ISA interrupts

http://www.gossamer-threads.com/lists/linux/kernel/2547605

as somebody needs to increment the penalty with PCI_USING when IRQ is assigned for a given ISA IRQ.

We might as well take [PATCH V4 1/3], [PATCH V4 2/3] and [PATCH V3 1/3] for this regression.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#5 lore raw

Re: [PATCH V4 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Bjorn Helgaas
Quoted 25 lines · Bjorn Helgaas
Quoted 11 lines · Sinan Kaya

The penalty determination of ISA IRQ goes through 4 paths.
1. assign PCI_USING during power up via acpi_irq_penalty_init.
2. update the penalty with acpi_penalize_isa_irq function based on the active parameter.
3. kernel command line penalty update via acpi_irq_penalty_update function.
4. increment the penalty as USING right after the IRQ is assign to PCI.

acpi_penalize_isa_irq and acpi_irq_penalty_update functions get called before the ACPI subsystem is started.

These API need to bypass the acpi_irq_get_penalty function.

I don't mind this patch, but the changelog doesn't tell me what's broken and why we need this fix. Apparently acpi_irq_get_penalty() doesn't work before ACPI is initialized, but I don't see *why* it wouldn't work.

However, I see one bug it *does* fix: we do not store the SCI penalty in the acpi_isa_irq_penalty[] table because acpi_isa_irq_penalty[] only holds ISA IRQ penalties, and there's no guarantee that the SCI is an ISA IRQ. But prior to this patch, we added in the SCI penalty to the acpi_isa_irq_penalty[] entry when the SCI was an ISA IRQ, which makes acpi_irq_get_penalty() return the wrong thing. Consider:

Quoted 6 lines
  Initially     acpi_isa_irq_penalty[9] = 0.
  Assume        sci_interrupt = 9.
  Then          acpi_irq_get_penalty(9) returns X.
  If we call    acpi_penalize_isa_irq(9, 1),
  it sets       acpi_isa_irq_penalty[9] = X,
  and now       acpi_irq_get_penalty(9) returns X + X.

Oops, I forgot the penalty we *intended* to add with acpi_penalize_isa_irq(). It's really like this, where X is the SCI penalty and Y is the part added by acpi_penalize_isa_irq():

  Initially     acpi_isa_irq_penalty[9] = 0.
  Assume        sci_interrupt = 9.
  Then          acpi_irq_get_penalty(9) returns X.
  If we call    acpi_penalize_isa_irq(9, 1),
  it sets       acpi_isa_irq_penalty[9] = X + Y,
  and now       acpi_irq_get_penalty(9) returns X + X + Y.

At the end, acpi_irq_get_penalty(9) *should* return X + Y, but instead it returns X + X + Y, i.e., the SCI penalty is included twice.

#12 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Bjorn Helgaas
Quoted 36 lines · Bjorn Helgaas
Quoted 28 lines · Sinan Kaya

The SCI penalize function was removed in two steps (first refactor and then remove) and these changes are reverted here in one go.

The commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements") refactored the original code so that SCI penalty is calculated dynamically by the time get_penalty function is called. That change is partially reverted here, specifically for the SCI IRQ alone.

The SCI penalize function was finally dropped by commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") that replaced the old SCI penalty API with penalty calculation carried out dynamically and based on the acpi_gbl_FADT.sci_interrupt value.

However, that new algorithm relies on the accurate setting of IRQ types and that doesn't happen early enough on some platforms which leads to incorrect penalty assignments for PCI IRQs. In those cases, irq_get_trigger_type() returns incorrect values for the IRQs in question, because they have not been registered yet by the time the penalties are calculated.

To fix this problem, we only need to fix the penalty for the SCI interrupt. It seems better to add a single "sci_penalty" variable, set it to PIRQ_PENALTY_PCI_USING if it's level/low or PIRQ_PENALTY_ISA_ALWAYS otherwise, and add "sci_penalty" in when appropriate. That should fix it for *any* SCI IRQ, not just those less than 256, and we don't have to add these extra penalty table entries that are all unused (except possibly for one entry if we have an SCI in the 16-255 range).

Quoted 2 lines

For this reason, revert commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") completely to restore the correct behavior.

I like this patch fine, except for the changelog. I don't think it's useful to describe this as a revert and give all the historical details. I think the important part is something like this:

Quoted 5 lines

We previously used irq_get_trigger_type(irq) to help compute the penalty for the SCI, but that depends on the SCI having been registered already. Add acpi_penalize_sci_irq() so platforms can tell us the SCI IRQ, trigger, and polarity so we can compute the penalty even before the SCI has been registered.

Thanks for the pointer [1] to the issues around acpi_penalize_sci_irq() being called before kmalloc() is available. That begs the question of exactly *why* we need acpi_penalize_sci_irq() so early -- I doubt we actually need to handle SCIs that early, and obviously we don't need to look up penalties that early (because we only look them up when enabling interrupt links, which happens much later).

[1] http://marc.info/?l=linux-acpi&m=145580159209240&w=2)

Quoted 1 line

Wait a minute, I still have a question here: what about other ACPI arches (ia64, arm64)? Don't they need to call acpi_penalize_sci_irq() somewhere?

Quoted 101 lines
Quoted 97 lines
---
 arch/x86/kernel/acpi/boot.c |  1 +
 drivers/acpi/pci_link.c     | 30 +++++++++++++++---------------
 include/linux/acpi.h        |  1 +
 3 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -0
index 90d84c3..0ffd26e 100644
@@ -453,6 +453,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
 		polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
 	mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
+	acpi_penalize_sci_irq(bus_irq, trigger, polarity);
 
 	/*
 	 * stash over-ride to indicate we've been here
drivers/acpi/pci_link.c +15 -15
index 4f37938..294b190 100644
@@ -87,6 +87,7 @@ struct acpi_pci_link {
 
 static LIST_HEAD(acpi_link_list);
 static DEFINE_MUTEX(acpi_link_lock);
+static int sci_irq = -1, sci_penalty;
 
 /* --------------------------------------------------------------------------
                             PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
 {
 	int penalty = 0;
 
-	/*
-	* Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict
-	* with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
-	* use for PCI IRQs.
-	*/
-	if (irq == acpi_gbl_FADT.sci_interrupt) {
-		u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
-
-		if (type != IRQ_TYPE_LEVEL_LOW)
-			penalty += PIRQ_PENALTY_ISA_ALWAYS;
-		else
-			penalty += PIRQ_PENALTY_PCI_USING;
-	}
+	if (irq == sci_irq)
+		penalty += sci_penalty;
 
 	if (irq < ACPI_MAX_ISA_IRQS)
 		return penalty + acpi_isa_irq_penalty[irq];
 
-	penalty += acpi_irq_pci_sharing_penalty(irq);
-	return penalty;
+	return penalty + acpi_irq_pci_sharing_penalty(irq);
 }
 
 int __init acpi_irq_penalty_init(void)
@@ -881,6 +870,17 @@ bool acpi_isa_irq_available(int irq)
 		    acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
 }
 
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
+{
+	sci_irq = irq;
+
+	if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
+	    polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
+		sci_penalty = PIRQ_PENALTY_PCI_USING;
+	else
+		sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
+}
+
 /*
  * Over-ride default table to reserve additional IRQs for use by ISA
  * e.g. acpi_irq_isa=5
include/linux/acpi.h +1 -0
index c5eaf2f..67d1d3e 100644
@@ -318,6 +318,7 @@ struct pci_dev;
 int acpi_pci_irq_enable (struct pci_dev *dev);
 void acpi_penalize_isa_irq(int irq, int active);
 bool acpi_isa_irq_available(int irq);
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
 void acpi_pci_irq_disable (struct pci_dev *dev);
 
 extern int ec_read(u8 addr, u8 *val);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#13 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

Quoted 7 lines · Bjorn Helgaas

[1] http://marc.info/?l=linux-acpi&m=145580159209240&w=2)

Quoted 1 line
Quoted 1 line

Wait a minute, I still have a question here: what about other ACPI arches (ia64, arm64)? Don't they need to call acpi_penalize_sci_irq() somewhere?

ACPI ARM64 architecture implements reduced ACPI profile which doesn't have GED object. Instead, ARM64 architecture uses onchip peripherals for similar functionality. If there is a need to signal interrupts, this is done by ACPI Notify in ASL or if absolutely needed using ACPI Generic Event Device (GED).

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Acked-by
#14 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

Quoted 9 lines · Sinan Kaya
Quoted 7 lines · Bjorn Helgaas

[1] http://marc.info/?l=linux-acpi&m=145580159209240&w=2)

Quoted 1 line
Quoted 1 line

Wait a minute, I still have a question here: what about other ACPI arches (ia64, arm64)? Don't they need to call acpi_penalize_sci_irq() somewhere?

Quoted 5 lines

ACPI ARM64 architecture implements reduced ACPI profile which doesn't have GED object. Instead, ARM64 architecture uses onchip peripherals for similar functionality. If there is a need to signal interrupts, this is done by ACPI Notify in ASL or if absolutely needed using ACPI Generic Event Device (GED).

OK. I guess ia64 never did call acpi_penalize_sci_irq(), so while it could be added someday to unify things, we don't need to add it now. Same for arm64.

So I'd like it if you updated the changelog, but I'm OK with the patch:

#16 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Bjorn Helgaas
Quoted 36 lines · Bjorn Helgaas
Quoted 28 lines · Sinan Kaya

The SCI penalize function was removed in two steps (first refactor and then remove) and these changes are reverted here in one go.

The commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements") refactored the original code so that SCI penalty is calculated dynamically by the time get_penalty function is called. That change is partially reverted here, specifically for the SCI IRQ alone.

The SCI penalize function was finally dropped by commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") that replaced the old SCI penalty API with penalty calculation carried out dynamically and based on the acpi_gbl_FADT.sci_interrupt value.

However, that new algorithm relies on the accurate setting of IRQ types and that doesn't happen early enough on some platforms which leads to incorrect penalty assignments for PCI IRQs. In those cases, irq_get_trigger_type() returns incorrect values for the IRQs in question, because they have not been registered yet by the time the penalties are calculated.

To fix this problem, we only need to fix the penalty for the SCI interrupt. It seems better to add a single "sci_penalty" variable, set it to PIRQ_PENALTY_PCI_USING if it's level/low or PIRQ_PENALTY_ISA_ALWAYS otherwise, and add "sci_penalty" in when appropriate. That should fix it for *any* SCI IRQ, not just those less than 256, and we don't have to add these extra penalty table entries that are all unused (except possibly for one entry if we have an SCI in the 16-255 range).

Quoted 2 lines

For this reason, revert commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") completely to restore the correct behavior.

I like this patch fine, except for the changelog. I don't think it's useful to describe this as a revert and give all the historical details. I think the important part is something like this:

Quoted 5 lines

We previously used irq_get_trigger_type(irq) to help compute the penalty for the SCI, but that depends on the SCI having been registered already. Add acpi_penalize_sci_irq() so platforms can tell us the SCI IRQ, trigger, and polarity so we can compute the penalty even before the SCI has been registered.

I think this is actually the critical patch that fixes the regression reported by Ondrej, so the changelog really should include details about the regression, e.g., something like this:

ACPI: pci_link: Penalize SCI correctly

Ondrej reported that IRQs stopped working in v4.7 on several platforms. A typical scenario, from Ondrej's VT82C694X/694X, is:

ACPI: Using PIC for interrupt routing
ACPI: PCI Interrupt Link [LNKA] (IRQs 1 3 4 5 6 7 10 *11 12 14 15)
ACPI: No IRQ available for PCI Interrupt Link [LNKA] 8139too 0000:00:0f.0: PCI INT A: no GSI

We're using PIC routing, so acpi_irq_balance == 0, and LNKA is already active at IRQ 11. In that case, acpi_pci_link_allocate() only tries to use the active IRQ (IRQ 11) which also happens to be the SCI.

We should penalize the SCI by PIRQ_PENALTY_PCI_USING, but irq_get_trigger_type(11) returns something other than IRQ_TYPE_LEVEL_LOW, so we penalize it by PIRQ_PENALTY_ISA_ALWAYS instead, which makes acpi_pci_link_allocate() assume the IRQ isn't available and give up.

Add acpi_penalize_sci_irq() so platforms can tell us the SCI IRQ, trigger, and polarity directly and we don't have to depend on irq_get_trigger_type().

I don't understand what's broken about using irq_get_trigger_type(). The SCI is registered in the following path, which is certainly before we try to enable LNKA for the 8139too device:

acpi_init # subsys_initcall
acpi_bus_init
acpi_enable_subsystem
acpi_ev_install_xrupt_handlers
acpi_ev_install_sci_handler
acpi_os_install_interrupt_handler(sci_interrupt, ...)
acpi_gsi_to_irq
acpi_register_gsi
irq_create_fwspec_mapping
irqd_set_trigger_type

In any event, I think this patch to add acpi_penalize_sci_irq() is fine.

Quoted 115 lines
Quoted 4 lines
Fixes commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")
Fixes commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function")

"commit" is redundant; it's sufficient to say:

Fixes 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")

In fact, I don't think you really need to include "commit" in the reference to 9e5ed6d1fb87 above either.

Quoted 97 lines
---
 arch/x86/kernel/acpi/boot.c |  1 +
 drivers/acpi/pci_link.c     | 30 +++++++++++++++---------------
 include/linux/acpi.h        |  1 +
 3 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -0
index 90d84c3..0ffd26e 100644
@@ -453,6 +453,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
 		polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
 	mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
+	acpi_penalize_sci_irq(bus_irq, trigger, polarity);
 
 	/*
 	 * stash over-ride to indicate we've been here
drivers/acpi/pci_link.c +15 -15
index 4f37938..294b190 100644
@@ -87,6 +87,7 @@ struct acpi_pci_link {
 
 static LIST_HEAD(acpi_link_list);
 static DEFINE_MUTEX(acpi_link_lock);
+static int sci_irq = -1, sci_penalty;
 
 /* --------------------------------------------------------------------------
                             PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
 {
 	int penalty = 0;
 
-	/*
-	* Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict
-	* with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
-	* use for PCI IRQs.
-	*/
-	if (irq == acpi_gbl_FADT.sci_interrupt) {
-		u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
-
-		if (type != IRQ_TYPE_LEVEL_LOW)
-			penalty += PIRQ_PENALTY_ISA_ALWAYS;
-		else
-			penalty += PIRQ_PENALTY_PCI_USING;
-	}
+	if (irq == sci_irq)
+		penalty += sci_penalty;
 
 	if (irq < ACPI_MAX_ISA_IRQS)
 		return penalty + acpi_isa_irq_penalty[irq];
 
-	penalty += acpi_irq_pci_sharing_penalty(irq);
-	return penalty;
+	return penalty + acpi_irq_pci_sharing_penalty(irq);
 }
 
 int __init acpi_irq_penalty_init(void)
@@ -881,6 +870,17 @@ bool acpi_isa_irq_available(int irq)
 		    acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
 }
 
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
+{
+	sci_irq = irq;
+
+	if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
+	    polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
+		sci_penalty = PIRQ_PENALTY_PCI_USING;
+	else
+		sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
+}
+
 /*
  * Over-ride default table to reserve additional IRQs for use by ISA
  * e.g. acpi_irq_isa=5
include/linux/acpi.h +1 -0
index c5eaf2f..67d1d3e 100644
@@ -318,6 +318,7 @@ struct pci_dev;
 int acpi_pci_irq_enable (struct pci_dev *dev);
 void acpi_penalize_isa_irq(int irq, int active);
 bool acpi_isa_irq_available(int irq);
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
 void acpi_pci_irq_disable (struct pci_dev *dev);
 
 extern int ec_read(u8 addr, u8 *val);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw

Re: [PATCH V4 3/3] Revert "ACPI, PCI, IRQ: separate ISA penalty calculation"

In reply to Sinan Kaya
Quoted 16 lines · Sinan Kaya

On 10/20/2016 7:31 PM, Bjorn Helgaas wrote:
...

Quoted 4 lines

And I don't think it fixes a user-visible problem, so it doesn't need to be applied immediately. I'm not sure this is worth doing by itself; maybe it should wait until we can do more cleanup and think about all these issues together?

It does fix the PCI_USING penalty assignment.

                if (link->irq.active && link->irq.active == irq)
                         penalty += PIRQ_PENALTY_PCI_USING;

If we drop this patch, then we need
[PATCH V3 1/3] ACPI, PCI IRQ: add PCI_USING penalty for ISA interrupts

Quoted 7 lines

http://www.gossamer-threads.com/lists/linux/kernel/2547605

as somebody needs to increment the penalty with PCI_USING when IRQ is assigned for a given ISA IRQ.

We might as well take [PATCH V4 1/3], [PATCH V4 2/3] and [PATCH V3 1/3] for this regression.

It sounds like either V3 1/3 or V4 3/3 will fix the regression. The V3 1/3 patch is much smaller and essentially makes this piece look like it did in v4.6.

The V4 3/3 patch removes acpi_irq_penalty_init() and compensates by using acpi_irq_pci_sharing_penalty() for ISA IRQs again. But acpi_irq_penalty_init() added PIRQ_PENALTY_PCI_POSSIBLE for _CRS, and only if there was no _PRS, while acpi_irq_pci_sharing_penalty() always adds PIRQ_PENALTY_PCI_USING for _CRS, regardless of whether _PRS exists.

Since V4 3/3 is so much bigger and makes this quite subtle change in how _CRS is handled, I like V3 1/3 better.

Are we all set to go now? I think I've acked the patches you mentioned.

Bjorn

Tested-by on v4 1/3
#7 lore raw

Re: [V4, 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Sinan Kaya
Quoted 31 lines · Sinan Kaya

The penalty determination of ISA IRQ goes through 4 paths.
1. assign PCI_USING during power up via acpi_irq_penalty_init.
2. update the penalty with acpi_penalize_isa_irq function based on the active parameter.
3. kernel command line penalty update via acpi_irq_penalty_update function.
4. increment the penalty as USING right after the IRQ is assign to PCI.

acpi_penalize_isa_irq and acpi_irq_penalty_update functions get called before the ACPI subsystem is started.

These API need to bypass the acpi_irq_get_penalty function.

---
 drivers/acpi/pci_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/pci_link.c +1 -1
index c983bf7..4f37938 100644
@@ -849,7 +849,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
                        continue;
 
                if (used)
-                       new_penalty = acpi_irq_get_penalty(irq) +
+                       new_penalty = acpi_isa_irq_penalty[irq] +
                                        PIRQ_PENALTY_ISA_USED;
                else
                        new_penalty = 0;

drivers/acpi/pci_link.c static int __init acpi_irq_penalty_update(char *str, int used) · line 877

Quoted 8 lines
drivers/acpi/pci_link.c +1 -1
@@ -871,7 +871,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 void acpi_penalize_isa_irq(int irq, int active)
 {
        if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
-               acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) +
+               acpi_isa_irq_penalty[irq] = acpi_isa_irq_penalty[irq] +
                  (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
 }
 

This series fixes one or more network adapters not working in Linux 32-bit x86 guest running inside VirtualBox if I have 4 network adapters enabled. The following message no longer appears in the kernel log:
ACPI: No IRQ available for PCI Interrupt Link [LNKD]. Try pci=noacpi or acpi=off

Tested-by on v4 2/3
#18 lore raw

Re: [V4,2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Sinan Kaya
Quoted 117 lines · Sinan Kaya

The SCI penalize function was removed in two steps (first refactor and then remove) and these changes are reverted here in one go.

The commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements") refactored the original code so that SCI penalty is calculated dynamically by the time get_penalty function is called. That change is partially reverted here, specifically for the SCI IRQ alone.

The SCI penalize function was finally dropped by commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") that replaced the old SCI penalty API with penalty calculation carried out dynamically and based on the acpi_gbl_FADT.sci_interrupt value.

However, that new algorithm relies on the accurate setting of IRQ types and that doesn't happen early enough on some platforms which leads to incorrect penalty assignments for PCI IRQs. In those cases, irq_get_trigger_type() returns incorrect values for the IRQs in question, because they have not been registered yet by the time the penalties are calculated.

To fix this problem, we only need to fix the penalty for the SCI interrupt. It seems better to add a single "sci_penalty" variable, set it to PIRQ_PENALTY_PCI_USING if it's level/low or PIRQ_PENALTY_ISA_ALWAYS otherwise, and add "sci_penalty" in when appropriate. That should fix it for *any* SCI IRQ, not just those less than 256, and we don't have to add these extra penalty table entries that are all unused (except possibly for one entry if we have an SCI in the 16-255 range).

For this reason, revert commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function") completely to restore the correct behavior.

Fixes commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")
Fixes commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function")
---
 arch/x86/kernel/acpi/boot.c |  1 +
 drivers/acpi/pci_link.c     | 30 +++++++++++++++---------------
 include/linux/acpi.h        |  1 +
 3 files changed, 17 insertions(+), 15 deletions(-)
arch/x86/kernel/acpi/boot.c +1 -0
index 90d84c3..0ffd26e 100644
@@ -453,6 +453,7 @@ static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger,
                polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
 
        mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
+       acpi_penalize_sci_irq(bus_irq, trigger, polarity);
 
        /*
         * stash over-ride to indicate we've been here
drivers/acpi/pci_link.c +15 -15
index 4f37938..294b190 100644
@@ -87,6 +87,7 @@ struct acpi_pci_link {
 
 static LIST_HEAD(acpi_link_list);
 static DEFINE_MUTEX(acpi_link_lock);
+static int sci_irq = -1, sci_penalty;
 
 /* --------------------------------------------------------------------------
                             PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
 {
        int penalty = 0;
 
-       /*
-       * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict
-       * with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
-       * use for PCI IRQs.
-       */
-       if (irq == acpi_gbl_FADT.sci_interrupt) {
-               u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
-
-               if (type != IRQ_TYPE_LEVEL_LOW)
-                       penalty += PIRQ_PENALTY_ISA_ALWAYS;
-               else
-                       penalty += PIRQ_PENALTY_PCI_USING;
-       }
+       if (irq == sci_irq)
+               penalty += sci_penalty;
 
        if (irq < ACPI_MAX_ISA_IRQS)
                return penalty + acpi_isa_irq_penalty[irq];
 
-       penalty += acpi_irq_pci_sharing_penalty(irq);
-       return penalty;
+       return penalty + acpi_irq_pci_sharing_penalty(irq);
 }
 
 int __init acpi_irq_penalty_init(void)
@@ -881,6 +870,17 @@ bool acpi_isa_irq_available(int irq)
                    acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
 }
 
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
+{
+       sci_irq = irq;
+
+       if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
+           polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
+               sci_penalty = PIRQ_PENALTY_PCI_USING;
+       else
+               sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
+}
+
 /*
  * Over-ride default table to reserve additional IRQs for use by ISA
  * e.g. acpi_irq_isa=5
include/linux/acpi.h +0 -0
index c5eaf2f..67d1d3e 100644

include/linux/acpi.h struct pci_dev; · line 324

Quoted 7 lines
include/linux/acpi.h +1 -0
@@ -318,6 +318,7 @@ struct pci_dev;
 int acpi_pci_irq_enable (struct pci_dev *dev);
 void acpi_penalize_isa_irq(int irq, int active);
 bool acpi_isa_irq_available(int irq);
+void acpi_penalize_sci_irq(int irq, int trigger, int polarity);
 void acpi_pci_irq_disable (struct pci_dev *dev);
 
 extern int ec_read(u8 addr, u8 *val);

This series fixes one or more network adapters not working in Linux 32-bit x86 guest running inside VirtualBox if I have 4 network adapters enabled. The following message no longer appears in the kernel log:
ACPI: No IRQ available for PCI Interrupt Link [LNKD]. Try pci=noacpi or acpi=off

Tested-by on v4 3/3
#24 lore raw

Re: [V4,3/3] Revert "ACPI,PCI,IRQ: separate ISA penalty calculation"

In reply to Sinan Kaya
Quoted 97 lines · Sinan Kaya

This reverts commit f7eca374f000 ("ACPI,PCI,IRQ: separate ISA penalty calculation") and commit 487cf917ed0d ("revert "ACPI, PCI, IRQ: remove redundant code in acpi_irq_penalty_init()"").

Now that we understand the real issue (SCI and ISA penalty getting calculated before ACPI start), there is no need for special handling for ISA interrupts.

Let's try to simplify the code one more time to share code.

---
 arch/x86/pci/acpi.c         |  1 -
 drivers/acpi/pci_link.c     | 44 +++++---------------------------------------
 include/acpi/acpi_drivers.h |  1 -
 3 files changed, 5 insertions(+), 41 deletions(-)
arch/x86/pci/acpi.c +0 -1
index 3cd6983..b2a4e2a 100644
@@ -396,7 +396,6 @@ int __init pci_acpi_init(void)
                return -ENODEV;
 
        printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
-       acpi_irq_penalty_init();
        pcibios_enable_irq = acpi_pci_irq_enable;
        pcibios_disable_irq = acpi_pci_irq_disable;
        x86_init.pci.init_irq = x86_init_noop;
drivers/acpi/pci_link.c +5 -39
index 294b190..dd14d78 100644
@@ -478,7 +478,8 @@ static int acpi_irq_pci_sharing_penalty(int irq)
                 * If a link is active, penalize its IRQ heavily
                 * so we try to choose a different IRQ.
                 */
-               if (link->irq.active && link->irq.active == irq)
+               if ((link->irq.active && link->irq.active == irq) &&
+                               (link->irq.initialized == 1))
                        penalty += PIRQ_PENALTY_PCI_USING;
 
                /*
@@ -501,45 +502,10 @@ static int acpi_irq_get_penalty(int irq)
                penalty += sci_penalty;
 
        if (irq < ACPI_MAX_ISA_IRQS)
-               return penalty + acpi_isa_irq_penalty[irq];
+               penalty += acpi_isa_irq_penalty[irq];
 
-       return penalty + acpi_irq_pci_sharing_penalty(irq);
-}
-
-int __init acpi_irq_penalty_init(void)
-{
-       struct acpi_pci_link *link;
-       int i;
-
-       /*
-        * Update penalties to facilitate IRQ balancing.
-        */
-       list_for_each_entry(link, &acpi_link_list, list) {
-
-               /*
-                * reflect the possible and active irqs in the penalty table --
-                * useful for breaking ties.
-                */
-               if (link->irq.possible_count) {
-                       int penalty =
-                           PIRQ_PENALTY_PCI_POSSIBLE /
-                           link->irq.possible_count;
-
-                       for (i = 0; i < link->irq.possible_count; i++) {
-                               if (link->irq.possible[i] < ACPI_MAX_ISA_IRQS)
-                                       acpi_isa_irq_penalty[link->irq.
-                                                        possible[i]] +=
-                                           penalty;
-                       }
-
-               } else if (link->irq.active &&
-                               (link->irq.active < ACPI_MAX_ISA_IRQS)) {
-                       acpi_isa_irq_penalty[link->irq.active] +=
-                           PIRQ_PENALTY_PCI_POSSIBLE;
-               }
-       }
-
-       return 0;
+       penalty += acpi_irq_pci_sharing_penalty(irq);
+       return penalty;
 }
 
 static int acpi_irq_balance = -1;      /* 0: static, 1: balance */
include/acpi/acpi_drivers.h +0 -0
index 29c6912..797ae2e 100644

include/acpi/acpi_drivers.h line 83

Quoted 7 lines
include/acpi/acpi_drivers.h +0 -1
@@ -78,7 +78,6 @@
 
 /* ACPI PCI Interrupt Link (pci_link.c) */
 
-int acpi_irq_penalty_init(void);
 int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
                               int *polarity, char **name);
 int acpi_pci_link_free_irq(acpi_handle handle);

This series fixes one or more network adapters not working in Linux 32-bit x86 guest running inside VirtualBox if I have 4 network adapters enabled. The following message no longer appears in the kernel log:
ACPI: No IRQ available for PCI Interrupt Link [LNKD]. Try pci=noacpi or acpi=off

author
#6 lore raw

Re: [PATCH V4 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Bjorn Helgaas
Quoted 5 lines · Bjorn Helgaas
Quoted 1 line

These API need to bypass the acpi_irq_get_penalty function.

I don't mind this patch, but the changelog doesn't tell me what's broken and why we need this fix. Apparently acpi_irq_get_penalty() doesn't work before ACPI is initialized, but I don't see *why* it wouldn't work.

I'll update the commit message as you suggested. The code doesn't work if we apply PATCH V4 2/3 + PATCH V4 3/3 without PATCH V4 1/3 since the caller is going to end up calling get_penalty function while ACPI is not initialized. This happened during the debug of this regression.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#3 lore raw

Re: [PATCH V4 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 6 lines
(quoted diff) +0 -0
@@ -871,7 +871,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
 >  void acpi_penalize_isa_irq(int irq, int active)
 >  {
 >         if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))

drivers/acpi/pci_link.c static int __init acpi_irq_penalty_update(char *str, int used) · line 874

Quoted 2 lines
drivers/acpi/pci_link.c +1 -1
-               acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) +
+               acpi_isa_irq_penalty[irq] = acpi_isa_irq_penalty[irq] +

This looks slightly odd. What about

+ acpi_isa_irq_penalty[irq] +=

Quoted 2 lines
Quoted 2 lines
                  (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);

}

Makes sense.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#15 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Sinan Kaya
Quoted 6 lines · Sinan Kaya
Quoted 4 lines

Wait a minute, I still have a question here: what about other ACPI

Quoted 3 lines

arches (ia64, arm64)? Don't they need to call acpi_penalize_sci_irq() somewhere?

ACPI ARM64 architecture implements reduced ACPI profile which doesn't have GED object.

I actually wanted to mean that ARM64 architecture doesn't have *GPE* object implemented on ACPI reduced profile.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#17 lore raw

Re: [PATCH V4 2/3] Revert "ACPI,PCI,IRQ: remove SCI penalize function"

In reply to Bjorn Helgaas
Quoted 9 lines · Bjorn Helgaas

I like this patch fine, except for the changelog. I don't think it's useful to describe this as a revert and give all the historical details. I think the important part is something like this:

We previously used irq_get_trigger_type(irq) to help compute the penalty for the SCI, but that depends on the SCI having been registered already. Add acpi_penalize_sci_irq() so platforms can tell us the SCI IRQ, trigger, and polarity so we can compute the penalty even before the SCI has been registered.

OK, will replace with this and also change the commit summary as

"ACPI,PCI,IRQ: save SCI IRQ details for runtime penalty calculation"

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Fixes commit 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")
Fixes commit 9e5ed6d1fb87 ("ACPI,PCI,IRQ: remove SCI penalize function")

"commit" is redundant; it's sufficient to say:

OK. I have been fighting with checkpatch. Checkpatch doesn't like a commit summary without "commit 12 char SHA"

Quoted 6 lines
Fixes 103544d86976 ("ACPI,PCI,IRQ: reduce resource requirements")

In fact, I don't think you really need to include "commit" in the reference to 9e5ed6d1fb87 above either.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#23 lore raw

Re: [PATCH V4 3/3] Revert "ACPI, PCI, IRQ: separate ISA penalty calculation"

In reply to Bjorn Helgaas
Quoted 3 lines · Bjorn Helgaas

Since V4 3/3 is so much bigger and makes this quite subtle change in how _CRS is handled, I like V3 1/3 better.

OK

Quoted 2 lines

Are we all set to go now? I think I've acked the patches you mentioned.

Yes, I'll post a follow up with your recommendations.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
author
#8 lore raw

Re: [V4, 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

In reply to Jonathan Liu

Thanks,

Quoted 7 lines · Jonathan Liu

This series fixes one or more network adapters not working in Linux 32-bit x86 guest running inside VirtualBox if I have 4 network adapters enabled. The following message no longer appears in the kernel log:
ACPI: No IRQ available for PCI Interrupt Link [LNKD]. Try pci=noacpi or acpi=off

I'm hoping that you can retest V5 so that Rafael can pull in your tested-by into the commit message.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#9 lore raw

Re: [V4, 1/3] ACPI, PCI, IRQ: assign ISA IRQ directly during early boot stages

Quoted 11 lines · Sinan Kaya

Thanks,

Quoted 7 lines · Jonathan Liu

This series fixes one or more network adapters not working in Linux 32-bit x86 guest running inside VirtualBox if I have 4 network adapters enabled. The following message no longer appears in the kernel log:
ACPI: No IRQ available for PCI Interrupt Link [LNKD]. Try pci=noacpi or acpi=off

Quoted 7 lines

I'm hoping that you can retest V5 so that Rafael can pull in your tested-by into the commit message.

--
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

Sure. Please CC me when you submit V5.

Regards,
Jonathan