🐛 Let go of a pages block's view and import before its answer
At a pages block's BLOCK_RELEASE its view went, with its import, into the cache of views, and a later pages block over the same runs took it. On metal2vulkan-runtime's device the import stayed a block the device knows until the cache let the view go, so after the release's answer, once the kext had unwired the pages and macOS could give them to anyone, a buffer the guest pinned at an address in the import resolved into it and lay over those pages, and a pinned buffer made zeroed from a byte had rt zero its range there on the CPU. A pages block's view is now never cached. It goes at the release with its import, which the platform forgets as the import's buffer goes, and the release's answer waits for that let-go on the surface worker, besides the command buffers it waited for before. After the answer no pin resolves in the import and no buffer the host makes lies over the pages; the platform frees the import, and the view's mapping with it, at its own last use of them. IOSurface views are cached as before. What changes for the guest: a pages block made again over the runs of a released one makes a view and an import of its own at its first need, where it took the cached view before, so where the guest took IMPORT_ADDRESSES the block's address, and the gpuAddress of the no-copy buffers over it, are the new import's rather than the released block's. A pages block's release is answered once its view is let go of. The views' summary line counts no pages views taken from the cache. What remaking the imports costs is measured apart: a view's import took 1.8 ms to make and 11.4 ms to free on an RTX 3090 (surface_pages.rs's module doc). Tests: on_vulkan_a_pin_in_a_released_pages_block_s_view_lies_outside_its_pages (red before: the released view's import was still known); a_pages_block_s_address_is_its_view_s_known_import_s_where_the_platform_knows_one now checks that the import is forgotten before the release's hold goes, and a_pages_block_made_again_over_the_same_runs_makes_a_view_of_its_own, an_unchanging_pages_block_s_view_is_asked_unchanging_each_block_its_own, a_read_only_pages_block_s_view_holds_no_import, the_views_debug_lines_name_a_view_s_runs_by_one_hash, a_pages_view_made_anew_logs_its_make_s_steps and a_cached_view_unheld_past_the_age_goes_and_one_taken_within_it_stays (now over surface views) replace the tests that held the cached pages views.
This commit is contained in:
1 parent
ace29e7471
commit
6c43e73eac
5 files changed
+394
-376
No files matched your search
@@ -2812,7 +2812,10 @@ impl<P: ApiPlatform> GraphicsControl<P> {
|
||||
/// the release, begun or not, to be committed, stood in for or failed, or its queue to end,
|
||||
/// and then for it to finish as above
|
||||
/// ([`GraphicsDecoder::drain_context_after_published`]); another block's does not wait for a
|
||||
/// command buffer posted on a ring and not yet begun.
|
||||
/// command buffer posted on a ring and not yet begun. Each waits too for the host to let go of
|
||||
/// the block's view: a pages block's goes with its import, which the platform that knows it
|
||||
/// as a block forgets, so no pin resolves in it once the kext gives the pages back
|
||||
/// ([`GraphicsDecoder::block_released_keeping`]).
|
||||
fn release_block(&self, release: &RgfxBlockRelease, answer: CompleteAnswer) {
|
||||
// Its waits' ends, for a slow answer's line (`slow_answers`).
|
||||
let marks = Arc::new(ReleaseMarks::asked());
|
||||
@@ -2880,10 +2883,14 @@ impl<P: ApiPlatform> GraphicsControl<P> {
|
||||
// waits for. The copy is made once the buffers still walked that may write the cache
|
||||
// have finished, on the last one's thread: the context's lane goes on.
|
||||
let held = Arc::clone(&drain);
|
||||
// And once its view is let go of: a pages block's goes with its import, which the
|
||||
// platform that knows it as a block forgets, so nothing of the host's names the pages
|
||||
// the kext unwires at the answer.
|
||||
let viewed = Box::new(Arc::clone(&drain));
|
||||
let (flags, offset) = (release.flags, release.offset);
|
||||
let m = Arc::clone(&marks);
|
||||
entry::run(|_| {
|
||||
decoder.block_released(
|
||||
decoder.block_released_keeping(
|
||||
&self.device,
|
||||
offset,
|
||||
flags,
|
||||
@@ -2899,6 +2906,7 @@ impl<P: ApiPlatform> GraphicsControl<P> {
|
||||
write back ({raise:?})"
|
||||
);
|
||||
}),
|
||||
viewed,
|
||||
);
|
||||
});
|
||||
marks.released();
|
||||
|
||||
@@ -2495,11 +2495,11 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
target: "reims_vgpu::graphics",
|
||||
"IOSurface pages in place: {} views made, {} taken from the cache, {} let go of \
|
||||
from it unheld for their mappings, {} unheld past their age; {} pages blocks' \
|
||||
views made, {} taken from the cache; {} named by their runs; refused: {} for \
|
||||
views made; {} named by their runs; refused: {} for \
|
||||
bad runs, {} not mapped, {} kept unviewed by the platform; asked whether they \
|
||||
need a device cache: {} in place, {} in place while the device's verdict was \
|
||||
pending, {} answered a cache, {} of them for want of room for their views",
|
||||
c.made, c.reused, c.idle_returned, c.aged, c.private, c.private_reused, c.by_runs,
|
||||
c.made, c.reused, c.idle_returned, c.aged, c.private, c.by_runs,
|
||||
c.bad_runs, c.not_mapped, c.unviewed, c.asked_in_place, c.asked_pending,
|
||||
c.asked_cache, c.asked_room
|
||||
);
|
||||
@@ -3341,7 +3341,7 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
}
|
||||
PagesInPlace::No(why) => {
|
||||
v.asked(surface_pages::Asked::Cache);
|
||||
let released = v.released(block, self.platform.vm());
|
||||
let released = v.released(block);
|
||||
// The cache the block's cached `SURFACE_PAGES` makes copies out the texels alone.
|
||||
v.laid_out(block, planes.to_vec());
|
||||
drop(v);
|
||||
@@ -3515,6 +3515,20 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
*self.shared.last_slow_copy.lock()
|
||||
}
|
||||
|
||||
/// [`Self::block_released_keeping`], with nothing kept until the block's view is let go of.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn block_released(
|
||||
&self,
|
||||
device: &P::Device,
|
||||
offset: u64,
|
||||
flags: u32,
|
||||
settled: impl FnOnce(),
|
||||
done: Box<dyn FnOnce() + Send>,
|
||||
failed: Box<dyn FnOnce(Raise) + Send>,
|
||||
) {
|
||||
self.block_released_keeping(device, offset, flags, settled, done, failed, Box::new(()));
|
||||
}
|
||||
|
||||
/// The block at `offset` was released, its `RGFX_BLOCK_RELEASE_*` `flags`: its surface view,
|
||||
/// if any, goes once the buffers over it have, and its device cache once the pages hold what
|
||||
/// a command buffer wrote of it, whether its surface had a client left or not
|
||||
@@ -3527,8 +3541,15 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
/// and its cache on the let-go worker, behind none of the surface worker's jobs: a burst of
|
||||
/// releases' caches, whose drops may take a while each, keeps no `SURFACE_PAGES` waiting for
|
||||
/// a thread. `settled` is told on this thread once the block's `SURFACE_PAGES` settled, for a
|
||||
/// slow answer's split (`slow_answers`).
|
||||
pub(crate) fn block_released(
|
||||
/// slow answer's split (`slow_answers`). `kept` is let go of once the block's hold of its view
|
||||
/// is: a pages block's view, never cached, goes then with its import, which the platform that
|
||||
/// knows it as a block forgets as it goes ([`surface_pages`], "Pages blocks"), so the release's
|
||||
/// answer, which the caller has `kept` hold, comes after it.
|
||||
#[expect(
|
||||
clippy::too_many_arguments,
|
||||
reason = "a release's parts, and what waits for its view"
|
||||
)]
|
||||
pub(crate) fn block_released_keeping(
|
||||
&self,
|
||||
device: &P::Device,
|
||||
offset: u64,
|
||||
@@ -3536,14 +3557,17 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
settled: impl FnOnce(),
|
||||
done: Box<dyn FnOnce() + Send>,
|
||||
failed: Box<dyn FnOnce(Raise) + Send>,
|
||||
kept: Box<dyn Send>,
|
||||
) {
|
||||
let asked = self.platform.clock().now_mono();
|
||||
self.settle_surface(offset);
|
||||
settled();
|
||||
let (ran, trace, done) = self.timed("BLOCK_RELEASE", offset, asked, done);
|
||||
let gone = (self.shared.surface_views.lock()).released(offset, self.platform.vm());
|
||||
if let Some(gone) = gone {
|
||||
self.shared.surface_worker.drop_later(offset, offset, gone);
|
||||
let gone = (self.shared.surface_views.lock()).released(offset);
|
||||
match gone {
|
||||
// The view first, then what waits for it.
|
||||
Some(gone) => (self.shared.surface_worker).drop_later(offset, offset, (gone, kept)),
|
||||
None => drop(kept),
|
||||
}
|
||||
// What the host's video devices made of the block's memory goes with its life.
|
||||
drop(self.shared.block_lives.lock().remove(&offset));
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -205,7 +205,7 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
/// ([`UNCACHED_COPIED`]). [`RGFX_STATUS_REFUSED`].
|
||||
pub(super) fn refuse_uncached(&self, device: &P::Device, block: u64) -> u32 {
|
||||
self.uncache_surface(device, block);
|
||||
let old = (self.shared.surface_views.lock()).released(block, self.platform.vm());
|
||||
let old = (self.shared.surface_views.lock()).released(block);
|
||||
drop(old);
|
||||
self.surface_caches
|
||||
.count_shapes(|c| c.uncached_refused += 1);
|
||||
|
||||
@@ -5535,7 +5535,15 @@ drops it. So a pages block's answer can come later than it would for a block
|
||||
of the region alone, by as long as the buffers its process had published and
|
||||
not yet begun take to be committed and to finish. No guest thread waits on the
|
||||
answer: the process's free returns at once, and the release worker posts and
|
||||
retires releases as their answers come. The kext posts an unshare out of its
|
||||
retires releases as their answers come. A pages block's answer also waits for
|
||||
the host to let go of the block's view and the view's import: the host keeps
|
||||
neither for a later block over the same pages, and the platform that knows the
|
||||
import as a block (metal2vulkan-runtime's) forgets it then. So after the answer
|
||||
the device holds no view of the block's pages that anything can reach: no pin
|
||||
resolves in its import, no buffer the host makes lies over the pages, and the
|
||||
command buffers that used them have finished; the platform frees the import,
|
||||
and the view's mapping with it, once its own last use of them is done. The
|
||||
kext posts an unshare out of its
|
||||
lock, so another holder's
|
||||
release can come first, and the host then takes the release as that holder's
|
||||
unshare too; the unshare that follows is not counted again. It also waits
|
||||
|
||||
Reference in new issue
Block a user