| 206 | } |
| 207 | |
| 208 | void * |
| 209 | mlx5_realloc(void *addr, uint32_t flags, size_t size, unsigned int align, |
| 210 | int socket) |
| 211 | { |
| 212 | void *new_addr; |
| 213 | bool rte_mem; |
| 214 | |
| 215 | /* Allocate directly if old memory address is NULL. */ |
| 216 | if (!addr) |
| 217 | return mlx5_malloc(flags, size, align, socket); |
| 218 | /* Get the memory type. */ |
| 219 | if (flags & MLX5_MEM_RTE) |
| 220 | rte_mem = true; |
| 221 | else if (flags & MLX5_MEM_SYS) |
| 222 | rte_mem = false; |
| 223 | else |
| 224 | rte_mem = mlx5_sys_mem.enable ? false : true; |
| 225 | /* Check if old memory and to be allocated memory are the same type. */ |
| 226 | if (rte_mem != mlx5_mem_is_rte(addr)) { |
| 227 | DRV_LOG(ERR, "Couldn't reallocate to different memory type."); |
| 228 | return NULL; |
| 229 | } |
| 230 | /* Allocate memory from rte memory. */ |
| 231 | if (rte_mem) { |
| 232 | new_addr = rte_realloc_socket(addr, size, align, socket); |
| 233 | mlx5_mem_update_msl(new_addr); |
| 234 | #ifdef RTE_LIBRTE_MLX5_DEBUG |
| 235 | if (new_addr) |
| 236 | __atomic_fetch_add(&mlx5_sys_mem.realloc_rte, 1, |
| 237 | __ATOMIC_RELAXED); |
| 238 | #endif |
| 239 | return new_addr; |
| 240 | } |
| 241 | /* Align is not supported for system memory. */ |
| 242 | if (align) { |
| 243 | DRV_LOG(ERR, "Couldn't reallocate with alignment"); |
| 244 | return NULL; |
| 245 | } |
| 246 | new_addr = realloc(addr, size); |
| 247 | #ifdef RTE_LIBRTE_MLX5_DEBUG |
| 248 | if (new_addr) |
| 249 | __atomic_fetch_add(&mlx5_sys_mem.realloc_sys, 1, |
| 250 | __ATOMIC_RELAXED); |
| 251 | #endif |
| 252 | return new_addr; |
| 253 | } |
| 254 | |
| 255 | void |
| 256 | mlx5_free(void *addr) |
no test coverage detected