#include #include #include "nm.hh" #include "storage/io_gen.hh" io_generator::io_generator( unsigned long req_size, unsigned long capacity, unsigned int read_pct, io_generator_address_mode addr_mode) : cur_offset(0), capacity(capacity), req_size(req_size), read_pct(read_pct), addr_mode(addr_mode), rng(rd()), dist(std::uniform_int_distribution(0, 99)), addr_rng(addr_rd()), addr_dist(std::uniform_int_distribution(0, capacity - 1)) { rng.seed(nm_get_uptime_ns()); addr_rng.seed(nm_get_uptime_ns()); } /* returns 0 on success */ int io_generator::issue(struct io_generator_ctx *ctx, char * buf) { ctx->size = req_size; // determine next IO offset if (addr_mode == IOGEN_ADDR_MONOTONIC_INCREASING) { if (cur_offset + req_size > capacity) { cur_offset = 0; } ctx->offset = cur_offset; cur_offset = cur_offset + req_size; } else { ctx->offset = (addr_dist(addr_rng) / req_size) * req_size; if (ctx->offset + req_size > capacity) { ctx->offset -= req_size; } } // determine next IO data int op_rng = dist(rng); if (op_rng < (int)read_pct) { ctx->op = IOGEN_READ; } else { ctx->op = IOGEN_WRITE; int data = dist(rng); memset(buf, data, req_size); } return 0; }