Home | History | Annotate | Download | only in fio

Lines Matching defs:io_u

38 static void mark_random_map(struct thread_data *td, struct io_u *io_u)
41 struct fio_file *f = io_u->file;
45 block = (io_u->offset - f->file_offset) / (uint64_t) min_bs;
46 nr_blocks = (io_u->buflen + min_bs - 1) / min_bs;
48 if (!(io_u->flags & IO_U_F_BUSY_OK))
51 if ((nr_blocks * min_bs) < io_u->buflen)
52 io_u->buflen = nr_blocks * min_bs;
404 static int get_next_block(struct thread_data *td, struct io_u *io_u,
408 struct fio_file *f = io_u->file;
423 io_u_set(td, io_u, IO_U_F_BUSY_OK);
433 io_u_set(td, io_u, IO_U_F_BUSY_OK);
456 io_u->offset = offset;
458 io_u->offset = b * td->o.ba[ddir];
473 static int __get_next_offset(struct thread_data *td, struct io_u *io_u,
476 struct fio_file *f = io_u->file;
477 enum fio_ddir ddir = io_u->ddir;
487 if (get_next_block(td, io_u, ddir, rw_seq_hit, is_random))
490 if (io_u->offset >= f->io_size) {
492 (unsigned long long) io_u->offset,
497 io_u->offset += f->file_offset;
498 if (io_u->offset >= f->real_file_size) {
500 (unsigned long long) io_u->offset,
508 static int get_next_offset(struct thread_data *td, struct io_u *io_u,
515 return ops->fill_io_u_off(td, io_u, is_random);
518 return __get_next_offset(td, io_u, is_random);
521 static inline bool io_u_fits(struct thread_data *td, struct io_u *io_u,
524 struct fio_file *f = io_u->file;
526 return io_u->offset + buflen <= f->io_size + get_start_offset(td, f);
529 static unsigned int __get_next_buflen(struct thread_data *td, struct io_u *io_u,
532 int ddir = io_u->ddir;
552 if (!io_u_fits(td, io_u, minbs))
576 io_u_fits(td, io_u, buflen))
586 } while (!io_u_fits(td, io_u, buflen));
591 static unsigned int get_next_buflen(struct thread_data *td, struct io_u *io_u,
598 return ops->fill_io_u_size(td, io_u, is_random);
601 return __get_next_buflen(td, io_u, is_random);
711 * Return the data direction for the next io_u. If the job is a
768 static void set_rw_ddir(struct thread_data *td, struct io_u *io_u)
773 struct fio_file *f = io_u->file;
780 io_u->ddir = io_u->acct_ddir = ddir;
782 if (io_u->ddir == DDIR_WRITE && td_ioengine_flagged(td, FIO_BARRIER) &&
786 io_u_set(td, io_u, IO_U_F_BARRIER);
797 void put_io_u(struct thread_data *td, struct io_u *io_u)
804 if (io_u->file && !(io_u->flags & IO_U_F_NO_FILE_PUT))
805 put_file_log(td, io_u->file);
807 io_u->file = NULL;
808 io_u_set(td, io_u, IO_U_F_FREE);
810 if (io_u->flags & IO_U_F_IN_CUR_DEPTH) {
814 io_u_qpush(&td->io_u_freelist, io_u);
819 void clear_io_u(struct thread_data *td, struct io_u *io_u)
821 io_u_clear(td, io_u, IO_U_F_FLIGHT);
822 put_io_u(td, io_u);
825 void requeue_io_u(struct thread_data *td, struct io_u **io_u)
827 struct io_u *__io_u = *io_u;
850 *io_u = NULL;
853 static int fill_io_u(struct thread_data *td, struct io_u *io_u)
860 set_rw_ddir(td, io_u);
865 if (!ddir_rw(io_u->ddir))
872 struct fio_file *f = io_u->file;
882 f->last_pos[io_u->ddir] = f->file_offset;
890 if (get_next_offset(td, io_u, &is_random)) {
891 dprint(FD_IO, "io_u %p, failed getting offset\n", io_u);
895 io_u->buflen = get_next_buflen(td, io_u, is_random);
896 if (!io_u->buflen) {
897 dprint(FD_IO, "io_u %p, failed getting buflen\n", io_u);
901 if (io_u->offset + io_u->buflen > io_u->file->real_file_size) {
902 dprint(FD_IO, "io_u %p, offset + buflen exceeds file size\n",
903 io_u);
905 (unsigned long long) io_u->offset, io_u->buflen,
906 (unsigned long long) io_u->file->real_file_size);
911 * mark entry before potentially trimming io_u
913 if (td_random(td) && file_randommap(td, io_u->file))
914 mark_random_map(td, io_u);
917 dprint_io_u(io_u, "fill_io_u");
918 td->zone_bytes += io_u->buflen;
1262 static long set_io_u_file(struct thread_data *td, struct io_u *io_u)
1271 io_u->file = f;
1274 if (!fill_io_u(td, io_u))
1279 io_u->file = NULL;
1449 struct io_u *__get_io_u(struct thread_data *td)
1451 struct io_u *io_u = NULL;
1460 io_u = io_u_rpop(&td->io_u_requeues);
1462 io_u = io_u_qpop(&td->io_u_freelist);
1464 io_u->file = NULL;
1465 io_u->buflen = 0;
1466 io_u->resid = 0;
1467 io_u->end_io = NULL;
1470 if (io_u) {
1471 assert(io_u->flags & IO_U_F_FREE);
1472 io_u_clear(td, io_u, IO_U_F_FREE | IO_U_F_NO_FILE_PUT |
1476 io_u->error = 0;
1477 io_u->acct_ddir = -1;
1480 io_u_set(td, io_u, IO_U_F_IN_CUR_DEPTH);
1481 io_u->ipo = NULL;
1493 return io_u;
1496 static bool check_get_trim(struct thread_data *td, struct io_u *io_u)
1515 if (get_trim && get_next_trim(td, io_u))
1522 static bool check_get_verify(struct thread_data *td, struct io_u *io_u)
1540 if (get_verify && !get_next_verify(td, io_u)) {
1555 static void small_content_scramble(struct io_u *io_u)
1557 unsigned int i, nr_blocks = io_u->buflen / 512;
1565 p = io_u->xfer_buf;
1566 boffset = io_u->offset;
1567 io_u->buf_filled_len = 0;
1575 offset = (io_u->start_time.tv_usec ^ boffset) & 511;
1581 end = p + 512 - sizeof(io_u->start_time);
1582 memcpy(end, &io_u->start_time, sizeof(io_u->start_time));
1589 * Return an io_u to be processed. Gets a buflen and offset, sets direction,
1590 * etc. The returned io_u is fully ready to be prepped and submitted.
1592 struct io_u *get_io_u(struct thread_data *td)
1595 struct io_u *io_u;
1599 io_u = __get_io_u(td);
1600 if (!io_u) {
1605 if (check_get_verify(td, io_u))
1607 if (check_get_trim(td, io_u))
1611 * from a requeue, io_u already setup
1613 if (io_u->file)
1620 if (read_iolog_get(td, io_u))
1622 } else if (set_io_u_file(td, io_u)) {
1624 dprint(FD_IO, "io_u %p, setting file failed\n", io_u);
1628 f = io_u->file;
1630 dprint(FD_IO, "io_u %p, setting file failed\n", io_u);
1636 if (ddir_rw(io_u->ddir)) {
1637 if (!io_u->buflen && !td_ioengine_flagged(td, FIO_NOIO)) {
1638 dprint(FD_IO, "get_io_u: zero buflen on %p\n", io_u);
1642 f->last_start[io_u->ddir] = io_u->offset;
1643 f->last_pos[io_u->ddir] = io_u->offset + io_u->buflen;
1645 if (io_u->ddir == DDIR_WRITE) {
1647 io_u_fill_buffer(td, io_u,
1649 io_u->buflen);
1654 populate_verify_io_u(td, io_u);
1657 } else if (io_u->ddir == DDIR_READ) {
1662 io_u->buf_filled_len = 0;
1669 io_u->xfer_buf = io_u->buf;
1670 io_u->xfer_buflen = io_u->buflen;
1673 assert(io_u->file);
1674 if (!td_io_prep(td, io_u)) {
1676 fio_gettime(&io_u->start_time, NULL);
1679 small_content_scramble(io_u);
1681 return io_u;
1685 put_io_u(td, io_u);
1689 static void __io_u_log_error(struct thread_data *td, struct io_u *io_u)
1691 enum error_type_bit eb = td_error_type(io_u->ddir, io_u->error);
1693 if (td_non_fatal_error(td, eb, io_u->error) && !td->o.error_dump)
1696 log_err("fio: io_u error%s%s: %s: %s offset=%llu, buflen=%lu\n",
1697 io_u->file ? " on file " : "",
1698 io_u->file ? io_u->file->file_name : "",
1699 strerror(io_u->error),
1700 io_ddir_name(io_u->ddir),
1701 io_u->offset, io_u->xfer_buflen);
1704 char *err = td->io_ops->errdetails(io_u);
1711 td_verror(td, io_u->error, "io_u error");
1714 void io_u_log_error(struct thread_data *td, struct io_u *io_u)
1716 __io_u_log_error(td, io_u);
1718 __io_u_log_error(td->parent, io_u);
1727 static void account_io_completion(struct thread_data *td, struct io_u *io_u,
1741 lusec = utime_since(&io_u->issue_time, &icd->time);
1746 tusec = utime_since(&io_u->start_time, &icd->time);
1747 add_lat_sample(td, idx, tusec, bytes, io_u->offset);
1766 add_clat_sample(td, idx, lusec, bytes, io_u->offset);
1771 add_bw_sample(td, io_u, bytes, lusec);
1774 add_iops_sample(td, io_u, bytes);
1777 if (td->ts.nr_block_infos && io_u->ddir == DDIR_TRIM) {
1778 uint32_t *info = io_u_block_info(td, io_u);
1780 if (io_u->ddir == DDIR_TRIM) {
1783 } else if (io_u->ddir == DDIR_WRITE) {
1813 static void io_completed(struct thread_data *td, struct io_u **io_u_ptr,
1816 struct io_u *io_u = *io_u_ptr;
1817 enum fio_ddir ddir = io_u->ddir;
1818 struct fio_file *f = io_u->file;
1820 dprint_io_u(io_u, "io complete");
1822 assert(io_u->flags & IO_U_F_FLIGHT);
1823 io_u_clear(td, io_u, IO_U_F_FLIGHT | IO_U_F_BUSY_OK);
1828 if (io_u->ipo) {
1832 if (io_u->error)
1833 unlog_io_piece(td, io_u);
1835 io_u->ipo->flags &= ~IP_F_IN_FLIGHT;
1852 if (!io_u->error && ddir_rw(ddir)) {
1853 unsigned int bytes = io_u->buflen - io_u->resid;
1860 if (!(io_u->flags & IO_U_F_VER_LIST))
1864 file_log_write_comp(td, f, io_u->offset, bytes);
1868 account_io_completion(td, io_u, icd, ddir, bytes);
1872 if (io_u->end_io) {
1873 ret = io_u->end_io(td, io_u_ptr);
1874 io_u = *io_u_ptr;
1878 } else if (io_u->error) {
1879 icd->error = io_u->error;
1880 io_u_log_error(td, io_u);
1895 if (io_u)
1896 io_u->error = 0;
1918 struct io_u *io_u;
1922 io_u = td->io_ops->event(td, i);
1924 io_completed(td, &io_u, icd);
1926 if (io_u)
1927 put_io_u(td, io_u);
1932 * Complete a single io_u for the sync engines.
1934 int io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
1940 io_completed(td, &io_u, &icd);
1942 if (io_u)
1943 put_io_u(td, io_u);
1996 * Call when io_u is really queued, to update the submission latency.
1998 void io_u_queued(struct thread_data *td, struct io_u *io_u)
2003 slat_time = utime_since(&io_u->start_time, &io_u->issue_time);
2008 add_slat_sample(td, io_u->ddir, slat_time, io_u->xfer_buflen,
2009 io_u->offset);
2090 void io_u_fill_buffer(struct thread_data *td, struct io_u *io_u,
2093 io_u->buf_filled_len = 0;
2094 fill_io_buffer(td, io_u->buf, min_write, max_bs);
2111 int do_io_u_sync(const struct thread_data *td, struct io_u *io_u)
2115 if (io_u->ddir == DDIR_SYNC) {
2116 ret = fsync(io_u->file->fd);
2117 } else if (io_u->ddir == DDIR_DATASYNC) {
2119 ret = fdatasync(io_u->file->fd);
2121 ret = io_u->xfer_buflen;
2122 io_u->error = EINVAL;
2124 } else if (io_u->ddir == DDIR_SYNC_FILE_RANGE)
2125 ret = do_sync_file_range(td, io_u->file);
2127 ret = io_u->xfer_buflen;
2128 io_u->error = EINVAL;
2132 io_u->error = errno;
2137 int do_io_u_trim(const struct thread_data *td, struct io_u *io_u)
2140 io_u->error = EINVAL;
2143 struct fio_file *f = io_u->file;
2146 ret = os_trim(f->fd, io_u->offset, io_u->xfer_buflen);
2148 return io_u->xfer_buflen;
2150 io_u->error = ret;