Command execution method, device, computer equipment and storage medium
By encapsulating virtual machine commands into the same virtual engine and using a scheduling algorithm to calculate the occupancy time, the problem of virtual machine resource waste is solved, and efficient utilization of GPU resources and timely execution of commands are achieved.
Patent Information
- Application Number
- CN202211278810.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-19
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2042-10-19
AI Technical Summary
In traditional command execution technology, GPU resources are not fully utilized in virtual machines, resulting in resource waste because the switch to the next virtual machine must wait until the current virtual machine command is completed, even though most commands do not require full GPU functions.
The same type of commands in multiple virtual machines are encapsulated into the same virtual engine. The scheduling algorithm is used to calculate the time each virtual engine to be run is allowed to occupy the physical engine, forming a work queue and executing commands in sequence to avoid resource waste.
Effectively utilize GPU resources to ensure that every command of the virtual engine to be run is executed, avoiding the situation where the physics engine is occupied for a long time by a few virtual engines while other virtual engines cannot be occupied.
Smart Images

Figure CN115586955B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud computing technology, and in particular to a command execution method, apparatus, computer equipment, storage medium, and computer program product. Background Art
[0002] With the rapid development of cloud computing and cloud services, end users have increasingly higher requirements for cloud resources. Among them, cloud users of cloud gaming, cloud desktops, machine learning, and deep learning are particularly sensitive to the performance of GPUs (Graphic Processing Units). Therefore, major manufacturers have conducted in-depth research on GPU virtualization technology.
[0003] Traditional command execution technology requires waiting for all commands in the current VM to complete before switching to the next VM to execute its commands. This means that the current VM occupies ownership of the GPU. However, in most practical applications, the commands to be executed in the VM do not require the full capabilities of the GPU, resulting in a waste of resources. Summary of the Invention
[0004] Based on this, it is necessary to provide a command execution method, apparatus, computer device, computer-readable storage medium and computer program product that can avoid waste of resources in order to address the above technical problems.
[0005] In a first aspect, the present application provides a command execution method, the method comprising:
[0006] Obtaining commands to be executed in multiple virtual machines, encapsulating the commands of the same type into the same virtual engine to obtain virtual engines to be run, where the number of the virtual engines is the same as the number of the types of the commands;
[0007] According to the order in which the command encapsulation of each of the virtual engines to be run is completed, a work queue including each of the virtual engines to be run is formed;
[0008] Based on the scheduling algorithm, calculating the time that each of the virtual engines to be run is allowed to occupy the physical engine;
[0009] Based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run in the work queue sequentially occupies the physical engine to execute the commands encapsulated by each virtual engine to be run.
[0010] In one embodiment, the calculating, based on the scheduling algorithm, the time period that each virtual engine to be run is allowed to occupy the physical engine includes:
[0011] When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the command encapsulated in the virtual engine to be run;
[0012] When it is detected that there are multiple virtual engines to be run in the work queue, the time period that each virtual engine to be run is allowed to occupy the physical engine is determined based on a scheduling algorithm.
[0013] In one embodiment, when it is detected that there are multiple virtual engines to be run in the work queue, determining the time period that each virtual engine to be run is allowed to occupy the physical engine based on a scheduling algorithm includes:
[0014] Obtaining total weight information of the virtual engines to be run, and obtaining weight information corresponding to each of the virtual engines to be run from input data of the physical device to which the physical engine belongs;
[0015] Obtaining weight information of each of the virtual engines to be run based on the parameter values corresponding to each of the virtual engines to be run and the total weight information;
[0016] Calculate the ratio of the weight information of each of the virtual engines to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each of the virtual engines to be run is allowed to occupy the physical engine; the scheduling period is a period for re-determining the time length that each of the virtual engines to be run is allowed to occupy the physical engine.
[0017] In one embodiment, when it is detected that there are multiple virtual engines to be run in the work queue, determining the time period that each virtual engine to be run is allowed to occupy the physical engine based on a scheduling algorithm, further includes:
[0018] Determining initial weight information of each of the virtual engines to be run based on the number of commands executed and the number of unexecuted commands of each of the virtual engines to be run during the previous allowed time period for occupying the physical engine;
[0019] Performing moving average processing on the initial weight information of each virtual engine to be run using an exponentially weighted moving average to obtain final weight information of each virtual engine to be run;
[0020] Normalizing the final weight information of each of the virtual engines to be run to obtain normalized weight information of each of the virtual engines to be run;
[0021] The second product of each normalized weight information and the scheduling period is calculated respectively to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0022] In one embodiment, the method of enabling each of the to-be-run virtual engines in the work queue to sequentially occupy the physical engine to execute the commands encapsulated by each of the to-be-run virtual engines based on the duration that each of the to-be-run virtual engines is allowed to occupy the physical engine and the duration that the physical engine can be occupied at one time, includes:
[0023] Taking out the virtual engines to be run from the head of the work queue in sequence according to a first-in-first-out method;
[0024] Based on the time period that each of the virtual engines to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time, each of the virtual engines to be run is taken out to occupy the physical engine to execute the encapsulated command;
[0025] When the time period for the virtual engine to be run to occupy the physical engine once ends and there are still unexecuted commands, the virtual engine to be run is added back to the end of the work queue, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0026] In one embodiment, the method of enabling each of the virtual engines to be run in the work queue to sequentially occupy the physical engine to execute the commands encapsulated by each virtual engine to be run based on the time allowed for each virtual engine to occupy the physical engine and the time that the physical engine can be occupied at one time, further includes:
[0027] When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state;
[0028] When the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
[0029] In one embodiment, the method further comprises:
[0030] When the command encapsulated in the to-be-run virtual engine is completely executed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
[0031] In a second aspect, the present application provides a command execution device, comprising:
[0032] A command encapsulation module is used to obtain commands to be executed in multiple virtual machines, encapsulate the commands of the same type into the same virtual engine, and obtain virtual engines to be run. The number of virtual engines is the same as the number of types to which the commands belong.
[0033] A work queue construction module, configured to construct a work queue including each of the virtual engines to be run according to the order in which the command encapsulation of each of the virtual engines to be run is completed;
[0034] A duration scheduling module, configured to calculate, based on a scheduling algorithm, the duration that each of the virtual engines to be run is allowed to occupy the physical engine;
[0035] The command execution module is used to enable each of the virtual engines to be run in the work queue to occupy the physical engine in turn to execute the commands encapsulated by each of the virtual engines to be run based on the time period each of the virtual engines to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time.
[0036] In a third aspect, the present application provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0037] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above method when executed by a processor.
[0038] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements the steps of the above method when executed by a processor.
[0039] The above-mentioned command execution method, apparatus, computer equipment, storage medium and computer program product can process commands in multiple virtual machines at the same time by encapsulating the same type of commands in multiple virtual machines into the same virtual engine, thereby avoiding the waste of resources in the physical engine. By using a scheduling algorithm, each virtual engine to be run in the work queue is assigned a time length that is allowed to occupy the physical engine, thereby ensuring that all commands encapsulated in each virtual engine to be run are executed. By executing the commands issued by the virtual machine according to the time length that each virtual engine to be run is allowed to occupy the physical engine and the time length that the physical engine can be occupied at one time, it is possible to avoid the situation where the physical engine is occupied for a long time by a few virtual engines to be run, while other virtual engines to be run cannot occupy the physical engine. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A diagram of an application environment of a command execution method in one embodiment;
[0041] Figure 2 1 is a flow chart of a command execution method according to an embodiment;
[0042] Figure 3 is a flowchart of a command execution method in another embodiment;
[0043] Figure 4 is a flowchart of a command execution method in another embodiment;
[0044] Figure 5 A schematic diagram of a framework of a command execution method in one embodiment;
[0045] Figure 6 A timing diagram of a command execution method in one embodiment;
[0046] Figure 7 is a flowchart of a command execution method in another embodiment;
[0047] Figure 8 is a structural block diagram of a command execution device in one embodiment;
[0048] Figure 9 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0050] The command execution method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The server 104 obtains the commands to be executed from multiple virtual machines, and encapsulates the same type of commands into the same virtual engine, thereby obtaining the virtual engines to be run. The server 104 organizes each virtual engine to be run into a work queue according to the order in which the commands of each virtual engine to be run are encapsulated. Based on the scheduling algorithm configured in the computing device, the server 104 calculates the time that each virtual engine to be run in the work queue is allowed to occupy the physical engine. After obtaining the time that each virtual engine to be run is allowed to occupy the physical engine, the server 104 then uses the time that the physical engine can be occupied at one time to orderly allow each virtual engine to be run in the work queue to occupy the physical engine in turn to execute the commands encapsulated by each virtual engine to be run. Terminal 102 may include, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices may include smart speakers, smart TVs, smart air conditioners, and smart car devices. Portable wearable devices may include smart watches, smart bracelets, and head-mounted devices. Server 104 may be implemented as a standalone server or a server cluster consisting of multiple servers.
[0051] In one embodiment, Figure 2 As shown, a command execution method is provided, which is applied to Figure 1 Taking the server 104 in the example as an example, the following steps are included:
[0052] Step 202: Obtain commands to be executed in multiple virtual machines, encapsulate commands of the same type into the same virtual engine, and obtain virtual engines to be run. The number of virtual engines is the same as the number of types to which each command belongs.
[0053] Among them, a virtual machine refers to a complete computer system with complete hardware system functions that runs in a completely isolated environment and is simulated by software. Users generate the commands to be executed through the virtual machine, thereby converting the operations to be executed into a language that can be recognized by the computer.
[0054] A command represents a user's request to a computer and is an instruction implemented by using the corresponding function in the computer. At the same time, commands for different virtual machines are encapsulated in different workloads of the virtual engine to distinguish the virtual machine to which each command belongs. For example, when a server obtains a codec command for converting information formats from a virtual machine, it needs to use the part of the computer with codec functions to execute the codec command. Commands are divided into two-dimensional commands, three-dimensional commands, and codec commands according to the functions implemented. The virtual engine is a structure that encapsulates the commands that need to be executed in the virtual machine.
[0055] Encapsulation refers to combining the obtained data and structure to form an organic whole, that is, organically combining the workload and the virtual engine to form a whole.
[0056] Specifically, after the server obtains the commands that need to be executed in multiple virtual machines, it places the obtained commands into the corresponding command buffer according to the type of each command. At the same time, it generates the same number of virtual engines as the type of command, and places the generated virtual engines into the engine storage area. When the server detects the existence of virtual engines in the engine storage area, it will encapsulate the commands of different virtual machines in the command buffer into different workloads according to the source of the commands, and encapsulate the workloads that encapsulate the same type of commands into the same virtual engine in the engine storage area, thereby obtaining the virtual engine to be run.
[0057] In an actual application, the server obtains three types of commands from three virtual machines, A, B, and C: 2D commands, 3D commands, and codec commands. After placing the obtained commands into corresponding command buffers according to their types, the server generates three virtual engines and places them into the engine storage area. When the server detects the existence of a virtual engine in the engine storage area, it encapsulates the 2D commands of different virtual machines in the 2D command buffer into different workloads based on the source of the commands, and then encapsulates the workloads encapsulating the 2D commands into the same virtual engine in the engine storage area. It also encapsulates the 3D commands of different virtual machines in the 3D command buffer into different workloads, and then encapsulates the workloads encapsulating the 3D commands into the same virtual engine in the engine storage area. It also encapsulates the codec commands of different virtual machines in the codec command buffer into different workloads, and then encapsulates the workloads encapsulating the codec commands into the same virtual engine in the engine storage area.
[0058] Step 204 : forming a work queue including each virtual engine to be run according to the order in which the command packaging of each virtual engine to be run is completed.
[0059] The work queue comprising each of the pending virtual engines is organized according to the order in which command encapsulation is completed. This means that the order in which the pending virtual engines are arranged in the work queue is determined based on the order in which the command encapsulation is completed. For example, if two types of commands, A and B, are encapsulated into corresponding virtual engines, and type A is encapsulated before type B, then the pending virtual engine encapsulated with type A will be placed before the pending virtual engine encapsulated with type B in the work queue.
[0060] Step 206: Based on the scheduling algorithm, calculate the time that each virtual engine to be run is allowed to occupy the physical engine.
[0061] The scheduling algorithm is a resource allocation algorithm specified for system resources. In reality, system resources are limited. When multiple processes attempt to use these resources, processes must be selected according to certain principles to occupy them. For example, in a batch processing system, due to the large number of short job processes, a scheduling algorithm that prioritizes short jobs can be used. Another example is that in a time-sharing system, to ensure a reasonable system response time, a round-robin method should be used for scheduling. The choice of scheduling algorithm is determined by the parameters input via the file descriptor. For example, if the input parameter is 1, a scheduling strategy that calculates weights based on the number of commands encapsulated in each virtual engine to be run is selected. If the input parameter is 2, a scheduling strategy with user-defined weights is selected.
[0062] Step 208 : Based on the time allowed for each virtual engine to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run in the work queue sequentially occupies the physical engine to execute the command encapsulated by each virtual engine to be run.
[0063] Physics engines are the physical devices that execute various commands in virtual machines. They are generally divided into real-time and high-precision engines. High-precision physics engines require higher processing power to calculate highly accurate physics and are often used in scientific experiments and computer-animated films. Real-time physics engines are primarily used in video games and other forms of interactive computing to simplify calculations and reduce accuracy in order to calculate game responses in a timely manner, ensuring that the game responds at an appropriate rate.
[0064] The physics engine's single-shot occupation duration indicates the time it takes to switch between the currently occupied virtual engines. For example, if the physics engine's single-shot occupation duration is 1ms, and there are two currently occupied virtual engines, A and B, then after Virtual Engine A takes 1ms to execute its encapsulated command, it switches to Virtual Engine B, which then takes 1ms to execute its encapsulated command. After Virtual Engine B takes 1ms to execute its encapsulated command, it switches back to Virtual Engine A. This switching cycle repeats until all encapsulated commands are executed.
[0065] Specifically, the server occupies the physical engine in turn to execute the commands encapsulated by each virtual engine to be run according to the arrangement position of each virtual engine to be run in the work queue, based on the time each virtual engine to be run is allowed to occupy the physical engine calculated by the scheduling algorithm and the duration that the physical engine can be occupied at one time adjusted by the physical device.
[0066] In a specific application, virtual engine A is allowed to occupy the physical engine for 20ms, virtual engine B is allowed to occupy the physical engine for 25ms, and virtual engine C is allowed to occupy the physical engine for 30ms. The physical engine can be occupied for 1ms at a time, and A, B, and C are arranged in the work queue in the order of A first, B second, and C third. When the physical engine is idle, virtual engine A submits a 1ms command to the physical engine for execution. Then virtual engine B submits a 1ms command to the physical engine for execution. Then virtual engine C submits a 1ms command to the physical engine for execution. The three virtual engines take turns submitting 1ms commands in the order of their arrangement until the encapsulated commands are executed.
[0067] In the above command method, by encapsulating the same type of commands in multiple virtual machines into the same virtual engine, the commands in multiple virtual machines can be processed simultaneously, thereby avoiding the waste of resources in the physical engine. By using a scheduling algorithm, each virtual engine to be run in the work queue is allocated the time it is allowed to occupy the physical engine, thereby ensuring that all the commands encapsulated in each virtual engine to be run are executed. By executing the commands issued by the virtual machine according to the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, it is possible to avoid the situation where the physical engine is occupied for a long time by a few virtual engines to be run, while other virtual engines to be run cannot occupy the physical engine.
[0068] In one embodiment, based on the scheduling algorithm, calculating the time that each virtual engine to be run is allowed to occupy the physical engine includes:
[0069] When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the command encapsulated in the virtual engine to be run.
[0070] When it is detected that there are multiple virtual engines to be run in the work queue, the time period that each virtual engine to be run is allowed to occupy the physical engine is determined based on the scheduling algorithm.
[0071] Specifically, when the server detects that there is only one virtual engine waiting to run in the work queue, it does not use a scheduling algorithm to calculate the time the virtual engine is allowed to occupy the physical engine. Instead, it directly dispatches the virtual engine to the physical engine, allowing the physical engine to execute all the commands encapsulated in the virtual engine in one go. When the server detects that there are multiple virtual engines waiting to run in the work queue, it uses a scheduling algorithm to calculate the time each virtual engine is allowed to occupy the physical engine, allowing the physical engines to execute the commands encapsulated by each virtual engine in turn.
[0072] In this embodiment, by determining whether to use a scheduling algorithm to calculate the time a virtual engine to be run is allowed to occupy a physical engine based on the number of virtual engines to be run, the processing flow during command execution can be simplified, so that commands can be executed in a timely manner.
[0073] In one embodiment, Figure 3 As shown, when it is detected that there are multiple virtual engines to be run in the work queue, a time slice is allocated to each virtual engine to be run, and the time period that each virtual engine to be run is allowed to occupy the physical engine is determined, including:
[0074] Step 302 : Obtain the total weight information of the virtual engines to be run, and obtain the weight information corresponding to each virtual engine to be run from the input data of the physical device to which the physical engine belongs.
[0075] Specifically, the server inputs the weight information of each virtual machine into the physical engine according to the user's preference. Since the weight relationship between the virtual machine and the virtual engine to be run is 1:1, the input weight information of the virtual machine can obtain the weight information of the virtual engine to be run corresponding to the virtual machine, and at the same time obtain the total weight information of the virtual engine to be run.
[0076] Step 304 : Obtaining weight information of each virtual engine to be run based on the parameter value and total weight information corresponding to each virtual engine to be run.
[0077] Step 306 : Calculate the ratio of the weight information of each virtual engine to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0078] The scheduling period is a period for re-determining the time that each virtual engine to be run is allowed to occupy the physical engine, and can be a value such as 16ms that does not cause the user to feel screen lag.
[0079] Specifically, after calculating the ratio of the weight information of each virtual engine to be run to the total weight information, the server multiplies each ratio obtained by the scheduling period to obtain the time period that each virtual engine to be run is allowed to occupy the physical engine.
[0080] In this embodiment, the weight information of each virtual engine to be run is obtained by customizing the output parameter value, so that the user can specify the weight of the virtual machine according to his or her needs, so that the command that the user requires to be completed as soon as possible can be executed quickly.
[0081] In one embodiment, Figure 4 As shown, when it is detected that there are multiple virtual engines to be run in the work queue, a time slice is allocated to each virtual engine to be run, and the time length that each virtual engine to be run is allowed to occupy the physical engine is determined, which also includes:
[0082] Step 402 : Determine initial weight information of each virtual engine to be run based on the number of commands executed and the number of unexecuted commands of each virtual engine to be run during the previous allowed time period for each virtual engine to occupy the physical engine.
[0083] The previous allowed duration of physical engine occupation refers to the duration that the running virtual engine was allowed to occupy the physical engine before it received the current allowed duration. For example, if the current allowed duration of physical engine occupation for virtual engine A is 10ms, but after one scheduling cycle, the allowed duration of physical engine occupation determined by the scheduling algorithm is 15ms, then the 10ms duration is the previous allowed duration of physical engine occupation for virtual engine A.
[0084] Specifically, the server uses a scheduling algorithm to calculate the initial weight information of each virtual engine to be run based on the number of commands that have been executed and the number of commands that have not been executed during the previous time allowed for each virtual engine to occupy the physical engine, and controls the sensitivity of the scheduling algorithm to congested commands by adding a constant.
[0085] In a specific application, the number of commands that have been executed by the virtual engine i to be run in the previous allowed time to occupy the physical engine is w i ', the number of commands that have not yet been executed is The weight information of running virtual engine i is expressed as c is a constant that controls the sensitivity of the scheduling algorithm to congestion commands, usually T represents the scheduling period.
[0086] Step 404 : Use exponentially weighted moving average to perform moving average processing on the initial weight information of each virtual engine to be run, so as to obtain the final weight information of each virtual engine to be run.
[0087] Among them, the exponentially weighted moving average means that the weighting coefficient of each value decreases exponentially over time, and the closer the value is to the current moment, the larger the weighting coefficient is.
[0088] Specifically, the server uses the exponentially weighted moving average method to process the initial weight information of each virtual engine to be run, so as to smooth the impact caused by the large changes in the commands encapsulated by the virtual engine to be run in a short period of time. The final weight information W after the moving average processing is i W i =α*w i +(1-α)*w i-1 ,α is the parameter that adjusts the impact of the command ratio on the prediction, which can be taken as 0.8.
[0089] Step 406 : Normalize the final weight information of each virtual engine to be run to obtain normalized weight information of each virtual engine to be run.
[0090] Normalization is used to confine the preprocessed data to a certain range, thereby eliminating the adverse effects of outliers. For example, for a system with a sampling frequency of 500 Hz, a normalized frequency of 400 Hz is 400 / 500 = 0.8, placing the normalized frequency range between [0, 1]. To convert the normalized frequency to angular frequency, multiply it by 2 / pi.
[0091] Specifically, the server adopts a normalization processing method to normalize the final weight information of each virtual engine to be run, thereby obtaining the normalized weight information W corresponding to each virtual engine to be run. i 'For W i '=atan(W i )*(2 / π).
[0092] Step 408 : Calculate the second product of each normalized weight information and the scheduling period to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0093] Specifically, the server obtains the normalized weight information W corresponding to each virtual engine to be run i 'After the scheduling period T, the normalized weight information W is calculated iThe product of ' and the scheduling period T is used to obtain the time that each virtual engine to be run is allowed to occupy the physical engine.
[0094] In this embodiment, by using an exponentially weighted moving average to process the initial weight information of each virtual engine to be run, the impact caused by a large change in the commands encapsulated by the virtual engine to be run in a short period of time can be mitigated.
[0095] In one embodiment, based on the time allowed for each virtual engine to be run to occupy the physical engine and the time that the physical engine can be occupied at one time, each virtual engine to be run in the work queue is sequentially occupied by the physical engine to execute the command encapsulated by each virtual engine to be run, including:
[0096] In a first-in-first-out manner, the virtual engines to be run are taken out from the head of the work queue in sequence.
[0097] Based on the time period that each virtual engine to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time, each virtual engine to be run is taken out to occupy the physical engine to execute the encapsulated command.
[0098] When the time that the virtual engine to be run occupies the physical engine once ends and there are still unexecuted commands, the virtual engine to be run is added to the end of the work queue again, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0099] The first-in-first-out (FIFO) method removes the first virtual engine from the work queue that completed command encapsulation. For example, if virtual engine A completes command encapsulation before virtual engine B, when removing virtual engines from the work queue to occupy physical engines, virtual engine A is removed first, followed by virtual engine B.
[0100] Specifically, the server removes each pending virtual engine from the work queue in the order in which the encapsulated commands are completed. Based on the time each pending virtual engine is allowed to occupy the physical engine and the time that the physical engine can be occupied at one time, each pending virtual engine sequentially occupies the physical engine to execute the encapsulated commands. When the server detects that a pending virtual engine has completed its command execution task but there are still unexecuted commands, the pending virtual engine that has not completed its command execution returns to the end of the work queue, waiting to be removed again to complete the execution of the unexecuted commands. This process is repeated until all the encapsulated commands in the pending virtual engine are executed.
[0101] In this embodiment, a first-in, first-out (FIFO) approach is used to select the virtual engines to be executed. This allows the virtual engines that complete command encapsulation first to occupy the physical engine first, thus ensuring fairness in command execution. The algorithm is also relatively simple to implement. By executing commands issued by the virtual machine based on the time allowed for each virtual engine to occupy the physical engine and the maximum time a physical engine can be occupied at a time, this prevents situations where a small number of virtual engines are occupying the physical engine for extended periods, leaving other virtual engines unable to occupy the physical engine.
[0102] In one embodiment, based on the time allowed for each virtual engine to be run to occupy the physical engine and the time that the physical engine can be occupied at one time, each virtual engine to be run in the work queue is sequentially occupied by the physical engine to execute the command encapsulated by each virtual engine to be run, further comprising:
[0103] When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state.
[0104] When the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
[0105] The non-idle state indicates that the physical engine is currently executing commands encapsulated in the virtual engine to be run and cannot be occupied by a new virtual engine to be run. The idle state indicates that the physical engine is not currently executing commands and can be directly occupied by the waiting virtual engine to be run.
[0106] Specifically, after the server takes out the virtual engines to be run from the work queue in sequence, it will first detect the state of the current physical engine. If the current physical engine is in an idle state, the virtual engines to be run will be directly distributed to the physical engine to execute the encapsulated commands; if the current physical engine is in a non-idle state, the virtual engines to be run will be adjusted to a waiting state, and when the physical engine is in an idle state, they will be distributed to the physical engine to execute the encapsulated commands.
[0107] In this embodiment, by determining the current state of the physical engine, each virtual engine to be run can occupy the physical engine in sequence and in an orderly manner to execute the encapsulated command, thereby avoiding congestion caused by multiple virtual engines to be run occupying the physical engine at the same time.
[0108] In one embodiment, the command execution method further includes:
[0109] When the command encapsulated in the virtual engine to be run is completed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
[0110] In this embodiment, by controlling the physical engine to send a command execution completion signal to the virtual machine corresponding to the executed command, it is possible to avoid the virtual machine from repeatedly sending the same command, thereby reducing waste of resources.
[0111] The present application also provides an application scenario, which applies the above-mentioned command execution method. Specifically, the application of the command execution method in this application scenario is as follows: when the physics engine has no command execution task, the parameters in the scheduling framework and the working thread are initialized first, and after initialization, the scheduling framework and the working thread are in a sleep state. The framework diagram of the command execution method is as follows: Figure 5 As shown, when multiple virtual machines simultaneously issue 2D commands, 3D commands, and codec commands, the 2D application is started and the GPU driver places the issued 2D commands into the 2D command buffer. The 3D application is started and the GPU driver places the issued 3D commands into the 3D command buffer. The codec application is started and the GPU driver places the issued codec commands into the codec command buffer. The same number of virtual engines as the command types are generated and placed into the engine storage area. At this time, the existence of virtual engines in the engine storage area will be detected. The timing diagram corresponding to the 2D command is as follows: Figure 6 After the detection is completed, the scheduling framework and worker threads in the sleeping state will be awakened to execute the command.
[0112] After the scheduling framework and the working thread are awakened, the 2D commands, 3D commands, and codec commands issued by the virtual machine are encapsulated into the corresponding virtual engines, obtaining the virtual engines A, B, and C to be run. The virtual engines A, B, and C to be run are organized into a work queue in the order in which the encapsulated commands are completed. The work queues of the virtual engines A, B, and C to be run, which are encapsulated with 2D commands, 3D commands, and codec commands, are arranged as follows: A is arranged in position 1, B is arranged in position 2, and C is arranged in position 3. Since it is detected that the number of virtual engines to be run exceeds 1, a scheduling algorithm is needed to calculate the length of time that each of the virtual engines A, B, and C to be run is allowed to occupy the physical engine. There are two scheduling algorithms for calculating the length of time that a virtual engine to be run is allowed to occupy the physical engine.
[0113] The first method is to customize the weights of each virtual engine to be run by the user. First, the total weight information set by the R&D personnel of the physical device to which the physical engine belongs during development is determined. When the virtual engines A, B, and C to be run are obtained, the weight information of each virtual engine A, B, and C to be run is determined by reading and writing file descriptors according to the user's preference. Then, the ratio of the total weight information to the virtual engines A, B, and C to be run is calculated respectively. Finally, the product of the ratio and the scheduling period is calculated to obtain the length of time that each virtual engine A, B, and C to be run is allowed to occupy the physical engine.
[0114] The second method is to calculate the weight of each virtual engine to be run according to the command encapsulated in each virtual engine to be run. First, determine the number of commands w executed by the virtual engines to be run A, B and C in the previous time allowed to occupy the physical engine. i ', and the number of unprocessed commands The constant c is introduced to control the sensitivity of the scheduling algorithm to congestion commands, and the weight calculation formula for the virtual engines A, B and C to be run is obtained as follows: Since the commands encapsulated by some virtual engines to be run may change significantly in a short period of time, it is also necessary to use exponential weighted average to process the weight calculation formula. The final weight information of each virtual engine to be run is W i =α*w i +(1-α)*w i-1 Then, in order to limit the preprocessed data to a certain range, the final weight is normalized to obtain the normalized weight W i '=atan(W i )*(2 / π). Finally, the obtained normalized weight is multiplied by the scheduling period to obtain the time that each of the running virtual engines A, B, and C is allowed to occupy the physical engine.
[0115] The second scheduling algorithm is used to calculate the length of time each virtual engine to be run is allowed to occupy the physical engine. It is found that the length of time that virtual engine A to be run is allowed to occupy the physical engine is 10ms, the length of time that virtual engine B to be run is allowed to occupy the physical engine is 15ms, and the length of time that virtual engine C to be run is allowed to occupy the physical engine is 20ms. When the physical engine can be occupied for 1ms at a time, virtual engines A, B, and C to be run take turns submitting 1ms commands for execution in sequence. After executing a command, the physical engine will send a command execution completion signal to the corresponding virtual machine. After all the commands issued by the virtual machine are executed and the command execution completion signal is sent, the scheduling framework and the working thread re-enter the sleep state and wait to be woken up again. The flow chart of the command execution method is shown as follows. Figure 7 shown.
[0116] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0117] Based on the same inventive concept, embodiments of the present application also provide a command execution device for implementing the aforementioned command execution method. The implementation solution provided by this device is similar to the implementation solution described in the aforementioned method. Therefore, the specific limitations of one or more command execution device embodiments provided below can be found in the above-mentioned limitations of the command execution method and will not be repeated here.
[0118] In one embodiment, Figure 8 As shown, a command execution device is provided, comprising:
[0119] The command encapsulation module 802 is used to obtain commands to be executed in multiple virtual machines, encapsulate commands of the same type into the same virtual engine, and obtain virtual engines to be run. The number of virtual engines is the same as the number of types of commands.
[0120] The work queue construction module 804 is configured to construct a work queue including each virtual engine to be run according to the order in which the command packaging of each virtual engine to be run is completed.
[0121] The duration scheduling module 806 is used to calculate the duration that each virtual engine to be run is allowed to occupy the physical engine based on a scheduling algorithm.
[0122] The command execution module 808 is used to enable each virtual engine to be run in the work queue to occupy the physical engine in turn to execute the command encapsulated by each virtual engine to be run based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time.
[0123] In one embodiment, the duration scheduling module further includes:
[0124] The first detection unit is configured to, when detecting that there is only one virtual engine to be run in the work queue, directly distribute the virtual engine to be run to the physical engine to execute the command encapsulated in the virtual engine to be run.
[0125] The second detection unit is configured to determine, based on a scheduling algorithm, the time period that each virtual engine to be run is allowed to occupy the physical engine when it is detected that there are multiple virtual engines to be run in the work queue.
[0126] In one embodiment, the second detection unit further includes:
[0127] The total weight information acquisition subunit is used to obtain the total weight information of the virtual engine to be run.
[0128] The file descriptor reading and writing subunit is used to input the parameter values corresponding to each virtual engine to be run into the physical device to which the physical engine belongs based on the file descriptor reading and writing method.
[0129] The weight information calculation subunit is used to obtain the weight information of each virtual engine to be run based on the parameter value corresponding to each virtual engine to be run and the total weight information.
[0130] The first duration calculation subunit is used to calculate the ratio of the weight information of each virtual engine to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the duration that each virtual engine to be run is allowed to occupy the physical engine.
[0131] In one embodiment, the second detection unit further includes:
[0132] The initial weight information calculation subunit is used to determine the initial weight information of each virtual engine to be run based on the number of commands executed and the number of unexecuted commands of each virtual engine to be run during the previous allowed time period for occupying the physical engine.
[0133] The final weight information calculation subunit is used to perform moving average processing on the initial weight information of each virtual engine to be run using an exponentially weighted moving average to obtain the final weight information of each virtual engine to be run.
[0134] The normalized weight information calculation subunit is used to normalize the final weight information of each virtual engine to be run, so as to obtain normalized weight information of each virtual engine to be run.
[0135] The second duration calculation subunit is used to respectively calculate the second product of each normalized weight information and the scheduling period to obtain the duration that each virtual engine to be run is allowed to occupy the physical engine.
[0136] In one embodiment, the command execution module further includes:
[0137] The engine acquisition unit is used to sequentially retrieve the virtual engines to be run from the head of the work queue in a first-in-first-out manner.
[0138] The command execution unit is used to make each virtual engine to be run occupy the physical engine to execute the encapsulated command based on the time allowed for each virtual engine to be run to occupy the physical engine and the time that the physical engine can be occupied at one time.
[0139] The command waiting unit is used to add the virtual engine to the end of the work queue when the time period for the virtual engine to be run to occupy the physical engine once ends and there are still unexecuted commands, and wait for the virtual engine to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0140] In one embodiment, the command execution module further includes:
[0141] The first state determination unit adjusts the virtual engine to be run to a waiting state when the physical engine is in a non-idle state.
[0142] The second state determination unit is configured to directly distribute the taken-out virtual engine to be run to the physical engine to execute the encapsulated command when the physical engine is in an idle state.
[0143] In one embodiment, the command execution device further includes:
[0144] The completion signal return module is used to control the physical engine to send a command execution completion signal to the virtual machine corresponding to the executed command after the command encapsulated in the virtual engine to be run is executed by the physical engine.
[0145] Each module in the command execution device can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0146] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 9As shown. The computer device includes a processor, a memory, an input / output interface (I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store the commands to be executed in the virtual machine, the type of each command, the number of command types, the order in which command encapsulation is completed, the scheduling algorithm, the time each virtual engine to be run is allowed to occupy the physical engine, the time a physical engine can be occupied at one time, the number of virtual engines to be run in the work queue, the total weight information of the virtual engines to be run, the weight information of each virtual engine to be run, the ratio of the weight information of each virtual engine to be run to the total weight information, the first product, the second product, the scheduling cycle, the initial weight information and final weight information of each virtual engine to be run, and the normalized weight information data. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a command method is implemented.
[0147] Those skilled in the art will understand that Figure 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0148] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0149] Obtain commands that need to be executed in multiple virtual machines, encapsulate commands of the same type into the same virtual engine, and obtain virtual engines to be run, where the number of virtual engines is the same as the number of types to which each command belongs; form a work queue including each virtual engine to be run according to the order in which command encapsulation of each virtual engine to be run is completed; calculate the time each virtual engine to be run is allowed to occupy the physical engine based on the scheduling algorithm; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run in the work queue is allowed to occupy the physical engine in turn to execute the command encapsulated by each virtual engine to be run.
[0150] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0151] When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the commands encapsulated in the virtual engine to be run; when it is detected that there are multiple virtual engines to be run in the work queue, the length of time each virtual engine to be run is allowed to occupy the physical engine is determined based on the scheduling algorithm.
[0152] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0153] Obtain the total weight information of the virtual engines to be run, and obtain the weight information corresponding to each virtual engine to be run from the input data of the physical device to which the physical engine belongs; obtain the weight information of each virtual engine to be run based on the parameter value corresponding to each virtual engine to be run and the total weight information; calculate the ratio of the weight information of each virtual engine to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0154] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0155] Based on the number of commands executed and the number of unexecuted commands by each virtual engine to be run during the previous allowed time period for occupying the physical engine, the initial weight information of each virtual engine to be run is determined; the initial weight information of each virtual engine to be run is averaged using an exponentially weighted moving average to obtain the final weight information of each virtual engine to be run; the final weight information of each virtual engine to be run is normalized to obtain the normalized weight information of each virtual engine to be run; the second product of each normalized weight information and the scheduling period is calculated to obtain the time period that each virtual engine to be run is allowed to occupy the physical engine.
[0156] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0157] In a first-in-first-out manner, the virtual engines to be run are taken out from the head of the work queue in sequence; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run is taken out and is allowed to occupy the physical engine to execute the encapsulated command; when the time the virtual engine to be run occupies the physical engine at one time ends and there are still unexecuted commands, the virtual engine to be run is added back to the end of the work queue, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0158] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0159] When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state; when the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
[0160] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0161] When the command encapsulated in the virtual engine to be run is completed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
[0162] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0163] Obtain commands that need to be executed in multiple virtual machines, encapsulate commands of the same type into the same virtual engine, and obtain virtual engines to be run, where the number of virtual engines is the same as the number of types to which each command belongs; form a work queue including each virtual engine to be run according to the order in which command encapsulation of each virtual engine to be run is completed; calculate the time each virtual engine to be run is allowed to occupy the physical engine based on the scheduling algorithm; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run in the work queue is allowed to occupy the physical engine in turn to execute the command encapsulated by each virtual engine to be run.
[0164] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0165] When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the commands encapsulated in the virtual engine to be run; when it is detected that there are multiple virtual engines to be run in the work queue, the length of time each virtual engine to be run is allowed to occupy the physical engine is determined based on the scheduling algorithm.
[0166] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0167] Obtain the total weight information of the virtual engines to be run, and obtain the weight information corresponding to each virtual engine to be run from the input data of the physical device to which the physical engine belongs; obtain the weight information of each virtual engine to be run based on the parameter value corresponding to each virtual engine to be run and the total weight information; calculate the ratio of the weight information of each virtual engine to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0168] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0169] Based on the number of commands executed and the number of unexecuted commands by each virtual engine to be run during the previous allowed time period for occupying the physical engine, the initial weight information of each virtual engine to be run is determined; the initial weight information of each virtual engine to be run is averaged using an exponentially weighted moving average to obtain the final weight information of each virtual engine to be run; the final weight information of each virtual engine to be run is normalized to obtain the normalized weight information of each virtual engine to be run; the second product of each normalized weight information and the scheduling period is calculated to obtain the time period that each virtual engine to be run is allowed to occupy the physical engine.
[0170] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0171] In a first-in-first-out manner, the virtual engines to be run are taken out from the head of the work queue in sequence; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run is taken out and is allowed to occupy the physical engine to execute the encapsulated command; when the time the virtual engine to be run occupies the physical engine at one time ends and there are still unexecuted commands, the virtual engine to be run is added back to the end of the work queue, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0172] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0173] When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state; when the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
[0174] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0175] When the command encapsulated in the virtual engine to be run is completed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
[0176] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0177] Obtain commands that need to be executed in multiple virtual machines, encapsulate commands of the same type into the same virtual engine, and obtain virtual engines to be run, where the number of virtual engines is the same as the number of types to which each command belongs; form a work queue including each virtual engine to be run according to the order in which command encapsulation of each virtual engine to be run is completed; calculate the time each virtual engine to be run is allowed to occupy the physical engine based on the scheduling algorithm; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run in the work queue is allowed to occupy the physical engine in turn to execute the command encapsulated by each virtual engine to be run.
[0178] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0179] When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the commands encapsulated in the virtual engine to be run; when it is detected that there are multiple virtual engines to be run in the work queue, the length of time each virtual engine to be run is allowed to occupy the physical engine is determined based on the scheduling algorithm.
[0180] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0181] Obtain the total weight information of the virtual engines to be run, and obtain the weight information corresponding to each virtual engine to be run from the input data of the physical device to which the physical engine belongs; obtain the weight information of each virtual engine to be run based on the parameter value corresponding to each virtual engine to be run and the total weight information; calculate the ratio of the weight information of each virtual engine to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
[0182] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0183] Based on the number of commands executed and the number of unexecuted commands by each virtual engine to be run during the previous allowed time period for occupying the physical engine, the initial weight information of each virtual engine to be run is determined; the initial weight information of each virtual engine to be run is averaged using an exponentially weighted moving average to obtain the final weight information of each virtual engine to be run; the final weight information of each virtual engine to be run is normalized to obtain the normalized weight information of each virtual engine to be run; the second product of each normalized weight information and the scheduling period is calculated to obtain the time period that each virtual engine to be run is allowed to occupy the physical engine.
[0184] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0185] In a first-in-first-out manner, the virtual engines to be run are taken out from the head of the work queue in sequence; based on the time each virtual engine to be run is allowed to occupy the physical engine and the time the physical engine can be occupied at one time, each virtual engine to be run is taken out and is allowed to occupy the physical engine to execute the encapsulated command; when the time the virtual engine to be run occupies the physical engine at one time ends and there are still unexecuted commands, the virtual engine to be run is added back to the end of the work queue, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
[0186] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0187] When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state; when the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
[0188] In one embodiment, when the computer program is executed by a processor, the following steps are further implemented:
[0189] When the command encapsulated in the virtual engine to be run is completed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
[0190] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions.
[0191] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, database or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processor involved in the various embodiments provided herein may be, but are not limited to, a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, and the like.
[0192] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0193] The above embodiments merely illustrate several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art may make various modifications and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A command execution method, characterized in that: The method comprises: Obtaining commands to be executed in multiple virtual machines, encapsulating the commands of the same type into the same virtual engine to obtain virtual engines to be run, where the number of the virtual engines is the same as the number of the types of the commands; According to the order in which the command encapsulation of each of the virtual engines to be run is completed, a work queue including each of the virtual engines to be run is formed; Calculating the time that each virtual engine to be run is allowed to occupy the physical engine based on the scheduling algorithm; Based on the time period that each of the virtual engines to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time, each of the virtual engines to be run in the work queue sequentially occupies the physical engine to execute the commands encapsulated by each of the virtual engines to be run; The method of enabling each of the to-be-run virtual engines in the work queue to sequentially occupy the physical engine to execute commands encapsulated by each of the to-be-run virtual engines based on the time duration each of the to-be-run virtual engines is allowed to occupy the physical engine and the time duration that the physical engine can be occupied at one time, includes: Taking out the virtual engines to be run from the head of the work queue in sequence according to a first-in-first-out method; Based on the time period that each of the virtual engines to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time, each of the virtual engines to be run is taken out to occupy the physical engine to execute the encapsulated command; When the time period for the virtual engine to be run to occupy the physical engine once ends and there are still unexecuted commands, the virtual engine to be run is added back to the end of the work queue, waiting to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
2. The method according to claim 1, characterized in that The calculating, based on the scheduling algorithm, the time period that each virtual engine to be run is allowed to occupy the physical engine includes: When it is detected that there is only one virtual engine to be run in the work queue, the virtual engine to be run is directly distributed to the physical engine to execute the command encapsulated in the virtual engine to be run; When it is detected that there are multiple virtual engines to be run in the work queue, the time period that each virtual engine to be run is allowed to occupy the physical engine is determined based on a scheduling algorithm.
3. The method according to claim 2, characterized in that When it is detected that there are multiple virtual engines to be run in the work queue, determining the time period that each virtual engine to be run is allowed to occupy the physical engine based on a scheduling algorithm, including: Obtaining total weight information of the virtual engines to be run, and obtaining weight information corresponding to each of the virtual engines to be run from input data of the physical device to which the physical engine belongs; Calculate the ratio of the weight information of each of the virtual engines to be run to the total weight information, and calculate the first product of the ratio and the scheduling period to obtain the time length that each of the virtual engines to be run is allowed to occupy the physical engine; the scheduling period is a period for re-determining the time length that each of the virtual engines to be run is allowed to occupy the physical engine.
4. The method according to claim 2, characterized in that When it is detected that there are multiple virtual engines to be run in the work queue, determining the time period that each virtual engine to be run is allowed to occupy the physical engine based on a scheduling algorithm, further comprising: Determining initial weight information of each of the virtual engines to be run based on the number of commands executed and the number of unexecuted commands of each of the virtual engines to be run during the previous allowed time period for occupying the physical engine; Performing moving average processing on the initial weight information of each virtual engine to be run using an exponentially weighted moving average to obtain final weight information of each virtual engine to be run; Normalizing the final weight information of each of the virtual engines to be run to obtain normalized weight information of each of the virtual engines to be run; The second product of each normalized weight information and the scheduling period is calculated respectively to obtain the time length that each virtual engine to be run is allowed to occupy the physical engine.
5. The method according to claim 1, wherein The method further includes: determining the time period that each virtual engine to be run is allowed to occupy the physical engine and the time period that the physical engine can be occupied at one time, so that each virtual engine to be run in the work queue sequentially occupies the physical engine to execute the command encapsulated by each virtual engine to be run; When the physical engine is in a non-idle state, the virtual engine to be run is adjusted to a waiting state; When the physical engine is in an idle state, the virtual engine to be run is directly distributed to the physical engine to execute the encapsulated command.
6. The method according to claim 1, characterized in that The method further comprises: When the command encapsulated in the to-be-run virtual engine is completely executed by the physical engine, the physical engine is controlled to send a command execution completion signal to the virtual machine corresponding to the executed command.
7. A command execution device, characterized in that: The device comprises: A command encapsulation module is used to obtain commands to be executed in multiple virtual machines, encapsulate the commands of the same type into the same virtual engine, and obtain virtual engines to be run. The number of virtual engines is the same as the number of types to which the commands belong. A work queue construction module, configured to construct a work queue including each of the virtual engines to be run according to the order in which the command encapsulation of each of the virtual engines to be run is completed; A duration scheduling module, configured to calculate, based on a scheduling algorithm, the duration that each of the virtual engines to be run is allowed to occupy the physical engine; A command execution module, configured to enable each of the virtual engines to be run in the work queue to sequentially occupy the physical engine to execute the commands encapsulated by each virtual engine to be run, based on the time allowed for each virtual engine to occupy the physical engine and the time that the physical engine can be occupied at one time; The command execution module also includes: An engine acquisition unit, configured to sequentially retrieve the virtual engines to be run from the head of the work queue in a first-in-first-out manner; a command execution unit, configured to, based on the time allowed for each of the virtual engines to be run to occupy the physical engine and the time that the physical engine can be occupied at one time, enable each of the virtual engines to be run to occupy the physical engine to execute the encapsulated command; The command waiting unit is used to add the virtual engine to the end of the work queue when the time period for the virtual engine to be run to occupy the physical engine once ends and there are still unexecuted commands, and wait for the virtual engine to occupy the physical engine again to execute the unexecuted commands of each virtual engine to be run.
8. The device according to claim 7, characterized in that The duration scheduling module also includes: A first detection unit is configured to, when detecting that there is only one virtual engine to be run in the work queue, directly dispatch the virtual engine to be run to the physical engine to execute the command encapsulated in the virtual engine to be run; The second detection unit is configured to determine, based on a scheduling algorithm, a time period that each of the virtual engines to be run is allowed to occupy the physical engine when it is detected that there are multiple virtual engines to be run in the work queue.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.