From 94015fc9d65b0f46ae877b85edfa1c9d30304ae1 Mon Sep 17 00:00:00 2001 From: dsl Date: Sat, 12 Mar 2005 16:29:59 +0000 Subject: [PATCH] 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. --- 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(-) diff --git a/sys/arch/sparc/sparc/svr4_machdep.c b/sys/arch/sparc/sparc/svr4_machdep.c index 6b2e7f10bd97..73ec394539f8 100644 --- a/sys/arch/sparc/sparc/svr4_machdep.c +++ b/sys/arch/sparc/sparc/svr4_machdep.c @@ -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 -__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 @@ svr4_trap(type, l) { 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 @@ svr4_trap(type, l) * 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 @@ svr4_trap(type, l) * 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 --git a/sys/arch/sparc64/sparc64/svr4_32_machdep.c b/sys/arch/sparc64/sparc64/svr4_32_machdep.c index f4b615a8d971..678c06a7f712 100644 --- a/sys/arch/sparc64/sparc64/svr4_32_machdep.c +++ b/sys/arch/sparc64/sparc64/svr4_32_machdep.c @@ -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 -__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 @@ svr4_32_trap(type, l) 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 @@ svr4_32_trap(type, l) * 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 @@ svr4_32_trap(type, l) * 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 --git a/sys/arch/sparc64/sparc64/svr4_machdep.c b/sys/arch/sparc64/sparc64/svr4_machdep.c index 8ec3da113f6a..be7847d66cc3 100644 --- a/sys/arch/sparc64/sparc64/svr4_machdep.c +++ b/sys/arch/sparc64/sparc64/svr4_machdep.c @@ -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 -__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 @@ svr4_trap(type, l) 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 @@ svr4_trap(type, l) * 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 @@ svr4_trap(type, l) * 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; - } + 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) & 0x00000000ffffffffUL; + tf->tf_out[1] = tm & 0x00000000ffffffffUL; 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: