Commit 698c4b02 authored by Jamie McCrae's avatar Jamie McCrae Committed by Carles Cufi
Browse files

mgmt: mcumgr: Use dedicated work queue for SMP



Fixes an issues where the system work queue can become a source of
contention and cause a deadlock by moving MCUMGR SMP processing to its
own dedicated work queue.

Signed-off-by: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent 4bd39c21
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -15,6 +15,17 @@ module = MCUMGR
module-str = mcumgr
source "subsys/logging/Kconfig.template.log_config"

config MCUMGR_SMP_WORKQUEUE_STACK_SIZE
	int "MCUMGR SMP workqueue stack size"
	default 2048
	help
	  Stack size of the MCUMGR SMP work queue.

config MCUMGR_SMP_WORKQUEUE_THREAD_PRIO
	int "MCUMGR SMP workqueue thread priority"
	default 3
	help
	  Scheduling priority of the MCUMGR SMP work queue.

config APP_LINK_WITH_MCUMGR
	bool "Link 'app' with MCUMGR"
+23 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/net/buf.h>
#include <zephyr/mgmt/mcumgr/buf.h>
#include "mgmt/mgmt.h"
@@ -25,6 +26,14 @@ LOG_MODULE_REGISTER(mcumgr_smp, CONFIG_MCUMGR_SMP_LOG_LEVEL);
#define WEAK
#endif

K_THREAD_STACK_DEFINE(smp_work_queue_stack, CONFIG_MCUMGR_SMP_WORKQUEUE_STACK_SIZE);

static struct k_work_q smp_work_queue;

static const struct k_work_queue_config smp_work_queue_config = {
	.name = "mcumgr smp"
};

/**
 * @brief Allocates a response buffer.
 *
@@ -256,5 +265,18 @@ WEAK void
zephyr_smp_rx_req(struct zephyr_smp_transport *zst, struct net_buf *nb)
{
	net_buf_put(&zst->zst_fifo, nb);
	k_work_submit(&zst->zst_work);
	k_work_submit_to_queue(&smp_work_queue, &zst->zst_work);
}

static int zephyr_smp_init(const struct device *dev)
{
	k_work_queue_init(&smp_work_queue);

	k_work_queue_start(&smp_work_queue, smp_work_queue_stack,
			   K_THREAD_STACK_SIZEOF(smp_work_queue_stack),
			   CONFIG_MCUMGR_SMP_WORKQUEUE_THREAD_PRIO, &smp_work_queue_config);

	return 0;
}

SYS_INIT(zephyr_smp_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);