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 <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2022-08-30 12:42:04 -07:00 committed by Carles Cufí
commit 7019baf6ac

View file

@ -541,16 +541,17 @@ static void thread_get_cpu_entry(void *p1, void *p2, void *p3)
*
* @see arch_curr_cpu()
*/
static int _cpu_id;
ZTEST(smp, test_get_cpu)
{
k_tid_t thread_id;
/* get current cpu number */
int cpu_id = arch_curr_cpu()->id;
_cpu_id = arch_curr_cpu()->id;
thread_id = k_thread_create(&t2, t2_stack, T2_STACK_SIZE,
(k_thread_entry_t)thread_get_cpu_entry,
&cpu_id, NULL, NULL,
&_cpu_id, NULL, NULL,
K_PRIO_COOP(2),
K_INHERIT_PERMS, K_NO_WAIT);