Skip to content

Commit b22f807

Browse files
committed
Bluetooth: Host: Use a dedicated workqueue wherever possible
Avoid the system workqueue, and introduce a general purpose Bluetooth workqueue that can be used in most situations. Signed-off-by: Johan Hedberg <[email protected]>
1 parent fa77f64 commit b22f807

File tree

18 files changed

+116
-91
lines changed

18 files changed

+116
-91
lines changed

subsys/bluetooth/host/Kconfig

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ config BT_HCI_TX_PRIO
7575

7676
choice BT_RECV_CONTEXT
7777
prompt "BT RX Thread Selection"
78-
default BT_RECV_WORKQ_SYS if SOC_SERIES_NRF51X
7978
default BT_RECV_WORKQ_BT
8079
help
8180
Selects in which context incoming low priority HCI packets are processed.
@@ -85,7 +84,8 @@ choice BT_RECV_CONTEXT
8584
packets are processed.
8685

8786
config BT_RECV_WORKQ_SYS
88-
bool "Process low priority HCI packets in the system work queue"
87+
bool "Process low priority HCI packets in the system work queue [DEPRECATED]"
88+
select DEPRECATED
8989
help
9090
When this option is selected, the host will process incoming low priority HCI packets
9191
in the system work queue.
@@ -127,6 +127,20 @@ config BT_RX_PRIO
127127
int
128128
default 8
129129

130+
config BT_WQ
131+
bool
132+
default y if BT_RECV_WORKQ_BT
133+
134+
if BT_WQ
135+
config BT_WQ_STACK_SIZE
136+
int
137+
default BT_RX_STACK_SIZE
138+
139+
config BT_WQ_PRIO
140+
int
141+
default BT_RX_PRIO
142+
endif
143+
130144
config BT_DRIVER_RX_HIGH_PRIO
131145
# Hidden option for Co-Operative HCI driver RX thread priority
132146
int

subsys/bluetooth/host/adv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,8 @@ int bt_le_adv_start(const struct bt_le_adv_param *param,
13181318

13191319
if (ad_is_limited(ad, ad_len)) {
13201320
k_work_init_delayable(&adv->lim_adv_timeout_work, adv_timeout);
1321-
k_work_reschedule(&adv->lim_adv_timeout_work,
1322-
K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT));
1321+
bt_work_reschedule(&adv->lim_adv_timeout_work,
1322+
K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT));
13231323
}
13241324

13251325
return err;

subsys/bluetooth/host/att.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ static void chan_rebegin_att_timeout(struct bt_att_tx_meta_data *user_data)
625625
* in-flight.
626626
*/
627627
if (chan->req) {
628-
k_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT);
628+
bt_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT);
629629
}
630630
}
631631

@@ -3544,8 +3544,8 @@ static int att_schedule_eatt_connect(struct bt_conn *conn, uint8_t chans_to_conn
35443544

35453545
att->eatt.chans_to_connect = chans_to_connect;
35463546

3547-
return k_work_reschedule(&att->eatt.connection_work,
3548-
credit_based_connection_delay(conn));
3547+
return bt_work_reschedule(&att->eatt.connection_work,
3548+
credit_based_connection_delay(conn));
35493549
}
35503550

35513551
static void handle_potential_collision(struct bt_att *att)

subsys/bluetooth/host/classic/avctp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void avctp_tx_raise(int msec)
6363
return;
6464
}
6565
LOG_DBG("kick TX");
66-
k_work_schedule(&avctp_tx_work, K_MSEC(msec));
66+
bt_work_schedule(&avctp_tx_work, K_MSEC(msec));
6767
}
6868

6969
static void bt_avctp_clear_tx(struct bt_avctp *session)

subsys/bluetooth/host/classic/avdtp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void avdtp_tx_raise(void)
288288
{
289289
if (!sys_slist_is_empty(&avdtp_tx_list)) {
290290
LOG_DBG("kick TX");
291-
k_work_submit(&avdtp_tx_work);
291+
bt_work_submit(&avdtp_tx_work);
292292
}
293293
}
294294

