Example #1
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;
}
Example #2
0
void
app_init_nics(void) {
#ifndef RTE_VERSION_NUM
  /* Init driver */
  printf("Initializing the PMD driver ...\n");
  if (rte_pmd_init_all() < 0) {
    rte_panic("Cannot init PMD\n");
  }
#elif RTE_VERSION < RTE_VERSION_NUM(1, 8, 0, 0)
  if (rte_eal_pci_probe() < 0) {
    rte_panic("Cannot probe PCI\n");
  }
#endif /* RTE_VERSION_NUM */
}
Example #3
0
void
init_dpdk(void)
{
    int ret;

    /* Initialize the PMD */
    ret = rte_pmd_init_all();
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "Failed to initialize poll mode drivers (error %d)\n", ret);

    /* Bind the drivers to usable devices */
    ret = rte_eal_pci_probe();
    if (ret < 0)
        rte_exit(EXIT_FAILURE, "rte_eal_pci_probe(): error %d\n", ret);

    if (rte_eth_dev_count() < 2)
        rte_exit(EXIT_FAILURE, "Not enough ethernet port available\n");
}
Example #4
0
int app_init(void)
{
	uint32_t i;
	char ring_name[MAX_NAME_LEN];
	char pool_name[MAX_NAME_LEN];

	/* init driver(s) */
	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");

	if (rte_eth_dev_count() == 0)
		rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n");

	/* load configuration profile */
	if (app_load_cfg_profile(cfg_profile) != 0)
		rte_exit(EXIT_FAILURE, "Invalid configuration profile\n");
	
	/* Initialize each active flow */
	for(i = 0; i < nb_pfc; i++) {
		uint32_t socket = rte_lcore_to_socket_id(qos_conf[i].rx_core);
		struct rte_ring *ring;

		rte_snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].rx_core);
		ring = rte_ring_lookup(ring_name);
		if (ring == NULL)
			qos_conf[i].rx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
			 	socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
		else
			qos_conf[i].rx_ring = ring;

		rte_snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].tx_core);
		ring = rte_ring_lookup(ring_name);
		if (ring == NULL)
			qos_conf[i].tx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
				socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
		else
			qos_conf[i].tx_ring = ring;


		/* create the mbuf pools for each RX Port */
		rte_snprintf(pool_name, MAX_NAME_LEN, "mbuf_pool%u", i);
		qos_conf[i].mbuf_pool = rte_mempool_create(pool_name, mp_size, MBUF_SIZE,
						burst_conf.rx_burst * 4,
						sizeof(struct rte_pktmbuf_pool_private),
						rte_pktmbuf_pool_init, NULL,
						rte_pktmbuf_init, NULL,
						rte_eth_dev_socket_id(qos_conf[i].rx_port),
						0);
		if (qos_conf[i].mbuf_pool == NULL)
			rte_exit(EXIT_FAILURE, "Cannot init mbuf pool for socket %u\n", i);

		app_init_port(qos_conf[i].rx_port, qos_conf[i].mbuf_pool);
		app_init_port(qos_conf[i].tx_port, qos_conf[i].mbuf_pool);
		
		qos_conf[i].sched_port = app_init_sched_port(qos_conf[i].tx_port, socket);
	}

	RTE_LOG(INFO, APP, "time stamp clock running at %" PRIu64 " Hz\n",
			 rte_get_timer_hz());
	
	RTE_LOG(INFO, APP, "Ring sizes: NIC RX = %u, Mempool = %d SW queue = %u,"
			 "NIC TX = %u\n", ring_conf.rx_size, mp_size, ring_conf.ring_size,
			 ring_conf.tx_size);

	RTE_LOG(INFO, APP, "Burst sizes: RX read = %hu, RX write = %hu,\n"
						  "             Worker read/QoS enqueue = %hu,\n"
						  "             QoS dequeue = %hu, Worker write = %hu\n",
		burst_conf.rx_burst, burst_conf.ring_burst, burst_conf.ring_burst, 
		burst_conf.qos_dequeue, burst_conf.tx_burst);

	RTE_LOG(INFO, APP, "NIC thresholds RX (p = %hhu, h = %hhu, w = %hhu),"
				 "TX (p = %hhu, h = %hhu, w = %hhu)\n",
		rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh,
		tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);

	return 0;
}
Example #5
0
static void
app_init_nics(void)
{
	unsigned socket;
	uint32_t lcore;
	uint8_t port, queue;
	int ret;
	uint32_t n_rx_queues, n_tx_queues;

	/* Init driver */
	printf("Initializing the PMD driver ...\n");
	if (rte_pmd_init_all() < 0) {
		rte_panic("Cannot init PMD\n");
	}

	if (rte_eal_pci_probe() < 0) {
		rte_panic("Cannot probe PCI\n");
	}

	/* Init NIC ports and queues, then start the ports */
	for (port = 0; port < APP_MAX_NIC_PORTS; port ++) {
		struct rte_mempool *pool;

		n_rx_queues = app_get_nic_rx_queues_per_port(port);
		n_tx_queues = app.nic_tx_port_mask[port];

		if ((n_rx_queues == 0) && (n_tx_queues == 0)) {
			continue;
		}

		/* Init port */
		printf("Initializing NIC port %u ...\n", (unsigned) port);
		ret = rte_eth_dev_configure(
			port,
			(uint8_t) n_rx_queues,
			(uint8_t) n_tx_queues,
			&port_conf);
		if (ret < 0) {
			rte_panic("Cannot init NIC port %u (%d)\n", (unsigned) port, ret);
		}
		rte_eth_promiscuous_enable(port);

		/* Init RX queues */
		for (queue = 0; queue < APP_MAX_RX_QUEUES_PER_NIC_PORT; queue ++) {
			if (app.nic_rx_queue_mask[port][queue] == 0) {
				continue;
			}

			app_get_lcore_for_nic_rx(port, queue, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			pool = app.lcore_params[lcore].pool;

			printf("Initializing NIC port %u RX queue %u ...\n",
				(unsigned) port,
				(unsigned) queue);
			ret = rte_eth_rx_queue_setup(
				port,
				queue,
				(uint16_t) app.nic_rx_ring_size,
				socket,
				&rx_conf,
				pool);
			if (ret < 0) {
				rte_panic("Cannot init RX queue %u for port %u (%d)\n",
					(unsigned) queue,
					(unsigned) port,
					ret);
			}
		}

		/* Init TX queues */
		if (app.nic_tx_port_mask[port] == 1) {
			app_get_lcore_for_nic_tx(port, &lcore);
			socket = rte_lcore_to_socket_id(lcore);
			printf("Initializing NIC port %u TX queue 0 ...\n",
				(unsigned) port);
			ret = rte_eth_tx_queue_setup(
				port,
				0,
				(uint16_t) app.nic_tx_ring_size,
				socket,
				&tx_conf);
			if (ret < 0) {
				rte_panic("Cannot init TX queue 0 for port %d (%d)\n",
					port,
					ret);
			}
		}

		/* Start port */
		ret = rte_eth_dev_start(port);
		if (ret < 0) {
			rte_panic("Cannot start port %d (%d)\n", port, ret);
		}
	}

	check_all_ports_link_status(APP_MAX_NIC_PORTS, (~0x0));
}
Example #6
0
DpdkPcapResultCode_t globalInit(char *errbuf)
{
    char *args[] = {"dpdkpcap_test", "-c 0x03", "-n 2", "-m 128", "--file-prefix=dpdkpcap_test"};

    if (initFinished == 1)
    {
        return DPDKPCAP_OK;
    }

    if (rte_eal_init(sizeof(args)/sizeof(char*), args) < 0)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not initialize DPDK");
        return DPDKPCAP_FAILURE;
    }

#ifdef VER_16
    if (rte_pmd_init_all() < 0)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not init driver");
        return DPDKPCAP_FAILURE;
    }
