nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

[HELP] How to get the cpuload of a each thread or task and overall cpuload in NuttX

Open harishn6 opened this issue 2 months ago • 4 comments

Description

Hi,

I am working on an application where I need to accurately measure the CPU load of individual threads/tasks, as well as the overall system CPU load in NuttX.

I have attempted to use the clock_cpuload() function to retrieve this information. However, I'm encountering an issue where clock_cpuload() consistently returns the same value for all tasks, regardless of their actual CPU usage.

Could someone please advise on the correct approach to obtain per-thread/task CPU load and the overall system CPU load in NuttX? Are there alternative methods or considerations I should be aware of when using clock_cpuload()? Specifically, am I missing any necessary setup or usage details?

Any insights or examples would be greatly appreciated.

Thanks & Regards, Harish Nayineni

Verification

  • [x] I have verified before submitting the report.

harishn6 avatar Oct 08 '25 04:10 harishn6

Hi @harishn6,

Very interesting project!

Did you enable all need CONFIGs necessary by clock_cpuload() to work (sched/sched/sched_cpuload.c)? I think so since you found that function that is not commonly used by other drivers.

I think the best way to measure precisely is using something like debugger tracer, i.e. JLINK RTT that is supported by NuttX (look at drivers/segger) because the clock_cpuload() by itself will introduce some overhead.

Maybe @xiaoxiang781216 @raiden00pl or @jkivilin have some idea why you are getting the same values for all tasks.

acassis avatar Oct 08 '25 21:10 acassis

Hello @xiaoxiang781216 ,@raiden00pl ,@jkivilin I would like to know any help you can provide on above discussion.

keykur111 avatar Oct 15 '25 09:10 keykur111

@Donny9 since Xiang seems busy, could you please take a look?

acassis avatar Oct 23 '25 18:10 acassis

clock_cpuload with 0(idle task) return cpu loading, other pid return the load of the specific thread. So, your usage is right, do you enable the related config correctly? Does ps already report the correct value?

xiaoxiang781216 avatar Oct 24 '25 03:10 xiaoxiang781216