Search code examples
c#wpftask-parallel-libraryprocess-managementhyperthreading

Is hyperthreading working?


I'm running some fairly processor-intensive stuff on my PC, and notice my CPU usage looks pretty odd. My PC is a quad-core i7-870, which supposedly has eight virtual cores.
I'm using the Task Parallel library in .NET 4, so expect all cores to be nicely utilised, but am getting information like this from Process Monitor:

CPU usage

Cores 6 and 8 are hardly getting touched, and apart from a brief burst, 4 isn't either.
Is this what I should expect?


Solution

  • For the most part, yes, I think this looks reasonable. Keep in mind that hyperthreading really just fakes two cores. Each physical core is given two frontends, so it can read two streams of instructions in parallel. But they still share the same execution units. So when one HT core is busy, the execution units are taken, and so its "twin" core will be able to do very little work.

    That seems to be what you're seeing on the first two cores (the second in particular makes it very obvious)

    Apart from this, you'll almost never be able to get perfect CPU utilization. Sometimes, a core just has to stall waiting for memory. Sometimes it's executing a costly non-pipelined instruction, effectively blocking the execution units on that physical core for perhaps tens or even hundreds of cycles.

    And sometimes, dependencies between instructions might just mean that you don't have anything for one or more cores to execute.

    Apart from that, you see 8 graphs, and you only have 4 cores, so yes, of course hyperthreading is working. ;)