Skip to content

Commit

Permalink
unix: defer Getpagesize() to runtime
Browse files Browse the repository at this point in the history
In general, page size is not a function of the archetecture. This was
addressed in the Go standard library here:
https://go-review.googlesource.com/25051

This change simply defers to the standard library "syscall" package,
which in turn defers to the runtime. This helps in addressing golang/go#10180 and
also fixes a bug on ppc64.

Currently, we return 65536 as the page size on ppc64, but the kernel
supports 4k and 64k sizes, see here:
http://elixir.free-electrons.com/linux/v4.13/source/arch/powerpc/include/asm/page.h#L24

Now that various page size calculations are not needed, various
components are now dead code and can also be removed. This CL reverts:
https://go-review.googlesource.com/14483
and part of:
https://go-review.googlesource.com/30755

Change-Id: I9d7a2d96359054e0dca9c985b026c8072b2eeaf3
Reviewed-on: https://go-review.googlesource.com/62111
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
josephlr authored and ianlancetaylor committed Sep 7, 2017
1 parent 31e1faf commit a45f555
Show file tree
Hide file tree
Showing 40 changed files with 16 additions and 145 deletions.
20 changes: 0 additions & 20 deletions unix/gccgo_linux_sparc64.go

This file was deleted.

4 changes: 0 additions & 4 deletions unix/linux/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,6 @@ const RNDGETENTCNT = C.RNDGETENTCNT

const PERF_IOC_FLAG_GROUP = C.PERF_IOC_FLAG_GROUP

// sysconf information

const _SC_PAGESIZE = C._SC_PAGESIZE

// Terminal handling

type Termios C.termios_t
Expand Down
15 changes: 15 additions & 0 deletions unix/pagesize_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2017 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.

// +build darwin dragonfly freebsd linux netbsd openbsd solaris

// For Unix, get the pagesize from the runtime.

package unix

import "syscall"

func Getpagesize() int {
return syscall.Getpagesize()
}
2 changes: 0 additions & 2 deletions unix/syscall_darwin_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_darwin_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 16384 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_dragonfly_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_freebsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_freebsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_freebsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ func Gettimeofday(tv *Timeval) (err error) {
return nil
}

func Getpagesize() int { return 4096 }

func Time(t *Time_t) (tt Time_t, err error) {
var tv Timeval
errno := gettimeofday(&tv)
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"unsafe"
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func Lstat(path string, stat *Stat_t) (err error) {
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_mips64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ package unix
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)

func Time(t *Time_t) (tt Time_t, err error) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_mipsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,3 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
}
return poll(&fds[0], len(fds), timeout)
}

func Getpagesize() int { return 4096 }
2 changes: 0 additions & 2 deletions unix/syscall_linux_ppc64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ package unix
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error)

Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_linux_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import (
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)

func Getpagesize() int { return 4096 }

//sysnb Gettimeofday(tv *Timeval) (err error)

func Time(t *Time_t) (tt Time_t, err error) {
Expand Down
20 changes: 0 additions & 20 deletions unix/syscall_linux_sparc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

package unix

import (
"sync/atomic"
"syscall"
)

//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
//sys Dup2(oldfd int, newfd int) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
Expand Down Expand Up @@ -63,21 +58,6 @@ import (
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func sysconf(name int) (n int64, err syscall.Errno)

// pageSize caches the value of Getpagesize, since it can't change
// once the system is booted.
var pageSize int64 // accessed atomically

func Getpagesize() int {
n := atomic.LoadInt64(&pageSize)
if n == 0 {
n, _ = sysconf(_SC_PAGESIZE)
atomic.StoreInt64(&pageSize, n)
}
return int(n)
}

func Ioperm(from int, num int, on int) (err error) {
return ENOSYS
}
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_netbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package unix

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_netbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package unix

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_netbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package unix

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_openbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package unix

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions unix/syscall_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package unix

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
4 changes: 0 additions & 4 deletions unix/syscall_openbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

package unix

import "syscall"

func Getpagesize() int { return syscall.Getpagesize() }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
16 changes: 0 additions & 16 deletions unix/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package unix

import (
"sync/atomic"
"syscall"
"unsafe"
)
Expand Down Expand Up @@ -699,18 +698,3 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e
func Munmap(b []byte) (err error) {
return mapper.Munmap(b)
}

//sys sysconf(name int) (n int64, err error)

// pageSize caches the value of Getpagesize, since it can't change
// once the system is booted.
var pageSize int64 // accessed atomically

func Getpagesize() int {
n := atomic.LoadInt64(&pageSize)
if n == 0 {
n, _ = sysconf(_SC_PAGESIZE)
atomic.StoreInt64(&pageSize, n)
}
return int(n)
}
4 changes: 0 additions & 4 deletions unix/types_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ type BpfTimeval C.struct_bpf_timeval

type BpfHdr C.struct_bpf_hdr

// sysconf information

const _SC_PAGESIZE = C._SC_PAGESIZE

// Terminal handling

type Termios C.struct_termios
Expand Down
14 changes: 1 addition & 13 deletions unix/zsyscall_solaris_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions unix/ztypes_linux_386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions unix/ztypes_linux_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions unix/ztypes_linux_arm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions unix/ztypes_linux_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a45f555

Please sign in to comment.