Skip to content

Commit 7019baf

Browse files
dcpleungcarlescufi
authored andcommitted
tests: kernel/smp: don't use stack to pass thread args
Inside test_get_cpu, the current CPU ID is stored in the test thread's stack. Another thread is spawned with a pointer to the variable holding this CPU ID, where this thread is supposed to run on another CPU. On a cache incoherent platform, this value of this variable may not have been updated on other CPU's internal cache. Therefore when checking CPU IDs inside the newly spawned thread, it is not checking the passed in CPU ID, but actually whatever is on the another CPU's cache. This results in random failure on the test_get_cpu test. Since for cache incoherence architectures, CONFIG_KERNEL_COHERENCE is enabled by default on SMP where shared data is placed in multiprocessor coherent (generally "uncached") memory. The fix to this is to simply make this variable as a global variable, as global variable are consided shared data and will be placed in multiprocessor coherent memory, and thus the correct value will be referenced inside the newly spawned thread. Fixes #49442 Signed-off-by: Daniel Leung <[email protected]>
1 parent dbe3874 commit 7019baf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tests/kernel/smp/src/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,16 +541,17 @@ static void thread_get_cpu_entry(void *p1, void *p2, void *p3)
541541
*
542542
* @see arch_curr_cpu()
543543
*/
544+
static int _cpu_id;
544545
ZTEST(smp, test_get_cpu)
545546
{
546547
k_tid_t thread_id;
547548

548549
/* get current cpu number */
549-
int cpu_id = arch_curr_cpu()->id;
550+
_cpu_id = arch_curr_cpu()->id;
550551

551552
thread_id = k_thread_create(&t2, t2_stack, T2_STACK_SIZE,
552553
(k_thread_entry_t)thread_get_cpu_entry,
553-
&cpu_id, NULL, NULL,
554+
&_cpu_id, NULL, NULL,
554555
K_PRIO_COOP(2),
555556
K_INHERIT_PERMS, K_NO_WAIT);
556557

0 commit comments

Comments
 (0)