Add exit_on_io_done option to the CPU IO engine

The CPU IO engine is most often used to saturate the system,
while running an IO load on it. As such, it's useful to have
CPU engine threads exit automatically, when IO has completed.
Add exit_on_io_done as a CPU IO engine option for that purpose.

Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/engines/cpu.c b/engines/cpu.c
index c798f18..85598ef 100644
--- a/engines/cpu.c
+++ b/engines/cpu.c
@@ -11,6 +11,7 @@
 	struct thread_data *td;
 	unsigned int cpuload;
 	unsigned int cpucycle;
+	unsigned int exit_io_done;
 };
 
 static struct fio_option options[] = {
@@ -36,6 +37,16 @@
 		.group	= FIO_OPT_G_INVALID,
 	},
 	{
+		.name	= "exit_on_io_done",
+		.lname	= "Exit when IO threads are done",
+		.type	= FIO_OPT_BOOL,
+		.off1	= offsetof(struct cpu_options, exit_io_done),
+		.help	= "Exit when IO threads finish",
+		.def	= "0",
+		.category = FIO_OPT_C_GENERAL,
+		.group	= FIO_OPT_G_INVALID,
+	},
+	{
 		.name	= NULL,
 	},
 };
@@ -45,6 +56,11 @@
 {
 	struct cpu_options *co = td->eo;
 
+	if (co->exit_io_done && !fio_running_or_pending_io_threads()) {
+		td->done = 1;
+		return FIO_Q_BUSY;
+	}
+
 	usec_spin(co->cpucycle);
 	return FIO_Q_COMPLETED;
 }