From 3195702323d1a073bbd4fdd248a48d54d3f49f3f Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Thu, 7 Nov 2024 15:08:31 +0800 Subject: [PATCH 1/2] 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 --- tests/benchmarks/sched/src/main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/benchmarks/sched/src/main.c b/tests/benchmarks/sched/src/main.c index 1a590af1eb37b..835d3c71fa1ab 100644 --- a/tests/benchmarks/sched/src/main.c +++ b/tests/benchmarks/sched/src/main.c @@ -36,6 +36,15 @@ static K_THREAD_STACK_DEFINE(partner_stack, 1024); static struct k_thread partner_thread; +#if (CONFIG_MP_MAX_NUM_CPUS > 1) +static struct k_thread busy_thread[CONFIG_MP_MAX_NUM_CPUS - 1]; + +#define BUSY_THREAD_STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE) + +static K_THREAD_STACK_ARRAY_DEFINE(busy_thread_stack, CONFIG_MP_MAX_NUM_CPUS - 1, + BUSY_THREAD_STACK_SIZE); +#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */ + _wait_q_t waitq; enum { @@ -88,8 +97,26 @@ static void partner_fn(void *arg1, void *arg2, void *arg3) } } +#if (CONFIG_MP_MAX_NUM_CPUS > 1) +static void busy_thread_entry(void *arg1, void *arg2, void *arg3) +{ + while (true) { + } +} +#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */ + int main(void) { +#if (CONFIG_MP_MAX_NUM_CPUS > 1) + /* Spawn busy threads that will execute on the other cores */ + for (uint32_t i = 0; i < CONFIG_MP_MAX_NUM_CPUS - 1; i++) { + k_thread_create(&busy_thread[i], busy_thread_stack[i], + BUSY_THREAD_STACK_SIZE, busy_thread_entry, + NULL, NULL, NULL, + K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT); + } +#endif /* (CONFIG_MP_MAX_NUM_CPUS > 1) */ + z_waitq_init(&waitq); int main_prio = k_thread_priority_get(k_current_get()); From b928d2688d83803ddd1e08fdadadbcd48868106f Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 8 Nov 2024 13:04:16 +0800 Subject: [PATCH 2/2] tests: benchmarks/sched: limit CPU to 1 for Intel ADSP ACE Due to addition of busy threads running on other cores, and the simulator runs in single thread bouncing through all cores, we are wasting quite a bit of time just busy waiting. This makes each simulator run too long for CI. So limit CPU number to 1. Signed-off-by: Daniel Leung Signed-off-by: Yong Cong Sin --- .../benchmarks/sched/boards/intel_adsp_ace15_mtpm_sim.conf | 6 ++++++ tests/benchmarks/sched/boards/intel_adsp_ace20_lnl_sim.conf | 6 ++++++ tests/benchmarks/sched/boards/intel_adsp_ace30_ptl_sim.conf | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/benchmarks/sched/boards/intel_adsp_ace15_mtpm_sim.conf create mode 100644 tests/benchmarks/sched/boards/intel_adsp_ace20_lnl_sim.conf create mode 100644 tests/benchmarks/sched/boards/intel_adsp_ace30_ptl_sim.conf diff --git a/tests/benchmarks/sched/boards/intel_adsp_ace15_mtpm_sim.conf b/tests/benchmarks/sched/boards/intel_adsp_ace15_mtpm_sim.conf new file mode 100644 index 0000000000000..bad81b9ffbfa5 --- /dev/null +++ b/tests/benchmarks/sched/boards/intel_adsp_ace15_mtpm_sim.conf @@ -0,0 +1,6 @@ +# Due to addition of busy threads running on other cores, +# and the simulator runs in single thread bouncing through +# all cores, we are wasting quite a bit of time just busy +# waiting. This makes each simulator run too long for CI. +# So limit CPU number to 1. +CONFIG_MP_MAX_NUM_CPUS=1 diff --git a/tests/benchmarks/sched/boards/intel_adsp_ace20_lnl_sim.conf b/tests/benchmarks/sched/boards/intel_adsp_ace20_lnl_sim.conf new file mode 100644 index 0000000000000..bad81b9ffbfa5 --- /dev/null +++ b/tests/benchmarks/sched/boards/intel_adsp_ace20_lnl_sim.conf @@ -0,0 +1,6 @@ +# Due to addition of busy threads running on other cores, +# and the simulator runs in single thread bouncing through +# all cores, we are wasting quite a bit of time just busy +# waiting. This makes each simulator run too long for CI. +# So limit CPU number to 1. +CONFIG_MP_MAX_NUM_CPUS=1 diff --git a/tests/benchmarks/sched/boards/intel_adsp_ace30_ptl_sim.conf b/tests/benchmarks/sched/boards/intel_adsp_ace30_ptl_sim.conf new file mode 100644 index 0000000000000..bad81b9ffbfa5 --- /dev/null +++ b/tests/benchmarks/sched/boards/intel_adsp_ace30_ptl_sim.conf @@ -0,0 +1,6 @@ +# Due to addition of busy threads running on other cores, +# and the simulator runs in single thread bouncing through +# all cores, we are wasting quite a bit of time just busy +# waiting. This makes each simulator run too long for CI. +# So limit CPU number to 1. +CONFIG_MP_MAX_NUM_CPUS=1