static int
globalinit(void)
{
    int rv;

    if (rte_eal_init(sizeof(ealargs)/sizeof(ealargs[0]),
                     /*UNCONST*/(void *)(uintptr_t)ealargs) < 0)
        OUT("eal init\n");

    if ((mbpool = rte_mempool_create("mbuf_pool", NMBUF, MBSIZE, MBALIGN,
                                     sizeof(struct rte_pktmbuf_pool_private),
                                     rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, 0, 0)) == NULL)
        OUT("mbuf pool\n");

    if (PMD_INIT() < 0)
        OUT("wm driver\n");
    if (rte_eal_pci_probe() < 0)
        OUT("PCI probe\n");
    if (rte_eth_dev_count() == 0)
        OUT("no ports\n");
    rv = 0;

out:
    return rv;
}
Exemple #2
0
static int
globalinit(struct virtif_user *viu)
{
	int rv;

	if ((rv = rte_eal_init(sizeof(ealargs)/sizeof(ealargs[0]),
	    /*UNCONST*/(void *)(uintptr_t)ealargs)) < 0)
		OUT("eal init");

	if ((mbpool_tx = rte_mempool_create("mbuf_pool_tx", NMBUF_TX, MBSIZE, 0/*MBCACHE*/,
	    sizeof(struct rte_pktmbuf_pool_private),
	    rte_pktmbuf_pool_init, NULL,
	    rte_pktmbuf_init, NULL, 0, 0)) == NULL) {
		rv = -EINVAL;
		OUT("mbuf pool tx");
	}
	if ((mbpool_rx = rte_mempool_create("mbuf_pool_rx", NMBUF_RX, MBSIZE, 0/*MBCACHE*/,
	    sizeof(struct rte_pktmbuf_pool_private),
	    rte_pktmbuf_pool_init, NULL,
	    rte_pktmbuf_init, NULL, 0, 0)) == NULL) {
		rv = -EINVAL;
		OUT("mbuf pool tx");
	}

	if (rte_eth_dev_count() == 0) {
		rv = -1;
		OUT("no ports");
	}
	rv = 0;

 out:
 	return rv;
}
Exemple #3
0
int main(void)
{
    int ret;
    struct cmdline *cl;
    int     param_num = 8;
    char *param[] = {"anscli",
                               "-c",
                               "1",
                               "-n",
                               "1",
                               "--no-pci",
                               "--socket-mem=1",
                               "--proc-type=secondary",
                               NULL};


    rte_set_log_level(RTE_LOG_ERR);
    ret = rte_eal_init(param_num, param);
    if (ret < 0)
        rte_panic("Cannot init EAL\n");

    ret = anscli_ring_init();
    if(ret != 0)
        rte_panic("Cannot init ring\n");


    cl = cmdline_stdin_new(ip_main_ctx, "ans> ");
    if (cl == NULL)
    rte_panic("Cannot create ans cmdline instance\n");

    cmdline_interact(cl);
    cmdline_stdin_exit(cl);

    return 0;
}
Exemple #4
0
int32_t main(int32_t argc, char **argv)
{
	int32_t ret = -1;
	
	ret = rte_eal_init(argc, argv);
	if(0 > ret)
	{
		rte_exit(EXIT_FAILURE, "rte_eal_init failed!\n");
	}

	argc -= ret;
	argv += ret;

	ret = udpi_parse_args(argc, argv);
	if(0 > ret)
	{
		udpi_print_usage(argv[0]);
		rte_exit(EXIT_FAILURE, "invalid user args!\n");
	}

	udpi_init();

	rte_eal_mp_remote_launch(udpi_lcore_main_loop, 
		NULL, CALL_MASTER);
	
	return 0;
}
Exemple #5
0
int
MAIN(int argc, char **argv)
{
	uint32_t lcore;
	int ret;

	/* Init EAL */
	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		return -1;
	argc -= ret;
	argv += ret;

	/* Parse application arguments (after the EAL ones) */
	ret = app_parse_args(argc, argv);
	if (ret < 0) {
		app_print_usage();
		return -1;
	}

	/* Init */
	app_init();
	app_print_params();

	/* Launch per-lcore init on every lcore */
	rte_eal_mp_remote_launch(app_lcore_main_loop, NULL, CALL_MASTER);
	RTE_LCORE_FOREACH_SLAVE(lcore) {
		if (rte_eal_wait_lcore(lcore) < 0) {
			return -1;
		}
	}

	return 0;
}
Exemple #6
0
/*
 * Parse the command line arguments passed to the application.
 */
