Virtual processor context switching method and device, storage medium and electronic equipment

By pre-cacheting the context information of the virtual processor, the problem of low virtualization real-time due to the long loading time of the virtual processor context switch is solved, which significantly shortens the switching delay and improves the responsiveness.

CN119201352APending Publication Date: 2024-12-27CHINA AUTOMOTIVE INNOVATION CORP
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411374749.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

In Hypervisor systems that support real-time scheduling, the virtual processor context switching loading time is too long, resulting in low real-time virtualization.

Method used

By determining the affinity attribute of the current task when an interrupt signal is received, and predicting the switching probability of the task based on the switching probability, when the probability reaches or exceeds the preset threshold, the context information of the corresponding virtual processor is pre-cachedated in order to quickly load it .

Benefits of technology

It effectively reduces unnecessary memory usage, optimizes resource allocation, shortens delays during the switching process, and improves the real-time response capabilities of the virtualized environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201352A_ABST
    Figure CN119201352A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a virtual processor context switching method and device, a storage medium and electronic device.The method comprises the steps that under the condition that a current virtual processor receives an interrupt signal, the affinity attribute of a current task executed on the current virtual processor is determined; under the condition that the affinity attribute represents that the virtual processor associated with the current task is the first virtual processor, predicting the switching probability of the current task; under the condition that the switching probability is greater than or equal to a preset probability threshold value, pre-caching context information of the first virtual processor in a cache region; when a context switching request is received, the current task is interrupted, the context information of the first virtual processor is extracted from the cache region and loaded to the first virtual processor, and the interrupted current task continues to be executed on the first virtual processor. And the problem of low virtualization real-time performance is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the technical field of virtualization technology, and in particular, to a virtual processor context switching method, device, storage medium, and electronic device. Background Art

[0002] In a Hypervisor (virtual machine monitor) system that supports real-time scheduling, the Hypervisor divides certain computing resources from the physical CPU according to the needs of the virtual machine to create multiple VCPUs (virtual central processing units). Since the physical CPU needs to be shared among multiple virtual machines, when the time slice of a virtual machine runs out or an interrupt occurs, the Hypervisor will perform a context switch. During the VCPU switching process, the Hypervisor needs to save the context of the currently running virtual machine (including CPU status, register values, etc.) and restore its context when switching to another virtual machine. In this way, each virtual machine can continue execution from where it last stopped when it obtains CPU resources.

[0003] In the related art, after the system scheduling is triggered, the scheduling algorithm is directly called, and a series of complex calculations are performed to determine whether a new VCPU is to be scheduled. If the calculation shows that a new VCPU is to be scheduled, the new virtual processor information is loaded.

[0004] It can be seen that the VCPU context switch loading time in the related art is the sum of the scheduling algorithm time and the time to load a new VCPU. There is a problem that the VCPU context switch loading time is too long, resulting in low virtualization real-time performance. Summary of the invention

[0005] The embodiments of the present application provide a virtual processor context switching method, device, storage medium and electronic device to at least solve the problem of low virtualization real-time performance due to long VCPU context switching loading time in the virtual processor context switching method in the related art.

[0006] According to one aspect of an embodiment of the present application, a virtual processor context switching method is provided, comprising: in a case where a current virtual processor receives an interrupt signal, determining an affinity attribute of a current task executed on the current virtual processor; the affinity attribute is used to characterize a virtual processor associated with the current task; in a case where the virtual processor characterized by the affinity attribute as being associated with the current task is a first virtual processor, predicting a switching probability of the current task; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is a probability that the current task is switched from the current virtual processor to the first virtual processor; in a case where the switching probability is greater than or equal to a preset probability threshold, pre-caching context information of the first virtual processor in a cache area; in a case where a context switching request is received, interrupting the current task, extracting the context information of the first virtual processor from the cache area and loading it onto the first virtual processor, scheduling the interrupted current task to the first virtual processor, and continuing to execute the interrupted current task on the first virtual processor.

[0007] According to another aspect of an embodiment of the present application, a virtual processor context switching device is provided, comprising: a task attribute determination module, for determining an affinity attribute of a current task executed on the current virtual processor when the current virtual processor receives an interrupt signal; the affinity attribute is used to characterize a virtual processor associated with the current task; a switching probability prediction module, for predicting a switching probability of the current task when the virtual processor characterized by the affinity attribute being associated with the current task is a first virtual processor; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is a probability that the current task is switched from the current virtual processor to the first virtual processor; a preloading module, for pre-caching context information of the first virtual processor in a cache area when the switching probability is greater than or equal to a preset probability threshold; and a context switching module, for interrupting the current task when a context switching request is received, extracting the context information of the first virtual processor from the cache area and loading it to the first virtual processor, scheduling the interrupted current task to the first virtual processor, and continuing to execute the interrupted current task on the first virtual processor.

[0008] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned virtual processor context switching method when running.

[0009] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the virtual processor context switching method through the computer program.

[0010] According to another aspect of the embodiments of the present application, a computer program product is provided, including a computer program, which implements the steps of any of the above-mentioned virtual processor context switching method embodiments when executed by a processor.

[0011] Through the embodiments of the present application, when the current virtual processor receives an interrupt signal and the task involved in the interrupt signal clearly specifies its affinity as the first virtual processor, the probability of the current task switching to the first virtual processor for execution is predicted, and only when the switching probability reaches or exceeds the preset probability threshold, the context information of the first virtual processor is pre-stored in the cache area; on the one hand, the context information of the first virtual processor is cached only under high switching probability, which effectively reduces unnecessary memory usage, optimizes resource allocation, and reduces overall memory consumption; on the other hand, when it is really necessary to switch to the first virtual processor, since the context information has been pre-cached, it can be quickly loaded directly from the cache, eliminating the time overhead of capturing the context of the first virtual processor in real time. This pre-caching and direct loading mechanism significantly shortens the delay in the switching process, improves the real-time response capability of the virtualization environment, and solves the problem of long VCPU context switching loading time in related technologies, resulting in low virtualization real-time performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 It is a hardware structure block diagram of an optional virtual processor context switching method of an embodiment of the present application;