@@ -1390,7 +1390,7 @@ static int avdtp_send_cmd(struct bt_avdtp *session, struct net_buf *buf, struct
13901390
/* Initialize and start timeout timer */
13911391
k_work_init_delayable(&session->timeout_work, avdtp_timeout);
13921392
/* Start timeout work */
1393-
k_work_reschedule(&session->timeout_work, AVDTP_TIMEOUT);
1393+
bt_work_reschedule(&session->timeout_work, AVDTP_TIMEOUT);
13941394

13951395
return 0;
13961396
}

subsys/bluetooth/host/classic/br.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,8 @@ int bt_br_set_discoverable(bool enable, bool limited)
12591259
err = write_scan_enable(BT_BREDR_SCAN_INQUIRY | BT_BREDR_SCAN_PAGE);
12601260
if (!err && (limited == true)) {
12611261
atomic_set_bit(bt_dev.flags, BT_DEV_LIMITED_DISCOVERABLE_MODE);
1262-
k_work_reschedule(&bt_br_limited_discoverable_timeout,
1263-
K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION));
1262+
bt_work_reschedule(&bt_br_limited_discoverable_timeout,
1263+
K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION));
12641264
}
12651265
return err;
12661266
}

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static int hfp_ag_send_data(struct bt_hfp_ag *ag, bt_hfp_ag_tx_cb_t cb, void *us
429429
hfp_ag_unlock(ag);
430430

431431
/* Always active tx work */
432-
k_work_reschedule(&ag->tx_work, K_NO_WAIT);
432+
bt_work_reschedule(&ag->tx_work, K_NO_WAIT);
433433

434434
return 0;
435435

@@ -724,20 +724,20 @@ static void bt_hfp_ag_set_call_state(struct bt_hfp_ag_call *call, bt_hfp_call_st
724724
free_call(call);
725725
break;
726726
case BT_HFP_CALL_OUTGOING:
727-
k_work_reschedule(&call->deferred_work,
727+
bt_work_reschedule(&call->deferred_work,
728728
K_SECONDS(CONFIG_BT_HFP_AG_OUTGOING_TIMEOUT));
729729
break;
730730
case BT_HFP_CALL_INCOMING:
731-
k_work_reschedule(&call->deferred_work,
731+
bt_work_reschedule(&call->deferred_work,
732732
K_SECONDS(CONFIG_BT_HFP_AG_INCOMING_TIMEOUT));
733733
break;
734734
case BT_HFP_CALL_ALERTING:
735735
if (!atomic_test_bit(call->flags, BT_HFP_AG_CALL_INCOMING_3WAY)) {
736-
k_work_reschedule(&call->ringing_work, K_NO_WAIT);
736+
bt_work_reschedule(&call->ringing_work, K_NO_WAIT);
737737
} else {
738738
k_work_cancel_delayable(&call->ringing_work);
739739
}
740-
k_work_reschedule(&call->deferred_work,
740+
bt_work_reschedule(&call->deferred_work,
741741
K_SECONDS(CONFIG_BT_HFP_AG_ALERTING_TIMEOUT));
742742
break;
743743
case BT_HFP_CALL_ACTIVE:
@@ -872,7 +872,7 @@ static void bt_ag_tx_work(struct k_work *work)
872872
LOG_WRN("tx ongoing flag is not set");
873873
}
874874
/* Due to the work is failed, restart the tx work */
875-
k_work_reschedule(&ag->tx_work, K_NO_WAIT);
875+
bt_work_reschedule(&ag->tx_work, K_NO_WAIT);
876876
}
877877
}
878878

@@ -1162,7 +1162,7 @@ static int bt_hfp_ag_cind_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
11621162
} else {
11631163
err = -EINPROGRESS;
11641164
atomic_set_bit(ag->flags, BT_HGP_AG_ONGOING_CALLS);
1165-
k_work_reschedule(&ag->ongoing_call_work,
1165+
bt_work_reschedule(&ag->ongoing_call_work,
11661166
K_MSEC(CONFIG_BT_HFP_AG_GET_ONGOING_CALL_TIMEOUT));
11671167
}
11681168
}
@@ -3595,7 +3595,7 @@ static void hfp_ag_sent(struct bt_rfcomm_dlc *dlc, int err)
35953595
LOG_DBG("Completed pending tx %p", tx);
35963596

35973597
/* Restart the tx work */
3598-
k_work_reschedule(&ag->tx_work, K_NO_WAIT);
3598+
bt_work_reschedule(&ag->tx_work, K_NO_WAIT);
35993599

36003600
tx->err = err;
36013601
k_fifo_put(&ag_tx_notify, tx);
@@ -3739,7 +3739,7 @@ static void bt_ag_ringing_work_cb(struct bt_hfp_ag *ag, void *user_data)
37393739
return;
37403740
}
37413741

