Skip to content

Commit 4b15936

Browse files
dcpleungcfriedt
authored andcommitted
tests: kernel/smp_boot_delay: workaround occassionally failures
test_smp_boot_delay sometimes fails due to thread started by IPI not having started or not finished running: * Using CPU mask to explicitly state which CPU to start the thread seems to fix the issue where the thread is not started quickly enough. * When the host system is under heavy load (e.g. twister-ing), emulators may not get enough CPU time to run the newly created thread. So extend the IPI delay a bit more to allow for this. Signed-off-by: Daniel Leung <[email protected]>
1 parent 1edc97c commit 4b15936

File tree

1 file changed

+13
-7
lines changed
  • tests/kernel/smp_boot_delay/src

1 file changed

+13
-7
lines changed

tests/kernel/smp_boot_delay/src/main.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define CPU_START_DELAY 10000
1313

1414
/* IPIs happen much faster than CPU startup */
15-
#define CPU_IPI_DELAY 1000
15+
#define CPU_IPI_DELAY 2500
1616

1717
BUILD_ASSERT(CONFIG_SMP);
1818
BUILD_ASSERT(CONFIG_SMP_BOOT_DELAY);
@@ -33,13 +33,17 @@ static void thread_fn(void *a, void *b, void *c)
3333

3434
ZTEST(smp_boot_delay, test_smp_boot_delay)
3535
{
36+
k_tid_t thr;
37+
3638
/* Create a thread of lower priority. This could run on
3739
* another CPU if it was available, but will not preempt us
3840
* unless we block (which we do not).
3941
*/
40-
k_thread_create(&cpu_thr, thr_stack, K_THREAD_STACK_SIZEOF(thr_stack),
41-
thread_fn, NULL, NULL, NULL,
42-
1, 0, K_NO_WAIT);
42+
thr = k_thread_create(&cpu_thr, thr_stack, K_THREAD_STACK_SIZEOF(thr_stack),
43+
thread_fn, NULL, NULL, NULL,
44+
1, 0, K_FOREVER);
45+
(void)k_thread_cpu_pin(thr, 1);
46+
k_thread_start(thr);
4347

4448
/* Make sure that thread has not run (because the cpu is halted) */
4549
k_busy_wait(CPU_START_DELAY);
@@ -61,9 +65,11 @@ ZTEST(smp_boot_delay, test_smp_boot_delay)
6165
* IPIs were correctly set up on the runtime-launched CPU.
6266
*/
6367
mp_flag = false;
64-
k_thread_create(&cpu_thr, thr_stack, K_THREAD_STACK_SIZEOF(thr_stack),
65-
thread_fn, NULL, NULL, NULL,
66-
1, 0, K_NO_WAIT);
68+
thr = k_thread_create(&cpu_thr, thr_stack, K_THREAD_STACK_SIZEOF(thr_stack),
69+
thread_fn, NULL, NULL, NULL,
70+
1, 0, K_FOREVER);
71+
(void)k_thread_cpu_pin(thr, 1);
72+
k_thread_start(thr);
6773

6874
k_busy_wait(CPU_IPI_DELAY);
6975

0 commit comments

Comments
 (0)