]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use monotonic clock for openbsd/386 and openbsd/amd64 timers
authorJoel Sing <jsing@google.com>
Wed, 26 Feb 2014 02:20:36 +0000 (13:20 +1100)
committerJoel Sing <jsing@google.com>
Wed, 26 Feb 2014 02:20:36 +0000 (13:20 +1100)
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
src/pkg/runtime/sys_openbsd_386.s
src/pkg/runtime/sys_openbsd_amd64.s

index c16276aca023207dc434af646da2df0416b371e6..714f907545c4f368b322535590189e21a73bfc5a 100644 (file)
@@ -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))
index d911e85c5393b9d4d1c51be0a7f307e9e61b21aa..8f0da5c0ee098f6dac1247c6687b517786d66c74 100644 (file)
@@ -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
index e5b7b01206d7ad1cd2676d7ac48cf962e29562a9..b2a61820a01b1639e1f92b9f663981a6ba7459f4 100644 (file)
@@ -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