
Recall first from DVFS and power domains
- CPUFreq governors select performance within policy limits, and scaling_cur_freq commonly reports the last frequency requested by the driver.
- An operating point can pair a supported frequency with the voltage required at that frequency.
- genpd can turn off a shared domain after its devices suspend and its other power constraints permit the transition.
Measure current at the board and at a rail
4 min readAll of this is only real if you can measure it and fix what breaks. This lesson answers per-rail measurement, the debugfs and powertop views, and the suspend hangs and wakeup storms that drain batteries.
The Linux kernel's power-management debugging guide describes suspend failures that occur during device handling or during the final transition into sleep. Both can leave you looking at a silent console. A current recording adds evidence during the interval when the console gives you little information. If current initially falls and then rises, note when the rise occurs and check whether Linux resumed. If current stays high, check whether entry stalled, the selected sleep mode has a higher current floor, or a circuit remained powered. Linux kernel power-management debugging guide
Start at the board's normal supply input. With power disconnected, put a multimeter in current mode in series with the supply, using the correct input jack and a range that can handle startup current. An ammeter placed across a supply can short it. The meter and its leads also introduce a voltage drop, called burden voltage. If the board resets or behaves differently with the meter inserted, check the voltage at the board under load before drawing conclusions. Keep the same supply and attached equipment across runs. A USB connection or powered peripheral can feed the board through a second path and cause the input meter to miss some of the current.
A handheld multimeter works for a steady sleeping plateau that lasts long enough to read. A logging power monitor records a time series and can show the entry dip, a burst during resume, and brief activity during the sleep interval. Choose a range that captures the peak while resolving the sleep current. Check the monitor's sampling rate and any averaging. A monitor that averages over the duration of a short pulse will report a smaller peak. Record voltage with current when it varies. At each sample, power is voltage times current. Summing power times each sample interval estimates the energy used over the run.
If board input current is high during sleep, use the schematic to identify which loads share each regulator output. A documented current-sense resistor, measurement jumper, or removable series link gives you a measurement point. With a known shunt, measure the voltage across it and divide by its resistance. With a documented removable link, disconnect power before replacing the link with an appropriately rated inline instrument. Check that the inserted resistance and peak voltage drop are acceptable for that rail. A voltage test point can tell you whether a rail remains energised. It takes a current measurement to tell you how much the load draws. Use the board input if there is no documented way to instrument the rail.
Keep input and output measurements at their own voltages. Adding the currents of two regulator outputs at different voltages does not give board input current. Compare power at each output with power at the input, allowing for regulator losses and any other loads. If a shared rail stays active, use the schematic to identify its consumers before attributing the entire reading to one device.
Begin recording while the board is running a known workload, then stop the workload and wait for the awake-idle current to settle. Record the suspend command and the wake stimulus against the monitor's timeline. A timestamped host console capture is useful. A spare GPIO wired to the monitor's trigger input can provide a more precise marker if the fixture supports it and the marker itself does not affect sleep. Measure active and awake-idle plateaus, the sleep plateau, the resume peak if your instrument resolves it, and the settled current after resume. Use comparable time windows across trials. For a battery-drain complaint, report the average over an interval long enough to include recurring wakeups and their active time.
Verify mem suspend with two independent wake events
3 min readRun the suspend commands on the lab board itself. A VM or WSL2 session can hold your notes and analyse exported traces. Its sleep interfaces describe the guest environment and cannot verify the board's rails or wake pins. Use a local console and save your work first. An SSH session can disappear as the network device suspends. Know how to recover the board if the programmed wake source fails.
cat /sys/power/state
cat /sys/power/mem_sleep
Look for mem in the first file. The brackets in mem_sleep identify the mode currently associated with mem. If the lab calls for deep and the file lists it, select it with printf '%s\n' deep | sudo tee /sys/power/mem_sleep and read the file back. If only s2idle is offered, label the trial as suspend-to-idle. If mem is absent, collect the board and kernel details and use a suspend-capable lab image or board for the remaining tests. Available modes and wake routes depend on the running kernel, firmware, and board configuration. Linux kernel system sleep states
Identify the RTC using the board configuration and the name files under /sys/class/rtc/. Use an alarm-capable RTC that can wake the selected sleep mode. Check for its wakealarm file. If its device exposes a power/wakeup control, record the original value and enable the wake policy for the test. On a board where the correct RTC is rtc0, the following commands clear any old lab alarm, set and read back a relative alarm, and request suspend only if those operations succeed. Reserve that RTC for the trial so clearing its alarm does not interfere with another service. Choose a longer delay if the board needs more time to enter sleep.
alarm=/sys/class/rtc/rtc0/wakealarm
printf '%s\n' 0 | sudo tee "$alarm" &&
printf '%s\n' +60 | sudo tee "$alarm" &&
cat "$alarm" &&
printf '%s\n' mem | sudo tee /sys/power/state
Check that the board remained in the low-current interval and resumed near the alarm deadline without a key press. Inspect the kernel log with sudo dmesg for suspend entry, resume, or an abort. The text echoed by tee only shows what it read from the pipeline. Use the command status, kernel log, and current trace to establish what happened. A returned prompt alone could mean either resume or failed entry.
For the GPIO trial, use the board's configured GPIO input key. It must have a wake route in the chosen sleep mode. A key that generates an input event while Linux is awake can still fail to wake a sleeping board. Locate the GPIO key device through the board configuration and its device in sysfs. If its power/wakeup file is present, record its original value, write enabled with sudo tee, and read it back. Check the board's wake configuration if the file is absent. Clear the alarm from the RTC trial and, if needed for recovery, set a new one well beyond the planned key press. Write mem again, wait for the current to settle, and press the key once. Confirm that resume follows the press and precedes any fallback alarm. Clear the lab alarm and restore wake settings at the end.
Find the cause of failed entry or high sleep current
4 min readUse the current trace to decide which Linux statistics to inspect first. For a stable but high sleep plateau, read the generic power-domain summary if your kernel and platform expose it. For repeated current rises, compare wakeup statistics over the trial. For high current while the board is awake and idle, inspect CPU idle residency before changing suspend settings.
mountpoint -q /sys/kernel/debug || sudo mount -t debugfs debugfs /sys/kernel/debug
sudo ls /sys/kernel/debug/pm_genpd
sudo cat /sys/kernel/debug/pm_genpd/pm_genpd_summary
sudo cat /sys/kernel/debug/wakeup_sources
Debugfs requires kernel support and access may be restricted. The pm_genpd directory is useful when the kernel exposes generic power domains. Its pm_genpd_summary lists domains, their reported state, and attached devices with runtime PM status. Read it during awake idle and after resume. If a domain remains on during awake idle, its devices and child domains give you places to look for activity or dependencies. The post-resume snapshot describes the resumed system. For the sleep interval itself, use the rail trace as evidence of electrical activity. A regulator can also remain enabled because it supplies other loads, even when Linux reports a particular domain off.
The wakeup_sources file lists registered kernel wakeup sources and their statistics. Capture it immediately before and after a suspect trial, matching rows by name and comparing counter deltas. event_count records events reported to a source. wakeup_count tracks events accounted as potentially aborting suspend while wakeup events are being checked. Neither counter is a complete count of physical wakeups. Compare the results with snapshots of /proc/interrupts, the kernel messages, and the timing of current bursts. An IRQ count can also rise after resume because a driver is doing ordinary work. Repeat with the same stimulus and change one wake setting at a time so the result is attributable.
On an Ubuntu board image with PowerTOP available, install it with sudo apt install powertop if needed and run sudo powertop. Let it sample an awake-idle interval. The Idle stats view shows the CPU idle residency the platform exposes. Limited time in deeper idle states alongside frequent wakeups in the Overview gives you a reason to check busy timers, processes, and devices before doing another run. Keep the workload and peripherals consistent and exit PowerTOP for the baseline current capture. CPU idle residency and wakeup rates are software observations. Use the meter or monitor for measured board current.
Going deeperExplore the mechanism
An unmasked wake-capable IRQ can drain a battery within hours if it repeatedly resumes the system and the active intervals dominate average current. With a level-triggered interrupt, a peripheral can hold the line asserted until the driver acknowledges the device's interrupt status. If the driver arms wake with that status still pending, the next suspend attempt can abort or resume almost immediately. If userspace retries suspend, the trace can show repeated dips and rises. Compare the electrical activity with counter deltas and kernel suspend messages. With a tested RTC fallback, temporarily disable wake for the suspect device through its power/wakeup control if supported. Repeat the same run. If the bursts stop, inspect the driver's handling of pending status, the interrupt trigger configuration, and whether wake stays armed when policy disables it. Re-enable the required wake path and verify both deliberate wake and stable sleep after the fix.
For an apparent hang, check /sys/power/pm_test if the kernel exposes it. The devices test exercises device suspend and resume without entering the final sleep state. Select devices with sudo tee, request mem, and check whether the test returns and what the kernel logged. Restore none before measuring actual suspend. A hang in this test narrows the investigation to work exercised in the test, including device callbacks. A successful test leaves later stages to investigate. Where tracing is available, the power:device_pm_callback_start and power:device_pm_callback_end trace events can identify a callback that started without a matching completion. Check the callback's phase before changing driver ordering. During suspend_noirq, normal device IRQ handlers have already been suspended, so code in that phase must avoid waiting for completion from one of those handlers. The absence of a suspend_noirq callback by itself is valid for many drivers. Investigate whether the hardware needs a specific operation at that stage. Linux kernel device power management
Keep the successful trace, selected sleep mode, wake configuration, and kernel build together with the results. The next lesson, Why and how to rebase a BSP, explains how to move board support to a newer baseline. These measurements give you repeatable checks for suspend entry, both wake routes, and sleep current after that change.
Key takeaways
- A logging power monitor can show brief wakeups that a handheld meter may miss.
- Board input current and regulator output current describe different measurement boundaries.
- The selected mem_sleep mode determines what writing mem requests.
- Power-domain status and wakeup counters help identify what to measure and test next.
Reflect
- Explain to a colleague, in two sentences: measure board input current across active, idle, suspended, and resumed intervals.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- Kernel documentationSystem sleep states
- Kernel documentationBasic power management debugging
- Kernel documentationDevice power management basics
- Man pagertc(4): real-time clock devices
Official documentation first. Links checked when the lesson was published.