diff --git a/userspace/playwav/src/main.rs b/userspace/playwav/src/main.rs index 46c8436f..c900495e 100644 --- a/userspace/playwav/src/main.rs +++ b/userspace/playwav/src/main.rs @@ -33,6 +33,13 @@ fn play(song: &str) -> Result<(), ExitCode> { ) .map_err(|_e| ExitCode::from(4))?; + for addr in (wav_map..wav_map + wav_size).step_by(4096) { + let _ = unsafe { + // prefault to read the file into memory + (addr as *const u64).read_volatile() + }; + } + //println!("file size: {}", wav_size); let get_current_hda_block = @@ -52,7 +59,10 @@ fn play(song: &str) -> Result<(), ExitCode> { let chunk = std::cmp::min(rem, 2048); - while ((get_current_hda_block() + 3) % buf_block_count) != wp_block {} + while ((get_current_hda_block() + 3) % buf_block_count) != wp_block { + // yield cpu for other tasks + let _ = syscall_user::yield_execution(); + } hda_data[wp_block * 2048..wp_block * 2048 + chunk] .copy_from_slice(&wav_data[file_block * 2048..file_block * 2048 + chunk]); @@ -61,7 +71,10 @@ fn play(song: &str) -> Result<(), ExitCode> { file_block += 1; } - while get_current_hda_block() != wp_block {} + while get_current_hda_block() != wp_block { + // yield cpu for other tasks + let _ = syscall_user::yield_execution(); + } hda_data.fill(0); //silence diff --git a/userspace/shell/src/nc.rs b/userspace/shell/src/nc.rs index 06217907..b9f0b188 100644 --- a/userspace/shell/src/nc.rs +++ b/userspace/shell/src/nc.rs @@ -56,7 +56,7 @@ fn recv(fd: usize) -> bool { fn start(fd: usize) { unsafe { - SENT = 0; + (&raw mut SENT).write(0); } let mut read_fds: FdSet = FdSet::new(); diff --git a/userspace/syscall-user/src/lib.rs b/userspace/syscall-user/src/lib.rs index 654846f0..781c232d 100644 --- a/userspace/syscall-user/src/lib.rs +++ b/userspace/syscall-user/src/lib.rs @@ -482,6 +482,10 @@ pub fn ioctl(fd: usize, cmd: usize, arg: usize) -> SyscallResult { unsafe { syscall3(SYS_IOCTL, fd, cmd, arg) } } +pub fn yield_execution() -> SyscallResult { + unsafe { syscall0(SYS_YIELD) } +} + pub fn sigaction( sig: usize, mut sigaction: Option<&mut syscall_defs::signal::SigAction>,