Method, device, storage medium and electronic equipment for adjusting scheduling type of CPU
Patent Information
- Application Number
- CN202311069006.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-23
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2043-08-23
AI Technical Summary
[0004]本申请提供了一种CPU的调度类型调整方法、装置、存储介质以及电子设备,以解决CPU的调度类型调整效率低的技术问题
[0015] Compared with the prior art, the above-mentioned technical solution provided in this application has the following advantages: The method provided in this application can adjust the scheduling type of a target CPU, whether the scheduling type is allowed or not, by adjusting the mask in the mask address after it goes offline, and then come back online according to the new scheduling type. This way, the scheduling type of the CPU can be adjusted without restarting or creating a new host machine, thus improving the efficiency of adjusting the scheduling type of the CPU.
Smart Images

Figure CN117032983B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more particularly to a method, apparatus, storage medium, and electronic device for adjusting the scheduling type of a CPU. Background Technology
[0002] In existing technology, when a virtual machine is started on a host machine, the Central Processing Unit (CPU) allocated to the virtual machine has two states: one is a scheduler-enabled type, and the other is a scheduler-disabled type. (When the CPU is started, a CPU set to the isolated state is a scheduler-disabled type CPU, while a CPU not set to the isolated state is a scheduler-enabled type CPU.) Programs running on a scheduler-disabled CPU are not interfered with by other processes scheduled by the scheduler, and other processes will not be scheduled to run on that CPU.
[0003] However, in existing technologies, once a CPU is started, its scheduling type is fixed and cannot be adjusted. Adjusting the CPU scheduling type requires restarting the host machine or deploying a new host machine and migrating the virtual machine. This method is time-consuming, requires significant manual intervention, and is inefficient. Summary of the Invention
[0004] This application provides a method, apparatus, storage medium, and electronic device for adjusting the scheduling type of a CPU, in order to solve the technical problem of low efficiency in adjusting the scheduling type of a CPU.
[0005] In a first aspect, this application provides a method for adjusting the scheduling type of a CPU, comprising: performing an offline operation on a target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling; reading a first mask value from the mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of the first type and the second type; adjusting the mask value stored at the mask address from the first mask value to a second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is a target type, and the target type is another of the first type and the second type; performing an online operation on the target CPU, and setting the scheduling type of the target CPU to the target type indicated by the second mask value.
[0006] Secondly, this application provides a CPU scheduling type adjustment device, comprising: a first execution module, configured to perform an offline operation on a target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling; a reading module, configured to read a first mask value from a mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of the first type and the second type; an adjustment module, configured to adjust the mask value stored at the mask address from the first mask value to a second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is a target type, and the target type is another of the first type and the second type; and a second execution module, configured to perform an online operation on the target CPU and set the scheduling type of the target CPU to the target type indicated by the second mask value.
[0007] As an optional example, the first execution module includes: a scheduling unit for terminating the process running on the target CPU or scheduling it to run on another CPU; and a termination unit for calling a state machine to stop the operation of the target CPU.
[0008] As an optional example, the scheduling unit includes: a scheduling subunit, configured to select a first CPU from other CPUs of the first type when the current type of the target CPU is a first type, and schedule all processes of the target CPU to the first CPU; or, if the current type of the target CPU is a second type, terminate all processes of the target CPU and restart all processes of the target CPU in other CPUs of the second type.
[0009] As an optional example, the scheduling subunit described above is also used to: determine the load of each CPU of the first type; calculate the average value of the load; determine the CPU whose load is less than the average value and is closest to the average value as the first CPU; or determine the CPU with the smallest load as the first CPU.
[0010] As an optional example, the adjustment module includes: an adjustment unit, configured to adjust the first mask value in the mask list corresponding to the mask address to the second mask value, wherein the mask list stores the correspondence between the CPU-id of the CPU and the mask value; or, delete the first mask value in the first mask list corresponding to the first type of CPU, and add the second mask value of the target CPU to the second mask list corresponding to the second type of CPU, wherein the first mask value and the second mask value correspond to the CPU-id of the target CPU.
[0011] As an optional example, the above apparatus further includes: a determination module, configured to, before performing an offline operation on the target CPU, count the load of each first type of CPU, including the target CPU; and, if the average load is less than a preset load value, determine one or more CPUs of the first type of CPUs as the target CPU.
[0012] As an optional example, the determination module includes: a processing unit, configured to sort the CPUs of the first type in ascending order of load; determine the first CPU of the first type as the current CPU, and perform the following operations: if the process on the current CPU can be scheduled to another CPU of the first type, determine the current CPU as the target CPU, and determine the next CPU of the current CPU as the new current CPU, until the process on the current CPU cannot be scheduled to another CPU of the first type.
[0013] Thirdly, this application provides an electronic device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the memory stores a computer program, and the processor is configured to implement any of the above-described CPU scheduling type adjustment methods when executing the computer program.
[0014] Fourthly, this application also provides a computer storage medium storing computer-executable instructions, which are used to execute the CPU scheduling type adjustment method described in any of the above claims of this application.
[0015] Compared with the prior art, the above-mentioned technical solution provided in this application has the following advantages: The method provided in this application can adjust the scheduling type of a target CPU, whether the scheduling type is allowed or not, by adjusting the mask in the mask address after it goes offline, and then come back online according to the new scheduling type. This way, the scheduling type of the CPU can be adjusted without restarting or creating a new host machine, thus improving the efficiency of adjusting the scheduling type of the CPU. Attached Figure Description
[0016] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0019] Figure 1 A flowchart illustrating a CPU scheduling type adjustment method provided in an embodiment of this application;
[0020] Figure 2 An isolated schematic diagram illustrating a CPU scheduling type adjustment method provided in an embodiment of this application;
[0021] Figure 3 A flowchart of another CPU scheduling type adjustment method provided in an embodiment of this application;
[0022] Figure 4 A flowchart illustrating yet another CPU scheduling type adjustment method provided in this application embodiment;
[0023] Figure 5 A flowchart illustrating yet another CPU scheduling type adjustment method provided in this application embodiment;
[0024] Figure 6 A flowchart illustrating yet another CPU scheduling type adjustment method provided in this application embodiment;
[0025] Figure 7 A schematic diagram illustrating the CPU shutdown process for a CPU scheduling type adjustment method provided in this application embodiment;
[0026] Figure 8 A schematic diagram of the adjustment mask for a CPU scheduling type adjustment method provided in an embodiment of this application;
[0027] Figure 9 A schematic diagram of CPU online operation for a CPU scheduling type adjustment method provided in this application embodiment;
[0028] Figure 10 A schematic diagram of the structure of a CPU scheduling type adjustment device provided in an embodiment of this application;
[0029] Figure 11 This is a schematic diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0030] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0031] The following disclosure provides numerous different embodiments or examples for implementing various structures of the invention. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of the invention. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0032] To address the technical problem of low efficiency in adjusting CPU scheduling types in existing technologies, this application provides a method for adjusting CPU scheduling types, which can improve the efficiency of adjusting CPU scheduling types.
[0033] Figure 1 This is a flowchart illustrating a CPU scheduling type adjustment method provided in an embodiment of this application. Figure 1 As shown, the above-mentioned CPU scheduling type adjustment method includes:
[0034] S102, perform a shutdown operation on the target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling.
[0035] S104, Read the first mask value from the mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of the first type and the second type;
[0036] S106, adjust the mask value stored in the mask address from the first mask value to the second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is the target type, and the target type is another one of the first type and the second type;
[0037] S108, perform an online operation on the target CPU and set the scheduling type of the target CPU to the target type indicated by the second mask value.
[0038] The CPU scheduling type adjustment method described above can be applied to scenarios where the CPU forms scheduling domains and scheduling groups after startup on the host machine. When the host machine starts the CPU, it starts the CPU according to the parameters recorded in memory. The parameters in memory include parameters indicating whether the CPU is isolated or non-isolated during startup. If the CPU is isolated, the program running on that CPU will not be interfered with by other processes scheduled by the scheduler; that is, other processes will not be automatically scheduled to run on that CPU. If the CPU is non-isolated, the process running on that CPU can be scheduled to other CPUs. The first type mentioned above is the allowed scheduling type, indicating that the CPU is not isolated, and the second type is the disallowed scheduling type, indicating that the CPU is isolated.
[0039] The scheduling domain mentioned above represents the hierarchical relationship in the CPU physical topology. The scheduling group is the basic unit of load balancing. It can be understood as scheduling the processes on the CPU within the scheduling group under the scheduling domain, thereby achieving process load balancing.
[0040] The aforementioned offline and online operations are essentially CPU processing operations. When a CPU goes offline, the processes running on that CPU will terminate or be scheduled away, and the CPU cannot be used until it comes back online. In other words, an offline CPU cannot provide the corresponding services; it needs to come online for the CPU to run threads and provide those services.
[0041] The mask address mentioned above is the address of the CPU's mask, which manages whether the CPU should be isolated. The mask includes mask values: the first mask value indicates the CPU is type one, and the second mask value indicates the CPU is type two. Adjusting the mask values controls the CPU's scheduling type. Furthermore, the mask address can include isolation and non-isolation lists. These lists can include the CPU's unique identifier or its mask value, allowing the system to determine whether the CPU is in an allowed or disallowed scheduling type. If the CPU is in an allowed scheduling type, processes on that CPU can be scheduled; if it is in a disallowed scheduling type, processes on that CPU cannot be scheduled.
[0042] In this embodiment, the target CPU whose scheduling type needs to be adjusted is first identified. Then, the target CPU is taken offline. When offline, the processes on the target CPU will terminate or be scheduled away. Next, the first mask value is read using the mask address to check whether the target CPU's scheduling type is an allowed or disallowed type. The target CPU's scheduling type can be modified. After modification, the first mask value is adjusted to the second mask value. When the target CPU is brought back online, it will be started according to the adjusted second mask value, thus completing the change of the target CPU's scheduling type.
[0043] like Figure 2 As shown, Figure 2 In this system, CPUs are divided into allowed scheduling types and disallowed scheduling types. Each CPU runs processes (the number of processes running on a CPU is not limited). If a process is on a CPU with an allowed scheduling type, it can be scheduled among CPUs with the same scheduling type. If a process is on a CPU with a disallowed scheduling type, it is not allowed to be scheduled among CPUs with the same scheduling type.
[0044] The method provided in this application embodiment can adjust the scheduling type of a target CPU, whether the scheduling type is allowed or not, by adjusting the mask in the mask address after it goes offline, and then coming back online according to the new scheduling type. This allows the CPU scheduling type to be adjusted without restarting or creating a new host machine, thus improving the efficiency of CPU scheduling type adjustment.
[0045] As an optional example, such as Figure 3 As shown, performing a shutdown operation on the target CPU includes:
[0046] S302 terminates the process running on the target CPU or schedules it to run on another CPU;
[0047] S304 calls the state machine to stop the target CPU from running.
[0048] In this embodiment, since processes are running on the target CPU, to take the target CPU offline, the processes on the target CPU must first be cleared. Clearing processes can be done by terminating or scheduling processes. Terminating a process terminates the process. You can then check whether the process can be restarted on another CPU as needed. If scheduling a process, the process is scheduled from the target CPU to another CPU.
[0049] When terminating a process, the timing of termination can be configured. Termination can occur after the process has been used or during a break in its usage. For example, when a process is invoked, it can be terminated after the invocation and before the next invocation. If the process needs to be invoked again, it can be restarted on a different CPU. Alternatively, the process can be terminated directly, and any unfinished tasks are considered failures.
[0050] As an optional example, such as Figure 4 As shown, terminating or rescheduling a process running on the target CPU to another CPU includes:
[0051] S402-1, if the target CPU's current type is type 1, select a first CPU from other CPUs of type 1 and schedule all processes of the target CPU to the first CPU; or
[0052] S402-2, if the target CPU is currently of type 2, terminate all processes of the target CPU and restart all processes of the target CPU in other types 2 CPUs.
[0053] In this embodiment, different methods can be selected to handle processes on the target CPU depending on its scheduling type. If the target CPU is a permitted scheduling type, it means that the processes on the target CPU can be scheduled to other CPUs, and process scheduling can be performed. Process scheduling can be intra-group scheduling, meaning the processes on the target CPU can be scheduled to other CPUs in the same group. The first CPU in the group can be found, and the processes on the target CPU can be scheduled to the first CPU. If the target CPU is a non-permitted scheduling type, the processes on the target CPU cannot be scheduled and can be terminated. Terminated processes can be restarted on other CPUs with non-permitted scheduling types.
[0054] As an alternative example, when the current type of the target CPU is type 1, selecting the first CPU from other CPUs of type 1 includes: determining the load of each CPU of type 1; calculating the average load; determining the CPU with a load less than the average and closest to the average as the first CPU; or determining the CPU with the lowest load as the first CPU.
[0055] In this embodiment, when the target CPU is a scheduling-enabled type, the first CPU can be determined before scheduling the process on the target CPU to the first CPU. The first CPU can be determined within the same scheduling group as the target CPU. The load of each CPU in the group can be determined; the load can be the CPU utilization rate. The higher the utilization rate, the higher the load. A CPU with a high load may cause CPU overload after the process is scheduled to it. Therefore, a CPU with a lower load should be selected as the first CPU. When selecting a CPU with a lower load, the CPU with the lowest load can be directly selected as the first CPU. Selecting the CPU with the lowest load ensures that the utilization rate of each CPU in the scheduling group is close to the same. In addition, when selecting a CPU with a lower load, the average load of all CPUs in the group can be calculated, and then the CPU with a load lower than the average but close to the average load can be selected as the first CPU. This selection method ensures that some CPUs in the group have low utilization rates, while the utilization rates of the remaining CPUs are close to the same, thus reserving some CPUs.
[0056] As an optional example, adjusting the mask value stored at the mask address from the first mask value to the second mask value includes:
[0057] S502-1, adjust the first mask value in the mask list corresponding to the mask address to the second mask value, wherein the mask list stores the correspondence between the CPU's CPU-id and the mask value;
[0058] S502-2, delete the first mask value from the first mask list corresponding to the first type of CPU, and add the second mask value of the target CPU to the second mask list corresponding to the second type of CPU, wherein the first mask value and the second mask value correspond to the CPU-id of the target CPU.
[0059] In this embodiment, the mask address corresponds to a mask, and the mask value is either a first mask value or a second mask value. The first mask value indicates that the CPU is of an allowed scheduling type, and the second mask value indicates that the CPU is of an unallowed scheduling type. The CPU type is adjusted by modifying the mask value of the mask address.
[0060] Alternatively, this embodiment may include a mask list for CPUs with allowed call types and a mask list for CPUs with disallowed scheduling types. The mask lists contain the CPU masks, i.e., CPU-ids. A CPU's CPU-id will only appear in one mask list. When checking a CPU's scheduling type, the CPU-id can be searched in both mask lists. The CPU whose CPU-id is found in which mask list corresponds to that scheduling type. When adjusting a CPU's scheduling type, the CPU-id is deleted from the mask list containing the CPU-id and added to the other mask list. When starting a CPU, it will be started according to the CPU type indicated in the mask lists.
[0061] As an optional example, such as Figure 6 As shown, before performing the offline operation on the target CPU, the above method also includes:
[0062] S602, calculates the load of each type 1 CPU, including the target CPU;
[0063] S604, when the average load is less than the load preset value, identifies one or more CPUs of the first type as the target CPU.
[0064] In this embodiment, before performing a shutdown operation on the target CPU, the target CPU can be automatically determined based on certain conditions. Once the target CPU is determined, the shutdown operation is performed on it. The condition is whether the average load of CPUs under the allowed scheduling type is less than a preset load value. The preset load value is a pre-defined value, such as 60%, indicating that the average load of CPUs under the allowed scheduling type cannot be less than 60%. If it is less than 60%, it means that the overall CPU load is not high, and scheduling can be performed to increase the load of some CPUs, thereby freeing up one or more CPUs. The CPU to be freed up is the target CPU, and then the target CPU is switched to a non-allowed scheduling type. Therefore, for each group of CPUs under the allowed scheduling type, the relationship between the average load and the preset load value can be compared to see if one or more target CPUs can be identified.
[0065] As an optional example, when the average load is less than the load preset value, identifying one or more CPUs of the first type as the target CPU includes: sorting the first type CPUs in ascending order of load; identifying the first first type CPU as the current CPU, and performing the following operations: if the process on the current CPU can be scheduled to another first type CPU, identifying the current CPU as the target CPU, and identifying the next CPU of the current CPU as the new current CPU, until the process on the current CPU cannot be scheduled to another first type CPU.
[0066] In this embodiment, when the average load of a group of CPUs with allowed scheduling types is determined to be less than a preset load value, one or more target CPUs are identified from this group. The method is to sort the CPUs by load from smallest to largest, first checking if the processes of the CPU with the lowest load can be scheduled to other CPUs in the same group. If they can be scheduled, the CPU with the lowest load can be designated as a target CPU. The target CPU no longer accepts processes scheduled from other CPUs. Next, the process of the CPU with the second lowest load is compared to see if it can be scheduled to other CPUs. At this point, the other CPUs no longer include the first CPU, as the first CPU has already been identified as a target CPU. Since the other CPUs have already taken over the processes of the first CPU, their load has increased. In the next assessment, the increased load and the reduction of one CPU are considered. When a CPU's processes can no longer be scheduled to other CPUs, it indicates that the load of the remaining CPUs is close to 100%, therefore, no more target CPUs can be identified. For the identified target CPUs, a shutdown operation can be performed, and they can be converted to a non-allowed scheduling type CPU.
[0067] Let's illustrate this with an example.
[0068] The CPU boot process begins first. The parameters used during CPU boot are located in the GRandUnified Bootloader (GRUB). These parameters are managed within GRUB through `housekeeping_mask` and `tick_nohz_full_mask`. `housekeeping_mask` is a mask management module used to manage the CPU mask. The CPU mask is divided into a mask list for allowed scheduling types and a mask list for disallowed scheduling types. During CPU boot, the type of CPU to boot is determined by checking the mask list. `tick_nohz_full_mask` is a configuration module used to configure the CPU to a nohz full state, in which the CPU does not run. `housekeeping_mask` and `tick_nohz_full_mask` are located in memory and can be looked up using their mask addresses.
[0069] Upon initial startup, if you want to change a CPU from an allowed scheduling type to a disallowed scheduling type, you can perform an OFFLINE operation on the target CPU. Then, you retrieve the kernel-mode address of the mask (the mask address) from kernel memory. Using this mask address, you find the target mask, which is the mask for the target CPU, located in either the allowed scheduling type mask list or the disallowed scheduling type mask list. By modifying the mask list containing the target mask, you change the CPU's type. After adjusting the target mask, you perform an ONLINE operation on the target CPU according to the adjusted target mask. This rebuilds the scheduling domain, either bringing the target CPU into the allowed scheduling domain or removing it from the allowed scheduling domain.
[0070] For the offline operation of the target CPU, such as Figure 7 As shown, the `echo 0> / sys / devices / system / cpu / cpux / online` interface can be called. The system kernel (such as the Linux operating system kernel) will call the state machine of the secure hardware removal tool (hotplug mechanism) to stop the CPU from running. It will search for the target CPU in the online CPU's online_store, and then execute the device_offline operation. It will stop the CPU through the dev->bus->fooline(dev) command, confirm that the CPU system is offline, and thus take the target CPU offline. At the same time, the processes on that CPU will be scheduled to other CPUs or terminated.
[0071] After the target CPU is taken offline, the loading module moves the target CPU's target mask from the list of allowed scheduling types to the list of disallowed scheduling types, or vice versa. In other words, it removes the target CPU from the isolated range. Figure 8 As shown, the ` / proc / sys` interface created by the registration tool `register_sysctl_table` is called, and the driver `insmod rebuild_cpu_mask_online.ko` is loaded. This driver is used to perform mask preparation operations before going online, determining whether the target CPU is an isolated CPU or a non-isolated CPU. If CPU1 is removed from the isolated range, the CPU-id is passed to the driver and the CPU mask is rebuilt as follows:
[0072] `echo 1> / proc / sys / ksyun_rebuild_cpumask / set_nonisolated_cpu_id`. If CPU1 is added to the isolated range, the CPU-id is passed to the driver using the following command to rebuild the CPU mask:
[0073] echo 1> / proc / sys / ksyun_rebuild_cpumask / set_isolated_cpu_id.
[0074] For CPU online operations, such as Figure 9 As shown, the `echo 1> / sys / devices / system / cpu / cpux / online` interface is called to locate the target CPU and perform the online operation based on the target CPU's mask. The CPU online operation is initiated via the `dev->bus->online(dev)` command. Once the CPU system is online, the state machine starts running, reconstructs the scheduling domain based on the `housekeeping_cpumask` mask, and runs the state machine until the CPU is online.
[0075] Figure 10 This is a schematic diagram of a CPU scheduling type adjustment device provided in an embodiment of this application. Figure 10 As shown, the CPU scheduling type adjustment device mentioned above includes:
[0076] The first execution module 1002 is used to perform an offline operation on the target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling.
[0077] The reading module 1004 is used to read a first mask value from the mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of a first type and a second type;
[0078] The adjustment module 1006 is used to adjust the mask value stored in the mask address from the first mask value to the second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is the target type, and the target type is another one of the first type and the second type;
[0079] The second execution module 1008 is used to perform an online operation on the target CPU and set the scheduling type of the target CPU to the target type indicated by the second mask value.
[0080] The CPU scheduling type adjustment method described above can be applied to scenarios where the CPU forms scheduling domains and scheduling groups after startup on the host machine. When the host machine starts the CPU, it starts the CPU according to the parameters recorded in memory. The parameters in memory include parameters indicating whether the CPU is isolated or non-isolated during startup. If the CPU is isolated, the program running on that CPU will not be interfered with by other processes scheduled by the scheduler; that is, other processes will not be automatically scheduled to run on that CPU. If the CPU is non-isolated, the process running on that CPU can be scheduled to other CPUs. The first type mentioned above is the allowed scheduling type, indicating that the CPU is not isolated, and the second type is the disallowed scheduling type, indicating that the CPU is isolated.
[0081] The scheduling domain mentioned above represents the hierarchical relationship in the CPU physical topology. The scheduling group is the basic unit of load balancing. It can be understood as scheduling the processes on the CPU within the scheduling group under the scheduling domain, thereby achieving process load balancing.
[0082] The aforementioned offline and online operations are essentially CPU processing operations. When a CPU goes offline, the processes running on that CPU will terminate or be scheduled away, and the CPU cannot be used until it comes back online. In other words, an offline CPU cannot provide the corresponding services; it needs to come online for the CPU to run threads and provide those services.
[0083] The mask address mentioned above is the address of the CPU's mask, which manages whether the CPU should be isolated. The mask includes mask values: the first mask value indicates the CPU is type one, and the second mask value indicates the CPU is type two. Adjusting the mask values controls the CPU's scheduling type. Furthermore, the mask address can include isolation and non-isolation lists. These lists can include the CPU's unique identifier or its mask value, allowing the system to determine whether the CPU is in an allowed or disallowed scheduling type. If the CPU is in an allowed scheduling type, processes on that CPU can be scheduled; if it is in a disallowed scheduling type, processes on that CPU cannot be scheduled.
[0084] In this embodiment, the target CPU whose scheduling type needs to be adjusted is first identified. Then, the target CPU is taken offline. When offline, the processes on the target CPU will terminate or be scheduled away. Next, the first mask value is read using the mask address to check whether the target CPU's scheduling type is an allowed or disallowed type. The target CPU's scheduling type can be modified. After modification, the first mask value is adjusted to the second mask value. When the target CPU is brought back online, it will be started according to the adjusted second mask value, thus completing the change of the target CPU's scheduling type.
[0085] like Figure 2 As shown, Figure 2 In this system, CPUs are divided into allowed scheduling types and disallowed scheduling types. Each CPU runs processes (the number of processes running on a CPU is not limited). If a process is on a CPU with an allowed scheduling type, it can be scheduled among CPUs with the same scheduling type. If a process is on a CPU with a disallowed scheduling type, it is not allowed to be scheduled among CPUs with the same scheduling type.
[0086] The method provided in this application embodiment can adjust the scheduling type of a target CPU, whether the scheduling type is allowed or not, by adjusting the mask in the mask address after it goes offline, and then coming back online according to the new scheduling type. This allows the CPU scheduling type to be adjusted without restarting or creating a new host machine, thus improving the efficiency of CPU scheduling type adjustment.
[0087] For other examples of this embodiment, please refer to the examples above, which will not be repeated here.
[0088] like Figure 11 As shown in the figure, this application provides an electronic device, including a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0089] Memory 113 is used to store computer programs;
[0090] In one embodiment of this application, when the processor 111 executes the program stored in the memory 113, it implements the CPU scheduling type adjustment method provided in any of the foregoing method embodiments.
[0091] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the CPU scheduling type adjustment method provided in any of the foregoing method embodiments.
[0092] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0093] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0094] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0095] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for adjusting the scheduling type of a CPU, characterized in that, include: Perform a shutdown operation on the target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling; Read the first mask value from the mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of the first type and the second type; The mask value stored at the mask address is adjusted from the first mask value to the second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is a target type, and the target type is another one of the first type and the second type; Perform an online operation on the target CPU and set the scheduling type of the target CPU to the target type indicated by the second mask value; The step of taking the target CPU offline includes: terminating the process running on the target CPU or scheduling it to run on another CPU; and calling a state machine to stop the operation of the target CPU. The step of terminating or rescheduling the processes running on the target CPU to other CPUs includes: if the current type of the target CPU is a first type, selecting a first CPU from other CPUs of the first type and rescheduling all processes of the target CPU to the first CPU; or, if the current type of the target CPU is a second type, terminating all processes of the target CPU and restarting all processes of the target CPU in other CPUs of the second type.
2. The method according to claim 1, characterized in that, When the current type of the target CPU is a first type, selecting the first CPU from other CPUs of the first type includes: Determine the load for each type of CPU; Calculate the average value of the load; The CPU whose load is less than the average value and is closest to the average value is determined as the first CPU; or the CPU with the smallest load is determined as the first CPU.
3. The method according to claim 1, characterized in that, The step of adjusting the mask value stored at the mask address from the first mask value to the second mask value includes: Adjust the first mask value in the mask list corresponding to the mask address to the second mask value, wherein the mask list stores the correspondence between the CPU's CPU-id and the mask value; or... Delete the first mask value from the first mask list corresponding to the first type of CPU, and add the second mask value of the target CPU to the second mask list corresponding to the second type of CPU, wherein the first mask value and the second mask value correspond to the CPU-id of the target CPU.
4. The method according to claim 1, characterized in that, Before performing the offline operation on the target CPU, the method further includes: The load of each first-type CPU, including the target CPU, is statistically analyzed. If the average load is less than a preset load value, one or more CPUs of the first type are identified as the target CPU.
5. The method according to claim 4, characterized in that, The step of identifying one or more CPUs of the first type as the target CPU when the average load is less than a preset load value includes: Sort the CPUs of the first type in ascending order of load; If the first CPU of the first type is determined as the current CPU, the following operations are performed: if the process on the current CPU can be scheduled to another CPU of the first type, the current CPU is determined as the target CPU, and the next CPU of the current CPU is determined as the new current CPU, until the process on the current CPU cannot be scheduled to another CPU of the first type.
6. A CPU scheduling type adjustment device, characterized in that, include: The first execution module is used to perform an offline operation on the target CPU, wherein the target CPU is a CPU whose scheduling type is to be adjusted, and the scheduling type includes a first type that allows task scheduling and a second type that does not allow task scheduling. A reading module is configured to read a first mask value from the mask address of the target CPU, wherein the first mask value is used to indicate the current type of the target CPU, and the current type is one of the first type and the second type; An adjustment module is used to adjust the mask value stored at the mask address from the first mask value to the second mask value, wherein the second mask value is used to indicate that the scheduling type of the target CPU is a target type, and the target type is another one of the first type and the second type; The second execution module is used to perform an online operation on the target CPU and set the scheduling type of the target CPU to the target type indicated by the second mask value; The step of taking the target CPU offline includes: terminating the process running on the target CPU or scheduling it to run on another CPU; and calling a state machine to stop the operation of the target CPU. The step of terminating or rescheduling the processes running on the target CPU to other CPUs includes: if the current type of the target CPU is a first type, selecting a first CPU from other CPUs of the first type and rescheduling all processes of the target CPU to the first CPU; or, if the current type of the target CPU is a second type, terminating all processes of the target CPU and restarting all processes of the target CPU in other CPUs of the second type.
7. An electronic device, characterized in that, include: At least one communication interface; At least one bus connected to the at least one communication interface; At least one processor connected to the at least one bus; At least one memory connected to the at least one bus, wherein the memory stores a computer program, and the processor executes the computer program to implement the method of any one of claims 1 to 5.
8. A computer-readable storage medium storing computer-executable instructions for performing the method described in any one of claims 1 to 5 of this application.