Skip to content

Bluetooth: Host: Introduce a Bluetooth workqueue #93033

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jhedberg
Copy link
Member

@jhedberg jhedberg commented Jul 11, 2025

Avoid the system workqueue, and introduce a general purpose Bluetooth workqueue that can be used in most situations.

jhedberg added 4 commits July 11, 2025 18:53
Update the minimal configurations for peripheral_hr and central_hr to match
what the Bluetooth stack current needs & uses. Also enable the serial
console, since that's possible to do while still fitting within 16k RAM
and is very helpful for basic verification and debugging.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The actual usage is substantially less than the default when using minimal
configurations on nRF51:

 BT CTLR RX          : STACK: unused 32 usage 288 / 320 (90 %); CPU: 0 %
 BT CTLR RX pri      : STACK: unused 32 usage 344 / 376 (91 %); CPU: 0 %

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Fine tune the mesh_demo app for bbc_microbit.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Avoid the system workqueue, and introduce a general purpose Bluetooth
workqueue that can be used in most situations.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Copy link

@jhedberg jhedberg requested a review from Copilot July 11, 2025 16:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a dedicated Bluetooth workqueue and migrates existing SMP, L2CAP, RFCOMM, GATT, ATT, and other host timers and work submissions from the system workqueue to the new bt_work_* API.

  • Added bt_work_submit, bt_work_schedule, and bt_work_reschedule wrappers and initialized a Bluetooth workqueue in hci_core.c.
  • Replaced all uses of k_work_submit, k_work_schedule, and k_work_reschedule with the new bt_work_* variants across host subsystems.
  • Updated Kconfig to introduce CONFIG_BT_WQ, deprecate the old BT receive workqueue option, and adjusted various sample configuration files.

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
subsys/bluetooth/host/smp.c Replaced SMP work reschedules with bt_work_reschedule
subsys/bluetooth/host/settings.c Updated settings store work submissions to bt_work_submit
subsys/bluetooth/host/l2cap.c Converted L2CAP work resubmit/submit to bt_work_*
subsys/bluetooth/host/keys.c Changed ID add work submission to bt_work_submit
subsys/bluetooth/host/id.c Swapped RPA update scheduling to bt_work_schedule
subsys/bluetooth/host/hci_core.h Added prototypes for bt_work_submit, bt_work_schedule, bt_work_reschedule
subsys/bluetooth/host/hci_core.c Implemented the Bluetooth workqueue and API wrappers
subsys/bluetooth/host/gatt.c Migrated service‐changed and notify work calls to bt_work_*
subsys/bluetooth/host/conn.c Updated auto-init work submission (one schedule call still uses k_work_schedule)
subsys/bluetooth/host/classic/rfcomm.c Converted various RFCOMM timers to use bt_work_reschedule
subsys/bluetooth/host/classic/l2cap_br.c Updated BR L2CAP monitoring and retransmission timers to bt_work_*
subsys/bluetooth/host/classic/br.c Replaced BR discoverable timeout scheduling with bt_work_reschedule
subsys/bluetooth/host/att.c Swapped ATT timeout and EATT connection scheduling to bt_work_*
subsys/bluetooth/host/adv.c Changed advertising timeout to bt_work_reschedule
subsys/bluetooth/host/Kconfig Introduced CONFIG_BT_WQ, deprecated BT_RECV_WORKQ_SYS
subsys/bluetooth/controller/Kconfig.ll_sw_split Added conditional default stack sizes for nRF51 controller RX threads
samples/bluetooth/peripheral_hr/prj_minimal.conf Enabled console, UART, serial and adjusted workqueue stack sizes
samples/bluetooth/mesh_demo/src/microbit.c Refactored button/PWM setup and removed device‐ready checks
samples/bluetooth/mesh_demo/boards/bbc_microbit.conf Updated ISR, main, and WQ stack sizes and mesh buffer counts
samples/bluetooth/central_hr/prj_minimal.conf Enabled console/UART and tuned stack sizes for BT and system workqueues
Comments suppressed due to low confidence (3)

subsys/bluetooth/host/Kconfig:131

  • [nitpick] Add a help description for CONFIG_BT_WQ to explain its purpose and default behavior.
config BT_WQ

samples/bluetooth/peripheral_hr/prj_minimal.conf:73

  • [nitpick] Lowering the system workqueue stack size significantly may impact sample stability; add a validation test or runtime check for stack usage.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=400

@@ -1208,8 +1208,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
}
#endif /* CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS */

k_work_schedule(&conn->deferred_work,
CONN_UPDATE_TIMEOUT);
k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT);
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

This call should use the new bt_work_schedule API to schedule on the Bluetooth workqueue instead of k_work_schedule.

Suggested change
k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT);
bt_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT);

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

The conn->deferred_work related code still uses the system workqueue, since there are application callbacks involved in several cases. The goal is to try to keep the new Bluetooth workqueue purely for Bluetooth host stack internal functionality, and anything that might reach over to the application side should be in another context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant