Task scheduling method and device based on virtual machine, equipment, medium and product

By using synchronization objects and time-slice scheduling threads to dynamically manage tasks in GPU virtualization technology, the problems of insufficient resource utilization and task blocking are solved, and efficient task scheduling and synchronization processing are achieved.

CN121785779APending Publication Date: 2026-04-03MOORE THREADS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

In existing GPU virtualization technologies, resource scheduling methods lead to insufficient utilization of physical GPU resources. Resources are idle when the task load is low, while task queuing and blocking occur during peak load periods, affecting the overall efficiency and responsiveness in multi-user environments.

Method used

By determining the first synchronization object corresponding to a task upon receiving it, and dynamically scheduling the task based on the state of the synchronization object, blocking or executing the task, dynamic resource management is achieved using a synchronization object pool and time-slice scheduling thread, thus avoiding task queuing and blocking.

Benefits of technology

It improves resource utilization efficiency in multi-user environments, avoids resource idleness and task blocking, and realizes dynamic scheduling and synchronous processing of tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121785779A_ABST
    Figure CN121785779A_ABST
Patent Text Reader

Abstract

The invention provides a task scheduling method and device based on a virtual machine, equipment, a medium and a product, the method is applied to processing equipment, at least one virtual machine runs in the processing equipment, and the method comprises the steps that under the condition that a to-be-processed task sent by a target virtual machine is received, the to-be-processed task is sent to the target virtual machine; determining a first synchronization object of the to-be-processed task in a first time slice, the target virtual machine being any one of the at least one virtual machine, the first time slice being one of target time slices allocated to the target virtual machine by the processing device, and the target time slice comprising at least one time slice; when it is detected that the first synchronization object is in a dormant state, blocking the to-be-processed task; and when it is detected that the first synchronization object is in the working state, executing the to-be-processed task. According to the embodiment of the invention, the phenomena of task queuing and task blocking can be avoided, and the resource use efficiency in a multi-user environment is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a task scheduling method and apparatus based on a virtual machine, an electronic device, a computer-readable storage medium, and a computer program product. Background Technology

[0002] In the field of Graphics Processing Unit (GPU) virtualization, a common approach involves dividing a single physical GPU device into multiple virtual resources to support the simultaneous operation of multiple GPU virtual machines. These virtual machines share the computing resources of the same physical GPU, thereby achieving hardware resource reuse. Currently, common computing power scheduling methods include static resource allocation and / or First In, First Out (FIFO) scheduling strategies. However, practical experience shows that this resource scheduling method may lead to insufficient utilization of physical GPU resources. For example, resources may be idle when the task load is low, or task queuing and blocking may occur during peak task loads, thus affecting the overall efficiency and responsiveness in a multi-user environment. Summary of the Invention

[0003] This disclosure provides a virtual machine-based task scheduling method and apparatus, electronic device, computer-readable storage medium, and computer program product.

[0004] In a first aspect, this disclosure provides a virtual machine-based task scheduling method applied to a processing device, wherein at least one virtual machine runs in the processing device, and the method includes:

[0005] Upon receiving a pending task sent by a target virtual machine, the pending task is determined to be a first synchronization object in a first time slice, wherein the target virtual machine is any one of the at least one virtual machines, and the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice.

[0006] If the first synchronization object is detected to be in a dormant state, the task to be processed is blocked.

[0007] If the first synchronization object is detected to be in a working state, the pending task is executed.

[0008] Secondly, this disclosure provides a virtual machine-based task scheduling apparatus applied to a processing device, wherein at least one virtual machine runs in the processing device, and the apparatus includes:

[0009] The first determining module is configured to, upon receiving a task to be processed sent by a target virtual machine, determine a first synchronization object of the task to be processed in a first time slice, wherein the target virtual machine is any one of the at least one virtual machines, the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice.

[0010] The first blocking module is configured to block the task to be processed when the first synchronization object is detected to be in a dormant state.

[0011] The first execution module is configured to execute the task to be processed when the first synchronization object is detected to be in a working state.

[0012] Thirdly, this disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the virtual machine-based task scheduling method described above.

[0013] Fourthly, this disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-described virtual machine-based task scheduling method.

[0014] Fifthly, this disclosure provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is run in a processor of an electronic device, the processor in the electronic device executes the above-described virtual machine-based task scheduling method.

[0015] The virtual machine-based task scheduling method provided in this disclosure is applied to a processing device. The processing device runs at least one virtual machine. After receiving a task to be processed from any virtual machine running in the processing device, the processing device determines the first synchronization object of the task in the first time slice and detects the current state of the first synchronization object to determine whether to execute the task. If the first synchronization object is detected to be in a dormant state, the task is blocked; if the first synchronization object is detected to be in a working state, the task is executed. Synchronous processing of tasks is achieved based on synchronization objects, improving synchronization efficiency. By scheduling and managing tasks assigned to synchronization objects, the execution and pause of tasks corresponding to virtual machines can be dynamically adjusted according to the real-time state of the synchronization objects, avoiding task queuing and blocking, and improving resource utilization efficiency in a multi-user environment.

[0016] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0017] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the embodiments of the present disclosure to explain the disclosure and do not constitute a limitation thereof. The above and other features and advantages will become more apparent to those skilled in the art from the detailed description of exemplary embodiments with reference to the accompanying drawings, in which:

[0018] Figure 1 A schematic diagram illustrating a scenario for a virtual machine-based task scheduling method provided in this embodiment of the disclosure;

[0019] Figure 2 A flowchart illustrating a virtual machine-based task scheduling method provided in this disclosure embodiment;

[0020] Figure 3 A flowchart illustrating a virtual machine-based task scheduling method provided in this embodiment of the disclosure;

[0021] Figure 4 A block diagram of a virtual machine-based task scheduling device provided in this disclosure embodiment;

[0022] Figure 5 This is a block diagram of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation

[0023] To enable those skilled in the art to better understand the technical solutions of this disclosure, exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments of this disclosure to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0024] Where there is no conflict, the various embodiments of this disclosure and the features thereof in the embodiments may be combined with each other.

[0025] As used herein, the term “and / or” includes any and all combinations of one or more related enumerated entries.

[0026] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. As used herein, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that when the terms “comprising” and / or “made of” are used in this specification, the presence of the stated feature, integral, step, operation, element, and / or component is specified, but the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof is not excluded. Words such as “connected” or “linked” are not limited to physical or mechanical connections but can include electrical connections, whether direct or indirect.

[0027] Unless otherwise specified, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and this disclosure, and will not be interpreted as having an idealized or overly formal meaning, unless expressly so defined herein.

[0028] With the development of GPU virtualization technology, sharing physical GPU resources among multiple virtual machines has become a common requirement. In current GPU virtualization scenarios, methods such as static allocation, FIFO, and priority scheduling are typically used to schedule physical GPU resources. Static allocation assigns a fixed amount of GPU resources to each virtual machine during system initialization, but this method cannot adapt to dynamic workloads. FIFO or priority scheduling methods typically adjust the scheduling order based on the priority of virtual machines or tasks, with higher-priority tasks receiving GPU resources first. While this method ensures that high-priority tasks are executed promptly, it may cause low-priority tasks to be blocked for extended periods. Therefore, how to efficiently and fairly allocate resources among multiple virtual machines has become a crucial challenge in GPU virtualization technology.

[0029] According to the virtual machine-based task scheduling method of this disclosure, upon receiving a task to be processed from a virtual machine running in a processing device, a first synchronization object of the task to be processed is determined, and the task to be processed is added to the task queue corresponding to the virtual machine. If the first synchronization object is detected to be in a dormant state (the first synchronization object has not yet been marked by the time-slice scheduling thread), the task to be processed is blocked. After the first synchronization object is detected to be in a working state (the first synchronization object has been marked by the time-slice scheduling thread), the task to be processed is executed. After the task to be processed is completed, it is deleted from the task queue corresponding to the virtual machine. By scheduling the execution and pausing of the task to be processed through the synchronization object and the time-slice scheduling thread, dynamic resource scheduling of the task to be processed is achieved, avoiding resource idleness or task blocking, and improving the overall efficiency of task scheduling for resource utilization in a multi-user environment.

[0030] The virtual machine-based task scheduling method according to embodiments of this disclosure can be executed by electronic devices such as terminal devices or servers. Terminal devices can be in-vehicle devices, user equipment (UE), mobile devices, user terminals, terminals, cellular phones, cordless phones, personal digital assistants (PDAs), handheld devices, computing devices, in-vehicle devices, wearable devices, etc. The method can be implemented by a processor calling computer-readable program instructions stored in memory. Alternatively, the method can be executed by a server.

[0031] See Figure 1 , Figure 1 This is a schematic diagram illustrating a scenario for a virtual machine-based task scheduling method provided in an embodiment of this disclosure. For example... Figure 1As shown, the virtual machine-based task scheduling method is applied to a processing device, which also runs n virtual machines, namely virtual machine 1, virtual machine 2... virtual machine n, where n is an integer greater than or equal to 1. To facilitate the management of pending tasks sent by different virtual machines, a task queue is configured for each virtual machine, i.e. Figure 1 The diagram shows task queues 1, 2, ..., n. In practical applications, the processing device can create a main thread to receive pending tasks sent by different virtual machines and schedule and execute these tasks. Specifically, when the main thread receives a pending task from a virtual machine, it can add the task to the corresponding task queue of that virtual machine. After executing the task, it can remove it from the corresponding task queue. In addition, the processing device also runs a time-slice scheduling thread (…). Figure 1 (Not shown) The time-slice scheduling thread can be used to allocate time slices to multiple virtual machines and mark the synchronization objects corresponding to the tasks to be processed, so that the main thread can execute the tasks to be processed of the marked synchronization objects, thereby realizing dynamic scheduling of tasks to be processed based on the workload and resource usage of the processing device.

[0032] It should be noted that the above Figure 1 The present disclosure provides a virtual machine-based task scheduling method as an example, but this method can also be applied to other GPU virtualization scenarios, depending on the specific application. The following provides a detailed explanation of the virtual machine-based task scheduling method.

[0033] Figure 2 A flowchart illustrating a virtual machine-based task scheduling method provided in this disclosure. See also... Figure 2 The method specifically includes the following steps:

[0034] Step 202: Upon receiving a pending task sent by the target virtual machine, determine the first synchronization object of the pending task in the first time slice, wherein the target virtual machine is any one of the at least one virtual machine, the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice.

[0035] Step 204: If the first synchronization object is detected to be in a dormant state, the task to be processed is blocked.

[0036] Step 206: If the first synchronization object is detected to be in a working state, execute the task to be processed.

[0037] In this context, "processing device" refers to a physical device equipped with GPU resources. The processing device contains a GPU virtualization module. When the GPU virtualization module starts, it indicates that multiple virtual machines corresponding to the processing device begin sharing the GPU resources. "Pending task" refers to a task sent by the target virtual machine to the main thread in the processing device, awaiting processing. In practical applications, pending tasks can be image processing tasks, video processing tasks, text processing tasks, etc. This disclosure does not limit the type of pending task. "Synchronization object" is used to track the dependencies and execution status of pending tasks. In practical applications, the synchronization object is specifically a synchronization primitive in the Linux kernel, namely `dma_fence`. "First synchronization object" refers to the synchronization object before the pending task is executed, that is, the first synchronization object assigned to it by the main thread upon receiving the pending task. "Sleeping state" refers to the state of the synchronization object before the time-slice scheduling thread marks it, while "working state" refers to the state of the synchronization object after the time-slice scheduling thread has marked it.

[0038] Specifically, after the GPU virtualization module in the processing device starts, multiple virtual machines running on the processing device can send pending tasks to the main thread running on the processing device. Upon receiving a pending task from any virtual machine, the main thread allocates a corresponding first synchronization object for the received task. The main thread monitors the current state of the first synchronization object in real time to determine whether to start executing the pending task based on the current state. In practical applications, the time-slice scheduling thread allocates a corresponding number of time slices to each virtual machine running on the processing device and schedules and executes the time slices in chronological order. When the time-slice scheduling thread schedules the target time slice for the target virtual machine, it begins marking the synchronization objects of multiple tasks corresponding to the target virtual machine, thus allowing the main thread to begin executing the multiple tasks sent by the target virtual machine. Before the time-slice scheduling thread marks the first synchronization object, the first synchronization object is in a dormant state, indicating that the pending task cannot be executed; after the time-slice scheduling thread marks the first synchronization object, the first synchronization object is in a working state, indicating that the pending task can begin execution. Therefore, when the main thread detects that the first synchronization object is in a sleeping state, it means that the first synchronization object has not yet been marked by the time-slice scheduling thread, and the pending task is blocked; when it detects that the first synchronization object is in a working state, it means that the first synchronization object has been marked by the time-slice scheduling thread, and the pending task is executed.

[0039] This embodiment of the disclosure can assign a corresponding synchronization object to each task, and when the target time slice corresponding to the target virtual machine is reached, the current state of the first synchronization object of the task to be processed is detected to determine whether the first synchronization object is currently in a dormant state or a working state. Based on the current state of the first synchronization object, it is determined whether to execute the task to be processed, so as to realize the dynamic adjustment of the processing of multiple tasks in the processing device, avoid task queuing and task blocking, and improve resource utilization.

[0040] Furthermore, to ensure that the tasks sent by each virtual machine can be executed in an orderly manner and to further improve task processing efficiency, a corresponding task queue can be created for each virtual machine to manage and schedule the tasks sent by each virtual machine.

[0041] Based on this, in a specific embodiment provided in this disclosure, the method further includes: adding the task to be processed to the task queue corresponding to the target virtual machine; and deleting the task from the task queue when the task to be processed is completed.

[0042] A task queue is a queue used to store pending tasks sent by a virtual machine. Specifically, upon receiving a pending task from a target virtual machine, the task is added to the corresponding task queue of the target virtual machine. During the execution of the pending task, its execution status can be checked, i.e., whether the task has been completed. If it is determined that the task has been completed, it can be deleted from the task queue.

[0043] In practical applications, each task requires at least one synchronization object to be allocated before execution, and at least one synchronization object to be destroyed after task execution. This leads to the creation and destruction of numerous synchronization objects when there are many tasks to process, increasing CPU utilization. Therefore, this embodiment of the disclosure reduces the frequent creation and destruction of synchronization objects by creating a synchronization object pool (i.e., dma_fence pool). The synchronization object pool is used to cache synchronization objects.

[0044] In one specific embodiment provided in this disclosure, a synchronization object pool can be created using the following method:

[0045] Create a blank synchronization object pool; create the preset number of synchronization objects in the blank synchronization object pool according to the preset number of tasks.

[0046] The blank synchronization object pool is an empty pool of synchronization objects that does not contain any synchronization objects. The preset number of tasks refers to the pre-defined number of synchronization objects that can be created.

[0047] Specifically, a blank synchronization object pool is created in the processing device, and a preset number of synchronization objects are created in the blank synchronization object pool according to a preset number of tasks, thereby obtaining a synchronization object pool containing the preset number of synchronization objects.

[0048] The embodiments disclosed herein can pre-create a certain number of synchronization objects in the synchronization object pool before receiving the pending tasks sent by the virtual machine, so that after receiving the pending tasks in the subsequent process, synchronization objects can be directly allocated to each pending task, thereby improving the allocation efficiency of synchronization objects.

[0049] In practical applications, a blank synchronization object pool can be created initially in the processing device. After receiving pending tasks from the virtual machine, a corresponding number of synchronization objects can be created based on the number of pending tasks. This ensures that synchronization objects are created according to the actual number of pending tasks received by the main thread, avoiding resource waste caused by insufficient or excessive numbers of synchronization objects in subsequent processes. The method of creating the synchronization object pool can be determined according to the actual application situation, and this disclosure does not impose any restrictions.

[0050] Furthermore, the main thread receives pending tasks sent by different virtual machines, determines the first synchronization object for the pending task from the created synchronization object pool, and adds the pending task to the task queue corresponding to the virtual machine to await execution. The specific implementation of determining the first synchronization object for the pending task is as follows:

[0051] In one specific embodiment provided in this disclosure, upon receiving a pending task sent by a virtual machine running in the processing device, determining the first synchronization object of the pending task includes:

[0052] Upon receiving a task processing request from the target virtual machine, the task to be processed is obtained from the task processing request; the first synchronization object is determined from the synchronization object pool corresponding to the processing device, and the first synchronization object is assigned to the task to be processed.

[0053] A task processing request is a request sent by the target virtual machine to the main thread of the processing device to process a task. The task processing request carries the task to be processed. Specifically, upon receiving a task processing request from the target virtual machine, the main thread retrieves the task to be processed from the request, obtains the first synchronization object from the created synchronization object pool, and assigns the first synchronization object to the task to be processed. In practical applications, a synchronization object queue can be created in the synchronization object pool to manage and store synchronization objects. Following the first-in, first-out (FIFO) principle, synchronization objects are retrieved from the synchronization object queue and assigned to the task to be processed.

[0054] The embodiments disclosed herein can achieve the following: after receiving a task to be processed sent by a virtual machine, a first synchronization object corresponding to the task to be processed is obtained from a pre-created synchronization object pool and allocated to the task, thereby improving allocation efficiency.

[0055] Furthermore, as mentioned above, after the GPU virtualization module starts, the main thread also needs to create a time-slice scheduling thread to schedule time slices and achieve fair allocation of GPU resources. In current practical applications, a fixed time slice is usually allocated to each virtual machine, and GPU resources are allocated to each virtual machine or task in a round-robin manner. Although the round-robin scheduling method can achieve fair allocation of GPU resources, it cannot dynamically adapt to the resource requirements of different tasks.

[0056] Based on this, in this embodiment of the disclosure, before the virtual machine sends the task to be processed to the main thread, the corresponding computing power weight is pre-configured for each virtual machine according to the resource requirements required by different virtual machines to execute the task, so that the time slice scheduling thread can allocate the corresponding time slice to each virtual machine according to the computing power weight.

[0057] Therefore, in a specific embodiment provided in this disclosure, after obtaining the task to be processed from the task processing request, the method further includes: obtaining the computing power weight of the target virtual machine from the task processing request; and determining the target time slice corresponding to the target virtual machine according to the mapping relationship between the computing power weight and the time slice.

[0058] The computing power weight is used to characterize the degree of time slice required for a virtual machine to execute a task. The higher the computing power weight, the more time slices the virtual machine needs to execute the task. The target time slice refers to at least one time slice allocated to the target virtual machine according to the computing power weight.

[0059] Specifically, after receiving a task processing request from the target virtual machine, the main thread, which also carries the computing power weight corresponding to the target virtual machine in the task processing request, obtains the computing power weight of the target virtual machine and sends it to the created time-slice scheduling thread. Based on this, the time-slice scheduling thread, upon receiving the computing power weight of the target virtual machine from the main thread, can determine the target time slice corresponding to the target virtual machine according to the mapping relationship between computing power weight and time slice. For example, if the computing power weight of virtual machine 1 is 2 and the computing power weight of virtual machine 2 is 3, then according to the mapping relationship between computing power weight and time slice, it can be determined that virtual machine 1 is allocated 2 time slices and virtual machine 2 is allocated 3 time slices.

[0060] The embodiments disclosed herein can determine the computing power weight of each virtual machine according to the needs of the virtual machine to execute the tasks to be processed, so that the time slice scheduling thread allocates a corresponding number of time slices to each virtual machine according to the computing power weight, thereby making the time slices obtained by each virtual machine not fixed, but allocated on demand, thus improving resource utilization.

[0061] In practical applications, after the main thread adds the task to the task queue, it executes `dma_fence_wait` on the first synchronization object of the task to be processed, blocking the task and waiting for scheduling, while also checking the status of the first synchronization object. Once it detects that the first synchronization object has been marked by the time-slice scheduling thread, it indicates that the time-slice scheduling thread has reached the time slice corresponding to the target virtual machine, and then executes `dma_fence_signal` on the first synchronization object. At this point, the main thread's task begins execution.

[0062] The embodiments of this disclosure can detect the state of the first synchronization object of the task to be processed to determine whether the first synchronization object has been marked by the time-slice scheduling thread, thereby determining whether the task to be processed can be executed, improving the synchronization of task execution in the task queue, and the fairness of resource scheduling according to time-slice round-robin.

[0063] In practical applications, the execution of a task may require multiple time slices. That is, if the current time slice expires before the task is completed, the time slice scheduling thread needs to schedule other time slices corresponding to the virtual machine to continue executing the task.

[0064] Based on this, in a specific embodiment provided in this disclosure, the method further includes: blocking the task to be processed when the task to be processed has not been completed and the first time slice has been completed; obtaining a second synchronization object of the task to be processed in a second time slice, wherein the second time slice is a time slice other than the first time slice in the target time slice, and the second time slice is later than the first time slice; continuing to block the task to be processed when the second synchronization object is detected to be in the dormant state; and continuing to execute the task to be processed when the second synchronization object is detected to be in the working state.

[0065] The second synchronization object is assigned to the task to be processed by the time slice scheduling thread when the first time slice expires or is about to expire.

[0066] Specifically, if a pending task has not been completed and its first time slice has been used up, it means that the first time slice has expired during the execution of the pending task, and it needs to wait for the next scheduling. In this case, the pending task is blocked. When the time slice scheduling thread detects that the first time slice of the pending task has expired or is about to expire, it will obtain a second synchronization object from the synchronization object pool and allocate the second synchronization object to the pending task. When the time slice scheduling thread reaches the second time slice of the target virtual machine, it means that the target virtual machine can execute the pending task again, and the main thread can check the status of the second synchronization object. At this time, the time slice scheduling thread obtains the task queue corresponding to the target virtual machine, obtains the second synchronization object corresponding to the pending task in the task queue, and marks the second synchronization object, that is, executes dma_fence_signal on the second synchronization object, so that the main thread can continue to execute the pending task. If the main thread detects that the second synchronization object is in a sleeping state, it means that the second synchronization object has not yet been marked by the time slice scheduling thread, and the pending task continues to be blocked. If the main thread detects that the second synchronization object is in a working state, it means that the second synchronization object has been marked by the time slice scheduling thread, and the pending task can continue to be executed.

[0067] If the time-slice scheduling thread detects that the second time slice of the target virtual machine has expired and the pending tasks have not yet been completed, it retrieves a new synchronization object from the synchronization object pool and assigns it to the pending tasks. If the time-slice scheduling thread executes the next time slice of the target virtual machine, it retrieves the target virtual machine's task queue and new synchronization objects for the pending tasks in the queue, marks the new synchronization objects, and allows the main thread to continue executing the pending tasks. This process is repeated, using the time-slice rotation method to continue executing the pending tasks until they are completed.

[0068] This embodiment of the disclosure enables the detection of the state of the second synchronization object allocated to the task to be processed by the time-slice scheduling thread when the task to be processed has not been completed and the first time slice has been executed, in order to determine whether the task to be processed can continue to be executed, thereby realizing dynamic scheduling of the task to be processed. Based on the time-slice round-robin method, tasks are scheduled in a round-robin fashion to ensure the fairness of task resource allocation.

[0069] As mentioned above, when the time slice scheduling thread detects that the first time slice has expired or is about to expire, it will allocate a second synchronization object to the task to be processed. The specific implementation of allocating a second synchronization object to the task to be processed is described below.

[0070] In one specific embodiment provided in this disclosure, the method further includes: during the execution of the task to be processed, detecting the remaining execution time of the first time slice; and when the remaining execution time reaches a preset time slice threshold, determining the second synchronization object.

[0071] The preset time slice threshold refers to a pre-defined threshold for the remaining execution time of a time slice, used to determine whether a second synchronization object should be allocated to the pending task. Examples include 0.05 seconds, 0.02 seconds, and 0 seconds. Specifically, during the execution of the pending task by the main thread, the time slice scheduling thread checks the remaining execution time of the first time slice. If the remaining execution time of the first time slice reaches the preset time slice threshold, it indicates that the first time slice is about to be completed or has already been completed. At this time, a second synchronization object is determined from the synchronization object pool and allocated to the pending task. It should be noted that if the preset time slice threshold is 0 seconds, it indicates that the first time slice has been completed, meaning the first time slice has expired.

[0072] The embodiments disclosed herein can realize the reallocation of a second synchronization object to the task to be processed when the first time slice is about to expire or has expired, and continue to block or execute the task to be processed based on the second synchronization object in the subsequent process, continue to realize dynamic scheduling of the task to be processed, and enable the task to be processed to be completed.

[0073] Furthermore, in a specific embodiment provided in this disclosure, the method further includes: when the task to be processed is completed, reclaiming the target synchronization object of the task to be processed to the synchronization object pool corresponding to the processing device, wherein the target synchronization object of the task to be processed includes at least the first synchronization object; and destroying the synchronization object pool when at least one virtual machine exits task execution.

[0074] The target synchronization objects include all synchronization objects allocated to the task during its execution. Specifically, upon completion of the task, all synchronization objects allocated to it (i.e., the target synchronization objects) are returned to the synchronization object pool. Furthermore, if the main thread detects that multiple virtual machines running on the processing device have exited task execution (i.e., the GPU virtualization module has exited), it indicates that the processing device no longer needs to provide GPU resources for the virtual machines. Therefore, the synchronization object pool can be destroyed, releasing the GPU resources of the processing device.

[0075] The embodiments disclosed herein enable the allocation and recycling of target synchronization objects corresponding to tasks to be processed based on a synchronization object pool, eliminating the need for frequent creation and destruction of target synchronization objects and reducing memory usage. Furthermore, the synchronization object pool can be destroyed when the GPU virtualization module exits, avoiding resource consumption.

[0076] Furthermore, in one specific embodiment provided in this disclosure, the method further includes: destroying the time-slice scheduling thread after all tasks of the at least one virtual machine have been completed.

[0077] Specifically, once all tasks in the task queue corresponding to each virtual machine have been completed, it means there are no more tasks to be scheduled and executed. Therefore, the time-slice scheduling thread is destroyed to avoid resource consumption. When the main thread receives tasks again, a new time-slice scheduling thread is created.

