Driveline: write labels only on change (idle 9.7 fps -> 0); perf: panel vsync counter + esp_timer reporting
Firmware / build (push) Successful in 4m2s
Firmware / build (push) Successful in 4m2s
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "driveline_screen.h"
|
||||
#include "uart_manager.h"
|
||||
#include <string.h>
|
||||
#include "display/lvgl_v8_port.h"
|
||||
#include "drivers/can_driver.h"
|
||||
#include "tuning_screen.h"
|
||||
@@ -67,12 +68,29 @@ static lv_obj_t* makeChip(lv_obj_t* parent, const char* text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a chip's text and colour in one go.
|
||||
* @brief lv_label_set_text() only if the text differs. lv_label_set_text()
|
||||
* re-lays-out and invalidates the label even when the string is the
|
||||
* same, and this screen refreshes at 10 Hz - with constant data that was
|
||||
* ~40 kpx redrawn 10x a second for nothing, a third of core 1 and 50 ms/s
|
||||
* of PSRAM writes (perf baseline 2026-09-27).
|
||||
*/
|
||||
static void setText(lv_obj_t* lbl, const char* text) {
|
||||
if (lbl == NULL) return;
|
||||
const char* cur = lv_label_get_text(lbl);
|
||||
if (cur != NULL && strcmp(cur, text) == 0) return;
|
||||
lv_label_set_text(lbl, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a chip's text and colour, touching the object only on a change
|
||||
* (a style write invalidates the object even for an identical value).
|
||||
*/
|
||||
static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
|
||||
if (chip == NULL) return;
|
||||
lv_label_set_text(chip, text);
|
||||
lv_obj_set_style_text_color(chip, colour, 0);
|
||||
setText(chip, text);
|
||||
if (lv_color_to32(lv_obj_get_style_text_color(chip, 0)) != lv_color_to32(colour)) {
|
||||
lv_obj_set_style_text_color(chip, colour, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,13 +310,13 @@ void tick() {
|
||||
// quiet with the car rather than freezing the last frame. 0x3B4 sends its
|
||||
// ignition nibble on-change, so this reset is effectively instant.
|
||||
if (!can_up || !dl.ignition_on) {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
lv_label_set_text(g_coolant_lbl, "--");
|
||||
lv_label_set_text(g_gearbox_lbl, "--");
|
||||
lv_label_set_text(g_rpm_lbl, "----");
|
||||
lv_label_set_text(g_torque_lbl, "--");
|
||||
lv_label_set_text(g_pedal_lbl, "--");
|
||||
lv_label_set_text(g_shaft_lbl, "--");
|
||||
setText(g_gear_lbl, "--");
|
||||
setText(g_coolant_lbl, "--");
|
||||
setText(g_gearbox_lbl, "--");
|
||||
setText(g_rpm_lbl, "----");
|
||||
setText(g_torque_lbl, "--");
|
||||
setText(g_pedal_lbl, "--");
|
||||
setText(g_shaft_lbl, "--");
|
||||
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
|
||||
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
// Leave the ignition chip telling the truth; mute the rest, since their
|
||||
@@ -319,37 +337,37 @@ void tick() {
|
||||
// ---- gear (composed: P/R/N, or D/S/M + engaged number) ---------------
|
||||
if ((gear_position_t)dl.lever != GEAR_UNKNOWN) {
|
||||
composeGear(dl, buf, sizeof(buf));
|
||||
lv_label_set_text(g_gear_lbl, buf);
|
||||
setText(g_gear_lbl, buf);
|
||||
} else {
|
||||
lv_label_set_text(g_gear_lbl, "--");
|
||||
setText(g_gear_lbl, "--");
|
||||
}
|
||||
|
||||
// ---- temperatures (only when the signal is real) ---------------------
|
||||
if (flags & VALID_FLAG_COOLANT_TEMP) {
|
||||
snprintf(buf, sizeof(buf), "%d.%d°C", coolant / 10, abs(coolant % 10));
|
||||
lv_label_set_text(g_coolant_lbl, buf);
|
||||
setText(g_coolant_lbl, buf);
|
||||
}
|
||||
if (flags & VALID_FLAG_GEARBOX_TEMP) {
|
||||
snprintf(buf, sizeof(buf), "%d.%d°C", gearbox / 10, abs(gearbox % 10));
|
||||
lv_label_set_text(g_gearbox_lbl, buf);
|
||||
setText(g_gearbox_lbl, buf);
|
||||
}
|
||||
|
||||
// ---- speeds ----------------------------------------------------------
|
||||
snprintf(buf, sizeof(buf), "%u", dl.engine_rpm);
|
||||
lv_label_set_text(g_rpm_lbl, buf);
|
||||
setText(g_rpm_lbl, buf);
|
||||
lv_bar_set_value(g_rpm_bar, dl.engine_rpm > RPM_MAX ? RPM_MAX : dl.engine_rpm, LV_ANIM_OFF);
|
||||
|
||||
// Torque is signed (negative under overrun/braking); one decimal, matching
|
||||
// the 0.5 Nm resolution of the field.
|
||||
snprintf(buf, sizeof(buf), "%d.%d", dl.engine_torque_x10 / 10, abs(dl.engine_torque_x10 % 10));
|
||||
lv_label_set_text(g_torque_lbl, buf);
|
||||
setText(g_torque_lbl, buf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%u", dl.pedal_percent);
|
||||
lv_label_set_text(g_pedal_lbl, buf);
|
||||
setText(g_pedal_lbl, buf);
|
||||
|
||||
// Provisional rpm from the single-point Launch factor (see automotive_data.h).
|
||||
snprintf(buf, sizeof(buf), "%u", can_output_shaft_rpm(dl.output_shaft_raw));
|
||||
lv_label_set_text(g_shaft_lbl, buf);
|
||||
setText(g_shaft_lbl, buf);
|
||||
|
||||
// ---- status chips ----------------------------------------------------
|
||||
setChip(g_ign_chip, dl.ignition_on ? "IGN ON" : "IGN OFF",
|
||||
|
||||
@@ -28,6 +28,14 @@ static uint32_t g_flushes = 0;
|
||||
static uint32_t g_flush_us_sum = 0;
|
||||
static uint32_t g_flush_px_sum = 0;
|
||||
|
||||
// vsync counters: written from the panel ISR, read from the reporter. 32-bit
|
||||
// aligned loads/stores are atomic on this core; no lock in the ISR.
|
||||
static volatile uint32_t g_vsync_count = 0;
|
||||
static volatile uint32_t g_vsync_gap_max_us = 0;
|
||||
static volatile uint32_t g_vsync_last_us = 0;
|
||||
|
||||
static esp_timer_handle_t g_timer = NULL;
|
||||
|
||||
// ---- window bookkeeping (loop) --------------------------------------------
|
||||
static int64_t g_window_start_us = 0;
|
||||
static uint64_t g_idle_start[2] = {0, 0};
|
||||
@@ -56,11 +64,15 @@ static uint64_t idleCounter(int core) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void timerCallback(void* arg);
|
||||
|
||||
static void resetWindow() {
|
||||
portENTER_CRITICAL(&g_mux);
|
||||
g_frames = g_frame_ms_sum = g_frame_ms_max = g_frame_px_sum = 0;
|
||||
g_flushes = g_flush_us_sum = g_flush_px_sum = 0;
|
||||
portEXIT_CRITICAL(&g_mux);
|
||||
g_vsync_count = 0;
|
||||
g_vsync_gap_max_us = 0;
|
||||
g_window_start_us = esp_timer_get_time();
|
||||
g_idle_start[0] = idleCounter(0);
|
||||
g_idle_start[1] = idleCounter(1);
|
||||
@@ -68,6 +80,14 @@ static void resetWindow() {
|
||||
|
||||
void init() {
|
||||
resetWindow();
|
||||
if (!g_timer) {
|
||||
esp_timer_create_args_t a = {};
|
||||
a.callback = timerCallback;
|
||||
a.arg = NULL;
|
||||
a.dispatch_method = ESP_TIMER_TASK;
|
||||
a.name = "perf";
|
||||
esp_timer_create(&a, &g_timer);
|
||||
}
|
||||
}
|
||||
|
||||
void onFrame(uint32_t time_ms, uint32_t px) {
|
||||
@@ -87,6 +107,17 @@ void onFlush(uint32_t time_us, uint32_t px) {
|
||||
portEXIT_CRITICAL(&g_mux);
|
||||
}
|
||||
|
||||
void IRAM_ATTR onVsync() {
|
||||
uint32_t now = (uint32_t)esp_timer_get_time();
|
||||
uint32_t last = g_vsync_last_us;
|
||||
g_vsync_last_us = now;
|
||||
g_vsync_count = g_vsync_count + 1;
|
||||
if (last != 0) {
|
||||
uint32_t gap = now - last;
|
||||
if (gap > g_vsync_gap_max_us) g_vsync_gap_max_us = gap;
|
||||
}
|
||||
}
|
||||
|
||||
/** Emit one PERF line for the window since the last reset, then reset. */
|
||||
static void report() {
|
||||
int64_t now_us = esp_timer_get_time();
|
||||
@@ -99,6 +130,10 @@ static void report() {
|
||||
flushes = g_flushes; fl_us = g_flush_us_sum; fl_px = g_flush_px_sum;
|
||||
portEXIT_CRITICAL(&g_mux);
|
||||
|
||||
uint32_t vsyncs = g_vsync_count;
|
||||
uint32_t vgap = g_vsync_gap_max_us;
|
||||
unsigned vsync_per_s = (unsigned)((uint64_t)vsyncs * 1000000ULL / win_us);
|
||||
|
||||
uint64_t idle0 = idleCounter(0) - g_idle_start[0];
|
||||
uint64_t idle1 = idleCounter(1) - g_idle_start[1];
|
||||
unsigned idle0_pct = (unsigned)((idle0 * 100) / win_us);
|
||||
@@ -117,7 +152,7 @@ static void report() {
|
||||
lv_idle = lv_timer_get_idle();
|
||||
}
|
||||
|
||||
print("PERF,%lu,%u.%u,%u.%u,%lu,%u,%u,%u,%u,%u,%u,%u,%u",
|
||||
print("PERF,%lu,%u.%u,%u.%u,%lu,%u,%u,%u,%u,%u,%u,%u,%u,%u,%lu",
|
||||
(unsigned long)millis(),
|
||||
fps10 / 10, fps10 % 10,
|
||||
avg_ms10 / 10, avg_ms10 % 10,
|
||||
@@ -128,7 +163,8 @@ static void report() {
|
||||
idle0_pct, idle1_pct,
|
||||
(unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||
(unsigned)heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT),
|
||||
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||
(unsigned)heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
vsync_per_s, (unsigned long)vgap);
|
||||
(void)flushes; (void)fl_px;
|
||||
resetWindow();
|
||||
}
|
||||
@@ -137,7 +173,7 @@ static void help() {
|
||||
print("perf one PERF line for the window since the last report");
|
||||
print("perf on [sec] PERF line every <sec> seconds (default 1) while you provoke symptoms");
|
||||
print("perf off");
|
||||
print("PERF,ts,fps,avg_ms,max_ms,kpx/frame,flush_ms/s,lvgl_idle%%,idle0%%,idle1%%,int_free,int_largest,psram_free");
|
||||
print("PERF,ts,fps,avg_ms,max_ms,kpx/frame,flush_ms/s,lvgl_idle%%,idle0%%,idle1%%,int_free,int_largest,psram_free,vsync/s,vsync_gap_max_us");
|
||||
}
|
||||
|
||||
bool handleCommand(const char* line) {
|
||||
@@ -159,21 +195,30 @@ bool handleCommand(const char* line) {
|
||||
g_periodic = true;
|
||||
g_last_report_ms = millis();
|
||||
resetWindow();
|
||||
print("[perf] periodic every %ld s (columns: ts,fps,avg_ms,max_ms,kpx,flush_ms/s,lv_idle,idle0,idle1,int_free,int_largest,psram)", s);
|
||||
// esp_timer, not loop(): the OTA job blocks loop() for the whole download
|
||||
// and that is exactly when we want to see the panel counters.
|
||||
if (g_timer) esp_timer_stop(g_timer);
|
||||
if (g_timer) esp_timer_start_periodic(g_timer, (uint64_t)g_period_ms * 1000ULL);
|
||||
print("[perf] periodic every %ld s (columns: ts,fps,avg_ms,max_ms,kpx,flush_ms/s,lv_idle,idle0,idle1,int_free,int_largest,psram,vsync/s,vsync_gap_max_us)", s);
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(argv[1], "off")) {
|
||||
g_periodic = false;
|
||||
if (g_timer) esp_timer_stop(g_timer);
|
||||
print("[perf] periodic off");
|
||||
return true;
|
||||
}
|
||||
if (!strcmp(argv[1], "off")) { g_periodic = false; print("[perf] periodic off"); return true; }
|
||||
help();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void timerCallback(void* arg) {
|
||||
(void)arg;
|
||||
if (g_periodic) report();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
if (!g_periodic) return;
|
||||
uint32_t now = millis();
|
||||
if (now - g_last_report_ms >= g_period_ms) {
|
||||
g_last_report_ms = now;
|
||||
report();
|
||||
}
|
||||
// Reporting moved to the esp_timer (see handleCommand "on").
|
||||
}
|
||||
|
||||
} // namespace PerfMon
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
*
|
||||
* PERF line (CSV, greppable like CANRAW):
|
||||
* PERF,<ts_ms>,<fps>,<avg_ms>,<max_ms>,<kpx/frame>,<flush_ms/s>,
|
||||
* <lvgl_idle%>,<idle0%>,<idle1%>,<int_free>,<int_largest>,<psram_free>
|
||||
* <lvgl_idle%>,<idle0%>,<idle1%>,<int_free>,<int_largest>,<psram_free>,
|
||||
* <vsync/s>,<vsync_gap_max_us>
|
||||
* vsync/s is the panel's own refresh rate (constant when healthy);
|
||||
* vsync_gap_max_us is the longest interval between two refreshes in the
|
||||
* window - a DMA underrun/restart stretches it.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -37,10 +41,20 @@ void onFrame(uint32_t time_ms, uint32_t px);
|
||||
/** Hook for the flush callback - one pixel copy into the framebuffer. */
|
||||
void onFlush(uint32_t time_us, uint32_t px);
|
||||
|
||||
/**
|
||||
* Hook for the RGB panel's refresh-finished (vsync) interrupt. ISR context:
|
||||
* counts frames the panel actually completed and the longest gap between two,
|
||||
* which is where a DMA underrun / restart (flicker, dots) shows up.
|
||||
*/
|
||||
void onVsync();
|
||||
|
||||
/** Console line beginning with "perf". */
|
||||
bool handleCommand(const char* line);
|
||||
|
||||
/** Periodic reporting. Call from loop(). */
|
||||
/**
|
||||
* Kept for compatibility; periodic reporting now runs from an esp_timer so it
|
||||
* survives a blocked loop() (the OTA job). Safe to call, does nothing.
|
||||
*/
|
||||
void tick();
|
||||
|
||||
} // namespace PerfMon
|
||||
|
||||
Reference in New Issue
Block a user