From e4ce6aadac9e1de8d5ea625e9680d24cabce0e1a Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 20 Dec 2020 22:34:41 +0100 Subject: 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. --- sys/src/9/omap/arch.c | 57 ++---------------------------------------------- sys/src/9/omap/fns.h | 2 -- sys/src/9/omap/syscall.c | 5 +---- sys/src/9/omap/trap.c | 7 +----- 4 files changed, 4 insertions(+), 67 deletions(-) (limited to 'sys/src/9/omap') diff --git a/sys/src/9/omap/arch.c b/sys/src/9/omap/arch.c index 4bbe28c2f..c0bf9c605 100644 --- a/sys/src/9/omap/arch.c +++ b/sys/src/9/omap/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)); - cycles(&t); - tos->kcycles += t - up->kentry; - tos->pcycles = t + up->pcycles; - tos->cyclefreq = m->cpuhz; - tos->pid = up->pid; - - /* make visible immediately to user proc */ - cachedwbinvse(tos, sizeof *tos); -} - /* * return the userpc the last exception happened at */ @@ -79,29 +60,15 @@ setregisters(Ureg* ureg, char* pureg, char* uva, int n) ureg->psr = ureg->psr & ~(PsrMask|PsrDfiq|PsrDirq) | v & (PsrMask|PsrDfiq|PsrDirq); } -/* - * 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,17 +93,11 @@ void procsetup(Proc* p) { fpusysprocsetup(p); - - cycles(&p->kentry); - p->pcycles = -p->kentry; } void procfork(Proc* p) { - p->kentry = up->kentry; - p->pcycles = -p->kentry; - fpuprocfork(p); } @@ -146,12 +107,6 @@ procfork(Proc* p) void procsave(Proc* p) { - uvlong t; - - cycles(&t); - p->pcycles += t; - p->kentry -= t; - // TODO: save and restore VFPv3 FP state once 5[cal] know the new registers. fpuprocsave(p); } @@ -159,14 +114,6 @@ procsave(Proc* 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/omap/fns.h b/sys/src/9/omap/fns.h index f52a2fa60..831c3eb8a 100644 --- a/sys/src/9/omap/fns.h +++ b/sys/src/9/omap/fns.h @@ -157,8 +157,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/omap/syscall.c b/sys/src/9/omap/syscall.c index 9c957a701..c89bfa66a 100644 --- a/sys/src/9/omap/syscall.c +++ b/sys/src/9/omap/syscall.c @@ -186,16 +186,13 @@ syscall(Ureg* ureg) long ret; int i, scallnr; - 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; if(up->procctl == Proc_tracesyscall){ up->procctl = Proc_stopme; diff --git a/sys/src/9/omap/trap.c b/sys/src/9/omap/trap.c index e8802849e..6c8021f02 100644 --- a/sys/src/9/omap/trap.c +++ b/sys/src/9/omap/trap.c @@ -465,12 +465,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); /* * All interrupts/exceptions should be resumed at ureg->pc-4, * except for Data Abort which resumes at ureg->pc-8. -- cgit v1.2.3