Skip to content

usb: retain DMA transfers and drain cancellable endpoints - #123

Merged
moratom merged 5 commits into
rvc2ng_developfrom
feat/rvc2ng-usb-support
Nov 25, 2026
Merged

moratom merged 5 commits into
rvc2ng_developfrom
feat/rvc2ng-usb-support

Conversation

@moratom

@moratom moratom commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

USB frame transport

Native camera frames keep their existing wire format. The sender queues the camera allocation to FunctionFS and retains it until the controller finishes. The host can reuse USB-mapped receive storage while an application holds earlier frames.

Review area Why it is here
usb_host.cpp and the retained write API Submit a DMA-BUF between the ordinary header and metadata. Cancellable endpoint I/O and terminal completion protect frame ownership when a host stops reading or disconnects.
usb_host_memory.cpp With identical DMA payloads, ordinary host buffers delivered 2.842–2.856 Gbit/s across three paired runs. Reuse delivered 3.556–3.559 Gbit/s. Each run transferred 1,199 × 4,177,920 bytes. The pool shares the system USBFS budget with control traffic.
Gate discovery and transactions in usb_host.cpp Select the named interface and hold one claim through the response. On protocol 1, an echoed nonce separates the new exchange from an abandoned reply. Protocol 0 keeps its existing framing.
Dispatcher reset and Windows semaphore commits Complete shutdown when a reset acknowledgement arrives and report a timed-out wait consistently on Windows. Both fixes have regressions.

Verification

On the focused head, 22 loopback/mock tests passed with system libusb and nine USB/reset tests passed with pinned libusb. The Linux receive suites share one allocator fixture. The wildcard discovery-count test gave the same inconsistent count on the target and feature commits in an isolated container. All 28 Linux, macOS and Windows matrix checks also passed on the focused head. This follow-up changes tests only.

Hardware coverage includes retained frames across reconnect on RVC2NG, RVC4 and RVC2, and recovery while USB remains configured. The raw-buffer comparison above isolates host mapping. The separate native dual-camera pipeline delivered 3.04128 Gbit/s of useful pixels over five 30-second runs. Hardware results and lifetime checks

Matevz Morato added 2 commits November 15, 2026 08:30
A server could serve its queued reset acknowledgement without stopping the transport, leaving reset waiting for a read that never ended. Close the local connection after serving the matching response through the existing dispatcher cleanup path.

Cover timed and untimed acknowledgements for both roles and timed silent peers. The regression fails when the dispatcher change is removed.
Keep native payload owners until FunctionFS DMA has stopped reading them. Native AIO makes endpoint reads and header/trailer writes cancellable, and connection close drains their real completions before releasing storage. Preserve legacy completion semantics without relaxing error or length checks.

Hold complete Gate exchanges under one interface claim, discover named composite interfaces, and synchronize protocol-1 transactions without replaying mutations. Reuse host receive mappings within shared USBFS headroom, retaining mappings and their accounting while applications hold frames.

Keep discovery, receive ownership, and DMA cancellation together because they share endpoint lookup and connection lifetime. The complete path is covered by native wire, cancellation, interface, admission, and ownership tests plus USB hardware qualification on RVC2NG, RVC4, and RVC2.
Matevz Morato added 3 commits November 15, 2026 08:41
Use the existing parenthesized std::min pattern so Windows headers cannot expand the Gate deadline and receive-limit calls as macros. Give the reset regression target the platform include directory already used by the other dispatcher tests, so its semaphore headers resolve on macOS and Windows.

The native Gate interface test and all six reset cases pass. The changes preserve transfer behavior and let the cross-platform CI jobs compile the new paths.
The Windows semaphore wrapper returned EINVAL when WaitForSingleObject timed out. The server dispatcher therefore treated an ordinary deadline as a wait failure, queued another reset, and waited indefinitely for a silent peer.

Map WAIT_TIMEOUT to ETIMEDOUT while preserving EINVAL for other failures. The new reset_server_timed_silent regression exposes this pre-existing Windows defect in both USB configurations.
Exercise transfer headroom and reconnect with the same held frames, so the interface and allocator suites use one modeled kernel budget and handle lifetime. Let CTest bound the reset calls directly.
@moratom
moratom marked this pull request as ready for review November 25, 2026 13:24
@moratom
moratom merged commit 1607dea into rvc2ng_develop Nov 25, 2026
28 checks passed
@moratom
moratom deleted the feat/rvc2ng-usb-support branch November 25, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant