From acbec142ae296722105306be97beeca400a3737b Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Tue, 26 Dec 2017 19:48:59 +0800 Subject: [PATCH] bdevperf: remove static array allocation for head and coremap We can use spdk_env_get_core_count() to determine the core count Change-Id: I854ec86f10c5670b02295214d1d36fe5d57e31a4 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/392934 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- test/lib/bdev/bdevperf/bdevperf.c | 43 +++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index 4f4512ef1..ba517ba3d 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -95,9 +95,8 @@ struct io_target { TAILQ_HEAD(, bdevperf_task) task_list; }; -#define SPDK_MAX_LCORE 128 -struct io_target *head[SPDK_MAX_LCORE]; -uint32_t coremap[SPDK_MAX_LCORE]; +struct io_target **head; +uint32_t *coremap; static int g_target_count = 0; /* @@ -108,19 +107,32 @@ static int g_target_count = 0; */ static size_t g_min_alignment = 8; -static void +static int blockdev_heads_init(void) { - uint32_t i, idx; + uint32_t i, idx = 0; + uint32_t core_count = spdk_env_get_core_count(); - for (i = 0; i < SPDK_MAX_LCORE; i++) { - head[i] = NULL; + head = calloc(core_count, sizeof(struct io_target *)); + if (!head) { + fprintf(stderr, "Cannot allocate head array with size=%u\n", + core_count); + return -1; + } + + coremap = calloc(core_count, sizeof(uint32_t)); + if (!coremap) { + free(head); + fprintf(stderr, "Cannot allocate coremap array with size=%u\n", + core_count); + return -1; } - idx = 0; SPDK_ENV_FOREACH_CORE(i) { coremap[idx++] = i; } + + return 0; } static void @@ -141,10 +153,11 @@ bdevperf_free_target(struct io_target *target) static void blockdev_heads_destroy(void) { - uint32_t i; + uint32_t i, core_count; struct io_target *target, *next_target; - for (i = 0; i < SPDK_MAX_LCORE; i++) { + core_count = spdk_env_get_core_count(); + for (i = 0; i < core_count; i++) { target = head[i]; while (target != NULL) { next_target = target->next; @@ -152,6 +165,9 @@ blockdev_heads_destroy(void) target = next_target; } } + + free(head); + free(coremap); } static void @@ -648,7 +664,12 @@ bdevperf_run(void *arg1, void *arg2) struct spdk_event *event; int rc; - blockdev_heads_init(); + rc = blockdev_heads_init(); + if (rc) { + spdk_app_stop(1); + return; + } + bdevperf_construct_targets(); rc = bdevperf_construct_targets_tasks();