Repository navigation
Conversation
Adds SUBSPACE_CORO_BACKEND_CO20, selected with --config=cpp20 in Bazel and automatically by CMake when CMAKE_CXX_STANDARD >= 20. The build always defines the backend macro, and a link-time symbol check rejects objects built for different backends. common/async gains task.h: async::Task<T>, ASYNC_AWAIT and ASYNC_RETURN let a function that waits be written once for every backend, and SyncWait runs a task from non-coroutine code. Waits, sockets, ByteStream and AsyncRuntime are implemented on co20::Scheduler. A co20 Context holds a co20 coroutine (which suspends) or an AsyncWaiter (which blocks the thread, yielding a stackful co::Coroutine), and falls back to poll(). The client's blocking API now takes const toolbelt::AsyncWaiter* instead of const co::Coroutine*. The co library is patched (patches/co_cpp20_wait_any_and_reap.patch) with a multi-fd Wait, reaping of finished coroutines, a fix for the poll fallback resuming a coroutine twice, non-aggregate ValueTask promises for GCC, destruction of all nested frames when a suspended coroutine is destroyed, and Run() honouring Stop() from a coroutine in epoll mode. The client and server are not yet converted to co20.
co 3.5.2 stores a ValueTask result in a std::optional and keeps an exception in exception_ptr, rather than storing a bare value and swallowing exceptions. SyncWait now rethrows a stored exception, as the other backends do, and unwraps the optional result. Under co20, Wait returns -1 on timeout as well as for a closed fd. Only a closed fd is an error, so a timed wait that expires is reported as DeadlineExceeded again.
The co20 fixes that were in patches/co_cpp20_wait_any_and_reap.patch are now a branch in ~/co (co 3.5.2, co20-subspace-support, commit fe00d44). Pin coroutines to that commit through a file:// remote in MODULE.bazel and in the CMake FetchContent, and delete the patch and its PATCH_COMMAND. The file:// pin only resolves on this machine until the branch is pushed to dallison/co.
The co20 changes were merged upstream as dallison/co#82 (db9ecf4), so the pin moves from the local ~/co branch to the GitHub remote.
- Convert ClientImpl server round-trips, buffer attachment/unmapping, split-buffer registration/lookup, channel reload callbacks, and publisher/subscriber slot search paths to return async::Task<T> using ASYNC_AWAIT / ASYNC_RETURN, keeping the synchronous public Client, Publisher, and Subscriber APIs unchanged via ASYNC_BLOCK (SyncWait). - Add <SyncName>Async variants (including CloseAsync) on Client, Publisher, and Subscriber for coroutines running on a co20::Scheduler, rejecting thread-safe clients with FailedPrecondition. - Convert Server, ClientHandler, TunnelManager, FFI, Python server wrapper, and plugin entry points to async::Task and RuntimeEngine, using SERVER_CLIENT_CALL / SERVER_CLIENT_CLOSE for in-process clients running on the server scheduler thread. - Route ASYNC_AWAIT through FastAwait so ValueTasks that complete without parking on the scheduler unwind in place instead of relying on compiler symmetric-transfer TCO (avoiding C stack overflow under GCC -O0 and AddressSanitizer), and guard hot-path reload/update checks. - Prevent ShouldReconnect from blocking in connect() when a co20 coroutine's interrupt fd is already signaled during server shutdown, and yield instead of sleeping in ListenerCoroutine's shutdown drain. - Gate co-only and zero-allocation tests under //:coro_backend_co20, add the cpp20 CI workflow job, and document the co20 backend in docs/cpp20-coroutines.md and CHANGELOG.md.
- Make ClientChannel::OpenBuffer and AttachShmBuffers async::Task so the memfd path can await GetRegisteredClientBuffer under co20. - Update the memfd-only AndroidBufferRegistrationTest for Task callbacks. - Gate c_client/shadow/rpc test targets off under the co20 CMake backend and link subspace_async into subspace_common so common tests link. - Record Linux verification results in the co20 handoff doc.
common_test and split_buffer_test failed to link on every backend because context.h references a backend link-check symbol defined in subspace_async.
Every call to an async::Task function allocated a coroutine frame from the
global heap: about 7 allocations per publish and 5 per read. Give every
co20::ValueTask a promise type (via a std::coroutine_traits specialisation)
whose operator new/delete use a per-thread, size-class frame pool, so a path
that has run once on a thread allocates nothing.
- Add common/async/frame_pool.{h,cc}. The pool is off under ASan/TSan so
they still see frame lifetimes; SUBSPACE_ASYNC_FRAME_POOL=0/1 overrides.
- Include task.h from co20_rpc's shared_ptr_pipe.h so every definition of its
ValueTask coroutine uses the same promise type.
- Run //client:alloc_test under co20 now that it holds, and add frame pool
tests to async_test.
- Update the co20 docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
co20) backend (--config=cpp20/-DSUBSPACE_CORO_BACKEND=co20) to the async layer, client, server, tunnel, FFI and plugins. Seedocs/cpp20-coroutines.md.docs/co20-linux-debug-handoff.md) with the results of the Linux run.common/async/frame_pool.h, installed for everyco20::ValueTaskbytask.h), so the publish and read paths allocate nothing once warm. Previously they cost about 7 and 5 heap allocations per message.//client:alloc_testnow runs under co20. The pool is off under ASan/TSan;-DSUBSPACE_ASYNC_FRAME_POOL=0disables it.--config=cpp20 --config=linux_memfddid not compile:ClientChannel::OpenBuffercalled the asyncGetRegisteredClientBufferwithout awaiting.OpenBuffer/AttachShmBuffersare nowasync::Task, and the memfd-onlyAndroidBufferRegistrationTestis updated.co20build failed:c_client,shadowandrpctests (which constructServerwithco::CoroutineScheduler) are now gated off underco20as in Bazel, andsubspace_commonlinkssubspace_async(for every backend, sincecontext.hreferences its link-check symbol) socommon_test/split_buffer_testlink.Test plan
Linux, Ubuntu 22.04, GCC 11:
bazelisk test --config=cpp20 //...bazelisk test //...--config=cpp20 --config=asanon common/client/server/rpc targets, plus 5x stress of bridge/tunnel tests--config=cpp20 --config=tsan(withsetarch -R)--config=cpp20 --config=linux_memfd(full suite) and default backend withlinux_memfd--config=cpp20 --config=mtls,--config=cpp20 --config=slot_size_64co20build +ctest(21/21)Known failures that also occur on the default backend (not
co20regressions)://client/python:client_test(runtime not first in library list),//coro_rpc/{client,test}(leaks in oldcoro_rpc)PluginTestin//client:client_test(nop_pluginlogging race through sharedtoolbelt::Loggerbuffer inServer::Stop)//rust_client:client_testcross-language tests (Rust client has no Linux memfd support)