Skip to content

Commit

Permalink
tests: benchmarks: multicore: Add synchronization between cores
Browse files Browse the repository at this point in the history
There is difference in boot time between Application and Radio cores.

When current consumption test is executed on two cores,
synchronize their startup.

Signed-off-by: Sebastian Głąb <sebastian.glab@nordicsemi.no>
  • Loading branch information
nordic-segl committed Feb 24, 2025
1 parent d4bbdb0 commit 9536f3f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
7 changes: 7 additions & 0 deletions tests/benchmarks/multicore/idle_pwm_led/remote/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ config TEST_SLEEP_DURATION_MS
Based on the value of 'min-residency-us' specified for each power state defined in the DTS,
core enters the lowest possible power state.

config TEST_ROLE_REMOTE
bool "Execute test variant for Remote core"
default y
help
KConfig used in synchronization phase.
Set TEST_ROLE_REMOTE=y on core that shall synchronize with the Host core.

source "Kconfig.zephyr"
36 changes: 33 additions & 3 deletions tests/benchmarks/multicore/idle_pwm_led/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
LOG_MODULE_REGISTER(idle_pwm_led, LOG_LEVEL_INF);

#include <zephyr/kernel.h>
#include <zephyr/cache.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/pm/device_runtime.h>
Expand All @@ -16,9 +17,11 @@ LOG_MODULE_REGISTER(idle_pwm_led, LOG_LEVEL_INF);
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led), gpios);
static const struct pwm_dt_spec pwm_led = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0));


#define PWM_STEPS_PER_SEC (50)

#define SHM_START_ADDR (DT_REG_ADDR(DT_NODELABEL(cpuapp_cpurad_ipc_shm)))
volatile static uint32_t *shared_var = (volatile uint32_t *) SHM_START_ADDR;
#define HOST_IS_READY (1)
#define REMOTE_IS_READY (2)

int main(void)
{
Expand Down Expand Up @@ -71,9 +74,36 @@ int main(void)

LOG_INF("Multicore idle_pwm_led test on %s", CONFIG_BOARD_TARGET);
LOG_INF("Core will sleep for %d ms", CONFIG_TEST_SLEEP_DURATION_MS);
LOG_INF("Shared memory at %p", (void *) shared_var);

#if defined(CONFIG_PM_DEVICE_RUNTIME)
pm_device_runtime_enable(pwm_led.dev);
pm_device_runtime_enable(pwm_led.dev);
#endif

/* Synchronize Remote core with Host core */
#if !defined(CONFIG_TEST_ROLE_REMOTE)
LOG_DBG("HOST starts");
*shared_var = HOST_IS_READY;
sys_cache_data_flush_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("HOST wrote HOST_IS_READY: %u", *shared_var);
while (*shared_var != REMOTE_IS_READY) {
k_msleep(1);
sys_cache_data_invd_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("shared_var is: %u", *shared_var);
}
LOG_DBG("HOST continues");
#else
LOG_DBG("REMOTE starts");
while (*shared_var != HOST_IS_READY) {
k_msleep(1);
sys_cache_data_invd_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("shared_var is: %u", *shared_var);
}
LOG_DBG("REMOTE found that HOST_IS_READY");
*shared_var = REMOTE_IS_READY;
sys_cache_data_flush_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("REMOTE wrote REMOTE_IS_READY: %u", *shared_var);
LOG_DBG("REMOTE continues");
#endif

#if defined(CONFIG_COVERAGE)
Expand Down
7 changes: 7 additions & 0 deletions tests/benchmarks/multicore/idle_pwm_loopback/remote/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ config TEST_SLEEP_DURATION_MS
Based on the value of 'min-residency-us' specified for each power state defined in the DTS,
core enters the lowest possible power state.

config TEST_ROLE_REMOTE
bool "Execute test variant for Remote core"
default y
help
KConfig used in synchronization phase.
Set TEST_ROLE_REMOTE=y on core that shall synchronize with the Host core.

source "Kconfig.zephyr"
33 changes: 33 additions & 0 deletions tests/benchmarks/multicore/idle_pwm_loopback/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
LOG_MODULE_REGISTER(idle_pwm_loop, LOG_LEVEL_INF);

#include <zephyr/kernel.h>
#include <zephyr/cache.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/pm/device_runtime.h>
Expand All @@ -21,6 +22,11 @@ LOG_MODULE_REGISTER(idle_pwm_loop, LOG_LEVEL_INF);
#error "Unsupported board: pwm_to_gpio_loopback node is not defined"
#endif

#define SHM_START_ADDR (DT_REG_ADDR(DT_NODELABEL(cpuapp_cpurad_ipc_shm)))
volatile static uint32_t *shared_var = (volatile uint32_t *) SHM_START_ADDR;
#define HOST_IS_READY (1)
#define REMOTE_IS_READY (2)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led), gpios);

static const struct gpio_dt_spec pin_in = GPIO_DT_SPEC_GET_BY_IDX(
Expand Down Expand Up @@ -133,6 +139,7 @@ int main(void)
LOG_INF("GPIO loopback at %s, pin %d", pin_in.port->name, pin_in.pin);
LOG_INF("Pulse/period: %u/%u usec", pulse / 1000, pwm_out.period / 1000);
LOG_INF("Expected number of edges in 1 second: %u (+/- %u)", edges, tolerance);
LOG_INF("Shared memory at %p", (void *) shared_var);
LOG_INF("===================================================================");

ret = pwm_is_ready_dt(&pwm_out);
Expand Down Expand Up @@ -162,6 +169,32 @@ int main(void)

k_timer_init(&my_timer, my_timer_handler, NULL);

/* Synchronize Remote core with Host core */
#if !defined(CONFIG_TEST_ROLE_REMOTE)
LOG_DBG("HOST starts");
*shared_var = HOST_IS_READY;
sys_cache_data_flush_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("HOST wrote HOST_IS_READY: %u", *shared_var);
while (*shared_var != REMOTE_IS_READY) {
k_msleep(1);
sys_cache_data_invd_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("shared_var is: %u", *shared_var);
}
LOG_DBG("HOST continues");
#else
LOG_DBG("REMOTE starts");
while (*shared_var != HOST_IS_READY) {
k_msleep(1);
sys_cache_data_invd_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("shared_var is: %u", *shared_var);
}
LOG_DBG("REMOTE found that HOST_IS_READY");
*shared_var = REMOTE_IS_READY;
sys_cache_data_flush_range((void *) shared_var, sizeof(*shared_var));
LOG_DBG("REMOTE wrote REMOTE_IS_READY: %u", *shared_var);
LOG_DBG("REMOTE continues");
#endif

#if defined(CONFIG_COVERAGE)
printk("Coverage analysis enabled\n");
while (test_repetitions--)
Expand Down

0 comments on commit 9536f3f

Please sign in to comment.