diff --git a/lib/src/dev/mt_dev.c b/lib/src/dev/mt_dev.c index d0fb8913d..385bb6896 100644 --- a/lib/src/dev/mt_dev.c +++ b/lib/src/dev/mt_dev.c @@ -199,6 +199,8 @@ static int dev_inf_get_stat_dpdk(struct mt_interface* inf) { stat_update_dpdk(stats_sum, &stats, drv_type); struct mtl_port_status* port_stats = &inf->user_stats_port; stat_update_dpdk(port_stats, &stats, drv_type); + struct mtl_port_status* stats_admin = &inf->stats_admin; + stat_update_dpdk(stats_admin, &stats, drv_type); if (!dev_stats_not_reset) { dbg("%s(%d), reset eth status\n", __func__, port); @@ -229,6 +231,9 @@ static int dev_inf_get_stat_sw(struct mt_interface* inf) { stat_update_sw(stats_sum, stats); struct mtl_port_status* port_stats = &inf->user_stats_port; stat_update_sw(port_stats, stats); + struct mtl_port_status* stats_admin = &inf->stats_admin; + stat_update_sw(stats_admin, stats); + memset(stats, 0, sizeof(*stats)); rte_spinlock_unlock(&inf->stats_lock); @@ -2385,6 +2390,38 @@ int mt_dev_tsc_done_action(struct mtl_main_impl* impl) { return 0; } +int mt_update_admin_port_stats(struct mtl_main_impl* impl) { + int num_ports = mt_num_ports(impl); + + for (int port = 0; port < num_ports; port++) { + struct mt_interface* inf = mt_if(impl, port); + dev_inf_get_stat(inf); + } + return 0; +} + +int mt_reset_admin_port_stats(struct mtl_main_impl* impl) { + int num_ports = mt_num_ports(impl); + + for (int port = 0; port < num_ports; port++) { + struct mt_interface* inf = mt_if(impl, port); + memset(&inf->stats_admin, 0, sizeof(inf->stats_admin)); + } + return 0; +} + +int mt_read_admin_port_stats(struct mtl_main_impl* impl, enum mtl_port port, + struct mtl_port_status* stats) { + if (port >= mt_num_ports(impl)) { + err("%s, invalid port %d\n", __func__, port); + return -EIO; + } + + struct mt_interface* inf = mt_if(impl, port); + memcpy(stats, &inf->stats_admin, sizeof(*stats)); + return 0; +} + int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status* stats) { struct mtl_main_impl* impl = mt; diff --git a/lib/src/dev/mt_dev.h b/lib/src/dev/mt_dev.h index 00dcf8c8b..48245ff31 100644 --- a/lib/src/dev/mt_dev.h +++ b/lib/src/dev/mt_dev.h @@ -71,4 +71,9 @@ int mt_dev_tsc_done_action(struct mtl_main_impl* impl); uint16_t mt_dev_rss_hash_queue(struct mtl_main_impl* impl, enum mtl_port port, uint32_t hash); +int mt_update_admin_port_stats(struct mtl_main_impl* impl); +int mt_read_admin_port_stats(struct mtl_main_impl* impl, enum mtl_port port, + struct mtl_port_status* stats); +int mt_reset_admin_port_stats(struct mtl_main_impl* impl); + #endif diff --git a/lib/src/mt_admin.c b/lib/src/mt_admin.c index 04d715141..9156bf4a4 100644 --- a/lib/src/mt_admin.c +++ b/lib/src/mt_admin.c @@ -331,9 +331,10 @@ static void admin_alarm_handler(void* param) { static int admin_func(struct mtl_main_impl* impl) { struct mt_admin* admin = mt_get_admin(impl); - dbg("%s, start\n", __func__); + mt_update_admin_port_stats(impl); + admin_cal_cpu_busy(impl); bool migrated = false; @@ -349,6 +350,8 @@ static int admin_func(struct mtl_main_impl* impl) { rte_eal_alarm_set(admin->period_us, admin_alarm_handler, impl); + mt_reset_admin_port_stats(impl); + return 0; } diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index 6bd7cbfa0..df97b8b80 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -696,6 +696,7 @@ struct mt_interface { struct mtl_port_status* dev_stats_sw; /* for MT_DRV_F_NOT_DPDK_PMD */ struct mtl_port_status stats_sum; /* for dev_inf_stat dump */ struct mtl_port_status user_stats_port; /* for mtl_get_port_stats */ + struct mtl_port_status stats_admin; /* stats used in admin task */ uint64_t simulate_malicious_pkt_tsc; diff --git a/lib/src/st2110/st_rx_video_session.c b/lib/src/st2110/st_rx_video_session.c index f7dc95c0b..c75fe91e4 100644 --- a/lib/src/st2110/st_rx_video_session.c +++ b/lib/src/st2110/st_rx_video_session.c @@ -3126,7 +3126,7 @@ void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl* s) { void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, struct st_rx_video_session_impl* s) { uint64_t avg_ns_per_loop = mt_sch_avg_ns_loop(sch); - /* aussme one taskelt can bulk 3 pkts */ + /* assume one taskelt can bulk 3 pkts */ s->cpu_busy_score = (double)avg_ns_per_loop / 3 / s->trs * 100.0; dbg("%s(%d), avg_ns_per_loop %" PRIu64 ", trs %f, busy %f\n", __func__, s->idx, avg_ns_per_loop, s->trs, s->cpu_busy_score); @@ -3139,13 +3139,12 @@ void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, enum mtl_port port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); struct mtl_port_status stats; memset(&stats, 0, sizeof(stats)); - mtl_get_port_stats(s->impl, port, &stats); + mt_read_admin_port_stats(s->impl, port, &stats); if (stats.rx_hw_dropped_packets) { dbg("%s(%d,%d), incomplete %d and hw_dropped_pkts %" PRIu64 "\n", __func__, sch->idx, s->idx, incomplete_frame_cnt, stats.rx_hw_dropped_packets); s->imiss_busy_score += 40.0; } - mtl_reset_port_stats(s->impl, port); if (s->imiss_busy_score > 95.0) { notice("%s(%d,%d), imiss busy, incomplete %d and hw_dropped_pkts %" PRIu64 "\n", __func__, sch->idx, s->idx, incomplete_frame_cnt,