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

Add a SDK part of IM Cluster Status Success to CHIP_ERROR #34597

Closed

Conversation

andy31415
Copy link
Contributor

@andy31415 andy31415 commented Jul 29, 2024

CHIP_ERROR currently covers global IM statuses as well as cluster-specific failures, however we did not cover cluster specific successes.

This PR adds a new part to CHIP_ERROR that encodes cluster statuses and updates StatusIB to be able to convert from them. Note that this still considers such success statuses as a CHIP_ERROR since the overhead of converting all tests to not check CHIP_NO_ERROR and have code inside IsSuccess would be quite expensive.

Background of this change:

Working on DataModel interface split, where Writes may return a CHIP_ERROR currently however that fails to encode ClusterSuccess.

I also considered making the DM provider interfaces return ClusterStatus however that requires more work since ReadAttribute relies on non-status errors like CHIP_NO_MEMORY to control code paths. As such, having a better return (e.g. a std::variant<ClusterStatus, ProcessingError> where ProcessingError would be out of space) requires more thought. Also a lot of SDK code returns CHIP_ERROR, so a CHIP_ERROR based interface seems slightly more convenient to use at this point).

Copy link

Review changes with SemanticDiff.

Copy link

github-actions bot commented Jul 29, 2024

PR #34597: Size comparison from 37fc757 to 5695fa4

Increases above 0.2%:

