Module Name: src Committed By: tls Date: Sat Jan 26 22:22:07 UTC 2013
Modified Files: src/sys/kern: kern_rndq.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/kern/kern_rndq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_rndq.c diff -u src/sys/kern/kern_rndq.c:1.9 src/sys/kern/kern_rndq.c:1.10 --- src/sys/kern/kern_rndq.c:1.9 Sat Jan 26 19:05:12 2013 +++ src/sys/kern/kern_rndq.c Sat Jan 26 22:22:07 2013 @@ -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 @@ rnd_attach_source(krndsource_t *rs, cons rs->total = 0; /* - * Force network devices to not collect any entropy by - * default. + * Some source setup, by type */ - if (type == RND_TYPE_NET) - flags |= (RND_FLAG_NO_COLLECT | RND_FLAG_NO_ESTIMATE); + rs->test = NULL; + rs->test_cnt = -1; - /* - * Hardware RNGs get extra space for statistical testing. - */ - if (type == RND_TYPE_RNG) { + switch (type) { + case RND_TYPE_NET: /* Don't collect by default */ + flags |= (RND_FLAG_NO_COLLECT | RND_FLAG_NO_ESTIMATE); + 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 @@ rnd_add_data_ts(krndsource_t *rs, const 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 "