What is it?

CPU scheduling is about scheduling what order the CPU should do tasks in. This can be a challenging problem as the CPU doesn't know what tasks are of higher priority to the user, and therefore doesn't know what order to do them in.

There are various ways to do scheduling. The first is first come first serve. This is is self-explanitory. The first task that is scheduled is the first one to be done, no matter how big or small it is.

The second is Round Robin. This type of scheduling makes sure that later tasks which are smaller, get done quicker by only focusing on a specific task for a certain amount of time before moving on. This can be good as smaller, later tasks will be done quicker.

Then there's shortest remaining time and shortest job. These order the jobs in order of shortest remaining time / shortest job, and then carry out the jobs from shortest to longest. This can be good as it does the shortest jobs first, however getting teh jobs in a sorted list can be challenging, especially at so many cycles per second

Interrupts

When an interrupt (IRQ: Interrupt ReQuest) occurs (such as a key stroke, mosue event, or system timer), the CPU has to handle the interrupt as quickly as possible (ISR: Interupt Service rountine), before moving onto the rest of the jobs that the CPU needs to do.

What actually happens in the CPU is more complex though. The registers from the job that the CPU was currently doing get moved onto a stack, where the last job is at the top, so it will be accessed next, like a stack of plates. The program counter gets set to the instruction of the IRQ and then the IQR gets carried out. Then the last job gets carried over from the stack onto the CPU where it can finally be fully completed.

Showcase:

Scheduler type
Max time slice
Instruction swap time
Speed