int parse_args(int argc, char** argv, app_params* p)
{
  // initialize the environment
  int ret = rte_eal_init(argc, argv);
  if (ret < 0) {
      rte_exit(EXIT_FAILURE, "Failed to initialize EAL: %i\n", ret);
  }

  // advance past the environmental settings
  argc -= ret;
  argv += ret;

  // parse arguments to the application
  ret = parse_app_args(argc, argv, p);
  if (ret < 0) {
      rte_exit(EXIT_FAILURE, "\n");
  }

  p->nb_ports = rte_eth_dev_count();
  p->nb_rx_workers = p->nb_rx_queue;
  p->nb_tx_workers = (rte_lcore_count() - 1) - p->nb_rx_workers;

  // validate the number of workers
  if(p->nb_tx_workers < p->nb_rx_workers) {
      rte_exit(EXIT_FAILURE, "Additional lcore(s) required; found=%u, required=%u \n",
          rte_lcore_count(), (p->nb_rx_queue*2) + 1);
  }

  return 0;
}
static int
globalinit(struct virtif_user *viu)
{
	int rv;

	if ((rv = rte_eal_init(sizeof(ealargs)/sizeof(ealargs[0]),
	    /*UNCONST*/(void *)(uintptr_t)ealargs)) < 0)
		OUT("eal init\n");

	/* disable mempool cache due to DPDK bug, not thread safe */
	if ((mbpool = rte_mempool_create("mbuf_pool", NMBUF, MBSIZE, 0/*MBCACHE*/,
	    sizeof(struct rte_pktmbuf_pool_private),
	    rte_pktmbuf_pool_init, NULL,
	    rte_pktmbuf_init, NULL, 0, 0)) == NULL) {
		rv = -EINVAL;
		OUT("mbuf pool\n");
	}

	if ((rv = PMD_INIT()) < 0)
		OUT("pmd init\n");
	if ((rv = rte_eal_pci_probe()) < 0)
		OUT("PCI probe\n");
	if (rte_eth_dev_count() == 0) {
		rv = -1;
		OUT("no ports\n");
	}
	rv = 0;

 out:
 	return rv;
}
Exemple #8
0
int main(int argc, char *argv[])
{
	int ret;

	signal(SIGINT, signal_handler);

	/* init EAL */
	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");

	g_vhost_ctrlr = vhost_scsi_ctrlr_construct("vhost.socket");
	if (g_vhost_ctrlr == NULL) {
		fprintf(stderr, "Construct vhost scsi controller failed\n");
		return 0;
	}

	if (sem_init(&exit_sem, 0, 0) < 0) {
		fprintf(stderr, "Error init exit_sem\n");
		return -1;
	}

	rte_vhost_driver_start(dev_pathname);

	/* loop for exit the application */
	while (1)
		sleep(1);

	return 0;
}
Exemple #9
0
int
main(int argc, char **argv)
{
	struct cmdline *cl;
	int ret;

	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		return -1;

	rte_timer_subsystem_init();

	argc -= ret;
	argv += ret;

	prgname = argv[0];

#ifndef RTE_EXEC_ENV_BAREMETAL
	if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL)
		return do_recursive_call();
