New upstream version 18.02
[deb_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 /*
19  * Wait until a lcore finished its job.
20  */
21 int
22 rte_eal_wait_lcore(unsigned slave_id)
23 {
24         if (lcore_config[slave_id].state == WAIT)
25                 return 0;
26
27         while (lcore_config[slave_id].state != WAIT &&
28                lcore_config[slave_id].state != FINISHED)
29                 rte_pause();
30
31         rte_rmb();
32
33         /* we are in finished state, go to wait state */
34         lcore_config[slave_id].state = WAIT;
35         return lcore_config[slave_id].ret;
36 }
37
38 /*
39  * Check that every SLAVE lcores are in WAIT state, then call
40  * rte_eal_remote_launch() for all of them. If call_master is true
41  * (set to CALL_MASTER), also call the function on the master lcore.
42  */
43 int
44 rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
45                          enum rte_rmt_call_master_t call_master)
46 {
47         int lcore_id;
48         int master = rte_get_master_lcore();
49
50         /* check state of lcores */
51         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
52                 if (lcore_config[lcore_id].state != WAIT)
53                         return -EBUSY;
54         }
55
56         /* send messages to cores */
57         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
58                 rte_eal_remote_launch(f, arg, lcore_id);
59         }
60
61         if (call_master == CALL_MASTER) {
62                 lcore_config[master].ret = f(arg);
63                 lcore_config[master].state = FINISHED;
64         }
65
66         return 0;
67 }
68
69 /*
70  * Return the state of the lcore identified by slave_id.
71  */
72 enum rte_lcore_state_t
73 rte_eal_get_lcore_state(unsigned lcore_id)
74 {
75         return lcore_config[lcore_id].state;
76 }
77
78 /*
79  * Do a rte_eal_wait_lcore() for every lcore. The return values are
80  * ignored.
81  */
82 void
83 rte_eal_mp_wait_lcore(void)
84 {
85         unsigned lcore_id;
86
87         RTE_LCORE_FOREACH_SLAVE(lcore_id) {
88                 rte_eal_wait_lcore(lcore_id);
89         }
90 }