Commit 9c314114 authored by Aram Hăvărneanu's avatar Aram Hăvărneanu

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

Also remove arch-specific Go files in the Plan 9 syscall package

LGTM=0intro
R=0intro, dave
CC=ality, golang-codereviews, jas, mischief, rsc
https://golang.org/cl/112720043
parent a84e3ad1
......@@ -295,30 +295,25 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return
}
func DecodeBintime(b []byte) (nsec int64, err error) {
if len(b) != 8 {
return -1, NewError("bad /dev/bintime format")
func nsec() int64 {
var scratch int64
r0, _, _ := Syscall(SYS_NSEC, uintptr(unsafe.Pointer(&scratch)), 0, 0)
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
if r0 == 0 {
return scratch
}
nsec = int64(b[0])<<56 |
int64(b[1])<<48 |
int64(b[2])<<40 |
int64(b[3])<<32 |
int64(b[4])<<24 |
int64(b[5])<<16 |
int64(b[6])<<8 |
int64(b[7])
return
return int64(r0)
}
func Gettimeofday(tv *Timeval) error {
nsec, e := nanotime()
if e != nil {
return e
}
nsec := nsec()
*tv = NsecToTimeval(nsec)
return e
return nil
}
func Getpagesize() int { return 0x1000 }
func Getegid() (egid int) { return -1 }
func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 }
......
// Copyright 2009 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.
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
}
// Copyright 2009 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.
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
}
......@@ -44,4 +44,6 @@ const (
SYS_AWAIT = 47
SYS_PREAD = 50
SYS_PWRITE = 51
SYS_TSEMACQUIRE = 52
SYS_NSEC = 53
)
......@@ -44,5 +44,6 @@ const (
SYS_AWAIT = 47
SYS_PREAD = 50
SYS_PWRITE = 51
SYS_NANOTIME = 60
SYS_TSEMACQUIRE = 52
SYS_NSEC = 53
)
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