Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Fix convertion of seconds to nanoseconds.



details:   https://anonhg.NetBSD.org/src/rev/67b333b268d5
branches:  trunk
changeset: 574795:67b333b268d5
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sat Mar 12 16:29:59 2005 +0000

description:
Fix convertion of seconds to nanoseconds.
Add the usec to the secs before subtracting the usec offset - otherwise
I suspect the value can do horribly wrong!
Change all T_SVR4_GETHRESTIME to return sec + nanoseconds (I've not sure
this is correct, but I doubt the 32bit emulation in a 64bit kernel should
act differently to a 32bit kernel!)
Untested - I don't even have a sparc compile setup at the moment.

diffstat:

 sys/arch/sparc/sparc/svr4_machdep.c        |  65 +++++++++++-----------------
 sys/arch/sparc64/sparc64/svr4_32_machdep.c |  67 +++++++++++------------------
 sys/arch/sparc64/sparc64/svr4_machdep.c    |  67 +++++++++++------------------
 3 files changed, 77 insertions(+), 122 deletions(-)

diffs (truncated from 325 to 300 lines):

diff -r 5db044487d73 -r 67b333b268d5 sys/arch/sparc/sparc/svr4_machdep.c
--- a/sys/arch/sparc/sparc/svr4_machdep.c       Sat Mar 12 16:17:33 2005 +0000
+++ b/sys/arch/sparc/sparc/svr4_machdep.c       Sat Mar 12 16:29:59 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_machdep.c,v 1.54 2004/03/22 12:28:02 nakayama Exp $        */
+/*     $NetBSD: svr4_machdep.c,v 1.55 2005/03/12 16:29:59 dsl Exp $     */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.54 2004/03/22 12:28:02 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.55 2005/03/12 16:29:59 dsl Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_kgdb.h"
@@ -543,6 +543,10 @@
 {
        int n;
        struct trapframe *tf = l->l_md.md_tf;
+       struct schedstate_percpu *spc;
+       struct timeval tv;
+       uint64_t tm;
+       int s;
 
        if (l->l_proc->p_emul != &emul_svr4)
                return 0;
@@ -577,20 +581,14 @@
                 * guaranteed to be monotonically increasing, which we
                 * obtain from mono_time(9).
                 */
-               {
-                       struct timeval tv;
-                       quad_t tm;
-                       int s;
+               s = splclock();
+               tv = mono_time;
+               splx(s);
 
-                       s = splclock();
-                       tv = mono_time;
-                       splx(s);
-
-                       tm = (u_quad_t) tv.tv_sec * 1000000000 +
-                           (u_quad_t) tv.tv_usec * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffUL;
-               }
+               tm = tv.tv_usec * 1000u;
+               tm += tv.tv_sec * (uint64_t)1000000000u;
+               tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
+               tf->tf_out[1] = tm & 0x00000000ffffffffUL;
                break;
 
        case T_SVR4_GETHRVTIME:
@@ -601,39 +599,26 @@
                 * for now using the process's real time augmented with its
                 * current runtime is the best we can do.
                 */
-               {
-                       struct schedstate_percpu *spc =
-                           &curcpu()->ci_schedstate;
-                       struct timeval tv;
-                       quad_t tm;
+               spc = &curcpu()->ci_schedstate;
 
-                       microtime(&tv);
+               microtime(&tv);
 
-                       tm =
-                           (u_quad_t) (l->l_proc->p_rtime.tv_sec +
-                                       tv.tv_sec -
-                                           spc->spc_runtime.tv_sec)
-                                       * 1000000 +
-                           (u_quad_t) (l->l_proc->p_rtime.tv_usec +
-                                       tv.tv_usec -
-                                           spc->spc_runtime.tv_usec)
-                                       * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffUL;
-               }
+               tm = (l->l_proc->p_rtime.tv_sec + tv.tv_sec -
+                               spc->spc_runtime.tv_sec) * (uint64_t)1000000u;
+               tm += l->l_proc->p_rtime.tv_usec + tv.tv_usec;
+               tm -= spc->spc_runtime.tv_usec;
+               tm *= 1000;
+               tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
+               tf->tf_out[1] = tm & 0x00000000ffffffffUL;
                break;
 
        case T_SVR4_GETHRESTIME:
                /*
                 * This is used by gettimeofday(3), among other things.
                 */
-               {
-                       struct timeval  tv;
-
-                       microtime(&tv);
-                       tf->tf_out[0] = tv.tv_sec;
-                       tf->tf_out[1] = tv.tv_usec * 1000;
-               }
+               microtime(&tv);
+               tf->tf_out[0] = tv.tv_sec;
+               tf->tf_out[1] = tv.tv_usec * 1000;
                break;
 
        default:
diff -r 5db044487d73 -r 67b333b268d5 sys/arch/sparc64/sparc64/svr4_32_machdep.c
--- a/sys/arch/sparc64/sparc64/svr4_32_machdep.c        Sat Mar 12 16:17:33 2005 +0000
+++ b/sys/arch/sparc64/sparc64/svr4_32_machdep.c        Sat Mar 12 16:29:59 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_32_machdep.c,v 1.18 2003/11/09 16:41:53 martin Exp $       */
+/*     $NetBSD: svr4_32_machdep.c,v 1.19 2005/03/12 16:29:59 dsl Exp $  */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_32_machdep.c,v 1.18 2003/11/09 16:41:53 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_32_machdep.c,v 1.19 2005/03/12 16:29:59 dsl Exp $");
 
 #ifndef _LKM
 #include "opt_ddb.h"
@@ -593,6 +593,10 @@
        int n;
        struct proc *p = l->l_proc;
        struct trapframe64 *tf = l->l_md.md_tf;
+       struct schedstate_percpu *spc;
+       struct timeval tv;
+       uint64_t tm;
+       int s;
 
        if (p->p_emul != &emul_svr4_32)
                return 0;
@@ -621,20 +625,14 @@
                 * guaranteed to be monotonically increasing, which we
                 * obtain from mono_time(9).
                 */
-               {
-                       struct timeval tv;
-                       quad_t tm;
-                       int s;
+               s = splclock();
+               tv = mono_time;
+               splx(s);
 
-                       s = splclock();
-                       tv = mono_time;
-                       splx(s);
-
-                       tm = (u_quad_t) tv.tv_sec * 1000000000 +
-                           (u_quad_t) tv.tv_usec * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffffUL;
-               }
+               tm = tv.tv_usec * 1000u;
+               tm += tv.tv_sec * (uint64_t)1000000000u;
+               tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffffUL;
+               tf->tf_out[1] = tm & 0x00000000ffffffffffUL;
                break;
 
        case T_SVR4_GETHRVTIME:
@@ -645,37 +643,24 @@
                 * for now using the process's real time augmented with its
                 * current runtime is the best we can do.
                 */
-               {
-                       struct schedstate_percpu *spc =
-                           &curcpu()->ci_schedstate;
-                       struct timeval tv;
-                       quad_t tm;
+               spc = &curcpu()->ci_schedstate;
 
-                       microtime(&tv);
+               microtime(&tv);
 
-                       tm =
-                           (u_quad_t) (p->p_rtime.tv_sec +
-                                       tv.tv_sec -
-                                           spc->spc_runtime.tv_sec)
-                                       * 1000000 +
-                           (u_quad_t) (p->p_rtime.tv_usec +
-                                       tv.tv_usec -
-                                           spc->spc_runtime.tv_usec)
-                                       * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffffUL;
-               }
+               tm = (p->p_rtime.tv_sec + tv.tv_sec -
+                       spc->spc_runtime.tv_sec) * (uint64_t)1000000u;
+               tm += p->p_rtime.tv_usec + tv.tv_usec;
+               tm -= spc->spc_runtime.tv_usec;
+               tm *= 1000;
+               tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffffUL;
+               tf->tf_out[1] = tm & 0x00000000ffffffffffUL;
                break;
 
        case T_SVR4_GETHRESTIME:
-               {
-                       /* I assume this is like gettimeofday(3) */
-                       struct timeval  tv;
-
-                       microtime(&tv);
-                       tf->tf_out[0] = tv.tv_sec;
-                       tf->tf_out[1] = tv.tv_usec;
-               }
+               /* I assume this is like gettimeofday(3) */
+               microtime(&tv);
+               tf->tf_out[0] = tv.tv_sec;
+               tf->tf_out[1] = tv.tv_usec * 1000u;
                break;
 
        default:
diff -r 5db044487d73 -r 67b333b268d5 sys/arch/sparc64/sparc64/svr4_machdep.c
--- a/sys/arch/sparc64/sparc64/svr4_machdep.c   Sat Mar 12 16:17:33 2005 +0000
+++ b/sys/arch/sparc64/sparc64/svr4_machdep.c   Sat Mar 12 16:29:59 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svr4_machdep.c,v 1.36 2004/03/22 12:28:02 nakayama Exp $        */
+/*     $NetBSD: svr4_machdep.c,v 1.37 2005/03/12 16:29:59 dsl Exp $     */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.36 2004/03/22 12:28:02 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: svr4_machdep.c,v 1.37 2005/03/12 16:29:59 dsl Exp $");
 
 #ifndef _LKM
 #include "opt_ddb.h"
@@ -627,6 +627,10 @@
        struct proc *p = l->l_proc;
        int n;
        struct trapframe64 *tf = l->l_md.md_tf;
+       struct schedstate_percpu *spc;
+       struct timeval tv;
+       uint64_t tm;
+       int s;
 
        if (p->p_emul != &emul_svr4)
                return 0;
@@ -655,20 +659,14 @@
                 * guaranteed to be monotonically increasing, which we
                 * obtain from mono_time(9).
                 */
-               {
-                       struct timeval tv;
-                       quad_t tm;
-                       int s;
+               s = splclock();
+               tv = mono_time;
+               splx(s);
 
-                       s = splclock();
-                       tv = mono_time;
-                       splx(s);
-
-                       tm = (u_quad_t) tv.tv_sec * 1000000000 +
-                           (u_quad_t) tv.tv_usec * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffUL;
-               }
+               tm = tv.tv_usec * 1000u;
+               tm += tv.tv_sec * (uint64_t)1000000000u;
+               tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
+               tf->tf_out[1] = tm & 0x00000000ffffffffUL;
                break;
 
        case T_SVR4_GETHRVTIME:
@@ -679,37 +677,24 @@
                 * for now using the process's real time augmented with its
                 * current runtime is the best we can do.
                 */
-               {
-                       struct schedstate_percpu *spc =
-                           &curcpu()->ci_schedstate;
-                       struct timeval tv;
-                       quad_t tm;
+               spc = &curcpu()->ci_schedstate;
 
-                       microtime(&tv);
+               microtime(&tv);
 
-                       tm =
-                           (u_quad_t) (p->p_rtime.tv_sec +
-                                       tv.tv_sec -
-                                           spc->spc_runtime.tv_sec)
-                                       * 1000000 +
-                           (u_quad_t) (p->p_rtime.tv_usec +
-                                       tv.tv_usec -
-                                           spc->spc_runtime.tv_usec)
-                                       * 1000;
-                       tf->tf_out[0] = (tm >> 32) & 0x00000000ffffffffUL;
-                       tf->tf_out[1] = tm & 0x00000000ffffffffUL;
-               }



Home | Main Index | Thread Index | Old Index