freertos, app_trace, heap: use esp_cpu_get_cycle_count to get ccount

portGET_RUN_TIME_COUNTER_VALUE should only be used in the kernel.
This commit is contained in:
Ivan Grokhotkov
2022-09-29 22:04:24 +02:00
parent 0b6bc7045e
commit 7e2f261a58
4 changed files with 21 additions and 17 deletions

View File

@@ -10,6 +10,7 @@
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "esp_cpu.h"
#include <stdlib.h>
#include <sys/param.h>
#include <string.h>
@@ -41,9 +42,9 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
*/
size_t new_size = (uint32_t)rand() % 1024;
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
cycles_before = esp_cpu_get_cycle_count();
void *new_p = heap_caps_realloc(p[n], new_size, MALLOC_CAP_DEFAULT);
realloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
realloc_time_average = esp_cpu_get_cycle_count() - cycles_before;
ESP_LOGD(TAG, "realloc %p -> %p (%zu -> %zu) time spent cycles: %lld \n", p[n], new_p, s[n], new_size, realloc_time_average);
heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true);
@@ -66,9 +67,9 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
}
TEST_ASSERT(heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true));
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
cycles_before = esp_cpu_get_cycle_count();
heap_caps_free(p[n]);
free_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
free_time_average = esp_cpu_get_cycle_count() - cycles_before;
ESP_LOGD(TAG, "freed %p (%zu) time spent cycles: %lld\n", p[n], s[n], free_time_average);
@@ -81,9 +82,9 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
s[n] = rand() % 1024;
heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true);
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
cycles_before = esp_cpu_get_cycle_count();
p[n] = heap_caps_malloc(s[n], MALLOC_CAP_DEFAULT);
alloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
alloc_time_average = esp_cpu_get_cycle_count() - cycles_before;
ESP_LOGD(TAG, "malloc %p (%zu) time spent cycles: %lld \n", p[n], s[n], alloc_time_average);
@@ -99,9 +100,9 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
}
for (int i = 0; i < NUM_POINTERS; i++) {
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
cycles_before = esp_cpu_get_cycle_count();
heap_caps_free( p[i]);
free_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
free_time_average = esp_cpu_get_cycle_count() - cycles_before;
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED during cleanup after freeing %p\n", p[i]);