doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_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                lcore_config[worker_id].state != FINISHED)
31                 rte_pause();
32
33         rte_rmb();
34
35         /* we are in finished state, go to wait state */
36         lcore_config[worker_id].state = WAIT;
37         return lcore_config[worker_id].ret;
38 }
39
40 /*
41  * Check that every WORKER lcores are in WAIT state, then call
42  * rte_eal_remote_launch() for all of them. If call_main is true
43  * (set to CALL_MAIN), also call the function on the main lcore.
44  */
45 int
46 rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
47                          enum rte_rmt_call_main_t call_main)
48 {
49         int lcore_id;
50         int main_lcore = rte_get_main_lcore();
51
52         /* check state of lcores */
53         RTE_LCORE_FOREACH_WORKER(lcore_id) {
54                 if (lcore_config[lcore_id].state != WAIT)
55                         return -EBUSY;
56         }
57
58         /* send messages to cores */
59         RTE_LCORE_FOREACH_WORKER(lcore_id) {
60                 rte_eal_remote_launch(f, arg, lcore_id);
61         }
62
63         if (call_main == CALL_MAIN) {
64                 lcore_config[main_lcore].ret = f(arg);
65                 lcore_config[main_lcore].state = FINISHED;
66         }
67
68         return 0;
69 }
70
71 /*
72  * Return the state of the lcore identified by worker_id.
73  */
74 enum rte_lcore_state_t
75 rte_eal_get_lcore_state(unsigned lcore_id)
76 {
77         return lcore_config[lcore_id].state;
78 }
79
80 /*
81  * Do a rte_eal_wait_lcore() for every lcore. The return values are
82  * ignored.
83  */
84 void
85 rte_eal_mp_wait_lcore(void)
86 {
87         unsigned lcore_id;
88
89         RTE_LCORE_FOREACH_WORKER(lcore_id) {
90                 rte_eal_wait_lcore(lcore_id);
91         }
92 }