Skip to content

Bluetooth: Host: ACL/ISO buffers and bt_conn_tx objects mismatch #89258

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

Conversation

PavelVPV
Copy link
Collaborator

@PavelVPV PavelVPV commented Apr 29, 2025

This PR addresses an issue of mismatch between ACL/ISO buffers reported by Controller and bt_conn_tx objects allocated by Host.

After #72090, each packet to be sent (whether ACL or ISO data) has a corresponding bt_conn_tx object, regardless of whether a callback is used.

This means that:

  1. number of packets Host can send to Controller is limited by the smaller of two values: ACL/ISO packets Controller can receive, and the number of bt_conn_tx objects allocated by Host.
  2. CONFIG_BT_CONN_TX_MAX is superseded by CONFIG_BT_BUF_ACL_TX_COUNT because Host starts using a free bt_conn_tx object only after checking that Controller can receive more ACL or ISO data over a connection.

The issue reported in #72017 is valid and results in inefficient resource usage. The points mentioned above mean that the solution suggested in #72017 is outdated after #72090. Using separate FIFOs for ACL and ISO data will only hide the problem of resource utilization.

This PR does 2 things:

  1. deprecates CONFIG_BT_CONN_TX_MAX and replaces it with CONFIG_BT_BUF_ACL_TX_COUNT for bt_conn_tx objects allocation for ACL tx buffers.
  2. adds a check with a warning if number of bt_conn_tx objects mismatches with ACL/ISO buffers reported by Controller and thus need to be changed for better resources utilization.

Fixes #72017.

@PavelVPV PavelVPV force-pushed the acl_iso_pkts_and_bt_conn_tx_misalignment branch 3 times, most recently from 6285e8e to 3024c4b Compare April 30, 2025 11:33
@PavelVPV PavelVPV changed the title Bluetooth: Host: ACL/ISO packets and bt_conn_tx misalignment Bluetooth: Host: Deprecate CONFIG_BT_CONN_TX_MAX May 5, 2025
@PavelVPV PavelVPV changed the title Bluetooth: Host: Deprecate CONFIG_BT_CONN_TX_MAX Bluetooth: Host: ACL/ISO buffers and bt_conn_tx objects mismatch May 5, 2025
@PavelVPV PavelVPV marked this pull request as ready for review May 5, 2025 19:48
@github-actions github-actions bot added Release Notes To be mentioned in the release notes area: Bluetooth area: Bluetooth Classic Bluetooth Classic (BR/EDR) area: Bluetooth Host Bluetooth Host (excluding BR/EDR) labels May 5, 2025
@@ -140,8 +140,8 @@ config BT_RFCOMM_L2CAP_MTU

config BT_RFCOMM_TX_MAX
int "Maximum number of pending TX buffers for RFCOMM"
default BT_CONN_TX_MAX
range BT_CONN_TX_MAX $(UINT8_MAX)
default BT_BUF_ACL_TX_COUNT
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lylezhu2012 , I see that the usage of CONFIG_BT_RFCOMM_TX_MAX has been removed in 17e2564 but it is used as a default value still for BT_HFP_AG_TX_BUF_COUNT. Not sure if you are aware. Just wanted to point out this.

jhedberg
jhedberg previously approved these changes May 6, 2025
Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

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

Looks fine, although in the long run I think it'd be better to reduce (and ideally completely remove) dependencies from the controller upward in the stack. The bt_buf_*() APIs and CONFIG_BT_BUF_ACL_TX_COUNT are kind of such a dependency - I know they can be considered a "shared" or "common" for the host and controller, but the controller should IMO have its own configuration options which the host-side can synchronize its options to when the host is using a local controller.

@cvinayak
Copy link
Collaborator

cvinayak commented May 6, 2025

the controller should IMO have its own configuration options which the host-side can synchronize its options to when the host is using a local controller.

@jhedberg This was originally the case until 6483e12, but now the Zephyr Controller does inherit CONFIG_BT_BUF_ACL_TX_COUNT under Host+Controller combined builds; I guess this is ok as there is now only one Kconfig anyway, under the common/Kconfig.

Do you think we still need Host and Controller seperate Kconfig, and they inherit values (hide one or the other in case of combined build) ?

alwa-nordic
alwa-nordic previously approved these changes May 6, 2025
@@ -329,7 +329,7 @@ config BT_CONN_FRAG_COUNT
if BT_CONN

