Tue Apr 14 13:26:59 2015 UTC ()
Group initialization of rnd_samples and rnd_global.


(riastradh)
diff -r1.58 -r1.59 src/sys/kern/kern_rndq.c

cvs diff -r1.58 -r1.59 src/sys/kern/Attic/kern_rndq.c (expand / switch to unified diff)

--- src/sys/kern/Attic/kern_rndq.c 2015/04/14 13:23:25 1.58
+++ src/sys/kern/Attic/kern_rndq.c 2015/04/14 13:26:58 1.59
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_rndq.c,v 1.58 2015/04/14 13:23:25 riastradh Exp $ */ 1/* $NetBSD: kern_rndq.c,v 1.59 2015/04/14 13:26:58 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon. 8 * by Michael Graff <explorer@flame.org> and Thor Lancelot Simon.
9 * This code uses ideas and algorithms from the Linux driver written by 9 * This code uses ideas and algorithms from the Linux driver written by
10 * Ted Ts'o. 10 * Ted Ts'o.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.58 2015/04/14 13:23:25 riastradh Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: kern_rndq.c,v 1.59 2015/04/14 13:26:58 riastradh Exp $");
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/atomic.h> 38#include <sys/atomic.h>
39#include <sys/ioctl.h> 39#include <sys/ioctl.h>
40#include <sys/fcntl.h> 40#include <sys/fcntl.h>
41#include <sys/select.h> 41#include <sys/select.h>
42#include <sys/poll.h> 42#include <sys/poll.h>
43#include <sys/kmem.h> 43#include <sys/kmem.h>
44#include <sys/mutex.h> 44#include <sys/mutex.h>
45#include <sys/proc.h> 45#include <sys/proc.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/conf.h> 47#include <sys/conf.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
@@ -485,40 +485,42 @@ rnd_skew_intr(void *arg) @@ -485,40 +485,42 @@ rnd_skew_intr(void *arg)
485/* 485/*
486 * initialize the global random pool for our use. 486 * initialize the global random pool for our use.
487 * rnd_init() must be called very early on in the boot process, so 487 * rnd_init() must be called very early on in the boot process, so
488 * the pool is ready for other devices to attach as sources. 488 * the pool is ready for other devices to attach as sources.
489 */ 489 */
490void 490void
491rnd_init(void) 491rnd_init(void)
492{ 492{
493 uint32_t c; 493 uint32_t c;
494 494
495 if (rnd_ready) 495 if (rnd_ready)
496 return; 496 return;
497 497
498 mutex_init(&rnd_samples.lock, MUTEX_DEFAULT, IPL_VM); 
499 rndsinks_init(); 
500 
501 /* 498 /*
502 * take a counter early, hoping that there's some variance in 499 * take a counter early, hoping that there's some variance in
503 * the following operations 500 * the following operations
504 */ 501 */
505 c = rnd_counter(); 502 c = rnd_counter();
506 503
507 LIST_INIT(&rnd_global.sources); 504 rndsinks_init();
 505
 506 /* Initialize the sample queue. */
 507 mutex_init(&rnd_samples.lock, MUTEX_DEFAULT, IPL_VM);
508 SIMPLEQ_INIT(&rnd_samples.q); 508 SIMPLEQ_INIT(&rnd_samples.q);
509 509
510 rndpool_init(&rnd_global.pool); 510 /* Initialize the global pool and sources list. */
511 mutex_init(&rnd_global.lock, MUTEX_DEFAULT, IPL_VM); 511 mutex_init(&rnd_global.lock, MUTEX_DEFAULT, IPL_VM);
 512 rndpool_init(&rnd_global.pool);
 513 LIST_INIT(&rnd_global.sources);
512 514
513 rnd_mempc = pool_cache_init(sizeof(rnd_sample_t), 0, 0, 0, 515 rnd_mempc = pool_cache_init(sizeof(rnd_sample_t), 0, 0, 0,
514 "rndsample", NULL, IPL_VM, 516 "rndsample", NULL, IPL_VM,
515 NULL, NULL, NULL); 517 NULL, NULL, NULL);
516 518
517 /* 519 /*
518 * Set resource limit. The rnd_process_events() function 520 * Set resource limit. The rnd_process_events() function
519 * is called every tick and process the sample queue. 521 * is called every tick and process the sample queue.
520 * Without limitation, if a lot of rnd_add_*() are called, 522 * Without limitation, if a lot of rnd_add_*() are called,
521 * all kernel memory may be eaten up. 523 * all kernel memory may be eaten up.
522 */ 524 */
523 pool_cache_sethardlimit(rnd_mempc, RND_POOLBITS, NULL, 0); 525 pool_cache_sethardlimit(rnd_mempc, RND_POOLBITS, NULL, 0);
524 526