platform target config section 37fc757 5695fa4 change % change
linux shell debug RAM 154760 155304 544 0.4
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 37fc757 5695fa4 change % change
bl602 lighting-app bl602 FLASH 1276462 1276512 50 0.0
RAM 95576 95576 0 0.0
bl602+mfd FLASH 1290720 1290770 50 0.0
RAM 95728 95728 0 0.0
bl602+rpc FLASH 1315430 1315480 50 0.0
RAM 104000 104000 0 0.0
bl702 lighting-app bl702 FLASH 1097356 1097406 50 0.0
RAM 15257 15257 0 0.0
bl702+mfd FLASH 1108050 1108100 50 0.0
RAM 15401 15401 0 0.0
bl702+rpc FLASH 1187422 1187472 50 0.0
RAM 24253 24253 0 0.0
bl706-eth FLASH 880656 880706 50 0.0
RAM 27360 27360 0 0.0
bl706-wifi FLASH 1133608 1133658 50 0.0
RAM 14693 14693 0 0.0
bl702l lighting-app bl702l FLASH 1084254 1084304 50 0.0
RAM 21812 21812 0 0.0
bl702l+mfd FLASH 1095516 1095566 50 0.0
RAM 21964 21964 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 801924 801956 32 0.0
RAM 109428 109428 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 816684 816716 32 0.0
RAM 117028 117028 0 0.0
lock-mtd LP_EM_CC1354P10_6 FLASH 808652 808676 24 0.0
RAM 111308 111308 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 762416 762440 24 0.0
RAM 105448 105448 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 747068 747092 24 0.0
RAM 105640 105640 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 606674 606722 48 0.0
RAM 204580 204580 0 0.0
lock CC3235SF_LAUNCHXL FLASH 652210 652258 48 0.0
RAM 204852 204852 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 671001 671033 32 0.0
RAM 77892 77892 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 690861 690885 24 0.0
RAM 80524 80524 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 690861 690885 24 0.0
RAM 80524 80524 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 647797 647829 32 0.0
RAM 72960 72960 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 609713 609737 24 0.0
RAM 70884 70884 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 629341 629365 24 0.0
RAM 73436 73436 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 629341 629365 24 0.0
RAM 73436 73436 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 625409 625433 24 0.0
RAM 73900 73900 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 645117 645149 32 0.0
RAM 76452 76452 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 645117 645149 32 0.0
RAM 76452 76452 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 593637 593661 24 0.0
RAM 67860 67860 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 613489 613513 24 0.0
RAM 70492 70492 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 613489 613513 24 0.0
RAM 70492 70492 0 0.0
efr32 lighting-app BRD4187C FLASH 929000 929024 24 0.0
RAM 134700 134700 0 0.0
lock-app BRD4338a FLASH 734716 734764 48 0.0
RAM 207988 207988 0 0.0
window-app BRD4187C FLASH 1014780 1014804 24 0.0
RAM 126636 126636 0 0.0
esp32 all-clusters-app c3devkit DRAM 91180 91236 56 0.1
FLASH 1484266 1484616 350 0.0
IRAM 75570 75570 0 0.0
m5stack DRAM 117660 117724 64 0.1
FLASH 1553239 1553611 372 0.0
IRAM 125403 125403 0 0.0
linux air-purifier-app debug unknown 4632 4632 0 0.0
FLASH 2710605 2710723 118 0.0
RAM 125200 125200 0 0.0
all-clusters-app debug unknown 5416 5416 0 0.0
FLASH 5911254 5913664 2410 0.0
RAM 500312 501016 704 0.1
all-clusters-minimal-app debug unknown 5312 5312 0 0.0
FLASH 5315394 5315512 118 0.0
RAM 236592 236592 0 0.0
bridge-app debug unknown 5296 5296 0 0.0
FLASH 4707196 4707314 118 0.0
RAM 214048 214048 0 0.0
chip-tool debug unknown 5784 5784 0 0.0
FLASH 12337160 12337276 116 0.0
RAM 553522 553522 0 0.0
chip-tool-ipv6only arm64 unknown 20192 20192 0 0.0
FLASH 11035980 11036092 112 0.0
RAM 603240 603240 0 0.0
fabric-admin debug unknown 5672 5672 0 0.0
FLASH 11343261 11343377 116 0.0
RAM 550362 550362 0 0.0
fabric-bridge-app debug unknown 4568 4568 0 0.0
FLASH 4463232 4463350 118 0.0
RAM 199248 199248 0 0.0
lighting-app debug+rpc+ui unknown 5968 5968 0 0.0
FLASH 5640753 5640881 128 0.0
RAM 225136 225136 0 0.0
lock-app debug unknown 5232 5232 0 0.0
FLASH 4757986 4758104 118 0.0
RAM 200704 200704 0 0.0
ota-provider-app debug unknown 4608 4608 0 0.0
FLASH 4402452 4402570 118 0.0
RAM 194880 194880 0 0.0
ota-requestor-app debug unknown 4544 4544 0 0.0
FLASH 4540598 4540716 118 0.0
RAM 199416 199416 0 0.0
shell debug unknown 4176 4176 0 0.0
FLASH 3000653 3000829 176 0.0
RAM 154760 155304 544 0.4
thermostat-no-ble arm64 unknown 9208 9208 0 0.0
FLASH 4259860 4259988 128 0.0
RAM 236368 236368 0 0.0
tv-app debug unknown 5504 5504 0 0.0
FLASH 5983453 5983565 112 0.0
RAM 578176 578176 0 0.0
tv-casting-app debug unknown 5168 5168 0 0.0
FLASH 10549869 10549997 128 0.0
RAM 638984 638984 0 0.0
mbed lock-app-release cy8cproto_062_4343w FLASH 1503444 1503444 0 0.0
RAM 226728 226728 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 898960 899312 352 0.0
RAM 141757 141787 30 0.0
nrf7002dk_nrf5340_cpuapp FLASH 964548 964884 336 0.0
RAM 140861 140891 30 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 834276 834300 24 0.0
RAM 140612 140612 0 0.0
nxp contact k32w0+release FLASH 576084 576116 32 0.0
RAM 70112 70112 0 0.0
k32w1+release FLASH 591784 591816 32 0.0
RAM 74152 74152 0 0.0
light k32w0+release FLASH 611696 611728 32 0.0
RAM 69616 69616 0 0.0
k32w1+release FLASH 676528 676552 24 0.0
RAM 82928 82928 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1625044 1625412 368 0.0
RAM 209936 210000 64 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1535284 1535332 48 0.0
RAM 206728 206728 0 0.0
light cy8ckit_062s2_43012 FLASH 1462532 1462580 48 0.0
RAM 200000 200000 0 0.0
lock cy8ckit_062s2_43012 FLASH 1459668 1459716 48 0.0
RAM 224344 224344 0 0.0
qpg lighting-app qpg6105+debug FLASH 654812 654844 32 0.0
RAM 104844 104844 0 0.0
lock-app qpg6105+debug FLASH 612264 612296 32 0.0
RAM 99328 99328 0 0.0
stm32 light STM32WB5MM-DK FLASH 477112 477144 32 0.0
RAM 144452 144452 0 0.0
telink air-quality-sensor-app tlsr9528a_retention FLASH 619000 619028 28 0.0
RAM 50664 50664 0 0.0
all-clusters-app tlsr9118bdk40d FLASH 671196 671226 30 0.0
RAM 149092 149120 28 0.0
all-clusters-minimal-app tlsr9528a FLASH 767122 767150 28 0.0
RAM 110284 110284 0 0.0
bridge-app tlsr9258a FLASH 677616 677644 28 0.0
RAM 91320 91320 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 620592 620620 28 0.0
RAM 50708 50708 0 0.0
light-switch-app-ota-shell-factory-data tlsr9528a FLASH 706436 706464 28 0.0
RAM 74036 74036 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 619276 619304 28 0.0
RAM 145276 145276 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 805362 805390 28 0.0
RAM 99200 99200 0 0.0
lock-app-dfu tlsr9528a FLASH 652370 652398 28 0.0
RAM 66740 66740 0 0.0
ota-requestor-app tlsr9258a FLASH 695652 695680 28 0.0
RAM 91004 91004 0 0.0
pump-app-usb tlsr9518adk80d FLASH 629946 629974 28 0.0
RAM 55484 55484 0 0.0
pump-controller-app tlsr9518adk80d FLASH 607548 607576 28 0.0
RAM 52728 52728 0 0.0
shell tlsr9518adk80d FLASH 466654 466654 0 0.0
RAM 68412 68412 0 0.0
smoke_co_alarm-app tlsr9528a_retention FLASH 627334 627362 28 0.0
RAM 52344 52344 0 0.0
temperature-measurement-app-mars-ota tlsr9518adk80d FLASH 651370 651398 28 0.0
RAM 56364 56364 0 0.0
thermostat tlsr9518adk80d FLASH 626256 626284 28 0.0
RAM 53052 53052 0 0.0
window-covering tlsr9118bdk40d FLASH 521510 521538 28 0.0
RAM 98264 98264 0 0.0
tizen all-clusters-app arm unknown 1588 1588 0 0.0
FLASH 1674116 1674520 404 0.0
RAM 49636 49700 64 0.1
chip-tool-ubsan arm unknown 2388 2388 0 0.0
FLASH 16382014 16382222 208 0.0
RAM 7190464 7190552 88 0.0

