Email WhatsApp
WeChat
WeChat QR

Table of Contents

USB Autosuspend on Linux

Linux exposes USB autosuspend through a device’s power/control file. Writing on there keeps that device out of runtime suspend, which gives you a way to check whether its trouble starts when it tries to wake up.

A USB camera on a KiwiPi 5 Pro might work as soon as you plug it in and fail when the capture service opens it again after a quiet period. A USB serial adapter can do something similar. Before changing anything, find the USB device in sysfs and check whether Linux has even allowed it to autosuspend.

KiwiPi 5 Pro board with USB ports on the cover of a Linux autosuspend guide
KiwiPi 5 Pro is the single-board computer used as the hardware example.

Find the device that drops off

Compare the USB tree and kernel log

Start a kernel log in one terminal and leave it running while you repeat the failure. Run lsusb and the tree view in another. Save what the tree looks like before and after the idle period. A disconnect followed by a new device number says the device re-enumerated, which can happen after a power or link problem too.

lsusb
lsusb -t
sudo journalctl -kf

If the device stays in the tree and only the application stops reading it, check the application’s log as well. On a KiwiPi single-board server, a service that closes a camera between captures and opens it again gives you a repeatable idle interval. Use that same interval in both parts of the test. Reconnecting the cable every time changes the conditions before you’ve recorded the failure.

Identify the sysfs device

A message like usb 2-1: points to a device directory called 2-1. Use the value from your own log. The suffix in 2-1:1.0 identifies a USB interface, so use the parent device directory for the commands below. Compare the vendor and product IDs with lsusb first, especially when a hub has several peripherals attached.

Official top-down photo of the KiwiPi 5 Pro showing its USB connectors
KiwiPi 5 Pro, view from above. Use the kernel log to match a connected peripheral to its USB device path.

Test autosuspend on one device

Read the policy and runtime state

Replace 2-1 in the example with the path you verified. auto allows runtime power management. A nonnegative autosuspend_delay_ms is an idle delay in milliseconds. A negative delay prevents autosuspend, even with auto. The runtime status tells you what the kernel sees at that instant. Reading active after reopening the camera tells you little about what happened while it was idle.

dev=/sys/bus/usb/devices/2-1
cat "$dev/idVendor" "$dev/idProduct"
cat "$dev/power/control" "$dev/power/runtime_status"
cat "$dev/power/autosuspend_delay_ms"

If power/control is already on at the point of failure, start with the connection and the application’s logs. A reset during sustained reads or writes is also reason to check the cable and supply. The KiwiPi 5 Pro power guide explains the board’s input requirements. A powered hub can help isolate a bus-power problem, provided you record that as a separate test.

Repeat the same idle cycle

If the device allows autosuspend, save the existing policy, write on, then repeat the same idle cycle and workload. Leave the cable and hub alone for this pass. If the device vanishes or you unplug it, identify it again before using the path. Run the restore command after the test in the same shell, with the same device still present.

previous=$(cat "$dev/power/control")
printf 'on\n' | sudo tee "$dev/power/control"
# Repeat the workload and idle cycle before restoring.
printf '%s\n' "$previous" | sudo tee "$dev/power/control"
Observation What to check next
Works after idle with on, fails with auto Repeat the comparison on the same USB path
Drops during a continuous transfer with both settings Try a known-good cable or powered hub separately
Still listed, application stops reading Review application and driver logs
PCIe NVMe fails to appear Follow the Linux NVMe detection guide

Keep a confirmed change

Scope the setting to the peripheral

A sysfs write is a live setting, so it may disappear on replug or reboot. If several runs point to the device’s resume behaviour, and the extra idle power is acceptable, apply a device-specific udev rule. Match the USB device’s vendor and product IDs. If several identical adapters share those IDs, add their distinct serial number when available. Then verify the policy after replug or reboot and check whether a distro power profile writes a different value later. Save the rule under /etc/udev/rules.d/ using a local filename ending in .rules. In the example, substitute the actual hexadecimal IDs before use. Reload rules with sudo udevadm control --reload-rules, then reconnect the device when it’s safe to do so.

ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTR{idVendor}=="1234", ATTR{idProduct}=="5678", ATTR{power/control}="on"

FAQ

Does this prevent the whole board from sleeping?

The device’s power/control setting governs runtime power management. System sleep has its own path, so a problem that starts only after waking the whole board needs a separate check.

Can I apply this to every USB device?

A broad change affects devices that already resume correctly. A device-specific setting preserves the other policies and gives you a clearer comparison.

Is a USB reset proof of autosuspend?

A reset can follow a power or link fault as well. Compare the same idle period with only the peripheral’s policy changed and preserve the kernel log from both runs.

Sources

Related Products

Kiwipi-5Pro

KiwiPi 5 Pro

KiwiPi 5 Pro is powered by Rockchip RK3588 8-core 64-bit processor with 4 Cortex-A76 (2.2GHz), 4 Cortex-A55(1.8GHz), and an independent NEON coprocessor.

Get in Touch about Your Needs

Contact Us