简体   繁体   English

libusb_control_transfer 在 Vmware Workstation 上非常慢

[英]libusb_control_transfer very slow with Vmware Workstation

I use libusb using the libusb_control_transfer function to send information to a USB device.我使用 libusb 使用libusb_control_transfer function 将信息发送到 USB 设备。

My host is WINDOWS 10 and my guest is Ubuntu 20.04 within Vmware Workstation version 16.2.3.我的主机是 WINDOWS 10,我的访客是 Ubuntu 20.04,在 Vmware Workstation 版本 16.2.3 中。

The problem is that communication using the libusb_control_transfer function is 20 times slower than I run it on Ubuntu without using vmware For example, sending 180KB takes me about 20 seconds with Vmware Workstation But when I do this without Vmware Workstation it takes 1-2 seconds.问题是使用libusb_control_transfer function 的通信比我在 Ubuntu 上运行它而不使用 vmware 慢 20 倍例如,发送 180KB 使用 Vmware Workstation 需要大约 20 秒但是当我在没有 Vmware Workstation 的情况下执行此操作需要 1-2 秒。

I made sure that USB is set up correctly for me in Setting -> USB Controller.我确保在设置 -> USB Controller 中为我正确设置了 USB。

ldd myBinary :
    linux-vdso.so.1
    libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
    libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 
    /lib64/ld-linux-x86-64.so.2 

My questions:我的问题:
Why is using libusb_control_transfer in Vmware Workstation much slower than using it in Ubuntu without VM?为什么在 Vmware Workstation 中使用 libusb_control_transfer 比在没有 VM 的 Ubuntu 中使用它慢得多?
Can someone make a recommendation how to fix that?有人可以建议如何解决这个问题吗?

You are in a virtual machine.您在虚拟机中。 All hardware "plugged" in your VM is bridged (in a way or another) to your host operating system, and it costs time. VM 中“插入”的所有硬件都桥接(以某种方式)到主机操作系统,这会花费时间。

You can't expect a VM to run at the same performances as a native machine - it's not even the case on a bare-metal hypervisor like ESX, which doesn't even have the extra cost of a host operating system... Unless you use ONLY CPU, RAM, SATA disk and.network - all these devices are easily and natively "shared" across applications, that's why virtual servers on bare-metal hypervisors are running very well, in particular if they use a dedicated physical mass storage for each server (and sometimes even their own.network card).您不能期望 VM 以与本机机器相同的性能运行——甚至在像 ESX 这样的裸机管理程序上也不是这样,它甚至没有主机操作系统的额外成本……除非您仅使用 CPU、RAM、SATA 磁盘和网络——所有这些设备都可以轻松地在应用程序之间“共享”,这就是裸机管理程序上的虚拟服务器运行良好的原因,特别是如果它们使用专用的物理大容量存储对于每个服务器(有时甚至是他们自己的网卡)。

It starts to be more complicated with resources/hardware which have exclusive/expensive access: GPU / screens, sound card, communication ports (from serial to USB passing by parallel ports), optical drives / slow disks, human interface devices in general (mouse, keyboard, ...), etc.对于具有独占/昂贵访问权限的资源/硬件,它开始变得更加复杂:GPU/屏幕、声卡、通信端口(从串行端口到 USB,通过并行端口)、光驱/慢速磁盘、一般人机界面设备(鼠标) , 键盘, ...), 等等

It means that your execution path is, more or less: VM application (VM user) -> VM drivers (VM kernel) -> VM VMWare bridges (VM kernel) -> Host VMWare bridges (Host user) -> Host VMWare app (Host user) -> Host drivers (Host kernel) -> Hardware.这意味着您的执行路径或多或少是:VM 应用程序(VM 用户)-> VM 驱动程序(VM 内核)-> VM VMWare 桥(VM 内核)-> 主机 VMWare 桥(主机用户)-> 主机 VMWare 应用程序(主机用户)-> 主机驱动程序(主机内核)-> 硬件。

And then, add the return path to get acknowledments and read data... Please note that some steps can be simple pass-through wrappers, so they can be quite fast, but still a lot of steps...然后,添加返回路径以获取确认和读取数据...请注意,某些步骤可以是简单的传递包装器,因此它们可以非常快,但仍然有很多步骤...

"A bit" longer than: Application (user) -> OS drivers (kernel) -> Hardware - that what happens for a native application. “有点”长于:应用程序(用户)-> OS 驱动程序(内核)-> 硬件 - 本机应用程序会发生什么。

For USB, it can be even worse, since drivers are partly in user land (USB device driver itself), and partly in kernel land (USB controller).对于 USB,情况可能更糟,因为驱动部分位于用户区(USB 设备驱动程序本身),部分位于 kernel 区(USB 控制器)。 So you have one more layer to cross compared to most drivers compared to most other hardware.因此,与大多数其他硬件相比,与大多数驱动程序相比,您需要多跨越一层。 And you got that on both guest and host operating systems.你在来宾和主机操作系统上都得到了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM