News for hackers. Stuff that matters.
Re:Comparison of Rust async and Linux thread context switch ... by singron on Friday February 12, 2021 @12:20AM (#26110981)
Google found that the main cost of context switching isn't really in the syscall boundary but in the task scheduling. That's why their linux fork has optional userspace scheduling of kernel threads with the switchto syscalls[0]. Essentially, if your thread already knows which thread should run next, it can context switch to it without having to schedule in the kernel, which is exactly the situation in these bucket brigade benchmarks.

This benchmark as written is probably underestimating kernel task scheduling cost since only 1 task is runnable at any 1 time, while a realistic multi-threaded system will have more runnable threads to juggle.

0: http://pdxplumbers.osuosl.org/2013/ocw//system/presentations...

Re:Comparison of Rust async and Linux thread context switch ... by otabdeveloper4 on Friday February 12, 2021 @03:35AM (#26111738)
Yes, the point of "async" isn't to save CPU cycles, it's to customize the scheduler so that you can prioritize resource use properly.

(E.g., don't switch to the systemd or sshd thread if a customer's web request is timing out.)

That said, doing this right is out of reach of the average programmer, and it's doubtful that the compiler has enough domain-specific knowledge to do this automatically.

"Async" of the Python and node.js fame is yet another thing, a hack to get around their interpreters' inability to use kernel multitasking features because of global locks.