What is the time between 2 mi_switches in freebsd.

Dag-Erling Smørgrav des at des.no
Wed Oct 8 19:46:14 UTC 2008


Jeroen Ruigrok van der Werven <asmodai at in-nomine.org> writes:
> -On [20081008 19:15], ushasri tummala (tummala.ushasri at gmail.com) wrote:
> > I just want to know how its(time between 2 mi_switch()) calculated
> > and in which variable is it stored in the code.(FreeBSD 5.2 release)
> > This is not addressed in text book.
> What Dag-Erling meant to say, and if I recall correctly, a switch() is
> highly dependent on your hardware. So the time taken for a specific
> machine can be vastly different from another machine.

No, no, no.

Assuming the question is really "what is the time between two task
switches",

A task switch can happen for one of many reasons:

 - first, and simplest, the current task has used up its quantum;

 - the current task is waiting for an external event (I/O, a mutex, a
   timeout, etc.)

 - the current task has terminated;

 - something happened to make a higher-priority task runnable;

 - ...

The closest you can get to a hard answer is if you consider only the
first of the above, in which case the answer is 1/hz second, where "hz"
is literally a kernel variable named hz.  Its default value is 1,000 on
amd64, i386, ia64 and sparc64, and 100 on all other platforms.

(actually, it's more complicated than that, because this default value
is a preprocessor macro called HZ which you can redefine in your kernel
config, and you can also set hz at boot time using the kern.hz loader
tunable)

A nice little project for someone with a lot of time on their hands
would be to make the FreeBSD kernel tickless, thus (to oversimplify)
eliminating hz.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list