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

Use explicit storage for ActionReturnStatus::c_str #34746

Conversation

andy31415
Copy link
Contributor

@andy31415 andy31415 commented Aug 2, 2024

Allocating some global storage for this is both not thread-safe and wastes RAM.

Use the stack for the small amount of storage (relatively ... same as 4 integers) that a return status string needs.

Changes

  • use separate storage for c_str and pass it in
  • fix a "buffer reset" bug that existed in the code on buffer re-use
  • Add unit tests

Allocating some global storage for this is both not thread-safe
and wastes RAM.

Use the stack for the tiny amount of storage (relatively ... same as 4
integers) that a return status string needs.
Copy link

Review changes with SemanticDiff.

Copy link

github-actions bot commented Aug 2, 2024

PR #34746: Size comparison from 138b5b8 to d67d7dc

Full report (3 builds for cc32xx, stm32)
platform target config section 138b5b8 d67d7dc change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 610542 610542 0 0.0
RAM 205380 205380 0 0.0
lock CC3235SF_LAUNCHXL FLASH 654846 654846 0 0.0
RAM 205620 205620 0 0.0
stm32 light STM32WB5MM-DK FLASH 477832 477832 0 0.0
RAM 144756 144756 0 0.0

Copy link

github-actions bot commented Aug 2, 2024

PR #34746: Size comparison from 138b5b8 to 0717287

Full report (8 builds for cc32xx, mbed, qpg, stm32, tizen)
platform target config section 138b5b8 0717287 change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 610542 610542 0 0.0
RAM 205380 205380 0 0.0
lock CC3235SF_LAUNCHXL FLASH 654846 654846 0 0.0
RAM 205620 205620 0 0.0
mbed lock-app-release cy8cproto_062_4343w FLASH 1505796 1505796 0 0.0
RAM 227296 227296 0 0.0
qpg lighting-app qpg6105+debug FLASH 655484 655484 0 0.0
RAM 105148 105148 0 0.0
lock-app qpg6105+debug FLASH 612920 612920 0 0.0
RAM 99632 99632 0 0.0
stm32 light STM32WB5MM-DK FLASH 477832 477832 0 0.0
RAM 144756 144756 0 0.0
tizen all-clusters-app arm unknown 1588 1588 0 0.0
FLASH 1705172 1705172 0 0.0
RAM 51820 51820 0 0.0
chip-tool-ubsan arm unknown 2404 2404 0 0.0
FLASH 16619658 16619658 0 0.0
RAM 7303836 7303804 -32 -0.0

Copy link

github-actions bot commented Aug 2, 2024

PR #34746: Size comparison from 138b5b8 to db1c883