#endif

	cl = cmdline_stdin_new(main_ctx, "RTE>>");
	if (cl == NULL) {
		return -1;
	}
	cmdline_interact(cl);
	cmdline_stdin_exit(cl);

	return 0;
}
Exemple #10
0
int main(int argc, char **argv)
{
    int c;
    int ret;
    int sp_sc;
    unsigned socket_io;

    /* initialize EAL first */
    ret = rte_eal_init(argc, argv);

    argc -= ret;
    argv += ret;

    sp_sc = 1;
    bulk_size = 1;
    while ((c = getopt(argc, argv, "sm:b:w:")) != -1) {
        switch (c) {
        case 's':
            sp_sc = 1;
            break;
        case 'm':
            sp_sc = 0;
            nb_producers = atoi(optarg);
            break;
        case 'b':
            bulk_size = atoi(optarg);
            break;
        case 'w':
            work_cycles = atoi(optarg);
            break;
        case '?':
            break;
        }
    }

    setlocale(LC_NUMERIC, "");

    socket_io = rte_lcore_to_socket_id(rte_get_master_lcore());

    ring = rte_ring_create(ring_name,
                           ring_size, socket_io, RING_F_SP_ENQ | RING_F_SC_DEQ);

    if (ring == NULL) {
        rte_panic("Cannot create ring");
    }

    if (sp_sc) {
        printf("[MASTER] Single Producer/Consumer\n");
        printf("[MASTER] Bulk size: %d\n", bulk_size);
        driver_sp_sc();
    } else {
        printf("[MASTER] Number of Producers/Consumers: %d\n", nb_producers);
        printf("[MASTER] Bulk size: %d\n", bulk_size);
        driver_mp_mc();
    }
    rte_eal_mp_wait_lcore();
}
Exemple #11
0
int main(int argc, char **argv)
{
	int rc;

	/*
	 * By default, the SPDK NVMe driver uses DPDK for huge page-based
	 *  memory management and NVMe request buffer pools.  Huge pages can
	 *  be either 2MB or 1GB in size (instead of 4KB) and are pinned in
	 *  memory.  Pinned memory is important to ensure DMA operations
	 *  never target swapped out memory.
	 *
	 * So first we must initialize DPDK.  "-c 0x1" indicates to only use
	 *  core 0.
	 */
	rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]), ealargs);
	if (rc < 0) {
		fprintf(stderr, "could not initialize dpdk\n");
		return 1;
	}

	/*
	 * Create the NVMe request buffer pool.  This will be used internally
	 *  by the SPDK NVMe driver to allocate an spdk_nvme_request data
	 *  structure for each I/O request.  This is implicitly passed to
	 *  the SPDK NVMe driver via an extern declaration in nvme_impl.h.
	 */
	request_mempool = rte_mempool_create("nvme_request", 8192,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

	if (request_mempool == NULL) {
		fprintf(stderr, "could not initialize request mempool\n");
		return 1;
	}

	printf("Initializing NVMe Controllers\n");

	/*
	 * Start the SPDK NVMe enumeration process.  probe_cb will be called
	 *  for each NVMe controller found, giving our application a choice on
	 *  whether to attach to each controller.  attach_cb will then be
	 *  called for each controller after the SPDK NVMe driver has completed
	 *  initializing the controller we chose to attach.
	 */
	rc = spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL);
	if (rc != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		cleanup();
		return 1;
	}

	printf("Initialization complete.\n");
	hello_world();
	cleanup();
	return 0;
}
Exemple #12
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;
	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;

	/* initialise the nic drivers */
	retval = init_drivers();
	if (retval != 0)
		rte_exit(EXIT_FAILURE, "Cannot initialise drivers\n");

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

	/* set up array for port data */
	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 */
	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();

	return 0;
}
Exemple #13
0
int main(int argc, char **argv)
{
	struct dev			*iter;
	int				rc, i;

	printf("NVMe Write/Read with End-to-End data protection test\n");

	rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]),
			  (char **)(void *)(uintptr_t)ealargs);

	if (rc < 0) {
		fprintf(stderr, "could not initialize dpdk\n");
		exit(1);
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

	if (request_mempool == NULL) {
		fprintf(stderr, "could not initialize request mempool\n");
		exit(1);
	}

	if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) {
		fprintf(stderr, "nvme_probe() failed\n");
		exit(1);
	}

	rc = 0;
	foreach_dev(iter) {
#define TEST(x) write_read_e2e_dp_tests(iter, x, #x)
		if (TEST(dp_with_pract_test)
		    || TEST(dp_without_pract_extended_lba_test)
		    || TEST(dp_without_flags_extended_lba_test)
		    || TEST(dp_without_pract_separate_meta_test)
		    || TEST(dp_without_pract_separate_meta_apptag_test)
		    || TEST(dp_without_flags_separate_meta_test)) {
#undef TEST
			rc = 1;
			printf("%s: failed End-to-End data protection tests\n", iter->name);
		}
	}

	printf("Cleaning up...\n");

	for (i = 0; i < num_devs; i++) {
		struct dev *dev = &devs[i];

		spdk_nvme_detach(dev->ctrlr);
	}

	return rc;
}
/* Main function */
int main(int argc, char **argv)
{
	int ret;
	int i;

	/* Create handler for SIGINT for CTRL + C closing and SIGALRM to print stats*/
	signal(SIGINT, sig_handler);
	signal(SIGALRM, alarm_routine);

	/* Initialize DPDK enviroment with args, then shift argc and argv to get application parameters */
	ret = rte_eal_init(argc, argv);
	if (ret < 0) FATAL_ERROR("Cannot init EAL\n");
	argc -= ret;
	argv += ret;

	/* Check if this application can use 1 core*/
	ret = rte_lcore_count ();
	if (ret != 2) FATAL_ERROR("This application needs exactly 2 cores.");

	/* Parse arguments */
	parse_args(argc, argv);
	if (ret < 0) FATAL_ERROR("Wrong arguments\n");

	/* Probe PCI bus for ethernet devices, mandatory only in DPDK < 1.8.0 */
	#if RTE_VER_MAJOR == 1 && RTE_VER_MINOR < 8
		ret = rte_eal_pci_probe();
		if (ret < 0) FATAL_ERROR("Cannot probe PCI\n");
	#endif

	/* Get number of ethernet devices */
	nb_sys_ports = rte_eth_dev_count();
	if (nb_sys_ports <= 0) FATAL_ERROR("Cannot find ETH devices\n");
	
	/* Create a mempool with per-core cache, initializing every element for be used as mbuf, and allocating on the current NUMA node */
	pktmbuf_pool = rte_mempool_create(MEMPOOL_NAME, buffer_size-1, MEMPOOL_ELEM_SZ, MEMPOOL_CACHE_SZ, sizeof(struct rte_pktmbuf_pool_private), rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL,rte_socket_id(), 0);
	if (pktmbuf_pool == NULL) FATAL_ERROR("Cannot create cluster_mem_pool. Errno: %d [ENOMEM: %d, ENOSPC: %d, E_RTE_NO_TAILQ: %d, E_RTE_NO_CONFIG: %d, E_RTE_SECONDARY: %d, EINVAL: %d, EEXIST: %d]\n", rte_errno, ENOMEM, ENOSPC, E_RTE_NO_TAILQ, E_RTE_NO_CONFIG, E_RTE_SECONDARY, EINVAL, EEXIST  );
	
	/* Create a ring for exchanging packets between cores, and allocating on the current NUMA node */
	intermediate_ring = rte_ring_create 	(RING_NAME, buffer_size, rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ );
 	if (intermediate_ring == NULL ) FATAL_ERROR("Cannot create ring");


	/* Operations needed for each ethernet device */			
	for(i=0; i < nb_sys_ports; i++)
		init_port(i);

	/* Start consumer and producer routine on 2 different cores: producer launched first... */
	ret =  rte_eal_mp_remote_launch (main_loop_producer, NULL, SKIP_MASTER);
	if (ret != 0) FATAL_ERROR("Cannot start consumer thread\n");	

	/* ... and then loop in consumer */
	main_loop_consumer ( NULL );	

	return 0;
}
Exemple #15
0
/*
 * Application main function - loops through
 * receiving and processing packets. Never returns
 */
