Skip to contentSkip to conversation

rtc: cmos: Stop using shared IRQ

PATCH Superseded Andy Shevchenko 3 participants 9 messages Jan 22, 2020 – Jan 23, 2020 Real time clock (RTC)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 rtc: cmos: Stop using shared IRQ

As reported by Guilherme G. Piccoli:

--- 8< --- 8< ---

The rtc-cmos interrupt setting was changed in the commit 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch") in order to allow shared interrupts; according to that commit's description, some machine got kernel warnings due to the interrupt line being shared between rtc-cmos and other hardware, and rtc-cmos didn't allow IRQ sharing that time.

After the aforementioned commit though it was observed a huge increase in lost HPET interrupts in some systems, observed through the following kernel message:

[...] hpet1: lost 35 rtc interrupts

After investigation, it was narrowed down to the shared interrupts usage when having the kernel option "irqpoll" enabled. In this case, all IRQ handlers are called for non-timer interrupts, if such handlers are setup in shared IRQ lines. The rtc-cmos IRQ handler could be set to hpet_rtc_interrupt(), which will produce the kernel "lost interrupts" message after doing work - lots of readl/writel to HPET registers, which are known to be slow.

Although "irqpoll" is not a default kernel option, it's used in some contexts, one being the kdump kernel (which is an already "impaired" kernel usually running with 1 CPU available), so the performance burden could be considerable. Also, the same issue would happen (in a shorter extent though) when using "irqfixup" kernel option.

In a quick experiment, a virtual machine with uptime of 2 minutes produced

Quoted 1 line

300 calls to hpet_rtc_interrupt() when "irqpoll" was set, whereas without

sharing interrupts this number reduced to 1 interrupt. Machines with more hardware than a VM should generate even more unnecessary HPET interrupts in this scenario.

--- 8< --- 8< ---

After looking into the rtc-cmos driver history and DSDT table from the Microsoft Surface 3, we may notice that Hans de Goede submitted a correct fix (see dependency below). Thus, we simply revert the culprit commit.

Fixes 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch")

Depends-on: a1e23a42f1bd ("rtc: cmos: Do not assume irq 8 for rtc when there are no legacy irqs")

---
 drivers/rtc/rtc-cmos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-cmos.c +1 -1