#endif

    if (rte_eal_pci_probe() < 0)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not probe devices");
        return DPDKPCAP_FAILURE;
    }

    rxPool = rte_mempool_create(DPDKPCAP_RX_POOL_NAME,
             DPDKPCAP_NB_MBUF,
             DPDKPCAP_MBUF_SIZE,
             DPDKPCAP_CACHE_SIZE,
             sizeof(struct rte_pktmbuf_pool_private),
             rte_pktmbuf_pool_init, NULL,
             rte_pktmbuf_init, NULL,
             SOCKET_ID_ANY,
             MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET);

    if(rxPool == NULL)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not allocate RX memory pool");
        return DPDKPCAP_FAILURE;
    }

    txPool = rte_mempool_create(DPDKPCAP_TX_POOL_NAME,
             DPDKPCAP_NB_MBUF,
             DPDKPCAP_MBUF_SIZE,
             DPDKPCAP_CACHE_SIZE,
             sizeof(struct rte_pktmbuf_pool_private),
             rte_pktmbuf_pool_init, NULL,
             rte_pktmbuf_init, NULL,
             SOCKET_ID_ANY,
             MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET);

    if(txPool == NULL)
    {
        snprintf (errbuf, PCAP_ERRBUF_SIZE, "Could not allocate TX memory pool");
        return DPDKPCAP_FAILURE;
    }

    initFinished = 1;
    return DPDKPCAP_OK;
}