From 1e06076c3c76e37ae12e5a8a956cd9453b5244ba Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Mon, 1 Aug 2022 20:37:49 +0800 Subject: [PATCH] component/bt: make OSI thread workqueue length configurable through API reduce the length of workqueue1 for BTC and HCI task # Conflicts: # components/bt/common/osi/thread.c --- components/bt/common/btc/core/btc_task.c | 7 ++++++- components/bt/common/osi/include/osi/thread.h | 2 +- components/bt/common/osi/thread.c | 7 ++++--- components/bt/host/bluedroid/hci/hci_layer.c | 7 ++++++- components/bt/host/bluedroid/stack/btu/btu_init.c | 6 +++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/components/bt/common/btc/core/btc_task.c b/components/bt/common/btc/core/btc_task.c index 9cc311c52c..e6693edfa3 100644 --- a/components/bt/common/btc/core/btc_task.c +++ b/components/bt/common/btc/core/btc_task.c @@ -77,6 +77,9 @@ #define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig #define BTC_TASK_NAME "BTC_TASK" #define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6) +#define BTC_TASK_WORKQUEUE_NUM (2) +#define BTC_TASK_WORKQUEUE0_LEN (0) +#define BTC_TASK_WORKQUEUE1_LEN (5) osi_thread_t *btc_thread; @@ -410,7 +413,9 @@ error_exit:; bt_status_t btc_init(void) { - btc_thread = osi_thread_create(BTC_TASK_NAME, BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 2); + const size_t workqueue_len[] = {BTC_TASK_WORKQUEUE0_LEN, BTC_TASK_WORKQUEUE1_LEN}; + btc_thread = osi_thread_create(BTC_TASK_NAME, BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, + BTC_TASK_WORKQUEUE_NUM, workqueue_len); if (btc_thread == NULL) { return BT_STATUS_NOMEM; } diff --git a/components/bt/common/osi/include/osi/thread.h b/components/bt/common/osi/include/osi/thread.h index fdabed1cf6..d5f150f32a 100644 --- a/components/bt/common/osi/include/osi/thread.h +++ b/components/bt/common/osi/include/osi/thread.h @@ -48,7 +48,7 @@ typedef enum { * param work_queue_num: speicify queue number, the queue[0] has highest priority, and the priority is decrease by index * return : if create successfully, return thread handler; otherwise return NULL. */ -osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num); +osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num, const size_t work_queue_len[]); /* * brief: Destroy a thread or task diff --git a/components/bt/common/osi/thread.c b/components/bt/common/osi/thread.c index fa35e87b86..5e0317219c 100644 --- a/components/bt/common/osi/thread.c +++ b/components/bt/common/osi/thread.c @@ -194,14 +194,14 @@ static void osi_thread_stop(osi_thread_t *thread) } //in linux, the stack_size, priority and core may not be set here, the code will be ignore the arguments -osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num) +osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priority, osi_thread_core_t core, uint8_t work_queue_num, const size_t work_queue_len[]) { int ret; struct osi_thread_start_arg start_arg = {0}; if (stack_size <= 0 || core < OSI_THREAD_CORE_0 || core > OSI_THREAD_CORE_AFFINITY || - work_queue_num <= 0) { + work_queue_num <= 0 || work_queue_len == NULL) { return NULL; } @@ -218,7 +218,8 @@ osi_thread_t *osi_thread_create(const char *name, size_t stack_size, int priorit } for (int i = 0; i < thread->work_queue_num; i++) { - thread->work_queues[i] = osi_work_queue_create(DEFAULT_WORK_QUEUE_CAPACITY); + size_t queue_len = work_queue_len[i] ? work_queue_len[i] : DEFAULT_WORK_QUEUE_CAPACITY; + thread->work_queues[i] = osi_work_queue_create(queue_len); if (thread->work_queues[i] == NULL) { goto _err; } diff --git a/components/bt/host/bluedroid/hci/hci_layer.c b/components/bt/host/bluedroid/hci/hci_layer.c index 054cabb628..bd1ade792b 100644 --- a/components/bt/host/bluedroid/hci/hci_layer.c +++ b/components/bt/host/bluedroid/hci/hci_layer.c @@ -40,6 +40,9 @@ #define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE) #define HCI_HOST_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 3) #define HCI_HOST_TASK_NAME "hciT" +#define HCI_HOST_TASK_WORKQUEUE_NUM (2) +#define HCI_HOST_TASK_WORKQUEUE0_LEN (0) +#define HCI_HOST_TASK_WORKQUEUE1_LEN (5) typedef struct { uint16_t opcode; @@ -107,7 +110,9 @@ int hci_start_up(void) goto error; } - hci_host_thread = osi_thread_create(HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, HCI_HOST_TASK_PRIO, HCI_HOST_TASK_PINNED_TO_CORE, 2); + const size_t workqueue_len[] = {HCI_HOST_TASK_WORKQUEUE0_LEN, HCI_HOST_TASK_WORKQUEUE1_LEN}; + hci_host_thread = osi_thread_create(HCI_HOST_TASK_NAME, HCI_HOST_TASK_STACK_SIZE, HCI_HOST_TASK_PRIO, HCI_HOST_TASK_PINNED_TO_CORE, + HCI_HOST_TASK_WORKQUEUE_NUM, workqueue_len); if (hci_host_thread == NULL) { return -2; } diff --git a/components/bt/host/bluedroid/stack/btu/btu_init.c b/components/bt/host/bluedroid/stack/btu/btu_init.c index 15b7fdbbc0..7699a471f0 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_init.c +++ b/components/bt/host/bluedroid/stack/btu/btu_init.c @@ -48,6 +48,8 @@ #define BTU_TASK_STACK_SIZE (BT_BTU_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) #define BTU_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 5) #define BTU_TASK_NAME "BTU_TASK" +#define BTU_TASK_WORKQUEUE_NUM (2) +#define BTU_TASK_WORKQUEUE0_LEN (0) hash_map_t *btu_general_alarm_hash_map; osi_mutex_t btu_general_alarm_lock; @@ -181,7 +183,9 @@ void BTU_StartUp(void) osi_mutex_new(&btu_l2cap_alarm_lock); - btu_thread = osi_thread_create(BTU_TASK_NAME, BTU_TASK_STACK_SIZE, BTU_TASK_PRIO, BTU_TASK_PINNED_TO_CORE, 1); + const size_t workqueue_len[] = {BTU_TASK_WORKQUEUE0_LEN}; + btu_thread = osi_thread_create(BTU_TASK_NAME, BTU_TASK_STACK_SIZE, BTU_TASK_PRIO, BTU_TASK_PINNED_TO_CORE, + BTU_TASK_WORKQUEUE_NUM, workqueue_len); if (btu_thread == NULL) { goto error_exit; }