[0013] Figure 2 is a flowchart of an optional virtual processor context switching method according to an embodiment of the present application;

[0014] Figure 3 It is an optional continuous related technology VCPU context switching process according to an embodiment of the present application;

[0015] Figure 4 is a flow chart of an optional method of pre-caching context information of a first virtual processor according to an embodiment of the present application;

[0016] Figure 5 is an optional virtual processor context switching flow chart according to an embodiment of the present application;

[0017] Figure 6is a structural block diagram of an optional virtual processor context switching device according to an embodiment of the present application;

[0018] Figure 7 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0019] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0020] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0021] According to one aspect of an embodiment of the present application, a virtual processor context switching method is provided. Optionally, in this embodiment, the virtual processor context switching method can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.

[0022] The network may include but is not limited to at least one of the following: wired network, wireless network. The wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the wireless network may include but is not limited to at least one of the following: WIFI, Bluetooth. The terminal device 102 may not be limited to a PC, a mobile phone, a tablet computer, or other devices.

[0023] The virtual processor context switching method of the embodiment of the present application can be executed by the terminal device 102, or can be executed by the server 104 and the terminal device 102 together. Taking the virtual processor context switching method of the embodiment executed by the terminal device 102 as an example, Figure 2 is a flow chart of an optional virtual processor context switching method according to an embodiment of the present application, such as Figure 2 As shown, the process of the method may include the following steps:

[0024] Step S202: when the current virtual processor receives an interrupt signal, determine the affinity attribute of the current task executed on the current virtual processor; the affinity attribute is used to characterize the virtual processor associated with the current task.

[0025] Among them, a virtual processor (VCPU) is a virtual CPU simulated in a computer system. It divides the physical CPU into multiple virtual processors through virtualization technology and provides various functions and interfaces, so that the virtual processor can run independent operating systems and applications. In virtualization technology, the physical CPU is divided into multiple virtual processors by virtualization software (such as virtual machine monitor VMM or Hypervisor), and each virtual machine (VM) can have its own set of virtual processors. In this way, the operating system and application in each virtual machine feel that they are running on an independent physical CPU. The current virtual processor refers to a virtual processor that is being executed on the terminal device.

[0026] An interrupt signal is a signal that causes the virtual processor to pause the currently executed instruction and execute the interrupt service routine (ISR). In a virtualized environment, an interrupt signal can be generated by physical hardware or a virtual machine monitor to notify the virtual machine or host that a specific event needs to be processed.

[0027] The current task refers to the part of a program or process that is being executed on the current virtual processor.

[0028] The affinity attribute is an attribute that describes the association between a task and a specific virtual processor. The affinity attribute instructs the operating system of the terminal device to schedule tasks with specific affinity attributes to execute on specific virtual processors as much as possible. In a multi-core processor and virtualization environment, the affinity attribute is used to characterize the virtual processor associated with the current task (such as a process, thread, or virtual machine). The "association" here means that during the execution of the task, it tends to or is bound to run on a specific virtual processor to reduce resource competition, improve cache hit rate, and reduce context switching overhead, thereby optimizing system performance. Suppose there is a multi-core server running multiple key business processes. By configuring CPU affinity, the administrator can bind certain key processes to specific VCPU cores. The affinity attribute of a task is usually defined in the application configuration file (such as AndroidManifest.xml). In the configuration file, each tag can contain an attribute to specify the task affinity of the task.

[0029] Optionally, when the current virtual processor receives an interrupt signal, the terminal device obtains the context information of the current virtual processor to determine the task currently being executed on the current virtual processor, records the task as the current task, and calls the configuration file to determine the task affinity of the current task based on the information contained in the tag corresponding to the current task in the configuration file.

[0030] Step S204, when the virtual processor represented by the affinity attribute as being associated with the current task is the first virtual processor, predict the switching probability of the current task; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is the probability of the current task switching from the current virtual processor to the first virtual processor.

[0031] The affinity attribute indicates that the virtual processor associated with the current task is the first virtual processor, indicating that the current task is bound to the first virtual processor.

[0032] The first virtual processor is a virtual processor specially created or designated to take over the current task. The first virtual processor has a high affinity with the current task, but before being designated, the current task did not run on the first virtual processor. In short, the first virtual processor is a new VCPU resource prepared to optimize the execution of the current task.

[0033] The switching probability refers to the possibility that the current task switches from the current virtual processor that is currently running to another first virtual processor with higher affinity (i.e., more relevant to the current task). The switching probability is a value between 0 and 1, which indicates the probability of the switching occurring. There are many factors that affect the switching probability. For example, the strength of the affinity attribute, the usage of system resources, the switching cost and benefit, network delay and bandwidth, and other factors. Taking the influence of the strength of the affinity attribute on the switching probability as an example, if the affinity between the current task and the first virtual processor is very strong, that is, the correlation between the two is very high, then the switching probability is relatively large. On the contrary, if the affinity is weak, the switching probability will be reduced accordingly. In practical applications, it is necessary to comprehensively consider these factors according to the specific situation to evaluate the switching probability and make reasonable decisions accordingly.

[0034] Optionally, when the affinity attribute characterizes that the virtual processor associated with the current task is the first virtual processor, the terminal device predicts the switching probability of the current task based on the strength of the affinity attribute, the usage of system resources, the historical data and performance of task execution, the switching cost and benefit, network delay and bandwidth, the limitations of virtualization technology and external factors.

