[PATCH] Add seperate read/write block size options
[fio.git] / init.c
diff --git a/init.c b/init.c
index 58defbe26f648a4b93d634d169b8e507c9bbbe84..616c51f27ff738e7d2d2bd3eddbf7c924d693c3b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -51,6 +51,7 @@
 #define DEF_UNLINK             (0)
 #define DEF_WRITE_BW_LOG       (0)
 #define DEF_WRITE_LAT_LOG      (0)
+#define DEF_NO_RAND_MAP                (0)
 
 #define td_var_offset(var)     ((size_t) &((struct thread_data *)0)->var)
 
@@ -138,7 +139,17 @@ static struct fio_option options[] = {
        {
                .name   = "bs",
                .type   = FIO_OPT_STR_VAL,
-               .off1   = td_var_offset(bs),
+               .off1   = td_var_offset(bs[DDIR_READ]),
+       },
+       {
+               .name   = "read_bs",
+               .type   = FIO_OPT_STR_VAL,
+               .off1   = td_var_offset(bs[DDIR_READ]),
+       },
+       {
+               .name   = "write_bs",
+               .type   = FIO_OPT_STR_VAL,
+               .off1   = td_var_offset(bs[DDIR_WRITE]),
        },
        {
                .name   = "offset",
@@ -163,8 +174,20 @@ static struct fio_option options[] = {
        {
                .name   = "bsrange",
                .type   = FIO_OPT_RANGE,
-               .off1   = td_var_offset(min_bs),
-               .off2   = td_var_offset(max_bs),
+               .off1   = td_var_offset(min_bs[DDIR_READ]),
+               .off2   = td_var_offset(max_bs[DDIR_READ]),
+       },
+       {
+               .name   = "read_bsrange",
+               .type   = FIO_OPT_RANGE,
+               .off1   = td_var_offset(min_bs[DDIR_READ]),
+               .off2   = td_var_offset(max_bs[DDIR_READ]),
+       },
+       {
+               .name   = "write_bsrange",
+               .type   = FIO_OPT_RANGE,
+               .off1   = td_var_offset(min_bs[DDIR_WRITE]),
+               .off2   = td_var_offset(max_bs[DDIR_WRITE]),
        },
        {
                .name   = "nrfiles",
@@ -342,6 +365,16 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_STR_SET,
                .off1   = td_var_offset(write_lat_log),
        },
+       {
+               .name   = "norandommap",
+               .type   = FIO_OPT_STR_SET,
+               .off1   = td_var_offset(norandommap),
+       },
+       {
+               .name   = "bs_unaligned",
+               .type   = FIO_OPT_STR_SET,
+               .off1   = td_var_offset(bs_unaligned),
+       },
        {
                .name = NULL,
        },
@@ -432,6 +465,9 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
 
 static void put_job(struct thread_data *td)
 {
+       if (td == &def_thread)
+               return;
+
        memset(&threads[td->thread_number - 1], 0, sizeof(*td));
        thread_number--;
 }
@@ -442,11 +478,6 @@ static void put_job(struct thread_data *td)
  */
 static void fixup_options(struct thread_data *td)
 {
-       if (!td->min_bs)
-               td->min_bs = td->bs;
-       if (!td->max_bs)
-               td->max_bs = td->bs;
-
        if (!td->rwmixread && td->rwmixwrite)
                td->rwmixread = 100 - td->rwmixwrite;
 
@@ -455,6 +486,48 @@ static void fixup_options(struct thread_data *td)
                free(td->write_iolog_file);
                td->write_iolog_file = NULL;
        }
+
+       if (td->io_ops->flags & FIO_SYNCIO)
+               td->iodepth = 1;
+       else {
+               if (!td->iodepth)
+                       td->iodepth = td->nr_files;
+       }
+
+       /*
+        * only really works for sequential io for now, and with 1 file
+        */
+       if (td->zone_size && !td->sequential && td->nr_files == 1)
+               td->zone_size = 0;
+
+       /*
+        * Reads can do overwrites, we always need to pre-create the file
+        */
+       if (td_read(td) || td_rw(td))
+               td->overwrite = 1;
+
+       if (td->bs[DDIR_READ] != DEF_BS)
+               td->bs[DDIR_WRITE] = td->bs[DDIR_READ];
+       if (!td->min_bs[DDIR_READ])
+               td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
+       if (!td->max_bs[DDIR_READ])
+               td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
+       if (!td->min_bs[DDIR_WRITE])
+               td->min_bs[DDIR_WRITE]= td->bs[DDIR_READ];
+       if (!td->max_bs[DDIR_WRITE])
+               td->max_bs[DDIR_WRITE] = td->bs[DDIR_READ];
+
+       td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
+
+       if (td_read(td) && !td_rw(td))
+               td->verify = 0;
+
+       if (td->norandommap && td->verify != VERIFY_NONE) {
+               log_err("fio: norandommap given, verify disabled\n");
+               td->verify = VERIFY_NONE;
+       }
+       if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
+               log_err("fio: bs_unaligned may not work with raw io\n");
 }
 
 /*
@@ -483,8 +556,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        }
 #endif
 
-       fixup_options(td);
-
        /*
         * the def_thread is just for options, it's not a real job
         */
@@ -502,24 +573,10 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                }
        }
 
