The <jobs> format is as follows:
directory=x Use 'x' as the top level directory for storing files
- rw=x 'x' may be: read, randread, write, or randwrite
+ rw=x 'x' may be: read, randread, write, randwrite,
+ rw (read-write mix), randrw (read-write random mix)
size=x Set file size to x bytes (x string can include k/m/g)
ioengine=x 'x' may be: aio/libaio/linuxaio for Linux aio,
posixaio for POSIX aio, sync for regular read/write io,
static int add_job(struct thread_data *td, const char *jobname, int prioclass,
int prio)
{
- char *ddir_str[] = { "read", "write", "randread", "randwrite" };
+ char *ddir_str[] = { "read", "write", "randread", "randwrite",
+ "rw", NULL, "randrw" };
struct stat sb;
int numjobs, ddir;
td->min_bs = td->bs;
if (td->max_bs == -1U)
td->max_bs = td->bs;
- if (td_read(td))
+ if (td_read(td) && !td_rw(td))
td->verify = 0;
if (td->stonewall && td->thread_number > 1)
if (write_bw_log)
setup_log(&td->bw_log);
- ddir = td->ddir + (!td->sequential << 1);
+ ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
printf("Client%d (g=%d): rw=%s, prio=%d/%d, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->thread_number, td->groupid, ddir_str[ddir], prioclass, prio, td->odirect, td->min_bs, td->max_bs, td->rate, td->io_engine_name, td->iodepth);
/*
td->ddir = DDIR_WRITE;
td->sequential = 0;
return 0;
+ } else if (!strncmp(mem, "rw", 2)) {
+ td->ddir = 0;
+ td->iomix = 1;
+ td->sequential = 1;
+ return 0;
+ } else if (!strncmp(mem, "randrw", 6)) {
+ td->ddir = 0;
+ td->iomix = 1;
+ td->sequential = 0;
+ return 0;
}
fprintf(stderr, "bad data direction: %s\n", mem);
* fill globals
*/
def_thread.ddir = DDIR_READ;
+ def_thread.iomix = 0;
def_thread.bs = DEF_BS;
def_thread.min_bs = -1;
def_thread.max_bs = -1;
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;
{
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);