[0035] For example, the terminal device collects relevant data about the current task, the current virtual processor and the first virtual processor (such as CPU usage, memory usage, I / O waiting time, task response time, etc.), and analyzes the potential cost and expected benefit of switching the current task from the current virtual processor to the first virtual processor based on the relevant data. Among them, the potential cost includes the overhead of context switching, the performance loss caused by cache failure, etc.; and the benefits include improved cache hit rate, reduced resource competition, faster task response time, etc. Based on the above relevant data and analysis results, the terminal device uses a suitable prediction model or algorithm (such as random forest, neural network, support vector machine, etc.) to estimate the switching probability of the current task from the current virtual processor to the first virtual processor.

[0036] Step S206 : When the switching probability is greater than or equal to a preset probability threshold, pre-caching the context information of the first virtual processor in the cache area.

[0037] The preset probability threshold is a predefined value for comparison with the calculated switching probability. When the switching probability reaches or exceeds the preset probability threshold, the switching operation is considered to be a high probability event, otherwise, the switching operation is considered to be a low probability event, and there is no need to pre-cache the context information of the first virtual processor. The preset probability threshold is usually set after comprehensive consideration of multiple factors such as system performance requirements, resource utilization, and task priority.

[0038] The cache area is an area in the system used to pre-cache the context information of the first virtual processor, which can reduce the delay and cost of data access.

[0039] The context information of the first virtual processor refers to a series of data and status information closely related to the execution state and related resources of the first virtual processor in the virtualization environment, such as pointer registers, program counters, virtual memory, global variables, stack information corresponding to the VCPU, page table space, and other information.

[0040] When the current task is running on the current virtual processor, various resources (such as CPU registers, memory, I / O devices, etc.) will be used and a series of state changes will occur. These state changes are context information, which records all environmental states when the task is executed to a certain moment. When switching tasks, the context information of the current task needs to be saved and restored when switching back to the task on the first virtual processor to ensure that the task can continue to execute on the first virtual processor from where it was last interrupted. By caching the context information of the first virtual processor, the execution state of the task can be restored more quickly when switching tasks, thereby reducing the switching overhead.

[0041] Optionally, when the switching probability is greater than or equal to a preset probability threshold, the terminal device initializes a cache area, captures context information of the first virtual processor, and stores the captured context information in a pre-prepared cache area.

[0042] Step S208, when a context switch request is received, the current task is interrupted, the context information of the first virtual processor is extracted from the cache area and loaded onto the first virtual processor, the interrupted current task is scheduled to the first virtual processor, and the interrupted current task is continued to be executed on the first virtual processor.

[0043] The context switch request is an instruction or signal issued by the operating system of the terminal device through a scheduling algorithm (such as a load balancing algorithm, etc.), which indicates that the operating system needs to suspend the task currently being executed on the current virtual processor and transfer the control of the current virtual processor to the first virtual processor. The context switch request is generally determined based on multiple factors, such as task priority, waiting time, resource requirements, processor utilization, etc.

[0044] Figure 3 The VCPU context switching process of the related technology in one embodiment is as follows. Figure 3As shown, in the related art, after triggering the system scheduling, the scheduling algorithm is directly called, and a series of complex calculations are performed to determine whether to switch to a new VCPU. If the calculation shows that it is necessary to switch, the new VCPU information is loaded. It can be seen that the VCPU context switching loading time in the related art is the sum of the scheduling algorithm time and the time to load the new VCPU. There is a problem that the VCPU context switching loading time is too long, resulting in low virtualization real-time performance.

[0045] Figure 4 FIG. 1 is a flowchart of an optional method of pre-caching context information of a first virtual processor in one embodiment, such as Figure 4 As shown, in the related art, after the interrupt signal arrives, a new VCPU detection mechanism is added. When new VCPU information is detected, the new VCPU information is loaded in advance. At this time, the larger of the scheduling algorithm running time and the new VCPU loading time is determined as the VCPU context switch loading time. Although the VCPU context switch loading time can also be reduced, this situation sacrifices memory space, and 100% pre-loading space is required after the new VCPU information is detected.

[0046] In the embodiment of the present application, only when the virtual processor represented by the affinity attribute is associated with the current task as the first virtual processor, and the switching probability of the current task is greater than or equal to the preset probability threshold, the context information of the first virtual processor will be pre-cached in the cache area. It can be understood that the context information of the first virtual processor can be cached only when the above two conditions are met at the same time. If only the condition that the virtual processor represented by the affinity attribute is associated with the current task as the first virtual processor is met, the context information of the first virtual processor will not be pre-loaded, which reduces the probability of memory consumption. In addition, in the embodiment of the present application, after the interrupt signal arrives, if a context switch request is received, the running time of the scheduling algorithm and the time to load the first virtual processor are determined, and the two are compared. The larger of the two is determined as the VCPU context switch loading time. Compared with the related art, the embodiment of the present application can reduce the VCPU context switch loading time and improve the real-time performance of virtualization.

[0047] Optionally, when the terminal device determines through a scheduling algorithm that a context switch needs to be performed, a context switch request is generated and sent to the corresponding component of the scheduler or virtualization layer of the operating system. After receiving the context switch request, the scheduler or virtualization layer interrupts the current task being executed and extracts context information related to the first virtual processor from the cache. The scheduler or virtualization layer loads the context information extracted from the cache to the first virtual processor to restore the register state, memory mapping, program counter, etc. of the first virtual processor so that the first virtual processor can continue to execute the previously interrupted task or start executing a new task. After that, the first virtual processor continues to execute the task from the point where it was interrupted.

