X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/94a87fe25c5ec021daf16edd64058ed6a37aba7d..12293ed1d71cd306ed9a5d021a79ba945fe4e680:/lunaix-os/kernel/sched.c?ds=inline diff --git a/lunaix-os/kernel/sched.c b/lunaix-os/kernel/sched.c index 7f124c4..ab04e66 100644 --- a/lunaix-os/kernel/sched.c +++ b/lunaix-os/kernel/sched.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -30,9 +31,12 @@ void sched_init() { size_t pg_size = ROUNDUP(sizeof(struct proc_info) * MAX_PROCESS, 0x1000); - assert_msg(vmm_alloc_pages( - KERNEL_PID, &__proc_table, pg_size, PG_PREM_RW, PP_FGPERSIST), - "Fail to allocate proc table"); + + for (size_t i = 0; i <= pg_size; i += 4096) { + uintptr_t pa = pmm_alloc_page(KERNEL_PID, PP_FGPERSIST); + vmm_set_mapping( + PD_REFERENCED, &__proc_table + i, pa, PG_PREM_RW, VMAP_NULL); + } sched_ctx = (struct scheduler){ ._procs = (struct proc_info*)&__proc_table, .ptable_len = 0, @@ -49,22 +53,10 @@ run(struct proc_info* proc) // FIXME: 这里还是得再考虑一下。 // tss_update_esp(__current->intr_ctx.esp); - - if (__current->page_table != proc->page_table) { - __current = proc; - cpu_lcr3(__current->page_table); - // from now on, the we are in the kstack of another process - } else { - __current = proc; - } - apic_done_servicing(); - signal_dispatch(); - asm volatile("pushl %0\n" - "jmp soft_iret\n" ::"r"(&__current->intr_ctx) - : "memory"); + "jmp switch_to\n" ::"r"(proc)); // kernel/asm/x86/interrupt.S } void @@ -149,11 +141,12 @@ _wait(pid_t wpid, int* status, int options) return -1; } + wpid = wpid ? wpid : -__current->pgid; cpu_enable_interrupt(); repeat: llist_for_each(proc, n, &__current->children, siblings) { - if (!~wpid || proc->pid == wpid) { + if (!~wpid || proc->pid == wpid || proc->pgid == -wpid) { if (proc->state == PROC_TERMNAT && !options) { status_flags |= PROCTERM; goto done; @@ -209,8 +202,10 @@ push_process(struct proc_info* process) process = &sched_ctx._procs[index]; - // make sure the address is in the range of process table + // make sure the reference is relative to process table llist_init_head(&process->children); + llist_init_head(&process->grp_member); + // every process is the child of first process (pid=1) if (process->parent) { llist_append(&process->parent->children, &process->siblings);