xref: /dpdk/lib/eal/include/rte_launch.h (revision 9856af40449d73ed4c342df343355aa99cbc4b8a)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_LAUNCH_H_
699a2dd95SBruce Richardson #define _RTE_LAUNCH_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * Launch tasks on other lcores
1299a2dd95SBruce Richardson  */
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson #ifdef __cplusplus
1599a2dd95SBruce Richardson extern "C" {
1699a2dd95SBruce Richardson #endif
1799a2dd95SBruce Richardson 
1899a2dd95SBruce Richardson /**
1999a2dd95SBruce Richardson  * State of an lcore.
2099a2dd95SBruce Richardson  */
2199a2dd95SBruce Richardson enum rte_lcore_state_t {
22f6c6c686SHonnappa Nagarahalli 	WAIT,
23f6c6c686SHonnappa Nagarahalli 	/**< waiting for new command */
24f6c6c686SHonnappa Nagarahalli 	RUNNING,
25f6c6c686SHonnappa Nagarahalli 	/**< executing command */
2699a2dd95SBruce Richardson };
2799a2dd95SBruce Richardson 
2899a2dd95SBruce Richardson /**
2999a2dd95SBruce Richardson  * Definition of a remote launch function.
3099a2dd95SBruce Richardson  */
3199a2dd95SBruce Richardson typedef int (lcore_function_t)(void *);
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson /**
3499a2dd95SBruce Richardson  * Launch a function on another lcore.
3599a2dd95SBruce Richardson  *
3699a2dd95SBruce Richardson  * To be executed on the MAIN lcore only.
3799a2dd95SBruce Richardson  *
3899a2dd95SBruce Richardson  * Sends a message to a worker lcore (identified by the worker_id) that
3999a2dd95SBruce Richardson  * is in the WAIT state (this is true after the first call to
4099a2dd95SBruce Richardson  * rte_eal_init()). This can be checked by first calling
4199a2dd95SBruce Richardson  * rte_eal_wait_lcore(worker_id).
4299a2dd95SBruce Richardson  *
4399a2dd95SBruce Richardson  * When the remote lcore receives the message, it switches to
4499a2dd95SBruce Richardson  * the RUNNING state, then calls the function f with argument arg. Once the
45f6c6c686SHonnappa Nagarahalli  * execution is done, the remote lcore switches to WAIT state and
4699a2dd95SBruce Richardson  * the return value of f is stored in a local variable to be read using
4799a2dd95SBruce Richardson  * rte_eal_wait_lcore().
4899a2dd95SBruce Richardson  *
4999a2dd95SBruce Richardson  * The MAIN lcore returns as soon as the message is sent and knows
5099a2dd95SBruce Richardson  * nothing about the completion of f.
5199a2dd95SBruce Richardson  *
5299a2dd95SBruce Richardson  * Note: This function is not designed to offer optimum
5399a2dd95SBruce Richardson  * performance. It is just a practical way to launch a function on
5499a2dd95SBruce Richardson  * another lcore at initialization time.
5599a2dd95SBruce Richardson  *
5699a2dd95SBruce Richardson  * @param f
5799a2dd95SBruce Richardson  *   The function to be called.
5899a2dd95SBruce Richardson  * @param arg
5999a2dd95SBruce Richardson  *   The argument for the function.
6099a2dd95SBruce Richardson  * @param worker_id
6199a2dd95SBruce Richardson  *   The identifier of the lcore on which the function should be executed.
6299a2dd95SBruce Richardson  * @return
6399a2dd95SBruce Richardson  *   - 0: Success. Execution of function f started on the remote lcore.
6499a2dd95SBruce Richardson  *   - (-EBUSY): The remote lcore is not in a WAIT state.
65*9856af40SBruce Richardson  *   - (-EPIPE): Error reading or writing pipe to worker thread
6699a2dd95SBruce Richardson  */
6799a2dd95SBruce Richardson int rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned worker_id);
6899a2dd95SBruce Richardson 
6999a2dd95SBruce Richardson /**
7099a2dd95SBruce Richardson  * This enum indicates whether the main core must execute the handler
7199a2dd95SBruce Richardson  * launched on all logical cores.
7299a2dd95SBruce Richardson  */
7399a2dd95SBruce Richardson enum rte_rmt_call_main_t {
7499a2dd95SBruce Richardson 	SKIP_MAIN = 0, /**< lcore handler not executed by main core. */
7599a2dd95SBruce Richardson 	CALL_MAIN,     /**< lcore handler executed by main core. */
7699a2dd95SBruce Richardson };
7799a2dd95SBruce Richardson 
7899a2dd95SBruce Richardson /**
7999a2dd95SBruce Richardson  * Launch a function on all lcores.
8099a2dd95SBruce Richardson  *
8199a2dd95SBruce Richardson  * Check that each WORKER lcore is in a WAIT state, then call
8299a2dd95SBruce Richardson  * rte_eal_remote_launch() for each lcore.
8399a2dd95SBruce Richardson  *
8499a2dd95SBruce Richardson  * @param f
8599a2dd95SBruce Richardson  *   The function to be called.
8699a2dd95SBruce Richardson  * @param arg
8799a2dd95SBruce Richardson  *   The argument for the function.
8899a2dd95SBruce Richardson  * @param call_main
8999a2dd95SBruce Richardson  *   If call_main set to SKIP_MAIN, the MAIN lcore does not call
9099a2dd95SBruce Richardson  *   the function. If call_main is set to CALL_MAIN, the function
9199a2dd95SBruce Richardson  *   is also called on main before returning. In any case, the main
9299a2dd95SBruce Richardson  *   lcore returns as soon as it finished its job and knows nothing
9399a2dd95SBruce Richardson  *   about the completion of f on the other lcores.
9499a2dd95SBruce Richardson  * @return
9599a2dd95SBruce Richardson  *   - 0: Success. Execution of function f started on all remote lcores.
9699a2dd95SBruce Richardson  *   - (-EBUSY): At least one remote lcore is not in a WAIT state. In this
9799a2dd95SBruce Richardson  *     case, no message is sent to any of the lcores.
9899a2dd95SBruce Richardson  */
9999a2dd95SBruce Richardson int rte_eal_mp_remote_launch(lcore_function_t *f, void *arg,
10099a2dd95SBruce Richardson 			     enum rte_rmt_call_main_t call_main);
10199a2dd95SBruce Richardson 
10299a2dd95SBruce Richardson /**
10399a2dd95SBruce Richardson  * Get the state of the lcore identified by worker_id.
10499a2dd95SBruce Richardson  *
10599a2dd95SBruce Richardson  * To be executed on the MAIN lcore only.
10699a2dd95SBruce Richardson  *
10799a2dd95SBruce Richardson  * @param worker_id
10899a2dd95SBruce Richardson  *   The identifier of the lcore.
10999a2dd95SBruce Richardson  * @return
11099a2dd95SBruce Richardson  *   The state of the lcore.
11199a2dd95SBruce Richardson  */
11299a2dd95SBruce Richardson enum rte_lcore_state_t rte_eal_get_lcore_state(unsigned int worker_id);
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson /**
11599a2dd95SBruce Richardson  * Wait until an lcore finishes its job.
11699a2dd95SBruce Richardson  *
11799a2dd95SBruce Richardson  * To be executed on the MAIN lcore only.
11899a2dd95SBruce Richardson  *
119f6c6c686SHonnappa Nagarahalli  * If the lcore identified by the worker_id is in RUNNING state, wait until
120f6c6c686SHonnappa Nagarahalli  * the lcore finishes its job and moves to the WAIT state.
12199a2dd95SBruce Richardson  *
12299a2dd95SBruce Richardson  * @param worker_id
12399a2dd95SBruce Richardson  *   The identifier of the lcore.
12499a2dd95SBruce Richardson  * @return
125f6c6c686SHonnappa Nagarahalli  *   - 0: If the remote launch function was never called on the lcore
126f6c6c686SHonnappa Nagarahalli  *     identified by the worker_id.
12799a2dd95SBruce Richardson  *   - The value that was returned by the previous remote launch
128f6c6c686SHonnappa Nagarahalli  *     function call.
12999a2dd95SBruce Richardson  */
13099a2dd95SBruce Richardson int rte_eal_wait_lcore(unsigned worker_id);
13199a2dd95SBruce Richardson 
13299a2dd95SBruce Richardson /**
13399a2dd95SBruce Richardson  * Wait until all lcores finish their jobs.
13499a2dd95SBruce Richardson  *
13599a2dd95SBruce Richardson  * To be executed on the MAIN lcore only. Issue an
13699a2dd95SBruce Richardson  * rte_eal_wait_lcore() for every lcore. The return values are
13799a2dd95SBruce Richardson  * ignored.
13899a2dd95SBruce Richardson  *
13999a2dd95SBruce Richardson  * After a call to rte_eal_mp_wait_lcore(), the caller can assume
14099a2dd95SBruce Richardson  * that all worker lcores are in a WAIT state.
14199a2dd95SBruce Richardson  */
14299a2dd95SBruce Richardson void rte_eal_mp_wait_lcore(void);
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson #ifdef __cplusplus
14599a2dd95SBruce Richardson }
14699a2dd95SBruce Richardson #endif
14799a2dd95SBruce Richardson 
14899a2dd95SBruce Richardson #endif /* _RTE_LAUNCH_H_ */
149