-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[kernel][src] reload timeout_tick with absolute base value #5402
Conversation
{ | ||
/* resume timer thread to check soft timer */ | ||
rt_thread_resume(&_timer_thread); | ||
need_schedule = RT_TRUE; |
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.
need_schedule 标记是防止 A 定时器回调中 sleep 等操作导致线程挂起。B 定时器启动时,意外将 timer 线程唤醒。导致 A 定时器意外唤醒
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.
need_schedule 这个变量的作用不是你说那样,跟你说的那个没联系,rt_timer_start 最后有两种情况,一种是需要进行任务调度切换到 timer 线程,一种是不需要。
需要任务调度的流程是: 开中断;调用rt_schedule
;return
返回。
不需要任务调度的流程是: 开中断;return
返回。
之前就是把上述两种流程合并到一起,用 need_schedule
变量控制中间 rt_schedule
是否被执行的开关。这样的用法在多处有 return 返回的情况下使用比较合适,但是这里只在函数最后紧挨着的地方有两个返回点,分开写代码语义比较清晰。
你可能想说的是 _soft_timer_status
这个变量,用来限制“某些”情况下任务调度,关于这个 pr 的详细说明,请移步论坛,那里有更全面的理论分析。
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.
能否贴一下论坛链接?
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.
_soft_timer_status
变量去掉后,timer 线程被异常唤醒的问题,这个问题是咋解决的?
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.
是的,这问题是怎么解决的?
timer 定时器的周期,指的是回调执行完成,下一次执行需要等待的时间。回调函数执行的时间,并不算在周期内 |
第一次听到这种说法。 |
我理解的定时器的周期,跟回调函数执行时间没关系,表示的是在一个固定周期内调用回调函数 比如:如果在10s的时候启动了一个周期是3s的周期性定时器A,那就是要在时刻,13、16、19、22、25、28... 的时刻去调用回调函数。 |
不能单纯从周期这个词上理解。定时器的周期,可以理解为自动调用 start 函数。 |
但是,我感觉大家应该都认为,周期就是周期的意思。。。你这种说法,我也是第一次听说 |
不必在周期这个概念上过于纠结,实际上一个完备的定时器是有多种不同的周期模式的, @thewon86 出出提到的是一种, @enkiller 炸弹哥提到的也是一种,怎么理解都对。 之前这个定时器到底什么时候开始计时其实在文档中没有明确体现出来,大家也是稀里糊涂的用,这次正好明确一下。其实我们的定时器也不需要像matlab或者ucos一样支持多种,只需要支持某一种就好。 https://blog.csdn.net/weixin_43455581/article/details/109221500
|
@mysterywolf fixedRate 模式有点儿意思,它考虑到了到达定时时间和执行回调函数时间之间可能存在时间差。timoeout 回调函数执行开始执行一次 rt_timer_start 也是同样的效果。 这样不限制在 timeout 回调里调用 rt_timer_start ,而且可以由应用决定是否重新计时。 |
我觉得OK! 其他的fixedRate fixedDelay可以不用实现,或者以后再实现都可以。我们只需要准确的明确,周期性定时器到底是从什么时候开始算起就好。 fixedSpacing 这种方式要比fixedDelay要好控制周期,因为软件定时器回调函数具体要执行多少时间估计起来很麻烦。 |
@mysterywolf 合并你的PR后,这个变成冲突了 |
src/timer.c
Outdated
/* | ||
* get timeout tick, | ||
* the max timeout tick shall not great than RT_TICK_MAX/2 | ||
*/ |
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.
这个注释应该删掉 这个是给之前那个assert的注释
src/timer.c
Outdated
rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL]; | ||
unsigned int tst_nr; | ||
static unsigned int random_nr; | ||
|
||
/* parameter check */ | ||
RT_ASSERT(timer != RT_NULL); | ||
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer); | ||
|
||
need_schedule = RT_FALSE; | ||
RT_ASSERT(timer->init_tick < RT_TICK_MAX / 2); |
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.
这个assert可以删掉了,在pr #5533 中,我已经把这个参数有效性的判断放在了init和create函数,上来就判断有效性。
https://github.com/RT-Thread/rt-thread/pull/5533/files#diff-340e9ee0d7971fa052b504957c48a3a313f76cb85490ff00afb3e9293d09f53aR335
https://github.com/RT-Thread/rt-thread/pull/5533/files#diff-340e9ee0d7971fa052b504957c48a3a313f76cb85490ff00afb3e9293d09f53aR266
https://github.com/RT-Thread/rt-thread/pull/5533/files#diff-340e9ee0d7971fa052b504957c48a3a313f76cb85490ff00afb3e9293d09f53aL404-L409
除了 @mysterywolf ,其他人是否搭成一致? @Guozhanxin @enkiller ?Please provide your comments, thank you. |
|
这次定时器修改后,需要在文档中定义好定时器的行为。 |
是的 这个在文档中心可以清楚的明确出来 |
拉取/合并请求描述:(PR description)
[
_timer_start
局部接口,可以指定定时器启动时间。timer->timeout_tick
。修改后的特性:
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 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