rtc: cmos: Use shared IRQ only for Microsoft Surface 3
PATCH 1/8 rtc: cmos: Use shared IRQ only for Microsoft Surface 3
As reported by Guilherme:
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.
This patch changes this behavior by preventing shared interrupts for everything, but Microsoft Surface 3 as stated in the culprit commit message. 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.
--- drivers/rtc/rtc-cmos.c | 21 +++++++++++++++++++-- include/linux/mc146818rtc.h | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-)
drivers/rtc/rtc-cmos.c +19 -2
@@ -27,6 +27,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/dmi.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h>
@@ -40,7 +41,6 @@#ifdef CONFIG_X86 #include <asm/i8259.h> #include <asm/processor.h> -#include <linux/dmi.h> #endif /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
@@ -836,6 +836,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)if (is_valid_irq (rtc_irq)) {irq_handler_t rtc_cmos_int_handler; +unsigned long irq_flags =0 ;if (use_hpet_alarm ()) { rtc_cmos_int_handler = hpet_rtc_interrupt;
@@ -849,8 +850,11 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) }else rtc_cmos_int_handler = cmos_interrupt; +if (flags &CMOS_RTC_FLAGS_SHARED_IRQ ) + irq_flags |=IRQF_SHARED ; + retval =request_irq (rtc_irq, rtc_cmos_int_handler, -IRQF_SHARED ,dev_name (&cmos_rtc.rtc->dev), + irq_flags,dev_name (&cmos_rtc.rtc->dev), cmos_rtc.rtc);if (retval <0 ) {dev_dbg (dev,"IRQ %d is already in use\n" , rtc_irq);
@@ -1215,6 +1219,16 @@ static void use_acpi_alarm_quirks(void)static inline void use_acpi_alarm_quirks (void ) { }#endif +static const struct dmi_system_id rtc_cmos_surface3_table[] = { + { + .ident ="Microsoft Surface 3" , + .matches = { +DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), + }, + }, + {} +}; +/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find * its device node and pass extra config data. This helps its driver use * capabilities that the now-obsolete mc146818 didn't have, and informs it
@@ -1229,6 +1243,9 @@ static void cmos_wake_setup(struct device *dev)use_acpi_alarm_quirks (); +if (dmi_check_system (rtc_cmos_surface3_table)) + acpi_rtc_info.flags |=CMOS_RTC_FLAGS_SHARED_IRQ ; +rtc_wake_setup (dev); acpi_rtc_info.wake_on = rtc_wake_on; acpi_rtc_info.wake_off = rtc_wake_off;
include/linux/mc146818rtc.h +3 -1
@@ -35,7 +35,9 @@ struct cmos_rtc_board_info {void (*wake_off)(struct device *dev);u32 flags; -#define CMOS_RTC_FLAGS_NOFREQ (1 << 0) +#define CMOS_RTC_FLAGS_NOFREQ (1 << 0) +#define CMOS_RTC_FLAGS_SHARED_IRQ (1 << 1) +int address_space;u8 rtc_day_alarm;/* zero, or register index */
Signature · 1 line
2.24.1
PATCH 2/8 x86/platform: Rename x86/apple.h -> x86/machine.h
Rename linux/platform_data/x86/apple.h to linux/platform_data/x86/machine.h in order to add new quirks later on. For sake of being less intrusive, leave former file that includes a latter one.
While here, add include to linux/types.h due to bool type in use.
--- include/linux/platform_data/x86/apple.h | 14 +------------- include/linux/platform_data/x86/machine.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 include/linux/platform_data/x86/machine.h
include/linux/platform_data/x86/apple.h +1 -13
@@ -1,13 +1 @@ -#ifndef PLATFORM_DATA_X86_APPLE_H -#define PLATFORM_DATA_X86_APPLE_H - -#ifdef CONFIG_X86 -/** -* x86_apple_machine - whether the machine is an x86 Apple Macintosh -*/ -extern bool x86_apple_machine; -#else -#define x86_apple_machine false -#endif - -#endif +#include <linux/platform_data/x86/machine.h>
include/linux/platform_data/x86/machine.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef PLATFORM_DATA_X86_MACHINE_H +#define PLATFORM_DATA_X86_MACHINE_H + +#include <linux/types.h> + +#ifdef CONFIG_X86 +/** +* x86_apple_machine - whether the machine is an x86 Apple Macintosh +*/ +extern bool x86_apple_machine; +#else +#define x86_apple_machine false +#endif + +#endif /* PLATFORM_DATA_X86_MACHINE_H */
Signature · 1 line
2.24.1
PATCH 3/8 x86/quirks: Add missed include to satisfy static checker
In reply to Andy ShevchenkoStatic checker is not happy with
.../kernel/quirks.c:666:6: warning: symbol 'x86_apple_machine' was not declared. Should it be static?
This is due to missed inclusion. Add it to satisfy the static checker.
--- arch/x86/kernel/quirks.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/quirks.c +1 -0
@@ -4,6 +4,7 @@*/ #include <linux/dmi.h> #include <linux/pci.h> +#include <linux/platform_data/x86/machine.h> #include <linux/irq.h> #include <asm/hpet.h>
Signature · 1 line
2.24.1
PATCH 4/8 x86/quirks: Convert DMI matching to use a table
In reply to Andy ShevchenkoIn order to extend the DMI based quirks, convert them to a table.
--- arch/x86/kernel/quirks.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
arch/x86/kernel/quirks.c +25 -2
@@ -667,8 +667,31 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_rasbool x86_apple_machine;EXPORT_SYMBOL (x86_apple_machine); +static int apple_machine_cb (const struct dmi_system_id *id) +{ + x86_apple_machine = true; +return 1 ; +} + +static const struct dmi_system_id x86_machine_table[] = { + { + .ident ="x86 Apple Macintosh" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Inc." ), + }, + .callback = apple_machine_cb, + }, + { + .ident ="x86 Apple Macintosh" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Apple Computer, Inc." ), + }, + .callback = apple_machine_cb, + }, + {} +}; +void __init early_platform_quirks (void ) { - x86_apple_machine =dmi_match (DMI_SYS_VENDOR ,"Apple Inc." ) || -dmi_match (DMI_SYS_VENDOR ,"Apple Computer, Inc." ); +dmi_check_system (x86_machine_table); }
Signature · 1 line
2.24.1
PATCH 5/8 x86/quirks: Add a DMI quirk for Microsoft Surface 3
In reply to Andy ShevchenkoAdd a DMI quirk for Microsoft Surface 3 which will be utilized by few drivers.
--- arch/x86/kernel/quirks.c | 16 ++++++++++++++++ include/linux/platform_data/x86/machine.h | 5 +++++ 2 files changed, 21 insertions(+)
arch/x86/kernel/quirks.c +16 -0
@@ -673,6 +673,15 @@ static int apple_machine_cb(const struct dmi_system_id *id)return 1 ; } +bool x86_microsoft_surface_3_machine; +EXPORT_SYMBOL (x86_microsoft_surface_3_machine); + +static int microsoft_surface_3_machine_cb (const struct dmi_system_id *id) +{ + x86_microsoft_surface_3_machine = true; +return 1 ; +} +static const struct dmi_system_id x86_machine_table[] = { { .ident ="x86 Apple Macintosh" ,
@@ -688,6 +697,13 @@ static const struct dmi_system_id x86_machine_table[] = { }, .callback = apple_machine_cb, }, + { + .ident = "Microsoft Surface 3", + .matches = { + DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"), + }, + .callback = microsoft_surface_3_machine_cb, + }, {} };
include/linux/platform_data/x86/machine.h +5 -0
@@ -8,8 +8,13 @@* x86_apple_machine - whether the machine is an x86 Apple Macintosh */ extern bool x86_apple_machine; +/** +* x86_microsoft_surface_3_machine - whether the machine is Microsoft Surface 3 +*/ +extern bool x86_microsoft_surface_3_machine;#else #define x86_apple_machine false +#define x86_microsoft_surface_3_machine false#endif #endif /* PLATFORM_DATA_X86_MACHINE_H */
Signature · 1 line
2.24.1
Mark Brown
maintainerRe: [PATCH v1 5/8] x86/quirks: Add a DMI quirk for Microsoft Surface 3
Quoted 1 line · Andy Shevchenko
Add a DMI quirk for Microsoft Surface 3 which will be utilized by few drivers.
I have patches 5 and 7 with no other context, what's going on with dependencies here?
Re: [PATCH v1 5/8] x86/quirks: Add a DMI quirk for Microsoft Surface 3
Quoted 5 lines · Mark Brown
Quoted 1 line · Andy Shevchenko
Add a DMI quirk for Microsoft Surface 3 which will be utilized by few drivers.
I have patches 5 and 7 with no other context, what's going on with dependencies here?
Other patches has no relation to ASoC or vise versa. I will Cc you for entire series in next version.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 6/8 platform/x86: surface3_wmi: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
--- drivers/platform/x86/surface3-wmi.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/platform/x86/surface3-wmi.c +2 -14
@@ -11,9 +11,9 @@#include <linux/slab.h> #include <linux/acpi.h> -#include <linux/dmi.h> #include <linux/input.h> #include <linux/mutex.h> +#include <linux/platform_data/x86/machine.h> #include <linux/platform_device.h> #include <linux/spi/spi.h>
@@ -29,18 +29,6 @@ MODULE_LICENSE("GPL");MODULE_ALIAS ("wmi:" SURFACE3_LID_GUID ); -static const struct dmi_system_id surface3_dmi_table[] = { -#if defined(CONFIG_X86) - { - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, -#endif - { } -}; -struct surface3_wmi {struct acpi_device *touchscreen_adev;struct acpi_device *pnp0c0d_adev;
@@ -201,7 +189,7 @@ static int __init s3_wmi_probe(struct platform_device *pdev) {int error; -if (!dmi_check_system (surface3_dmi_table)) +if (!x86_microsoft_surface_3_machine)return -ENODEV ;memset (&s3_wmi,0 ,sizeof (s3_wmi));
Signature · 1 line
2.24.1
PATCH 7/8 ASoC: Intel: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
--- .../intel/common/soc-acpi-intel-cht-match.c | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-)
sound/soc/intel/common/soc-acpi-intel-cht-match.c +3 -25
@@ -5,31 +5,11 @@* Copyright (c) 2017, Intel Corporation. */ -#include <linux/dmi.h> +#include <linux/platform_data/x86/machine.h> +#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> -static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 - -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} - -static const struct dmi_system_id cht_table[] = { - { - .callback = cht_surface_quirk_cb, - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, - { } -}; -static struct snd_soc_acpi_mach cht_surface_mach = { .id ="10EC5640" , .drv_name ="cht-bsw-rt5645" ,
@@ -43,9 +23,7 @@ static struct snd_soc_acpi_mach *cht_quirk(void *arg) {struct snd_soc_acpi_mach *mach = arg; -dmi_check_system (cht_table); - -if (cht_machine_id ==CHT_SURFACE_MACH ) +if (x86_microsoft_surface_3_machine)return &cht_surface_mach;else return mach;
Signature · 6 lines
2.24.1 _______________________________________________ Alsa-devel mailing list [email protected] https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [PATCH v1 7/8] ASoC: Intel: Switch DMI table match to a test of variable
Quoted 10 lines · Andy Shevchenko
Since we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
Cc Cezary Rojewski <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Cc Liam Girdwood <[email protected]>Cc Jie Yang <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Thanks Andy.
Quoted 54 lines
--- .../intel/common/soc-acpi-intel-cht-match.c | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-)sound/soc/intel/common/soc-acpi-intel-cht-match.c +3
-25@@ -5,31 +5,11 @@* Copyright (c) 2017, Intel Corporation. */ -#include <linux/dmi.h> +#include <linux/platform_data/x86/machine.h> +#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> -static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 - -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} - -static const struct dmi_system_id cht_table[] = { - { - .callback = cht_surface_quirk_cb, - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, - { } -}; -static struct snd_soc_acpi_mach cht_surface_mach = { .id ="10EC5640" , .drv_name ="cht-bsw-rt5645" ,@@ -43,9 +23,7 @@ static struct snd_soc_acpi_mach *cht_quirk(void *arg) {struct snd_soc_acpi_mach *mach = arg; -dmi_check_system (cht_table); - -if (cht_machine_id ==CHT_SURFACE_MACH ) +if (x86_microsoft_surface_3_machine)return &cht_surface_mach;else return mach;
Re: [PATCH v1 7/8] ASoC: Intel: Switch DMI table match to a test of variable
Quoted 12 lines · Pierre-Louis Bossart
Quoted 10 lines · Andy Shevchenko
Since we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
Cc Cezary Rojewski <[email protected]>Cc Pierre-Louis Bossart <[email protected]>Cc Liam Girdwood <[email protected]>Cc Jie Yang <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 3 lines
Thanks Andy.
Thank you. Though I think I'll re-do this a bit, i.e.
- convert the cht_quirk() to oneliner that is using ternary operator
- convert also codec driver to use variable instead of DMI match
Quoted 52 lines
Quoted 52 lines
--- .../intel/common/soc-acpi-intel-cht-match.c | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-)sound/soc/intel/common/soc-acpi-intel-cht-match.c +3
-25@@ -5,31 +5,11 @@* Copyright (c) 2017, Intel Corporation. */ -#include <linux/dmi.h> +#include <linux/platform_data/x86/machine.h> +#include <sound/soc-acpi.h> #include <sound/soc-acpi-intel-match.h> -static unsigned long cht_machine_id; - -#define CHT_SURFACE_MACH 1 - -static int cht_surface_quirk_cb (const struct dmi_system_id *id) -{ - cht_machine_id =CHT_SURFACE_MACH ; -return 1 ; -} - -static const struct dmi_system_id cht_table[] = { - { - .callback = cht_surface_quirk_cb, - .matches = { -DMI_MATCH (DMI_SYS_VENDOR ,"Microsoft Corporation" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, - { } -}; -static struct snd_soc_acpi_mach cht_surface_mach = { .id ="10EC5640" , .drv_name ="cht-bsw-rt5645" ,@@ -43,9 +23,7 @@ static struct snd_soc_acpi_mach *cht_quirk(void *arg) {struct snd_soc_acpi_mach *mach = arg; -dmi_check_system (cht_table); - -if (cht_machine_id ==CHT_SURFACE_MACH ) +if (x86_microsoft_surface_3_machine)return &cht_surface_mach;else return mach;
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 8/8 rtc: cmos: Switch DMI table match to a test of variable
In reply to Andy ShevchenkoSince we have a common x86 quirk that provides an exported variable, use it instead of local DMI table match.
--- drivers/rtc/rtc-cmos.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/rtc/rtc-cmos.c +2 -11
@@ -33,6 +33,7 @@#include <linux/init.h> #include <linux/interrupt.h> #include <linux/spinlock.h> +#include <linux/platform_data/x86/machine.h> #include <linux/platform_device.h> #include <linux/log2.h> #include <linux/pm.h>
@@ -1219,16 +1220,6 @@ static void use_acpi_alarm_quirks(void)static inline void use_acpi_alarm_quirks (void ) { }#endif -static const struct dmi_system_id rtc_cmos_surface3_table[] = { - { - .ident ="Microsoft Surface 3" , - .matches = { -DMI_MATCH (DMI_PRODUCT_NAME ,"Surface 3" ), - }, - }, - {} -}; -/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find * its device node and pass extra config data. This helps its driver use * capabilities that the now-obsolete mc146818 didn't have, and informs it
@@ -1243,7 +1234,7 @@ static void cmos_wake_setup(struct device *dev)use_acpi_alarm_quirks (); -if (dmi_check_system (rtc_cmos_surface3_table)) +if (x86_microsoft_surface_3_machine) acpi_rtc_info.flags |=CMOS_RTC_FLAGS_SHARED_IRQ ;rtc_wake_setup (dev);
Signature · 1 line
2.24.1
Quoted 33 lines · Andy Shevchenko
As reported by Guilherme:
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.This patch changes this behavior by preventing shared interrupts for everything, but Microsoft Surface 3 as stated in the culprit commit message. 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
Quoted 8 lines
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.
Fixes 079062b28fb4 ("rtc: cmos: prevent kernel warning on IRQ flags mismatch")Reported-by Guilherme G. Piccoli <[email protected]>Suggested-by Thomas Gleixner <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Andy, thanks for the great patch! It works for me, I've tested it on top of 5.5-rc7, no more RTC lost interrupts while using the "irqpoll" parameter. So, feel free to add my:
Cheers,
Guilherme
Quoted 7 lines · Guilherme G. Piccoli
On 17/01/2020 14:56, Andy Shevchenko wrote:
Andy, thanks for the great patch! It works for me, I've tested it on top of 5.5-rc7, no more RTC lost interrupts while using the "irqpoll" parameter. So, feel free to add my:
Tested-by Guilherme G. Piccoli <[email protected]>
Thank you for testing!
(Un)fortunately I dug a bit into the history of the patches and into the ACPI tables of MS Surface 3. I have another (better) solution which I will send separately from this series.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
[...]
Thank you for testing!(Un)fortunately I dug a bit into the history of the patches and into the ACPI tables of MS Surface 3. I have another (better) solution which I will send separately from this series.
OK, if possible, loop me in and I can test that too. Appreciate your effort on this!
Thanks,
Guilherme