Skip to content

Commit ab70fb3

Browse files
sched: handle pending io
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent b5c3762 commit ab70fb3

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/aero_kernel/src/userland/scheduler/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ impl Scheduler {
130130
pub fn log_ptable(&self) {
131131
self.tasks.0.lock().iter().for_each(|(pid, task)| {
132132
log::info!(
133-
"task(pid={pid:?}, path={:?})",
134-
task.path().unwrap_or(String::from("<unknown>"))
133+
"task(pid={pid:?}, path={:?}, state={:?})",
134+
task.path().unwrap_or(String::from("<unknown>")),
135+
task.state()
135136
)
136137
});
137138
}

src/aero_kernel/src/userland/scheduler/round_robin.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ impl SchedulerInterface for RoundRobin {
213213
if let Some(task) = cursor.remove() {
214214
queue.push_runnable(task);
215215
}
216+
} else {
217+
task.set_pending_io(true)
216218
}
217219
}
218220

@@ -226,7 +228,10 @@ impl SchedulerInterface for RoundRobin {
226228
.expect("IDLE task should not await for anything")
227229
.clone();
228230

229-
// TODO: Make sure the task has no pending IO.
231+
if task.has_pending_io() {
232+
task.set_pending_io(false);
233+
return Ok(());
234+
}
230235

231236
if let Some(duration) = duration {
232237
queue.push_deadline_awaiting(task, duration);

src/aero_kernel/src/userland/task.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use alloc::sync::{Arc, Weak};
2323
use spin::RwLock;
2424

2525
use core::cell::UnsafeCell;
26-
use core::sync::atomic::{AtomicIsize, AtomicU8, AtomicUsize, Ordering};
26+
use core::sync::atomic::{AtomicBool, AtomicIsize, AtomicU8, AtomicUsize, Ordering};
2727

2828
use crate::fs::cache::{DirCacheImpl, DirCacheItem};
2929
use crate::fs::{self, FileSystem};
@@ -186,6 +186,7 @@ pub struct Task {
186186
signals: Signals,
187187

188188
executable: Mutex<Option<DirCacheItem>>,
189+
pending_io: AtomicBool,
189190

190191
pub(super) link: intrusive_collections::LinkedListLink,
191192
pub(super) clink: intrusive_collections::LinkedListLink,
@@ -227,6 +228,8 @@ impl Task {
227228
link: Default::default(),
228229
clink: Default::default(),
229230

231+
pending_io: AtomicBool::new(false),
232+
230233
sleep_duration: AtomicUsize::new(0),
231234
exit_status: AtomicIsize::new(0),
232235

@@ -265,6 +268,7 @@ impl Task {
265268
exit_status: AtomicIsize::new(0),
266269

267270
executable: Mutex::new(None),
271+
pending_io: AtomicBool::new(false),
268272

269273
children: Mutex::new(Default::default()),
270274
parent: Mutex::new(None),
@@ -297,6 +301,7 @@ impl Task {
297301
pid,
298302

299303
executable: Mutex::new(self.executable.lock().clone()),
304+
pending_io: AtomicBool::new(false),
300305

301306
children: Mutex::new(Default::default()),
302307
parent: Mutex::new(None),
@@ -313,6 +318,14 @@ impl Task {
313318
this
314319
}
315320

321+
pub fn has_pending_io(&self) -> bool {
322+
self.pending_io.load(Ordering::SeqCst)
323+
}
324+
325+
pub fn set_pending_io(&self, yes: bool) {
326+
self.pending_io.store(yes, Ordering::SeqCst)
327+
}
328+
316329
pub fn signals(&self) -> &Signals {
317330
&self.signals
318331
}
@@ -379,17 +392,18 @@ impl Task {
379392
if pid == -1 {
380393
// wait for any child process if no specific process is requested.
381394
//
382-
// NOTE: we collect all of the zombie list's process IDs instead of the children
383-
// list since the child could have been removed from the children list and become a zombie
384-
// before the parent had a chance to wait for it.
385-
let pids = self
395+
// NOTE: we collect all of the zombie list's process IDs with the children
396+
// list since the child could have been removed from the children list and
397+
// become a zombie before the parent had a chance to wait for it.
398+
let mut pids = self
386399
.zombies
387400
.list
388401
.lock_irq()
389402
.iter()
390403
.map(|e| e.pid().as_usize())
391404
.collect::<alloc::vec::Vec<_>>();
392405

406+
pids.extend(self.children.lock_irq().iter().map(|e| e.pid().as_usize()));
393407
self.zombies.waitpid(&pids, status)
394408
} else {
395409
self.zombies.waitpid(&[pid as _], status)
@@ -536,7 +550,7 @@ impl Task {
536550
parent.zombies.add_zombie(self.this());
537551

538552
if self.is_process_leader() {
539-
parent.signal(aero_syscall::signal::SIGCHLD);
553+
// parent.signal(aero_syscall::signal::SIGCHLD);
540554
}
541555
}
542556
}

0 commit comments

Comments
 (0)