File tree Expand file tree Collapse file tree
include/f_core/os/tenants Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,9 +28,8 @@ class CCpuMonitorTenant : public CTenant {
2828
2929private:
3030 CMessagePort<CpuMonitorData>& outputPort;
31-
32- uint32_t prevExecutionCycles = 0 ;
33- uint32_t prevTotalCycles = 0 ;
31+ uint64_t prevExecutionCycles = 0 ;
32+ uint64_t prevTotalCycles = 0 ;
3433
3534#if DT_NODE_EXISTS(DT_ALIAS(die_temp))
3635 const device *dieTempSensor = DEVICE_DT_GET (DT_ALIAS (die_temp));
Original file line number Diff line number Diff line change @@ -54,14 +54,18 @@ uint32_t CCpuMonitorTenant::getUptime() {
5454
5555uint8_t CCpuMonitorTenant::getUtilization () {
5656 k_thread_runtime_stats stats{0 };
57-
5857 k_thread_runtime_stats_all_get (&stats);
59- if (stats.execution_cycles == 0 ) {
58+
59+ uint64_t deltaExecution = stats.execution_cycles - prevExecutionCycles;
60+ uint64_t deltaTotal = stats.total_cycles - prevTotalCycles;
61+
62+ prevExecutionCycles = stats.execution_cycles ;
63+ prevTotalCycles = stats.total_cycles ;
64+
65+ if (deltaExecution == 0 ) {
6066 return 0 ; // Avoid division by zero
6167 }
6268
63- // Note that total cycles is non-idle cycles
64- // and execution cycles is the sum of non-idle + idle cycles.
65- return static_cast <uint8_t >(
66- ((stats.total_cycles ) * 100 ) / (stats.execution_cycles ));
69+ // Utilization is the percentage of non-idle cycles in the interval
70+ return static_cast <uint8_t >((deltaTotal * 100 ) / deltaExecution);
6771}
You can’t perform that action at this time.
0 commit comments