Re: Seeking Assistance: Implementing USB Device Suspend/Resume in User Space Driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 7, 2024 at 7:50 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, May 07, 2024 at 05:14:25PM +0530, Muni Sekhar wrote:
> > Thank you, it is very helpful.
> >
> > To verify the USB device suspend\resume functionality, I configured
> > the USB Power Management variables as follows:
> >
> > # cat /sys/bus/usb/devices/2-1.7/power/wakeup
> > enabled
> >
> > # cat /sys/bus/usb/devices/2-1.7/power/control
> > on
>
> This means that the device will be permanently on, and so it will never
> be suspended.  If you want to allow the device to be suspended, you
> have to write "auto" to the file.
Thanks a lot for these inputs.
Now, I can verify USB device auto-suspend and auto-resume through the
kernel log.

In my test system, I found three buses "Bus 001, 002, and 003" using
the lsusb command.

The USB device I want to test is located on "Bus 002".


# lsusb | grep "Bus 002" | wc
      4      37     224

As per the output of the above command, there are 4 USB devices on
"Bus 002" in my test system.


# ls -l /sys/bus/usb/devices/2*
lrwxrwxrwx 1 root root 0 Feb 14 14:48 /sys/bus/usb/devices/2-0:1.0 ->
../../../devices/pci0000:00/0000:00:14.0/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1 ->
../../../devices/pci0000:00/0000:00:14.0/usb2/2-1
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1.1 ->
../../../devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.1
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1:1.0 ->
../../../devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1.1:1.0
-> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.1/2-1.1:1.0
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1.7 ->
../../../devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.7
lrwxrwxrwx 1 root root 0 May  7 13:16 /sys/bus/usb/devices/2-1.7:1.0
-> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1.7/2-1.7:1.0

# ls -l /sys/bus/usb/devices/2* | wc
      7      77     892


The above command shows seven nodes in /sys/bus/usb/devices/2* directory.

The wakeup, control, and autosuspend_delay_ms attribute files are
controlled via /sys/bus/usb/devices/.../power/, where "..." represents
the device's ID.

I identified my test device in /sys/bus/usb/devices/.../power/ by
iterating through all the directories, reading the idVendor attribute
file, and then manipulating the power management attribute files.

Is there a way to manually map /sys/bus/usb/devices/.../power/ from
the lsusb output? Can this mapping be done from a user space program
as well? Do you have any reference examples for this? If so, could you
share their GitHub location?


>
> > # cat /sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms
> > 0
> >
> > # cat /sys/module/usbcore/parameters/autosuspend
> > 2
> >
> >
> > So, I configured the system to autosuspend the USB device as soon as
> > it becomes idle, with no transactions running through the USB device.
> > Now, how can I verify that the USB device has entered suspend mode
> > from user space? When checking /var/log/kern.log, there are no
> > relevant print statements. Are there any other log files related to
> > power management or USB subsystems?
> > Please correct me if anything in the test procedure mentioned above is
> > incorrect.
>
> You can see the device's current state by reading the
> power/runtime_status attribute file in sysfs.  There are lots of other
> informative files in that directory; you should look at them.
>
> If you want to get more debugging information in the kernel log, you can
> enable dynamic debugging for usbcore:
>
>         echo module usbcore =p >/sys/kernel/debug/dynamic_debug/control
>
> Alan Stern



-- 
Thanks,
Sekhar





[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux