Can threads switch processors?

At my workplace there is a common powerful 24-core server on which we run our tasks. To use the full power of a multi-core processor, I wrote a multi-threaded version of a long-term program, so that 24 threads are simultaneously launched on each core (through the threading library in Jython ).

The program runs quickly if there are no other tasks. However, I did a lot of work simultaneously on one core, and as a result, a thread running on that particular core took a long time, slowing down the entire program (since the threads had to join the data at the end). However, threads on other processors completed execution long ago - so I basically had 23 cores idle and 1 core worked with thread and hard work, or at least that's what my diagnosis is. This was further confirmed by looking at the output of the time command, the sys time was very low compared to user time (which means a lot was expected).

In this case, the operating system ( Linux ) does not switch tasks to different CPUs if one processor is loaded and the other ones do not work? If not, can I do this in my program (in Jython ). Sometimes it’s not difficult to request different CPU loads, and then switch to one that is relatively free.

Thanks.

+4
source share
1 answer

Source http://www.ibm.com/developerworks/linux/library/l-scheduler/ :

To maintain a balanced workload between processors, work can be redistributed, taking work from an overloaded processor and providing it with underload. Linux 2.6 Scheduler provides this functionality using load balancing. Every 200 ms, the processor checks to see if the processor loads, if any, the processor performs task balancing with several processors.

The negative aspect of this process is that the new CPU cache is cold for the transferred task (you need to pull your data into the cache).

It looks like Linux is already balancing kernel threads.

However, assuming the Linux load balance is instantaneous (which is not the case), your problem still boils down to where you have 23 cores and 24 tasks. In the worst case scenario (when all tasks take an equally long time), it takes twice as much time as having only 23 tasks, because if they all take the same time to complete, then the last task remains to wait for another task to be executed to completion there is a free core.

If the wall time of the program suffers a slowdown of about 2x, this is probably the problem.

If it is significantly worse than 2x, you may be in an earlier version of the Linux scheduler.

+1
source

All Articles