Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: missing Linux clock_adjtime #57618

Closed
jclark opened this issue Jan 5, 2023 · 6 comments
Closed

x/sys/unix: missing Linux clock_adjtime #57618

jclark opened this issue Jan 5, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jclark
Copy link

jclark commented Jan 5, 2023

What version of Go are you using (go version)?

$ go version
go version go1.19.4 linux/amd64

Does this issue reproduce with the latest release?

Yes (with 1.19.4)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jjc/.cache/go-build"
GOENV="/home/jjc/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jjc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jjc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jjc/gps2phc/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4114271922=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.19.4 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.19.4
uname -sr: Linux 6.0.12-300.fc37.x86_64
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.36.
gdb --version: GNU gdb (GDB) Fedora Linux 12.1-6.fc37

What did you do?

Try to use unix.ClockAdjtime

What did you expect to see?

ClockAdjtime available in unix package.

clock_adjtime is like adjtimex but takes a clockid_t as it's first arg.

https://man7.org/linux/man-pages/man2/adjtimex.2.html

The unix pkg provides adjtimex and the associated Timex struct. It also provides the other functions that take a clockid_t (like ClockGettime).

clock_adjtime is needed by programs that use PTP Hardware Clocks (e.g. https://github.com/facebook/time/blob/ecba0ea401caa4cd45f6bb2d261946cc5cc52a5d/phc/phc.go#L131)

What did you see instead?

I got an error:

ClockAdjtime is not declared by package unix

Fix

It can be written using Syscall like this:

func ClockAdjtime(clockid uint32, buf *unix.Timex) (state int, err error) {
	err = nil
	r0, _, e1 := unix.Syscall(unix.SYS_CLOCK_ADJTIME, uintptr(clockid), uintptr(unsafe.Pointer(buf)), 0)
	state = int(r0)
	if e1 != 0 {
		err = e1
	}
	return
}

I think it can be fixed in the unix package just by adding

//sys ClockAdjtime(clockid int32, buf *Timex) (state int, err error)

to syscall_unix.go around line 1802.

@seankhliao seankhliao changed the title sys/unix: missing Linux clock_adjtime x/sys/unix: missing Linux clock_adjtime Jan 5, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 5, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jan 5, 2023
@seankhliao
Copy link
Member

seankhliao commented Jan 5, 2023

feel free to send a CL

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 5, 2023
@AxeZhan
Copy link

AxeZhan commented Jan 19, 2023

Hi, forks. I'm a newcomer who wants to contribute to the community. Can I assign myself and try to solve this issue? :)

@ianlancetaylor
Copy link
Contributor

@kidddddddddddddddddddddd Go for it. Thanks.

@AxeZhan
Copy link

AxeZhan commented Jan 20, 2023

Thanks
/assign

@AxeZhan
Copy link

AxeZhan commented Jan 20, 2023

Got stucked by generate codes😅.
When I ran dockerfile directly it says can't find mkall.go. When I ran it manully and mount this repo, some error will occuer when merging the files.
I wonder what's the right command to generate files?

@gopherbot
Copy link

Change https://go.dev/cl/463056 mentions this issue: x/sys/unix: add support for clock_adjtime on Linux

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FeatureRequest FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants