From b3d8f928a95e6e69dad35f76ab959eee34254831 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Thu, 13 Jun 2024 19:13:19 -0400 Subject: [PATCH] syscall: reorganize blocking for IO syscalls --- include/kernel/proc.h | 1 + sched/proc.c | 2 +- sched/syscall.c | 13 ++++--------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/kernel/proc.h b/include/kernel/proc.h index 7ab87cb..38581b1 100644 --- a/include/kernel/proc.h +++ b/include/kernel/proc.h @@ -76,5 +76,6 @@ struct proc *proc_find(pid_t pid); void proc_set_current(pid_t pid); void proc_init(unsigned num_cpus); void schedule(); +void syscall_block(); #endif /* _PROC_H_ */ diff --git a/sched/proc.c b/sched/proc.c index 6295ea8..4f9cc6a 100644 --- a/sched/proc.c +++ b/sched/proc.c @@ -163,7 +163,7 @@ void proc_unblock(pid_t pid) if (proc) { spinlock_acquire(&proc->lock); - proc->state = PROC_BLOCKED; + proc->state = PROC_STOPPED; spinlock_release(&proc->lock); } } diff --git a/sched/syscall.c b/sched/syscall.c index 815104a..60c8da7 100644 --- a/sched/syscall.c +++ b/sched/syscall.c @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include "kernel/lock.h" #include #include #include @@ -42,15 +43,7 @@ ssize_t sys_read(int fd, void *buf, size_t count) return -ENOMEM; ssize_t ret; - bool blocked = false; - while ((ret = vfs_read(file, tmp_buf, fdesc->pos, count)) == -EAGAIN) { - blocked = true; - proc_block(getpid(), true); - yield(); - } - - if (blocked) - proc_unblock(getpid()); + ret = vfs_read(file, tmp_buf, fdesc->pos, count); if (ret > 0) memcpy(buf, tmp_buf, count); @@ -127,7 +120,9 @@ void sys_exit(int status) if (proc == NULL) return; + spinlock_acquire(&proc->lock); proc->state = PROC_STOPPED; + spinlock_release(&proc->lock); proc_term(getpid());