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