Module Name: src Committed By: riastradh Date: Fri Mar 18 23:34:44 UTC 2022
Modified Files: src/sys/kern: kern_entropy.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.35 -r1.36 src/sys/kern/kern_entropy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_entropy.c diff -u src/sys/kern/kern_entropy.c:1.35 src/sys/kern/kern_entropy.c:1.36 --- src/sys/kern/kern_entropy.c:1.35 Wed Mar 16 23:56:55 2022 +++ src/sys/kern/kern_entropy.c Fri Mar 18 23:34:44 2022 @@ -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 @@ entropy_init(void) 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 @@ entropy_init_late(void) 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 @@ entropy_init_cpu(void *ptr, void *cookie 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"); } /*