Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default = []

multitask = [
"dep:percpu", "dep:spinlock", "dep:lazy_init", "dep:memory_addr",
"dep:scheduler", "dep:timer_list", "kernel_guard","taskctx/multitask"
"dep:scheduler", "dep:timer_list", "kernel_guard","taskctx/multitask","dep:cpumask"
]
irq = []
tls = ["axhal/tls", "taskctx/tls"]
Expand Down Expand Up @@ -47,6 +47,7 @@ taskctx = { git = "https://github.com/Starry-OS/taskctx.git" }
axlog = { git = "https://github.com/Starry-OS/axlog.git" }
linked_list = { git = "https://github.com/Starry-OS/linked_list.git" }
axbacktrace = { git = "https://github.com/kern-crates/axbacktrace.git" }
cpumask = { git = "https://github.com/arceos-org/cpumask.git", optional = true }

[dev-dependencies]
rand = "0.8"
Expand Down
37 changes: 17 additions & 20 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
use alloc::{string::String, sync::Arc};
#[cfg(feature = "monolithic")]
use axhal::KERNEL_PROCESS_ID;

use kernel_guard::NoPreemptIrqSave;
use crate::task::{ScheduleTask, TaskState};

use crate::schedule::get_wait_for_exit_queue;
use crate::processor::select_processor;
use crate::processor::get_wait_for_exit_queue;
#[doc(cfg(feature = "multitask"))]
pub use crate::task::{new_task, CurrentTask, TaskId};
#[doc(cfg(feature = "multitask"))]
pub use crate::wait_queue::WaitQueue;

pub use crate::processor::{current_processor, Processor};

pub use crate::schedule::schedule;

#[cfg(feature = "irq")]
pub use crate::schedule::schedule_timeout;
pub use crate::processor::current_processor;

/// The reference type of a task.
pub type AxTaskRef = Arc<AxTask>;
Expand Down Expand Up @@ -75,7 +70,7 @@ pub fn init_scheduler_secondary() {
#[doc(cfg(feature = "irq"))]
pub fn on_timer_tick() {
crate::timers::check_events();
crate::schedule::scheduler_timer_tick();
current_processor::<NoPreemptIrqSave>().scheduler_timer_tick();
}

#[cfg(feature = "preempt")]
Expand All @@ -84,16 +79,15 @@ pub fn on_timer_tick() {
/// disable_preempt ctx
pub fn current_check_preempt_pending() {
let curr = crate::current();
// if task is already exited or blocking,
// no need preempt, they are rescheduling
if curr.get_preempt_pending() && curr.can_preempt() && !curr.is_exited() && !curr.is_blocking()

if curr.get_preempt_pending() && curr.can_preempt() && !curr.is_blocked()
{
debug!(
"current {} is to be preempted , allow {}",
curr.id_name(),
curr.can_preempt()
);
crate::schedule::schedule()
current_processor::<NoPreemptIrqSave>().reschedule();
}
}

Expand All @@ -113,7 +107,7 @@ where
#[cfg(feature = "monolithic")]
0,
);
Processor::first_add_task(task.clone());
select_processor::<NoPreemptIrqSave>(&task).add_task(task.clone());
task
}

Expand All @@ -140,13 +134,13 @@ where
///
/// [CFS]: https://en.wikipedia.org/wiki/Completely_Fair_Scheduler
pub fn set_priority(prio: isize) -> bool {
crate::schedule::set_current_priority(prio)
current_processor::<NoPreemptIrqSave>().set_current_priority(prio)
}

/// Current task gives up the CPU time voluntarily, and switches to another
/// ready task.
pub fn yield_now() {
crate::schedule::yield_current();
current_processor::<NoPreemptIrqSave>().yield_current();
}

/// Current task is going to sleep for the given duration.
Expand All @@ -161,13 +155,13 @@ pub fn sleep(dur: core::time::Duration) {
/// If the feature `irq` is not enabled, it uses busy-wait instead.
pub fn sleep_until(deadline: axhal::time::TimeValue) {
#[cfg(feature = "irq")]
crate::schedule::schedule_timeout(deadline);
current_processor::<NoPreemptIrqSave>().schedule_timeout(deadline);
#[cfg(not(feature = "irq"))]
axhal::time::busy_wait_until(deadline);
}
/// wake up task
pub fn wakeup_task(task: AxTaskRef) {
crate::schedule::wakeup_task(task)
current_processor::<NoPreemptIrqSave>().wakeup_task(task);
}

/// Current task is going to sleep, it will be woken up when the given task exits.
Expand Down Expand Up @@ -198,9 +192,12 @@ pub fn wake_vfork_process(task: &AxTaskRef) {

/// Exits the current task.
pub fn exit(exit_code: i32) -> ! {
crate::schedule::exit_current(exit_code)
current_processor::<NoPreemptIrqSave>().exit_current(exit_code);
}

/// The wrapper type for cpumask::CpuMask with SMP configuration.
pub type CpuMask = cpumask::CpuMask<{ axconfig::SMP }>;

/// The idle task routine.
///
/// It runs an infinite loop that keeps calling [`yield_now()`].
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ cfg_if::cfg_if! {
mod processor;
mod task;

mod schedule;
mod api;
mod wait_list;
mod wait_queue;
Expand Down
Loading