[PATCH] fio: Add [global] job number to set default options for threads.
authorJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 14:23:57 +0000 (16:23 +0200)
committerJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 14:23:57 +0000 (16:23 +0200)
README.fio
examples/aio-read
fio.c

index 7c5e430ff04c4efaa4fb14837722c95bf915e7c4..8880ed7f877f6833cca63fd10fb8b73695e9fcd9 100644 (file)
@@ -93,5 +93,10 @@ And fio would be invoked as:
 
 $ fio -o0 -s -b4096 -f file_with_above
 
+'global' is a reserved keyword. When used as the filename, it sets the
+default options for the threads following that section. It is possible
+to have more than one global section in the file, as it only affects
+subsequent jobs.
 
 Also see the examples/ dir for sample job files.
+
index 9862166b3c1e9016f580190039141566164f152e..556e450b615a71836b0547b98d84f7d5eccbdc86 100644 (file)
@@ -1,29 +1,18 @@
 ; Read 4 files with aio at different depths
-
-[/data1/file1]
+[global]
 aio
+random
 rw=0
 bs=128
+
+[/data1/file1]
 aio_depth=4
-random
 
 [/data1/file2]
-aio
-rw=0
-bs=128
 aio_depth=32
-random
 
 [/data1/file3]
-;aio
-rw=0
-bs=128
-aio_depth=4
-random
+aio_depth=8
 
 [/data1/file4]
