Skip to content

Commit 3195702

Browse files
committed
tests: sched: Add busy threads for SMP
The sched benchmark is designed for systems with a single CPU. Otherwise, the timestamps would be wrong when the partner thread is scheduled on another CPU, i.e. negative values: ``` unpend 63 ready 62 switch -16562 pend 18937 tot 2500 (avg 928) ``` When the system allows for multiple CPUs, spawn a non-preemptible thread to keep the other CPUs busy. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent c3466b1 commit 3195702

File tree

1 file changed

+27
-0
lines changed
  • tests/benchmarks/sched/src

1 file changed

+27
-0
lines changed

tests/benchmarks/sched/src/main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
static K_THREAD_STACK_DEFINE(partner_stack, 1024);
3737
static struct k_thread partner_thread;
3838

39+
#if (CONFIG_MP_MAX_NUM_CPUS > 1)
40+
static struct k_thread busy_thread[CONFIG_MP_MAX_NUM_CPUS - 1];
41+
42+
#define BUSY_THREAD_STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)
43+
44+
static K_THREAD_STACK_ARRAY_DEFINE(busy_thread_stack, CONFIG_MP_MAX_NUM_CPUS - 1,
45+
BUSY_THREAD_STACK_SIZE);
46+
#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */
47+
3948
_wait_q_t waitq;
4049

4150
enum {
@@ -88,8 +97,26 @@ static void partner_fn(void *arg1, void *arg2, void *arg3)
8897
}
8998
}
9099

100+
#if (CONFIG_MP_MAX_NUM_CPUS > 1)
101+
static void busy_thread_entry(void *arg1, void *arg2, void *arg3)
102+
{
103+
while (true) {
104+
}
105+
}
106+
#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */
107+
91108
int main(void)
92109
{
110+
#if (CONFIG_MP_MAX_NUM_CPUS > 1)
111+
/* Spawn busy threads that will execute on the other cores */
112+
for (uint32_t i = 0; i < CONFIG_MP_MAX_NUM_CPUS - 1; i++) {
113+
k_thread_create(&busy_thread[i], busy_thread_stack[i],
114+
BUSY_THREAD_STACK_SIZE, busy_thread_entry,
115+
NULL, NULL, NULL,
116+
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);
117+
}
118+
#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */
119+
93120
z_waitq_init(&waitq);
94121

95122
int main_prio = k_thread_priority_get(k_current_get());

0 commit comments

Comments
 (0)