mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
wireless/bluetooth: Add option to set the HCI TX thread affinity
By enabling the config `CONFIG_BLUETOOTH_TXCMD_PINNED_TO_CORE` and setting the value of `CONFIG_BLUETOOTH_TXCMD_CORE`, it's possible to pin the HCI TX thread to a specific core on a SMP-enabled setup. This is necessary for devices that require that the function that sends data (`bt_send`) to be called from a specific core.
This commit is contained in:
committed by
Xiang Xiao
parent
ef1ad691c3
commit
fe156a40e3
@@ -193,6 +193,25 @@ config BLUETOOTH_TXCONN_NMSGS
|
|||||||
int "Tx connection thread mqueue size"
|
int "Tx connection thread mqueue size"
|
||||||
default 16
|
default 16
|
||||||
|
|
||||||
|
config BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
bool "Pin Tx command thread to specific core"
|
||||||
|
depends on SMP
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
This option enables us to set the affinity of the Tx command thread
|
||||||
|
to make it run on a specific core.
|
||||||
|
|
||||||
|
if BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
|
||||||
|
config BLUETOOTH_TXCMD_CORE
|
||||||
|
int "Tx command thread CPU core"
|
||||||
|
default 1
|
||||||
|
range 1 SMP_NCPUS
|
||||||
|
---help---
|
||||||
|
Select the core to pin the Tx command thread.
|
||||||
|
|
||||||
|
endif # BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
|
||||||
endmenu # Kernel Thread Configuration
|
endmenu # Kernel Thread Configuration
|
||||||
|
|
||||||
config BLUETOOTH_SMP_SELFTEST
|
config BLUETOOTH_SMP_SELFTEST
|
||||||
|
|||||||
@@ -1499,6 +1499,10 @@ static void cmd_queue_deinit(void)
|
|||||||
static void cmd_queue_init(void)
|
static void cmd_queue_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
#ifdef CONFIG_BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
cpu_set_t cpuset;
|
||||||
|
#endif
|
||||||
|
int pid;
|
||||||
|
|
||||||
/* When there is a command to be sent to the Bluetooth driver, it queued on
|
/* When there is a command to be sent to the Bluetooth driver, it queued on
|
||||||
* the Tx queue and received by logic on the Tx kernel thread.
|
* the Tx queue and received by logic on the Tx kernel thread.
|
||||||
@@ -1512,10 +1516,29 @@ static void cmd_queue_init(void)
|
|||||||
|
|
||||||
g_btdev.ncmd = 1;
|
g_btdev.ncmd = 1;
|
||||||
g_btdev.tx_status = OK;
|
g_btdev.tx_status = OK;
|
||||||
ret = kthread_create("BT HCI Tx", CONFIG_BLUETOOTH_TXCMD_PRIORITY,
|
|
||||||
|
#ifdef CONFIG_BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
sched_lock();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pid = kthread_create("BT HCI Tx", CONFIG_BLUETOOTH_TXCMD_PRIORITY,
|
||||||
CONFIG_BLUETOOTH_TXCMD_STACKSIZE,
|
CONFIG_BLUETOOTH_TXCMD_STACKSIZE,
|
||||||
hci_tx_kthread, NULL);
|
hci_tx_kthread, NULL);
|
||||||
DEBUGASSERT(ret > 0);
|
DEBUGASSERT(pid > 0);
|
||||||
|
|
||||||
|
#ifdef CONFIG_BLUETOOTH_TXCMD_PINNED_TO_CORE
|
||||||
|
CPU_ZERO(&cpuset);
|
||||||
|
CPU_SET((CONFIG_BLUETOOTH_TXCMD_CORE - 1), &cpuset);
|
||||||
|
ret = nxsched_set_affinity(pid, sizeof(cpuset), &cpuset);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
wlerr("Failed to set affinity error=%d\n", ret);
|
||||||
|
DEBUGPANIC();
|
||||||
|
}
|
||||||
|
|
||||||
|
sched_unlock();
|
||||||
|
#endif
|
||||||
|
|
||||||
UNUSED(ret);
|
UNUSED(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user