Date: Fri, 31 Jul 2015 10:40:16 -0700 From: John Baldwin <jhb@freebsd.org> To: freebsd-amd64@freebsd.org Subject: Re: kernel timers and clocks Message-ID: <6399789.W1exljHUsy@ralph.baldwin.cx> In-Reply-To: <239381437645154@web15m.yandex.ru> References: <239381437645154@web15m.yandex.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, July 23, 2015 11:52:34 AM deco33000@yandex.com wrote: > Hello, > > I am trying to figure out how timers work for the amd64 platform on freebsd 10. > > How the kernel manage the timers? is it using TSC? The kern.timecounter sysctl tree shows the available timercounters (and information about each one) as well as which one is currently being used. Note that timecounters are used to compute the uptime and time-of-day for get*time and *time as well as gettimeofday() and clock_gettime() in userland. There is another timer interface used to manage interval timers. This uses timer interrupts to terminate sleeps, and things like setitimer(), alarm(), etc. (also the timeouts for select(2) and poll(2), etc.). These can be examined via the kern.eventtimer sysctl tree. In some cases the same hardware can be used for both purposes, but not always. On x86 it is common to use the TSC for the timecounter and the local APIC timer for the event timer. > I see lot of functions using getnanotime and friend but I don't get how they work. > They just iterate over time and read a volatile value. Where/how is that value kept updated? Every so often an event timer interrupt triggers the tc_windup() function in kern_tc.c. That function updates the timehands structure used by getnanotime() and friends. -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6399789.W1exljHUsy>