kIMGlobalStatus = 5, ///< Interaction Model global status code.
kIMClusterStatusFailure = 6, ///< Interaction Model cluster-specific status code (failure)
kApplication = 7, ///< Application-defined errors; see CHIP_APPLICATION_ERROR
kIMClusterStatusSuccess = 8, ///< Interaction Model cluster-specific status code (success)
Copy link
Contributor

@bzbarsky-apple bzbarsky-apple Jul 29, 2024

Choose a reason for hiding this comment

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

We sort of purposefully did not do this, because encoding a "success" status as a CHIP_ERROR is really weird and brittle: various callers have to know that your error is not really an error and that things should be propagated properly.

This is particularly bad when the thing returning this is not in tail-call position, obviously.

For cases when we might have a cluster-specific success we really need to be using a different return type than CHIP_ERROR, or use CHIP_ERROR to indicate actualy errors but have an out-param for the status or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difficulty was that conceptually Read/Write/Invoke are supposed to be StatusIB (so ClusterStatus) however for chunking we are also expecting a CHIP_ERROR to encode the out of space errors.

I am concerned that the ripple effect of that. The existing code logic is not very clean on single-return because AddStatus is separated from error code return and that allowed our types to diverge.

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing we could do:

  1. Add an mOutOfSpace member to AttributeValueEncoder.
  2. Set this member as needed in the relevant public Encode methods (we can do this without too much codesize hit, maybe).
  3. Have whatever created the AttributeValueEncoder check that state (like it already checks the mTriedEncode state) and handle it appropriately.
  4. Change AttributeAccessInterface::Read to return ClusterStatus
  5. Change DataModel::Provider::ReadAttribute to return ClusterStatus

That does mean not being able to use ReturnErrorOnFailure() all over in Read, though....

Another option is to just hang the ClusterStatus off the AttributeValueEncoder and the few consumers that want a success status can do that, and we check for it in the one chokepoint at the callsite.

@andy31415
Copy link
Contributor Author

closing for #34708

@andy31415 andy31415 closed this Aug 1, 2024
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