The VA-API hardware tests open their displays on GatedRuntime since
b52eea52f, whose exit gate closes before the drivers' exit-time destructors
run, after iHD aborted a test process that exited while a kept session was let
go on another thread. The NVIDIA arm's tests ran on std's runtime, which has
no gate: its waits fell back to StdRuntime::shared where no backend's opening
made a runtime, and the Annex B decoder's test handed it std's. Its call
threads and the sweep of work kept past a deadline call NVDEC, NVENC and CUDA
on threads of their own, so a test's process could exit beside them the same
way. No abort was seen on NVIDIA.
In a test the NVIDIA waits now fall back to GatedRuntime, which the first load
of a driver's library makes and arms (arm_exit, as Library::open and cuInit
call it), so its hook runs before what the library registered. The Annex B
decoder's test and the session-start probes hand the gated runtime too. One
gate serves the process, whichever arm's driver loads, so the NVIDIA tests use
VA-API's (vaapi::gated) rather than a second one.
A test of the pattern runs in a child process that registers an exit handler
as a driver's library would, then has the crate arm its gate: at exit the
crate's steps are refused by the time that handler runs. On std's runtime they
were still given. The product is unchanged: outside tests the fallback is
std's, as before.
59 lines
3.7 KiB
Markdown
59 lines
3.7 KiB
Markdown
# Core
|
|
|
|
`crates/reims-vgpu-video`'s `core` module (`src/core.rs`) is what the host's video arms
|
|
share, independent of the host, the driver and QEMU. It links nothing of the library's: the
|
|
library hands it a runtime instead. Each module's doc says what it holds; this file is the
|
|
overview.
|
|
|
|
## The runtime and the locks
|
|
|
|
- **`runtime`**: the threads and the clock the video code runs on, a `Runtime` of three calls
|
|
(a thread's start, the monotonic clock's time, one timed wait). The library's is its
|
|
platform's (reims-vgpu's `video/runtime.rs`, `PlatformRuntime`): a thread is a worker of the
|
|
platform's, named as the video code asks and marked as the library's, so that a panic on it ends
|
|
the process at once, and every bound is kept on the platform's monotonic clock, which a test
|
|
makes virtual. `StdRuntime` is std's threads and clock, for the examples; the hardware
|
|
tests of both arms run on it with an exit gate of their own (`vaapi::gated`), as the host's
|
|
runtime has one. A `Bell` is the one place the video code waits on a condition variable with a
|
|
deadline.
|
|
- **`sync`**: the locks, `parking_lot`'s, the types `reims_vgpu_vulkan::core::sync` re-exports.
|
|
|
|
## A guest surface's memory
|
|
|
|
- **`surfaces`**: a guest surface's layout (`SurfaceLayout`, `PlaneLayout`); **`fourcc`** the
|
|
four-character codes that name its pixel format.
|
|
- **`device_memory`**: a surface's memory as a device reaches it, for an arm whose GPU writes
|
|
a decoded picture into the guest's pages itself.
|
|
- `DeviceMemory` gives the pages as a dma-buf of byte ranges (`dma_buf_of`), for a GPU that
|
|
imports one (VA-API), or as one contiguous view in the host's address space
|
|
(`host_view`), for one that registers host memory (CUDA's `cuMemHostRegister`). Each is
|
|
the same pages the guest reads. The reims-graphics device's planes answer it over the
|
|
library's own view of the guest's RAM (reims-vgpu's `PlanePages`, in
|
|
`graphics/decode/video.rs`).
|
|
- `MemoryIdentity` names one mapping of the pages: the same for every hold on it, and never
|
|
the same for another mapping, so that an import kept by it is never used for pages mapped
|
|
since. `MemoryLife` goes with the mapping, and tells what kept something by its identity.
|
|
- `DeviceImports` keeps an arm's imports by identity and a variant of the arm's own, made
|
|
once for each and dropped on a thread of the runtime's as soon as the mapping goes.
|
|
- `GuestTarget` is a surface's layout checked against its memory, so that a device told to
|
|
write its planes writes nowhere else.
|
|
|
|
## Bounded waits
|
|
|
|
**`device_wait`**: no driver's blocking wait has a bound of its own (NVDEC's map, NVENC's lock,
|
|
CUDA's synchronous copy, VA-API's sync), so each backend asks the driver's own non-blocking
|
|
question until the work is done or `DEVICE_WAIT` (5 s) has passed (`poll_until`). Past it, the
|
|
work fails as the backend's malfunction, and the decoder or encoder fails each later call at
|
|
once. What the device may still write is kept until it is done: the backend's memory and
|
|
handle, an import of a guest buffer the device writes itself among them, go to `Lingering`,
|
|
whose thread asks each kept work's question every `LINGER_POLL` (100 ms) and drops it once the
|
|
device is done. Work a device never finishes is kept until the process ends, since freeing it
|
|
would hand memory the device may still write back to the allocator or to the guest.
|
|
|
|
## What a backend answers
|
|
|
|
**`backend`**: the pixel formats a backend writes (`PixelFormat`), whether its device wrote a
|
|
picture into a guest surface itself (`DeviceWrite`, `Declined` with why where it took the CPU's
|
|
copy instead), and why it could not do what it was asked (`BackendError`: unsupported, bad
|
|
data, a skipped leading picture, or the backend's malfunction).
|