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) { ...@@ -295,30 +295,25 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return return
} }
func DecodeBintime(b []byte) (nsec int64, err error) { func nsec() int64 {
if len(b) != 8 { var scratch int64
return -1, NewError("bad /dev/bintime format")
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 | return int64(r0)
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
} }
func Gettimeofday(tv *Timeval) error { func Gettimeofday(tv *Timeval) error {
nsec, e := nanotime() nsec := nsec()
if e != nil {
return e
}
*tv = NsecToTimeval(nsec) *tv = NsecToTimeval(nsec)
return e return nil
} }
func Getpagesize() int { return 0x1000 }
func Getegid() (egid int) { return -1 } func Getegid() (egid int) { return -1 }
func Geteuid() (euid int) { return -1 } func Geteuid() (euid int) { return -1 }
func Getgid() (gid 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
}
...@@ -4,44 +4,46 @@ ...@@ -4,44 +4,46 @@
package syscall package syscall
const ( const (
SYS_SYSR1 = 0 SYS_SYSR1 = 0
SYS_BIND = 2 SYS_BIND = 2
SYS_CHDIR = 3 SYS_CHDIR = 3
SYS_CLOSE = 4 SYS_CLOSE = 4
SYS_DUP = 5 SYS_DUP = 5
SYS_ALARM = 6 SYS_ALARM = 6
SYS_EXEC = 7 SYS_EXEC = 7
SYS_EXITS = 8 SYS_EXITS = 8
SYS_FAUTH = 10 SYS_FAUTH = 10
SYS_SEGBRK = 12 SYS_SEGBRK = 12
SYS_OPEN = 14 SYS_OPEN = 14
SYS_OSEEK = 16 SYS_OSEEK = 16
SYS_SLEEP = 17 SYS_SLEEP = 17
SYS_RFORK = 19 SYS_RFORK = 19
SYS_PIPE = 21 SYS_PIPE = 21
SYS_CREATE = 22 SYS_CREATE = 22
SYS_FD2PATH = 23 SYS_FD2PATH = 23
SYS_BRK_ = 24 SYS_BRK_ = 24
SYS_REMOVE = 25 SYS_REMOVE = 25
SYS_NOTIFY = 28 SYS_NOTIFY = 28
SYS_NOTED = 29 SYS_NOTED = 29
SYS_SEGATTACH = 30 SYS_SEGATTACH = 30
SYS_SEGDETACH = 31 SYS_SEGDETACH = 31
SYS_SEGFREE = 32 SYS_SEGFREE = 32
SYS_SEGFLUSH = 33 SYS_SEGFLUSH = 33
SYS_RENDEZVOUS = 34 SYS_RENDEZVOUS = 34
SYS_UNMOUNT = 35 SYS_UNMOUNT = 35
SYS_SEMACQUIRE = 37 SYS_SEMACQUIRE = 37
SYS_SEMRELEASE = 38 SYS_SEMRELEASE = 38
SYS_SEEK = 39 SYS_SEEK = 39
SYS_FVERSION = 40 SYS_FVERSION = 40
SYS_ERRSTR = 41 SYS_ERRSTR = 41
SYS_STAT = 42 SYS_STAT = 42
SYS_FSTAT = 43 SYS_FSTAT = 43
SYS_WSTAT = 44 SYS_WSTAT = 44
SYS_FWSTAT = 45 SYS_FWSTAT = 45
SYS_MOUNT = 46 SYS_MOUNT = 46
SYS_AWAIT = 47 SYS_AWAIT = 47
SYS_PREAD = 50 SYS_PREAD = 50
SYS_PWRITE = 51 SYS_PWRITE = 51
SYS_TSEMACQUIRE = 52
SYS_NSEC = 53
) )
...@@ -4,45 +4,46 @@ ...@@ -4,45 +4,46 @@
package syscall package syscall
const ( const (
SYS_SYSR1 = 0 SYS_SYSR1 = 0
SYS_BIND = 2 SYS_BIND = 2
SYS_CHDIR = 3 SYS_CHDIR = 3
SYS_CLOSE = 4 SYS_CLOSE = 4
SYS_DUP = 5 SYS_DUP = 5
SYS_ALARM = 6 SYS_ALARM = 6
SYS_EXEC = 7 SYS_EXEC = 7
SYS_EXITS = 8 SYS_EXITS = 8
SYS_FAUTH = 10 SYS_FAUTH = 10
SYS_SEGBRK = 12 SYS_SEGBRK = 12
SYS_OPEN = 14 SYS_OPEN = 14
SYS_OSEEK = 16 SYS_OSEEK = 16
SYS_SLEEP = 17 SYS_SLEEP = 17
SYS_RFORK = 19 SYS_RFORK = 19
SYS_PIPE = 21 SYS_PIPE = 21
SYS_CREATE = 22 SYS_CREATE = 22
SYS_FD2PATH = 23 SYS_FD2PATH = 23
SYS_BRK_ = 24 SYS_BRK_ = 24
SYS_REMOVE = 25 SYS_REMOVE = 25
SYS_NOTIFY = 28 SYS_NOTIFY = 28
SYS_NOTED = 29 SYS_NOTED = 29
SYS_SEGATTACH = 30 SYS_SEGATTACH = 30
SYS_SEGDETACH = 31 SYS_SEGDETACH = 31
SYS_SEGFREE = 32 SYS_SEGFREE = 32
SYS_SEGFLUSH = 33 SYS_SEGFLUSH = 33
SYS_RENDEZVOUS = 34 SYS_RENDEZVOUS = 34
SYS_UNMOUNT = 35 SYS_UNMOUNT = 35
SYS_SEMACQUIRE = 37 SYS_SEMACQUIRE = 37
SYS_SEMRELEASE = 38 SYS_SEMRELEASE = 38
SYS_SEEK = 39 SYS_SEEK = 39
SYS_FVERSION = 40 SYS_FVERSION = 40
SYS_ERRSTR = 41 SYS_ERRSTR = 41
SYS_STAT = 42 SYS_STAT = 42
SYS_FSTAT = 43 SYS_FSTAT = 43
SYS_WSTAT = 44 SYS_WSTAT = 44
SYS_FWSTAT = 45 SYS_FWSTAT = 45
SYS_MOUNT = 46 SYS_MOUNT = 46
SYS_AWAIT = 47 SYS_AWAIT = 47
SYS_PREAD = 50 SYS_PREAD = 50
SYS_PWRITE = 51 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