From nobody@FreeBSD.ORG Fri Jun  4 11:05:21 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id CB25A14C01; Fri,  4 Jun 1999 11:05:21 -0700 (PDT)
Message-Id: <19990604180521.CB25A14C01@hub.freebsd.org>
Date: Fri,  4 Jun 1999 11:05:21 -0700 (PDT)
From: dwhite@pond.net
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: System clock timewarps
X-Send-Pr-Version: www-1.0

>Number:         12022
>Category:       kern
>Synopsis:       System clock timewarps
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    phk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun  4 11:10:01 PDT 1999
>Closed-Date:    Thu Nov 15 07:38:57 PST 2001
>Last-Modified:  Thu Nov 15 07:39:25 PST 2001
>Originator:     Doug White
>Release:        3.1-RELEASE and later
>Organization:
Pacific Crest Networks, Inc.
>Environment:
FreeBSD squid.pcrest.net 3.1-RELEASE FreeBSD 3.1-RELEASE #1: Mon May 10 23:00:37 PDT 1999     root@squid.pcrest.net:/usr/src/sys/compile/SQUID  i386

>Description:
The TSC time calibration code appears badly broken.  It cannot get a 
consistent read off the system TSC and miscalculates the CPU clock.  
Furthermore, it's causing the system clock to run fast at the rate of 
about 5 minutes/hour.  

Normally, the TSC should sync to 90000689 or thereabouts.  On the problem
machine, we have the following values:
May 10 19:53:45 myname /kernel: Timecounter "TSC"  frequency 84792684 Hz
May 10 19:58:23 myname /kernel: Timecounter "TSC"  frequency 78478318 Hz
May 10 20:04:29 myname /kernel: Timecounter "TSC"  frequency 90205024 Hz
May 10 20:10:49 squid /kernel: Timecounter "TSC"  frequency 82086508 Hz
May 10 20:13:09 squid /kernel: Timecounter "TSC"  frequency 83890627 Hz
May 10 22:50:53 squid /kernel: Timecounter "TSC"  frequency 87498832 Hz
May 10 22:56:12 squid /kernel.GENERIC: Timecounter "TSC"  frequency 79380441 Hz
May 10 23:01:42 squid /kernel: Timecounter "TSC"  frequency 86596730 Hz
May 10 23:03:58 squid /kernel: Timecounter "TSC"  frequency 90205040 Hz
May 11 19:40:41 squid /kernel: Timecounter "TSC"  frequency 82988540 Hz
May 11 19:43:37 squid /kernel: Timecounter "TSC"  frequency 84792851 Hz
May 11 19:46:05 squid /kernel: Timecounter "TSC"  frequency 90204971 Hz
May 11 12:36:59 squid /kernel: Timecounter "TSC"  frequency 87498777 Hz
May 11 16:18:42 squid /kernel: Timecounter "TSC"  frequency 86596851 Hz
May 12 15:54:47 squid /kernel: Timecounter "TSC"  frequency 87498803 Hz

This machine ran 3.0-RELEASE previously without any such problems.

