Rename fio_mutex into fio_sem
authorBart Van Assche <bart.vanassche@wdc.com>
Wed, 14 Mar 2018 15:31:37 +0000 (08:31 -0700)
committerBart Van Assche <bart.vanassche@wdc.com>
Thu, 15 Mar 2018 16:56:43 +0000 (09:56 -0700)
Since fio_mutex implements a semaphore, rename fio_mutex into fio_sem.
Rename those fio_sem instances that have 'mutex' embedded in their
name. Rename the mutex.h and .c source files into fio_sem.h and .c
respectively.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
26 files changed:
Makefile
backend.c
cgroup.c
diskutil.c
diskutil.h
file.h
filehash.c
filelock.c
filesetup.c
fio.h
fio_sem.c [new file with mode: 0644]
fio_sem.h [new file with mode: 0644]
flow.c
gettime-thread.c
helper_thread.c
helper_thread.h
init.c
mutex.c [deleted file]
mutex.h [deleted file]
profiles/act.c
server.c
server.h
smalloc.c
stat.c
stat.h
t/dedupe.c

index ce1deedc9239838a50b90e87d7f585898130aabd..9ac9a390e761dad5137f6c475ef30b3f4fde232f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,7 @@ endif
 SOURCE :=      $(sort $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \
                $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/lib/*.c))) \
                gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \
-               eta.c verify.c memory.c io_u.c parse.c mutex.c rwlock.c \
+               eta.c verify.c memory.c io_u.c parse.c fio_sem.c rwlock.c \
                pshared.c options.c \
                smalloc.c filehash.c profile.c debug.c engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
@@ -212,7 +212,7 @@ endif
 -include $(OBJS:.o=.d)
 
 T_SMALLOC_OBJS = t/stest.o
-T_SMALLOC_OBJS += gettime.o mutex.o pshared.o smalloc.o t/log.o t/debug.o \
+T_SMALLOC_OBJS += gettime.o fio_sem.o pshared.o smalloc.o t/log.o t/debug.o \
                  t/arch.o
 T_SMALLOC_PROGS = t/stest
 
@@ -246,7 +246,7 @@ T_BTRACE_FIO_PROGS = t/fio-btrace2fio
 endif
 
 T_DEDUPE_OBJS = t/dedupe.o
-T_DEDUPE_OBJS += lib/rbtree.o t/log.o mutex.o pshared.o smalloc.o gettime.o \
+T_DEDUPE_OBJS += lib/rbtree.o t/log.o fio_sem.o pshared.o smalloc.o gettime.o \
                crc/md5.o lib/memalign.o lib/bloom.o t/debug.o crc/xxhash.o \
                t/arch.o crc/murmur3.o crc/crc32c.o crc/crc32c-intel.o \
                crc/crc32c-arm64.o crc/fnv.o
index 69220e4597d61c97413ab6b7fdd6af9f644a5cdc..d82d49487c84991b8105508cd419cd557b58182b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -60,7 +60,7 @@
 #include "helper_thread.h"
 #include "pshared.h"
 
-static struct fio_mutex *startup_mutex;
+static struct fio_sem *startup_sem;
 static struct flist_head *cgroup_list;
 static char *cgroup_mnt;
 static int exit_value;
@@ -427,7 +427,7 @@ static void check_update_rusage(struct thread_data *td)
        if (td->update_rusage) {
                td->update_rusage = 0;
                update_rusage_stat(td);
-               fio_mutex_up(td->rusage_sem);
+               fio_sem_up(td->rusage_sem);
        }
 }
 
@@ -1570,11 +1570,11 @@ static void *thread_main(void *data)
        }
 
        td_set_runstate(td, TD_INITIALIZED);
-       dprint(FD_MUTEX, "up startup_mutex\n");
-       fio_mutex_up(startup_mutex);
-       dprint(FD_MUTEX, "wait on td->mutex\n");
-       fio_mutex_down(td->mutex);
-       dprint(FD_MUTEX, "done waiting on td->mutex\n");
+       dprint(FD_MUTEX, "up startup_sem\n");
+       fio_sem_up(startup_sem);
+       dprint(FD_MUTEX, "wait on td->sem\n");
+       fio_sem_down(td->sem);
+       dprint(FD_MUTEX, "done waiting on td->sem\n");
 
        /*
         * A new gid requires privilege, so we need to do this before setting
@@ -1803,11 +1803,11 @@ static void *thread_main(void *data)
                deadlock_loop_cnt = 0;
                do {
                        check_update_rusage(td);
-                       if (!fio_mutex_down_trylock(stat_mutex))
+                       if (!fio_sem_down_trylock(stat_sem))
                                break;
                        usleep(1000);
                        if (deadlock_loop_cnt++ > 5000) {
-                               log_err("fio seems to be stuck grabbing stat_mutex, forcibly exiting\n");
+                               log_err("fio seems to be stuck grabbing stat_sem, forcibly exiting\n");
                                td->error = EDEADLK;
                                goto err;
                        }
@@ -1820,7 +1820,7 @@ static void *thread_main(void *data)
                if (td_trim(td) && td->io_bytes[DDIR_TRIM])
                        update_runtime(td, elapsed_us, DDIR_TRIM);
                fio_gettime(&td->start, NULL);
-               fio_mutex_up(stat_mutex);
+               fio_sem_up(stat_sem);
 
                if (td->error || td->terminate)
                        break;
@@ -1844,10 +1844,10 @@ static void *thread_main(void *data)
                 */
                check_update_rusage(td);
 
-               fio_mutex_down(stat_mutex);
+               fio_sem_down(stat_sem);
                update_runtime(td, elapsed_us, DDIR_READ);
                fio_gettime(&td->start, NULL);
-               fio_mutex_up(stat_mutex);
+               fio_sem_up(stat_sem);
 
                if (td->error || td->terminate)
                        break;
@@ -2318,7 +2318,7 @@ reap:
 
                        init_disk_util(td);
 
-                       td->rusage_sem = fio_mutex_init(FIO_MUTEX_LOCKED);
+                       td->rusage_sem = fio_sem_init(FIO_SEM_LOCKED);
                        td->update_rusage = 0;
 
                        /*
@@ -2363,8 +2363,8 @@ reap:
                                } else if (i == fio_debug_jobno)
                                        *fio_debug_jobp = pid;
                        }
-                       dprint(FD_MUTEX, "wait on startup_mutex\n");
-                       if (fio_mutex_down_timeout(startup_mutex, 10000)) {
+                       dprint(FD_MUTEX, "wait on startup_sem\n");
+                       if (fio_sem_down_timeout(startup_sem, 10000)) {
                                log_err("fio: job startup hung? exiting.\n");
                                fio_terminate_threads(TERMINATE_ALL);
                                fio_abort = 1;
@@ -2372,7 +2372,7 @@ reap:
                                free(fd);
                                break;
                        }
-                       dprint(FD_MUTEX, "done waiting on startup_mutex\n");
+                       dprint(FD_MUTEX, "done waiting on startup_sem\n");
                }
 
                /*
@@ -2431,7 +2431,7 @@ reap:
                        m_rate += ddir_rw_sum(td->o.ratemin);
                        t_rate += ddir_rw_sum(td->o.rate);
                        todo--;
-                       fio_mutex_up(td->mutex);
+                       fio_sem_up(td->sem);
                }
 
                reap_threads(&nr_running, &t_rate, &m_rate);
@@ -2480,13 +2480,13 @@ int fio_backend(struct sk_out *sk_out)
                setup_log(&agg_io_log[DDIR_TRIM], &p, "agg-trim_bw.log");
        }
 
-       startup_mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
-       if (startup_mutex == NULL)
+       startup_sem = fio_sem_init(FIO_SEM_LOCKED);
+       if (startup_sem == NULL)
                return 1;
 
        set_genesis_time();
        stat_init();
-       helper_thread_create(startup_mutex, sk_out);
+       helper_thread_create(startup_sem, sk_out);
 
        cgroup_list = smalloc(sizeof(*cgroup_list));
        INIT_FLIST_HEAD(cgroup_list);
@@ -2511,11 +2511,11 @@ int fio_backend(struct sk_out *sk_out)
                steadystate_free(td);
                fio_options_free(td);
                if (td->rusage_sem) {
-                       fio_mutex_remove(td->rusage_sem);
+                       fio_sem_remove(td->rusage_sem);
                        td->rusage_sem = NULL;
                }
-               fio_mutex_remove(td->mutex);
-               td->mutex = NULL;
+               fio_sem_remove(td->sem);
+               td->sem = NULL;
        }
 
        free_disk_util();
@@ -2523,7 +2523,7 @@ int fio_backend(struct sk_out *sk_out)
        sfree(cgroup_list);
        sfree(cgroup_mnt);
 
-       fio_mutex_remove(startup_mutex);
+       fio_sem_remove(startup_sem);
        stat_exit();
        return exit_value;
 }
index a297e2ac82e82f5145edfcb9cc509b23134a360b..4fab977aeb8c3ddadadf1680692d7bf5210d70dd 100644 (file)
--- a/cgroup.c
+++ b/cgroup.c
@@ -11,7 +11,7 @@
 #include "cgroup.h"
 #include "smalloc.h"
 
-static struct fio_mutex *lock;
+static struct fio_sem *lock;
 
 struct cgroup_member {
        struct flist_head list;
@@ -70,9 +70,9 @@ err:
        }
        if (td->o.cgroup_nodelete)
                cm->cgroup_nodelete = 1;
-       fio_mutex_down(lock);
+       fio_sem_down(lock);
        flist_add_tail(&cm->list, clist);
-       fio_mutex_up(lock);
+       fio_sem_up(lock);
 }
 
 void cgroup_kill(struct flist_head *clist)
@@ -83,7 +83,7 @@ void cgroup_kill(struct flist_head *clist)
        if (!lock)
                return;
 
-       fio_mutex_down(lock);
+       fio_sem_down(lock);
 
        flist_for_each_safe(n, tmp, clist) {
                cm = flist_entry(n, struct cgroup_member, list);
@@ -94,7 +94,7 @@ void cgroup_kill(struct flist_head *clist)
                sfree(cm);
        }
 
-       fio_mutex_up(lock);
+       fio_sem_up(lock);
 }
 
 static char *get_cgroup_root(struct thread_data *td, char *mnt)
@@ -198,12 +198,12 @@ void cgroup_shutdown(struct thread_data *td, char **mnt)
 
 static void fio_init cgroup_init(void)
 {
-       lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       lock = fio_sem_init(FIO_SEM_UNLOCKED);
        if (!lock)
                log_err("fio: failed to allocate cgroup lock\n");
 }
 
 static void fio_exit cgroup_exit(void)
 {
-       fio_mutex_remove(lock);
+       fio_sem_remove(lock);
 }
index 789071d197fcd2a4bd2abd9dfc01c1ae4235e954..1f2471be50470377c0acca7bdec3e441e5c1b8fa 100644 (file)
@@ -17,7 +17,7 @@
 static int last_majdev, last_mindev;
 static struct disk_util *last_du;
 
-static struct fio_mutex *disk_util_mutex;
+static struct fio_sem *disk_util_sem;
 
 static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
                int majdev, int mindev, char *path);
@@ -35,7 +35,7 @@ static void disk_util_free(struct disk_util *du)
                slave->users--;
        }
 
-       fio_mutex_remove(du->lock);
+       fio_sem_remove(du->lock);
        free(du->sysfs_root);
        sfree(du);
 }
@@ -120,7 +120,7 @@ int update_io_ticks(void)
 
        dprint(FD_DISKUTIL, "update io ticks\n");
 
-       fio_mutex_down(disk_util_mutex);
+       fio_sem_down(disk_util_sem);
 
        if (!helper_should_exit()) {
                flist_for_each(entry, &disk_list) {
@@ -130,7 +130,7 @@ int update_io_ticks(void)
        } else
                ret = 1;
 
-       fio_mutex_up(disk_util_mutex);
+       fio_sem_up(disk_util_sem);
        return ret;
 }
 
@@ -139,18 +139,18 @@ static struct disk_util *disk_util_exists(int major, int minor)
        struct flist_head *entry;
        struct disk_util *du;
 
-       fio_mutex_down(disk_util_mutex);
+       fio_sem_down(disk_util_sem);
 
        flist_for_each(entry, &disk_list) {
                du = flist_entry(entry, struct disk_util, list);
 
                if (major == du->major && minor == du->minor) {
-                       fio_mutex_up(disk_util_mutex);
+                       fio_sem_up(disk_util_sem);
                        return du;
                }
        }
 
-       fio_mutex_up(disk_util_mutex);
+       fio_sem_up(disk_util_sem);
        return NULL;
 }
 
@@ -312,10 +312,10 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
        du->minor = mindev;
        INIT_FLIST_HEAD(&du->slavelist);
        INIT_FLIST_HEAD(&du->slaves);
-       du->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       du->lock = fio_sem_init(FIO_SEM_UNLOCKED);
        du->users = 0;
 
-       fio_mutex_down(disk_util_mutex);
+       fio_sem_down(disk_util_sem);
 
        flist_for_each(entry, &disk_list) {
                __du = flist_entry(entry, struct disk_util, list);
@@ -324,7 +324,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
 
                if (!strcmp((char *) du->dus.name, (char *) __du->dus.name)) {
                        disk_util_free(du);
-                       fio_mutex_up(disk_util_mutex);
+                       fio_sem_up(disk_util_sem);
                        return __du;
                }
        }
@@ -335,7 +335,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
        get_io_ticks(du, &du->last_dus);
 
        flist_add_tail(&du->list, &disk_list);
-       fio_mutex_up(disk_util_mutex);
+       fio_sem_up(disk_util_sem);
 
        find_add_disk_slaves(td, path, du);
        return du;
@@ -559,7 +559,7 @@ static void aggregate_slaves_stats(struct disk_util *masterdu)
 
 void disk_util_prune_entries(void)
 {
-       fio_mutex_down(disk_util_mutex);
+       fio_sem_down(disk_util_sem);
 
        while (!flist_empty(&disk_list)) {
                struct disk_util *du;
@@ -570,8 +570,8 @@ void disk_util_prune_entries(void)
        }
 
        last_majdev = last_mindev = -1;
-       fio_mutex_up(disk_util_mutex);
-       fio_mutex_remove(disk_util_mutex);
+       fio_sem_up(disk_util_sem);
+       fio_sem_remove(disk_util_sem);
 }
 
 void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg,
@@ -693,13 +693,13 @@ void show_disk_util(int terse, struct json_object *parent,
        struct disk_util *du;
        bool do_json;
 
-       if (!disk_util_mutex)
+       if (!disk_util_sem)
                return;
 
-       fio_mutex_down(disk_util_mutex);
+       fio_sem_down(disk_util_sem);
 
        if (flist_empty(&disk_list)) {
-               fio_mutex_up(disk_util_mutex);
+               fio_sem_up(disk_util_sem);
                return;
        }
 
@@ -722,10 +722,10 @@ void show_disk_util(int terse, struct json_object *parent,
                }
        }
 
-       fio_mutex_up(disk_util_mutex);
+       fio_sem_up(disk_util_sem);
 }
 
 void setup_disk_util(void)
 {
-       disk_util_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       disk_util_sem = fio_sem_init(FIO_SEM_UNLOCKED);
 }
index ee5c0afd75984535da56fae52b9788f8c3e591f2..c1035785c0a883bb1f2d571ad29d2944bf8fd059 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "lib/output_buffer.h"
 #include "helper_thread.h"
-#include "mutex.h"
+#include "fio_sem.h"
 
 struct disk_util_stats {
        uint64_t ios[2];
@@ -67,7 +67,7 @@ struct disk_util {
 
        struct timespec time;
 
-       struct fio_mutex *lock;
+       struct fio_sem *lock;
        unsigned long users;
 };
 
@@ -76,7 +76,7 @@ static inline void disk_util_mod(struct disk_util *du, int val)
        if (du) {
                struct flist_head *n;
 
-               fio_mutex_down(du->lock);
+               fio_sem_down(du->lock);
                du->users += val;
 
                flist_for_each(n, &du->slavelist) {
@@ -85,7 +85,7 @@ static inline void disk_util_mod(struct disk_util *du, int val)
                        slave = flist_entry(n, struct disk_util, slavelist);
                        slave->users += val;
                }
-               fio_mutex_up(du->lock);
+               fio_sem_up(du->lock);
        }
 }
 static inline void disk_util_inc(struct disk_util *du)
diff --git a/file.h b/file.h
index cc721ee27a33c03e1ed1ff430170bbdec5b77432..8fd34b136c23972ba79ff06e4bad096d2e12eb6e 100644 (file)
--- a/file.h
+++ b/file.h
@@ -125,7 +125,7 @@ struct fio_file {
         * if io is protected by a semaphore, this is set
         */
        union {
-               struct fio_mutex *lock;
+               struct fio_sem *lock;
                struct fio_rwlock *rwlock;
        };
 
index edeeab4863c8ff831391f539e53492f1c78df5c7..b55ab7340e68065de4bcb6eb6e8f39111d38886e 100644 (file)
@@ -16,7 +16,7 @@
 static 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_sem *hash_lock;
 static struct bloom *file_bloom;
 
 static unsigned short hash(const char *name)
@@ -27,18 +27,18 @@ static unsigned short hash(const char *name)
 void fio_file_hash_lock(void)
 {
        if (hash_lock)
-               fio_mutex_down(hash_lock);
+               fio_sem_down(hash_lock);
 }
 
 void fio_file_hash_unlock(void)
 {
        if (hash_lock)
-               fio_mutex_up(hash_lock);
+               fio_sem_up(hash_lock);
 }
 
 void remove_file_hash(struct fio_file *f)
 {
-       fio_mutex_down(hash_lock);
+       fio_sem_down(hash_lock);
 
        if (fio_file_hashed(f)) {
                assert(!flist_empty(&f->hash_list));
@@ -46,7 +46,7 @@ void remove_file_hash(struct fio_file *f)
                fio_file_clear_hashed(f);
        }
 
-       fio_mutex_up(hash_lock);
+       fio_sem_up(hash_lock);
 }
 
 static struct fio_file *__lookup_file_hash(const char *name)
@@ -73,9 +73,9 @@ struct fio_file *lookup_file_hash(const char *name)
 {
        struct fio_file *f;
 
-       fio_mutex_down(hash_lock);
+       fio_sem_down(hash_lock);
        f = __lookup_file_hash(name);
-       fio_mutex_up(hash_lock);
+       fio_sem_up(hash_lock);
        return f;
 }
 
@@ -88,7 +88,7 @@ struct fio_file *add_file_hash(struct fio_file *f)
 
        INIT_FLIST_HEAD(&f->hash_list);
 
-       fio_mutex_down(hash_lock);
+       fio_sem_down(hash_lock);
 
        alias = __lookup_file_hash(f->file_name);
        if (!alias) {
@@ -96,7 +96,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_sem_up(hash_lock);
        return alias;
 }
 
@@ -109,17 +109,17 @@ void file_hash_exit(void)
 {
        unsigned int i, has_entries = 0;
 
-       fio_mutex_down(hash_lock);
+       fio_sem_down(hash_lock);
        for (i = 0; i < HASH_BUCKETS; i++)
                has_entries += !flist_empty(&file_hash[i]);
-       fio_mutex_up(hash_lock);
+       fio_sem_up(hash_lock);
 
        if (has_entries)
                log_err("fio: file hash not empty on exit\n");
 
        sfree(file_hash);
        file_hash = NULL;
-       fio_mutex_remove(hash_lock);
+       fio_sem_remove(hash_lock);
        hash_lock = NULL;
        bloom_free(file_bloom);
        file_bloom = NULL;
@@ -134,6 +134,6 @@ void file_hash_init(void)
        for (i = 0; i < HASH_BUCKETS; i++)
                INIT_FLIST_HEAD(&file_hash[i]);
 
-       hash_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       hash_lock = fio_sem_init(FIO_SEM_UNLOCKED);
        file_bloom = bloom_new(BLOOM_SIZE);
 }
index 6e84970fc0064cafaeb0945befd5f4355fd9cf7b..cc98aafc07852a369e1db32ed7f50b8b2ff31e7d 100644 (file)
 #include "flist.h"
 #include "filelock.h"
 #include "smalloc.h"
-#include "mutex.h"
+#include "fio_sem.h"
 #include "hash.h"
 #include "log.h"
 
 struct fio_filelock {
        uint32_t hash;
-       struct fio_mutex lock;
+       struct fio_sem lock;
        struct flist_head list;
        unsigned int references;
 };
@@ -26,7 +26,7 @@ struct fio_filelock {
        
 static struct filelock_data {
        struct flist_head list;
-       struct fio_mutex lock;
+       struct fio_sem lock;
 
        struct flist_head free_list;
        struct fio_filelock ffs[MAX_FILELOCKS];
@@ -58,9 +58,9 @@ static struct fio_filelock *get_filelock(int trylock, int *retry)
                if (ff || trylock)
                        break;
 
-               fio_mutex_up(&fld->lock);
+               fio_sem_up(&fld->lock);
                usleep(1000);
-               fio_mutex_down(&fld->lock);
+               fio_sem_down(&fld->lock);
                *retry = 1;
        } while (1);
 
@@ -78,13 +78,13 @@ int fio_filelock_init(void)
        INIT_FLIST_HEAD(&fld->list);
        INIT_FLIST_HEAD(&fld->free_list);
 
-       if (__fio_mutex_init(&fld->lock, FIO_MUTEX_UNLOCKED))
+       if (__fio_sem_init(&fld->lock, FIO_SEM_UNLOCKED))
                goto err;
 
        for (i = 0; i < MAX_FILELOCKS; i++) {
                struct fio_filelock *ff = &fld->ffs[i];
 
-               if (__fio_mutex_init(&ff->lock, FIO_MUTEX_UNLOCKED))
+               if (__fio_sem_init(&ff->lock, FIO_SEM_UNLOCKED))
                        goto err;
                flist_add_tail(&ff->list, &fld->free_list);
        }
@@ -101,7 +101,7 @@ void fio_filelock_exit(void)
                return;
 
        assert(flist_empty(&fld->list));
-       __fio_mutex_remove(&fld->lock);
+       __fio_sem_remove(&fld->lock);
 
        while (!flist_empty(&fld->free_list)) {
                struct fio_filelock *ff;
@@ -109,7 +109,7 @@ void fio_filelock_exit(void)
                ff = flist_first_entry(&fld->free_list, struct fio_filelock, list);
 
                flist_del_init(&ff->list);
-               __fio_mutex_remove(&ff->lock);
+               __fio_sem_remove(&ff->lock);
        }
 
        sfree(fld);
@@ -172,11 +172,11 @@ static bool __fio_lock_file(const char *fname, int trylock)
 
        hash = jhash(fname, strlen(fname), 0);
 
-       fio_mutex_down(&fld->lock);
+       fio_sem_down(&fld->lock);
        ff = fio_hash_get(hash, trylock);
        if (ff)
                ff->references++;
-       fio_mutex_up(&fld->lock);
+       fio_sem_up(&fld->lock);
 
        if (!ff) {
                assert(!trylock);
@@ -184,14 +184,14 @@ static bool __fio_lock_file(const char *fname, int trylock)
        }
 
        if (!trylock) {
-               fio_mutex_down(&ff->lock);
+               fio_sem_down(&ff->lock);
                return false;
        }
 
-       if (!fio_mutex_down_trylock(&ff->lock))
+       if (!fio_sem_down_trylock(&ff->lock))
                return false;
 
-       fio_mutex_down(&fld->lock);
+       fio_sem_down(&fld->lock);
 
        /*
         * If we raced and the only reference to the lock is us, we can
@@ -202,10 +202,10 @@ static bool __fio_lock_file(const char *fname, int trylock)
                ff = NULL;
        }
 
-       fio_mutex_up(&fld->lock);
+       fio_sem_up(&fld->lock);
 
        if (ff) {
-               fio_mutex_down(&ff->lock);
+               fio_sem_down(&ff->lock);
                return false;
        }
 
@@ -229,12 +229,12 @@ void fio_unlock_file(const char *fname)
 
        hash = jhash(fname, strlen(fname), 0);
 
-       fio_mutex_down(&fld->lock);
+       fio_sem_down(&fld->lock);
 
        ff = fio_hash_find(hash);
        if (ff) {
                int refs = --ff->references;
-               fio_mutex_up(&ff->lock);
+               fio_sem_up(&ff->lock);
                if (!refs) {
                        flist_del_init(&ff->list);
                        put_filelock(ff);
@@ -242,5 +242,5 @@ void fio_unlock_file(const char *fname)
        } else
                log_err("fio: file not found for unlocking\n");
 
-       fio_mutex_up(&fld->lock);
+       fio_sem_up(&fld->lock);
 }
index 4b0f40d6f9e458071446ab64becf007260188f1e..7cbce1327f8f21edb32159376be406841016ef62 100644 (file)
@@ -1622,7 +1622,7 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
                f->rwlock = fio_rwlock_init();
                break;
        case FILE_LOCK_EXCLUSIVE:
-               f->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+               f->lock = fio_sem_init(FIO_SEM_UNLOCKED);
                break;
        default:
                log_err("fio: unknown lock mode: %d\n", td->o.file_lock_mode);
@@ -1707,7 +1707,7 @@ void lock_file(struct thread_data *td, struct fio_file *f, enum fio_ddir ddir)
                else
                        fio_rwlock_write(f->rwlock);
        } else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE)
-               fio_mutex_down(f->lock);
+               fio_sem_down(f->lock);
 
        td->file_locks[f->fileno] = td->o.file_lock_mode;
 }
@@ -1720,7 +1720,7 @@ void unlock_file(struct thread_data *td, struct fio_file *f)
        if (td->o.file_lock_mode == FILE_LOCK_READWRITE)
                fio_rwlock_unlock(f->rwlock);
        else if (td->o.file_lock_mode == FILE_LOCK_EXCLUSIVE)
-               fio_mutex_up(f->lock);
+               fio_sem_up(f->lock);
 
        td->file_locks[f->fileno] = FILE_LOCK_NONE;
 }
diff --git a/fio.h b/fio.h
index 0f6dfb6e6e8d93d8c35e97aaca5c5dd3d0c59044..9551048745b685bcb1e1b96ac47aeaa0eef56eab 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -62,7 +62,7 @@
 #include <cuda.h>
 #endif
 
-struct fio_mutex;
+struct fio_sem;
 
 /*
  * offset generator types
@@ -199,7 +199,7 @@ struct thread_data {
        struct timespec iops_sample_time;
 
        volatile int update_rusage;
-       struct fio_mutex *rusage_sem;
+       struct fio_sem *rusage_sem;
        struct rusage ru_start;
        struct rusage ru_end;
 
@@ -342,7 +342,7 @@ struct thread_data {
        uint64_t this_io_bytes[DDIR_RWDIR_CNT];
        uint64_t io_skip_bytes;
        uint64_t zone_bytes;
-       struct fio_mutex *mutex;
+       struct fio_sem *sem;
        uint64_t bytes_done[DDIR_RWDIR_CNT];
 
        /*
diff --git a/fio_sem.c b/fio_sem.c
new file mode 100644 (file)
index 0000000..b9a1bf1
--- /dev/null
+++ b/fio_sem.c
@@ -0,0 +1,167 @@
+#include <string.h>
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "log.h"
+#include "fio_sem.h"
+#include "pshared.h"
+#include "os/os.h"
+#include "fio_time.h"
+#include "gettime.h"
+
+void __fio_sem_remove(struct fio_sem *sem)
+{
+       assert(sem->magic == FIO_SEM_MAGIC);
+       pthread_cond_destroy(&sem->cond);
+
+       /*
+        * Ensure any subsequent attempt to grab this semaphore will fail
+        * with an assert, instead of just silently hanging.
+        */
+       memset(sem, 0, sizeof(*sem));
+}
+
+void fio_sem_remove(struct fio_sem *sem)
+{
+       __fio_sem_remove(sem);
+       munmap((void *) sem, sizeof(*sem));
+}
+
+int __fio_sem_init(struct fio_sem *sem, int value)
+{
+       int ret;
+
+       sem->value = value;
+       sem->magic = FIO_SEM_MAGIC;
+
+       ret = mutex_cond_init_pshared(&sem->lock, &sem->cond);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+struct fio_sem *fio_sem_init(int value)
+{
+       struct fio_sem *sem = NULL;
+
+       sem = (void *) mmap(NULL, sizeof(struct fio_sem),
+                               PROT_READ | PROT_WRITE,
+                               OS_MAP_ANON | MAP_SHARED, -1, 0);
+       if (sem == MAP_FAILED) {
+               perror("mmap semaphore");
+               return NULL;
+       }
+
+       if (!__fio_sem_init(sem, value))
+               return sem;
+
+       fio_sem_remove(sem);
+       return NULL;
+}
+
+static bool sem_timed_out(struct timespec *t, unsigned int msecs)
+{
+       struct timeval tv;
+       struct timespec now;
+
+       gettimeofday(&tv, NULL);
+       now.tv_sec = tv.tv_sec;
+       now.tv_nsec = tv.tv_usec * 1000;
+
+       return mtime_since(t, &now) >= msecs;
+}
+
+int fio_sem_down_timeout(struct fio_sem *sem, unsigned int msecs)
+{
+       struct timeval tv_s;
+       struct timespec base;
+       struct timespec t;
+       int ret = 0;
+
+       assert(sem->magic == FIO_SEM_MAGIC);
+
+       gettimeofday(&tv_s, NULL);
+       base.tv_sec = t.tv_sec = tv_s.tv_sec;
+       base.tv_nsec = t.tv_nsec = tv_s.tv_usec * 1000;
+
+       t.tv_sec += msecs / 1000;
+       t.tv_nsec += ((msecs * 1000000ULL) % 1000000000);
+       if (t.tv_nsec >= 1000000000) {
+               t.tv_nsec -= 1000000000;
+               t.tv_sec++;
+       }
+
+       pthread_mutex_lock(&sem->lock);
+
+       sem->waiters++;
+       while (!sem->value && !ret) {
+               /*
+                * Some platforms (FreeBSD 9?) seems to return timed out
+                * way too early, double check.
+                */
+               ret = pthread_cond_timedwait(&sem->cond, &sem->lock, &t);
+               if (ret == ETIMEDOUT && !sem_timed_out(&base, msecs))
+                       ret = 0;
+       }
+       sem->waiters--;
+
+       if (!ret) {
+               sem->value--;
+               pthread_mutex_unlock(&sem->lock);
+               return 0;
+       }
+
+       pthread_mutex_unlock(&sem->lock);
+       return ret;
+}
+
+bool fio_sem_down_trylock(struct fio_sem *sem)
+{
+       bool ret = true;
+
+       assert(sem->magic == FIO_SEM_MAGIC);
+
+       pthread_mutex_lock(&sem->lock);
+       if (sem->value) {
+               sem->value--;
+               ret = false;
+       }
+       pthread_mutex_unlock(&sem->lock);
+
+       return ret;
+}
+
+void fio_sem_down(struct fio_sem *sem)
+{
+       assert(sem->magic == FIO_SEM_MAGIC);
+
+       pthread_mutex_lock(&sem->lock);
+
+       while (!sem->value) {
+               sem->waiters++;
+               pthread_cond_wait(&sem->cond, &sem->lock);
+               sem->waiters--;
+       }
+
+       sem->value--;
+       pthread_mutex_unlock(&sem->lock);
+}
+
+void fio_sem_up(struct fio_sem *sem)
+{
+       int do_wake = 0;
+
+       assert(sem->magic == FIO_SEM_MAGIC);
+
+       pthread_mutex_lock(&sem->lock);
+       read_barrier();
+       if (!sem->value && sem->waiters)
+               do_wake = 1;
+       sem->value++;
+
+       if (do_wake)
+               pthread_cond_signal(&sem->cond);
+
+       pthread_mutex_unlock(&sem->lock);
+}
diff --git a/fio_sem.h b/fio_sem.h
new file mode 100644 (file)
index 0000000..a796ddd
--- /dev/null
+++ b/fio_sem.h
@@ -0,0 +1,31 @@
+#ifndef FIO_SEM_H
+#define FIO_SEM_H
+
+#include <pthread.h>
+#include "lib/types.h"
+
+#define FIO_SEM_MAGIC          0x4d555445U
+
+struct fio_sem {
+       pthread_mutex_t lock;
+       pthread_cond_t cond;
+       int value;
+       int waiters;
+       int magic;
+};
+
+enum {
+       FIO_SEM_LOCKED  = 0,
+       FIO_SEM_UNLOCKED        = 1,
+};
+
+extern int __fio_sem_init(struct fio_sem *, int);
+extern struct fio_sem *fio_sem_init(int);
+extern void __fio_sem_remove(struct fio_sem *);
+extern void fio_sem_remove(struct fio_sem *);
+extern void fio_sem_up(struct fio_sem *);
+extern void fio_sem_down(struct fio_sem *);
+extern bool fio_sem_down_trylock(struct fio_sem *);
+extern int fio_sem_down_timeout(struct fio_sem *, unsigned int);
+
+#endif
diff --git a/flow.c b/flow.c
index 384187ef0a59095d7754c6435132afe00ef9fd09..a8dbfb9bb48e66a991953810d2c25d92eeeacb54 100644 (file)
--- a/flow.c
+++ b/flow.c
@@ -1,5 +1,5 @@
 #include "fio.h"
-#include "mutex.h"
+#include "fio_sem.h"
 #include "smalloc.h"
 #include "flist.h"
 
@@ -11,7 +11,7 @@ struct fio_flow {
 };
 
 static struct flist_head *flow_list;
-static struct fio_mutex *flow_lock;
+static struct fio_sem *flow_lock;
 
 int flow_threshold_exceeded(struct thread_data *td)
 {
@@ -49,7 +49,7 @@ static struct fio_flow *flow_get(unsigned int id)
        if (!flow_lock)
                return NULL;
 
-       fio_mutex_down(flow_lock);
+       fio_sem_down(flow_lock);
 
        flist_for_each(n, flow_list) {
                flow = flist_entry(n, struct fio_flow, list);
@@ -62,7 +62,7 @@ static struct fio_flow *flow_get(unsigned int id)
        if (!flow) {
                flow = smalloc(sizeof(*flow));
                if (!flow) {
-                       fio_mutex_up(flow_lock);
+                       fio_sem_up(flow_lock);
                        return NULL;
                }
                flow->refs = 0;
@@ -74,7 +74,7 @@ static struct fio_flow *flow_get(unsigned int id)
        }
 
        flow->refs++;
-       fio_mutex_up(flow_lock);
+       fio_sem_up(flow_lock);
        return flow;
 }
 
@@ -83,14 +83,14 @@ static void flow_put(struct fio_flow *flow)
        if (!flow_lock)
                return;
 
-       fio_mutex_down(flow_lock);
+       fio_sem_down(flow_lock);
 
        if (!--flow->refs) {
                flist_del(&flow->list);
                sfree(flow);
        }
 
-       fio_mutex_up(flow_lock);
+       fio_sem_up(flow_lock);
 }
 
 void flow_init_job(struct thread_data *td)
@@ -115,7 +115,7 @@ void flow_init(void)
                return;
        }
 
-       flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       flow_lock = fio_sem_init(FIO_SEM_UNLOCKED);
        if (!flow_lock) {
                log_err("fio: failed to allocate flow lock\n");
                sfree(flow_list);
@@ -128,7 +128,7 @@ void flow_init(void)
 void flow_exit(void)
 {
        if (flow_lock)
-               fio_mutex_remove(flow_lock);
+               fio_sem_remove(flow_lock);
        if (flow_list)
                sfree(flow_list);
 }
index fc52236bf5969028aabec5c0507f445e91298d65..87f50600cca01a78d25f53f167d7835212dde5cc 100644 (file)
@@ -35,18 +35,18 @@ static void fio_gtod_update(void)
 }
 
 struct gtod_cpu_data {
-       struct fio_mutex *mutex;
+       struct fio_sem *sem;
        unsigned int cpu;
 };
 
 static void *gtod_thread_main(void *data)
 {
-       struct fio_mutex *mutex = data;
+       struct fio_sem *sem = data;
        int ret;
 
        ret = fio_setaffinity(gettid(), fio_gtod_cpumask);
 
-       fio_mutex_up(mutex);
+       fio_sem_up(sem);
 
        if (ret == -1) {
                log_err("gtod: setaffinity failed\n");
@@ -69,17 +69,17 @@ static void *gtod_thread_main(void *data)
 
 int fio_start_gtod_thread(void)
 {
-       struct fio_mutex *mutex;
+       struct fio_sem *sem;
        pthread_attr_t attr;
        int ret;
 
-       mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
-       if (!mutex)
+       sem = fio_sem_init(FIO_SEM_LOCKED);
+       if (!sem)
                return 1;
 
        pthread_attr_init(&attr);
        pthread_attr_setstacksize(&attr, 2 * PTHREAD_STACK_MIN);
-       ret = pthread_create(&gtod_thread, &attr, gtod_thread_main, mutex);
+       ret = pthread_create(&gtod_thread, &attr, gtod_thread_main, sem);
        pthread_attr_destroy(&attr);
        if (ret) {
                log_err("Can't create gtod thread: %s\n", strerror(ret));
@@ -92,11 +92,11 @@ int fio_start_gtod_thread(void)
                goto err;
        }
 
-       dprint(FD_MUTEX, "wait on startup_mutex\n");
-       fio_mutex_down(mutex);
-       dprint(FD_MUTEX, "done waiting on startup_mutex\n");
+       dprint(FD_MUTEX, "wait on startup_sem\n");
+       fio_sem_down(sem);
+       dprint(FD_MUTEX, "done waiting on startup_sem\n");
 err:
-       fio_mutex_remove(mutex);
+       fio_sem_remove(sem);
        return ret;
 }
 
index 1d89d3a17ce070aa70d781e2b1fe1cb1af67c72f..c890da4a3869327a9a5387d1f306487e8488cb1a 100644 (file)
@@ -12,7 +12,7 @@ static struct helper_data {
        pthread_t thread;
        pthread_mutex_t lock;
        pthread_cond_t cond;
-       struct fio_mutex *startup_mutex;
+       struct fio_sem *startup_sem;
 } *helper_data;
 
 void helper_thread_destroy(void)
@@ -84,7 +84,7 @@ static void *helper_thread_main(void *data)
        memcpy(&last_du, &ts, sizeof(ts));
        memcpy(&last_ss, &ts, sizeof(ts));
 
-       fio_mutex_up(hd->startup_mutex);
+       fio_sem_up(hd->startup_sem);
 
        msec_to_next_event = DISK_UTIL_MSEC;
        while (!ret && !hd->exit) {
@@ -152,7 +152,7 @@ static void *helper_thread_main(void *data)
        return NULL;
 }
 
-int helper_thread_create(struct fio_mutex *startup_mutex, struct sk_out *sk_out)
+int helper_thread_create(struct fio_sem *startup_sem, struct sk_out *sk_out)
 {
        struct helper_data *hd;
        int ret;
@@ -168,7 +168,7 @@ int helper_thread_create(struct fio_mutex *startup_mutex, struct sk_out *sk_out)
        if (ret)
                return 1;
 
-       hd->startup_mutex = startup_mutex;
+       hd->startup_sem = startup_sem;
 
        ret = pthread_create(&hd->thread, NULL, helper_thread_main, hd);
        if (ret) {
@@ -178,8 +178,8 @@ int helper_thread_create(struct fio_mutex *startup_mutex, struct sk_out *sk_out)
 
        helper_data = hd;
 
-       dprint(FD_MUTEX, "wait on startup_mutex\n");
-       fio_mutex_down(startup_mutex);
-       dprint(FD_MUTEX, "done waiting on startup_mutex\n");
+       dprint(FD_MUTEX, "wait on startup_sem\n");
+       fio_sem_down(startup_sem);
+       dprint(FD_MUTEX, "done waiting on startup_sem\n");
        return 0;
 }
index 78933b13253d01613b5c7996f81577aa3c8c78dd..d7df6c4d804d03693efae459a794366df599ce6f 100644 (file)
@@ -6,6 +6,6 @@ extern void helper_do_stat(void);
 extern bool helper_should_exit(void);
 extern void helper_thread_destroy(void);
 extern void helper_thread_exit(void);
-extern int helper_thread_create(struct fio_mutex *, struct sk_out *);
+extern int helper_thread_create(struct fio_sem *, struct sk_out *);
 
 #endif
diff --git a/init.c b/init.c
index bb0627b208a6c06bbcc4968744f838146f8060d3..53aba18899c9129986b06786d8f35c0436526de4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1471,7 +1471,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                        f->real_file_size = -1ULL;
        }
 
-       td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
+       td->sem = fio_sem_init(FIO_SEM_LOCKED);
 
        td->ts.clat_percentiles = o->clat_percentiles;
        td->ts.lat_percentiles = o->lat_percentiles;
diff --git a/mutex.c b/mutex.c
deleted file mode 100644 (file)
index 03291c7..0000000
--- a/mutex.c
+++ /dev/null
@@ -1,167 +0,0 @@
-#include <string.h>
-#include <sys/mman.h>
-#include <assert.h>
-
-#include "log.h"
-#include "mutex.h"
-#include "pshared.h"
-#include "os/os.h"
-#include "fio_time.h"
-#include "gettime.h"
-
-void __fio_mutex_remove(struct fio_mutex *mutex)
-{
-       assert(mutex->magic == FIO_MUTEX_MAGIC);
-       pthread_cond_destroy(&mutex->cond);
-
-       /*
-        * Ensure any subsequent attempt to grab this mutex will fail
-        * with an assert, instead of just silently hanging.
-        */
-       memset(mutex, 0, sizeof(*mutex));
-}
-
-void fio_mutex_remove(struct fio_mutex *mutex)
-{
-       __fio_mutex_remove(mutex);
-       munmap((void *) mutex, sizeof(*mutex));
-}
-
-int __fio_mutex_init(struct fio_mutex *mutex, int value)
-{
-       int ret;
-
-       mutex->value = value;
-       mutex->magic = FIO_MUTEX_MAGIC;
-
-       ret = mutex_cond_init_pshared(&mutex->lock, &mutex->cond);
-       if (ret)
-               return ret;
-
-       return 0;
-}
-
-struct fio_mutex *fio_mutex_init(int value)
-{
-       struct fio_mutex *mutex = NULL;
-
-       mutex = (void *) mmap(NULL, sizeof(struct fio_mutex),
-                               PROT_READ | PROT_WRITE,
-                               OS_MAP_ANON | MAP_SHARED, -1, 0);
-       if (mutex == MAP_FAILED) {
-               perror("mmap mutex");
-               return NULL;
-       }
-
-       if (!__fio_mutex_init(mutex, value))
-               return mutex;
-
-       fio_mutex_remove(mutex);
-       return NULL;
-}
-
-static bool mutex_timed_out(struct timespec *t, unsigned int msecs)
-{
-       struct timeval tv;
-       struct timespec now;
-
-       gettimeofday(&tv, NULL);
-       now.tv_sec = tv.tv_sec;
-       now.tv_nsec = tv.tv_usec * 1000;
-
-       return mtime_since(t, &now) >= msecs;
-}
-
-int fio_mutex_down_timeout(struct fio_mutex *mutex, unsigned int msecs)
-{
-       struct timeval tv_s;
-       struct timespec base;
-       struct timespec t;
-       int ret = 0;
-
-       assert(mutex->magic == FIO_MUTEX_MAGIC);
-
-       gettimeofday(&tv_s, NULL);
-       base.tv_sec = t.tv_sec = tv_s.tv_sec;
-       base.tv_nsec = t.tv_nsec = tv_s.tv_usec * 1000;
-
-       t.tv_sec += msecs / 1000;
-       t.tv_nsec += ((msecs * 1000000ULL) % 1000000000);
-       if (t.tv_nsec >= 1000000000) {
-               t.tv_nsec -= 1000000000;
-               t.tv_sec++;
-       }
-
-       pthread_mutex_lock(&mutex->lock);
-
-       mutex->waiters++;
-       while (!mutex->value && !ret) {
-               /*
-                * Some platforms (FreeBSD 9?) seems to return timed out
-                * way too early, double check.
-                */
-               ret = pthread_cond_timedwait(&mutex->cond, &mutex->lock, &t);
-               if (ret == ETIMEDOUT && !mutex_timed_out(&base, msecs))
-                       ret = 0;
-       }
-       mutex->waiters--;
-
-       if (!ret) {
-               mutex->value--;
-               pthread_mutex_unlock(&mutex->lock);
-               return 0;
-       }
-
-       pthread_mutex_unlock(&mutex->lock);
-       return ret;
-}
-
-bool fio_mutex_down_trylock(struct fio_mutex *mutex)
-{
-       bool ret = true;
-
-       assert(mutex->magic == FIO_MUTEX_MAGIC);
-
-       pthread_mutex_lock(&mutex->lock);
-       if (mutex->value) {
-               mutex->value--;
-               ret = false;
-       }
-       pthread_mutex_unlock(&mutex->lock);
-
-       return ret;
-}
-
-void fio_mutex_down(struct fio_mutex *mutex)
-{
-       assert(mutex->magic == FIO_MUTEX_MAGIC);
-
-       pthread_mutex_lock(&mutex->lock);
-
-       while (!mutex->value) {
-               mutex->waiters++;
-               pthread_cond_wait(&mutex->cond, &mutex->lock);
-               mutex->waiters--;
-       }
-
-       mutex->value--;
-       pthread_mutex_unlock(&mutex->lock);
-}
-
-void fio_mutex_up(struct fio_mutex *mutex)
-{
-       int do_wake = 0;
-
-       assert(mutex->magic == FIO_MUTEX_MAGIC);
-
-       pthread_mutex_lock(&mutex->lock);
-       read_barrier();
-       if (!mutex->value && mutex->waiters)
-               do_wake = 1;
-       mutex->value++;
-
-       if (do_wake)
-               pthread_cond_signal(&mutex->cond);
-
-       pthread_mutex_unlock(&mutex->lock);
-}
diff --git a/mutex.h b/mutex.h
deleted file mode 100644 (file)
index 0c39873..0000000
--- a/mutex.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef FIO_MUTEX_H
-#define FIO_MUTEX_H
-
-#include <pthread.h>
-#include "lib/types.h"
-
-#define FIO_MUTEX_MAGIC                0x4d555445U
-
-struct fio_mutex {
-       pthread_mutex_t lock;
-       pthread_cond_t cond;
-       int value;
-       int waiters;
-       int magic;
-};
-
-enum {
-       FIO_MUTEX_LOCKED        = 0,
-       FIO_MUTEX_UNLOCKED      = 1,
-};
-
-extern int __fio_mutex_init(struct fio_mutex *, int);
-extern struct fio_mutex *fio_mutex_init(int);
-extern void __fio_mutex_remove(struct fio_mutex *);
-extern void fio_mutex_remove(struct fio_mutex *);
-extern void fio_mutex_up(struct fio_mutex *);
-extern void fio_mutex_down(struct fio_mutex *);
-extern bool fio_mutex_down_trylock(struct fio_mutex *);
-extern int fio_mutex_down_timeout(struct fio_mutex *, unsigned int);
-
-#endif
index 3fa5afacba415a8bd4cc65850b22553c12974c8e..5d3bd2544ed9b714b5b769c2bbe7cf6bcb7c4a09 100644 (file)
@@ -38,7 +38,7 @@ struct act_slice {
 };
 
 struct act_run_data {
-       struct fio_mutex *mutex;
+       struct fio_sem *sem;
        unsigned int pending;
 
        struct act_slice *slices;
@@ -337,9 +337,9 @@ static int act_io_u_lat(struct thread_data *td, uint64_t nsec)
 
 static void get_act_ref(void)
 {
-       fio_mutex_down(act_run_data->mutex);
+       fio_sem_down(act_run_data->sem);
        act_run_data->pending++;
-       fio_mutex_up(act_run_data->mutex);
+       fio_sem_up(act_run_data->sem);
 }
 
 static int show_slice(struct act_slice *slice, unsigned int slice_num)
@@ -396,7 +396,7 @@ static void put_act_ref(struct thread_data *td)
        struct act_prof_data *apd = td->prof_data;
        unsigned int i, slice;
 
-       fio_mutex_down(act_run_data->mutex);
+       fio_sem_down(act_run_data->sem);
 
        if (!act_run_data->slices) {
                act_run_data->slices = calloc(apd->nr_slices, sizeof(struct act_slice));
@@ -416,7 +416,7 @@ static void put_act_ref(struct thread_data *td)
        if (!--act_run_data->pending)
                act_show_all_stats();
 
-       fio_mutex_up(act_run_data->mutex);
+       fio_sem_up(act_run_data->sem);
 }
 
 static int act_td_init(struct thread_data *td)
@@ -464,7 +464,7 @@ static struct profile_ops act_profile = {
 static void fio_init act_register(void)
 {
        act_run_data = calloc(1, sizeof(*act_run_data));
-       act_run_data->mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       act_run_data->sem = fio_sem_init(FIO_SEM_UNLOCKED);
 
        if (register_profile(&act_profile))
                log_err("fio: failed to register profile 'act'\n");
@@ -476,7 +476,7 @@ static void fio_exit act_unregister(void)
                free((void *) act_opts[++org_idx]);
 
        unregister_profile(&act_profile);
-       fio_mutex_remove(act_run_data->mutex);
+       fio_sem_remove(act_run_data->sem);
        free(act_run_data->slices);
        free(act_run_data);
        act_run_data = NULL;
index 959786f8b711647ebe703d40126c24de41a0598a..65d4484edae5b82fa01db3237ee7ed4ab7391a68 100644 (file)
--- a/server.c
+++ b/server.c
@@ -74,7 +74,7 @@ struct fio_fork_item {
 };
 
 struct cmd_reply {
-       struct fio_mutex lock;
+       struct fio_sem lock;
        void *data;
        size_t size;
        int error;
@@ -108,12 +108,12 @@ static const char *fio_server_ops[FIO_NET_CMD_NR] = {
 
 static void sk_lock(struct sk_out *sk_out)
 {
-       fio_mutex_down(&sk_out->lock);
+       fio_sem_down(&sk_out->lock);
 }
 
 static void sk_unlock(struct sk_out *sk_out)
 {
-       fio_mutex_up(&sk_out->lock);
+       fio_sem_up(&sk_out->lock);
 }
 
 void sk_out_assign(struct sk_out *sk_out)
@@ -129,9 +129,9 @@ void sk_out_assign(struct sk_out *sk_out)
 
 static void sk_out_free(struct sk_out *sk_out)
 {
-       __fio_mutex_remove(&sk_out->lock);
-       __fio_mutex_remove(&sk_out->wait);
-       __fio_mutex_remove(&sk_out->xmit);
+       __fio_sem_remove(&sk_out->lock);
+       __fio_sem_remove(&sk_out->wait);
+       __fio_sem_remove(&sk_out->xmit);
        sfree(sk_out);
 }
 
@@ -558,7 +558,7 @@ static void fio_net_queue_entry(struct sk_entry *entry)
                flist_add_tail(&entry->list, &sk_out->list);
                sk_unlock(sk_out);
 
-               fio_mutex_up(&sk_out->wait);
+               fio_sem_up(&sk_out->wait);
        }
 }
 
@@ -1039,7 +1039,7 @@ static int handle_command(struct sk_out *sk_out, struct flist_head *job_list,
                                memcpy(rep->data, in->data, in->size);
                        }
                }
-               fio_mutex_up(&rep->lock);
+               fio_sem_up(&rep->lock);
                break;
                }
        default:
@@ -1138,7 +1138,7 @@ static int handle_sk_entry(struct sk_out *sk_out, struct sk_entry *entry)
 {
        int ret;
 
-       fio_mutex_down(&sk_out->xmit);
+       fio_sem_down(&sk_out->xmit);
 
        if (entry->flags & SK_F_VEC)
                ret = send_vec_entry(sk_out, entry);
@@ -1150,7 +1150,7 @@ static int handle_sk_entry(struct sk_out *sk_out, struct sk_entry *entry)
                                        entry->size, &entry->tag, NULL);
        }
 
-       fio_mutex_up(&sk_out->xmit);
+       fio_sem_up(&sk_out->xmit);
 
        if (ret)
                log_err("fio: failed handling cmd %s\n", fio_server_op(entry->opcode));
@@ -1215,7 +1215,7 @@ static int handle_connection(struct sk_out *sk_out)
                                break;
                        } else if (!ret) {
                                fio_server_check_jobs(&job_list);
-                               fio_mutex_down_timeout(&sk_out->wait, timeout);
+                               fio_sem_down_timeout(&sk_out->wait, timeout);
                                continue;
                        }
 
@@ -1361,9 +1361,9 @@ static int accept_loop(int listen_sk)
                sk_out = smalloc(sizeof(*sk_out));
                sk_out->sk = sk;
                INIT_FLIST_HEAD(&sk_out->list);
-               __fio_mutex_init(&sk_out->lock, FIO_MUTEX_UNLOCKED);
-               __fio_mutex_init(&sk_out->wait, FIO_MUTEX_LOCKED);
-               __fio_mutex_init(&sk_out->xmit, FIO_MUTEX_UNLOCKED);
+               __fio_sem_init(&sk_out->lock, FIO_SEM_UNLOCKED);
+               __fio_sem_init(&sk_out->wait, FIO_SEM_LOCKED);
+               __fio_sem_init(&sk_out->xmit, FIO_SEM_UNLOCKED);
 
                pid = fork();
                if (pid) {
@@ -2033,7 +2033,7 @@ int fio_server_get_verify_state(const char *name, int threadnumber,
        if (!rep)
                return ENOMEM;
 
-       __fio_mutex_init(&rep->lock, FIO_MUTEX_LOCKED);
+       __fio_sem_init(&rep->lock, FIO_SEM_LOCKED);
        rep->data = NULL;
        rep->error = 0;
 
@@ -2046,7 +2046,7 @@ int fio_server_get_verify_state(const char *name, int threadnumber,
        /*
         * Wait for the backend to receive the reply
         */
-       if (fio_mutex_down_timeout(&rep->lock, 10000)) {
+       if (fio_sem_down_timeout(&rep->lock, 10000)) {
                log_err("fio: timed out waiting for reply\n");
                ret = ETIMEDOUT;
                goto fail;
@@ -2083,7 +2083,7 @@ fail:
        *datap = data;
 
        sfree(rep->data);
-       __fio_mutex_remove(&rep->lock);
+       __fio_sem_remove(&rep->lock);
        sfree(rep);
        return ret;
 }
index bd892fcc1ad6b02c70a35569435f1d5b5484cba4..d652d31cf8992b5233b21fad77765a2e13426ece 100644 (file)
--- a/server.h
+++ b/server.h
@@ -17,10 +17,10 @@ struct sk_out {
                                 * protected by below ->lock */
 
        int sk;                 /* socket fd to talk to client */
-       struct fio_mutex lock;  /* protects ref and below list */
+       struct fio_sem lock;    /* protects ref and below list */
        struct flist_head list; /* list of pending transmit work */
-       struct fio_mutex wait;  /* wake backend when items added to list */
-       struct fio_mutex xmit;  /* held while sending data */
+       struct fio_sem wait;    /* wake backend when items added to list */
+       struct fio_sem xmit;    /* held while sending data */
 };
 
 /*
index cab7132511b1729b152278f119d300c83f54b5d2..d19e108a35e0919aada104e4965471e32d8e7384 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -14,7 +14,7 @@
 #include <fcntl.h>
 
 #include "fio.h"
-#include "mutex.h"
+#include "fio_sem.h"
 #include "arch/arch.h"
 #include "os/os.h"
 #include "smalloc.h"
@@ -40,7 +40,7 @@ static const int int_mask = sizeof(int) - 1;
 #endif
 
 struct pool {
-       struct fio_mutex *lock;                 /* protects this pool */
+       struct fio_sem *lock;                   /* protects this pool */
        void *map;                              /* map of blocks */
        unsigned int *bitmap;                   /* blocks free/busy map */
        size_t free_blocks;             /* free blocks */
@@ -192,7 +192,7 @@ static bool add_pool(struct pool *pool, unsigned int alloc_size)
        pool->bitmap = (unsigned int *)((char *) ptr + (pool->nr_blocks * SMALLOC_BPL));
        memset(pool->bitmap, 0, bitmap_blocks * sizeof(unsigned int));
 
-       pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       pool->lock = fio_sem_init(FIO_SEM_UNLOCKED);
        if (!pool->lock)
                goto out_fail;
 
@@ -232,7 +232,7 @@ static void cleanup_pool(struct pool *pool)
        munmap(pool->map, pool->mmap_size);
 
        if (pool->lock)
-               fio_mutex_remove(pool->lock);
+               fio_sem_remove(pool->lock);
 }
 
 void scleanup(void)
@@ -309,12 +309,12 @@ static void sfree_pool(struct pool *pool, void *ptr)
        i = offset / SMALLOC_BPL;
        idx = (offset % SMALLOC_BPL) / SMALLOC_BPB;
 
-       fio_mutex_down(pool->lock);
+       fio_sem_down(pool->lock);
        clear_blocks(pool, i, idx, size_to_blocks(hdr->size));
        if (i < pool->next_non_full)
                pool->next_non_full = i;
        pool->free_blocks += size_to_blocks(hdr->size);
-       fio_mutex_up(pool->lock);
+       fio_sem_up(pool->lock);
 }
 
 void sfree(void *ptr)
@@ -348,7 +348,7 @@ static void *__smalloc_pool(struct pool *pool, size_t size)
        unsigned int last_idx;
        void *ret = NULL;
 
-       fio_mutex_down(pool->lock);
+       fio_sem_down(pool->lock);
 
        nr_blocks = size_to_blocks(size);
        if (nr_blocks > pool->free_blocks)
@@ -391,7 +391,7 @@ static void *__smalloc_pool(struct pool *pool, size_t size)
                ret = pool->map + offset;
        }
 fail:
-       fio_mutex_up(pool->lock);
+       fio_sem_up(pool->lock);
        return ret;
 }
 
diff --git a/stat.c b/stat.c
index 8a242c97430bd0bff2502013af5fd848a2a57881..98ab63893900bcc09ba9a5be785dceffa30b1fff 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -20,7 +20,7 @@
 
 #define LOG_MSEC_SLACK 1
 
-struct fio_mutex *stat_mutex;
+struct fio_sem *stat_sem;
 
 void clear_rusage_stat(struct thread_data *td)
 {
@@ -1946,9 +1946,9 @@ void __show_run_stats(void)
 
 void show_run_stats(void)
 {
-       fio_mutex_down(stat_mutex);
+       fio_sem_down(stat_sem);
        __show_run_stats();
-       fio_mutex_up(stat_mutex);
+       fio_sem_up(stat_sem);
 }
 
 void __show_running_run_stats(void)
@@ -1958,7 +1958,7 @@ void __show_running_run_stats(void)
        struct timespec ts;
        int i;
 
-       fio_mutex_down(stat_mutex);
+       fio_sem_down(stat_sem);
 
        rt = malloc(thread_number * sizeof(unsigned long long));
        fio_gettime(&ts, NULL);
@@ -1984,7 +1984,7 @@ void __show_running_run_stats(void)
                        continue;
                if (td->rusage_sem) {
                        td->update_rusage = 1;
-                       fio_mutex_down(td->rusage_sem);
+                       fio_sem_down(td->rusage_sem);
                }
                td->update_rusage = 0;
        }
@@ -2001,7 +2001,7 @@ void __show_running_run_stats(void)
        }
 
        free(rt);
-       fio_mutex_up(stat_mutex);
+       fio_sem_up(stat_sem);
 }
 
 static bool status_interval_init;
