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

TCP: Use RunOnTCPIP() for the LwIP TCP EndPoint #36962

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

wqx6
Copy link
Contributor

@wqx6 wqx6 commented Jan 6, 2025

Changes

  • Use RunOnTCPIP() in TCPEndPointImplLwIP instead of LOCK_TCPIP_CORE()/UNLOCK_TCPIP_CORE().
  • The LwIP callback with call function NewEndPoint() which is required to be called in Matter context. And the new endpoint will be used immediately after it is created. so we cannot use ScheduleLambda(). This PR creates a new function RunOnMatterContext() for it.

Testing

  • Build ESP32 example after enable chip_inet_config_enable_tcp_endpoint.

Copy link

Review changes with  SemanticDiff

@wqx6 wqx6 changed the title TCP: Use RunOnTCPIP() for the LwIP TCP EndPoint and Fix memory in PacketBufferHandle::New() TCP: Use RunOnTCPIP() for the LwIP TCP EndPoint and Fix memory leak in PacketBufferHandle::New() Jan 6, 2025
Copy link

github-actions bot commented Jan 6, 2025

PR #36962: Size comparison from 1b4c56c to 5256657

Increases above 0.2%:

platform target config section 1b4c56c 5256657 change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840208 842144 1936 0.2
lock-ftd LP_EM_CC1354P10_6 FLASH 825748 827684 1936 0.2
pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
lock CC3235SF_LAUNCHXL FLASH 574217 576233 2016 0.4
Full report (14 builds for cc13x4_26x4, cc32xx, nrfconnect, qpg, stm32, tizen)
platform target config section 1b4c56c 5256657 change % change
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840208 842144 1936 0.2
RAM 123696 123696 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 825748 827684 1936 0.2
RAM 125584 125584 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
RAM 114060 114060 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
RAM 114260 114260 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
RAM 205800 205800 0 0.0
lock CC3235SF_LAUNCHXL FLASH 574217 576233 2016 0.4
RAM 205944 205944 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918100 918132 32 0.0
RAM 143332 143332 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 890592 890620 28 0.0
RAM 141519 141519 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852164 852196 32 0.0
RAM 142244 142244 0 0.0
qpg lighting-app qpg6105+debug FLASH 664328 664360 32 0.0
RAM 105456 105456 0 0.0
lock-app qpg6105+debug FLASH 622156 622188 32 0.0
RAM 99908 99908 0 0.0
stm32 light STM32WB5MM-DK FLASH 485080 485112 32 0.0
RAM 144912 144912 0 0.0
tizen all-clusters-app arm unknown 5160 5160 0 0.0
FLASH 1780984 1781068 84 0.0
RAM 93684 93684 0 0.0
chip-tool-ubsan arm unknown 10848 10848 0 0.0
FLASH 18003494 18003742 248 0.0
RAM 7858000 7858016 16 0.0

Copy link

github-actions bot commented Jan 6, 2025

PR #36962: Size comparison from 1b4c56c to 267b09d

Increases above 0.2%:

