Skip to content

Commit

Permalink
Bluetooth: ATT: Internalize ATT PDU TX pool
Browse files Browse the repository at this point in the history
Why?
- metadata is easier to manage as an array + index
  - less error-prone -> less memory-management bugs
- we can. because of the previous refactor
- PDU allocations are more predictable
- ATT buffer size can be optimized by app
- isolates ATT from the rest of the ACL users
  - decouples ATT PDU size from e.g. SMP w/ LESC

Drawbacks:
- higher memory usage
- kconfig change

The higher memory use is only temporary, as this will be followed-up
with more refactors that should bring it back down.

Signed-off-by: Jonathan Rico <[email protected]>
Co-authored-by: Aleksander Wasaznik <[email protected]>
  • Loading branch information
2 people authored and jhedberg committed Dec 15, 2023
1 parent 47ec435 commit a05a475
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 95 deletions.
3 changes: 3 additions & 0 deletions doc/releases/migration-guide-3.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ Bootloader
Bluetooth
=========

* ATT now has its own TX buffer pool.
If extra ATT buffers were configured using :kconfig:option:`CONFIG_BT_L2CAP_TX_BUF_COUNT`,
they now instead should be configured through :kconfig:option:`CONFIG_BT_ATT_TX_COUNT`.
* The HCI implementation for both the Host and the Controller sides has been
renamed for the IPC transport. The ``CONFIG_BT_RPMSG`` Kconfig option is now
:kconfig:option:`CONFIG_BT_HCI_IPC`, and the ``zephyr,bt-hci-rpmsg-ipc``
Expand Down
16 changes: 8 additions & 8 deletions include/zephyr/bluetooth/gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ struct bt_gatt_exchange_params {
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*
* @retval -EALREADY The MTU exchange procedure has been already performed.
*/
Expand Down Expand Up @@ -1502,7 +1502,7 @@ struct bt_gatt_discover_params {
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_discover(struct bt_conn *conn,
struct bt_gatt_discover_params *params);
Expand Down Expand Up @@ -1617,7 +1617,7 @@ struct bt_gatt_read_params {
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params);

Expand Down Expand Up @@ -1670,7 +1670,7 @@ struct bt_gatt_write_params {
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside Bluetooth event context to get blocking behavior. Queue size is
* controlled by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* controlled by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);

Expand Down Expand Up @@ -1707,7 +1707,7 @@ int bt_gatt_write(struct bt_conn *conn, struct bt_gatt_write_params *params);
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
const void *data, uint16_t length,
Expand All @@ -1733,7 +1733,7 @@ int bt_gatt_write_without_response_cb(struct bt_conn *conn, uint16_t handle,
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
static inline int bt_gatt_write_without_response(struct bt_conn *conn,
uint16_t handle, const void *data,
Expand Down Expand Up @@ -1895,7 +1895,7 @@ struct bt_gatt_subscribe_params {
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_subscribe(struct bt_conn *conn,
struct bt_gatt_subscribe_params *params);
Expand Down Expand Up @@ -1941,7 +1941,7 @@ int bt_gatt_resubscribe(uint8_t id, const bt_addr_le_t *peer,
* @retval -ENOMEM ATT request queue is full and blocking would cause deadlock.
* Allow a pending request to resolve before retrying, or call this function
* outside the BT RX thread to get blocking behavior. Queue size is controlled
* by @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}.
* by @kconfig{CONFIG_BT_ATT_TX_COUNT}.
*/
int bt_gatt_unsubscribe(struct bt_conn *conn,
struct bt_gatt_subscribe_params *params);
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/tmap_bmr/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CONFIG_UTF8=y

CONFIG_BT_SMP=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_L2CAP_TX_BUF_COUNT=20
CONFIG_BT_ATT_TX_COUNT=20

# TMAP support
CONFIG_BT_TMAP=y
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/tmap_peripheral/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CONFIG_UTF8=y

CONFIG_BT_SMP=y
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_L2CAP_TX_BUF_COUNT=20
CONFIG_BT_ATT_TX_COUNT=20

# TMAP support
CONFIG_BT_TMAP=y
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/audio/tbs_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LOG_MODULE_REGISTER(bt_tbs_client, CONFIG_BT_TBS_CLIENT_LOG_LEVEL);
IS_ENABLED(CONFIG_BT_TBS_CLIENT_CALL_FRIENDLY_NAME) + \
IS_ENABLED(CONFIG_BT_TBS_CLIENT_INCOMING_CALL))

BUILD_ASSERT(CONFIG_BT_L2CAP_TX_BUF_COUNT >= TBS_CLIENT_BUF_COUNT, "Too few L2CAP buffers");
BUILD_ASSERT(CONFIG_BT_ATT_TX_COUNT >= TBS_CLIENT_BUF_COUNT, "Too few ATT buffers");

#include "common/bt_str.h"

Expand Down
9 changes: 9 additions & 0 deletions subsys/bluetooth/host/Kconfig.gatt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

menu "ATT and GATT Options"

config BT_ATT_TX_COUNT
int "Number of ATT buffers"
default BT_BUF_ACL_TX_COUNT
default 3
range 1 255
help
These buffers are only used for sending anything over ATT.
Requests, responses, indications, confirmations, notifications.

config BT_ATT_PREPARE_COUNT
int "Number of ATT prepare write buffers"
default 0
Expand Down
Loading

0 comments on commit a05a475

Please sign in to comment.