-
Notifications
You must be signed in to change notification settings - Fork 17.4k
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
runtime: on PPC64x, arm64, mips64x time.Now precision is in microseconds, not nanoseconds #11222
Comments
Originally I opened this as gccgo only, but now I see it applies to golang as well. The time.now function in sys_linux_ppc64x.s is calling gettimeofday which only has microsecond precision instead of nanosecond precision like Time is supposed. |
Fetch the current time in nanoseconds, not microseconds, by using clock_gettime rather than gettimeofday. Update golang/go#11222. Fixes https://gcc.gnu.org/PR66574. Change-Id: Ia9596f6a4b301ac0aa3b311e91106d0b9952ec3f Reviewed-on: https://go-review.googlesource.com/17156 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This is now fixed on gccgo mainline but the problem remains for the GNU/Linux targets arm64, mips64x, ppc64x. They should call clock_gettime, not gettimeday. |
As of go1.7rc3, I'm still seeing this as an issue, at least on ppc64le. Running the same test as above gives. start: 2016-07-27 14:21:51.111599 +0000 UTC since: 0 now: 2016-07-27 14:21:51.1116 +0000 UTC
start: 2016-07-27 14:21:51.112122 +0000 UTC since: 1000 now: 2016-07-27 14:21:51.112124 +0000 UTC
start: 2016-07-27 14:21:51.112142 +0000 UTC since: 1000 now: 2016-07-27 14:21:51.112144 +0000 UTC
start: 2016-07-27 14:21:51.112162 +0000 UTC since: 260000 now: 2016-07-27 14:21:51.112423 +0000 UTC
start: 2016-07-27 14:21:51.112441 +0000 UTC since: 1000 now: 2016-07-27 14:21:51.112443 +0000 UTC |
The bug is still open so that's not very surprising? |
We're going to look into fixing this for ppc64x. Just wondering if there was any additional information to share on this. We don't know if it is only wrong for ppc64x or still incorrect on the other platforms mentioned above. |
Fetch the current time in nanoseconds, not microseconds, by using clock_gettime rather than gettimeofday. Fixes golang#11222
CL https://golang.org/cl/26790 mentions this issue. |
Fetch the current time in nanoseconds, not microseconds, by using clock_gettime rather than gettimeofday. Updates #11222 Change-Id: I1c2c1b88f80ae82002518359436e19099061c6fb Reviewed-on: https://go-review.googlesource.com/26790 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Minux Ma <minux@golang.org>
Fetch the current time in nanoseconds, not microseconds, by using clock_gettime rather than gettimeofday. Updates golang#11222 Change-Id: I1c2c1b88f80ae82002518359436e19099061c6fb
Fetch the current time in nanoseconds, not microseconds, by using clock_gettime rather than gettimeofday. Updates golang#11222 Change-Id: I1c2c1b88f80ae82002518359436e19099061c6fb
I don't actually get where it is required that timestamps in Time format returned by time.Now() have actually nanosecond precision. Certainly not here: |
@vogtd, it's not required. It's nice. |
And also would be consistent between platforms. 👍 |
All right, so it's rather an improvement request than a bugreport. I'm a bit lost about about the status regarding s390[x]:
|
It is not yet fixed in golang for s390x. |
@vogtd The gofrontend used by gccgo uses different code to get the time. It already returns nanosecond precision for |
@ianlancetaylor interested in the case of s390x on 1.7 ie not using gccgo, as that is what we are using now. |
CL https://golang.org/cl/27710 mentions this issue. |
This should improve the precision of time.now() from microseconds to nanoseconds. Also, modify runtime.nanotime to keep it consistent with cleanup done to time.now. Updates #11222 for s390x. Change-Id: I27864115ea1fee7299360d9003cd3a8355f624d3 Reviewed-on: https://go-review.googlesource.com/27710 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Ian says gccgo is already OK. I assume it uses clock_gettime(CLOCK_REALTIME) always. As for the gc toolchain, I surveyed all the time.now implementations in runtime/*.s:
On OS X, there is no nanosecond system call. If the kernel equation is not available, the only fallback is gettimeofday (microseconds). On Linux, arm64 and mips64x should use clock_gettime(CLOCK_REALTIME). That's easy since there is assembly for clock_gettime(CLOCK_MONOTONIC) already that I can copy. I sent CL 32177 for those. Otherwise it looks like everything is fetching nanosecond precision already. Of course, precision does not imply accuracy. I doubt that windows is updating the kernel memory copy of the current time every 100ns, for example, and invoking a clock_gettime(CLOCK_REALTIME) system call to fetch the time at nanosecond accuracy may itself take 10s or 100s of nanoseconds. In fact precision does not even imply precision. There's no guarantee that the kernel is even computing nanoseconds during the system call. It might always come back with only microseconds, for example. But that's not Go's problem. |
CL https://golang.org/cl/32177 mentions this issue. |
libgo/runtime/go-nanotime.c calls gettimeofday which only provides microsecond precision, not the nanosecond precision that is documented for Time.
Here is a testcase that demonstrates the problem. I built it using gccgo from the latest gcc5 branch, and I can see the libgo code for go-nanotime.c is the same in trunk so would expect the same behavior there. The problem occurs on ppc64le and x86 with gccgo; did not try ppc64 but would expect that behavior there too. Problem does not occur with golang.
The value of 0 occurs intermittently for the "since" value in the output due to the lack of precision.
Could clock_gettime be called instead to get nanosecond precision?
The text was updated successfully, but these errors were encountered: