xref: /dpdk/lib/eal/include/rte_launch.h (revision 9856af40449d73ed4c342df343355aa99cbc4b8a)
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,
23 	/**< waiting for new command */
24 	RUNNING,
25 	/**< executing command */
26 };
27 
28 /**
29  * Definition of a remote launch function.
30  */
31 typedef int (lcore_function_t)(void *);
32 
33 /**
34  * Launch a function on another lcore.
35  *
36  * To be executed on the MAIN lcore only.
37  *
38  * Sends a message to a worker lcore (identified by the worker_id) that
39  * is in the WAIT state (this is true after the first call to
40  * rte_eal_init()). This can be checked by first calling
41  * rte_eal_wait_lcore(worker_id).
42  *
43  * When the remote lcore receives the message, it switches to
44  * the RUNNING state, then calls the function f with argument arg. Once the
45  * execution is done, the remote lcore switches to WAIT state and
46  * the return value of f is stored in a local variable to be read using
47  * rte_eal_wait_lcore().
48  *
49  * The MAIN lcore returns as soon as the message is sent and knows
50  * nothing about the completion of f.
51  *
52  * Note: This function is not designed to offer optimum
53  * performance. It is just a practical way to launch a function on
54  * another lcore at initialization time.
55  *
56  * @param f
57  *   The function to be called.
58  * @param arg
59  *   The argument for the function.
60  * @param worker_id
61  *   The identifier of the lcore on which the function should be executed.
62  * @return
63  *   - 0: Success. Execution of function f started on the remote lcore.
64  *   - (-EBUSY): The remote lcore is not in a WAIT state.
65  *   - (-EPIPE): Error reading or writing pipe to worker thread
66  */
67 int rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned worker_id);
68 
69 /**
70  * This enum indicates whether the main core must execute the handler
71  * launched on all logical cores.
72  */
73 enum rte_rmt_call_main_t {
74 	SKIP_MAIN = 0, /**< lcore handler not executed by main core. */
75 	CALL_MAIN,     /**< lcore handler executed by main core. */
76 };
77 
78 /**
79  * Launch a function on all lcores.
80  *
81  * Check that each WORKER lcore is in a WAIT state, then call
82  * rte_eal_remote_launch() for each lcore.
83  *
84  * @param f
85  *   The function to be called.
86  * @param arg
87  *   The argument for the function.
88  * @param call_main
89  *   If call_main set to SKIP_MAIN, the MAIN lcore does not call
90  *   the function. If call_main is set to CALL_MAIN, the function
91  *   is also called on main before returning. In any case, the main
92  *   lcore returns as soon as it finished its job and knows nothing
93  *   about the completion of f on the other lcores.
94  * @return
95  *   - 0: Success. Execution of function f started on all remote lcores.
96  *   - (-EBUSY): At least one remote lcore is not in a WAIT state. In this
97  *     case, no message is sent to any of the lcores.
98  */
99 int rte_eal_mp_remote_launch(lcore_function_t *f, void *arg,
100 			     enum rte_rmt_call_main_t call_main);
101 
102 /**
103  * Get the state of the lcore identified by worker_id.
104  *
105  * To be executed on the MAIN lcore only.
106  *
107  * @param worker_id
108  *   The identifier of the lcore.
109  * @return
110  *   The state of the lcore.
111  */
112 enum rte_lcore_state_t rte_eal_get_lcore_state(unsigned int worker_id);
113 
114 /**
115  * Wait until an lcore finishes its job.
116  *
117  * To be executed on the MAIN lcore only.
118  *
119  * If the lcore identified by the worker_id is in RUNNING state, wait until
120  * the lcore finishes its job and moves to the WAIT state.
121  *
122  * @param worker_id
123  *   The identifier of the lcore.
124  * @return
125  *   - 0: If the remote launch function was never called on the lcore
126  *     identified by the worker_id.
127  *   - The value that was returned by the previous remote launch
128  *     function call.
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