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

[Tizen] Run single thread for processing all GLib sources #25762

Merged
merged 14 commits into from
Apr 14, 2023

Conversation

arkq
Copy link
Contributor

@arkq arkq commented Mar 21, 2023

Problem

Currently Tizen platform spawns a new thread every time an async Tizen API call is about to be made. This is required to make sure that Tizen API internally will attach IO sources to correct context - context which is processed by Matter event loop. A dedicated Matter event loop is required, because it is possible, that Tizen application will not run default GLib main event loop.

This PR is a first step for adding proper matter stack locking when processing GLib-based Tizen events.

Changes

  • run Matter GLib main event loop in a dedicated thread started during Matter stack initialization
  • synchronically invoke all async Tizen API calls on the Matter GLib context (so it will be processed by our dedicated thread)
  • removed MainLoop class

Testing

Tested locally by performing BLE commissioning Linux-Tizen, Tizen-Linux and Tizen-Tizen.
CI will test network commissioning.

@github-actions github-actions bot added platform tizen For Tizen platform labels Mar 21, 2023
@github-actions
Copy link

PR #25762: Size comparison from f994dae to 6adb6e4

Decreases (1 build for cc32xx)
platform target config section f994dae 6adb6e4 change % change
cc32xx lock CC3235SF_LAUNCHXL .debug_info 20248023 20248022 -1 -0.0
Full report (1 build for cc32xx)
platform target config section f994dae 6adb6e4 change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 645601 645601 0 0.0
(read/write) 203848 203848 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197248 197248 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 930292 930292 0 0.0
.debug_aranges 87400 87400 0 0.0
.debug_frame 300320 300320 0 0.0
.debug_info 20248023 20248022 -1 -0.0
.debug_line 2661345 2661345 0 0.0
.debug_loc 2805489 2805489 0 0.0
.debug_ranges 283264 283264 0 0.0
.debug_str 3027174 3027174 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105993 105993 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 380421 380421 0 0.0
.symtab 257408 257408 0 0.0
.text 537488 537488 0 0.0

@github-actions
Copy link

PR #25762: Size comparison from ec2ad41 to 6ff2e19

Increases (1 build for cc32xx)
platform target config section ec2ad41 6ff2e19 change % change
cc32xx lock CC3235SF_LAUNCHXL .debug_info 20309905 20309906 1 0.0
Full report (1 build for cc32xx)
platform target config section ec2ad41 6ff2e19 change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 645745 645745 0 0.0
(read/write) 203848 203848 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197248 197248 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 933102 933102 0 0.0
.debug_aranges 87704 87704 0 0.0
.debug_frame 301604 301604 0 0.0
.debug_info 20309905 20309906 1 0.0
.debug_line 2680953 2680953 0 0.0
.debug_loc 2827596 2827596 0 0.0
.debug_ranges 286376 286376 0 0.0
.debug_str 3041114 3041114 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105953 105953 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 380555 380555 0 0.0
.symtab 257456 257456 0 0.0
.text 537672 537672 0 0.0

@github-actions
Copy link

PR #25762: Size comparison from a27bc8c to 6a2c8c9

Increases (1 build for cc32xx)
platform target config section a27bc8c 6a2c8c9 change % change
cc32xx lock CC3235SF_LAUNCHXL .debug_info 20310043 20310044 1 0.0
Full report (1 build for cc32xx)
platform target config section a27bc8c 6a2c8c9 change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 645769 645769 0 0.0
(read/write) 203848 203848 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197248 197248 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 933102 933102 0 0.0
.debug_aranges 87704 87704 0 0.0
.debug_frame 301596 301596 0 0.0
.debug_info 20310043 20310044 1 0.0
.debug_line 2681003 2681003 0 0.0
.debug_loc 2827360 2827360 0 0.0
.debug_ranges 286352 286352 0 0.0
.debug_str 3041144 3041144 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105953 105953 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 380543 380543 0 0.0
.symtab 257472 257472 0 0.0
.text 537696 537696 0 0.0

@github-actions
Copy link

PR #25762: Size comparison from a27bc8c to 2ee6abb

Full report (1 build for cc32xx)
platform target config section a27bc8c 2ee6abb change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 645769 645769 0 0.0
(read/write) 203848 203848 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197248 197248 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 933102 933102 0 0.0
.debug_aranges 87704 87704 0 0.0
.debug_frame 301596 301596 0 0.0
.debug_info 20310043 20310043 0 0.0
.debug_line 2681003 2681003 0 0.0
.debug_loc 2827360 2827360 0 0.0
.debug_ranges 286352 286352 0 0.0
.debug_str 3041144 3041144 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105953 105953 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 380543 380543 0 0.0
.symtab 257472 257472 0 0.0
.text 537696 537696 0 0.0

Copy link
Contributor

@dh79pyun dh79pyun left a comment

Choose a reason for hiding this comment

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

Looks good

@hyunuktak
Copy link
Contributor

It looks good overall. and i have a question for you.
In the changed structure, is there an action for timeout if the call is not completed for the asynchronous function call?

@arkq
Copy link
Contributor Author

arkq commented Apr 11, 2023

In the changed structure, is there an action for timeout if the call is not completed for the asynchronous function call?

@hyunuktak , no, currently there is no such concept as timeout for GLibMatterContextInvokeSync() calls. This function is not async, but synchronous by design. The purpose of this function is to run given callback on GLib context, that's all. The next step for this refactoring (in another PR) will be proper locking of matter stack when running callback function. However, we are not sure whether it will be possible without duplicating glib internal functions. So, other possibility is that the dedicated glib thread will be removed. So, for internal calls the g_main_context_invoke_full() in the GLibMatterContextInvokeSync() will not switch threads at all - callback will be called right away. If one wants async processing it will have to be done separately, e.g. use glib timeout source (but not with g_idle_add() - this will use global main context, and we do not want that).

EDIT:
As for now I will convert this PR to draft, because some small fixes are required for that PR (I've discovered some issues when working on #25960)

@arkq arkq marked this pull request as draft April 11, 2023 07:16
@arkq arkq marked this pull request as ready for review April 14, 2023 14:09
@github-actions
Copy link

PR #25762: Size comparison from b42e176 to e6a495f

Decreases (1 build for cc32xx)
platform target config section b42e176 e6a495f change % change
cc32xx lock CC3235SF_LAUNCHXL .debug_info 20326061 20326060 -1 -0.0
Full report (1 build for cc32xx)
platform target config section b42e176 e6a495f change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 643081 643081 0 0.0
(read/write) 203848 203848 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197248 197248 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 933224 933224 0 0.0
.debug_aranges 87760 87760 0 0.0
.debug_frame 302028 302028 0 0.0
.debug_info 20326061 20326060 -1 -0.0
.debug_line 2687403 2687403 0 0.0
.debug_loc 2838361 2838361 0 0.0
.debug_ranges 288040 288040 0 0.0
.debug_str 3042379 3042379 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 104393 104393 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 377626 377626 0 0.0
.symtab 256832 256832 0 0.0
.text 536568 536568 0 0.0

@andy31415 andy31415 merged commit a202465 into project-chip:master Apr 14, 2023
@arkq arkq deleted the tizen-glib-one-thread-v2 branch April 14, 2023 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants