file: unionize lfsr/randommap
authorJens Axboe <axboe@fb.com>
Mon, 15 Dec 2014 16:38:43 +0000 (09:38 -0700)
committerJens Axboe <axboe@fb.com>
Mon, 15 Dec 2014 16:38:43 +0000 (09:38 -0700)
We only use one of them, add file flags to distinguish between the
two.

Signed-off-by: Jens Axboe <axboe@fb.com>
file.h
filesetup.c
io_ddir.h
io_u.c

diff --git a/file.h b/file.h
index 4d24bdc563399c02a7be6c2e431759ac1203ae87..f7a1eae14408240c6f92222b97b98fa5cd58a35e 100644 (file)
--- a/file.h
+++ b/file.h
@@ -27,6 +27,8 @@ enum fio_file_flags {
        FIO_FILE_size_known     = 1 << 4,       /* size has been set */
        FIO_FILE_hashed         = 1 << 5,       /* file is on hash */
        FIO_FILE_partial_mmap   = 1 << 6,       /* can't do full mmap */
+       FIO_FILE_axmap          = 1 << 7,       /* uses axmap */
+       FIO_FILE_lfsr           = 1 << 8,       /* lfsr is used */
 };
 
 enum file_lock_mode {
@@ -107,11 +109,12 @@ struct fio_file {
        };
 
        /*
-        * block map for random io
+        * block map or LFSR for random io
         */
-       struct axmap *io_axmap;
-
-       struct fio_lfsr lfsr;
+       union {
+               struct axmap *io_axmap;
+               struct fio_lfsr lfsr;
+       };
 
        /*
         * Used for zipf random distribution
@@ -154,6 +157,8 @@ FILE_FLAG_FNS(done);
 FILE_FLAG_FNS(size_known);
 FILE_FLAG_FNS(hashed);
 FILE_FLAG_FNS(partial_mmap);
+FILE_FLAG_FNS(axmap);
+FILE_FLAG_FNS(lfsr);
 #undef FILE_FLAG_FNS
 
 /*
index c026048ff7f3fbb951cf7b8f34dfe4c6738e5bb6..0fb5589b7c33ce1aa154c21ecf42cf52a682c4d8 100644 (file)
@@ -1044,12 +1044,16 @@ int init_random_map(struct thread_data *td)
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
 
-                       if (!lfsr_init(&f->lfsr, blocks, seed, 0))
+                       if (!lfsr_init(&f->lfsr, blocks, seed, 0)) {
+                               fio_file_set_lfsr(f);
                                continue;
+                       }
                } else if (!td->o.norandommap) {
                        f->io_axmap = axmap_new(blocks);
-                       if (f->io_axmap)
+                       if (f->io_axmap) {
+                               fio_file_set_axmap(f);
                                continue;
+                       }
                } else if (td->o.norandommap)
                        continue;
 
@@ -1104,8 +1108,10 @@ void close_and_free_files(struct thread_data *td)
 
                sfree(f->file_name);
                f->file_name = NULL;
-               axmap_free(f->io_axmap);
-               f->io_axmap = NULL;
+               if (fio_file_axmap(f)) {
+                       axmap_free(f->io_axmap);
+                       f->io_axmap = NULL;
+               }
                sfree(f);
        }
 
@@ -1537,9 +1543,9 @@ void fio_file_reset(struct thread_data *td, struct fio_file *f)
                f->last_start[i] = -1ULL;
        }
 
-       if (f->io_axmap)
+       if (fio_file_axmap(f))
                axmap_reset(f->io_axmap);
-       if (td->o.random_generator == FIO_RAND_GEN_LFSR)
+       else if (fio_file_lfsr(f))
                lfsr_reset(&f->lfsr, td->rand_seeds[FIO_RAND_BLOCK_OFF]);
 }
 
index 269768ecac9e1b3da452d3279b17e5b8de496385..b16a6b9bade95ce0e0822b5728021d5fae149f7d 100644 (file)
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -42,7 +42,7 @@ enum td_ddir {
 #define td_trim(td)            ((td)->o.td_ddir & TD_DDIR_TRIM)
 #define td_rw(td)              (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW)
 #define td_random(td)          ((td)->o.td_ddir & TD_DDIR_RAND)
-#define file_randommap(td, f)  (!(td)->o.norandommap && (f)->io_axmap)
+#define file_randommap(td, f)  (!(td)->o.norandommap && fio_file_axmap((f)))
 
 static inline int ddir_sync(enum fio_ddir ddir)
 {
diff --git a/io_u.c b/io_u.c
index efbcea9eb15bb47dca4e0f802f85ad86197665de..23a9e4ada729efbc2a53bd9b3d4e12047be1d5c6 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -100,6 +100,8 @@ static int __get_next_rand_offset(struct thread_data *td, struct fio_file *f,
        } else {
                uint64_t off = 0;
 
+               assert(fio_file_lfsr(f));
+
                if (lfsr_next(&f->lfsr, &off))
                        return 1;