Skip to content

Commit c0d6fad

Browse files
jori-nordiccfriedt
authored andcommitted
Bluetooth: host: poll on CTLR buffers instead of host TX queue
When there are no buffers, it doesn't make sense to repeatedly try to send the host TX queue. Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no> (cherry picked from commit ef19c64)
1 parent 60ae4f9 commit c0d6fad

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int send_frag(struct bt_conn *conn, struct net_buf *buf, uint8_t flags,
480480
int err = 0;
481481

482482
/* Check if the controller can accept ACL packets */
483-
if (k_sem_take(bt_conn_get_pkts(conn), K_MSEC(100))) {
483+
if (k_sem_take(bt_conn_get_pkts(conn), K_NO_WAIT)) {
484484
/* not `goto fail`, we don't want to free the tx context: in the
485485
* case where it is the original buffer, it will contain the
486486
* callback ptr.
@@ -717,10 +717,26 @@ static int conn_prepare_events(struct bt_conn *conn,
717717

718718
BT_DBG("Adding conn %p to poll list", conn);
719719

720-
k_poll_event_init(&events[0],
721-
K_POLL_TYPE_FIFO_DATA_AVAILABLE,
722-
K_POLL_MODE_NOTIFY_ONLY,
723-
&conn->tx_queue);
720+
bool buffers_available = k_sem_count_get(bt_conn_get_pkts(conn)) > 0;
721+
bool packets_waiting = !k_fifo_is_empty(&conn->tx_queue);
722+
723+
if (packets_waiting && !buffers_available) {
724+
/* Only resume sending when the controller has buffer space
725+
* available for this connection.
726+
*/
727+
BT_DBG("wait on ctlr buffers");
728+
k_poll_event_init(&events[0],
729+
K_POLL_TYPE_SEM_AVAILABLE,
730+
K_POLL_MODE_NOTIFY_ONLY,
731+
bt_conn_get_pkts(conn));
732+
} else {
733+
/* Wait until there is more data to send. */
734+
BT_DBG("wait on host fifo");
735+
k_poll_event_init(&events[0],
736+
K_POLL_TYPE_FIFO_DATA_AVAILABLE,
737+
K_POLL_MODE_NOTIFY_ONLY,
738+
&conn->tx_queue);
739+
}
724740
events[0].tag = BT_EVENT_CONN_TX_QUEUE;
725741

726742
return 0;

subsys/bluetooth/host/hci_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,13 @@ static void process_events(struct k_poll_event *ev, int count)
23722372
switch (ev->state) {
23732373
case K_POLL_STATE_SIGNALED:
23742374
break;
2375+
case K_POLL_STATE_SEM_AVAILABLE:
2376+
/* After this fn is exec'd, `bt_conn_prepare_events()`
2377+
* will be called once again, and this time buffers will
2378+
* be available, so the FIFO will be added to the poll
2379+
* list instead of the ctlr buffers semaphore.
2380+
*/
2381+
break;
23752382
case K_POLL_STATE_FIFO_DATA_AVAILABLE:
23762383
if (ev->tag == BT_EVENT_CMD_TX) {
23772384
send_cmd();
@@ -2431,6 +2438,7 @@ static void hci_tx_thread(void *p1, void *p2, void *p3)
24312438
events[0].state = K_POLL_STATE_NOT_READY;
24322439
ev_count = 1;
24332440

2441+
/* This adds the FIFO per-connection */
24342442
if (IS_ENABLED(CONFIG_BT_CONN) || IS_ENABLED(CONFIG_BT_ISO)) {
24352443
ev_count += bt_conn_prepare_events(&events[1]);
24362444
}

tests/bluetooth/bsim_bt/bsim_test_l2cap_stress/src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern enum bst_result_t bst_result;
3636
}
3737

3838

39-
#define WAIT_SECONDS 120 /* seconds */
39+
#define WAIT_SECONDS 270 /* seconds */
4040
#define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/
4141

4242
#define FAIL(...) \

tests/bluetooth/bsim_bt/bsim_test_l2cap_stress/tests_scripts/l2cap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=4 -testid=per
3535
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=5 -testid=peripheral -rs=230
3636
Execute "${bsim_exe}" -v=${verbosity_level} -s=${simulation_id} -d=6 -testid=peripheral -rs=9
3737

38-
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=7 -sim_length=240e6 $@
38+
Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} -D=7 -sim_length=270e6 $@
3939

4040
for process_id in $process_ids; do
4141
wait $process_id || let "exit_code=$?"

0 commit comments

Comments
 (0)