index 033303708c8b..cb28bbdc9e17 100644
@@ -850,7 +850,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
 			rtc_cmos_int_handler = cmos_interrupt;
 
 		retval = request_irq(rtc_irq, rtc_cmos_int_handler,
-				IRQF_SHARED, dev_name(&cmos_rtc.rtc->dev),
+				0, dev_name(&cmos_rtc.rtc->dev),
 				cmos_rtc.rtc);
 		if (retval < 0) {
 			dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/3 rtc: cmos: Use predefined value for RTC IRQ on legacy x86

When legacy devices are present on x86 machine, the RTC IRQ has a dedicated pre-defined value. Use it instead of hard coded number.

---
 drivers/rtc/rtc-cmos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-cmos.c +1 -1
index cb28bbdc9e17..aee55b658f85 100644
@@ -1305,7 +1305,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 		 * hardcode it on systems with a legacy PIC.
 		 */
 		if (nr_legacy_irqs())
-			irq = 8;
+			irq = RTC_IRQ;
 #endif
 		return cmos_do_probe(&pnp->dev,
 				pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
Signature · 1 line
2.24.1
#2 lore raw

PATCH 3/3 rtc: cmos: Refactor code by using the new dmi_get_bios_year() helper

In reply to Andy Shevchenko

Refactor code by using the new dmi_get_bios_year() helper instead of open coding its functionality. This also makes logic slightly clearer.

No changes intended.

---
 drivers/rtc/rtc-cmos.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/rtc/rtc-cmos.c +4 -4
index aee55b658f85..b795fe4cbd2e 100644
@@ -1197,8 +1197,6 @@ static void rtc_wake_off(struct device *dev)
 /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
 static void use_acpi_alarm_quirks(void)
 {
-	int year;
-
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
 		return;
 
@@ -1208,8 +1206,10 @@ static void use_acpi_alarm_quirks(void)
 	if (!is_hpet_enabled())
 		return;
 
-	if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015)
-		use_acpi_alarm = true;
+	if (dmi_get_bios_year() < 2015)
+		return;
+
+	use_acpi_alarm = true;
 }
 #else
 static inline void use_acpi_alarm_quirks(void) { }
Signature · 1 line
2.24.1
#3 lore raw
In reply to Andy Shevchenko

Hi,

Quoted 44 lines · Andy Shevchenko

As reported by Guilherme G. Piccoli:

--- 8< --- 8< ---

The rtc-cmos interrupt setting was changed in the commit 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch") in order to allow shared interrupts; according to that commit's description, some machine got kernel warnings due to the interrupt line being shared between rtc-cmos and other hardware, and rtc-cmos didn't allow IRQ sharing that time.

After the aforementioned commit though it was observed a huge increase in lost HPET interrupts in some systems, observed through the following kernel message:

[...] hpet1: lost 35 rtc interrupts

After investigation, it was narrowed down to the shared interrupts usage when having the kernel option "irqpoll" enabled. In this case, all IRQ handlers are called for non-timer interrupts, if such handlers are setup in shared IRQ lines. The rtc-cmos IRQ handler could be set to hpet_rtc_interrupt(), which will produce the kernel "lost interrupts" message after doing work - lots of readl/writel to HPET registers, which are known to be slow.

Although "irqpoll" is not a default kernel option, it's used in some contexts, one being the kdump kernel (which is an already "impaired" kernel usually running with 1 CPU available), so the performance burden could be considerable. Also, the same issue would happen (in a shorter extent though) when using "irqfixup" kernel option.

In a quick experiment, a virtual machine with uptime of 2 minutes produced

Quoted 1 line

300 calls to hpet_rtc_interrupt() when "irqpoll" was set, whereas without

sharing interrupts this number reduced to 1 interrupt. Machines with more hardware than a VM should generate even more unnecessary HPET interrupts in this scenario.

--- 8< --- 8< ---

After looking into the rtc-cmos driver history and DSDT table from the Microsoft Surface 3, we may notice that Hans de Goede submitted a correct fix (see dependency below). Thus, we simply revert the culprit commit.

Quoted 5 lines
Fixes 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch")

Depends-on: a1e23a42f1bd ("rtc: cmos: Do not assume irq 8 for rtc when there are no legacy irqs")

Entire series looks good to me:

Regards,

Hans

Quoted 18 lines
---
  drivers/rtc/rtc-cmos.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-cmos.c +1 -1
index 033303708c8b..cb28bbdc9e17 100644
@@ -850,7 +850,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
  			rtc_cmos_int_handler = cmos_interrupt;
 
  		retval = request_irq(rtc_irq, rtc_cmos_int_handler,
-				IRQF_SHARED, dev_name(&cmos_rtc.rtc->dev),
+				0, dev_name(&cmos_rtc.rtc->dev),
  				cmos_rtc.rtc);
  		if (retval < 0) {
  			dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
Reviewed-by
#4 lore raw

Hi,

Quoted 53 lines · Hans de Goede

Hi,

Quoted 44 lines · Andy Shevchenko

As reported by Guilherme G. Piccoli:

--- 8< --- 8< ---

The rtc-cmos interrupt setting was changed in the commit 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch") in order to allow shared interrupts; according to that commit's description, some machine got kernel warnings due to the interrupt line being shared between rtc-cmos and other hardware, and rtc-cmos didn't allow IRQ sharing that time.

After the aforementioned commit though it was observed a huge increase in lost HPET interrupts in some systems, observed through the following kernel message:

[...] hpet1: lost 35 rtc interrupts

After investigation, it was narrowed down to the shared interrupts usage when having the kernel option "irqpoll" enabled. In this case, all IRQ handlers are called for non-timer interrupts, if such handlers are setup in shared IRQ lines. The rtc-cmos IRQ handler could be set to hpet_rtc_interrupt(), which will produce the kernel "lost interrupts" message after doing work - lots of readl/writel to HPET registers, which are known to be slow.

Although "irqpoll" is not a default kernel option, it's used in some contexts, one being the kdump kernel (which is an already "impaired" kernel usually running with 1 CPU available), so the performance burden could be considerable. Also, the same issue would happen (in a shorter extent though) when using "irqfixup" kernel option.

In a quick experiment, a virtual machine with uptime of 2 minutes produced

Quoted 1 line

300 calls to hpet_rtc_interrupt() when "irqpoll" was set, whereas without

sharing interrupts this number reduced to 1 interrupt. Machines with more hardware than a VM should generate even more unnecessary HPET interrupts in this scenario.

--- 8< --- 8< ---

After looking into the rtc-cmos driver history and DSDT table from the Microsoft Surface 3, we may notice that Hans de Goede submitted a correct fix (see dependency below). Thus, we simply revert the culprit commit.

Quoted 5 lines
Fixes 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch")

Depends-on: a1e23a42f1bd ("rtc: cmos: Do not assume irq 8 for rtc when there are no legacy irqs")

Quoted 3 lines

Entire series looks good to me:

That should have been:

Of course, sorry.

Regards,

Hans

Quoted 17 lines
Quoted 17 lines

---
  drivers/rtc/rtc-cmos.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-cmos.c +1 -1
index 033303708c8b..cb28bbdc9e17 100644
@@ -850,7 +850,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
               rtc_cmos_int_handler = cmos_interrupt;
           retval = request_irq(rtc_irq, rtc_cmos_int_handler,
-                IRQF_SHARED, dev_name(&cmos_rtc.rtc->dev),
+                0, dev_name(&cmos_rtc.rtc->dev),
                   cmos_rtc.rtc);
           if (retval < 0) {
               dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
 
Tested-by on v1 1/3
#5 lore raw
In reply to Andy Shevchenko
Quoted 1 line · Andy Shevchenko

[...]

Thank you Andy, great and simple series! I've tested that on top of 5.5-rc7 and it's working fine with "irqpoll" enabled. Feel free to add my:

The only oddity here is about the scissors, I'm not sure how it is supposed to work on git, but when I git am'ed the patch, the commit message was only "As reported by Guilherme G. Piccoli:", everything else was dropped.
Cheers,

Guilherme

#6 lore raw
Quoted 9 lines · Guilherme Piccoli
Quoted 1 line · Andy Shevchenko

[...]

Thank you Andy, great and simple series! I've tested that on top of 5.5-rc7 and it's working fine with "irqpoll" enabled. Feel free to add my:

Thanks!

Quoted 4 lines

The only oddity here is about the scissors, I'm not sure how it is supposed to work on git, but when I git am'ed the patch, the commit message was only "As reported by Guilherme G. Piccoli:", everything else was dropped.

I didn't read any RFC or document about '--- ' line. But seems either bug in git-am, or I have to put something else at the beginning of those lines.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 9 lines · Andy Shevchenko

[...]

Quoted 4 lines

The only oddity here is about the scissors, I'm not sure how it is supposed to work on git, but when I git am'ed the patch, the commit message was only "As reported by Guilherme G. Piccoli:", everything else was dropped.

I didn't read any RFC or document about '--- ' line. But seems either bug in git-am, or I have to put something else at the beginning of those lines.

Interesting! What I usually do is to add comments to-be-disregarded-on-merge right below "---", before the diff starts. Git will discard this full block. I guess probably having the "---" on top makes Git discard everything below it until the diff. Anyway, hope your commit message don't get messed in the merge heh

Cheers,

Guilherme

#8 lore raw
Quoted 8 lines · Guilherme Piccoli
Quoted 6 lines · Andy Shevchenko

[...]

Quoted 4 lines

The only oddity here is about the scissors, I'm not sure how it is supposed to work on git, but when I git am'ed the patch, the commit message was only "As reported by Guilherme G. Piccoli:", everything else was dropped.

Quoted 8 lines
Quoted 3 lines

I didn't read any RFC or document about '--- ' line. But seems either bug in git-am, or I have to put something else at the beginning of those lines.

Interesting! What I usually do is to add comments to-be-disregarded-on-merge right below "---", before the diff starts. Git will discard this full block. I guess probably having the "---" on top makes Git discard everything below it until the diff.

For the record it's '--- ' (mind the whitespace at the end).

Quoted 1 line

Anyway, hope your commit message don't get messed in the merge heh

I'll send a new version.

Signature · 2 lines
With Best Regards,
Andy Shevchenko