forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add thread suspend-resume SMP stress test
Adds a test to stress k_thread_suspend() and k_thread_resume() on an SMP system. The test should take about 30 seconds. Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
- Loading branch information
1 parent
1e6ff5f
commit 9852e8e
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(smp) | ||
|
||
target_sources(app PRIVATE src/main.c) | ||
|
||
target_include_directories(app PRIVATE | ||
${ZEPHYR_BASE}/kernel/include | ||
${ZEPHYR_BASE}/arch/${ARCH}/include | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_SMP=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/tc_util.h> | ||
#include <zephyr/ztest.h> | ||
#include <zephyr/kernel.h> | ||
|
||
#if CONFIG_MP_MAX_NUM_CPUS < 2 | ||
#error "SMP test requires at least two CPUs!" | ||
#endif | ||
|
||
#define STACK_SIZE 1024 | ||
|
||
#define NUM_THREADS 6 | ||
|
||
K_THREAD_STACK_ARRAY_DEFINE(thread_stack, NUM_THREADS, STACK_SIZE); | ||
struct k_thread thread[NUM_THREADS]; | ||
|
||
volatile uint64_t thread_counter[NUM_THREADS]; | ||
|
||
static void thread_entry(void *p1, void *p2, void *p3) | ||
{ | ||
struct k_thread *resume_thread = p1; | ||
unsigned int self_index = (unsigned int)(uintptr_t)p2; | ||
|
||
while (1) { | ||
if (resume_thread != NULL) { | ||
k_thread_resume(resume_thread); | ||
} | ||
|
||
thread_counter[self_index]++; | ||
|
||
if (self_index != 0) { | ||
k_thread_suspend(k_current_get()); | ||
} | ||
} | ||
} | ||
|
||
ZTEST(smp_suspend_resume, test_smp_thread_suspend_resume_stress) | ||
{ | ||
unsigned int i; | ||
uint64_t counter[NUM_THREADS] = {}; | ||
|
||
/* Create the threads */ | ||
|
||
printk("Starting ...\n"); | ||
|
||
for (i = 0; i < NUM_THREADS; i++) { | ||
|
||
k_thread_create(&thread[i], thread_stack[i], | ||
STACK_SIZE, thread_entry, | ||
i < (NUM_THREADS - 1) ? &thread[i + 1] : NULL, | ||
(void *)(uintptr_t)i, NULL, | ||
10 - i, 0, K_FOREVER); | ||
|
||
k_thread_suspend(&thread[i]); | ||
|
||
k_thread_start(&thread[i]); | ||
} | ||
|
||
/* | ||
* All newly created test threads are currently in the suspend state. | ||
* Start the first thread. | ||
*/ | ||
|
||
k_thread_resume(&thread[0]); | ||
|
||
for (unsigned int iteration = 0; iteration < 30; iteration++) { | ||
k_sleep(K_MSEC(1000)); | ||
|
||
for (i = 0; i < NUM_THREADS; i++) { | ||
zassert_false(counter[i] == thread_counter[i], | ||
" -- Thread %u appears to be hung: %llu\n", | ||
i, thread_counter[i]); | ||
|
||
counter[i] = thread_counter[i]; | ||
|
||
} | ||
} | ||
} | ||
|
||
ZTEST_SUITE(smp_suspend_resume, NULL, NULL, NULL, NULL, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tests: | ||
kernel.smp_suspend: | ||
tags: | ||
- kernel | ||
- smp | ||
filter: (CONFIG_MP_MAX_NUM_CPUS > 1) |