fix timer overflow#10365
Closed
htl5241 wants to merge 2 commits intoRT-Thread:masterfrom
htl5241:fix-timer-overflow
Closed
fix timer overflow#10365htl5241 wants to merge 2 commits intoRT-Thread:masterfrom htl5241:fix-timer-overflow
htl5241 wants to merge 2 commits intoRT-Thread:masterfrom
htl5241:fix-timer-overflow
Conversation
Contributor
Author
|
这个patch 修复的是,当tick溢出时可以正确计算。 |
Contributor
Author
|
@Rbb666 review 一下 |
Contributor
Author
|
当系统长时间不关机,tick溢出,所在的事件就会出问题。 |
Contributor
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Consider replacing the raw subtraction with the overflow-safe helper rt_tick_get_delta(next_timeout) for consistency and clarity.
Suggested change
| 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; |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(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