[0078] This embodiment implements a system whereby, upon receiving a pending task from a virtual machine running on a processing device, the main thread determines the first synchronization object corresponding to the pending task and adds the pending task to the virtual machine's corresponding task queue, thereby managing pending tasks sent by each virtual machine through the task queue. When the first synchronization object is detected to be marked by the time-slice scheduling thread, the pending task is executed, achieving synchronized processing based on the synchronization object and improving synchronization efficiency. Once the pending task is determined to be completed, it is removed from the task queue, promptly releasing the computing resources of the processing device and reducing resource consumption. By using the main thread and time-slice scheduling thread running on the processing device, combined with the synchronization object, to schedule and manage pending tasks, the execution and pause of pending tasks in the task queue can be dynamically adjusted according to the scheduling of the main thread and the time-slice scheduling thread, avoiding task queuing and task blocking, and improving resource utilization efficiency in a multi-user environment.

[0079] Based on the computing power weight of the virtual machine, a corresponding time slice is allocated to each virtual machine, realizing on-demand allocation of time slices according to the resource needs of the virtual machine and ensuring fair allocation of resources. During the round-robin process, the time slice scheduling thread marks the synchronization objects of the tasks to be processed, so that the tasks to be processed are awakened and can continue to be executed by the main thread, thereby improving the synchronization between tasks.

[0080] The following is in conjunction with the appendix Figure 3 For further explanation and description of the virtual machine-based task scheduling method provided in the embodiments of this disclosure, please refer to [link to relevant documentation]. Figure 3 , Figure 3 A flowchart illustrating a virtual machine-based task scheduling method provided in this disclosure is shown below. Figure 3As shown, after detecting the GPU virtualization module's startup, the main thread running on the processing device creates a synchronization primitive pool (dma_fence pool) and a task queue corresponding to each virtual machine. Upon receiving a task to be processed from a virtual machine, the main thread creates a time-slice scheduling thread, which begins scheduling after creation. Simultaneously, upon receiving a task, the main thread retrieves a synchronization primitive (dma_fence) from the pool and assigns it to the task, adding it to the virtual machine's task queue. It then executes `dma_fence_wait` on the assigned primitive to block the task. During this process, the main thread can monitor the state of the synchronization primitives. When the time-slice scheduling thread reaches a virtual machine's time slice, it retrieves the virtual machine's task queue and the synchronization primitives for the tasks to be processed within it. It then executes `dma_fence_signal` on these primitives to mark them. Upon detecting that a synchronization primitive for a task has been marked, the virtual machine begins executing the task on the main thread, and the main thread monitors the execution status of the task. If the main thread detects that the synchronization primitive of the task to be processed has not been marked, it will continue to check the status of the synchronization primitive until it is detected that the synchronization primitive has been marked.

[0081] Furthermore, when the main thread detects that a pending task has completed execution, it reclaims the synchronization primitives allocated to that task back to the synchronization primitive pool and removes the task from the task queue. If the main thread detects that a pending task has not completed execution, it indicates that the task's time slice has expired. The time-slice scheduling thread retrieves a new synchronization primitive from the pool and allocates it to the pending task. Since the new synchronization primitive has not yet been marked by the time-slice scheduling thread, the main thread executes `dma_fence_wait` on the new primitive to block the task until it detects that the new primitive has been marked by the time-slice scheduling thread. This process repeats until the task is completed. If all tasks in the task queue have been completed, the time-slice scheduling thread is destroyed. When the main thread receives pending tasks from the virtual machine again, a new time-slice scheduling thread is created. If there are uncompleted tasks in the queue, the time-slice scheduling thread continues scheduling. If the main thread detects that the GPU virtualization module has exited, it destroys the synchronization primitive pool. If it detects that the GPU virtualization module has not exited, it continues to receive pending tasks from the virtual machine.

[0082] This embodiment implements a system where the main thread and the time-slice scheduling thread work together. Upon receiving a task from a virtual machine running on the processing device, the main thread determines the corresponding synchronization primitive and adds the task to the virtual machine's task queue, managing tasks sent by each virtual machine through the task queue. When the time-slice scheduling thread detects that a synchronization primitive has been marked, the task is executed, achieving synchronized processing based on the synchronization primitive and improving synchronization efficiency. Once the task is completed, it is removed from the task queue, releasing computing resources and reducing resource consumption. The time-slice scheduling thread, upon detecting the expiration of a virtual machine's time slice, reassigns a new synchronization primitive to the task, ensuring execution continues when the virtual machine's time slice is rescheduled. By using the main thread and the time-slice scheduling thread, combined with synchronization primitives, to schedule and manage tasks, the execution and pause of tasks in the task queue can be dynamically adjusted based on the scheduling of the main thread and the time-slice scheduling thread, avoiding task queuing and blocking, and improving resource utilization efficiency in a multi-user environment.

[0083] It is understood that the various method embodiments mentioned above in this disclosure can be combined with each other to form combined embodiments without violating the principle and logic. Due to space limitations, this disclosure will not elaborate further. Those skilled in the art will understand that in the above methods of specific implementation, the specific execution order of each step should be determined by its function and possible internal logic.

[0084] In addition, this disclosure also provides a task scheduling device, an electronic device, and a computer-readable storage medium, all of which can be used to implement any of the virtual machine-based task scheduling methods provided in this disclosure. The corresponding technical solutions and descriptions are described in the corresponding section of the method and will not be repeated here.

[0085] Figure 4 This is a block diagram of a virtual machine-based task scheduling device provided in an embodiment of the present disclosure.

[0086] See Figure 4 This disclosure provides a virtual machine-based task scheduling device applied to a processing device, wherein at least one virtual machine is running in the processing device, and the device includes:

[0087] The first determining module 402 is configured to, upon receiving a task to be processed sent by a target virtual machine, determine a first synchronization object of the task to be processed in a first time slice, wherein the target virtual machine is any one of the at least one virtual machine, the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice.

[0088] The first blocking module 404 is configured to block the task to be processed when the first synchronization object is detected to be in a sleep state.

[0089] The first execution module 406 is configured to execute the task to be processed when the first synchronization object is detected to be in a working state.

[0090] Optionally, the device further includes:

[0091] The second blocking module is configured to block the task to be processed if the task to be processed has not been completed and the first time slice has been completed.

[0092] The acquisition module is configured to acquire the second synchronization object of the task to be processed in the second time slice, wherein the second time slice is a time slice in the target time slice other than the first time slice, and the second time slice is later than the first time slice;

[0093] The third blocking module is configured to continue blocking the pending task when the second synchronization object is detected to be in the sleep state.

[0094] The second execution module is configured to continue executing the pending task when the second synchronization object is detected to be in the working state.

[0095] Optionally, the device further includes a second determining module configured to:

[0096] During the execution of the task to be processed, the remaining execution time of the first time slice is detected;

[0097] If the remaining execution time reaches a preset time slice threshold, the second synchronization object is determined.

[0098] Optionally, the first determining module 402 is further configured to:

[0099] Upon receiving a task processing request sent by the target virtual machine, the task to be processed is obtained from the task processing request;

[0100] The first synchronization object is determined from the synchronization object pool corresponding to the processing device, and the first synchronization object is assigned to the task to be processed.

[0101] Optionally, the device further includes a third determining module configured to:

[0102] Obtain the computing power weight of the target virtual machine from the task processing request;

[0103] Based on the mapping relationship between the computing power weight and the time slice, the target time slice corresponding to the target virtual machine is determined.

[0104] Optionally, the device further includes:

[0105] The recycling module is configured to, upon completion of the pending task, recycle the target synchronization object of the pending task to the synchronization object pool corresponding to the processing device, wherein the target synchronization object of the pending task includes at least the first synchronization object.

[0106] The object pool destruction module is configured to destroy the synchronization object pool when at least one virtual machine has exited task execution.

[0107] Optionally, the processing device further includes a main thread and a time-slice scheduling thread, and the device further includes:

[0108] The detection module is configured to detect the object state of a third synchronization object based on the main thread and the time-slice scheduling thread, wherein the third synchronization object is either the first synchronization object or the second synchronization object;

[0109] The detection module is further configured as follows:

[0110] The main thread detects whether the third synchronization object is marked by the time-slice scheduling thread.

[0111] If the main thread detects that the third synchronization object has not been marked by the time slice scheduling thread, it determines that the object state of the third synchronization object is the sleeping state.

[0112] When the main thread detects that the third synchronization object has been marked by the time-slice scheduling thread, it determines that the object state of the third synchronization object is the working state.

[0113] Optionally, the device further includes:

[0114] The thread destruction module is configured to destroy the time-slice scheduling thread when all tasks of the at least one virtual machine have been completed.

[0115] Optionally, the device further includes:

[0116] The add module is configured to add the task to be processed to the task queue corresponding to the target virtual machine;

[0117] The deletion module is configured to remove the pending task from the task queue when the pending task has been completed.

[0118] This embodiment implements a system whereby, upon receiving a pending task from a virtual machine running on a processing device, the main thread determines the first synchronization object corresponding to the pending task and adds the pending task to the virtual machine's corresponding task queue, thereby managing pending tasks sent by each virtual machine through the task queue. When the first synchronization object is detected to be marked by the time-slice scheduling thread, the pending task is executed, achieving synchronized processing based on the synchronization object and improving synchronization efficiency. Once the pending task is determined to be completed, it is removed from the task queue, promptly releasing the computing resources of the processing device and reducing resource consumption. By using the main thread and time-slice scheduling thread running on the processing device, combined with the synchronization object, to schedule and manage pending tasks, the execution and pause of pending tasks in the task queue can be dynamically adjusted according to the scheduling of the main thread and the time-slice scheduling thread, avoiding task queuing and task blocking, and improving resource utilization efficiency in a multi-user environment.

[0119] Based on the computing power weight of the virtual machine, a corresponding time slice is allocated to each virtual machine, realizing on-demand allocation of time slices according to the resource needs of the virtual machine and ensuring fair allocation of resources. During the round-robin process, the time slice scheduling thread marks the synchronization objects of the tasks to be processed, so that the tasks to be processed are awakened and can continue to be executed by the main thread, thereby improving the synchronization between tasks.

[0120] Figure 5 This is a block diagram of an electronic device provided in an embodiment of the present disclosure.

[0121] See Figure 5 This disclosure provides an electronic device 700, which includes: at least one processor 701; at least one memory 702; and one or more I / O interfaces 703 connected between the processor 701 and the memory 702; wherein the memory 702 stores one or more computer programs that can be executed by at least one processor 701, and the one or more computer programs are executed by at least one processor 701 to enable at least one processor 701 to execute the above-described virtual machine-based task scheduling method.

[0122] This disclosure also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the aforementioned virtual machine-based task scheduling method. The computer-readable storage medium may be volatile or non-volatile.

[0123] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code is run in the processor of an electronic device, the processor in the electronic device executes the above-described virtual machine-based task scheduling method.

[0124] Those skilled in the art will understand that all or some of the steps, systems, and apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software can be distributed on a computer-readable storage medium, which may include computer storage media (or non-transitory media) and communication media (or transient media).

[0125] As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable program instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technologies, portable compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, it is known to those skilled in the art that communication media typically contain computer-readable program instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0126] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.

[0127] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.

[0128] The computer program product described herein can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0129] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0130] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.

[0131] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.

[0132] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0133] Example embodiments have been disclosed herein, and while specific terminology has been used, it is for illustrative purposes only and should be construed as such, and is not intended to be limiting. In some instances, it will be apparent to those skilled in the art that features, characteristics, and / or elements described in connection with particular embodiments may be used alone, or in combination with features, characteristics, and / or elements described in connection with other embodiments, unless otherwise expressly indicated. Therefore, those skilled in the art will understand that various changes in form and detail may be made without departing from the scope of this disclosure as set forth by the appended claims.

Claims

1. A task scheduling method based on a virtual machine, characterized in that, Applied to a processing device in which at least one virtual machine is running, the method includes: Upon receiving a pending task sent by a target virtual machine, the pending task is determined to be a first synchronization object in a first time slice, wherein the target virtual machine is any one of the at least one virtual machines, and the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice. If the first synchronization object is detected to be in a dormant state, the task to be processed is blocked. If the first synchronization object is detected to be in a working state, the pending task is executed.

2. The method as described in claim 1, characterized in that, The method further includes: If the pending task has not been completed and the first time slice has been completed, the pending task will be blocked. Obtain the second synchronization object of the task to be processed in the second time slice, wherein the second time slice is a time slice in the target time slice other than the first time slice, and the second time slice is later than the first time slice; If the second synchronization object is detected to be in the sleep state, the pending task will continue to be blocked; If the second synchronization object is detected to be in the working state, the pending task continues to be executed.

3. The method as described in claim 2, characterized in that, The method further includes: During the execution of the task to be processed, the remaining execution time of the first time slice is detected; If the remaining execution time reaches a preset time slice threshold, the second synchronization object is determined.

4. The method as described in claim 1, characterized in that, Upon receiving a pending task from the target virtual machine, the first synchronization object of the pending task in the first time slice is determined, including: Upon receiving a task processing request sent by the target virtual machine, the task to be processed is obtained from the task processing request; The first synchronization object is determined from the synchronization object pool corresponding to the processing device, and the first synchronization object is assigned to the task to be processed.

5. The method as described in claim 4, characterized in that, After obtaining the task to be processed from the task processing request, the method further includes: Obtain the computing power weight of the target virtual machine from the task processing request; Based on the mapping relationship between the computing power weight and the time slice, the target time slice corresponding to the target virtual machine is determined.

6. The method according to any one of claims 1-5, characterized in that, The method further includes: When the pending task is completed, the target synchronization object of the pending task is recycled to the synchronization object pool corresponding to the processing device, wherein the target synchronization object of the pending task includes at least the first synchronization object. The synchronization object pool is destroyed if at least one virtual machine exits task execution.

7. The method as described in claim 2, characterized in that, The processing device also runs a main thread and a time-slice scheduling thread, and the method further includes: The object state of the third synchronization object is detected based on the main thread and the time slice scheduling thread, wherein the third synchronization object is either the first synchronization object or the second synchronization object; Based on the main thread and the time-slice scheduling thread, the object state of the third synchronization object is detected, including: The main thread detects whether the third synchronization object is marked by the time-slice scheduling thread. If the main thread detects that the third synchronization object has not been marked by the time slice scheduling thread, it determines that the object state of the third synchronization object is the sleeping state. When the main thread detects that the third synchronization object has been marked by the time-slice scheduling thread, it determines that the object state of the third synchronization object is the working state.

8. The method as described in claim 7, characterized in that, The method further includes: The time-slice scheduling thread is destroyed once all tasks of at least one virtual machine have been completed.

9. The method as described in claim 1, characterized in that, The method further includes: Add the task to be processed to the task queue corresponding to the target virtual machine; Once the pending task has been completed, the pending task will be removed from the task queue.

10. A virtual machine-based task scheduling device, characterized in that, Applied to a processing device in which at least one virtual machine is running, the device includes: The first determining module is configured to, upon receiving a task to be processed sent by a target virtual machine, determine a first synchronization object of the task to be processed in a first time slice, wherein the target virtual machine is any one of the at least one virtual machines, the first time slice is one of the target time slices allocated by the processing device to the target virtual machine, and the target time slice includes at least one time slice. The first blocking module is configured to block the task to be processed when the first synchronization object is detected to be in a dormant state. The first execution module is configured to execute the task to be processed when the first synchronization object is detected to be in a working state.

11. An electronic device, characterized in that, include: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the method as described in any one of claims 1-9.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-9.

13. A computer program product, characterized in that, Includes computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code, wherein when the computer-readable code is executed in a processor of an electronic device, the processor in the electronic device performs the method as described in any one of claims 1-9.