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