thread scheduling priority

Daniel Eischen eischen at vigrid.com
Mon Jul 7 07:14:04 PDT 2003


On Mon, 7 Jul 2003, Petri Helenius wrote:

> I have two threads on a SMP (2 CPU, HT disabled) box with world+kernel
> from mid-June. (cvsupping to latest right now) and a process which
> runs two threads with the following code snippet, more or less in a process
> & maintenance (collecting statistics, doing housekeeping, etc.) fashion. 
> While
> the main thread does it's stuff it competes for a mutex with the other 
> thread. However
> I'm observing that the thread created in the snippet below has hard time 
> getting
> scheduled  while the main thread is running.

First, you should say what threading library you are using.
I'll answer assuming you are using libkse (if you aren't, ignore me).

Try forcing libkse to use one KSE.  By default, libkse will
create as many KSEs as CPUs that you have.  It is possible
that there is a problem with trying to keep both KSEs active
when you only have 2 threads and one or more of them block
or sleep.  To do this, set kern.threads.debug=1 and
kern.threads.virtual_cpu=1:

	# sysctl kern.threads.debug=1
	# sysctl kern.threads.virtual_cpu=1

Also, the default scheduling policy is SCHED_RR and the RR
interval is 20msec.  If your main thread is in a busy loop,
no other threads will run for 20 or so msec (assuming 1 KSE).

-- 
Dan Eischen



More information about the freebsd-threads mailing list