x86/time: check usability of IRQ0 PIT timer
Subsystems (4)
PATCH 1/2 x86/time: check usability of IRQ0 PIT timer
Modern Intel SoCs now include a special ITSSPRC register that can be used to "gate" the PIT such that IRQ0 interrupts do not fire.
With Intel Apollo Lake we are starting to see consumer products that have a BIOS option to apply this (defaulting to gated). Some such products also lack the HPET ACPI table, so there is no HPET either.
At this point, Linux needs to stop assuming that the IRQ0 timer is available.
Move APIC code to check IRQ0 to time.c, then check and record the IRQ0 PIT timer usability after it is set up. If it does not produce any interrupts, unregister the clock event source.
--- arch/x86/include/asm/time.h | 2 + arch/x86/kernel/apic/io_apic.c | 101 ++++--------------------------- arch/x86/kernel/i8253.c | 6 ++ arch/x86/kernel/time.c | 106 ++++++++++++++++++++++++++++++++- drivers/clocksource/i8253.c | 6 ++ include/linux/clockchips.h | 3 + include/linux/i8253.h | 2 + kernel/time/tick-internal.h | 2 - 8 files changed, 134 insertions(+), 94 deletions(-)
arch/x86/include/asm/time.h +2 -0
@@ -10,4 +10,6 @@ extern void time_init(void);extern struct clock_event_device *global_clock_event; +extern bool irq0_timer_works (void ); +#endif /* _ASM_X86_TIME_H */
arch/x86/kernel/apic/io_apic.c +11 -90
143 lines not on this page · raw message
arch/x86/kernel/i8253.c +6 -0
@@ -24,6 +24,12 @@ void __init setup_pit_timer(void) global_clock_event = &i8253_clockevent; } +void __init remove_pit_timer (void ) +{ +clockevent_i8253_exit (); + global_clock_event =NULL ; +} +#ifndef CONFIG_X86_64 static int __init init_pit_clocksource (void ) {
arch/x86/kernel/time.c +104 -2
128 lines not on this page · raw message
drivers/clocksource/i8253.c +6 -0
@@ -193,4 +193,10 @@ void __init clockevent_i8253_init(bool oneshot)clockevents_config_and_register (&i8253_clockevent,PIT_TICK_RATE , 0xF, 0x7FFF); } + +void __init clockevent_i8253_exit (void ) +{ +clockevents_switch_state (&i8253_clockevent,CLOCK_EVT_STATE_DETACHED ); +clockevents_unbind_device (&i8253_clockevent,smp_processor_id ()); +}#endif
include/linux/clockchips.h +3 -0
@@ -187,6 +187,9 @@ extern void clockevents_config_and_register(struct clock_event_device *dev, u32 freq, unsigned long min_delta, unsigned long max_delta); +extern void clockevents_switch_state (struct clock_event_device *dev, +enum clock_event_state state); +extern int clockevents_update_freq (struct clock_event_device *ce,u32 freq); static inline void
include/linux/i8253.h +2 -0
@@ -24,7 +24,9 @@ extern raw_spinlock_t i8253_lock;extern bool i8253_clear_counter_on_shutdown;extern struct clock_event_device i8253_clockevent;extern void clockevent_i8253_init (bool oneshot); +extern void clockevent_i8253_exit (void );extern void setup_pit_timer (void ); +extern void remove_pit_timer (void );#endif /* __LINUX_I8253_H */
kernel/time/tick-internal.h +0 -2
@@ -51,8 +51,6 @@ static inline void clockevent_set_state(struct clock_event_device *dev,extern void clockevents_shutdown (struct clock_event_device *dev);extern void clockevents_exchange_device (struct clock_event_device *old,struct clock_event_device *new); -extern void clockevents_switch_state (struct clock_event_device *dev, -enum clock_event_state state);extern int clockevents_program_event (struct clock_event_device *dev,ktime_t expires,bool force);extern void clockevents_handle_noop (struct clock_event_device *dev);
Signature · 1 line
2.19.1
PATCH 2/2 x86/ioapic: avoid timer manipulation when IRQ0 timer is unavailable
New products based on Intel Apollo Lake are appearing where the HPET is not present in ACPI, and the legacy 8254 PIT is "gated" by default in the BIOS setup menu.
This leads an early boot "IO-APIC + timer doesn't work!" kernel panic on a black screen (before the framebuffer is initialized).
Avoid the IO-APIC IRQ0 timer manipulation & verification on platforms where the legacy IRQ0 timer has been determined as unavailable.
This fixes boot on Connex L1430 and Scope SN116PYA with default BIOS settings.
--- arch/x86/kernel/apic/io_apic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/apic/io_apic.c +1 -1
@@ -2243,7 +2243,7 @@ void __init setup_IO_APIC(void)sync_Arb_IDs ();setup_IO_APIC_irqs ();init_IO_APIC_traps (); -if (nr_legacy_irqs ()) +if (global_clock_event &&nr_legacy_irqs ())check_timer (); ioapic_initialized =1 ;
Signature · 1 line
2.19.1
Quoted 10 lines · Daniel Drake
/* Default timer init function */
void__inithpet_time_init(void)
{arch/x86/kernel/time.c +5
-2-if (!hpet_enable ()) -setup_pit_timer (); +if (hpet_enable ()) { +setup_default_timer_irq (); +return ; + } +
arch/x86/kernel/time.c static void __init setup_default_timer_irq(void) · line 184
Quoted 10 lines
arch/x86/kernel/time.c +9
-0+/* Fall back on legacy 8253 PIT */ +setup_pit_timer ();setup_default_timer_irq (); + +/* +* Intel SoCs like ApolloLake, Skylake and newer can have +* their PIT "gated" by the BIOS such that IRQ0 does not +* tick. Check for that situation here. +*/ +if (!irq0_timer_works ()) {
So you rely on the fact that the legacy PIC delivery is working here. That's fragile at best especially when this is a boot of a crash kernel.
arch/x86/kernel/time.c static void __init setup_default_timer_irq(void)
Quoted 9 lines
arch/x86/kernel/time.c +9
-0+pr_info ("HPET is not available, and 8253 timer is not working. " +"Continuing without IRQ0 timer.\n" ); +remove_default_timer_irq (); +remove_pit_timer (); + } + +void __init clockevent_i8253_exit (void ) +{ +clockevents_switch_state (&i8253_clockevent,CLOCK_EVT_STATE_DETACHED );
Smart, but broken. The PIT clockevent is still referenced in the clockevents core code after the unbind. The unbind logic is there for a reason and just because the above duct tape does not explode in your face does not make it more correct. :)
drivers/clocksource/i8253.c void __init clockevent_i8253_init(bool oneshot) · line 200
Quoted 1 line
drivers/clocksource/i8253.c +1
-0+clockevents_unbind_device (&i8253_clockevent,smp_processor_id ());
We really want to avoid the whole register and whatever dance at all for these devices. Let me think about it some more.
Thanks,
tglx