Skip to content

Commit

Permalink
[refactor] move migration_entry into run_queue.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Nov 22, 2024
1 parent 252800a commit 790cb35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 1 addition & 9 deletions modules/axtask/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn set_current_affinity(cpumask: AxCpuMask) -> bool {
const MIGRATION_TASK_STACK_SIZE: usize = 4096;
// Spawn a new migration task for migrating.
let migration_task = TaskInner::new(
move || migrate_entry(curr.clone()),
move || crate::run_queue::migrate_entry(curr),
"migration-task".into(),
MIGRATION_TASK_STACK_SIZE,
)
Expand Down Expand Up @@ -215,11 +215,3 @@ pub fn run_idle() -> ! {
axhal::arch::wait_for_irqs();
}
}

/// The task routine for migrating the current task to the correct CPU.
///
/// It calls `select_run_queue` to get the correct run queue for the task, and
/// then puts the task to the run queue.
fn migrate_entry(migrated_task: AxTaskRef) {
select_run_queue::<NoPreemptIrqSave>(&migrated_task).put_prev_task(migrated_task);
}
19 changes: 13 additions & 6 deletions modules/axtask/src/run_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ impl<'a, G: BaseGuard> AxRunQueueRef<'a, G> {
self.inner.scheduler.lock().add_task(task);
}

/// Puts the previous task back to the scheduler if the run queue.
pub fn put_prev_task(&mut self, task: AxTaskRef) {
assert!(task.is_ready());
self.inner.scheduler.lock().put_prev_task(task, false);
}

/// Unblock one task by inserting it into the run queue.
///
/// This function does nothing if the task is not in [`TaskState::Blocked`],
Expand Down Expand Up @@ -602,6 +596,19 @@ fn gc_entry() {
}
}

/// The task routine for migrating the current task to the correct CPU.
///
/// It calls `select_run_queue` to get the correct run queue for the task, and
/// then puts the task to the scheduler of target run queue.
#[cfg(feature = "smp")]
pub(crate) fn migrate_entry(migrated_task: AxTaskRef) {
select_run_queue::<kernel_guard::NoPreemptIrqSave>(&migrated_task)
.inner
.scheduler
.lock()
.put_prev_task(migrated_task, false)
}

/// Clear the `on_cpu` field of previous task running on this CPU.
#[cfg(feature = "smp")]
pub(crate) unsafe fn clear_prev_task_on_cpu() {
Expand Down

0 comments on commit 790cb35

Please sign in to comment.