From d63fbc8a8edbfe6dde99131f62da4697a8212438 Mon Sep 17 00:00:00 2001 From: Yuri Date: Fri, 21 May 2021 17:09:00 +0000 Subject: [PATCH] nvmf: allow poll groups to run on a subset of cores In order to avoid latency imbalances, the user can specify a cpu mask on which the poll groups should run. This code update added data structures to control set of CPU cores. Change-Id: Iaf69d75da2fc6fed350d97d11027ce09e9432210 Signed-off-by: Yuri Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5610 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Ziye Yang Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Michael Haeuptle Reviewed-by: Aleksey Marchuk --- mk/spdk.lib_deps.mk | 2 +- module/event/subsystems/nvmf/event_nvmf.h | 2 ++ module/event/subsystems/nvmf/nvmf_tgt.c | 20 +++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mk/spdk.lib_deps.mk b/mk/spdk.lib_deps.mk index bc812ac7f..225144ba5 100644 --- a/mk/spdk.lib_deps.mk +++ b/mk/spdk.lib_deps.mk @@ -167,7 +167,7 @@ DEPDIRS-event_vmd := init vmd $(JSON_LIBS) log thread DEPDIRS-event_bdev := init bdev event_accel event_vmd event_sock DEPDIRS-event_nbd := init nbd event_bdev -DEPDIRS-event_nvmf := init nvmf event_bdev event_sock thread log bdev $(JSON_LIBS) +DEPDIRS-event_nvmf := init nvmf event_bdev event_sock thread log bdev util $(JSON_LIBS) DEPDIRS-event_scsi := init scsi event_bdev DEPDIRS-event_iscsi := init iscsi event_scsi event_sock diff --git a/module/event/subsystems/nvmf/event_nvmf.h b/module/event/subsystems/nvmf/event_nvmf.h index 72b52d2ec..9c796f9bb 100644 --- a/module/event/subsystems/nvmf/event_nvmf.h +++ b/module/event/subsystems/nvmf/event_nvmf.h @@ -61,4 +61,6 @@ extern uint16_t g_spdk_nvmf_tgt_crdt[3]; extern struct spdk_nvmf_tgt *g_spdk_nvmf_tgt; +extern struct spdk_cpuset *g_poll_groups_mask; + #endif diff --git a/module/event/subsystems/nvmf/nvmf_tgt.c b/module/event/subsystems/nvmf/nvmf_tgt.c index 00797386a..65b40b8d6 100644 --- a/module/event/subsystems/nvmf/nvmf_tgt.c +++ b/module/event/subsystems/nvmf/nvmf_tgt.c @@ -64,6 +64,7 @@ struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf = { .admin_passthru.identify_ctrlr = false }; +struct spdk_cpuset *g_poll_groups_mask = NULL; struct spdk_nvmf_tgt *g_spdk_nvmf_tgt = NULL; uint32_t g_spdk_nvmf_tgt_max_subsystems = 0; uint16_t g_spdk_nvmf_tgt_crdt[3] = {0, 0, 0}; @@ -150,6 +151,16 @@ nvmf_tgt_destroy_poll_groups(void) } } +static uint32_t +nvmf_get_cpuset_count(void) +{ + if (g_poll_groups_mask) { + return spdk_cpuset_count(g_poll_groups_mask); + } else { + return spdk_env_get_core_count(); + } +} + static void nvmf_tgt_create_poll_group_done(void *ctx) { @@ -157,9 +168,9 @@ nvmf_tgt_create_poll_group_done(void *ctx) TAILQ_INSERT_TAIL(&g_poll_groups, pg, link); - assert(g_num_poll_groups < spdk_env_get_core_count()); + assert(g_num_poll_groups < nvmf_get_cpuset_count()); - if (++g_num_poll_groups == spdk_env_get_core_count()) { + if (++g_num_poll_groups == nvmf_get_cpuset_count()) { g_tgt_state = NVMF_TGT_INIT_START_SUBSYSTEMS; nvmf_tgt_advance_state(); } @@ -195,9 +206,12 @@ nvmf_tgt_create_poll_groups(void) assert(g_tgt_init_thread != NULL); SPDK_ENV_FOREACH_CORE(i) { + if (g_poll_groups_mask && !spdk_cpuset_get_cpu(g_poll_groups_mask, i)) { + continue; + } snprintf(thread_name, sizeof(thread_name), "nvmf_tgt_poll_group_%u", i); - thread = spdk_thread_create(thread_name, NULL); + thread = spdk_thread_create(thread_name, g_poll_groups_mask); assert(thread != NULL); spdk_thread_send_msg(thread, nvmf_tgt_create_poll_group, NULL);