Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 May 2001 17:57:42 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        neugebar@dcs.gla.ac.uk (Rolf Neugebauer)
Cc:        freebsd-alpha@FreeBSD.ORG
Subject:   Re: determine cycle counter frequency in user space
Message-ID:  <200105011758.KAA17133@usr01.primenet.com>
In-Reply-To: <ysqpudt9yus.fsf@therese.dcs.gla.ac.uk> from "Rolf Neugebauer" at May 01, 2001 10:56:27 AM

next in thread | previous in thread | raw e-mail | index | archive | help
> > The closest you will find is hw.cpu_mhz, via sysctl.
> 
> Not on my 4.2-STABLE, late February vintage. I could parse
> hw.model, but that reports 533MHz, while dmesg reports 531MHz.
> 
> In a followup, Mike mentioned fluctuations of clock frequency. Any
> idea, by how much this fluctuation can be? percentage of MHz, kHz?
> 
> In general, I am not too fussed about these fluctuations, as I can
> take some fine grained samples using cycle counters together with more
> coarse grained once obtained from gettimeofday().
> 
> However, to get an estimate for cycles per second, I was looking for a
> programmatic way to access above mentioned variables instead of
> providing them as command line arguments. I'll just add an appropriate
> sysctl to get cycles_per_sec. If people are interested, I'll submit a
> patch.

It's unlikely that you will be able to do what you want the
way you want to do it.

In particular, it's possible for your program to be context
switched in the middle of your calculation, or for the system
to take interrupts, etc., wihch will result in serious skew
of your numbers.

When I did this task, I cheated tremendously.

Minimally, you will require periodic resynchornization with
the kernel drift information stored in timer structure.  You
should see /sys/i386/isa/clock.c and the timer code in the
file /sys/kern/kern_time.c.

Tracking through this code is actually pretty miserable, since
it uses the aforementioned structure as a template, so there's
no global place you can go to retrieve the syncronization data
in the kernel, since it's hidden on the other side of a pointer.

I wish this code were better documented as to its intended
function.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105011758.KAA17133>