-
Notifications
You must be signed in to change notification settings - Fork 7.3k
kernel: Timeslicing and yield to share code #85538
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
base: main
Are you sure you want to change the base?
kernel: Timeslicing and yield to share code #85538
Conversation
When timeslicing moves the current thread to the end of the priority queue, it is functionally equivalent to yielding. Signed-off-by: Peter Mitsis <[email protected]>
bba16a7
to
09c6f14
Compare
Updated as per @cfriedt 's comments. |
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.
No real complaints here, but just to be That Guy: if this is really removing duplicated code, why is it increasing the line count by 5?
Sometimes refactoring just isn't worth it, IMHO. In this case the API changes needed to effect the unification are larger than the code being duplicated. Not worth it, IMHO.
@andyross - There is one other thing to consider. We recently did some optimization on k_yield(). By having move_thread_to_end_of_prio_q() / z_yield() use the same logic as k_yield(), we also gain the benefits of those optimizations at ISR level. Also, FWIW, I think this also cleans up the SMP behavior as well. Without this proposed change, the SMP version of move_thread_to_end_of_prio_q() / z_yield() logically becomes (after realizing that thread is always _current) ...
|
Yes, QUEUED should only be needed when SMP=y because live threads always remain in the queue on UP as an optimization (they have to come out on SMP so that other CPUs don't try to select them, but obviously that isn't a problem when there are no other CPUs). It would be good to clean that logic up for sure, to e.g. unify the list operations with the bit set such that one can be elided in an obvious way. There are gotchas though with the way things interact with other optimizations though, IIRC. |
When timeslicing moves the current thread to the end of the priority queue, it is functionally equivalent to yielding. It makes sense for the two to share common code.