Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 1 | #include <unistd.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <string.h> |
| 4 | #include <signal.h> |
| 5 | #include <time.h> |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 6 | |
| 7 | #include "fio.h" |
| 8 | #include "os.h" |
| 9 | |
| 10 | /* |
| 11 | * The ->file_map[] contains a map of blocks we have or have not done io |
| 12 | * to yet. Used to make sure we cover the entire range in a fair fashion. |
| 13 | */ |
| 14 | static int random_map_free(struct thread_data *td, struct fio_file *f, |
| 15 | unsigned long long block) |
| 16 | { |
| 17 | unsigned int idx = RAND_MAP_IDX(td, f, block); |
| 18 | unsigned int bit = RAND_MAP_BIT(td, f, block); |
| 19 | |
| 20 | return (f->file_map[idx] & (1UL << bit)) == 0; |
| 21 | } |
| 22 | |
| 23 | /* |
Jens Axboe | df41558 | 2006-10-20 11:41:03 +0200 | [diff] [blame] | 24 | * Mark a given offset as used in the map. |
| 25 | */ |
| 26 | static void mark_random_map(struct thread_data *td, struct fio_file *f, |
| 27 | struct io_u *io_u) |
| 28 | { |
Jens Axboe | afdbe58 | 2007-02-10 19:01:57 +0100 | [diff] [blame] | 29 | unsigned int min_bs = td->rw_min_bs; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 30 | unsigned long long block; |
| 31 | unsigned int blocks; |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 32 | unsigned int nr_blocks; |
Jens Axboe | df41558 | 2006-10-20 11:41:03 +0200 | [diff] [blame] | 33 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 34 | block = io_u->offset / (unsigned long long) min_bs; |
| 35 | blocks = 0; |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 36 | nr_blocks = (io_u->buflen + min_bs - 1) / min_bs; |
| 37 | |
| 38 | while (blocks < nr_blocks) { |
Jens Axboe | df41558 | 2006-10-20 11:41:03 +0200 | [diff] [blame] | 39 | unsigned int idx, bit; |
| 40 | |
| 41 | if (!random_map_free(td, f, block)) |
| 42 | break; |
| 43 | |
| 44 | idx = RAND_MAP_IDX(td, f, block); |
| 45 | bit = RAND_MAP_BIT(td, f, block); |
| 46 | |
Jens Axboe | 0032bf9 | 2007-02-13 17:39:56 +0100 | [diff] [blame] | 47 | fio_assert(td, idx < f->num_maps); |
Jens Axboe | df41558 | 2006-10-20 11:41:03 +0200 | [diff] [blame] | 48 | |
| 49 | f->file_map[idx] |= (1UL << bit); |
| 50 | block++; |
| 51 | blocks++; |
| 52 | } |
| 53 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 54 | if ((blocks * min_bs) < io_u->buflen) |
| 55 | io_u->buflen = blocks * min_bs; |
Jens Axboe | df41558 | 2006-10-20 11:41:03 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 59 | * Return the next free block in the map. |
| 60 | */ |
| 61 | static int get_next_free_block(struct thread_data *td, struct fio_file *f, |
| 62 | unsigned long long *b) |
| 63 | { |
| 64 | int i; |
| 65 | |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 66 | i = f->last_free_lookup; |
| 67 | *b = (i * BLOCKS_PER_MAP); |
Jens Axboe | ee88470 | 2006-12-20 10:58:07 +0100 | [diff] [blame] | 68 | while ((*b) * td->rw_min_bs < f->real_file_size) { |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 69 | if (f->file_map[i] != -1UL) { |
| 70 | *b += ffz(f->file_map[i]); |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 71 | f->last_free_lookup = i; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | *b += BLOCKS_PER_MAP; |
| 76 | i++; |
| 77 | } |
| 78 | |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * For random io, generate a random new block and see if it's used. Repeat |
| 84 | * until we find a free one. For sequential io, just return the end of |
| 85 | * the last io issued. |
| 86 | */ |
| 87 | static int get_next_offset(struct thread_data *td, struct fio_file *f, |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 88 | struct io_u *io_u) |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 89 | { |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 90 | const int ddir = io_u->ddir; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 91 | unsigned long long b, rb; |
| 92 | long r; |
| 93 | |
| 94 | if (!td->sequential) { |
Jens Axboe | f697125 | 2006-11-15 10:00:31 +0100 | [diff] [blame] | 95 | unsigned long long max_blocks = f->file_size / td->min_bs[ddir]; |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 96 | int loops = 5; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 97 | |
| 98 | do { |
| 99 | r = os_random_long(&td->random_state); |
| 100 | b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0)); |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 101 | if (td->norandommap) |
| 102 | break; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 103 | rb = b + (f->file_offset / td->min_bs[ddir]); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 104 | loops--; |
| 105 | } while (!random_map_free(td, f, rb) && loops); |
| 106 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 107 | /* |
| 108 | * if we failed to retrieve a truly random offset within |
| 109 | * the loops assigned, see if there are free ones left at all |
| 110 | */ |
| 111 | if (!loops && get_next_free_block(td, f, &b)) |
| 112 | return 1; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 113 | } else |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 114 | b = f->last_pos / td->min_bs[ddir]; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 115 | |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 116 | io_u->offset = (b * td->min_bs[ddir]) + f->file_offset; |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 117 | if (io_u->offset >= f->real_file_size) |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 118 | return 1; |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 123 | static unsigned int get_next_buflen(struct thread_data *td, struct fio_file *f, |
| 124 | struct io_u *io_u) |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 125 | { |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 126 | const int ddir = io_u->ddir; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 127 | unsigned int buflen; |
| 128 | long r; |
| 129 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 130 | if (td->min_bs[ddir] == td->max_bs[ddir]) |
| 131 | buflen = td->min_bs[ddir]; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 132 | else { |
| 133 | r = os_random_long(&td->bsrange_state); |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 134 | buflen = (unsigned int) (1 + (double) (td->max_bs[ddir] - 1) * r / (RAND_MAX + 1.0)); |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 135 | if (!td->bs_unaligned) |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 136 | buflen = (buflen + td->min_bs[ddir] - 1) & ~(td->min_bs[ddir] - 1); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 139 | while (buflen + io_u->offset > f->real_file_size) { |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 140 | if (buflen == td->min_bs[ddir]) |
| 141 | return 0; |
| 142 | |
| 143 | buflen = td->min_bs[ddir]; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return buflen; |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Return the data direction for the next io_u. If the job is a |
| 151 | * mixed read/write workload, check the rwmix cycle and switch if |
| 152 | * necessary. |
| 153 | */ |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 154 | static enum fio_ddir get_rw_ddir(struct thread_data *td) |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 155 | { |
| 156 | if (td_rw(td)) { |
| 157 | struct timeval now; |
| 158 | unsigned long elapsed; |
| 159 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 160 | fio_gettime(&now, NULL); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 161 | elapsed = mtime_since_now(&td->rwmix_switch); |
| 162 | |
| 163 | /* |
| 164 | * Check if it's time to seed a new data direction. |
| 165 | */ |
| 166 | if (elapsed >= td->rwmixcycle) { |
| 167 | unsigned int v; |
| 168 | long r; |
| 169 | |
| 170 | r = os_random_long(&td->rwmix_state); |
| 171 | v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0))); |
| 172 | if (v < td->rwmixread) |
| 173 | td->rwmix_ddir = DDIR_READ; |
| 174 | else |
| 175 | td->rwmix_ddir = DDIR_WRITE; |
| 176 | memcpy(&td->rwmix_switch, &now, sizeof(now)); |
| 177 | } |
| 178 | return td->rwmix_ddir; |
| 179 | } else if (td_read(td)) |
| 180 | return DDIR_READ; |
| 181 | else |
| 182 | return DDIR_WRITE; |
| 183 | } |
| 184 | |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 185 | void put_io_u(struct thread_data *td, struct io_u *io_u) |
| 186 | { |
| 187 | io_u->file = NULL; |
| 188 | list_del(&io_u->list); |
| 189 | list_add(&io_u->list, &td->io_u_freelist); |
| 190 | td->cur_depth--; |
| 191 | } |
| 192 | |
| 193 | static int fill_io_u(struct thread_data *td, struct fio_file *f, |
| 194 | struct io_u *io_u) |
| 195 | { |
| 196 | /* |
| 197 | * If using an iolog, grab next piece if any available. |
| 198 | */ |
| 199 | if (td->read_iolog) |
| 200 | return read_iolog_get(td, io_u); |
| 201 | |
| 202 | /* |
Jens Axboe | 87dc1ab | 2006-10-24 14:41:26 +0200 | [diff] [blame] | 203 | * see if it's time to sync |
| 204 | */ |
| 205 | if (td->fsync_blocks && !(td->io_blocks[DDIR_WRITE] % td->fsync_blocks) |
| 206 | && should_fsync(td)) { |
| 207 | io_u->ddir = DDIR_SYNC; |
| 208 | io_u->file = f; |
| 209 | return 0; |
| 210 | } |
| 211 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 212 | io_u->ddir = get_rw_ddir(td); |
| 213 | |
Jens Axboe | 87dc1ab | 2006-10-24 14:41:26 +0200 | [diff] [blame] | 214 | /* |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 215 | * No log, let the seq/rand engine retrieve the next buflen and |
| 216 | * position. |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 217 | */ |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 218 | if (get_next_offset(td, f, io_u)) |
| 219 | return 1; |
Jens Axboe | c685b5b | 2007-02-10 20:02:28 +0100 | [diff] [blame] | 220 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 221 | io_u->buflen = get_next_buflen(td, f, io_u); |
| 222 | if (!io_u->buflen) |
| 223 | return 1; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 224 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 225 | /* |
| 226 | * mark entry before potentially trimming io_u |
| 227 | */ |
| 228 | if (!td->read_iolog && !td->sequential && !td->norandommap) |
| 229 | mark_random_map(td, f, io_u); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 230 | |
Jens Axboe | bca4ed4 | 2007-02-12 05:13:23 +0100 | [diff] [blame] | 231 | /* |
| 232 | * If using a write iolog, store this entry. |
| 233 | */ |
| 234 | if (td->write_iolog_file) |
| 235 | write_iolog_put(td, io_u); |
| 236 | |
| 237 | io_u->file = f; |
| 238 | return 0; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 241 | static void io_u_mark_depth(struct thread_data *td) |
| 242 | { |
| 243 | int index = 0; |
| 244 | |
| 245 | switch (td->cur_depth) { |
| 246 | default: |
| 247 | index++; |
| 248 | case 32 ... 63: |
| 249 | index++; |
| 250 | case 16 ... 31: |
| 251 | index++; |
| 252 | case 8 ... 15: |
| 253 | index++; |
| 254 | case 4 ... 7: |
| 255 | index++; |
| 256 | case 2 ... 3: |
| 257 | index++; |
| 258 | case 1: |
| 259 | break; |
| 260 | } |
| 261 | |
| 262 | td->io_u_map[index]++; |
| 263 | td->total_io_u++; |
| 264 | } |
| 265 | |
Jens Axboe | ec11830 | 2007-02-17 04:38:20 +0100 | [diff] [blame^] | 266 | static void io_u_mark_latency(struct thread_data *td, unsigned long msec) |
| 267 | { |
| 268 | int index = 0; |
| 269 | |
| 270 | switch (msec) { |
| 271 | default: |
| 272 | index++; |
| 273 | case 1024 ... 2047: |
| 274 | index++; |
| 275 | case 512 ... 1023: |
| 276 | index++; |
| 277 | case 256 ... 511: |
| 278 | index++; |
| 279 | case 128 ... 255: |
| 280 | index++; |
| 281 | case 64 ... 127: |
| 282 | index++; |
| 283 | case 32 ... 63: |
| 284 | index++; |
| 285 | case 16 ... 31: |
| 286 | index++; |
| 287 | case 8 ... 15: |
| 288 | index++; |
| 289 | case 4 ... 7: |
| 290 | index++; |
| 291 | case 2 ... 3: |
| 292 | index++; |
| 293 | case 0 ... 1: |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | td->io_u_lat[index]++; |
| 298 | } |
| 299 | |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 300 | struct io_u *__get_io_u(struct thread_data *td) |
| 301 | { |
| 302 | struct io_u *io_u = NULL; |
| 303 | |
| 304 | if (!queue_full(td)) { |
| 305 | io_u = list_entry(td->io_u_freelist.next, struct io_u, list); |
| 306 | |
Jens Axboe | 6040dab | 2006-10-24 19:38:15 +0200 | [diff] [blame] | 307 | io_u->buflen = 0; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 308 | io_u->error = 0; |
| 309 | io_u->resid = 0; |
| 310 | list_del(&io_u->list); |
| 311 | list_add(&io_u->list, &td->io_u_busylist); |
| 312 | td->cur_depth++; |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 313 | io_u_mark_depth(td); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return io_u; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * Return an io_u to be processed. Gets a buflen and offset, sets direction, |
| 321 | * etc. The returned io_u is fully ready to be prepped and submitted. |
| 322 | */ |
| 323 | struct io_u *get_io_u(struct thread_data *td, struct fio_file *f) |
| 324 | { |
| 325 | struct io_u *io_u; |
| 326 | |
| 327 | io_u = __get_io_u(td); |
| 328 | if (!io_u) |
| 329 | return NULL; |
| 330 | |
| 331 | if (td->zone_bytes >= td->zone_size) { |
| 332 | td->zone_bytes = 0; |
| 333 | f->last_pos += td->zone_skip; |
| 334 | } |
| 335 | |
| 336 | if (fill_io_u(td, f, io_u)) { |
| 337 | put_io_u(td, io_u); |
| 338 | return NULL; |
| 339 | } |
| 340 | |
Jens Axboe | ee88470 | 2006-12-20 10:58:07 +0100 | [diff] [blame] | 341 | if (io_u->buflen + io_u->offset > f->real_file_size) { |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 342 | if (td->io_ops->flags & FIO_RAWIO) { |
| 343 | put_io_u(td, io_u); |
| 344 | return NULL; |
| 345 | } |
| 346 | |
Jens Axboe | ee88470 | 2006-12-20 10:58:07 +0100 | [diff] [blame] | 347 | io_u->buflen = f->real_file_size - io_u->offset; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Jens Axboe | 87dc1ab | 2006-10-24 14:41:26 +0200 | [diff] [blame] | 350 | if (io_u->ddir != DDIR_SYNC) { |
| 351 | if (!io_u->buflen) { |
| 352 | put_io_u(td, io_u); |
| 353 | return NULL; |
| 354 | } |
| 355 | |
Jens Axboe | 87dc1ab | 2006-10-24 14:41:26 +0200 | [diff] [blame] | 356 | f->last_pos += io_u->buflen; |
| 357 | |
| 358 | if (td->verify != VERIFY_NONE) |
| 359 | populate_verify_io_u(td, io_u); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 362 | if (td_io_prep(td, io_u)) { |
| 363 | put_io_u(td, io_u); |
| 364 | return NULL; |
| 365 | } |
| 366 | |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 367 | /* |
| 368 | * Set io data pointers. |
| 369 | */ |
Jens Axboe | cec6b55 | 2007-02-06 20:15:38 +0100 | [diff] [blame] | 370 | io_u->xfer_buf = io_u->buf; |
| 371 | io_u->xfer_buflen = io_u->buflen; |
Jens Axboe | 165faf1 | 2007-02-07 11:30:37 +0100 | [diff] [blame] | 372 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 373 | fio_gettime(&io_u->start_time, NULL); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 374 | return io_u; |
| 375 | } |
| 376 | |
| 377 | void io_completed(struct thread_data *td, struct io_u *io_u, |
| 378 | struct io_completion_data *icd) |
| 379 | { |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 380 | unsigned long msec; |
| 381 | |
Jens Axboe | 87dc1ab | 2006-10-24 14:41:26 +0200 | [diff] [blame] | 382 | if (io_u->ddir == DDIR_SYNC) { |
| 383 | td->last_was_sync = 1; |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | td->last_was_sync = 0; |
| 388 | |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 389 | if (!io_u->error) { |
| 390 | unsigned int bytes = io_u->buflen - io_u->resid; |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 391 | const enum fio_ddir idx = io_u->ddir; |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 392 | |
| 393 | td->io_blocks[idx]++; |
| 394 | td->io_bytes[idx] += bytes; |
| 395 | td->zone_bytes += bytes; |
| 396 | td->this_io_bytes[idx] += bytes; |
| 397 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 398 | io_u->file->last_completed_pos = io_u->offset + io_u->buflen; |
| 399 | |
| 400 | msec = mtime_since(&io_u->issue_time, &icd->time); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 401 | |
| 402 | add_clat_sample(td, idx, msec); |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 403 | add_bw_sample(td, idx, &icd->time); |
Jens Axboe | ec11830 | 2007-02-17 04:38:20 +0100 | [diff] [blame^] | 404 | io_u_mark_latency(td, msec); |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 405 | |
| 406 | if ((td_rw(td) || td_write(td)) && idx == DDIR_WRITE) |
| 407 | log_io_piece(td, io_u); |
| 408 | |
| 409 | icd->bytes_done[idx] += bytes; |
| 410 | } else |
| 411 | icd->error = io_u->error; |
| 412 | } |
| 413 | |
| 414 | void ios_completed(struct thread_data *td, struct io_completion_data *icd) |
| 415 | { |
| 416 | struct io_u *io_u; |
| 417 | int i; |
| 418 | |
Jens Axboe | 02bcaa8 | 2006-11-24 10:42:00 +0100 | [diff] [blame] | 419 | fio_gettime(&icd->time, NULL); |
| 420 | |
Jens Axboe | 10ba535 | 2006-10-20 11:39:27 +0200 | [diff] [blame] | 421 | icd->error = 0; |
| 422 | icd->bytes_done[0] = icd->bytes_done[1] = 0; |
| 423 | |
| 424 | for (i = 0; i < icd->nr; i++) { |
| 425 | io_u = td->io_ops->event(td, i); |
| 426 | |
| 427 | io_completed(td, io_u, icd); |
| 428 | put_io_u(td, io_u); |
| 429 | } |
| 430 | } |