From owner-freebsd-current@FreeBSD.ORG Fri Dec 3 23:47:33 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9F9C106564A; Fri, 3 Dec 2010 23:47:33 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 0C6988FC0C; Fri, 3 Dec 2010 23:47:32 +0000 (UTC) Received: from porto.topspin.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id BAA01968; Sat, 04 Dec 2010 01:47:31 +0200 (EET) (envelope-from avg@freebsd.org) Received: from localhost.topspin.kiev.ua ([127.0.0.1]) by porto.topspin.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1POfLf-0001Pq-7M; Sat, 04 Dec 2010 01:47:31 +0200 Message-ID: <4CF98192.3050909@freebsd.org> Date: Sat, 04 Dec 2010 01:47:30 +0200 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.12) Gecko/20101029 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: Jung-uk Kim References: <4CF92852.20705@freebsd.org> <201012031305.53750.jkim@FreeBSD.org> <4CF93395.3060601@freebsd.org> <201012031504.02532.jkim@FreeBSD.org> In-Reply-To: <201012031504.02532.jkim@FreeBSD.org> X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org Subject: Re: non-invariant tsc and cputicker 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: Fri, 03 Dec 2010 23:47:34 -0000 on 03/12/2010 22:03 Jung-uk Kim said the following: > On Friday 03 December 2010 01:14 pm, Andriy Gapon wrote: >> on 03/12/2010 20:05 Jung-uk Kim said the following: >>> On Friday 03 December 2010 12:26 pm, Andriy Gapon wrote: >>>> FreeBSD uses cpu_ticks [function pointer] in a few places for a >>>> few things like process CPU time accounting. On x86 cpu_ticks >>>> always points to rdtsc. If TSC is not invariant that leads to >>>> incorrect accounting of "CPU ticks". The code pretends to try to >>>> handle changing cpufreq levels, but does that incorrectly. >>> >>> Arg... Probably it is my fault. :-( >>> >>>> I think that we could use a selected timecounter instead of >>>> "raw" TSC if the latter is not invariant. In this case >>>> cpu_ticks calls would be slightly costlier, but always correct. >>>> >>>> The change is quite trivial: >>>> http://people.freebsd.org/~avg/tsc-cputicker.diff >>>> >>>> What do you think? >>> >>> Why don't we just fix it properly? >> >> Patch? :-) > > Attached. I fail to see how this corrects the calculations (cpu tick accumulation) in !invariant_tsc case. >> It seems that it is not too trivial to do and is prone to error >> accumulation given how the ticks are added up. >> Besides, why using a timecounter would not be a proper fix? > > Well, it is not that simple, unfortunately. Because init_TSC() is > called very early, your patch will select dummy timecounter as a CPU > ticker if my memory serves. It is very hard to implement right on > x86 arch. :-( I don't think that init_TSC() is called earlier than the code that probes CPU features. After all, presence of TSC is another CPU feature. -- Andriy Gapon