src/dpdk/lib/librte_eal/freebsd/eal.c
static int
rte_eal_config_create(void)
{
	struct rte_config *config = rte_eal_get_configuration();
	const struct internal_config *internal_conf =
		eal_get_internal_configuration();
	size_t page_sz = sysconf(_SC_PAGE_SIZE);
	size_t cfg_len = sizeof(struct rte_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_conf->no_shconf)
		return 0;

	/* map the config before base address so that we don't waste a page */
	if (internal_conf->base_virtaddr != 0)
		rte_mem_cfg_addr = (void *)
			RTE_ALIGN_FLOOR(internal_conf->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\n",
				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\n",
			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?\n", 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\n");
		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\n");
		munmap(rte_mem_cfg_addr, cfg_len);
		close(mem_cfg_fd);
		mem_cfg_fd = -1;
		return -1;
	}

	memcpy(rte_mem_cfg_addr, config->mem_config, sizeof(struct rte_mem_config));
	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
	 */
	config->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
	return 0;
}
/* create memory configuration in shared/mmap memory. Take out
 * a write lock on the memsegs, so we can auto-detect primary/secondary.
 * This means we never close the file while running (auto-close on exit).
 * We also don't lock the whole file, so that in future we can use read-locks
 * on other parts, e.g. memzones, to detect if there are running secondary
 * processes. */
create memory configuration in shared/mmap memory. Take out
a write lock on the memsegs, so we can auto-detect primary/secondary.
This means we never close the file while running (auto-close on exit).
We also don't lock the whole file, so that in future we can use read-locks
on other parts, e.g. memzones, to detect if there are running secondary
processes.
create memory configuration in shared / mmap memory . Take out a write lock on the memsegs so we can auto - detect primary / secondary . This means we never close the file while running ( auto - close on exit ) . We also don ' t lock the whole file so that in future we can use read - locks on other parts e . g . memzones to detect if there are running secondary processes .
static int
rte_eal_config_create(void)
{
	struct rte_config *config = rte_eal_get_configuration();
	const struct internal_config *internal_conf =
		eal_get_internal_configuration();
	size_t page_sz = sysconf(_SC_PAGE_SIZE);
	size_t cfg_len = sizeof(struct rte_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_conf->no_shconf)
		return 0;
	if (internal_conf->base_virtaddr != 0)
		rte_mem_cfg_addr = (void *)
			RTE_ALIGN_FLOOR(internal_conf->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\n",
				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\n",
			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?\n", pathname);
		return -1;
	}
	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\n");
		close(mem_cfg_fd);
		mem_cfg_fd = -1;
		return -1;
	}
	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\n");
		munmap(rte_mem_cfg_addr, cfg_len);
		close(mem_cfg_fd);
		mem_cfg_fd = -1;
		return -1;
	}
	memcpy(rte_mem_cfg_addr, config->mem_config, sizeof(struct rte_mem_config));
	config->mem_config = rte_mem_cfg_addr;
	config->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
	return 0;
}
static int rte_eal_config_create ( void ) { struct rte_config * config = rte_eal_get_configuration ( ) ; const struct internal_config * internal_conf = eal_get_internal_configuration ( ) ; size_t page_sz = sysconf ( _SC_PAGE_SIZE ) ; size_t cfg_len = sizeof ( struct rte_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_conf -> no_shconf ) return 0 ; if ( internal_conf -> base_virtaddr != 0 ) rte_mem_cfg_addr = ( void * ) RTE_ALIGN_FLOOR ( internal_conf -> 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 , " \n " , 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 , " \n " , 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 , " " " \n " , pathname ) ; return -1 ; } 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 , " \n " ) ; close ( mem_cfg_fd ) ; mem_cfg_fd = -1 ; return -1 ; } 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 , " \n " ) ; munmap ( rte_mem_cfg_addr , cfg_len ) ; close ( mem_cfg_fd ) ; mem_cfg_fd = -1 ; return -1 ; } memcpy ( rte_mem_cfg_addr , config -> mem_config , sizeof ( struct rte_mem_config ) ) ; config -> mem_config = rte_mem_cfg_addr ; config -> mem_config -> mem_cfg_addr = ( uintptr_t ) rte_mem_cfg_addr ; return 0 ; }
create memory configuration in shared/mmap memory.
create memory configuration in shared / mmap memory .
/* map the config before base address so that we don't waste a page */ /* reserve space for config */ /* remap the actual file into the space we've just reserved */ /* store address of the config in the config itself so that secondary
	 * processes could later map the config into this exact location
	 */