Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/xcl/src/hle/dstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,6 @@ fn note_request(r: &Request) {
// the first requests: where a title's data goes and how it is packed
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
let k = N.fetch_add(1, Ordering::Relaxed);
REQUESTS.fetch_add(1, Ordering::Relaxed);
BYTES.fetch_add(n as u64, Ordering::Relaxed);
if k < 16 || k.is_power_of_two() {
crate::xlog_info!(
"DirectStorage: request #{k}: options {:#x} ({} source{}), destination {:#x}{} ({n} bytes, page offset {}), source size {}, intermediate {}",
Expand All @@ -869,13 +867,21 @@ fn note_request(r: &Request) {
}
}

/// Called when a request completes successfully to record its bytes.
fn note_request_success(n: usize) {
REQUESTS.fetch_add(1, Ordering::Relaxed);
BYTES.fetch_add(n as u64, Ordering::Relaxed);
}

/// Run a request; the destination gets the bytes or nothing.
unsafe fn execute(r: &Request, file: Option<&FileInner>, dest_pages: Option<&[usize]>, src_pages: Option<&[usize]>) -> Result<(), HRESULT> {
let n = r.destination_size as usize;
note_request(r);
if !r.dest_physical_pages() && !writable(r.destination as usize, n) {
return Err(E_ACCESS_VIOLATION);
}
// Requests that fail after this point will have their bytes/reqs counted in note_request_success
// only on successful completion
let src: Vec<u8> = if r.memory_source() {
let mut b = vec![0u8; r.source_size as usize];
if r.source_physical_pages() {
Expand Down Expand Up @@ -953,6 +959,8 @@ unsafe fn execute(r: &Request, file: Option<&FileInner>, dest_pages: Option<&[us
} else if n > 0 {
std::ptr::copy_nonoverlapping(payload.as_ptr(), r.destination as *mut u8, n);
}
// Record successful request only after all data has been written
note_request_success(n);
Ok(())
}

Expand Down
13 changes: 9 additions & 4 deletions crates/xcl/src/hle/dstorage/parallel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Bounded preparation of file-backed zlib requests. The queue thread owns
//! file reads, cancellation checks, and retirement; decoders own private buffers.

use super::{note_request, read_exact_at, writable, Entry, FileInner, QueueInner, Request, E_ABORT, E_ACCESS_VIOLATION, E_FILE_HANDLE, E_ZLIB_DATA};
use super::{note_request, note_request_success, read_exact_at, writable, Entry, FileInner, QueueInner, Request, E_ABORT, E_ACCESS_VIOLATION, E_FILE_HANDLE, E_ZLIB_DATA};
use crate::util::{HRESULT, S_OK};
use std::collections::{HashMap, VecDeque};
use std::ffi::c_void;
Expand Down Expand Up @@ -463,13 +463,18 @@ impl<'a> Pipeline<'a> {
// The title can unmap the destination while a decoder runs. The late
// check resolves lazy pages, and the kernel copy handles a subsequent unmap.
if writable(at, n) && (n == 0 || write_destination(at, &payload.bytes[..n])) {
Ok(())
Ok(n)
} else {
Err(E_ACCESS_VIOLATION)
}
});
if let Err(hr) = result {
self.queue.update_error(hr, task.req, task.file.as_deref(), since_status);
match result {
Ok(n) => {
note_request_success(n);
}
Err(hr) => {
self.queue.update_error(hr, task.req, task.file.as_deref(), since_status);
}
}
#[cfg(test)]
notify_test(self.queue, TestEvent::Retired(task.seq));
Expand Down
Loading