[0048] Through the above steps S202 to S206, when the current virtual processor receives an interrupt signal and the task involved in the interrupt signal clearly specifies its affinity as the first virtual processor, the probability of the current task switching to the first virtual processor for execution is predicted, and only when the switching probability reaches or exceeds the preset probability threshold, the context information of the first virtual processor is pre-stored in the cache area; on the one hand, the context information of the first virtual processor is cached only under high switching probability, which effectively reduces unnecessary memory usage, optimizes resource allocation, and reduces overall memory consumption; on the other hand, when it is really necessary to switch to the first virtual processor, since the context information has been pre-cached, it can be quickly loaded directly from the cache, eliminating the time overhead of real-time capture of the context of the first virtual processor. This pre-caching and direct loading mechanism significantly shortens the delay in the switching process, improves the real-time response capability of the virtualization environment, and solves the problem of long VCPU context switching loading time in related technologies, resulting in low virtualization real-time performance.

[0049] In an exemplary embodiment, after determining the affinity attribute of the current task executed on the current virtual processor, the virtual processor context switching method further includes:

[0050] 1. When the virtual processor represented by the affinity attribute as being associated with the current task is not the first virtual processor, determine a second virtual processor to take over the current task; the second virtual processor is a virtual processor selected by a first scheduling algorithm for load balancing to take over the current task.

[0051] Among them, the second virtual processor refers to the scenario of task scheduling, when the current task is not specified to be executed on the first virtual processor (such as a new VCPU), the operating system of the terminal device selects a suitable virtual processor to take over the current task through a scheduling algorithm based on the current system status and resource availability. The selected virtual processor is the second virtual processor. For example, the second virtual processor can be the most suitable virtual processor among the existing virtual processors to take over the current task. In the previous task scheduling process, the context information of the second virtual processor may have been captured. Therefore, it is only necessary to search the historical data to find the context information of the second virtual processor without capturing it again, reducing the overhead of capturing the context information of the second virtual processor. The second virtual processor is responsible for taking over and continuing to execute the current task when the current task cannot continue to execute on the originally planned virtual processor (i.e., the current virtual processor).

[0052] The first scheduling algorithm is the main algorithm used to allocate and schedule tasks among multiple virtual processors. When a hardware or system exception triggers an interrupt, or a thread is blocked while waiting for a signal, the system scheduling will be triggered, and the VCPU may be woken up and scheduled. The first scheduling algorithm evaluates the status of all currently available virtual processors based on a series of strategies (such as load balancing, resource utilization, task priority, affinity preference, etc.), and decides whether to switch the VCPU accordingly. When the program to which the interrupt jumps is still executing on the current virtual processor, there is no need to switch the context. On the contrary, it is necessary to determine which virtual processor is most suitable to take over or execute the current task, and switch to other virtual processors, which involves context switching operations.

[0053] Optionally, Figure 5 FIG. 4 is a flowchart of a virtual processor context switch in one embodiment. Figure 5 As shown, when the affinity attribute of the current task indicates that the virtual processor associated with the current task is not the first virtual processor, the terminal device starts the first scheduling algorithm and selects a virtual processor from multiple virtual processors that is most suitable for taking over the current task as the second virtual processor based on the load conditions of all current virtual processors.

[0054] 2. When a context switch request is received, the current task is interrupted, the context information of the second virtual processor is obtained and loaded onto the second virtual processor, the interrupted current task is scheduled to the second virtual processor, and the interrupted current task is continued to be executed on the second virtual processor.

[0055] Optionally, when the terminal device determines through a scheduling algorithm that a context switch needs to be performed, a context switch request is generated and sent to the corresponding component of the scheduler or virtualization layer of the operating system. After receiving the context switch request, the scheduler or virtualization layer interrupts the current task being executed and captures the context information of the second virtual processor. The scheduler or virtualization layer loads the extracted context information of the second virtual processor into the second virtual processor to restore the register state, memory mapping, program counter, etc. of the second virtual processor so that the second virtual processor can continue to execute the previously interrupted task or start executing a new task. Afterwards, the second virtual processor continues to execute the task from the point where it was interrupted.

[0056] In some embodiments, Figure 5 As shown, in the case where a context retention request is received, the current task continues to be executed on the current virtual processor.

[0057] Through this embodiment, when the affinity attribute of the current task indicates that the virtual processor associated with the current task is not the first virtual processor, the second virtual processor for taking over the current task is selected through the first scheduling algorithm for load balancing, and during the actual switching process, the current task is switched to the second virtual processor for continued execution, thereby improving task execution efficiency.

[0058] In an exemplary embodiment, predicting the switching probability of the current task includes:

[0059] The switching probability of the current task is predicted according to the priority of the current task and the priority of the task to be executed on the first virtual processor.

[0060] Among them, the priority of a task refers to the order in which tasks are sorted according to factors such as the urgency, importance, and time requirements of the task. Priority is an attribute used to determine the order in which tasks are executed. High-priority tasks are usually executed first, while low-priority tasks may be executed after all high-priority tasks are completed. The priority of a task can be expressed in numerical values, with higher numerical values ​​indicating higher priority.

[0061] Optionally, the terminal device obtains the priority of the current task, queries the priority list of all tasks to be executed on the first virtual processor, calculates the difference between the priority of the current task and the priority of each task to be executed on the target processor, and uses a predefined model or algorithm (such as a rule-based model, a statistical model, a machine learning model, etc.) to predict the switching probability.

[0062] For example, if the priority of the current task is higher than the priorities of all tasks to be executed on the first virtual processor, the switching probability is 1 (determined to switch); otherwise, the switching probability is 0 (no switching).

[0063] For example, a linear model based on priority difference is defined, and the linear model defines that the switching probability is proportional to the priority difference between the current task and the highest priority task to be executed on the first virtual processor. The priority difference is calculated by the linear model, and a linear function (such as switching probability = priority difference / maximum possible difference) is applied to calculate the switching probability.

