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 uint32_t 12 spdk_env_get_core_count(void) 13 { 14 return rte_lcore_count(); 15 } 16 17 uint32_t 18 spdk_env_get_current_core(void) 19 { 20 return rte_lcore_id(); 21 } 22 23 uint32_t 24 spdk_env_get_main_core(void) 25 { 26 return rte_get_main_lcore(); 27 } 28 29 uint32_t 30 spdk_env_get_first_core(void) 31 { 32 return rte_get_next_lcore(-1, 0, 0); 33 } 34 35 uint32_t 36 spdk_env_get_last_core(void) 37 { 38 uint32_t i; 39 uint32_t last_core = UINT32_MAX; 40 41 SPDK_ENV_FOREACH_CORE(i) { 42 last_core = i; 43 } 44 45 assert(last_core != UINT32_MAX); 46 47 return last_core; 48 } 49 50 uint32_t 51 spdk_env_get_next_core(uint32_t prev_core) 52 { 53 unsigned lcore; 54 55 lcore = rte_get_next_lcore(prev_core, 0, 0); 56 if (lcore == RTE_MAX_LCORE) { 57 return UINT32_MAX; 58 } 59 return lcore; 60 } 61 62 uint32_t 63 spdk_env_get_socket_id(uint32_t core) 64 { 65 if (core >= RTE_MAX_LCORE) { 66 return SPDK_ENV_SOCKET_ID_ANY; 67 } 68 69 return rte_lcore_to_socket_id(core); 70 } 71 72 int 73 spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg) 74 { 75 int rc; 76 77 rc = rte_eal_remote_launch(fn, arg, core); 78 79 return rc; 80 } 81 82 void 83 spdk_env_thread_wait_all(void) 84 { 85 rte_eal_mp_wait_lcore(); 86 } 87