Skip to main content

TECH VEDA

Corporate on-site training - Submit proposal Pick your modulesSharpen your kernel skills: deep dives, drivers, Yocto, CVEs, careers — updated daily. Read the blog →
Edge AI

NPU Runtime PM on RK3588: Why Inference Slows After Idle and How to Measure It

NPU runtime PM on RK3588: what an inference after an idle gap waits for, how to trace it with rpm and regulator events, and how to tune the autosuspend delay.

NPU Runtime PM on RK3588: Why Inference Slows After Idle and How to Measure It

On an RK3588 running the mainline rocket driver, each NPU core is allowed to runtime-suspend 50 ms after its last job completes. As each core suspends, the generic power domain code can switch off that core’s power domain. Once all three are suspended, it can switch off the shared NPU domains and, on boards such as the Rock 5B, the NPU supply rail. The next inference waits while all of that powers back up, before the NPU executes anything. This article shows how to see each step of NPU runtime PM in sysfs, debugfs and ftrace, and how to measure its cost on your board.

A vision pipeline on an RK3588 board gives steady inference times at 30 frames per second. Drop to a few frames per second, or switch to motion-triggered capture, and the same model can become slower per inference. The model, the Mesa delegate and the input did not change. The idle time between jobs did, and NPU runtime PM in the kernel acts on it. This article covers the mainline rocket accel driver on RK3588 at Linux 6.18, 7.3 and 7.4-rc3, with the Rock 5B device tree as the board example. Rockchip’s out-of-tree rknpu driver is not covered.

Where NPU runtime PM turns the hardware off

NPU runtime PM on this SoC is three layers acting in sequence. Each one is visible separately, and the diagnosis depends on knowing which layer you are looking at.

The driver. The device tree describes the NPU as three platform devices, one per core, npu@fdab0000, npu@fdac0000 and npu@fdad0000, each with its own IOMMU. rocket_core_init() opts each core in to autosuspend. This is v7.4-rc3; the 50 ms value is the same at v6.18 and v7.3:

	pm_runtime_use_autosuspend(dev);

	/*
	 * As this NPU will be most often used as part of a media pipeline that
	 * ends presenting in a display, choose 50 ms (~3 frames at 60Hz) as an
	 * autosuspend delay as that will keep the device powered up while the
	 * pipeline is running.
	 */
	pm_runtime_set_autosuspend_delay(dev, 50);

The job path holds the device active only while a job is in flight. rocket_job_run(), the scheduler’s run-job callback, takes a runtime PM reference before it attaches the IOMMU domain and starts the hardware: pm_runtime_resume_and_get() at v7.3 and v7.4-rc3, pm_runtime_get_sync() at v6.18. The completion interrupt handler calls pm_runtime_mark_last_busy() and then pm_runtime_put_autosuspend(), which starts the 50 ms timer. The runtime PM core arms it with up to 25 percent slack, so suspend starts between 50 and about 62 ms after completion. The driver’s suspend callback then gates its clocks.

The power domains. In rk3588-base.dtsi, core 0 and its IOMMU sit in RK3588_PD_NPUTOP. Cores 1 and 2, with their IOMMUs, sit in RK3588_PD_NPU1 and RK3588_PD_NPU2, children of NPUTOP, which is itself a child of RK3588_PD_NPU. The Rockchip driver registers these genpd domains with no governor and with GENPD_FLAG_PM_CLK, so genpd also stops and starts every clock in each device’s node. Without a governor, genpd powers a domain off as soon as every device in it is suspended and every child domain is off. The domains therefore go down from the leaves: NPU1 and NPU2 after their core and IOMMU suspend, then NPUTOP, then NPU.

The supply rail. The Rockchip driver marks the RK3588 npu domain as needing a regulator, and the Rock 5B device tree supplies one:

&pd_npu {
	domain-supply = <&vdd_npu_s0>;
};

