@@ -380,6 +380,7 @@ static uint8_t ans_get_port_rx_queues_nb(const uint8_t port, struct ans_user_con
380
380
}
381
381
return (uint8_t )(++ queue );
382
382
}
383
+
383
384
/**********************************************************************
384
385
*@description:
385
386
*
@@ -391,24 +392,47 @@ static uint8_t ans_get_port_rx_queues_nb(const uint8_t port, struct ans_user_con
391
392
*@return values:
392
393
*
393
394
**********************************************************************/
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 )
395
396
{
396
397
uint16_t i ;
397
- uint8_t queue_nb = 0 ;
398
+ uint8_t lcore_id ;
399
+ struct ans_lcore_queue * lcore_queue ;
398
400
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 ++ )
400
405
{
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 )
402
424
{
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 ++ ;
406
428
}
429
+
407
430
}
408
431
409
- return ( queue_nb ) ;
432
+ return ;
410
433
}
411
434
435
+
412
436
/**********************************************************************
413
437
*@description:
414
438
*
@@ -427,7 +451,6 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
427
451
uint16_t queueid ;
428
452
unsigned lcore_id ;
429
453
uint8_t nb_rx_queue = 0 ;
430
- uint8_t max_rx_queue = 0 ;
431
454
uint8_t queue , socketid ;
432
455
uint32_t n_tx_queue , nb_lcores , nb_mbuf ;
433
456
struct ether_addr eth_addr ;
@@ -438,7 +461,7 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
438
461
nb_lcores = rte_lcore_count ();
439
462
n_tx_queue = nb_lcores ;
440
463
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 ;
442
465
443
466
printf ("\nStart to Init port \n" );
444
467
@@ -461,9 +484,12 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
461
484
462
485
nb_rx_queue = ans_get_port_rx_queues_nb (portid , user_conf );
463
486
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
+ */
467
493
printf ("\t Creating queues: rx queue number=%d tx queue number=%u... \n" , nb_rx_queue , (unsigned )n_tx_queue );
468
494
469
495
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
482
508
for (lcore_id = 0 ; lcore_id < RTE_MAX_LCORE ; lcore_id ++ )
483
509
{
484
510
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
+
487
517
if (user_conf -> numa_on )
488
518
socketid = (uint8_t )rte_lcore_to_socket_id (lcore_id );
489
519
else
@@ -500,7 +530,7 @@ static int ans_init_ports(unsigned short nb_ports, struct ans_user_config *user
500
530
/* user default tx conf */
501
531
502
532
/* 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 */
504
534
505
535
printf ("\t lcore id:%u, tx queue id:%d, socket id:%d \n" , lcore_id , queueid , socketid );
506
536
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
510
540
if (ret < 0 )
511
541
rte_exit (EXIT_FAILURE , "rte_eth_tx_queue_setup: err=%d, " "port=%d\n" , ret , portid );
512
542
513
- lcore_conf [lcore_id ].tx_queue [portid ].queue_id = queueid ;
514
543
544
+ struct ans_lcore_queue * qconf = & lcore_conf [lcore_id ];
545
+ qconf -> tx_queue [portid ].queue_id = queueid ;
515
546
queueid ++ ;
547
+
548
+ qconf -> port_id [qconf -> n_tx_port ] = portid ;
549
+ qconf -> n_tx_port ++ ;
550
+
516
551
}
517
552
518
553
printf ("\n" );
@@ -704,6 +739,21 @@ static inline int ans_send_packet(uint8_t port, struct rte_mbuf *m)
704
739
return 0 ;
705
740
}
706
741
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
+ }
707
757
/**********************************************************************
708
758
*@description:
709
759
*
@@ -763,8 +813,7 @@ static void ans_init_timer()
763
813
**********************************************************************/
764
814
static int ans_main_loop (__attribute__((unused )) void * dummy )
765
815
{
766
- unsigned nb_ports ;
767
- int i , j , nb_rx ;
816
+ int i , nb_rx ;
768
817
unsigned lcore_id ;
769
818
uint64_t prev_tsc , diff_tsc , cur_tsc ;
770
819
uint8_t portid , queueid ;
@@ -795,8 +844,7 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
795
844
RTE_LOG (INFO , USER8 , " -- lcoreid=%u portid=%hhu rxqueueid=%hhu\n" , lcore_id , portid , queueid );
796
845
}
797
846
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 ());
800
848
801
849
timer_10ms_tsc = rte_get_tsc_hz () / 100 ;
802
850
@@ -835,14 +883,18 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
835
883
* This could be optimized (use queueid instead of
836
884
* portid), but it is not called so often
837
885
*/
838
- for (portid = 0 ; portid < nb_ports ; portid ++ )
886
+ for (i = 0 ; i < qconf -> n_tx_port ; i ++ )
839
887
{
888
+ portid = qconf -> port_id [i ];
889
+ ans_eth_tx_flush (portid );
890
+ /*
840
891
tx_queue = &qconf->tx_queue[portid];
841
892
if(tx_queue->pkts_nb == 0)
842
893
continue;
843
894
844
895
ans_send_burst(portid, tx_queue->queue_id, tx_queue->pkts, tx_queue->pkts_nb);
845
896
tx_queue->pkts_nb = 0;
897
+ */
846
898
}
847
899
848
900
prev_tsc = cur_tsc ;
@@ -882,7 +934,6 @@ static int ans_main_loop(__attribute__((unused)) void *dummy)
882
934
**********************************************************************/
883
935
static void ans_signal_handler (int signum )
884
936
{
885
- int nb_ports ;
886
937
if (signum == SIGINT || signum == SIGTERM )
887
938
{
888
939
printf ("\nSignal %d received, preparing to exit...\n" , signum );
@@ -1002,7 +1053,7 @@ int main(int argc, char **argv)
1002
1053
}
1003
1054
1004
1055
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 ;
1006
1057
init_conf .port_bypass = ans_bypass_packet ;
1007
1058
1008
1059
ret = ans_initialize (& init_conf );
@@ -1017,7 +1068,6 @@ int main(int argc, char **argv)
1017
1068
uint16_t kni_id ;
1018
1069
struct ether_addr eth_addr ;
1019
1070
uint16_t qmapping_nb ;
1020
- struct ans_port_qmapping qmapping [32 ];
1021
1071
struct rte_eth_dev_info dev_info ;
1022
1072
1023
1073
for (portid = 0 ; portid < nb_ports ; portid ++ )
@@ -1052,10 +1102,13 @@ int main(int argc, char **argv)
1052
1102
1053
1103
ans_iface_add (portid , kni_id , ifname , & eth_addr );
1054
1104
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 );
1057
1108
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" );
1059
1112
1060
1113
/* host byte order */
1061
1114
int ip_addr = 0x0a000002 ;
0 commit comments