Merge branch 'master' of https://github.com/bvanassche/fio
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index 3b296cd7d09afd45bab04eb0e3208acc11d73dc8..5213c60f1a984570a5ee2fe2eceda1f605ed6853 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -82,8 +82,8 @@ static void iolog_delay(struct thread_data *td, unsigned long delay)
 {
        uint64_t usec = utime_since_now(&td->last_issue);
        unsigned long orig_delay = delay;
-       uint64_t this_delay;
        struct timespec ts;
+       int ret = 0;
 
        if (delay < td->time_offset) {
                td->time_offset = 0;
@@ -97,13 +97,13 @@ static void iolog_delay(struct thread_data *td, unsigned long delay)
        delay -= usec;
 
        fio_gettime(&ts, NULL);
-       while (delay && !td->terminate) {
-               this_delay = delay;
-               if (this_delay > 500000)
-                       this_delay = 500000;
 
-               usec_sleep(td, this_delay);
-               delay -= this_delay;
+       while (delay && !td->terminate) {
+               ret = io_u_queued_complete(td, 0);
+               if (ret < 0)
+                       td_verror(td, -ret, "io_u_queued_complete");
+               if (utime_since_now(&ts) > delay)
+                       break;
        }
 
        usec = utime_since_now(&ts);
@@ -439,7 +439,7 @@ static bool read_iolog(struct thread_data *td)
        unsigned long long offset;
        unsigned int bytes;
        unsigned long long delay = 0;
-       int reads, writes, waits, fileno = 0, file_action = 0; /* stupid gcc */
+       int reads, writes, trims, waits, fileno = 0, file_action = 0; /* stupid gcc */
        char *rfname, *fname, *act;
        char *str, *p;
        enum fio_ddir rw;
@@ -461,7 +461,7 @@ static bool read_iolog(struct thread_data *td)
        rfname = fname = malloc(256+16);
        act = malloc(256+16);
 
-       syncs = reads = writes = waits = 0;
+       syncs = reads = writes = trims = waits = 0;
        while ((p = fgets(str, 4096, td->io_log_rfile)) != NULL) {
                struct io_piece *ipo;
                int r;
@@ -552,6 +552,13 @@ static bool read_iolog(struct thread_data *td)
                        if (read_only)
                                continue;
                        writes++;
+               } else if (rw == DDIR_TRIM) {
+                       /*
+                        * Don't add a trim for ro mode
+                        */
+                       if (read_only)
+                               continue;
+                       trims++;
                } else if (rw == DDIR_WAIT) {
                        if (td->o.no_stall)
                                continue;
@@ -634,14 +641,16 @@ static bool read_iolog(struct thread_data *td)
                return true;
        }
 
-       if (!reads && !writes && !waits)
+       if (!reads && !writes && !waits && !trims)
                return false;
-       else if (reads && !writes)
-               td->o.td_ddir = TD_DDIR_READ;
-       else if (!reads && writes)
-               td->o.td_ddir = TD_DDIR_WRITE;
-       else
-               td->o.td_ddir = TD_DDIR_RW;
+
+       td->o.td_ddir = 0;
+       if (reads)
+               td->o.td_ddir |= TD_DDIR_READ;
+       if (writes)
+               td->o.td_ddir |= TD_DDIR_WRITE;
+       if (trims)
+               td->o.td_ddir |= TD_DDIR_TRIM;
 
        return true;
 }
@@ -993,14 +1002,14 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
 
        if (log_offset) {
                if (log_prio)
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %llu, 0x%04x\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %llu, 0x%04x\n";
                else
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %llu, %u\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %llu, %u\n";
        } else {
                if (log_prio)
-                       fmt = "%lu, %" PRId64 ", %u, %llu, 0x%04x\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, 0x%04x\n";
                else
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %u\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %u\n";
        }
 
        nr_samples = sample_size / __log_entry_sz(log_offset);
@@ -1015,7 +1024,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
 
                if (!log_offset) {
                        fprintf(f, fmt,
-                               (unsigned long) s->time,
+                               s->time,
                                s->data.val,
                                io_sample_ddir(s), (unsigned long long) s->bs,
                                prio_val);
@@ -1023,7 +1032,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
                        struct io_sample_offset *so = (void *) s;
 
                        fprintf(f, fmt,
-                               (unsigned long) s->time,
+                               s->time,
                                s->data.val,
                                io_sample_ddir(s), (unsigned long long) s->bs,
                                (unsigned long long) so->offset,
@@ -1866,9 +1875,7 @@ void td_writeout_logs(struct thread_data *td, bool unit_logs)
 
 void fio_writeout_logs(bool unit_logs)
 {
-       struct thread_data *td;
-       int i;
-
-       for_each_td(td, i)
+       for_each_td(td) {
                td_writeout_logs(td, unit_logs);
+       } end_for_each();
 }