News for hackers. Stuff that matters.
Re:Writing an OS in Rust: Async/Await by m0th87 on Monday March 30, 2020 @11:32AM (#22728792)
Is it possible to context switch between userspace processes directly, without going through the kernel, i.e. a kind of fast, inter-process cooperative multitasking? I know earlier operating systems used inter-process cooperative multitasking, but I'm guessing they still went through the scheduler?

I was trying to figure out if QNX does this with `MsgSend`, as QNX is renowned for being a fast microkernel, but it wasn't clear to me. According to Animats, "There's no scheduling delay; the control transfer happens immediately, almost like a coroutine. There's no CPU switch, so the data that's being sent is in the cache the service process will need." [1] According to wikipedia, "If the receiving process is waiting for the message, control of the CPU is transferred at the same time, without a pass through the CPU scheduler." [2]

It seems like `MsgSend` circumvents the scheduler, but does it circumvent context switching to the kernel entirely too?

1: https://news.ycombinator.com/item?id=9872640

2: https://en.wikipedia.org/wiki/QNX#Technology

Re:Writing an OS in Rust: Async/Await by retrac on Monday March 30, 2020 @01:20PM (#22729982)
It's not possible without specific hardware support.

Context-switching on most current platforms with virtual memory requires fiddling with things like page mappings, and that simply must be done from supervisor mode.

The ability to switch tasks in hardware has existed on some historical machines. For example the GEC 4000 series basically implemented a microkernel, including the scheduler, in hardware. Switching to another process was done with a single hardware instruction.

I don't think anything current has such features besides the long-obsolete and unused taskswitching feature on x86 processors.

Re:Writing an OS in Rust: Async/Await by cwzwarich on Monday March 30, 2020 @12:02PM (#22729058)
No, it doesn't circumvent context switching to the kernel. With memory protection and separate address spaces, you generally need privileged execution to change page tables. However, the raw CPU cost of a syscall exception to the kernel followed by an exception return to userspace isn't actually all that high compared to all of the work that an OS usually does on top of it.
Re:Writing an OS in Rust: Async/Await by bregma on Monday March 30, 2020 @02:55PM (#22731035)
MsgSend() in QNX Neutrino does not circumvent the kernel, just the scheduler. If you're clever and lucky you can get an entire round trip to and from the service in a single timeslice. On the other hand, MsgSend() always blocks, so the call could be preempted depending on service priority or if there is an I/O wait or whatever, and that would mean the scheduler comes to play.
Re:Writing an OS in Rust: Async/Await by yencabulator on Thursday April 02, 2020 @10:52AM (#22759654)
In the vaporware Mill CPU design, yes. On x86, afaik hard no.