kernel: reset and restore up->cursyscall in trap

This way sleep() knows that it should not interrupt the process
to serve awake().

Also rename Proc.insyscall to Proc.inkernel since that's the meaning
of the flag, which is only read to serve awake()'s mechanics and
to accounttime(). Indeed faultAmd64 was setting insyscall to 1.
This commit is contained in:
Giacomo Tesio 2017-05-17 01:16:49 +02:00
parent 960e8a0d4e
commit 1dc8991331
5 changed files with 22 additions and 15 deletions

View File

@ -236,7 +236,7 @@ syscall(Syscalls scallnr, Ureg* ureg)
cycles(&up->kentry);
m->syscall++;
up->insyscall = 1;
up->inkernel = 1;
up->cursyscall = (Syscalls)scallnr;
up->pc = ureg->ip;
up->dbgreg = ureg;
@ -344,7 +344,7 @@ syscall(Syscalls scallnr, Ureg* ureg)
splx(s);
}
up->insyscall = 0;
up->inkernel = 0;
up->psstate = 0;
up->cursyscall = 0;
@ -444,7 +444,7 @@ sysrforkchild(Proc* child, Proc* parent)
/* Things from bottom of syscall which were never executed */
child->psstate = 0;
child->insyscall = 0;
child->inkernel = 0;
fpusysrforkchild(child, parent);
}

View File

@ -575,7 +575,8 @@ static void
faultamd64(Ureg* ureg, void* _1)
{
uint64_t addr, arg;
int ftype, user, insyscall;
int ftype, user, inkernel;
Syscalls cursyscall;
char buf[ERRMAX];
void (*pt)(Proc*, int, int64_t, int64_t);
@ -606,8 +607,10 @@ faultamd64(Ureg* ureg, void* _1)
pt(up, STrap, 0, arg);
}
insyscall = up->insyscall;
up->insyscall = 1;
inkernel = up->inkernel;
cursyscall = up->cursyscall;
up->inkernel = 1;
up->cursyscall = 0;
if(iskaddr(addr)){
jehanne_print("kaddr %#llux pc %#p\n", addr, ureg->ip);
// prflush();
@ -623,10 +626,13 @@ if(iskaddr(addr)){
fault_types[ftype], addr);
proc_check_pages();
postnote(up, 1, buf, NDebug);
if(insyscall)
if(inkernel){
up->cursyscall = cursyscall;
error(buf);
}
}
up->insyscall = insyscall;
up->cursyscall = cursyscall;
up->inkernel = inkernel;
}
/*

View File

@ -44,7 +44,7 @@ int
canwakeup(Syscalls scall)
{
if(scall == 0){
/* fault set insyscall to 1 */
/* on page fault */
return 0;
}
switch(scall){

View File

@ -608,8 +608,9 @@ struct Proc
int64_t pcycles;
Profbuf* prof;
int insyscall;
Syscalls cursyscall;
int inkernel; /* either on syscall or fault */
Syscalls cursyscall; /* zero on fault */
int32_t blockingfd; /* fd currenly read/written */
QLock debug; /* to access debugging elements of User */

View File

@ -568,7 +568,7 @@ newproc(void)
p = psalloc();
p->state = Scheding;
p->insyscall = 0;
p->inkernel = 0;
p->cursyscall = 0;
p->psstate = "New";
p->mach = 0;
@ -714,7 +714,7 @@ sleep(Rendez *r, int (*f)(void*), void *arg)
if((*f)(arg)
|| (up->notepending && !up->notedeferred)
|| (up->insyscall && awakeOnBlock(up) && canwakeup(up->cursyscall))){
|| (up->inkernel && awakeOnBlock(up) && canwakeup(up->cursyscall))){
/*
* if condition happened or a note is pending
* never mind
@ -761,7 +761,7 @@ SleepAwakened:
forceclosefgrp();
error(Eintr);
}
if(up->insyscall && awakeOnBlock(up) && canwakeup(up->cursyscall))
if(up->inkernel && awakeOnBlock(up) && canwakeup(up->cursyscall))
goto SleepAwakened;
splx(s);
@ -1690,7 +1690,7 @@ accounttime(void)
p = m->proc;
if(p) {
nrun++;
p->time[p->insyscall]++;
p->time[p->inkernel]++;
}
/* calculate decaying duty cycles */