From c3037ed0666d1dad5d522fdbd0822b0adf3e9374 Mon Sep 17 00:00:00 2001 From: James Clark Date: Wed, 25 Jan 2023 17:50:15 +0700 Subject: [PATCH] unix: add support for clock_adjtime on Linux This provides a ClockAdjtime function providing access to the clock_adjtime system call on Linux. The clock_adjtime system call is like adjtimex, but takes a clockid_t as its first argument. The unix package already provides Adjtimex and the associated Timex struct; it also provides the other functions that take a clockid_t (like ClockGettime). ClockAdjtime is an essential system call for programs that want to use the Linux PTP hardware clock infrastructure (see https://docs.kernel.org/driver-api/ptp.html). Fixes golang/go#57618 Change-Id: I68d022425eb9cd394a204ad7fedab985c0496fee Reviewed-on: https://go-review.googlesource.com/c/sys/+/463056 Reviewed-by: Tobias Klauser Reviewed-by: Bryan Mills Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor --- unix/syscall_linux.go | 1 + unix/zsyscall_linux.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index bea511fc..5443dddd 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1800,6 +1800,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sysnb Capset(hdr *CapUserHeader, data *CapUserData) (err error) //sys Chdir(path string) (err error) //sys Chroot(path string) (err error) +//sys ClockAdjtime(clockid int32, buf *Timex) (state int, err error) //sys ClockGetres(clockid int32, res *Timespec) (err error) //sys ClockGettime(clockid int32, time *Timespec) (err error) //sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error) diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 293cf368..36ea3a55 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -537,6 +537,17 @@ func Chroot(path string) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ClockAdjtime(clockid int32, buf *Timex) (state int, err error) { + r0, _, e1 := Syscall(SYS_CLOCK_ADJTIME, uintptr(clockid), uintptr(unsafe.Pointer(buf)), 0) + state = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ClockGetres(clockid int32, res *Timespec) (err error) { _, _, e1 := Syscall(SYS_CLOCK_GETRES, uintptr(clockid), uintptr(unsafe.Pointer(res)), 0) if e1 != 0 {