mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 02:07:55 +00:00
improved stability of cpu usage calculation
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <hal.h>
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "performance_counter.hpp"
|
||||
|
||||
void write_m4_panic_msg(const char *panic_message, struct extctx *ctxp) {
|
||||
if (ctxp == nullptr) {
|
||||
@@ -120,29 +121,25 @@ void update_performance_counters() {
|
||||
auto performance_counter_active = shared_memory.request_m4_performance_counter;
|
||||
if (performance_counter_active == 0x00)
|
||||
return;
|
||||
|
||||
static bool last_paint_state = false;
|
||||
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
|
||||
return;
|
||||
|
||||
volatile auto idle_thread = chSysGetIdleThread();
|
||||
if (chThdGetTicks(idle_thread) > 0x10000000) {
|
||||
return;
|
||||
}
|
||||
|
||||
idle_thread = nullptr;
|
||||
|
||||
last_paint_state = !last_paint_state;
|
||||
|
||||
auto now = chTimeNow();
|
||||
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
|
||||
|
||||
static systime_t last_time;
|
||||
static systime_t last_last_time;
|
||||
|
||||
auto time_elapsed = now - last_time;
|
||||
auto idle_elapsed = idle_ticks - last_last_time;
|
||||
|
||||
last_time = now;
|
||||
last_last_time = idle_ticks;
|
||||
|
||||
auto cpu_usage = (time_elapsed - idle_elapsed) / 10;
|
||||
auto utilisation = get_cpu_utilisation_in_percent();
|
||||
auto free_stack = (uint32_t)get_free_stack_space();
|
||||
auto free_heap = chCoreStatus();
|
||||
|
||||
shared_memory.m4_cpu_usage = cpu_usage;
|
||||
shared_memory.m4_cpu_usage = utilisation;
|
||||
shared_memory.m4_stack_usage = free_stack;
|
||||
shared_memory.m4_heap_usage = free_heap;
|
||||
}
|
||||
|
Reference in New Issue
Block a user