1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef _RTE_LAUNCH_H_ 6 #define _RTE_LAUNCH_H_ 7 8 /** 9 * @file 10 * 11 * Launch tasks on other lcores 12 */ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /** 19 * State of an lcore. 20 */ 21 enum rte_lcore_state_t { 22 WAIT, /**< waiting a new command */ 23 RUNNING, /**< executing command */ 24 FINISHED, /**< command executed */ 25 }; 26 27 /** 28 * Definition of a remote launch function. 29 */ 30 typedef int (lcore_function_t)(void *); 31 32 /** 33 * Launch a function on another lcore. 34 * 35 * To be executed on the MAIN lcore only. 36 * 37 * Sends a message to a worker lcore (identified by the worker_id) that 38 * is in the WAIT state (this is true after the first call to 39 * rte_eal_init()). This can be checked by first calling 40 * rte_eal_wait_lcore(worker_id). 41 * 42 * When the remote lcore receives the message, it switches to 43 * the RUNNING state, then calls the function f with argument arg. Once the 44 * execution is done, the remote lcore switches to a FINISHED state and 45 * the return value of f is stored in a local variable to be read using 46 * rte_eal_wait_lcore(). 47 * 48 * The MAIN lcore returns as soon as the message is sent and knows 49 * nothing about the completion of f. 50 * 51 * Note: This function is not designed to offer optimum 52 * performance. It is just a practical way to launch a function on 53 * another lcore at initialization time. 54 * 55 * @param f 56 * The function to be called. 57 * @param arg 58 * The argument for the function. 59 * @param worker_id 60 * The identifier of the lcore on which the function should be executed. 61 * @return 62 * - 0: Success. Execution of function f started on the remote lcore. 63 * - (-EBUSY): The remote lcore is not in a WAIT state. 64 */ 65 int rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned worker_id); 66 67 /** 68 * This enum indicates whether the main core must execute the handler 69 * launched on all logical cores. 70 */ 71 enum rte_rmt_call_main_t { 72 SKIP_MAIN = 0, /**< lcore handler not executed by main core. */ 73 CALL_MAIN, /**< lcore handler executed by main core. */ 74 }; 75 76 /** 77 * Launch a function on all lcores. 78 * 79 * Check that each WORKER lcore is in a WAIT state, then call 80 * rte_eal_remote_launch() for each lcore. 81 * 82 * @param f 83 * The function to be called. 84 * @param arg 85 * The argument for the function. 86 * @param call_main 87 * If call_main set to SKIP_MAIN, the MAIN lcore does not call 88 * the function. If call_main is set to CALL_MAIN, the function 89 * is also called on main before returning. In any case, the main 90 * lcore returns as soon as it finished its job and knows nothing 91 * about the completion of f on the other lcores. 92 * @return 93 * - 0: Success. Execution of function f started on all remote lcores. 94 * - (-EBUSY): At least one remote lcore is not in a WAIT state. In this 95 * case, no message is sent to any of the lcores. 96 */ 97 int rte_eal_mp_remote_launch(lcore_function_t *f, void *arg, 98 enum rte_rmt_call_main_t call_main); 99 100 /** 101 * Get the state of the lcore identified by worker_id. 102 * 103 * To be executed on the MAIN lcore only. 104 * 105 * @param worker_id 106 * The identifier of the lcore. 107 * @return 108 * The state of the lcore. 109 */ 110 enum rte_lcore_state_t rte_eal_get_lcore_state(unsigned int worker_id); 111 112 /** 113 * Wait until an lcore finishes its job. 114 * 115 * To be executed on the MAIN lcore only. 116 * 117 * If the worker lcore identified by the worker_id is in a FINISHED state, 118 * switch to the WAIT state. If the lcore is in RUNNING state, wait until 119 * the lcore finishes its job and moves to the FINISHED state. 120 * 121 * @param worker_id 122 * The identifier of the lcore. 123 * @return 124 * - 0: If the lcore identified by the worker_id is in a WAIT state. 125 * - The value that was returned by the previous remote launch 126 * function call if the lcore identified by the worker_id was in a 127 * FINISHED or RUNNING state. In this case, it changes the state 128 * of the lcore to WAIT. 129 */ 130 int rte_eal_wait_lcore(unsigned worker_id); 131 132 /** 133 * Wait until all lcores finish their jobs. 134 * 135 * To be executed on the MAIN lcore only. Issue an 136 * rte_eal_wait_lcore() for every lcore. The return values are 137 * ignored. 138 * 139 * After a call to rte_eal_mp_wait_lcore(), the caller can assume 140 * that all worker lcores are in a WAIT state. 141 */ 142 void rte_eal_mp_wait_lcore(void); 143 144 #ifdef __cplusplus 145 } 146 #endif 147 148 #endif /* _RTE_LAUNCH_H_ */ 149