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

SystemLayerImplSelect: fix Request/ClearCallbackOnPendingXXX() for… #21135

Merged

Conversation

plan44
Copy link
Contributor

@plan44 plan44 commented Jul 22, 2022

…dispatch case, clean transport

Problem

For CHIP_SYSTEM_CONFIG_USE_DISPATCH (Darwin) case, Request/ClearCallbackOnPendingXXX() were not working (no loop calling select to evaluate watches).
But still, these methods were called in TCP and UDP endpoint implementations, despite dispatch-specific extra code for the same purpose in the endpoints.

Change overview

This changeset now moves all CHIP_SYSTEM_CONFIG_USE_DISPATCH specific socket watching code into SystemLayerImplSelect, by making Request/ClearCallbackOnPendingXXX() actually working with dispatch.

The issue surfaced in my (a bit exotic) use case when I needed to get callbacks for events on a plain socket not wrapped as TCPEndPoint.
Doing this, I realized Request/ClearCallbackOnPendingXXX() were non-functional due to the missing select main loop.
Fixing this revealed the similar dispatch code in the endpoints that was needed to get those events handled despite Request/ClearCallbackOnPendingXXX() not working. That dispatch specific endpoint code now became redundant (delivering events twice), so had to be removed.

Testing

  • manually regression tested with bridge-example running on darwin (hence using dispatch), showing no difference when being run with and w/o these changes applied - except for Request/ClearCallbackOnPendingXXX() not working without the changes.

I am aware that this might be a too deep intervention and too limited testing for coming from a CHIP newbie like me (not newbie in code deep diving, though), but I think it cleans up an inconsistency in the IP endpoints, and maybe can be of use after review by CHIP experts...

@github-actions
Copy link

github-actions bot commented Jul 22, 2022

PR #21135: Size comparison from e58147e to 3b3b1b1

