From owner-freebsd-amd64@freebsd.org Sat Aug 1 05:32:32 2015 Return-Path: Delivered-To: freebsd-amd64@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9EAC39B16C8 for ; Sat, 1 Aug 2015 05:32:32 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 55F011809 for ; Sat, 1 Aug 2015 05:32:32 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (75-48-78-19.lightspeed.cncrca.sbcglobal.net [75.48.78.19]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 5CEF9B980; Sat, 1 Aug 2015 01:32:31 -0400 (EDT) From: John Baldwin To: freebsd-amd64@freebsd.org Subject: Re: kernel timers and clocks Date: Fri, 31 Jul 2015 10:40:16 -0700 Message-ID: <6399789.W1exljHUsy@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: <239381437645154@web15m.yandex.ru> References: <239381437645154@web15m.yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Sat, 01 Aug 2015 01:32:31 -0400 (EDT) X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Aug 2015 05:32:32 -0000 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