Task isolation method, device, operating system, equipment and storage medium
By registering preset interfaces in the operating system kernel and dynamically identifying and binding non-isolated CPUs, the problem of static isolation requiring a system restart is solved, and efficient and dynamic CPU isolation configuration updates are achieved, improving CPU resource utilization and the operational stability of critical tasks.
Patent Information
- Application Number
- CN202110199647.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-22
- Publication Date
- 2025-10-14
- Estimated Expiration
- 2041-02-22
AI Technical Summary
In the existing technology, static isolation method to achieve CPU isolation requires restarting the system to take effect, which makes the operation complicated and inefficient, and cannot meet the need of updating CPU isolation configuration on demand.
Register a preset interface in the operating system kernel, receive the CPU identifier entered by the user through the interface, automatically identify and bind non-isolated CPUs, and dynamically isolate tasks that are not subject to resource control to avoid interference with critical tasks.
It enables on-demand updates of CPU isolation configurations without restarting the system, improving operational efficiency and resource utilization, and ensuring the safe and efficient operation of critical tasks.
Smart Images

Figure CN113296938B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a task isolation method and device, an operating system, a device and a storage medium. BACKGROUND
[0002] At present, an embedded operating system is used in many electronic devices, and the embedded operating system generally includes a plurality of hardware such as a central processing unit (CPU), a memory, a general device interface, and software such as an operating system kernel and a user application.
[0003] In the embedded operating system including a plurality of CPUs, the isolation of the CPUs can be realized by a static isolation mode, and some key tasks (which can be specified by a user) can be configured to run on the isolated CPUs to prevent interference of other tasks on the key tasks, so as to ensure safe and efficient running of the key tasks.
[0004] At present, the isolation of the CPUs by the static isolation mode means that the user isolates the CPUs specified in an isolcpus parameter by configuring the isolcpus parameter, and then the user can bind the key tasks and the isolated CPUs together, so that the key tasks can exclusively occupy the bound CPUs.
[0005] However, when the above static isolation mode is used, the system needs to be restarted to make the configured isolcpus parameter effective, which means that if the isolcpus parameter needs to be updated, the system needs to be restarted again after the isolcpus parameter is updated to make the updated isolcpus parameter effective, which is complicated and low in efficiency. SUMMARY
[0006] The embodiments of the present application provide a task isolation method, device, operating system, device and storage medium, which can realize efficient and dynamic binding of tasks not controlled by resources to CPUs not isolated on demand.
[0007] In a first aspect, the embodiments of the present application provide a task isolation method applied to an operating system kernel, and the method comprises:
[0008] receiving a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, and the first processor identifier being an identifier of an isolated processor;
[0009] determining a first task in a user mode not configured with a processor resource from tasks contained in a root node of a target control group, the target control group corresponding to a processor subsystem;
[0010] bind the first task with a second processor identifier, the second processor identifier being an identifier of a processor that is not isolated, the second processor identifier being determined by the first processor identifier and all processor identifiers recorded by the operating system kernel.
[0011] In a second aspect, an embodiment of the present application provides a task isolation apparatus located in an operating system kernel, the apparatus comprising:
[0012] a receiving module configured to receive a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, the first processor identifier being an identifier of an isolated processor;
[0013] a determining module configured to determine, among tasks contained in a root node of a target control group, a first task in a user mode that has not been configured with processor resources, the target control group corresponding to a processor subsystem;
[0014] a binding module configured to bind the first task with a second processor identifier, the second processor identifier being an identifier of a processor that is not isolated, the second processor identifier being determined by the first processor identifier and all processor identifiers recorded by the operating system kernel.
[0015] In a third aspect, an embodiment of the present application provides an operating system, comprising:
[0016] a plurality of processors, and an operating system kernel, the operating system kernel having a preset interface registered therein, the operating system kernel being configured to:
[0017] receive a first processor identifier input by a user through the preset interface, the first processor identifier being an identifier of an isolated processor;
[0018] determine, among tasks contained in a root node of a target control group, a first task in a user mode that has not been configured with processor resources, the target control group corresponding to a processor subsystem;
[0019] bind the first task with a second processor identifier, the second processor identifier being an identifier of a processor that is not isolated, the second processor identifier being determined by the first processor identifier and all processor identifiers recorded by the operating system kernel.
[0020] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising: a memory, a plurality of processors, and an operating system kernel; wherein the memory has executable code stored thereon, the executable code, when executed by the operating system kernel, causing the operating system kernel to at least implement the task isolation method according to the first aspect.
[0021] In a fifth aspect, an embodiment of the present application provides a non-transitory machine readable storage medium having stored thereon executable code that, when executed by an operating system kernel of an electronic device, causes the operating system kernel to at least perform the task isolation method as in the first aspect.
[0022] In the scheme provided by the embodiment of the present application, an interface is pre-registered in the operating system kernel, so that a user triggers the operating system kernel to automatically perform subsequent task isolation steps by writing to the interface. The user writes the identifier of the current CPU that the user wants to isolate, referred to as the first CPU identifier, to the preset interface. Based on the first CPU identifier input by the user, the corresponding CPU is isolated. In actual application, there are some special tasks in the operating system, which are not controlled by resources, that is, the user does not limit which CPU resources these tasks cannot use (i.e., the CPU resource configuration of these tasks is not performed), so these tasks can actually use all CPUs, which will interfere with the tasks running on the isolated CPU, so these tasks need to be identified and the CPU resources that these tasks can use need to be limited. To this end, first, after receiving the first CPU identifier input by the user, the operating system kernel determines the first task of the user state that has not performed CPU resource configuration among the tasks contained in the root node of the target control group (cgroup for short), and the target cgroup corresponds to the CPU subsystem. The first task is the task that is not controlled by resources as described above. Then, the operating system kernel binds the first task with a second CPU identifier, and the second CPU identifier is the identifier of the CPU other than the isolated CPU among the multiple CPUs contained by the operating system, that is, the identifier of the non-isolated CPU. The binding of the first task and the second CPU identifier means that the CPU that can be used by the first task is limited to the non-isolated CPU, so that the first task that is not controlled by resources will not run on the isolated CPU in the future, thereby ensuring the running safety of the tasks on the isolated CPU.
[0023] From the above scheme, based on the above-mentioned preset interface registered in the operating system kernel, the user can input the identifier of the current CPU that needs to be isolated to the preset interface as needed whenever the user needs to update the CPU isolation configuration, so that the operating system kernel can automatically complete the identification of the user state task that is not controlled by resources and the binding of the identified user state task to the non-isolated CPU, achieving convenience and efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 A schematic diagram of the structure of a cgroup tree provided in an embodiment of the present invention;
[0026] Figure 2 A flowchart of a task isolation method provided by an embodiment of the present invention;
[0027] Figure 3 A flowchart of a first task identification method provided by an embodiment of the present invention;
[0028] Figure 4 A schematic diagram of a task isolation execution scenario provided by an embodiment of the present invention;
[0029] Figure 5 A schematic diagram of the structure of a task isolation device provided by an embodiment of the present invention;
[0030] Figure 6 A schematic diagram of the structure of an operating system provided by an embodiment of the present invention;
[0031] Figure 7 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0032] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0033] The terms used in the embodiments of the present invention are for the purpose of describing specific embodiments only and are not intended to limit the present invention. The singular forms "a," "an," "the," and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, and unless the context clearly indicates otherwise, "a plurality" generally includes at least two.
[0034] Depending on context, the word "if" as used herein can be interpreted to mean "when" or "while" or "in response to determining" or "in response to detecting." Similarly, the phrase "if it is determined" or "if [a stated condition or event] is detected" can be interpreted to mean "upon determining" or "in response to determining" or "upon detecting [the stated condition or event]" or "in response to detecting [the stated condition or event]."
[0035] In addition, the step timing in each of the following method embodiments is only an example, and is not strictly limited.
[0036] Before introducing the task isolation scheme provided by the embodiments of the present application, several concepts involved in the present text are briefly described:
[0037] Task: A task is the most basic unit of program control by an operating system. In practical applications, a task can be a process or a thread running in an operating system, and thus, in the present text, a task can be understood as a process or a thread.
[0038] Control group (cgroup): A cgroup is a mechanism for managing processes (i.e., tasks) in groups. From the perspective of a user, a cgroup technology is to organize all processes in an operating system into independent trees, each tree containing all processes in the operating system, each node of the tree being a process group, and each tree being associated with one or more subsystems. There can be many cgroup trees in an operating system. The role of a tree is to group processes, and the role of a subsystem is to operate on these groups.
[0039] The subsystems involved in a cgroup include, but are not limited to, the following subsystems:
[0040] device: Device permission control
[0041] cpu: Control of CPU occupancy
[0042] cpuset: Assignment of specified CPUs and memory nodes
[0043] memory: Limitation of the upper limit of memory usage
[0044] cpuacct: Statistics of CPU usage.
[0045] For ease of understanding, the composition structure of a cgroup tree is described below by way of example. Assume that an operating system includes 100 tasks (i.e., 100 processes) task 1 to task 100, and a user can create a cgroup tree as follows: Figure 1 Figure 1 As shown in the tree, the root node Boot contains 70 tasks, i.e., task 1 to task 70. Two child nodes are created under the root node, which are denoted as child node A and child node B. The child node A contains 10 tasks, i.e., task 71 to task 80, and the child node B contains 10 tasks, i.e., task 91 to task 100. Under the child node A, two child nodes are further created, which are denoted as child node A1 and child node A2. The child node A1 contains 8 tasks, i.e., task 81 to task 88, and the child node A2 contains 2 tasks, i.e., task 89 and task 90.
[0046] Sched_domain: In order to describe the relationship between CPUs, a sched_domain is introduced. Based on the sched_domain, load balancing between CPUs can be performed. Through the description of the sched_domain, the operating system kernel can know the relationship between CPUs. For CPUs with a distant relationship, migration of processes between them is avoided as much as possible; and for CPUs with a close relationship, migration of processes between them is tolerated to a certain extent.
[0047] Wild task: A wild task can be referred to as a wild task, which is a task that is not allocated with CPU resources. The wild task can be derived from the operating system itself or a daemon process of a service.
[0048] CPU isolation: CPU isolation refers to isolating a specified range of CPUs to ensure that all tasks running on the CPUs are user-recognized or specified critical tasks.
[0049] Static CPU isolation: After the CPU isolation configuration (i.e., the configuration of the isolated CPU range) takes effect, the isolated CPU range cannot be re-specified, i.e., the CPU isolation configuration cannot be updated, unless the system is restarted.
[0050] Dynamic CPU isolation: The isolated CPU range can be re-specified at any time, i.e., the configuration takes effect immediately, without the need to restart the system.
[0051] Currently, the static CPU isolation technology can be used to ensure that critical business runs on the isolated CPUs by configuring the CPU isolation, so as to ensure the performance of the critical business. However, since the system needs to be restarted to make the configuration take effect after the configuration, and the critical business does not always need so many CPUs, there is a serious waste of resources in daily life. Therefore, the dynamic isolation technology is needed to modify the CPU isolation range at any time, so as to better utilize the CPU resources, save costs, and improve the overall business performance. In simple terms, the dynamic isolation technology is a technology that dynamically updates the CPU isolation configuration on demand, and the configuration takes effect without the need to restart the system.
[0052] But one difficulty, many wild task is not controlled by resources, they can be some system tasks, or some service daemon, or some business processes not yet included in the control, to isolate these not controlled by resources tasks, the existing technology can not meet the needs of CPU dynamic isolation.
[0053] Based on this, the CPU dynamic isolation technology for the task not controlled by resources is provided in the embodiment of the application, which is a technology capable of dynamically isolating CPU in the case that the isolation target is not controlled by resources, and capable of simply and effectively performing CPU resource dynamic isolation on the wild task, that is, dynamically limiting the task not controlled by resources to run on the unisolated CPU according to the configuration requirement of the isolated CPU, so as to avoid the interference of the task not controlled by resources on the user-specified key task.
[0054] As can be seen, in the embodiment of the application, the task isolation can be considered as isolating the task not controlled by resources to run on the unisolated CPU.
[0055] For example, assuming that the user-specified key task is task A, the task not controlled by resources is task B, and the operating system includes 16 CPUs CPU0-CPU15, when the first configured isolated CPU is CPU0-CPU3, task A runs on a CPU in CPU0-CPU3, at this time, task B should be limited to run on CPU4-CPU15.
[0056] The execution process of the task isolation scheme provided by the embodiment of the application will be described in detail below.
[0057] Figure 2 The flowchart of the task isolation method provided by the embodiment of the application is shown in Figure 2 The method includes the following steps:
[0058] 201, the operating system kernel receives the first CPU identifier input by the user through the preset interface, the preset interface is pre-registered in the operating system kernel, and the first CPU identifier is the identifier of the isolated CPU.
[0059] In the embodiment of the application, an interface is pre-registered in the operating system kernel to trigger the dynamic isolation configuration of the CPU through the preset interface.
[0060] The preset interface registered in the operating system kernel is represented as / proc / dyn_isolcpus for example, and when a user wants to update the isolated configuration of the CPU, the user can input a new isolated CPU range by calling the preset interface.
[0061] The current input isolated CPU identifier is referred to as a first CPU identifier herein. Assuming that there are 16 CPUs, CPU0-CPU15, in the operating system, the first CPU identifier can be CPU0-CPU9 for example, indicating that the current CPUs to be isolated are CPU0-CPU9.
[0062] Assuming that the current CPUs to be isolated are CPU0-CPU9, the user can input:
[0063] echo "0-9" > / proc / dyn_isolcpus.
[0064] If CPU 7 and CPU8 are to be left for use later, the user can re-input:
[0065] echo "0-6,9" > / proc / dyn_isolcpus.
[0066] If the isolation is to be cancelled, i.e., no CPU is isolated, the user can input:
[0067] echo > / proc / dyn_isolcpus.
[0068] That is, the user can dynamically input the corresponding CPU isolation configuration parameter in the preset interface as needed.
[0069] The configuration of the CPU identifier to be isolated to the preset interface triggers the operating system kernel to automatically perform the following operation steps to complete the processing corresponding to the current CPU isolation configuration operation. As can be seen, when the CPU isolation configuration needs to be updated, the user only needs to perform a read-write operation on the preset interface once, and the operation and maintenance overhead is very low.
[0070] It is worth noting that the preset interface is registered in the operating system kernel, and the following steps are also performed by the operating system kernel, i.e., not in the user mode but in the kernel mode, and the performance overhead is low.
[0071] 202、The operating system kernel determines a first task of the user mode which has not performed CPU resource configuration in the tasks contained in the root node of the target control group, and the target control group corresponds to the CPU subsystem.
[0072] 203、the operating system kernel binds the first task with a second CPU identifier, the second CPU identifier being an identifier of a CPU that is not isolated, the second CPU identifier being determined by the first CPU identifier and all CPU identifiers recorded by the operating system kernel.
[0073] Suppose that there are N CPUs in the operating system, and the first CPU identifier corresponds to M CPUs that are isolated, then the second identifier corresponds to the remaining (N-M) CPUs. In the above example, the first CPU identifier corresponds to CPU0-CPU9, and the second CPU identifier corresponds to CPU10-CPU15.
[0074] On the basis that the user inputs the first CPU identifier through a preset interface, the task isolation purpose at this time is to identify the tasks in the current operating system that are not controlled by resources, and bind these tasks to the CPUs that are not isolated, that is, limit the CPU range that these tasks can use to the CPUs that are not isolated, so as to avoid interference with the tasks running on the isolated CPUs.
[0075] Based on this, on the one hand, optionally, the user can trigger a binding request according to the first CPU identifier, the binding request including the identifier of the second task and the first processor identifier, at this time, the operating system kernel binds the second task with a target CPU in the isolated CPU based on the binding request triggered by the user. Wherein, the second task is specified by the user. Wherein, the operating system kernel knows that the second task needs to be bound to the isolated CPU according to the first CPU identifier, and when the first CPU identifier corresponds to multiple CPUs, the operating system kernel can determine the target CPU for binding the second task according to methods such as load balancing.
[0076] On the other hand, the first tasks in the operating system that are not controlled by resources need to be identified and bound to the CPUs that are not isolated, that is, bound to the second CPU identifier.
[0077] Specifically, the object to be identified in the embodiment of the application is the first task in the user mode that is not controlled by resources, that is, not configured with processor resources, in the root node of the target control group (cgroup) corresponding to the CPU subsystem, simply put, it is the task under the CPU cgroup root node that has not been bound with the CPU, and does not include the kernel task.
[0078] Since the CPU resources are allocated in this paper, the traversal range of the first task is the root node of the target control group (cgroup) corresponding to the CPU subsystem, simply referred to as the CPU cgroup root node.
[0079] In the root node, there can be many tasks, both user mode tasks and kernel mode tasks. In this embodiment, the first task is only for user mode tasks, and kernel mode tasks are not considered.
[0080] The reason for not isolating kernel mode tasks (such as various kernel processes) here is very simple. Kernel mode tasks often have their own design, and if a problem occurs, it will have a great impact on the operating system, and may even cause a crash. In the static isolation case, there are also kernel mode tasks (such as kworker) bound to isolated CPUs. Therefore, for stability considerations, kernel mode tasks are excluded from the objects that need to be identified.
[0081] The specific identification process of the first task will be described below.
[0082] After identifying the first task, the CPU range bound to the first task is reconfigured to the unisolated CPUs corresponding to the second CPU identifier. In the above example, the CPU range bound to the first task is set to CPUs 10-15, so that the first task can only use CPUs 10-15 in the subsequent first task, and cannot run on the isolated CPUs 0-9.
[0083] It is worth noting that the first task is currently running on a certain CPU. If the current CPU is the isolated CPU corresponding to the first CPU identifier, the first task also needs to be migrated to the unisolated CPU corresponding to the second CPU identifier. For example, assuming that the first task is currently running on CPU 5, the first task needs to be migrated from CPU 5 to a CPU in CPUs 10-15. It can be any CPU in CPUs 10-15, or it can be determined which CPU to migrate to according to load balancing and other strategies.
[0084] In addition, it is also worth mentioning that there will be tasks constantly generated in the operating system, and the dynamic isolation of the CPU is performed by the operating system kernel, which can make the new CPU isolation configuration effective for the newly generated new tasks, and make the new CPU isolation configuration effective for the tasks already existing under the CPU cgroup root node, and there will be no missing tasks. Specifically, after the current user triggers a new CPU isolation configuration by inputting the first CPU identifier, if a new task is generated and the user does not perform the binding setting of which CPU the new task needs to be bound to, the newly generated task will be added to the CPU cgroup root node. In the process of traversing the first task under the root node by the operating system kernel, the traversal result will include the new task and other tasks that have existed in the root node before, so that the new CPU isolation configuration will be effective for all the first tasks traversed, that is, the first task will be bound to the unisolated CPU corresponding to the second CPU identifier.
[0085] Based on the current input of the user who needs to isolate the CPU corresponding to the first CPU identifier, in addition to completing the above-mentioned identification of the first task and the binding operation of the CPU (the CPU corresponding to the second CPU identifier) that can be used by the first task, the operating system kernel can also update the CPU identifier corresponding to the scheduling domain to the second CPU identifier, that is, the operating system kernel needs to rebuild the scheduling domain accordingly according to the current user's CPU isolation configuration operation, to indicate that the subsequent load balancing is only performed on the unisolated CPUs corresponding to the second CPU identifier.
[0086] In addition, as mentioned above, the first task traversed in the CPU cgroup root node in the embodiment of the application is a user mode task, which does not include a kernel mode task, which does not mean that the kernel mode task cannot be limited to work on the unisolated CPU. Only in the above-mentioned process of traversing the first task, the kernel mode task can not be considered, and special processing means can be used for the kernel mode task. Specifically, in the embodiment of the application, optionally, a special kernel mode task can be processed for the limitation of the CPU used:
[0087] The operating system kernel determines the unbound CPU kernel mode task, and binds the kernel mode task to the second CPU identifier.
[0088] In actual application, some kernel tasks can be bound to run on certain CPUs, such as being bound to isolated CPUs, and some kernel tasks can not be bound to CPUs, such as unbound kworker. For these kernel tasks (such as unbound kworker), the kernel tasks can be bound to unisolated CPUs corresponding to the second CPU identifier, so that the kernel tasks can only run on the unisolated CPUs, and interference on tasks running on the isolated CPUs can be avoided.
[0089] As can be seen, whenever a user needs to update the isolation configuration of the CPUs, the user can input new CPU identifiers that need to be isolated to a preset interface in the operating system kernel, and based on the user-inputted CPU identifiers that need to be isolated, the operating system kernel can automatically perform subsequent processing steps of CPU dynamic isolation: identifying a first task not under resource control, and isolating the first task to run on unisolated CPUs to achieve isolation of the running environment of the first task and other tasks running on the isolated CPUs. In the above execution process, the operating system does not need to be restarted, the processing result takes effect immediately, and the user operation is simple, and only one read-write operation of the preset interface needs to be performed.
[0090] The identification process of the first task not under resource control will be described below.
[0091] Figure 3 A flowchart of a first task identification method provided by an embodiment of the present application is shown in FIG. 3, which can include the following steps: Figure 3
[0092] 301. The operating system kernel can first filter at least one user task from tasks contained in the root node of the target control group according to the task types of the tasks stored.
[0093] 302. For a target user task in the at least one user task, if the CPU bound to the target user task corresponds to the third CPU identifier, the operating system kernel determines that the first task includes the target user task, wherein the third CPU identifier is the identifier of the CPU not isolated before the first CPU identifier is received.
[0094] The operating system kernel can maintain the task types of all tasks generated in the operating system, and based on this, the operating system kernel can traverse all user tasks existing under the root node of the CPU cgroup as the at least one user task.
[0095] Next, for any one of the at least one user mode task, referred to as a target user mode task, it is necessary to determine whether the target user mode task is a target of a current user triggered CPU isolation configuration, wherein the current user triggered CPU isolation configuration is triggered by the user inputting a first CPU identifier via a preset interface, i.e., the first CPU identifier corresponding CPU needs to be isolated at present.
[0096] In general, if the target user mode task is currently bound to a CPU range of all CPUs that are not isolated at present, the target user mode task will be included in the first task.
[0097] The "all CPUs that are not isolated at present" are the CPUs corresponding to the third CPU identifier, i.e., the CPUs that are not isolated according to the currently effective CPU isolation configuration.
[0098] When the user inputs a CPU isolation configuration x at T1 (i.e., inputs a CPU identifier that needs to be isolated via a preset interface), the CPU isolation configuration x will take effect only after the operating system kernel executes the above steps 201-203. When the user re-enters a CPU isolation configuration y at T2, the CPU isolation configuration x is currently in effect, and the "all CPUs that are not isolated at present" are the CPUs corresponding to the CPU isolation configuration x, i.e., the CPUs that are not isolated according to the CPU isolation configuration x.
[0099] As can be seen, assuming that the CPU identifier that needs to be isolated input by the current user is a first CPU identifier, the last configuration information input by the user is used in the process of completing the CPU isolation corresponding to the first CPU identifier: the CPU identifier that is not isolated at the last configuration, referred to as a third CPU identifier. If the CPU identifier currently bound to the target user mode task is the third CPU identifier, the target user mode task will be included in the first task.
[0100] For ease of understanding, the following examples are given in conjunction with Figure 4 Assuming that the operating system includes 16 CPUs CPU0-CPU15, and initially, the user has not input any parameters to the above preset interface, i.e., the user has not triggered the CPU isolation configuration, at this time, the operating system kernel iterates the user mode tasks whose bound CPU range is CPU0-CPU15 in the CPU cgroup root node, and these iterated user mode tasks are the first task, and the operating system kernel limits the bound CPU range of these first tasks to CPU0-CPU15 (because there is no CPU that needs to be isolated at this time, so all CPUs are not isolated CPUs).
[0101] Subsequently, as Figure 4As shown in the figure, at time T1, the user executed a CPU isolation configuration in the preset interface, entering the CPU identifiers of CPUs 0 to 9 to be isolated. The operating system kernel then isolated CPUs 0 to 9 and traversed the CPU cgroup root node to find user-mode tasks bound to CPUs 0 to 15: tasks a1 to am. The reason for traversing to find the user-mode tasks bound to CPUs 0 to 15 as the first task is that, before the CPU isolation configuration was implemented, the non-isolated CPUs constrained by the already-effective CPU isolation configuration were CPUs 0 to 15. The operating system kernel then bound the first task to CPUs 10 to 15, making the new CPU isolation configuration effective. This binding to CPUs 10 to 15 is because the current CPU isolation configuration specifies that CPUs 0 to 9 are isolated. Therefore, the first task, which is not subject to resource control, needs to be bound to the non-isolated CPUs 10 to 15.
[0102] Afterwards, if Figure 4 As shown in the figure, at time T2, the user executed another CPU isolation configuration in the preset interface, and entered the CPU identifiers to be isolated as CPU0 to CPU6. At this time, the operating system kernel isolates CPU0 to CPU6 and traverses the CPUcgroup root node to find user-mode tasks with a bound CPU range of CPU10 to CPU15: task b1 to task bk. The reason why the user-mode task with a bound CPU range of CPU10 to CPU15 is traversed as the first task is that before this CPU isolation configuration, the non-isolated CPUs constrained by the effective CPU isolation configuration were CPU10 to CPU15. Afterwards, the operating system kernel binds the traversed first task to CPU7 to CPU15 to make this CPU isolation configuration effective.
[0103] Based on the above example, if a user-mode task d is initially configured by the user to be bound to CPUs 10 to 15 , then during the execution of the CPU isolation configuration input at time T2 , the first task may also include the user-mode task d.
[0104] The following describes in detail the task isolation device of one or more embodiments of the present invention. Those skilled in the art will appreciate that these devices can be configured using commercially available hardware components through the steps taught in this solution.
[0105] Figure 5 The structure diagram of a task isolation device provided by an embodiment of the present invention is located in the operating system kernel. Figure 5As shown, the apparatus comprises a receiving module 11, a determining module 12, and a binding module 13.
[0106] The receiving module 11 is configured to receive a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, and the first processor identifier being an identifier of an isolated processor.
[0107] The determining module 12 is configured to determine, from tasks contained in a root node of a target control group, a first task in a user mode which has not been configured with a processor resource, the target control group corresponding to a processor subsystem.
[0108] The binding module 13 is configured to bind the first task with a second processor identifier, the second processor identifier being an identifier of a non-isolated processor, and the second processor identifier being determined according to the first processor identifier and all processor identifiers recorded by the operating system kernel.
[0109] Optionally, the apparatus further comprises a migration module configured to, if it is determined that the first task is currently running on the isolated processor, migrate the first task to the non-isolated processor.
[0110] Optionally, the binding module 13 is further configured to receive a binding request triggered by a user, the binding request comprising an identifier of a second task and the first processor identifier, and bind the second task with a target processor in the isolated processor according to the first processor identifier.
[0111] Optionally, the determining module 12 is specifically configured to filter at least one user mode task from the tasks contained in the root node of the target control group according to task types of the tasks which have been stored, and determine that the first task comprises a target user mode task in the at least one user mode task if a processor bound by the target user mode task corresponds to a third processor identifier, the third processor identifier being an identifier of a non-isolated processor before the first processor identifier is received.
[0112] Optionally, the apparatus further comprises a scheduling domain updating module configured to update a processor identifier corresponding to a scheduling domain to the second processor identifier.
[0113] Optionally, the binding module 13 is further configured to determine a kernel mode task of an unbound processor, and bind the kernel mode task with the second processor identifier.
[0114] Figure 5The device shown can execute the task isolation method provided in the aforementioned embodiments. For detailed execution process and technical effects, please refer to the description in the aforementioned embodiments and will not be repeated here.
[0115] Figure 6 A schematic diagram of the structure of an operating system provided by an embodiment of the present invention is shown in FIG. Figure 6 As shown, the operating system includes multiple processors ( Figure 6 CPU0 to CPU15 shown in the figure), operating system kernel, wherein a preset interface is registered in the operating system kernel. The operating system kernel is used to:
[0116] receiving a first processor identifier input by a user through a preset interface, where the first processor identifier is an identifier of the isolated processor;
[0117] Determining a first task in a user state that has not undergone processor resource configuration among tasks included in a root node of a target control group corresponding to a processor subsystem;
[0118] The first task is bound to a second processor identifier, where the second processor identifier is an identifier of a non-isolated processor and is determined by the first processor identifier and all processor identifiers recorded by the operating system kernel.
[0119] The detailed execution process and technical effects of the operating system kernel are described in the aforementioned embodiments and will not be repeated here.
[0120] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention is shown in FIG. Figure 7 As shown, the electronic device may include: a memory, multiple processors, and an operating system kernel. The memory stores executable code, and when the executable code is executed by the operating system kernel, the operating system kernel can at least implement the task isolation method provided in the aforementioned embodiment.
[0121] In addition, an embodiment of the present invention provides a non-temporary machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the task isolation method provided in the aforementioned embodiment.
[0122] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Those skilled in the art can understand and implement the present invention without inventive effort.
[0123] Through the description of the above embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by means of the necessary general hardware platform, and of course can also be implemented by means of the combination of hardware and software. Based on such understanding, the above technical solutions can be embodied in the form of computer products, and the present application can be in the form of computer program products implemented on one or more computer usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer usable program codes.
[0124] Finally, it should be noted that: the above examples are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A task isolation method, applied to an operating system kernel, comprising: receiving a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, and updating a processor isolation configuration by performing a read and write operation on the preset interface, the first processor identifier being an identifier of the isolated processor; Determining a first task in a user state that has not undergone processor resource configuration among tasks included in a root node of a target control group corresponding to a processor subsystem; Identify kernel-mode tasks that are not bound to a processor; Binding both the first task and the kernel-mode task to a second processor identifier, where the second processor identifier is an identifier of a non-isolated processor, and the second processor identifier is determined by the first processor identifier and all processor identifiers recorded by the operating system kernel; The processor identifier corresponding to the scheduling domain is updated to the second processor identifier.
2. The method according to claim 1, further comprising: If it is determined that the first task is currently running on the isolated processor, the first task is migrated to the non-isolated processor.
3. The method according to claim 1, further comprising: receiving a binding request triggered by a user, wherein the binding request includes an identifier of the second task and an identifier of the first processor; Bind the second task to a target processor in the isolated processors according to the first processor identifier.
4. The method according to claim 1, wherein The step of determining, from among the tasks included in the root node of the target control group, a first task in a user state in which processor resource configuration has not been performed, includes: Filtering out at least one user-mode task from the tasks included in the root node of the target control group according to the task types of the stored tasks; For the target user-state task in the at least one user-state task, if the processor bound to the target user-state task corresponds to the third processor identifier, it is determined that the first task includes the target user-state task; wherein, the third processor identifier is the identifier of the processor that has not been isolated before receiving the first processor identifier.
5. A task isolation operation device located in an operating system kernel, the device comprising: a receiving module, configured to receive a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, and update the processor isolation configuration by performing a read and write operation on the preset interface, the first processor identifier being an identifier of the isolated processor; a determination module, configured to determine a first task in a user state that has not been subjected to processor resource configuration among tasks included in a root node of a target control group, the target control group corresponding to the processor subsystem; Identify kernel-mode tasks that are not bound to a processor; a binding module, configured to bind both the first task and the kernel-mode task to a second processor identifier, where the second processor identifier is an identifier of a non-isolated processor, and the second processor identifier is determined by the first processor identifier and all processor identifiers recorded by the operating system kernel; The scheduling domain updating module is configured to update the processor identifier corresponding to the scheduling domain to the second processor identifier.
6. An operating system comprising: Multiple processors and an operating system kernel, wherein a preset interface is registered in the operating system kernel, and the operating system kernel is used to: receiving a first processor identifier input by a user through a preset interface, the preset interface being pre-registered in the operating system kernel, and updating a processor isolation configuration by performing a read and write operation on the preset interface, the first processor identifier being an identifier of the isolated processor; Determining a first task in a user state that has not undergone processor resource configuration among tasks included in a root node of a target control group corresponding to a processor subsystem; Identify kernel-mode tasks that are not bound to a processor; Binding both the first task and the kernel-mode task to a second processor identifier, where the second processor identifier is an identifier of a non-isolated processor, and the second processor identifier is determined by the first processor identifier and all processor identifiers recorded by the operating system kernel; The processor identifier corresponding to the scheduling domain is updated to the second processor identifier.
7. An electronic device comprising: A memory, multiple processors, and an operating system kernel; wherein, the memory stores executable code, and when the executable code is executed by the operating system kernel, the operating system kernel executes the task isolation method according to any one of claims 1 to 4.
8. A non-transitory machine-readable storage medium having executable code stored thereon, which, when executed by an operating system kernel of an electronic device, causes the operating system kernel to execute the task isolation method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
CPU isolation method and device and storage medium
CN110928601A