From 373466380586b04b8a9163938a8daf3f5cb9dd45 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Wed, 26 Feb 2014 13:20:36 +1100 Subject: [PATCH] runtime: use monotonic clock for openbsd/386 and openbsd/amd64 timers Switch nanotime to a monotonic clock on openbsd/386 and openbsd/amd64. Also use a monotonic clock when for thrsleep, since the sleep duration is based on the value returned from nanotime. Update #6007 LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/68460044 --- src/pkg/runtime/os_openbsd.c | 2 +- src/pkg/runtime/sys_openbsd_386.s | 4 +++- src/pkg/runtime/sys_openbsd_amd64.s | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pkg/runtime/os_openbsd.c b/src/pkg/runtime/os_openbsd.c index c16276aca0..714f907545 100644 --- a/src/pkg/runtime/os_openbsd.c +++ b/src/pkg/runtime/os_openbsd.c @@ -82,7 +82,7 @@ runtime·semasleep(int64 ns) // NOTE: tv_nsec is int64 on amd64, so this assumes a little-endian system. ts.tv_nsec = 0; ts.tv_sec = runtime·timediv(ns, 1000000000, (int32*)&ts.tv_nsec); - runtime·thrsleep(&m->waitsemacount, CLOCK_REALTIME, &ts, &m->waitsemalock, nil); + runtime·thrsleep(&m->waitsemacount, CLOCK_MONOTONIC, &ts, &m->waitsemalock, nil); } // reacquire lock while(runtime·xchg(&m->waitsemalock, 1)) diff --git a/src/pkg/runtime/sys_openbsd_386.s b/src/pkg/runtime/sys_openbsd_386.s index d911e85c53..8f0da5c0ee 100644 --- a/src/pkg/runtime/sys_openbsd_386.s +++ b/src/pkg/runtime/sys_openbsd_386.s @@ -9,6 +9,8 @@ #include "zasm_GOOS_GOARCH.h" #include "../../cmd/ld/textflag.h" +#define CLOCK_MONOTONIC $3 + // Exit the entire program (like C exit) TEXT runtime·exit(SB),NOSPLIT,$-4 MOVL $1, AX @@ -133,7 +135,7 @@ TEXT time·now(SB), NOSPLIT, $32 // void nanotime(int64 *nsec) TEXT runtime·nanotime(SB),NOSPLIT,$32 LEAL 12(SP), BX - MOVL $0, 4(SP) // arg 1 - clock_id + MOVL CLOCK_MONOTONIC, 4(SP) // arg 1 - clock_id MOVL BX, 8(SP) // arg 2 - tp MOVL $87, AX // sys_clock_gettime INT $0x80 diff --git a/src/pkg/runtime/sys_openbsd_amd64.s b/src/pkg/runtime/sys_openbsd_amd64.s index e5b7b01206..b2a61820a0 100644 --- a/src/pkg/runtime/sys_openbsd_amd64.s +++ b/src/pkg/runtime/sys_openbsd_amd64.s @@ -9,6 +9,8 @@ #include "zasm_GOOS_GOARCH.h" #include "../../cmd/ld/textflag.h" +#define CLOCK_MONOTONIC $3 + // int64 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void)); TEXT runtime·tfork(SB),NOSPLIT,$32 @@ -166,7 +168,7 @@ TEXT time·now(SB), NOSPLIT, $32 RET TEXT runtime·nanotime(SB),NOSPLIT,$24 - MOVQ $0, DI // arg 1 - clock_id + MOVQ CLOCK_MONOTONIC, DI // arg 1 - clock_id LEAQ 8(SP), SI // arg 2 - tp MOVL $87, AX // sys_clock_gettime SYSCALL -- 2.48.1