[PATCH] lost RTC interrupts

From: Dinakar Guniguntala
Date: Fri Jun 04 2004 - 05:30:08 EST


Paul,

The calculation for the number of interrupts lost when the
RTC stops generating interrupts seems to be broken for HZ=1000

Also, the following patch returns more accurate lost interrupt
data (At the cost of some accounting for every interrupt)
Let me know if you think the accounting is unnecessary

Thanks
Dinakar
diff -Naurp linux-2.6.7-rc2/drivers/char/rtc.c linux-2.6.7-rc2-rtc/drivers/char/rtc.c
--- linux-2.6.7-rc2/drivers/char/rtc.c 2004-05-30 11:56:50.000000000 +0530
+++ linux-2.6.7-rc2-rtc/drivers/char/rtc.c 2004-06-03 13:09:04.000000000 +0530
@@ -169,6 +169,9 @@ static unsigned long rtc_freq = 0; /* Cu
static unsigned long rtc_irq_data = 0; /* our output to the world */
static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */

+static unsigned long prev_jiffies = 0;
+static unsigned long rtcticks_in_pjiffies = 0;
+
#ifdef RTC_IRQ
/*
* rtc_task_lock nests inside rtc_lock.
@@ -239,6 +242,12 @@ irqreturn_t rtc_interrupt(int irq, void

spin_unlock (&rtc_lock);

+ if (jiffies != prev_jiffies) {
+ prev_jiffies = jiffies;
+ rtcticks_in_pjiffies = 0;
+ }
+ rtcticks_in_pjiffies++;
+
/* Now do the rest of the actions */
spin_lock(&rtc_task_lock);
if (rtc_callback)
@@ -1094,7 +1103,7 @@ static void rtc_dropped_irq(unsigned lon
if (rtc_status & RTC_TIMER_ON)
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);

- rtc_irq_data += ((rtc_freq/HZ)<<8);
+ rtc_irq_data += ((rtc_freq/HZ * 2*HZ/100 - rtcticks_in_pjiffies)<<8);
rtc_irq_data &= ~0xff;
rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); /* restart */

@@ -1102,6 +1111,9 @@ static void rtc_dropped_irq(unsigned lon

spin_unlock_irq(&rtc_lock);

+ prev_jiffies = jiffies;
+ rtcticks_in_pjiffies = 1;
+
printk(KERN_WARNING "rtc: lost some interrupts at %ldHz.\n", freq);

/* Now we have new data */