分享

【树莓派笔记】USB口性能

 金刚光 2023-04-07 发布于辽宁

使用Raspberry Pi 4 Model B在做一些开发工作,需要用到多个USB口,了解了下 Raspberry Pi 的USB口相关的性能。

Raspberry Pi 4

Raspberry Pi 4B有2个 USB 3.0 接口和2个 USB 2.0 接口,全部连接到一个 VL805 USB 控制器上。所有四个端口上的 USB 2.0 的线都连接到 VL805 内的单个 USB 2.0 集线器(hub)上,所以这四个USB 2.0的总带宽实际只有一个USB 2.0 端口的带宽。如果四个USB口接的都是USB 1.1 或 USB 2.0协议规范的USB设备,那么它们的总带宽也就只有480Mbps。

Raspberry Pi 4B使用的VL805 USB 控制器,在网上查了下这款USB 控制器的介绍,如下所示:

VIA VL805是一个单芯片USB 3.0主机控制器,启用了PCI Express接口与USB(5Gbps的超高速),高速(480Mbps)的,全速(12Mbps)的搭载平台,和低速度(1.5Mbps)的装置。根集线器包括4个下行端口,从而实现同时运行多个外设。

VIA VL805符合通用串行总线3.0规范和英特尔的可扩展的xHCI主机控制器接口,并完全向后兼容USB 2.0和1.1规范,确保传统的USB设备的无缝连接。 VIA VL805拥有了PCI Express 2.0 x1接口,PCI Express 1.0的向后兼容,非常适合在PC主机和附加卡应用。

其中注意到VL805使用的是PCI Express 2.0 x1,该接口可用带宽是500MB/s,也就是4Gbps。那么该USB 控制器的总带宽就是4Gbps,而USB 3.0的速率为5Gbps,也就是说达不到USB3.0的最大速率,只有80%。如果2个USB 3.0 口同时使用,可用带宽就会更低。

在 Raspberry Pi 4 上,以前型号上使用的 USB 控制器位于 USB type C 口上,默认情况下处于禁用状态。

Raspberry Pi Zero, 1, 2 and 3

Raspberry Pi Zero, 1, 2, 3这些之前的型号都只支持一个根USB口(root USB port),所有USB设备的数据都会集中到这条单一总线上,该总线的最高运行速度为 480Mbps。也就是所有设备都要共享这480Mbps的USB带宽。

Raspberry Pi Zero, 1, 2, 3对于USB 高速(high-speed)设备的支持没有问题,但对低速(low speed)和全速(full speed)设备的支持却不好,与低速和全速设备通信时产生的软件开销会影响同时活动的设备数量,如果连接少量的低速和全速设备不会引起任何问题。

已知的 USB 问题

在树莓派的官网中的已知USB问题章节Known USB Issues可以看到列出了一些树莓派的USB问题。

1. 与USB 3.0 集线器的交互性

Interoperability with USB 3.0 hubs

There is an issue with USB 3.0 hubs in conjunction with the use of full or low speed devices, including most mice and keyboards. A bug in most USB 3.0 hub hardware means that the models prior to Pi 4 cannot talk to full or low speed devices connected to a USB 3.0 hub.

USB 2.0 high speed devices, including USB 2.0 hubs, operate correctly when connected via a USB 3.0 hub.

Avoid connecting low or full speed devices into a USB 3.0 hub. As a workaround, plug a USB 2.0 hub into the downstream port of the USB 3.0 hub and connect the low speed device, or use a USB 2.0 hub between the Pi and the USB 3.0 hub, then plug low speed devices into the USB 2.0 hub.

从上文可以看到,树莓派的USB对于USB 3.0 集线器的兼容性是有问题的。Raspberry Pi 4由于有 USB 3.0 接口,所以没有兼容性问题,其他在Raspberry Pi 4之前的型号都会有无法与连接在 USB 3.0 集线器上的全速或者低速设备通讯的问题。

示意图如下:

Interoperability with USB 3.0 hubs

官方的解决方案就是在 USB 3.0 集线器与全速或者低速设备之间接入一个 USB 2.0 集线器,或者是在树莓派和 USB 3.0 集线器之间使用 USB 2.0 集线器,然后全速或者低速设备接到USB 2.0 集线器上。总之就是要避免将低速或全速设备连接到 USB 3.0 集线器上。

示意图如下:

解决方案一
解决方案二

2. USB 1.1 webcams

USB 1.1 webcams

Old webcams may be full speed devices. Because these devices transfer a lot of data and incur additional software overhead, reliable operation is not guaranteed. As a workaround, try to use the camera at a lower resolution.

由于Raspberry Pi 4之前的设备对低速(low speed)和全速(full speed)设备的支持程度很不好,与低速和全速设备通信时会产生的较大的软件开销。而旧的网络摄像头可能是全速设备,网络摄像头的数据量较大,传输大量数据会产生额外的软件开销,树莓派无法保证可靠运行。

官方的解决方案是尝试去降低分辨率,使用较低的分辨率会减小传输的数据量。

3. Esoteric USB sound cards

Esoteric USB sound cards

Expensive audiophile sound cards typically use large amounts of USB bandwidth: reliable operation with 96kHz/192kHz DACs is not guaranteed. As a workaround, forcing the output stream to be CD quality (44.1kHz/48kHz 16-bit) will reduce the stream bandwidth to reliable levels.

发烧级的USB声卡通常能支持96kHz/192kHz的录音室音质,与此相对就要使用大量的 USB 带宽,所以树莓派无法保证96kHz/192kHz的可靠运行。

官方的解决方法是将声卡的输出修改为 CD 质量(44.1kHz/48kHz 16 位),以此将数据流带宽降低到树莓派可以可靠运行的水平。

4. Single TT USB hubs

Single TT USB hubs

USB 2.0 and 3.0 hubs have a mechanism for talking to full or low speed devices connected to their downstream ports called a transaction translator (TT). This device buffers high speed requests from the host and transmits them at full or low speed to the downstream device. Two configurations of hub are allowed by the USB specification: Single TT (one TT for all ports) and Multi TT (one TT per port). Because of a hardware limitation, if too many full or low speed devices are plugged into a single TT hub, the devices may behave unreliably. It is recommended to use a Multi TT hub to interface with multiple full and low speed devices. As a workaround, spread full and low speed devices out between the Pi’s own USB port and the single TT hub.

如果使用单个事务转换器的USB集线器(Single TT USB hubs),并且将多个全速或低速设备接入该USB集线器中,由于树莓派的硬件问题,会导致运行不可靠。所以官方建议使用多个事务转换器的USB集线器(Multi TT USB hubs)。如果只有单个事务转换器的USB集线器,那么官方的解决方法是,将全速和低速设备分布在树莓派自己的 USB 端口和USB集线器之间。

总结

总体看来,树莓派的USB性能略显拉垮,Raspberry Pi 4 的所有 USB2.0 接口共用带宽,USB3.0 接口带宽无法拉满,Raspberry Pi 4之前版本的树莓派有很多兼容性问题,并且也是所有接口共同带宽。再结合树莓派 USB 口的供电能力偏弱的问题,可以看到树莓派的USB性能很一般,不能拿来做一些要求较高的事情,但做一些基本的事情还是可以的。

参考资料

Universial Serial Bus (USB)

Known USB Issues

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多