Source-Changes-HG archive

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

[src/trunk]: src/sys Use binuptime, not microtime/nanotime as substitute cycl...



details:   https://anonhg.NetBSD.org/src/rev/9efb9966da51
branches:  trunk
changeset: 337424:9efb9966da51
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Apr 14 12:25:41 2015 +0000

description:
Use binuptime, not microtime/nanotime as substitute cycle counter.

diffstat:

 sys/dev/rndpseudo.c  |  22 ++++++++++++++--------
 sys/kern/kern_rndq.c |  26 ++++++++++++++------------
 2 files changed, 28 insertions(+), 20 deletions(-)

diffs (104 lines):

diff -r ce7eff5dddb3 -r 9efb9966da51 sys/dev/rndpseudo.c
--- a/sys/dev/rndpseudo.c       Tue Apr 14 12:21:12 2015 +0000
+++ b/sys/dev/rndpseudo.c       Tue Apr 14 12:25:41 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rndpseudo.c,v 1.28 2015/04/14 12:21:12 riastradh Exp $ */
+/*     $NetBSD: rndpseudo.c,v 1.29 2015/04/14 12:25:41 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.28 2015/04/14 12:21:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rndpseudo.c,v 1.29 2015/04/14 12:25:41 riastradh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -156,20 +156,26 @@
 EVCNT_ATTACH_STATIC(rndpseudo_hard);
 
 /*
- * Generate a 32-bit counter.  This should be more machine dependent,
- * using cycle counters and the like when possible.
+ * Generate a 32-bit counter.
  */
-static inline u_int32_t
+static inline uint32_t
 rndpseudo_counter(void)
 {
-       struct timeval tv;
+       struct bintime bt;
+       uint32_t ret;
 
 #if defined(__HAVE_CPU_COUNTER)
        if (cpu_hascounter())
                return (cpu_counter32());
 #endif
-       microtime(&tv);
-       return (tv.tv_sec * 1000000 + tv.tv_usec);
+
+       binuptime(&bt);
+       ret = bt.sec;
+       ret |= bt.sec >> 32;
+       ret |= bt.frac;
+       ret |= bt.frac >> 32;
+
+       return ret;
 }
 
 /*
diff -r ce7eff5dddb3 -r 9efb9966da51 sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c      Tue Apr 14 12:21:12 2015 +0000
+++ b/sys/kern/kern_rndq.c      Tue Apr 14 12:25:41 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rndq.c,v 1.48 2015/04/14 11:59:40 riastradh Exp $ */
+/*     $NetBSD: kern_rndq.c,v 1.49 2015/04/14 12:25:41 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.48 2015/04/14 11:59:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.49 2015/04/14 12:25:41 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -223,22 +223,24 @@
 static inline uint32_t
 rnd_counter(void)
 {
-       struct timespec ts;
+       struct bintime bt;
        uint32_t ret;
 
 #if defined(__HAVE_CPU_COUNTER)
        if (cpu_hascounter())
                return cpu_counter32();
 #endif
-       if (rnd_ready) {
-               nanouptime(&ts);
-               ret = ts.tv_sec;
-               ret *= (uint32_t)1000000000;
-               ret += ts.tv_nsec;
-               return ret;
-       }
-       /* when called from rnd_init, its too early to call nanotime safely */
-       return (0);
+       if (!rnd_ready)
+               /* Too early to call nanotime.  */
+               return 0;
+
+       binuptime(&bt);
+       ret = bt.sec;
+       ret |= bt.sec >> 32;
+       ret |= bt.frac;
+       ret |= bt.frac >> 32;
+
+       return ret;
 }
 
 /*



Home | Main Index | Thread Index | Old Index