Hyper threading


If the operating system schedules multiple threads against a hyper-threaded CPU, the CLR automatically takes advantage of this. This is certainly the case for new versions of the OS like Windows Server 2003.

Also, the CLR did work to properly spin on a hyper threaded system. If you are writing your own spinlocks in managed code, be sure to use Thread.SpinWait so that you get the same benefits.

We also tune subsystems like the scalable server GC so that they make sensible decisions for hyper threading.

Comments (5)

  1. Hi Chris,

    (Wow, i’m very impressed by dropping a comment on one of your posts)

    It’s almost a question, in fact. I was looking for infos about hyperthreading yesterday, and I found a page on Intel’s web site that says that both versions of XP support hyperthreading (with a compatible CPU, of course).

    Link:
    http://www.intel.com/support/platform/ht/os.htm

    So, does the CLR take advantage of an HT CPU on XP too?

    /Christophe

  2. Chris Brumme says:

    Yes it does.

  3. Brian Grunkemeyer says:

    Chris, thanks for mentioning the SpinWait method. We’ve talked about this a few times in the past, but this never came up. I’ll use it in a few of my test cases. Perhaps I should mention this in my reliability document?

  4. The .NET 1.0 SDK documentation for Thread.SpinWait is not exactly illuminating:

    Thread.SpinWait Method [C#]: Causes a thread to wait the number of times defined by the iterations parameter.

    What exactly does Thread.SpinWait do?

  5. Chris Brumme says:

    Assume the usual caveats about how implementations are subject to change, etc.

    In a loop, we do a ‘rep nop’ instruction for the number of iterations you specify. This instruction is the approved way to create a yield from one logical CPU to another logical CPU of a hyper-threaded physical CPU.

Skip to main content