Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(draw): fix the default draw thread stack is too large #5951

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

FASTSHIFT
Copy link
Collaborator

@FASTSHIFT FASTSHIFT commented Mar 25, 2024

Description of the feature or fix

Fix the memory waste caused by the default draw thread stack being too large, and add a stack size check when some components that consume stack space are opened.

cc @GorgonMeducer

Notes

@FASTSHIFT FASTSHIFT force-pushed the fix_draw_stack branch 5 times, most recently from b87a061 to 6ca97b2 Compare March 25, 2024 04:08
Copy link
Contributor

@W-Mai W-Mai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding freetype stack limitations 😁

@GorgonMeducer
Copy link
Contributor

It looks good to me. Maybe we can add check for other components too.

XuNeo
XuNeo previously approved these changes Mar 25, 2024
@kisvegabor
Copy link
Member

Do you have any info about the stack usage of ThorVG?

@FASTSHIFT
Copy link
Collaborator Author

Do you have any info about the stack usage of ThorVG?

I haven't tested ThorVG on embedded devices yet. Have you tested it before? How many stacks were used?

@kisvegabor
Copy link
Member

I've used it for Lottie animations. I'll check the stack usage today.

@kisvegabor
Copy link
Member

I've tested with rendering the vector demo in 100x100 and 200x200 resolution. The extra stack usage was the same in both cases: 20kB. So let's say minimum 24kB is needed, but 32kB is recommended.

In lv_draw_sw.c we can also check the set stack size based and if it's to small based on the settings an #error or #warning can be triggered.

On side note, in case of multi core rendering, we could dedicate a core to FreeType and/or ThorVG, so that we don't need to allocate that large stack multiple times.

@FASTSHIFT
Copy link
Collaborator Author

I've tested with rendering the vector demo in 100x100 and 200x200 resolution. The extra stack usage was the same in both cases: 20kB. So let's say minimum 24kB is needed, but 32kB is recommended.

In lv_draw_sw.c we can also check the set stack size based and if it's to small based on the settings an #error or #warning can be triggered.

On side note, in case of multi core rendering, we could dedicate a core to FreeType and/or ThorVG, so that we don't need to allocate that large stack multiple times.

Done,The ThorVG check has been added.

@FASTSHIFT FASTSHIFT requested a review from XuNeo April 4, 2024 08:59
Signed-off-by: FASTSHIFT <[email protected]>
Signed-off-by: FASTSHIFT <[email protected]>
XuNeo
XuNeo previously approved these changes Apr 4, 2024
config LV_DRAW_THREAD_STACK_SIZE
int "Stack size of draw thread in bytes"
default 8192
depends on LV_USE_OS > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also depends on LV_USE_DRAW_SW as its the stack size of the SW render task.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LV_DRAW_THREAD_STACK_SIZE should work as a general configuration, not just for software rendering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessarily true that all renderes need 8k RAM by default. A simpler one optimized of for size with less features might use only 2kB, but a heavier one might need much more.

E.g. PXP has a hard coded 2kB stack size. So LV_DRAW_THREAD_STACK_SIZE is not really a general configuration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's come to a conclusion on this before merging.

Copy link
Collaborator Author

@FASTSHIFT FASTSHIFT Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be done the other way around. Most draw units should use LV_DRAW_THREAD_STACK_SIZE as stack size configuration instead of hard-coding. If the draw unit does not need to draw freetype fonts, it can be hard-coded in its own code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there are 2 cases:

  1. The GPU is limited and doesn't really depend on lv_conf.h ➡️ the stack size can be hardcoded (e.g. PXP)
  2. The GPU is more powerful and can use FreeType or ThorVG if enabled ➡️ it should use LV_DRAW_THREAD_STACK_SIZE.

If we approach it like this, I agree with current version. 👍

lv_conf_template.h Show resolved Hide resolved
@kisvegabor kisvegabor merged commit 4d0c029 into lvgl:master Apr 8, 2024
16 checks passed
@FASTSHIFT FASTSHIFT deleted the fix_draw_stack branch April 10, 2024 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants