Discussion:
Problem with SetThreadAffinityMask + HT
(too old to reply)
JS Labrie
2010-07-27 19:45:13 UTC
Permalink
Hi,

the setup is a dual 4 core Nehalem (E5540) with HyperThreading (HT) enabled
running under Windows 7 Enterprise x64.

We have made a simple program that creates threads and we put an affinity on
them. For example, we create 4 threads and set an affinity of 0xAA. In that
case, the 4 threads will not run in parallel. We will have 2 or 3 at most.
The only time we get the 4 threads running at the same time is if we set the
affinity to be all processors or if we force each thread to a single CPU.
Under Vista or with HT disabled, the behaviour is not seen.

Does anybody have an idea?

thanks
Jean-Sebastien
Tim Roberts
2010-07-29 05:21:49 UTC
Permalink
Post by JS Labrie
the setup is a dual 4 core Nehalem (E5540) with HyperThreading (HT) enabled
running under Windows 7 Enterprise x64.
We have made a simple program that creates threads and we put an affinity on
them. For example, we create 4 threads and set an affinity of 0xAA. In that
case, the 4 threads will not run in parallel. We will have 2 or 3 at most.
The only time we get the 4 threads running at the same time is if we set the
affinity to be all processors or if we force each thread to a single CPU.
Under Vista or with HT disabled, the behaviour is not seen.
Does anybody have an idea?
You are assuming that the two processors of a hyperthreaded core will
always be represented by adjacent bits. I'm not convinced that is promised
anywhere in the documentation.

The operating system already knows about hyperthreading, and will try to
populate the cores before it doubles one up. I'm not convinced you're
actually helping yourself, which is generally the case with affinities.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
m
2010-07-29 23:12:35 UTC
Permalink
What are you trying to achieve by setting specific affinity? If you want
the threads to NOT run in parallel, then this is unreliable since the
scheduler will just interrupt you; but if you want the threads to run in
parallel, then why set the affinity at all since the scheduler will attempt
to do this as much as possible as a default behaviour?

IMHO, the best use of affinity / ideal processors is on NUMA where
restricting a thread, or group of threads, to a node can improve memory
locality and execution time in a way that the scheduler can't judge
effectively.
Post by JS Labrie
Hi,
the setup is a dual 4 core Nehalem (E5540) with HyperThreading (HT) enabled
running under Windows 7 Enterprise x64.
We have made a simple program that creates threads and we put an affinity on
them. For example, we create 4 threads and set an affinity of 0xAA. In that
case, the 4 threads will not run in parallel. We will have 2 or 3 at most.
The only time we get the 4 threads running at the same time is if we set the
affinity to be all processors or if we force each thread to a single CPU.
Under Vista or with HT disabled, the behaviour is not seen.
Does anybody have an idea?
thanks
Jean-Sebastien
Loading...