From: Jens Axboe Date: Thu, 12 Jun 2008 09:53:57 +0000 (+0200) Subject: Convert file hash lock to spinlocks X-Git-Tag: fio-1.22-rc1~22 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=0ec7b3c9a0926e6377bd145206bb9f6a70be610d Convert file hash lock to spinlocks Signed-off-by: Jens Axboe --- diff --git a/filehash.c b/filehash.c index a00ac788..97c0b3c7 100644 --- a/filehash.c +++ b/filehash.c @@ -5,13 +5,15 @@ #include "flist.h" #include "crc/crc16.h" +#include "spinlock.h" + #define HASH_BUCKETS 512 #define HASH_MASK (HASH_BUCKETS - 1) unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); static struct flist_head *file_hash; -static struct fio_mutex *hash_lock; +static struct fio_spinlock *hash_lock; static unsigned short hash(const char *name) { @@ -20,7 +22,7 @@ static unsigned short hash(const char *name) void remove_file_hash(struct fio_file *f) { - fio_mutex_down(hash_lock); + fio_spin_lock(hash_lock); if (f->flags & FIO_FILE_HASHED) { assert(!flist_empty(&f->hash_list)); @@ -28,7 +30,7 @@ void remove_file_hash(struct fio_file *f) f->flags &= ~FIO_FILE_HASHED; } - fio_mutex_up(hash_lock); + fio_spin_unlock(hash_lock); } static struct fio_file *__lookup_file_hash(const char *name) @@ -52,9 +54,9 @@ struct fio_file *lookup_file_hash(const char *name) { struct fio_file *f; - fio_mutex_down(hash_lock); + fio_spin_lock(hash_lock); f = __lookup_file_hash(name); - fio_mutex_up(hash_lock); + fio_spin_unlock(hash_lock); return f; } @@ -67,7 +69,7 @@ struct fio_file *add_file_hash(struct fio_file *f) INIT_FLIST_HEAD(&f->hash_list); - fio_mutex_down(hash_lock); + fio_spin_lock(hash_lock); alias = __lookup_file_hash(f->file_name); if (!alias) { @@ -75,7 +77,7 @@ struct fio_file *add_file_hash(struct fio_file *f) flist_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]); } - fio_mutex_up(hash_lock); + fio_spin_unlock(hash_lock); return alias; } @@ -83,16 +85,17 @@ void file_hash_exit(void) { unsigned int i, has_entries = 0; - fio_mutex_down(hash_lock); + fio_spin_lock(hash_lock); for (i = 0; i < HASH_BUCKETS; i++) has_entries += !flist_empty(&file_hash[i]); - fio_mutex_up(hash_lock); + + file_hash = NULL; + fio_spin_unlock(hash_lock); if (has_entries) log_err("fio: file hash not empty on exit\n"); - file_hash = NULL; - fio_mutex_remove(hash_lock); + fio_spinlock_remove(hash_lock); hash_lock = NULL; } @@ -104,5 +107,5 @@ void file_hash_init(void *ptr) for (i = 0; i < HASH_BUCKETS; i++) INIT_FLIST_HEAD(&file_hash[i]); - hash_lock = fio_mutex_init(1); + hash_lock = fio_spinlock_init(); }