bdevperf: Delete g_min_alignment and g_buf_size and use per target variables instead

Remove two global variables and use variables per target instead.

g_min_alignment:

Bdevperf creates task on a target after creating the target, and
we has removed any limitation about alignment described in the comment.

Remove g_min_alignment and use each bdev's alignment to call
spdk_zmalloc() instead.

g_buf_size:

We had set the size of task->buf by not g_buf_size but g_io_size
by mistake.  We have not used any global buffer pool and can use
buffer size per io_target instead.

Delete g_buf_size and add buf_size to struct io_target.  Then
initialize target->buf_size in bdevperf_construct_target() and use it
instead of g_buf_size including the fix in
bdevperf_construct_task_on_target().

Besides, as a minor cleanup, remove duplicated initialization of
global variables in this patch. Global variables are already
initialized at their definition. Remove duplicated initialization
from main() function. It is ensured that global variables are
automatically zeroed but write initialized value expilcitly for
compatibility and clarification.

These will be helpful to parallelize targets and tasks management among
multiple threads.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Iba23dec3e1da8810da7523da09bae858eb4484a2
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/512
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-02-05 03:02:44 -05:00 committed by Tomasz Zawadzki
parent 63c50be82e
commit f7f504cf42

View File

@ -56,9 +56,8 @@ struct bdevperf_task {
struct spdk_bdev_io_wait_entry bdev_io_wait;
};
static const char *g_workload_type;
static const char *g_workload_type = NULL;
static int g_io_size = 0;
static uint64_t g_buf_size = 0;
/* initialize to invalid value so we can detect if user overrides it. */
static int g_rw_percentage = -1;
static int g_is_random;
@ -68,7 +67,7 @@ static bool g_continue_on_failure = false;
static bool g_unmap = false;
static bool g_write_zeroes = false;
static bool g_flush = false;
static int g_queue_depth;
static int g_queue_depth = 0;
static uint64_t g_time_in_usec;
static int g_show_performance_real_time = 0;
static uint64_t g_show_performance_period_in_usec = 1000000;
@ -79,8 +78,8 @@ static bool g_shutdown = false;
static uint64_t g_shutdown_tsc;
static bool g_zcopy = true;
static struct spdk_thread *g_master_thread;
static int g_time_in_sec;
static bool g_mix_specified;
static int g_time_in_sec = 0;
static bool g_mix_specified = false;
static const char *g_target_bdev_name;
static bool g_wait_for_tests = false;
static struct spdk_jsonrpc_request *g_request = NULL;
@ -106,6 +105,7 @@ struct io_target {
uint64_t size_in_ios;
uint64_t offset_in_ios;
uint64_t io_size_blocks;
uint64_t buf_size;
uint32_t dif_check_flags;
bool is_draining;
struct spdk_poller *run_timer;
@ -130,14 +130,6 @@ static struct spdk_bdevperf g_bdevperf = {
struct io_target_group *g_next_tg;
static uint32_t g_target_count = 0;
/*
* Used to determine how the I/O buffers should be aligned.
* This alignment will be bumped up for blockdevs that
* require alignment based on block length - for example,
* AIO blockdevs.
*/
static size_t g_min_alignment = 8;
static void
generate_data(void *buf, int buf_len, int block_size, void *md_buf, int md_size,
int num_blocks, int seed)
@ -294,7 +286,6 @@ bdevperf_construct_target(struct spdk_bdev *bdev)
{
struct io_target_group *group;
struct io_target *target;
size_t align;
int block_size, data_block_size;
int rc;
@ -343,7 +334,7 @@ bdevperf_construct_target(struct spdk_bdev *bdev)
return 0;
}
g_buf_size = spdk_max(g_buf_size, target->io_size_blocks * block_size);
target->buf_size = target->io_size_blocks * block_size;
target->dif_check_flags = 0;
if (spdk_bdev_is_dif_check_enabled(bdev, SPDK_DIF_CHECK_TYPE_REFTAG)) {
@ -354,12 +345,6 @@ bdevperf_construct_target(struct spdk_bdev *bdev)
}
target->size_in_ios = spdk_bdev_get_num_blocks(bdev) / target->io_size_blocks;
align = spdk_bdev_get_buf_align(bdev);
/*
* TODO: This should actually use the LCM of align and g_min_alignment, but
* it is fairly safe to assume all alignments are powers of two for now.
*/
g_min_alignment = spdk_max(g_min_alignment, align);
target->is_draining = false;
target->run_timer = NULL;
@ -526,7 +511,7 @@ bdevperf_complete(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
spdk_bdev_io_get_iovec(bdev_io, &iovs, &iovcnt);
assert(iovcnt == 1);
assert(iovs != NULL);
if (!verify_data(task->buf, g_buf_size, iovs[0].iov_base, iovs[0].iov_len,
if (!verify_data(task->buf, target->buf_size, iovs[0].iov_base, iovs[0].iov_len,
spdk_bdev_get_block_size(target->bdev),
task->md_buf, spdk_bdev_io_get_md_buf(bdev_io),
spdk_bdev_get_md_size(target->bdev),
@ -768,7 +753,7 @@ bdevperf_zcopy_get_buf_complete(struct spdk_bdev_io *bdev_io, bool success, void
assert(iovcnt == 1);
assert(iovs != NULL);
copy_data(iovs[0].iov_base, iovs[0].iov_len, task->buf, g_buf_size,
copy_data(iovs[0].iov_base, iovs[0].iov_len, task->buf, target->buf_size,
spdk_bdev_get_block_size(target->bdev),
spdk_bdev_io_get_md_buf(bdev_io), task->md_buf,
spdk_bdev_get_md_size(target->bdev), target->io_size_blocks);
@ -829,7 +814,7 @@ bdevperf_submit_single(struct io_target *target, struct bdevperf_task *task)
task->offset_blocks = offset_in_ios * target->io_size_blocks;
if (g_verify || g_reset) {
generate_data(task->buf, g_buf_size,
generate_data(task->buf, target->buf_size,
spdk_bdev_get_block_size(target->bdev),
task->md_buf, spdk_bdev_get_md_size(target->bdev),
target->io_size_blocks, rand_r(&seed) % 256);
@ -838,7 +823,7 @@ bdevperf_submit_single(struct io_target *target, struct bdevperf_task *task)
return;
} else {
task->iov.iov_base = task->buf;
task->iov.iov_len = g_buf_size;
task->iov.iov_len = target->buf_size;
task->io_type = SPDK_BDEV_IO_TYPE_WRITE;
}
} else if (g_flush) {
@ -856,7 +841,7 @@ bdevperf_submit_single(struct io_target *target, struct bdevperf_task *task)
return;
} else {
task->iov.iov_base = task->buf;
task->iov.iov_len = g_buf_size;
task->iov.iov_len = target->buf_size;
task->io_type = SPDK_BDEV_IO_TYPE_WRITE;
}
}
@ -1067,8 +1052,8 @@ static struct bdevperf_task *bdevperf_construct_task_on_target(struct io_target
return NULL;
}
task->buf = spdk_zmalloc(g_io_size, g_min_alignment, NULL, SPDK_ENV_LCORE_ID_ANY,
SPDK_MALLOC_DMA);
task->buf = spdk_zmalloc(target->buf_size, spdk_bdev_get_buf_align(target->bdev), NULL,
SPDK_ENV_LCORE_ID_ANY, SPDK_MALLOC_DMA);
if (!task->buf) {
fprintf(stderr, "Cannot allocate buf for task=%p\n", task);
free(task);
@ -1100,11 +1085,6 @@ bdevperf_construct_targets_tasks(void)
struct bdevperf_task *task;
int i, task_num = g_queue_depth;
/*
* Create the task pool after we have enumerated the targets, so that we know
* the min buffer alignment. Some backends such as AIO have alignment restrictions
* that must be accounted for.
*/
if (g_reset) {
task_num += 1;
}
@ -1516,13 +1496,6 @@ main(int argc, char **argv)
opts.reactor_mask = NULL;
opts.shutdown_cb = spdk_bdevperf_shutdown_cb;
/* default value */
g_queue_depth = 0;
g_io_size = 0;
g_workload_type = NULL;
g_time_in_sec = 0;
g_mix_specified = false;
if ((rc = spdk_app_parse_args(argc, argv, &opts, "zfq:o:t:w:CM:P:S:T:", NULL,
bdevperf_parse_arg, bdevperf_usage)) !=
SPDK_APP_PARSE_ARGS_SUCCESS) {