atkielski.anthony at wanadoo.fr
Sun Mar 27 13:33:31 PST 2005
> Multiple processors can run multiple processes at the same time. A HT
> processor can only run two threads from the same process.
This is incorrect. HT processors don't care where the threads come
from; it is possible to run threads from two completely different
processes on the same HT processor. The threads have completely
independent architectural states and can come from anywhere in the
However, the design of hyperthreading favors a certain amount of
commonality between the contexts of each thread. While it's best to
have different instruction mixes, it helps if both threads are executing
in the same memory spaces, since resources such as on-device cache are
shared between the threads in the HT processor. Completely different
threads in different processes executing out of different areas of
memory might cause more contention for cache and similar resources (TLB,
etc.), diminishing the advantage of hyperthreading.
Also, spin waits need special consideration on HT processors. If one
thread spins on a gate or semaphore held by the other thread, it
effectively slows the other thread down, keeping both threads moving
more slowly than they might if they were in completely separate
processors. A solution for this suggested by Intel is the PAUSE
instruction, which forces complete execution of a spin-wait instruction
before the next execution can begin, thus freeing resources for the
other thread in the processor. Intel recommends the use of PAUSE even
when HT processors are not being used.
Still another recommendation is to schedule first physically independent
processors, then HT logical processors. This requires that the OS be
aware of the difference between the two. This usually makes more
efficient use of processor resources, except for some very specific
cases where running two threads on the same HT processor might run as
fast or faster than running them separately (if they are referencing a
lot of the same shared resources, such as cache).
Intel claims up to a 30% improvement in throughput for an HT processor
as compared to a normal processor. For truly separate physical
processors, the improvement is more like 60%, and possibly much more.
Hyperthreading should not be seen as a substitute for multiple
processors. It's more like a way to make better use of each processor.
Hyperthreading is especially useful when multiple execution threads
exist in a common context, such as multithreaded daemons or
multithreaded desktop applications. In these situations, the HT
architecture is used to the fullest, with corresponding improvements in
Recent changes in FreeBSD architecture to allow a multithreaded kernel
are among the situations in which hyperthreading can be put to good use.
The new multithreaded architecture of Apache 2.x should also be able to
put HT to good use.
More information about the freebsd-questions