xmos / sw_usb_audio

XMOS USB Audio reference design
Other
32 stars 17 forks source link

Zero data in output stream from Thesycon driver. #132

Closed xross closed 1 year ago

xross commented 1 year ago

On a particular laptop (HP I7) glitching is experienced on the output stream using the Thesycon driver. This has been captured on a USB trace and shows runs of zeros in the data from the host. A USB trace was captured and converted to a wav for easy inspection.

During debugging it was noted that in the in Thesycon SpyTool the EmptyPackets counter was increasing. In the logs we do see errors - using the debug driver.

Interestingly when we enable “extra info” in the logs the issue goes away - no more glitches. This issue has been reported to Thesycon.

xross commented 1 year ago

Thesycon report that 0 "SYNC LOST" in the trace occurs when empty packets are sent to the host from the device. We are confident this is not the case and also this would not explain why turning on lost of tracing would make the issue immediately go away. Investigation continues.

xross commented 1 year ago

Further inspection of the USB traces by Thesycon show sections where the host is not requesting data from the device. no_data_2 no_data

Thesycon System Information (https://thesycon.de/tsi/TSI.exe) dump from the laptop in question:

tsi.log

Suggestions to resolve include disabling the ESET Antivirus "edevmon.sys" filter driver installed in the USB stack and disabling C-States. From thesycon:

"Another problem can be power management. This is a mobile platform. We've seen DMA issues on such systems in the past. You can try to disable C-States on this system. Call the attached tool with "ppmutil DisableC". This changes the power scheme. But be aware that can lead to a higher power consumption of the system."

xross commented 1 year ago

Disabling antivirus and c-states in the bios does not work-around the issue. Uninstalling the Thesycon driver and using the built-in UAC2.0 driver works fine.

xross commented 1 year ago

Thesycon have provided an updated driver (v5.57.0). This uses a larger USB buffer by default. It seems to resolve the issue on the problematic laptop(s) at 44.1/48kHz but we still see occasional glitching at 192kHz.

xross commented 1 year ago

This issues relates to the hardware of the Lenovo test laptop, in particular it relates to "PCIe Link State Power Management" which is a power saving feature at the PCIe level. If it's enabled, it increases DMA latency for the XHCI which leads to the issue we observed.

Normally, in a vanilla Windows installation, there are multiple power profiles available including "Balanced" and "High Performance". For some reason, on the test Lenovo laptop there is only one profile available: Balanced. In the Balanced profile, PCIe Link State Power Management is enabled by default while in High Performance it is disabled.

You can re-activate the High Performance profile by executing powercfg /s SCHEME_MIN from an elevated command prompt. See also: https://thegeekpage.com/restore-missing-high-performance-power-plan/

When we do this and then switch to the High Performance power plan, the issue goes away. It comes back if we switch back to Balanced.

Normally there is an advanced settings dialog available which enables the user to tweak this setting per power plan. For some reason, on this Lenovo machine there is no such setting in this dialog. We have been able to re-activate the advanced setting by following the instructions from this article: https://www.tenforums.com/tutorials/100629-remove-link-state-power-management-power-options-windows-10-a.html

If you download and execute the Add_Link_State_Power_Management_to_Power_Options.reg file referenced there, this makes the Link State Power Management option available in the plan settings. If you toggle this setting between "Maximum power savings" and "Off", the issue appears/disappears.

Conclusion: On this system, Lenovo went too far with power saving optimizations. They enabled aggressive PCIe power management by default, removed the High Performance power plan and also removed the advanced settings option, so that the user is not able to adjust this setting.