remove \n from panics, and use rdtsc() directly to avoid unnecessary indirection. need to submit additional patch to make perfticks return uvlong. Reference: /n/patches.lsub.org/patch/trapnits.1 Date: Sun Oct 28 18:36:58 CET 2012 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/k10/trap.c Thu Jul 12 10:53:55 2012 +++ /sys/src/nix/k10/trap.c Sun Oct 28 17:40:48 2012 @@ -7,7 +7,6 @@ #include #include "ureg.h" -#include "../port/pmc.h" #include "io.h" #include "amd64.h" @@ -17,8 +16,8 @@ static void debugbpt(Ureg*, void*); static void faultamd64(Ureg*, void*); static void doublefault(Ureg*, void*); -static void ipihdler(Ureg*, void*); static void unexpected(Ureg*, void*); +static void expected(Ureg*, void*); static void dumpstackwithureg(Ureg*); static Lock vctllock; @@ -158,7 +157,7 @@ Vctl *v; if(vno < 0 || vno >= 256) - panic("trapenable: vno %d\n", vno); + panic("trapenable: vno %d", vno); v = malloc(sizeof(Vctl)); v->type = "trap"; v->tbdf = BUSUNKNOWN; @@ -202,8 +201,8 @@ trapenable(VectorBPT, debugbpt, 0, "#BP"); trapenable(VectorPF, faultamd64, 0, "#PF"); trapenable(Vector2F, doublefault, 0, "#DF"); - intrenable(IdtIPI, ipihdler, 0, BUSUNKNOWN, "#IPI"); trapenable(Vector15, unexpected, 0, "#15"); + trapenable(IdtIPI, expected, 0, "#IPI"); nmienable(); addarchfile("irqalloc", 0444, irqallocread, nil); @@ -250,9 +249,9 @@ void intrtime(int vno) { - ulong diff, x; /* should be uvlong */ + uvlong diff, x; - x = perfticks(); + x = rdtsc(); diff = x - m->perf.intrts; m->perf.intrts = x; @@ -264,20 +263,12 @@ intrtimes[vno].count++; } -static void -pmcnop(Mach *) -{ -} - -void (*_pmcupdate)(Mach *m) = pmcnop; - /* go to user space */ void kexit(Ureg*) { uvlong t; Tos *tos; - Mach *mp; /* * precise time accounting, kernel exit @@ -288,18 +279,12 @@ tos->kcycles += t - up->kentry; tos->pcycles = up->pcycles; tos->pid = up->pid; - if (up->ac != nil) - mp = up->ac; - else - mp = m; - tos->core = mp->machno; - tos->nixtype = mp->nixrole; - _pmcupdate(m); + tos->core = m->machno; /* * The process may change its core. * Be sure it has the right cyclefreq. */ - tos->cyclefreq = mp->cyclefreq; + tos->cyclefreq = m->cyclefreq; } void @@ -334,17 +319,15 @@ vno = ureg->type; - m->perf.intrts = perfticks(); + m->perf.intrts = rdtsc(); user = userureg(ureg); - if(user && (m->nixrole == NIXTC)){ + if(user){ up->dbgreg = ureg; cycles(&up->kentry); } clockintr = 0; - _pmcupdate(m); - if(ctl = vctl[vno]){ if(ctl->isintr){ m->intr++; @@ -412,21 +395,12 @@ } if(vno < nelem(excname)) panic("%s", excname[vno]); - panic("unknown trap/intr: %d\n", vno); + panic("unknown trap/intr: %d", vno); } splhi(); /* delaysched set because we held a lock or because our quantum ended */ if(up && up->delaysched && clockintr){ - if(0) - if(user && up->ac == nil && up->nqtrap == 0 && up->nqsyscall == 0){ - if(!waserror()){ - up->ac = getac(up, -1); - poperror(); - runacore(); - return; - } - } sched(); splhi(); } @@ -468,7 +442,7 @@ iprint("r15\t%#16.16llux\n", ureg->r15); iprint("ds %#4.4ux es %#4.4ux fs %#4.4ux gs %#4.4ux\n", ureg->ds, ureg->es, ureg->fs, ureg->gs); - iprint("ureg fs\t%#ux\n", *(unsigned int *)&ureg->ds); + iprint("ureg fs\t%#ux\n", *(u32int*)&ureg->ds); iprint("type\t%#llux\n", ureg->type); iprint("error\t%#llux\n", ureg->error); iprint("pc\t%#llux\n", ureg->ip); @@ -477,8 +451,8 @@ iprint("sp\t%#llux\n", ureg->sp); iprint("ss\t%#llux\n", ureg->ss); iprint("type\t%#llux\n", ureg->type); - iprint("FS\t%#llux\n", rdmsr(FSbase)); - iprint("GS\t%#llux\n", rdmsr(GSbase)); + iprint("fs\t%#llux\n", rdmsr(FSbase)); + iprint("gs\t%#llux\n", rdmsr(GSbase)); iprint("m\t%#16.16p\nup\t%#16.16p\n", m, up); } @@ -595,12 +569,8 @@ } static void -ipihdler(Ureg*, void*) +expected(Ureg*, void*) { - coherence(); - if(isbooting(m) && m->proc == nil){ - tcquiesce(); - } } static void @@ -612,8 +582,8 @@ addr = m->cr2; user = userureg(ureg); -// if(!user && mmukmapsync(addr)) -// return; + if(!user && vmapsync(addr) == 0) + return; /* * There must be a user context. @@ -621,7 +591,7 @@ * initialisation before the system is fully up. */ if(up == nil){ - panic("fault with up == nil; pc %#llux addr %#llux\n", + panic("fault with up == nil; pc %#llux addr %#llux", ureg->ip, addr); } read = !(ureg->error & 2); @@ -642,7 +612,7 @@ * the game's a bogey. */ if(!user && (!insyscall || up->nerrlab == 0)) - panic("fault: %#llux\n", addr); + panic("fault: %#llux", addr); sprint(buf, "sys: trap: fault %s addr=%#llux", read? "read": "write", addr); postnote(up, 1, buf, NDebug); @@ -698,6 +668,8 @@ { ureg->ip = p->sched.pc; ureg->sp = p->sched.sp+BY2SE; + ureg->r14 = (uvlong)p; + ureg->r15 = (uvlong)m; /* well, better than nothing */ } uintptr