Struct taskctx::TaskInner

source ·
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 */
}
Expand description

The inner task structure used as the minimal unit of scheduling.

Fields§

§page_table_token: UnsafeCell<usize>

the page table token of the process which the task belongs to

§cpu_set: AtomicU64

TODO: to support the sched_setaffinity

TODO: move to the upper layer

§send_sigchld_when_exit: bool

退出时是否向父进程发送SIG_CHILD

§sched_status: UnsafeCell<SchedStatus>

The scheduler status of the task, which defines the scheduling policy and priority

§is_vforked_child: AtomicBool

Whether the task is a thread which is vforked by another task

Implementations§

source§

impl TaskInner

source

pub const fn id(&self) -> TaskId

Gets the ID of the task.

source

pub fn name(&self) -> &str

Gets the name of the task.

source

pub fn set_name(&self, name: &str)

Sets the name of the task.

source

pub fn id_name(&self) -> String

Get a combined string of the task ID and name.

source

pub fn get_kernel_stack_top(&self) -> Option<usize>

获取内核栈栈顶

source

pub fn new<F>( entry: F, name: String, stack_size: usize, process_id: u64, page_table_token: usize, sig_child: bool, tls_area: (usize, usize) ) -> TaskInner
where F: FnOnce() + Send + 'static,

Create a new task with the given entry function and stack size.

source

pub fn init_task_ctx( &mut self, entry: usize, kstack_top: VirtAddr, tls: VirtAddr )

To init the task context

Arguments
  • entry - the entry point of the task

  • kstack_top - the top of the kernel stack

  • tls - the address of the thread local storage

source§

impl TaskInner

Methods for time statistics

source

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

source

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

source

pub fn time_stat_when_switch_from(&self, current_tick: usize)

update the time information when the task is switched out

source

pub fn time_stat_when_switch_to(&self, current_tick: usize)

update the time information when the task is ready to be switched in

source

pub fn time_stat_output(&self) -> (usize, usize)

output the time statistics

The format is (user time, kernel time) in nanoseconds

source

pub fn timer_output(&self) -> (usize, usize)

输出计时器信息 (计时器周期,当前计时器剩余时间) 单位为us

source

pub fn set_timer( &self, timer_interval_ns: usize, timer_remained_ns: usize, timer_type: usize ) -> bool

设置计时器信息

若type不为None则返回成功

source

pub fn time_stat_reset(&self, current_tick: usize)

重置统计时间

source§

impl TaskInner

source

pub fn set_child_tid(&self, tid: usize)

store the child thread ID at the location pointed to by child_tid in clone args

source

pub fn set_clear_child_tid(&self, tid: usize)

clear (zero) the child thread ID at the location pointed to by child_tid in clone args

source

pub fn get_clear_child_tid(&self) -> usize

get the pointer to the child thread ID

source

pub fn get_page_table_token(&self) -> usize

get the page table token of the process which the task belongs to

source

pub fn set_page_table_token(&self, token: usize)

force to set the page table token of the process UNSAFELY

source

pub fn get_process_id(&self) -> u64

get the process ID of the task

source

pub fn set_process_id(&self, process_id: u64)

set the process ID of the task

source

pub fn set_leader(&self, is_lead: bool)

set the flag whether the task is the main thread of the process

source

pub fn is_leader(&self) -> bool

whether the task is the main thread of the process

source

pub fn set_cpu_set(&self, mask: usize, set_size: usize, max_cpu_num: usize)

设置CPU set,其中set_size为bytes长度

source

pub fn get_cpu_set(&self) -> usize

to get the CPU set

source

pub fn set_sched_status(&self, status: SchedStatus)

set the scheduling policy and priority

source

pub fn get_sched_status(&self) -> SchedStatus

get the scheduling policy and priority

source

pub fn get_ctx(&self) -> &TaskContext

get the task context for task switch

source

pub fn get_sig_child(&self) -> bool

whether to send SIG_CHILD when the task exits

source

pub fn set_sig_child(&mut self, sig_child: bool)

set whether to send SIG_CHILD when the task exits

source

pub unsafe fn set_tls_force(&self, value: usize)

Safety

It is unsafe because it may cause undefined behavior if the fs_base is not a valid address.

source

pub fn set_vfork_child(&self, is_vfork_child: bool)

To set whether the task will be blocked by a vfork child

source

pub fn is_vfork_child(&self) -> bool

获取父进程blocked_by_vfork布尔值

source§

impl TaskInner

source

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.

source

pub fn state(&self) -> TaskState

the state of the task

source

pub fn set_state(&self, state: TaskState)

set the state of the task

source

pub fn is_running(&self) -> bool

Whether the task is running

source

pub fn is_ready(&self) -> bool

Whether the task is ready to be scheduled

source

pub fn is_blocked(&self) -> bool

Whether the task is blocked

source

pub const fn is_init(&self) -> bool

Whether the task has been inited

source

pub const fn is_idle(&self) -> bool

Whether the task is the idle task

source

pub fn set_preempt_pending(&self, pending: bool)

Set the task waiting for reschedule

source

pub fn get_preempt_pending(&self) -> bool

Get whether the task is waiting for reschedule

source

pub fn can_preempt(&self, current_disable_count: usize) -> bool

Whether the task can be preempted

source

pub fn disable_preempt(&self)

Disable the preemption

source

pub fn enable_preempt(&self)

Enable the preemption by increasing the disable count

Only when the count is zero, the task can be preempted

source

pub fn preempt_num(&self) -> usize

Get the number of preempt disable counter

source

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

source

pub fn get_exit_code(&self) -> i32

Get the exit code

source

pub fn set_exit_code(&self, code: i32)

Set the task exit code

source

pub fn get_entry(&self) -> Option<*mut dyn FnOnce()>

Get the task entry

source

pub fn get_tls_ptr(&self) -> usize

Get the task tls pointer

source

pub fn reset_time_stat(&self, current_timestamp: usize)

Reset the task time statistics

source

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

Trait Implementations§

source§

impl Debug for TaskInner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for TaskInner

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for TaskInner

source§

impl Sync for TaskInner

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.