Increases (2 builds for cc13x2_26x2, cyw30739)
platform target config section e58147e 3b3b1b1 change % change
cc13x2_26x2 shell LP_CC2652R7 (read/write) 185980 185988 8 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 582034 582042 8 0.0
.app_xip_area 460424 460432 8 0.0
Decreases (15 builds for cc13x2_26x2, linux, nrfconnect, telink)
platform target config section e58147e 3b3b1b1 change % change
cc13x2_26x2 all-clusters-minimal-app LP_CC2652R7 (read only) 633983 633975 -8 -0.0
.text 556100 556092 -8 -0.0
shell LP_CC2652R7 (read only) 660866 660858 -8 -0.0
.text 575444 575436 -8 -0.0
linux all-clusters-app debug (read only) 2981689 2981673 -16 -0.0
.text 2537682 2537666 -16 -0.0
all-clusters-minimal-app debug (read only) 2827585 2827569 -16 -0.0
.text 2385394 2385378 -16 -0.0
chip-tool-ipv6only arm64 (read only) 9779324 9779308 -16 -0.0
.text 7737204 7737188 -16 -0.0
lighting-app debug+rpc (read only) 2565441 2565425 -16 -0.0
.text 2179986 2179970 -16 -0.0
lock-app debug (read only) 2530433 2530417 -16 -0.0
.text 2134770 2134754 -16 -0.0
ota-provider-app debug (read only) 2334081 2334065 -16 -0.0
.text 1965954 1965938 -16 -0.0
ota-requestor-app debug (read only) 2452505 2452489 -16 -0.0
.text 2072290 2072274 -16 -0.0
tv-app debug (read only) 3116033 3116017 -16 -0.0
.text 2677042 2677026 -16 -0.0
tv-casting-app debug (read only) 5369777 5369761 -16 -0.0
.text 4768498 4768482 -16 -0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1177091 1177075 -16 -0.0
text 812588 812576 -12 -0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1157143 1157127 -16 -0.0
text 801900 801884 -16 -0.0
telink light-switch-app tlsr9518adk80d (read/write) 799620 799604 -16 -0.0
text 567210 567198 -12 -0.0
lighting-app tlsr9518adk80d (read/write) 819668 819652 -16 -0.0
text 583756 583744 -12 -0.0
Full report (43 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section e58147e 3b3b1b1 change % change
bl602 lighting-app bl602 (read/write) 1380794 1380794 0 0.0
.bss 117474 117474 0 0.0
.data 4480 4480 0 0.0
.text 1050944 1050944 0 0.0
bl602+rpc (read/write) 1426202 1426202 0 0.0
.bss 124922 124922 0 0.0
.data 4600 4600 0 0.0
.text 1082600 1082600 0 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 668383 668383 0 0.0
(read/write) 182960 182960 0 0.0
.bss 74236 74236 0 0.0
.data 3356 3356 0 0.0
.rodata 88335 88335 0 0.0
.text 579732 579732 0 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 633983 633975 -8 -0.0
(read/write) 157804 157804 0 0.0
.bss 73532 73532 0 0.0
.data 3356 3356 0 0.0
.rodata 77559 77559 0 0.0
.text 556100 556092 -8 -0.0
lock-ftd LP_CC2652R7 (read only) 671595 671595 0 0.0
(read/write) 169924 169924 0 0.0
.bss 71300 71300 0 0.0
.data 3280 3280 0 0.0
.rodata 76451 76451 0 0.0
.text 594664 594664 0 0.0
lock-mtd LP_CC2652R7 (read only) 653847 653847 0 0.0
(read/write) 183360 183360 0 0.0
.bss 66988 66988 0 0.0
.data 3280 3280 0 0.0
.rodata 101167 101167 0 0.0
.text 552200 552200 0 0.0
pump-app LP_CC2652R7 (read only) 681271 681271 0 0.0
(read/write) 161104 161104 0 0.0
.bss 71388 71388 0 0.0
.data 3280 3280 0 0.0
.rodata 89183 89183 0 0.0
.text 591604 591604 0 0.0
pump-controller-app LP_CC2652R7 (read only) 667039 667039 0 0.0
(read/write) 175456 175456 0 0.0
.bss 71508 71508 0 0.0
.data 3276 3276 0 0.0
.rodata 85039 85039 0 0.0
.text 581520 581520 0 0.0
shell LP_CC2652R7 (read only) 660866 660858 -8 -0.0
(read/write) 185980 185988 8 0.0
.bss 76540 76540 0 0.0
.data 3360 3360 0 0.0
.rodata 85106 85106 0 0.0
.text 575444 575436 -8 -0.0
cyw30739 light cyw930739m2evb_01 (read/write) 582034 582042 8 0.0
.app_xip_area 460424 460432 8 0.0
.bss 64404 64404 0 0.0
.data 716 716 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 587942 587942 0 0.0
.app_xip_area 461604 461604 0 0.0
.bss 69132 69132 0 0.0
.data 720 720 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 586494 586494 0 0.0
.app_xip_area 465732 465732 0 0.0
.bss 63612 63612 0 0.0
.data 660 660 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read/write) 1087680 1087680 0 0.0
.bss 133220 133220 0 0.0
.data 2048 2048 0 0.0
.text 952392 952392 0 0.0
BRD4161A+rpc (read/write) 1141972 1141972 0 0.0
.bss 149892 149892 0 0.0
.data 2260 2260 0 0.0
.text 989796 989796 0 0.0
BRD4161A+rs911x (read/write) 952180 952180 0 0.0
.bss 140928 140928 0 0.0
.data 2048 2048 0 0.0
.text 809184 809184 0 0.0
lock-app BRD4161A+wf200 (read/write) 1128424 1128424 0 0.0
.bss 144304 144304 0 0.0
.data 2056 2056 0 0.0
.text 982044 982044 0 0.0
window-app BRD4161A (read/write) 1081156 1081156 0 0.0
.bss 134692 134692 0 0.0
.data 2076 2076 0 0.0
.text 944368 944368 0 0.0
esp32 all-clusters-app c3devkit (read only) 1021958 1021958 0 0.0
(read/write) 1486434 1486434 0 0.0
.dram0.bss 70232 70232 0 0.0
.dram0.data 14600 14600 0 0.0
.flash.rodata 216160 216160 0 0.0
.flash.text 1021958 1021958 0 0.0
.iram0.text 62902 62902 0 0.0
m5stack (read only) 1075723 1075723 0 0.0
(read/write) 488448 488448 0 0.0
.dram0.bss 75752 75752 0 0.0
.dram0.data 34144 34144 0 0.0
.flash.rodata 246556 246556 0 0.0
.flash.text 1070339 1070339 0 0.0
.iram0.text 123267 123267 0 0.0
k32w light k32w0+release (read/write) 641520 641520 0 0.0
.bss 69696 69696 0 0.0
.data 2028 2028 0 0.0
.text 567068 567068 0 0.0
lock k32w0+release (read/write) 698880 698880 0 0.0
.bss 70144 70144 0 0.0
.data 2036 2036 0 0.0
.text 623972 623972 0 0.0
linux all-clusters-app debug (read only) 2981689 2981673 -16 -0.0
(read/write) 155344 155344 0 0.0
.bss 61792 61792 0 0.0
.data 2064 2064 0 0.0
.data.rel.ro 85224 85224 0 0.0
.dynamic 608 608 0 0.0
.got 4568 4568 0 0.0
.init 27 27 0 0.0
.init_array 1064 1064 0 0.0
.rodata 265867 265867 0 0.0
.text 2537682 2537666 -16 -0.0
all-clusters-minimal-app debug (read only) 2827585 2827569 -16 -0.0
(read/write) 147016 147016 0 0.0
.bss 60992 60992 0 0.0
.data 2064 2064 0 0.0
.data.rel.ro 77784 77784 0 0.0
.dynamic 608 608 0 0.0
.got 4488 4488 0 0.0
.init 27 27 0 0.0
.init_array 1056 1056 0 0.0
.rodata 266731 266731 0 0.0
.text 2385394 2385378 -16 -0.0
bridge-app debug+rpc (read only) 2342289 2342289 0 0.0
(read/write) 126920 126920 0 0.0
.bss 50080 50080 0 0.0
.data 3824 3824 0 0.0
.data.rel.ro 67240 67240 0 0.0
.dynamic 608 608 0 0.0
.got 4392 4392 0 0.0
.init 27 27 0 0.0
.init_array 736 736 0 0.0
.rodata 199368 199368 0 0.0
.text 1980610 1980610 0 0.0
chip-tool debug (read only) 10349889 10349889 0 0.0
(read/write) 631912 631912 0 0.0
.bss 24760 24760 0 0.0
.data 3266 3266 0 0.0
.data.rel.ro 597480 597480 0 0.0
.dynamic 608 608 0 0.0
.got 5088 5088 0 0.0
.init 27 27 0 0.0
.init_array 648 648 0 0.0
.rodata 522005 522005 0 0.0
.text 8374292 8374292 0 0.0
chip-tool-ipv6only arm64 (read only) 9779324 9779308 -16 -0.0
(read/write) 679441 679441 0 0.0
.bss 32833 32833 0 0.0
.data 3272 3272 0 0.0
.data.rel.ro 624824 624824 0 0.0
.dynamic 560 560 0 0.0
.got 13552 13552 0 0.0
.init 24 24 0 0.0
.init_array 192 192 0 0.0
.rodata 457724 457724 0 0.0
.text 7737204 7737188 -16 -0.0
lighting-app debug+rpc (read only) 2565441 2565425 -16 -0.0
(read/write) 129888 129888 0 0.0
.bss 49632 49632 0 0.0
.data 2096 2096 0 0.0
.data.rel.ro 72296 72296 0 0.0
.dynamic 608 608 0 0.0
.got 4392 4392 0 0.0
.init 27 27 0 0.0
.init_array 824 824 0 0.0
.rodata 215056 215056 0 0.0
.text 2179986 2179970 -16 -0.0
lock-app debug (read only) 2530433 2530417 -16 -0.0
(read/write) 124872 124872 0 0.0
.bss 48032 48032 0 0.0
.data 1712 1712 0 0.0
.data.rel.ro 69272 69272 0 0.0
.dynamic 608 608 0 0.0
.got 4424 4424 0 0.0
.init 27 27 0 0.0
.init_array 800 800 0 0.0
.rodata 230064 230064 0 0.0
.text 2134770 2134754 -16 -0.0
ota-provider-app debug (read only) 2334081 2334065 -16 -0.0
(read/write) 118672 118672 0 0.0
.bss 47680 47680 0 0.0
.data 1936 1936 0 0.0
.data.rel.ro 63256 63256 0 0.0
.dynamic 608 608 0 0.0
.got 4488 4488 0 0.0
.init 27 27 0 0.0
.init_array 680 680 0 0.0
.rodata 204920 204920 0 0.0
.text 1965954 1965938 -16 -0.0
ota-requestor-app debug (read only) 2452505 2452489 -16 -0.0
(read/write) 125576 125576 0 0.0
.bss 50016 50016 0 0.0
.data 2240 2240 0 0.0
.data.rel.ro 67480 67480 0 0.0
.dynamic 608 608 0 0.0
.got 4480 4480 0 0.0
.init 27 27 0 0.0
.init_array 736 736 0 0.0
.rodata 208608 208608 0 0.0
.text 2072290 2072274 -16 -0.0
shell debug (read only) 2568297 2568297 0 0.0
(read/write) 141400 141400 0 0.0
.bss 57608 57608 0 0.0
.data 1248 1248 0 0.0
.data.rel.ro 76856 76856 0 0.0
.dynamic 608 608 0 0.0
.got 4136 4136 0 0.0
.init 27 27 0 0.0
.init_array 936 936 0 0.0
.rodata 229170 229170 0 0.0
.text 2181570 2181570 0 0.0
thermostat-no-ble arm64 (read only) 2341916 2341916 0 0.0
(read/write) 141249 141249 0 0.0
.bss 55233 55233 0 0.0
.data 1672 1672 0 0.0
.data.rel.ro 75592 75592 0 0.0
.dynamic 560 560 0 0.0
.got 4984 4984 0 0.0
.init 24 24 0 0.0
.init_array 400 400 0 0.0
.rodata 139572 139572 0 0.0
.text 1965536 1965536 0 0.0
tv-app debug (read only) 3116033 3116017 -16 -0.0
(read/write) 257024 257024 0 0.0
.bss 167064 167064 0 0.0
.data 4736 4736 0 0.0
.data.rel.ro 78792 78792 0 0.0
.dynamic 608 608 0 0.0
.got 4848 4848 0 0.0
.init 27 27 0 0.0
.init_array 960 960 0 0.0
.rodata 250568 250568 0 0.0
.text 2677042 2677026 -16 -0.0
tv-casting-app debug (read only) 5369777 5369761 -16 -0.0
(read/write) 158328 158328 0 0.0
.bss 51256 51256 0 0.0
.data 2432 2432 0 0.0
.data.rel.ro 98352 98352 0 0.0
.dynamic 608 608 0 0.0
.got 4736 4736 0 0.0
.init 27 27 0 0.0
.init_array 920 920 0 0.0
.rodata 334753 334753 0 0.0
.text 4768498 4768482 -16 -0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2449240 2449240 0 0.0
.bss 214444 214444 0 0.0
.data 5872 5872 0 0.0
.text 1411884 1411884 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1177091 1177075 -16 -0.0
bss 143068 143068 0 0.0
rodata 142572 142572 0 0.0
text 812588 812576 -12 -0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1157143 1157127 -16 -0.0
bss 142304 142304 0 0.0
rodata 134104 134104 0 0.0
text 801900 801884 -16 -0.0
p6 all-clusters-app default (read only) 881632 881632 0 0.0
(read/write) 1686628 1686628 0 0.0
.bss 149064 149064 0 0.0
.data 2648 2648 0 0.0
.text 1526528 1526528 0 0.0
all-clusters-minimal-app default (read only) 882352 882352 0 0.0
(read/write) 1630732 1630732 0 0.0
.bss 148344 148344 0 0.0
.data 2648 2648 0 0.0
.text 1471352 1471352 0 0.0
light-app default (read only) 890656 890656 0 0.0
(read/write) 1550972 1550972 0 0.0
.bss 140248 140248 0 0.0
.data 2440 2440 0 0.0
.text 1399896 1399896 0 0.0
lock-app default (read only) 886184 886184 0 0.0
(read/write) 1588564 1588564 0 0.0
.bss 144704 144704 0 0.0
.data 2456 2456 0 0.0
.text 1433016 1433016 0 0.0
telink light-switch-app tlsr9518adk80d (read/write) 799620 799604 -16 -0.0
bss 70744 70744 0 0.0
noinit 40416 40416 0 0.0
text 567210 567198 -12 -0.0
lighting-app tlsr9518adk80d (read/write) 819668 819652 -16 -0.0
bss 71588 71588 0 0.0
noinit 40416 40416 0 0.0
text 583756 583744 -12 -0.0

