Commit 8ccfc680 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: add SysctlClockinfo on NetBSD

NetBSD uses sysctl with struct clockinfo to get clock rate information
from the kernel. Add type Clockinfo and the SysctlClockinfo function
to query this information.

This will be used in github.com/tklauser/go-sysconf to get _SC_CLK_TCK
on NetBSD.

Change-Id: I9e67d766f491ec3b460f26cb243b3595f0ba4d69
Reviewed-on: https://go-review.googlesource.com/138035
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c2ed4eda
......@@ -93,6 +93,23 @@ func nametomib(name string) (mib []_C_int, err error) {
return mib, nil
}
func SysctlClockinfo(name string) (*Clockinfo, error) {
mib, err := sysctlmib(name)
if err != nil {
return nil, err
}
n := uintptr(SizeofClockinfo)
buf := make([]byte, SizeofClockinfo)
if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil {
return nil, err
}
if n != SizeofClockinfo {
return nil, EIO
}
return (*Clockinfo)(unsafe.Pointer(&buf[0])), nil
}
//sysnb pipe() (fd1 int, fd2 int, err error)
func Pipe(p []int) (err error) {
if len(p) != 2 {
......
......@@ -4,6 +4,12 @@
package unix_test
import (
"testing"
"golang.org/x/sys/unix"
)
// stringsFromByteSlice converts a sequence of attributes to a []string.
// On NetBSD, each entry consists of a single byte containing the length
// of the attribute name, followed by the attribute name.
......@@ -18,3 +24,12 @@ func stringsFromByteSlice(buf []byte) []string {
}
return result
}
func TestSysctlClockinfo(t *testing.T) {
ci, err := unix.SysctlClockinfo("kern.clockrate")
if err != nil {
t.Fatal(err)
}
t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v",
ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz)
}
......@@ -279,3 +279,9 @@ type Sysctlnode C.struct_sysctlnode
// Uname
type Utsname C.struct_utsname
// Clockinfo
const SizeofClockinfo = C.sizeof_struct_clockinfo
type Clockinfo C.struct_clockinfo
......@@ -446,3 +446,13 @@ type Utsname struct {
Version [256]byte
Machine [256]byte
}
const SizeofClockinfo = 0x14
type Clockinfo struct {
Hz int32
Tick int32
Tickadj int32
Stathz int32
Profhz int32
}
......@@ -453,3 +453,13 @@ type Utsname struct {
Version [256]byte
Machine [256]byte
}
const SizeofClockinfo = 0x14
type Clockinfo struct {
Hz int32
Tick int32
Tickadj int32
Stathz int32
Profhz int32
}
......@@ -451,3 +451,13 @@ type Utsname struct {
Version [256]byte
Machine [256]byte
}
const SizeofClockinfo = 0x14
type Clockinfo struct {
Hz int32
Tick int32
Tickadj int32
Stathz int32
Profhz int32
}
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