mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 02:13:24 +00:00
Refactor ostd::task::processor
based on faster CPU-local cells
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
05564ecd4f
commit
37a9590cfe
@ -26,7 +26,7 @@ pub(crate) use ostd::{
|
||||
#[macro_export]
|
||||
macro_rules! current {
|
||||
() => {
|
||||
$crate::process::current()
|
||||
$crate::process::Process::current().unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,7 @@ pub use credentials::{credentials, credentials_mut, Credentials, Gid, Uid};
|
||||
pub use exit::do_exit_group;
|
||||
pub use kill::{kill, kill_all, kill_group, tgkill};
|
||||
pub use process::{
|
||||
current, ExitCode, JobControl, Pgid, Pid, Process, ProcessBuilder, ProcessGroup, Session, Sid,
|
||||
Terminal,
|
||||
ExitCode, JobControl, Pgid, Pid, Process, ProcessBuilder, ProcessGroup, Session, Sid, Terminal,
|
||||
};
|
||||
pub use process_filter::ProcessFilter;
|
||||
pub use process_vm::{MAX_ARGV_NUMBER, MAX_ARG_LEN, MAX_ENVP_NUMBER, MAX_ENV_LEN};
|
||||
|
@ -103,6 +103,15 @@ pub struct Process {
|
||||
}
|
||||
|
||||
impl Process {
|
||||
/// Returns the current process.
|
||||
///
|
||||
/// It returns `None` if:
|
||||
/// - the function is called in the bootstrap context;
|
||||
/// - or if the current task is not associated with a process.
|
||||
pub fn current() -> Option<Arc<Process>> {
|
||||
Some(Thread::current()?.as_posix_thread()?.process())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new(
|
||||
pid: Pid,
|
||||
@ -636,15 +645,6 @@ impl Process {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn current() -> Arc<Process> {
|
||||
let current_thread = current_thread!();
|
||||
if let Some(posix_thread) = current_thread.as_posix_thread() {
|
||||
posix_thread.process()
|
||||
} else {
|
||||
panic!("[Internal error]The current thread does not belong to a process");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(ktest)]
|
||||
mod test {
|
||||
|
||||
|
@ -50,13 +50,12 @@ impl Thread {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the current thread, or `None` if the current task is not associated with a thread.
|
||||
/// Returns the current thread.
|
||||
///
|
||||
/// Except for unit tests, all tasks should be associated with threads. This method is useful
|
||||
/// when writing code that can be called directly by unit tests. If this isn't the case,
|
||||
/// consider using [`current_thread!`] instead.
|
||||
/// This function returns `None` if the current task is not associated with
|
||||
/// a thread, or if called within the bootstrap context.
|
||||
pub fn current() -> Option<Arc<Self>> {
|
||||
Task::current()
|
||||
Task::current()?
|
||||
.data()
|
||||
.downcast_ref::<Weak<Thread>>()?
|
||||
.upgrade()
|
||||
|
@ -5,7 +5,7 @@ use core::mem;
|
||||
use aster_rights::Full;
|
||||
use ostd::{
|
||||
mm::{KernelSpace, VmIo, VmReader, VmWriter},
|
||||
task::current_task,
|
||||
task::Task,
|
||||
};
|
||||
|
||||
use crate::{prelude::*, vm::vmar::Vmar};
|
||||
@ -34,14 +34,8 @@ pub fn read_bytes_from_user(src: Vaddr, dest: &mut VmWriter<'_>) -> Result<()> {
|
||||
check_vaddr(src)?;
|
||||
}
|
||||
|
||||
let current_task = current_task().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the current task is missing",
|
||||
))?;
|
||||
let user_space = current_task.user_space().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the user space is missing",
|
||||
))?;
|
||||
let current_task = Task::current().unwrap();
|
||||
let user_space = current_task.user_space().unwrap();
|
||||
|
||||
let mut user_reader = user_space.vm_space().reader(src, copy_len)?;
|
||||
user_reader.read_fallible(dest).map_err(|err| err.0)?;
|
||||
@ -54,14 +48,8 @@ pub fn read_val_from_user<T: Pod>(src: Vaddr) -> Result<T> {
|
||||
check_vaddr(src)?;
|
||||
}
|
||||
|
||||
let current_task = current_task().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the current task is missing",
|
||||
))?;
|
||||
let user_space = current_task.user_space().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the user space is missing",
|
||||
))?;
|
||||
let current_task = Task::current().unwrap();
|
||||
let user_space = current_task.user_space().unwrap();
|
||||
|
||||
let mut user_reader = user_space
|
||||
.vm_space()
|
||||
@ -88,14 +76,8 @@ pub fn write_bytes_to_user(dest: Vaddr, src: &mut VmReader<'_, KernelSpace>) ->
|
||||
check_vaddr(dest)?;
|
||||
}
|
||||
|
||||
let current_task = current_task().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the current task is missing",
|
||||
))?;
|
||||
let user_space = current_task.user_space().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the user space is missing",
|
||||
))?;
|
||||
let current_task = Task::current().unwrap();
|
||||
let user_space = current_task.user_space().unwrap();
|
||||
|
||||
let mut user_writer = user_space.vm_space().writer(dest, copy_len)?;
|
||||
user_writer.write_fallible(src).map_err(|err| err.0)?;
|
||||
@ -108,14 +90,8 @@ pub fn write_val_to_user<T: Pod>(dest: Vaddr, val: &T) -> Result<()> {
|
||||
check_vaddr(dest)?;
|
||||
}
|
||||
|
||||
let current_task = current_task().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the current task is missing",
|
||||
))?;
|
||||
let user_space = current_task.user_space().ok_or(Error::with_message(
|
||||
Errno::EFAULT,
|
||||
"the user space is missing",
|
||||
))?;
|
||||
let current_task = Task::current().unwrap();
|
||||
let user_space = current_task.user_space().unwrap();
|
||||
|
||||
let mut user_writer = user_space
|
||||
.vm_space()
|
||||
|
Reference in New Issue
Block a user