summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Van Assche <bart.vanassche@wdc.com>2018-03-14 08:26:15 -0700
committerBart Van Assche <bart.vanassche@wdc.com>2018-03-15 09:54:43 -0700
commitae626d4ead6416adf464cf209cdf3e8b85d58190 (patch)
treefcb28a72a7ed2d29a432e9aa386e949fa9041b86
parent69b98f11d62cb12482130fac79b8ebf00c0bb139 (diff)
Split mutex.c and .h each into three files
Create separate header and source files for the struct fio_mutex functions, for the struct fio_rwlock functions and for the helper functions for initializing process shared mutexes and condition variables. Replace an #include directive by a forward declaration in fio.h. Minimize the #include directives in mutex.c, rwlock.c and pshared.c. This patch does not change any functionality. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
-rw-r--r--Makefile13
-rw-r--r--backend.c1
-rw-r--r--diskutil.h1
-rw-r--r--filesetup.c1
-rw-r--r--fio.h3
-rw-r--r--helper_thread.c1
-rw-r--r--iolog.c1
-rw-r--r--mutex.c157
-rw-r--r--mutex.h16
-rw-r--r--pshared.c76
-rw-r--r--pshared.h10
-rw-r--r--rwlock.c82
-rw-r--r--rwlock.h19
-rw-r--r--workqueue.c1
14 files changed, 204 insertions, 178 deletions
diff --git a/Makefile b/Makefile
index d73b944..ce1deed 100644
--- a/Makefile
+++ b/Makefile
@@ -41,7 +41,8 @@ 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 options.c \
+ eta.c verify.c memory.c io_u.c parse.c mutex.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 \
engines/ftruncate.c engines/filecreate.c \
@@ -211,7 +212,8 @@ endif
-include $(OBJS:.o=.d)
T_SMALLOC_OBJS = t/stest.o
-T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o t/debug.o t/arch.o
+T_SMALLOC_OBJS += gettime.o mutex.o pshared.o smalloc.o t/log.o t/debug.o \
+ t/arch.o
T_SMALLOC_PROGS = t/stest
T_IEEE_OBJS = t/ieee754.o
@@ -244,9 +246,10 @@ 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 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
+T_DEDUPE_OBJS += lib/rbtree.o t/log.o mutex.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
T_DEDUPE_PROGS = t/fio-dedupe
T_VS_OBJS = t/verify-state.o t/log.o crc/crc32c.o crc/crc32c-intel.o crc/crc32c-arm64.o t/debug.o
diff --git a/backend.c b/backend.c
index b4a09ac..69220e4 100644
--- a/backend.c
+++ b/backend.c
@@ -58,6 +58,7 @@
#include "lib/mountcheck.h"
#include "rate-submit.h"
#include "helper_thread.h"
+#include "pshared.h"
static struct fio_mutex *startup_mutex;
static struct flist_head *cgroup_list;
diff --git a/diskutil.h b/diskutil.h
index 91b4202..ee5c0af 100644
--- a/diskutil.h
+++ b/diskutil.h
@@ -5,6 +5,7 @@
#include "lib/output_buffer.h"
#include "helper_thread.h"
+#include "mutex.h"
struct disk_util_stats {
uint64_t ios[2];
diff --git a/filesetup.c b/filesetup.c
index 1a187ff..4b0f40d 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -15,6 +15,7 @@
#include "os/os.h"
#include "hash.h"
#include "lib/axmap.h"
+#include "rwlock.h"
#ifdef CONFIG_LINUX_FALLOCATE
#include <linux/falloc.h>
diff --git a/fio.h b/fio.h
index 85546c5..0f6dfb6 100644
--- a/fio.h
+++ b/fio.h
@@ -20,7 +20,6 @@
#include "fifo.h"
#include "arch/arch.h"
#include "os/os.h"
-#include "mutex.h"
#include "log.h"
#include "debug.h"
#include "file.h"
@@ -63,6 +62,8 @@
#include <cuda.h>
#endif
+struct fio_mutex;
+
/*
* offset generator types
*/
diff --git a/helper_thread.c b/helper_thread.c
index b05f821..1d89d3a 100644
--- a/helper_thread.c
+++ b/helper_thread.c
@@ -2,6 +2,7 @@
#include "smalloc.h"
#include "helper_thread.h"
#include "steadystate.h"
+#include "pshared.h"
static struct helper_data {
volatile int exit;
diff --git a/iolog.c b/iolog.c
index 7d5a136..460d7a2 100644
--- a/iolog.c
+++ b/iolog.c
@@ -20,6 +20,7 @@
#include "filelock.h"
#include "smalloc.h"
#include "blktrace.h"
+#include "pshared.h"
static int iolog_flush(struct io_log *log);
diff --git a/mutex.c b/mutex.c
index acc88dc..03291c7 100644
--- a/mutex.c
+++ b/mutex.c
@@ -1,20 +1,11 @@
-#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <time.h>
-#include <errno.h>
-#include <pthread.h>
#include <sys/mman.h>
#include <assert.h>
-#include "fio.h"
#include "log.h"
#include "mutex.h"
-#include "arch/arch.h"
+#include "pshared.h"
#include "os/os.h"
-#include "helpers.h"
#include "fio_time.h"
#include "gettime.h"
@@ -36,78 +27,6 @@ void fio_mutex_remove(struct fio_mutex *mutex)
munmap((void *) mutex, sizeof(*mutex));
}
-int cond_init_pshared(pthread_cond_t *cond)
-{
- pthread_condattr_t cattr;
- int ret;
-
- ret = pthread_condattr_init(&cattr);
- if (ret) {
- log_err("pthread_condattr_init: %s\n", strerror(ret));
- return ret;
- }
-
-#ifdef CONFIG_PSHARED
- ret = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
- if (ret) {
- log_err("pthread_condattr_setpshared: %s\n", strerror(ret));
- return ret;
- }
-#endif
- ret = pthread_cond_init(cond, &cattr);
- if (ret) {
- log_err("pthread_cond_init: %s\n", strerror(ret));
- return ret;
- }
-
- return 0;
-}
-
-int mutex_init_pshared(pthread_mutex_t *mutex)
-{
- pthread_mutexattr_t mattr;
- int ret;
-
- ret = pthread_mutexattr_init(&mattr);
- if (ret) {
- log_err("pthread_mutexattr_init: %s\n", strerror(ret));
- return ret;
- }
-
- /*
- * Not all platforms support process shared mutexes (FreeBSD)
- */
-#ifdef CONFIG_PSHARED
- ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
- if (ret) {
- log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
- return ret;
- }
-#endif
- ret = pthread_mutex_init(mutex, &mattr);
- if (ret) {
- log_err("pthread_mutex_init: %s\n", strerror(ret));
- return ret;
- }
-
- return 0;
-}
-
-int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond)
-{
- int ret;
-
- ret = mutex_init_pshared(mutex);
- if (ret)
- return ret;
-
- ret = cond_init_pshared(cond);
- if (ret)
- return ret;
-
- return 0;
-}
-
int __fio_mutex_init(struct fio_mutex *mutex, int value)
{
int ret;
@@ -246,77 +165,3 @@ void fio_mutex_up(struct fio_mutex *mutex)
pthread_mutex_unlock(&mutex->lock);
}
-
-void fio_rwlock_write(struct fio_rwlock *lock)
-{
- assert(lock->magic == FIO_RWLOCK_MAGIC);
- pthread_rwlock_wrlock(&lock->lock);
-}
-
-void fio_rwlock_read(struct fio_rwlock *lock)
-{
- assert(lock->magic == FIO_RWLOCK_MAGIC);
- pthread_rwlock_rdlock(&lock->lock);
-}
-
-void fio_rwlock_unlock(struct fio_rwlock *lock)
-{
- assert(lock->magic == FIO_RWLOCK_MAGIC);
- pthread_rwlock_unlock(&lock->lock);
-}
-
-void fio_rwlock_remove(struct fio_rwlock *lock)
-{
- assert(lock->magic == FIO_RWLOCK_MAGIC);
- munmap((void *) lock, sizeof(*lock));
-}
-
-struct fio_rwlock *fio_rwlock_init(void)
-{
- struct fio_rwlock *lock;
- pthread_rwlockattr_t attr;
- int ret;
-
- lock = (void *) mmap(NULL, sizeof(struct fio_rwlock),
- PROT_READ | PROT_WRITE,
- OS_MAP_ANON | MAP_SHARED, -1, 0);
- if (lock == MAP_FAILED) {
- perror("mmap rwlock");
- lock = NULL;
- goto err;
- }
-
- lock->magic = FIO_RWLOCK_MAGIC;
-
- ret = pthread_rwlockattr_init(&attr);
- if (ret) {
- log_err("pthread_rwlockattr_init: %s\n", strerror(ret));
- goto err;
- }
-#ifdef CONFIG_PSHARED
- ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
- if (ret) {
- log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret));
- goto destroy_attr;
- }
-
- ret = pthread_rwlock_init(&lock->lock, &attr);
-#else
- ret = pthread_rwlock_init(&lock->lock, NULL);
-#endif
-
- if (ret) {
- log_err("pthread_rwlock_init: %s\n", strerror(ret));
- goto destroy_attr;
- }
-
- pthread_rwlockattr_destroy(&attr);
-
- return lock;
-destroy_attr:
- pthread_rwlockattr_destroy(&attr);
-err:
- if (lock)
- fio_rwlock_remove(lock);
- return NULL;
-}
diff --git a/mutex.h b/mutex.h
index 54009ba..0c39873 100644
--- a/mutex.h
+++ b/mutex.h
@@ -5,7 +5,6 @@
#include "lib/types.h"
#define FIO_MUTEX_MAGIC 0x4d555445U
-#define FIO_RWLOCK_MAGIC 0x52574c4fU
struct fio_mutex {
pthread_mutex_t lock;
@@ -15,11 +14,6 @@ struct fio_mutex {
int magic;
};
-struct fio_rwlock {
- pthread_rwlock_t lock;
- int magic;
-};
-
enum {
FIO_MUTEX_LOCKED = 0,
FIO_MUTEX_UNLOCKED = 1,
@@ -34,14 +28,4 @@ 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);
-extern void fio_rwlock_read(struct fio_rwlock *);
-extern void fio_rwlock_write(struct fio_rwlock *);
-extern void fio_rwlock_unlock(struct fio_rwlock *);
-extern struct fio_rwlock *fio_rwlock_init(void);
-extern void fio_rwlock_remove(struct fio_rwlock *);
-
-extern int mutex_init_pshared(pthread_mutex_t *);
-extern int cond_init_pshared(pthread_cond_t *);
-extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *);
-
#endif
diff --git a/pshared.c b/pshared.c
new file mode 100644
index 0000000..74812ed
--- /dev/null
+++ b/pshared.c
@@ -0,0 +1,76 @@
+#include <string.h>
+
+#include "log.h"
+#include "pshared.h"
+
+int cond_init_pshared(pthread_cond_t *cond)
+{
+ pthread_condattr_t cattr;
+ int ret;
+
+ ret = pthread_condattr_init(&cattr);
+ if (ret) {
+ log_err("pthread_condattr_init: %s\n", strerror(ret));
+ return ret;
+ }
+
+#ifdef CONFIG_PSHARED
+ ret = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
+ if (ret) {
+ log_err("pthread_condattr_setpshared: %s\n", strerror(ret));
+ return ret;
+ }
+#endif
+ ret = pthread_cond_init(cond, &cattr);
+ if (ret) {
+ log_err("pthread_cond_init: %s\n", strerror(ret));
+ return ret;
+ }
+
+ return 0;
+}
+
+int mutex_init_pshared(pthread_mutex_t *mutex)
+{
+ pthread_mutexattr_t mattr;
+ int ret;
+
+ ret = pthread_mutexattr_init(&mattr);
+ if (ret) {
+ log_err("pthread_mutexattr_init: %s\n", strerror(ret));
+ return ret;
+ }
+
+ /*
+ * Not all platforms support process shared mutexes (FreeBSD)
+ */
+#ifdef CONFIG_PSHARED
+ ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
+ if (ret) {
+ log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
+ return ret;
+ }
+#endif
+ ret = pthread_mutex_init(mutex, &mattr);
+ if (ret) {
+ log_err("pthread_mutex_init: %s\n", strerror(ret));
+ return ret;
+ }
+
+ return 0;
+}
+
+int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond)
+{
+ int ret;
+
+ ret = mutex_init_pshared(mutex);
+ if (ret)
+ return ret;
+
+ ret = cond_init_pshared(cond);
+ if (ret)
+ return ret;
+
+ return 0;
+}
diff --git a/pshared.h b/pshared.h
new file mode 100644
index 0000000..a58df6f
--- /dev/null
+++ b/pshared.h
@@ -0,0 +1,10 @@
+#ifndef FIO_PSHARED_H
+#define FIO_PSHARED_H
+
+#include <pthread.h>
+
+extern int mutex_init_pshared(pthread_mutex_t *);
+extern int cond_init_pshared(pthread_cond_t *);
+extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *);
+
+#endif
diff --git a/rwlock.c b/rwlock.c
new file mode 100644
index 0000000..7d9ad73
--- /dev/null
+++ b/rwlock.c
@@ -0,0 +1,82 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "log.h"
+#include "rwlock.h"
+#include "os/os.h"
+
+void fio_rwlock_write(struct fio_rwlock *lock)
+{
+ assert(lock->magic == FIO_RWLOCK_MAGIC);
+ pthread_rwlock_wrlock(&lock->lock);
+}
+
+void fio_rwlock_read(struct fio_rwlock *lock)
+{
+ assert(lock->magic == FIO_RWLOCK_MAGIC);
+ pthread_rwlock_rdlock(&lock->lock);
+}
+
+void fio_rwlock_unlock(struct fio_rwlock *lock)
+{
+ assert(lock->magic == FIO_RWLOCK_MAGIC);
+ pthread_rwlock_unlock(&lock->lock);
+}
+
+void fio_rwlock_remove(struct fio_rwlock *lock)
+{
+ assert(lock->magic == FIO_RWLOCK_MAGIC);
+ munmap((void *) lock, sizeof(*lock));
+}
+
+struct fio_rwlock *fio_rwlock_init(void)
+{
+ struct fio_rwlock *lock;
+ pthread_rwlockattr_t attr;
+ int ret;
+
+ lock = (void *) mmap(NULL, sizeof(struct fio_rwlock),
+ PROT_READ | PROT_WRITE,
+ OS_MAP_ANON | MAP_SHARED, -1, 0);
+ if (lock == MAP_FAILED) {
+ perror("mmap rwlock");
+ lock = NULL;
+ goto err;
+ }
+
+ lock->magic = FIO_RWLOCK_MAGIC;
+
+ ret = pthread_rwlockattr_init(&attr);
+ if (ret) {
+ log_err("pthread_rwlockattr_init: %s\n", strerror(ret));
+ goto err;
+ }
+#ifdef CONFIG_PSHARED
+ ret = pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ if (ret) {
+ log_err("pthread_rwlockattr_setpshared: %s\n", strerror(ret));
+ goto destroy_attr;
+ }
+
+ ret = pthread_rwlock_init(&lock->lock, &attr);
+#else
+ ret = pthread_rwlock_init(&lock->lock, NULL);
+#endif
+
+ if (ret) {
+ log_err("pthread_rwlock_init: %s\n", strerror(ret));
+ goto destroy_attr;
+ }
+
+ pthread_rwlockattr_destroy(&attr);
+
+ return lock;
+destroy_attr:
+ pthread_rwlockattr_destroy(&attr);
+err:
+ if (lock)
+ fio_rwlock_remove(lock);
+ return NULL;
+}
diff --git a/rwlock.h b/rwlock.h
new file mode 100644
index 0000000..2968eed
--- /dev/null
+++ b/rwlock.h
@@ -0,0 +1,19 @@
+#ifndef FIO_RWLOCK_H
+#define FIO_RWLOCK_H
+
+#include <pthread.h>
+
+#define FIO_RWLOCK_MAGIC 0x52574c4fU
+
+struct fio_rwlock {
+ pthread_rwlock_t lock;
+ int magic;
+};
+
+extern void fio_rwlock_read(struct fio_rwlock *);
+extern void fio_rwlock_write(struct fio_rwlock *);
+extern void fio_rwlock_unlock(struct fio_rwlock *);
+extern struct fio_rwlock *fio_rwlock_init(void);
+extern void fio_rwlock_remove(struct fio_rwlock *);
+
+#endif
diff --git a/workqueue.c b/workqueue.c
index 18ec198..841dbb9 100644
--- a/workqueue.c
+++ b/workqueue.c
@@ -10,6 +10,7 @@
#include "flist.h"
#include "workqueue.h"
#include "smalloc.h"
+#include "pshared.h"
enum {
SW_F_IDLE = 1 << 0,