Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Tweak the previous a little: don't be so hasty to d...



details:   https://anonhg.NetBSD.org/src/rev/344407a4cc52
branches:  trunk
changeset: 784371:344407a4cc52
user:      tls <tls%NetBSD.org@localhost>
date:      Sat Jan 26 22:22:07 2013 +0000

description:
Tweak the previous a little: don't be so hasty to declare sources "fast"
and process them in bulk, but, always declare hardware RNGs and VM system
sources as "fast" since in these cases efficiency is important and data
will be abundant.

diffstat:

 sys/kern/kern_rndq.c |  34 +++++++++++++++++++---------------
 1 files changed, 19 insertions(+), 15 deletions(-)

diffs (66 lines):

diff -r 798e71ca625f -r 344407a4cc52 sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c      Sat Jan 26 22:04:18 2013 +0000
+++ b/sys/kern/kern_rndq.c      Sat Jan 26 22:22:07 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rndq.c,v 1.9 2013/01/26 19:05:12 tls Exp $        */
+/*     $NetBSD: kern_rndq.c,v 1.10 2013/01/26 22:22:07 tls 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.9 2013/01/26 19:05:12 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.10 2013/01/26 22:22:07 tls Exp $");
 
 #include <sys/param.h>
 #include <sys/ioctl.h>
@@ -522,21 +522,24 @@
        rs->total = 0;
 
        /*
-        * Force network devices to not collect any entropy by
-        * default.
+        * Some source setup, by type
         */
-       if (type == RND_TYPE_NET)
+       rs->test = NULL;
+       rs->test_cnt = -1;
+
+       switch (type) {
+           case RND_TYPE_NET:          /* Don't collect by default */
                flags |= (RND_FLAG_NO_COLLECT | RND_FLAG_NO_ESTIMATE);
-
-       /*
-        * Hardware RNGs get extra space for statistical testing.
-        */
-       if (type == RND_TYPE_RNG) {
+               break;
+           case RND_TYPE_RNG:          /* Space for statistical testing */
                rs->test = kmem_alloc(sizeof(rngtest_t), KM_NOSLEEP);
                rs->test_cnt = 0;
-       } else {
-               rs->test = NULL;
-               rs->test_cnt = -1;
+               /* FALLTHRU */
+           case RND_TYPE_VM:           /* Process samples in bulk always */
+               flags |= RND_FLAG_FAST;
+               break;
+           default:
+               break;
        }
 
        rs->type = type;
@@ -681,8 +684,9 @@
 
                        getmicrouptime(&upt);
                        if ((todo >= RND_SAMPLE_COUNT) ||
-                           (rs->total > upt.tv_sec) ||
-                            (upt.tv_sec > 10 &&
+                           (rs->total > upt.tv_sec * 10) ||
+                           (upt.tv_sec > 10 && rs->total > upt.tv_sec) ||
+                           (upt.tv_sec > 100 &&
                              rs->total > upt.tv_sec / 10)) {
 #ifdef RND_VERBOSE
                                printf("rnd: source %s is fast (%d samples "



Home | Main Index | Thread Index | Old Index