From nobody@FreeBSD.org  Mon Aug 27 10:36:49 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 8899037B407
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 27 Aug 2001 10:36:47 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f7RHal426984;
	Mon, 27 Aug 2001 10:36:47 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200108271736.f7RHal426984@freefall.freebsd.org>
Date: Mon, 27 Aug 2001 10:36:47 -0700 (PDT)
From: Blapp Martin <mb@imp.ch>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Time drifting on STABLE SMP when calling gettimeofday().
X-Send-Pr-Version: www-1.0

>Number:         30135
>Category:       kern
>Synopsis:       Time drifting on STABLE SMP when calling gettimeofday().
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 27 10:40:01 PDT 2001
>Closed-Date:    Mon Sep 3 11:30:21 PDT 2001
>Last-Modified:  Mon Sep 03 11:30:33 PDT 2001
>Originator:     Blapp Martin
>Release:        4.4-PRERELEASE
>Organization:
Improware AG
>Environment:
FreeBSD xx.xx.xx 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #1:
Thu Aug 16 15:17:53 CEST 2001
root@xx:/usr/obj/usr/src/sys/DOCSIS  i386
>Description:
Serverworks Chipset

Timecounter "i8254"  frequency 1193182 Hz
CPU: Pentium III/Pentium III Xeon/Celeron (933.37-MHz 686-class CPU)
  Origin = "GenuineIntel"  Id = 0x686  Stepping = 6
  Features=0x383fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE>

Changing APIC ID for IO APIC #1 from 3 to 1 in MP table
Changing APIC ID for IO APIC #1 from 3 to 1 on chip
Programming 16 pins in IOAPIC #0
IOAPIC #0 intpin 2 -> irq 0
Programming 16 pins in IOAPIC #1
FreeBSD/SMP: Multiprocessor motherboard
 cpu0 (BSP): apic id:  3, version: 0x00040011, at 0xfee00000
 cpu1 (AP):  apic id:  0, version: 0x00040011, at 0xfee00000
 io0 (APIC): apic id:  2, version: 0x000f0011, at 0xfec00000
 io1 (APIC): apic id:  1, version: 0x000f0011, at 0xfec01000
>How-To-Repeat:
If you produce 100% load with this program on one CPU, the time drifting
happens. The drift is about 10% !!!

It seems that gettimeofday() produces the effect. Other load
does not make anything and seems to be harmless.

#include <sys/types.h>
#include <sys/time.h>
#include <err.h>

int
main(void)
{
	
	for(;;) {
		struct timeval tv;
		struct timezone tz;
		gettimeofday(&tv, &tz);
	}
	return (0);
}
>Fix:
Not known.

This is really a severe Problem on bigger servers ! Ntpd gives up after
some minutes cause the jitter is to big, and calling ntpdate all 10 seconds
is not really a solution.
>Release-Note:
>Audit-Trail:

From: Martin Blapp <mb@imp.ch>
To: <freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: kern/30135: Time drifting on STABLE SMP when calling gettimeofday
Date: Mon, 27 Aug 2001 19:55:23 +0200 (CEST)

 I've to add:
 
 It is a forward timedrifting. And also these lines
 may be interesting:
 
 APIC_IO: Testing 8254 interrupt delivery
 APIC_IO: Broken MP table detected:
 8254 is not connected to IOAPIC #0 intpin 2
 APIC_IO: routing 8254 via 8259 and IOAPIC #0 intpin 0
 
 On single CPU on the same CPU there is NO time-drifting.
 So it is related to SMP.
 
 But why does gettimeofday() modify the system counter
 only on SMP systems ?
 
 Martin
 

From: Martin Blapp <mb@imp.ch>
To: <freebsd-gnats-submit@FreeBSD.org>
Cc:  
Subject: Re: kern/30135: Time drifting on STABLE SMP when calling gettimeofday
Date: Thu, 30 Aug 2001 17:34:58 +0200 (CEST)

 Thomas Moestl and I have found that the following workaround
 makes the clock speedup disappearing:
 
 --- sys/i386/isa/clock.c        Thu Aug 30 17:01:31 2001
 +++ sys/i386/isa/clock.c.new    Thu Aug 30 17:01:29 2001
 @@ -1203,7 +1203,7 @@
         high = inb(TIMER_CNTR0);
         count = timer0_max_count - ((high << 8) | low);
         if (count < i8254_lastcount ||
 -           (!i8254_ticked && (clkintr_pending ||
 +           (!i8254_ticked && (/*clkintr_pending || */
             ((count < 20 || (!(ef & PSL_I) && count < timer0_max_count /
 
 Maybe someone else know more ?
 
 Martin
 
 Martin Blapp, mb@imp.ch
 ------------------------------------------------------------------
 Improware AG, UNIX solution and service provider
 Zurlindenstrasse 29, 4133 Pratteln, Switzerland
 Phone: +41 061 826 93 00: +41 61 826 93 01
 PGP Fingerprint: 57E 7CCD 2769 E7AC C5FA  DF2C 19C6 DCD1 1B3A EC9C
 ------------------------------------------------------------------
 
 
State-Changed-From-To: open->feedback 
State-Changed-By: dd 
State-Changed-When: Mon Sep 3 11:12:11 PDT 2001 
State-Changed-Why:  
Tor applied his fix to RELENG_4.  Can this be closed? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30135 
State-Changed-From-To: feedback->closed 
State-Changed-By: dd 
State-Changed-When: Mon Sep 3 11:30:21 PDT 2001 
State-Changed-Why:  
Submitter is happy with the applied fix. 

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