Skip to content

Commit 0d9dab3

Browse files
Johan Hedbergjhedberg
authored andcommitted
Bluetooth: Introduce separate pool for discardable events
Introduce a separate buffer pool for events which the HCI driver considers discardable. Examples of such events could be e.g. Advertising Reports. The benefit of having such a pool means that the if there is a heavy inflow of such events it will not cause the allocation for other critical events to block and may even eliminate deadlocks in some cases. Also update all mesh samples not to specify explicit RX buffer counts anymore. Instead, create appropriate defaults in Kconfig so that we only need to override this in the app for cases like the bbc:microbit with limited memory. Signed-off-by: Johan Hedberg <[email protected]>
1 parent fc2fcd1 commit 0d9dab3

File tree

29 files changed

+57
-31
lines changed

29 files changed

+57
-31
lines changed

drivers/bluetooth/hci/h4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static struct net_buf *get_rx(int timeout)
162162
BT_DBG("type 0x%02x, evt 0x%02x", rx.type, rx.evt.evt);
163163

164164
if (rx.type == H4_EVT) {
165-
return bt_buf_get_evt(rx.evt.evt, timeout);
165+
return bt_buf_get_evt(rx.evt.evt, rx.discardable, timeout);
166166
}
167167

168168
return bt_buf_get_rx(BT_BUF_ACL_IN, timeout);

drivers/bluetooth/hci/h5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static inline struct net_buf *get_evt_buf(u8_t evt)
408408
{
409409
struct net_buf *buf;
410410

411-
buf = bt_buf_get_evt(evt, K_NO_WAIT);
411+
buf = bt_buf_get_evt(evt, false, K_NO_WAIT);
412412
if (buf) {
413413
net_buf_add_u8(h5.rx_buf, evt);
414414
}

drivers/bluetooth/hci/ipm_stm32wb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ void TM_EvtReceivedCb(TL_EvtPacket_t *hcievt)
115115
hcievt->evtserial.evt.evtcode);
116116
goto out;
117117
default:
118-
buf = bt_buf_get_evt(evtserial.evt.evtcode, K_FOREVER);
118+
buf = bt_buf_get_evt(evtserial.evt.evtcode, false,
119+
K_FOREVER);
119120
break;
120121
}
121122
net_buf_add_mem(buf, &hcievt->evtserial.evt,

drivers/bluetooth/hci/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void bt_spi_rx_thread(void)
355355
continue;
356356
default:
357357
buf = bt_buf_get_evt(rxmsg[EVT_HEADER_EVENT],
358-
K_FOREVER);
358+
false, K_FOREVER);
359359
break;
360360
}
361361

drivers/bluetooth/hci/userchan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int bt_dev_index = -1;
5858
static struct net_buf *get_rx(const u8_t *buf)
5959
{
6060
if (buf[0] == H4_EVT) {
61-
return bt_buf_get_evt(buf[1], K_FOREVER);
61+
return bt_buf_get_evt(buf[1], false, K_FOREVER);
6262
}
6363

6464
return bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);

include/bluetooth/buf.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ struct net_buf *bt_buf_get_cmd_complete(s32_t timeout);
6969
* This will set the buffer type so bt_buf_set_type() does not need to
7070
* be explicitly called before bt_recv_prio() or bt_recv().
7171
*
72-
* @param evt HCI event code
73-
* @param timeout Timeout in milliseconds, or one of the special values
74-
* K_NO_WAIT and K_FOREVER.
72+
* @param evt HCI event code
73+
* @param discardable Whether the driver considers the event discardable.
74+
* @param timeout Timeout in milliseconds, or one of the special values
75+
* K_NO_WAIT and K_FOREVER.
7576
* @return A new buffer.
7677
*/
77-
struct net_buf *bt_buf_get_evt(u8_t evt, s32_t timeout);
78+
struct net_buf *bt_buf_get_evt(u8_t evt, bool discardable, s32_t timeout);
7879

7980
/** Set the buffer type
8081
*

include/bluetooth/hci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ struct bt_hci_cp_le_set_privacy_mode {
13621362

13631363
/* Event definitions */
13641364

1365+
#define BT_HCI_EVT_UNKNOWN 0x00
13651366
#define BT_HCI_EVT_VENDOR 0xff
13661367

13671368
#define BT_HCI_EVT_INQUIRY_COMPLETE 0x01

samples/bluetooth/mesh/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ CONFIG_BT_PERIPHERAL=y
2626

2727
CONFIG_BT=y
2828
CONFIG_BT_TINYCRYPT_ECC=y
29-
CONFIG_BT_RX_BUF_COUNT=30
3029
CONFIG_BT_L2CAP_RX_MTU=69
3130
CONFIG_BT_L2CAP_TX_MTU=69
3231
CONFIG_BT_L2CAP_TX_BUF_COUNT=5

samples/bluetooth/mesh/prj_bbc_microbit.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ CONFIG_SETTINGS_FCB=y
1717
CONFIG_BT=y
1818
CONFIG_BT_TINYCRYPT_ECC=y
1919
CONFIG_BT_RX_STACK_SIZE=1100
20+
CONFIG_BT_RX_BUF_COUNT=3
21+
CONFIG_BT_DISCARDABLE_BUF_COUNT=3
2022

2123
CONFIG_BT_CTLR_DUP_FILTER_LEN=0
2224
CONFIG_BT_OBSERVER=y

samples/bluetooth/mesh_demo/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ CONFIG_MAIN_STACK_SIZE=512
33
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
44

55
CONFIG_BT=y
6-
CONFIG_BT_RX_BUF_COUNT=30
76
CONFIG_BT_TINYCRYPT_ECC=y
87
#CONFIG_BT_DEBUG_LOG=y
98
CONFIG_BT_OBSERVER=y

0 commit comments

Comments
 (0)