mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-08 21:06:48 +00:00
Reimplement scheduler with intrusive linked list
This commit is contained in:
parent
c172373b54
commit
3f8deaa28b
@ -18,6 +18,7 @@ uart_16550 = "0.2.0"
|
||||
pod = {path = "../pod"}
|
||||
pod-derive = {path = "../pod-derive"}
|
||||
acpi= "4.1.1"
|
||||
intrusive-collections = "0.9.5"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "1.0"
|
||||
|
@ -11,4 +11,4 @@ pub use self::scheduler::{set_scheduler, Scheduler};
|
||||
pub(crate) use self::task::context_switch;
|
||||
pub(crate) use self::task::TaskContext;
|
||||
pub(crate) use self::task::SWITCH_TO_USER_SPACE_TASK;
|
||||
pub use self::task::{Task, TaskStatus};
|
||||
pub use self::task::{Task, TaskStatus, TaskAdapter};
|
||||
|
@ -11,6 +11,9 @@ use crate::user::{syscall_switch_to_user_space, trap_switch_to_user_space, UserS
|
||||
use crate::vm::{VmAllocOptions, VmFrameVec};
|
||||
use crate::{prelude::*, UPSafeCell};
|
||||
|
||||
use intrusive_collections::intrusive_adapter;
|
||||
use intrusive_collections::LinkedListAtomicLink;
|
||||
|
||||
use super::processor::{current_task, schedule};
|
||||
|
||||
core::arch::global_asm!(include_str!("switch.S"));
|
||||
@ -66,6 +69,7 @@ lazy_static! {
|
||||
},
|
||||
exit_code: usize::MAX,
|
||||
kstack: KernelStack::new(),
|
||||
link: LinkedListAtomicLink::new(),
|
||||
};
|
||||
task.task_inner.exclusive_access().task_status = TaskStatus::Runnable;
|
||||
task.task_inner.exclusive_access().ctx.rip = context_switch_to_user_space as usize;
|
||||
@ -98,8 +102,12 @@ pub struct Task {
|
||||
exit_code: usize,
|
||||
/// kernel stack, note that the top is SyscallFrame/TrapFrame
|
||||
kstack: KernelStack,
|
||||
link: LinkedListAtomicLink,
|
||||
}
|
||||
|
||||
// TaskAdapter struct is implemented for building relationships between doubly linked list and Task struct
|
||||
intrusive_adapter!(pub TaskAdapter = Arc<Task>: Task { link: LinkedListAtomicLink });
|
||||
|
||||
pub(crate) struct TaskInner {
|
||||
pub task_status: TaskStatus,
|
||||
pub ctx: TaskContext,
|
||||
@ -166,6 +174,7 @@ impl Task {
|
||||
},
|
||||
exit_code: 0,
|
||||
kstack: KernelStack::new(),
|
||||
link: LinkedListAtomicLink::new(),
|
||||
};
|
||||
|
||||
result.task_inner.exclusive_access().task_status = TaskStatus::Runnable;
|
||||
@ -210,6 +219,7 @@ impl Task {
|
||||
},
|
||||
exit_code: 0,
|
||||
kstack: KernelStack::new(),
|
||||
link: LinkedListAtomicLink::new(),
|
||||
};
|
||||
|
||||
result.task_inner.exclusive_access().task_status = TaskStatus::Runnable;
|
||||
|
@ -17,6 +17,7 @@ jinux-rights-proc = {path="../jinux-rights-proc"}
|
||||
jinux-util = {path="../jinux-util"}
|
||||
virtio-input-decoder = "0.1.4"
|
||||
ascii = { version = "1.1", default-features = false, features = ["alloc"] }
|
||||
intrusive-collections = "0.9.5"
|
||||
|
||||
# parse elf file
|
||||
xmas-elf = "0.8.0"
|
||||
|
@ -1,16 +1,16 @@
|
||||
use crate::prelude::*;
|
||||
use jinux_frame::task::{set_scheduler, Scheduler, Task};
|
||||
use jinux_frame::task::{set_scheduler, Scheduler, Task, TaskAdapter};
|
||||
|
||||
pub const TASK_INIT_CAPABILITY: usize = 16;
|
||||
use intrusive_collections::LinkedList;
|
||||
|
||||
pub struct FifoScheduler {
|
||||
tasks: Mutex<VecDeque<Arc<Task>>>,
|
||||
tasks: Mutex<LinkedList<TaskAdapter>>,
|
||||
}
|
||||
|
||||
impl FifoScheduler {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tasks: Mutex::new(VecDeque::with_capacity(TASK_INIT_CAPABILITY)),
|
||||
tasks: Mutex::new(LinkedList::new(TaskAdapter::new())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user