]> Cypherpunks repositories - gostls13.git/commitdiff
syscall, runtime: Plan 9: use nanotime syscall on amd64
authorAkshat Kumar <seed@mail.nanosouffle.net>
Tue, 26 Feb 2013 00:56:08 +0000 (01:56 +0100)
committerRon Minnich <rminnich@gmail.com>
Tue, 26 Feb 2013 00:56:08 +0000 (01:56 +0100)
Separates the implementation of nanotime on 64-bit
version of Plan 9 from that on the 32-bit version.
The former uses a syscall.

R=rsc, rminnich, ality
CC=golang-dev
https://golang.org/cl/7379051

src/pkg/runtime/sys_plan9_amd64.s
src/pkg/runtime/thread_plan9.c
src/pkg/runtime/time_plan9_386.c [new file with mode: 0644]
src/pkg/syscall/syscall_plan9.go
src/pkg/syscall/syscall_plan9_386.go
src/pkg/syscall/syscall_plan9_amd64.go
src/pkg/syscall/zsysnum_plan9_amd64.go

index be164a04602e44c1eb0ae4c4655dfd2509678d27..b34f98a6855f9081d49d3ebc63871ee0851b0d67 100644 (file)
@@ -104,6 +104,12 @@ TEXT runtime·plan9_semrelease(SB),7,$0
        SYSCALL
        RET
 
+TEXT runtime·nanotime(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $60, BP
+       SYSCALL
+       RET
+
 TEXT runtime·rfork(SB),7,$0
        MOVQ    $0x8000, AX
        MOVQ    $19, BP // rfork
index 625c8b48d4d9cbcffcaa790fda86b142f7a012d0..f2169e8e68db9af2fc464e18352cbbfd980f1fb1 100644 (file)
@@ -115,34 +115,6 @@ 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;
-}
-
 void
 time·now(int64 sec, int32 nsec)
 {
diff --git a/src/pkg/runtime/time_plan9_386.c b/src/pkg/runtime/time_plan9_386.c
new file mode 100644 (file)
index 0000000..a29d457
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "runtime.h"
+#include "os_GOOS.h"
+
+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;
+}
index 94bed0981f08fd71d5aecc63335d5d03a2d1aaaa..ef5bc5e8cdbe281e7aadfd0654bdc7e898fc73da 100644 (file)
@@ -312,29 +312,12 @@ func DecodeBintime(b []byte) (nsec int64, err error) {
        return
 }
 
-func Gettimeofday(tv *Timeval) (err error) {
-       // TODO(paulzhol):
-       // avoid reopening a file descriptor for /dev/bintime on each call,
-       // use lower-level calls to avoid allocation.
-
-       var b [8]byte
-       var nsec int64
-
-       fd, e := Open("/dev/bintime", O_RDONLY)
+func Gettimeofday(tv *Timeval) error {
+       nsec, e := nanotime()
        if e != nil {
                return e
        }
-       defer Close(fd)
-
-       if _, e = Pread(fd, b[:], 0); e != nil {
-               return e
-       }
-
-       if nsec, e = DecodeBintime(b[:]); e != nil {
-               return e
-       }
        *tv = NsecToTimeval(nsec)
-
        return e
 }
 
index 4e4c7511e5c078ea60b96b5afb3010c88360c5ad..7357e0ba67a752df43e900523a77c92ad5850d01 100644 (file)
@@ -5,3 +5,28 @@
 package syscall
 
 func Getpagesize() int { return 0x1000 }
+
+func nanotime() (nsec int64, err error) {
+       // TODO(paulzhol):
+       // avoid reopening a file descriptor for /dev/bintime on each call,
+       // use lower-level calls to avoid allocation.
+
+       var b [8]byte
+       nsec = -1
+
+       fd, err := Open("/dev/bintime", O_RDONLY)
+       if err != nil {
+               return
+       }
+       defer Close(fd)
+
+       if _, err = Pread(fd, b[:], 0); err != nil {
+               return
+       }
+
+       if nsec, err = DecodeBintime(b[:]); err != nil {
+               return -1, err
+       }
+
+       return
+}
index 6f752f21366809b9f82bc8696ab1cda69140b813..9387db3e522cf50639d87fe86921a52f6b8b3f19 100644 (file)
@@ -5,3 +5,10 @@
 package syscall
 
 func Getpagesize() int { return 0x200000 }
+
+// Used by Gettimeofday, which expects
+// an error return value.
+func nanotime() (int64, error) {
+       r1, _, _ := RawSyscall(SYS_NANOTIME, 0, 0, 0)
+       return int64(r1), nil
+}
index 4135b8d819b4adaf51f2901551808b9003929fb8..c03864647418a271ba707f41325ce0c8ee79807d 100644 (file)
@@ -44,4 +44,5 @@ const (
        SYS_AWAIT      = 47
        SYS_PREAD      = 50
        SYS_PWRITE     = 51
+       SYS_NANOTIME   = 60
 )