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

subsys: debug: Added full CPU utilization monitor #87658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

koffes
Copy link
Collaborator

@koffes koffes commented Mar 25, 2025

  • Added a module and tests to detect full CPU load

@koffes koffes force-pushed the idle_observer branch 2 times, most recently from 00b1aa1 to 861689e Compare March 30, 2025 20:07
@koffes koffes marked this pull request as ready for review March 30, 2025 20:07
@koffes koffes requested a review from nordic-krch March 30, 2025 20:08
@github-actions github-actions bot requested review from dcpleung and nashif March 30, 2025 20:08
@koffes
Copy link
Collaborator Author

koffes commented Mar 30, 2025

This PR resolves #71945. We may need to discuss a bit when it comes to multicore architectures.

@nashif
Copy link
Member

nashif commented Mar 30, 2025

you need to rebase

@nordic-krch
Copy link
Collaborator

I wonder if it would not be lighter and simpler to reuse already existing periodic cpu load logging functionality. Move it to k_timer instead of k_work and add option to report load only if load is above given configurable threshold. When threshold is set then it would report it as LOG_WRN (or printk if logging is disabled). Using current approach requires enabling thread stats which increases code size and that may be an issue for smaller cores (e.g. flpr).

@koffes
Copy link
Collaborator Author

koffes commented Mar 31, 2025

PR has been rebased.
Thanks for the input @nordic-krch. I would like more people to weigh in on your suggestion on "periodic cpu load". I can rewrite to use that, but would like to know if it is required. There will be changes there as well as you say, changing to k_timer will influence all other applications. I'd prefer to minimize impact on existing features. Using LOG_WRN is not an option, as that may never be scheduled to run.

@nordic-krch
Copy link
Collaborator

@koffes callback might be added as well there and printk can be used instead of LOG_WRN when logging is disabled. Note that when logging is enabled then printk by default goes through logging so it is also not guaranteed to be printed.

@koffes koffes force-pushed the idle_observer branch 2 times, most recently from c5bb9da to 84c052e Compare April 3, 2025 20:00
@koffes
Copy link
Collaborator Author

koffes commented Apr 3, 2025

@nordic-krch : re-written based on your comment. Have not changed the printing, as the user can do this in the callback.

- Added a CPU load callback with threshold
- Changed cpu_load to use k_timer instead of k_work

Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
Copy link
Collaborator

@nordic-krch nordic-krch left a comment

Choose a reason for hiding this comment

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

Looks ok. I've opened #88222 so it will be possible to enable periodic logging but set cpu_load log level below INF and use periodic callback only for tracking if threshold is exceeded.

void high_load_cb(uint8_t percent)
{
last_cpu_load_percent = percent;
TC_PRINT("percendt %u", percent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
TC_PRINT("percendt %u", percent);
TC_PRINT("percent %u", percent);

*
* @retval 0 - Callback registered/cancelled.
* @retval -EINVAL if the threshold is invalid.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

redundant line

/** @brief Optional registration of callback when load is greater or equal to the threshold.
*
* Submitting NULL pointer will cancel the callback.
*
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add parameter description?

@@ -48,6 +49,23 @@ int cpu_load_get(bool reset);
*/
void cpu_load_log_control(bool enable);

/* Optional callback for cpu_load_cb_reg
*
* This will be called from the k_timer expiry_fn.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* This will be called from the k_timer expiry_fn.
* This will be called from the k_timer expiry_fn used for periodic logging. CONFIG_CPU_LOAD_LOG_PERIODICALLY must be configured to a positive value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants