Re: non-invariant tsc and cputicker

From: Jung-uk Kim <jkim_at_FreeBSD.org>
Date: Fri, 3 Dec 2010 15:03:59 -0500
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.

> 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. :-(

Jung-uk Kim

> >> P.S. it's probably a good idea to merge i386 and amd64 tsc.c
> >> files into a common x86 version, which would be the same as i386
> >> version, which seems to be generic enough.
> >
> > Agreed.
>
> Cool!

Received on Fri Dec 03 2010 - 19:04:10 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:09 UTC