-#include <stdio.h>
-#include <stdlib.h>
-#include "list.h"
-#include "fio.h"
-
-void write_iolog_put(struct thread_data *td, struct io_u *io_u)
-{
- fprintf(td->iolog_f, "%u,%llu,%lu\n", io_u->ddir, io_u->offset, io_u->buflen);
-}
-
-static void iolog_delay(struct thread_data *td, unsigned long delay)
-{
- unsigned long usec = utime_since_now(&td->last_issue);
-
- if (delay < usec)
- return;
-
- delay -= usec;
-
- /*
- * less than 100 usec delay, just regard it as noise
- */
- if (delay < 100)
- return;
-
- usec_sleep(td, delay);
-}
-
-int read_iolog_get(struct thread_data *td, struct io_u *io_u)
-{
- struct io_piece *ipo;
-
- if (!list_empty(&td->io_log_list)) {
- ipo = list_entry(td->io_log_list.next, struct io_piece, list);
- list_del(&ipo->list);
- io_u->offset = ipo->offset;
- io_u->buflen = ipo->len;
- io_u->ddir = ipo->ddir;
- io_u->file = ipo->file;
-
- if (ipo->delay)
- iolog_delay(td, ipo->delay);
-
- /*
- * work around, this needs a format change to work for > 1 file
- */
- if (!io_u->file)
- io_u->file = &td->files[0];
- free(ipo);
- return 0;
- }
-
- return 1;
-}
-
-void prune_io_piece_log(struct thread_data *td)
-{
- struct io_piece *ipo;
- struct rb_node *n;
-
- while ((n = rb_first(&td->io_hist_tree)) != NULL) {
- ipo = rb_entry(n, struct io_piece, rb_node);
- rb_erase(n, &td->io_hist_tree);
- free(ipo);
- }
-}
-
-/*
- * log a successful write, so we can unwind the log for verify
- */
-void log_io_piece(struct thread_data *td, struct io_u *io_u)
-{
- struct rb_node **p, *parent;
- struct io_piece *ipo, *__ipo;
-
- ipo = malloc(sizeof(struct io_piece));
- ipo->file = io_u->file;
- ipo->offset = io_u->offset;
- ipo->len = io_u->buflen;
-
- /*
- * We don't need to sort the entries, if:
- *
- * Sequential writes, or
- * Random writes that lay out the file as it goes along
- *
- * For both these cases, just reading back data in the order we
- * wrote it out is the fastest.
- */
- if (!td_random(td) || !td->o.overwrite ||
- (io_u->file->flags & FIO_FILE_NOSORT)) {
- INIT_LIST_HEAD(&ipo->list);
- list_add_tail(&ipo->list, &td->io_hist_list);
- return;
- }
-
- RB_CLEAR_NODE(&ipo->rb_node);
- p = &td->io_hist_tree.rb_node;
- parent = NULL;