int
main(int argc, char *argv[])
{
	int retval = 0;
	uint8_t port = 0;
	char *port_name;

	if ((retval = rte_eal_init(argc, argv)) < 0) {
		RTE_LOG(INFO, APP, "EAL init failed.\n");
		return -1;
	}

	argc -= retval;
	argv += retval;
	if (parse_app_args(argc, argv) < 0)
		rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n");

	memset(kni_list, 0, sizeof(struct rte_kni) * MAX_KNI_PORTS);

	/* Open KNI or exit */
	kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
	if (kni_fd < 0) {
		RTE_LOG(ERR, KNI, "Can not open /dev/%s\n", KNI_DEVICE);
		return -1;
	}

	/* Lookup for vports struct */
	if (ovs_vport_lookup_vport_info() == NULL)
		return -1;

	/* Initialise the devices for each port*/
	for (port = 0; port < ports_n; port++) {
		port_name = port_names[port];
		RTE_LOG(INFO, KNI, "Attaching queues for port '%s'\n", port_name);
		if (create_kni_device(&kni_list[port], port_name, port) < 0)
			return -1;
	}

	RTE_LOG(INFO, KNI, "\nKNI client handling packets \n");
	RTE_LOG(INFO, KNI, "[Press Ctrl-C to quit ...]\n");

	for (;;) {
		for (port = 0; port < ports_n; port++) {
			/* Sleep to reduce processor load. As long as we respond
			 * before rtnetlink times out we will still be able to ifup
			 * and change mtu
			 */
			sleep(1);
			rte_kni_handle_request(&kni_list[port]);
		}
	}

	return 0;
}
Exemple #16
0
int initDpdk(char* progname)
{
    int ret;
    static char *eal_args[] = {progname, "-c0xf", "-n1", "-m128", "--file-prefix=drone"};

    // TODO: read env var DRONE_RTE_EAL_ARGS to override defaults

    ret = rte_eal_init(sizeof(eal_args)/sizeof(char*), eal_args);
    if (ret < 0)
        rte_panic("Cannot init EAL\n");

    mbufPool_ = rte_mempool_create("DpktPktMbuf",
                                   16*1024, // # of mbufs
                                   2048, // sz of mbuf
                                   32,   // per-lcore cache sz
                                   sizeof(struct rte_pktmbuf_pool_private),
                                   rte_pktmbuf_pool_init, // pool ctor
                                   NULL, // pool ctor arg
                                   rte_pktmbuf_init, // mbuf ctor
                                   NULL, // mbuf ctor arg
                                   SOCKET_ID_ANY,
                                   0     // flags
                                  );

    if (!mbufPool_)
        rte_exit(EXIT_FAILURE, "cannot init mbuf pool\n");

    if (rte_pmd_init_all() < 0)
        rte_exit(EXIT_FAILURE, "cannot init pmd\n");

    if (rte_eal_pci_probe() < 0)
        rte_exit(EXIT_FAILURE, "cannot probe PCI\n");

    // init lcore information
    lcoreCount_ = rte_lcore_count();
    lcoreFreeMask_ = 0;
    for (int i = 0; i < lcoreCount_; i++) {
        if (rte_lcore_is_enabled(i) && (unsigned(i) != rte_get_master_lcore()))
            lcoreFreeMask_ |= (1 << i);
    }
    qDebug("lcore_count = %d, lcore_free_mask = 0x%llx",
           lcoreCount_, lcoreFreeMask_);

    // assign a lcore for Rx polling
    rxLcoreId_ = getFreeLcore();
    if (rxLcoreId_ < 0)
        rte_exit(EXIT_FAILURE, "not enough cores for Rx polling");

    stopRxPoll_ = false;

    return 0;
}
Exemple #17
0
int main(int argc, char *argv[])
{
    int eal_init_ret = rte_eal_init(argc, argv);
    if (eal_init_ret < 0) {
        rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n");
    }

    FLAGS_logtostderr = 1;
    google::InitGoogleLogging(argv[0]);
    ::testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}
