Repository navigation
fix(monitorusb): replace hwinfo --usb with sysfs reading to eliminate ioctl audio stutter (PMS 381051) - #969
Closed
GongHeng2017 wants to merge 1 commit into
Closed
GongHeng2017 wants to merge 1 commit into
GongHeng2017 wants to merge 1 commit into
Conversation
… ioctl audio stutter Root cause (PMS 381051): On USB hot-plug events, MonitorUsb::monitor() spawned "hwinfo --usb" which opens every /dev/bus/usb/*/* node and issues ioctl(USBDEVFS_CONTROL) control transfers to read device descriptors. On affected xHCI controllers these control transfers stall isochronous audio URBs for ~970 ms, exceeding the ~93 ms PulseAudio buffer and causing audible playback stuttering. Fix: Replace the external hwinfo process with direct reads of /sys/bus/usb/devices/ attribute files (idVendor, idProduct, bDeviceClass, bInterfaceClass, etc.). Sysfs reads perform no USB I/O whatsoever, eliminating the control-transfer interference while producing a string in the same key:value format that EnableUtils::disableOutDevice() and WakeupUtils::updateWakeupDeviceInfo() already parse. The new getUsbInfoFromSysfs() function: - Enumerates device entries (skipping interfaces) under /sys/bus/usb/devices/ - Reads standard sysfs USB attributes (idVendor, idProduct, manufacturer, product, serial, bcdDevice, bDeviceClass/SubClass/Protocol, busnum, devnum, speed) - Derives hwinfo-compatible "Hardware Class" from bDeviceClass (hub) and HID interface class/subclass/protocol (keyboard/mouse) - Constructs SysFS Device Link and SysFS ID paths from canonical paths - Detects USB network adapters for Permanent HW Address / Device File - Builds Module Alias from device attributes - Emits >10 lines per device block (required by getMapInfo LEAST_NUM=10)
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideImplementationReplace the hotplug-time hwinfo process with sysfs enumeration, including its helpers and required includes, to avoid USB control transfers while preserving the information consumed downstream.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述 (PMS 381051)
在受影响的 xHCI 控制器上,USB 设备热插拔时会导致约 970ms 的音频卡顿。
根因分析
MonitorUsb::monitor()在检测到 USB add/remove 事件时,同步执行hwinfo --usb。hwinfo 会打开所有/dev/bus/usb/*/*设备节点并发送ioctl(USBDEVFS_CONTROL)控制传输来读取设备描述符。这些控制传输在受影响的 xHCI 控制器上会阻塞音频等时传输 (isochronous URB) 约 970ms,超过 PulseAudio 约 93ms 的缓冲区,导致可听见的音频卡顿。修复方案(方案 3)
用直接读取
/sys/bus/usb/devices/下的 sysfs 属性文件替代hwinfo --usb外部进程。sysfs 文件读取不涉及任何 USB I/O,从根本上消除了控制传输干扰。修改内容
文件:
deepin-devicemanager-server/deepin-deviceinfo/src/hotplug/monitorusb.cpp新增
getUsbInfoFromSysfs()静态函数,遍历/sys/bus/usb/devices/下的设备条目,读取 sysfs 属性(idVendor、idProduct、manufacturer、product、serial、bDeviceClass、bInterfaceClass 等),生成与 hwinfo--usb输出格式兼容的字符串。新增
usbHardwareClass()辅助函数,根据 bDeviceClass (0x09=hub) 和 HID 接口的 bInterfaceSubClass/bInterfaceProtocol 推导 hwinfo 风格的 "Hardware Class"(hub/keyboard/mouse/usb)。新增
readSysfsAttr()辅助函数,安全读取 sysfs 属性文件。在
monitor()中将QProcess::execute("hwinfo", {"--usb"})替换为getUsbInfoFromSysfs()调用。兼容性保证
生成的字符串格式完全兼容现有消费者:
所有设备块均超过 10 行(满足
LEAST_NUM=10要求)。影响范围
monitorusb.cpp一个文件detectthread.cpp中的hwinfo --usb --keyboard --mouse调用(属设计缺陷,不在本次修复范围)mainjob.cpp中的sqlCopytoKernel调用(仅在启动和唤醒时执行,非热插拔路径)Summary by Sourcery
Eliminate USB hotplug audio stutter by switching device information collection from hwinfo to non-I/O sysfs reads.
Bug Fixes:
Enhancements: