github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/runtime/time_plan9_386.c (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "runtime.h" 6 #include "os_GOOS.h" 7 8 int64 9 runtime·nanotime(void) 10 { 11 static int32 fd = -1; 12 byte b[8]; 13 uint32 hi, lo; 14 15 // As long as all goroutines share the same file 16 // descriptor table we can get away with using 17 // just a static fd. Without a lock the file can 18 // be opened twice but that's okay. 19 // 20 // Using /dev/bintime gives us a latency on the 21 // order of ten microseconds between two calls. 22 // 23 // The naïve implementation (without the cached 24 // file descriptor) is roughly four times slower 25 // in 9vx on a 2.16 GHz Intel Core 2 Duo. 26 27 if(fd < 0 && (fd = runtime·open("/dev/bintime", OREAD|OCEXEC, 0)) < 0) 28 return 0; 29 if(runtime·pread(fd, b, sizeof b, 0) != sizeof b) 30 return 0; 31 hi = b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3]; 32 lo = b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7]; 33 return (int64)hi<<32 | (int64)lo; 34 }