From ede585e9913c11eb2e881c64767dba9d549276eb Mon Sep 17 00:00:00 2001 From: rwatson Date: Wed, 11 Aug 2004 03:33:32 +0000 Subject: Perform a lockless read to test whether an entropy havesting fifo is full, avoiding the cost of mutex operations if it is. We re-test once the mutex is acquired to make sure it's still true before doing the -modify-write part of the read-modify-write. Note that due to the maximum fifo depth being pretty deep, this is unlikely to improve harvesting performance yet. Approved by: markm --- sys/dev/random/randomdev_soft.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sys') diff --git a/sys/dev/random/randomdev_soft.c b/sys/dev/random/randomdev_soft.c index c73e098..6f4851b 100644 --- a/sys/dev/random/randomdev_soft.c +++ b/sys/dev/random/randomdev_soft.c @@ -296,6 +296,10 @@ random_harvest_internal(u_int64_t somecounter, const void *entropy, { struct harvest *event; + /* Lockless read to avoid lock operations if fifo is full. */ + if (harvestfifo[origin].count >= RANDOM_FIFO_MAX) + return; + /* Lock the particular fifo */ mtx_lock_spin(&harvestfifo[origin].lock); -- cgit v1.1