Skip to content

Commit

Permalink
Replace millisecond timer with microsecond one for cpuload calculation (
Browse files Browse the repository at this point in the history
  • Loading branch information
onkwon authored Jul 27, 2024
1 parent 1382e85 commit e970aea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/memsize.baseline
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
text data bss dec hex filename
193480 57252 507021 757753 b8ff9 build/template.elf
193528 57252 507029 757809 b9031 build/template.elf
13 changes: 6 additions & 7 deletions ports/esp-idf/cpuload.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* SPDX-License-Identifier: MIT
*/

#include "libmcu/board.h"

#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

Expand All @@ -20,15 +19,15 @@ static struct cpuload {

void on_task_switch_in(void)
{
static uint32_t t0;
static uint32_t sum_elapsed;
static uint64_t t0;
static uint64_t sum_elapsed;

uint32_t t1 = board_get_time_since_boot_ms();
uint64_t t1 = esp_timer_get_time(); /* in microseconds */
uint32_t elapsed = t1 - t0;

/* NOTE: count at least 1 even if the task has run for much shorter time
* as millisecond unit timer used here. For fine granularity, introduce
* high-resolution timer. */
* as microsecond unit timer used here. For fine granularity, introduce
* more high-resolution timer. */
if (elapsed == 0) {
elapsed = 1;
}
Expand Down

0 comments on commit e970aea

Please sign in to comment.