From 6b839cf645d969e9388db2860c1de87c7df4459b Mon Sep 17 00:00:00 2001 From: Luis Ubieda Date: Thu, 13 Feb 2025 20:06:37 -0500 Subject: [PATCH 1/2] p4wq: Add Kconfig to perform early init on threads In order to make them functional for devices during init. Default behavior is to keep late initialization, as before. Signed-off-by: Luis Ubieda (cherry picked from commit ec45b29ea305335f4dc8ebe6283719ed86ea515e) --- lib/os/Kconfig | 10 ++++++++++ lib/os/p4wq.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/lib/os/Kconfig b/lib/os/Kconfig index 9ce3be2a66ebf..004df87ccf390 100644 --- a/lib/os/Kconfig +++ b/lib/os/Kconfig @@ -106,6 +106,16 @@ config MPSC_CLEAR_ALLOCATED When enabled packet space is zeroed before returning from allocation. endif +if SCHED_DEADLINE + +config P4WQ_INIT_STAGE_EARLY + bool "Early initialization of P4WQ threads" + help + Initialize P4WQ threads early so that the P4WQ can be used on devices + initialization sequence. + +endif + config REBOOT bool "Reboot functionality" help diff --git a/lib/os/p4wq.c b/lib/os/p4wq.c index 22d24da140b83..3d7310c47ee68 100644 --- a/lib/os/p4wq.c +++ b/lib/os/p4wq.c @@ -213,7 +213,11 @@ void k_p4wq_enable_static_thread(struct k_p4wq *queue, struct k_thread *thread, * so they can initialize in parallel instead of serially on the main * CPU. */ +#if defined(CONFIG_P4WQ_INIT_STAGE_EARLY) +SYS_INIT(static_init, POST_KERNEL, 1); +#else SYS_INIT(static_init, APPLICATION, 99); +#endif void k_p4wq_submit(struct k_p4wq *queue, struct k_p4wq_work *item) { From 91e13d91b024d70698f9ad1fcfec845964d32125 Mon Sep 17 00:00:00 2001 From: Luis Ubieda Date: Thu, 13 Feb 2025 20:07:50 -0500 Subject: [PATCH 2/2] rtio: workq: Select Early P4WQ threads init Otherwise the RTIO Workqueue is not functional for devices during init. An example of this issue is devices using SPI transfers with default spi_rtio. Signed-off-by: Luis Ubieda (cherry picked from commit 2ce2794987049022e1f754f87d3c9b9bd098a3a8) --- subsys/rtio/Kconfig.workq | 1 + 1 file changed, 1 insertion(+) diff --git a/subsys/rtio/Kconfig.workq b/subsys/rtio/Kconfig.workq index af85220415692..ad8dcd8ffdf7e 100644 --- a/subsys/rtio/Kconfig.workq +++ b/subsys/rtio/Kconfig.workq @@ -4,6 +4,7 @@ config RTIO_WORKQ bool "RTIO Work-queues service to process Sync operations" select SCHED_DEADLINE + select P4WQ_INIT_STAGE_EARLY select RTIO_CONSUME_SEM help Enable RTIO Work-queues to allow processing synchronous operations