TD_REAPED,
};
-#define should_fsync(td) (td_write(td) && (!(td)->odirect || (td)->override_sync))
+#define should_fsync(td) ((td_write(td) || td_rw(td)) && (!(td)->odirect || (td)->override_sync))
static sem_t startup_sem;
memcpy(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash));
}
+unsigned int hweight32(unsigned int w)
+{
+ unsigned int res = w - ((w >> 1) & 0x55555555);
+
+ res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+ res = (res + (res >> 4)) & 0x0F0F0F0F;
+ res = res + (res >> 8);
+
+ return (res + (res >> 16)) & 0x000000FF;
+}
+
+unsigned long hweight64(unsigned long long w)
+{
+#if __WORDSIZE == 32
+ return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+#elif __WORDSIZE == 64
+ unsigned long long v = w - ((w >> 1) & 0x5555555555555555ul);
+
+ v = (v & 0x3333333333333333ul) + ((v >> 2) & 0x3333333333333333ul);
+ v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
+ v = v + (v >> 8);
+ v = v + (v >> 16);
+
+ return (v + (v >> 32)) & 0x00000000000000FFul;
+#else
+#error __WORDSIZE not defined
+#endif
+}
+
+static int get_rw_ddir(struct thread_data *td)
+{
+ /*
+ * perhaps cheasy, but use the hamming weight of the position
+ * as a randomizer for data direction.
+ */
+ if (td_rw(td))
+ return hweight64(td->last_pos) & 1;
+ else if (td_read(td))
+ return DDIR_READ;
+ else
+ return DDIR_WRITE;
+}
+
/*
* fill body of io_u->buf with random data and add a header with the
* (eg) sha1sum of that data.
if (td->verify != VERIFY_NONE)
populate_io_u(td, io_u);
- if (td_io_prep(td, io_u, td_read(td))) {
+ if (td_io_prep(td, io_u, get_rw_ddir(td))) {
put_io_u(td, io_u);
return NULL;
}
if (!io_u->error) {
unsigned int bytes = io_u->buflen - io_u->resid;
- int idx = io_u->ddir;
+ const int idx = io_u->ddir;
td->io_blocks[idx]++;
td->io_bytes[idx] += bytes;
msec = mtime_since(&io_u->issue_time, &e);
- add_clat_sample(td, io_u->ddir, msec);
- add_bw_sample(td, io_u->ddir);
+ add_clat_sample(td, idx, msec);
+ add_bw_sample(td, idx);
- if (td_write(td) && io_u->ddir == DDIR_WRITE)
+ if ((td_rw(td) || td_write(td)) && idx == DDIR_WRITE)
log_io_piece(td, io_u);
icd->bytes_done[idx] += bytes;
if (td->cur_depth)
cleanup_pending_aio(td);
- if (should_fsync(td))
+ if (should_fsync(td) && td->fsync_blocks)
sync_td(td);
}
if (!td->file_size || td->file_size > td->real_file_size)
td->file_size = td->real_file_size;
+ td->file_size -= td->file_offset;
return 0;
}
if (!td->file_size || td->file_size > td->real_file_size)
td->file_size = td->real_file_size;
+ td->file_size -= td->file_offset;
return 0;
}
if (ret)
return ret;
- if (td->file_offset + td->file_size > td->real_file_size) {
- fprintf(stderr, "Client%d: offset extends end (%Lu > %Lu)\n", td->thread_number, td->file_offset + td->file_size, td->real_file_size);
+ if (td->file_offset > td->real_file_size) {
+ fprintf(stderr, "Client%d: offset extends end (%Lu > %Lu)\n", td->thread_number, td->file_offset, td->real_file_size);
return 1;
}
{
int flags;
- if (td_read(td))
- flags = PROT_READ;
- else {
+ if (td_rw(td))
+ flags = PROT_READ | PROT_WRITE;
+ else if (td_write(td)) {
flags = PROT_WRITE;
if (td->verify != VERIFY_NONE)
flags |= PROT_READ;
- }
+ } else
+ flags = PROT_READ;
td->mmap = mmap(NULL, td->file_size, flags, MAP_SHARED, td->fd, td->file_offset);
if (td->mmap == MAP_FAILED) {
if (td->odirect)
flags |= O_DIRECT;
- if (td_read(td)) {
- if (td->filetype == FIO_TYPE_CHAR)
- flags |= O_RDWR;
- else
- flags |= O_RDONLY;
-
- td->fd = open(td->file_name, flags);
- } else {
+ if (td_write(td) || td_rw(td)) {
if (td->filetype == FIO_TYPE_FILE) {
if (!td->overwrite)
flags |= O_TRUNC;
flags |= O_RDWR;
td->fd = open(td->file_name, flags, 0600);
+ } else {
+ if (td->filetype == FIO_TYPE_CHAR)
+ flags |= O_RDWR;
+ else
+ flags |= O_RDONLY;
+
+ td->fd = open(td->file_name, flags);
}
if (td->fd == -1) {
do_io(td);
td->runtime[td->ddir] += mtime_since_now(&td->start);
+ if (td_rw(td))
+ td->runtime[td->ddir ^ 1] = td->runtime[td->ddir];
+
update_rusage_stat(td);
if (td->error || td->terminate)
c = 'E';
break;
case TD_RUNNING:
- if (td_read(td)) {
+ if (td_rw(td)) {
+ if (td->sequential)
+ c = 'M';
+ else
+ c = 'm';
+ } else if (td_read(td)) {
if (td->sequential)
c = 'R';
else
unsigned int eta_sec = 0;
bytes_total = td->total_io_size;
- if (td->verify)
- bytes_total <<= 1;
+
+ /*
+ * if writing, bytes_total will be twice the size. If mixing,
+ * assume a 50/50 split and thus bytes_total will be 50% larger.
+ */
+ if (td->verify) {
+ if (td_rw(td))
+ bytes_total = bytes_total * 3 / 2;
+ else
+ bytes_total <<= 1;
+ }
if (td->zone_size && td->zone_skip)
bytes_total /= (td->zone_skip / td->zone_size);
if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
double perc;
+
bytes_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE];
perc = (double) bytes_done / (double) bytes_total;
if (perc > 1.0)
eta_sec = (elapsed * (1.0 / perc)) - elapsed;
- if (eta_sec > (td->timeout - elapsed))
+ if (td->timeout && eta_sec > (td->timeout - elapsed))
eta_sec = td->timeout - elapsed;
} else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED) {
int t_eta = 0, r_eta = 0;
if (elapsed >= 3)
eta_secs[i] = thread_eta(td, elapsed);
+ else
+ eta_secs[i] = INT_MAX;
check_str_update(td);
}
}
}
- if (eta_sec == INT_MAX)
- eta_sec = 0;
-
- if (eta_sec) {
+ if (eta_sec != INT_MAX && elapsed) {
perc = (double) elapsed / (double) (elapsed + eta_sec);
eta_to_str(eta_str, eta_sec);
}
printf("Threads now running (%d)", nr_running);
if (m_rate || t_rate)
printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
- if (eta_sec) {
+ if (eta_sec != INT_MAX) {
perc *= 100.0;
printf(": [%s] [%3.2f%% done] [eta %s]", run_str, perc,eta_str);
}