Skip to content

Commit dc42873

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 ff90ce6 commit dc42873

File tree

15 files changed

+103
-78
lines changed

15 files changed

+103
-78
lines changed

subsys/bluetooth/host/Kconfig

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

7777
choice BT_RECV_CONTEXT
7878
prompt "BT RX Thread Selection"
79-
default BT_RECV_WORKQ_SYS if SOC_SERIES_NRF51X
8079
default BT_RECV_WORKQ_BT
8180
help
8281
Selects in which context incoming low priority HCI packets are processed.
@@ -86,7 +85,8 @@ choice BT_RECV_CONTEXT
8685
packets are processed.
8786

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

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

subsys/bluetooth/host/adv.c

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

14321432
if (ad_is_limited(ad, ad_len)) {
14331433
k_work_init_delayable(&adv->lim_adv_timeout_work, adv_timeout);
1434-
k_work_reschedule(&adv->lim_adv_timeout_work,
1435-
K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT));
1434+
bt_work_reschedule(&adv->lim_adv_timeout_work,
1435+
K_SECONDS(CONFIG_BT_LIM_ADV_TIMEOUT));
14361436
}
14371437

14381438
return err;

subsys/bluetooth/host/att.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static void chan_rebegin_att_timeout(struct bt_att_tx_meta_data *user_data)
630630
* in-flight.
631631
*/
632632
if (chan->req) {
633-
k_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT);
633+
bt_work_reschedule(&chan->timeout_work, BT_ATT_TIMEOUT);
634634
}
635635
}
636636

@@ -3579,8 +3579,8 @@ static int att_schedule_eatt_connect(struct bt_conn *conn, uint8_t chans_to_conn
35793579

35803580
att->eatt.chans_to_connect = chans_to_connect;
35813581

3582-
return k_work_reschedule(&att->eatt.connection_work,
3583-
credit_based_connection_delay(conn));
3582+
return bt_work_reschedule(&att->eatt.connection_work,
3583+
credit_based_connection_delay(conn));
35843584
}
35853585

35863586
static void handle_potential_collision(struct bt_att *att)

subsys/bluetooth/host/classic/br.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,8 @@ int bt_br_set_discoverable(bool enable, bool limited)
12181218
err = write_scan_enable(BT_BREDR_SCAN_INQUIRY | BT_BREDR_SCAN_PAGE);
12191219
if (!err && (limited == true)) {
12201220
atomic_set_bit(bt_dev.flags, BT_DEV_LIMITED_DISCOVERABLE_MODE);
1221-
k_work_reschedule(&bt_br_limited_discoverable_timeout,
1222-
K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION));
1221+
bt_work_reschedule(&bt_br_limited_discoverable_timeout,
1222+
K_SECONDS(CONFIG_BT_LIMITED_DISCOVERABLE_DURATION));
12231223
}
12241224
return err;
12251225
}

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,29 +438,29 @@ static void l2cap_br_start_timer(struct bt_l2cap_br_chan *br_chan, enum l2cap_br
438438
if (type == BT_L2CAP_BR_TIMER_RET) {
439439
if (!atomic_test_and_set_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
440440
k_work_cancel_delayable(&br_chan->monitor_work);
441-
k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
441+
bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
442442
LOG_DBG("Start ret timer");
443443
} else {
444444
if (!restart) {
445445
return;
446446
}
447447

448-
k_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
448+
bt_work_reschedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
449449
LOG_DBG("Restart ret timer");
450450
}
451451
} else {
452452
if (atomic_test_and_clear_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
453453
k_work_cancel_delayable(&br_chan->ret_work);
454-
k_work_schedule(&br_chan->monitor_work,
455-
K_MSEC(br_chan->tx.monitor_timeout));
454+
bt_work_schedule(&br_chan->monitor_work,
455+
K_MSEC(br_chan->tx.monitor_timeout));
456456
LOG_DBG("Start monitor timer");
457457
} else {
458458
if (!restart) {
459459
return;
460460
}
461461

462-
k_work_reschedule(&br_chan->monitor_work,
463-
K_MSEC(br_chan->tx.monitor_timeout));
462+
bt_work_reschedule(&br_chan->monitor_work,
463+
K_MSEC(br_chan->tx.monitor_timeout));
464464
LOG_DBG("Restart monitor timer");
465465
}
466466
}
@@ -736,7 +736,7 @@ static void l2cap_br_ret_timeout(struct k_work *work)
736736

737737
/* Restart the timer */
738738
if (atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
739-
k_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
739+
bt_work_schedule(&br_chan->ret_work, K_MSEC(br_chan->tx.ret_timeout));
740740
}
741741

742742
LOG_DBG("chan %p retransmission timeout", br_chan);
@@ -805,7 +805,7 @@ static void l2cap_br_monitor_timeout(struct k_work *work)
805805

806806
/* Restart the timer */
807807
if (!atomic_test_bit(br_chan->flags, L2CAP_FLAG_RET_TIMER)) {
808-
k_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout));
808+
bt_work_schedule(&br_chan->monitor_work, K_MSEC(br_chan->tx.monitor_timeout));
809809
}
810810

