I'm running some fairly processor-intensive stuf开发者_开发技巧f 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:Cores 6 and 8 are hardly getting touched, and apart from a brief burst, 4 isn't either.
Is this what I should expect?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. ;)
In short
- yes it works (of course)
- profile it
- YMMV - hyperthreading is not multi-coring and as such depends heavily on the type of instruction load and cache saturation etc. Not knowing anything about your code (except that it is C#, really) you might look for collections of 'small objects' that could be made into straight System.Array's of structs (A generic
List<>
will also use an Array internally and optimize for struct element types)
$0.02
It all depends on your algorithm implementation. TPL will use proper number of cores depending upon the data dependency in your algorithm
精彩评论