MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ff_mmap_init

Function ff_mmap_init

lib/ff_memory.c:228–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228int ff_mmap_init()
229{
230 int err = 0;
231 int i = 0;
232 uint64_t virt_addr = (uint64_t)NULL;
233 phys_addr_t phys_addr = 0;
234 uint64_t bsd_memsz = (ff_global_cfg.freebsd.mem_size << 20);
235 unsigned int bsd_pagesz = 0;
236
237 ff_page_start = (uint64_t)mmap( NULL, bsd_memsz, PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0);
238 if (ff_page_start == (uint64_t)-1){
239 rte_panic("ff_mmap_init get ff_page_start failed, err=%d.\n", errno);
240 return -1;
241 }
242
243 if ( mlock((void*)ff_page_start, bsd_memsz)<0 ) {
244 rte_panic("mlock failed, err=%d.\n", errno);
245 return -1;
246 }
247 ff_page_end = ff_page_start + bsd_memsz;
248 bsd_pagesz = (bsd_memsz>>12);
249 rte_log(RTE_LOG_INFO, RTE_LOGTYPE_USER1, "ff_mmap_init mmap %d pages, %d MB.\n", bsd_pagesz, ff_global_cfg.freebsd.mem_size);
250 printf("ff_mmap_init mem[0x%lx:0x%lx]\n", ff_page_start, ff_page_end);
251
252 if (posix_memalign((void**)&ff_mpage_phy, sizeof(phys_addr_t), bsd_pagesz*sizeof(phys_addr_t))!=0){
253 rte_panic("posix_memalign get ff_mpage_phy failed, err=%d.\n", errno);
254 return -1;
255 }
256
257 stklist_init(&ff_mpage_ctl, bsd_pagesz);
258
259 for (i=0; (unsigned)i<bsd_pagesz; i++ ){
260 virt_addr = ff_page_start + PAGE_SIZE*i;
261 memset((void*)virt_addr, 0, PAGE_SIZE);
262
263 stklist_push( &ff_mpage_ctl, virt_addr);
264 ff_mpage_phy[i] = rte_mem_virt2phy((const void*)virt_addr);
265 if ( ff_mpage_phy[i] == RTE_BAD_IOVA ){
266 rte_panic("rte_mem_virt2phy return invalid address.");
267 return -1;
268 }
269 }
270
271 ff_txring_init(&nic_tx_ring[0], RTE_MAX_ETHPORTS);
272
273 return 0;
274}
275
276// 1: vma in fstack page table; 0: vma not in fstack pages, in DPDK pool.
277static inline int ff_chk_vma(const uint64_t virtaddr)

Callers 1

ff_dpdk_initFunction · 0.85

Calls 7

rte_logFunction · 0.85
stklist_initFunction · 0.85
memsetFunction · 0.85
stklist_pushFunction · 0.85
ff_txring_initFunction · 0.85
printfFunction · 0.70
rte_mem_virt2phyFunction · 0.50

Tested by

no test coverage detected