-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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: fix k_sleep in no multi-threading mode #80979
base: main
Are you sure you want to change the base?
kernel: fix k_sleep in no multi-threading mode #80979
Conversation
kernel/nothread.c
Outdated
} else { | ||
expected_wakeup_ticks = Z_TICK_ABS(ticks); | ||
/* ticks is absolute timeout expiration */ | ||
ticks_to_wait = Z_TICK_ABS(ticks) - sys_clock_tick_get_32(); |
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.
If we have already passed the absolute point in time (Z_TICKS_ABS(ticks) < sys_clock_tick_get_32()), we should set ticks_to_wait
to 0, otherwise we are waiting when we should not be waiting.
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 for the comment. Fixed it
Fix k_sleep implementation for no multi-threading mode. Absolute value of timeout expiration was fed to the k_busy_wait() function instead of delta value. That caused bug like incrementing of sleep time in geometric progression (while actual function argument is constant) during program running. Signed-off-by: Mikhail Kushnerov <[email protected]>
0a90522
to
5910b95
Compare
@peter-mitsis , is this a fix that is needed for the upcoming 4.0 release? |
@mmahadevan108 - I think this would be worthwhile for 4.0. |
@KushnerovMikhail or @peter-mitsis can you please file an Issue so it can be tracked to a detail in the release-notes? |
uint32_t curr_ticks = sys_clock_tick_get_32(); | ||
|
||
if (Z_TICK_ABS(ticks) > curr_ticks) { | ||
ticks_to_wait = Z_TICK_ABS(ticks) - curr_ticks; |
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.
Are they possible to be negative number?
(Just a question.)
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.
Not really understand question.
If you talking about Z_TICK_ABS(ticks)
, than it can. But negative values are caught by previous if.
If you talking about ticks_to_wait
, I think there is no meaning in waiting negative time. So, I make it unsigned.
sys_clock_tick_get_32()
, of course, can not be negative.
Moving the milestone to 4.1. Please add the |
Fix k_sleep implementation for no multi-threading mode.
Fixes #81210
Absolute value of timeout expiration was fed to the k_busy_wait() function instead of delta value. That caused bug like incrementing of sleep time in geometric progression (while actual function argument is constant) during program running.
You can check it by simple program with
CONFIG_MULTITHREADING=n
option:Output from qemu_riscv64
Before fix:
100
200
400
800
...
After fix:
100
100
100
100
...