Skip to content

Commit

Permalink
st2110: add tasklet time measure for session level (#676)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx authored Dec 29, 2023
1 parent 38ba225 commit a868967
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 134 deletions.
7 changes: 7 additions & 0 deletions lib/src/mt_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ struct mt_udp_hdr {
struct rte_udp_hdr udp; /* size: 8 */
} __attribute__((__packed__)) __rte_aligned(2);

struct mt_stat_u64 {
uint64_t max;
uint64_t min;
uint64_t cnt;
uint64_t sum;
};

#endif
6 changes: 2 additions & 4 deletions lib/src/mt_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,8 @@ struct mt_sch_tasklet_impl {
bool request_exit;
bool ack_exit;

uint64_t stat_max_time_ns;
uint64_t stat_sum_time_ns;
uint64_t stat_time_cnt;
uint64_t stat_min_time_ns;
/* for time measure */
struct mt_stat_u64 stat_time;
};

enum mt_sch_type {
Expand Down
27 changes: 8 additions & 19 deletions lib/src/mt_sch.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,8 @@ static int sch_tasklet_func(void* args) {
if (time_measure) tsc_s = mt_get_tsc(impl);
pending += ops->handler(ops->priv);
if (time_measure) {
uint32_t delta_ns = mt_get_tsc(impl) - tsc_s;
tasklet->stat_max_time_ns = RTE_MAX(tasklet->stat_max_time_ns, delta_ns);
tasklet->stat_min_time_ns = RTE_MIN(tasklet->stat_min_time_ns, delta_ns);
tasklet->stat_sum_time_ns += delta_ns;
tasklet->stat_time_cnt++;
uint64_t delta_ns = mt_get_tsc(impl) - tsc_s;
mt_stat_u64_update(&tasklet->stat_time, delta_ns);
}
}
if (sch->allow_sleep && (pending == MTL_TASKLET_ALL_DONE)) {
Expand Down Expand Up @@ -372,19 +369,11 @@ static bool sch_is_capable(struct mtl_sch_impl* sch, int quota_mbs,
return true;
}

static void sch_tasklet_stat_clear(struct mt_sch_tasklet_impl* tasklet) {
tasklet->stat_max_time_ns = 0;
tasklet->stat_min_time_ns = (uint64_t)-1;
tasklet->stat_sum_time_ns = 0;
tasklet->stat_time_cnt = 0;
}

static int sch_stat(void* priv) {
struct mtl_sch_impl* sch = priv;
int num_tasklet = sch->max_tasklet_idx;
struct mt_sch_tasklet_impl* tasklet;
int idx = sch->idx;
uint64_t avg_ns;

if (!mt_sch_is_active(sch)) return 0;

Expand All @@ -396,14 +385,14 @@ static int sch_stat(void* priv) {
if (!tasklet) continue;

dbg("SCH(%d): tasklet %s at %d\n", idx, tasklet->name, i);
if (tasklet->stat_time_cnt) {
avg_ns = tasklet->stat_sum_time_ns / tasklet->stat_time_cnt;
struct mt_stat_u64* stat_time = &tasklet->stat_time;
if (stat_time->cnt) {
uint64_t avg_ns = stat_time->sum / stat_time->cnt;
notice("SCH(%d,%d): tasklet %s, avg %.2fus max %.2fus min %.2fus\n", idx, i,
tasklet->name, (float)avg_ns / NS_PER_US,
(float)tasklet->stat_max_time_ns / NS_PER_US,
(float)tasklet->stat_min_time_ns / NS_PER_US);
sch_tasklet_stat_clear(tasklet);
(float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US);
}
mt_stat_u64_init(stat_time);
}
}

Expand Down Expand Up @@ -802,7 +791,7 @@ mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl* sch,
snprintf(tasklet->name, ST_MAX_NAME_LEN - 1, "%s", tasklet_ops->name);
tasklet->sch = sch;
tasklet->idx = i;
sch_tasklet_stat_clear(tasklet);
mt_stat_u64_init(&tasklet->stat_time);

sch->tasklet[i] = tasklet;
sch->max_tasklet_idx = RTE_MAX(sch->max_tasklet_idx, i + 1);
Expand Down
14 changes: 14 additions & 0 deletions lib/src/mt_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,18 @@ int mt_sysfs_write_uint32(const char* path, uint32_t value);

uint32_t mt_softrss(uint32_t* input_tuple, uint32_t input_len);

static inline void mt_stat_u64_init(struct mt_stat_u64* stat) {
stat->max = 0;
stat->min = (uint64_t)-1;
stat->sum = 0;
stat->cnt = 0;
}

static inline void mt_stat_u64_update(struct mt_stat_u64* stat, uint64_t new) {
stat->max = RTE_MAX(stat->max, new);
stat->min = RTE_MIN(stat->min, new);
stat->sum += new;
stat->cnt++;
}

#endif
17 changes: 13 additions & 4 deletions lib/src/st2110/st_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ struct st_tx_video_session_impl {
uint32_t stat_interlace_second_field;
/* for display */
double stat_cpu_busy_score;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_tx_video_sessions_mgr {
Expand Down Expand Up @@ -740,6 +742,8 @@ struct st_rx_video_session_impl {
uint32_t stat_st22_boxes;
/* for stat display */
double stat_cpu_busy_score;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_rx_video_sessions_mgr {
Expand All @@ -748,8 +752,6 @@ struct st_rx_video_sessions_mgr {
int max_idx; /* max session index */
/* pkt rx task */
struct mt_sch_tasklet_impl* pkt_rx_tasklet;
/* control task */
struct mt_sch_tasklet_impl* ctl_tasklet;

struct st_rx_video_session_impl* sessions[ST_SCH_MAX_RX_VIDEO_SESSIONS];
/* protect session, spin(fast) lock as it call from tasklet aslo */
Expand Down Expand Up @@ -842,14 +844,15 @@ struct st_tx_audio_session_impl {
uint32_t stat_max_notify_frame_us;
uint32_t stat_unrecoverable_error;
uint32_t stat_recoverable_error;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_tx_audio_sessions_mgr {
struct mtl_main_impl* parent;
int idx; /* index for current sessions mgr */
int max_idx; /* max session index */
struct mt_sch_tasklet_impl* tasklet_build;
struct mt_sch_tasklet_impl* tasklet_trans;
struct mt_sch_tasklet_impl* tasklet;

/* all audio sessions share same ring/queue */
struct rte_ring* ring[MTL_PORT_MAX];
Expand Down Expand Up @@ -962,6 +965,8 @@ struct st_rx_audio_session_impl {
int st30_stat_pkts_rtp_ring_full;
uint64_t st30_stat_last_time;
uint32_t stat_max_notify_frame_us;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_rx_audio_sessions_mgr {
Expand Down Expand Up @@ -1046,6 +1051,8 @@ struct st_tx_ancillary_session_impl {
uint64_t stat_last_time;
uint32_t stat_max_next_frame_us;
uint32_t stat_max_notify_frame_us;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_tx_ancillary_sessions_mgr {
Expand Down Expand Up @@ -1098,6 +1105,8 @@ struct st_rx_ancillary_session_impl {
int st40_stat_pkts_received;
uint64_t st40_stat_last_time;
uint32_t stat_max_notify_rtp_us;
/* for tasklet session time measure */
struct mt_stat_u64 stat_time;
};

struct st_rx_ancillary_sessions_mgr {
Expand Down
22 changes: 21 additions & 1 deletion lib/src/st2110/st_rx_ancillary_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,22 @@ static int rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl* s)

static int rx_ancillary_sessions_tasklet_handler(void* priv) {
struct st_rx_ancillary_sessions_mgr* mgr = priv;
struct mtl_main_impl* impl = mgr->parent;
struct st_rx_ancillary_session_impl* s;
int pending = MTL_TASKLET_ALL_DONE;
uint64_t tsc_s = 0;

for (int sidx = 0; sidx < mgr->max_idx; sidx++) {
s = rx_ancillary_session_try_get(mgr, sidx);
if (!s) continue;
if (s->time_measure) tsc_s = mt_get_tsc(impl);

pending += rx_ancillary_session_tasklet(s);

if (s->time_measure) {
uint64_t delta_ns = mt_get_tsc(impl) - tsc_s;
mt_stat_u64_update(&s->stat_time, delta_ns);
}
rx_ancillary_session_put(mgr, sidx);
}

Expand Down Expand Up @@ -361,6 +369,7 @@ static int rx_ancillary_session_attach(struct mtl_main_impl* impl,
s->st40_stat_pkts_dropped = 0;
s->st40_stat_last_time = mt_get_monotonic_time();
rte_atomic32_set(&s->st40_stat_frames_received, 0);
mt_stat_u64_init(&s->stat_time);

ret = rx_ancillary_session_init_hw(impl, s);
if (ret < 0) {
Expand Down Expand Up @@ -417,7 +426,18 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl* s) {
s->st40_stat_pkts_wrong_ssrc_dropped = 0;
}
if (s->time_measure) {
notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, s->stat_max_notify_rtp_us);
struct mt_stat_u64* stat_time = &s->stat_time;
if (stat_time->cnt) {
uint64_t avg_ns = stat_time->sum / stat_time->cnt;
notice("RX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", idx,
(float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US,
(float)stat_time->min / NS_PER_US);
}
mt_stat_u64_init(stat_time);

if (s->stat_max_notify_rtp_us > 8) {
notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, s->stat_max_notify_rtp_us);
}
s->stat_max_notify_rtp_us = 0;
}
}
Expand Down
24 changes: 22 additions & 2 deletions lib/src/st2110/st_rx_audio_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,22 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) {

static int rx_audio_sessions_tasklet_handler(void* priv) {
struct st_rx_audio_sessions_mgr* mgr = priv;
struct mtl_main_impl* impl = mgr->parent;
struct st_rx_audio_session_impl* s;
int pending = MTL_TASKLET_ALL_DONE;
uint64_t tsc_s = 0;

for (int sidx = 0; sidx < mgr->max_idx; sidx++) {
s = rx_audio_session_try_get(mgr, sidx);
if (!s) continue;
if (s->time_measure) tsc_s = mt_get_tsc(impl);

pending += rx_audio_session_tasklet(s);

if (s->time_measure) {
uint64_t delta_ns = mt_get_tsc(impl) - tsc_s;
mt_stat_u64_update(&s->stat_time, delta_ns);
}
rx_audio_session_put(mgr, sidx);
}

Expand Down Expand Up @@ -609,6 +617,7 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl,
s->st30_stat_frames_dropped = 0;
rte_atomic32_set(&s->st30_stat_frames_received, 0);
s->st30_stat_last_time = mt_get_monotonic_time();
mt_stat_u64_init(&s->stat_time);

if (s->ops.flags & ST30_RX_FLAG_ENABLE_TIMING_PARSER) {
info("%s(%d), enable the timing analyze\n", __func__, idx);
Expand Down Expand Up @@ -689,8 +698,19 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr,
s->st30_stat_pkts_len_mismatch_dropped = 0;
}
if (s->time_measure) {
notice("RX_AUDIO_SESSION(%d,%d): notify frame max %uus\n", m_idx, idx,
s->stat_max_notify_frame_us);
struct mt_stat_u64* stat_time = &s->stat_time;
if (stat_time->cnt) {
uint64_t avg_ns = stat_time->sum / stat_time->cnt;
notice("RX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min %.2fus\n",
m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US,
(float)stat_time->min / NS_PER_US);
}
mt_stat_u64_init(stat_time);

if (s->stat_max_notify_frame_us > 8) {
notice("RX_AUDIO_SESSION(%d,%d): notify frame max %uus\n", m_idx, idx,
s->stat_max_notify_frame_us);
}
s->stat_max_notify_frame_us = 0;
}

Expand Down
Loading

0 comments on commit a868967

Please sign in to comment.