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
timer: k_timer_start should be allowed to start start with duration = 0 #1073
timer: k_timer_start should be allowed to start start with duration = 0 #1073
Conversation
Adding my view on this here as well: there are use cases where the k_timer_start() API user wants the timer to fire for the first time as soon as possible, and then after that using the given period. In such cases giving K_NO_WAIT seems like the most intuitive thing, i.e. forbidding it makes the API worse (IMO). |
Hi @jhedberg There are 2 approaches to this: Approach2 (Approach proposed by jhedberg): - Allow duration 0 value passed in the duration to be legal and handle 0 case inside k_timer_start something like :- But there are some points we should consider against approach 2:-
Looking at above points it looks like Approach 1 is more convenient as compared to Approach 2. Also I did grep and found that all instances of k_thread_start as using Non Zero as duration argument (excepy microbit Display). For microbit Display I have submitted a patch #1074. So technically we put 2 patches |
Hi @youvedeep Some answers to your points regarding approach 2:
Assuming that the justification in point 1 is valid, if the API user desires "as soon as possible" triggering of the first timer callback, having to pass 1 instead of 0 makes the API usage "weird" in that what you're giving it is a bit arbitrary and not reflecting the exact intention. |
I agree with @jhedberg here in that, from the point of view of the API user, it is much more understandable to have a K_NO_WAIT parameter passed in when you want the timer to fire as soon as possible, instead of having to artificially hardcode an arbitrary value of "1". What the kernel does internally is an entirely different thing, but "fire timer ~now" is a valid usecase. |
c8a27df
to
76bf0ce
Compare
@youvedeep @galak @jhedberg @cvinayak we just had a similar confusion happen to one of our developers, when he tried to call k_sleep(K_FOREVER) and that just returns immediately. I think K_NO_WAIT and K_FOREVER should be allowed in all kernel APIs or not allowed at all. |
Hi @carlescufi I looked at this and here are my comments:- What Documentation indicates :- (Do not allow) What intuition indicates:- (Allow -1) I think this confusion is starting due to this intuition , So we should :- " |
76bf0ce
to
041a1db
Compare
Hi @carlescufi / @jhedberg can you please help me to verify if my latest patch fixes GFX issue on microbit device. |
@youvedeep I can do that, as soon as I get back to my office where the hw is |
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.
Sorry, I didn't realize the patch had been updated (github doesn't send any notification for that). I tested with TICKLESS_KERNEL=y using samples/boards/microbit/display and it works fine. Just one small whitespace issue.
kernel/include/timeout_q.h
Outdated
if (!timeout_in_ticks) { | ||
_handle_one_expired_timeout(timeout); | ||
return; | ||
|
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.
Minor thing: redundant empty line here
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.
Thanks @jhedberg / @carlescufi for testing quickly :). appreciate your help.
Sure I will incorporate your review comment into next patch version.
@jhedberg oh thanks for that |
041a1db
to
1d56955
Compare
k_timer_start(timer, duration, period) is API used to start a timer. Currently duration parameters accepts only positive number. But a user may require to do some periodic activity ASAP and start timer with 0 value. So this patch allows 0 as minimum value of duration. In this patch, when duration value is set as 0 then timer expiration handler is called instead of submiting this into timeout queue. Jira: ZEP-2497 Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
1d56955
to
6420170
Compare
Signed-off-by: James Prestwood <james.prestwood@intel.com>
Duration specify time interval before timer expires for first time,
it is measured in milliseconds.
A user may submit an periodic activity starting with ASAP.
So it should allow 0 as value for duration.
So this patch implements adds 0 as valid value for duration.
Jira: ZEP-2497
Signed-off-by: Youvedeep Singh youvedeep.singh@intel.com