blktrace: load improvements
authorJens Axboe <axboe@fb.com>
Wed, 26 Feb 2014 21:42:13 +0000 (13:42 -0800)
committerJens Axboe <axboe@fb.com>
Wed, 26 Feb 2014 21:42:13 +0000 (13:42 -0800)
- Set the state explicitly to SETTING_UP when loading the
  traces. This could take a while, so tell the status thread
  that we are setting up so it knows how to display us
  correctly.

- Fix a bug with multiple devices where we didn't cache the
  major/minor properly. This made blktrace spend tons of CPU
  cycles looking up /sys.

- Handle multiple devices correctly when adding files.

Signed-off-by: Jens Axboe <axboe@fb.com>
blktrace.c
engines/net.c
engines/rbd.c
file.h
filesetup.c
init.c
iolog.c
options.c

index 9e4e5998a73246cfa9a1df5e2adb2926777c056b..107a65b27884aacc580b5895e3ec29d02565574f 100644 (file)
@@ -217,6 +217,8 @@ static int trace_add_file(struct thread_data *td, __u32 device)
 
                dprint(FD_BLKTRACE, "add devices %s\n", dev);
                fileno = add_file_exclusive(td, dev);
+               td->files[fileno]->major = maj;
+               td->files[fileno]->minor = min;
                trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
                last_fileno = fileno;
        }
@@ -369,7 +371,7 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
        unsigned int cpu;
        unsigned int rw_bs[2];
        struct fifo *fifo;
-       int fd, i;
+       int fd, i, old_state;
        struct fio_file *f;
 
        fd = open(filename, O_RDONLY);
@@ -380,6 +382,9 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
 
        fifo = fifo_alloc(TRACE_FIFO_SIZE);
 
+       old_state = td->runstate;
+       td_set_runstate(td, TD_SETTING_UP);
+
        td->o.size = 0;
 
        cpu = 0;
@@ -458,6 +463,8 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
        fifo_free(fifo);
        close(fd);
 
+       td_set_runstate(td, old_state);
+
        if (!td->files_index) {
                log_err("fio: did not find replay device(s)\n");
                return 1;
index dd06861cf4b841852255ad84ac29c76ad25c568a..1df8d0635cf1b746ae7d597d1b4b4398f0019d2d 100644 (file)
@@ -1194,7 +1194,7 @@ static int fio_netio_setup(struct thread_data *td)
        struct netio_data *nd;
 
        if (!td->files_index) {
-               add_file(td, td->o.filename ?: "net", 0);
+               add_file(td, td->o.filename ?: "net", 0, 0);
                td->o.nr_files = td->o.nr_files ?: 1;
        }
 
index 39fa0ceb21c8f97c6c1ac1bcc3e83bcace424903..5a4a3e271f6c32ce7ee073df139e47e490f6daec 100644 (file)
@@ -377,7 +377,7 @@ static int fio_rbd_setup(struct thread_data *td)
         * The size of the RBD is set instead of a artificial file.
         */
        if (!td->files_index) {
-               add_file(td, td->o.filename ? : "rbd", 0);
+               add_file(td, td->o.filename ? : "rbd", 0, 0);
                td->o.nr_files = td->o.nr_files ? : 1;
        }
        f = td->files[0];
diff --git a/file.h b/file.h
index d065a25096447e00cb218382c83e6458038d4b55..c929d1dae482fe01c43b51980e0b5c72914ac57c 100644 (file)
--- a/file.h
+++ b/file.h
@@ -167,7 +167,7 @@ extern int __must_check generic_close_file(struct thread_data *, struct fio_file
 extern int __must_check generic_get_file_size(struct thread_data *, struct fio_file *);
 extern int __must_check file_lookup_open(struct fio_file *f, int flags);
 extern int __must_check pre_read_files(struct thread_data *);
-extern int add_file(struct thread_data *, const char *, int);
+extern int add_file(struct thread_data *, const char *, int, int);
 extern int add_file_exclusive(struct thread_data *, const char *);
 extern void get_file(struct fio_file *);
 extern int __must_check put_file(struct thread_data *, struct fio_file *);
index 7669d704663d52bf2d1d8ffeefeb5a45fd155861..1acf6adcf377cfe861590ad067baec1e0db643b6 100644 (file)
@@ -1145,7 +1145,7 @@ static void free_already_allocated() {
        }
 }
 
-int add_file(struct thread_data *td, const char *fname, int numjob)
+int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
 {
        int cur_files = td->files_index;
        char file_name[PATH_MAX];
@@ -1237,6 +1237,9 @@ int add_file(struct thread_data *td, const char *fname, int numjob)
        if (!td->o.open_files)
                td->o.open_files = 1;
 
+       if (inc)
+               td->o.nr_files++;
+
        dprint(FD_FILE, "file %p \"%s\" added at %d\n", f, f->file_name,
                                                        cur_files);
 
@@ -1253,7 +1256,7 @@ int add_file_exclusive(struct thread_data *td, const char *fname)
                        return i;
        }
 
-       return add_file(td, fname, 0);
+       return add_file(td, fname, 0, 1);
 }
 
 void get_file(struct fio_file *f)
@@ -1362,8 +1365,7 @@ static int recurse_dir(struct thread_data *td, const char *dirname)
                }
 
                if (S_ISREG(sb.st_mode)) {
-                       add_file(td, full_path, 0);
-                       td->o.nr_files++;
+                       add_file(td, full_path, 0, 1);
                        continue;
                }
                if (!S_ISDIR(sb.st_mode))
diff --git a/init.c b/init.c
index 6a65e552fc71fb0a793a4c0d0385145696e02d09..73ec9eb22a8d2f36ff773f4e468fb1c4e3744bd5 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1026,10 +1026,10 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                file_alloced = 1;
 
                if (o->nr_files == 1 && exists_and_not_file(jobname))
-                       add_file(td, jobname, job_add_num);
+                       add_file(td, jobname, job_add_num, 0);
                else {
                        for (i = 0; i < o->nr_files; i++)
-                               add_file(td, make_filename(fname, o, jobname, job_add_num, i), job_add_num);
+                               add_file(td, make_filename(fname, o, jobname, job_add_num, i), job_add_num, 0);
                }
        }
 
diff --git a/iolog.c b/iolog.c
index eeaca291e21eb6503712f29a602ca5ad121a2615..b8ee067fa7d948f744ef24045fef28038f76b40d 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -323,8 +323,7 @@ static int read_iolog2(struct thread_data *td, FILE *f)
                } else if (r == 2) {
                        rw = DDIR_INVAL;
                        if (!strcmp(act, "add")) {
-                               td->o.nr_files++;
-                               fileno = add_file(td, fname, 0);
+                               fileno = add_file(td, fname, 0, 1);
                                file_action = FIO_LOG_ADD_FILE;
                                continue;
                        } else if (!strcmp(act, "open")) {
index 625d3a25d51fb237dd89aefc6e3a742f8da0dca1..6d3956e307bf6049abf5dc2ae4b5a56f86e862ef 100644 (file)
--- a/options.c
+++ b/options.c
@@ -827,8 +827,7 @@ static int str_filename_cb(void *data, const char *input)
        while ((fname = get_next_name(&str)) != NULL) {
                if (!strlen(fname))
                        break;
-               add_file(td, fname, 0);
-               td->o.nr_files++;
+               add_file(td, fname, 0, 1);
        }
 
        free(p);