Skip to content
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

Rehabilitate _current usage #83674

Merged
merged 3 commits into from
Jan 10, 2025
Merged

Rehabilitate _current usage #83674

merged 3 commits into from
Jan 10, 2025

Conversation

npitre
Copy link
Collaborator

@npitre npitre commented Jan 8, 2025

This is the revert of the (unwarranted IMHO) _current deprecation as
I suggested in PR #80716. Additional cleanups are also included.

@ycsin
Copy link
Member

ycsin commented Jan 8, 2025

Totally slipped out of my mind, thanks for this PR

andyross
andyross previously approved these changes Jan 8, 2025
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentative +1, with the caveat that I'm going to refuse to engage in any resulting arguments. Not a fan of treewide "naming things" changes in general, especially not of treewide naming things reversions. But I do agree that _current is and was always a cleaner name for the concept (though IIRC I gave a +1 to the rename too...)

Nicolas Pitre added 3 commits January 8, 2025 13:02
Mostly a revert of commit b1def71 ("arch: deprecate `_current`").

This commit was part of PR zephyrproject-rtos#80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.

The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.

Hence this revert.

Signed-off-by: Nicolas Pitre <[email protected]>
Define the generic _current directly and get rid of the generic
arch_current_get().

The SMP default implementation is now known as z_smp_current_get().
It is no longer inlined which saves significant binary size (about 10%
for some random test case I checked).

Introduce z_current_thread_set() and use it in place of
arch_current_thread_set() for updating the current thread pointer
given this is not necessarily an architecture specific operation.
The architecture specific optimization, when enabled, should only care
about its own things and not have to also update the generic
_current_cpu->current copy.

Signed-off-by: Nicolas Pitre <[email protected]>
Repeated references to _current won't produce a different result as the
executing thread instance is always the same. Use the const attribute to
let the compiler know it may reuse a previously obtained value. This offset
the penalty for moving z_smp_current_get() out of line and provides yet
more binary size reduction.

This change is isolated in its own commit to ease bisecting in case some
unexpected misbehavior is eventually observed.

Signed-off-by: Nicolas Pitre <[email protected]>
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refresh +1, the need for a const attribute is a great catch.

@npitre
Copy link
Collaborator Author

npitre commented Jan 8, 2025 via email

Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i found out I did not like the arch_current_thread() call soon after this was merged and was planning to come back and address this, thanks.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click the button correctly

@kartben kartben merged commit bc6eded into zephyrproject-rtos:main Jan 10, 2025
49 checks passed
@npitre npitre deleted the current branch January 10, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants