News for hackers. Stuff that matters.
Re:Making the Tokio scheduler 10x faster by networkimprov on Monday October 14, 2019 @01:35PM (#21250723)
The Go team is working on an update of its scheduler to make it preemptive. Will Tokio follow suit?

https://github.com/golang/go/issues/24543

Re:Making the Tokio scheduler 10x faster by carllerche on Monday October 14, 2019 @01:41PM (#21250794)
My understanding of that PR is it relates to how the Go compiler does code generation. Rust takes a different approach and is about to ship `async / await` which is a different strategy.

Preemption is out of scope for Tokio as we are focusing on a runtime to power Rust async functions. So, for the foreseeable, Tokio will using "cooperative preemption" via `await` points.

Re:Making the Tokio scheduler 10x faster by 15155 on Monday October 14, 2019 @01:44PM (#21250830)
IIRC: one of the issues with the original Rust stdlib greenthread implementation was that it's extremely difficult to preempt execution in a systems language. It's also quite difficult to add userland execution preemption without incurring significant performance penalties.

How do you preempt syscalls or FFI calls? (Go will almost certainly also have this issue with cgo modules)

I would be very surprised if preemptible Futures are something Tokio can or would implement.

Re:Making the Tokio scheduler 10x faster by wbl on Monday October 14, 2019 @04:48PM (#21252719)
What does systems mean here? There is a dirty trick with a NOP and self rewriting code that's quite cheap when not triggered. I think java does it that way.
Re:Making the Tokio scheduler 10x faster by sansnomme on Monday October 14, 2019 @05:24PM (#21253062)
Elaborate?
Re:Making the Tokio scheduler 10x faster by wbl on Monday October 14, 2019 @06:16PM (#21253469)
So you put in a NOP before each backward jump. To preempt you overwrite it with a jump to a handler that saves the state of the thread.
Re:Making the Tokio scheduler 10x faster by jedisct1 on Monday October 14, 2019 @06:51PM (#21253708)
How multitasking used to work on Atari :)

But this requires code pages to be writable. Which, from a security perspective is awful.

Re:Making the Tokio scheduler 10x faster by nine_k on Monday October 14, 2019 @07:56PM (#21254175)
This presumes writable code segments, which many OSes shun.
Re:Making the Tokio scheduler 10x faster by hyperman1 on Tuesday October 15, 2019 @07:09AM (#21257337)
It's java. Dynamic code generated by a jit.
Re:Making the Tokio scheduler 10x faster by adwn on Tuesday October 15, 2019 @12:15AM (#21255516)
Which NOP do you overwrite? Do you have to do this for all backward-jump-NOPs in all loaded executable code, or do you have to determine, which loop the thread in question is executing right now?
Re:Making the Tokio scheduler 10x faster by heavenlyblue on Monday October 14, 2019 @07:17PM (#21253914)
How does that resolve syscall question?
Re:Making the Tokio scheduler 10x faster by wbl on Monday October 14, 2019 @09:56PM (#21254886)
Syscall you have to do with a signal
Re:Making the Tokio scheduler 10x faster by pcwalton on Monday October 14, 2019 @01:49PM (#21250883)
Preemption isn't a concept that applies to a task scheduler like Tokio. You can't just inject more states into a finite state machine at runtime.
Re:Making the Tokio scheduler 10x faster by Exuma on Monday October 14, 2019 @03:42PM (#21251981)
When does that get released into Go? That sounds cool