Skip to content

Commit 5054fa6

Browse files
author
yeliao
committed
[int][opt][zbt] optimize some behaviors
Project: Bluetooth redmine: #10288, REDMINE-10288 ext-redmine: bug|feat#id [Description in detail] 1. Change tx from syswork queue to specified work queue to avoid sys work queue run in thread with priority 23. 2. Added more wait for 56x before host enabled Affected branch: [master] Change-Id: Ia0155c41cd5f2807aa346fe2bb313f60d30b85ca
1 parent 8dad815 commit 5054fa6

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

zephyr_bt/include/rtt4zephyr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct arch_esf
1919
#define device rt_device
2020

2121
bool device_is_ready(const struct device *dev);
22-
#define K_PRIO_COOP(x) (RT_THREAD_PRIORITY_HIGH+x)
22+
#define K_PRIO_COOP(x) (RT_THREAD_PRIORITY_HIGH+x-8)
2323

2424

2525
#ifndef POPCOUNT

zephyr_bt/include/zbt_rtt.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,13 +2528,32 @@
25282528
//BT_RX_PRIO
25292529
#ifdef BT_RX_PRIO
25302530
#define CONFIG_BT_RX_PRIO BT_RX_PRIO
2531+
2532+
#ifndef BT_TX_PRIO
2533+
#define BT_TX_PRIO BT_RX_PRIO
2534+
#endif
2535+
2536+
#ifdef BT_TX_PRIO
2537+
#define CONFIG_BT_TX_PRIO BT_TX_PRIO
2538+
#endif
2539+
25312540
#endif
25322541

25332542
//BT_RX_STACK_SIZE
25342543
#ifdef BT_RX_STACK_SIZE
25352544
#define CONFIG_BT_RX_STACK_SIZE BT_RX_STACK_SIZE
2545+
2546+
// reuse rx define
2547+
#ifndef BT_TX_STACK_SIZE
2548+
#define BT_TX_STACK_SIZE BT_RX_STACK_SIZE
2549+
#endif
2550+
2551+
#ifdef BT_TX_STACK_SIZE
2552+
#define CONFIG_BT_TX_STACK_SIZE BT_TX_STACK_SIZE
2553+
#endif
25362554
#endif
25372555

2556+
25382557
//BT_SCAN_AND_INITIATE_IN_PARALLEL
25392558
#ifdef BT_SCAN_AND_INITIATE_IN_PARALLEL
25402559
#define CONFIG_BT_SCAN_AND_INITIATE_IN_PARALLEL BT_SCAN_AND_INITIATE_IN_PARALLEL

zephyr_bt/sf_port/zbt_hci.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ static void rx_work_handler(struct k_work *work);
9898
static K_WORK_DEFINE(rx_work, rx_work_handler);
9999
#if defined(CONFIG_BT_RECV_WORKQ_BT)
100100
static struct k_work_q bt_workq;
101+
static struct k_work_q bt_txworkq;
101102
static K_KERNEL_STACK_DEFINE(rx_thread_stack, CONFIG_BT_RX_STACK_SIZE);
103+
static K_KERNEL_STACK_DEFINE(tx_thread_stack, CONFIG_BT_TX_STACK_SIZE);
102104
#endif /* CONFIG_BT_RECV_WORKQ_BT */
103105

104106
static void init_work(struct k_work *work);
@@ -4827,7 +4829,17 @@ int bt_enable(bt_ready_cb_t cb)
48274829
_rwip_init_handler = rwip_init_dummy_handler;
48284830
bluetooth_init();
48294831
ble_power_on();
4832+
4833+
#if defined(BSP_USING_DATA_SVC) && !defined(DATA_SVC_MBOX_THREAD_DISABLED)
4834+
extern rt_err_t sifli_sem_take_ex(int32_t timeout);
4835+
rt_err_t err = sifli_sem_take_ex(5000);
4836+
if (err != RT_EOK)
4837+
LOG_W("take sema failed %d", err);
4838+
else
4839+
rt_thread_mdelay(1000);
4840+
#else
48304841
rt_thread_delay(1000);
4842+
#endif
48314843

48324844
#if DT_HAS_CHOSEN(zephyr_bt_hci)
48334845
if (!device_is_ready(bt_dev.hci))
@@ -4888,10 +4900,16 @@ int bt_enable(bt_ready_cb_t cb)
48884900
#if defined(CONFIG_BT_RECV_WORKQ_BT)
48894901
/* RX thread */
48904902
k_work_queue_init(&bt_workq);
4903+
k_work_queue_init(&bt_txworkq);
4904+
48914905
k_work_queue_start(&bt_workq, (uint32_t *)rx_thread_stack,
48924906
CONFIG_BT_RX_STACK_SIZE,
48934907
K_PRIO_COOP(CONFIG_BT_RX_PRIO), NULL);
48944908
k_thread_name_set(bt_workq.work_thread, "BT RX WQ");
4909+
k_work_queue_start(&bt_txworkq, (uint32_t *)tx_thread_stack,
4910+
CONFIG_BT_TX_STACK_SIZE,
4911+
K_PRIO_COOP(CONFIG_BT_TX_PRIO), NULL);
4912+
k_thread_name_set(bt_txworkq.work_thread, "BT TX WQ");
48954913
#endif
48964914

48974915
#if DT_HAS_CHOSEN(zephyr_bt_hci)
@@ -5332,6 +5350,11 @@ static K_WORK_DEFINE(tx_work, tx_processor);
53325350
void bt_tx_irq_raise(void)
53335351
{
53345352
LOG_DBG("kick TX");
5353+
// Make tx_work and rx_work in the same thread and reuse the macro of CONFIG_BT_RECV_WORKQ_XXX
5354+
#if defined(CONFIG_BT_RECV_WORKQ_SYS)
53355355
k_work_submit(&tx_work);
5356+
#elif defined(CONFIG_BT_RECV_WORKQ_BT)
5357+
k_work_submit_to_queue(&bt_txworkq, &tx_work);
5358+
#endif /* CONFIG_BT_RECV_WORKQ_SYS */
53365359
}
53375360

0 commit comments

Comments
 (0)