简体   繁体   English

如果程序在虚拟机上运行,​​程序的系统执行时间是否会改变?

[英]Does the system execution time of a program change if it's running on a virtual machine?

A friend asked for a command that can be used to find the real system execution time for a program in Linux. 一位朋友问一个命令,该命令可用于查找Linux中某个程序的实际系统执行时间。 I replied that the time command is a great one. 我回答说, time命令是一个很好的命令。

He then asked, is the time of execution (via time ) for a program which is returned by the virtual machine when you query for the execution time, the same as the real system execution time of the program? 然后,他问,当您查询执行时间时,虚拟机返回的程序的执行时间(通过time )是否与该程序的实际系统执行时间相同?

My instinct was to say it depends : 我的直觉是说这取决于

  1. If there are enough resources on the machine , then the VM time returned would be the same as the real/wall clock time of the program execution. 如果机器上有足够的资源 ,则返回的VM时间将与程序执行的实际/挂钟时间相同。

  2. If the system does NOT have sufficient resources , then the VM time will be much different than the real (system) execution time. 如果系统没有足够的资源 ,则VM时间将与实际(系统)执行时间有很大不同。 Moreover, the VM is an application on top of the OS, which has its own scheduler. 此外,VM是OS之上的应用程序,具有自己的调度程序。 This means that the VM needs to invoke systems calls which are then processed by the OS which in turn communicate with hardware and then provide a real (system) execution time. 这意味着VM需要调用系统调用,然后由OS处理这些系统调用,然后OS与硬件进行通信,然后提供实际的(系统)执行时间。 Hence, the time returned can be different than real time in this situation. 因此,在这种情况下,返回的时间可能与实时不同。

  3. If the executed program is simple , then the VM time could be equal to real (system) time. 如果执行的程序很简单 ,则VM时间可能等于实际(系统)时间。

  4. If the executed program is NOT simple , then the VM time could be much different. 如果执行的程序不简单 ,则VM时间可能会大不相同。

Are my assumptions correct? 我的假设正确吗?

I now wonder: How could you find/calculate the real execution time of a program ran on a virtual machine? 我现在想知道: 您如何找到/计算在虚拟机上运行的程序的实际执行时间? Any ideas? 有任何想法吗?

The complexity of the program doesn't matter. 程序的复杂性无关紧要。

The guest OS doesn't have visibility into the host. 来宾操作系统无法查看主机。 If you run 'time' on the guest, the 'sys' value returned is describing guest system resources used, only. 如果在客户机上运行“时间”,则返回的“ sys”值仅描述所使用的客户机系统资源。

Or to rephrase: in a typical virtual machine setup, you're going to allocate only a portion of the host CPU resources to the guest OS. 或者换个说法:在典型的虚拟机设置中,您将只将一部分主机CPU资源分配给来宾OS。 But that's all the guest can see, and thus, that's all the 'time' command can report on. 但这就是来宾可以看到的所有内容,因此,这就是“时间”命令可以报告的所有内容。 Since you allocated this when you launched the VM, the guest cannot exhaust all of the host resources. 由于您是在启动VM时分配的,因此guest虚拟机无法耗尽所有主机资源。

This is true of pretty much any VM: it would be a major security issue if the guest had knowledge of the hypervisor. 几乎所有VM都是如此:如果来宾了解虚拟机管理程序,这将是一个主要的安全问题。

So yes the sys time could absolutely differ for VM versus real hardware, because the guest won't have full resources. 因此,是的,对于VM和实际硬件,系统时间可能完全不同,因为来宾系统将没有完整的资源。 You could also see variability depending on whether you're dealing with hardware or software virtualization. 您还可能看到可变性,具体取决于您要处理的是硬件还是软件虚拟化。

Some good reading here (sections 10.3 through 10.5): 这里有一些不错的阅读材料(第10.3至10.5节):

https://www.virtualbox.org/manual/ch10.html#hwvirt https://www.virtualbox.org/manual/ch10.html#hwvirt

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

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