Skip to content

Commit 482d183

Browse files
peter-mitsiscfriedt
authored andcommitted
tests: Update smp test to support 12 CPUs
Updates the smp test to support nsim/nsim_hs5x/smp/12cores. Furthermore, if someone attempts to build the smp test for more than 12 CPUs, report an error message informing the user to reduce the number of CPUs. This reduction can be in the form of a custom overlay for the board in question. Fixes #96339 Signed-off-by: Peter Mitsis <[email protected]>
1 parent daab73d commit 482d183

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/kernel/smp/src/main.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@
1414
#error SMP test requires at least two CPUs!
1515
#endif
1616

17+
/*
18+
* The test is designed to work with no more than 12 CPUs.
19+
* If attempting to run on a platform with more than that,
20+
* create a custom board overlay file to reduce the number
21+
* of CPUs to 12.
22+
*/
23+
#if CONFIG_MP_MAX_NUM_CPUS > 12
24+
#error "Test only supports up to 12 CPUs\nReduce CONFIG_MP_MAX_NUM_CPUS\n"
25+
#endif
26+
1727
#define RUN_FACTOR (CONFIG_SMP_TEST_RUN_FACTOR / 100.0)
1828

1929
#define T2_STACK_SIZE (2048 + CONFIG_TEST_EXTRA_STACK_SIZE)
2030
#define STACK_SIZE (384 + CONFIG_TEST_EXTRA_STACK_SIZE)
2131
#define DELAY_US 50000
22-
#define TIMEOUT 1000
32+
#define TIMEOUT 5000
2333
#define EQUAL_PRIORITY 1
2434
#define TIME_SLICE_MS 500
2535
#define THREAD_DELAY 1
@@ -372,11 +382,11 @@ ZTEST(smp, test_coop_resched_threads)
372382
* since we don't give up current CPU, last thread
373383
* will not get scheduled
374384
*/
375-
spawn_threads(K_PRIO_COOP(10), num_threads, !EQUAL_PRIORITY,
385+
spawn_threads(K_PRIO_COOP(12), num_threads, !EQUAL_PRIORITY,
376386
&thread_entry_fn, THREAD_DELAY);
377387

378388
/* Wait for some time to let other core's thread run */
379-
k_busy_wait(DELAY_US);
389+
k_busy_wait(DELAY_US * 5);
380390

381391

382392
/* Reassure that cooperative thread's are not preempted
@@ -413,7 +423,7 @@ ZTEST(smp, test_preempt_resched_threads)
413423
* lower priority thread should
414424
* be preempted by higher ones
415425
*/
416-
spawn_threads(K_PRIO_PREEMPT(10), num_threads, !EQUAL_PRIORITY,
426+
spawn_threads(K_PRIO_PREEMPT(12), num_threads, !EQUAL_PRIORITY,
417427
&thread_entry_fn, THREAD_DELAY);
418428

419429
spin_for_threads_exit();
@@ -446,11 +456,11 @@ ZTEST(smp, test_yield_threads)
446456
* of cores, so the last thread would be
447457
* pending.
448458
*/
449-
spawn_threads(K_PRIO_COOP(10), num_threads, !EQUAL_PRIORITY,
459+
spawn_threads(K_PRIO_COOP(12), num_threads, !EQUAL_PRIORITY,
450460
&thread_entry_fn, !THREAD_DELAY);
451461

452462
k_yield();
453-
k_busy_wait(DELAY_US);
463+
k_busy_wait(DELAY_US * 5);
454464

455465
for (int i = 0; i < num_threads; i++) {
456466
zassert_true(tinfo[i].executed == 1,
@@ -475,7 +485,7 @@ ZTEST(smp, test_sleep_threads)
475485
{
476486
unsigned int num_threads = arch_num_cpus();
477487

478-
spawn_threads(K_PRIO_COOP(10), num_threads, !EQUAL_PRIORITY,
488+
spawn_threads(K_PRIO_COOP(12), num_threads, !EQUAL_PRIORITY,
479489
&thread_entry_fn, !THREAD_DELAY);
480490

481491
k_msleep(TIMEOUT);
@@ -533,7 +543,7 @@ static void check_wokeup_threads(int tnum)
533543
/* k_wakeup() isn't synchronous, give the other CPU time to
534544
* schedule them
535545
*/
536-
k_busy_wait(200000);
546+
k_busy_wait(300000);
537547

538548
for (i = 0; i < tnum; i++) {
539549
if (tinfo[i].executed == 1 && threads_woke_up <= tnum) {
@@ -558,7 +568,7 @@ ZTEST(smp, test_wakeup_threads)
558568
unsigned int num_threads = arch_num_cpus();
559569

560570
/* Spawn threads to run on all remaining cores */
561-
spawn_threads(K_PRIO_COOP(10), num_threads - 1, !EQUAL_PRIORITY,
571+
spawn_threads(K_PRIO_COOP(12), num_threads - 1, !EQUAL_PRIORITY,
562572
&thread_wakeup_entry, !THREAD_DELAY);
563573

564574
/* Check if all the threads have started, then call wakeup */

0 commit comments

Comments
 (0)