Skip to content

runtime: use vDSO clock_gettime on linux/mips64x #35181

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/os_linux_novdso.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// +build linux
// +build !386,!amd64,!arm,!arm64,!ppc64,!ppc64le
// +build !386,!amd64,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le

package runtime

Expand Down
78 changes: 74 additions & 4 deletions src/runtime/sys_linux_mips64x.s
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,88 @@ TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28

// func walltime1() (sec int64, nsec int32)
TEXT runtime·walltime1(SB),NOSPLIT,$16
MOVV R29, R16 // R16 is unchanged by C code
MOVV R29, R1

MOVV g_m(g), R17 // R17 = m

// Set vdsoPC and vdsoSP for SIGPROF traceback.
MOVV R31, m_vdsoPC(R17)
MOVV R29, m_vdsoSP(R17)

MOVV m_curg(R17), R4
MOVV g, R5
BNE R4, R5, noswitch

MOVV m_g0(R17), R4
MOVV (g_sched+gobuf_sp)(R4), R1 // Set SP to g0 stack

noswitch:
SUBV $16, R1
AND $~15, R1 // Align for C code
MOVV R1, R29

MOVW $0, R4 // CLOCK_REALTIME
MOVV $0(R29), R5
MOVV $SYS_clock_gettime, R2
SYSCALL

MOVV runtime·vdsoClockgettimeSym(SB), R25
BEQ R25, fallback

JAL (R25)

finish:
MOVV 0(R29), R3 // sec
MOVV 8(R29), R5 // nsec

MOVV R16, R29 // restore SP
MOVV R0, m_vdsoSP(R17) // clear vdsoSP

MOVV R3, sec+0(FP)
MOVW R5, nsec+8(FP)
RET

fallback:
MOVV $SYS_clock_gettime, R2
SYSCALL
JMP finish

TEXT runtime·nanotime1(SB),NOSPLIT,$16
MOVV R29, R16 // R16 is unchanged by C code
MOVV R29, R1

MOVV g_m(g), R17 // R17 = m

// Set vdsoPC and vdsoSP for SIGPROF traceback.
MOVV R31, m_vdsoPC(R17)
MOVV R29, m_vdsoSP(R17)

MOVV m_curg(R17), R4
MOVV g, R5
BNE R4, R5, noswitch

MOVV m_g0(R17), R4
MOVV (g_sched+gobuf_sp)(R4), R1 // Set SP to g0 stack

noswitch:
SUBV $16, R1
AND $~15, R1 // Align for C code
MOVV R1, R29

MOVW $1, R4 // CLOCK_MONOTONIC
MOVV $0(R29), R5
MOVV $SYS_clock_gettime, R2
SYSCALL

MOVV runtime·vdsoClockgettimeSym(SB), R25
BEQ R25, fallback

JAL (R25)

finish:
MOVV 0(R29), R3 // sec
MOVV 8(R29), R5 // nsec

MOVV R16, R29 // restore SP
MOVV R0, m_vdsoSP(R17) // clear vdsoSP

// sec is in R3, nsec in R5
// return nsec in R3
MOVV $1000000000, R4
Expand All @@ -237,6 +302,11 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$16
MOVV R3, ret+0(FP)
RET

fallback:
MOVV $SYS_clock_gettime, R2
SYSCALL
JMP finish

TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28
MOVW how+0(FP), R4
MOVV new+8(FP), R5
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/vdso_elf64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// +build linux
// +build amd64 arm64 ppc64 ppc64le
// +build amd64 arm64 mips64 mips64le ppc64 ppc64le

package runtime

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/vdso_in_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build linux,!386,!amd64,!arm,!arm64,!ppc64,!ppc64le !linux
// +build linux,!386,!amd64,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le !linux

package runtime

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/vdso_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// +build linux
// +build 386 amd64 arm arm64 ppc64 ppc64le
// +build 386 amd64 arm arm64 mips64 mips64le ppc64 ppc64le

package runtime

Expand Down
28 changes: 28 additions & 0 deletions src/runtime/vdso_linux_mips64x.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 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 linux
// +build mips64 mips64le

package runtime

const (
// vdsoArrayMax is the byte-size of a maximally sized array on this architecture.
// See cmd/compile/internal/mips64/galign.go arch.MAXWIDTH initialization.
vdsoArrayMax = 1<<50 - 1
)

// see man 7 vdso : mips
var vdsoLinuxVersion = vdsoVersionKey{"LINUX_2.6", 0x3ae75f6}

// The symbol name is not __kernel_clock_gettime as suggested by the manpage;
// according to Linux source code it should be __vdso_clock_gettime instead.
var vdsoSymbolKeys = []vdsoSymbolKey{
{"__vdso_clock_gettime", 0xd35ec75, 0x6e43a318, &vdsoClockgettimeSym},
}

// initialize to fall back to syscall
var (
vdsoClockgettimeSym uintptr = 0
)