When that domain powers off, rockchip_pd_power_off() calls regulator_disable() on vdd_npu_s0. When it powers on, rockchip_pd_power_on() enables the regulator first and the domain second. On the Rock 5B, vdd_npu_s0 is an RK8602 converter on I2C1, and its node carries regulator-enable-ramp-delay = <500>. The regulator core reads that property as the rail’s enable time and waits for it after switching the regulator on. The npu-supply and sram-supply properties on the core nodes are not read by the rocket driver, so the domain is the only consumer the driver path itself adds.

The resume path is longer than the suspend path suggests. A job that reaches a fully idle NPU waits in the scheduler’s run-job path for a register write to the regulator over I2C and at least 500 µs of declared ramp time. It then waits for up to three domain power-on sequences, two for core 0, and for the core’s clocks. One of them, SCMI_CLK_NPU, is shared by all three cores and provided through SCMI, so when no other core holds it, enabling it is a request to firmware. The inference runtime counts this NPU runtime PM work as inference time and does not report it separately.

When the 50 ms autosuspend delay is crossed

The timer starts at job completion and runs per core. What matters is each core’s idle gap: the time from its last completion interrupt to the next job placed on it. If every job went to one core, 30 frames per second with a 15 ms inference would leave an 18 ms gap and the core would never suspend. At 10 frames per second the gap would be about 85 ms, and every frame would find a suspended core. Motion-triggered inference is usually in the second case.

Jobs do not always go to one core. The rocket driver gives each open file a scheduler entity listing all cores. When the entity’s queue is empty, drm_sched_entity_select_rq() picks a core again by load score, and an idle entity still counts against the core it last used. Reading the v7.4-rc3 scheduler code, one process submitting one job at a time should alternate between two cores, so each core’s gap is about twice the frame interval minus the inference time: about 52 ms at 30 frames per second, at the delay. Check the placement with the drm_sched_job_run trace event below before tuning. NPU runtime PM state is per core, and that decides which submissions wait for a resume.

Reading the NPU runtime PM state on the board

Start with the driver binding and the per-core NPU runtime PM attributes. Device names come from the unit address and node name.

root@rock-5b:~# ls /sys/bus/platform/drivers/rocket/
root@rock-5b:~# grep -H . /sys/bus/platform/devices/fdab0000.npu/power/{control,runtime_status,autosuspend_delay_ms}
root@rock-5b:~# for d in fdab0000 fdac0000 fdad0000; do grep -H . /sys/bus/platform/devices/$d.npu/power/runtime_status; done

With nothing running, expect control to read auto, autosuspend_delay_ms to read 50, and runtime_status to read suspended on every core; active cores read active during a run. Any other delay means user space, such as a udev rule, or a patched kernel changed it.

Next, the domains. The genpd debugfs directories use the Rockchip domain names npu, nputop, npu1 and npu2.

root@rock-5b:~# mountpoint -q /sys/kernel/debug || mount -t debugfs none /sys/kernel/debug
root@rock-5b:~# for p in npu nputop npu1 npu2; do echo "$p: $(cat /sys/kernel/debug/pm_genpd/$p/current_state)"; done
root@rock-5b:~# cat /sys/kernel/debug/pm_genpd/nputop/devices
root@rock-5b:~# cat /sys/kernel/debug/pm_genpd/npu/idle_states

current_state reads on, or off-0 when the domain is off. The devices file for nputop should list core 0 and its IOMMU. The Usage column in idle_states counts power-offs: if it rises by about one per inference, every inference waited for a full power-up from the rail upwards.

Then the rail. Find the regulator by name and read num_users, the number of consumers that have it enabled: 1 while the NPU domain is on, 0 when it is off. The state file exists only if the regulator driver can report it.

root@rock-5b:~# r=$(dirname $(grep -l vdd_npu_s0 /sys/class/regulator/*/name)); grep -H . $r/state $r/num_users $r/microvolts

Timing the resume with ftrace