-       if (td->io_ops->flags & FIO_SYNCIO)
-               td->iodepth = 1;
-       else {
-               if (!td->iodepth)
-                       td->iodepth = td->nr_files;
-       }
-
-       /*
-        * only really works for sequential io for now, and with 1 file
-        */
-       if (td->zone_size && !td->sequential && td->nr_files == 1)
-               td->zone_size = 0;
+       if (td->odirect)
+               td->io_ops->flags |= FIO_RAWIO;
 
-       /*
-        * Reads can do overwrites, we always need to pre-create the file
-        */
-       if (td_read(td) || td_rw(td))
-               td->overwrite = 1;
+       fixup_options(td);
 
        td->filetype = FIO_TYPE_FILE;
        if (!stat(jobname, &sb)) {
@@ -529,9 +586,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        td->filetype = FIO_TYPE_CHAR;
        }
 
-       if (td->odirect)
-               td->io_ops->flags |= FIO_RAWIO;
-
        if (td->filename)
                td->nr_uniq_files = 1;
        else
@@ -578,13 +632,6 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
        td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
 
-       if (td->min_bs == -1U)
-               td->min_bs = td->bs;
-       if (td->max_bs == -1U)
-               td->max_bs = td->bs;
-       if (td_read(td) && !td_rw(td))
-               td->verify = 0;
-
        if (td->stonewall && td->thread_number > 1)
                groupid++;
 
@@ -610,7 +657,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        if (td->io_ops->flags & FIO_CPUIO)
                                fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
                        else
-                               fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_ops->name, td->iodepth);
+                               fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d/%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs[DDIR_READ], td->max_bs[DDIR_READ], td->min_bs[DDIR_WRITE], td->max_bs[DDIR_WRITE], td->rate, td->io_ops->name, td->iodepth);
                } else if (job_add_num == 1)
                        fprintf(f_out, "...\n");
        }
@@ -676,12 +723,14 @@ int init_random_state(struct thread_data *td)
        if (td->rand_repeatable)
                seeds[3] = DEF_RANDSEED;
 
