From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 20 13:46:24 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 1270610656A4 for ; Fri, 20 Aug 2010 13:46:24 +0000 (UTC) (envelope-from spawk@acm.poly.edu) Received: from acm.poly.edu (acm.poly.edu [128.238.9.200]) by mx1.freebsd.org (Postfix) with ESMTP id A788F8FC15 for ; Fri, 20 Aug 2010 13:46:21 +0000 (UTC) Received: (qmail 77993 invoked from network); 20 Aug 2010 13:46:21 -0000 Received: from unknown (HELO ?192.168.1.216?) (spawk@66.206.120.2) by acm.poly.edu with AES256-SHA encrypted SMTP; 20 Aug 2010 13:46:21 -0000 Message-ID: <4C6E8732.8090304@acm.poly.edu> Date: Fri, 20 Aug 2010 09:46:26 -0400 From: Boris Kochergin User-Agent: Thunderbird 2.0.0.24 (X11/20100530) MIME-Version: 1.0 To: Jesse Smith References: <1282310063.2601.9.camel@hp-laptop> In-Reply-To: <1282310063.2601.9.camel@hp-laptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org 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 13:46:24 -0000 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. > > Thanks for any advice, > Jesse > > As someone pointed out on -hackers, the jiffies situation in Linux is messy because it depends on the architecture, what version of the kernel is in use, etc. If, in the end, you're just interested in things like the real and CPU time used, however, check out kvm_getprocs(3). The information available with that call is documented in the kinfo_proc structure in /usr/include/sys/user.h. -Boris