@bzbarsky-apple
Copy link
Contributor

@vivien-apple

@bzbarsky-apple
Copy link
Contributor

@plan44 Could you look into the test failures, please?

@plan44 plan44 force-pushed the PR/fix_socket_event_watching branch from 3b3b1b1 to 683c97d Compare July 23, 2022 14:37
@github-actions
Copy link

github-actions bot commented Jul 23, 2022

PR #21135: Size comparison from b647dfb to 683c97d

Increases (3 builds for bl602, telink)
platform target config section b647dfb 683c97d change % change
bl602 lighting-app bl602 .text 1050944 1050948 4 0.0
telink light-switch-app tlsr9518adk80d text 567210 567214 4 0.0
lighting-app tlsr9518adk80d text 583754 583758 4 0.0
Decreases (3 builds for cyw30739, k32w, nrfconnect)
platform target config section b647dfb 683c97d change % change
cyw30739 light cyw930739m2evb_01 (read/write) 582042 582034 -8 -0.0
.app_xip_area 460432 460424 -8 -0.0
k32w light k32w0+release (read/write) 641520 641504 -16 -0.0
.text 567068 567052 -16 -0.0
nrfconnect all-clusters-minimal-app nrf52840dk_nrf52840 text 801968 801964 -4 -0.0
Full report (32 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section b647dfb 683c97d change % change
bl602 lighting-app bl602 (read/write) 1380794 1380794 0 0.0
.bss 117474 117474 0 0.0
.data 4480 4480 0 0.0
.text 1050944 1050948 4 0.0
bl602+rpc (read/write) 1426202 1426202 0 0.0
.bss 124922 124922 0 0.0
.data 4600 4600 0 0.0
.text 1082600 1082600 0 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 668479 668479 0 0.0
(read/write) 182864 182864 0 0.0
.bss 74236 74236 0 0.0
.data 3356 3356 0 0.0
.rodata 88367 88367 0 0.0
.text 579796 579796 0 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 634063 634063 0 0.0
(read/write) 157804 157804 0 0.0
.bss 73532 73532 0 0.0
.data 3356 3356 0 0.0
.rodata 77591 77591 0 0.0
.text 556148 556148 0 0.0
lock-ftd LP_CC2652R7 (read only) 671603 671603 0 0.0
(read/write) 169916 169916 0 0.0
.bss 71300 71300 0 0.0
.data 3280 3280 0 0.0
.rodata 76451 76451 0 0.0
.text 594672 594672 0 0.0
lock-mtd LP_CC2652R7 (read only) 653847 653847 0 0.0
(read/write) 183360 183360 0 0.0
.bss 66988 66988 0 0.0
.data 3280 3280 0 0.0
.rodata 101167 101167 0 0.0
.text 552200 552200 0 0.0
pump-app LP_CC2652R7 (read only) 681271 681271 0 0.0
(read/write) 161104 161104 0 0.0
.bss 71388 71388 0 0.0
.data 3280 3280 0 0.0
.rodata 89183 89183 0 0.0
.text 591604 591604 0 0.0
pump-controller-app LP_CC2652R7 (read only) 667039 667039 0 0.0
(read/write) 175456 175456 0 0.0
.bss 71508 71508 0 0.0
.data 3276 3276 0 0.0
.rodata 85039 85039 0 0.0
.text 581520 581520 0 0.0
shell LP_CC2652R7 (read only) 660954 660954 0 0.0
(read/write) 185892 185892 0 0.0
.bss 76540 76540 0 0.0
.data 3360 3360 0 0.0
.rodata 85146 85146 0 0.0
.text 575492 575492 0 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 582042 582034 -8 -0.0
.app_xip_area 460432 460424 -8 -0.0
.bss 64404 64404 0 0.0
.data 716 716 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 587942 587942 0 0.0
.app_xip_area 461604 461604 0 0.0
.bss 69132 69132 0 0.0
.data 720 720 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 586494 586494 0 0.0
.app_xip_area 465732 465732 0 0.0
.bss 63612 63612 0 0.0
.data 660 660 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read/write) 1087680 1087680 0 0.0
.bss 133220 133220 0 0.0
.data 2048 2048 0 0.0
.text 952392 952392 0 0.0
BRD4161A+rpc (read/write) 1141972 1141972 0 0.0
.bss 149892 149892 0 0.0
.data 2260 2260 0 0.0
.text 989796 989796 0 0.0
BRD4161A+rs911x (read/write) 952180 952180 0 0.0
.bss 140928 140928 0 0.0
.data 2048 2048 0 0.0
.text 809184 809184 0 0.0
lock-app BRD4161A+wf200 (read/write) 1128424 1128424 0 0.0
.bss 144304 144304 0 0.0
.data 2056 2056 0 0.0
.text 982044 982044 0 0.0
window-app BRD4161A (read/write) 1081156 1081156 0 0.0
.bss 134692 134692 0 0.0
.data 2076 2076 0 0.0
.text 944368 944368 0 0.0
esp32 all-clusters-app c3devkit (read only) 1022020 1022020 0 0.0
(read/write) 1486522 1486522 0 0.0
.dram0.bss 70232 70232 0 0.0
.dram0.data 14600 14600 0 0.0
.flash.rodata 216248 216248 0 0.0
.flash.text 1022020 1022020 0 0.0
.iram0.text 62902 62902 0 0.0
m5stack (read only) 1075795 1075795 0 0.0
(read/write) 488528 488528 0 0.0
.dram0.bss 75752 75752 0 0.0
.dram0.data 34144 34144 0 0.0
.flash.rodata 246636 246636 0 0.0
.flash.text 1070411 1070411 0 0.0
.iram0.text 123267 123267 0 0.0
k32w light k32w0+release (read/write) 641520 641504 -16 -0.0
.bss 69696 69696 0 0.0
.data 2028 2028 0 0.0
.text 567068 567052 -16 -0.0
lock k32w0+release (read/write) 698880 698880 0 0.0
.bss 70144 70144 0 0.0
.data 2036 2036 0 0.0
.text 623972 623972 0 0.0
linux chip-tool-ipv6only arm64 (read only) 9779324 9779324 0 0.0
(read/write) 679441 679441 0 0.0
.bss 32833 32833 0 0.0
.data 3272 3272 0 0.0
.data.rel.ro 624824 624824 0 0.0
.dynamic 560 560 0 0.0
.got 13552 13552 0 0.0
.init 24 24 0 0.0
.init_array 192 192 0 0.0
.rodata 457724 457724 0 0.0
.text 7737204 7737204 0 0.0
thermostat-no-ble arm64 (read only) 2341916 2341916 0 0.0
(read/write) 141249 141249 0 0.0
.bss 55233 55233 0 0.0
.data 1672 1672 0 0.0
.data.rel.ro 75592 75592 0 0.0
.dynamic 560 560 0 0.0
.got 4984 4984 0 0.0
.init 24 24 0 0.0
.init_array 400 400 0 0.0
.rodata 139572 139572 0 0.0
.text 1965536 1965536 0 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2449240 2449240 0 0.0
.bss 214444 214444 0 0.0
.data 5872 5872 0 0.0
.text 1411884 1411884 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1177235 1177235 0 0.0
bss 143068 143068 0 0.0
rodata 142652 142652 0 0.0
text 812656 812656 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1157287 1157287 0 0.0
bss 142304 142304 0 0.0
rodata 134184 134184 0 0.0
text 801968 801964 -4 -0.0
p6 all-clusters-app default (read only) 881632 881632 0 0.0
(read/write) 1686780 1686780 0 0.0
.bss 149064 149064 0 0.0
.data 2648 2648 0 0.0
.text 1526680 1526680 0 0.0
all-clusters-minimal-app default (read only) 882352 882352 0 0.0
(read/write) 1630884 1630884 0 0.0
.bss 148344 148344 0 0.0
.data 2648 2648 0 0.0
.text 1471504 1471504 0 0.0
light-app default (read only) 890656 890656 0 0.0
(read/write) 1550972 1550972 0 0.0
.bss 140248 140248 0 0.0
.data 2440 2440 0 0.0
.text 1399896 1399896 0 0.0
lock-app default (read only) 886184 886184 0 0.0
(read/write) 1588564 1588564 0 0.0
.bss 144704 144704 0 0.0
.data 2456 2456 0 0.0
.text 1433016 1433016 0 0.0
telink light-switch-app tlsr9518adk80d (read/write) 799620 799620 0 0.0
bss 70744 70744 0 0.0
noinit 40416 40416 0 0.0
text 567210 567214 4 0.0
lighting-app tlsr9518adk80d (read/write) 819668 819668 0 0.0
bss 71588 71588 0 0.0
noinit 40416 40416 0 0.0
text 583754 583758 4 0.0