This machine has a custom kernel without APM built in, and I believe APM
is disabled in the BIOS (not 100% sure, but this is a server.

I've also tried setting kern.timecounter.method=1 with no effect.
>How-To-Repeat:
. Find a PC.
. Boot 3.1 or later on it a few times.
. Watch the TSC go nuts.
>Fix:


>Release-Note:
>Audit-Trail:

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: dwhite@pond.net
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/12022: System clock timewarps 
Date: Fri, 04 Jun 1999 20:19:55 +0200

 Disable APM in your bios or add apm to your kernel config.
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 FreeBSD -- It will take a long time before progress goes too far!
 

From: Doug White <dwhite@pond.net>
To: Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/12022: System clock timewarps 
Date: Fri, 4 Jun 1999 11:09:58 -0700 (PDT)

 On Fri, 4 Jun 1999, Poul-Henning Kamp wrote:
 
 > Disable APM in your bios or add apm to your kernel config.
 
 Hm, I'll try it, but I thought the trend was to turn it off...
 
 Doug White                    | Pacific Crest Networks
 Internet:  dwhite@pond.net    | http://www.pond.net/
 
 

From: Chris Dillon <cdillon@wolves.k12.mo.us>
To: dwhite@pond.net
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/12022: System clock timewarps
Date: Fri, 4 Jun 1999 14:20:11 -0500 (CDT)

 On Fri, 4 Jun 1999 dwhite@pond.net wrote:
 
 > I've also tried setting kern.timecounter.method=1 with no effect.
 > >How-To-Repeat:
 > . Find a PC.
 > . Boot 3.1 or later on it a few times.
 > . Watch the TSC go nuts.
 > >Fix:
 
 On the one 3.1+ (actually 3.2-STABLE) PIII-500 box I have here at
 work, TSC is extremely stable.  Over 30 boots, I see it has ranged
 from 498830507 Hz to 498831075 Hz.  I assume a total deviation of less
 than 1KHz (actually 568Hz, .000001% deviation) on a 500MHz clock is
 pretty darn stable.  (Almost too stable... did I get that percentage
 right? I'm no statistician).
 
 I did experience just one time on my box at home a serious deviation,
 but overall it seems to be very stable.  I don't have the actual
 figures from my box at home available right now, but ntpdate never
 adjusted the time more than about a couple of seconds a day until that
 one time the reported TSC was about 50% of the actual clockrate
 (Celeron 433), making the wall clock run extremely fast.
 
 
 -- Chris Dillon - cdillon@wolves.k12.mo.us - cdillon@inter-linc.net
    FreeBSD: The fastest and most stable server OS on the planet.
    For Intel x86 and Alpha architectures (SPARC under development).
    ( http://www.freebsd.org )
 
    "One should admire Windows users.  It takes a great deal of
     courage to trust Windows with your data."
 
 

From: Doug White <dwhite@pond.net>
To: Chris Dillon <cdillon@wolves.k12.mo.us>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: kern/12022: System clock timewarps
Date: Fri, 4 Jun 1999 12:06:34 -0700 (PDT)

 On Fri, 4 Jun 1999, Chris Dillon wrote:
 
 > On Fri, 4 Jun 1999 dwhite@pond.net wrote:
 > 
 > > I've also tried setting kern.timecounter.method=1 with no effect.
 > > >How-To-Repeat:
 > > . Find a PC.
 > > . Boot 3.1 or later on it a few times.
 > > . Watch the TSC go nuts.
 > > >Fix:
 > 
 > On the one 3.1+ (actually 3.2-STABLE) PIII-500 box I have here at
 > work, TSC is extremely stable.  Over 30 boots, I see it has ranged
 > from 498830507 Hz to 498831075 Hz.  I assume a total deviation of less
 > than 1KHz (actually 568Hz, .000001% deviation) on a 500MHz clock is
 > pretty darn stable.  (Almost too stable... did I get that percentage
 > right? I'm no statistician).
 
 Hm.  I'm wondering if this is isolated to just P90s.  I can't test the
 machine until later tonight since it's a router for some of the building
 networks, but I'll report my findings.
 
 Then maybe we can document this problem.
 
 Doug White                    | Pacific Crest Networks
 Internet:  dwhite@pond.net    | http://www.pond.net/
 
 

From: John.Shue@symmetron.com (John A. Shue)
To: <freebsd-gnats-submit@freebsd.org>, <dwhite@pond.net>,
	<cdillon@wolves.k12.mo.us>, <phk@critter.freebsd.dk>
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Mon, 14 Jun 1999 14:46:40 -0400

 It's not just P90s.
 
 My P100 is showing the same symptoms:
 
 The BIOS reports the chip as a 100MHz Pentium.
 
 dmesg says:
   Timecounter "i8254"  frequency 1193182 Hz
   Timecounter "TSC"  frequency 79001623 Hz
   CPU: Pentium/P54C (79.00-MHz 586-class CPU)
     Origin = "GenuineIntel"  Id = 0x525  Stepping=5
     Features=0x1bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8>
 
 My clock is out by 2 minutes (126 seconds) every 10 minutes.  That's 756 seconds (126 * 6)
 per hour.
 
 (79.00 MHz / 100 MHz * 3600) - 3600 = -756 seconds!
 
 -john
 
 ---------------
 John A. Shue
 4000 Legato Road, Suite 600
 Fairfax, VA 22033
 (703) 591-5559
 (703) 591-6337 FAX
 
 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: John.Shue@symmetron.com
Cc: freebsd-gnats-submit@freebsd.org, dwhite@pond.net,
	cdillon@wolves.k12.mo.us
Subject: Re: kern/12022: System clock timewarps 
Date: Mon, 14 Jun 1999 20:58:24 +0200

 Check APM setting in bios.
 
 
 In message <008301beb696$3d759be0$42baefce@mail.symmetron.com>, John A. Shue wr
 ites:
 >It's not just P90s.
 >
 >My P100 is showing the same symptoms:
 >
 >The BIOS reports the chip as a 100MHz Pentium.
 >
 >dmesg says:
 >  Timecounter "i8254"  frequency 1193182 Hz
 >  Timecounter "TSC"  frequency 79001623 Hz
 >  CPU: Pentium/P54C (79.00-MHz 586-class CPU)
 >    Origin = "GenuineIntel"  Id = 0x525  Stepping=5
 >    Features=0x1bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8>
 >
 >My clock is out by 2 minutes (126 seconds) every 10 minutes.  That's 756 seconds (126 * 6)
 >per hour.
 >
 >(79.00 MHz / 100 MHz * 3600) - 3600 = -756 seconds!
 >
 >-john
 >
 >---------------
 >John A. Shue
 >4000 Legato Road, Suite 600
 >Fairfax, VA 22033
 >(703) 591-5559
 >(703) 591-6337 FAX
 >
 >
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 FreeBSD -- It will take a long time before progress goes too far!
 

From: John.Shue@symmetron.com (John A. Shue)
To: "Poul-Henning Kamp" <phk@critter.freebsd.dk>
Cc: <freebsd-gnats-submit@freebsd.org>, <dwhite@pond.net>,
	<cdillon@wolves.k12.mo.us>
Subject: RE: kern/12022: System clock timewarps 
Date: Mon, 14 Jun 1999 15:34:54 -0400

 This motherboard doesn't have APM.
 
 -----Original Message-----
 From: Poul-Henning Kamp [mailto:phk@critter.freebsd.dk]
 Sent: Monday, June 14, 1999 2:58 PM
 To: John.Shue@symmetron.com
 Cc: freebsd-gnats-submit@freebsd.org; dwhite@pond.net;
 cdillon@wolves.k12.mo.us
 Subject: Re: kern/12022: System clock timewarps
 
 
 
 Check APM setting in bios.
 
 
 In message <008301beb696$3d759be0$42baefce@mail.symmetron.com>, John A. Shue wr
 ites:
 >It's not just P90s.
 >
 >My P100 is showing the same symptoms:
 >
 >The BIOS reports the chip as a 100MHz Pentium.
 >
 >dmesg says:
 >  Timecounter "i8254"  frequency 1193182 Hz
 >  Timecounter "TSC"  frequency 79001623 Hz
 >  CPU: Pentium/P54C (79.00-MHz 586-class CPU)
 >    Origin = "GenuineIntel"  Id = 0x525  Stepping=5
 >    Features=0x1bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8>
 >
 >My clock is out by 2 minutes (126 seconds) every 10 minutes.  That's 756 seconds (126 *
 6)
 >per hour.
 >
 >(79.00 MHz / 100 MHz * 3600) - 3600 = -756 seconds!
 >
 >-john
 >
 >---------------
 >John A. Shue
 >4000 Legato Road, Suite 600
 >Fairfax, VA 22033
 >(703) 591-5559
 >(703) 591-6337 FAX
 >
 >
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 FreeBSD -- It will take a long time before progress goes too far!
 
 

From: "Andy V. Oleynik" <andyo@prime.net.ua>
To: freebsd-gnats-submit@freebsd.org, dwhite@pond.net
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Thu, 17 Jun 1999 09:55:20 +0300

 I have 2 boxes at work:
 1. Timecounter "i8254"  frequency 1193182 Hz
     Timecounter "TSC"  frequency 90040111 Hz
     CPU: AMD K5 model 0 (90.04-MHz 586-class CPU)
     Origin = "AuthenticAMD"  Id = 0x501  Stepping=1
     Features=0x3bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8,APIC>
     (BIOS reports: AMD-k5-PR90 CPU,
                                  Award Modular BIOS v4.51PG,
                                  Award P&P BIOS extension v1.0A,
                                  M/B 580VPX-ITE8661-2A5LDL1CC-0)
 2.
     Sorry, I can't give Timecounters strings 'cos I've removed 3.2-S and
 
     installed 2.2.8-R on this PC due the clock bug.
     CPU: AMD K5 model 0 (74.54-MHz 586-class CPU)
     Origin = "AuthenticAMD"  Id = 0x501  Stepping=1
     Features=0x3bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8,APIC>
     (BIOS reports: AMD-k5-PR75 CPU,
                                  Award Modular BIOS v4.51PG release
 03/03/1997S,
                                  Award P&P BIOS extension v1.0A,
                                  M/B I430VX-02071997C-00)
 Timecounters on 1st PC:
     Jun 14 09:58:28 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 14 09:58:28 volodya /kernel: Timecounter "TSC"  frequency
 90040208 Hz
     Jun 14 14:55:40 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 14 14:55:40 volodya /kernel: Timecounter "TSC"  frequency
 90040168 Hz
     Jun 14 14:58:47 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 14 14:58:47 volodya /kernel: Timecounter "TSC"  frequency
 90039940 Hz
     Jun 15 09:20:31 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 15 09:20:31 volodya /kernel: Timecounter "TSC"  frequency
 90040205 Hz
     Jun 15 17:25:56 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 15 17:25:56 volodya /kernel: Timecounter "TSC"  frequency
 90039919 Hz
     Jun 16 09:22:18 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 16 09:22:18 volodya /kernel: Timecounter "TSC"  frequency
 90039896 Hz
     Jun 17 09:46:25 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 17 09:46:25 volodya /kernel: Timecounter "TSC"  frequency
 90039989 Hz
     Jun 17 09:52:11 volodya /kernel: Timecounter "i8254"  frequency
 1193182 Hz
     Jun 17 09:52:11 volodya /kernel: Timecounter "TSC"  frequency
 90040111 Hz
 On both was (on 1st remains) installed 3.2-R upgaded to STABLE.
 Again, kernel clock latancy on both is about 55 min/hour (real 1 hour =
 5 min on PC).
 APM disabled on both.
 
 --
 WBW  Andy V. Oleynik
 
 (prime.net.ua's sysadmin)
 
 
 
 

From: John.Shue@symmetron.com (John A. Shue)
To: <freebsd-gnats-submit@freebsd.org>, <dwhite@pond.net>
Cc: <phk@critter.freebsd.dk>, <cdillon@wolves.k12.mo.us>,
	<andyo@prime.net.ua>
Subject: Re: kern/12022: System clock timewarps
Date: Mon, 21 Jun 1999 10:10:36 -0400

 Here is a temporary hack that fixes the timewarps on my Pentium-100MHz machine.
 
 I use the sysctl command to change the TSC setting from whatever the timecounter code
 detected to the speed of my processor.
 
 To run this command at boot, I created a file in the /usr/local/etc/rc.d directory called
 buggy_TSC_fix.sh (contents of this file are listed at the end of this email).
 
 With this fix, my clock has gone from being 25 minutes fast every 2 hours to being 0.1
 seconds fast every 2 hours.  I have also added a line to my /etc/crontab to run ntpdate
 every 2 hours.
 
 Also, while testing this fix out, I booted up with the absolutely worst TSC probe yet:
 64MHz. Here is a list of all the TSC probes for my 100MHz machine since I installed
 3.2-RELEASE:
 
 Timecounter "TSC"  frequency 75000994 Hz
 Timecounter "TSC"  frequency 76695754 Hz
 Timecounter "TSC"  frequency 79001605 Hz
 Timecounter "TSC"  frequency 79001623 Hz
 Timecounter "TSC"  frequency 76001260 Hz
 Timecounter "TSC"  frequency 81001327 Hz
 Timecounter "TSC"  frequency 64001215 Hz
 
 Hopefully the TSC probing code gets fixed so that this temporary fix can be removed
 someday.
 
 buggy_TSC_fix.sh
 ----------------
 #!/bin/sh
 #
 # replace 100000000 with the speed of your processor in hertz.
 /sbin/sysctl -w machdep.tsc_freq=100000000 > /dev/null && echo -n ' buggy_TSC_fix'
 --end-of-file---
 
 -john
 
 ---------------
 John A. Shue
 4000 Legato Road, Suite 600
 Fairfax, VA 22033
 (703) 591-5559
 (703) 591-6337 FAX
 
 

From: "Andy V. Oleynik" <andyo@prime.net.ua>
To: freebsd-gnats-submit@freebsd.org, dwhite@pond.net
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Wed, 23 Jun 1999 10:46:26 +0300

 Trick with machdep.tsc_freq doesnt work for AMD-k5 model 0
 platforms.
 According to Poul-Henning's advice I've disabled TSC counter
 by zeroing tsc_present variable atfer  it's last initialisation in
 i386/isa/clock.c. More subtle solution (disabling it with option
 in kernel config file) was failed for me.
 
 --
 WBW  Andy V. Oleynik  (When U work in virtual office
                        U have good chance to obtain virtual money %-)
 
 
 
 

From: Barry Pederson <bpederson@geocities.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Mon, 23 Aug 1999 22:09:26 -0500

 I got bit by this too.  Machine is Dell Dimension XPS P90 running
 3.2-Release, so maybe problem -is- with Pentium 90's and 100's?   No APM
 options available in the BIOS.
 
 Anyhow, ended up doing pretty much the same thing John Shue did, stick a
 script in /usr/local/etc/rc.d to sysctl -w machdep.tsc_freq to an
 appropriate value at bootup.
 
   Barry
 

From: abc@firehouse.net
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Thu, 16 Dec 1999 22:41:16 -0500 (EST)

 >Submitter-Id:   current-users
 >Originator:     Alan Clegg
 >Organization:   Firehouse Network Consulting
 >Confidential:   no
 >Synopsis:       Clock warp semi-fix
 >Severity:       serious
 >Priority:       high
 >Category:       i386
 >Release:        FreeBSD 3.4-RC i386
 >Class:          sw-bug
 >Environment: 
 
 	Winbook XL2 500Mhz Celeron laptop
 
 >Description: 
 
 	Timewarp of over 6 seconds per minute (losing 6 seconds)
 
 >How-To-Repeat: 
 
 	enable kernel APM, watch clock skew so badly that nothing
 	can bring it back.
 
 >Fix: 
 
 	Since I don't have the option of turning off APM (no BIOS
 	options), and I really like being able to watch the status
 	of my batteries, I need both clock _AND_ apm.
 	
 	I enable use of TSC even if there is APM.  While this may
 	act funky on certain systems, it sure did fix the problem
 	here.  Might we add another OPTION to allow use of tsc
 	even if there is APM for those systems where it actually
 	works?
 
 	Change of (around 824 of /sys/i386/isa/clock.c):
 
 ---------------
         if (apm_version != APMINI_CANTFIND)
 +#if defined(APM_TSC_OK)
 +               printf("APM BIOS found but using tsc anyway\n");
 +else
                 return;
 +#endif /* !defined(APM_TSC_OK) */
  #endif /* NAPM > 0 */
 ---------------
 
 	with the addition of:
 
 options	APM_TSC_OK
 
 	to my config file allows me to override code to override
 	broken BIOS.  8-)
 
 AlanC
 

From: "Alan Clegg" <abc@firehouse.net>
To: freebsd-gnats-submit@freebsd.org, dwhite@pond.net
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: 18 Dec 1999 03:39:31 -0000

 Note that the above code fragment should have had:
 
 +#else
 
 instead of 
 
 +else
 
 AlanC
 
 

From: "Kostya Lukin" <lukin@ivcme.elektra.ru>
To: <freebsd-gnats-submit@FreeBSD.org>, <dwhite@pond.net>
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Wed, 26 Jan 2000 21:05:17 +0300

 Addind options "AUTO_EOI_1" to kernel configuration helped me.
 
 Kostya Lukin
 
 
 

From: "Kostya Lukin" <lukin@ivcme.elektra.ru>
To: <freebsd-gnats-submit@FreeBSD.org>, <dwhite@pond.net>
Cc:  
Subject: Re: kern/12022: System clock timewarps
Date: Thu, 27 Jan 2000 16:18:05 +0300

 Sorry, I mean that adding
 
 options "AUTO_EOI_1"
 
 and
 
 options CLK_USE_TSC_CALIBRATION
 
 to kernel configuration file made TSC probes more accurate on my HP
 Netserver LH (Pentium 75).
 
 Kostya Lukin
 
 
 
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: hoek 
Responsible-Changed-When: Tue May 16 14:54:04 PDT 2000 
Responsible-Changed-Why:  
I'll let you close this. 
State-Changed-From-To: open->closed 
State-Changed-By: asmodai 
State-Changed-When: Thu Nov 15 07:38:57 PST 2001 
State-Changed-Why:  
This looks to have been worked around on or solved in 4-STABLE's 
sources. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=12022 
>Unformatted:
