-
Notifications
You must be signed in to change notification settings - Fork 747
kernel: scheduler: Use NonZeroU32 instead of u32 for start()
and get_remaining_us()
#4254
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
Conversation
|
||
SchedulingDecision::RunProcess((next, Some(timeslice))) |
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.
Is this assert required in production code? It looks odd. I would rather add an abstraction types such as NonZeroU32
to show that timeslice may never be 0.
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.
I agree this code is really not what we would like. If RoundRobinSched::time_remaining
was a NonZeroU32
we could do proper checks and avoid the chance of a panic.
This is a draft until I get access to a Raspberry Pi Pico board and ensure nothing is broken. |
53879fd
to
1d88e17
Compare
I notice now that the footprint in release mode is increased by 8 bytes. Strange though. The sole explanation I have right now is |
I checked the PR against |
start()
and get_remaining_us()
start()
and get_remaining_us()
|
||
SchedulingDecision::RunProcess((next, Some(timeslice))) |
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.
I agree this code is really not what we would like. If RoundRobinSched::time_remaining
was a NonZeroU32
we could do proper checks and avoid the chance of a panic.
Pull Request Overview
This pull request changes the type of the
us
argument forSchedulerTimer::start()
andSchedulerTimer::get_remaining_us()
return type. UsingNonZeroU32
has two benefits:NonZeroU32
type also forces the programmer to check for null values, thus it provides better type safety.Option<NonZeroU32>
can be optimized, thus reducing the memory footprint of the kernel, albeit by a few bytes:As a side effect, this PR requires the change of the
SchedulingDecision::RunProcess
variant since the scheduler may never decide to run a process for 0 micro seconds.Testing Strategy
This pull request was tested by running
c_hello
andblink
applications on Raspberry Pi Pico using the round robin scheduler.TODO or Help Wanted
No help needed.
Documentation Updated
Formatting
make prepush
.