From 1b7ce8053071b9d82fe149fdef29f6b76754fc3e Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 22 Dec 2017 08:21:35 +0800 Subject: [PATCH] env: export spdk_env_get_last_core function. Also use this function in iscsi/conn.c Change-Id: I25f6da175eddb12c4ac2624d695c2c43c871d8e8 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/392713 Tested-by: SPDK Automated Test System Reviewed-by: Reviewed-by: Jim Harris --- include/spdk/env.h | 6 ++++++ lib/env_dpdk/threads.c | 18 ++++++++++++++++++ lib/iscsi/conn.c | 7 ++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index fb81b5678..86c133b61 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -227,6 +227,12 @@ uint32_t spdk_env_get_current_core(void); */ uint32_t spdk_env_get_first_core(void); +/** + * \brief Return the index of the last dedicated CPU core for + * this application. + */ +uint32_t spdk_env_get_last_core(void); + /** * \brief Return the index of the next dedicated CPU core for * this application. diff --git a/lib/env_dpdk/threads.c b/lib/env_dpdk/threads.c index 3a06d0446..1e23906cd 100644 --- a/lib/env_dpdk/threads.c +++ b/lib/env_dpdk/threads.c @@ -54,6 +54,24 @@ spdk_env_get_first_core(void) return rte_get_next_lcore(-1, 0, 0); } +uint32_t +spdk_env_get_last_core(void) +{ + uint32_t i; + static uint32_t last_core = UINT32_MAX; + + /* Already know the last_core, just return */ + if (last_core != UINT32_MAX) { + return last_core; + } + + SPDK_ENV_FOREACH_CORE(i) { + last_core = i; + } + + return last_core; +} + uint32_t spdk_env_get_next_core(uint32_t prev_core) { diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index c5b95996c..27bd1aabf 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -349,7 +349,7 @@ int spdk_initialize_iscsi_conns(void) { size_t conns_size; int conns_array_fd, rc; - uint32_t i, last_core = 0; + uint32_t i, last_core; SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_init\n"); @@ -383,10 +383,7 @@ int spdk_initialize_iscsi_conns(void) g_conns_array[i].id = i; } - SPDK_ENV_FOREACH_CORE(i) { - last_core = i; - } - + last_core = spdk_env_get_last_core(); g_num_connections = calloc(last_core + 1, sizeof(uint32_t)); if (!g_num_connections) { SPDK_ERRLOG("Could not allocate array size=%u for g_num_connections\n",