-       for_each_file(td, f, i) {
-               blocks = (f->file_size + td->min_bs - 1) / td->min_bs;
-               num_maps = blocks / BLOCKS_PER_MAP;
-               f->file_map = malloc(num_maps * sizeof(long));
-               f->num_maps = num_maps;
-               memset(f->file_map, 0, num_maps * sizeof(long));
+       if (!td->norandommap) {
+               for_each_file(td, f, i) {
+                       blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
+                       num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
+                       f->file_map = malloc(num_maps * sizeof(long));
+                       f->num_maps = num_maps;
+                       memset(f->file_map, 0, num_maps * sizeof(long));
+               }
        }
 
        os_random_seed(seeds[3], &td->random_state);
@@ -845,7 +894,7 @@ int parse_jobs_ini(char *file, int stonewall_flag)
 {
        unsigned int global;
        struct thread_data *td;
-       char *string, *name, *tmpbuf;
+       char *string, *name;
        fpos_t off;
        FILE *f;
        char *p;
@@ -859,15 +908,16 @@ int parse_jobs_ini(char *file, int stonewall_flag)
 
        string = malloc(4096);
        name = malloc(256);
-       tmpbuf = malloc(4096);
+       memset(name, 0, 256);
 
        stonewall = stonewall_flag;
-       while ((p = fgets(string, 4096, f)) != NULL) {
-               if (ret)
+       do {
+               p = fgets(string, 4095, f);
+               if (!p)
                        break;
                if (is_empty_or_comment(p))
                        continue;
-               if (sscanf(p, "[%s]", name) != 1)
+               if (sscanf(p, "[%255s]", name) != 1)
                        continue;
 
                global = !strncmp(name, "global", 6);
@@ -892,10 +942,12 @@ int parse_jobs_ini(char *file, int stonewall_flag)
                while ((p = fgets(string, 4096, f)) != NULL) {
                        if (is_empty_or_comment(p))
                                continue;
-                       if (strstr(p, "["))
-                               break;
 
                        strip_blank_front(&p);
+
+                       if (p[0] == '[')
+                               break;
+
                        strip_blank_end(p);
 
                        fgetpos(f, &off);
@@ -905,20 +957,20 @@ int parse_jobs_ini(char *file, int stonewall_flag)
                         * dump all the bad ones. Makes trial/error fixups
                         * easier on the user.
                         */
-                       ret = parse_option(p, options, td);
+                       ret |= parse_option(p, options, td);
                }
 
                if (!ret) {
                        fsetpos(f, &off);
                        ret = add_job(td, name, 0);
+               } else {
+                       log_err("fio: job %s dropped\n", name);
+                       put_job(td);
                }
-               if (ret)
-                       break;
-       }
+       } while (!ret);
 
        free(string);
        free(name);
-       free(tmpbuf);
        fclose(f);
        return ret;
 }
@@ -937,9 +989,10 @@ static int fill_def_thread(void)
         */
        def_thread.ddir = DDIR_READ;
        def_thread.iomix = 0;
-       def_thread.bs = DEF_BS;
-       def_thread.min_bs = -1;
-       def_thread.max_bs = -1;
+       def_thread.bs[DDIR_READ] = DEF_BS;
+       def_thread.bs[DDIR_WRITE] = DEF_BS;
+       def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0;
+       def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0;
        def_thread.odirect = DEF_ODIRECT;
        def_thread.ratecycle = DEF_RATE_CYCLE;
        def_thread.sequential = DEF_SEQUENTIAL;
@@ -964,6 +1017,7 @@ static int fill_def_thread(void)
        def_thread.unlink = DEF_UNLINK;
        def_thread.write_bw_log = write_bw_log;
        def_thread.write_lat_log = write_lat_log;
+       def_thread.norandommap = DEF_NO_RAND_MAP;
 #ifdef FIO_HAVE_DISK_UTIL
        def_thread.do_disk_util = 1;
 #endif
@@ -1035,7 +1089,12 @@ static int parse_cmd_line(int argc, char *argv[])
                                        return 0;
                        }
 
-                       parse_cmd_option(opt, val, options, td);
+                       ret = parse_cmd_option(opt, val, options, td);
+                       if (ret) {
+                               log_err("fio: job dropped\n");
+                               put_job(td);
+                               td = NULL;
+                       }
                        break;
                }
                default:
@@ -1165,7 +1224,6 @@ int parse_options(int argc, char *argv[])
 
        if (!thread_number) {
                log_err("No jobs defined(s)\n");
-               usage();
                return 1;
        }