Improve process switching and syscall log spam

This commit is contained in:
Justin C. Miller
2019-03-22 17:43:29 -07:00
parent 9472dab522
commit b18243f098
2 changed files with 20 additions and 14 deletions

View File

@@ -284,6 +284,8 @@ scheduler::schedule(uintptr_t rsp0)
// TODO: lol a real clock // TODO: lol a real clock
static uint64_t now = 0; static uint64_t now = 0;
pid_t lastpid = m_current->pid;
m_current->rsp = rsp0; m_current->rsp = rsp0;
m_runlists[m_current->priority].remove(m_current); m_runlists[m_current->priority].remove(m_current);
@@ -312,9 +314,11 @@ scheduler::schedule(uintptr_t rsp0)
page_table *pml4 = m_current->pml4; page_table *pml4 = m_current->pml4;
page_manager::set_pml4(pml4); page_manager::set_pml4(pml4);
if (lastpid != m_current->pid) {
bool loading = m_current->flags && process_flags::loading; bool loading = m_current->flags && process_flags::loading;
log::debug(logs::task, "Scheduler switched to process %d, priority %d%s.", log::debug(logs::task, "Scheduler switched to process %d, priority %d%s.",
m_current->pid, m_current->priority, loading ? " (loading)" : ""); m_current->pid, m_current->priority, loading ? " (loading)" : "");
}
return rsp0; return rsp0;
} }

View File

@@ -49,7 +49,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::debug: case syscall::debug:
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received DEBUG syscall\n", p->pid); cons->printf("\nProcess %d: Received DEBUG syscall\n", p->pid);
cons->set_color(); cons->set_color();
print_regs(regs); print_regs(regs);
cons->printf("\n Syscall enters: %8d\n", __counter_syscall_enter); cons->printf("\n Syscall enters: %8d\n", __counter_syscall_enter);
@@ -58,7 +58,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::message: case syscall::message:
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received MESSAGE syscall\n", p->pid); cons->printf("\nProcess %d: Received MESSAGE syscall\n", p->pid);
cons->set_color(); cons->set_color();
break; break;
@@ -69,7 +69,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
auto &s = scheduler::get(); auto &s = scheduler::get();
auto *p = s.current(); auto *p = s.current();
p->wait_on_signal(-1ull); p->wait_on_signal(-1ull);
cons->printf("\nProcess %u: Received PAUSE syscall\n", p->pid); cons->printf("\nProcess %d: Received PAUSE syscall\n", p->pid);
cons->set_color(); cons->set_color();
return_rsp = s.schedule(return_rsp); return_rsp = s.schedule(return_rsp);
} }
@@ -78,7 +78,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::sleep: case syscall::sleep:
{ {
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received SLEEP syscall\n", p->pid); cons->printf("\nProcess %d: Received SLEEP syscall\n", p->pid);
cons->printf("Sleeping until %lu\n", regs.rbx); cons->printf("Sleeping until %lu\n", regs.rbx);
cons->set_color(); cons->set_color();
@@ -89,17 +89,18 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::getpid: case syscall::getpid:
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received GETPID syscall\n", p->pid); cons->printf("\nProcess %d: Received GETPID syscall\n", p->pid);
cons->set_color(); cons->set_color();
regs.rax = p->pid; regs.rax = p->pid;
break; break;
case syscall::send: case syscall::send:
{ {
uint32_t target = regs.rdi; pid_t target = regs.rdi;
uintptr_t data = regs.rsi;
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received SEND syscall, target %u\n", p->pid, target); cons->printf("\nProcess %d: Received SEND syscall, target %d, data %016lx\n", p->pid, target, data);
cons->set_color(); cons->set_color();
if (p->wait_on_send(target)) if (p->wait_on_send(target))
@@ -109,10 +110,11 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::receive: case syscall::receive:
{ {
uint32_t source = regs.rdi; pid_t source = regs.rdi;
uintptr_t data = regs.rsi;
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received RECEIVE syscall, source %u\n", p->pid, source); cons->printf("\nProcess %d: Received RECEIVE syscall, source %d, dat %016lx\n", p->pid, source, data);
cons->set_color(); cons->set_color();
if (p->wait_on_receive(source)) if (p->wait_on_receive(source))
@@ -123,7 +125,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::fork: case syscall::fork:
{ {
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received FORK syscall\n", p->pid); cons->printf("\nProcess %d: Received FORK syscall\n", p->pid);
cons->set_color(); cons->set_color();
pid_t pid = p->fork(return_rsp); pid_t pid = p->fork(return_rsp);
@@ -133,7 +135,7 @@ syscall_dispatch(uintptr_t return_rsp, cpu_state &regs)
case syscall::exit: case syscall::exit:
cons->set_color(11); cons->set_color(11);
cons->printf("\nProcess %u: Received EXIT syscall\n", p->pid); cons->printf("\nProcess %d: Received EXIT syscall\n", p->pid);
cons->set_color(); cons->set_color();
p->exit(regs.rdi); p->exit(regs.rdi);
return_rsp = s.schedule(return_rsp); return_rsp = s.schedule(return_rsp);