-aio
-rw=0
-bs=128
-aio_depth=8
-random
+aio_depth=16
diff --git a/fio.c b/fio.c
index 4498f73ac006634ff5439e677c4821bbc3246640..c60353a2748c43e7ff48ba33819c1a21e2b4d7f3 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -94,12 +94,8 @@ enum {
 
 #define ALIGN(buf)     (char *) (((unsigned long) (buf) + MASK) & ~(MASK))
 
-static int sequential = DEF_SEQUENTIAL;
 static int write_stat = DEF_WRITESTAT;
 static int repeatable = DEF_RAND_REPEAT;
-static int timeout = DEF_TIMEOUT;
-static int odirect = DEF_ODIRECT;
-static int global_bs = DEF_BS;
 static int rate_quit = 1;
 
 static int thread_number;
@@ -107,8 +103,6 @@ static char *ini_file;
 
 static int shm_id;
 
-static cpu_set_t def_cpumask;
-
 enum {
        DDIR_READ = 0,
        DDIR_WRITE,
@@ -143,6 +137,7 @@ struct thread_data {
        unsigned int delay_sleep;
        unsigned int fsync_blocks;
        unsigned int start_delay;
+       unsigned int timeout;
        unsigned int use_aio;
        cpu_set_t cpumask;
 
@@ -181,6 +176,7 @@ struct thread_data {
 };
 
 static struct thread_data *threads;
+static struct thread_data def_thread;
 
 static sem_t startup_sem;
 
@@ -814,10 +810,12 @@ static int setup_rate(struct thread_data *td)
        return 0;
 }
 
-static struct thread_data *get_new_job(void)
+static struct thread_data *get_new_job(int global)
 {
        struct thread_data *td;
 
+       if (global)
+               return &def_thread;
        if (thread_number >= MAX_JOBS)
                return NULL;
 
@@ -825,18 +823,12 @@ static struct thread_data *get_new_job(void)
        memset(td, 0, sizeof(*td));
 
        td->thread_number = thread_number;
-       td->ddir = DDIR_READ;
-       td->bs = global_bs;
-       td->odirect = 1;
-       td->delay_sleep = 0;
-       td->rate = 0;
-       td->ratecycle = DEF_RATE_CYCLE;
-       td->sequential = sequential;
-       td->ioprio = 0;
-       td->use_aio = 0;
-       td->aio_depth = 0;
-       td->aio_cur_depth = 0;
-       memcpy(&td->cpumask, &def_cpumask, sizeof(td->cpumask));
+       td->ddir = def_thread.ddir;
+       td->bs = def_thread.bs;
+       td->odirect = def_thread.odirect;
+       td->ratecycle = def_thread.ratecycle;
+       td->sequential = def_thread.sequential;
+       memcpy(&td->cpumask, &def_thread.cpumask, sizeof(td->cpumask));
 
        return td;
 }
@@ -850,6 +842,9 @@ static void put_job(struct thread_data *td)
 static int add_job(struct thread_data *td, const char *filename, int prioclass,
                   int prio)
 {
+       if (td == &def_thread)
+               return 0;
+
        strcpy(td->file_name, filename);
        td->stat_fd = -1;
        sem_init(&td->mutex, 1, 0);
@@ -918,7 +913,7 @@ static void parse_jobs_cmd(int argc, char *argv[], int index)
 
                filename[0] = 0;
 
-               td = get_new_job();
+               td = get_new_job(0);
                if (!td)
                        break;
 
@@ -1065,9 +1060,9 @@ static int is_empty_or_comment(char *line)
        unsigned int i;
 
        for (i = 0; i < strlen(line); i++) {
-               if (!isspace(line[i]) && !iscntrl(line[i]))
-                       return 0;
                if (line[i] == ';')
+                       return 1;
+               if (!isspace(line[i]) && !iscntrl(line[i]))
                        return 0;
        }
 
@@ -1076,7 +1071,7 @@ static int is_empty_or_comment(char *line)
 
 static int parse_jobs_ini(char *file)
 {
-       unsigned int prioclass, prio, cpu;
+       unsigned int prioclass, prio, cpu, global;
        struct thread_data *td;
        char *string, *name;
        fpos_t off;
@@ -1098,9 +1093,11 @@ static int parse_jobs_ini(char *file)
                if (sscanf(p, "[%s]", name) != 1)
                        continue;
 
+               global = !strncmp(name, "global", 6);
+
                name[strlen(name) - 1] = '\0';
 
-               td = get_new_job();
+               td = get_new_job(global);
                if (!td)
                        break;
 
@@ -1211,20 +1208,20 @@ static int parse_options(int argc, char *argv[])
                switch (*parm) {
                        case 's':
                                parm++;
-                               sequential = !!atoi(parm);
+                               def_thread.sequential = !!atoi(parm);
                                break;
                        case 'b':
                                parm++;
-                               global_bs = atoi(parm);
-                               global_bs <<= 10;
-                               if (!global_bs) {
+                               def_thread.bs = atoi(parm);
+                               def_thread.bs <<= 10;
+                               if (!def_thread.bs) {
                                        printf("bad block size\n");
-                                       global_bs = DEF_BS;
+                                       def_thread.bs = DEF_BS;
                                }
                                break;
                        case 't':
                                parm++;
-                               timeout = atoi(parm);
+                               def_thread.timeout = atoi(parm);
                                break;
                        case 'w':
                                parm++;
@@ -1240,7 +1237,7 @@ static int parse_options(int argc, char *argv[])
                                break;
                        case 'o':
                                parm++;
-                               odirect = !!atoi(parm);
+                               def_thread.odirect = !!atoi(parm);
                                break;
                        case 'f':
                                if (i + 1 >= argc) {
@@ -1298,9 +1295,9 @@ static void run_threads(char *argv[])
 
        signal(SIGINT, sig_handler);
 
-       if (timeout) {
+       if (def_thread.timeout) {
                signal(SIGALRM, sig_handler);
-               alarm(timeout);
+               alarm(def_thread.timeout);
        }
 
        todo = thread_number;
@@ -1393,11 +1390,21 @@ int main(int argc, char *argv[])
 
        atexit(free_shm);
 
-       if (sched_getaffinity(getpid(), sizeof(def_cpumask), &def_cpumask) == -1) {
+       if (sched_getaffinity(getpid(), sizeof(cpu_set_t), &def_thread.cpumask) == -1) {
                perror("sched_getaffinity");
                return 1;
        }
 
+       /*
+        * fill globals
+        */
+       def_thread.ddir = DDIR_READ;
+       def_thread.bs = DEF_BS;
+       def_thread.odirect = 1;
+       def_thread.ratecycle = DEF_RATE_CYCLE;
+       def_thread.sequential = 1;
+       def_thread.timeout = DEF_TIMEOUT;
+
        i = parse_options(argc, argv);
 
        if (ini_file) {
@@ -1411,7 +1418,7 @@ int main(int argc, char *argv[])
                return 1;
        }
 
-       printf("%s: %s, bs=%uKiB, timeo=%u, write_stat=%u, odirect=%d\n", argv[0], sequential ? "sequential" : "random", global_bs >> 10, timeout, write_stat, odirect);
+       printf("%s: %s, bs=%uKiB, timeo=%u, write_stat=%u, odirect=%d\n", argv[0], def_thread.sequential ? "sequential" : "random", def_thread.bs >> 10, def_thread.timeout, write_stat, def_thread.odirect);
 
        run_threads(argv);