Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/kernel/services/threads/workqueue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ use of it.
for example, if the new work items perform blocking operations that
would delay other system workqueue processing to an unacceptable degree.

Stack Size
==========

By default the stack size of the system workqueue is determined co-operatively
among all users of the workqueue. The build system compares the value of all
Kconfig symbols matching the pattern
``CONFIG_SYSTEM_WORKQUEUE_MIN_STACK_SIZE_*`` and selects the largest value as
the stack size. :kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE` is
included in this calculation by its value being copied into
:kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_MIN_STACK_SIZE_DEFAULT`.

.. note::
This behaviour can be disabled through
:kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE_IGNORE_MIN`, in which
case the value of :kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE` will
be used directly.

How to Use Workqueues
*********************

Expand Down
9 changes: 9 additions & 0 deletions doc/releases/migration-guide-4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ Build System
Kernel
******

* The stack size of the system workqueue is now computed co-operatively
among users as the maximum value of any Kconfig options whose name starts
with ``CONFIG_SYSTEM_WORKQUEUE_MIN_STACK_SIZE_``. The existing
:kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE` symbol value is copied
to :kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_MIN_STACK_SIZE_DEFAULT` so that
it is included in the calculation without any application changes.
The previous behaviour can be selected with
:kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE_IGNORE_MIN`.

Boards
******

Expand Down
15 changes: 15 additions & 0 deletions kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ if(${CONFIG_KERNEL_MEM_POOL})
zephyr_compile_definitions(K_HEAP_MEM_POOL_SIZE=${final_heap_size})
endif()

# Import all custom SYSTEM_WORKQUEUE_MIN_STACK_SIZE size requirements
import_kconfig(CONFIG_SYSTEM_WORKQUEUE_MIN_STACK_SIZE_ ${DOTCONFIG} min_stack_size_keys)
if(${CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE_IGNORE_MIN})
set(stack_size_max ${CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE})
else()
# Find the largest of all "MIN_STACK_SIZE" requested
set(stack_size_max 0)
foreach(val ${min_stack_size_keys})
if(${${val}} GREATER ${stack_size_max})
set(stack_size_max ${${val}})
endif()
endforeach()
endif()
zephyr_compile_definitions(K_SYSTEM_WORKQUEUE_STACK_SIZE=${stack_size_max})

# The last 2 files inside the target_sources_ifdef should be
# userspace_handler.c and userspace.c. If not the linker would complain.
# This order has to be maintained. Any new file should be placed
Expand Down
17 changes: 15 additions & 2 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,23 @@ rsource "Kconfig.obj_core"
menu "System Work Queue Options"
config SYSTEM_WORKQUEUE_STACK_SIZE
int "System workqueue stack size"
default 4096 if COVERAGE_GCOV
default 2560 if WIFI_NM_WPA_SUPPLICANT
default 1024

config SYSTEM_WORKQUEUE_STACK_SIZE_IGNORE_MIN
bool "Ignore the minimum system workqueue stack size requirement"
help
This option can be set to force setting a smaller system workqueue
stack size than what's specified by enabled subsystems. This can be
useful when optimizing memory usage and a more precise system workqueue
size is known for a given application.


config SYSTEM_WORKQUEUE_MIN_STACK_SIZE_DEFAULT
int
default SYSTEM_WORKQUEUE_STACK_SIZE
help
Used to maintain compatibility with explicit stack size setting.

config SYSTEM_WORKQUEUE_PRIORITY
int "System workqueue priority"
default -2 if COOP_ENABLED && !PREEMPT_ENABLED
Expand Down
3 changes: 1 addition & 2 deletions kernel/system_work_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include <zephyr/kernel.h>
#include <zephyr/init.h>

static K_KERNEL_STACK_DEFINE(sys_work_q_stack,
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE);
static K_KERNEL_STACK_DEFINE(sys_work_q_stack, K_SYSTEM_WORKQUEUE_STACK_SIZE);

struct k_work_q k_sys_work_q;

Expand Down
4 changes: 4 additions & 0 deletions modules/hostap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ config WIFI_NM_WPA_SUPPLICANT

if WIFI_NM_WPA_SUPPLICANT

config SYSTEM_WORKQUEUE_MIN_STACK_SIZE_WPA_SUPPLICANT
int
default 2560

config HEAP_MEM_POOL_ADD_SIZE_HOSTAP
def_int 66560 if WIFI_NM_HOSTAPD_AP
def_int 48000 if WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ def check_no_undef_outside_kconfig(self, kconf):
"SRAM2", # Referenced in a comment in samples/application_development
"STACK_SIZE", # Used as an example in the Kconfig docs
"STD_CPP", # Referenced in CMake comment
"SYSTEM_WORKQUEUE_MIN_STACK_SIZE_", # Used as an option matching prefix
"TEST1",
"TOOLCHAIN_ARCMWDT_SUPPORTS_THREAD_LOCAL_STORAGE", # The symbol is defined in the toolchain
# Kconfig which is sourced based on Zephyr
Expand Down
5 changes: 5 additions & 0 deletions subsys/testsuite/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ config COVERAGE_GCOV

endchoice

config SYSTEM_WORKQUEUE_MIN_STACK_SIZE_COVERAGE_GCOV
int
depends on COVERAGE_GCOV
default 4096

config COVERAGE_GCOV_HEAP_SIZE
int "Size of heap allocated for gcov coverage data dump"
depends on COVERAGE_GCOV
Expand Down
Loading