Bug 17800

Summary: [PATCH] problem with statclock initialization
Product: Base System Reporter: Jose M. Alcaide <jose>
Component: i386Assignee: Bruce Evans <bde>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Jose M. Alcaide 2000-04-04 23:40:01 UTC
I found that the RTC does not generate statclock interrupts on a
Dell Inspiron 3700 laptop under some circumstances (after rebooting while
connected to AC power).  Probably the BIOS fiddles the MC146818A in
such a way that an interrupt is pending when the kernel initializes
the system clocks.  The routine cpu_initclocks() should ensure that
there are no RTC interrupts pending before enabling IRQ8 in the ICU.
This can be easily accomplished simply reading the RTC_INTR register.
I tested this solution on my I3.7k laptop, and now the statclock always
works.  Maybe other laptops are affected by the same problem.

Fix: The following patch (against 4.0-RELEASE's clock.c, but I think it is
applicable to -CURRENT) does the trick:

--------------------------- CUT HERE --------------------------
How-To-Repeat: Install FreeBSD 3.x, 4.0-STABLE or 5.0-CURRENT on a Dell Inspiron 3700 :-)
Be sure that apm(4)'s 0x20 flag is _not_ set.
Reboot with shutdown -r (warm boot).
Type "vmstat -i" or "systat -vmstat".
Comment 1 jmas freebsd_committer freebsd_triage 2000-04-05 13:49:13 UTC
Responsible Changed
From-To: freebsd-bugs->bde

Over to maintainer (I think) 

Comment 2 Charlie Schluting 2004-11-18 21:12:05 UTC
I had the same problem described in this PR with a Dell Latitude CPt. I 
believe its the same motherboard, or very similar. In both 5.2.1 and 
6-CURRENT I couldn't get cpu usage stats.

Jose's patch fixes it... though the patch is no longer valid in 
6-CURRENT (from cvs 2 days ago).

New patch. Same content, different location:
---------------------------------------------------------------------
--- sys/i386/isa/clock.c.old    Thu Nov 18 11:18:59 2004
+++ sys/i386/isa/clock.c        Thu Nov 18 11:12:10 2004
@@ -946,6 +946,7 @@
         /* Initialize RTC. */
         writertc(RTC_STATUSA, rtc_statusa);
         writertc(RTC_STATUSB, RTCSB_24HR);
+       rtcin(RTC_INTR); /* clear any pending interrupt */

         /* Don't bother enabling the statistics clock. */
         if (!statclock_disable) {
---------------------------------------------------------------------

Tested, and it works.
Please commit :)

-Charlie Schluting
Comment 3 John Baldwin freebsd_committer freebsd_triage 2005-02-03 19:06:13 UTC
State Changed
From-To: open->closed

Expanded version of the patch committed.