From 031ff08bc665d864e667c6d53e10cae734d4357f Mon Sep 17 00:00:00 2001 From: Keith Short Date: Mon, 25 Oct 2021 14:51:53 -0600 Subject: [PATCH] tests: benchmark: Add power management to footprint Add a build-only test to track footprint when enabling device power management. Signed-off-by: Keith Short --- tests/benchmarks/footprints/CMakeLists.txt | 3 +- tests/benchmarks/footprints/prj_pm.conf | 9 +++ tests/benchmarks/footprints/src/main.c | 5 ++ tests/benchmarks/footprints/src/pm_device.c | 67 +++++++++++++++++++++ tests/benchmarks/footprints/testcase.yaml | 4 ++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 tests/benchmarks/footprints/prj_pm.conf create mode 100644 tests/benchmarks/footprints/src/pm_device.c diff --git a/tests/benchmarks/footprints/CMakeLists.txt b/tests/benchmarks/footprints/CMakeLists.txt index cc20b10631b..094feeb1241 100644 --- a/tests/benchmarks/footprints/CMakeLists.txt +++ b/tests/benchmarks/footprints/CMakeLists.txt @@ -4,9 +4,10 @@ cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(common_kernel_footprint) -FILE(GLOB app_sources src/[^u]*.c) +FILE(GLOB app_sources src/[^up]*.c) target_sources(app PRIVATE ${app_sources}) target_sources_ifdef(CONFIG_USERSPACE app PRIVATE src/userspace.c) +target_sources_ifdef(CONFIG_PM_DEVICE app PRIVATE src/pm_device.c) target_include_directories(app PRIVATE ${ZEPHYR_BASE}/kernel/include diff --git a/tests/benchmarks/footprints/prj_pm.conf b/tests/benchmarks/footprints/prj_pm.conf new file mode 100644 index 00000000000..4d829cde56f --- /dev/null +++ b/tests/benchmarks/footprints/prj_pm.conf @@ -0,0 +1,9 @@ +CONFIG_HEAP_MEM_POOL_SIZE=256 +CONFIG_MAIN_STACK_SIZE=2048 +CONFIG_MP_NUM_CPUS=1 +CONFIG_PM=y +CONFIG_PM_DEVICE=y +CONFIG_PM_DEVICE_RUNTIME=y +CONFIG_THREAD_NAME=y +CONFIG_LOG=y +CONFIG_LOG_MODE_MINIMAL=y diff --git a/tests/benchmarks/footprints/src/main.c b/tests/benchmarks/footprints/src/main.c index 6f6e4e35299..67c1ca3386f 100644 --- a/tests/benchmarks/footprints/src/main.c +++ b/tests/benchmarks/footprints/src/main.c @@ -30,6 +30,7 @@ struct k_thread my_thread_0; extern void run_heap_malloc_free(void); extern void run_libc(void); extern void run_mutex(void); +extern void run_pm_device(void); extern void run_semaphore(void); extern void run_thread_system(void); extern void run_timer(void); @@ -63,6 +64,10 @@ void main(void) run_workq(); +#ifdef CONFIG_PM_DEVICE + run_pm_device(); +#endif + #ifdef CONFIG_USERSPACE run_userspace(); #endif diff --git a/tests/benchmarks/footprints/src/pm_device.c b/tests/benchmarks/footprints/src/pm_device.c new file mode 100644 index 00000000000..7adbdb1b14e --- /dev/null +++ b/tests/benchmarks/footprints/src/pm_device.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Google, LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Stub driver to measure the footprint impact of power management + * + */ +#include +#include +#include + +#define DUMMY_PM_DRIVER_NAME "dummy_pm_driver" +#define DUMMY_DRIVER_NAME "dummy_driver" + +static int dummy_init(const struct device *dev) +{ + return 0; +} + +static int dummy_device_pm_ctrl(const struct device *dev, + enum pm_device_action action) +{ + return 0; +} + +/* Define a driver with and without power management enabled */ +DEVICE_DEFINE(dummy_pm_driver, DUMMY_PM_DRIVER_NAME, &dummy_init, + dummy_device_pm_ctrl, NULL, NULL, APPLICATION, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DEVICE_DEFINE(dummy_driver, DUMMY_DRIVER_NAME, &dummy_init, + NULL, NULL, NULL, APPLICATION, + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +void run_pm_device(void) +{ + const struct device *dev; + enum pm_device_state pm_state; + + /* Get the PM state from a device with PM support */ + dev = device_get_binding(DUMMY_PM_DRIVER_NAME); + if (pm_device_state_get(dev, &pm_state)) { + printk("\n PM device get state failed\n"); + return; + } + + if (pm_device_get(dev)) { + printk("\n PM device runtime get failed\n"); + return; + } + + if (pm_device_put(dev)) { + printk("\n PM device runtime put failed\n"); + return; + } + + /* Get the PM state from a device without PM support */ + dev = device_get_binding(DUMMY_DRIVER_NAME); + if (pm_device_state_get(dev, &pm_state) != ENOSYS) { + printk("\n PM device get state did not fail\n"); + return; + } +} diff --git a/tests/benchmarks/footprints/testcase.yaml b/tests/benchmarks/footprints/testcase.yaml index b465bf0f331..4653a54d41e 100644 --- a/tests/benchmarks/footprints/testcase.yaml +++ b/tests/benchmarks/footprints/testcase.yaml @@ -2,6 +2,10 @@ tests: benchmark.kernel.footprints.default: tags: benchmark build_only: true + benchmark.kernel.footprints.pm: + tags: benchmark + build_only: true + extra_args: CONF_FILE=prj_pm.conf benchmark.kernel.footprints.userspace: filter: CONFIG_ARCH_HAS_USERSPACE extra_args: CONF_FILE=prj_userspace.conf