From 638983d72d6edb25c87f51534cae6ff3715dc49a Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jan 2023 14:23:51 -0800 Subject: [PATCH 1/4] sample/zbus: qemu_nios2 needs faster tick for zbus test with picolibc Picolibc is enough faster than the minimal C library that the zbus benchmark will likely complete in well under 10ms on qemu_nios2. As this target cannot provide a clock at higher resolution than the system tick, we need to increase that rate to get a non-zero runtime for this benchmark. Add new nios2-specific config variables that change the CONFIG_SYS_CLOCK_TICKS_PER_SEC value, leaving all other platforms using the standard value. We cannot just increase it for every platform as qemu_arc_hs6x fails with a 1kHz rate. Signed-off-by: Keith Packard --- samples/subsys/zbus/benchmark/sample.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/subsys/zbus/benchmark/sample.yaml b/samples/subsys/zbus/benchmark/sample.yaml index 45d4bbde5d4a0..643a61407d2c9 100644 --- a/samples/subsys/zbus/benchmark/sample.yaml +++ b/samples/subsys/zbus/benchmark/sample.yaml @@ -19,6 +19,7 @@ tests: - CONFIG_BM_ONE_TO=8 - CONFIG_BM_MESSAGE_SIZE=256 - CONFIG_BM_ASYNC=y + - arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 sample.zbus.benchmark_sync: tags: zbus min_ram: 16 @@ -37,3 +38,4 @@ tests: - CONFIG_BM_ONE_TO=8 - CONFIG_BM_MESSAGE_SIZE=256 - CONFIG_BM_ASYNC=n + - arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 From c689f50c45a5d818ea3ebac63f571aef955db13c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jan 2023 16:27:51 -0800 Subject: [PATCH 2/4] samples: subsys: zbus: Avoid stack overflow with TLS Enabling TLS increases stack usage by a small amount as that is where any TLS variables are stored. When enabled, this sample ends up overflowing the 512-byte subscriber task stack and the IDLE_STACK_SIZE consumer stacks Replace the fixed 512-byte subscriber stack allocation with CONFIG_MAIN_STACK_SIZE so that it adopts a value controlled by the configuration in case it needs to be adjusted further. Increased CONFIG_IDLE_STACK_SIZE to 1024 to provide more space in each consumer stack. Signed-off-by: Keith Packard --- samples/subsys/zbus/benchmark/sample.yaml | 2 ++ samples/subsys/zbus/hello_world/src/main.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/subsys/zbus/benchmark/sample.yaml b/samples/subsys/zbus/benchmark/sample.yaml index 643a61407d2c9..f371d2c06ccfc 100644 --- a/samples/subsys/zbus/benchmark/sample.yaml +++ b/samples/subsys/zbus/benchmark/sample.yaml @@ -20,6 +20,7 @@ tests: - CONFIG_BM_MESSAGE_SIZE=256 - CONFIG_BM_ASYNC=y - arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 + - CONFIG_IDLE_STACK_SIZE=1024 sample.zbus.benchmark_sync: tags: zbus min_ram: 16 @@ -39,3 +40,4 @@ tests: - CONFIG_BM_MESSAGE_SIZE=256 - CONFIG_BM_ASYNC=n - arch:nios2:CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000 + - CONFIG_IDLE_STACK_SIZE=1024 diff --git a/samples/subsys/zbus/hello_world/src/main.c b/samples/subsys/zbus/hello_world/src/main.c index 64e33e878a4f1..d97eed3654930 100644 --- a/samples/subsys/zbus/hello_world/src/main.c +++ b/samples/subsys/zbus/hello_world/src/main.c @@ -89,7 +89,8 @@ static void subscriber_task(void) } } -K_THREAD_DEFINE(subscriber_task_id, 512, subscriber_task, NULL, NULL, NULL, 3, 0, 0); +K_THREAD_DEFINE(subscriber_task_id, CONFIG_MAIN_STACK_SIZE, + subscriber_task, NULL, NULL, NULL, 3, 0, 0); #if defined(CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS) static int count; From e5e99d792c59370dda11e53344ff3427bdec6b13 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jan 2023 20:18:25 -0800 Subject: [PATCH 3/4] tests: kernel: Provide more stack space for context test This test overflows when TLS is used, provide plenty of extra space to avoid that. Signed-off-by: Keith Packard --- tests/kernel/context/testcase.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/kernel/context/testcase.yaml b/tests/kernel/context/testcase.yaml index 7eeda47e488fb..8d973af7126aa 100644 --- a/tests/kernel/context/testcase.yaml +++ b/tests/kernel/context/testcase.yaml @@ -1,8 +1,11 @@ tests: kernel.context: tags: kernel + extra_configs: + - CONFIG_TEST_EXTRA_STACK_SIZE=1024 kernel.context.linker_generator: platform_allow: qemu_cortex_m3 tags: kernel linker_generator extra_configs: - CONFIG_CMAKE_LINKER_GENERATOR=y + - CONFIG_TEST_EXTRA_STACK_SIZE=1024 From 7a0003a23fa99025ee54575afef88b486924c01f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 10 Jan 2023 20:43:46 -0800 Subject: [PATCH 4/4] tests: logging: Stack overflow caught with TLS in log_core_additional When thread local storage is enabled, log_core_additional generates stack overflows in the main thread on several architectures. Increase the stack size to 4096 bytes for this thread. Signed-off-by: Keith Packard --- tests/subsys/logging/log_core_additional/log_sync.conf | 1 + tests/subsys/logging/log_core_additional/log_user.conf | 2 +- tests/subsys/logging/log_core_additional/prj.conf | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/subsys/logging/log_core_additional/log_sync.conf b/tests/subsys/logging/log_core_additional/log_sync.conf index f0685b5b2bfd0..c9894d82dd752 100644 --- a/tests/subsys/logging/log_core_additional/log_sync.conf +++ b/tests/subsys/logging/log_core_additional/log_sync.conf @@ -6,3 +6,4 @@ CONFIG_LOG=y CONFIG_LOG_OUTPUT=y CONFIG_LOG_BACKEND_UART=y CONFIG_LOG_MODE_IMMEDIATE=y +CONFIG_MAIN_STACK_SIZE=4096 diff --git a/tests/subsys/logging/log_core_additional/log_user.conf b/tests/subsys/logging/log_core_additional/log_user.conf index 6ed18a2106319..4922dfbb411b0 100644 --- a/tests/subsys/logging/log_core_additional/log_user.conf +++ b/tests/subsys/logging/log_core_additional/log_user.conf @@ -11,4 +11,4 @@ CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=1 CONFIG_THREAD_MONITOR=y CONFIG_LOG_PRINTK=y CONFIG_LOG_BLOCK_IN_THREAD=y -CONFIG_MAIN_STACK_SIZE=1024 +CONFIG_MAIN_STACK_SIZE=4096 diff --git a/tests/subsys/logging/log_core_additional/prj.conf b/tests/subsys/logging/log_core_additional/prj.conf index 7368ba16e73ad..a2bacab3cf500 100644 --- a/tests/subsys/logging/log_core_additional/prj.conf +++ b/tests/subsys/logging/log_core_additional/prj.conf @@ -11,6 +11,7 @@ CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_CBPRINTF_LIBC_SUBSTS=y CONFIG_ZTEST_STACK_SIZE=4096 CONFIG_LOG_PROCESS_THREAD=n +CONFIG_MAIN_STACK_SIZE=4096 CONFIG_MPSC_CLEAR_ALLOCATED=y CONFIG_LOG_BACKEND_UART=y