diff options
| author | 杨威 <[email protected]> | 2023-06-30 20:53:48 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-06-30 22:35:53 +0800 |
| commit | 1d2c42ee129184237c877b49e5e8cc42ac4c8d60 (patch) | |
| tree | 1d17077c9caaa9f59e60824303f7010061fc8ca5 /src | |
| parent | 791860229367b7e7b0513d14553767d512579254 (diff) | |
🦄 refactor(marsio4_worker): 重构调用polling_stream_timeout逻辑,减少1s内的重复调用
Diffstat (limited to 'src')
| -rw-r--r-- | src/dealpkt/plug_support.c | 5 | ||||
| -rw-r--r-- | src/dealpkt/stream_manage.c | 71 | ||||
| -rw-r--r-- | src/packet_io/packet_io_marsio.c | 43 |
3 files changed, 70 insertions, 49 deletions
diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index a6c068d..d6d0afa 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -1932,7 +1932,10 @@ long long sapp_random(void) int sapp_usleep(int usec)
{
struct timespec sleep_time_val;
-
+ if(unlikely (usec <= 0))
+ {
+ return 0;
+ }
sleep_time_val.tv_sec = 0;
sleep_time_val.tv_nsec = usec * 1000;
diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c index 717c24c..359298e 100644 --- a/src/dealpkt/stream_manage.c +++ b/src/dealpkt/stream_manage.c @@ -336,6 +336,7 @@ void streamaddlist(struct streamindex *pindex,struct stream_list *plist) { timeouts_update(plist->streamindex_timer, g_CurrentTime); plist->last_update_timer_s = g_CurrentTime; + plist->interval_to_next_timeout_s=timeouts_timeout(plist->streamindex_timer); } struct timeout *t = timeouts_get(plist->streamindex_timer); if(t == NULL) @@ -432,6 +433,7 @@ extern int call_streamentry(struct streaminfo *a_stream, const void *this_iphdr, int del_stream_by_time(struct stream_list *plist, const struct streamindex *current_drive_index, int thread_id) { int ret = 0; + struct timeout *t=NULL; struct global_stream *g_stream = G_MESA_GLOBAL_STREAM[thread_id]; if(unlikely(plist->last_update_timer_s < g_CurrentTime)) { @@ -439,42 +441,47 @@ int del_stream_by_time(struct stream_list *plist, const struct streamindex *curr if(g_stream->user_define_timer_cnt > 0) { timeouts_update(g_stream->user_define_timer, g_CurrentTime); + g_stream->interval_to_next_timeout_s = timeouts_timeout(g_stream->user_define_timer); } plist->last_update_timer_s = g_CurrentTime; + plist->interval_to_next_timeout_s=timeouts_timeout(plist->streamindex_timer); } - struct timeout *t = timeouts_get(plist->streamindex_timer); - if (t != NULL) + if (plist->interval_to_next_timeout_s == 0) { - struct streamindex *pindex = (struct streamindex *)sapp_get_struct_header(t, struct streamindex, timeout); - struct streaminfo_private *pstream_pr = &(pindex->stream); - struct streaminfo *pstream = &(pstream_pr->stream_public); - - if (pindex == current_drive_index) - { /* ��ǰ�����ڵ�����ʱ, ˵��֮ǰ�ܳ�ʱ��û�а�����, ��ʱ����free, ���Ƿ���1, �ٵ���reset */ - if (STREAM_TYPE_TCP == pstream->type) - { - /* 2016-12-15 lijia add, ��ʱreset֮ǰ, ��Ҫ����link_state */ - ((struct tcpdetail_private *)(pstream->pdetail))->link_state = STREAM_LINK_TIMEOUT; - } - ret = 1; - } - else - { - if (STREAM_TYPE_TCP == pstream->type) - { - ((struct tcpdetail_private *)(pstream->pdetail))->link_state = STREAM_LINK_TIMEOUT; - tcp_free_stream(pindex, NULL, NULL, NULL); - ret = 2; - } - else - { - pstream_pr->stream_close_reason = STREAM_CLOSE_REASON_TIMEOUT; - udp_free_stream(pindex); - ret = 2; - } - } - } - if(g_stream->user_define_timer_cnt > 0) + t = timeouts_get(plist->streamindex_timer); + if (t != NULL) + { + struct streamindex *pindex = (struct streamindex *)sapp_get_struct_header(t, struct streamindex, timeout); + struct streaminfo_private *pstream_pr = &(pindex->stream); + struct streaminfo *pstream = &(pstream_pr->stream_public); + + if (pindex == current_drive_index) + { /* ��ǰ�����ڵ�����ʱ, ˵��֮ǰ�ܳ�ʱ��û�а�����, ��ʱ����free, ���Ƿ���1, �ٵ���reset */ + if (STREAM_TYPE_TCP == pstream->type) + { + /* 2016-12-15 lijia add, ��ʱreset֮ǰ, ��Ҫ����link_state */ + ((struct tcpdetail_private *)(pstream->pdetail))->link_state = STREAM_LINK_TIMEOUT; + } + ret = 1; + } + else + { + if (STREAM_TYPE_TCP == pstream->type) + { + ((struct tcpdetail_private *)(pstream->pdetail))->link_state = STREAM_LINK_TIMEOUT; + tcp_free_stream(pindex, NULL, NULL, NULL); + ret = 2; + } + else + { + pstream_pr->stream_close_reason = STREAM_CLOSE_REASON_TIMEOUT; + udp_free_stream(pindex); + ret = 2; + } + } + } + } + if(g_stream->user_define_timer_cnt > 0 && g_stream->interval_to_next_timeout_s == 0) { t = timeouts_get(g_stream->user_define_timer); if (t != NULL) diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index 45f95cc..162a0f6 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -879,15 +879,16 @@ static int marsio4_sleep_time_table[100] = static inline void marsio4_sleep(int tid, int tot_call_times, int rcv_pkt_times)
{
- if (ptr_marsio_poll_wait != NULL)
- {
- ptr_marsio_poll_wait(sapp_marsio4_instance, g_mr4_dev_up_handle_set, g_mr4_device_num, tid, 900); // sapp�ڲ���ʱ����С����Ϊ�룬�˴����ó�ʱΪΪ900���룬���ڶ����ģʽ���ó�CPUʱ��
- }
- else
- {
- float work_percent = ((float)rcv_pkt_times / (float)tot_call_times) * 100.0;
- if ((work_percent < 90.0) && (marsio4_sleep_time_table[(int)work_percent] > 0))
+ float work_percent = ((float)rcv_pkt_times / (float)tot_call_times) * 100.0;
+
+ if ((work_percent < 90.0)&& (marsio4_sleep_time_table[(int)work_percent] > 0))
+ {
+ if (ptr_marsio_poll_wait != NULL)
+ {
+ ptr_marsio_poll_wait(sapp_marsio4_instance, g_mr4_dev_up_handle_set, g_mr4_device_num, tid, 900); // sapp�ڲ���ʱ����С����Ϊ�룬�˴����ó�ʱΪΪ900���룬���ڶ����ģʽ���ó�CPUʱ��
+ }
+ else
{
sapp_usleep(marsio4_sleep_time_table[(int)work_percent]);
}
@@ -949,21 +950,30 @@ static void *marsio4_worker(void *arg) */
int polling_enabled = sapp_global_val->config.packet_io.polling_enabled;
int infinite_loop_enabled = sapp_global_val->config.packet_io.infinite_loop_enabled;
+ int polling_timeout_ret=POLLING_STATE_WORK;
while(SAPP_STATE_PROCESSING == sapp_global_val->individual_volatile->current_state){
if(marsio4_process_packet(tseq, &raw_pkt) > 0){
rcv_pkt_tims++;
}else{
marsio4_flush_queue_buf(tseq);
/* �ް�ʱҪ����polling�ӿ� */
- if(polling_enabled && (g_PollingFunNum > 0)){
- if((stream_process_polling(tseq) & POLLING_STATE_WORK) != 0)
+ if (likely(polling_enabled))
+ {
+ if ((g_PollingFunNum > 0))
{
- polling_work_times++;
+ if ((stream_process_polling(tseq) & POLLING_STATE_WORK) != 0)
+ {
+ polling_work_times++;
+ }
+ }
+ if (polling_timeout_ret & POLLING_STATE_WORK)
+ {
+ polling_timeout_ret=polling_stream_timeout(tseq);
+ if ((polling_timeout_ret&POLLING_STATE_WORK))
+ {
+ polling_work_times++;
+ }
}
- }
- if(polling_enabled && (polling_stream_timeout(tseq) & POLLING_STATE_WORK))
- {
- polling_work_times++;
}
}
@@ -982,7 +992,7 @@ static void *marsio4_worker(void *arg) total_call_times++;
}
- if(total_call_times >= 100){
+ if(total_call_times >= sapp_global_val->config.packet_io.polling_priority){
if(likely(infinite_loop_enabled == 0))
{
marsio4_sleep(tseq, total_call_times, rcv_pkt_tims + polling_work_times);
@@ -990,6 +1000,7 @@ static void *marsio4_worker(void *arg) total_call_times = 0;
rcv_pkt_tims = 0;
polling_work_times = 0;
+ polling_timeout_ret=POLLING_STATE_WORK;
}
}
return NULL;
|
