Threads and SMP kernel scheduling

Ulf Lilleengen ulf.lilleengen at gmail.com
Thu Jan 8 06:08:12 PST 2009


On Thu, Jan 08, 2009 at 04:23:08AM -0500, Mehmet Ali Aksoy TÜYSÜZ wrote:
> Hi all,
> 
> After I had a bit googling I got confused.
> 
> My questions are simple and they are as follows :
> 
> 1-) "Are pthreads (or threads in general) of one process scheduled to
> different cores on multi-core systems running Linux or BSD?"
> 
The standard threading library in FreeBSD will use a 1:1 mapping between
userland threads(pthreads) and kernel threads. This means that each thread
may run on a different core than other threads.

> 2-) What if there are multiple processes which have multiple threads? Does
> it change the answer of (1)?
No, the same mapping applies. Although threads of one process may preferably
run on the same core, each thread of a process may run on any of the cores
available.

> 
> I found some answers but they are not sharp. Somebody says "can be
> scheduled" but "can be" is not a precise answer (in my opinion.)
Well, it means that there are more factors deciding where a thread is put. If
you look at a factor such as affinity, one thread may preferable be scheduled
to the same core since the cache may contain data relevant to the thread.

> 
> Thanks everybody in advance.
> 
Hope everything is at least a bit clearer.

-- 
Ulf Lilleengen


More information about the freebsd-hackers mailing list