diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index 6f8ebde3..639bcdef 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go @@ -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 { diff --git a/unix/syscall_netbsd_test.go b/unix/syscall_netbsd_test.go index de8c0797..3573a133 100644 --- a/unix/syscall_netbsd_test.go +++ b/unix/syscall_netbsd_test.go @@ -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) +} diff --git a/unix/types_netbsd.go b/unix/types_netbsd.go index 1494aafc..c49621ce 100644 --- a/unix/types_netbsd.go +++ b/unix/types_netbsd.go @@ -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 diff --git a/unix/ztypes_netbsd_386.go b/unix/ztypes_netbsd_386.go index 4b86fb2b..9e9088de 100644 --- a/unix/ztypes_netbsd_386.go +++ b/unix/ztypes_netbsd_386.go @@ -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 +} diff --git a/unix/ztypes_netbsd_amd64.go b/unix/ztypes_netbsd_amd64.go index 9048a509..ed3f1736 100644 --- a/unix/ztypes_netbsd_amd64.go +++ b/unix/ztypes_netbsd_amd64.go @@ -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 +} diff --git a/unix/ztypes_netbsd_arm.go b/unix/ztypes_netbsd_arm.go index 00525e7b..d263b614 100644 --- a/unix/ztypes_netbsd_arm.go +++ b/unix/ztypes_netbsd_arm.go @@ -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 +}