From f880cc8c15089c8d33145b71e0c2fbf2af050709 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 5 Feb 2024 08:42:15 +0100 Subject: [PATCH] fix(benchmark): improve the benchmark (#5558) --- demos/benchmark/lv_demo_benchmark.c | 94 ++++++++++++++++++----------- src/core/lv_refr.c | 4 ++ src/misc/lv_event.h | 2 + src/others/sysmon/lv_sysmon.c | 27 +++++++-- src/others/sysmon/lv_sysmon.h | 8 ++- 5 files changed, 92 insertions(+), 43 deletions(-) diff --git a/demos/benchmark/lv_demo_benchmark.c b/demos/benchmark/lv_demo_benchmark.c index 3f9d4d255..a7e9f16f9 100644 --- a/demos/benchmark/lv_demo_benchmark.c +++ b/demos/benchmark/lv_demo_benchmark.c @@ -117,12 +117,15 @@ static void multiple_rgb_images_cb(void) lv_obj_set_style_pad_row(lv_screen_active(), 20, 0); LV_IMG_DECLARE(img_benchmark_cogwheel_rgb); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 116; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 116) / 116; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 116; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 116) / 116; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * obj = lv_img_create(lv_screen_active()); lv_image_set_src(obj, &img_benchmark_cogwheel_rgb); @@ -140,12 +143,15 @@ static void multiple_argb_images_cb(void) lv_obj_set_style_pad_row(lv_screen_active(), 20, 0); LV_IMG_DECLARE(img_benchmark_cogwheel_argb); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 116; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 116) / 116; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 116; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 116) / 116; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * obj = lv_img_create(lv_screen_active()); lv_image_set_src(obj, &img_benchmark_cogwheel_argb); @@ -163,12 +169,15 @@ static void rotated_argb_image_cb(void) lv_obj_set_style_pad_row(lv_screen_active(), 20, 0); LV_IMG_DECLARE(img_benchmark_cogwheel_argb); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 116; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 116) / 116; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 116; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 116) / 116; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * obj = lv_img_create(lv_screen_active()); lv_image_set_src(obj, &img_benchmark_cogwheel_argb); @@ -190,10 +199,12 @@ static void multiple_labels_cb(void) lv_text_get_size(&s, "Hello LVGL!", lv_obj_get_style_text_font(lv_screen_active(), 0), 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE); - uint32_t cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / (s.x + 30); + int32_t cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / (s.x + 30); cnt = cnt * ((lv_display_get_vertical_resolution(NULL) - 200) / (s.y + 50)); - uint32_t i; + if(cnt < 1) cnt = 1; + + int32_t i; for(i = 0; i < cnt; i++) { lv_obj_t * obj = lv_label_create(lv_screen_active()); lv_label_set_text(obj, "Hello LVGL!"); @@ -227,12 +238,15 @@ static void multiple_arcs_cb(void) lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); LV_IMG_DECLARE(img_benchmark_cogwheel_argb); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / lv_dpx(160); - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / lv_dpx(160); + int32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / lv_dpx(160); + int32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / lv_dpx(160); - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * obj = lv_arc_create(lv_screen_active()); @@ -259,12 +273,15 @@ static void containers_cb(void) lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 300; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / 150; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 300; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 16) / 150; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * card = card_create(); if(x == 0) lv_obj_add_flag(card, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); @@ -278,12 +295,15 @@ static void containers_with_overlay_cb(void) lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 300; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / 150; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 300; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 16) / 150; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * card = card_create(); if(x == 0) lv_obj_add_flag(card, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); @@ -300,12 +320,15 @@ static void containers_with_opa_cb(void) lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 300; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / 150; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 300; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 16) / 150; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * card = card_create(); if(x == 0) lv_obj_add_flag(card, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); @@ -320,12 +343,15 @@ static void containers_with_opa_layer_cb(void) lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW_WRAP); lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - uint32_t hor_cnt = (lv_display_get_horizontal_resolution(NULL) - 16) / 300; - uint32_t ver_cnt = (lv_display_get_vertical_resolution(NULL) - 16) / 150; + int32_t hor_cnt = ((int32_t)lv_display_get_horizontal_resolution(NULL) - 16) / 300; + int32_t ver_cnt = ((int32_t)lv_display_get_vertical_resolution(NULL) - 16) / 150; - uint32_t y; + if(hor_cnt < 1) hor_cnt = 1; + if(ver_cnt < 1) ver_cnt = 1; + + int32_t y; for(y = 0; y < ver_cnt; y++) { - uint32_t x; + int32_t x; for(x = 0; x < hor_cnt; x++) { lv_obj_t * card = card_create(); lv_obj_set_style_opa_layered(card, LV_OPA_50, 0); diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index 5bedd063b..dc9d3b303 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -1055,6 +1055,8 @@ static void wait_for_flushing(lv_display_t * disp) LV_PROFILER_BEGIN; LV_LOG_TRACE("begin"); + lv_display_send_event(disp, LV_EVENT_FLUSH_WAIT_START, NULL); + if(disp->flush_wait_cb) { disp->flush_wait_cb(disp); } @@ -1063,6 +1065,8 @@ static void wait_for_flushing(lv_display_t * disp) } disp->flushing_last = 0; + lv_display_send_event(disp, LV_EVENT_FLUSH_WAIT_FINISH, NULL); + LV_LOG_TRACE("end"); LV_PROFILER_END; } diff --git a/src/misc/lv_event.h b/src/misc/lv_event.h index d5926dd1b..de47c368b 100644 --- a/src/misc/lv_event.h +++ b/src/misc/lv_event.h @@ -107,6 +107,8 @@ typedef enum { LV_EVENT_RENDER_READY, LV_EVENT_FLUSH_START, LV_EVENT_FLUSH_FINISH, + LV_EVENT_FLUSH_WAIT_START, + LV_EVENT_FLUSH_WAIT_FINISH, LV_EVENT_VSYNC, diff --git a/src/others/sysmon/lv_sysmon.c b/src/others/sysmon/lv_sysmon.c index 067064998..609efc122 100644 --- a/src/others/sysmon/lv_sysmon.c +++ b/src/others/sysmon/lv_sysmon.c @@ -126,18 +126,31 @@ static void perf_monitor_disp_event_cb(lv_event_t * e) info->measured.refr_cnt++; break; case LV_EVENT_RENDER_START: + info->measured.render_in_progress = 1; info->measured.render_start = lv_tick_get(); break; case LV_EVENT_RENDER_READY: + info->measured.render_in_progress = 0; info->measured.render_elaps_sum += lv_tick_elaps(info->measured.render_start); info->measured.render_cnt++; break; case LV_EVENT_FLUSH_START: - info->measured.flush_start = lv_tick_get(); + case LV_EVENT_FLUSH_WAIT_START: + if(info->measured.render_in_progress) { + info->measured.flush_in_render_start = lv_tick_get(); + } + else { + info->measured.flush_not_in_render_start = lv_tick_get(); + } break; case LV_EVENT_FLUSH_FINISH: - info->measured.flush_elaps_sum += lv_tick_elaps(info->measured.flush_start); - info->measured.flush_cnt++; + case LV_EVENT_FLUSH_WAIT_FINISH: + if(info->measured.render_in_progress) { + info->measured.flush_in_render_elaps_sum += lv_tick_elaps(info->measured.flush_in_render_start); + } + else { + info->measured.flush_not_in_render_elaps_sum += lv_tick_elaps(info->measured.flush_not_in_render_start); + } break; default: break; @@ -171,11 +184,13 @@ static void perf_update_timer_cb(lv_timer_t * t) info->calculated.cpu = 100 - LV_SYSMON_GET_IDLE(); info->calculated.refr_avg_time = info->measured.refr_cnt ? (info->measured.refr_elaps_sum / info->measured.refr_cnt) : 0; - info->calculated.flush_avg_time = info->measured.flush_cnt ? (info->measured.flush_elaps_sum / info->measured.flush_cnt) - : 0; + + info->calculated.flush_avg_time = info->measured.render_cnt ? + ((info->measured.flush_in_render_elaps_sum + info->measured.flush_not_in_render_elaps_sum) + / info->measured.render_cnt) : 0; /*Flush time was measured in rendering time so subtract it*/ info->calculated.render_avg_time = info->measured.render_cnt ? ((info->measured.render_elaps_sum - - info->measured.flush_elaps_sum) / + info->measured.flush_in_render_elaps_sum) / info->measured.render_cnt) : 0; info->calculated.cpu_avg_total = ((info->calculated.cpu_avg_total * (info->calculated.run_cnt - 1)) + diff --git a/src/others/sysmon/lv_sysmon.h b/src/others/sysmon/lv_sysmon.h index 982adc74e..74ab800bd 100644 --- a/src/others/sysmon/lv_sysmon.h +++ b/src/others/sysmon/lv_sysmon.h @@ -52,9 +52,11 @@ typedef struct { uint32_t render_start; uint32_t render_elaps_sum; /*Contains the flush time too*/ uint32_t render_cnt; - uint32_t flush_start; - uint32_t flush_elaps_sum; - uint32_t flush_cnt; + uint32_t flush_in_render_start; + uint32_t flush_in_render_elaps_sum; + uint32_t flush_not_in_render_start; + uint32_t flush_not_in_render_elaps_sum; + uint32_t render_in_progress : 1; } measured; struct {