in reply to Re^3: Design advice: Classic boss/worker program memory consumption (context switching is cheap)
in thread Design advice: Classic boss/worker program memory consumption
context switching is cheap
Sorry Tye, but that is twaddle. Eiher guesswork, or naiveté.
Firstly, which type of "context switch" are you mis-describing?
- Thread-context.
- Process-context.
The cost of a hardware-based, thread-only context switch runs from 10's to over 1000 microseconds. Add in the need to invalidate and refill L1/L2/L3 caches, and the total time to re-consitute a thread-context back the point that real work can proceed can actually take longer than the maximum timeslice some (flavours of some) OSs will allocate to a thread.
And don't go blaming threads; switching process-contexts is a (collection of) software operations and is more expensive still.
The cost of context switch may come from several aspects. The processor registers need to be saved and restored, the OS kernel code (scheduler) must execute, the TLB entries need to be reloaded, and processor pipeline must be flushed. These costs are directly associated with almost every context switch in a multitasking system. These are the direct costs.
In addition, context switch leads to cache sharing between multiple processes, which may result in performance degradation. This cost varies for different workloads with different memory access behaviors and for different architectures. These are cache interference costs or indirect costs of a context switch
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Design advice: Classic boss/worker program memory consumption (cache misses suck)
by tye (Sage) on May 21, 2014 at 03:15 UTC | |
by BrowserUk (Patriarch) on May 21, 2014 at 12:21 UTC |