@@ -401,45 +401,43 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio
401401  }
402402  pkts_per_frame  =  pkts_per_frame  *  reactive ;
403403  measured_bps  =  s -> st20_pkt_size  *  pkts_per_sec  *  reactive ;
404+   pad_interval  =  (float )s -> st20_total_pkts  / (pkts_per_frame  -  s -> st20_total_pkts );
404405
405-   /* If the measured speed is lower than expected. Set higher bps and retrain to add 
406-    * padding */ 
406+   /* padding can only help if the actual throughput is slightly higher than expected. */ 
407+   if  (measured_bps  >  rl_bps  &&  pad_interval  >  32 ) {
408+     s -> pacing .pad_interval  =  pad_interval ;
409+     mt_pacing_train_pad_result_add (impl , port , rl_bps , pad_interval );
410+     train_end_time  =  mt_get_tsc (impl );
411+     info ("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n" , __func__ ,
412+          idx , s_port , pad_interval , pkts_per_frame ,
413+          (double )(train_end_time  -  train_start_time ) / NS_PER_S );
414+     return  0 ;
415+   }
407416  if  (measured_bps  <  rl_bps ) {
408-     info ("%s(%d), measured bps %"  PRIu64  " is lower then  set bps %"  PRIu64  "\n" , __func__ ,
417+     info ("%s(%d), measured bps %"  PRIu64  " is lower than  set bps %"  PRIu64  "\n" , __func__ ,
409418         idx , (uint64_t )measured_bps , rl_bps );
419+   } else  {
420+     info ("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts %d\n" ,
421+          __func__ , idx , pad_interval , pkts_per_frame , s -> st20_total_pkts );
422+   }
410423
411-      if  (!mt_pacing_train_bps_result_search (impl , port , rl_bps , & bps_to_set )) {
412-        err ("%s(%d), measured speed is too low  on already trained bps\n" , __func__ , idx );
413-        return  - EINVAL ;
414-      }
424+   if  (!mt_pacing_train_bps_result_search (impl , port , rl_bps , & bps_to_set )) {
425+     err ("%s(%d), measured speed is out of range  on already trained bps\n" , __func__ , idx );
426+     return  - EINVAL ;
427+   }
415428
416429/* Slightly increase the target bitrate to compensate for measurement inaccuracies, 
417430 * rounding errors, and system overhead. This helps ensure the actual transmission bitrate 
418431 * meets or exceeds the required rate 
419432 */ 
420433#define  INCREASE_BPS_FACTOR  1.005
421-     bps_to_set  =  INCREASE_BPS_FACTOR  *  (rl_bps  *  rl_bps ) / measured_bps ;
422-     info ("%s(%d), increase bps to %"  PRIu64  "\n" , __func__ , idx , bps_to_set );
423-     mt_pacing_train_bps_result_add (impl , port , rl_bps , bps_to_set );
424-     mt_txq_set_tx_bps (queue , bps_to_set );
425-     ret  =  tv_train_pacing (impl , s , s_port );
426-     return  ret ;
427-   }
428- 
429-   pad_interval  =  (float )s -> st20_total_pkts  / (pkts_per_frame  -  s -> st20_total_pkts );
430-   if  (pad_interval  <  32 ) {
431-     err ("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts %d\n" ,
432-         __func__ , idx , pad_interval , pkts_per_frame , s -> st20_total_pkts );
433-     return  - EINVAL ;
434-   }
435- 
436-   s -> pacing .pad_interval  =  pad_interval ;
437-   mt_pacing_train_pad_result_add (impl , port , rl_bps , pad_interval );
438-   train_end_time  =  mt_get_tsc (impl );
439-   info ("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n" , __func__ ,
440-        idx , s_port , pad_interval , pkts_per_frame ,
441-        (double )(train_end_time  -  train_start_time ) / NS_PER_S );
442-   return  0 ;
434+   bps_to_set  =  INCREASE_BPS_FACTOR  *  (rl_bps  *  rl_bps ) / measured_bps ;
435+   info ("%s(%d), Retrain pacing with bps changed to %"  PRIu64  "\n" , __func__ , idx ,
436+        bps_to_set );
437+   mt_pacing_train_bps_result_add (impl , port , rl_bps , bps_to_set );
438+   mt_txq_set_tx_bps (queue , bps_to_set );
439+   ret  =  tv_train_pacing (impl , s , s_port );
440+   return  ret ;
443441}
444442
445443static  int  tv_init_pacing (struct  mtl_main_impl *  impl ,
0 commit comments