From owner-freebsd-current@FreeBSD.ORG Thu Jun 16 00:10:08 2011 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from [127.0.0.1] (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by hub.freebsd.org (Postfix) with ESMTP id 4BFDC106566C; Thu, 16 Jun 2011 00:10:07 +0000 (UTC) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim To: freebsd-current@FreeBSD.org Date: Wed, 15 Jun 2011 20:09:54 -0400 User-Agent: KMail/1.6.2 References: <201106151639.30308.jkim@FreeBSD.org> <201106151819.32495.jkim@FreeBSD.org> In-Reply-To: <201106151819.32495.jkim@FreeBSD.org> MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_UnU+NA6KT35yX0f" Message-Id: <201106152009.56163.jkim@FreeBSD.org> Cc: Ian FREISLICH Subject: Re: Time keeping Issues with the low-resolution TSC timecounter X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Jun 2011 00:10:08 -0000 --Boundary-00=_UnU+NA6KT35yX0f Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wednesday 15 June 2011 06:19 pm, Jung-uk Kim wrote: > On Wednesday 15 June 2011 04:39 pm, Jung-uk Kim wrote: > > On Wednesday 15 June 2011 03:27 pm, Ian FREISLICH wrote: > > > > > The problem I noticed first is that it takes unusually long > > > > > until a key press is repeated. With the default eventtimer > > > > > (HPET) it seems to take about 4s, which can be slightly > > > > > improved by switching to i8254. > > > > > > > > > > The "error beep" seems to take longer than usual, too, > > > > > and the system "feels sluggish" in general. > > > > > > > > > > An effect that is easier to measure is that the system is > > > > > unable to properly keep the time. Again the problem is less > > > > > severe when using i8254 instead of HPET: > > > > > > > > [SNIP] > > > > > > > > First of all, please do not mix timecounter issues with > > > > eventtimer. They are not directly related. > > > > > > > > Can you please show me verbose boot messages *without* your > > > > patch? Does "sysctl kern.timecounter.hardware=HPET" help > > > > *without* touching eventtimers? > > > > > > I have the same issue with my system (Atom N270). The effect > > > that I see is about 29 wall clock seconds are recorded as 1 > > > system second. > > > > Can please you send me output from the following? > > > > sh -c 'count=10; while [ $count -gt 0 ]; do count=$((count - > > 1));\ sysctl kern.timecounter; sleep 1; done' > > The OP sent me some data. The following is cooked data from what I > got: > > TSC Delta Elapsed Time > ---------------+---------------+------------ > 2245026970 > 2249708604 4681634 0.3003693189 > 2255874998 6166394 0.3956301509 > 2260656402 4781404 0.3067704701 > 2261993048 1336646 0.0857579744 > 2264175164 2182116 0.1400025497 > 2266445706 2270542 0.1456758803 > 2266987003 541297 0.0347291162 > 2267645095 658092 0.0422225757 > 2268274965 629870 0.0404118782 > 2268979787 704822 0.0452207294 > 2270482069 1502282 0.0963850274 > 2271140877 658808 0.0422685136 > > HPET Delta Elapsed Time > ---------------+---------------+------------ > 1322734365 > 1337156221 14421856 1.0072408644 > 1351548130 14391909 1.0051493276 > 1365949265 14401135 1.0057936833 > 1380376349 14427084 1.0076059946 > 1394823985 14447636 1.0090413726 > 1409273964 14449979 1.0092050107 > 1423719753 14445789 1.0089123757 > 1438167064 14447311 1.0090186742 > 1452613630 14446566 1.0089666424 > 1467062977 14449347 1.0091608710 > 1481522037 14459060 1.0098392393 > 1495969404 14447367 1.0090225853 > > As you can see, HPET increases normally (within errors from > sleep(3) accuracy, syscall overhead, etc.) but TSC-low is totally > erratic (and too low). I don't know how this can happen, though. > :-( > > I need some time to figure it out. Can you please test the attached patch? Theoretically, it should not make a difference but I'd like to see if it does, just in case. Thanks, Jung-uk Kim --Boundary-00=_UnU+NA6KT35yX0f Content-Type: text/plain; charset="iso-8859-1"; name="tsc.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tsc.diff" Index: sys/x86/x86/tsc.c =================================================================== --- sys/x86/x86/tsc.c (revision 223102) +++ sys/x86/x86/tsc.c (working copy) @@ -579,6 +579,9 @@ tsc_get_timecount(struct timecounter *tc __unused) static u_int tsc_get_timecount_low(struct timecounter *tc) { + uint32_t low, high; - return (rdtsc() >> (int)(intptr_t)tc->tc_priv); + __asm __volatile("rdtsc; shrd %2,%1,%0" + : "=a" (low), "=d" (high) : "Ic" ((uint8_t)(intptr_t)tc->tc_priv)); + return (low); } --Boundary-00=_UnU+NA6KT35yX0f--