int main(int argc, char *argv[])
{
	setlocale(LC_NUMERIC, "en_US.utf-8");

	int retval = 0;

	if ((retval = rte_eal_init(argc, argv)) < 0)
		return -1;

	argc -= retval;
	argv += retval;

	if(argc < 1)
	{
		RTE_LOG(INFO, APP, "usage: -- port\n");
		return 0;
	}

	char rx_ring_name[RTE_RING_NAMESIZE];
	char tx_ring_name[RTE_RING_NAMESIZE];

	/* be aware that ring name is in ovs point of view */
	sprintf(rx_ring_name, "%s_tx", argv[1]);
	sprintf(tx_ring_name, "%s_rx", argv[1]);

	init(tx_ring_name, rx_ring_name);

	printf("Free count in tx: %d\n", rte_ring_free_count(tx_ring));

	signal(SIGALRM, ALARMhandler);
	alarm(PRINT_INTERVAL);

	RTE_LOG(INFO, APP, "Finished Process Init.\n");

#ifdef USE_BURST
	RTE_LOG(INFO, APP, "Burst Enabled.\n");
#else
	RTE_LOG(INFO, APP, "Burst Disabled.\n");
#endif

#if ALLOC_METHOD == ALLOC_OVS
	RTE_LOG(INFO, APP, "Alloc method is OVS.\n");
#elif ALLOC_METHOD == ALLOC_APP
	RTE_LOG(INFO, APP, "Alloc method is APP.\n");
#endif

	send_loop();

	RTE_LOG(INFO, APP, "Done\n");
	return 0;
}
Exemple #19
0
int main(int argc, char **argv)
{
	struct dev			*iter;
	int				rc, i;

	rc = rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]),
			  (char **)(void *)(uintptr_t)ealargs);

	if (rc < 0) {
		fprintf(stderr, "could not initialize dpdk\n");
		exit(1);
	}

	request_mempool = rte_mempool_create("nvme_request", 8192,
					     spdk_nvme_request_size(), 128, 0,
					     NULL, NULL, NULL, NULL,
					     SOCKET_ID_ANY, 0);

	if (request_mempool == NULL) {
		fprintf(stderr, "could not initialize request mempool\n");
		exit(1);
	}

	if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		return 1;
	}

	rc = 0;

	foreach_dev(iter) {
		struct spdk_nvme_qpair *qpair;

		qpair = spdk_nvme_ctrlr_alloc_io_qpair(iter->ctrlr, 0);
		if (!qpair) {
			fprintf(stderr, "spdk_nvme_ctrlr_alloc_io_qpair() failed\n");
			rc = 1;
		} else {
			reserve_controller(iter->ctrlr, qpair, iter->pci_dev);
		}
	}

	printf("Cleaning up...\n");

	for (i = 0; i < num_devs; i++) {
		struct dev *dev = &devs[i];
		spdk_nvme_detach(dev->ctrlr);
	}

	return rc;
}
Exemple #20
0
lagopus_result_t
lagopus_dataplane_init(int argc, const char *const argv[]) {
  int ret;
  size_t argsize;
  char **copy_argv;
  int i;

  argsize = sizeof(char *) * (argc + 1);
  copy_argv = malloc(argsize);
  if (copy_argv == NULL) {
    return LAGOPUS_RESULT_NO_MEMORY;
  }
  copy_argv[0] = argv[0];
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "--")) {
      memcpy(&copy_argv[1], &argv[i + 1], sizeof(char *) * (argc - i - 1));
      break;
    }
  }
  if (i == argc) {
    /* "--" is not found in argv */
    memcpy(copy_argv, argv, argsize);
    rawsocket_only_mode = true;
  } else {
    argc -= i;
    optind = 1;

    /* init EAL */
    ret = rte_eal_init(argc, copy_argv);
    if (ret < 0) {
      return LAGOPUS_RESULT_INVALID_ARGS;
    }
    optind = ret + 1;
    rawsocket_only_mode = false;
  }

  /* parse application arguments (after the EAL ones) */
  ret = app_parse_args(argc, copy_argv);
  free(copy_argv);
  if (ret < 0) {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (rawsocket_only_mode != true) {
    /* Init */
    app_init();
    app_print_params();
  }

  return LAGOPUS_RESULT_OK;
}
void main(int argc, char *argv[])
{
	/* init EAL, parsing EAL args */
	int count = 0;
	count = rte_eal_init(argc, argv);
	assert(count >= 0);

	/* skip the `--` separating EAL params from test params */
	count++;

	run_command(argc - count, argv + count, commands);

	exit(EXIT_SUCCESS);
}
int main(int argc, char **argv) {
	// eal args
	int num_args = rte_eal_init(argc, argv);
	if (num_args < 0)
		rte_exit(EXIT_FAILURE, "init failed");
	argc -= num_args;
	argv += num_args;

	// our args: [-s] port1 port2
	uint8_t port1, port2;
	char opt = getopt(argc, argv, "s");
	bool simple_tx = opt == 's';
	if (simple_tx) {
		printf("Requesting simple tx path\n");
		argc--;
		argv++;
	} else {
		printf("Requesting full-featured tx path\n");
	}
	if (argc != 3) {
		printf("usage: [-s] port1 port2\n");
		return -1;
	}
	port1 = atoi(argv[1]);
	port2 = atoi(argv[2]);
	printf("Using ports %d and %d\n", port1, port2);

	if (!config_port(port1, simple_tx)) return -1;
	if (!config_port(port2, simple_tx)) return -1;

	struct rte_mempool* pool = make_mempool();
	
	uint64_t sent = 0;
	uint64_t next_print = rte_get_tsc_hz();
	uint64_t last_sent = 0;
	while (true) {
		sent += send_pkts(port1, pool);
		sent += send_pkts(port2, pool);
		uint64_t time = rte_rdtsc();
		if (time >= next_print) {
			double elapsed = (time - next_print + rte_get_tsc_hz()) / rte_get_tsc_hz();
			uint64_t pkts = sent - last_sent;
			printf("Packet rate: %.2f Mpps\n", (double) pkts / elapsed / 1000000);
			next_print = time + rte_get_tsc_hz();
			last_sent = sent;
		}
	}

	return 0;
}
Exemple #23
0
int
MAIN(int argc, char **argv)
{
	int ret;

	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_panic("Cannot init EAL\n");

    //test_share_hashmap<int>();
    test_share_hashmap< int, int >();

	return 0;
}
Exemple #24
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;
}
Exemple #25
0
static int
u2_init(void)
{
	if (rte_eal_init(sizeof(ealargs) / sizeof(ealargs[0]),ealargs) < 0) {
		fprintf(stderr, "failed to initialize DPDK EAL!\n");
		return 1;
	}

	printf("\n========================================\n");
	printf(  "  nvme_lat/u2_lat - ict.ncic.syssw.ufo"    );
	printf("\n========================================\n");

	request_mempool = rte_mempool_create("nvme_request",
	                                     U2_REQUEST_POOL_SIZE, spdk_nvme_request_size(),
	                                     U2_REQUEST_CACHE_SIZE, U2_REQUEST_PRIVATE_SIZE,
	                                     NULL, NULL, NULL, NULL,
	                                     SOCKET_ID_ANY, 0);
	if (request_mempool == NULL) {
		fprintf(stderr, "failed to create request pool!\n");
		return 1;
	}

	if (spdk_nvme_probe(NULL, probe_cb, attach_cb)) {
		fprintf(stderr, "failed to probe and attach to NVMe device!\n");
		return 1;
	}

	if (!u2_ctrlr) {
		fprintf(stderr, "failed to probe a suitable controller!\n");
		return 1;
	}

	if (!spdk_nvme_ns_is_active(u2_ns)) {
		fprintf(stderr, "namespace %d is IN-ACTIVE!\n", u2_ns_id);
		return 1;
	}

	if (u2_ns_size < io_size) {
		fprintf(stderr, "invalid I/O size %"PRIu32"!\n", io_size);
		return 1;
	}

	if (!u2_qpair) {
		fprintf(stderr, "failed to allocate queue pair!\n");
		return 1;
	}

	return 0;
}
Exemple #26
0
/*
 * The main function, which does initialization and calls the per-lcore
 * functions.
 */
