-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix timer overflow #10365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix timer overflow #10365
Conversation
|
这个patch 修复的是,当tick溢出时可以正确计算。 |
|
@Rbb666 review 一下 |
|
当系统长时间不关机,tick溢出,所在的事件就会出问题。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes redundant tick calculations and addresses timer overflow by adopting safer delta-based comparisons across several subsystems.
- Replaced direct tick arithmetic with overflow-safe logic in
timer.c - Updated
rt_thread_delay_untilinthread.cto usert_tick_get_deltaand refined overflow handling - Standardized timeout adjustments in
mempool.candipc.cusingrt_tick_get_delta
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/timer.c | Removed redundant current_tick, changed overflow check to raw subtraction |
| src/thread.c | Swapped manual tick diff with rt_tick_get_delta, refactored delay-until logic |
| src/mempool.c | Replaced rt_tick_get() subtraction with rt_tick_get_delta |
| src/ipc.c | Renamed tick_delta to tick_stamp and applied rt_tick_get_delta for all timeout recalculations |
|
|
||
| ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout); | ||
| if ((ret == RT_EOK) && (next_timeout <= rt_tick_get())) | ||
| if ((ret == RT_EOK) && ((rt_tick_get() - next_timeout) < RT_TICK_MAX / 2)) |
Copilot
AI
Jun 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing the raw subtraction with the overflow-safe helper rt_tick_get_delta(next_timeout) for consistency and clarity.
| if ((ret == RT_EOK) && ((rt_tick_get() - next_timeout) < RT_TICK_MAX / 2)) | |
| if ((ret == RT_EOK) && (rt_tick_get_delta(next_timeout) < RT_TICK_MAX / 2)) |
src/thread.c
Outdated
| { | ||
| rt_tick_t left_tick; | ||
| rt_tick_t target_tick; | ||
| target_tick = *tick + inc_tick; |
Copilot
AI
Jun 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After computing left_tick, the code never updates *tick to target_tick, so subsequent calls may use an outdated baseline. Consider adding *tick = target_tick; before suspending the thread.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up