[PATCH] fio: Add option for setting timeout of individual threads
authorJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 14:36:39 +0000 (16:36 +0200)
committerJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 14:36:39 +0000 (16:36 +0200)
README.fio
fio.c

index 8880ed7f877f6833cca63fd10fb8b73695e9fcd9..e542600fbdb684f43a7abcb866f00048a0d7899d 100644 (file)
@@ -38,6 +38,7 @@ The <jobs> format is as follows:
        cpumask=x       Allow job to run on CPUs defined by mask
        fsync=x         If writing, fsync after every x blocks have been written
        startdelay=x    Start this thread x seconds after startup
+       timeout=x       Terminate x seconds after startup
        aio             Use Linux async io
        aio_depth=x     Allow x iocbs in flight
 
diff --git a/fio.c b/fio.c
index c60353a2748c43e7ff48ba33819c1a21e2b4d7f3..053ceaa7f95dac1d84dbaaf91b1de8c8a0d5f79a 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -394,6 +394,14 @@ static int check_min_rate(struct thread_data *td, struct timeval *now)
        return 0;
 }
 
+static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
+{
+       if (mtime_since(&td->start, t) >= td->timeout * 1000)
+               return 1;
+
+       return 0;
+}
+
 #define should_fsync(td)       ((td)->ddir == DDIR_WRITE && !(td)->odirect)
 
 static void do_sync_io(struct thread_data *td)
@@ -453,6 +461,9 @@ static void do_sync_io(struct thread_data *td)
                        td->min_latency = msec;
                if (msec > td->max_latency)
                        td->max_latency = msec;
+
+               if (runtime_exceeded(td, &e))
+                       break;
        }
 
        if (should_fsync(td))
@@ -594,6 +605,9 @@ static void do_async_io(struct thread_data *td)
                        td->error = ENODATA;
                        break;
                }
+
+               if (runtime_exceeded(td, &e))
+                       break;
        }
 }
 
@@ -828,6 +842,7 @@ static struct thread_data *get_new_job(int global)
        td->odirect = def_thread.odirect;
        td->ratecycle = def_thread.ratecycle;
        td->sequential = def_thread.sequential;
+       td->timeout = def_thread.timeout;
        memcpy(&td->cpumask, &def_thread.cpumask, sizeof(td->cpumask));
 
        return td;
@@ -1014,6 +1029,13 @@ static void parse_jobs_cmd(int argc, char *argv[], int index)
                        td->start_delay = strtoul(string, NULL, 10);
                }
 
+               c = strstr(p, "timeout=");
+               if (c) {
+                       c += 8;
+                       fill_option(c, string);
+                       td->timeout = strtoul(string, NULL, 10);
+               }
+
                c = strstr(p, "aio_depth=");
                if (c) {
                        c += 10;
@@ -1160,6 +1182,10 @@ static int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
+                       if (!check_int(p, "timeout", &td->timeout)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
                        if (!check_int(p, "aio_depth", &td->aio_depth)) {
                                fgetpos(f, &off);
                                continue;
@@ -1295,11 +1321,6 @@ static void run_threads(char *argv[])
 
        signal(SIGINT, sig_handler);
 
-       if (def_thread.timeout) {
-               signal(SIGALRM, sig_handler);
-               alarm(def_thread.timeout);
-       }
-
        todo = thread_number;
        nr_running = 0;
        m_rate = t_rate = 0;