Commit 76e9e535 by Ben Clayton

Subzero: Ensure coroutines are same-thread.

Marl now has a new flag on the task to say that it should be run on the same thread that calls `marl::schedule()`. This can dramatically reduce the scheduling overhead when bouncing between two tasks, as other threads do not have to be woken. ``` > go run ./third_party/marl/tools/cmd/benchdiff/main.go pre.json post.json Delta | Test name | (A) pre.json | (B) post.json -15.53x -1m16.299750679s | Coroutines/Fibonacci/iterations:16777216 | 1m21.551049724s | 5.251299045s -15.71x -1.206771937s | Coroutines/Fibonacci/iterations:262144 | 1.288789249s | 82.017312ms -15.72x -9.624071378s | Coroutines/Fibonacci/iterations:2097152 | 10.277884306s | 653.812928ms -15.77x -35.755µs | Coroutines/Fibonacci/iterations:8 | 38.176µs | 2.421µs -15.77x -150.190662ms | Coroutines/Fibonacci/iterations:32768 | 160.356788ms | 10.166126ms -15.79x -18.864275ms | Coroutines/Fibonacci/iterations:4096 | 20.139344ms | 1.275069ms -15.93x -2.332202ms | Coroutines/Fibonacci/iterations:512 | 2.488404ms | 156.202µs -15.96x -292.896µs | Coroutines/Fibonacci/iterations:64 | 312.481µs | 19.585µs ``` Bug: b/145754674 Change-Id: I0e014083e1dbc9f5cdf51e7abc378df6be22d805 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/42410Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d53eecae
...@@ -4760,7 +4760,7 @@ static Nucleus::CoroutineHandle invokeCoroutineBegin(std::function<Nucleus::Coro ...@@ -4760,7 +4760,7 @@ static Nucleus::CoroutineHandle invokeCoroutineBegin(std::function<Nucleus::Coro
::getOrCreateScheduler().bind(); ::getOrCreateScheduler().bind();
} }
marl::schedule([=] { auto run = [=] {
// Store handle in TLS so that the coroutine can grab it right away, before // Store handle in TLS so that the coroutine can grab it right away, before
// any fiber switch occurs. // any fiber switch occurs.
coro::setHandleParam(coroData); coro::setHandleParam(coroData);
...@@ -4770,7 +4770,8 @@ static Nucleus::CoroutineHandle invokeCoroutineBegin(std::function<Nucleus::Coro ...@@ -4770,7 +4770,8 @@ static Nucleus::CoroutineHandle invokeCoroutineBegin(std::function<Nucleus::Coro
coroData->done.signal(); // coroutine is done. coroData->done.signal(); // coroutine is done.
coroData->suspended.signal(); // resume any blocking await() call. coroData->suspended.signal(); // resume any blocking await() call.
coroData->terminated.signal(); // signal that the coroutine data is ready for freeing. coroData->terminated.signal(); // signal that the coroutine data is ready for freeing.
}); };
marl::schedule(marl::Task(run, marl::Task::Flags::SameThread));
coroData->suspended.wait(); // block until the first yield or coroutine end coroData->suspended.wait(); // block until the first yield or coroutine end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment