zoukankan      html  css  js  c++  java
  • dpdk eal_get_virtual_area + rte_config.mem_config

    static int
    rte_eal_config_create(void)
    {
            size_t page_sz = sysconf(_SC_PAGE_SIZE);
            size_t cfg_len = sizeof(*rte_config.mem_config);
            size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz);
            void *rte_mem_cfg_addr, *mapped_mem_cfg_addr;
            int retval;
    
            const char *pathname = eal_runtime_config_path();
    
            if (internal_config.no_shconf)
                    return 0;
    
            /* map the config before base address so that we don't waste a page */
            if (internal_config.base_virtaddr != 0)
                    rte_mem_cfg_addr = (void *)
                            RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
                            sizeof(struct rte_mem_config), page_sz);
            else
                    rte_mem_cfg_addr = NULL;
    
            if (mem_cfg_fd < 0){
                    mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
                    if (mem_cfg_fd < 0) {
                            RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config
    ",
                                    pathname);
                            return -1;
                    }
            }
    retval = ftruncate(mem_cfg_fd, cfg_len);
            if (retval < 0){
                    close(mem_cfg_fd);
                    mem_cfg_fd = -1;
                    RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config
    ",
                            pathname);
                    return -1;
            }
    
            retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
            if (retval < 0){
                    close(mem_cfg_fd);
                    mem_cfg_fd = -1;
                    RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary "
                            "process running?
    ", pathname);
                    return -1;
            }
    
            /* reserve space for config */
            rte_mem_cfg_addr = eal_get_virtual_area(rte_mem_cfg_addr,
                            &cfg_len_aligned, page_sz, 0, 0);
            if (rte_mem_cfg_addr == NULL) {
                    RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config
    ");
                    close(mem_cfg_fd);
                    mem_cfg_fd = -1;
                    return -1;
            }
    
            /* remap the actual file into the space we've just reserved */
            mapped_mem_cfg_addr = mmap(rte_mem_cfg_addr,
                            cfg_len_aligned, PROT_READ | PROT_WRITE,
                    MAP_SHARED | MAP_FIXED, mem_cfg_fd, 0);
            if (mapped_mem_cfg_addr == MAP_FAILED) {
                    RTE_LOG(ERR, EAL, "Cannot remap memory for rte_config
    ");
                    munmap(rte_mem_cfg_addr, cfg_len);
                    close(mem_cfg_fd);
                    mem_cfg_fd = -1;
                    return -1;
            }
    
            memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
            rte_config.mem_config = rte_mem_cfg_addr;
    
            /* store address of the config in the config itself so that secondary
             * processes could later map the config into this exact location
             */
            rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
    
            return 0;
    }
  • 相关阅读:
    苏州大学2017年复试试题
    四川大学2019年复试试题
    四川大学2009年复试试题
    华东师范大学2019年复试试题
    华东师范大学2018年复试试题
    华东师范大学2017年复试试题
    华东师范大学2016年复试试题
    中国科学院大学2020年高等代数考研试题
    中国科学院大学2020年数学分析考研试题
    中国科学技术大学2020年高等代数考研试题
  • 原文地址:https://www.cnblogs.com/dream397/p/13590951.html
Copyright © 2011-2022 走看看