Sysfs shows NPU runtime PM states; ftrace shows their cost. The rpm events carry the device name, so one subsystem filter limits them to the NPU and IOMMU devices, whose names start with fda. The regulator events mark when the rail was switched on and when the wait for it ended. drm_sched_job_run names each job’s core in its dev= field.

root@rock-5b:~# mountpoint -q /sys/kernel/tracing || mount -t tracefs none /sys/kernel/tracing
root@rock-5b:~# echo 'name ~ "fda*"' > /sys/kernel/tracing/events/rpm/filter
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/rpm/rpm_resume/enable
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/rpm/rpm_suspend/enable
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/rpm/rpm_return_int/enable
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/gpu_scheduler/drm_sched_job_run/enable
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/regulator/regulator_enable/enable
root@rock-5b:~# echo 1 > /sys/kernel/tracing/events/regulator/regulator_enable_complete/enable
root@rock-5b:~# echo > /sys/kernel/tracing/trace

Leave the NPU idle for a second, run one inference, and then read the trace:

root@rock-5b:~# cat /sys/kernel/tracing/trace

For a cold submission, expect rpm_resume for an NPU core, then rpm_resume for its IOMMU. The IOMMU resumes first as a device-link supplier and shares the core’s domain, so its resume powers the domains, and the regulator_enable and regulator_enable_complete lines for vdd_npu_s0 appear inside it. The IOMMU’s rpm_return_int follows, then the core’s. The time between the core’s rpm_resume and its rpm_return_int is the wait for power on your board. With the NPU kept busy, the regulator lines disappear.

For the end-to-end figure, use a test program that loads the model once and runs single inferences separated by a configurable sleep, timing each. Sweep the sleep from 0 to 100 ms in 5 ms steps, then 200 and 1000 ms, recording drm_sched_job_run so each sample is tied to a core. Expect a smaller step when the core in use has been idle for 50 ms, and a larger one when all cores have, which includes the rail. Starting a new process per inference does not work: model load would dominate every sample.

Changing the NPU runtime PM delay without patching the driver

The delay can be tested before anything is rebuilt. Set it on all three cores, because the scheduler can use any of them:

root@rock-5b:~# for d in fdab0000 fdac0000 fdad0000; do echo 200 > /sys/bus/platform/devices/$d.npu/power/autosuspend_delay_ms; done

A negative value prevents runtime suspend. Writing on to control calls pm_runtime_forbid(), which takes a usage reference and resumes the device, so it stays powered until you write auto. The ABI document says delays of 1000 ms or more are rounded up to a second; the v7.4-rc3 code does not round, but applies up to 25 percent slack to any delay.

To make a chosen delay persistent, a udev rule that matches devices bound to the rocket driver can write the attribute after probe, when autosuspend is already enabled. Match both events: add covers the coldplug replay at boot when the driver is built in, and bind covers a module loaded after udev has started. Place it in /etc/udev/rules.d/70-rocket-npu-pm.rules, or install it from a Yocto or Buildroot package:

ACTION=="add|bind", SUBSYSTEM=="platform", DRIVER=="rocket", ATTR{power/autosuspend_delay_ms}="200"

After a reboot, confirm that it took effect on all three cores:

root@rock-5b:~# grep -H . /sys/bus/platform/devices/fda{b,c,d}0000.npu/power/autosuspend_delay_ms

Choose the value from measured idle gaps: long enough for the longest gap that needs warm-start latency, and no longer, because the domains and the rail stay powered while nothing runs.

Common wrong turns

Blaming the model or the delegate. The slow inference follows a pause, which looks like a runtime warm-up effect, and runtimes do one-time work after a model is loaded. The sleep sweep separates the two: a warm-up happens once per load, while an NPU runtime PM cost returns after every gap longer than the delay.

Reading the genpd latency columns as the answer. idle_states_desc has a column headed Latency(us), so it looks like the measured cost. On these domains it reads 0, and that is not a measurement. Genpd only times power-on and power-off when the domain has a governor, and the Rockchip driver registers its domains without one. Use ftrace instead.

