]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use the nsec system call instead of /dev/bintime on Plan 9
authorAram Hăvărneanu <aram@mgk.ro>
Wed, 9 Jul 2014 10:33:42 +0000 (12:33 +0200)
committerAram Hăvărneanu <aram@mgk.ro>
Wed, 9 Jul 2014 10:33:42 +0000 (12:33 +0200)
LGTM=0intro
R=0intro
CC=ality, dave, golang-codereviews, jas, mischief, rsc
https://golang.org/cl/104570043

src/pkg/runtime/os_plan9.c
src/pkg/runtime/os_plan9.h
src/pkg/runtime/sys_plan9_386.s
src/pkg/runtime/sys_plan9_amd64.s

index 6da7c7ef52d2ec9c9098ead9899f0fe827f4eebc..02723fd9e45daab0db3d62d17173596dfc9aeeaf 100644 (file)
@@ -150,29 +150,13 @@ runtime·usleep(uint32 µs)
 int64
 runtime·nanotime(void)
 {
-       static int32 fd = -1;
-       byte b[8];
-       uint32 hi, lo;
-
-       // As long as all goroutines share the same file
-       // descriptor table we can get away with using
-       // just a static fd.  Without a lock the file can
-       // 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;
+       int64 ns, scratch;
+
+       ns = runtime·nsec(&scratch);
+       // TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
+       if(ns == 0)
+               return scratch;
+       return ns;
 }
 
 void
index 00ea8366d76e455474f0311458a82ade337e0d79..8bc57262d951a2c0eb3604a2ceaa5133d9b4a6d4 100644 (file)
@@ -15,6 +15,7 @@ int32 runtime·plan9_tsemacquire(uint32 *addr, int32 ms);
 int32  runtime·plan9_semrelease(uint32 *addr, int32 count);
 int32  runtime·notify(void (*fn)(void*, int8*));
 int32  runtime·noted(int32);
+int64  runtime·nsec(int64*);
 void   runtime·sigtramp(void*, int8*);
 void   runtime·sigpanic(void);
 void   runtime·goexitsall(int8*);
index 6a390120594f86800fa30476f981b01bc7c461a8..5e8c7420e29d7976dc897d519f3ff8521d1e862f 100644 (file)
@@ -64,6 +64,16 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
        INT     $64
        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
        MOVL    $28, AX
        INT     $64
index bcecc39638b8642df1c849a306548771974bf020..8f4a5c05eccf14c9f346c0c6b78b6d32422d2c84 100644 (file)
@@ -77,6 +77,11 @@ TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
        SYSCALL
        RET
 
+TEXT runtime·nsec(SB),NOSPLIT,$0
+       MOVQ    $53, BP
+       SYSCALL
+       RET
+
 TEXT runtime·notify(SB),NOSPLIT,$0
        MOVQ    $28, BP
        SYSCALL