From: Clemens Ladisch To prevent the emulated RTC timer from stopping when interrupts are disabled for too long, implement the watchdog timer to restart it when needed. Andi: "The interrupt handler should just read the time (it likely has to do that anyways) and check for that directly. That is what I did in my noidletick HPET patch and it worked ok." Signed-off-by: Clemens Ladisch Cc: Venkatesh Pallipadi Cc: Andi Kleen Cc: Vojtech Pavlik Signed-off-by: Andrew Morton --- arch/i386/kernel/time_hpet.c | 36 +++++++++++++++++++++++++++++++++ arch/x86_64/kernel/time.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff -puN arch/i386/kernel/time_hpet.c~hpet-rtc-emulation-add-watchdog-timer arch/i386/kernel/time_hpet.c --- devel/arch/i386/kernel/time_hpet.c~hpet-rtc-emulation-add-watchdog-timer 2006-02-03 03:15:40.000000000 -0800 +++ devel-akpm/arch/i386/kernel/time_hpet.c 2006-02-03 03:15:40.000000000 -0800 @@ -411,9 +411,45 @@ int hpet_set_periodic_freq(unsigned long int hpet_rtc_dropped_irq(void) { + unsigned int cnt, ticks_per_int, lost_ints; + if (!is_hpet_enabled()) return 0; + if (UIE_on | PIE_on | AIE_on) { + /* + * The interrupt handler schedules the next interrupt at a + * constant offset from the time the current interrupt was + * scheduled, without regard to the actual time. When the + * handler is delayed too long, it tries to schedule the next + * interrupt in the past and the hardware would not interrupt + * until the counter had wrapped around. We catch it here. + */ + cnt = hpet_readl(HPET_COUNTER); + /* was the comparator set to a time in the past? */ + if ((int)(cnt - hpet_t1_cmp) > 0) { + /* determine how many interrupts were actually lost */ + ticks_per_int = (hpet_tick * HZ) / hpet_rtc_int_freq; + lost_ints = (cnt - hpet_t1_cmp) / ticks_per_int + 1; + /* + * Make sure that, even with the time needed to execute + * this code, the next scheduled interrupt has been + * moved back to the future. + */ + lost_ints++; + + cnt = hpet_t1_cmp + lost_ints * ticks_per_int; + hpet_writel(cnt, HPET_T1_CMP); + hpet_t1_cmp = cnt; + + if (PIE_on) + PIE_count += lost_ints; + + printk(KERN_WARNING "rtc: lost some interrupts" + " at %ldHz.\n", hpet_rtc_int_freq); + } + } + return 1; } diff -puN arch/x86_64/kernel/time.c~hpet-rtc-emulation-add-watchdog-timer arch/x86_64/kernel/time.c --- devel/arch/x86_64/kernel/time.c~hpet-rtc-emulation-add-watchdog-timer 2006-02-03 03:15:40.000000000 -0800 +++ devel-akpm/arch/x86_64/kernel/time.c 2006-02-03 03:15:40.000000000 -0800 @@ -1262,9 +1262,45 @@ int hpet_set_periodic_freq(unsigned long int hpet_rtc_dropped_irq(void) { + unsigned int cnt, ticks_per_int, lost_ints; + if (!is_hpet_enabled()) return 0; + if (UIE_on | PIE_on | AIE_on) { + /* + * The interrupt handler schedules the next interrupt at a + * constant offset from the time the current interrupt was + * scheduled, without regard to the actual time. When the + * handler is delayed too long, it tries to schedule the next + * interrupt in the past and the hardware would not interrupt + * until the counter had wrapped around. We catch it here. + */ + cnt = hpet_readl(HPET_COUNTER); + /* was the comparator set to a time in the past? */ + if ((int)(cnt - hpet_t1_cmp) > 0) { + /* determine how many interrupts were actually lost */ + ticks_per_int = (hpet_tick * HZ) / hpet_rtc_int_freq; + lost_ints = (cnt - hpet_t1_cmp) / ticks_per_int + 1; + /* + * Make sure that, even with the time needed to execute + * this code, the next scheduled interrupt has been + * moved back to the future. + */ + lost_ints++; + + cnt = hpet_t1_cmp + lost_ints * ticks_per_int; + hpet_writel(cnt, HPET_T1_CMP); + hpet_t1_cmp = cnt; + + if (PIE_on) + PIE_count += lost_ints; + + printk(KERN_WARNING "rtc: lost some interrupts" + " at %ldHz.\n", hpet_rtc_int_freq); + } + } + return 1; } _