From: JS Labrie on
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
From: Tim Roberts on
JS Labrie <JSLabrie(a)discussions.microsoft.com> wrote:
>
>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, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: m on
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.

"JS Labrie" <JSLabrie(a)discussions.microsoft.com> wrote in message
news:B93ECE3A-352A-4DC1-A5A6-65CE3C6939AE(a)microsoft.com...
> 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