Re: [PATCH RFC] x86, tsc: Allow for high latency in quick_pit_calibrate()

From: George Spelvin
Date: Thu Jun 04 2015 - 12:38:23 EST


Ingo Molnar wrote:
> - Alternatively, I also tried a different method: to set up the RTC
> periodic IRQ during early boot, but not have an IRQ handler, polling
> RTC_PF in the rtc_cmos_read(RTC_INTR_FLAGS) IRQ status byte.
>
> Unfortunately when I do this then PIO based RTC accesses can take
> tens of thousands of cycles, and the resulting jitter is pretty bad
> and hard to filter:

Did you use rtc_cmos_read()? Because that's a rather complex function with
lots of locking, to allow NMI access to CMOS. (Basically, it keeps
a shadow copy of the address register, which the NMI puts back after
it does its nested access.)

You want to do the locking and selection of the register to read
just once, and have just the raw inb() in the loop. The resultant
code looks like this:


lock_cmos_prefix(RTC_REG_C);
outb(RTC_REG_C, RTC_PORT(0));

for (lots of iterations) {
flag = inb(RTC_PORT(1)) & 0x40;
}

lock_cmos_suffix(RTC_REG_C);

That should be a *lot* better.

Also, you don't have to enable interrupts in the RTC to get the PF bit
set periodically. You only program the interval (register A lsbits),
not the IRQ (register B bit 6). In fact, disabling the interrupt is
probably safer.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/