Skip to content

Commit 1e9d7b6

Browse files
jori-nordicalwa-nordic
authored andcommitted
Bluetooth: buf: Put command complete/status in sync buf pool
Why is it ok to use the sync pool? Because command complete/status is processed in prio: that means on the same stack as the `bt_recv()` call from the driver. Why does it fix the issue? Because the complete/status event goes into a pool that is guaranteed to have one free buffer any time `bt_recv()` is not executing. Since the driver is the one calling bt_recv(), it (hopefully) will finish one `bt_recv()` before starting another one. Fixes #78223 Co-authored-by: Aleksander Wasaznik <[email protected]> Signed-off-by: Aleksander Wasaznik <[email protected]> Signed-off-by: Jonathan Rico <[email protected]> (cherry picked from commit 6d5cce6) Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 948652a commit 1e9d7b6

File tree

1 file changed

+9
-17
lines changed
  • subsys/bluetooth/host

1 file changed

+9
-17
lines changed

subsys/bluetooth/host/buf.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@
1414

1515
#include <zephyr/bluetooth/hci.h>
1616

17-
#if defined(CONFIG_BT_CONN)
18-
#if defined(CONFIG_BT_ISO)
19-
#define MAX_EVENT_COUNT CONFIG_BT_MAX_CONN + CONFIG_BT_ISO_MAX_CHAN
20-
#else
21-
#define MAX_EVENT_COUNT CONFIG_BT_MAX_CONN
22-
#endif /* CONFIG_BT_ISO */
23-
#elif defined(CONFIG_BT_ISO)
24-
#define MAX_EVENT_COUNT CONFIG_BT_ISO_MAX_CHAN
25-
#endif /* CONFIG_BT_CONN */
26-
27-
#if defined(CONFIG_BT_CONN) || defined(CONFIG_BT_ISO)
28-
#define NUM_COMLETE_EVENT_SIZE BT_BUF_EVT_SIZE( \
29-
sizeof(struct bt_hci_cp_host_num_completed_packets) + \
30-
MAX_EVENT_COUNT * sizeof(struct bt_hci_handle_count))
17+
/* Events have a length field of 1 byte. This size fits all events.
18+
*
19+
* It's true that we don't put all kinds of events there (yet). However, the
20+
* command complete event has an arbitrary payload, depending on opcode.
21+
*/
22+
#define SYNC_EVT_SIZE (BT_BUF_RESERVE + BT_HCI_EVT_HDR_SIZE + 255)
3123

3224
/* Pool for RX HCI buffers that are always freed by `bt_recv`
3325
* before it returns.
@@ -37,9 +29,7 @@
3729
* the HCI transport to fill buffers in parallel with `bt_recv`
3830
* consuming them.
3931
*/
40-
#define SYNC_EVT_SIZE NUM_COMLETE_EVENT_SIZE
4132
NET_BUF_POOL_FIXED_DEFINE(sync_evt_pool, 1, SYNC_EVT_SIZE, sizeof(struct bt_buf_data), NULL);
42-
#endif /* CONFIG_BT_CONN || CONFIG_BT_ISO */
4333

4434
NET_BUF_POOL_FIXED_DEFINE(discardable_pool, CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT,
4535
BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE),
@@ -96,9 +86,11 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable,
9686
switch (evt) {
9787
#if defined(CONFIG_BT_CONN) || defined(CONFIG_BT_ISO)
9888
case BT_HCI_EVT_NUM_COMPLETED_PACKETS:
89+
#endif /* CONFIG_BT_CONN || CONFIG_BT_ISO */
90+
case BT_HCI_EVT_CMD_STATUS:
91+
case BT_HCI_EVT_CMD_COMPLETE:
9992
buf = net_buf_alloc(&sync_evt_pool, timeout);
10093
break;
101-
#endif /* CONFIG_BT_CONN || CONFIG_BT_ISO */
10294
default:
10395
if (discardable) {
10496
buf = net_buf_alloc(&discardable_pool, timeout);

0 commit comments

Comments
 (0)