@@ -94,6 +94,11 @@ var unsupportedQueue2IrqDrivers = []string{
9494 "xsc" ,
9595}
9696
97+ const (
98+ gveNicQueueFilter = "gve-ntfy-blk"
99+ gveNicQueueDelimeter = "@"
100+ )
101+
97102var ErrUnsupportedNicIrq2Queue = errors .New ("unsupported nic irq to queue mapping" )
98103
99104var netnsMutex sync.Mutex
@@ -555,6 +560,84 @@ func GetNicTxQueuesXpsConf(nic *NicBasicInfo) (map[int]string, error) {
555560 return txQueuesXpsConf , nil
556561}
557562
563+ func getGVENicQueue2Irq (nicInfo * NicBasicInfo ) (map [int ]int , map [int ]int , error ) {
564+ if len (nicInfo .Irqs ) < nicInfo .QueueNum * 2 {
565+ return nil , nil , fmt .Errorf ("%s total irqs count(%d) of all irqs %+v less than 2 * queueNum(%d)" ,
566+ nicInfo , len (nicInfo .Irqs ), nicInfo .Irqs , nicInfo .QueueNum )
567+ }
568+ nicAllIrqs := sets .NewInt (nicInfo .Irqs ... )
569+
570+ b , err := os .ReadFile (InterruptsFile )
571+ if err != nil {
572+ return nil , nil , fmt .Errorf ("failed to ReadFile(%s), err %s" , InterruptsFile , err )
573+ }
574+
575+ lines := strings .Split (string (b ), "\n " )
576+ queue2Irq := make (map [int ]int )
577+
578+ for _ , line := range lines {
579+ if len (line ) == 0 {
580+ continue
581+ }
582+
583+ cols := strings .Fields (line )
584+ if len (cols ) == 0 {
585+ continue
586+ }
587+
588+ irq , err := strconv .Atoi (strings .TrimSuffix (cols [0 ], ":" ))
589+ if err != nil {
590+ klog .Warningf ("failed to parse irq number, err %s" , err )
591+ continue
592+ }
593+
594+ if ! nicAllIrqs .Has (irq ) {
595+ continue
596+ }
597+
598+ queueStr := cols [len (cols )- 1 ]
599+ if ! strings .Contains (queueStr , gveNicQueueFilter ) {
600+ continue
601+ }
602+
603+ queueCols := strings .Split (queueStr , gveNicQueueDelimeter )
604+ if len (queueCols ) < 2 {
605+ continue
606+ }
607+
608+ queue , err := strconv .Atoi (strings .TrimPrefix (queueCols [0 ], gveNicQueueFilter ))
609+ if err != nil {
610+ continue
611+ }
612+
613+ queue2Irq [queue ] = irq
614+ }
615+
616+ if len (queue2Irq ) < nicInfo .QueueNum * 2 {
617+ return nil , nil , fmt .Errorf ("%s total count (%d) of tx/rx irqs %+v is not equal to 2 * queueNum(%d)" ,
618+ nicInfo , len (queue2Irq ), queue2Irq , nicInfo .QueueNum )
619+ }
620+
621+ txQueue2Irq := make (map [int ]int )
622+ rxQueue2Irq := make (map [int ]int )
623+ firstRxQueueIndex := len (queue2Irq ) / 2
624+
625+ for queue , irq := range queue2Irq {
626+ // low half are tx queues, high half are rx queues,
627+ // refer to gve_tx_idx_to_ntfy, gve_rx_idx_to_ntfy, gve_tx_add_to_block, gve_rx_add_to_block, gve_napi_poll functions
628+ // from https://code.byted.org/data-system-ste/compute-virtual-ethernet-linux/tree/master/usr/src/gve-1.4.9+byted1
629+ // and gve nic shrinked queues's irqs still exist in /proc/interrupts, e.g., when nic's queue number changed from 32 to 16,
630+ // nic's original 32 queues's irqs still exist in /proc/interrupts
631+ if queue < nicInfo .QueueNum {
632+ txQueue2Irq [queue ] = irq
633+ } else if queue >= firstRxQueueIndex && queue < firstRxQueueIndex + nicInfo .QueueNum {
634+ rxQueue2Irq [queue - firstRxQueueIndex ] = irq
635+ }
636+ }
637+
638+ return rxQueue2Irq , txQueue2Irq , nil
639+ }
640+
558641func isUnsupportedNicQueue2Irq (nic * NicBasicInfo ) bool {
559642 if nic == nil {
560643 return false
@@ -712,6 +795,10 @@ func GetNicQueue2IrqWithQueueFilter(nicInfo *NicBasicInfo, queueFilters []string
712795
713796// GetNicQueue2Irq get nic queue naming in /proc/interrrupts
714797func GetNicQueue2Irq (nicInfo * NicBasicInfo ) (map [int ]int , map [int ]int , error ) {
798+ if strings .HasPrefix (nicInfo .Driver , NicDriverGVE ) {
799+ return getGVENicQueue2Irq (nicInfo )
800+ }
801+
715802 if nicInfo .IsVirtioNetDev {
716803 queueFilter := fmt .Sprintf ("%s-input" , nicInfo .VirtioNetName )
717804 queueDelimeter := "."
@@ -910,6 +997,9 @@ func GetNicQueuesCount(nicName string) (int, error) {
910997 return - 1 , fmt .Errorf ("ioctl SIOCETHTOOL failed: %v" , errno )
911998 }
912999
1000+ if ec .CombinedCount == 0 {
1001+ return int (ec .RxCount ), nil
1002+ }
9131003 return int (ec .CombinedCount ), nil
9141004}
9151005
0 commit comments