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/kw | |
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/kw')
-rw-r--r-- | sys/src/9/kw/arch.c | 59 | ||||
-rw-r--r-- | sys/src/9/kw/archkw.c | 1 | ||||
-rw-r--r-- | sys/src/9/kw/fns.h | 2 | ||||
-rw-r--r-- | sys/src/9/kw/syscall.c | 5 | ||||
-rw-r--r-- | sys/src/9/kw/trap.c | 7 |
5 files changed, 6 insertions, 68 deletions
diff --git a/sys/src/9/kw/arch.c b/sys/src/9/kw/arch.c index bd5562f5d..8f73da606 100644 --- a/sys/src/9/kw/arch.c +++ b/sys/src/9/kw/arch.c @@ -39,25 +39,6 @@ evenaddr(uintptr addr) } } -/* go to user space */ -void -kexit(Ureg*) -{ - uvlong t; - Tos *tos; - - /* precise time accounting, kernel exit */ - tos = (Tos*)(USTKTOP-sizeof(Tos)); - t = fastticks(nil); - tos->kcycles += t - up->kentry; - tos->pcycles = t + up->pcycles; - tos->cyclefreq = Frequency; - tos->pid = up->pid; - - /* make visible immediately to user proc */ - cachedwbinvse(tos, sizeof *tos); -} - /* * return the userpc the last exception happened at */ @@ -80,28 +61,14 @@ setregisters(Ureg* ureg, char* pureg, char* uva, int n) } /* - * this is the body for all kproc's - */ -static void -linkproc(void) -{ - spllo(); - up->kpfun(up->kparg); - pexit("kproc exiting", 0); -} - -/* * setup stack and initial PC for a new kernel proc. This is architecture * dependent because of the starting stack location */ void -kprocchild(Proc *p, void (*func)(void*), void *arg) +kprocchild(Proc *p, void (*entry)(void)) { - p->sched.pc = (uintptr)linkproc; + p->sched.pc = (uintptr)entry; p->sched.sp = (uintptr)p->kstack+KSTACK; - - p->kpfun = func; - p->kparg = arg; } /* @@ -126,16 +93,11 @@ void procsetup(Proc* p) { fpusysprocsetup(p); - - cycles(&p->kentry); - p->pcycles = -p->kentry; } void -procfork(Proc* p) +procfork(Proc*) { - p->kentry = up->kentry; - p->pcycles = -p->kentry; } /* @@ -144,27 +106,12 @@ procfork(Proc* p) void procsave(Proc* p) { - uvlong t; - - cycles(&t); - p->pcycles += t; - p->kentry -= t; - fpuprocsave(p); } void procrestore(Proc* p) { - uvlong t; - - if(p->kp) - return; - - cycles(&t); - p->pcycles -= t; - p->kentry += t; - fpuprocrestore(p); } diff --git a/sys/src/9/kw/archkw.c b/sys/src/9/kw/archkw.c index bcffd5e4c..e7ad5f000 100644 --- a/sys/src/9/kw/archkw.c +++ b/sys/src/9/kw/archkw.c @@ -381,6 +381,7 @@ void archconfinit(void) { m->cpuhz = Frequency; + m->cyclefreq = m->cpuhz; m->delayloop = m->cpuhz/2000; /* initial estimate */ fixaddrmap(); if (Debug) diff --git a/sys/src/9/kw/fns.h b/sys/src/9/kw/fns.h index f74e993cc..64feffc6a 100644 --- a/sys/src/9/kw/fns.h +++ b/sys/src/9/kw/fns.h @@ -140,8 +140,6 @@ extern int userureg(Ureg*); void* vmap(uintptr, usize); void vunmap(void*, usize); -extern void kexit(Ureg*); - #define getpgcolor(a) 0 #define kmapinval() diff --git a/sys/src/9/kw/syscall.c b/sys/src/9/kw/syscall.c index 773a151d5..067c4a48b 100644 --- a/sys/src/9/kw/syscall.c +++ b/sys/src/9/kw/syscall.c @@ -187,16 +187,13 @@ syscall(Ureg* ureg) int i, scallnr; vlong startns, stopns; - if(!userureg(ureg)) + if(!kenter(ureg)) panic("syscall: from kernel: pc %#lux r14 %#lux psr %#lux", ureg->pc, ureg->r14, ureg->psr); - cycles(&up->kentry); - m->syscall++; up->insyscall = 1; up->pc = ureg->pc; - up->dbgreg = ureg; scallnr = ureg->r0; up->scallnr = scallnr; diff --git a/sys/src/9/kw/trap.c b/sys/src/9/kw/trap.c index 0ced0bd6e..1b0705b05 100644 --- a/sys/src/9/kw/trap.c +++ b/sys/src/9/kw/trap.c @@ -376,12 +376,7 @@ trap(Ureg *ureg) rem, up, ureg, ureg->pc); } - user = (ureg->psr & PsrMask) == PsrMusr; - if(user){ - up->dbgreg = ureg; - cycles(&up->kentry); - } - + user = kenter(ureg); if(ureg->type == PsrMabt+1) ureg->pc -= 8; else |