tests: smp_suspend: Add configurable delay

Adds a configurable delay to the test threads. It exists to keep
thread0 from hogging the scheduler's spin lock and giving threads
on another core a better chance to obtain that lock and not starve.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis
2024-01-24 09:31:04 -05:00
committed by Fabio Baltieri
parent ffa3e415a0
commit 7d762050ba
2 changed files with 24 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
# Copyright (c) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
mainmenu "SMP suspend test"
source "Kconfig.zephyr"
config SMP_TEST_RELAX
int "A delay to compensate for spinlock bias induced by arch_spin_relax"
default 16
+14 -1
View File
@@ -33,6 +33,19 @@ static void thread_entry(void *p1, void *p2, void *p3)
thread_counter[self_index]++;
/*
* Contentious spinlocks embedded within tight loops (such as
* this one) have a CPU bias induced by arch_spin_relax(). We
* counteract this by introducing a configurable delay so that
* other threads have a chance to acquire the spinlock and
* prevent starvation.
*/
for (volatile unsigned int i = 0;
i < CONFIG_SMP_TEST_RELAX;
i++) {
}
if (self_index != 0) {
k_thread_suspend(k_current_get());
}
@@ -73,7 +86,7 @@ ZTEST(smp_suspend_resume, test_smp_thread_suspend_resume_stress)
for (i = 0; i < NUM_THREADS; i++) {
zassert_false(counter[i] == thread_counter[i],
" -- Thread %u appears to be hung: %llu\n",
" -- Thread %u is starving: %llu\n",
i, thread_counter[i]);
counter[i] = thread_counter[i];