3742-
k_work_reschedule(&call->ringing_work,
3742+
bt_work_reschedule(&call->ringing_work,
37433743
K_SECONDS(CONFIG_BT_HFP_AG_RING_NOTIFY_INTERVAL));
37443744

37453745
err = hfp_ag_send_data(ag, NULL, NULL, "\r\nRING\r\n");

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,29 +445,29 @@ static void l2cap_br_start_timer(struct bt_l2cap_br_chan *br_chan, enum l2cap_br
445445
if (type == BT_L2CAP_BR_TIMER_RET) {
446446
if (!atomic_test_and_set_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
447447
k_work_cancel_delayable(&br_chan->monitor_work);
448-
k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
448+
bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
449449
LOG_DBG("Start ret timer");
450450
} else {
451451
if (!restart) {
452452
return;
453453
}
454454

455-
k_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
455+
bt_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
456456
LOG_DBG("Restart ret timer");
457457
}
458458
} else {
459459
if (atomic_test_and_clear_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
460460
k_work_cancel_delayable(&br_chan->ret_work);
461-
k_work_schedule(&br_chan->monitor_work,
462-
K_MSEC(br_chan->tx.monitor_timeout));
461+
bt_work_schedule(&br_chan->monitor_work,
462+
K_MSEC(br_chan->tx.monitor_timeout));
463463
LOG_DBG("Start monitor timer");
464464
} else {
465465
if (!restart) {
466466
return;
467467
}
468468

469-
k_work_reschedule(&br_chan->monitor_work,
470-
K_MSEC(br_chan->tx.monitor_timeout));
469+
bt_work_reschedule(&br_chan->monitor_work,
470+
K_MSEC(br_chan->tx.monitor_timeout));
471471
LOG_DBG("Restart monitor timer");
472472
}
473473
}
@@ -743,7 +743,7 @@ static void l2cap_br_ret_timeout(struct k_work *work)
743743

744744
/* Restart the timer */
745745
if (atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
746-
k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
746+
bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
747747
}
748748

749749
LOG_DBG("chan %p retransmission timeout", br_chan);
@@ -812,7 +812,7 @@ static void l2cap_br_monitor_timeout(struct k_work *work)
812812

813813
/* Restart the timer */
814814
if (!atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
815-
k_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout));
815+
bt_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout));
816816
}
817817

818818
LOG_DBG("chan %p monitor timeout", br_chan);
@@ -974,7 +974,7 @@ static void l2cap_br_chan_send_req(struct bt_l2cap_br_chan *chan,
974974
* final expiration, when the response is received, or the physical
975975
* link is lost.
976976
*/
977-
k_work_reschedule(&chan->rtx_work, timeout);
977+
bt_work_reschedule(&chan->rtx_work, timeout);
978978
}
979979

980980
#if defined(CONFIG_BT_L2CAP_RET_FC)
@@ -4913,7 +4913,7 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident, struct n
49134913
break;
49144914
case BT_L2CAP_BR_PENDING:
49154915
br_chan->ident = ident;
4916-
k_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT);
4916+
bt_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT);
49174917
break;
49184918
default:
49194919
l2cap_br_chan_cleanup(chan);

