News for hackers. Stuff that matters.
Re:Cooperative Threading by cfallin on Wednesday November 13, 2019 @01:50AM (#21521696)
That would still involve entering and leaving kernel mode, because timer alarms ultimately are triggered by a hardware interrupt (from e.g. the APIC timer or, in really old x86 machines, the 8254 programmable interval timer, aka IRQ 0). So IRQ -> switch to kernel timer IRQ handler (prologue saves all usermode registers) -> examine internal data structures, find pending alarm signal -> modify process state, pushing signal frame and setting RIP to signal handler -> return to userspace. That's probably slower than just Timer IRQ -> switch to kernel -> invoke scheduler -> decides to preempt, changes to new thread -> restore context, return to user space (but I'd be curious if someone actually measured).

Fundamentally, preemption has to originate from a hardware IRQ (or IPI from another core), so really the only way would be to kernel-bypass by setting an IRQ handler in userspace (ring 3). That's technically possible on x86 (IDT entry can have a ring-3 code segment) but I don't think the kernel has a mechanism for that...

Re:Cooperative Threading by nitrogen on Wednesday November 13, 2019 @12:24PM (#21526734)
How do user-mode network drivers work? Do they rely on polling, or do they still have the kernel handle interrupts?
Re:Cooperative Threading by gpderetta on Wednesday November 13, 2019 @05:30AM (#21522658)
I wonder whether virtualization hardware can be used for this.