Zephyr Project API 3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
SMP Tests

SMP. More...

Modules

 SMP Integration Tests
 
 SMP Module Tests
 

Functions

 ZTEST (smp, test_smp_coop_threads)
 Verify SMP with 2 cooperative threads.
 
 ZTEST (smp, test_cpu_id_threads)
 Verify CPU IDs of threads in SMP.
 
 ZTEST (smp, test_coop_switch_in_abort)
 Verify the code path when we do context switch in k_thread_abort on SMP system.
 
 ZTEST (smp, test_coop_resched_threads)
 Test cooperative threads non-preemption.
 
 ZTEST (smp, test_preempt_resched_threads)
 Test preemptness of preemptive thread.
 
 ZTEST (smp, test_yield_threads)
 Validate behavior of thread when it yields.
 
 ZTEST (smp, test_sleep_threads)
 Test behavior of thread when it sleeps.
 
 ZTEST (smp, test_wakeup_threads)
 Test behavior of wakeup() in SMP case.
 
 ZTEST (smp, test_smp_release_global_lock)
 Test scenario that a thread release the global lock.
 
 ZTEST (smp, test_inc_concurrency)
 Test if the concurrency of SMP works or not.
 
static void process_events (void *arg0, void *arg1, void *arg2)
 Torture test for context switching code.
 
static void check_affinity (void *arg0, void *arg1, void *arg2)
 Torture test for cpu affinity code.
 

Detailed Description

SMP.

Function Documentation

◆ check_affinity()

static void check_affinity ( void *  arg0,
void *  arg1,
void *  arg2 
)
static

#include <tests/kernel/smp/src/main.c>

Torture test for cpu affinity code.

Pin thread to a specific cpu. Once thread gets cpu, check the cpu id is correct and then thread will give up cpu.

◆ process_events()

static void process_events ( void *  arg0,
void *  arg1,
void *  arg2 
)
static

#include <tests/kernel/smp/src/main.c>

Torture test for context switching code.

Leverage the polling API to stress test the context switching code. This test will hammer all the CPUs with thread swapping requests.

◆ ZTEST() [1/10]

ZTEST ( smp  ,
test_coop_resched_threads   
)

#include <tests/kernel/smp/src/main.c>

Test cooperative threads non-preemption.

Spawn cooperative threads equal to number of cores supported. Main thread will already be running on 1 core. Check if the last thread created preempts any threads already running.

◆ ZTEST() [2/10]

ZTEST ( smp  ,
test_coop_switch_in_abort   
)

#include <tests/kernel/smp/src/main.c>

Verify the code path when we do context switch in k_thread_abort on SMP system.

test logic:

  • The ztest thread has cooperative priority.
  • From ztest thread we spawn N number of cooperative threads, where N = number of CPUs.
    • The spawned cooperative are executing infinite loop (so they occupy CPU core until they are aborted).
    • We have (number of CPUs - 1) spawned threads run and executing infinite loop, as current CPU is occupied by ztest cooperative thread. Due to that the last of spawned threads is ready but not executing.
  • We abort spawned threads one-by-one from the ztest thread.
    • At the first k_thread_abort call the ztest thread will be preempted by the remaining spawned thread which has higher priority than ztest thread. But... k_thread_abort call should has destroyed one of the spawned threads, so ztest thread should have a CPU available to run on.
  • We expect that all spawned threads will be aborted successfully.

This was the test case for zephyrproject-rtos/zephyr#58040 issue where this test caused system hang.

◆ ZTEST() [3/10]

ZTEST ( smp  ,
test_cpu_id_threads   
)

#include <tests/kernel/smp/src/main.c>

Verify CPU IDs of threads in SMP.

Verify whether thread running on other core is parent thread from child thread

◆ ZTEST() [4/10]

ZTEST ( smp  ,
test_inc_concurrency   
)

#include <tests/kernel/smp/src/main.c>

Test if the concurrency of SMP works or not.

Validate the global lock and unlock API of SMP are thread-safe. We make 3 thread to increase the global count in different cpu and they both do locking then unlocking for LOOP_COUNT times. It shall be no deadlock happened and total global count shall be 3 * LOOP COUNT.

We show the 4 kinds of scenario:

  • No any lock used
  • Use global irq lock
  • Use semaphore
  • Use mutex

◆ ZTEST() [5/10]

ZTEST ( smp  ,
test_preempt_resched_threads   
)

#include <tests/kernel/smp/src/main.c>

Test preemptness of preemptive thread.

Create preemptive thread and let it run on another core and verify if it gets preempted if another thread of higher priority is spawned

◆ ZTEST() [6/10]

ZTEST ( smp  ,
test_sleep_threads   
)

#include <tests/kernel/smp/src/main.c>

Test behavior of thread when it sleeps.

Spawn cooperative thread and call sleep() from main thread. After timeout, all threads has to be scheduled.

◆ ZTEST() [7/10]

ZTEST ( smp  ,
test_smp_coop_threads   
)

#include <tests/kernel/smp/src/main.c>

Verify SMP with 2 cooperative threads.

Multi processing is verified by checking whether 2 cooperative threads run simultaneously at different cores

◆ ZTEST() [8/10]

ZTEST ( smp  ,
test_smp_release_global_lock   
)

#include <tests/kernel/smp/src/main.c>

Test scenario that a thread release the global lock.

Validate the scenario that make the internal APIs of SMP z_smp_release_global_lock() to be called.

◆ ZTEST() [9/10]

ZTEST ( smp  ,
test_wakeup_threads   
)

#include <tests/kernel/smp/src/main.c>

Test behavior of wakeup() in SMP case.

Spawn number of threads equal to number of remaining cores and let them sleep for a while. Call wakeup() of those threads from parent thread and check if they are all running

◆ ZTEST() [10/10]

ZTEST ( smp  ,
test_yield_threads   
)

#include <tests/kernel/smp/src/main.c>

Validate behavior of thread when it yields.

Spawn cooperative threads equal to number of cores, so last thread would be pending, call yield() from main thread. Now, all threads must be executed