From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 20 14:48:31 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 97DF61065672 for ; Fri, 20 Aug 2010 14:48:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 687278FC1A for ; Fri, 20 Aug 2010 14:48:31 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id EF72A46B17; Fri, 20 Aug 2010 10:48:30 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id C10468A04E; Fri, 20 Aug 2010 10:48:29 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Fri, 20 Aug 2010 09:38:45 -0400 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20100217; KDE/4.4.5; amd64; ; ) References: <1282310063.2601.9.camel@hp-laptop> In-Reply-To: <1282310063.2601.9.camel@hp-laptop> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201008200938.45590.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 20 Aug 2010 10:48:29 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Jesse Smith Subject: Re: Converting from jiffies to ticks X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2010 14:48:31 -0000 On Friday, August 20, 2010 9:14:23 am Jesse Smith wrote: > I am currently trying to port a program from Linux to FreeBSD which > detects how much processor time a process is using. The native Linux > code does this (in part) by reading the number of "jiffies" a given > process uses. This info is pulled from the /proc/PID/stat file. > > One function is failing on FreeBSD and it's obviously because FreeBSD > does not have all the same files/data in the /proc directory. > > I've looked around and, as I understand it, FreeBSD uses "ticks" instead > of "jiffies" to measure process usage. However, how to gather that data > is a bit lost on me. > > This raises a question for me: > Where can I find the equivalent information on FreeBSD? I assume > there's a function call. Maybe in the kvm_* family? I need to be able to > get the number of ticks a given PID is using, both in the kernel and > userspace. > > > The rest of the program measures everything in "jiffies", so it would be > ideal for me to get the ticks used on FreeBSD (based on PID), convert it > to "jiffies" and pass it back to the main program. FreeBSD saves the total runtime in an architecture-dependent "ticker" count that is separate from "ticks". ("ticks" tends to run at hz, so by default 1000 times per second, where as the 'ticker' on x86 is the TSC which runs at the clock speed of the CPU (throttling and turbo boost aside)). You can look at the calcru() function to see how the kernel converts the runtime "ticker" count (saved in rux_runtime) into microseconds. -- John Baldwin