eal: unify wait for complete init
[dpdk.git] / lib / librte_eal / common / eal_common_mcfg.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <rte_config.h>
6 #include <rte_eal_memconfig.h>
7
8 #include "eal_internal_cfg.h"
9 #include "eal_memcfg.h"
10
11 void
12 eal_mcfg_complete(void)
13 {
14         struct rte_config *cfg = rte_eal_get_configuration();
15         struct rte_mem_config *mcfg = cfg->mem_config;
16
17         /* ALL shared mem_config related INIT DONE */
18         if (cfg->process_type == RTE_PROC_PRIMARY)
19                 mcfg->magic = RTE_MAGIC;
20
21         internal_config.init_complete = 1;
22 }
23
24 void
25 eal_mcfg_wait_complete(void)
26 {
27         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
28
29         /* wait until shared mem_config finish initialising */
30         while (mcfg->magic != RTE_MAGIC)
31                 rte_pause();
32 }
33
34 void
35 rte_mcfg_mem_read_lock(void)
36 {
37         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
38         rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
39 }
40
41 void
42 rte_mcfg_mem_read_unlock(void)
43 {
44         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
45         rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
46 }
47
48 void
49 rte_mcfg_mem_write_lock(void)
50 {
51         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
52         rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
53 }
54
55 void
56 rte_mcfg_mem_write_unlock(void)
57 {
58         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
59         rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
60 }
61
62 void
63 rte_mcfg_tailq_read_lock(void)
64 {
65         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
66         rte_rwlock_read_lock(&mcfg->qlock);
67 }
68
69 void
70 rte_mcfg_tailq_read_unlock(void)
71 {
72         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
73         rte_rwlock_read_unlock(&mcfg->qlock);
74 }
75
76 void
77 rte_mcfg_tailq_write_lock(void)
78 {
79         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
80         rte_rwlock_write_lock(&mcfg->qlock);
81 }
82
83 void
84 rte_mcfg_tailq_write_unlock(void)
85 {
86         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
87         rte_rwlock_write_unlock(&mcfg->qlock);
88 }
89
90 void
91 rte_mcfg_mempool_read_lock(void)
92 {
93         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
94         rte_rwlock_read_lock(&mcfg->mplock);
95 }
96
97 void
98 rte_mcfg_mempool_read_unlock(void)
99 {
100         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
101         rte_rwlock_read_unlock(&mcfg->mplock);
102 }
103
104 void
105 rte_mcfg_mempool_write_lock(void)
106 {
107         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
108         rte_rwlock_write_lock(&mcfg->mplock);
109 }
110
111 void
112 rte_mcfg_mempool_write_unlock(void)
113 {
114         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
115         rte_rwlock_write_unlock(&mcfg->mplock);
116 }