platform target config section 1b4c56c 267b09d change % change
cc13x4_26x4 pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
lock CC3235SF_LAUNCHXL FLASH 574217 576233 2016 0.4
Full report (69 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 1b4c56c 267b09d change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1354914 1354954 40 0.0
RAM 104160 104160 0 0.0
bl702 lighting-app bl702+eth FLASH 652136 652172 36 0.0
RAM 25353 25353 0 0.0
bl702+wifi FLASH 829740 829776 36 0.0
RAM 14093 14093 0 0.0
bl706+mfd+rpc+littlefs FLASH 1058212 1058264 52 0.0
RAM 23933 23933 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 979330 979382 52 0.0
RAM 16596 16596 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840208 842144 1936 0.2
RAM 123696 123696 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 825748 827684 1936 0.2
RAM 125584 125584 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
RAM 114060 114060 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
RAM 114260 114260 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
RAM 205800 205800 0 0.0
lock CC3235SF_LAUNCHXL FLASH 574217 576233 2016 0.4
RAM 205944 205944 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 681745 681777 32 0.0
RAM 78756 78756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 658525 658557 32 0.0
RAM 73824 73824 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 618369 618393 24 0.0
RAM 71748 71748 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 637997 638021 24 0.0
RAM 74292 74292 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 637997 638021 24 0.0
RAM 74292 74292 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 637769 637801 32 0.0
RAM 74756 74756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 657477 657509 32 0.0
RAM 77300 77300 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 657477 657509 32 0.0
RAM 77300 77300 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 614389 614421 32 0.0
RAM 68844 68844 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634241 634273 32 0.0
RAM 71476 71476 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634241 634273 32 0.0
RAM 71476 71476 0 0.0
efr32 lock-app BRD4187C FLASH 932676 932708 32 0.0
RAM 160228 160228 0 0.0
BRD4338a FLASH 747160 747200 40 0.0
RAM 233356 233356 0 0.0
window-app BRD4187C FLASH 1025592 1025624 32 0.0
RAM 128332 128332 0 0.0
esp32 all-clusters-app c3devkit DRAM 95352 95352 0 0.0
FLASH 1541940 1541976 36 0.0
IRAM 82552 82552 0 0.0
m5stack DRAM 116332 116332 0 0.0
FLASH 1548142 1548178 36 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4752 4752 0 0.0
FLASH 2730137 2730259 122 0.0
RAM 133096 133096 0 0.0
all-clusters-app debug unknown 5560 5560 0 0.0
FLASH 6018726 6018844 118 0.0
RAM 524024 524024 0 0.0
all-clusters-minimal-app debug unknown 5456 5456 0 0.0
FLASH 5355204 5355324 120 0.0
RAM 243008 243008 0 0.0
bridge-app debug unknown 5472 5472 0 0.0
FLASH 4703618 4703738 120 0.0
RAM 221760 221760 0 0.0
chip-tool debug unknown 5992 5992 0 0.0
FLASH 12868552 12868672 120 0.0
RAM 582650 582650 0 0.0
chip-tool-ipv6only arm64 unknown 21408 21408 0 0.0
FLASH 10997296 10997472 176 0.0
RAM 633664 633664 0 0.0
fabric-admin debug unknown 5816 5816 0 0.0
FLASH 11274263 11274383 120 0.0
RAM 582994 582994 0 0.0
fabric-bridge-app debug unknown 4728 4728 0 0.0
FLASH 4528852 4528970 118 0.0
RAM 208880 208880 0 0.0
fabric-sync debug unknown 4968 4968 0 0.0
FLASH 5639429 5639557 128 0.0
RAM 475912 475912 0 0.0
lighting-app debug+rpc+ui unknown 6136 6136 0 0.0
FLASH 5639409 5639521 112 0.0
RAM 232008 232008 0 0.0
lock-app debug unknown 5408 5408 0 0.0
FLASH 4751986 4752104 118 0.0
RAM 208008 208008 0 0.0
ota-provider-app debug unknown 4768 4768 0 0.0
FLASH 4378612 4378732 120 0.0
RAM 201696 201696 0 0.0
ota-requestor-app debug unknown 4720 4720 0 0.0
FLASH 4517520 4517642 122 0.0
RAM 206280 206280 0 0.0
shell debug unknown 4248 4248 0 0.0
FLASH 3036685 3036813 128 0.0
RAM 160736 160736 0 0.0
thermostat-no-ble arm64 unknown 9584 9584 0 0.0
FLASH 4118968 4119144 176 0.0
RAM 246296 246296 0 0.0
tv-app debug unknown 5736 5736 0 0.0
FLASH 5988693 5988805 112 0.0
RAM 599344 599344 0 0.0
tv-casting-app debug unknown 5320 5320 0 0.0
FLASH 11094621 11094733 112 0.0
RAM 695608 695608 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918100 918136 36 0.0
RAM 143332 143332 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 890592 890624 32 0.0
RAM 141519 141519 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852164 852200 36 0.0
RAM 142244 142244 0 0.0
nxp contact k32w0+release FLASH 585952 585984 32 0.0
RAM 71112 71112 0 0.0
mcxw71+release FLASH 600512 600544 32 0.0
RAM 63208 63208 0 0.0
light k32w0+release FLASH 612716 612748 32 0.0
RAM 70504 70504 0 0.0
k32w1+release FLASH 686920 686952 32 0.0
RAM 48840 48840 0 0.0
lock mcxw71+release FLASH 763264 763296 32 0.0
RAM 70876 70876 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647500 1650236 2736 0.2
RAM 212128 212128 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1555132 1557884 2752 0.2
RAM 208944 208944 0 0.0
light cy8ckit_062s2_43012 FLASH 1470236 1472988 2752 0.2
RAM 200912 200912 0 0.0
lock cy8ckit_062s2_43012 FLASH 1467956 1470708 2752 0.2
RAM 225272 225272 0 0.0
qpg lighting-app qpg6105+debug FLASH 664328 664368 40 0.0
RAM 105456 105456 0 0.0
lock-app qpg6105+debug FLASH 622156 622188 32 0.0
RAM 99908 99908 0 0.0
stm32 light STM32WB5MM-DK FLASH 485080 485112 32 0.0
RAM 144912 144912 0 0.0
telink bridge-app tlsr9258a FLASH 683636 683684 48 0.0
RAM 91248 91248 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 623876 623918 42 0.0
RAM 31488 31488 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 772786 772828 42 0.0
RAM 49348 49348 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 711318 711360 42 0.0
RAM 73544 73544 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 628322 628370 48 0.0
RAM 142180 142180 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814340 814388 48 0.0
RAM 99724 99724 0 0.0
tizen all-clusters-app arm unknown 5160 5160 0 0.0
FLASH 1780984 1781068 84 0.0
RAM 93684 93684 0 0.0
chip-tool-ubsan arm unknown 10848 10848 0 0.0
FLASH 18003494 18003742 248 0.0
RAM 7858000 7858016 16 0.0

@andy31415
Copy link
Contributor

@wqx6 please fix build errors and add a ###Testing section to describe how things were tested.

src/system/SystemLayer.cpp Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 7, 2025

PR #36962: Size comparison from f8d457a to cca01f2

Increases above 0.2%:

platform target config section f8d457a4 cca01f2 change % change
cc13x4_26x4 pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
lock CC3235SF_LAUNCHXL FLASH 574217 576241 2024 0.4
Full report (69 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section f8d457a4 cca01f2 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1354914 1354956 42 0.0
RAM 104160 104160 0 0.0
bl702 lighting-app bl702+eth FLASH 652136 652176 40 0.0
RAM 25353 25353 0 0.0
bl702+wifi FLASH 829740 829780 40 0.0
RAM 14093 14093 0 0.0
bl706+mfd+rpc+littlefs FLASH 1058212 1058256 44 0.0
RAM 23933 23933 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 979330 979374 44 0.0
RAM 16596 16596 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840208 842152 1944 0.2
RAM 123696 123696 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 825748 827692 1944 0.2
RAM 125584 125584 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
RAM 114060 114060 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
RAM 114260 114260 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
RAM 205800 205800 0 0.0
lock CC3235SF_LAUNCHXL FLASH 574217 576241 2024 0.4
RAM 205944 205944 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 681745 681785 40 0.0
RAM 78756 78756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 658525 658565 40 0.0
RAM 73824 73824 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 618369 618401 32 0.0
RAM 71748 71748 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 637997 638029 32 0.0
RAM 74292 74292 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 637997 638029 32 0.0
RAM 74292 74292 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 637769 637801 32 0.0
RAM 74756 74756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 657477 657517 40 0.0
RAM 77300 77300 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 657477 657517 40 0.0
RAM 77300 77300 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 614389 614421 32 0.0
RAM 68844 68844 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634241 634281 40 0.0
RAM 71476 71476 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634241 634281 40 0.0
RAM 71476 71476 0 0.0
efr32 lock-app BRD4187C FLASH 932676 932708 32 0.0
RAM 160228 160228 0 0.0
BRD4338a FLASH 747160 747200 40 0.0
RAM 233356 233356 0 0.0
window-app BRD4187C FLASH 1025592 1025656 64 0.0
RAM 128332 128332 0 0.0
esp32 all-clusters-app c3devkit DRAM 95352 95352 0 0.0
FLASH 1541956 1541996 40 0.0
IRAM 82552 82552 0 0.0
m5stack DRAM 116332 116332 0 0.0
FLASH 1548162 1548194 32 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4752 4752 0 0.0
FLASH 2730137 2730275 138 0.0
RAM 133096 133096 0 0.0
all-clusters-app debug unknown 5560 5560 0 0.0
FLASH 6018726 6018860 134 0.0
RAM 524024 524024 0 0.0
all-clusters-minimal-app debug unknown 5456 5456 0 0.0
FLASH 5355204 5355340 136 0.0
RAM 243008 243008 0 0.0
bridge-app debug unknown 5472 5472 0 0.0
FLASH 4703618 4703754 136 0.0
RAM 221760 221760 0 0.0
chip-tool debug unknown 5992 5992 0 0.0
FLASH 12868552 12868688 136 0.0
RAM 582650 582650 0 0.0
chip-tool-ipv6only arm64 unknown 21408 21408 0 0.0
FLASH 10997296 10997520 224 0.0
RAM 633664 633664 0 0.0
fabric-admin debug unknown 5816 5816 0 0.0
FLASH 11274263 11274399 136 0.0
RAM 582994 582994 0 0.0
fabric-bridge-app debug unknown 4728 4728 0 0.0
FLASH 4528852 4528986 134 0.0
RAM 208880 208880 0 0.0
fabric-sync debug unknown 4968 4968 0 0.0
FLASH 5639429 5639573 144 0.0
RAM 475912 475912 0 0.0
lighting-app debug+rpc+ui unknown 6136 6136 0 0.0
FLASH 5639409 5639537 128 0.0
RAM 232008 232008 0 0.0
lock-app debug unknown 5408 5408 0 0.0
FLASH 4751986 4752120 134 0.0
RAM 208008 208008 0 0.0
ota-provider-app debug unknown 4768 4768 0 0.0
FLASH 4378612 4378748 136 0.0
RAM 201696 201696 0 0.0
ota-requestor-app debug unknown 4720 4720 0 0.0
FLASH 4517520 4517658 138 0.0
RAM 206280 206280 0 0.0
shell debug unknown 4248 4248 0 0.0
FLASH 3036685 3036829 144 0.0
RAM 160736 160736 0 0.0
thermostat-no-ble arm64 unknown 9584 9584 0 0.0
FLASH 4118968 4119192 224 0.0
RAM 246296 246296 0 0.0
tv-app debug unknown 5736 5736 0 0.0
FLASH 5988693 5988821 128 0.0
RAM 599344 599344 0 0.0
tv-casting-app debug unknown 5320 5320 0 0.0
FLASH 11094621 11094749 128 0.0
RAM 695608 695608 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918100 918128 28 0.0
RAM 143332 143332 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 890592 890620 28 0.0
RAM 141519 141519 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852164 852192 28 0.0
RAM 142244 142244 0 0.0
nxp contact k32w0+release FLASH 585952 586000 48 0.0
RAM 71112 71112 0 0.0
mcxw71+release FLASH 600512 600544 32 0.0
RAM 63208 63208 0 0.0
light k32w0+release FLASH 612716 612748 32 0.0
RAM 70504 70504 0 0.0
k32w1+release FLASH 686920 686952 32 0.0
RAM 48840 48840 0 0.0
lock mcxw71+release FLASH 763264 763296 32 0.0
RAM 70876 70876 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647500 1650236 2736 0.2
RAM 212128 212128 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1555132 1557884 2752 0.2
RAM 208944 208944 0 0.0
light cy8ckit_062s2_43012 FLASH 1470236 1472988 2752 0.2
RAM 200912 200912 0 0.0
lock cy8ckit_062s2_43012 FLASH 1467956 1470708 2752 0.2
RAM 225272 225272 0 0.0
qpg lighting-app qpg6105+debug FLASH 664328 664368 40 0.0
RAM 105456 105456 0 0.0
lock-app qpg6105+debug FLASH 622156 622188 32 0.0
RAM 99908 99908 0 0.0
stm32 light STM32WB5MM-DK FLASH 485080 485104 24 0.0
RAM 144912 144912 0 0.0
telink bridge-app tlsr9258a FLASH 683636 683686 50 0.0
RAM 91248 91248 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 623876 623926 50 0.0
RAM 31488 31488 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 772786 772836 50 0.0
RAM 49348 49348 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 711318 711368 50 0.0
RAM 73544 73544 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 628322 628372 50 0.0
RAM 142180 142180 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814340 814390 50 0.0
RAM 99724 99724 0 0.0
tizen all-clusters-app arm unknown 5160 5160 0 0.0
FLASH 1780980 1781076 96 0.0
RAM 93684 93684 0 0.0
chip-tool-ubsan arm unknown 10848 10848 0 0.0
FLASH 18003494 18003670 176 0.0
RAM 7858000 7858040 40 0.0

System::Layer & lSystemLayer = listenEP->GetSystemLayer();
TCPEndPointImplLwIP * listenEP = static_cast<TCPEndPointImplLwIP *>(arg);
TCPEndPointImplLwIP * conEP = nullptr;
System::LayerFreeRTOS & lSystemLayer = static_cast<System::LayerFreeRTOS &>(listenEP->GetSystemLayer());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this cast OK? Is it really the case that any time we are using LwIP we are using LayerFreeRTOS?

It really seems like the right thing to do is for any work that needs to happen on the Matter queue to actually happen on the Matter queue, async. If we need to snapshot some data for that, we snapshot that data....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a declared argument in system.gni

chip_system_config_use_lwip = chip_with_lwip && current_os == "freertos"

And we have no such scenario on which we are using LwIP for other OSs. This cast seems OK for now.

It really seems like the right thing to do is for any work that needs to happen on the Matter queue to actually happen on the Matter queue, async. If we need to snapshot some data for that, we snapshot that data....

Yes, I have tried to use ScheduleLamba to post the EndPoint allocating to Matter queue, but ScheduleLamba is a async function and we have to use the allocated endpoint immediately after the ScheduleLamba. Also I have tried to post all the following actions in the LwIPHandleIncomingConnection to Matter queue but encountered another issue. --- If we use ScheduleLamba for the whole LwIPHandleIncomingConnection, the function will ends immediately and the LwIP will finish three-way handshake and start receives TCP packets, the peer will also start sending TCP packets, but the arg and recv function is not set at that time(as the set process is post to Matter queue). This will result the timeout for TCP.

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 have moved the function back to System::Layer but added a macro for the RunWithMatterContextLock() function so that it will only be available when the system has lock. And also change here to System::Layer.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a declared argument in system.gni

Just for future reference: that's an argument with a default value. Builds can set the argument to a non-default value; that's why it's an argument. For example, config/openiotsdk/chip-gn/args.gni does that. Or you can do it via command-line.

It sounds like there are bigger architectural problems here, in that lwip is delivering notifications on some random thread but expecting them to do various work synchronously that we just can't easily do synchronously... For now I guess the locking is OK, but we should make the failure modes clear... I'll comment on the PR with details.

Copy link

github-actions bot commented Jan 9, 2025

PR #36962: Size comparison from f8d457a to a331147

Increases above 0.2%:

platform target config section f8d457a4 a331147 change % change
bl702 lighting-app bl702+eth FLASH 652136 726294 74158 11.4
bl702+wifi FLASH 829740 913164 83424 10.1
bl706+mfd+rpc+littlefs FLASH 1058212 1174002 115790 10.9
bl702l lighting-app bl702l+mfd+littlefs FLASH 979330 1083070 103740 10.6
cc13x4_26x4 pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
lock CC3235SF_LAUNCHXL FLASH 574217 576241 2024 0.4
Full report (69 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section f8d457a4 a331147 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1354914 1354998 84 0.0
RAM 104160 104152 -8 -0.0
bl702 lighting-app bl702+eth FLASH 652136 726294 74158 11.4
RAM 25353 25361 8 0.0
bl702+wifi FLASH 829740 913164 83424 10.1
RAM 14093 14101 8 0.1
bl706+mfd+rpc+littlefs FLASH 1058212 1174002 115790 10.9
RAM 23933 23941 8 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 979330 1083070 103740 10.6
RAM 16596 16612 16 0.1
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840208 842152 1944 0.2
RAM 123696 123696 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 825748 827692 1944 0.2
RAM 125584 125584 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 772568 774512 1944 0.3
RAM 114060 114060 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 756748 758692 1944 0.3
RAM 114260 114260 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540049 542073 2024 0.4
RAM 205800 205800 0 0.0
lock CC3235SF_LAUNCHXL FLASH 574217 576241 2024 0.4
RAM 205944 205944 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 681745 681785 40 0.0
RAM 78756 78756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 701597 701629 32 0.0
RAM 81396 81396 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 658525 658565 40 0.0
RAM 73824 73824 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 618369 618401 32 0.0
RAM 71748 71748 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 637997 638029 32 0.0
RAM 74292 74292 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 637997 638029 32 0.0
RAM 74292 74292 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 637769 637801 32 0.0
RAM 74756 74756 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 657477 657517 40 0.0
RAM 77300 77300 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 657477 657517 40 0.0
RAM 77300 77300 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 614389 614421 32 0.0
RAM 68844 68844 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634241 634281 40 0.0
RAM 71476 71476 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634241 634281 40 0.0
RAM 71476 71476 0 0.0
efr32 lock-app BRD4187C FLASH 932676 932708 32 0.0
RAM 160228 160228 0 0.0
BRD4338a FLASH 747160 747200 40 0.0
RAM 233356 233356 0 0.0
window-app BRD4187C FLASH 1025592 1025656 64 0.0
RAM 128332 128332 0 0.0
esp32 all-clusters-app c3devkit DRAM 95352 95352 0 0.0
FLASH 1541956 1541996 40 0.0
IRAM 82552 82552 0 0.0
m5stack DRAM 116332 116332 0 0.0
FLASH 1548162 1548186 24 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4752 4752 0 0.0
FLASH 2730137 2730275 138 0.0
RAM 133096 133096 0 0.0
all-clusters-app debug unknown 5560 5560 0 0.0
FLASH 6018726 6018860 134 0.0
RAM 524024 523992 -32 -0.0
all-clusters-minimal-app debug unknown 5456 5456 0 0.0
FLASH 5355204 5355340 136 0.0
RAM 243008 243008 0 0.0
bridge-app debug unknown 5472 5472 0 0.0
FLASH 4703618 4703754 136 0.0
RAM 221760 221760 0 0.0
chip-tool debug unknown 5992 5992 0 0.0
FLASH 12868552 12866924 -1628 -0.0
RAM 582650 582586 -64 -0.0
chip-tool-ipv6only arm64 unknown 21408 21400 -8 -0.0
FLASH 10997296 10995952 -1344 -0.0
RAM 633664 633584 -80 -0.0
fabric-admin debug unknown 5816 5816 0 0.0
FLASH 11274263 11272409 -1854 -0.0
RAM 582994 582930 -64 -0.0
fabric-bridge-app debug unknown 4728 4728 0 0.0
FLASH 4528852 4528986 134 0.0
RAM 208880 208880 0 0.0
fabric-sync debug unknown 4968 4968 0 0.0
FLASH 5639429 5639573 144 0.0
RAM 475912 475880 -32 -0.0
lighting-app debug+rpc+ui unknown 6136 6136 0 0.0
FLASH 5639409 5639537 128 0.0
RAM 232008 232008 0 0.0
lock-app debug unknown 5408 5408 0 0.0
FLASH 4751986 4752120 134 0.0
RAM 208008 208008 0 0.0
ota-provider-app debug unknown 4768 4768 0 0.0
FLASH 4378612 4378748 136 0.0
RAM 201696 201696 0 0.0
ota-requestor-app debug unknown 4720 4720 0 0.0
FLASH 4517520 4517658 138 0.0
RAM 206280 206280 0 0.0
shell debug unknown 4248 4248 0 0.0
FLASH 3036685 3036829 144 0.0
RAM 160736 160736 0 0.0
thermostat-no-ble arm64 unknown 9584 9584 0 0.0
FLASH 4118968 4119192 224 0.0
RAM 246296 246296 0 0.0
tv-app debug unknown 5736 5736 0 0.0
FLASH 5988693 5988821 128 0.0
RAM 599344 599312 -32 -0.0
tv-casting-app debug unknown 5320 5320 0 0.0
FLASH 11094621 11092829 -1792 -0.0
RAM 695608 695496 -112 -0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918100 918128 28 0.0
RAM 143332 143332 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 890592 890620 28 0.0
RAM 141519 141519 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852164 852192 28 0.0
RAM 142244 142244 0 0.0
nxp contact k32w0+release FLASH 585952 586096 144 0.0
RAM 71112 71112 0 0.0
mcxw71+release FLASH 600512 601608 1096 0.2
RAM 63208 63328 120 0.2
light k32w0+release FLASH 612716 612732 16 0.0
RAM 70504 70504 0 0.0
k32w1+release FLASH 686920 687352 432 0.1
RAM 48840 48920 80 0.2
lock mcxw71+release FLASH 763264 763680 416 0.1
RAM 70876 70956 80 0.1
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647500 1650236 2736 0.2
RAM 212128 212128 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1555132 1557884 2752 0.2
RAM 208944 208944 0 0.0
light cy8ckit_062s2_43012 FLASH 1470236 1472988 2752 0.2
RAM 200912 200912 0 0.0
lock cy8ckit_062s2_43012 FLASH 1467956 1470708 2752 0.2
RAM 225272 225272 0 0.0
qpg lighting-app qpg6105+debug FLASH 664328 664368 40 0.0
RAM 105456 105456 0 0.0
lock-app qpg6105+debug FLASH 622156 622188 32 0.0
RAM 99908 99908 0 0.0
stm32 light STM32WB5MM-DK FLASH 485080 485104 24 0.0
RAM 144912 144912 0 0.0
telink bridge-app tlsr9258a FLASH 683636 683684 48 0.0
RAM 91248 91248 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 623876 623924 48 0.0
RAM 31488 31488 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 772786 772758 -28 -0.0
RAM 49348 49348 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 711318 711366 48 0.0
RAM 73544 73544 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 628322 628370 48 0.0
RAM 142180 142180 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814340 814384 44 0.0
RAM 99724 99724 0 0.0
tizen all-clusters-app arm unknown 5160 5160 0 0.0
FLASH 1780980 1781076 96 0.0
RAM 93684 93684 0 0.0
chip-tool-ubsan arm unknown 10848 10844 -4 -0.0
FLASH 18003494 17999262 -4232 -0.0
RAM 7858000 7855872 -2128 -0.0

@andy31415
Copy link
Contributor

@wqx6 do we know why this costs 2K of flash? that is a lot

src/inet/TCPEndPointImplLwIP.cpp Show resolved Hide resolved
src/inet/TCPEndPointImplLwIP.cpp Outdated Show resolved Hide resolved
src/system/SystemLayer.h Outdated Show resolved Hide resolved
src/system/PlatformEventSupport.h Outdated Show resolved Hide resolved
src/system/SystemPacketBuffer.cpp Outdated Show resolved Hide resolved
#endif
// Set ther length and total length of the head packet buffer and all the chained packet buffers to 0
// as we don't put any data in them. And set the ref to 1 for all the buffers.
for (PacketBuffer * pktBuf = lPacket; pktBuf != nullptr; pktBuf = pktBuf->ChainedBuffer())
Copy link
Contributor

Choose a reason for hiding this comment

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

So... I am quite sure that various callers of PacketBufferHandle::New expect to get back a non-chained buffer and will fail if that is not the case. Other failure modes just in this function, if for some reason we have a chained buffer: what if aReservedSize is larger than the size of the head buffer? Then we have a corrupt lPacket->payload...

I would suggest splitting this piece out of the TCP changes, since it's not directly related, so we can figure out what should actually happen here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the platforms which don't use lwip, the allocated packet buffer will never have a chained buffer, but for platforms using LwIP, the pbuf_alloc() will allocate pbuf with chained pbufs if the allocated size is too large, and in our current code the chained pbufs will never be released which causes memory leak.

Agreed that we should split the change, reverted it in this PR.

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple Jan 17, 2025

Choose a reason for hiding this comment

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

My point is not that we don't need this change, but rather that we probably need a complete rethink of how we use packetbuffers if New can ever create a chained buffer. It will break crypto code, it will break all sorts of stuff....

Thank you for pulling this part out.

@wqx6 wqx6 changed the title TCP: Use RunOnTCPIP() for the LwIP TCP EndPoint and Fix memory leak in PacketBufferHandle::New() TCP: Use RunOnTCPIP() for the LwIP TCP EndPoint Jan 13, 2025
Copy link

github-actions bot commented Jan 13, 2025

PR #36962: Size comparison from 3f62505 to 637fa24

Increases above 0.2%:

platform target config section 3f62505 637fa24 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540285 542025 1740 0.3
lock CC3235SF_LAUNCHXL FLASH 574453 576193 1740 0.3
efr32 lock-app BRD4338a FLASH 747208 749224 2016 0.3
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647684 1654812 7128 0.4
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1555316 1560588 5272 0.3
light cy8ckit_062s2_43012 FLASH 1470420 1475196 4776 0.3
lock cy8ckit_062s2_43012 FLASH 1468156 1472980 4824 0.3
Full report (65 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, psoc6, qpg, stm32, telink, tizen)
platform target config section 3f62505 637fa24 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1354946 1355350 404 0.0
RAM 104152 103952 -200 -0.2
bl702 lighting-app bl702+eth FLASH 726512 726034 -478 -0.1
RAM 25361 25353 -8 -0.0
bl702+wifi FLASH 913126 912904 -222 -0.0
RAM 14101 14093 -8 -0.1
bl706+mfd+rpc+littlefs FLASH 1173960 1173762 -198 -0.0
RAM 23941 23933 -8 -0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 1083028 1082790 -238 -0.0
RAM 16612 16604 -8 -0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 840400 842128 1728 0.2
RAM 123712 123552 -160 -0.1
lock-ftd LP_EM_CC1354P10_6 FLASH 825932 827628 1696 0.2
RAM 125600 125440 -160 -0.1
pump-app LP_EM_CC1354P10_6 FLASH 772836 774524 1688 0.2
RAM 114076 113916 -160 -0.1
pump-controller-app LP_EM_CC1354P10_6 FLASH 757016 758720 1704 0.2
RAM 114276 114116 -160 -0.1
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 540285 542025 1740 0.3
RAM 205816 205304 -512 -0.2
lock CC3235SF_LAUNCHXL FLASH 574453 576193 1740 0.3
RAM 205960 205448 -512 -0.2
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 681809 681601 -208 -0.0
RAM 78756 78596 -160 -0.2
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 701653 701453 -200 -0.0
RAM 81396 81236 -160 -0.2
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 701653 701453 -200 -0.0
RAM 81396 81236 -160 -0.2
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 658589 658389 -200 -0.0
RAM 73824 73664 -160 -0.2
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 618425 618153 -272 -0.0
RAM 71748 71588 -160 -0.2
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 638053 637789 -264 -0.0
RAM 74292 74132 -160 -0.2
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 638053 637789 -264 -0.0
RAM 74292 74132 -160 -0.2
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 637825 637601 -224 -0.0
RAM 74756 74596 -160 -0.2
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 657533 657317 -216 -0.0
RAM 77300 77140 -160 -0.2
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 657533 657317 -216 -0.0
RAM 77300 77140 -160 -0.2
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 614445 614213 -232 -0.0
RAM 68844 68684 -160 -0.2
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 634297 634065 -232 -0.0
RAM 71476 71316 -160 -0.2
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 634297 634065 -232 -0.0
RAM 71476 71316 -160 -0.2
efr32 lock-app BRD4187C FLASH 932740 932500 -240 -0.0
RAM 160228 160068 -160 -0.1
BRD4338a FLASH 747208 749224 2016 0.3
RAM 233356 233196 -160 -0.1
window-app BRD4187C FLASH 1025656 1026888 1232 0.1
RAM 128332 128172 -160 -0.1
esp32 all-clusters-app c3devkit DRAM 95352 95192 -160 -0.2
FLASH 1541996 1541904 -92 -0.0
IRAM 82552 82552 0 0.0
m5stack DRAM 116332 116172 -160 -0.1
FLASH 1548246 1548458 212 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4752 4752 0 0.0
FLASH 2731685 2723231 -8454 -0.3
RAM 133160 133160 0 0.0
all-clusters-app debug unknown 5560 5560 0 0.0
FLASH 6020306 5996466 -23840 -0.4
RAM 526008 526072 64 0.0
all-clusters-minimal-app debug unknown 5456 5456 0 0.0
FLASH 5356400 5341652 -14748 -0.3
RAM 243072 243072 0 0.0
bridge-app debug unknown 5472 5472 0 0.0
FLASH 4704816 4696806 -8010 -0.2
RAM 221824 221824 0 0.0
chip-tool debug unknown 5992 5984 -8 -0.1
FLASH 12938676 12867152 -71524 -0.6
RAM 587002 587002 0 0.0
chip-tool-ipv6only arm64 unknown 21560 21536 -24 -0.1
FLASH 11053856 10989440 -64416 -0.6
RAM 638064 638048 -16 -0.0
fabric-admin debug unknown 5816 5808 -8 -0.1
FLASH 11334801 11274263 -60538 -0.5
RAM 587346 587346 0 0.0
fabric-bridge-app debug unknown 4728 4728 0 0.0
FLASH 4529968 4521754 -8214 -0.2
RAM 208928 208928 0 0.0
fabric-sync debug unknown 4968 4968 0 0.0
FLASH 5641333 5622981 -18352 -0.3
RAM 477880 477880 0 0.0
lighting-app debug+rpc+ui unknown 6136 6136 0 0.0
FLASH 5640945 5631329 -9616 -0.2
RAM 232072 232072 0 0.0
lock-app debug unknown 5408 5408 0 0.0
FLASH 4753184 4744566 -8618 -0.2
RAM 208072 208072 0 0.0
ota-provider-app debug unknown 4768 4768 0 0.0
FLASH 4379730 4372108 -7622 -0.2
RAM 201744 201744 0 0.0
ota-requestor-app debug unknown 4720 4720 0 0.0
FLASH 4518638 4510122 -8516 -0.2
RAM 206312 206312 0 0.0
shell debug unknown 4248 4248 0 0.0
FLASH 3037885 3023197 -14688 -0.5
RAM 160792 160792 0 0.0
thermostat-no-ble arm64 unknown 9584 9552 -32 -0.3
FLASH 4120104 4110296 -9808 -0.2
RAM 246384 246368 -16 -0.0
tv-app debug unknown 5736 5736 0 0.0
FLASH 5990677 5966741 -23936 -0.4
RAM 601312 601312 0 0.0
tv-casting-app debug unknown 5320 5312 -8 -0.2
FLASH 11167325 11102349 -64976 -0.6
RAM 700496 700496 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 918156 917804 -352 -0.0
RAM 143332 143172 -160 -0.1
nrf7002dk_nrf5340_cpuapp FLASH 890664 890868 204 0.0
RAM 141519 141359 -160 -0.1
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 852220 851932 -288 -0.0
RAM 142244 142084 -160 -0.1
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1647684 1654812 7128 0.4
RAM 212144 211632 -512 -0.2
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1555316 1560588 5272 0.3
RAM 208960 208448 -512 -0.2
light cy8ckit_062s2_43012 FLASH 1470420 1475196 4776 0.3
RAM 200928 200416 -512 -0.3
lock cy8ckit_062s2_43012 FLASH 1468156 1472980 4824 0.3
RAM 225280 224768 -512 -0.2
qpg lighting-app qpg6105+debug FLASH 664392 664176 -216 -0.0
RAM 105456 105296 -160 -0.2
lock-app qpg6105+debug FLASH 622204 622004 -200 -0.0
RAM 99908 99748 -160 -0.2
stm32 light STM32WB5MM-DK FLASH 485136 484976 -160 -0.0
RAM 144912 144752 -160 -0.1
telink bridge-app tlsr9258a FLASH 683698 683564 -134 -0.0
RAM 91248 91088 -160 -0.2
contact-sensor-app tlsr9528a_retention FLASH 623938 623810 -128 -0.0
RAM 31488 31488 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 772772 772664 -108 -0.0
RAM 49348 49348 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 777388 777268 -120 -0.0
RAM 99812 99652 -160 -0.2
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 711380 711250 -130 -0.0
RAM 73544 73384 -160 -0.2
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 628384 628264 -120 -0.0
RAM 142180 142020 -160 -0.1
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814398 814278 -120 -0.0
RAM 99724 99564 -160 -0.2
tizen all-clusters-app arm unknown 5160 5120 -40 -0.8
FLASH 1781748 1767268 -14480 -0.8
RAM 93720 93708 -12 -0.0
chip-tool-ubsan arm unknown 10924 10904 -20 -0.2
FLASH 18121646 17949886 -171760 -0.9
RAM 7909212 7842672 -66540 -0.8

Copy link
Contributor

Choose a reason for hiding this comment

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

having the header separated from the CPP is not ok - please make sure they are joined.

If you have trouble due to dependencies, that is a layering issue that has to be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is an issue of dependency cycle. The core depends on system and the platform depends on the core so if we reside the cpp with the header, it will call functions from platform lib but be used in system lib.

Copy link
Contributor Author

@wqx6 wqx6 Jan 15, 2025

Choose a reason for hiding this comment

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

We also separated the PlatformEventSupport.h and PlatformEventSupport.cpp, should we also reside them together?
I have trouble on residing them, could you please provide a solution for it?


using namespace ::chip::DeviceLayer;

#if !CHIP_SYSTEM_CONFIG_NO_LOCKING
Copy link
Contributor

Choose a reason for hiding this comment

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

please make these decisions in build.gn: include the CPP file only if platform locking exists.

Depending on usage, we may also consider creating a separate target of locking-not-available-do-not-use (or some other name) that contains these files in case of locking not available, so that GN fails to complie if people try to use locking when no locking available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the macro in this file and this file will be include when chip_system_config_locking != "none" in gn

src/system/SystemLayer.h Outdated Show resolved Hide resolved
Copy link
Contributor

@andy31415 andy31415 left a comment

Choose a reason for hiding this comment

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

Request changes on header and cpp file needing to reside together.

src/platform/PlatformLockSupport.cpp Outdated Show resolved Hide resolved
Comment on lines 20 to 21
/* this file behaves like a config.h, comes first */
#include <platform/internal/CHIPDeviceLayerInternal.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this got copy/pasted, but is that include needed in any way here? I would think PlatformManager.h and PlatformLockSupport.h include whatever headers they depend on.

Copy link
Contributor Author

@wqx6 wqx6 Jan 20, 2025

Choose a reason for hiding this comment

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

NXP(FreeRTOS) build CI fails if removing this line.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the failure, exactly?

#pragma once

/**
* The declared functions in this header are defined in src/platform/PlatformLockSupport.cpp because of dependency cycle issues.
Copy link
Contributor

@andy31415 andy31415 Jan 20, 2025

Choose a reason for hiding this comment

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

This is not good. Layering issue has to be fixed.

This header does not have any dependencies that I can see, so why is it not in platform then?

We need to figure out what depends on what else properly.

@wqx6
Copy link
Contributor Author

wqx6 commented Feb 6, 2025

@andy31415 @bzbarsky-apple I made the following change which doesn't need to add the PlatformLockSupport

  1. Add a pre-allocated connection endpoint for the TCP listen endpoint
  2. the pre-allocated will be allocated when the listen endpoint is created and listening.
  3. After the pre-connection endpoint is used, the listen endpoint will pre-allocate another endpoint for the next connection.

Could you please review it?

Copy link

github-actions bot commented Feb 7, 2025

PR #36962: Size comparison from ce47e22 to d5069a3

Increases above 0.2%:

platform target config section ce47e22 d5069a3 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 538925 540737 1812 0.3
lock CC3235SF_LAUNCHXL FLASH 572805 574617 1812 0.3
Full report (72 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section ce47e22 d5069a3 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1094778 1094778 0 0.0
RAM 103346 103346 0 0.0
bl702 lighting-app bl702+eth FLASH 650600 650600 0 0.0
RAM 25265 25265 0 0.0
bl702+wifi FLASH 828564 828564 0 0.0
RAM 13981 13981 0 0.0
bl706+mfd+rpc+littlefs FLASH 1057816 1057816 0 0.0
RAM 23893 23893 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 888502 888502 0 0.0
RAM 18504 18504 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 971544 971544 0 0.0
RAM 16368 16368 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 838456 840204 1748 0.2
RAM 123480 123496 16 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 823860 825608 1748 0.2
RAM 125360 125376 16 0.0
pump-app LP_EM_CC1354P10_6 FLASH 771036 772784 1748 0.2
RAM 113820 113836 16 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 755304 757052 1748 0.2
RAM 114028 114044 16 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 538925 540737 1812 0.3
RAM 205208 205224 16 0.0
lock CC3235SF_LAUNCHXL FLASH 572805 574617 1812 0.3
RAM 205360 205376 16 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 679809 679809 0 0.0
RAM 78548 78548 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 699653 699653 0 0.0
RAM 81188 81188 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 699653 699653 0 0.0
RAM 81188 81188 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 656589 656589 0 0.0
RAM 73616 73616 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 616153 616153 0 0.0
RAM 71532 71532 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 635781 635781 0 0.0
RAM 74076 74076 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 635781 635781 0 0.0
RAM 74076 74076 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 635657 635657 0 0.0
RAM 74540 74540 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 655365 655365 0 0.0
RAM 77084 77084 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 655365 655365 0 0.0
RAM 77084 77084 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 612077 612077 0 0.0
RAM 68628 68628 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 631937 631937 0 0.0
RAM 71268 71268 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 631937 631937 0 0.0
RAM 71268 71268 0 0.0
efr32 lock-app BRD4187C FLASH 937120 937120 0 0.0
RAM 159904 159904 0 0.0
BRD4338a FLASH 730516 730516 0 0.0
RAM 234716 234716 0 0.0
window-app BRD4187C FLASH 1029808 1029808 0 0.0
RAM 128008 128008 0 0.0
esp32 all-clusters-app c3devkit DRAM 97312 97312 0 0.0
FLASH 1577574 1577574 0 0.0
IRAM 83820 83820 0 0.0
m5stack DRAM 116100 116100 0 0.0
FLASH 1545434 1545434 0 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4760 4760 0 0.0
FLASH 2709805 2709805 0 0.0
RAM 132784 132784 0 0.0
all-clusters-app debug unknown 5568 5568 0 0.0
FLASH 5976268 5976268 0 0.0
RAM 531600 531600 0 0.0
all-clusters-minimal-app debug unknown 5464 5464 0 0.0
FLASH 5324612 5324612 0 0.0
RAM 242712 242712 0 0.0
bridge-app debug unknown 5480 5480 0 0.0
FLASH 4683224 4683224 0 0.0
RAM 221448 221448 0 0.0
chip-tool debug unknown 6120 6120 0 0.0
FLASH 13099952 13099952 0 0.0
RAM 596578 596578 0 0.0
chip-tool-ipv6only arm64 unknown 21816 21816 0 0.0
FLASH 11163376 11163376 0 0.0
RAM 648256 648256 0 0.0
fabric-admin debug unknown 5808 5808 0 0.0
FLASH 11388981 11388981 0 0.0
RAM 596362 596362 0 0.0
fabric-bridge-app debug unknown 4736 4736 0 0.0
FLASH 4508482 4508482 0 0.0
RAM 208632 208632 0 0.0
fabric-sync debug unknown 4976 4976 0 0.0
FLASH 5614773 5614773 0 0.0
RAM 483504 483504 0 0.0
lighting-app debug+rpc+ui unknown 6144 6144 0 0.0
FLASH 5630465 5630465 0 0.0
RAM 231792 231792 0 0.0
lock-app debug unknown 5416 5416 0 0.0
FLASH 4731818 4731818 0 0.0
RAM 207696 207696 0 0.0
ota-provider-app debug unknown 4776 4776 0 0.0
FLASH 4360788 4360788 0 0.0
RAM 201336 201336 0 0.0
ota-requestor-app debug unknown 4728 4728 0 0.0
FLASH 4498196 4498196 0 0.0
RAM 205920 205920 0 0.0
shell debug unknown 4256 4256 0 0.0
FLASH 3006445 3006445 0 0.0
RAM 160472 160472 0 0.0
thermostat-no-ble arm64 unknown 9512 9512 0 0.0
FLASH 4097736 4097736 0 0.0
RAM 246024 246024 0 0.0
tv-app debug unknown 5744 5744 0 0.0
FLASH 5953653 5953653 0 0.0
RAM 606904 606904 0 0.0
tv-casting-app debug unknown 5320 5320 0 0.0
FLASH 11273469 11273469 0 0.0
RAM 710864 710864 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 907584 907584 0 0.0
RAM 142411 142411 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 902100 902100 0 0.0
RAM 124755 124755 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 846188 846188 0 0.0
RAM 141339 141339 0 0.0
nxp contact k32w0+release FLASH 584768 584768 0 0.0
RAM 70876 70876 0 0.0
mcxw71+release FLASH 600232 600232 0 0.0
RAM 63096 63096 0 0.0
light k32w0+release FLASH 611076 611076 0 0.0
RAM 70268 70268 0 0.0
k32w1+release FLASH 685552 685552 0 0.0
RAM 48680 48680 0 0.0
lock mcxw71+release FLASH 749040 749040 0 0.0
RAM 67492 67492 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1646972 1649564 2592 0.2
RAM 211576 211832 256 0.1
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1553876 1556452 2576 0.2
RAM 208392 208648 256 0.1
light cy8ckit_062s2_43012 FLASH 1469604 1472196 2592 0.2
RAM 200368 200624 256 0.1
lock cy8ckit_062s2_43012 FLASH 1467540 1470132 2592 0.2
RAM 224704 224960 256 0.1
qpg lighting-app qpg6105+debug FLASH 662360 662360 0 0.0
RAM 105220 105220 0 0.0
lock-app qpg6105+debug FLASH 620148 620148 0 0.0
RAM 99664 99664 0 0.0
stm32 light STM32WB5MM-DK FLASH 483016 483016 0 0.0
RAM 144688 144688 0 0.0
telink bridge-app tl7218x FLASH 665410 665410 0 0.0
RAM 90828 90828 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 622172 622172 0 0.0
RAM 31500 31500 0 0.0
light-app-ota-shell-factory-data tl3218x FLASH 770956 770956 0 0.0
RAM 43568 43568 0 0.0
tl7218x FLASH 779458 779458 0 0.0
RAM 98704 98704 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 680770 680770 0 0.0
RAM 52192 52192 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 709324 709324 0 0.0
RAM 73400 73400 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 626260 626260 0 0.0
RAM 142032 142032 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 814104 814104 0 0.0
RAM 99608 99608 0 0.0
tizen all-clusters-app arm unknown 5104 5104 0 0.0
FLASH 1752644 1752644 0 0.0
RAM 93508 93508 0 0.0
chip-tool-ubsan arm unknown 11396 11396 0 0.0
FLASH 18698574 18698574 0 0.0
RAM 8183320 8183320 0 0.0

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