views:

118

answers:

2

Hi,

Is there any evidence to suggest that by manually picking which processor to run a thread on you can improve system performance?

For example say you dedicated the thread that does the most work to one core and all other "helper" threads to a second.

+1  A: 

I can't see that there is a case for this.

Remember that any multiprocessor enabled OS will automatically allocate processor time as it sees fit in an attempt to balance out processor loading.

This means that in reality any process thread that you have running will be constantly interrupted, based on the thread priority, so that the OS can allocate processor time to other processes. Individual computations within the same thread may not even be executed on the same processor.

If you fixed process code to run on just the one specified processor then this would likely hinder its performance as it would not allow the OS to balance processor loading.

I suppose that you could make large parts of it a critical section but this would hinder your application in other areas, especially the processing of any sub threads.

ChrisBD
A: 

It seems possible, at least in theory, that system performance could be degraded somewhat by having a thread bounce around between different cores. Since many multi-core designs involve a separate L1 cache for each core, any time a thread moves to a new core, any data that thread was accessing before is no longer cached in the new core and has to be fetched from a higher level cache (or memory).

Keeping a thread running on the same core will increase the likelihood that the L1 cache has data pertinent to what the thread is doing. Of course, how much of an impact this has depends on other factors as well, like the size of the cache and how many other threads are being scheduled "concurrently" on the core.

Dan Moulding
Unless you are actually running one thread per core (which seems unlikely) then the effect of switching cores will be very similar to the effect of switching context on the same core.
Ade Miller
Well, no, context switches will not necessarily have the same effect. Yes, if the cache is completely (or significantly) refilled with new data by the time the "original" thread is switched back in, then the context switch and core switch will have a similar effect. However, this won't necessarily be the case. Also, your assumption about one thread per core being unlikely is not true. It's quite common for most threads in the system to be idle, with only one (or a few) actually doing anything. So 99% of the time, you may very well be running only one thread per core.
Dan Moulding