Recent changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following changes since commit 99614958d743d0fdea9b1875d3a41a5a51e9769d:

  Revert "diskutil: ensure that we lock around disk_list access" (2012-08-01 20:25:53 +0200)

are available in the git repository at:
  git://git.kernel.dk/fio.git master

Jens Axboe (2):
      diskutil: ensure that we lock around disk_list access
      mutex: make 0/1 FIO_MUTEX_LOCKED and FIO_MUTEX_UNLOCKED

 backend.c   |   24 ++++++++++++++++++++----
 cgroup.c    |    2 +-
 diskutil.c  |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 diskutil.h  |   11 +++++++++--
 filehash.c  |    2 +-
 filesetup.c |    2 +-
 flow.c      |    2 +-
 gettime.c   |    2 +-
 init.c      |    2 +-
 iolog.h     |    1 -
 mutex.h     |    5 +++++
 smalloc.c   |    2 +-
 12 files changed, 89 insertions(+), 22 deletions(-)

---

Diff of recent changes:

diff --git a/backend.c b/backend.c
index e1dc0ac..e41e8f1 100644
--- a/backend.c
+++ b/backend.c
@@ -50,6 +50,7 @@
 #include "server.h"
 
 static pthread_t disk_util_thread;
+static struct fio_mutex *disk_thread_mutex;
 static struct fio_mutex *startup_mutex;
 static struct fio_mutex *writeout_mutex;
 static struct flist_head *cgroup_list;
@@ -1588,20 +1589,28 @@ static void run_threads(void)
 	fio_unpin_memory();
 }
 
+void wait_for_disk_thread_exit(void)
+{
+	fio_mutex_down(disk_thread_mutex);
+}
+
 static void *disk_thread_main(void *data)
 {
+	int ret = 0;
+
 	fio_mutex_up(startup_mutex);
 
-	while (threads) {
+	while (threads && !ret) {
 		usleep(DISK_UTIL_MSEC * 1000);
 		if (!threads)
 			break;
-		update_io_ticks();
+		ret = update_io_ticks();
 
 		if (!is_backend)
 			print_thread_status();
 	}
 
+	fio_mutex_up(disk_thread_mutex);
 	return NULL;
 }
 
@@ -1609,14 +1618,20 @@ static int create_disk_util_thread(void)
 {
 	int ret;
 
+	setup_disk_util();
+
+	disk_thread_mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
+
 	ret = pthread_create(&disk_util_thread, NULL, disk_thread_main, NULL);
 	if (ret) {
+		fio_mutex_remove(disk_thread_mutex);
 		log_err("Can't create disk util thread: %s\n", strerror(ret));
 		return 1;
 	}
 
 	ret = pthread_detach(disk_util_thread);
 	if (ret) {
+		fio_mutex_remove(disk_thread_mutex);
 		log_err("Can't detatch disk util thread: %s\n", strerror(ret));
 		return 1;
 	}
@@ -1646,10 +1661,10 @@ int fio_backend(void)
 		setup_log(&agg_io_log[DDIR_WRITE], 0);
 	}
 
-	startup_mutex = fio_mutex_init(0);
+	startup_mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
 	if (startup_mutex == NULL)
 		return 1;
-	writeout_mutex = fio_mutex_init(1);
+	writeout_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 	if (writeout_mutex == NULL)
 		return 1;
 
@@ -1680,5 +1695,6 @@ int fio_backend(void)
 
 	fio_mutex_remove(startup_mutex);
 	fio_mutex_remove(writeout_mutex);
+	fio_mutex_remove(disk_thread_mutex);
 	return exit_value;
 }
diff --git a/cgroup.c b/cgroup.c
index ea6bbd6..86d4d5e 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -182,7 +182,7 @@ void cgroup_shutdown(struct thread_data *td, char **mnt)
 
 static void fio_init cgroup_init(void)
 {
-	lock = fio_mutex_init(1);
+	lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 }
 
 static void fio_exit cgroup_exit(void)
diff --git a/diskutil.c b/diskutil.c
index feb8852..a3a5b4d 100644
--- a/diskutil.c
+++ b/diskutil.c
@@ -14,6 +14,9 @@
 static int last_majdev, last_mindev;
 static struct disk_util *last_du;
 