[0064] For example, collect historical data, including task priority, processor load, switching decision information, etc. Use machine learning algorithms (such as logistic regression, decision tree, neural network, etc.) to train a model to predict the probability of switching given the priority difference and processor load. Input the priority of the current task and the load of the first virtual processor, and use the trained model to predict the probability of switching.

[0065] Through this embodiment, the switching probability of the current task is predicted based on the priority of the current task and the priority of the task to be executed on the first virtual processor. By associating the switching probability with the task priority, high-priority tasks can be executed first to ensure that critical or urgent tasks are processed in a timely manner. This priority-driven execution strategy reduces task waiting time and improves the overall efficiency of task execution. Correspondingly, if it is predicted that the switching probability of the current task on the first virtual processor is low and the task priority on the first virtual processor is high, the system tends to continue to execute the high-priority task on the first virtual processor, thereby reducing unnecessary context switching and reducing switching overhead.

[0066] In an exemplary embodiment, predicting the switching probability of the current task according to the priority of the current task and the priority of the task to be executed on the first virtual processor includes:

[0067] 1. Obtain a task list of the first virtual processor; the task list records the tasks to be executed on the first virtual processor; the current task and the tasks to be executed in the task list have corresponding priorities respectively.

[0068] The task list is a data structure for recording a group of tasks to be executed on the first virtual processor. In the first virtual processor, the task list usually contains detailed information of all tasks that have not been executed, and is used to schedule and manage the execution order of tasks.

[0069] To-be-executed tasks are those tasks that have been submitted to the first virtual processor but have not yet been actually executed. To-be-executed tasks are recorded in the task list and wait for processing according to a certain priority or scheduling policy. The number and type of tasks to be executed depends on the system load and the task scheduling policy. In the task list, each task to be executed can be assigned a priority value so that the system can determine the execution order of the tasks based on these values.

[0070] Optionally, the terminal device uses an API provided by the operating system or virtualization platform to obtain a task list of the first virtual processor, extracts information of all tasks to be executed from the task list, and records priority information of each task to be executed.

[0071] 2. When the priority of the current task is not lower than the highest priority among the priorities of the tasks to be executed in the task list, determine the first probability as the switching probability of the current task; the first probability is greater than or equal to a preset probability threshold.

[0072] The highest priority refers to the priority of the task with the highest priority value among all the tasks to be executed in the task list. Generally, a task with a higher priority value indicates that it is more important or urgent.

[0073] The first probability refers to the switching probability of the current task set when the priority of the current task is not lower than the highest priority of the tasks to be executed in the task list. The first probability is set to a value greater than a preset probability threshold when the priority of the current task is higher than the priority of all tasks to be executed on the first virtual processor. For example, the first probability can be set to 1, that is, if the priority of the current task is higher than the priority of all tasks to be executed on the first virtual processor, the first probability is 1, indicating that the switching is certain.

[0074] It can be seen from the above embodiment that the switching probability of the current task is predicted only when the affinity attribute of the current task represents that the virtual processor associated with the current task is the first virtual processor, and the context information of the first virtual processor is pre-cached in the cache area only when the switching probability of the current task is greater than or equal to the preset probability threshold. Therefore, a flag bit VCPU_SWITCH can be added to indicate the adaptation of the above two conditions. If the flag bit VCPU_SWITCH is set to TRUE, it means that the affinity attribute of the current task represents that the virtual processor associated with the current task is the first virtual processor, and the switching probability of the current task is greater than or equal to the preset probability threshold. At this time, the possibility of switching the current virtual processor is relatively large, and the context information of the first virtual processor is pre-loaded in advance. Among them, the time consumption of VCPU_SWITCH setting is very small and can be ignored. It can be understood that the memory will only consume the pre-load space at a certain probability (only when VCPU_SWITCH=TRUE, <100%).

[0075] Alternatively, if Figure 5 As shown, the terminal device obtains the task list of the first virtual processor, searches for all tasks to be executed in the task list, finds the task with the highest priority value, and records it as the highest priority. The terminal device compares the priority of the current task with the highest priority determined in the task list. If the priority of the current task is not lower than the highest priority, it means that the priority of the current task is high enough. When the priority of the current task is not lower than the highest priority, a first probability greater than a preset probability threshold is set, and the first probability is used as the switching probability of the current task.

[0076] Through this embodiment, the determination of the switching probability is simplified to the comparison between the current task priority and the highest priority of the task list, which can greatly simplify the logic of task scheduling. This intuitive scheduling strategy is easy to implement and maintain, and also reduces the possibility of errors.

[0077] In an exemplary embodiment, the virtual processor context switching method further includes:

[0078] When the priority of the current task is lower than the highest priority among the priorities of the tasks to be executed in the task list, the second probability is determined as the switching probability of the current task; and the second probability is less than a preset probability threshold.

[0079] The second probability refers to the switching probability of the current task when the priority of the current task is lower than the highest priority of the tasks to be executed in the task list. The second probability is set to a value less than the preset probability threshold when the priority of the current task is lower than the highest priority task to be executed on the first virtual processor. For example, the second probability can be set to 0, that is, if the priority of the current task is lower than the highest priority on the first virtual processor, the second probability is 0, indicating no switching.

[0080] Alternatively, if Figure 5 As shown, the terminal device obtains the task list of the first virtual processor, searches for all tasks to be executed in the task list, finds the task with the highest priority value, and records it as the highest priority. The terminal device compares the priority of the current task with the highest priority determined in the task list. If the priority of the current task is lower than the highest priority, it means that the priority of the current task is not high enough. When the priority of the current task is lower than the highest priority, a second probability that is less than a preset probability threshold is set, and the second probability is used as the switching probability of the current task.

