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

Bluetooth: Mesh: fix NO_ACTIONS scheduling #20054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HaavardRei
Copy link
Contributor

If the Scheduler Setup Server receives a Scheduler Action Set message setting the next scheduled task to NO_ACTIONS, it will schedule the next task in line.

Previously, the "canceled" task would be executed if it was first in line.

@HaavardRei HaavardRei requested a review from a team as a code owner January 23, 2025 13:44
@github-actions github-actions bot added changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. ble mesh Label for ble mesh PRbot. Add this if PR is related to ble mesh and you need to get review. labels Jan 23, 2025
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Jan 23, 2025

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 4

Inputs:

Sources:

sdk-nrf: PR head: be56440eaa9be9505faeb964d2a2d9f2a783ea6d

more details

sdk-nrf:

PR head: be56440eaa9be9505faeb964d2a2d9f2a783ea6d
merge base: f36abd1818b4606e9d825bac64356764b5dca37d
target head (main): 085e5a678ca84a3b5c8cd2e0c3b41de872f4b9cf
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (1)
subsys
│  ├── bluetooth
│  │  ├── mesh
│  │  │  │ scheduler_srv.c

Outputs:

Toolchain

Version: 342151af73
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:342151af73_912848a074

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 823
  • ✅ Integration tests
    • ✅ test-fw-nrfconnect-ble_mesh
Disabled integration tests
    • desktop52_verification
    • doc-internal
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-boot
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_mosh
    • test-fw-nrfconnect-nrf-iot_positioning
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread
    • test-fw-nrfconnect-zigbee
    • test-low-level
    • test-sdk-audio
    • test-sdk-dfu
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-sidewalk
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

Copy link
Contributor

@alxelax alxelax left a comment

Choose a reason for hiding this comment

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

Action still remains in persistent memory. If this is periodic action, it will start again after reset device.

@@ -639,6 +639,12 @@ static int action_set(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx
run_scheduler(srv);
}

/* If the next scheduled action is set to "NO_ACTIONS", cancel it. */
if ((srv->sch_reg[idx].action == BT_MESH_SCHEDULER_NO_ACTIONS) && (srv->idx == idx)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if BT_MESH_SCHEDULER_NO_ACTIONS came for not ongoing action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, changed it to check whether the bitmap is active for the corresponding index, and to only run the scheduler if the canceled task is first in line.

@HaavardRei
Copy link
Contributor Author

Action still remains in persistent memory. If this is periodic action, it will start again after reset device.

Won't it be cleared here? https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/bluetooth/mesh/scheduler_srv.c#L647
is_entry_defined returns false then store sets the data to NULL?

@HaavardRei HaavardRei force-pushed the mesh_scheduler_srv_cancel_work branch from e5db06a to f8b36f9 Compare January 24, 2025 06:59
Copy link
Contributor

@alxelax alxelax left a comment

Choose a reason for hiding this comment

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

LGTM just the minor comment

I suppose it is worth to provide PR link in Firesquad channel request, that customer can cherry-pick fix before release.

@HaavardRei
Copy link
Contributor Author

LGTM just the minor comment

I suppose it is worth to provide PR link in Firesquad channel request, that customer can cherry-pick fix before release.

They're in-the-loop through Jira, I'll ping them once it's merged :)

Comment on lines 646 to 658
/* If the next scheduled action is set to "NO_ACTIONS", schedule the next in line */
if (srv->idx == idx) {
run_scheduler(srv);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic can cause buggy behavior.

Imagine:

  1. Only single schedule register was set with valid action. So, active_bitmap has exactly one bit set, and the action is scheduled.
  2. User immediately issues another action_set, changing the same register index to NO_ACTION but leaves all other fields unchanged.
  3. Now, flow reaches here, and since there is just one action (which is now NO_ACTION), run_scheduler() returns early.
  4. Nothing is changed, and the stale scheduled work still continues.

What is needed, I think, is this:

Suggested change
/* If the next scheduled action is set to "NO_ACTIONS", schedule the next in line */
if (srv->idx == idx) {
run_scheduler(srv);
}
}
/* If the next scheduled action is set to "NO_ACTIONS", schedule the next in line */
if (srv->idx == idx) {
cancel_action(srv, idx);
run_scheduler(srv);
}
}

It will also be useful to extend the existing tests to cover this bugfix.

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 missed the case where there's no other upcoming task. Now the server indices are cleared (set to BT_MESH_SCHEDULER_ACTION_ENTRY_COUNT) and the run_scheduler function will cancel the work in this case.

@HaavardRei HaavardRei force-pushed the mesh_scheduler_srv_cancel_work branch from f8b36f9 to 1e05d9e Compare January 24, 2025 12:39
@HaavardRei HaavardRei requested a review from omkar3141 January 24, 2025 12:45
If the Scheduler Setup Server receives a Scheduler Action Set message
setting the next scheduled task to NO_ACTIONS, it will schedule the
next task in line.

Previously, the "canceled" task would be executed if it was first in
line.

Signed-off-by: Håvard Reierstad <[email protected]>
@HaavardRei HaavardRei force-pushed the mesh_scheduler_srv_cancel_work branch from 1e05d9e to be56440 Compare January 24, 2025 12:47
@alxelax alxelax removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ble mesh Label for ble mesh PRbot. Add this if PR is related to ble mesh and you need to get review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants