dpdk l2fwd (2)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

dpdkl2fwd(2)回到l2fwd的main函数中intMAIN(intargc,char**argv){structlcore_queue_conf*qconf;structrte_eth_dev_infodev_info;intret;uint8_tnb_ports;uint8_tnb_ports_available;uint8_tportid,last_port;unsignedlcore_id,rx_lcore_id;unsignednb_ports_in_mask=0;/*initEAL*/ret=rte_eal_init(argc,argv);if(ret0)rte_exit(EXIT_FAILURE,InvalidEALarguments\n);argc-=ret;argv+=ret;/*parseapplicationarguments(aftertheEALones)*/ret=l2fwd_parse_args(argc,argv);if(ret0)rte_exit(EXIT_FAILURE,InvalidL2FWDarguments\n);/*createthembufpool*/l2fwd_pktmbuf_pool=rte_mempool_create(mbuf_pool,NB_MBUF,MBUF_SIZE,32,sizeof(structrte_pktmbuf_pool_private),rte_pktmbuf_pool_init,NULL,rte_pktmbuf_init,NULL,rte_socket_id(),0);if(l2fwd_pktmbuf_pool==NULL)rte_exit(EXIT_FAILURE,Cannotinitmbufpool\n);/*initdriver(s)*/if(rte_pmd_init_all()0)rte_exit(EXIT_FAILURE,Cannotinitpmd\n);if(rte_eal_pci_probe()0)rte_exit(EXIT_FAILURE,CannotprobePCI\n);nb_ports=rte_eth_dev_count();if(nb_ports==0)rte_exit(EXIT_FAILURE,NoEthernetports-bye\n);if(nb_portsRTE_MAX_ETHPORTS)nb_ports=RTE_MAX_ETHPORTS;/*resetl2fwd_dst_ports*/for(portid=0;portidRTE_MAX_ETHPORTS;portid++)l2fwd_dst_ports[portid]=0;last_port=0;/*port0发给port1,port1发给port0.两个端口为一对,互相发包*//**EachlogicalcoreisassignedadedicatedTXqueueoneachport.*/for(portid=0;portidnb_ports;portid++){/*skipportsthatarenotenabled*/if((l2fwd_enabled_port_mask&(1portid))==0)continue;if(nb_ports_in_mask%2){l2fwd_dst_ports[portid]=last_port;l2fwd_dst_ports[last_port]=portid;}elselast_port=portid;nb_ports_in_mask++;rte_eth_dev_info_get(portid,&dev_info);}if(nb_ports_in_mask%2){printf(Notice:oddnumberofportsinportmask.\n);l2fwd_dst_ports[last_port]=last_port;}rx_lcore_id=0;qconf=NULL;/*每个core负责收l2fwd_rx_queue_per_lcore个端口,每个端口(其实应该是QUEUE,因为这里一个port只有一个QUEUE)只能由一个lcore进行收包*//*Initializetheport/queueconfigurationofeachlogicalcore*/for(portid=0;portidnb_ports;portid++){/*skipportsthatarenotenabled*/if((l2fwd_enabled_port_mask&(1portid))==0)continue;/*getthelcore_idforthisport*/while(rte_lcore_is_enabled(rx_lcore_id)==0||lcore_queue_conf[rx_lcore_id].n_rx_port==l2fwd_rx_queue_per_lcore){rx_lcore_id++;if(rx_lcore_id=RTE_MAX_LCORE)rte_exit(EXIT_FAILURE,Notenoughcores\n);}if(qconf!=&lcore_queue_conf[rx_lcore_id])/*Assignedanewlogicalcoreintheloopabove.*/qconf=&lcore_queue_conf[rx_lcore_id];qconf-rx_port_list[qconf-n_rx_port]=portid;qconf-n_rx_port++;printf(Lcore%u:RXport%u\n,rx_lcore_id,(unsigned)portid);}nb_ports_available=nb_ports;/*每个port收发包队列的初始化*//*Initialiseeachport*/for(portid=0;portidnb_ports;portid++){/*skipportsthatarenotenabled*/if((l2fwd_enabled_port_mask&(1portid))==0){printf(Skippingdisabledport%u\n,(unsigned)portid);nb_ports_available--;continue;}/*initport*/printf(Initializingport%u...,(unsigned)portid);fflush(stdout);ret=rte_eth_dev_configure(portid,1,1,&port_conf);if(ret0)rte_exit(EXIT_FAILURE,Cannotconfiguredevice:err=%d,port=%u\n,ret,(unsigned)portid);rte_eth_macaddr_get(portid,&l2fwd_ports_eth_addr[portid]);/*initoneRXqueue*/fflush(stdout);ret=rte_eth_rx_queue_setup(portid,0,nb_rxd,rte_eth_dev_socket_id(portid),&rx_conf,l2fwd_pktmbuf_pool);if(ret0)rte_exit(EXIT_FAILURE,rte_eth_rx_queue_setup:err=%d,port=%u\n,ret,(unsigned)portid);/*initoneTXqueueoneachport*/fflush(stdout);ret=rte_eth_tx_queue_setup(portid,0,nb_txd,rte_eth_dev_socket_id(portid),&tx_conf);if(ret0)rte_exit(EXIT_FAILURE,rte_eth_tx_queue_setup:err=%d,port=%u\n,ret,(unsigned)portid);/*Startdevice*/ret=rte_eth_dev_start(portid);if(ret0)rte_exit(EXIT_FAILURE,rte_eth_dev_start:err=%d,port=%u\n,ret,(unsigned)portid);printf(done:\n);rte_eth_promiscuous_enable(portid);printf(Port%u,MACaddress:%02X:%02X:%02X:%02X:%02X:%02X\n\n,(unsigned)portid,l2fwd_ports_eth_addr[portid].addr_bytes[0],l2fwd_ports_eth_addr[portid].addr_bytes[1],l2fwd_ports_eth_addr[portid].addr_bytes[2],l2fwd_ports_eth_addr[portid].addr_bytes[3],l2fwd_ports_eth_addr[portid].addr_bytes[4],l2fwd_ports_eth_addr[portid].addr_bytes[5]);/*initializeportstats*/memset(&port_statistics,0,sizeof(port_statistics));}if(!nb_ports_available){rte_exit(EXIT_FAILURE,Allavailableportsaredisabled.Pleasesetportmask.\n);}check_all_ports_link_status(nb_ports,l2fwd_enabled_port_mask);/*启动l2fwd线程*//*launchper-lcoreinitoneverylcore*/rte_eal_mp_remote_launch(l2fwd_launch_one_lcore,NULL,CALL_MASTER);RTE_LCORE_FOREACH_SLAVE(lcore_id){if(rte_eal_wait_lcore(lcore_id)0)return-1;}return0;}以下详细分析端口初始化过程;对于每个port,首先调用rte_eth_dev_configure配置端口的收发包队列个数,并初始化收发包队列控制块;intrte_eth_dev_configure(uint8_tport_id,uint16_tnb_rx_q,uint16_tnb_tx_q,conststructrte_eth_conf*dev_conf){structrte_eth_dev*dev;structrte_eth_dev_infodev_info;intdiag;/*只能由primary进程初始化*//*Thisfunctionisonlysafewhencalledfromtheprimaryprocess*inamulti-processsetup*/PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);if(port_id=nb_ports||port_id=RTE_MAX_ETHPORTS){PMD_DEBUG_TRACE(Invalidport_id=%d\n,port_id);return(-EINVAL);}dev=&rte_eth_devices[port_id];/*在PMD驱动初始化过程中,E1000的ops注册为eth_em_ops*/FUNC_PTR_OR_ERR_RET(*dev-dev_ops-dev_infos_get,-ENOTSUP);FUNC_PTR_OR_ERR_RET(*de

1 / 39
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功