Beispiel #1
0
static int
test_ivshmem_create_lots_of_memzones(void)
{
	int i;
	char name[IVSHMEM_NAME_LEN];
	const struct rte_memzone *mz;

	ASSERT(rte_ivshmem_metadata_create(METADATA_NAME) == 0,
			"Failed to create metadata");

	for (i = 0; i < RTE_LIBRTE_IVSHMEM_MAX_ENTRIES; i++) {
		snprintf(name, sizeof(name), "mz_%i", i);

		mz = rte_memzone_reserve(name, CACHE_LINE_SIZE, SOCKET_ID_ANY, 0);
		ASSERT(mz != NULL, "Failed to reserve memzone");

		ASSERT(rte_ivshmem_metadata_add_memzone(mz, METADATA_NAME) == 0,
				"Failed to add memzone");
	}
	mz = rte_memzone_reserve("one too many", CACHE_LINE_SIZE, SOCKET_ID_ANY, 0);
	ASSERT(mz != NULL, "Failed to reserve memzone");

	ASSERT(rte_ivshmem_metadata_add_memzone(mz, METADATA_NAME) < 0,
		"Metadata should have been full");

	return 0;
}
Beispiel #2
0
static int
test_ivshmem_create_too_many_metadata_configs(void)
{
	int i;
	char name[IVSHMEM_NAME_LEN];

	for (i = 0; i < RTE_LIBRTE_IVSHMEM_MAX_METADATA_FILES; i++) {
		snprintf(name, sizeof(name), "test_%d", i);
		ASSERT(rte_ivshmem_metadata_create(name) == 0,
				"Create config file failed");
	}

	ASSERT(rte_ivshmem_metadata_create(name) < 0,
			"Create config file didn't fail");

	return 0;
}
Beispiel #3
0
static int
test_ivshmem_create_duplicate_metadata(void)
{
	ASSERT(rte_ivshmem_metadata_create(DUPLICATE_METADATA) < 0,
			"Creating duplicate metadata should have failed");

	return 0;
}
Beispiel #4
0
static int
create_duplicate(void)
{
	/* create a metadata that another process will then try to overwrite */
	ASSERT (rte_ivshmem_metadata_create(DUPLICATE_METADATA) == 0,
			"Creating metadata failed");
	return 0;
}
Beispiel #5
0
/**
 * Main init function for the multi-process server app,
 * calls subfunctions to do each stage of the initialisation.
 */
int
init(int argc, char *argv[])
{
	int retval;
	uint8_t i, total_ports;

	/* init EAL, parsing EAL args */
	retval = rte_eal_init(argc, argv);
	if (retval < 0)
		return -1;
	argc -= retval;
	argv += retval;
	
	/* get total number of ports */
	total_ports = 0;

	/* parse additional, application arguments */
	retval = parse_app_args(total_ports, argc, argv);
	if (retval != 0)
		return -1;

	/* initialise mbuf pools */
	retval = init_mbuf_pools();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

	
	init_shm_rings();
	
	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
	{
		/* create metadata, output cmdline */
		if (rte_ivshmem_metadata_create(IVSHMEN_METADATA_NAME) < 0)
			rte_exit(EXIT_FAILURE, "Cannot create IVSHMEM metadata\n");	
		if (rte_ivshmem_metadata_add_mempool(pktmbuf_pool, IVSHMEN_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to IVSHMEM metadata\n");				
		
		for (i = 0; i < num_rings; i++) 
		{
			if (rte_ivshmem_metadata_add_ring(clients[i].rx_q,
					IVSHMEN_METADATA_NAME) < 0)
				rte_exit(EXIT_FAILURE, "Cannot add ring client %d to IVSHMEM metadata\n", i);
		}
		generate_ivshmem_cmdline(IVSHMEN_METADATA_NAME);
	}
	
	
	return 0;
}
Beispiel #6
0
static int
test_ivshmem_create_duplicate_memzone(void)
{
	const struct rte_memzone *mz;

	ASSERT(rte_ivshmem_metadata_create(METADATA_NAME) == 0,
			"Failed to create metadata");

	mz = rte_memzone_reserve("mz", CACHE_LINE_SIZE, SOCKET_ID_ANY, 0);
	ASSERT(mz != NULL, "Failed to reserve memzone");

	ASSERT(rte_ivshmem_metadata_add_memzone(mz, METADATA_NAME) == 0,
			"Failed to add memzone");

	ASSERT(rte_ivshmem_metadata_add_memzone(mz, METADATA_NAME) < 0,
			"Added the same memzone twice");

	return 0;
}
Beispiel #7
0
static int
test_ivshmem_create_multiple_metadata_configs(void)
{
	int i;
	char name[IVSHMEM_NAME_LEN];
	struct rte_ivshmem_metadata *metadata;

	for (i = 0; i < RTE_LIBRTE_IVSHMEM_MAX_METADATA_FILES / 2; i++) {
		snprintf(name, sizeof(name), "test_%d", i);
		rte_ivshmem_metadata_create(name);
		metadata = mmap_metadata(name);

		ASSERT(metadata->magic_number == IVSHMEM_MAGIC,
				"Magic number is not that magic");

		ASSERT(strncmp(metadata->name, name, sizeof(metadata->name)) == 0,
				"Name has not been set up");
	}

	return 0;
}
Beispiel #8
0
static int
test_ivshmem_create_metadata_config(void)
{
	struct rte_ivshmem_metadata *metadata;

	rte_ivshmem_metadata_create(METADATA_NAME);

	metadata = mmap_metadata(METADATA_NAME);

	ASSERT(metadata != MAP_FAILED, "Metadata mmaping failed");

	ASSERT(metadata->magic_number == IVSHMEM_MAGIC,
			"Magic number is not that magic");

	ASSERT(strncmp(metadata->name, METADATA_NAME, sizeof(metadata->name)) == 0,
			"Name has not been set up");

	ASSERT(metadata->entry[0].offset == 0, "Offest is not initialized");
	ASSERT(metadata->entry[0].mz.addr == 0, "mz.addr is not initialized");
	ASSERT(metadata->entry[0].mz.len == 0, "mz.len is not initialized");

	return 0;
}
Beispiel #9
0
/**
 * Main init function for the multi-process server app,
 * calls subfunctions to do each stage of the initialisation.
 */
int
init(int argc, char *argv[])
{
	int retval;
	const struct rte_memzone *mz;
	unsigned i, total_ports;

	/* init EAL, parsing EAL args */
	retval = rte_eal_init(argc, argv);
	if (retval < 0)
		return -1;
	argc -= retval;
	argv += retval;

	/* get total number of ports */
	total_ports = rte_eth_dev_count();

	/* set up array for port data */
	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
	{
		mz = rte_memzone_lookup(MZ_PORT_INFO);
		if (mz == NULL)
			rte_exit(EXIT_FAILURE, "Cannot get port info structure\n");
		ports = mz->addr;
	}
	else /* RTE_PROC_PRIMARY */
	{
		mz = rte_memzone_reserve(MZ_PORT_INFO, sizeof(*ports),
					rte_socket_id(), NO_FLAGS);
		if (mz == NULL)
			rte_exit(EXIT_FAILURE, "Cannot reserve memory zone for port information\n");
		memset(mz->addr, 0, sizeof(*ports));
		ports = mz->addr;
	}

	/* parse additional, application arguments */
	retval = parse_app_args(total_ports, argc, argv);
	if (retval != 0)
		return -1;

	/* initialise mbuf pools */
	retval = init_mbuf_pools();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot create needed mbuf pools\n");

	/* now initialise the ports we will use */	
	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
	{
		for (i = 0; i < ports->num_ports; i++) {
			retval = init_port(ports->id[i]);
			if (retval != 0)
				rte_exit(EXIT_FAILURE, "Cannot initialise port %u\n",
						(unsigned)i);
		}
	}
	check_all_ports_link_status(ports->num_ports, (~0x0));

	/* initialise the client queues/rings for inter-eu comms */
	
	init_shm_rings();
	
	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
	{
		RTE_LOG(INFO, APP, "HOST SHARE MEM Init.\n");
		/* create metadata, output cmdline 
		if (rte_hostshmem_metadata_create(HOSTSHMEM_METADATA_NAME) < 0)
			rte_exit(EXIT_FAILURE, "Cannot create HOSTSHMEM metadata\n");
		if (rte_hostshmem_metadata_add_memzone(mz, HOSTSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add memzone to HOSTSHMEM metadata\n");					
		if (rte_hostshmem_metadata_add_mempool(pktmbuf_pool, HOSTSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to HOSTSHMEM metadata\n");	
		for (i = 0; i < num_clients; i++) 
		{
			if (rte_hostshmem_metadata_add_ring(clients[i].rx_q,
					HOSTSHMEM_METADATA_NAME) < 0)
				rte_exit(EXIT_FAILURE, "Cannot add ring client %d to HOSTSHMEM metadata\n", i);
		}
		generate_hostshmem_cmdline(HOSTSHMEM_METADATA_NAME);
		*/
		
		const struct rte_mem_config *mcfg;
		/* get pointer to global configuration */
		mcfg = rte_eal_get_configuration()->mem_config;

		for (i = 0; i < RTE_MAX_MEMSEG; i++) {
			if (mcfg->memseg[i].addr == NULL)
				break;

			printf("Segment %u: phys:0x%"PRIx64", len:%zu, "
				   "virt:%p, socket_id:%"PRId32", "
				   "hugepage_sz:%"PRIu64", nchannel:%"PRIx32", "
				   "nrank:%"PRIx32"\n", i,
				   mcfg->memseg[i].phys_addr,
				   mcfg->memseg[i].len,
				   mcfg->memseg[i].addr,
				   mcfg->memseg[i].socket_id,
				   mcfg->memseg[i].hugepage_sz,
				   mcfg->memseg[i].nchannel,
				   mcfg->memseg[i].nrank);
		}
		
		RTE_LOG(INFO, APP, "HOST SHARE MEM Init. done\n");
		
		RTE_LOG(INFO, APP, "IV SHARE MEM Init.\n");
		/* create metadata, output cmdline */
		if (rte_ivshmem_metadata_create(IVSHMEM_METADATA_NAME) < 0)
			rte_exit(EXIT_FAILURE, "Cannot create IVSHMEM metadata\n");	
		if (rte_ivshmem_metadata_add_memzone(mz, IVSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add memzone to IVSHMEM metadata\n");					
		if (rte_ivshmem_metadata_add_mempool(pktmbuf_pool, IVSHMEM_METADATA_NAME))
			rte_exit(EXIT_FAILURE, "Cannot add mbuf mempool to IVSHMEM metadata\n");				
		
		for (i = 0; i < num_clients; i++) 
		{
			if (rte_ivshmem_metadata_add_ring(clients[i].rx_q,
					IVSHMEM_METADATA_NAME) < 0)
				rte_exit(EXIT_FAILURE, "Cannot add ring client %d to IVSHMEM metadata\n", i);
		}
		generate_ivshmem_cmdline(IVSHMEM_METADATA_NAME);
		RTE_LOG(INFO, APP, "IV SHARE MEM Done.\n");
	}
	
	
	return 0;
}
Beispiel #10
0
static int
test_ivshmem_api_test(void)
{
	const struct rte_memzone * mz;
	struct rte_mempool * mp;
	struct rte_ring * r;
	char buf[BUFSIZ];

	memset(buf, 0, sizeof(buf));

	r = rte_ring_create("ring", 1, SOCKET_ID_ANY, 0);
	mp = rte_mempool_create("mempool", 1, 1, 1, 1, NULL, NULL, NULL, NULL,
			SOCKET_ID_ANY, 0);
	mz = rte_memzone_reserve("memzone", 64, SOCKET_ID_ANY, 0);

	ASSERT(r != NULL, "Failed to create ring");
	ASSERT(mp != NULL, "Failed to create mempool");
	ASSERT(mz != NULL, "Failed to reserve memzone");

	/* try to create NULL metadata */
	ASSERT(rte_ivshmem_metadata_create(NULL) < 0,
			"Created metadata with NULL name");

	/* create valid metadata to do tests on */
	ASSERT(rte_ivshmem_metadata_create(METADATA_NAME) == 0,
			"Failed to create metadata");

	/* test adding memzone */
	ASSERT(rte_ivshmem_metadata_add_memzone(NULL, NULL) < 0,
			"Added NULL memzone to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_memzone(NULL, METADATA_NAME) < 0,
			"Added NULL memzone");
	ASSERT(rte_ivshmem_metadata_add_memzone(mz, NULL) < 0,
			"Added memzone to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_memzone(mz, NONEXISTENT_METADATA) < 0,
			"Added memzone to nonexistent metadata");

	/* test adding ring */
	ASSERT(rte_ivshmem_metadata_add_ring(NULL, NULL) < 0,
			"Added NULL ring to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_ring(NULL, METADATA_NAME) < 0,
			"Added NULL ring");
	ASSERT(rte_ivshmem_metadata_add_ring(r, NULL) < 0,
			"Added ring to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_ring(r, NONEXISTENT_METADATA) < 0,
			"Added ring to nonexistent metadata");

	/* test adding mempool */
	ASSERT(rte_ivshmem_metadata_add_mempool(NULL, NULL) < 0,
			"Added NULL mempool to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_mempool(NULL, METADATA_NAME) < 0,
			"Added NULL mempool");
	ASSERT(rte_ivshmem_metadata_add_mempool(mp, NULL) < 0,
			"Added mempool to NULL metadata");
	ASSERT(rte_ivshmem_metadata_add_mempool(mp, NONEXISTENT_METADATA) < 0,
			"Added mempool to nonexistent metadata");

	/* test creating command line */
	ASSERT(rte_ivshmem_metadata_cmdline_generate(NULL, sizeof(buf), METADATA_NAME) < 0,
			"Written command line into NULL buffer");
	ASSERT(strnlen(buf, sizeof(buf)) == 0, "Buffer is not empty");

	ASSERT(rte_ivshmem_metadata_cmdline_generate(buf, 0, METADATA_NAME) < 0,
			"Written command line into small buffer");
	ASSERT(strnlen(buf, sizeof(buf)) == 0, "Buffer is not empty");

	ASSERT(rte_ivshmem_metadata_cmdline_generate(buf, sizeof(buf), NULL) < 0,
			"Written command line for NULL metadata");
	ASSERT(strnlen(buf, sizeof(buf)) == 0, "Buffer is not empty");

	ASSERT(rte_ivshmem_metadata_cmdline_generate(buf, sizeof(buf),
			NONEXISTENT_METADATA) < 0,
			"Writen command line for nonexistent metadata");
	ASSERT(strnlen(buf, sizeof(buf)) == 0, "Buffer is not empty");

	/* add stuff to config */
	ASSERT(rte_ivshmem_metadata_add_memzone(mz, METADATA_NAME) == 0,
			"Failed to add memzone to valid config");
	ASSERT(rte_ivshmem_metadata_add_ring(r, METADATA_NAME) == 0,
			"Failed to add ring to valid config");
	ASSERT(rte_ivshmem_metadata_add_mempool(mp, METADATA_NAME) == 0,
			"Failed to add mempool to valid config");

	/* create config */
	ASSERT(rte_ivshmem_metadata_cmdline_generate(buf, sizeof(buf),
			METADATA_NAME) == 0, "Failed to write command-line");

	/* check if something was written */
	ASSERT(strnlen(buf, sizeof(buf)) != 0, "Buffer is empty");

	/* make sure we don't segfault */
	rte_ivshmem_metadata_dump(stdout, NULL);

	/* dump our metadata */
	rte_ivshmem_metadata_dump(stdout, METADATA_NAME);

	return 0;
}