]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add nanotime for Plan 9
authorAnthony Martin <ality@pbrane.org>
Fri, 18 Nov 2011 03:09:28 +0000 (22:09 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 18 Nov 2011 03:09:28 +0000 (22:09 -0500)
R=paulzhol, rsc, dave, rminnich
CC=golang-dev
https://golang.org/cl/5327063

src/pkg/runtime/plan9/386/signal.c
src/pkg/runtime/plan9/386/sys.s
src/pkg/runtime/plan9/os.h
src/pkg/runtime/plan9/thread.c

index 77e40d35a96c7cebf5103a3b34c35116e9f88458..c0b759c713604a8ae2fa7d560d6e8d17ca712146 100644 (file)
@@ -4,12 +4,6 @@
 
 #include "runtime.h"
 
-int64
-runtime·nanotime(void) 
-{
-       // Won't compile.
-}
-
 String
 runtime·signame(int32)
 {
index a15362ff704ce9b9368b65b191c26b7beba8ca7a..97be276be6336d80ddb8f25def6ccc25d0495519 100644 (file)
@@ -14,16 +14,14 @@ TEXT runtime·open(SB),7,$0
        INT     $64
        RET
 
-// TODO(ality): remove use of deprecated system calls
-
-TEXT runtime·read(SB),7,$0
-       MOVL    $15, AX
-       INT             $64
+TEXT runtime·pread(SB),7,$0
+       MOVL    $50, AX
+       INT     $64
        RET
 
-TEXT runtime·write(SB),7,$0
-       MOVL    $20, AX
-       INT             $64
+TEXT runtime·pwrite(SB),7,$0
+       MOVL    $51, AX
+       INT     $64
        RET
 
 TEXT runtime·close(SB),7,$0
@@ -90,9 +88,9 @@ TEXT runtime·rfork(SB),7,$0
        MOVL    0(BX), BX
        
        // more paranoia; check that stack splitting code works
-       PUSHAL
+       PUSHL   SI
        CALL    runtime·emptyfunc(SB)
-       POPAL
+       POPL    SI
        
        CALL    SI      // fn()
        CALL    runtime·exit(SB)
index dcbdab25a935e39ec5654f7d04b8fc9693b23e85..b7b83834949d37010435d95fe3718aceced852a0 100644 (file)
@@ -4,6 +4,8 @@
 
 // Plan 9-specific system calls
 int32  runtime·open(uint8 *file, int32 mode);
+int32  runtime·pread(int32 fd, void *buf, int32 nbytes, int64 offset);
+int32  runtime·pwrite(int32 fd, void *buf, int32 nbytes, int64 offset);
 int32  runtime·read(int32 fd, void *buf, int32 nbytes);
 int32  runtime·close(int32 fd);
 void   runtime·exits(int8* msg);
@@ -16,9 +18,14 @@ int32        runtime·plan9_semrelease(uint32 *addr, int32 count);
 /* open */
 enum
 {
-       OREAD                   = 0,
-       OWRITE                  = 1,
-       ORDWR                   = 2
+       OREAD   = 0,
+       OWRITE  = 1,
+       ORDWR   = 2,
+       OEXEC   = 3,
+       OTRUNC  = 16,
+       OCEXEC  = 32,
+       ORCLOSE = 64,
+       OEXCL   = 0x1000
 };
 
 /* rfork */
index 8ad06ca1e40e0273e3fcc97c4decf7395bd0d96b..87ea8a23634ecfc9f8b5eca062cefd204cb25e43 100644 (file)
@@ -69,6 +69,34 @@ runtime·usleep(uint32 µs)
        runtime·sleep(ms);
 }
 
+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((byte*)"/dev/bintime", OREAD|OCEXEC)) < 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;
+}
+
 extern Tos *_tos;
 void
 runtime·exit(int32)
@@ -183,3 +211,15 @@ void
 runtime·sigpanic(void)
 {
 }
+
+int32
+runtime·read(int32 fd, void *buf, int32 nbytes)
+{
+       return runtime·pread(fd, buf, nbytes, -1LL);
+}
+
+int32
+runtime·write(int32 fd, void *buf, int32 nbytes)
+{
+       return runtime·pwrite(fd, buf, nbytes, -1LL);
+}