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",