Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump/librump/rumpkern Make hyperentropy rndsource work s...
details: https://anonhg.NetBSD.org/src/rev/989e5a0d2ee3
branches: trunk
changeset: 343623:989e5a0d2ee3
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Feb 17 01:42:25 2016 +0000
description:
Make hyperentropy rndsource work synchronously, again.
This time for real! *crosses fingers*
diffstat:
sys/rump/librump/rumpkern/hyperentropy.c | 49 +++++--------------------------
1 files changed, 8 insertions(+), 41 deletions(-)
diffs (87 lines):
diff -r 42d359c5e8b9 -r 989e5a0d2ee3 sys/rump/librump/rumpkern/hyperentropy.c
--- a/sys/rump/librump/rumpkern/hyperentropy.c Wed Feb 17 01:23:32 2016 +0000
+++ b/sys/rump/librump/rumpkern/hyperentropy.c Wed Feb 17 01:42:25 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hyperentropy.c,v 1.11 2016/01/26 23:12:17 pooka Exp $ */
+/* $NetBSD: hyperentropy.c,v 1.12 2016/02/17 01:42:25 riastradh Exp $ */
/*
* Copyright (c) 2014 Antti Kantee. All Rights Reserved.
@@ -26,10 +26,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hyperentropy.c,v 1.11 2016/01/26 23:12:17 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperentropy.c,v 1.12 2016/02/17 01:42:25 riastradh Exp $");
#include <sys/param.h>
-#include <sys/atomic.h>
#include <sys/kmem.h>
#include <sys/rndpool.h>
#include <sys/rndsource.h>
@@ -39,12 +38,10 @@
#include <rump/rumpuser.h>
static krndsource_t rndsrc;
-static volatile unsigned hyperentropy_wanted;
-static void *feedrandom_softint;
#define MAXGET (RND_POOLBITS/NBBY)
static void
-feedrandom(size_t bytes)
+feedrandom(size_t bytes, void *cookie __unused)
{
uint8_t *rnddata;
size_t dsize;
@@ -52,46 +49,16 @@
rnddata = kmem_intr_alloc(MAXGET, KM_SLEEP);
if (rumpuser_getrandom(rnddata, MIN(MAXGET, bytes),
RUMPUSER_RANDOM_HARD|RUMPUSER_RANDOM_NOWAIT, &dsize) == 0)
- rnd_add_data(&rndsrc, rnddata, dsize, NBBY*dsize);
+ rnd_add_data_sync(&rndsrc, rnddata, dsize, NBBY*dsize);
kmem_intr_free(rnddata, MAXGET);
}
-static void
-feedrandom_intr(void *cookie __unused)
-{
-
- feedrandom(atomic_swap_uint(&hyperentropy_wanted, 0));
-}
-
-static void
-feedrandom_cb(size_t bytes, void *cookie __unused)
-{
- unsigned old, new;
-
- do {
- old = hyperentropy_wanted;
- new = ((MAXGET - old) < bytes? MAXGET : (old + bytes));
- } while (atomic_cas_uint(&hyperentropy_wanted, old, new) != old);
-
- softint_schedule(feedrandom_softint);
-}
-
void
rump_hyperentropy_init(void)
{
- if (rump_threads) {
- feedrandom_softint =
- softint_establish(SOFTINT_CLOCK|SOFTINT_MPSAFE,
- feedrandom_intr, NULL);
- KASSERT(feedrandom_softint != NULL);
- rndsource_setcb(&rndsrc, feedrandom_cb, &rndsrc);
- rnd_attach_source(&rndsrc, "rump_hyperent", RND_TYPE_VM,
- RND_FLAG_COLLECT_VALUE|RND_FLAG_HASCB);
- } else {
- /* without threads, just fill the pool */
- rnd_attach_source(&rndsrc, "rump_hyperent", RND_TYPE_VM,
- RND_FLAG_COLLECT_VALUE);
- feedrandom(MAXGET);
- }
+ rndsource_setcb(&rndsrc, &feedrandom, NULL);
+ rnd_attach_source(&rndsrc, "rump_hyperent", RND_TYPE_VM,
+ RND_FLAG_COLLECT_VALUE|RND_FLAG_HASCB);
+ feedrandom(MAXGET, NULL);
}
Home |
Main Index |
Thread Index |
Old Index