int
main(int argc, char *argv[])
{
	struct rte_mempool *mbuf_pool;
	unsigned nb_ports;
	uint8_t portid;

	/* Initialize the Environment Abstraction Layer (EAL). */
	int ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");

	argc -= ret;
	argv += ret;

	/* Check that there is an even number of ports to send/receive on. */
	nb_ports = rte_eth_dev_count();
	if (nb_ports < 2 || (nb_ports & 1))
		rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n");

	/* Creates a new mempool in memory to hold the mbufs. */
	mbuf_pool = rte_mempool_create("MBUF_POOL",
				       NUM_MBUFS * nb_ports,
				       MBUF_SIZE,
				       MBUF_CACHE_SIZE,
				       sizeof(struct rte_pktmbuf_pool_private),
				       rte_pktmbuf_pool_init, NULL,
				       rte_pktmbuf_init,      NULL,
				       rte_socket_id(),
				       0);

	if (mbuf_pool == NULL)
		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");

	/* Initialize all ports. */
	for (portid = 0; portid < nb_ports; portid++)
		if (port_init(portid, mbuf_pool) != 0)
			rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
					portid);

	if (rte_lcore_count() > 1)
		printf("\nWARNING: Too many lcores enabled. Only 1 used.\n");

	/* Call lcore_main on the master core only. */
	lcore_main();

	return 0;
}
Exemple #27
0
int main(int argc, char* argv[]) {

	int ret;
    struct rte_mempool *mbuf_pool;

    /* Initialize the Environment Abstraction Layer (EAL). */
    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");

    /* Creates a new mempool in memory to hold the msend_bufs. */
    mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS,
	MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());

    if (mbuf_pool == NULL)
        rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");

	// Create Signal Action for interrupts
	struct sigaction newSigAction;
    memset((void *)&newSigAction, 0, sizeof(struct sigaction));
    newSigAction.sa_handler = &signal_handler;
    newSigAction.sa_flags = SA_NODEFER;

    // Attach signal handlers
    if (sigaction(SIGINT, &newSigAction, NULL) < 0) {
        fprintf(stderr, "Error attaching signal handler.\n");
        exit(0);
    }
    if (sigaction(SIGALRM, &newSigAction, NULL) < 0) {
        fprintf(stderr, "Error attaching signal handler.\n");
        exit(0);
    }
    if (sigaction(SIGRTMIN, &newSigAction, NULL) < 0) {
        fprintf(stderr, "Error attaching signal handler.\n");
        exit(0);
    }

	sleep(1);

	setup_sender(mbuf_pool);

    rte_eal_mp_wait_lcore();

    return 0;

}
Exemple #28
0
int
main(int argc, char **argv)
{
#ifdef RTE_LIBRTE_CMDLINE
	struct cmdline *cl;
#endif
	int ret;

	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		return -1;

#ifdef RTE_LIBRTE_TIMER
	rte_timer_subsystem_init();
#endif

	if (commands_init() < 0)
		return -1;

	argv += ret;

	prgname = argv[0];

#ifndef RTE_EXEC_ENV_BAREMETAL
	if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL)
		return do_recursive_call();