[0081] Through this embodiment, the switching probability is simplified to a binary decision (ie, switching or not switching), which can respond to the needs of high-priority tasks more quickly and reduce the delay of task execution, thereby meeting the real-time requirements.

[0082] In an exemplary embodiment, the virtual processor context switching method further includes:

[0083] 1. When the switching probability is less than a preset probability threshold, determine a third virtual processor to take over the current task; the third virtual processor is a virtual processor selected by a second scheduling algorithm for load balancing and used to take over the current task.

[0084] Among them, the third virtual processor refers to the scenario of task scheduling, when the current task is specified to be executed on the first virtual processor (such as a new VCPU), but it is impossible to switch to the specified first virtual processor according to the current system state, the operating system of the terminal device selects a suitable virtual processor to take over the current task through a scheduling algorithm according to the current system state and resource availability, and the selected virtual processor is the third virtual processor. For example, the third virtual processor can be the most suitable virtual processor among the existing virtual processors to take over the current task, or it can be another newly established virtual processor. The third virtual processor is responsible for taking over and continuing to execute the current task when the current task cannot continue to execute on the originally planned virtual processor (i.e., the current virtual processor).

[0085] The second scheduling algorithm is the main algorithm used to allocate and schedule tasks among multiple virtual processors. The second scheduling algorithm evaluates the status of all currently available virtual processors based on a series of strategies (such as load balancing, resource utilization, task priority, affinity preference, etc.), and determines which virtual processor is most suitable to take over or execute the current task. It should be noted that the first scheduling algorithm and the second scheduling algorithm can be the same algorithm, or an algorithm dynamically selected according to the status of the system.

[0086] Alternatively, if Figure 5 As shown, when the affinity attribute of the current task indicates that the virtual processor associated with the current task is the first virtual processor, but it is impossible to switch to the specified first virtual processor according to the current system state, the terminal device starts the second scheduling algorithm and selects a virtual processor that is most suitable for taking over the current task from multiple virtual processors according to the load conditions of all current virtual processors as the third virtual processor.

[0087] 2. When a context switch request is received, the current task is interrupted, the context information of the third virtual processor is obtained and loaded onto the third virtual processor, the interrupted current task is scheduled to the third virtual processor, and the interrupted current task is continued to be executed on the third virtual processor.

[0088] Alternatively, if Figure 5 As shown, when the terminal device determines through the scheduling algorithm that a context switch needs to be performed, a context switch request is generated and sent to the corresponding component of the scheduler or virtualization layer of the operating system. After receiving the context switch request, the scheduler or virtualization layer interrupts the current task being executed and captures the context information of the third virtual processor. The scheduler or virtualization layer loads the extracted context information of the third virtual processor into the third virtual processor to restore the register state, memory mapping, program counter, etc. of the third virtual processor so that the third virtual processor can continue to execute the previously interrupted task or start executing a new task. Afterwards, the third virtual processor continues to execute the task from the point where it was interrupted.

[0089] In some embodiments, Figure 5 As shown, in the case where a context retention request is received, the current task continues to be executed on the current virtual processor.

[0090] Through this embodiment, when the affinity attribute of the current task indicates that the virtual processor associated with the current task is the first virtual processor, but it is impossible to switch to the designated first virtual processor according to the current system state, a third virtual processor for taking over the current task is selected through the second scheduling algorithm for load balancing, and during the actual switching process, the current task is switched to the third virtual processor for continued execution, thereby improving task execution efficiency.

[0091] In an exemplary embodiment, after pre-caching the context information of the first virtual processor in the cache area, the virtual processor context switching method further includes:

[0092] When a context retention request is received, the current task is continued to be executed on the current virtual processor, and the context information of the first virtual processor pre-cached in the cache area is deleted.

[0093] The context retention request is used to indicate that the current task should continue to be executed on the current virtual processor instead of being migrated to the first virtual processor.

[0094] Alternatively, if Figure 5 As shown, when the terminal device receives the context retention request, it responds to the context retention request and continues to execute the current task on the current virtual processor without performing any migration operation. Since it has been decided not to migrate the task to the first virtual processor at the current moment, the context information of the first virtual processor previously pre-cached for possible migration now becomes redundant. At this time, the terminal device deletes the pre-cached context information of the first virtual processor from the cache area to release the cache space for other uses.

[0095] Through this embodiment, after the context information of the first virtual processor is pre-cached in the cache area, if a context retention request is received, the context information of the first virtual processor pre-cached in the cache area is deleted to release cache space, reduce memory usage, and maintain stable operation of the system.

[0096] In a detailed embodiment, a virtual processor context switching method includes:

[0097] 1. When the current virtual processor receives an interrupt signal, an affinity attribute of a current task executed on the current virtual processor is determined; the affinity attribute is used to characterize a virtual processor associated with the current task.

[0098] 2. When the virtual processor represented by the affinity attribute as being associated with the current task is not the first virtual processor, execute step 3; when the virtual processor represented by the affinity attribute as being associated with the current task is the first virtual processor, execute steps 4-10; wherein the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled.

[0099] 3. Determine a second virtual processor that takes over the current task; the second virtual processor is a virtual processor selected by a first scheduling algorithm for load balancing and is used to take over the current task; when a context switch request is received, interrupt the current task, obtain context information of the second virtual processor and load it to the second virtual processor, schedule the interrupted current task to the second virtual processor, and continue to execute the interrupted current task on the second virtual processor.

[0100] 4. Obtain a task list of the first virtual processor; the task list records the tasks to be executed on the first virtual processor; the current task and the tasks to be executed in the task list have corresponding priorities respectively.

[0101] 5. When the priority of the current task is not lower than the highest priority among the priorities of the tasks to be executed in the task list, execute step 6; when the priority of the current task is lower than the highest priority among the priorities of the tasks to be executed in the task list, execute step 7.

