| 266 | } |
| 267 | |
| 268 | static int |
| 269 | test_multi_alloc_statistics(void) |
| 270 | { |
| 271 | int ret = -1; /* default return is error, cleared at end on success */ |
| 272 | int socket = 0; |
| 273 | struct rte_malloc_socket_stats pre_stats, post_stats ,first_stats, second_stats; |
| 274 | size_t size = 2048; |
| 275 | int align = 1024; |
| 276 | int overhead = 0; |
| 277 | const size_t pgsz = rte_mem_page_size(); |
| 278 | const size_t heap_size = (1 << 22); |
| 279 | |
| 280 | if (pgsz > heap_size) { |
| 281 | printf("Page size (%zu) is bigger than heap size, skipping alloc stats test\n", |
| 282 | pgsz); |
| 283 | return TEST_SKIPPED; |
| 284 | } |
| 285 | if (heap_size % pgsz != 0) { |
| 286 | printf("Heap size (%zu) is not a multiple of page size (%zu), skipping alloc stats test\n", |
| 287 | heap_size, pgsz); |
| 288 | return TEST_SKIPPED; |
| 289 | } |
| 290 | |
| 291 | if (rte_malloc_heap_create(__func__) != 0) { |
| 292 | printf("Failed to create test malloc heap\n"); |
| 293 | goto end; |
| 294 | } |
| 295 | |
| 296 | /* Allocate some memory using malloc and add it to our test heap. */ |
| 297 | void *unaligned_memory = malloc(heap_size + pgsz); |
| 298 | if (unaligned_memory == NULL) { |
| 299 | printf("Failed to allocate memory\n"); |
| 300 | goto cleanup_empty_heap; |
| 301 | } |
| 302 | void *memory = RTE_PTR_ALIGN(unaligned_memory, pgsz); |
| 303 | if (rte_malloc_heap_memory_add(__func__, memory, heap_size, NULL, |
| 304 | heap_size / pgsz, pgsz) != 0) { |
| 305 | printf("Failed to add memory to heap\n"); |
| 306 | goto cleanup_allocated_memory; |
| 307 | } |
| 308 | socket = rte_malloc_heap_get_socket(__func__); |
| 309 | if (socket < 0) { |
| 310 | printf("Failed to get socket for test malloc heap.\n"); |
| 311 | goto cleanup_all; |
| 312 | } |
| 313 | |
| 314 | /* Dynamically calculate the overhead by allocating one cacheline and |
| 315 | * then comparing what was allocated from the heap. |
| 316 | */ |
| 317 | rte_malloc_get_socket_stats(socket, &pre_stats); |
| 318 | |
| 319 | void *dummy = rte_malloc_socket(NULL, RTE_CACHE_LINE_SIZE, 0, socket); |
| 320 | if (dummy == NULL) |
| 321 | goto cleanup_all; |
| 322 | |
| 323 | rte_malloc_get_socket_stats(socket, &post_stats); |
| 324 | |
| 325 | /* after subtracting cache line, remainder is overhead */ |
no test coverage detected