wazero icon indicating copy to clipboard operation
wazero copied to clipboard

JIT: consider locking Goroutine thread until JIT exits

Open mathetake opened this issue 3 years ago • 2 comments

We could use runtime.LockOSThread() to block Goruntime from switching the goroutine via async preemption which can happen at any point of execution.

Even though we've tested the JIT execution is stable without locking (as in jit/engine_test.go ), there might be still some condition where the JIT would fail.

This needs more through investigation on how Goroutine saves CPU registers when switches happens (at source code level), and more test cases to ensure whether or not we need thread blocking via LockOSThread.

mathetake avatar Jan 21 '22 03:01 mathetake

Be aware that parking/unparking threads under runtime.LockOSThread() seems to cause context switches https://github.com/golang/go/issues/21827

I suspect that locking will also cause context switches on any goroutine that have accumulated on the M in question since the last time it was locked, but I could be wrong about this.

CannibalVox avatar Mar 01 '22 21:03 CannibalVox

@CannibalVox thanks for the info!

mathetake avatar Mar 02 '22 01:03 mathetake