4 ms·
Where does a context switch fall in this? A function call?
by anonymousDan 7y ago
Where does a context switch fall in this? A function call?
- gameswithgo 7y agoif the function address is in l1 cache, and has no parameters, its about like an l1 cache I think. if its in ram, then like ram. then size/amount of parameters affects it, and its not continuous because at some threshold compilers may start doing it differently.
- mangamadaiyan 7y agoDefinitely more expensive than a function call. You need to switch to a different virtual address space, set up the CPU registers appropriately, et cetera. All of this happens in kernel space, so you also have a switch to kernel mode (and back). Latency wise, this should be somewhere in the single-digit microsecond range, I'd think. However, fallouts of a context switch include dealing with cache misses, TLB misses, and the like, which - depending on what you do - could be pretty expensive.
- jcranmer 7y agoFunction call overhead is on the order of several 10s of clock cycles (round to 100, not 10), or a few dozen nanoseconds. The actual impact of function calls is usually not so much the overhead of the call itself, but rather on the fact that function calls tend to be barriers to analyses and optimizations. Context switches are closer to about 1µs in the best case, with interprocess context switches maybe reaching 5µs. The time here is much more variable because the really painful thing is the effect of TLB flushing and other microarchitectural state going completely haywire.
- yjftsjthsd-h 7y ago> The time here is much more variable because the really painful thing is the effect of TLB flushing and other microarchitectural state going completely haywire. Isn't context switch also where spectre/meltdown mitigations hit the hardest, too?