#endif

#ifdef RTE_LIBEAL_USE_HPET
	if (rte_eal_hpet_init(1) < 0)
#endif
		RTE_LOG(INFO, APP,
				"HPET is not enabled, using TSC as default timer\n");


#ifdef RTE_LIBRTE_CMDLINE
	cl = cmdline_stdin_new(main_ctx, "RTE>>");
	if (cl == NULL) {
		return -1;
	}
	cmdline_interact(cl);
	cmdline_stdin_exit(cl);
#endif

	return 0;
}
Exemple #29
0
int main(int argc, char **argv)
{
	int ret;
	struct cmdline *cl;

	ret = rte_eal_init(argc, argv);
	if (ret < 0)
		rte_panic("Cannot init EAL\n");

	cl = cmdline_stdin_new(main_ctx, "example> ");
	if (cl == NULL)
		rte_panic("Cannot create cmdline instance\n");
	cmdline_interact(cl);
	cmdline_stdin_exit(cl);

	return 0;
}
Exemple #30
0
/* Main function, does initialisation and calls the per-lcore functions */
	int
main(int argc, char *argv[])
{
	struct rte_mempool *mbuf_pool;
	uint8_t portid = 0;

	/* init EAL */
	int ret = rte_eal_init(argc, argv);

	if (ret < 0)
		rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
	argc -= ret;
	argv += ret;

	mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
			NUM_MBUFS, MBUF_CACHE_SIZE, 0,
			RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
	if (mbuf_pool == NULL)
		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");

	/* initialize all ports */
	if (port_init(portid, mbuf_pool) != 0)
		rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8"\n",
				portid);

	stats_mapping_setup(portid);

	fdir_filter_add(portid, FDIR_DROP_ADDR, RTE_ETH_FDIR_REJECT, 0);
	fdir_filter_add(portid, FDIR_ACCEPT_ADDR, RTE_ETH_FDIR_ACCEPT, 1);

	ntuple_filter_add(portid, NTUPLE_DROP_ADDR, PKT_DROP_QUEUE);
	ntuple_filter_add(portid, NTUPLE_ACCEPT_ADDR, PKT_ACCEPT_QUEUE);

	fdir_get_infos(portid);

	if (rte_lcore_count() > 1)
		printf("\nWARNING: Too much enabled lcores - "
				"App uses only 1 lcore\n");

	lcore_stats();

	/* call lcore_main on master core only */
	//lcore_main();

	return 0;
}