feat(server): make server alloc-free on bare_metal, and surface inbound non-SD unicast#131
Closed
JustinKovacich wants to merge 3 commits into
Closed
feat(server): make server alloc-free on bare_metal, and surface inbound non-SD unicast#131JustinKovacich wants to merge 3 commits into
JustinKovacich wants to merge 3 commits into
Conversation
…estCallback Two related changes to land the no-alloc bare-metal server path: 1. drop _alloc from the server feature and gate every alloc usage (use alloc::sync::Arc, Wrappable handles, SocketOptions, sd-protocol import, run_inner's 64 KiB vec! and new_with_deps/new_passive_with_deps' Arc-wrap constructors) so client+server+bare_metal builds with zero __rust_alloc/__rg_alloc symbol references. The Server struct's started latch is now a feature-gated StartedLatch type alias (Arc<AtomicBool> under _alloc, &'static AtomicBool on bare metal) passed through ServerStorage; the H/Hsd/Hep default generics use cfg'd DefaultSocketHandle/DefaultSdStateHandle/DefaultEventPublisherHandle aliases so Arc names don't need to resolve under no-alloc. StaticSubscriptionHandle returns core::future::Ready instead of alloc::boxed::Box::pin (the lock closures are synchronous). 2. Add NonSdRequestCallback fn-pointer on ServerStorage/Server, threaded through run_with_buffers/run_combined/recv_loop, invoked in place of the historical 'non-SD ignored' branch — surfaces method requests / fire-and-forget calls (e.g. halo's HWP1* requests) to the consumer FFI without requiring a ChannelFactory-backed ServerUpdates channel.
add non-SD observer support and no-alloc witness tests Co-authored-by: Justin Kovacich <32140377+JustinKovacich@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the server feature to be allocator-free by default for bare_metal/no_std usage, and adds an optional callback to surface inbound non-Service Discovery (non-SD) unicast SOME/IP datagrams to consumers.
Changes:
- Make bare-metal
SubscriptionHandleoperations allocation-free by returningcore::future::Readyinstead of boxed futures. - Add
NonSdRequestCallback/non_sd_observerplumbing fromServerDepsthrough the server runtime receive loop, plus tests that witness the callback behavior. - Add a new
no_alloc_server_witnessintegration test and register it inCargo.tomlas a no-alloc CI gate.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/no_alloc_server_witness.rs | New no-alloc runtime witness for StaticSubscriptionHandle hot paths. |
| tests/bare_metal_server.rs | Adds non_sd_observer initialization and callback behavior tests. |
| tests/bare_metal_e2e.rs | Updates ServerDeps construction to include non_sd_observer: None. |
| src/server/subscription_manager.rs | Removes heap allocation from bare-metal subscribe/unsubscribe by returning Ready. |
| src/server/runtime.rs | Threads non_sd_observer into recv_loop and invokes it for non-SD unicast datagrams. |
| src/server/mod.rs | Introduces NonSdRequestCallback, StartedLatch abstraction, and carries observer/latch through storage and run futures. |
| src/lib.rs | Re-exports NonSdRequestCallback under the server feature. |
| examples/embassy_net_client/src/main.rs | Updates example deps struct to set non_sd_observer: None. |
| examples/bare_metal_server/src/main.rs | Updates example deps struct to set non_sd_observer: None. |
| Cargo.toml | Removes _alloc implication from server feature; registers no_alloc_server_witness test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+649
to
+652
| #[cfg(feature = "_alloc")] | ||
| type StartedLatch = Arc<AtomicBool>; | ||
| #[cfg(not(feature = "_alloc"))] | ||
| type StartedLatch = &'static AtomicBool; |
Comment on lines
+642
to
+643
| /// payload is the full raw datagram bytes; the caller is responsible | ||
| /// for re-parsing the SOME/IP header (and applying any E2E check) on |
Comment on lines
+468
to
+474
| drive_until(|| { | ||
| OBSERVED_SOME | ||
| .get() | ||
| .and_then(|m| m.lock().unwrap().clone()) | ||
| .is_some() | ||
| }) | ||
| .await; |
Comment on lines
+559
to
+566
| let observed = OBSERVED_NONE | ||
| .get() | ||
| .and_then(|m| m.lock().unwrap().clone()); | ||
| assert!( | ||
| observed.is_none(), | ||
| "callback must NOT fire when non_sd_observer is None; got {:?}", | ||
| observed | ||
| ); |
Contributor
Author
|
Folded into |
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.
Makes the
serverfeature alloc-free by default and adds a callback for non-SD SOME/IP unicast datagrams.No-alloc support and feature gating
serveris alloc-free by default; allocator-backed conveniences gated behind_alloc. Default handle types switch betweenArc<T>and&'static Tby allocator availability.StartedLatchisArc<AtomicBool>on alloc builds,&'static AtomicBoolon no-alloc.Non-SD SOME/IP datagram callback
non_sd_observer(NonSdRequestCallback) invoked for every non-SD unicast datagram.Subscription handling for bare-metal/no-alloc
SubscriptionHandlereturnscore::future::Readyinstead of boxed futures onno_std.API
NonSdRequestCallbackunder theserverfeature.Stack: this ← #127 (PR 0) ← #129 (PR 1).