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

kernel: Add k_thread_runtime_stats_is_enabled function #80450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rruuaanng
Copy link
Collaborator

@rruuaanng rruuaanng commented Oct 25, 2024

Add 'k_thread_runtime_stats_is_enabled' to 'usage.c', which's used to check whether runtime statistics collection is enabled for a thread.

It can determine whether the thread has enabled runtime statistics collection when the program is running. It allows users to add conditional statements based on this function when using it.

for example:

void f()
{
    // Assume there is a thread id
    if (k_thread_runtime_stats_is_enabled(id)) {
        /* do something */
    }
    ...
}

And it can provide a complete support when similar operations are needed. for example enable, disable, is_enabled.
For example, its use in the implementation of CLOCK_THREAD_CPUTIME_ID actually lacks k_thread_runtime_stats_is_enabled, which makes the entire function impossible to implement safely. It is necessary.

..

@rruuaanng rruuaanng force-pushed the gh80363 branch 2 times, most recently from fc52903 to 075a033 Compare October 25, 2024 15:12
@rruuaanng rruuaanng changed the title kernel: Add k_thread_runtime_stats_enabled function kernel: Add k_thread_runtime_stats_is_enabled function Oct 25, 2024
@rruuaanng rruuaanng marked this pull request as ready for review October 25, 2024 15:28
@zephyrbot zephyrbot added the area: POSIX POSIX API Library label Oct 26, 2024
@zephyrbot zephyrbot requested a review from ycsin October 26, 2024 10:40
@rruuaanng rruuaanng force-pushed the gh80363 branch 2 times, most recently from 70b4aa0 to 04e6d25 Compare October 26, 2024 12:02
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

Thanks for all of the POSIX clock work.

Just a question / suggestion regarding runtime function call overhead.

include/zephyr/kernel.h Outdated Show resolved Hide resolved
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

Just some suggestions around CONFIG_POSIX_THREAD_CPUTIME

lib/posix/options/clock.c Outdated Show resolved Hide resolved
lib/posix/options/clock.c Outdated Show resolved Hide resolved
lib/posix/options/clock.c Outdated Show resolved Hide resolved
@rruuaanng rruuaanng force-pushed the gh80363 branch 2 times, most recently from 5302a73 to e9323cc Compare October 28, 2024 04:18
@rruuaanng rruuaanng requested a review from cfriedt October 28, 2024 04:26
@rruuaanng
Copy link
Collaborator Author

I've made change, Please riewer again!

lib/posix/options/clock.c Outdated Show resolved Hide resolved
peter-mitsis
peter-mitsis previously approved these changes Oct 28, 2024
Copy link
Collaborator

@peter-mitsis peter-mitsis left a comment

Choose a reason for hiding this comment

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

Kernel side seems reasonable to me.

ycsin
ycsin previously approved these changes Oct 29, 2024
cfriedt
cfriedt previously approved these changes Jan 6, 2025
@cfriedt cfriedt requested a review from stephanosio January 6, 2025 02:26
@cfriedt
Copy link
Member

cfriedt commented Jan 7, 2025

@rruuaanng - needs a rebase again to resolve the merge conflict, but it would also be a good opportunity to add @ycsin's change request as well.

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.

One more nitpick that I can't get past. But that's my only complaint, feel free to assume +1 once resolved.

kernel/usage.c Outdated Show resolved Hide resolved
@rruuaanng rruuaanng dismissed stale reviews from ycsin and cfriedt via cf17e92 January 8, 2025 05:50
@rruuaanng rruuaanng force-pushed the gh80363 branch 2 times, most recently from cf17e92 to bc2896f Compare January 8, 2025 05:55
@andyross andyross self-requested a review January 8, 2025 16:46
@rruuaanng rruuaanng force-pushed the gh80363 branch 3 times, most recently from 1ac81f7 to 8966b7c Compare February 10, 2025 10:57
@rruuaanng rruuaanng requested review from cfriedt and ycsin February 11, 2025 00:55
@rruuaanng
Copy link
Collaborator Author

rruuaanng commented Feb 11, 2025

Please review them again! @cfriedt @ycsin @andyross. If there are no other points, I will be ready to rebase, thanks.

include/zephyr/kernel.h Outdated Show resolved Hide resolved
Add posix 'CLOCK_THREAD_CPUTIME_ID' support to measure the
total CPU execution time of the current thread.

Signed-off-by: James Roy <rruuaanng@outlook.com>
Add test for 'clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts)'.

Signed-off-by: James Roy <rruuaanng@outlook.com>
Add 'k_thread_runtime_stats_is_enabled' function, whichs
used to check whether runtime statistics collection is
enabled for a thread.

Signed-off-by: James Roy <rruuaanng@outlook.com>
Add test for 'k_thread_runtime_stats_is_enabled(tid)'.

Signed-off-by: James Roy <rruuaanng@outlook.com>
Copy link
Member

@ycsin ycsin left a comment

Choose a reason for hiding this comment

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

🥳

@rruuaanng rruuaanng requested review from kartben and cfriedt February 12, 2025 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants