Hi all,
I'm trying to get time using `CLOCK_REALTIME_COARSE` and
`CLOCK_MONOTONIC_COARSE` for performance reasons, and need to use vdso call
by hand-written assembly code. That is, I want to reimplement `time.Now`
using `CLOCK_REALTIME_COARSE` and `CLOCK_MONOTONIC_COARSE`.
I referenced the code in runtime and found that there's an issue #20427
indicates that I need to switch to g0 for vdso calls, so I tried two
methods but neither is good.
## The first method
The first method I tried is just copy the code in runtime and simply change
the clockid, but this requires copying all the runtime type definations as
well to make the compiler generate "go_asm.h" for me.
The code runs well, but this is really ugly and unmaintainable as the type
definations may change across different go versions.
## The second method
The second method I tried is to link the `runtime.systemstack` and use it
to do vdso calls:
```go
//go:linkname systemstack runtime.systemstack
//go:noescape
func systemstack(fn func())
```
My code is something like this:
```go
// now calls vdso and is implemented in asm
func now() (sec int64, nsec int32, mono int64)
func Now() {
var sec, mono int64
var nsec int32
systemstack(func() {
sec, nsec, mono = now()
})
... // logic copied from time.Now()
}
```
The code runs well without `-race`(test isn't enough), but I encountered
fatal error under `-race` mode.
For detailed information, I've filed an issue:
https://github.com/golang/go/issues/45768.
## The right way?
So I really want to know what is the right way to do vdso call outside
runtime?
Thanks very much!
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/49e183dc-4f13-4627-b0ae-cab2c15ae931n%40googlegroups.com.