power-performance
npx machina-cli add skill beriberikix/zephyr-agent-skills/power-performance --openclawZephyr Power & Performance
Maximize the efficiency of your embedded system by balancing power consumption and computational performance.
Core Workflows
1. Power Management (PM)
Implement system-level and peripheral-specific power saving strategies.
- Reference: power_management.md
- Key Tools:
pm_device_action_run,pm_state_set, Residency hooks.
2. Performance Tuning
Optimize critical code paths and monitor system resources.
- Reference: performance_tuning.md
- Key Tools:
CONFIG_THREAD_ANALYZER, Linker Map, Code relocation.
3. Memory Optimization
Relocate code and data to utilize the fastest memory available.
- Reference: performance_tuning.md
- Key Tools:
__ramfunc, Relocation scripts.
Quick Start (Device Suspend)
#include <zephyr/pm/device.h>
const struct device *spi0 = DEVICE_DT_GET(DT_NODELABEL(spi0));
void sleep_spi(void) {
pm_device_action_run(spi0, PM_DEVICE_ACTION_SUSPEND);
}
Professional Patterns (Optimization)
- Aggressive Suspend: Transition peripherals to low-power states as soon as their transaction is complete.
- ITCM/DTCM: Use Tightly Coupled Memory for time-critical control loops to avoid Flash latency.
- Runtime Monitoring: Always enable the thread analyzer during development to find the "RAM floor" for your application.
- Coordinated Sleep: To coordinate sleep across modules, see Zbus for event-driven power management.
Resources
- References:
power_management.md: System states, device PM, and hooks.performance_tuning.md: Optimization strategies and relocation.
Source
git clone https://github.com/beriberikix/zephyr-agent-skills/blob/main/skills/power-performance/SKILL.mdView on GitHub Overview
Maximize efficiency by balancing power consumption and computational performance in Zephyr RTOS. This skill covers system power states (Idle, Suspend, Off), device-level power management, residency hooks, and code/data relocation to speed up critical paths, helping reduce battery drain, latency, and memory pressure.
How This Skill Works
It combines system-wide and peripheral Power Management using APIs like pm_device_action_run and pm_state_set with residency hooks, plus performance tuning through CONFIG_THREAD_ANALYZER, linker maps, and code relocation. Memory optimization relocates code/data to the fastest memory with __ramfunc and relocation scripts to accelerate hot paths.
When to Use It
- Optimizing battery life on battery-powered embedded devices
- Reducing latency in time-critical control loops
- Addressing tight memory constraints with code/data relocation
- Coordinating sleep across multiple modules for deeper power savings
- During development to identify RAM usage and optimize hotspots with thread analyzer
Quick Start
- Step 1: #include <zephyr/pm/device.h> and obtain a device handle (e.g., const struct device *spi0 = DEVICE_DT_GET(DT_NODELABEL(spi0));)
- Step 2: Implement suspend for the device using the snippet: void sleep_spi(void) { pm_device_action_run(spi0, PM_DEVICE_ACTION_SUSPEND); }
- Step 3: Enable runtime monitoring and relocation for hot paths (enable CONFIG_THREAD_ANALYZER and set up code relocation to RAM)
Best Practices
- Aggressive Suspend: move peripherals to low-power states as soon as their transactions complete
- ITCM/DTCM: place time-critical control loops in tightly coupled memory to avoid Flash latency
- Runtime Monitoring: enable the thread analyzer during development to locate the RAM floor
- Coordinated Sleep: use Zbus for event-driven, cross-module power management
- Memory Relocation: relocate hot code/data to RAM using __ramfunc and relocation scripts
Example Use Cases
- Suspend a SPI peripheral when idle using pm_device_action_run(spi0, PM_DEVICE_ACTION_SUSPEND) as shown in the quick start
- Move latency-sensitive control loops into ITCM/DTCM to bypass Flash latency
- Enable CONFIG_THREAD_ANALYZER during development to identify RAM footprint and optimize usage
- Place critical functions in RAM with __ramfunc to improve ISR response times
- Coordinate sleep across modules with Zbus for efficient event-driven power management