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 rte_wait_until_equal_32(&mcfg->magic, RTE_MAGIC, __ATOMIC_RELAXED); 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 struct internal_config *internal_conf = 53 eal_get_internal_configuration(); 54 55 internal_conf->legacy_mem = mcfg->legacy_mem; 56 internal_conf->single_file_segments = mcfg->single_file_segments; 57 } 58 59 void 60 eal_mcfg_update_from_internal(void) 61 { 62 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 63 const struct internal_config *internal_conf = 64 eal_get_internal_configuration(); 65 66 mcfg->legacy_mem = internal_conf->legacy_mem; 67 mcfg->single_file_segments = internal_conf->single_file_segments; 68 /* record current DPDK version */ 69 mcfg->version = RTE_VERSION; 70 } 71 72 void 73 rte_mcfg_mem_read_lock(void) 74 { 75 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 76 rte_rwlock_read_lock(&mcfg->memory_hotplug_lock); 77 } 78 79 void 80 rte_mcfg_mem_read_unlock(void) 81 { 82 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 83 rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock); 84 } 85 86 void 87 rte_mcfg_mem_write_lock(void) 88 { 89 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 90 rte_rwlock_write_lock(&mcfg->memory_hotplug_lock); 91 } 92 93 void 94 rte_mcfg_mem_write_unlock(void) 95 { 96 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 97 rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock); 98 } 99 100 void 101 rte_mcfg_tailq_read_lock(void) 102 { 103 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 104 rte_rwlock_read_lock(&mcfg->qlock); 105 } 106 107 void 108 rte_mcfg_tailq_read_unlock(void) 109 { 110 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 111 rte_rwlock_read_unlock(&mcfg->qlock); 112 } 113 114 void 115 rte_mcfg_tailq_write_lock(void) 116 { 117 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 118 rte_rwlock_write_lock(&mcfg->qlock); 119 } 120 121 void 122 rte_mcfg_tailq_write_unlock(void) 123 { 124 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 125 rte_rwlock_write_unlock(&mcfg->qlock); 126 } 127 128 void 129 rte_mcfg_mempool_read_lock(void) 130 { 131 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 132 rte_rwlock_read_lock(&mcfg->mplock); 133 } 134 135 void 136 rte_mcfg_mempool_read_unlock(void) 137 { 138 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 139 rte_rwlock_read_unlock(&mcfg->mplock); 140 } 141 142 void 143 rte_mcfg_mempool_write_lock(void) 144 { 145 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 146 rte_rwlock_write_lock(&mcfg->mplock); 147 } 148 149 void 150 rte_mcfg_mempool_write_unlock(void) 151 { 152 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 153 rte_rwlock_write_unlock(&mcfg->mplock); 154 } 155 156 void 157 rte_mcfg_timer_lock(void) 158 { 159 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 160 rte_spinlock_lock(&mcfg->tlock); 161 } 162 163 void 164 rte_mcfg_timer_unlock(void) 165 { 166 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 167 rte_spinlock_unlock(&mcfg->tlock); 168 } 169 170 bool 171 rte_mcfg_get_single_file_segments(void) 172 { 173 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; 174 return (bool)mcfg->single_file_segments; 175 } 176