RT-Thread / RT-Thread/rt-thread
[proposal] `rt_timer_check` 长时间关闭中断,影响系统实时性, 或许可以优化
Open
Nobody has claimed this yet.
proposal
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
目前 rt_timer_check 为了确保 timer list 的一致性,全程关闭中断 (时间长达数十us, 且理论上会随定时器数量的增加而变大),影响了系统的实时性,或许可以通过算法优化,尽可能减少中断关闭的时间。
此问题是社区微信群里的大佬提出的,个人认为确实值得优化,但暂时没想到太好的方案, mark 一下。
一些 tips:
- 群里大佬提到了在执行 hook 的时候暂时恢复中断来减少关闭中断的时间,但我感觉不太可。。。示例如下:
@@ -685,9 +685,16 @@ void rt_timer_check(void)
}
/* add timer to temporary list */
rt_list_insert_after(&list, &(t->row[RT_TIMER_SKIP_LIST_LEVEL - 1]));
+
+ /* enable interrupt */
+ rt_hw_interrupt_enable(level);
+
/* call timeout function */
t->timeout_func(t->parameter);
+ /* disable interrupt */
+ level = rt_hw_interrupt_disable();
+
/* re-get tick */
current_tick = rt_tick_get();
- 个人对别的实时操作系统了解不多,好奇 free-rtos 等其它实时操作系统是如何做的,是否有更好的方案.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/timer.c around rt_timer_check() near line 665 and trace how timer-list consistency, interrupt masking, timeout hooks, and tick rereading interact. Compare the proposed interrupt enable/disable sequence with the existing invariants and relevant RTOS approaches; done means a justified design that reduces interrupt-disabled time without breaking timer behavior or list consistency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, operating-systems
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100