vmx(1): use cycles() instead of nsec() when possible

this provides better timing and reduced number of syscalls (~2.7M old
vs ~35K new in a test)
This commit is contained in:
Sigrid 2020-07-31 15:48:54 +02:00
parent de27182a8e
commit 853f0e33fe
6 changed files with 15 additions and 13 deletions

View file

@ -52,3 +52,4 @@ uintptr vmemwrite(void *, uintptr, uintptr);
int x86access(int, uintptr, int, uvlong*, int, int, TLB *);
u32int io(int, u16int, u32int, int);
int x86step(void);
uvlong nanosec(void);

View file

@ -31,7 +31,7 @@ rtcadvance(void)
vlong t;
if(rtcnext != -1){
t = nsec();
t = nanosec();
if(t >= rtcnext){
cmos[0xc] |= 0x40;
rtcnext = -1;
@ -58,7 +58,7 @@ rtcset(void)
default: d = 4 + (cmos[0xa] & 0xf);
}
b = (1000000000ULL << d) / 1048576;
t = nsec();
t = nanosec();
rtcnext = t + b - t % b;
settimer(rtcnext);
}
@ -464,7 +464,7 @@ pitadvance(void)
for(i = 0; i < 3; i++){
p = &pit[i];
nt = nsec();
nt = nanosec();
t = nt - p->lastnsec;
p->lastnsec = nt;
switch(p->mode){
@ -533,7 +533,7 @@ pitsetreload(int n, int hi, u8int v)
if(p->access != 3 || hi){
p->count = p->reload;
p->state = 1;
p->lastnsec = nsec();
p->lastnsec = nanosec();
settimer(p->lastnsec + p->count * PERIOD);
}else
p->state = 0;
@ -543,7 +543,7 @@ pitsetreload(int n, int hi, u8int v)
if(p->state == 0 && (p->access != 3 || hi)){
p->count = p->reload;
p->state = 1;
p->lastnsec = nsec();
p->lastnsec = nanosec();
pitadvance();
}
break;
@ -621,7 +621,7 @@ pitio(int isin, u16int port, u32int val, int sz, void *)
pit[n].reload = 0;
pit[n].readstate = pit[n].access == 1 ? READHI : READLO;
pit[n].writestate = pit[n].access == 1 ? READHI : READLO;
pit[n].lastnsec = nsec();
pit[n].lastnsec = nanosec();
switch(pit[n].mode){
case 0:
pitout(n, 0);

View file

@ -15,6 +15,7 @@ OFILES=\
vesa.$O \
9p.$O \
x86.$O \
nanosec.$O \
</sys/src/cmd/mkone

View file

@ -358,7 +358,7 @@ keyproc(void *)
n = read(fd, buf, sizeof(buf)-1);
if(n <= 0)
sysfatal("read /dev/kbd: %r");
kbwatchdog = nsec();
kbwatchdog = nanosec();
buf[n-1] = 0;
buf[n] = 0;
}
@ -431,7 +431,7 @@ mousethread(void *)
clicked = m.buttons & 1;
break;
}
if(kbwatchdog != 0 && nsec() - kbwatchdog > 1000ULL*1000*1000)
if(kbwatchdog != 0 && nanosec() - kbwatchdog > 1000ULL*1000*1000)
mousegrab = 0;
gotm = 1;
if(!ptinrect(m.xy, grabout)){
@ -503,7 +503,7 @@ drawtext(void)
p += 160;
}
cp = (vga.crtc[14] << 8 | vga.crtc[15]);
if(cp >= sa && cp < sa + 80*25 && (vga.crtc[10] & 0x20) == 0 && nsec() / 500000000 % 2 == 0){
if(cp >= sa && cp < sa + 80*25 && (vga.crtc[10] & 0x20) == 0 && nanosec() / 500000000 % 2 == 0){
buf[0] = cp437[tfb[cp*2]];
attr = tfb[cp*2+1];
r.min = Pt((cp - sa) % 80 * 8, (cp - sa) / 80 * 16);

View file

@ -518,7 +518,7 @@ vionetwproc(void *vp)
if((v->net.flags & VNETHEADER) != 0){
txbuf[0] = len >> 8;
txbuf[1] = len;
ns = nsec();
ns = nanosec();
txbuf[2] = ns >> 56;
txbuf[3] = ns >> 48;
txbuf[4] = ns >> 40;

View file

@ -430,20 +430,20 @@ sleeperproc(void *)
vlong then, now;
timerid = threadid();
timerevent = nsec() + SleeperPoll;
timerevent = nanosec() + SleeperPoll;
unlock(&timerlock);
threadsetname("sleeper");
for(;;){
lock(&timerlock);
then = timerevent;
now = nsec();
now = nanosec();
if(then <= now) timerevent = now + SleeperPoll;
unlock(&timerlock);
if(then - now >= MinSleep){
sleep((then - now) / MSEC);
continue;
}
while(nsec() < then)
while(nanosec() < then)
;
sendul(sleepch, 0);
}