A method and device for rebuilding Linux kernel scheduler
By reconstructing the scheduling data and status data of the kernel scheduler in downtime, the scheduling policy inaccuracy caused by the kernel scheduler data error is solved, and automatic failure recovery and accuracy improvement is achieved.
Patent Information
- Application Number
- CN202111501122.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2025-05-20
- Estimated Expiration
- 2041-12-09
AI Technical Summary
In the prior art, the scheduling data of the kernel scheduler or the state data of the scheduling entity are prone to errors, resulting in inaccurate scheduling strategies, and manual correction is difficult to ensure accuracy, which increases labor costs.
When the system is in downtime mode, the kernel scheduler's scheduler's scheduler and the status data of each scheduled entity are reconstructed, including determining all scheduled entities, clearing and rebuilding the status data, clearing and rebuilding the scheduled data, and finally exiting the downtime mode to restore scheduling.
It realizes automatic reconstruction when a kernel scheduler fails, reduces manual review costs, improves the accuracy of fault recovery, and ensures the correct use of status data and schedule data.
Smart Images

Figure CN114385392B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the technical field of the Linux kernel scheduler, and in particular, to a method and apparatus for reconstructing a Linux kernel scheduler. Background Art
[0002] The kernel scheduler in the Linux system is used to reasonably allocate kernel resources to each process to improve the system fluency of Linux. The scheduling process of each process by the kernel scheduler is relatively complex. Generally speaking, after a certain scheduling entity (process or process group) is incorporated into the scheduling of the kernel scheduler, the kernel scheduler will start to record and initialize the state data of the scheduling entity as the state data corresponding to the scheduling entity. Then, over time, the state data of the scheduling entity is periodically updated according to the scheduling policy until the scheduling entity is completed by the kernel execution. The kernel scheduler obtains scheduling data recording the scheduling order information of each scheduling entity according to the state data corresponding to each scheduling entity and the scheduling policy, and the kernel scheduler completes the scheduling of each scheduling entity in sequence according to the scheduling data.
[0003] Among them, the scheduling policy of the kernel scheduler consists of many functions, including constructing which state data (such as constructing virtual run time) for the scheduling entities incorporated into the kernel scheduler, how to initialize the state data values corresponding to each scheduling data, how to periodically update the state data values corresponding to each scheduling data, and how to sort according to the state data corresponding to each scheduling data to obtain the scheduling data for recording order information, etc. Different scheduling policies include different functions. Therefore, the kernel scheduler will have different scheduling processes for each scheduling entity when using different scheduling policies.
[0004] In practical applications, there may be errors in the scheduling data or the state data corresponding to each scheduling entity. For example, when updating the scheduling policy of the kernel scheduler, the updated scheduling policy uses the scheduling state data before the update. However, due to inappropriate update timing, etc., the scheduling policy before the update does not update the state data of each scheduling entity in time, resulting in inaccurate state data corresponding to each scheduling entity on which the updated scheduling policy is based.
[0005] In the related art, technical personnel correct the state data or scheduling data corresponding to each scheduling entity by analyzing the complete scheduling process of the kernel scheduler. This manual correction method not only has difficulty in ensuring accuracy but also adds labor costs. Summary of the Invention
[0006] In view of this, one or more embodiments of this specification provide a method for reconstructing a Linux kernel scheduler.
[0007] To achieve the above object, one or more embodiments of this specification provide the following technical solutions:
[0008] According to the first aspect of one or more embodiments of this specification, a method for reconstructing a Linux kernel scheduler is proposed. The kernel scheduler constructs scheduling data based on the status data and scheduling policies corresponding to each scheduling entity included in the scheduling, and completes the scheduling of each scheduling entity in sequence according to the constructed scheduling data. The method includes:
[0009] After receiving an instruction to reconstruct the kernel scheduler, call the stop machine function to put the system into the halt mode to stop the kernel scheduler from scheduling the scheduling entities, and perform the following steps while the system is in the halt mode:
[0010] Determine all scheduling entities included in the scheduling of the kernel scheduler;
[0011] Perform a dequeue operation on each scheduling entity included in the scheduling of the kernel scheduler, and clear the status data corresponding to each scheduling entity;
[0012] After performing a dequeue operation on all scheduling entities included in the scheduling of the kernel scheduler, perform an enqueue operation on each dequeued scheduling entity, and reconstruct and initialize the corresponding status data for the scheduling entity according to the scheduling policy of the kernel scheduler;
[0013] Clear the scheduling data of the kernel scheduler;
[0014] Based on the corresponding status data reconstructed and initialized for each scheduling entity, and the scheduling policy, reconstruct the scheduling data;
[0015] Exit the halt mode to continue the kernel scheduler's scheduling of the scheduling entities.
[0016] According to the second aspect of one or more embodiments of this specification, a device for reconstructing a Linux kernel scheduler is proposed. The kernel scheduler constructs scheduling data based on the status data and scheduling policies corresponding to each scheduling entity included in the scheduling, and completes the scheduling of each scheduling entity in sequence according to the constructed scheduling data. The device includes:
[0017] A receiving module, configured to call the stop machine function to put the system into the halt mode to stop the kernel scheduler from scheduling the scheduling entities after receiving an instruction to reconstruct the kernel scheduler;
[0018] A determining module, configured to determine all scheduling entities included in the scheduling of the kernel scheduler;
[0019] The empty status data module is used to perform a dequeue operation on each scheduling entity included in the scheduling of the kernel scheduler and empty the status data corresponding to each scheduling entity;
[0020] The rebuilt status data module is used to perform a dequeue operation on all scheduling entities included in the scheduling of the kernel scheduler, then perform an enqueue operation on each dequeued scheduling entity, and rebuild and initialize the corresponding status data for the scheduling entity according to the scheduling policy of the kernel scheduler;
[0021] The empty scheduling data module empties the scheduling data of the kernel scheduler;
[0022] The rebuilt scheduling data module is used to rebuild the scheduling data based on the corresponding status data rebuilt and initialized for each scheduling entity and the scheduling policy;
[0023] The exit module is used to exit the halt mode to continue the scheduling of scheduling entities by the kernel scheduler.
[0024] The method for rebuilding the Linux kernel scheduler proposed in this specification rebuilds the scheduling data of the kernel scheduler and the status data of each scheduling entity when the system is in the halt mode. Specifically, first determine all scheduling entities included in the kernel scheduler, perform a dequeue operation on each scheduling entity, and empty the status data corresponding to each scheduling entity. After performing a dequeue operation on all scheduling entities, perform an enqueue operation on each dequeued scheduling entity, and rebuild and initialize the corresponding status data for the scheduling entity according to the scheduling policy of the kernel scheduler. Finally, rebuild the scheduling data according to the status data rebuilt for each scheduling entity and the scheduling policy. After the rebuilding is completed, exit the halt mode to enable the kernel scheduler to continue scheduling the scheduling entities.
[0025] Through one or more embodiments of this specification, in the case of a failure of the kernel scheduler, the reconstruction of the kernel scheduler can be automatically completed without manual review of the scheduling process of the kernel scheduler one by one, saving labor costs and improving the accuracy of fault recovery. Moreover, the method of this specification can ensure the correct use and maintenance of the corresponding status data and scheduling data, has high versatility, can be applied to kernel schedulers with different scheduling policies, and reduces the risk coefficient. Brief Description of the Drawings
[0026] Figure 1 is a schematic flowchart of a method for rebuilding a Linux kernel scheduler provided by an exemplary embodiment.
[0027] Figure 2 is a schematic flowchart of another method for rebuilding a Linux kernel scheduler provided by an exemplary embodiment.
[0028] Figure 3 It is a schematic structural diagram of a reconstruction device for a Linux kernel scheduler provided by an exemplary embodiment.
[0029] Figure 4 It is a schematic structural diagram of a device provided by an exemplary embodiment. Detailed implementation manners
[0030] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with one or more embodiments of this specification. On the contrary, they are only examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0031] It should be noted that: In other embodiments, the steps of the corresponding methods are not necessarily executed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step for description in other embodiments.
[0032] The Linux system is widely used. For example, most of the systems used by cloud service providers in cloud services are Linux systems. In the Linux system, generally, the kernel scheduler reasonably allocates kernel resources to each process. However, with the actual business requirements, different requirements for the allocation method of kernel resources have emerged, and many kernel schedulers with different scheduling strategies have been derived. Taking the completely fair scheduler in the derivation process as an example, in the previous kernel schedulers, the process was used as the scheduling unit, that is, the scheduling entities were all processes, and scheduling was performed in turn according to the actual running time or the weights of different processes. When multiple users use the same system, users with more processes will occupy more kernel resources for a long time. Due to the fact that users with more processes occupy more kernel resources for a long time, the processes of users with fewer processes cannot be well processed. In cloud services, when multiple users share the same system resources, such a situation is not expected to occur and is very unfriendly to users whose long-term processes cannot be processed.
[0033] Therefore, the Completely Fair Scheduler appears. The scheduling entities are processes or process groups. Multiple processes of a user form a process group, and resources are allocated with the process group as a scheduling entity, making the kernel resources obtained by each user completely fair. Hence, it is called the Completely Fair Scheduler.
[0034] In the future, according to actual needs, more kernel schedulers with different scheduling strategies will be derived to update and upgrade the scheduling strategies of the kernel schedulers. For example, change the update period of the status data corresponding to each scheduling entity, change the update rules of the status data corresponding to each entity, or record more status information of each scheduling entity. The status data corresponding to each scheduling entity may be more, and so on.
[0035] It should be noted that the scheduling strategy of each kernel scheduler consists of many functions, including constructing what status data for the scheduling entities incorporated into the kernel scheduler (such as constructing virtual run time), how to initialize the status data values corresponding to each scheduling data, how to periodically update the status data values corresponding to each scheduling data, and how to sort according to the status data corresponding to each scheduling data to obtain the scheduling data for recording order information. Different scheduling strategies include different functions. Therefore, the kernel scheduler will have different scheduling processes for each scheduling entity using different scheduling strategies.
[0036] Among them, different scheduling strategies will construct different status data for the scheduling entities. For example, the scheduling strategy of the above-mentioned Completely Fair Scheduler will construct virtual run time and update it periodically. Another example is that before the Completely Fair Scheduler was derived, the scheduling strategy of the Real-Time Scheduler would record the actual run time of each scheduling entity and update it periodically.
[0037] Due to different scheduling strategies, the scheduling data will also be different. For example, for the scheduling strategy of the above-mentioned Completely Fair Scheduler, the scheduling data is a red-black tree constructed with the virtual run time corresponding to each scheduling entity as the key. For the rt scheduler, it is executed in the order of the actual run time of each scheduling entity, and the scheduling data is multiple queues with priorities.
[0038] Generally speaking, a kernel scheduler needs to have a scheduling strategy, which will construct corresponding status data for each scheduling entity, and the status data corresponding to each scheduling entity is used to represent the status information recorded after the scheduling entity is incorporated into the kernel scheduler for scheduling. The kernel scheduler constructs scheduling data for recording scheduling order information based on the status data corresponding to each scheduling entity incorporated into the scheduling and the scheduling strategy, and completes the scheduling of each scheduling entity in sequence according to the constructed scheduling data.
[0039] The above is an introduction to the kernel scheduler. In actual applications, problems may occur with the status data corresponding to each scheduling entity in the kernel scheduler or the scheduling data of the kernel scheduler. For example, a problem occurs when the scheduling policy of the kernel scheduler is executed, causing the status data corresponding to a certain scheduling entity not to be updated in a timely manner. Another example is that when the scheduling policy of the kernel scheduler is updated, the recorded status data or scheduling data changes, and so on.
[0040] Based on this, this specification proposes a method for reconstructing the Linux kernel scheduler. When the system is in the shutdown mode, the scheduling data of the kernel scheduler and the status data of each scheduling entity are reconstructed. Specifically, first determine all the scheduling entities included in the kernel scheduler, perform a dequeue operation on each scheduling entity, and clear the status data corresponding to each scheduling entity. After performing the dequeue operation on all the scheduling entities, perform an enqueue operation on each dequeued scheduling entity, and according to the scheduling policy of the kernel scheduler, reconstruct and initialize the corresponding status data for this scheduling entity. Finally, according to the status data reconstructed for each scheduling entity and the scheduling policy, reconstruct the scheduling data. After the reconstruction is completed, exit the shutdown mode so that the kernel scheduler can continue to schedule the scheduling entities.
[0041] Through one or more embodiments of this specification, in the case of a failure of the kernel scheduler, the reconstruction of the kernel scheduler can be automatically completed without manually checking the scheduling process of the kernel scheduler one by one, saving labor costs and improving the accuracy of fault recovery. Moreover, the method of this specification can ensure the correct use and maintenance of the corresponding status data and scheduling data, has high versatility, can be applied to different kernel schedulers, and reduces the risk coefficient.
[0042] Next, a detailed description of the method for reconstructing the Linux kernel scheduler shown in this specification will be given. As Figure 1 shown, it is a schematic flowchart of the method for reconstructing the Linux kernel scheduler shown in this specification, including the following steps:
[0043] Step 101: After receiving an instruction to reconstruct the kernel scheduler, call the stop machine function to make the system enter the shutdown mode to stop the kernel scheduler from scheduling the scheduling entities, and execute steps 103 to 111 when the system is in the shutdown mode.
[0044] Among them, the instruction to reconstruct the kernel scheduler can be input by the user to reconstruct the faulty kernel scheduler, or triggered by a certain event (for example, detecting that there is a problem with the scheduling data in the kernel scheduler, or detecting that there is a problem with the status data corresponding to a certain scheduling entity, etc.).
[0045] If the instruction to reconstruct the kernel scheduler is input by the user, then according to the instruction input by the user, the corresponding kernel scheduler can be reconstructed. If it is triggered by an event, then the reconstructed kernel scheduler is the kernel scheduler where the event occurred.
[0046] It should be noted that the stop machine command is the process with the highest priority in the system. After calling the stopmachine function, the system will be in the halt mode. The system will not process other processes and will only process the relevant calculations under the stop machine command. Therefore, after calling the stop machine function, all systems are in the halt mode, and the scheduling of the kernel scheduler will also stop accordingly. (When manually checking and reviewing the scheduling process of the kernel scheduler, the stop machine command also needs to be invoked to make all systems in the halt mode.) For a detailed description of the stop machine command, refer to the description in the related technology, and no detailed description will be provided here.
[0047] After the system is in the halt mode, the following steps are executed.
[0048] Step 103: Determine all scheduling entities included in the scheduling of the kernel scheduler.
[0049] In the Linux system, there is more than one kernel scheduler. The system allocates processes to different kernel schedulers according to the type of the process. For example, real-time processes are allocated to the real-time kernel scheduler, and ordinary processes are allocated to the Completely Fair Scheduler, etc.
[0050] Since not all processes or process groups in the system belong to the scheduling of a single kernel scheduler, when reconstructing the kernel scheduler, it is necessary to determine all scheduler entities included in the scheduling of this kernel scheduler.
[0051] Among them, each kernel scheduler will have a corresponding run queue. The run queue corresponding to the kernel scheduler can be traversed to determine the processes and process groups in the run queue corresponding to the kernel scheduler, and the processes or process groups in the run queue corresponding to the kernel scheduler are determined as the scheduling entities included in the scheduling of the kernel scheduler.
[0052] Step 105: Perform a dequeue operation on each scheduling entity included in the scheduling of the kernel scheduler, and clear the status data corresponding to each scheduling entity.
[0053] The scheduling entities included in each kernel scheduler will be placed in the corresponding run queue by the kernel scheduler. When a scheduling entity is included in the scheduling, it will be placed in the corresponding queue. During the enqueue process, the corresponding status data will be constructed for it and the corresponding status data will be initialized.
[0054] Therefore, when reconstructing the status data corresponding to a scheduling entity, it is necessary to first perform a dequeue operation to empty the run queue corresponding to the kernel scheduler and empty the status data corresponding to each scheduling entity.
[0055] It should be noted that the "emptying" mentioned in this specification refers to deleting the corresponding data. Emptying the status data corresponding to a scheduling entity means deleting the status data in the kernel scheduler that is used to record the status information of this scheduling entity.
[0056] Step 107: After performing a dequeue operation on all scheduling entities scheduled by the kernel scheduler, perform an enqueue operation on each dequeued scheduling entity, and reconstruct and initialize the corresponding status data for this scheduling entity according to the scheduling policy of the kernel scheduler.
[0057] After performing a dequeue operation on all scheduling entities scheduled by the kernel scheduler, it means setting the run queue corresponding to the kernel scheduler to be empty, becoming an empty queue. Then perform an enqueue operation on each dequeued scheduling entity, and reconstruct and initialize the corresponding status data for this scheduling entity according to the scheduling policy of the kernel scheduler.
[0058] Among them, the enqueue of a scheduling entity in this specification means recording the identifier corresponding to a process or a process group into the run queue as a scheduling entity of the kernel scheduler, and the dequeue of a scheduling entity means deleting the identifier corresponding to a process or a process group from the run queue.
[0059] Step 109: Empty the scheduling data of the kernel scheduler.
[0060] The kernel scheduler schedules the included scheduling entities according to the order information recorded in the scheduling data, and the scheduling data is obtained based on the status data corresponding to each scheduling entity and the scheduling policy. Since the status data corresponding to each scheduling data has changed, the scheduling data also needs to be reconstructed, and the previous scheduling data needs to be emptied.
[0061] Step 111: Based on the corresponding status data reconstructed and initialized for each scheduling entity and the scheduling policy, reconstruct the scheduling data for the kernel scheduler.
[0062] Step 113: Exit the halt mode to continue the scheduling of scheduling entities by the kernel scheduler.
[0063] After exiting the halt mode, the system will continue to process each process, and the kernel scheduler will also resume scheduling each scheduler entity.
[0064] After the kernel scheduler is rebuilt, the state data corresponding to the scheduling entities incorporated into the kernel scheduler are all the rebuilt state data, and the scheduling data is also the rebuilt scheduling data. Therefore, after the kernel scheduler resumes scheduling for each scheduling entity, the data it depends on are all re-initialized data, and correct scheduling is performed based on each initialized data.
[0065] Through one or more embodiments of this specification, in the case of a kernel scheduler failure, the reconstruction of the kernel scheduler can be automatically completed without manually reviewing the scheduling process of the kernel scheduler one by one, saving labor costs and improving the accuracy of fault recovery. Moreover, the method of this specification can ensure the correct use and maintenance of the corresponding state data and scheduling data, has high generality, can be applied to kernel schedulers with different scheduling strategies, and reduces the risk coefficient.
[0066] It should be noted that the state data of this specification is used to represent the state information recorded after a scheduling entity is incorporated into the kernel scheduler for scheduling. The scheduling data is used to record the scheduling order information of each scheduling entity.
[0067] Among them, when the policy of the kernel scheduler is the completely fair policy, the kernel scheduler at this time is a completely fair kernel scheduler, and the completely fair kernel scheduler is already a relatively mature technology, which will not be elaborated in detail in this specification. When the kernel scheduler is a completely fair kernel scheduler, at this time, the state data corresponding to the scheduling entity at least includes the virtual run time, and the kernel scheduling data includes a red-black tree with the virtual run time corresponding to each scheduling entity as the key.
[0068] Among them, in the case where the scheduling entity is a process group, the state data corresponding to the scheduling entity further includes: a red-black tree with the virtual run time corresponding to each process within the group as the key.
[0069] The high-precision timer is a timer used for precise timing in the kernel system, which can be accurate to nanoseconds. The kernel scheduler can call the high-precision timer to time the execution time of each scheduling entity, etc., and some kernel schedulers will perform scheduling based on the timing of the high-precision timer as a reference.
[0070] Therefore, in one or more embodiments, between steps 105, it is also possible to first determine whether the status flag bit of the high-precision timer of the kernel scheduler is in the enabled state, and in the case where it is determined that the status flag bit of the high-precision timer is in the enabled state, turn off the high-precision timer.
[0071] After step 111, in the case where it is determined that the status flag bit of the high-precision timer is in the enabled state, turn on the high-precision timer.
[0072] In addition, in the case where the instruction for reconstructing the scheduler is to update the scheduling policy of the kernel scheduler, as Figure 2 shown, the method for reconstructing the Linux kernel scheduler includes:
[0073] Step 201: After receiving the instruction to reconstruct the kernel scheduler, call the stop machine function to put the system into the halt mode to stop the kernel scheduler from scheduling scheduling entities, and execute steps 203 to 211 while the system is in the halt mode.
[0074] Step 203: Determine all scheduling entities incorporated into the scheduling of the kernel scheduler.
[0075] Step 205: Perform a dequeue operation on each scheduling entity incorporated into the scheduling of the kernel scheduler, and clear the status data corresponding to each scheduling entity.
[0076] Step 207: After performing a dequeue operation on all scheduling entities incorporated into the scheduling of the kernel scheduler, perform an enqueue operation on each dequeued scheduling entity, and re - construct and initialize the corresponding status data for this scheduling entity according to the updated scheduling policy of the kernel scheduler.
[0077] Step 209: Clear the scheduling data of the kernel scheduler.
[0078] Step 211: Re - construct the scheduling data based on the corresponding status data re - constructed and initialized for each scheduling entity, and the updated scheduling policy.
[0079] Step 213: Exit the halt mode to continue the kernel scheduler's scheduling of scheduling entities.
[0080] Next, this specification takes the Completely Fair Scheduling policy as an example to elaborate in detail on the method for reconstructing the Linux kernel scheduler.
[0081] 1. The reconstruction of the kernel scheduler needs to be carried out in an atomic environment (the atomic environment, or the so - called interrupt environment, where all data remains in the current state and will not change), so the stop machine mechanism (calling the stopmachine function) can be used to enter the system halt state, making all CPUs in the stopping state.
[0082] 2. Clean the current status data and scheduling data.
[0083] 1) Traverse the task_groups linked list in the system:
[0084] ⅰ. Clean the cfs_rq (the run queue corresponding to the CFS kernel scheduler) on each CPU:
[0085] Processes on cfs_rq are all dequeued, and relevant scheduling states are cleared. For example, data related to load (load) and tasks_timeline (red-black tree) are cleared.
[0086] ii. Clear the data status related to se (scheduling entity) corresponding to all cfs_rq in step i.
[0087] iii. By traversing the throttled_cfs_rq linked list (except for root_task_group, root_task_group is the root node, and only root_task_group indicates that the linked list is empty), process the cfs_rq that has been throttled (suspended) on task_groups, force it to perform an unthrottle operation, and turn off the high-precision timer of CFS bandwidth.
[0088] 2) Traverse the run queues rq of all CPUs:
[0089] Clear the relevant data status on rq.
[0090] 3. Rebuild the kernel scheduler:
[0091] 1) Traverse the task_list in the system:
[0092] Judge the status of each process. If it is in the running state, clear its corresponding relevant status, such as the flag bit of on_rq (whether to join the corresponding red-black tree), vruntime (virtual running time) and other status data, and then enqueue it. The relevant data status will be automatically updated and synchronized by calling the scheduler function.
[0093] 2) Traverse the task_groups linked list of the system:
[0094] Detect the timer status of the task group. If it is in the period_active state, start the high-precision timer of CFS bandwidth, otherwise there is no need to start.
[0095] 4. Exit the stop machine state, and the system continues to run.
[0096] The above is a detailed description of the method for rebuilding the Linux kernel scheduler. Next, a detailed description of the device for rebuilding the Linux kernel scheduler corresponding to the above method will be given.
[0097] This specification also provides a reconstruction device for a Linux kernel scheduler. The kernel scheduler constructs scheduling data based on the status data and scheduling policies corresponding to each scheduling entity included in the scheduling, and completes the scheduling of each scheduling entity in sequence according to the constructed scheduling data; as Figure 3 shown, the device includes:
[0098] A receiving module 301, configured to, after receiving an instruction to reconstruct the kernel scheduler, call the stop machine function to put the system into a halt mode to stop the kernel scheduler from scheduling scheduling entities;
[0099] A determining module 303, configured to determine all scheduling entities included in the scheduling of the kernel scheduler;
[0100] A clearing status data module 305, configured to perform a dequeue operation on each scheduling entity included in the scheduling of the kernel scheduler, and clear the status data corresponding to each scheduling entity;
[0101] A reconstructing status data module 307, configured to, after performing a dequeue operation on all scheduling entities included in the scheduling of the kernel scheduler, perform an enqueue operation on each dequeued scheduling entity, and reconstruct and initialize the corresponding status data for the scheduling entity according to the scheduling policy of the kernel scheduler;
[0102] A clearing scheduling data module 309, configured to clear the scheduling data of the kernel scheduler;
[0103] A reconstructing scheduling data module 311, configured to reconstruct scheduling data based on the corresponding status data reconstructed and initialized for each scheduling entity, and the scheduling policy;
[0104] An exiting module 313, configured to exit the halt mode to continue the kernel scheduler's scheduling of scheduling entities.
[0105] Wherein, when the kernel scheduler is a completely fair scheduler:
[0106] The status data corresponding to the scheduling entity at least includes virtual run time;
[0107] The scheduling data includes a red-black tree with the virtual run times corresponding to each scheduling entity as keywords.
[0108] In addition, when the scheduling entity is a process group, the status data corresponding to the scheduling entity further includes: a red-black tree with the virtual run times corresponding to each process within the group as keywords.
[0109] In addition, when the kernel scheduler is a completely fair scheduler, the device may further include:
[0110] A shutdown module, configured to determine whether a status flag bit of a high-precision timer of the kernel scheduler is in an enabled state before performing a dequeue operation on each scheduling entity scheduled by the kernel scheduler; and to shut down the high-precision timer when it is determined that the status flag bit of the high-precision timer is in the enabled state.
[0111] An enable module, configured to enable the high-precision timer when it is determined that the status flag bit of the high-precision timer is in the enabled state, after reconstructing and initializing corresponding state data for each scheduling entity and before exiting the halt mode, based on the reconstructed scheduling data for the kernel scheduler and the scheduling policy.
[0112] In addition, the determination module may specifically be configured to:
[0113] Traverse the run queue corresponding to the kernel scheduler, determine the processes and process groups in the run queue, and determine the processes or process groups in the run queue as the scheduling entities scheduled by the kernel scheduler.
[0114] When the reconstruction instruction is to update the scheduling policy of the kernel scheduler, the reconstruction state data module may specifically be configured to:
[0115] After performing a dequeue operation on all scheduling entities scheduled by the kernel scheduler, perform an enqueue operation on each dequeued scheduling entity, and reconstruct and initialize corresponding state data for the scheduling entity according to the updated scheduling policy of the kernel scheduler.
[0116] The reconstruction scheduling data module may specifically be configured to:
[0117] Reconstruct scheduling data based on the corresponding state data reconstructed and initialized for each scheduling entity and the updated scheduling policy.
[0118] The devices and modules illustrated in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, and the specific form of the computer may be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver device, a game console, a tablet computer, a wearable device, or a combination of any several of these devices.
[0119] In a typical configuration, a computer includes one or more processors (CPUs), an input / output interface, a network interface, and memory. The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0120] This specification also provides an electronic device, including:
[0121] A processor;
[0122] A memory for storing processor-executable instructions;
[0123] Wherein, the processor runs the executable instructions to implement the reconstruction method of the Linux kernel scheduler as described in any one of the above.
[0124] Figure 4 FIG. shows a more specific schematic diagram of the hardware structure of a computing device provided by an embodiment of this specification. The device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. Among them, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are communicatively connected to each other inside the device through the bus 1050.
[0125] The processor 1010 may be implemented in a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, etc., and is used to execute relevant programs to implement the technical solutions provided by the embodiments of this specification.
[0126] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), a static storage device, a dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When implementing the technical solutions provided by the embodiments of this specification through software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.
[0127] The input / output interface 1030 is used to connect to the input / output module to achieve information input and output. The input / output module can be configured as a component in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Among them, the input devices can include keyboards, mice, touchscreens, microphones, various sensors, etc., and the output devices can include displays, speakers, vibrators, indicator lights, etc.
[0128] The communication interface 1040 is used to connect to the communication module (not shown in the figure) to achieve communication interaction between this device and other devices. Among them, the communication module can achieve communication through wired means (such as USB, network cable, etc.) or through wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0129] The bus 1050 includes a path for transmitting information between various components of the device (such as the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).
[0130] It should be noted that although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, those skilled in the art can understand that the above device may also only include the components necessary to implement the solution of the embodiments of this specification, and do not have to include all the components shown in the figure.
[0131] This specification also provides a computer-readable storage medium, on which computer instructions are stored, and when the instructions are executed by the processor, the steps of the reconstruction method of the Linux kernel scheduler as described in any of the above are implemented.
[0132] Computer-readable media include permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0133] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device that includes a series of elements includes not only those elements, but also other elements that are not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises one..." do not exclude the existence of other identical elements in the process, method, commodity or device that includes the elements.
[0134] The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0135] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "one", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0136] It should be understood that although the terms first, second, third, etc. may be used in one or more embodiments of this specification to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "when" or "while" or "in response to determining".
[0137] The above are only the preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included within the scope protected by one or more embodiments of this specification.
Claims
1. A method for reconstructing a Linux kernel scheduler, wherein the kernel scheduler constructs scheduling data according to the state data corresponding to each scheduling entity included in the scheduling and the scheduling policy, and sequentially completes the scheduling of each scheduling entity according to the constructed scheduling data; the method comprises: After receiving the instruction to rebuild the kernel scheduler, the stop machine function is called to put the system into the stop mode to stop the kernel scheduler from scheduling the scheduling entity. The following steps are performed when the system is in the stop mode: Determine all scheduling entities to be included in the kernel scheduler; Performing a dequeue operation on each scheduling entity included in the kernel scheduler, and clearing the status data corresponding to each scheduling entity; After performing a dequeue operation on all scheduling entities included in the kernel scheduler, performing an enqueue operation on each scheduling entity after the dequeue, and re-building and initializing corresponding state data for the scheduling entity according to the scheduling policy of the kernel scheduler; Clearing the scheduling data of the kernel scheduler; Reconstructing the scheduling data based on the corresponding state data reconstructed and initialized for each scheduling entity and the scheduling strategy; Exit the shutdown mode to continue the scheduling of the scheduling entity by the kernel scheduler.
2. The method according to claim 1, wherein the state data is used to represent the state information recorded after the scheduling entity is included in the scheduling by the kernel scheduler.
3. According to the method of claim 1, the scheduling data is used to record the scheduling order information of each scheduling entity.
4. The method according to claim 1, wherein when the kernel scheduler is a completely fair scheduler: The state data corresponding to the scheduling entity includes at least virtual running time; The scheduling data includes a red-black tree with the virtual running time corresponding to each scheduling entity as a key.
5. The method according to claim 4, wherein when the scheduling entity is a process group, the status data corresponding to the scheduling entity further includes: A red-black tree with the virtual running time corresponding to each process in the group as the key.
6. The method according to claim 4, before performing a dequeue operation on each scheduling entity included in the kernel scheduler, further comprising: Determine whether the status flag bit of the high-precision timer of the kernel scheduler is in an on state; When determining that the status flag of the high-precision timer is in the on state, shutting down the high-precision timer; After re-building scheduling data for the kernel scheduler based on the corresponding state data re-built and initialized for each scheduling entity and the scheduling policy, and before exiting the shutdown mode, the method further includes: When it is determined that the status flag of the high-precision timer is in the on state, the high-precision timer is turned on.
7. The method of claim 1, wherein determining all scheduling entities to be scheduled by the kernel scheduler comprises: The running queue corresponding to the kernel scheduler is traversed to determine the processes and process groups in the running queue, and the processes or process groups in the running queue are determined as scheduling entities to be included in the kernel scheduler.
8. The method according to claim 1, wherein when the reconstruction instruction is to update the scheduling policy of the kernel scheduler: The re-building and initializing corresponding state data for the scheduling entity according to the scheduling policy of the kernel scheduler includes: Rebuilding and initializing corresponding state data for the scheduling entity according to the updated scheduling policy of the kernel scheduler; The reconstructing of the scheduling data based on the corresponding state data reconstructed and initialized for each scheduling entity and the scheduling strategy includes: The scheduling data is reconstructed based on the corresponding state data reconstructed and initialized for each scheduling entity and the updated scheduling policy.
9. A reconstruction device for a Linux kernel scheduler, wherein the kernel scheduler constructs scheduling data according to the state data corresponding to each scheduling entity included in the scheduling and the scheduling strategy, and sequentially completes the scheduling of each scheduling entity according to the constructed scheduling data; the device comprises: A receiving module, configured to, after receiving an instruction to rebuild the kernel scheduler, call a stop machine function to put the system into a shutdown mode, so as to stop the kernel scheduler from scheduling the scheduling entity; A determination module, used for determining all scheduling entities to be included in the scheduling of the kernel scheduler; A status data clearing module is used to perform a dequeue operation on each scheduling entity included in the kernel scheduler, and clear the status data corresponding to each scheduling entity; A state data reconstruction module is used to perform a dequeue operation on all scheduling entities included in the kernel scheduler, perform an enqueue operation on each scheduling entity after the dequeue operation, and re-build and initialize corresponding state data for the scheduling entity according to the scheduling policy of the kernel scheduler; A clearing schedule data module, clearing the schedule data of the kernel scheduler; A scheduling data reconstruction module, used to reconstruct scheduling data based on the corresponding state data reconstructed and initialized for each scheduling entity and the scheduling strategy; The exit module is used to exit the shutdown mode to continue the scheduling of the scheduling entity by the kernel scheduler.
10. The apparatus of claim 9, wherein when the kernel scheduler is a completely fair scheduler: The state data corresponding to the scheduling entity includes at least virtual running time; The scheduling data includes a red-black tree with the virtual running time corresponding to each scheduling entity as a keyword.
11. The device according to claim 10, wherein when the scheduling entity is a process group, the status data corresponding to the scheduling entity further includes: A red-black tree with the virtual running time corresponding to each process in the group as the key.
12. The apparatus of claim 10, further comprising: A closing module is used to determine whether the status flag of the high-precision timer of the kernel scheduler is in an on state before performing a dequeue operation on each scheduling entity included in the kernel scheduler; if it is determined that the status flag of the high-precision timer is in an on state, close the high-precision timer; An enabling module is used to enable the high-precision timer after re-building the scheduling data for the kernel scheduler based on the corresponding status data re-built and initialized for each scheduling entity and the scheduling policy, and before exiting the shutdown mode, when it is determined that the status flag of the high-precision timer is in the enabled state.
13. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the Linux kernel scheduler reconstruction method according to any one of claims 1 to 8 by running the executable instructions.
14. A computer-readable storage medium having computer instructions stored thereon, wherein when the instructions are executed by a processor, the steps of the method for reconstructing a Linux kernel scheduler according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Method for dispatching I / O of asymmetry virtual machine based on multi-core dynamic partitioning
CN101706742A
Kernel virtual machine scheduling policy-based implementation method
CN101894047A