subsys/bluetooth/host/classic/rfcomm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void rfcomm_dlc_tx_trigger(struct bt_rfcomm_dlc *dlc)
242242

243243
LOG_DBG("DLC %p TX trigger", dlc);
244244

245-
err = k_work_submit(&dlc->tx_work);
245+
err = bt_work_submit(&dlc->tx_work);
246246
if (err < 0) {
247247
LOG_ERR("Failed to submit tx work: %d", err);
248248
}
@@ -408,7 +408,7 @@ static void rfcomm_session_disconnect(struct bt_rfcomm_session *session)
408408

409409
session->state = BT_RFCOMM_STATE_DISCONNECTING;
410410
rfcomm_send_disc(session, 0);
411-
k_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT);
411+
bt_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT);
412412
}
413413

414414
static struct net_buf *rfcomm_make_uih_msg(struct bt_rfcomm_session *session,
@@ -498,7 +498,7 @@ static void rfcomm_dlc_init(struct bt_rfcomm_dlc *dlc,
498498
k_work_init_delayable(&dlc->rtx_work, rfcomm_dlc_rtx_timeout);
499499

500500
/* Start a conn timer which includes auth as well */
501-
k_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT);
501+
bt_work_schedule(&dlc->rtx_work, RFCOMM_CONN_TIMEOUT);
502502

503503
dlc->_next = session->dlcs;
504504
session->dlcs = dlc;
@@ -686,7 +686,7 @@ static void rfcomm_dlc_tx_worker(struct k_work *work)
686686

687687
if (dlc->state == BT_RFCOMM_STATE_DISCONNECTING) {
688688
rfcomm_send_disc(dlc->session, dlc->dlci);
689-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
689+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
690690
} else {
691691
rfcomm_dlc_destroy(dlc);
692692
}
@@ -955,7 +955,7 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc)
955955
case BT_RFCOMM_STATE_CONFIG:
956956
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
957957
rfcomm_send_disc(dlc->session, dlc->dlci);
958-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
958+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
959959
break;
960960
case BT_RFCOMM_STATE_CONNECTED:
961961
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
@@ -1375,8 +1375,8 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, uint8_t dlci)
13751375

13761376
if (!session->dlcs) {
13771377
/* Start a session idle timer */
1378-
k_work_reschedule(&dlc->session->rtx_work,
1379-
RFCOMM_IDLE_TIMEOUT);
1378+
bt_work_reschedule(&dlc->session->rtx_work,
1379+
RFCOMM_IDLE_TIMEOUT);
13801380
}
13811381
} else {
13821382
/* Cancel idle timer */
@@ -1834,7 +1834,7 @@ int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc)
18341834
*/
18351835
dlc->state = BT_RFCOMM_STATE_USER_DISCONNECT;
18361836
rfcomm_dlc_tx_trigger(dlc);
1837-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
1837+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
18381838

18391839
return 0;
18401840
}

subsys/bluetooth/host/conn.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,7 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state)
12191219
}
12201220
#endif /* CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS */
12211221

1222-
k_work_schedule(&conn->deferred_work,
1223-
CONN_UPDATE_TIMEOUT);
1222+
k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT);
12241223
}
12251224
#endif /* CONFIG_BT_CONN */
12261225

@@ -1832,7 +1831,7 @@ static K_WORK_DEFINE(procedures_on_connect, auto_initiated_procedures);
18321831
static void schedule_auto_initiated_procedures(struct bt_conn *conn)
18331832
{
18341833
LOG_DBG("[%p] Scheduling auto-init procedures", conn);
1835-
k_work_submit(&procedures_on_connect);
1834+
bt_work_submit(&procedures_on_connect);
18361835
}
18371836

18381837
void bt_conn_connected(struct bt_conn *conn)

0 commit comments

Comments
 (0)