…spatch, clean transport

For CHIP_SYSTEM_CONFIG_USE_DISPATCH (Darwin) case, Request/ClearCallbackOnPendingXXX() were not working (no loop calling select to evaluate watches), but were called in TCP and UDP endpoint implementations, despite dispatch-specific extra code for the same purpose in the endpoints.

This changeset now moves all CHIP_SYSTEM_CONFIG_USE_DISPATCH specific socket watching code into SystemLayerImplSelect, by making Request/ClearCallbackOnPendingXXX() actually working with dispatch.

The issue surfaced in my (a bit exotic) use case when I needed to get callbacks for events on a plain socket not wrapped as TCPEndPoint.
Doing this, I realized Request/ClearCallbackOnPendingXXX() were non-functional due to missing select main loop.
Fixing this revealed the similar dispatch code in the endpoints that was needed to get those events handled despite Request/ClearCallbackOnPendingXXX() not working. That extra endpoint code now became redundant (delivering events twice), so had to be removed.

I am aware that this might be a too deep intervention for coming from a CHIP newbie like me (not newbie in code deep diving, though), but I think it cleans up an inconsistency in the IP endpoints.
@plan44 plan44 force-pushed the PR/fix_socket_event_watching branch from 683c97d to fd85659 Compare July 23, 2022 16:29
@github-actions
Copy link

