Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Rather than holding samples from each source until we ha...
details: https://anonhg.NetBSD.org/src/rev/45fe8ba423c7
branches: trunk
changeset: 784361:45fe8ba423c7
user: tls <tls%NetBSD.org@localhost>
date: Sat Jan 26 19:05:11 2013 +0000
description:
Rather than holding samples from each source until we have 64 at a time to
process, process them ASAP for low-rate sources, and for all sources if we
have not yet acquired initial entropy.
diffstat:
sys/kern/kern_rndq.c | 46 +++++++++++++++++++++++++++++++++++-----------
sys/sys/rnd.h | 3 ++-
2 files changed, 37 insertions(+), 12 deletions(-)
diffs (111 lines):
diff -r 73867ba19a62 -r 45fe8ba423c7 sys/kern/kern_rndq.c
--- a/sys/kern/kern_rndq.c Sat Jan 26 18:44:21 2013 +0000
+++ b/sys/kern/kern_rndq.c Sat Jan 26 19:05:11 2013 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: kern_rndq.c,v 1.8 2013/01/24 14:23:45 riastradh Exp $ */
+/* $NetBSD: kern_rndq.c,v 1.9 2013/01/26 19:05:12 tls Exp $ */
/*-
- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.8 2013/01/24 14:23:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.9 2013/01/26 19:05:12 tls Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -80,12 +80,6 @@
#endif
/*
- * The size of a temporary buffer, kmem_alloc()ed when needed, and used for
- * reading and writing data.
- */
-#define RND_TEMP_BUFFER_SIZE 128
-
-/*
* This is a little bit of state information attached to each device that we
* collect entropy from. This is simply a collection buffer, and when it
* is full it will be "detached" from the source and added to the entropy
@@ -665,6 +659,7 @@
rnd_sample_t *state = NULL;
const uint32_t *dint = data;
int todo, done, filled = 0;
+ int sample_count;
SIMPLEQ_HEAD(, _rnd_sample_t) tmp_samples =
SIMPLEQ_HEAD_INITIALIZER(tmp_samples);
@@ -672,11 +667,40 @@
return;
}
+ todo = len / sizeof(*dint);
+ /*
+ * Let's try to be efficient: if we are warm, and a source
+ * is adding entropy at a rate of at least 1 bit every 10 seconds,
+ * mark it as "fast" and add its samples in bulk.
+ */
+ if (__predict_true(rs->flags & RND_FLAG_FAST)) {
+ sample_count = RND_SAMPLE_COUNT;
+ } else {
+ if (!cold && rnd_initial_entropy) {
+ struct timeval upt;
+
+ getmicrouptime(&upt);
+ if ((todo >= RND_SAMPLE_COUNT) ||
+ (rs->total > upt.tv_sec) ||
+ (upt.tv_sec > 10 &&
+ rs->total > upt.tv_sec / 10)) {
+#ifdef RND_VERBOSE
+ printf("rnd: source %s is fast (%d samples "
+ "at once, %d bits in %lld seconds), "
+ "processing samples in bulk.\n",
+ rs->name, todo, rs->total,
+ (long long int)upt.tv_sec);
+#endif
+ rs->flags |= RND_FLAG_FAST;
+ }
+ }
+ sample_count = 2;
+ }
+
/*
* Loop over data packaging it into sample buffers.
* If a sample buffer allocation fails, drop all data.
*/
- todo = len / sizeof(*dint);
for (done = 0; done < todo ; done++) {
state = rs->state;
if (state == NULL) {
@@ -691,7 +715,7 @@
state->values[state->cursor] = dint[done];
state->cursor++;
- if (state->cursor == RND_SAMPLE_COUNT) {
+ if (state->cursor == sample_count) {
SIMPLEQ_INSERT_HEAD(&tmp_samples, state, next);
filled++;
rs->state = NULL;
diff -r 73867ba19a62 -r 45fe8ba423c7 sys/sys/rnd.h
--- a/sys/sys/rnd.h Sat Jan 26 18:44:21 2013 +0000
+++ b/sys/sys/rnd.h Sat Jan 26 19:05:11 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rnd.h,v 1.34 2012/11/25 15:29:55 christos Exp $ */
+/* $NetBSD: rnd.h,v 1.35 2013/01/26 19:05:11 tls Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -91,6 +91,7 @@
*/
#define RND_FLAG_NO_ESTIMATE 0x00000100 /* don't estimate entropy */
#define RND_FLAG_NO_COLLECT 0x00000200 /* don't collect entropy */
+#define RND_FLAG_FAST 0x00000400 /* process samples in bulk */
#define RND_TYPE_UNKNOWN 0 /* unknown source */
#define RND_TYPE_DISK 1 /* source is physical disk */
Home |
Main Index |
Thread Index |
Old Index