+static struct fio_mutex *disk_util_mutex;
+static int disk_util_exit;
+
 FLIST_HEAD(disk_list);
 
 static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
@@ -102,17 +105,26 @@ static void update_io_tick_disk(struct disk_util *du)
 	memcpy(ldus, &__dus, sizeof(__dus));
 }
 
-void update_io_ticks(void)
+int update_io_ticks(void)
 {
 	struct flist_head *entry;
 	struct disk_util *du;
+	int ret = 0;
 
 	dprint(FD_DISKUTIL, "update io ticks\n");
 
-	flist_for_each(entry, &disk_list) {
-		du = flist_entry(entry, struct disk_util, list);
-		update_io_tick_disk(du);
-	}
+	fio_mutex_down(disk_util_mutex);
+
+	if (!disk_util_exit) {
+		flist_for_each(entry, &disk_list) {
+			du = flist_entry(entry, struct disk_util, list);
+			update_io_tick_disk(du);
+		}
+	} else
+		ret = 1;
+
+	fio_mutex_up(disk_util_mutex);
+	return ret;
 }
 
 static struct disk_util *disk_util_exists(int major, int minor)
@@ -120,13 +132,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);
+
 	flist_for_each(entry, &disk_list) {
 		du = flist_entry(entry, struct disk_util, list);
 
-		if (major == du->major && minor == du->minor)
+		if (major == du->major && minor == du->minor) {
+			fio_mutex_up(disk_util_mutex);
 			return du;
+		}
 	}
 
+	fio_mutex_up(disk_util_mutex);
 	return NULL;
 }
 
@@ -273,9 +290,11 @@ 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(1);
+	du->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 	du->users = 0;
 
+	fio_mutex_down(disk_util_mutex);
+
 	flist_for_each(entry, &disk_list) {
 		__du = flist_entry(entry, struct disk_util, list);
 
@@ -283,6 +302,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);
 			return __du;
 		}
 	}
@@ -293,6 +313,8 @@ 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);
+
 	find_add_disk_slaves(td, path, du);
 	return du;
 }
@@ -521,6 +543,11 @@ void free_disk_util(void)
 {
 	struct disk_util *du;
 
+	disk_util_exit = 1;
+	wait_for_disk_thread_exit();
+
+	fio_mutex_down(disk_util_mutex);
+
 	while (!flist_empty(&disk_list)) {
 		du = flist_entry(disk_list.next, struct disk_util, list);
 		flist_del(&du->list);
@@ -528,6 +555,8 @@ void free_disk_util(void)
 	}
 
 	last_majdev = last_mindev = -1;
+	fio_mutex_up(disk_util_mutex);
+	fio_mutex_remove(disk_util_mutex);
 }
 
 void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg,
@@ -573,8 +602,12 @@ void show_disk_util(int terse)
 	struct flist_head *entry;
 	struct disk_util *du;
 
-	if (flist_empty(&disk_list))
+	fio_mutex_down(disk_util_mutex);
+
+	if (flist_empty(&disk_list)) {
+		fio_mutex_up(disk_util_mutex);
 		return;
+	}
 
 	if (!terse)
 		log_info("\nDisk stats (read/write):\n");
@@ -585,4 +618,11 @@ void show_disk_util(int terse)
 		aggregate_slaves_stats(du);
 		print_disk_util(&du->dus, &du->agg, terse);
 	}
+
+	fio_mutex_up(disk_util_mutex);
+}
+
+void setup_disk_util(void)
+{
+	disk_util_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 }
diff --git a/diskutil.h b/diskutil.h
index 5a9b079..88dde55 100644
--- a/diskutil.h
+++ b/diskutil.h
@@ -94,6 +94,8 @@ static inline void disk_util_dec(struct disk_util *du)
 
 extern struct flist_head disk_list;
 
+extern void wait_for_disk_thread_exit(void);
+
 /*
  * disk util stuff
  */
