sched: schedule after vfs_read error -EGAIN

This commit is contained in:
Michael Shaw 2024-06-17 13:03:53 -04:00
commit 86041e90e4
5 changed files with 28 additions and 1 deletions

View file

@ -44,7 +44,9 @@
movq %r13, 96(%rax)
movq %r14, 104(%rax)
movq %r15, 112(%rax)
.endm
.macro save_iretq_frame
/* save IRETQ frame */
popq %rdi
movq %rdi, 120(%rax)
@ -126,6 +128,7 @@
_irq_\nr:
cli
save_context
save_iretq_frame
/* call irq handler */
movq $\nr, %rdi
call irq
@ -198,6 +201,7 @@ gate_syscall:
cli
movq %r10, %rcx
save_context
save_iretq_frame
pushq %rax
movq 0(%rax), %rdi
movq 40(%rax), %rsi
@ -214,6 +218,7 @@ gate_syscall:
syscall_block:
cli
save_context
save_iretq_frame
call schedule
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */

View file

@ -132,13 +132,18 @@ void schedule()
spinlock_acquire(&proc->lock);
switch (proc->state) {
case PROC_BLOCKED:
if (sem_trywait(&proc->block_sem)) {
spinlock_release(&proc->lock);
break;
}
/* fallthrough */
case PROC_STOPPED:
proc->state = PROC_RUNNING;
spinlock_release(&proc->lock);
_return_to_user(&proc->regs, proc->cr3);
break;
case PROC_BLOCKED:
case PROC_RUNNING:
spinlock_release(&proc->lock);
break;

View file

@ -49,6 +49,7 @@ ssize_t sys_read(int fd, void *buf, size_t count)
while ((ret = vfs_read(file, tmp_buf, fdesc->pos, count)) == -EAGAIN) {
proc->state = PROC_BLOCKED;
schedule();
}
proc->state = PROC_RUNNING;