diff --git a/wireless/bluetooth/Kconfig b/wireless/bluetooth/Kconfig index d5c60c2dc5a..fbe17788af7 100644 --- a/wireless/bluetooth/Kconfig +++ b/wireless/bluetooth/Kconfig @@ -193,6 +193,25 @@ config BLUETOOTH_TXCONN_NMSGS int "Tx connection thread mqueue size" 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 config BLUETOOTH_SMP_SELFTEST diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c index 1d95f0ea1b2..d7e192247e6 100644 --- a/wireless/bluetooth/bt_hcicore.c +++ b/wireless/bluetooth/bt_hcicore.c @@ -1499,6 +1499,10 @@ static void cmd_queue_deinit(void) static void cmd_queue_init(void) { 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 * 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.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, 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); }