1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #include <errno.h> 6 7 #include <rte_launch.h> 8 #include <rte_atomic.h> 9 #include <rte_pause.h> 10 #include <rte_lcore.h> 11 12 #include "eal_private.h" 13 14 /* 15 * Wait until a lcore finished its job. 16 */ 17 int 18 rte_eal_wait_lcore(unsigned worker_id) 19 { 20 while (__atomic_load_n(&lcore_config[worker_id].state, 21 __ATOMIC_ACQUIRE) != WAIT) 22 rte_pause(); 23 24 return lcore_config[worker_id].ret; 25 } 26 27 /* 28 * Check that every WORKER lcores are in WAIT state, then call 29 * rte_eal_remote_launch() for all of them. If call_main is true 30 * (set to CALL_MAIN), also call the function on the main lcore. 31 */ 32 int 33 rte_eal_mp_remote_launch(int (*f)(void *), void *arg, 34 enum rte_rmt_call_main_t call_main) 35 { 36 int lcore_id; 37 int main_lcore = rte_get_main_lcore(); 38 39 /* check state of lcores */ 40 RTE_LCORE_FOREACH_WORKER(lcore_id) { 41 if (lcore_config[lcore_id].state != WAIT) 42 return -EBUSY; 43 } 44 45 /* send messages to cores */ 46 RTE_LCORE_FOREACH_WORKER(lcore_id) { 47 rte_eal_remote_launch(f, arg, lcore_id); 48 } 49 50 if (call_main == CALL_MAIN) { 51 lcore_config[main_lcore].ret = f(arg); 52 lcore_config[main_lcore].state = WAIT; 53 } 54 55 return 0; 56 } 57 58 /* 59 * Return the state of the lcore identified by worker_id. 60 */ 61 enum rte_lcore_state_t 62 rte_eal_get_lcore_state(unsigned lcore_id) 63 { 64 return lcore_config[lcore_id].state; 65 } 66 67 /* 68 * Do a rte_eal_wait_lcore() for every lcore. The return values are 69 * ignored. 70 */ 71 void 72 rte_eal_mp_wait_lcore(void) 73 { 74 unsigned lcore_id; 75 76 RTE_LCORE_FOREACH_WORKER(lcore_id) { 77 rte_eal_wait_lcore(lcore_id); 78 } 79 } 80