Skip to content

Commit ddeeecd

Browse files
PavelVPVhenrikbrixandersen
authored andcommitted
bluetooth: host: Add a check for num of bt_conn_tx and ACL/ISO bufs
After #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>
1 parent 1ee5123 commit ddeeecd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_ZTEST), "Missing DT chosen property for HCI");
9292
#define BT_HCI_QUIRKS 0
9393
#endif
9494

95+
/* These checks are added to warn if the number of ACL or ISO packets in Controller is not equal to
96+
* the number of bt_conn_tx contexts allocated by Host. The inequality of these two values can lead
97+
* to inefficient resources usage either on Host's or Controller's side.
98+
*/
99+
#define CHECK_NUM_OF_ACL_PKTS(_num) \
100+
do { \
101+
if (CONFIG_BT_BUF_ACL_TX_COUNT != (_num)) { \
102+
LOG_WRN("Num of Controller's ACL packets != ACL bt_conn_tx contexts" \
103+
" (%u != %u)", (_num), CONFIG_BT_BUF_ACL_TX_COUNT); \
104+
} \
105+
} while (0)
106+
107+
#define CHECK_NUM_OF_ISO_PKTS(_num) \
108+
do { \
109+
if (CONFIG_BT_ISO_TX_BUF_COUNT != (_num)) { \
110+
LOG_WRN("Num of Controller's ISO packets != ISO bt_conn_tx contexts" \
111+
"(%u != %u)", (_num), CONFIG_BT_ISO_TX_BUF_COUNT); \
112+
} \
113+
} while (0)
114+
95115
void bt_tx_irq_raise(void);
96116

97117
#define HCI_CMD_TIMEOUT K_SECONDS(10)
@@ -3145,6 +3165,8 @@ static void le_read_buffer_size_complete(struct net_buf *buf)
31453165

31463166
LOG_DBG("ACL LE buffers: pkts %u mtu %u", rp->le_max_num, bt_dev.le.acl_mtu);
31473167

3168+
CHECK_NUM_OF_ACL_PKTS(rp->le_max_num);
3169+
31483170
k_sem_init(&bt_dev.le.acl_pkts, rp->le_max_num, rp->le_max_num);
31493171
#endif /* CONFIG_BT_CONN */
31503172
}
@@ -3164,6 +3186,8 @@ static void read_buffer_size_v2_complete(struct net_buf *buf)
31643186
LOG_DBG("ACL LE buffers: pkts %u mtu %u", rp->acl_max_num, bt_dev.le.acl_mtu);
31653187

31663188
k_sem_init(&bt_dev.le.acl_pkts, rp->acl_max_num, rp->acl_max_num);
3189+
3190+
CHECK_NUM_OF_ACL_PKTS(rp->acl_max_num);
31673191
}
31683192
#endif /* CONFIG_BT_CONN */
31693193

@@ -3180,6 +3204,8 @@ static void read_buffer_size_v2_complete(struct net_buf *buf)
31803204

31813205
k_sem_init(&bt_dev.le.iso_pkts, rp->iso_max_num, rp->iso_max_num);
31823206
bt_dev.le.iso_limit = rp->iso_max_num;
3207+
3208+
CHECK_NUM_OF_ISO_PKTS(rp->iso_max_num);
31833209
#endif /* CONFIG_BT_ISO */
31843210
}
31853211

0 commit comments

Comments
 (0)