Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Avoid calling entropy_pending() with E->lock held.
details: https://anonhg.NetBSD.org/src/rev/7f9a7c1c9eb6
branches: trunk
changeset: 971653:7f9a7c1c9eb6
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Apr 30 16:43:12 2020 +0000
description:
Avoid calling entropy_pending() with E->lock held.
This is part I of avoiding percpu_foreach with spin lock held.
diffstat:
sys/kern/kern_entropy.c | 40 +++++++++++++++++++++-------------------
1 files changed, 21 insertions(+), 19 deletions(-)
diffs (75 lines):
diff -r 9dc7179ff3ae -r 7f9a7c1c9eb6 sys/kern/kern_entropy.c
--- a/sys/kern/kern_entropy.c Thu Apr 30 15:12:25 2020 +0000
+++ b/sys/kern/kern_entropy.c Thu Apr 30 16:43:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_entropy.c,v 1.2 2020/04/30 03:42:23 riastradh Exp $ */
+/* $NetBSD: kern_entropy.c,v 1.3 2020/04/30 16:43:12 riastradh Exp $ */
/*-
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.2 2020/04/30 03:42:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.3 2020/04/30 16:43:12 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -932,29 +932,32 @@
static void
entropy_thread(void *cookie)
{
+ bool consolidate;
for (;;) {
/*
- * Wait until someone wants to consolidate or there's
- * full entropy somewhere among the CPUs, as confirmed
- * at most once per minute.
+ * Wait until there's full entropy somewhere among the
+ * CPUs, as confirmed at most once per minute, or
+ * someone wants to consolidate.
*/
- mutex_enter(&E->lock);
- for (;;) {
- if (E->consolidate ||
- entropy_pending() >= ENTROPY_CAPACITY*NBBY) {
- E->consolidate = false;
- break;
- }
- cv_timedwait(&E->cv, &E->lock, 60*hz);
+ if (entropy_pending() >= ENTROPY_CAPACITY*NBBY) {
+ consolidate = true;
+ } else {
+ mutex_enter(&E->lock);
+ if (!E->consolidate)
+ cv_timedwait(&E->cv, &E->lock, 60*hz);
+ consolidate = E->consolidate;
+ E->consolidate = false;
+ mutex_exit(&E->lock);
}
- mutex_exit(&E->lock);
- /* Do it. */
- entropy_consolidate();
+ if (consolidate) {
+ /* Do it. */
+ entropy_consolidate();
- /* Mitigate abuse. */
- kpause("entropy", false, hz, NULL);
+ /* Mitigate abuse. */
+ kpause("entropy", false, hz, NULL);
+ }
}
}
@@ -969,7 +972,6 @@
uint32_t pending = 0;
percpu_foreach(entropy_percpu, &entropy_pending_cpu, &pending);
-
return pending;
}
Home |
Main Index |
Thread Index |
Old Index