github-actions bot commented Jul 23, 2022

PR #21135: Size comparison from b647dfb to fd85659

Increases (3 builds for bl602, telink)
platform target config section b647dfb fd85659 change % change
bl602 lighting-app bl602 .text 1050944 1050948 4 0.0
telink light-switch-app tlsr9518adk80d text 567210 567212 2 0.0
lighting-app tlsr9518adk80d text 583754 583756 2 0.0
Decreases (1 build for cyw30739)
platform target config section b647dfb fd85659 change % change
cyw30739 light cyw930739m2evb_01 (read/write) 582042 582034 -8 -0.0
.app_xip_area 460432 460424 -8 -0.0
Full report (32 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section b647dfb fd85659 change % change
bl602 lighting-app bl602 (read/write) 1380794 1380794 0 0.0
.bss 117474 117474 0 0.0
.data 4480 4480 0 0.0
.text 1050944 1050948 4 0.0
bl602+rpc (read/write) 1426202 1426202 0 0.0
.bss 124922 124922 0 0.0
.data 4600 4600 0 0.0
.text 1082600 1082600 0 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 668479 668479 0 0.0
(read/write) 182864 182864 0 0.0
.bss 74236 74236 0 0.0
.data 3356 3356 0 0.0
.rodata 88367 88367 0 0.0
.text 579796 579796 0 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 634063 634063 0 0.0
(read/write) 157804 157804 0 0.0
.bss 73532 73532 0 0.0
.data 3356 3356 0 0.0
.rodata 77591 77591 0 0.0
.text 556148 556148 0 0.0
lock-ftd LP_CC2652R7 (read only) 671603 671603 0 0.0
(read/write) 169916 169916 0 0.0
.bss 71300 71300 0 0.0
.data 3280 3280 0 0.0
.rodata 76451 76451 0 0.0
.text 594672 594672 0 0.0
lock-mtd LP_CC2652R7 (read only) 653847 653847 0 0.0
(read/write) 183360 183360 0 0.0
.bss 66988 66988 0 0.0
.data 3280 3280 0 0.0
.rodata 101167 101167 0 0.0
.text 552200 552200 0 0.0
pump-app LP_CC2652R7 (read only) 681271 681271 0 0.0
(read/write) 161104 161104 0 0.0
.bss 71388 71388 0 0.0
.data 3280 3280 0 0.0
.rodata 89183 89183 0 0.0
.text 591604 591604 0 0.0
pump-controller-app LP_CC2652R7 (read only) 667039 667039 0 0.0
(read/write) 175456 175456 0 0.0
.bss 71508 71508 0 0.0
.data 3276 3276 0 0.0
.rodata 85039 85039 0 0.0
.text 581520 581520 0 0.0
shell LP_CC2652R7 (read only) 660954 660954 0 0.0
(read/write) 185892 185892 0 0.0
.bss 76540 76540 0 0.0
.data 3360 3360 0 0.0
.rodata 85146 85146 0 0.0
.text 575492 575492 0 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 582042 582034 -8 -0.0
.app_xip_area 460432 460424 -8 -0.0
.bss 64404 64404 0 0.0
.data 716 716 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 587942 587942 0 0.0
.app_xip_area 461604 461604 0 0.0
.bss 69132 69132 0 0.0
.data 720 720 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 586494 586494 0 0.0
.app_xip_area 465732 465732 0 0.0
.bss 63612 63612 0 0.0
.data 660 660 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read/write) 1087680 1087680 0 0.0
.bss 133220 133220 0 0.0
.data 2048 2048 0 0.0
.text 952392 952392 0 0.0
BRD4161A+rpc (read/write) 1141972 1141972 0 0.0
.bss 149892 149892 0 0.0
.data 2260 2260 0 0.0
.text 989796 989796 0 0.0
BRD4161A+rs911x (read/write) 952180 952180 0 0.0
.bss 140928 140928 0 0.0
.data 2048 2048 0 0.0
.text 809184 809184 0 0.0
lock-app BRD4161A+wf200 (read/write) 1128424 1128424 0 0.0
.bss 144304 144304 0 0.0
.data 2056 2056 0 0.0
.text 982044 982044 0 0.0
window-app BRD4161A (read/write) 1081156 1081156 0 0.0
.bss 134692 134692 0 0.0
.data 2076 2076 0 0.0
.text 944368 944368 0 0.0
esp32 all-clusters-app c3devkit (read only) 1022020 1022020 0 0.0
(read/write) 1486522 1486522 0 0.0
.dram0.bss 70232 70232 0 0.0
.dram0.data 14600 14600 0 0.0
.flash.rodata 216248 216248 0 0.0
.flash.text 1022020 1022020 0 0.0
.iram0.text 62902 62902 0 0.0
m5stack (read only) 1075795 1075795 0 0.0
(read/write) 488528 488528 0 0.0
.dram0.bss 75752 75752 0 0.0
.dram0.data 34144 34144 0 0.0
.flash.rodata 246636 246636 0 0.0
.flash.text 1070411 1070411 0 0.0
.iram0.text 123267 123267 0 0.0
k32w light k32w0+release (read/write) 641520 641520 0 0.0
.bss 69696 69696 0 0.0
.data 2028 2028 0 0.0
.text 567068 567068 0 0.0
lock k32w0+release (read/write) 698880 698880 0 0.0
.bss 70144 70144 0 0.0
.data 2036 2036 0 0.0
.text 623972 623972 0 0.0
linux chip-tool-ipv6only arm64 (read only) 9779324 9779324 0 0.0
(read/write) 679441 679441 0 0.0
.bss 32833 32833 0 0.0
.data 3272 3272 0 0.0
.data.rel.ro 624824 624824 0 0.0
.dynamic 560 560 0 0.0
.got 13552 13552 0 0.0
.init 24 24 0 0.0
.init_array 192 192 0 0.0
.rodata 457724 457724 0 0.0
.text 7737204 7737204 0 0.0
thermostat-no-ble arm64 (read only) 2341916 2341916 0 0.0
(read/write) 141249 141249 0 0.0
.bss 55233 55233 0 0.0
.data 1672 1672 0 0.0
.data.rel.ro 75592 75592 0 0.0
.dynamic 560 560 0 0.0
.got 4984 4984 0 0.0
.init 24 24 0 0.0
.init_array 400 400 0 0.0
.rodata 139572 139572 0 0.0
.text 1965536 1965536 0 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2449240 2449240 0 0.0
.bss 214444 214444 0 0.0
.data 5872 5872 0 0.0
.text 1411884 1411884 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1177235 1177235 0 0.0
bss 143068 143068 0 0.0
rodata 142652 142652 0 0.0
text 812656 812656 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1157287 1157287 0 0.0
bss 142304 142304 0 0.0
rodata 134184 134184 0 0.0
text 801968 801968 0 0.0
p6 all-clusters-app default (read only) 881632 881632 0 0.0
(read/write) 1686780 1686780 0 0.0
.bss 149064 149064 0 0.0
.data 2648 2648 0 0.0
.text 1526680 1526680 0 0.0
all-clusters-minimal-app default (read only) 882352 882352 0 0.0
(read/write) 1630884 1630884 0 0.0
.bss 148344 148344 0 0.0
.data 2648 2648 0 0.0
.text 1471504 1471504 0 0.0
light-app default (read only) 890656 890656 0 0.0
(read/write) 1550972 1550972 0 0.0
.bss 140248 140248 0 0.0
.data 2440 2440 0 0.0
.text 1399896 1399896 0 0.0
lock-app default (read only) 886184 886184 0 0.0
(read/write) 1588564 1588564 0 0.0
.bss 144704 144704 0 0.0
.data 2456 2456 0 0.0
.text 1433016 1433016 0 0.0
telink light-switch-app tlsr9518adk80d (read/write) 799620 799620 0 0.0
bss 70744 70744 0 0.0
noinit 40416 40416 0 0.0
text 567210 567212 2 0.0
lighting-app tlsr9518adk80d (read/write) 819668 819668 0 0.0
bss 71588 71588 0 0.0
noinit 40416 40416 0 0.0
text 583754 583756 2 0.0

