2
votes

Does context switch between process take equal time for all the Process ( Constant Time ) or the context switch time is dependent on various local factors which varies from process to process ( like process size,stack size etc..) ?

EDIT : Assume the OS and Hardware are fixed, means will the time be same in a given OS and hwd. environment ?

1
This is two different questions - you cannot combine them with 'or' :)Martin James
Also 'quantum' is a word that should not enter into any discussion of OS scheduling. It strongly suggests that threads can only run for some set of discrete intervals. Most OS have not worked like that since the late 60's.Martin James
If you want guarantees, you will have to use a real-time OS that provides them :(Martin James
Also remember about caches. With all other things being equal, if one process' data structures are in the cache, while the other's aren't, you'll spend extra cycles bringing them into the cache from the main memory.Alexey Frunze
@Alex - that is true if the data is actually in main memory. If it's been paged out..Martin James

1 Answers

1
votes

It varies with hardware as well as OS/process :( To run a thread from a different process, memory-management context, floating-point context etc. must be swapped. This is easier/quicker on some hardware than others.

Drivers vary widely in the time they take to handle their hardware and signal the OS that a thread should be made running - so that's another complication.

In some cases, such a swap may need the preemption of a thread running on another core than the one that received the hardware/software interrupt that initiated the swap. This takes a lot longer than swapping context on the same processor.

It's difficult to come up with any sort of average figure on this. Where would you time it from - the driver interrupt that initiated the inter-process thread swap or from the entry to the scheduler from the driver?

So, overall, we can probably agree that it takes some time and it can vary.