X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=fio.c;h=b0afdcc85f303303b2513194b20bfc7212651c83;hp=ab84b60a59ca77ace2e9984b4353b530a569ed8c;hb=c8bb6faf52ea8079e98df17cd2c5a029d3f33057;hpb=b2560f3ca4677e2908fc4111f4d04fae5df3b229 diff --git a/fio.c b/fio.c index ab84b60a..b0afdcc8 100644 --- a/fio.c +++ b/fio.c @@ -46,7 +46,7 @@ int thread_number = 0; int shm_id = 0; int temp_stall_ts; -static volatile int startup_sem; +static struct fio_sem *startup_sem; static volatile int fio_abort; static int exit_value; @@ -301,9 +301,17 @@ static void do_verify(struct thread_data *td) case FIO_Q_COMPLETED: if (io_u->error) ret = -io_u->error; - else if (io_u->xfer_buflen != io_u->resid && io_u->resid) { + else if (io_u->resid) { int bytes = io_u->xfer_buflen - io_u->resid; + /* + * zero read, fail + */ + if (!bytes) { + td_verror(td, ENODATA, "full resid"); + put_io_u(td, io_u); + break; + } io_u->xfer_buflen = io_u->resid; io_u->xfer_buf += bytes; requeue_io_u(td, &io_u); @@ -361,31 +369,6 @@ static void do_verify(struct thread_data *td) td_set_runstate(td, TD_RUNNING); } -/* - * Not really an io thread, all it does is burn CPU cycles in the specified - * manner. - */ -static void do_cpuio(struct thread_data *td) -{ - struct timeval e; - int split = 100 / td->cpuload; - int i = 0; - - while (!td->terminate) { - fio_gettime(&e, NULL); - - if (runtime_exceeded(td, &e)) - break; - - if (!(i % split)) - __usec_sleep(10000); - else - usec_sleep(td, 10000); - - i++; - } -} - /* * Main IO worker function. It retrieves io_u's to process and queues * and reaps them, checking for rate and errors along the way. @@ -424,9 +407,18 @@ static void do_io(struct thread_data *td) case FIO_Q_COMPLETED: if (io_u->error) ret = -io_u->error; - else if (io_u->xfer_buflen != io_u->resid && io_u->resid) { + else if (io_u->resid) { int bytes = io_u->xfer_buflen - io_u->resid; + /* + * zero read, fail + */ + if (!bytes) { + td_verror(td, ENODATA, "full resid"); + put_io_u(td, io_u); + break; + } + io_u->xfer_buflen = io_u->resid; io_u->xfer_buf += bytes; requeue_io_u(td, &io_u); @@ -566,9 +558,6 @@ static int init_io_u(struct thread_data *td) int i, max_units; char *p; - if (td->io_ops->flags & FIO_CPUIO) - return 0; - if (td->io_ops->flags & FIO_SYNCIO) max_units = 1; else @@ -611,7 +600,7 @@ static int switch_ioscheduler(struct thread_data *td) FILE *f; int ret; - if (td->io_ops->flags & FIO_CPUIO) + if (td->io_ops->flags & FIO_DISKLESSIO) return 0; sprintf(tmp, "%s/queue/scheduler", td->sysfs_root); @@ -656,27 +645,29 @@ static int switch_ioscheduler(struct thread_data *td) return 0; } -static void clear_io_state(struct thread_data *td) +static int clear_io_state(struct thread_data *td) { struct fio_file *f; - int i; + int i, ret; - td->ts->stat_io_bytes[0] = td->ts->stat_io_bytes[1] = 0; + td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0; td->this_io_bytes[0] = td->this_io_bytes[1] = 0; td->zone_bytes = 0; + td->rate_bytes = 0; td->last_was_sync = 0; - for_each_file(td, f, i) { - f->last_completed_pos = 0; - - f->last_pos = 0; - if (td->io_ops->flags & FIO_SYNCIO) - lseek(f->fd, SEEK_SET, 0); + for_each_file(td, f, i) + td_io_close_file(td, f); - if (f->file_map) - memset(f->file_map, 0, f->num_maps * sizeof(long)); + ret = 0; + for_each_file(td, f, i) { + ret = td_io_open_file(td, f); + if (ret) + break; } + + return ret; } /* @@ -687,6 +678,7 @@ static void *thread_main(void *data) { unsigned long long runtime[2]; struct thread_data *td = data; + int clear_state; if (!td->use_thread) setsid(); @@ -729,21 +721,24 @@ static void *thread_main(void *data) goto err; td_set_runstate(td, TD_INITIALIZED); - fio_sem_up(&startup_sem); - fio_sem_down(&td->mutex); + fio_sem_up(startup_sem); + fio_sem_down(td->mutex); + + /* + * the ->mutex semaphore is now no longer used, close it to avoid + * eating a file descriptor + */ + fio_sem_remove(td->mutex); if (!td->create_serialize && setup_files(td)) goto err; - if (open_files(td)) - goto err; - /* - * Do this late, as some IO engines would like to have the - * files setup prior to initializing structures. - */ if (td_io_init(td)) goto err; + if (open_files(td)) + goto err; + if (td->exec_prerun) { if (system(td->exec_prerun) < 0) goto err; @@ -751,23 +746,25 @@ static void *thread_main(void *data) fio_gettime(&td->epoch, NULL); memcpy(&td->timeout_end, &td->epoch, sizeof(td->epoch)); - getrusage(RUSAGE_SELF, &td->ts->ru_start); + getrusage(RUSAGE_SELF, &td->ts.ru_start); runtime[0] = runtime[1] = 0; + clear_state = 0; while (td->loops--) { fio_gettime(&td->start, NULL); - memcpy(&td->ts->stat_sample_time, &td->start, sizeof(td->start)); + memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start)); if (td->ratemin) - memcpy(&td->lastrate, &td->ts->stat_sample_time, sizeof(td->lastrate)); + memcpy(&td->lastrate, &td->ts.stat_sample_time, sizeof(td->lastrate)); + + if (clear_state && clear_io_state(td)) + break; - clear_io_state(td); prune_io_piece_log(td); - if (td->io_ops->flags & FIO_CPUIO) - do_cpuio(td); - else - do_io(td); + do_io(td); + + clear_state = 1; if (td_read(td) && td->io_bytes[DDIR_READ]) runtime[DDIR_READ] += utime_since_now(&td->start); @@ -780,7 +777,9 @@ static void *thread_main(void *data) if (td->verify == VERIFY_NONE) continue; - clear_io_state(td); + if (clear_io_state(td)) + break; + fio_gettime(&td->start, NULL); do_verify(td); @@ -792,16 +791,18 @@ static void *thread_main(void *data) } update_rusage_stat(td); - fio_gettime(&td->end_time, NULL); - td->runtime[0] = runtime[0] / 1000; - td->runtime[1] = runtime[1] / 1000; - - if (td->ts->bw_log) - finish_log(td, td->ts->bw_log, "bw"); - if (td->ts->slat_log) - finish_log(td, td->ts->slat_log, "slat"); - if (td->ts->clat_log) - finish_log(td, td->ts->clat_log, "clat"); + td->ts.runtime[0] = runtime[0] / 1000; + td->ts.runtime[1] = runtime[1] / 1000; + td->ts.total_run_time = mtime_since_now(&td->epoch); + td->ts.io_bytes[0] = td->io_bytes[0]; + td->ts.io_bytes[1] = td->io_bytes[1]; + + if (td->ts.bw_log) + finish_log(td, td->ts.bw_log, "bw"); + if (td->ts.slat_log) + finish_log(td, td->ts.slat_log, "slat"); + if (td->ts.clat_log) + finish_log(td, td->ts.clat_log, "clat"); if (td->write_iolog_file) write_iolog_close(td); if (td->exec_postrun) { @@ -864,7 +865,7 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) * ->io_ops is NULL for a thread that has closed its * io engine */ - if (td->io_ops && td->io_ops->flags & FIO_CPUIO) + if (td->io_ops && !strcmp(td->io_ops->name, "cpuio")) cputhreads++; if (!td->pid || td->runstate == TD_REAPED) @@ -1022,23 +1023,22 @@ static void run_threads(void) */ td_set_runstate(td, TD_CREATED); map[this_jobs++] = td; - fio_sem_init(&startup_sem, 1); nr_started++; if (td->use_thread) { if (pthread_create(&td->thread, NULL, thread_main, td)) { perror("thread_create"); nr_started--; + break; } } else { - if (fork()) - fio_sem_down(&startup_sem); - else { + if (!fork()) { int ret = fork_main(shm_id, i); exit(ret); } } + fio_sem_down(startup_sem); } /* @@ -1093,7 +1093,7 @@ static void run_threads(void) m_rate += td->ratemin; t_rate += td->rate; todo--; - fio_sem_up(&td->mutex); + fio_sem_up(td->mutex); } reap_threads(&nr_running, &t_rate, &m_rate); @@ -1143,6 +1143,8 @@ int main(int argc, char *argv[]) setup_log(&agg_io_log[DDIR_WRITE]); } + startup_sem = fio_sem_init(0); + set_genesis_time(); disk_util_timer_arm(); @@ -1157,5 +1159,6 @@ int main(int argc, char *argv[]) } } + fio_sem_remove(startup_sem); return exit_value; }