tests: latency_measure: Add busy threads for SMP

The latency_measure benchmark is designed for systems with a single
CPU. When the system allows for multiple CPUs, instead of forcing
a single CPU to be used via 'prj.conf', spawn a non-preemptible
thread to keep the other CPUs busy.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2024-08-12 22:12:14 +00:00 committed by Anas Nashif
commit ee7bbf55e0
2 changed files with 27 additions and 2 deletions

View file

@ -20,8 +20,6 @@ CONFIG_COVERAGE=n
# Disable system power management # Disable system power management
CONFIG_PM=n CONFIG_PM=n
# Can only run under 1 CPU
CONFIG_MP_MAX_NUM_CPUS=1
CONFIG_TIMING_FUNCTIONS=y CONFIG_TIMING_FUNCTIONS=y
CONFIG_HEAP_MEM_POOL_SIZE=2048 CONFIG_HEAP_MEM_POOL_SIZE=2048

View file

@ -31,6 +31,14 @@ K_THREAD_STACK_DEFINE(alt_stack, ALT_STACK_SIZE);
K_SEM_DEFINE(pause_sem, 0, 1); K_SEM_DEFINE(pause_sem, 0, 1);
#if (CONFIG_MP_MAX_NUM_CPUS > 1)
struct k_thread busy_thread[CONFIG_MP_MAX_NUM_CPUS - 1];
#define BUSY_THREAD_STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)
K_THREAD_STACK_DEFINE(busy_thread_stack, BUSY_THREAD_STACK_SIZE);
#endif
struct k_thread start_thread; struct k_thread start_thread;
struct k_thread alt_thread; struct k_thread alt_thread;
@ -60,6 +68,14 @@ extern int stack_blocking_ops(uint32_t num_iterations, uint32_t start_options,
uint32_t alt_options); uint32_t alt_options);
extern void heap_malloc_free(void); extern void heap_malloc_free(void);
#if (CONFIG_MP_MAX_NUM_CPUS > 1)
static void busy_thread_entry(void *arg1, void *arg2, void *arg3)
{
while (1) {
}
}
#endif
static void test_thread(void *arg1, void *arg2, void *arg3) static void test_thread(void *arg1, void *arg2, void *arg3)
{ {
uint32_t freq; uint32_t freq;
@ -68,6 +84,17 @@ static void test_thread(void *arg1, void *arg2, void *arg3)
ARG_UNUSED(arg2); ARG_UNUSED(arg2);
ARG_UNUSED(arg3); ARG_UNUSED(arg3);
#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
#ifdef CONFIG_USERSPACE #ifdef CONFIG_USERSPACE
k_mem_domain_add_partition(&k_mem_domain_default, k_mem_domain_add_partition(&k_mem_domain_default,
&bench_mem_partition); &bench_mem_partition);