Are process schedulers implemented at OS level or Hardware level?

0

Are process schedulers implemented in software or hardware? If it's done in hardware how does the hardware keep track of the number of processes and where they're located when they're inactive? If it's software, does the hardware normally provide instructions to help with scheduling such as for loading or storing the registers at an address in memory?

EnderShadow

Posted 2015-12-23T02:52:59.577

Reputation: 53

There have been processor instructions to assist the scheduler and interrupt handlers. Some architectures (e.g. Intel i386 onward IIRC) had context save and context restore instructions. See http://wiki.osdev.org/Context_Switching

– sawdust – 2015-12-23T07:15:28.443

Answers

1

x86 CPUs on your normal PC platform do not implement scheduling in hardware, it is the kernel's job to do that. Neither do any other common CPUs such as ARM, MIPS, PowerPC, etc.

does the hardware normally provide instructions to help with scheduling such as for loading or storing the registers at an address in memory?

"Loading and storing registers at an address in memory" is a fundamental CPU operation that helps with just about everything a CPU does, not just scheduling tasks.

And not really - continuing with x86 as an example, there aren't any special process scheduling instructions.

About the only thing required from hardware from a scheduling perspective - if you want to have a pre-emptive multitasking system as opposed to a cooperative multitasking system - is a way to interrupt a task that is taking too long, and the PC platform provides timers that cause interrupts when they expire as a way to force a process to relinquish control of the CPU.

LawrenceC

Posted 2015-12-23T02:52:59.577

Reputation: 63 487

-1 for "And not really - continuing with x86 as an example, there aren't any special process scheduling instructions." – sawdust – 2015-12-23T07:17:43.410

You do have the TSS stuff which supports task switching (if it's used) but not task scheduling. – LawrenceC – 2015-12-23T11:20:19.953

If there's no task switching, then what's the purpose of task scheduling? When would a newly-ready, highest-priority task preempt an active lower-priority task? Are you claiming that it's not the scheduler's job to perform that switch? – sawdust – 2015-12-23T19:13:45.207

I agree with you (I did forget about the TSS features) - but just to be pedantic, deciding when a task runs and actually switching it are related but different things. IIRC you can't just set up task gates and then be done with it, you need something "above" the tasks that says ok, which task runs next - even if it's simple round robin or whatever. Looks like I should refresh my knowledge about this, though. :) – LawrenceC – 2015-12-24T12:13:55.993

Read this - http://wiki.osdev.org/Context_Switching

– LawrenceC – 2015-12-24T14:37:07.393

"Read this" -- Duh, I already posted that link in a comment to the Q yesterday. "deciding when a task runs and actually switching it are related but different things" -- That just boils down to more routines in one scheduler module, that is, it's still all under the purview of the scheduler subsystem. FWIW for other reasons I was looking in Linux kernel/sched/core.c, and found routines for determining the next task to run and task switching. – sawdust – 2015-12-24T19:35:08.067