[0102] 6. Determine the first probability as the switching probability of the current task; the first probability is greater than or equal to a preset probability threshold; wherein the switching probability is the probability of the current task switching from the current virtual processor to the first virtual processor.

[0103] 7. Determine the second probability as the switching probability of the current task; the second probability is less than a preset probability threshold.

[0104] 8. When the switching probability is greater than or equal to the preset probability threshold, execute step 9; when the switching probability is less than the preset probability threshold, execute step 10.

[0105] 9. Pre-caching the context information of the first virtual processor in a cache area; in case of receiving a context switch request, interrupting the current task, extracting the context information of the first virtual processor from the cache area and loading it onto the first virtual processor, scheduling the interrupted current task to the first virtual processor, and continuing to execute the interrupted current task on the first virtual processor; in case of receiving a context keep request, continuing to execute the current task on the current virtual processor, and deleting the context information of the first virtual processor pre-cached in the cache area.

[0106] 10. Determine a third virtual processor that takes over the current task; the third virtual processor is a virtual processor selected by a second scheduling algorithm for load balancing and is used to take over the current task; when a context switch request is received, interrupt the current task, obtain context information of the third virtual processor and load it onto the third virtual processor, schedule the interrupted current task to the third virtual processor, and continue to execute the interrupted current task on the third virtual processor.

[0107] Through this embodiment, when the current virtual processor receives an interrupt signal and the task involved in the interrupt signal clearly specifies its affinity as the first virtual processor, the probability of the current task switching to the first virtual processor for execution is predicted, and only when the switching probability reaches or exceeds the preset probability threshold, the context information of the first virtual processor is pre-stored in the cache area; on the one hand, the context information of the first virtual processor is cached only under high switching probability, which effectively reduces unnecessary memory usage, optimizes resource allocation, and reduces overall memory consumption; on the other hand, when it is really necessary to switch to the first virtual processor, since the context information has been pre-cached, it can be quickly loaded directly from the cache, eliminating the time overhead of real-time capture of the context of the first virtual processor. This pre-caching and direct loading mechanism significantly shortens the delay in the switching process, improves the real-time response capability of the virtualization environment, and solves the problem of long VCPU context switching loading time in related technologies, resulting in low virtualization real-time performance.

[0108] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0109] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware server, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.

[0110] According to another aspect of the embodiment of the present application, a virtual processor context switching device is also provided, which is used to implement the virtual processor context switching method provided in the above-mentioned embodiment, and the description thereof has been made without further details. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and contemplated.

[0111] Figure 6 is a structural block diagram of an optional virtual processor context switching device according to an embodiment of the present application, such as Figure 6 As shown, the device may include:

[0112] The task attribute determination module 601 is used to determine the affinity attribute of the current task executed on the current virtual processor when the current virtual processor receives an interrupt signal; the affinity attribute is used to characterize the virtual processor associated with the current task;

[0113] A switching probability prediction module 602 is used to predict the switching probability of the current task when the virtual processor represented by the affinity attribute as being associated with the current task is a first virtual processor; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is the probability of the current task being switched from the current virtual processor to the first virtual processor;

[0114] A preloading module 603, configured to pre-cache the context information of the first virtual processor in a cache area when the switching probability is greater than or equal to a preset probability threshold;

[0115] The context switching module 604 is used to interrupt the current task when receiving a context switching request, extract the context information of the first virtual processor from the cache area and load it to the first virtual processor, schedule the interrupted current task to the first virtual processor, and continue to execute the interrupted current task on the first virtual processor.

[0116] In an exemplary embodiment, the task attribute determination module 601 is also used to determine a second virtual processor that takes over the current task when the virtual processor represented by the affinity attribute as being associated with the current task is not the first virtual processor; the second virtual processor is a virtual processor selected by a first scheduling algorithm for load balancing to take over the current task; the context switching module 604 is also used to interrupt the current task when a context switching request is received, obtain the context information of the second virtual processor and load it onto the second virtual processor, schedule the interrupted current task to the second virtual processor, and continue to execute the interrupted current task on the second virtual processor.

[0117] In an exemplary embodiment, the switching probability prediction module 602 is further configured to predict the switching probability of the current task according to the priority of the current task and the priority of the task to be executed on the first virtual processor.

[0118] In an exemplary embodiment, the switching probability prediction module 602 is also used to obtain a task list of the first virtual processor; the task list records the tasks to be executed on the first virtual processor; the current task and the tasks to be executed in the task list have corresponding priorities respectively; when the priority of the current task is not lower than the highest priority among the priorities of the tasks to be executed in the task list, the first probability is determined as the switching probability of the current task; the first probability is greater than or equal to the preset probability threshold.

[0119] In an exemplary embodiment, the switching probability prediction module 602 is also used to determine a second probability as the switching probability of the current task when the priority of the current task is lower than the highest priority among the priorities of the tasks to be executed in the task list; and the second probability is less than the preset probability threshold.

[0120] In an exemplary embodiment, the preloading module 603 is also used to determine a third virtual processor that takes over the current task when the switching probability is less than the preset probability threshold; the third virtual processor is a virtual processor selected by a second scheduling algorithm for load balancing and used to take over the current task; the context switching module is also used to interrupt the current task when a context switching request is received, obtain the context information of the third virtual processor and load it to the third virtual processor, schedule the interrupted current task to the third virtual processor, and continue to execute the interrupted current task on the third virtual processor.

[0121] In an exemplary embodiment, the context switching module 604 is further configured to, upon receiving a context retention request, continue to execute the current task on the current virtual processor and delete the context information of the first virtual processor pre-cached in the cache area.

[0122] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0123] According to another aspect of the embodiments of the present application, a storage medium is further provided. Optionally, in this embodiment, the storage medium can be used to execute the program code of any of the virtual processor context switching methods in the embodiments of the present application.

