| 892 | }; |
| 893 | |
| 894 | static int |
| 895 | create_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, struct extmem_param *param, |
| 896 | bool huge) |
| 897 | { |
| 898 | uint64_t pgsizes[] = {RTE_PGSIZE_2M, RTE_PGSIZE_1G, /* x86_64, ARM */ |
| 899 | RTE_PGSIZE_16M, RTE_PGSIZE_16G}; /* POWER */ |
| 900 | unsigned int cur_page, n_pages, pgsz_idx; |
| 901 | size_t mem_sz, cur_pgsz; |
| 902 | rte_iova_t *iovas = NULL; |
| 903 | void *addr; |
| 904 | int ret; |
| 905 | |
| 906 | for (pgsz_idx = 0; pgsz_idx < RTE_DIM(pgsizes); pgsz_idx++) { |
| 907 | /* skip anything that is too big */ |
| 908 | if (pgsizes[pgsz_idx] > SIZE_MAX) |
| 909 | continue; |
| 910 | |
| 911 | cur_pgsz = pgsizes[pgsz_idx]; |
| 912 | |
| 913 | /* if we were told not to allocate hugepages, override */ |
| 914 | if (!huge) |
| 915 | cur_pgsz = sysconf(_SC_PAGESIZE); |
| 916 | |
| 917 | ret = calc_mem_size(nb_mbufs, mbuf_sz, cur_pgsz, &mem_sz); |
| 918 | if (ret < 0) { |
| 919 | TESTPMD_LOG(ERR, "Cannot calculate memory size\n"); |
| 920 | return -1; |
| 921 | } |
| 922 | |
| 923 | /* allocate our memory */ |
| 924 | addr = alloc_mem(mem_sz, cur_pgsz, huge); |
| 925 | |
| 926 | /* if we couldn't allocate memory with a specified page size, |
| 927 | * that doesn't mean we can't do it with other page sizes, so |
| 928 | * try another one. |
| 929 | */ |
| 930 | if (addr == NULL) |
| 931 | continue; |
| 932 | |
| 933 | /* store IOVA addresses for every page in this memory area */ |
| 934 | n_pages = mem_sz / cur_pgsz; |
| 935 | |
| 936 | iovas = malloc(sizeof(*iovas) * n_pages); |
| 937 | |
| 938 | if (iovas == NULL) { |
| 939 | TESTPMD_LOG(ERR, "Cannot allocate memory for iova addresses\n"); |
| 940 | goto fail; |
| 941 | } |
| 942 | /* lock memory if it's not huge pages */ |
| 943 | if (!huge) |
| 944 | mlock(addr, mem_sz); |
| 945 | |
| 946 | /* populate IOVA addresses */ |
| 947 | for (cur_page = 0; cur_page < n_pages; cur_page++) { |
| 948 | rte_iova_t iova; |
| 949 | size_t offset; |
| 950 | void *cur; |
| 951 |
no test coverage detected