Skip to content

Commit

Permalink
debug: Make heap integrity check less heavy
Browse files Browse the repository at this point in the history
If PSRAM is available, alternate between checking internal RAM
and PSRAM, to make the checks less CPU-intensive.

Has no effect if no PSRAM is available, as only internal RAM
has to be checked in that case.
  • Loading branch information
MattiasTF committed May 28, 2024
1 parent b0dc24f commit f1e6e05
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions software/src/modules/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,24 @@ void Debug::register_events()
register_task("wpsT", 0, ExpectMissing);
}

#if defined(BOARD_HAS_PSRAM) && BOARD_HAS_PSRAM == 1
#define CHECK_PSRAM 1
#else
#define CHECK_PSRAM 0
#endif

void Debug::loop()
{
micros_t start = now_us();
bool check_ok = heap_caps_check_integrity_all(integrity_check_print_errors);
if (CHECK_PSRAM && check_psram_next) {
psram_heap_valid = heap_caps_check_integrity(MALLOC_CAP_SPIRAM, integrity_check_print_errors);
check_psram_next = false;
} else {
internal_heap_valid = heap_caps_check_integrity(MALLOC_CAP_INTERNAL, integrity_check_print_errors);
if (CHECK_PSRAM) {
check_psram_next = true;
}
}
uint32_t runtime = static_cast<uint32_t>(static_cast<int64_t>(now_us() - start));

integrity_check_runs++;
Expand All @@ -488,7 +502,7 @@ void Debug::loop()
integrity_check_runtime_max = runtime;
}

if (!check_ok) {
if (!(internal_heap_valid & psram_heap_valid)) {
state_slow.get("heap_integrity_ok")->updateBool(false);
integrity_check_print_errors = false;
}
Expand Down
3 changes: 3 additions & 0 deletions software/src/modules/debug/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ class Debug final : public IModule
uint32_t integrity_check_runtime_sum = 0;
uint32_t integrity_check_runtime_max = 0;
bool integrity_check_print_errors = true;
bool internal_heap_valid = true;
bool psram_heap_valid = true;
bool check_psram_next = false;
};

0 comments on commit f1e6e05

Please sign in to comment.