eal: move OS common config objects
[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_eal_memconfig.h>
6 #include <rte_version.h>
7
8 #include "eal_internal_cfg.h"
9 #include "eal_memcfg.h"
10 #include "eal_private.h"
11
12 void
13 eal_mcfg_complete(void)
14 {
15         struct rte_config *cfg = rte_eal_get_configuration();
16         struct rte_mem_config *mcfg = cfg->mem_config;
17         struct internal_config *internal_conf =
18                 eal_get_internal_configuration();
19
20         /* ALL shared mem_config related INIT DONE */
21         if (cfg->process_type == RTE_PROC_PRIMARY)
22                 mcfg->magic = RTE_MAGIC;
23
24         internal_conf->init_complete = 1;
25 }
26
27 void
28 eal_mcfg_wait_complete(void)
29 {
30         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
31
32         /* wait until shared mem_config finish initialising */
33         while (mcfg->magic != RTE_MAGIC)
34                 rte_pause();
35 }
36
37 int
38 eal_mcfg_check_version(void)
39 {
40         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
41
42         /* check if version from memconfig matches compiled in macro */
43         if (mcfg->version != RTE_VERSION)
44                 return -1;
45
46         return 0;
47 }
48
49 void
50 eal_mcfg_update_internal(void)
51 {
52         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
53         struct internal_config *internal_conf =
54                 eal_get_internal_configuration();
55
56         internal_conf->legacy_mem = mcfg->legacy_mem;
57         internal_conf->single_file_segments = mcfg->single_file_segments;
58 }
59
60 void
61 eal_mcfg_update_from_internal(void)
62 {
63         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
64         const struct internal_config *internal_conf =
65                 eal_get_internal_configuration();
66
67         mcfg->legacy_mem = internal_conf->legacy_mem;
68         mcfg->single_file_segments = internal_conf->single_file_segments;
69         /* record current DPDK version */
70         mcfg->version = RTE_VERSION;
71 }
72
73 void
74 rte_mcfg_mem_read_lock(void)
75 {
76         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
77         rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
78 }
79
80 void
81 rte_mcfg_mem_read_unlock(void)
82 {
83         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
84         rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
85 }
86
87 void
88 rte_mcfg_mem_write_lock(void)
89 {
90         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
91         rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
92 }
93
94 void
95 rte_mcfg_mem_write_unlock(void)
96 {
97         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
98         rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
99 }
100
101 void
102 rte_mcfg_tailq_read_lock(void)
103 {
104         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
105         rte_rwlock_read_lock(&mcfg->qlock);
106 }
107
108 void
109 rte_mcfg_tailq_read_unlock(void)
110 {
111         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
112         rte_rwlock_read_unlock(&mcfg->qlock);
113 }
114
115 void
116 rte_mcfg_tailq_write_lock(void)
117 {
118         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
119         rte_rwlock_write_lock(&mcfg->qlock);
120 }
121
122 void
123 rte_mcfg_tailq_write_unlock(void)
124 {
125         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
126         rte_rwlock_write_unlock(&mcfg->qlock);
127 }
128
129 void
130 rte_mcfg_mempool_read_lock(void)
131 {
132         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
133         rte_rwlock_read_lock(&mcfg->mplock);
134 }
135
136 void
137 rte_mcfg_mempool_read_unlock(void)
138 {
139         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
140         rte_rwlock_read_unlock(&mcfg->mplock);
141 }
142
143 void
144 rte_mcfg_mempool_write_lock(void)
145 {
146         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
147         rte_rwlock_write_lock(&mcfg->mplock);
148 }
149
150 void
151 rte_mcfg_mempool_write_unlock(void)
152 {
153         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
154         rte_rwlock_write_unlock(&mcfg->mplock);
155 }
156
157 void
158 rte_mcfg_timer_lock(void)
159 {
160         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
161         rte_spinlock_lock(&mcfg->tlock);
162 }
163
164 void
165 rte_mcfg_timer_unlock(void)
166 {
167         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
168         rte_spinlock_unlock(&mcfg->tlock);
169 }
170
171 bool
172 rte_mcfg_get_single_file_segments(void)
173 {
174         struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
175         return (bool)mcfg->single_file_segments;
176 }