Skip to content

Commit 280b2f9

Browse files
committed
Delta
1 parent e2a02da commit 280b2f9

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

include/f_core/os/tenants/c_cpu_monitor_tenant.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ class CCpuMonitorTenant : public CTenant {
2828

2929
private:
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));

lib/f_core/os/tenants/c_cpu_monitor_tenant.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ uint32_t CCpuMonitorTenant::getUptime() {
5454

5555
uint8_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
}

0 commit comments

Comments
 (0)