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