summaryrefslogtreecommitdiffstats
path: root/sys/dev/random
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-11-03 10:02:50 +0000
committerrwatson <rwatson@FreeBSD.org>2004-11-03 10:02:50 +0000
commite75806b324f1078202c5e608e8771f46612c68bc (patch)
treefadfea7ce1c734aafa69e6bd674d9d931f392da3 /sys/dev/random
parent4bde5fc90babbe596b5711e83ffa9e7247b742a4 (diff)
downloadFreeBSD-src-e75806b324f1078202c5e608e8771f46612c68bc.zip
FreeBSD-src-e75806b324f1078202c5e608e8771f46612c68bc.tar.gz
(1) Move from O(n) list copies to O(1) list concatenation, which is
supported for STAILQ via STAILQ_CONCAT(). (2) Maintain a count of the number of entries in the thread-local entropy fifo so that we can keep the other fifo counts in synch. MFC after: 3 weeks MFC with: randomdev_soft.c revisions 1.5 and 1.6 Suggested by: jhb (1)
Diffstat (limited to 'sys/dev/random')
-rw-r--r--sys/dev/random/randomdev_soft.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/sys/dev/random/randomdev_soft.c b/sys/dev/random/randomdev_soft.c
index 5847022..e44f1b6 100644
--- a/sys/dev/random/randomdev_soft.c
+++ b/sys/dev/random/randomdev_soft.c
@@ -237,10 +237,11 @@ random_kthread(void *arg __unused)
{
STAILQ_HEAD(, harvest) local_queue;
struct harvest *event = NULL;
- int active;
+ int active, local_count;
enum esource source;
STAILQ_INIT(&local_queue);
+ local_count = 0;
/* Process until told to stop */
for (; random_kthread_control == 0;) {
@@ -254,14 +255,9 @@ random_kthread(void *arg __unused)
* Drain entropy source records into a thread-local
* queue for processing while not holding the mutex.
*/
- while ((event =
- STAILQ_FIRST(&harvestfifo[source].head)) != NULL) {
- /* Get a harvested entropy event */
- harvestfifo[source].count--;
- STAILQ_REMOVE_HEAD(&harvestfifo[source].head,
- next);
- STAILQ_INSERT_TAIL(&local_queue, event, next);
- }
+ STAILQ_CONCAT(&local_queue, &harvestfifo[source].head);
+ local_count += harvestfifo[source].count;
+ harvestfifo[source].count = 0;
}
/*
@@ -274,14 +270,15 @@ random_kthread(void *arg __unused)
STAILQ_FOREACH(event, &local_queue, next)
random_process_event(event);
mtx_lock_spin(&harvest_mtx);
- while ((event = STAILQ_FIRST(&local_queue)) != NULL) {
- STAILQ_REMOVE_HEAD(&local_queue, next);
- STAILQ_INSERT_TAIL(&emptyfifo.head, event,
- next);
- }
+ STAILQ_CONCAT(&emptyfifo.head, &local_queue);
+ emptyfifo.count += local_count;
+ local_count = 0;
}
mtx_unlock_spin(&harvest_mtx);
+ KASSERT(local_count == 0, ("random_kthread: local_count %d",
+ local_count));
+
/* Found nothing, so don't belabour the issue */
if (!active)
tsleep(&harvestfifo, PUSER, "-", hz / 10);
OpenPOWER on IntegriCloud