[0124] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.

[0125] Optionally, in this embodiment, the storage medium is configured to store a program code for executing any of the above virtual processor context switching methods.

[0126] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, which will not be described in detail in this embodiment.

[0127] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.

[0128] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned virtual processor context switching method is also provided. The electronic device may be a smart device, a server, a terminal, or a combination thereof.

[0129] Figure 7 is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 7 As shown, it includes a processor 702, a communication interface 704, a memory 706 and a communication bus 708, wherein the processor 702, the communication interface 704 and the memory 706 communicate with each other through the communication bus 708, wherein,

[0130] Memory 706, used to store computer programs;

[0131] The processor 702 is used to implement the program code of any of the above virtual processor context switching methods when executing the computer program stored in the memory 706.

[0132] Optionally, the communication bus may be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 The communication interface is used for communication between the above electronic device and other devices.

[0133] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0134] As an example, the memory 706 may include but is not limited to each module in the virtual processor context switching device. In addition, it may also include but is not limited to other module units in the virtual processor context switching device, which will not be repeated in this example.

[0135] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0136] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0137] It can be understood by those skilled in the art that Figure 7 The structure shown is for illustration only. The device for implementing the above virtual processor context switching method may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 7 The structure of the electronic device is not limited. Figure 7 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 7 Different configurations shown.

[0138] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.

[0139] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.

[0140] The embodiments of the present application also provide a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the steps in any one of the above method embodiments.

[0141] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.

[0142] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0143] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0144] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0145] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0146] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.

[0147] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist physically separately, or at least two units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0148] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A virtual processor context switching method, characterized in that: include: In the case where the current virtual processor receives an interrupt signal, determining an affinity attribute of a current task executed on the current virtual processor; The affinity attribute is used to characterize the virtual processor associated with the current task; In the case where the virtual processor represented by the affinity attribute as being associated with the current task is a first virtual processor, predicting the switching probability of the current task; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is the probability of the current task being switched from the current virtual processor to the first virtual processor; In a case where the switching probability is greater than or equal to a preset probability threshold, pre-caching the context information of the first virtual processor in a cache area; When a context switch request is received, the current task is interrupted, the context information of the first virtual processor is extracted from the cache area and loaded onto the first virtual processor, the interrupted current task is scheduled to the first virtual processor, and the interrupted current task continues to be executed on the first virtual processor.

2. The method according to claim 1, characterized in that After determining the affinity attribute of the current task executed on the current virtual processor, the method further includes: In the case where the virtual processor represented by the affinity attribute as being associated with the current task is not the first virtual processor, determining a second virtual processor to take over the current task; the second virtual processor is a virtual processor selected by a first scheduling algorithm for load balancing and used to take over the current task; When a context switch request is received, the current task is interrupted, the context information of the second virtual processor is obtained and loaded onto the second virtual processor, the interrupted current task is scheduled to the second virtual processor, and the interrupted current task continues to be executed on the second virtual processor.

3. The method according to claim 1, characterized in that The predicting the switching probability of the current task includes: The switching probability of the current task is predicted according to the priority of the current task and the priority of the task to be executed on the first virtual processor.

4. The method according to claim 3, characterized in that The predicting the switching probability of the current task according to the priority of the current task and the priority of the task to be executed on the first virtual processor includes: Obtaining a task list of the first virtual processor; the task list records the tasks to be executed on the first virtual processor; the current task and the tasks to be executed in the task list respectively have corresponding priorities; When the priority of the current task is not lower than the highest priority among the priorities of the tasks to be executed in the task list, a first probability is determined as the switching probability of the current task; and the first probability is greater than or equal to the preset probability threshold.

5. The method according to claim 4, characterized in that The method further comprises: When the priority of the current task is lower than the highest priority among the priorities of the tasks to be executed in the task list, a second probability is determined as the switching probability of the current task; and the second probability is less than the preset probability threshold.

6. The method according to claim 1, characterized in that The method further comprises: In the case where the switching probability is less than the preset probability threshold, determining a third virtual processor to take over the current task; the third virtual processor is a virtual processor selected by a second scheduling algorithm for load balancing and used to take over the current task; When a context switch request is received, the current task is interrupted, the context information of the third virtual processor is obtained and loaded onto the third virtual processor, the interrupted current task is scheduled to the third virtual processor, and the interrupted current task continues to be executed on the third virtual processor.

7. The method according to any one of claims 1 to 6, characterized in that: After pre-caching the context information of the first virtual processor in the cache area, the method further includes: In case of receiving a context retention request, the current task is continued to be executed on the current virtual processor, and the context information of the first virtual processor pre-cached in the cache area is deleted.

8. A virtual processor context switching device, characterized in that: include: A task attribute determination module, used for determining the affinity attribute of the current task executed on the current virtual processor when the current virtual processor receives an interrupt signal; the affinity attribute is used for characterizing the virtual processor associated with the current task; a switching probability prediction module, for predicting the switching probability of the current task when the virtual processor represented by the affinity attribute as being associated with the current task is a first virtual processor; the first virtual processor is a virtual processor rebuilt to take over the current task and to which the current task has not been scheduled, and the switching probability is the probability of the current task being switched from the current virtual processor to the first virtual processor; a preloading module, configured to pre-cache the context information of the first virtual processor in a cache area when the switching probability is greater than or equal to a preset probability threshold; A context switching module is used to interrupt the current task when receiving a context switching request, extract the context information of the first virtual processor from the cache area and load it to the first virtual processor, schedule the interrupted current task to the first virtual processor, and continue to execute the interrupted current task on the first virtual processor.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of any one of the methods of claims 1 to 7 when executed by a processor.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Instruction conversion context switching optimization method based on stack frame hierarchical compression

    CN119829133A