Skip to content

Commit

Permalink
add walltime for linux amd64/arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jul 2, 2024
1 parent a65d8e0 commit 8188558
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions walltime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build (linux && amd64) || (linux && arm64)

package log

func walltime() (sec int64, nsec int32)

Check failure on line 5 in walltime.go

View workflow job for this annotation

GitHub Actions / lint

func `walltime` is unused (unused)
26 changes: 26 additions & 0 deletions walltime.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "textflag.h"

#ifdef GOOS_linux
#ifdef GOARCH_amd64
// func walltime() (sec int64, nsec int32)
TEXT ·walltime(SB), NOSPLIT, $8-12
CALL runtime·nanotime1(SB)
MOVQ AX, ret+0(FP) // sec
MOVQ DX, ret+0(FP) // nsec
RET
#endif
#endif

#ifdef GOOS_linux
#ifdef GOARCH_arm64
// func walltime() (sec int64, nsec int32)
TEXT ·walltime(SB), NOSPLIT, $24-12
// Call runtime.walltime
CALL runtime·walltime(SB)
// Get the return values
MOVD R3, ret+0(FP) // sec
MOVW R5, ret+8(FP) // nsec
RET
#endif
#endif

16 changes: 16 additions & 0 deletions walltime_safe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build !((linux && amd64) || (linux && arm64))

package log

import (
_ "unsafe"
)

//go:noescape
//go:linkname time_now time.now
func time_now() (sec int64, nsec int32, mono int64)

func walltime() (sec int64, nsec int32) {
sec, nsec = time_now()
return
}

0 comments on commit 8188558

Please sign in to comment.