config BT_CONN_TX_MAX
int "Maximum number of pending TX buffers with a callback"
int "Maximum number of pending TX buffers with a callback [DEPRECATED]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't deprecated KConfig select DEPRECATED option?
Like here: https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/bluetooth/mesh/Kconfig#L1492-L1494

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't work for numeric Kconfigs.

Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

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

This does not seem like the correct solution to the problem. While it does fix it, it also adds a significant restriction on (at least ISO) that may break some applications

@jhedberg
Copy link
Member

jhedberg commented May 6, 2025

Do you think we still need Host and Controller seperate Kconfig, and they inherit values (hide one or the other in case of combined build) ?

What I'd like to move towards is to make the HCI driver API clean in the sense that its implementors shouldn't know or care who its users are (the user could be the Zephyr host, HCI raw, or something completely different). Right now we have subsys/bluetooth/host/buf.c and include/zephyr/bluetooth/buf.h implementing bt_buf_*() APIs that HCI drivers depend on. The only API drivers should care about is what's part of include/zephyr/drivers/bluetooth.h. I suppose the situation might be a bit murkier with Kconfig options, but simply namespace-wise CONFIG_BT_BUF_* sounds like its owned by the bt_buf_* subcomponent of the Zephyr host stack.

@PavelVPV PavelVPV dismissed stale reviews from alwa-nordic and jhedberg via c2d155f May 8, 2025 12:27
@PavelVPV PavelVPV force-pushed the acl_iso_pkts_and_bt_conn_tx_misalignment branch from 3024c4b to c2d155f Compare May 8, 2025 12:27
Thalley
Thalley previously approved these changes May 8, 2025
PavelVPV added 2 commits May 12, 2025 07:50
After zephyrproject-rtos#72090, each
packet to be sent (wether ACL or ISO data) has a corresponding
`bt_conn_tx` object, regardless of whether a callback is used.

This means that number of packets Host can send to Controller is limited
by the smaller of two values: ACL/ISO packets Controller can receive,
and the number of `bt_conn_tx` objects allocated by Host.

A mismatch between these numbers may lead to inefficient resource usage
on either Host or Controller side. If Host allocates fewer `bt_conn_tx`
objects than the number of buffers available on Controller for a given
data type, some Controller buffers may go unused. Conversely, if Host
allocates more `bt_conn_tx` objects than Controller can consume, the
excess objects remain unused.

This commit adds a check and issues a warning if the number of
`bt_conn_tx` objects is not aligned with the number of ACL/ISO buffers
reported by Controller via the LE Read Buffer Size v1 or v2 command.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
After zephyrproject-rtos#72090,
`conn_tx_alloc` no longer blocks, and each buffer always has a
corresponding `bt_conn_tx` object. This eliminates the need to configure
the number of `bt_conn_tx` objects via `CONFIG_BT_CONN_TX_MAX`, since
every buffer now carries its own context even when no callback is used.

This commit deprecates `CONFIG_BT_CONN_TX_MAX` as it is no longer
necessary. Instead, `CONFIG_BT_BUF_ACL_TX_COUNT` is used to allocate
`bt_conn_tx` objects for outgoing ACL data. ZLL already uses
`CONFIG_BT_BUF_ACL_TX_COUNT` to configure the number of outgoing ACL
packets. With this change, modifying the packet count will automatically
adjust the number of corresponding contexts, preventing both context
starvatoin and underutilization.

This approach also aligns with ISO, where the number of `bt_conn_tx`
objects for outgoing ISOdata matches `CONFIG_BT_ISO_TX_BUF_COUNT`.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
@PavelVPV PavelVPV force-pushed the acl_iso_pkts_and_bt_conn_tx_misalignment branch from c2d155f to b53d7c8 Compare May 12, 2025 05:50
@PavelVPV PavelVPV requested a review from Thalley May 12, 2025 05:50
@PavelVPV
Copy link
Collaborator Author

@jhedberg, @alwa-nordic, please take a look at this PR one more time.

@henrikbrixandersen henrikbrixandersen merged commit 14b4e30 into zephyrproject-rtos:main May 12, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Classic Bluetooth Classic (BR/EDR) area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bluetooth: (conn.c) ACL buffers can "steal" ISO TX contexts
7 participants