@woody-apple woody-apple enabled auto-merge (squash) July 25, 2022 18:37
@woody-apple woody-apple merged commit 3ca630c into project-chip:master Jul 25, 2022
@woody-apple
Copy link
Contributor

Fast tracking platform changes

github-actions bot pushed a commit that referenced this pull request Jul 25, 2022
…spatch, clean transport (#21135)

For CHIP_SYSTEM_CONFIG_USE_DISPATCH (Darwin) case, Request/ClearCallbackOnPendingXXX() were not working (no loop calling select to evaluate watches), but were called in TCP and UDP endpoint implementations, despite dispatch-specific extra code for the same purpose in the endpoints.

This changeset now moves all CHIP_SYSTEM_CONFIG_USE_DISPATCH specific socket watching code into SystemLayerImplSelect, by making Request/ClearCallbackOnPendingXXX() actually working with dispatch.

The issue surfaced in my (a bit exotic) use case when I needed to get callbacks for events on a plain socket not wrapped as TCPEndPoint.
Doing this, I realized Request/ClearCallbackOnPendingXXX() were non-functional due to missing select main loop.
Fixing this revealed the similar dispatch code in the endpoints that was needed to get those events handled despite Request/ClearCallbackOnPendingXXX() not working. That extra endpoint code now became redundant (delivering events twice), so had to be removed.

I am aware that this might be a too deep intervention for coming from a CHIP newbie like me (not newbie in code deep diving, though), but I think it cleans up an inconsistency in the IP endpoints.
woody-apple added a commit that referenced this pull request Jul 25, 2022
…spatch, clean transport (#21135) (#21186)

For CHIP_SYSTEM_CONFIG_USE_DISPATCH (Darwin) case, Request/ClearCallbackOnPendingXXX() were not working (no loop calling select to evaluate watches), but were called in TCP and UDP endpoint implementations, despite dispatch-specific extra code for the same purpose in the endpoints.

This changeset now moves all CHIP_SYSTEM_CONFIG_USE_DISPATCH specific socket watching code into SystemLayerImplSelect, by making Request/ClearCallbackOnPendingXXX() actually working with dispatch.

The issue surfaced in my (a bit exotic) use case when I needed to get callbacks for events on a plain socket not wrapped as TCPEndPoint.
Doing this, I realized Request/ClearCallbackOnPendingXXX() were non-functional due to missing select main loop.
Fixing this revealed the similar dispatch code in the endpoints that was needed to get those events handled despite Request/ClearCallbackOnPendingXXX() not working. That extra endpoint code now became redundant (delivering events twice), so had to be removed.

I am aware that this might be a too deep intervention for coming from a CHIP newbie like me (not newbie in code deep diving, though), but I think it cleans up an inconsistency in the IP endpoints.

Co-authored-by: Lukas Zeller <luz@plan44.ch>
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
if (watch->mWrSource)
{
dispatch_resume(watch->mWrSource);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right... For example, TCP will call RequestCallbackOnPendingWrite for every single packet, without doing any ClearCallbackOnPendingWrite in between. So we will have multiple dispatch_resume calls when the dispatch source is already resumed. You're not allowed to do that, per the API documentation.

I have not carefully checked for other failure modes in TCP and UDP here, but fundamentally assuming that their calls to RequestCallback* and ClearCallback* will be ordered in a sane way is not reasonable: those calls have an API designed around a single boolean flag, not a counter. So we need to keep track with a boolean flag, and ensure our counter is only ever 0 or 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I will update the change accordingly.

@bzbarsky-apple
Copy link
Contributor

bzbarsky-apple commented Jul 26, 2022

@plan44 Can you please fix the issue in #21135 (review) ?

plan44 added a commit to plan44/connectedhomeip that referenced this pull request Jul 27, 2022
…learCallback

As pointed out in project-chip#21135, the previous version was not safe when calls to RequestCallbackXX and ClearCallbackXX were not balanced, and there's no reason to believe API clients would balance them.

This version does no longer try to suspend the source (because that could be problematic when done from within callbacks) but now follows the original semantics of just changing mPendingIO flags to enable/disable callback, with the exception of requesting the callback for the first time (which triggers creation of the dispatch source).

WIP: more detailed testing shows:

- TCPtest from src/transport/raw/tests never bothers to set up a dispatch queue in the first place, so fails.

- when NetworkTestHelpers.cpp is modified to setup a dispatch queue, TCPtest succeeds, crashes or fails randomly

- TestSystemWakeEvent from src/system/tests succeeds despite not setting up a dispatch queue. Apparently, the test result does not depend on the handlers set up actually returning events.

- all other tests (run on macos, `ninja -C out/host check`) pass

As making use of Request/ClearCallbackXXX without having a dispatch queue installed points to a problem (most likely only occurring in tests with only partial system init), I added a ChipLogError to make this visible.
@plan44
Copy link
Contributor Author

plan44 commented Jul 27, 2022

@bzbarsky-apple Turns out to be much more difficult than I thought...

I tried to fix and test the issue you pointed out. I tried several variants, but did not get TCPtest from src/transport/raw/tests producing reliable results (random crash/success/failure on every invocation). It does so in original form (where it does not bother to set up a dispatch queue at all) and also when I patched NetworkTestHelpers.cpp to install a dispatch queue.

All other tests are fine (run on macOS).

First I just made sure suspend/resume remains balanced in SystemLayerImplSelect as you suggested.
Then, suspecting problems with calling dispatch_suspend from within a callback (TCPtest does that), stopped using suspend/resume at all, but just using the flags to decide about calling back or not.

This is as near as I could get to the original semantics where Request/ClearCallback just change flags - only the first RequestCallback installs the dispatch source.

As I do not want to trigger the whole PR machinery with this WIP, this is on a separate branch in my fork for now:

https://github.com/plan44/connectedhomeip/tree/PR/fix_socket_event_watching_WIP

The failures in TCPtest seem more like a test artifact than a real problem to me, but I definitely don't understand the stack well enough yet to be sure.

@bzbarsky-apple
Copy link
Contributor

@plan44 When running the unit tests, there is no dispatch queue (long story). So the ChipLogError(DeviceLayer, "RequestCallbackOnPendingRead with no dispatch queue installed: callback will not work"); bit from the WIP might be the issue there.

Basically, when there is no dispatch queue that code is supposed to fall back on the non-dispatch "just do sockets" code....

@plan44
Copy link
Contributor Author

plan44 commented Jul 28, 2022

When running the unit tests, there is no dispatch queue (long story)

I can imagine ;-) Trying to debug I realized that the PlatformManager would be needed to properly set it up, firing up half of the stack for a test that should be simple.

Basically, when there is no dispatch queue that code is supposed to fall back on the non-dispatch "just do sockets" code....

Ok, thanks. That helped me to understand the problem: In my previous attempt I intentionally only set the flag when the source could actually be installed. This broke the select()-based DriveIO() fallback.

The new version now just always sets the flag, and then tries to install the source, but when no dispatch is available it just outputs the warning. In non-test cases, the warning should definitely never appear, in tests it may, depending on the setup (and I changed the wording to make that clear).

See new PR #21349

@bzbarsky-apple
Copy link
Contributor

I realized that the PlatformManager would be needed to properly set it up

Yep, and then the rabbit hole gets deep. :) #21349 looks great, thank you!

isiu-apple pushed a commit to isiu-apple/connectedhomeip that referenced this pull request Sep 16, 2022
…spatch, clean transport (project-chip#21135)

For CHIP_SYSTEM_CONFIG_USE_DISPATCH (Darwin) case, Request/ClearCallbackOnPendingXXX() were not working (no loop calling select to evaluate watches), but were called in TCP and UDP endpoint implementations, despite dispatch-specific extra code for the same purpose in the endpoints.

This changeset now moves all CHIP_SYSTEM_CONFIG_USE_DISPATCH specific socket watching code into SystemLayerImplSelect, by making Request/ClearCallbackOnPendingXXX() actually working with dispatch.

The issue surfaced in my (a bit exotic) use case when I needed to get callbacks for events on a plain socket not wrapped as TCPEndPoint.
Doing this, I realized Request/ClearCallbackOnPendingXXX() were non-functional due to missing select main loop.
Fixing this revealed the similar dispatch code in the endpoints that was needed to get those events handled despite Request/ClearCallbackOnPendingXXX() not working. That extra endpoint code now became redundant (delivering events twice), so had to be removed.

I am aware that this might be a too deep intervention for coming from a CHIP newbie like me (not newbie in code deep diving, though), but I think it cleans up an inconsistency in the IP endpoints.
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.

3 participants