From 9ed346bab02c967ac656a58bc024f9505d8e3d7a Mon Sep 17 00:00:00 2001 From: Bosko Milekic Date: Fri, 9 Feb 2001 06:11:45 +0000 Subject: Change and clean the mutex lock interface. mtx_enter(lock, type) becomes: mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks) mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized) similarily, for releasing a lock, we now have: mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN. We change the caller interface for the two different types of locks because the semantics are entirely different for each case, and this makes it explicitly clear and, at the same time, it rids us of the extra `type' argument. The enter->lock and exit->unlock change has been made with the idea that we're "locking data" and not "entering locked code" in mind. Further, remove all additional "flags" previously passed to the lock acquire/release routines with the exception of two: MTX_QUIET and MTX_NOSWITCH The functionality of these flags is preserved and they can be passed to the lock/unlock routines by calling the corresponding wrappers: mtx_{lock, unlock}_flags(lock, flag(s)) and mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN locks, respectively. Re-inline some lock acq/rel code; in the sleep lock case, we only inline the _obtain_lock()s in order to ensure that the inlined code fits into a cache line. In the spin lock case, we inline recursion and actually only perform a function call if we need to spin. This change has been made with the idea that we generally tend to avoid spin locks and that also the spin locks that we do have and are heavily used (i.e. sched_lock) do recurse, and therefore in an effort to reduce function call overhead for some architectures (such as alpha), we inline recursion for this case. Create a new malloc type for the witness code and retire from using the M_DEV type. The new type is called M_WITNESS and is only declared if WITNESS is enabled. Begin cleaning up some machdep/mutex.h code - specifically updated the "optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently need those. Finally, caught up to the interface changes in all sys code. Contributors: jake, jhb, jasone (in no particular order) --- sys/dev/random/harvest.c | 2 +- sys/dev/random/yarrow.c | 72 ++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 37 deletions(-) (limited to 'sys/dev/random') diff --git a/sys/dev/random/harvest.c b/sys/dev/random/harvest.c index 60067dca19f1..93ce35b1f5b0 100644 --- a/sys/dev/random/harvest.c +++ b/sys/dev/random/harvest.c @@ -123,7 +123,7 @@ void random_set_wakeup_exit(void *control) { wakeup(control); - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); kthread_exit(0); /* NOTREACHED */ } diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c index 816ab2380472..f1325e5ec3da 100644 --- a/sys/dev/random/yarrow.c +++ b/sys/dev/random/yarrow.c @@ -96,10 +96,10 @@ random_kthread(void *arg /* NOTUSED */) struct source *source; #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("OWNERSHIP Giant == %d sched_lock == %d\n", mtx_owned(&Giant), mtx_owned(&sched_lock)); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif for (pl = 0; pl < 2; pl++) @@ -114,11 +114,11 @@ random_kthread(void *arg /* NOTUSED */) else { #ifdef DEBUG1 - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("HARVEST src=%d bits=%d/%d pool=%d count=%lld\n", event->source, event->bits, event->frac, event->pool, event->somecounter); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* Suck the harvested entropy out of the queue and hash @@ -160,9 +160,9 @@ random_kthread(void *arg /* NOTUSED */) /* Is the thread scheduled for a shutdown? */ if (random_kthread_control != 0) { #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random kthread setting terminate\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif random_set_wakeup_exit(&random_kthread_control); /* NOTREACHED */ @@ -179,9 +179,9 @@ random_init(void) int error; #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random initialise\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* This can be turned off by the very paranoid @@ -213,9 +213,9 @@ random_init(void) random_init_harvester(random_harvest_internal, read_random_real); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random initialise finish\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif return 0; @@ -225,31 +225,31 @@ void random_deinit(void) { #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random deinitialise\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* Deregister the randomness harvesting routine */ random_deinit_harvester(); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random deinitialise waiting for thread to terminate\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* Command the hash/reseed thread to end and wait for it to finish */ - mtx_enter(&harvestring.lockout_mtx, MTX_DEF); + mtx_lock(&harvestring.lockout_mtx); random_kthread_control = -1; msleep((void *)&random_kthread_control, &harvestring.lockout_mtx, PUSER, "rndend", 0); - mtx_exit(&harvestring.lockout_mtx, MTX_DEF); + mtx_unlock(&harvestring.lockout_mtx); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random deinitialise removing mutexes\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* Remove the mutexes */ @@ -257,9 +257,9 @@ random_deinit(void) mtx_destroy(&harvestring.lockout_mtx); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random deinitialise finish\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif } @@ -276,13 +276,13 @@ reseed(int fastslow) int i, j; #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Reseed type %d\n", fastslow); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif /* The reseed task must not be jumped on */ - mtx_enter(&random_reseed_mtx, MTX_DEF); + mtx_lock(&random_reseed_mtx); /* 1. Hash the accumulated entropy into v[0] */ @@ -353,12 +353,12 @@ reseed(int fastslow) /* XXX Not done here yet */ /* Release the reseed mutex */ - mtx_exit(&random_reseed_mtx, MTX_DEF); + mtx_unlock(&random_reseed_mtx); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Reseed finish\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif if (!random_state.seeded) { @@ -379,7 +379,7 @@ read_random_real(void *buf, u_int count) u_int retval; /* The reseed task must not be jumped on */ - mtx_enter(&random_reseed_mtx, MTX_DEF); + mtx_lock(&random_reseed_mtx); if (gate) { generator_gate(); @@ -423,7 +423,7 @@ read_random_real(void *buf, u_int count) cur -= retval; } } - mtx_exit(&random_reseed_mtx, MTX_DEF); + mtx_unlock(&random_reseed_mtx); return retval; } @@ -462,9 +462,9 @@ generator_gate(void) u_char temp[KEYSIZE]; #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Generator gate\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif for (i = 0; i < KEYSIZE; i += sizeof(random_state.counter)) { @@ -477,9 +477,9 @@ generator_gate(void) memset((void *)temp, 0, KEYSIZE); #ifdef DEBUG - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Generator gate finish\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif } @@ -495,16 +495,16 @@ random_harvest_internal(u_int64_t somecounter, void *entropy, u_int count, int newhead, tail; #ifdef DEBUG1 - mtx_enter(&Giant, MTX_DEF); + mtx_lock(&Giant); printf("Random harvest\n"); - mtx_exit(&Giant, MTX_DEF); + mtx_unlock(&Giant); #endif if (origin < ENTROPYSOURCE) { /* Add the harvested data to the ring buffer, but * do not block. */ - if (mtx_try_enter(&harvestring.lockout_mtx, MTX_DEF)) { + if (mtx_trylock(&harvestring.lockout_mtx)) { tail = atomic_load_acq_int(&harvestring.tail); newhead = (harvestring.head + 1) % HARVEST_RING_SIZE; @@ -533,7 +533,7 @@ random_harvest_internal(u_int64_t somecounter, void *entropy, u_int count, wakeup(&harvestring.head); } - mtx_exit(&harvestring.lockout_mtx, MTX_DEF); + mtx_unlock(&harvestring.lockout_mtx); } -- cgit v1.2.3