From 70d096e7758450bbb4e7cdd85d7af51bba4f448f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 20 Dec 2018 09:03:39 +0900 Subject: [PATCH] nvme_perf: Factor out allocate task operation into a function Subsequent patches will support DIF and DIX in NVMe Perf and will make buffer management a little complex. This patch tries to make them a little easier. Change-Id: I3e0e3e03ca386467c7477e1ec8aa537ca47316e2 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/437903 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- examples/nvme/perf/perf.c | 52 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 9db10daa5..b60774625 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -756,33 +756,41 @@ check_io(struct ns_worker_ctx *ns_ctx) } } -static void -submit_io(struct ns_worker_ctx *ns_ctx, int queue_depth) +static struct perf_task * +allocate_task(struct ns_worker_ctx *ns_ctx, int queue_depth) { struct perf_task *task; uint32_t max_io_size_bytes; + task = calloc(1, sizeof(*task)); + if (task == NULL) { + fprintf(stderr, "Out of memory allocating tasks\n"); + exit(1); + } + + /* maximum extended lba format size from all active namespace, + * it's same with g_io_size_bytes for namespace without metadata. + */ + max_io_size_bytes = g_io_size_bytes + g_max_io_md_size * g_max_io_size_blocks; + task->buf = spdk_dma_zmalloc(max_io_size_bytes, g_io_align, NULL); + if (task->buf == NULL) { + fprintf(stderr, "task->buf spdk_dma_zmalloc failed\n"); + exit(1); + } + memset(task->buf, queue_depth % 8 + 1, max_io_size_bytes); + + task->ns_ctx = ns_ctx; + + return task; +} + +static void +submit_io(struct ns_worker_ctx *ns_ctx, int queue_depth) +{ + struct perf_task *task; + while (queue_depth-- > 0) { - task = calloc(1, sizeof(*task)); - if (task == NULL) { - fprintf(stderr, "Out of memory allocating tasks\n"); - exit(1); - } - - /* maximum extended lba format size from all active - * namespace, it's same with g_io_size_bytes for - * namespace without metadata - */ - max_io_size_bytes = g_io_size_bytes + g_max_io_md_size * g_max_io_size_blocks; - task->buf = spdk_dma_zmalloc(max_io_size_bytes, g_io_align, NULL); - if (task->buf == NULL) { - fprintf(stderr, "task->buf spdk_dma_zmalloc failed\n"); - exit(1); - } - memset(task->buf, queue_depth % 8 + 1, max_io_size_bytes); - - task->ns_ctx = ns_ctx; - + task = allocate_task(ns_ctx, queue_depth); submit_single_io(task); } }