pub struct TaskInner {
pub page_table_token: UnsafeCell<usize>,
pub cpu_set: AtomicU64,
pub send_sigchld_when_exit: bool,
pub sched_status: UnsafeCell<SchedStatus>,
pub is_vforked_child: AtomicBool,
/* private fields */
}
multitask
only.Expand description
The inner task structure used as the minimal unit of scheduling.
Fields§
§page_table_token: UnsafeCell<usize>
monolithic
only.the page table token of the process which the task belongs to
cpu_set: AtomicU64
monolithic
only.TODO: to support the sched_setaffinity
TODO: move to the upper layer
send_sigchld_when_exit: bool
monolithic
only.退出时是否向父进程发送SIG_CHILD
sched_status: UnsafeCell<SchedStatus>
monolithic
only.The scheduler status of the task, which defines the scheduling policy and priority
is_vforked_child: AtomicBool
monolithic
only.Whether the task is a thread which is vforked by another task
Implementations§
source§impl TaskInner
impl TaskInner
sourcepub fn get_kernel_stack_top(&self) -> Option<usize>
pub fn get_kernel_stack_top(&self) -> Option<usize>
获取内核栈栈顶
source§impl TaskInner
impl TaskInner
Methods for time statistics
sourcepub fn time_stat_from_user_to_kernel(&self, current_tick: usize)
pub fn time_stat_from_user_to_kernel(&self, current_tick: usize)
update the time information when the task is switched from user mode to kernel mode
sourcepub fn time_stat_from_kernel_to_user(&self, current_tick: usize)
pub fn time_stat_from_kernel_to_user(&self, current_tick: usize)
update the time information when the task is switched from kernel mode to user mode
sourcepub fn time_stat_when_switch_from(&self, current_tick: usize)
pub fn time_stat_when_switch_from(&self, current_tick: usize)
update the time information when the task is switched out
sourcepub fn time_stat_when_switch_to(&self, current_tick: usize)
pub fn time_stat_when_switch_to(&self, current_tick: usize)
update the time information when the task is ready to be switched in
sourcepub fn time_stat_output(&self) -> (usize, usize)
pub fn time_stat_output(&self) -> (usize, usize)
output the time statistics
The format is (user time, kernel time) in nanoseconds
sourcepub fn timer_output(&self) -> (usize, usize)
pub fn timer_output(&self) -> (usize, usize)
输出计时器信息 (计时器周期,当前计时器剩余时间) 单位为us
sourcepub fn set_timer(
&self,
timer_interval_ns: usize,
timer_remained_ns: usize,
timer_type: usize
) -> bool
pub fn set_timer( &self, timer_interval_ns: usize, timer_remained_ns: usize, timer_type: usize ) -> bool
设置计时器信息
若type不为None则返回成功
sourcepub fn time_stat_reset(&self, current_tick: usize)
pub fn time_stat_reset(&self, current_tick: usize)
重置统计时间
source§impl TaskInner
impl TaskInner
sourcepub fn set_child_tid(&self, tid: usize)
Available on crate feature monolithic
only.
pub fn set_child_tid(&self, tid: usize)
monolithic
only.store the child thread ID at the location pointed to by child_tid in clone args
sourcepub fn set_clear_child_tid(&self, tid: usize)
Available on crate feature monolithic
only.
pub fn set_clear_child_tid(&self, tid: usize)
monolithic
only.clear (zero) the child thread ID at the location pointed to by child_tid in clone args
sourcepub fn get_clear_child_tid(&self) -> usize
Available on crate feature monolithic
only.
pub fn get_clear_child_tid(&self) -> usize
monolithic
only.get the pointer to the child thread ID
sourcepub fn get_page_table_token(&self) -> usize
Available on crate feature monolithic
only.
pub fn get_page_table_token(&self) -> usize
monolithic
only.get the page table token of the process which the task belongs to
sourcepub fn set_page_table_token(&self, token: usize)
Available on crate feature monolithic
only.
pub fn set_page_table_token(&self, token: usize)
monolithic
only.force to set the page table token of the process UNSAFELY
sourcepub fn get_process_id(&self) -> u64
Available on crate feature monolithic
only.
pub fn get_process_id(&self) -> u64
monolithic
only.get the process ID of the task
sourcepub fn set_process_id(&self, process_id: u64)
Available on crate feature monolithic
only.
pub fn set_process_id(&self, process_id: u64)
monolithic
only.set the process ID of the task
sourcepub fn set_leader(&self, is_lead: bool)
Available on crate feature monolithic
only.
pub fn set_leader(&self, is_lead: bool)
monolithic
only.set the flag whether the task is the main thread of the process
sourcepub fn is_leader(&self) -> bool
Available on crate feature monolithic
only.
pub fn is_leader(&self) -> bool
monolithic
only.whether the task is the main thread of the process
sourcepub fn set_cpu_set(&self, mask: usize, set_size: usize, max_cpu_num: usize)
Available on crate feature monolithic
only.
pub fn set_cpu_set(&self, mask: usize, set_size: usize, max_cpu_num: usize)
monolithic
only.设置CPU set,其中set_size为bytes长度
sourcepub fn get_cpu_set(&self) -> usize
Available on crate feature monolithic
only.
pub fn get_cpu_set(&self) -> usize
monolithic
only.to get the CPU set
sourcepub fn set_sched_status(&self, status: SchedStatus)
Available on crate feature monolithic
only.
pub fn set_sched_status(&self, status: SchedStatus)
monolithic
only.set the scheduling policy and priority
sourcepub fn get_sched_status(&self) -> SchedStatus
Available on crate feature monolithic
only.
pub fn get_sched_status(&self) -> SchedStatus
monolithic
only.get the scheduling policy and priority
sourcepub fn get_ctx(&self) -> &TaskContext
Available on crate feature monolithic
only.
pub fn get_ctx(&self) -> &TaskContext
monolithic
only.get the task context for task switch
sourcepub fn get_sig_child(&self) -> bool
Available on crate feature monolithic
only.
pub fn get_sig_child(&self) -> bool
monolithic
only.whether to send SIG_CHILD when the task exits
sourcepub fn set_sig_child(&mut self, sig_child: bool)
Available on crate feature monolithic
only.
pub fn set_sig_child(&mut self, sig_child: bool)
monolithic
only.set whether to send SIG_CHILD when the task exits
sourcepub unsafe fn set_tls_force(&self, value: usize)
Available on crate feature monolithic
and x86-64 only.
pub unsafe fn set_tls_force(&self, value: usize)
monolithic
and x86-64 only.Safety
It is unsafe because it may cause undefined behavior if the fs_base
is not a valid address.
sourcepub fn set_vfork_child(&self, is_vfork_child: bool)
Available on crate feature monolithic
only.
pub fn set_vfork_child(&self, is_vfork_child: bool)
monolithic
only.To set whether the task will be blocked by a vfork child
sourcepub fn is_vfork_child(&self) -> bool
Available on crate feature monolithic
only.
pub fn is_vfork_child(&self) -> bool
monolithic
only.获取父进程blocked_by_vfork布尔值
source§impl TaskInner
impl TaskInner
sourcepub fn new_init(name: String, tls_area: (usize, usize)) -> TaskInner
pub fn new_init(name: String, tls_area: (usize, usize)) -> TaskInner
Creates an “init task” using the current CPU states, to use as the current task.
As it is the current task, no other task can switch to it until it switches out.
And there is no need to set the entry
, kstack
or tls
fields, as
they will be filled automatically when the task is switches out.
sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the task is running
sourcepub fn is_blocked(&self) -> bool
pub fn is_blocked(&self) -> bool
Whether the task is blocked
sourcepub fn set_preempt_pending(&self, pending: bool)
Available on crate feature preempt
only.
pub fn set_preempt_pending(&self, pending: bool)
preempt
only.Set the task waiting for reschedule
sourcepub fn get_preempt_pending(&self) -> bool
Available on crate feature preempt
only.
pub fn get_preempt_pending(&self) -> bool
preempt
only.Get whether the task is waiting for reschedule
sourcepub fn can_preempt(&self, current_disable_count: usize) -> bool
Available on crate feature preempt
only.
pub fn can_preempt(&self, current_disable_count: usize) -> bool
preempt
only.Whether the task can be preempted
sourcepub fn disable_preempt(&self)
Available on crate feature preempt
only.
pub fn disable_preempt(&self)
preempt
only.Disable the preemption
sourcepub fn enable_preempt(&self)
Available on crate feature preempt
only.
pub fn enable_preempt(&self)
preempt
only.Enable the preemption by increasing the disable count
Only when the count is zero, the task can be preempted
sourcepub fn preempt_num(&self) -> usize
Available on crate feature preempt
only.
pub fn preempt_num(&self) -> usize
preempt
only.Get the number of preempt disable counter
sourcepub const unsafe fn ctx_mut_ptr(&self) -> *mut TaskContext
pub const unsafe fn ctx_mut_ptr(&self) -> *mut TaskContext
Get the task context pointer
Safety
The task context pointer is mutable, but it will be accessed by only one task at a time
sourcepub fn get_exit_code(&self) -> i32
pub fn get_exit_code(&self) -> i32
Get the exit code
sourcepub fn set_exit_code(&self, code: i32)
pub fn set_exit_code(&self, code: i32)
Set the task exit code
sourcepub fn get_tls_ptr(&self) -> usize
Available on crate feature tls
only.
pub fn get_tls_ptr(&self) -> usize
tls
only.Get the task tls pointer
sourcepub fn reset_time_stat(&self, current_timestamp: usize)
pub fn reset_time_stat(&self, current_timestamp: usize)
Reset the task time statistics
sourcepub fn check_pending_signal(&self) -> Option<usize>
pub fn check_pending_signal(&self) -> Option<usize>
Check whether the timer triggered
If the timer has triggered, then reset it and return the signal number