Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there an easy way to check whether a certain single-threaded application is being balanced across CPU cores by Windows?

I have already tried Process Explorer but I could not find a way to read it out, if possible in the first place.

The reason I am wanting to know this, is because I understand that not all single-threaded applications get balanced, but rather stick to 1 core instead.

share|improve this question
    
There's really no easy way to tell, but it's hard to see how that would be useful information anyway. If it's the only thing running, you can use the task manager to look at the load on each core. –  David Schwartz Jul 27 '12 at 0:18
1  
Applications must be written to take advantage of multiple cores. Since the programmer has to take care of identifying which parts of the program can be split and run concurrently and then has to deal with maintaining locks on data, many developers simply don't write their apps in this way. You said not all single-threaded applications get balanced. In fact, NO single-threaded applications can be split among cores. The application must be multi-threaded. This is a great question though because I can't seem to find an answer... –  Paul Ackerman Jul 27 '12 at 0:23
    
The programmer can lock an application to a particular CPU core if they want to, but there's rarely a good reason to do so. –  Harry Johnston Jul 27 '12 at 2:18
add comment

1 Answer

up vote 2 down vote accepted

"Balanced" is a relative term.

Moving a process between cores can invalidate certain optimizations (shared cache helps, but CPU registers are per core still), so if your OS is "balancing" a process by moving it around it may be causing more harm than good.
For highly optimized (often hand-crafted assembly) programs it can take longer to restore register states than to just let the process keep one CPU all to itself.

On the other hand if a CPU-Bound process doesn't use the registers heavily and doesn't so much care if they have to be reloaded, and if there is a lot of contention for the CPU, moving it around to whatever processor is available might improve performance.

What I'm getting at here is that for a single-threaded process You don't care -- Trust your operating system's scheduler to do the Right Thing (it really is smarter than you about this sort of thing).


For multithreaded processes the same logic applies, just multiple times: Do you care WHERE the threads are running as long as they're getting the CPU time they need and running quickly?
My guess is no.


To answer the question you asked: Because you really shouldn't care I don't think it's possible.

There's certainly not an easy way to get at this in Windows (the task manager and Process Explorer don't expose it anyway). You could look in to Power Shell scripting, but I don't believe there's a way to do it there either...

share|improve this answer
    
I should not care as long as it gets the CPU time it needs, but if I am planning to run multiple instances of this single-threaded application, would it not mean that only one core gets to deal with all of it? If so, I would like to assign a specific core to each of them. Would it not be a shame to have a beast of a CPU but only to be able to use one core? –  Xen Jul 27 '12 at 15:09
    
@Xen A single threaded app won't limit all instances of itself to a single thread, so you don't need to worry. If you want to try to control it manually anyway, you can use Set Affinity in Task Manager. If you fire up a bunch of instances, you can set the affinity of each process (assuming multiple instances spawn multiple processes) to an individual core, if you want. That said, voretaq7's right that the OS scheduler is going to do a better job than you will of getting the application the CPU it needs. –  HopelessN00b Jul 27 '12 at 21:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.