Full report (85 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, mbed, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 138b5b8 db1c883 change % change
bl602 lighting-app bl602 FLASH 1277760 1277742 -18 -0.0
RAM 95896 95896 0 0.0
bl602+mfd FLASH 1292018 1292000 -18 -0.0
RAM 96048 96048 0 0.0
bl602+rpc FLASH 1316728 1316710 -18 -0.0
RAM 104320 104320 0 0.0
bl702 lighting-app bl702 FLASH 1098904 1098886 -18 -0.0
RAM 15249 15249 0 0.0
bl702+mfd FLASH 1109598 1109580 -18 -0.0
RAM 15393 15393 0 0.0
bl702+rpc FLASH 1188970 1188952 -18 -0.0
RAM 24245 24245 0 0.0
bl706-eth FLASH 881938 881920 -18 -0.0
RAM 27352 27352 0 0.0
bl706-wifi FLASH 1135116 1135098 -18 -0.0
RAM 14685 14685 0 0.0
bl702l lighting-app bl702l FLASH 1086066 1085792 -274 -0.0
RAM 21804 21804 0 0.0
bl702l+mfd FLASH 1097072 1097054 -18 -0.0
RAM 21956 21956 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 802704 802664 -40 -0.0
RAM 117620 117620 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 818652 818628 -24 -0.0
RAM 125220 125220 0 0.0
lock-mtd LP_EM_CC1354P10_6 FLASH 810936 810904 -32 -0.0
RAM 119500 119500 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 763132 763108 -24 -0.0
RAM 113640 113640 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 747784 747768 -16 -0.0
RAM 113832 113832 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 610542 610502 -40 -0.0
RAM 205380 205380 0 0.0
lock CC3235SF_LAUNCHXL FLASH 654846 654774 -72 -0.0
RAM 205620 205620 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 671777 671745 -32 -0.0
RAM 78348 78348 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 691637 691597 -40 -0.0
RAM 80980 80980 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 691637 691597 -40 -0.0
RAM 80980 80980 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 648565 648541 -24 -0.0
RAM 73416 73416 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 610417 610409 -8 -0.0
RAM 71340 71340 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 630053 630037 -16 -0.0
RAM 73892 73892 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 630053 630037 -16 -0.0
RAM 73892 73892 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 627785 627761 -24 -0.0
RAM 74356 74356 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 647501 647469 -32 -0.0
RAM 76908 76908 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 647501 647469 -32 -0.0
RAM 76908 76908 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 599885 599861 -24 -0.0
RAM 68372 68372 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 619737 619713 -24 -0.0
RAM 71004 71004 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 619737 619713 -24 -0.0
RAM 71004 71004 0 0.0
efr32 lighting-app BRD4187C FLASH 929744 929712 -32 -0.0
RAM 135148 135148 0 0.0
lock-app BRD4338a FLASH 737180 737108 -72 -0.0
RAM 208436 208436 0 0.0
window-app BRD4187C FLASH 1015540 1015508 -32 -0.0
RAM 127084 127084 0 0.0
esp32 all-clusters-app c3devkit DRAM 94136 94136 0 0.0
FLASH 1530542 1530482 -60 -0.0
IRAM 82538 82538 0 0.0
m5stack DRAM 115072 115072 0 0.0
FLASH 1541126 1541014 -112 -0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4632 4632 0 0.0
FLASH 2746547 2746489 -58 -0.0
RAM 128368 128272 -96 -0.1
all-clusters-app debug unknown 5416 5416 0 0.0
FLASH 6027690 6027556 -134 -0.0
RAM 509904 509840 -64 -0.0
all-clusters-minimal-app debug unknown 5312 5312 0 0.0
FLASH 5367580 5367522 -58 -0.0
RAM 240000 239936 -64 -0.0
bridge-app debug unknown 5296 5296 0 0.0
FLASH 4727326 4727268 -58 -0.0
RAM 217024 216960 -64 -0.0
chip-tool debug unknown 5832 5832 0 0.0
FLASH 12496588 12496444 -144 -0.0
RAM 558362 558298 -64 -0.0
chip-tool-ipv6only arm64 unknown 20352 20352 0 0.0
FLASH 11174028 11173884 -144 -0.0
RAM 608320 608256 -64 -0.0
fabric-admin debug unknown 5672 5672 0 0.0
FLASH 11474831 11474687 -144 -0.0
RAM 555098 555034 -64 -0.0
fabric-bridge-app debug unknown 4568 4568 0 0.0
FLASH 4483348 4483290 -58 -0.0
RAM 202192 202128 -64 -0.0
lighting-app debug+rpc+ui unknown 5968 5968 0 0.0
FLASH 5661393 5661345 -48 -0.0
RAM 228112 228048 -64 -0.0
lock-app debug unknown 5232 5232 0 0.0
FLASH 4782156 4782098 -58 -0.0
RAM 203840 203776 -64 -0.0
ota-provider-app debug unknown 4608 4608 0 0.0
FLASH 4422470 4422412 -58 -0.0
RAM 197824 197760 -64 -0.0
ota-requestor-app debug unknown 4544 4544 0 0.0
FLASH 4560616 4560558 -58 -0.0
RAM 202360 202296 -64 -0.0
shell debug unknown 4176 4176 0 0.0
FLASH 3066781 3066717 -64 -0.0
RAM 158952 158888 -64 -0.0
thermostat-no-ble arm64 unknown 9352 9352 0 0.0
FLASH 4357396 4357332 -64 -0.0
RAM 242216 242152 -64 -0.0
tv-app debug unknown 5504 5504 0 0.0
FLASH 6004661 6004533 -128 -0.0
RAM 583552 583488 -64 -0.0
tv-casting-app debug unknown 5176 5176 0 0.0
FLASH 10701117 10700973 -144 -0.0
RAM 645608 645544 -64 -0.0
mbed lock-app-release cy8cproto_062_4343w FLASH 1505796 1505732 -64 -0.0
RAM 227296 227296 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 906920 906844 -76 -0.0
RAM 142225 142225 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 879492 879492 0 0.0
RAM 140364 140364 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 838636 838596 -40 -0.0
RAM 141062 141062 0 0.0
nxp contact k32w0+release FLASH 576716 576700 -16 -0.0
RAM 70416 70416 0 0.0
k32w1+release FLASH 592440 592408 -32 -0.0
RAM 74456 74456 0 0.0
light k32w0+release FLASH 612376 612344 -32 -0.0
RAM 69920 69920 0 0.0
k32w1+release FLASH 677264 677240 -24 -0.0
RAM 83232 83232 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1636108 1635916 -192 -0.0
RAM 210912 210912 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1541244 1541116 -128 -0.0
RAM 207664 207664 0 0.0
light cy8ckit_062s2_43012 FLASH 1463476 1463348 -128 -0.0
RAM 200776 200776 0 0.0
lock cy8ckit_062s2_43012 FLASH 1462204 1462156 -48 -0.0
RAM 225120 225120 0 0.0
qpg lighting-app qpg6105+debug FLASH 655484 655460 -24 -0.0
RAM 105148 105148 0 0.0
lock-app qpg6105+debug FLASH 612920 612912 -8 -0.0
RAM 99632 99632 0 0.0
stm32 light STM32WB5MM-DK FLASH 477832 477792 -40 -0.0
RAM 144756 144756 0 0.0
telink air-quality-sensor-app tlsr9528a_retention FLASH 619760 619742 -18 -0.0
RAM 50936 50936 0 0.0
all-clusters-app tlsr9118bdk40d FLASH 678550 678490 -60 -0.0
RAM 149556 149556 0 0.0
all-clusters-minimal-app tlsr9528a FLASH 771784 771754 -30 -0.0
RAM 110732 110732 0 0.0
bridge-app tlsr9258a FLASH 678374 678356 -18 -0.0
RAM 91624 91624 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 621352 621334 -18 -0.0
RAM 50980 50980 0 0.0
light-switch-app-ota-shell-factory-data tlsr9528a FLASH 707216 707198 -18 -0.0
RAM 74316 74316 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 620140 620110 -30 -0.0
RAM 145580 145580 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 806226 806196 -30 -0.0
RAM 99504 99504 0 0.0
lock-app-dfu tlsr9528a FLASH 654102 654076 -26 -0.0
RAM 67012 67012 0 0.0
ota-requestor-app tlsr9258a FLASH 696408 696390 -18 -0.0
RAM 91308 91308 0 0.0
pump-app-usb tlsr9518adk80d FLASH 630708 630690 -18 -0.0
RAM 55756 55756 0 0.0
pump-controller-app tlsr9518adk80d FLASH 608308 608290 -18 -0.0
RAM 53000 53000 0 0.0
shell tlsr9518adk80d FLASH 466810 466810 0 0.0
RAM 68660 68660 0 0.0
smoke_co_alarm-app tlsr9528a_retention FLASH 628120 628102 -18 -0.0
RAM 52696 52696 0 0.0
temperature-measurement-app-mars-ota tlsr9518adk80d FLASH 652130 652112 -18 -0.0
RAM 56636 56636 0 0.0
thermostat tlsr9518adk80d FLASH 631896 631874 -22 -0.0
RAM 53376 53376 0 0.0
window-covering tlsr9118bdk40d FLASH 522270 522252 -18 -0.0
RAM 98536 98536 0 0.0
tizen all-clusters-app arm unknown 1588 1588 0 0.0
FLASH 1705172 1705140 -32 -0.0
RAM 51820 51820 0 0.0
chip-tool-ubsan arm unknown 2404 2404 0 0.0
FLASH 16619658 16619594 -64 -0.0
RAM 7303836 7303808 -28 -0.0

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

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

Much nicer, thank you!

@andy31415 andy31415 merged commit 3a5e3db into project-chip:master Aug 7, 2024
68 checks passed
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.

4 participants