Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern entropy(9): Create per-CPU state earlier.



details:   https://anonhg.NetBSD.org/src/rev/46d88dc06d9d
branches:  trunk
changeset: 363953:46d88dc06d9d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Mar 18 23:34:44 2022 +0000

description:
entropy(9): Create per-CPU state earlier.

This will make it possible to use it from interrupts as soon as they
start, which means the global entropy pool lock won't have to block
interrupts.

diffstat:

 sys/kern/kern_entropy.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (52 lines):

diff -r 1ded78827627 -r 46d88dc06d9d sys/kern/kern_entropy.c
--- a/sys/kern/kern_entropy.c   Fri Mar 18 23:33:41 2022 +0000
+++ b/sys/kern/kern_entropy.c   Fri Mar 18 23:34:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_entropy.c,v 1.35 2022/03/16 23:56:55 riastradh Exp $      */
+/*     $NetBSD: kern_entropy.c,v 1.36 2022/03/18 23:34:44 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.35 2022/03/16 23:56:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.36 2022/03/18 23:34:44 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -382,6 +382,10 @@
        LIST_FOREACH(rs, &E->sources, list)
                rs->state = percpu_alloc(sizeof(struct rndsource_cpu));
 
+       /* Allocate and initialize the per-CPU state.  */
+       entropy_percpu = percpu_create(sizeof(struct entropy_cpu),
+           entropy_init_cpu, entropy_fini_cpu, NULL);
+
        /* Enter the boot cycle count to get started.  */
        extra[i++] = entropy_timer();
        KASSERT(i == __arraycount(extra));
@@ -406,10 +410,6 @@
 
        KASSERT(E->stage == ENTROPY_WARM);
 
-       /* Allocate and initialize the per-CPU state.  */
-       entropy_percpu = percpu_create(sizeof(struct entropy_cpu),
-           entropy_init_cpu, entropy_fini_cpu, NULL);
-
        /*
         * Establish the softint at the highest softint priority level.
         * Must happen after CPU detection.
@@ -453,8 +453,10 @@
        ec->ec_pending = 0;
        ec->ec_locked = false;
 
+       /* XXX ci_cpuname may not be initialized early enough.  */
        evcnt_attach_dynamic(ec->ec_softint_evcnt, EVCNT_TYPE_MISC, NULL,
-           ci->ci_cpuname, "entropy softint");
+           ci->ci_cpuname[0] == '\0' ? "cpu0" : ci->ci_cpuname,
+           "entropy softint");
 }
 
 /*



Home | Main Index | Thread Index | Old Index