@@ -380,6 +380,7 @@ static uint8_t ans_get_port_rx_queues_nb(const uint8_t port, struct ans_user_con
380380 }
381381 return (uint8_t )(++ queue );
382382}
383+
383384/**********************************************************************
384385*@description:
385386*
@@ -391,24 +392,47 @@ static uint8_t ans_get_port_rx_queues_nb(const uint8_t port, struct ans_user_con
391392*@return values:
392393*
393394**********************************************************************/
394- static uint8_t ans_get_port_rx_qmapping (const uint8_t port , uint8_t qmapping_size , struct ans_port_qmapping * qmapping , struct ans_user_config * user_conf )
395+ static void ans_get_port_queue (const uint8_t port , struct ans_port_queue * port_queue , struct ans_lcore_queue * lcore_conf )
395396{
396397 uint16_t i ;
397- uint8_t queue_nb = 0 ;
398+ uint8_t lcore_id ;
399+ struct ans_lcore_queue * lcore_queue ;
398400
399- for (i = 0 ; i < user_conf -> lcore_param_nb && queue_nb < qmapping_size ; ++ i )
401+ port_queue -> rxq_nb = 0 ;
402+ port_queue -> txq_nb = 0 ;
403+
404+ for (lcore_id = 0 ; lcore_id < RTE_MAX_LCORE ; lcore_id ++ )
400405 {
401- if (user_conf -> lcore_param [i ].port_id == port )
406+ if (rte_lcore_is_enabled (lcore_id ) == 0 )
407+ continue ;
408+
409+ lcore_queue = & lcore_conf [lcore_id ];
410+
411+ /* get rx queue */
412+ for (i = 0 ; i < lcore_queue -> n_rx_queue ; i ++ )
413+ {
414+ if (lcore_queue -> rx_queue [i ].port_id == port )
415+ {
416+ port_queue -> rx_qmapping [port_queue -> rxq_nb ].lcore_id = lcore_id ;
417+ port_queue -> rx_qmapping [port_queue -> rxq_nb ].queue_id = lcore_queue -> rx_queue [i ].queue_id ;
418+ port_queue -> rxq_nb ++ ;
419+ }
420+ }
421+
422+ /* get tx queue */
423+ if (lcore_queue -> tx_queue [port ].queue_id != INVALID_QUEUE_ID )
402424 {
403- qmapping [ queue_nb ].lcore_id = user_conf -> lcore_param [ i ]. lcore_id ;
404- qmapping [ queue_nb ].queue_id = user_conf -> lcore_param [ i ].queue_id ;
405- queue_nb ++ ;
425+ port_queue -> tx_qmapping [ port_queue -> txq_nb ].lcore_id = lcore_id ;
426+ port_queue -> tx_qmapping [ port_queue -> txq_nb ].queue_id = lcore_queue -> tx_queue [ port ].queue_id ;
427+ port_queue -> txq_nb ++ ;
406428 }
429+
407430 }
408431
409- return ( queue_nb ) ;
432+ return ;
410433}
411434
435+
412436/**********************************************************************
413437*@description:
414438*
@@ -427,7 +451,6 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
427451 uint16_t queueid ;
428452 unsigned lcore_id ;
429453 uint8_t nb_rx_queue = 0 ;
430- uint8_t max_rx_queue = 0 ;
431454 uint8_t queue , socketid ;
432455 uint32_t n_tx_queue , nb_lcores , nb_mbuf ;
433456 struct ether_addr eth_addr ;
@@ -438,7 +461,7 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
438461 nb_lcores = rte_lcore_count ();
439462 n_tx_queue = nb_lcores ;
440463 if (n_tx_queue > MAX_TX_QUEUE_PER_PORT )
441- n_tx_queue = MAX_TX_QUEUE_PER_PORT ;
464+ n_tx_queue = MAX_TX_QUEUE_PER_PORT ;
442465
443466 printf ("\nStart to Init port \n" );
444467
@@ -461,9 +484,12 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
461484
462485 nb_rx_queue = ans_get_port_rx_queues_nb (portid , user_conf );
463486
464- if (max_rx_queue < nb_rx_queue )
465- max_rx_queue = nb_rx_queue ;
466-
487+ /*
488+ if(dev_info.max_rx_queues < nb_rx_queue)
489+ {
490+ rte_exit(EXIT_FAILURE, "Cannot configure not existed rxq: ""port=%d\n", portid);
491+ }
492+ */
467493 printf ("\t Creating queues: rx queue number=%d tx queue number=%u... \n" , nb_rx_queue , (unsigned )n_tx_queue );
468494
469495 ret = rte_eth_dev_configure (portid , nb_rx_queue , (uint16_t )n_tx_queue , & ans_port_conf );
@@ -482,8 +508,12 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
482508 for (lcore_id = 0 ; lcore_id < RTE_MAX_LCORE ; lcore_id ++ )
483509 {
484510 if (rte_lcore_is_enabled (lcore_id ) == 0 )
485- continue ;
486-
511+ {
512+ /* if lcore is enable, set as a invalid queue id */
513+ lcore_conf [lcore_id ].tx_queue [portid ].queue_id = INVALID_QUEUE_ID ;
514+ continue ;
515+ }
516+
487517 if (user_conf -> numa_on )
488518 socketid = (uint8_t )rte_lcore_to_socket_id (lcore_id );
489519 else
@@ -500,7 +530,7 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
500530 /* user default tx conf */
501531
502532 /* txconf = &ans_tx_conf; */
503- txconf -> txq_flags = 0 ; /* enable NIC all TX offload */
533+ txconf -> txq_flags = 0 ; /* enable NIC all TX offload, shall set it to 0 for some nic to enable hw offload */
504534
505535 printf ("\t lcore id:%u, tx queue id:%d, socket id:%d \n" , lcore_id , queueid , socketid );
506536 printf ("\t Conf-- tx pthresh:%d, tx hthresh:%d, tx wthresh:%d, txq_flags:0x%x \n" , txconf -> tx_thresh .pthresh ,
@@ -510,9 +540,14 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
510540 if (ret < 0 )
511541 rte_exit (EXIT_FAILURE , "rte_eth_tx_queue_setup: err=%d, " "port=%d\n" , ret , portid );
512542
513- lcore_conf [lcore_id ].tx_queue [portid ].queue_id = queueid ;
514543
544+ struct ans_lcore_queue * qconf = & lcore_conf [lcore_id ];
545+ qconf -> tx_queue [portid ].queue_id = queueid ;
515546 queueid ++ ;
547+
548+ qconf -> port_id [qconf -> n_tx_port ] = portid ;
549+ qconf -> n_tx_port ++ ;
550+
516551 }
517552
518553 printf ("\n" );
@@ -704,6 +739,21 @@ static inline int ans_send_packet(uint8_t port, struct rte_mbuf *m)
704739 return 0 ;
705740}
706741
742+ /**********************************************************************
743+ *@description:
744+ *
745+ *
746+ *@parameters:
747+ * [in]:
748+ * [in]:
749+ *
750+ *@return values:
751+ *
752+ **********************************************************************/
753+ uint16_t ans_tx_burst (uint16_t port_id , uint16_t queue_id , struct rte_mbuf * * tx_pkts , uint16_t nb_pkts )
754+ {
755+ return rte_eth_tx_burst (port_id , queue_id , tx_pkts , nb_pkts );
756+ }
707757/**********************************************************************
708758*@description:
709759*
@@ -763,8 +813,7 @@ static void ans_init_timer()
763813**********************************************************************/
764814static int ans_main_loop (__attribute__((unused )) void * dummy )
765815{
766- unsigned nb_ports ;
767- int i , j , nb_rx ;
816+ int i , nb_rx ;
768817 unsigned lcore_id ;
769818 uint64_t prev_tsc , diff_tsc , cur_tsc ;
770819 uint8_t portid , queueid ;
@@ -795,8 +844,7 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
795844 RTE_LOG (INFO , USER8 , " -- lcoreid=%u portid=%hhu rxqueueid=%hhu\n" , lcore_id , portid , queueid );
796845 }
797846
798- nb_ports = rte_eth_dev_count ();
799- printf ("nb ports %d hz: %ld \n" , nb_ports , rte_get_tsc_hz ());
847+ printf ("hz: %ld \n" , rte_get_tsc_hz ());
800848
801849 timer_10ms_tsc = rte_get_tsc_hz () / 100 ;
802850
@@ -835,14 +883,18 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
835883 * This could be optimized (use queueid instead of
836884 * portid), but it is not called so often
837885 */
838- for (portid = 0 ; portid < nb_ports ; portid ++ )
886+ for (i = 0 ; i < qconf -> n_tx_port ; i ++ )
839887 {
888+ portid = qconf -> port_id [i ];
889+ ans_eth_tx_flush (portid );
890+ /*
840891 tx_queue = &qconf->tx_queue[portid];
841892 if(tx_queue->pkts_nb == 0)
842893 continue;
843894
844895 ans_send_burst(portid, tx_queue->queue_id, tx_queue->pkts, tx_queue->pkts_nb);
845896 tx_queue->pkts_nb = 0;
897+ */
846898 }
847899
848900 prev_tsc = cur_tsc ;
@@ -882,7 +934,6 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
882934**********************************************************************/
883935static void ans_signal_handler (int signum )
884936{
885- int nb_ports ;
886937 if (signum == SIGINT || signum == SIGTERM )
887938 {
888939 printf ("\nSignal %d received, preparing to exit...\n" , signum );
@@ -1002,7 +1053,7 @@ int main(int argc, char **argv)
10021053 }
10031054
10041055 init_conf .ip_sync = ans_user_conf .ipsync_on ;
1005- init_conf .port_send = ans_send_packet ;
1056+ init_conf .port_send = ans_tx_burst ;
10061057 init_conf .port_bypass = ans_bypass_packet ;
10071058
10081059 ret = ans_initialize (& init_conf );
@@ -1017,7 +1068,6 @@ int main(int argc, char **argv)
10171068 uint16_t kni_id ;
10181069 struct ether_addr eth_addr ;
10191070 uint16_t qmapping_nb ;
1020- struct ans_port_qmapping qmapping [32 ];
10211071 struct rte_eth_dev_info dev_info ;
10221072
10231073 for (portid = 0 ; portid < nb_ports ; portid ++ )
@@ -1052,10 +1102,13 @@ int main(int argc, char **argv)
10521102
10531103 ans_iface_add (portid , kni_id , ifname , & eth_addr );
10541104
1055- /* set port rx queue mapping */
1056- qmapping_nb = ans_get_port_rx_qmapping (portid , 32 , qmapping , & ans_user_conf );
1105+ /* set port queue mapping */
1106+ struct ans_port_queue port_queue ;
1107+ ans_get_port_queue (portid , & port_queue , g_lcore_queue );
10571108
1058- ans_iface_set_queue (ifname , qmapping_nb , qmapping );
1109+ ret = ans_iface_set_queue (ifname , & port_queue );
1110+ if (ret != 0 )
1111+ rte_exit (EXIT_FAILURE , "set queue failed \n" );
10591112
10601113 /* host byte order */
10611114 int ip_addr = 0x0a000002 ;
0 commit comments