Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Oct 2008 10:51:06 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?= <des@des.no>, ushasri tummala <tummala.ushasri@gmail.com>, Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Subject:   Re: What is the time between 2 mi_switches in freebsd.
Message-ID:  <200810131051.07174.jhb@freebsd.org>
In-Reply-To: <86zlleq397.fsf@ds4.des.no>
References:  <53fa490b0810071947j23fc0f72n5360b6f174ddc96d@mail.gmail.com> <20081008174956.GA98121@nexus.in-nomine.org> <86zlleq397.fsf@ds4.des.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday 08 October 2008 03:46:12 pm Dag-Erling Sm=C3=B8rgrav wrote:
> Jeroen Ruigrok van der Werven <asmodai@in-nomine.org> writes:
> > -On [20081008 19:15], ushasri tummala (tummala.ushasri@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.
>=20
> No, no, no.
>=20
> Assuming the question is really "what is the time between two task
> switches",
>=20
> A task switch can happen for one of many reasons:
>=20
>  - first, and simplest, the current task has used up its quantum;
>=20
>  - the current task is waiting for an external event (I/O, a mutex, a
>    timeout, etc.)
>=20
>  - the current task has terminated;
>=20
>  - something happened to make a higher-priority task runnable;
>=20
>  - ...
>=20
> 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, hz isn't the quantum.  sched_tick() is called 'hz' times per seco=
nd,=20
but the scheduler is free to implement its own quantum.  The default quantu=
m=20
for 4BSD is actually hz / 10 for example:

static int	sched_quantum;	/* Roundrobin scheduling quantum in ticks. */
#define	SCHED_QUANTUM	(hz / 10)	/* Default sched quantum */

I'm not sure what ULE's quantum is or how it is computed.

=2D-=20
John Baldwin



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