Multiprocessor Scheduling

From OSDev.wiki
Revision as of 22:16, 6 March 2007 by Combuster (talk | contribs) (Rough import from osfaq)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Convert

Introduction

[Scheduling Algorithms] can get tricky when more than one CPU is involved, and with Intel's Hyperthreading technology (one complex CPU appearing as mutliple CPUs), MultiProcessors OSdev'ing come to the hobbyist aswell...

All of a sudden, the details of the CPU architecture become even more important than with singleprocessor systems. How is the Memory Management Unit (MMU) designed? Some CPUs are able to hold page tables for more than one process in their Translation Lookaside Buffer (TLB) - it would benefit the system performance if the same process would always run on the same CPU, instead of a different one each time it is scheduled.

Another issue is multithreading. On a single-CPU system, multithreading (i.e., more than one control flow in a single address space) is a fine thing, and if done right can greatly benefit a system's performance. But on a multiprocessor system, there are even greater benefits to win - while at the same time it gets harder to achieve them.

ToDo: I have to remember putting that piece about scheduler activations in here...


Other facts ...

One thing that I have read on the subject is that some threads may be *pinned* on a specific CPU while other threads will execute on the first available CPU. This can make sense, for instance, to make the GUI server's main thread 'resident' on a CPU to achive high responsiveness (other threads that want to interact with the GUI can do so without incurring a context switch penalty :)

Pinning a thread to a CPU also helps the CPU's cache. If a thread is jumping between CPUs each time it is run, it never gets chance to fill either CPU's cache with code or data: it might run for a moment, and load some instructions from main memory, then get pre-empted. Next time it is scheduled, it might be running on a different CPU, where it would need to load the cache all over again. If the scheduler can assign each thread its own favourite CPU, it can help increase cache performance. Of course, if two threads with the same favourite CPU want to run at the same time on a dual processor system, one of them will have to take the 'wrong' CPU.

System V (iirc) had a nice synchronisation tool (a sort of smart spinlock) for multiprocessors that allowed a thread to busy-wait for a resource as long as the resource holder was active on another CPU and to enter the SLEEP state when the holder wasn't running. This has been proved in papers (which i lost the references) that this method pays and leads to better performances than always entering the SLEEP state when a resource was busy.

Related Threads

[SMP Compatibility|Forum:6377]