Treating an I/O error as “no runtime PM”. An error from a power attribute looks like proof that the device has no runtime PM. In fact autosuspend_delay_ms returns EIO whenever the driver has not called pm_runtime_use_autosuspend(). The Rockchip IOMMU uses runtime PM without autosuspend, so expect the error on fdab9000.iommu while its runtime_status reads active or suspended. The error itself looks like this, captured on an x86-64 virtual machine running Linux 6.18.44:

raghu@techveda.org:~$ cat /sys/bus/platform/devices/serial8250/power/autosuspend_delay_ms
cat: /sys/bus/platform/devices/serial8250/power/autosuspend_delay_ms: Input/output error
raghu@techveda.org:~$ cat /sys/bus/platform/devices/serial8250/power/runtime_status
unsupported

On that machine unsupported means runtime PM is disabled for the device, which is not the case for the IOMMU. The IOMMU follows its core through a device link created with DL_FLAG_PM_RUNTIME.

Pinning one core. This is attractive because one sysfs write removes the rail ramp from the path at once. Writing on to core 0’s control keeps NPUTOP, the NPU domain and the rail on. Cores 1 and 2 still suspend and their leaf domains still power off, and pinning does not change where jobs are placed. Jobs on another core still wait for a partial resume, so the timing improves but is not flat, and the spread looks like noise.

Verification checklist

  1. ls /sys/bus/platform/drivers/rocket/ lists fdab0000.npu, fdac0000.npu and fdad0000.npu.
  2. autosuspend_delay_ms on each of the three cores reads the value you chose, after a reboot, not only after a manual write.
  3. With the pipeline running at its slowest real frame rate, the Usage count in /sys/kernel/debug/pm_genpd/npu/idle_states stops rising.
  4. The ftrace capture taken during that run shows no regulator_enable line for vdd_npu_s0 between inferences.
  5. The sleep sweep shows flat per-inference timing up to your longest real idle gap.
  6. After the pipeline stops, all four domains read off-0 in current_state within about 1.25 times the delay, so idle power is still saved.

Key takeaways

  • In the mainline rocket driver, NPU runtime PM suspends each core 50 ms after its last job, at v6.18, v7.3 and v7.4-rc3.
  • Genpd powers the NPU domains off from the leaves up; on the Rock 5B the top domain switches off vdd_npu_s0, which declares a 500 µs enable ramp.
  • The resume happens in the scheduler’s run-job path; the inference runtime counts it as inference time without reporting it separately.
  • Measure it with rpm and regulator trace events, not genpd’s latency columns, and tune autosuspend_delay_ms on all three cores.

Reading a driver’s runtime PM calls, its power domain tree and its regulator path together is the kind of work covered in TECH VEDA’s Linux Device Drivers training.

Was this worth your time?

Frequently asked questions

What is the default NPU autosuspend delay in the mainline rocket driver?
50 ms for each of the three RK3588 NPU cores, at Linux 6.18, 7.3 and 7.4-rc3. It can be changed at runtime through power/autosuspend_delay_ms.

Why does reading autosuspend_delay_ms on the NPU IOMMU give an I/O error?
The file returns EIO when the driver has not enabled autosuspend. The Rockchip IOMMU uses runtime PM without autosuspend, and follows its NPU core through a device link.

Is keeping one NPU core powered enough to avoid the NPU runtime PM resume cost?
No. It keeps the top NPU domains and the supply rail on, but the other cores still suspend and the scheduler can still place jobs on them. Set the delay on all three cores.

References

RB
Raghu Bharadwaj

Founder, TECH VEDA — 20+ years teaching the Linux kernel, device drivers and embedded systems.

Follow on LinkedIn

Get new posts by email

Kernel, embedded Linux and AI-era engineering — a few sharp reads a month. No spam.

We email occasionally and never share your address.