@@ -2690,7 +2690,7 @@ int calc_log_samples(void)
 
 void stat_init(void)
 {
-       stat_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       stat_sem = fio_sem_init(FIO_SEM_UNLOCKED);
 }
 
 void stat_exit(void)
@@ -2699,8 +2699,8 @@ void stat_exit(void)
         * When we have the mutex, we know out-of-band access to it
         * have ended.
         */
-       fio_mutex_down(stat_mutex);
-       fio_mutex_remove(stat_mutex);
+       fio_sem_down(stat_sem);
+       fio_sem_remove(stat_sem);
 }
 
 /*
diff --git a/stat.h b/stat.h
index 7580f0d6cdab63c431f15195178d77a4636685ff..8e7bcdb24d1e187194d9c65368bbf82db550279c 100644 (file)
--- a/stat.h
+++ b/stat.h
@@ -277,7 +277,7 @@ struct io_u_plat_entry {
        uint64_t io_u_plat[FIO_IO_U_PLAT_NR];
 };
 
-extern struct fio_mutex *stat_mutex;
+extern struct fio_sem *stat_sem;
 
 extern struct jobs_eta *get_jobs_eta(bool force, size_t *size);
 
index 9a50821ed972921d926bb87ff8d2c9d7836f3561..1b4277c1b9d3c17b20dccb9df16e7092552f4123 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "../flist.h"
 #include "../log.h"
-#include "../mutex.h"
+#include "../fio_sem.h"
 #include "../smalloc.h"
 #include "../minmax.h"
 #include "../crc/md5.h"
@@ -62,7 +62,7 @@ struct item {
 
 static struct rb_root rb_root;
 static struct bloom *bloom;
-static struct fio_mutex *rb_lock;
+static struct fio_sem *rb_lock;
 
 static unsigned int blocksize = 4096;
 static unsigned int num_threads;
@@ -75,7 +75,7 @@ static unsigned int use_bloom = 1;
 
 static uint64_t total_size;
 static uint64_t cur_offset;
-static struct fio_mutex *size_lock;
+static struct fio_sem *size_lock;
 
 static struct fio_file file;
 
@@ -102,7 +102,7 @@ static int get_work(uint64_t *offset, uint64_t *size)
        uint64_t this_chunk;
        int ret = 1;
 
-       fio_mutex_down(size_lock);
+       fio_sem_down(size_lock);
 
        if (cur_offset < total_size) {
                *offset = cur_offset;
@@ -112,7 +112,7 @@ static int get_work(uint64_t *offset, uint64_t *size)
                ret = 0;
        }
 
-       fio_mutex_up(size_lock);
+       fio_sem_up(size_lock);
        return ret;
 }
 
@@ -215,9 +215,9 @@ static void insert_chunk(struct item *i)
                        if (!collision_check)
                                goto add;
 
-                       fio_mutex_up(rb_lock);
+                       fio_sem_up(rb_lock);
                        ret = col_check(c, i);
-                       fio_mutex_down(rb_lock);
+                       fio_sem_down(rb_lock);
 
                        if (!ret)
                                goto add;
@@ -241,7 +241,7 @@ static void insert_chunks(struct item *items, unsigned int nitems,
 {
        int i;
 
-       fio_mutex_down(rb_lock);
+       fio_sem_down(rb_lock);
 
        for (i = 0; i < nitems; i++) {
                if (bloom) {
@@ -255,7 +255,7 @@ static void insert_chunks(struct item *items, unsigned int nitems,
                        insert_chunk(&items[i]);
        }
 
-       fio_mutex_up(rb_lock);
+       fio_sem_up(rb_lock);
 }
 
 static void crc_buf(void *buf, uint32_t *hash)
@@ -383,7 +383,7 @@ static int run_dedupe_threads(struct fio_file *f, uint64_t dev_size,
        total_size = dev_size;
        total_items = dev_size / blocksize;
        cur_offset = 0;
-       size_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       size_lock = fio_sem_init(FIO_SEM_UNLOCKED);
 
        threads = malloc(num_threads * sizeof(struct worker_thread));
        for (i = 0; i < num_threads; i++) {
@@ -414,7 +414,7 @@ static int run_dedupe_threads(struct fio_file *f, uint64_t dev_size,
        *nextents = nitems;
        *nchunks = nitems - *nchunks;
 
-       fio_mutex_remove(size_lock);
+       fio_sem_remove(size_lock);
        free(threads);
        return err;
 }
@@ -581,7 +581,7 @@ int main(int argc, char *argv[])
        sinit();
 
        rb_root = RB_ROOT;
-       rb_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
+       rb_lock = fio_sem_init(FIO_SEM_UNLOCKED);
 
        ret = dedupe_check(argv[optind], &nextents, &nchunks);
 
@@ -592,7 +592,7 @@ int main(int argc, char *argv[])
                show_stat(nextents, nchunks);
        }
 
-       fio_mutex_remove(rb_lock);
+       fio_sem_remove(rb_lock);
        if (bloom)
                bloom_free(bloom);
        scleanup();