diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-20 22:34:41 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-12-20 22:34:41 +0100 |
commit | e4ce6aadac9e1de8d5ea625e9680d24cabce0e1a (patch) | |
tree | 63c0b00f6f2c8eac29d4a0354d402206bc61397a /sys/src/9/sgi/trap.c | |
parent | 08c1622b0d8de92c2650d7b0338d9abf20985827 (diff) |
kernel: handle tos and per process pcycle counters in port/
we might as well handle the per process cycle
counter in the portable part instead of duplicating the code
in every arch and have inconsistent implementations.
we now have a portable kenter() and kexit() function,
that is ment to be used in trap/syscall from user,
which updates the counters.
some kernels missed initializing Mach.cyclefreq.
Diffstat (limited to 'sys/src/9/sgi/trap.c')
-rw-r--r-- | sys/src/9/sgi/trap.c | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/sys/src/9/sgi/trap.c b/sys/src/9/sgi/trap.c index 08b3960df..2bea55c34 100644 --- a/sys/src/9/sgi/trap.c +++ b/sys/src/9/sgi/trap.c @@ -152,23 +152,6 @@ kvce(Ureg *ur, int ecode) } } -/* prepare to go to user space */ -void -kexit(Ureg *ur) -{ - Tos *tos; - - /* replicate fpstate to ureg status */ - if(up->fpstate != FPactive) - ur->status &= ~CU1; - - /* precise time accounting, kernel exit */ - tos = (Tos*)(USTKTOP-sizeof(Tos)); - tos->kcycles += fastticks(&tos->cyclefreq) - up->kentry; - tos->pcycles = up->pcycles; - tos->pid = up->pid; -} - void trap(Ureg *ur) { @@ -190,18 +173,11 @@ trap(Ureg *ur) dumpstack(); for(;;); } - - ecode = (ur->cause>>2)&EXCMASK; - user = userureg(ur); + user = kenter(ur); if (ur->cause & TS) panic("trap: tlb shutdown"); - + ecode = (ur->cause>>2)&EXCMASK; fpchk = 0; - if(user){ - up->dbgreg = ur; - cycles(&up->kentry); - } - clockintr = 0; switch(ecode){ case CINT: @@ -308,6 +284,9 @@ trap(Ureg *ur) if(user){ notify(ur); + /* replicate fpstate to ureg status */ + if(up->fpstate != FPactive) + ur->status &= ~CU1; kexit(ur); } } @@ -701,12 +680,12 @@ syscall(Ureg *ur) vlong startns; char *e; - cycles(&up->kentry); + if(!kenter(ur)) + panic("syscall from kernel"); m->syscall++; up->insyscall = 1; up->pc = ur->pc; - up->dbgreg = ur; ur->cause = 16<<2; /* for debugging: system call is undef 16 */ scallnr = ur->r1; @@ -774,6 +753,9 @@ syscall(Ureg *ur) /* if we delayed sched because we held a lock, sched now */ if(up->delaysched) sched(); + /* replicate fpstate to ureg status */ + if(up->fpstate != FPactive) + ur->status &= ~CU1; kexit(ur); } @@ -794,23 +776,11 @@ forkchild(Proc *p, Ureg *ur) cur->pc += 4; } -static void -linkproc(void) +kprocchild(Proc *p, void (*entry)(void)) { - spllo(); - up->kpfun(up->kparg); - pexit("kproc exiting", 0); -} - -void -kprocchild(Proc *p, void (*func)(void*), void *arg) -{ - p->sched.pc = (ulong)linkproc; + p->sched.pc = (ulong)entry; p->sched.sp = (ulong)p->kstack+KSTACK; - - p->kpfun = func; - p->kparg = arg; } /* set up user registers before return from exec() */ |