@@ -401,45 +401,46 @@ 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 is effective only when the actual throughput slightly exceeds the expected value.
407+ * The pad interval decreases as the measured throughput surpasses the expected rate. If the
408+ * difference is too significant, it indicates an issue. A minimum padding value of 32 is chosen
409+ * as a reasonable threshold. */
410+ if (measured_bps > rl_bps && pad_interval > 32 ) {
411+ s -> pacing .pad_interval = pad_interval ;
412+ mt_pacing_train_pad_result_add (impl , port , rl_bps , pad_interval );
413+ train_end_time = mt_get_tsc (impl );
414+ info ("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n" , __func__ ,
415+ idx , s_port , pad_interval , pkts_per_frame ,
416+ (double )(train_end_time - train_start_time ) / NS_PER_S );
417+ return 0 ;
418+ }
407419 if (measured_bps < rl_bps ) {
408- info ("%s(%d), measured bps %" PRIu64 " is lower then set bps %" PRIu64 "\n" , __func__ ,
420+ info ("%s(%d), measured bps %" PRIu64 " is lower than set bps %" PRIu64 "\n" , __func__ ,
409421 idx , (uint64_t )measured_bps , rl_bps );
422+ } else {
423+ info ("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts %d\n" ,
424+ __func__ , idx , pad_interval , pkts_per_frame , s -> st20_total_pkts );
425+ }
410426
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- }
427+ if (!mt_pacing_train_bps_result_search (impl , port , rl_bps , & bps_to_set )) {
428+ err ("%s(%d), measured speed is out of range on already trained bps\n" , __func__ , idx );
429+ return - EINVAL ;
430+ }
415431
416432/* Slightly increase the target bitrate to compensate for measurement inaccuracies,
417433 * rounding errors, and system overhead. This helps ensure the actual transmission bitrate
418434 * meets or exceeds the required rate
419435 */
420436#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 ;
437+ bps_to_set = INCREASE_BPS_FACTOR * (rl_bps * rl_bps ) / measured_bps ;
438+ info ("%s(%d), Retrain pacing with bps changed to %" PRIu64 "\n" , __func__ , idx ,
439+ bps_to_set );
440+ mt_pacing_train_bps_result_add (impl , port , rl_bps , bps_to_set );
441+ mt_txq_set_tx_bps (queue , bps_to_set );
442+ ret = tv_train_pacing (impl , s , s_port );
443+ return ret ;
443444}
444445
445446static int tv_init_pacing (struct mtl_main_impl * impl ,
0 commit comments