eal: unify internal config 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 eal_mcfg_update_internal(void)
36 {
37         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
38
39         internal_config.legacy_mem = mcfg->legacy_mem;
40         internal_config.single_file_segments = mcfg->single_file_segments;
41 }
42
43 void
44 eal_mcfg_update_from_internal(void)
45 {
46         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
47
48         mcfg->legacy_mem = internal_config.legacy_mem;
49         mcfg->single_file_segments = internal_config.single_file_segments;
50 }
51
52 void
53 rte_mcfg_mem_read_lock(void)
54 {
55         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
56         rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
57 }
58
59 void
60 rte_mcfg_mem_read_unlock(void)
61 {
62         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
63         rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
64 }
65
66 void
67 rte_mcfg_mem_write_lock(void)
68 {
69         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
70         rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
71 }
72
73 void
74 rte_mcfg_mem_write_unlock(void)
75 {
76         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
77         rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
78 }
79
80 void
81 rte_mcfg_tailq_read_lock(void)
82 {
83         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
84         rte_rwlock_read_lock(&mcfg->qlock);
85 }
86
87 void
88 rte_mcfg_tailq_read_unlock(void)
89 {
90         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
91         rte_rwlock_read_unlock(&mcfg->qlock);
92 }
93
94 void
95 rte_mcfg_tailq_write_lock(void)
96 {
97         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
98         rte_rwlock_write_lock(&mcfg->qlock);
99 }
100
101 void
102 rte_mcfg_tailq_write_unlock(void)
103 {
104         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
105         rte_rwlock_write_unlock(&mcfg->qlock);
106 }
107
108 void
109 rte_mcfg_mempool_read_lock(void)
110 {
111         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
112         rte_rwlock_read_lock(&mcfg->mplock);
113 }
114
115 void
116 rte_mcfg_mempool_read_unlock(void)
117 {
118         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
119         rte_rwlock_read_unlock(&mcfg->mplock);
120 }
121
122 void
123 rte_mcfg_mempool_write_lock(void)
124 {
125         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
126         rte_rwlock_write_lock(&mcfg->mplock);
127 }
128
129 void
130 rte_mcfg_mempool_write_unlock(void)
131 {
132         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
133         rte_rwlock_write_unlock(&mcfg->mplock);
134 }