811811
LOG_DBG("chan %p monitor timeout", br_chan);
@@ -962,7 +962,7 @@ static void l2cap_br_chan_send_req(struct bt_l2cap_br_chan *chan,
962962
* final expiration, when the response is received, or the physical
963963
* link is lost.
964964
*/
965-
k_work_reschedule(&chan->rtx_work, timeout);
965+
bt_work_reschedule(&chan->rtx_work, timeout);
966966
}
967967

968968
#if defined(CONFIG_BT_L2CAP_RET_FC)
@@ -4805,7 +4805,7 @@ static void l2cap_br_conn_rsp(struct bt_l2cap_br *l2cap, uint8_t ident, struct n
48054805
break;
48064806
case BT_L2CAP_BR_PENDING:
48074807
br_chan->ident = ident;
4808-
k_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT);
4808+
bt_work_reschedule(&br_chan->rtx_work, L2CAP_BR_CONN_TIMEOUT);
48094809
break;
48104810
default:
48114811
l2cap_br_chan_cleanup(chan);

subsys/bluetooth/host/classic/rfcomm.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static void rfcomm_session_disconnect(struct bt_rfcomm_session *session)
394394

395395
session->state = BT_RFCOMM_STATE_DISCONNECTING;
396396
rfcomm_send_disc(session, 0);
397-
k_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT);
397+
bt_work_reschedule(&session->rtx_work, RFCOMM_DISC_TIMEOUT);
398398
}
399399

400400
static struct net_buf *rfcomm_make_uih_msg(struct bt_rfcomm_session *session,
@@ -475,7 +475,7 @@ static void rfcomm_dlc_init(struct bt_rfcomm_dlc *dlc,
475475
k_work_init_delayable(&dlc->rtx_work, rfcomm_dlc_rtx_timeout);
476476

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

480480
dlc->_next = session->dlcs;
481481
session->dlcs = dlc;
@@ -644,7 +644,7 @@ static void rfcomm_dlc_tx_thread(void *p1, void *p2, void *p3)
644644

645645
if (dlc->state == BT_RFCOMM_STATE_DISCONNECTING) {
646646
rfcomm_send_disc(dlc->session, dlc->dlci);
647-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
647+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
648648
} else {
649649
rfcomm_dlc_destroy(dlc);
650650
}
@@ -917,7 +917,7 @@ static int rfcomm_dlc_close(struct bt_rfcomm_dlc *dlc)
917917
case BT_RFCOMM_STATE_CONFIG:
918918
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
919919
rfcomm_send_disc(dlc->session, dlc->dlci);
920-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
920+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
921921
break;
922922
case BT_RFCOMM_STATE_CONNECTED:
923923
dlc->state = BT_RFCOMM_STATE_DISCONNECTING;
@@ -1346,8 +1346,8 @@ static void rfcomm_handle_disc(struct bt_rfcomm_session *session, uint8_t dlci)
13461346

13471347
if (!session->dlcs) {
13481348
/* Start a session idle timer */
1349-
k_work_reschedule(&dlc->session->rtx_work,
1350-
RFCOMM_IDLE_TIMEOUT);
1349+
bt_work_reschedule(&dlc->session->rtx_work,
1350+
RFCOMM_IDLE_TIMEOUT);
13511351
}
13521352
} else {
13531353
/* Cancel idle timer */
@@ -1805,7 +1805,7 @@ int bt_rfcomm_dlc_disconnect(struct bt_rfcomm_dlc *dlc)
18051805
k_fifo_put(&dlc->tx_queue,
18061806
net_buf_alloc(&dummy_pool, K_NO_WAIT));
18071807

1808-
k_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
1808+
bt_work_reschedule(&dlc->rtx_work, RFCOMM_DISC_TIMEOUT);
18091809

18101810
return 0;
18111811
}

subsys/bluetooth/host/conn.c

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

1211-
k_work_schedule(&conn->deferred_work,
1212-
CONN_UPDATE_TIMEOUT);
1211+
k_work_schedule(&conn->deferred_work, CONN_UPDATE_TIMEOUT);
12131212
}
12141213
#endif /* CONFIG_BT_CONN */
12151214

@@ -1801,7 +1800,7 @@ static K_WORK_DEFINE(procedures_on_connect, auto_initiated_procedures);
18011800
static void schedule_auto_initiated_procedures(struct bt_conn *conn)
18021801
{
18031802
LOG_DBG("[%p] Scheduling auto-init procedures", conn);
1804-
k_work_submit(&procedures_on_connect);
1803+
bt_work_submit(&procedures_on_connect);
18051804
}
18061805

18071806
void bt_conn_connected(struct bt_conn *conn)

subsys/bluetooth/host/gatt.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ static int gatt_register(struct bt_gatt_service *svc)
13061306
static inline void sc_work_submit(k_timeout_t timeout)
13071307
{
13081308
#if defined(CONFIG_BT_GATT_SERVICE_CHANGED)
1309-
k_work_reschedule(&gatt_sc.work, timeout);
1309+
bt_work_reschedule(&gatt_sc.work, timeout);
13101310
#endif
13111311
}
13121312

@@ -1468,8 +1468,8 @@ static void gatt_delayed_store_enqueue(uint8_t id, const bt_addr_le_t *peer_addr
14681468

14691469
atomic_set_bit(el->flags, flag);
14701470

1471-
k_work_reschedule(&gatt_delayed_store.work,
1472-
K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS));
1471+
bt_work_reschedule(&gatt_delayed_store.work,
1472+
K_MSEC(CONFIG_BT_SETTINGS_DELAYED_STORE_MS));
14731473
}
14741474
}
14751475

@@ -1539,7 +1539,7 @@ void bt_gatt_init(void)
15391539
if (IS_ENABLED(CONFIG_BT_LONG_WQ)) {
15401540
bt_long_wq_schedule(&db_hash.work, DB_HASH_TIMEOUT);
15411541
} else {
1542-
k_work_schedule(&db_hash.work, DB_HASH_TIMEOUT);
1542+
bt_work_schedule(&db_hash.work, DB_HASH_TIMEOUT);
15431543
}
15441544
#endif /* CONFIG_BT_GATT_CACHING */
15451545

@@ -1625,7 +1625,7 @@ static void db_changed(void)
16251625
if (IS_ENABLED(CONFIG_BT_LONG_WQ)) {
16261626
bt_long_wq_reschedule(&db_hash.work, DB_HASH_TIMEOUT);
16271627
} else {
1628-
k_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT);
1628+
bt_work_reschedule(&db_hash.work, DB_HASH_TIMEOUT);
16291629
}
16301630

16311631
for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) {
@@ -2496,8 +2496,8 @@ static int gatt_notify_mult(struct bt_conn *conn, uint16_t handle,
24962496
/* Use `k_work_schedule` to keep the original deadline, instead of
24972497
* re-setting the timeout whenever a new notification is appended.
24982498
*/
2499-
k_work_schedule(&nfy_mult_work,
2500-
K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS));
2499+
bt_work_schedule(&nfy_mult_work,
2500+
K_MSEC(CONFIG_BT_GATT_NOTIFY_MULTIPLE_FLUSH_MS));
25012501

25022502
return 0;
25032503
}

0 commit comments

Comments
 (0)