[go: up one dir, main page]

CN117076137A - CPU dynamic frequency modulation method under virtualization - Google Patents

CPU dynamic frequency modulation method under virtualization Download PDF

Info

Publication number
CN117076137A
CN117076137A CN202311332134.9A CN202311332134A CN117076137A CN 117076137 A CN117076137 A CN 117076137A CN 202311332134 A CN202311332134 A CN 202311332134A CN 117076137 A CN117076137 A CN 117076137A
Authority
CN
China
Prior art keywords
cpu
management domain
load
frequency modulation
hypervisor
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202311332134.9A
Other languages
Chinese (zh)
Other versions
CN117076137B (en
Inventor
韩乃平
张云飞
齐璇
战茅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Kirin Software Co Ltd
Original Assignee
Kirin Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Kirin Software Co Ltd filed Critical Kirin Software Co Ltd
Priority to CN202311332134.9A priority Critical patent/CN117076137B/en
Publication of CN117076137A publication Critical patent/CN117076137A/en
Application granted granted Critical
Publication of CN117076137B publication Critical patent/CN117076137B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F1/00Details not covered by groups G06F3/00 - G06F13/00 and G06F21/00
    • G06F1/04Generating or distributing clock signals or signals derived directly therefrom
    • G06F1/08Clock generators with changeable or programmable clock frequency
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Power Sources (AREA)

Abstract

虚拟化下的CPU动态调频方法,包括如下步骤:启动管理域的CPU调频系统;设置管理域的调频策略;在管理域上实现负载重定向,将管理域操作系统的负载计算函数重定向到Hypervisor中,使得在Hypervisor中能够将虚拟CPU的负载和实际物理CPU的负载进行转换,Hypervisor返回虚拟机时,能将负载计算结果写回到管理域操作系统中。本发明解决了虚拟化场景下CPU动态调频功能的需求。使嵌入式设备在虚拟化场景下可以准确感知物理CPU的实际负载,并根据负载进行动态调频,使设备运行兼顾性能、实时性、功耗、散热等需求。

The CPU dynamic frequency regulation method under virtualization includes the following steps: start the CPU frequency regulation system of the management domain; set the frequency regulation policy of the management domain; implement load redirection on the management domain and redirect the load calculation function of the management domain operating system to the hypervisor , so that the virtual CPU load and the actual physical CPU load can be converted in the hypervisor. When the hypervisor returns to the virtual machine, the load calculation result can be written back to the management domain operating system. The present invention solves the need for CPU dynamic frequency modulation function in virtualization scenarios. This enables embedded devices to accurately perceive the actual load of the physical CPU in virtualization scenarios, and perform dynamic frequency modulation based on the load, so that the device operation takes into account performance, real-time, power consumption, heat dissipation and other requirements.

Description

虚拟化下的CPU动态调频方法CPU dynamic frequency regulation method under virtualization

技术领域Technical field

本发明涉及虚拟机资源调度技术领域,具体涉及虚拟化下的CPU动态调频方法。The present invention relates to the technical field of virtual machine resource scheduling, and specifically relates to a CPU dynamic frequency modulation method under virtualization.

背景技术Background technique

随着虚拟化技术的不断发展使得它在物联网、嵌入式工业自动化、车载系统、网络设备等领域得到广泛应用。通过有效地利用硬件资源和提供更灵活的部署方式,虚拟化为嵌入式系统带来了新的可能性和优势。在这些非数据中心场景下,CPU调频技术显得尤为重要。CPU调频允许动态调整CPU频率,从而在性能和节能方面都带来了好处。调频技术对于嵌入式设备来说主要为了解决以下关键问题:With the continuous development of virtualization technology, it has been widely used in the Internet of Things, embedded industrial automation, vehicle systems, network equipment and other fields. Virtualization brings new possibilities and advantages to embedded systems by efficiently utilizing hardware resources and providing more flexible deployment methods. In these non-data center scenarios, CPU frequency modulation technology is particularly important. CPU throttling allows the CPU frequency to be dynamically adjusted, providing benefits in both performance and energy savings. Frequency modulation technology is mainly used to solve the following key problems for embedded devices:

1、性能提升:1. Performance improvement:

在需要时使用更高的频率以获得更好的性能: CPU动态调频使得在必要时可以提高CPU频率。这对于"重负载"用例特别有帮助,其中应用程序需要更多的处理能力。通过使用更高的频率,任务可以更快地完成,从而提升整个系统的性能。Use higher frequencies when needed for better performance: CPU Dynamic Scaling enables the CPU frequency to be increased when necessary. This is particularly helpful for "heavy load" use cases, where the application requires more processing power. By using higher frequencies, tasks can be completed faster, thus improving overall system performance.

加快引导过程:在引导过程中增加CPU频率可以加快引导速度,使系统更快地变为可操作状态。这在需要快速启动时间的设备中尤为有益。Speed up the boot process: Increasing the CPU frequency during the boot process can speed up the boot process, making the system become operational faster. This is especially beneficial in devices that require fast boot times.

2、节能:2. Energy saving:

在轻负载情况下使用较低的频率以提高功率效率: CPU动态调频的一个主要优势是能够在系统负载较轻时降低CPU频率。这带来了节能效果,在嵌入式设备的嵌入式领域尤为关键。通过降低频率,设备的能耗可以减少,从而延长电池寿命。Use lower frequencies under light loads to improve power efficiency: One of the main advantages of CPU dynamic scaling is the ability to reduce the CPU frequency when the system load is light. This brings energy savings, which is particularly critical in the embedded field of embedded devices. By reducing the frequency, the device's energy consumption can be reduced, thereby extending battery life.

防止过热并延长CPU寿命: 在某些情况下,CPU动态调频可以帮助防止CPU过热。通过在负载较低时降低频率,CPU产生的热量减少,这在散热能力有限的设备中尤为重要。防止过热不仅提高了功率效率,还有助于延长CPU的寿命。Prevent overheating and extend CPU life: In some cases, CPU Dynamic Scaling can help prevent the CPU from overheating. By lowering the frequency when the load is lower, the CPU generates less heat, which is especially important in devices with limited cooling capabilities. Preventing overheating not only improves power efficiency, it also helps extend the life of your CPU.

性能优化和功耗效率的结合,使得CPU动态调频成为嵌入式系统中的一个有价值的功能。它与资源受限的设备要求相吻合,在性能和能耗之间取得合适的平衡至关重要。CPU动态调频的作用在提供更好的用户体验和各种应用的高效运行方面变得更加重要。The combination of performance optimization and power efficiency makes CPU dynamic tuning a valuable feature in embedded systems. It coincides with resource-constrained device requirements, where striking the right balance between performance and energy consumption is crucial. The role of CPU dynamic frequency scaling has become more important in providing a better user experience and efficient operation of various applications.

通常在操作系统中就会有CPU调频的完整实现,包括调频算法、驱动等。以Linux系统为例,它包括:Usually there will be a complete implementation of CPU frequency modulation in the operating system, including frequency modulation algorithms, drivers, etc. Taking the Linux system as an example, it includes:

1、驱动程序支持:Linux 内核中包含了多种 CPUFreq 驱动程序,用于支持不同的CPU 架构和芯片组。这些驱动程序与特定的硬件平台交互,以调整 CPU 频率。1. Driver support: The Linux kernel contains a variety of CPUFreq drivers to support different CPU architectures and chipsets. These drivers interact with the specific hardware platform to adjust the CPU frequency.

2、Governor(调频策略):每个 CPUFreq 驱动程序支持多个调频策略,也称为Governor。Governor 用于根据系统负载和需求选择适当的频率。2. Governor (frequency modulation strategy): Each CPUFreq driver supports multiple frequency modulation strategies, also called Governor. Governor is used to select the appropriate frequency based on system load and demand.

3、CPUFreq 调度器接口:Linux 内核通过 CPUFreq 调度器接口与各个 Governor交互。当需要调整 CPU 频率时,调度器选择适当的 Governor 来处理频率调整请求。3. CPUFreq scheduler interface: The Linux kernel interacts with each Governor through the CPUFreq scheduler interface. When the CPU frequency needs to be adjusted, the scheduler selects the appropriate Governor to handle the frequency adjustment request.

4、用户空间接口:Linux 提供了 sysfs 接口,允许用户在用户空间中设置和查询CPUFreq 参数。通过 sysfs,用户可以选择不同的 Governor 或手动设置频率。4. User space interface: Linux provides the sysfs interface, allowing users to set and query CPUFreq parameters in user space. Through sysfs, users can choose a different governor or set the frequency manually.

但是在设备引入虚拟化技术以后,CPU调频就变得大不相同。如图1所示,调频的依据是CPU的负载计算,也就是说CPU负载大,则需要较高的频率以提高CPU的算力和实时性。当CPU的负载较小时需要降低CPU的频率,以减少能量的消耗。开启虚拟化以后(Hypervisor以Xen为例进行说明),会在系统之上虚拟出多个客户机,其中第一个启动Linux系统称为dom0(中文可称之为管理域),其它客户机可以称为domu(中文可称之为客户域)。不同的客户机分处不同的域,并且相互隔离。其中dom0称为特权域,它拥有整个系统的硬件资源权限,这其中就包括CPU调频驱动及相应的硬件权限,其它domu访问硬件必须向dom0发起申请。但dom0操作系统只能计算自身虚拟机的负载情况,并不能感知其它虚拟机的负载。如果让dom0直接去进行CPU动态调频的话,就不能做出正确的决策,影响其它客户机的运行。But after the device introduces virtualization technology, CPU frequency regulation becomes very different. As shown in Figure 1, frequency modulation is based on CPU load calculation, which means that if the CPU load is large, a higher frequency is needed to improve the CPU's computing power and real-time performance. When the CPU load is small, the CPU frequency needs to be reduced to reduce energy consumption. After virtualization is turned on (Hypervisor uses Xen as an example), multiple clients will be virtualized on the system. The first one to start the Linux system is called dom0 (it can be called the management domain in Chinese), and other clients can It is called domu (it can be called customer domain in Chinese). Different clients are located in different domains and are isolated from each other. Among them, dom0 is called the privileged domain. It has the hardware resource permissions of the entire system, including the CPU frequency modulation driver and corresponding hardware permissions. Other domu must apply to dom0 to access the hardware. However, the dom0 operating system can only calculate the load of its own virtual machine and cannot sense the load of other virtual machines. If dom0 is allowed to directly perform dynamic CPU frequency modulation, it will not be able to make correct decisions and affect the operation of other clients.

另外还有一种思路是在Xen中实现CPU动态调频功能。因为Xen了解每个客户机和物理CPU的运行情况,所以它来做CPU调频的决策是比较正确的。但问题主要是像Xen这类典型的TYPE-I型虚拟机,基本上都具有轻量化的特点。它是处在硬件和操作系统之间薄薄的一层。而如果Xen要去完成整个CPU调频功能的话,需要集成大量的CPU调频驱动。因为不同芯片的CPU调频驱动千差万别,而为了适配不通的硬件,其代码量是相当巨大,而且考虑到后续的维护,也有很多的工作量。将大量的驱动代码移植到Xen中,显然不是TYPE-I型虚拟机的初衷。Another idea is to implement the CPU dynamic frequency modulation function in Xen. Because Xen understands the operation of each guest and physical CPU, it makes more correct decisions about CPU frequency scaling. But the main problem is that typical TYPE-I virtual machines like Xen are basically lightweight. It is a thin layer between the hardware and the operating system. And if Xen wants to complete the entire CPU frequency modulation function, it needs to integrate a large number of CPU frequency modulation drivers. Because the CPU frequency modulation drivers of different chips vary widely, and in order to adapt to different hardware, the amount of code is quite huge, and considering the subsequent maintenance, there is also a lot of workload. Porting a large amount of driver code to Xen is obviously not the original intention of the TYPE-I virtual machine.

发明内容Contents of the invention

为解决已有技术存在的不足,本发明提供了一种虚拟化下的CPU动态调频方法,包括如下步骤:In order to solve the shortcomings of the existing technology, the present invention provides a CPU dynamic frequency modulation method under virtualization, which includes the following steps:

步骤S1:启动管理域的CPU调频系统;Step S1: Start the CPU frequency modulation system of the management domain;

步骤S2:设置管理域的调频策略;Step S2: Set the frequency modulation policy of the management domain;

步骤S3:在管理域上实现负载重定向,将管理域操作系统的负载计算函数重定向到Hypervisor中,由Hypersivor进行CPU负载计算,在负载计算过程中Hypersivor能够将虚拟CPU的负载和实际物理CPU的负载进行转换,Hypervisor返回管理域时,能将负载计算结果写回到管理域操作系统中,使管理域操作系统基于调频策略完成调频工作;Step S3: Implement load redirection on the management domain, redirect the load calculation function of the management domain operating system to the Hypervisor, and let Hypersivor perform CPU load calculation. During the load calculation process, Hypersivor can compare the load of the virtual CPU with the actual physical CPU. When the hypervisor returns to the management domain, it can write the load calculation results back to the management domain operating system, so that the management domain operating system can complete the frequency regulation work based on the frequency regulation policy;

其中,管理域为虚拟化系统中第一个启动的虚拟机,负责运行和监控后续启动的其它虚拟机,管理域运行于Hypervisor上,管理域操作系统为运行于该第一个启动的虚拟机上的操作系统。Among them, the management domain is the first virtual machine started in the virtualization system and is responsible for running and monitoring other virtual machines that are subsequently started. The management domain runs on the hypervisor, and the management domain operating system runs on the first started virtual machine. operating system on.

其中,通过在管理域内核的arch/arm/xen/enlighten.c中去掉disable_cpufreq()函数,使得管理域操作系统能够正常加载CPU调频模块。Among them, by removing the disable_cpufreq() function in arch/arm/xen/enlighten.c of the management domain kernel, the management domain operating system can load the CPU frequency modulation module normally.

其中,所述步骤S2中,管理域的调频策略为Performance、Powersave或Ondemand,三种调频策略的调频原则分别如下:In step S2, the frequency modulation strategy of the management domain is Performance, Powersave or Ondemand. The frequency modulation principles of the three frequency modulation strategies are as follows:

Performance:保持最高频率以获取最佳性能;Performance: Maintain the highest frequency for optimal performance;

Powersave:使用最低频率以降低能耗;Powersave: Use the lowest frequency to reduce energy consumption;

Ondemand:根据负载动态调整频率。Ondemand: Dynamically adjust frequency based on load.

其中,所述步骤S2中,管理域的调频策略为Ondemand。In step S2, the frequency modulation policy of the management domain is Ondemand.

其中,所述步骤S3中,通过如下步骤在管理域上实现负载计算重定向:Among them, in step S3, load calculation redirection is implemented on the management domain through the following steps:

步骤S31:使用内核提供的kallsyms_lookup_name 函数找到dbs_update的内存地址;Step S31: Use the kallsyms_lookup_name function provided by the kernel to find the memory address of dbs_update;

步骤S32:在步骤S31所找到的内存地址上进行指令替换,将dbs_update函数替换为操作系统内核专门为管理域实现的Xen跳转函数privcmd_ioctl;因为Xen中掌握真正的CPU硬件资源,从而在Hypervisor中实现实际物理CPU的负载计算,在Hypervisor返回时将Hypervisor中负载计算模块的负载计算结果传递给管理域操作系统;其中,Xen为Hypervisor的一种实现模式;Step S32: Perform instruction replacement on the memory address found in step S31, and replace the dbs_update function with the Xen jump function privcmd_ioctl implemented by the operating system kernel specifically for the management domain; because Xen controls the real CPU hardware resources, thus in the hypervisor Realize the load calculation of the actual physical CPU, and transfer the load calculation result of the load calculation module in the Hypervisor to the management domain operating system when the Hypervisor returns; among them, Xen is an implementation mode of the Hypervisor;

步骤S33:管理域根据计算结果调用调频驱动,实现CPU的动态调频。Step S33: The management domain calls the frequency modulation driver according to the calculation result to implement dynamic frequency modulation of the CPU.

其中,Xen中的负载计算模块的实现方法如下:Among them, the load calculation module in Xen is implemented as follows:

步骤S321:在Xen中为每个物理CPU维护一个VCPU的队列,VCPU按照优先级递减的顺序依次排列在队列中;Step S321: Maintain a VCPU queue for each physical CPU in Xen, and the VCPUs are arranged in the queue in order of decreasing priority;

步骤S322:每个物理CPU设置一个IDLE VCPU,作为优先级最低的VCPU任务,在CPU空闲时调度,该IDLE VCPU负责跟踪VCPU的状态及相应运行时间,由此得到IDLE VCPU的运行时间;Step S322: Each physical CPU sets an IDLE VCPU as the lowest priority VCPU task and schedules it when the CPU is idle. The IDLE VCPU is responsible for tracking the status of the VCPU and the corresponding running time, thereby obtaining the running time of the IDLE VCPU;

步骤S323:根据如下公式循环计算所有物理CPU的负载,从中选出最大负载传递给管理域,作为Ondemand策略的决策参数:Step S323: Calculate the load of all physical CPUs cyclically according to the following formula, select the maximum load and pass it to the management domain as the decision parameter of the Ondemand policy:

;

其中,采样周期为对物理CPU运行队列中进行负载计算时所涉及到的时间段。Among them, the sampling period is the time period involved in load calculation in the physical CPU run queue.

其中,IDLE VCPU的运行时间为整个物理CPU的空闲时间。Among them, the running time of IDLE VCPU is the idle time of the entire physical CPU.

本发明的虚拟化下的CPU动态调频方法,解决了虚拟化场景下CPU动态调频功能的需求。使嵌入式设备在虚拟化场景下可以准确感知物理CPU的实际负载,并根据负载进行动态调频,使设备运行兼顾性能、实时性、功耗、散热等需求。The CPU dynamic frequency modulation method under virtualization of the present invention solves the need for CPU dynamic frequency modulation function in virtualization scenarios. This enables embedded devices to accurately perceive the actual load of the physical CPU in virtualization scenarios, and perform dynamic frequency modulation based on the load, so that the device operation takes into account performance, real-time, power consumption, heat dissipation and other requirements.

附图说明Description of the drawings

图1:已有技术未虚拟化以及虚拟化后CPU调频逻辑比对图。Figure 1: Comparison diagram of CPU frequency modulation logic between existing technologies without virtualization and after virtualization.

图2:本发明的负载重定向原理图。Figure 2: Principle diagram of load redirection of the present invention.

图3:本发明的Xen的CPU负载计算原理图。Figure 3: Principle diagram of Xen's CPU load calculation of the present invention.

具体实施方式Detailed ways

为了对本发明的技术方案及有益效果有更进一步的了解,下面结合附图详细说明本发明的技术方案及其产生的有益效果。In order to have a further understanding of the technical solutions and beneficial effects of the present invention, the technical solutions of the present invention and the beneficial effects thereof will be described in detail below with reference to the accompanying drawings.

理论上来说Hypervisor对硬件拥有更高的管理权限,客户机所掌握的硬件资源是经过Hypervisor虚拟化或直通以后的。从这点来说Hypervisor更适合来完成CPU调频的任务。但是这无疑将是一项巨大的工作。首先调频算法需要独立实现,其次是CPU调频驱动程序需要大量集成在Hypervisor中。本发明的思路是尽量的使用客户机操作系统的现有功能。以Linux系统为例,现已形成了比较完善的CPU调频算法,并基于Linux系统的强生态特性,可以适配绝大部分的CPU调频驱动。Theoretically speaking, the hypervisor has higher management rights over the hardware, and the hardware resources controlled by the client are virtualized or pass-through by the hypervisor. From this point of view, the Hypervisor is more suitable to complete the task of CPU frequency regulation. But it will undoubtedly be a huge undertaking. First, the frequency modulation algorithm needs to be implemented independently, and secondly, the CPU frequency modulation driver needs to be heavily integrated into the hypervisor. The idea of the present invention is to use the existing functions of the client operating system as much as possible. Taking the Linux system as an example, a relatively complete CPU frequency modulation algorithm has been formed, and based on the strong ecological characteristics of the Linux system, it can adapt to most CPU frequency modulation drivers.

如果要使用操作系统自己的CPU调频系统,最重要的是要解决Host客户机无法感知其它客户机和实际CPU负载的问题。本发明的思路是通过函数打桩的方法,将操作系统的负载计算函数重定向到Hypervisor中去。在Hypervisor中将虚拟CPU的负载和实际物理CPU的负载进行转换。在Hypervisor返回虚拟机时,将负载计算结果回写到操作系统中去。这样客户机操作系统对于CPU调频是透明的,不需要做任何修改。同时Hypervisor中只需要做相对较少的改动就可以实现整个系统的争取CPU动态调频功能。If you want to use the operating system's own CPU frequency regulation system, the most important thing is to solve the problem that the Host client cannot sense other clients and the actual CPU load. The idea of the present invention is to redirect the load calculation function of the operating system to the hypervisor through the method of function piling. Convert the load of the virtual CPU and the load of the actual physical CPU in the hypervisor. When the hypervisor returns to the virtual machine, the load calculation results are written back to the operating system. In this way, the guest operating system is transparent to CPU frequency regulation and does not need to make any modifications. At the same time, only relatively few changes need to be made in the hypervisor to realize the dynamic CPU frequency regulation function of the entire system.

本发明的一个较优实施例中基于ARMv8架构,虚拟化软件使用Xen 4.17.0版本,HOST客户机为Linux5.0内核,具体实现上述构思的步骤如下:A preferred embodiment of the present invention is based on the ARMv8 architecture, the virtualization software uses the Xen 4.17.0 version, and the HOST client is the Linux 5.0 kernel. The specific steps to implement the above concept are as follows:

1、启用dom0的CPU调频系统。1. Enable the CPU frequency modulation system of dom0.

在Xen的架构中,为了防止Linux客户机进行错误的CPU调频操作。一般都会禁用Linux的调频模块。所以,本发明的第一步是使能 dom0的调频模块。在dom0内核的arch/arm/xen/enlighten.c中去掉disable_cpufreq()函数,这样Linux会正常加载cpu调频模块,从而使能dom0的CPU动态调频功能。In the Xen architecture, in order to prevent the Linux client from performing incorrect CPU frequency modulation operations. Generally, the Linux frequency modulation module is disabled. Therefore, the first step of the present invention is to enable the frequency modulation module of dom0. Remove the disable_cpufreq() function in arch/arm/xen/enlighten.c of the dom0 kernel, so that Linux will load the cpu frequency modulation module normally, thereby enabling the CPU dynamic frequency modulation function of dom0.

在无虚拟化的系统中,系统由硬件和操作系统软件组成。而在虚拟化引入以后,是在硬件和操作系统之间插入一层软件,我们称之为hypervisor(中文:虚拟机监控器)。这样在hypervisor之上就可以运行多个虚拟机。这些虚拟机中最特殊的是第一个启动的虚拟机,我们可以称为dom0,中文名称叫做管理域,而后续启动的虚拟机就是普通虚拟机,称为domu。Dom0是运行 Xen 虚拟机监视器(Hypervisor)的特殊虚拟机,负责管理和监控其他虚拟机(DomU)。Dom0 通常具有对物理硬件资源的直接访问权限,包括对设备驱动程序的控制,以及负责整个虚拟化环境的配置和维护。DomU 代表了普通的虚拟机,通常运行不同的操作系统和应用程序。DomU 被称为“非特权域”或“客户域”,因为它们不具备直接访问物理硬件资源的权限,而是依赖于 Dom0 来提供这些资源。虚拟机的数量可以根据需求创建多个 DomU。管理域作为特殊虚拟机,其本身可以运行Linux系统或者其它操作系统。在本发明中管理域操作系统就是运行于管理域的Linux系统。In a system without virtualization, the system consists of hardware and operating system software. After the introduction of virtualization, a layer of software is inserted between the hardware and the operating system, which we call a hypervisor (Chinese: virtual machine monitor). In this way, multiple virtual machines can be run on the hypervisor. The most special of these virtual machines is the first started virtual machine, which we can call dom0, and its Chinese name is called the management domain. The subsequent started virtual machines are ordinary virtual machines, called domu. Dom0 is a special virtual machine running the Xen virtual machine monitor (Hypervisor) and is responsible for managing and monitoring other virtual machines (DomU). Dom0 typically has direct access to physical hardware resources, including control of device drivers, and is responsible for the configuration and maintenance of the entire virtualized environment. DomU represents a normal virtual machine, usually running different operating systems and applications. DomUs are called "unprivileged domains" or "guest domains" because they do not have direct access to physical hardware resources, but rely on Dom0 to provide these resources. Multiple DomUs can be created based on the number of virtual machines required. The management domain is a special virtual machine that can run Linux or other operating systems. In the present invention, the management domain operating system is the Linux system running in the management domain.

2、设置dom0 的调频策略为Ondemand。2. Set the frequency modulation policy of dom0 to Ondemand.

目前在Xen的调频策略中主要以下三种:Currently, there are three main frequency modulation strategies in Xen:

Performance:保持最高频率以获取最佳性能。Performance: Maintain the highest frequency for best performance.

Powersave:使用最低频率以降低能耗。Powersave: Use the lowest frequency to reduce energy consumption.

Ondemand:根据负载动态调整频率。Ondemand: Dynamically adjust frequency based on load.

但由于Xen中并没有所有芯片的调频驱动程序,所以其应用比较有限。它只是实现了调频相关算法和策略,而真正的硬件驱动支持需要用户去实现。However, since Xen does not have FM drivers for all chips, its application is relatively limited. It only implements frequency modulation related algorithms and strategies, and real hardware driver support requires users to implement it.

在本发明中使用“dom0代理,负载计算重定向”的方式去实现xen的调频功能。其中Performance和Powersave相对比较简单,不涉及复杂的负载计算,只需要根据用户需要去设置最大频率和最低频率就可以。对于大多数系统来说,Ondemand 调频策略能够在热量散发、功耗、性能和可管理性之间提供最佳平衡。当系统在一天中的特定时间段内处于繁忙状态时,Ondemand 调频策略会根据负载自动在最大和最小频率之间进行切换,无需进一步干预。所以本发明主要阐述Ondemand策略的实现方法。在dom0的Linux系统中可以通过cpufrequtils工具设置,具体命令为:cpufreq-set -r -g ondemand。除此之外也可以通过/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor系统接口去修改当前CPU的调频策略。In the present invention, the method of "dom0 proxy, load calculation redirection" is used to realize the frequency modulation function of xen. Among them, Performance and Powersave are relatively simple and do not involve complex load calculations. They only need to set the maximum frequency and minimum frequency according to the user's needs. For most systems, the Ondemand throttling policy provides the best balance between thermal dissipation, power consumption, performance, and manageability. When the system is busy during certain times of the day, the Ondemand frequency regulation policy automatically switches between maximum and minimum frequencies based on load without further intervention. Therefore, this invention mainly describes the implementation method of the Ondemand policy. In the Linux system of dom0, it can be set through the cpufrequtils tool. The specific command is: cpufreq-set -r -g ondemand. In addition, you can also modify the current CPU frequency regulation strategy through the /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor system interface.

3、dom0代理,负载计算重定向的实现3. dom0 proxy, implementation of load calculation redirection

Ondemand会定期(通常是每隔一段时间)检测CPU的负载情况。负载可以通过各种指标来衡量,例如CPU利用率、就绪队列长度等。调节器会根据负载情况动态地在支持的频率范围内进行频率调整。这意味着它可以根据系统需求实时地适应不同的工作负载。本发明主要通过函数打桩,去修改Ondemand的负载计算结果,使负载计算能够体现整个物理CPU的负荷情况,而不仅仅是dom0 系统自身的负载。具体实现方法如下:Ondemand will detect the CPU load periodically (usually every once in a while). Load can be measured through various metrics such as CPU utilization, ready queue length, etc. The regulator dynamically adjusts frequency within the supported frequency range based on load conditions. This means it can adapt to different workloads in real time based on system needs. The present invention mainly modifies the load calculation result of Ondemand through function piling, so that the load calculation can reflect the load situation of the entire physical CPU, not just the load of the dom0 system itself. The specific implementation method is as follows:

(1)关键指令探测(1) Key instruction detection

如图2所示,在dom0 Linux内核的代码段中,Ondemand通过选定的governor去调用od_dbs_update函数去执行定期的负载检测和频率调整。其中od_dbs_update调用od_update函数,在od_update中调用真正的负载计算函数dbs_update(dbs_update是Linux内核下drivers/cpufreq/cpufreq_governor.c文件中负责负载计算的函数),然后根据负载计算结果去调用调频驱动,最终改变CPU的硬件频率。所以我们这里需要打桩的函数是dbs_update。使用内核提供的kallsyms_lookup_name 函数找到dbs_update的内存地址,该函数是利用内核中 kallsyms 功能。内核将系统中用到的函数符号和地址存储到proc文件系统中去,然后通过kallsyms_lookup_name函数就可以找到内核符号(也即dbs_update函数符号)和地址的对应关系。As shown in Figure 2, in the code segment of the dom0 Linux kernel, Ondemand calls the od_dbs_update function through the selected governor to perform regular load detection and frequency adjustment. Among them, od_dbs_update calls the od_update function, and calls the real load calculation function dbs_update in od_update (dbs_update is the function responsible for load calculation in the drivers/cpufreq/cpufreq_governor.c file under the Linux kernel), and then calls the frequency modulation driver based on the load calculation result, and finally changes CPU hardware frequency. So the function we need to pile here is dbs_update. Use the kallsyms_lookup_name function provided by the kernel to find the memory address of dbs_update. This function uses the kallsyms function in the kernel. The kernel stores the function symbols and addresses used in the system in the proc file system, and then uses the kallsyms_lookup_name function to find the corresponding relationship between the kernel symbols (that is, the dbs_update function symbols) and the addresses.

图2中,bl和ret是arm64的汇编指令。BL是分支指令(Branch with Link),通常用于函数调用。BL指令的作用是跳转到指定的函数,并将返回地址(下一条指令的地址)保存在链接寄存器(LR)中,以便在函数执行完后返回到调用它的地方。ret为返回指令,跳转到链接寄存器 (LR) 中存储的地址,从而实现函数返回。In Figure 2, bl and ret are assembly instructions of arm64. BL is a branch instruction (Branch with Link), usually used for function calls. The function of the BL instruction is to jump to the specified function and save the return address (the address of the next instruction) in the link register (LR) so that after the function is executed, it can be returned to the place where it was called. ret is a return instruction that jumps to the address stored in the link register (LR) to implement function return.

(2)负载计算重定向(2) Load calculation redirection

在该地址上进行指令替换,将函数替换为privcmd_ioctl。privcmd_ioctl是Linux内核为dom0专门实现的xen跳转函数,其本质是ARMv8的HVC指令,通过该函数可以陷入EL2模式下的Xen代码。由于Xen中掌握了真正的CPU硬件资源,所以我们可以在这里实现实际物理CPU的负载计算。Xen中的负载计算模块将计算结果在虚拟化层返回(通过eret指令返回之前的模式)的时候传递给dom0。dom0根据计算结果调用调频驱动,实现CPU的动态调频。Ondemand会根据采样频率周期性的去调节CPU的频率,而每次调频都会触发到Xen中去。这样虽然是借用dom0的调频系统,但其实际的决策参数(负载)是由Xen提供的,保证了dom0能客观的完成调频工作。Perform instruction substitution at this address and replace the function with privcmd_ioctl. privcmd_ioctl is a xen jump function specially implemented by the Linux kernel for dom0. Its essence is the HVC instruction of ARMv8. This function can be used to fall into the Xen code in EL2 mode. Since real CPU hardware resources are mastered in Xen, we can implement actual physical CPU load calculation here. The load calculation module in Xen passes the calculation results to dom0 when the virtualization layer returns (returning to the previous mode through the eret instruction). dom0 calls the frequency modulation driver based on the calculation results to implement dynamic frequency modulation of the CPU. Ondemand will periodically adjust the CPU frequency based on the sampling frequency, and each frequency adjustment will be triggered into Xen. Although the frequency modulation system of dom0 is borrowed, the actual decision-making parameters (load) are provided by Xen, which ensures that dom0 can objectively complete the frequency modulation work.

4、Hypervisor中负载计算模块的实现4. Implementation of load calculation module in Hypervisor

CPU负载涉及CPU工作量的大小,通常是以百分比来表示。在无虚拟化的系统中CPU负载就是CPU下所有进程经过算法计算以后的结果,比如IO负载、内存负载、网络负载等等。但是有了虚拟化以后,虚拟机的负载计算就是虚拟的,并不能代表实际物理CPU上的负载量。所以,这里使用hypervisor去完成物理CPU的工作量统计。在hypervisor中,物理CPU下边挂的是VCPU队列,可以理解为每个VCPU就是无虚拟化系统下的任务,如图3所示。这时候VCPU其实就可以看作物理CPU的负载对象。CPU load refers to the size of the CPU workload, usually expressed as a percentage. In a system without virtualization, the CPU load is the result of algorithm calculation of all processes under the CPU, such as IO load, memory load, network load, etc. However, with virtualization, the load calculation of the virtual machine is virtual and does not represent the load on the actual physical CPU. Therefore, the hypervisor is used here to complete the workload statistics of the physical CPU. In the hypervisor, the VCPU queue is hung under the physical CPU. It can be understood that each VCPU is a task in a non-virtualization system, as shown in Figure 3. At this time, VCPU can actually be regarded as the load object of the physical CPU.

在Xen中为每个物理CPU维护了一个VCPU的队列,VCPU按照优先级递减的顺序依次排列在队列中。同时,每个物理CPU还有一个IDLE VCPU(如图3),它是优先级最低的VCPU任务,在CPU空闲时调度,该IDLE VCPU负责跟踪VCPU的状态及相应运行时间,由此得到IDLEVCPU的运行时间。IDLE VCPU的运行时间就是整个物理CPU的空闲时间,也即CPU没有任务运行时进入的状态,所以我们可以通过VCPU的信息知道物理CPU空闲状态的时间。Xen maintains a VCPU queue for each physical CPU, and the VCPUs are arranged in the queue in descending order of priority. At the same time, each physical CPU also has an IDLE VCPU (as shown in Figure 3), which is the lowest priority VCPU task and is scheduled when the CPU is idle. The IDLE VCPU is responsible for tracking the status of the VCPU and the corresponding running time, thus obtaining the IDLE VCPU's operation hours. The running time of IDLE VCPU is the idle time of the entire physical CPU, that is, the state the CPU enters when there is no task running, so we can know the idle state time of the physical CPU through the VCPU information.

负载计算是反映一段时间内运行队列中的平均任务量(也即上个公式得到的一个百分比)。这个平均值是通过一段时间内运行队列的采样来计算的,而这个采样周期的长度可以是1分钟、5分钟和15分钟。这三个值分别表示了不同时间范围内的平均负载情况。在实际的负载计算算法中,这个值通常是动态变化的。The load calculation reflects the average number of tasks in the run queue over a period of time (that is, a percentage obtained by the previous formula). This average is calculated by sampling the run queue over a period of time, and the length of this sampling period can be 1 minute, 5 minutes, and 15 minutes. These three values represent the average load conditions in different time ranges. In actual load calculation algorithms, this value usually changes dynamically.

Xen需要循环计算所有的物理CPU的负载,从中选出最大负载(也即空闲CPU运行时间最少的物理CPU所对应的负载)传递给dom0,作为Ondemand策略的决策参数。Xen needs to cyclically calculate the load of all physical CPUs, and select the maximum load (that is, the load corresponding to the physical CPU with the least idle CPU running time) to be passed to dom0 as the decision parameter of the Ondemand policy.

Xen 会周期性地检查各个物理 CPU 的负载情况,以及虚拟机的需求。这可以是一个动态的过程,虚拟机的需求和物理 CPU 的负载都可能随时间变化。如果 Xen 发现某个物理 CPU 的负载较高,而其他物理 CPU 负载较低,它可以考虑进行动态迁移。这意味着Xen 可以将一个虚拟机的 vCPU 从一个物理 CPU 迁移到另一个物理 CPU 上,以实现负载均衡。Xen periodically checks the load on each physical CPU and the needs of the virtual machine. This can be a dynamic process, and both the virtual machine's needs and the load on the physical CPU can change over time. If Xen finds that one physical CPU is under high load and other physical CPUs are under low load, it can consider live migration. This means that Xen can migrate a virtual machine's vCPU from one physical CPU to another physical CPU to achieve load balancing.

因此,通过本发明提供的方法,dom0 Linux系统不需要做任何修改就可以完成虚拟化场景下的CPU调频功能,因为在全虚拟化盛行的今天,很多情况下是不允许去修改客户机操作系统本身的。Therefore, through the method provided by the present invention, the dom0 Linux system can complete the CPU frequency modulation function in a virtualization scenario without any modification, because in today's era of full virtualization, modification of the guest operating system is not allowed in many cases. self.

同时,本发明充分利用了dom0 Linux系统的生态,这样就可以完全适配那些支持Linux系统的芯片硬件,不需要单独的去实现不同硬件的驱动,省去了大量的驱动移植和硬件适配的工作。At the same time, the present invention makes full use of the ecology of the dom0 Linux system, so that it can be fully adapted to the chip hardware that supports the Linux system, without the need to implement separate drivers for different hardware, and saves a lot of driver transplantation and hardware adaptation. Work.

虽然本发明已利用上述较佳实施例进行说明,然其并非用以限定本发明的保护范围,任何本领域技术人员在不脱离本发明的精神和范围之内,相对上述实施例进行各种变动与修改仍属本发明所保护的范围,因此本发明的保护范围以权利要求书所界定的为准。Although the present invention has been described using the above preferred embodiments, they are not intended to limit the scope of the present invention. Any person skilled in the art can make various changes relative to the above embodiments without departing from the spirit and scope of the present invention. and modifications still fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be defined by the claims.

Claims (7)

1. The CPU dynamic frequency modulation method under virtualization is characterized by comprising the following steps:
step S1: starting a CPU frequency modulation system of a management domain;
step S2: setting a frequency modulation strategy of a management domain;
step S3: the load redirection is realized on the management domain, the load calculation function of the management domain operating system is redirected to the Hypervisor, the Hypervisor carries out CPU load calculation, the Hypervisor can convert the load of the virtual CPU and the load of the actual physical CPU in the load calculation process, and when the Hypervisor returns to the management domain, the load calculation result can be written back to the management domain operating system, so that the management domain operating system completes the frequency modulation work based on the frequency modulation strategy;
the management domain is a first started virtual machine in the virtualized system and is responsible for running and monitoring other virtual machines started later, the management domain runs on the Hypervisor, and the management domain operating system is an operating system running on the first started virtual machine.
2. The method according to claim 1, wherein in step S1, the management domain operating system is enabled to load the CPU frequency modulation module normally by removing the disable_cpu freq () function from the arch/arm/xen/enlight.c of the management domain kernel.
3. The method for dynamic frequency modulation of CPU under virtualization according to claim 1, wherein in step S2, the frequency modulation policy of the management domain is Performance, powersave or Ondemand, and the frequency modulation principles of the three frequency modulation policies are as follows:
performance: maintaining the highest frequency for optimal performance;
powersave: the lowest frequency is used to reduce energy consumption;
ondemand: the frequency is dynamically adjusted according to the load.
4. The method for dynamic frequency modulation of CPU under virtualization according to claim 3, wherein in step S2, the frequency modulation policy of the management domain is Ondemand.
5. The method for dynamically tuning a CPU under virtualization according to claim 4, wherein in step S3, load calculation redirection is implemented on a management domain by:
step S31: finding a memory address of dbs_update by using a kallsyms_lookup_name function provided by a kernel;
step S32: performing instruction replacement on the memory address found in the step S31, and replacing the dbs_update function with a Xen jump function privcmd_ioctl which is specially realized by the kernel of the operating system for the management domain; because the real CPU hardware resource is mastered in Xen, the load calculation of the actual physical CPU is realized in the Hypervisor, and the load calculation result of the load calculation module in the Hypervisor is transmitted to the management domain operating system when the Hypervisor returns; wherein Xen is one mode of implementation of Hypervisor;
step S33: and the management domain calls the frequency modulation drive according to the calculation result to realize the dynamic frequency modulation of the CPU.
6. The method for dynamically tuning CPU frequency under virtualization according to claim 5, wherein the load calculation module in Xen is implemented as follows:
step S321: maintaining a queue of VCPUs for each physical CPU in Xen, wherein the VCPUs are sequentially arranged in the queue according to the descending order of priority;
step S322: each physical CPU is provided with an IDLE VCPU which is used as a VCPU task with the lowest priority and is scheduled when the CPU is IDLE, and the IDLE VCPU is responsible for tracking the state and the corresponding running time of the VCPU, so that the running time of the IDLE VCPU is obtained;
step S323: and circularly calculating the loads of all physical CPUs according to the following formula, and selecting the maximum load from the loads to be transmitted to a management domain as a decision parameter of an Ondemand strategy:
the sampling period is a time period involved in load calculation of the physical CPU running queue.
7. The method for dynamically tuning a CPU under virtualization according to claim 6, wherein the IDLE VCPU has a run time of the entire physical CPU.
CN202311332134.9A 2023-10-16 2023-10-16 CPU dynamic frequency modulation method under virtualization Active CN117076137B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311332134.9A CN117076137B (en) 2023-10-16 2023-10-16 CPU dynamic frequency modulation method under virtualization

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311332134.9A CN117076137B (en) 2023-10-16 2023-10-16 CPU dynamic frequency modulation method under virtualization

Publications (2)

Publication Number Publication Date
CN117076137A true CN117076137A (en) 2023-11-17
CN117076137B CN117076137B (en) 2024-01-26

Family

ID=88706453

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311332134.9A Active CN117076137B (en) 2023-10-16 2023-10-16 CPU dynamic frequency modulation method under virtualization

Country Status (1)

Country Link
CN (1) CN117076137B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101470634A (en) * 2007-12-24 2009-07-01 联想(北京)有限公司 CPU resource scheduling method and virtual machine monitor, virtual machine system
US20160116954A1 (en) * 2014-10-28 2016-04-28 Linkedln Corporation Dynamic adjustment of cpu operating frequency
CN106648890A (en) * 2016-12-06 2017-05-10 中国科学院重庆绿色智能技术研究院 Cloud computing server resource on-line management method and system with energy consumption sensing function
CN114327763A (en) * 2021-12-27 2022-04-12 中瓴智行(成都)科技有限公司 Hypervisor-based dynamic frequency modulation method and electronic equipment
CN116560802A (en) * 2023-07-05 2023-08-08 麒麟软件有限公司 Virtual machine load-based virtual machine self-adaptive thermal migration method and system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101470634A (en) * 2007-12-24 2009-07-01 联想(北京)有限公司 CPU resource scheduling method and virtual machine monitor, virtual machine system
US20160116954A1 (en) * 2014-10-28 2016-04-28 Linkedln Corporation Dynamic adjustment of cpu operating frequency
CN106648890A (en) * 2016-12-06 2017-05-10 中国科学院重庆绿色智能技术研究院 Cloud computing server resource on-line management method and system with energy consumption sensing function
CN114327763A (en) * 2021-12-27 2022-04-12 中瓴智行(成都)科技有限公司 Hypervisor-based dynamic frequency modulation method and electronic equipment
CN116560802A (en) * 2023-07-05 2023-08-08 麒麟软件有限公司 Virtual machine load-based virtual machine self-adaptive thermal migration method and system

Also Published As

Publication number Publication date
CN117076137B (en) 2024-01-26

Similar Documents

Publication Publication Date Title
JP6029660B2 (en) Heterogeneous computation separated from the operating system
Patros et al. Toward sustainable serverless computing
Mateescu et al. Hybrid computing—where HPC meets grid and cloud computing
US8307369B2 (en) Power control method for virtual machine and virtual computer system
US9104494B2 (en) Virtual computer system and its optimization method
JP5763168B2 (en) Reduction of power consumption by masking processing from processor performance management system
US20170269951A1 (en) Managing virtual machine migration
US8631253B2 (en) Manager and host-based integrated power saving policy in virtualization systems
CN101169731A (en) Multi-channel multi-core server and its CPU virtualization processing method
Foster Enabling cost-effective resource leases with virtual machines
US20250173193A1 (en) Coordinated Scheduling Method and Related Device
Sanjeevi et al. NUTS scheduling approach for cloud data centers to optimize energy consumption
Lin et al. A heuristic task scheduling algorithm for heterogeneous virtual clusters
Qiao et al. Energy-Aware process scheduling in Linux
US20230393898A1 (en) Pre-emptive scheduling of workloads to enable improved sharing of resources
CN117076137A (en) CPU dynamic frequency modulation method under virtualization
Bacou et al. Drowsy-DC: Data center power management system
Thiam et al. Energy efficient cloud data center using dynamic virtual machine consolidation algorithm
US20250190249A1 (en) Resource scheduling method and apparatus
Petrucci et al. Dynamic configuration support for power-aware virtualized server clusters
Monteiro et al. Quantum virtual machine: power and performance management in virtualized web servers clusters
Georgopoulos et al. Energy-efficient heterogeneous computing at exaSCALE—ECOSCALE
Eibel et al. Empya: saving energy in the face of varying workloads
Deka et al. Team: Time and energy aware application partitioning and resource allocation strategy on mec platform
US20220350639A1 (en) Processing device, control unit, electronic device, method for the electronic device, and computer program for the electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant