X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=c93896001296419f1a348f2b5f9f46f660b0a366;hp=6234c42b3a91b32305110f96e9e216472a9f537c;hb=55bc972818cdec46f47633da62758e4dcdb6f3f6;hpb=7e77dd026d85253936aef432ba8f3e89b96b805c diff --git a/io_u.c b/io_u.c index 6234c42b..c9389600 100644 --- a/io_u.c +++ b/io_u.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "fio.h" #include "os.h" @@ -193,6 +194,9 @@ static enum fio_ddir get_rw_ddir(struct thread_data *td) void put_io_u(struct thread_data *td, struct io_u *io_u) { + assert((io_u->flags & IO_U_F_FREE) == 0); + io_u->flags |= IO_U_F_FREE; + io_u->file = NULL; list_del(&io_u->list); list_add(&io_u->list, &td->io_u_freelist); @@ -289,23 +293,23 @@ static void io_u_mark_latency(struct thread_data *td, unsigned long msec) switch (msec) { default: index++; - case 1024 ... 2047: + case 1000 ... 1999: index++; - case 512 ... 1023: + case 750 ... 999: index++; - case 256 ... 511: + case 500 ... 749: index++; - case 128 ... 255: + case 250 ... 499: index++; - case 64 ... 127: + case 100 ... 249: index++; - case 32 ... 63: + case 50 ... 99: index++; - case 16 ... 31: + case 20 ... 49: index++; - case 8 ... 15: + case 10 ... 19: index++; - case 4 ... 7: + case 4 ... 9: index++; case 2 ... 3: index++; @@ -352,6 +356,9 @@ struct io_u *__get_io_u(struct thread_data *td) } if (io_u) { + assert(io_u->flags & IO_U_F_FREE); + io_u->flags &= ~IO_U_F_FREE; + io_u->error = 0; list_del(&io_u->list); list_add(&io_u->list, &td->io_u_busylist); @@ -441,6 +448,9 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, { unsigned long msec; + assert(io_u->flags & IO_U_F_FLIGHT); + io_u->flags &= ~IO_U_F_FLIGHT; + if (io_u->ddir == DDIR_SYNC) { td->last_was_sync = 1; return; @@ -506,6 +516,9 @@ static void ios_completed(struct thread_data *td, } } +/* + * Complete a single io_u for the sync engines. + */ long io_u_sync_complete(struct thread_data *td, struct io_u *io_u, endio_handler *handler) { @@ -521,6 +534,9 @@ long io_u_sync_complete(struct thread_data *td, struct io_u *io_u, return -1; } +/* + * Called to complete min_events number of io for the async engines. + */ long io_u_queued_complete(struct thread_data *td, int min_events, endio_handler *handler) @@ -566,3 +582,64 @@ void io_u_queued(struct thread_data *td, struct io_u *io_u) slat_time = mtime_since(&io_u->start_time, &io_u->issue_time); add_slat_sample(td, io_u->ddir, slat_time); } + +#ifdef FIO_USE_TIMEOUT +void io_u_set_timeout(struct thread_data *td) +{ + assert(td->cur_depth); + + td->timer.it_interval.tv_sec = 0; + td->timer.it_interval.tv_usec = 0; + td->timer.it_value.tv_sec = IO_U_TIMEOUT + IO_U_TIMEOUT_INC; + td->timer.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &td->timer, NULL); + fio_gettime(&td->timeout_end, NULL); +} +#else +void io_u_set_timeout(struct thread_data fio_unused *td) +{ +} +#endif + +#ifdef FIO_USE_TIMEOUT +static void io_u_timeout_handler(int fio_unused sig) +{ + struct thread_data *td, *__td; + pid_t pid = getpid(); + int i; + + log_err("fio: io_u timeout\n"); + + /* + * TLS would be nice... + */ + td = NULL; + for_each_td(__td, i) { + if (__td->pid == pid) { + td = __td; + break; + } + } + + if (!td) { + log_err("fio: io_u timeout, can't find job\n"); + exit(1); + } + + if (!td->cur_depth) { + log_err("fio: timeout without pending work?\n"); + return; + } + + log_err("fio: io_u timeout: job=%s, pid=%d\n", td->name, td->pid); + td->error = ETIMEDOUT; + exit(1); +} +#endif + +void io_u_init_timeout(void) +{ +#ifdef FIO_USE_TIMEOUT + signal(SIGALRM, io_u_timeout_handler); +#endif +}