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

View File

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

View File

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

View File

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

View File

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