@@ -102,13 +104,18 @@ extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int
 extern void show_disk_util(int terse);
 extern void free_disk_util(void);
 extern void init_disk_util(struct thread_data *);
-extern void update_io_ticks(void);
+extern int update_io_ticks(void);
+extern void setup_disk_util(void);
 #else
 #define print_disk_util(dus, agg, terse)
 #define show_disk_util(terse)
 #define free_disk_util()
 #define init_disk_util(td)
-#define update_io_ticks()
+#define setup_disk_util()
+static inline int update_io_ticks(void)
+{
+	return 0;
+}
 #endif
 
 #endif
diff --git a/filehash.c b/filehash.c
index 1bb1eb2..392464e 100644
--- a/filehash.c
+++ b/filehash.c
@@ -107,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_mutex_init(FIO_MUTEX_UNLOCKED);
 }
diff --git a/filesetup.c b/filesetup.c
index 371b405..6277f0f 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -1006,7 +1006,7 @@ int add_file(struct thread_data *td, const char *fname)
 		f->lock = fio_mutex_rw_init();
 		break;
 	case FILE_LOCK_EXCLUSIVE:
-		f->lock = fio_mutex_init(1);
+		f->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 		break;
 	default:
 		log_err("fio: unknown lock mode: %d\n", td->o.file_lock_mode);
diff --git a/flow.c b/flow.c
index bf5eeec..2993f4e 100644
--- a/flow.c
+++ b/flow.c
@@ -92,7 +92,7 @@ void flow_exit_job(struct thread_data *td)
 
 void flow_init(void)
 {
-	flow_lock = fio_mutex_init(1);
+	flow_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 	flow_list = smalloc(sizeof(*flow_list));
 	INIT_FLIST_HEAD(flow_list);
 }
diff --git a/gettime.c b/gettime.c
index e8f5ab5..5b49287 100644
--- a/gettime.c
+++ b/gettime.c
@@ -304,7 +304,7 @@ int fio_start_gtod_thread(void)
 	pthread_attr_t attr;
 	int ret;
 
-	mutex = fio_mutex_init(0);
+	mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
 	if (!mutex)
 		return 1;
 
diff --git a/init.c b/init.c
index 3865d09..475a6ad 100644
--- a/init.c
+++ b/init.c
@@ -807,7 +807,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(0);
+	td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
 
 	td->ts.clat_percentiles = td->o.clat_percentiles;
 	if (td->o.overwrite_plist)
diff --git a/iolog.h b/iolog.h
index 95617fc..1853846 100644
--- a/iolog.h
+++ b/iolog.h
@@ -107,7 +107,6 @@ extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
 extern void add_iops_sample(struct thread_data *, enum fio_ddir, struct timeval *);
 extern void init_disk_util(struct thread_data *);
 extern void update_rusage_stat(struct thread_data *);
-extern void update_io_ticks(void);
 extern void setup_log(struct io_log **, unsigned long);
 extern void finish_log(struct thread_data *, struct io_log *, const char *);
 extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *);
diff --git a/mutex.h b/mutex.h
index 5938e95..6fdf7c6 100644
--- a/mutex.h
+++ b/mutex.h
@@ -10,6 +10,11 @@ struct fio_mutex {
 	int waiters;
 };
 
+enum {
+	FIO_MUTEX_LOCKED	= 0,
+	FIO_MUTEX_UNLOCKED	= 1,
+};
+
 extern struct fio_mutex *fio_mutex_init(int);
 extern void fio_mutex_remove(struct fio_mutex *);
 extern void fio_mutex_down(struct fio_mutex *);
diff --git a/smalloc.c b/smalloc.c
index 5ba2004..d0b6f1e 100644
--- a/smalloc.c
+++ b/smalloc.c
@@ -206,7 +206,7 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
 	pool->map = ptr;
 	pool->bitmap = (void *) ptr + (pool->nr_blocks * SMALLOC_BPL);
 
-	pool->lock = fio_mutex_init(1);
+	pool->lock = fio_mutex_init(FIO_MUTEX_UNLOCKED);
 	if (!pool->lock)
 		goto out_fail;
 
--
To unsubscribe from this list: send the line "unsubscribe fio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux