1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2017 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "env_internal.h" 7 8 #include <rte_config.h> 9 #include <rte_lcore.h> 10 11 #include "spdk/cpuset.h" 12 13 uint32_t 14 spdk_env_get_core_count(void) 15 { 16 return rte_lcore_count(); 17 } 18 19 uint32_t 20 spdk_env_get_current_core(void) 21 { 22 return rte_lcore_id(); 23 } 24 25 uint32_t 26 spdk_env_get_main_core(void) 27 { 28 return rte_get_main_lcore(); 29 } 30 31 uint32_t 32 spdk_env_get_first_core(void) 33 { 34 return rte_get_next_lcore(-1, 0, 0); 35 } 36 37 uint32_t 38 spdk_env_get_last_core(void) 39 { 40 uint32_t i; 41 uint32_t last_core = UINT32_MAX; 42 43 SPDK_ENV_FOREACH_CORE(i) { 44 last_core = i; 45 } 46 47 assert(last_core != UINT32_MAX); 48 49 return last_core; 50 } 51 52 uint32_t 53 spdk_env_get_next_core(uint32_t prev_core) 54 { 55 unsigned lcore; 56 57 lcore = rte_get_next_lcore(prev_core, 0, 0); 58 if (lcore == RTE_MAX_LCORE) { 59 return UINT32_MAX; 60 } 61 return lcore; 62 } 63 64 uint32_t 65 spdk_env_get_socket_id(uint32_t core) 66 { 67 if (core >= RTE_MAX_LCORE) { 68 return SPDK_ENV_SOCKET_ID_ANY; 69 } 70 71 return rte_lcore_to_socket_id(core); 72 } 73 74 void 75 spdk_env_get_cpuset(struct spdk_cpuset *cpuset) 76 { 77 uint32_t i; 78 79 spdk_cpuset_zero(cpuset); 80 SPDK_ENV_FOREACH_CORE(i) { 81 spdk_cpuset_set_cpu(cpuset, i, true); 82 } 83 } 84 85 int 86 spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg) 87 { 88 int rc; 89 90 rc = rte_eal_remote_launch(fn, arg, core); 91 92 return rc; 93 } 94 95 void 96 spdk_env_thread_wait_all(void) 97 { 98 rte_eal_mp_wait_lcore(); 99 } 100