Commit a84e3ad1 authored by Aram Hăvărneanu's avatar Aram Hăvărneanu

runtime: use the nsec system call instead of /dev/bintime on Plan 9

LGTM=0intro
R=0intro
CC=ality, dave, golang-codereviews, jas, mischief, rsc
https://golang.org/cl/104570043
parent 0a2083ed
...@@ -150,29 +150,13 @@ runtime·usleep(uint32 µs) ...@@ -150,29 +150,13 @@ runtime·usleep(uint32 µs)
int64 int64
runtime·nanotime(void) runtime·nanotime(void)
{ {
static int32 fd = -1; int64 ns, scratch;
byte b[8];
uint32 hi, lo; ns = runtime·nsec(&scratch);
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
// As long as all goroutines share the same file if(ns == 0)
// descriptor table we can get away with using return scratch;
// just a static fd. Without a lock the file can return ns;
// be opened twice but that's okay.
//
// Using /dev/bintime gives us a latency on the
// order of ten microseconds between two calls.
//
// The naïve implementation (without the cached
// file descriptor) is roughly four times slower
// in 9vx on a 2.16 GHz Intel Core 2 Duo.
if(fd < 0 && (fd = runtime·open("/dev/bintime", OREAD|OCEXEC, 0)) < 0)
return 0;
if(runtime·pread(fd, b, sizeof b, 0) != sizeof b)
return 0;
hi = b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3];
lo = b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7];
return (int64)hi<<32 | (int64)lo;
} }
void void
......
...@@ -15,6 +15,7 @@ int32 runtime·plan9_tsemacquire(uint32 *addr, int32 ms); ...@@ -15,6 +15,7 @@ int32 runtime·plan9_tsemacquire(uint32 *addr, int32 ms);
int32 runtime·plan9_semrelease(uint32 *addr, int32 count); int32 runtime·plan9_semrelease(uint32 *addr, int32 count);
int32 runtime·notify(void (*fn)(void*, int8*)); int32 runtime·notify(void (*fn)(void*, int8*));
int32 runtime·noted(int32); int32 runtime·noted(int32);
int64 runtime·nsec(int64*);
void runtime·sigtramp(void*, int8*); void runtime·sigtramp(void*, int8*);
void runtime·sigpanic(void); void runtime·sigpanic(void);
void runtime·goexitsall(int8*); void runtime·goexitsall(int8*);
......
...@@ -64,6 +64,16 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0 ...@@ -64,6 +64,16 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
INT $64 INT $64
RET RET
TEXT runtime·nsec(SB),NOSPLIT,$0
MOVL $53, AX
INT $64
CMPL AX, $-1
JNE 4(PC)
MOVL a+0(FP), CX
MOVL AX, 0(CX)
MOVL AX, 4(CX)
RET
TEXT runtime·notify(SB),NOSPLIT,$0 TEXT runtime·notify(SB),NOSPLIT,$0
MOVL $28, AX MOVL $28, AX
INT $64 INT $64
......
...@@ -77,6 +77,11 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0 ...@@ -77,6 +77,11 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
SYSCALL SYSCALL
RET RET
TEXT runtime·nsec(SB),NOSPLIT,$0
MOVQ $53, BP
SYSCALL
RET
TEXT runtime·notify(SB),NOSPLIT,$0 TEXT runtime·notify(SB),NOSPLIT,$0
MOVQ $28, BP MOVQ $28, BP
SYSCALL SYSCALL
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment