From 5903e7b7907854014478b6febfc5645a203ff59e Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 26 Feb 2014 13:42:13 -0800 Subject: [PATCH] blktrace: load improvements - 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 --- blktrace.c | 9 ++++++++- engines/net.c | 2 +- engines/rbd.c | 2 +- file.h | 2 +- filesetup.c | 10 ++++++---- init.c | 4 ++-- iolog.c | 3 +-- options.c | 3 +-- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/blktrace.c b/blktrace.c index 9e4e5998..107a65b2 100644 --- a/blktrace.c +++ b/blktrace.c @@ -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; diff --git a/engines/net.c b/engines/net.c index dd06861c..1df8d063 100644 --- a/engines/net.c +++ b/engines/net.c @@ -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; } diff --git a/engines/rbd.c b/engines/rbd.c index 39fa0ceb..5a4a3e27 100644 --- a/engines/rbd.c +++ b/engines/rbd.c @@ -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 d065a250..c929d1da 100644 --- 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 *); diff --git a/filesetup.c b/filesetup.c index 7669d704..1acf6adc 100644 --- a/filesetup.c +++ b/filesetup.c @@ -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 6a65e552..73ec9eb2 100644 --- 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 eeaca291..b8ee067f 100644 --- 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")) { diff --git a/options.c b/options.c index 625d3a25..6d3956e3 100644 --- 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); -- 2.25.1