Process scheduling method and device of linux kernel and electronic equipment

By capturing thread/process wake-up events in Linux system, determining dependencies and creating dependency graphs, the priority of dependent threads/processes is improved, and the problem of extended response time when CFS scheduling strategy deals with dependency threads/processes is solved, and faster thread/process response is achieved.

CN119806760APending Publication Date: 2025-04-11SEAWAY TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411599747.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-11
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In Linux systems, when CFS scheduling policies deal with threads or processes with dependencies, they may lead to extended response time and cannot meet scenarios where there are higher requirements for response time.

Method used

By capturing thread/process wake-up events, determining dependencies and creating thread/process dependency graphs, finding the target thread/process targets that are dependent thread/processes, and increasing their priorities to optimize the scheduler.

Benefits of technology

It effectively solves the problem of slow response of threads or processes caused by resource dependencies, and improves the response speed of threads/processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806760A_ABST
    Figure CN119806760A_ABST
Patent Text Reader

Abstract

The invention provides a process scheduling method and device for a linux kernel and electronic equipment, and the method comprises the steps: determining a dependent thread / process and a depended thread / process, recording a thread / process dependency relationship between the dependent thread / process and the depended thread / process, creating a thread / process dependency graph according to the thread / process dependency relationship, and scheduling the thread / process dependency graph according to the thread / process dependency relationship. And according to a thread / process dependency relationship of the thread / process dependency graph, searching a target depended thread / process of the target thread / process, improving a thread / process priority of the target depended thread / process, and completing scheduler optimization. Therefore, the target depended thread / process blocking the target thread / process is searched based on the thread / process dependency graph, the priority of the target depended thread / process is improved, the problem of slow thread / process response caused by the resource dependency relationship can be fundamentally solved, and the thread / process response speed is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of operating systems, and in particular to a process scheduling method, device and electronic device for a Linux kernel. Background Art

[0002] As a medium between applications and hardware resources, the operating system has the important responsibilities of managing hardware resources, providing an operating environment for applications, and ensuring the security and stability of the system. On the operating system, multiple applications can be run simultaneously, and the threads or processes of these applications often have different priorities and real-time requirements. Taking the Linux system as an example, its built-in scheduler is responsible for managing and allocating CPU resources. Through reasonable scheduling strategies, it ensures that the threads and processes of each application can obtain the required CPU time fairly and efficiently, thereby meeting different priorities and real-time requirements.

[0003] In Linux systems, CFS (Completely Fair Scheduler) is a common scheduling strategy. The CFS scheduler maintains a "virtual running time" value for each thread or process, which is calculated based on the weighted sum of the actual running time and the waiting time of the thread or process, and is sorted using a red-black tree. CFS ensures the fairness of threads or processes by introducing weighted waiting time to prevent some threads or processes from occupying CPU resources for a long time and causing starvation of other threads or processes. However, when dealing with threads or threads with dependencies, such as threads in a thread pool waiting for shared resources or processes communicating through pipes, some threads may not respond in time due to differences in the running order and execution time of multiple threads or processes. In this case, the CFS scheduling policy may not meet scenarios with higher requirements for response time.

[0004] In the related art, the real-time response problem of the CFS scheduling strategy when dealing with threads or processes with resource dependencies can be solved. Although the response speed can be improved to a certain extent by changing the scheduling strategy of the threads or processes, it is often accompanied by the limitations of overall system performance degradation or uneven resource allocation. Therefore, this method cannot fundamentally solve the problem of slow thread or process response caused by resource dependencies. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a Linux kernel process scheduling method, device and electronic device to solve the problem of slow thread or process response caused by resource dependency. The specific technical solution is as follows:

[0006] In a first aspect of an embodiment of the present application, a process scheduling method of a Linux kernel is first provided, the method comprising:

[0007] When a thread / process wake-up event is captured, determining a dependent thread / process and a dependent thread / process, and recording a thread / process dependency relationship between the dependent thread / process and the dependent thread / process;

[0008] Creating a thread / process dependency graph based on the thread / process dependency relationship, wherein the thread / process dependency graph is used to record the thread / process dependency relationship;

[0009] When the target thread / process is awakened, searching for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship of the thread / process dependency graph;

[0010] The thread / process priority of the target dependent thread / process is increased to complete scheduler optimization.

[0011] In an optional implementation, creating a thread / process dependency graph according to the thread / process dependency relationship includes:

[0012] Obtaining a thread / process identifier, wherein the thread / process identifier includes a dependent thread / process identifier and a dependent thread / process identifier;

[0013] Creating a dependent thread / process linked list according to the thread / process dependency and the thread / process identifier;

[0014] The thread / process dependency relationship includes resource sharing or communication relationship between threads or processes in the thread pool;

[0015] A node is created in the thread / process dependency graph, and the dependent thread / process identifier and the dependent thread / process linked list are stored in the node.

[0016] In an optional embodiment, the method further comprises:

[0017] Obtaining the dependent thread / process identifier and the dependent thread / process linked list stored in the node;

[0018] The dependent thread / process identifier is hashed to obtain a hash value, and the hash value is used as a key and the dependent thread / process linked list is stored as a value in a hash cache structure.

[0019] In an optional implementation, searching for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship in the thread / process dependency graph includes:

[0020] Obtaining a dependent thread / process identifier of the target thread / process, performing hash processing on the dependent thread / process identifier of the target thread / process to obtain a target hash value;

[0021] Searching for a hash value matching the target hash value in a hash cache structure, and searching for a dependent thread / process linked list corresponding to the matching hash value;

[0022] According to the dependent thread / process linked list corresponding to the matching hash value, the target dependent thread / process of the target thread / process is searched.

[0023] In an optional implementation, the step of increasing the thread / process priority of the target dependent thread / process to complete scheduler optimization includes:

[0024] When the battery power of the device is higher than a preset threshold and / or the device is not in energy-saving mode, the thread / process priority of the dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing scheduler optimization;

[0025] In the case where the application corresponding to the target dependent thread / process is a specific application, the thread / process priority of the target dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing the scheduler optimization.

[0026] In an optional implementation, the step of increasing the thread / process priority of the target dependent thread / process so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process includes:

[0027] The first level value of the target dependent thread / process is modified to complete the priority improvement.

[0028] In an optional embodiment, the method further comprises:

[0029] After the scheduler optimization is completed, the priority of the target dependent thread / process is restored to its original state.

[0030] In an optional implementation, restoring the priority of the target dependent thread / process to an original state includes:

[0031] The first level value of the target dependent thread / process is modified to an initial level value, so that the priority of the target dependent thread / process is restored to its original state.

[0032] In a second aspect of the embodiment of the present application, a process scheduling device of a Linux kernel is also provided, the device comprising:

[0033] A capture module, when capturing a thread / process wake-up event, determines a dependent thread / process and a dependent thread / process, and records a thread / process dependency relationship between the dependent thread / process and the dependent thread / process;

[0034] A creation module is used to create a thread / process dependency graph according to the thread / process dependency relationship, wherein the thread / process dependency graph is used to record the thread / process dependency relationship;

[0035] A search module, when a target thread / process is awakened, searches for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship of the thread / process dependency graph;

[0036] The promotion module promotes the thread / process priority of the target dependent thread / process to complete the scheduler optimization.

[0037] In a third aspect of an embodiment of the present invention, there is further provided an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0038] Memory, used to store computer programs;

[0039] The processor is used to implement the steps of the process scheduling method of the Linux kernel described in any one of the first aspects above when executing the program stored in the memory.

[0040] In a fourth aspect of an embodiment of the present invention, a storage medium is further provided, wherein instructions are stored in the storage medium, and when the storage medium is run on a computer, the computer executes the steps of the process scheduling method of the Linux kernel described in any one of the above-mentioned first aspects.

[0041] In a fifth aspect of the embodiments of the present invention, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute any of the Linux kernel process scheduling methods described in the first aspect above.

[0042] The above technical solution provided by the embodiment of the present application, when a thread / process wake-up event is captured, determines the dependent thread / process and the dependent thread / process, and records the thread / process dependency relationship between the dependent thread / process and the dependent thread / process, creates a thread / process dependency graph based on the thread / process dependency relationship, and the thread / process dependency graph is used to record the thread / process dependency relationship, and when the target thread / process is awakened, finds the target dependent thread / process of the target thread / process based on the thread / process dependency relationship of the thread / process dependency graph, improves the thread / process priority of the target dependent thread / process, and completes the scheduler optimization. In this way, based on finding the target dependent thread / process that hinders the target thread / process based on the thread / process dependency graph, and improving the thread / process priority of the target dependent thread / process, the problem of slow thread / process response caused by resource dependency can be fundamentally solved, and the thread / process response speed can be accelerated. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0045] Figure 1 A schematic diagram of an implementation flow of a process scheduling method for a Linux kernel provided in an embodiment of the present application;

[0046] Figure 2 A schematic diagram of an implementation flow of another Linux kernel process scheduling method provided in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of an implementation flow of searching for a target dependent thread / process of a target thread / process provided in an embodiment of the present application;

[0048] Figure 4 A schematic diagram of an implementation flow of improving the thread / process priority of a target dependent thread / process to complete scheduler optimization provided in an embodiment of the present application;

[0049] Figure 5 A schematic diagram of the structure of a process scheduling device for a Linux kernel provided in an embodiment of the present application;

[0050] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0052] To facilitate understanding of the embodiments of the present application, further explanation will be given below with reference to specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present application.

[0053] like Figure 1 As shown, it is a schematic diagram of an implementation flow of a process scheduling method of a Linux kernel provided in an embodiment of the present application. The method may specifically include the following steps:

[0054] S101, when a thread / process wake-up event is captured, determining a dependent thread / process and a dependent thread / process, and recording a thread / process dependency relationship between the dependent thread / process and the dependent thread / process.

[0055] In an embodiment of the present application, when a thread / process wake-up event is captured, the dependent thread / process and the dependent thread / process are determined, and the thread / process dependency between the dependent thread / process and the dependent thread / process is recorded. A hook mechanism can be used to call a function to capture the wake-up event. The thread / process dependency can be a resource sharing or communication relationship between threads or processes in a thread pool, which is not limited to the present application example.

[0056] For example, in the Linux kernel, the sched_wakeup and try_to_wake_up functions can be called through the hook mechanism. When capturing the wake-up event A, thread / process A and thread / process B have a resource sharing or communication relationship. Thread / process A needs to rely on thread / process B when running. Then thread / process A depends on thread / process B, that is, thread / process A is the dependent thread / process, and thread / process B is the dependent thread / process B. The thread / process dependency relationship between thread / process A and thread / process B is recorded.

[0057] S102: Create a thread / process dependency graph based on the thread / process dependency relationship, where the thread / process dependency graph is used to record the thread / process dependency relationship.

[0058] In an embodiment of the present application, a thread / process dependency graph is created based on the thread / process dependency relationship between the dependent thread / process and the dependent thread / process, and the thread / process dependency relationship is stored in the thread / process dependency graph.

[0059] For example, when a thread / process wake-up event is captured, thread / process A and thread / process B have a resource sharing or communication relationship, and thread / process A depends on thread / process B. Then thread / process A is the dependent thread / process, and thread / process B is the dependent thread / process B. The thread / process dependency relationship between the dependent thread / process A and the dependent thread / process B is recorded, and the dependency relationship between threads / processes A and B is stored in the thread / process dependency graph.

[0060] S103, when the target thread / process is awakened, the target dependent thread / process of the target thread / process is searched according to the thread / process dependency relationship in the thread / process dependency graph.

[0061] In an embodiment of the present application, when a target thread / process is awakened, the target dependent thread / process of the target thread / process is searched according to the thread / process dependency relationship of the thread / process dependency graph.

[0062] For example, the target thread / process A is awakened, and the target dependent thread / process B of the target thread / process A is found according to the thread / process dependency relationship in the thread / process dependency graph.

[0063] S104, raising the thread / process priority of the target dependent thread / process to complete scheduler optimization.

[0064] In the embodiment of the present application, the thread / process priority of the target dependent thread / process is increased to complete the scheduler optimization.

[0065] For example, the target dependent thread / process A's target dependent thread / process is thread / process B, and the priority of thread / process B is increased to complete the scheduler optimization.

[0066] Through the above description of the technical solution provided by the embodiment of the present application, when a thread / process wake-up event is captured, the dependent thread / process and the dependent thread / process are determined, and the thread / process dependency relationship between the dependent thread / process and the dependent thread / process is recorded. According to the thread / process dependency relationship, a thread / process dependency graph is created. The thread / process dependency graph is used to record the thread / process dependency relationship. When the target thread / process is awakened, according to the thread / process dependency relationship of the thread / process dependency graph, the target dependent thread / process of the target thread / process is found, and the thread / process priority of the target dependent thread / process is increased to complete the scheduler optimization. In this way, based on the thread / process dependency graph, the target dependent thread / process that hinders the target thread / process is found, and the thread / process priority of the target dependent thread / process is increased, the problem of slow thread / process response caused by resource dependency can be fundamentally solved, and the thread / process response speed can be accelerated.

[0067] like Figure 2 As shown, it is a schematic diagram of the implementation flow of another Linux kernel process scheduling method provided in an embodiment of the present application, which may specifically include the following contents:

[0068] S201, when a thread / process wake-up event is captured, determining a dependent thread / process and a dependent thread / process, and recording a thread / process dependency relationship between the dependent thread / process and the dependent thread / process.

[0069] In the embodiment of the present application, this step is similar to the above-mentioned step S101, and the embodiment of the present application will not be described one by one here.

[0070] S202, obtaining a thread / process ID, where the thread / process ID includes a dependent thread / process ID and a dependent thread / process ID.

[0071] In an embodiment of the present application, a thread / process identifier is obtained, and the thread / process identifier includes a dependent thread / process identifier and a dependent thread / process identifier, wherein the thread / process identifier can be a thread / process id (Identity, abbreviated as: unique code), which is not limited in the present application example.

[0072] For example, obtain the thread / process identification (thread / process id), including the dependent thread / process id and the dependent thread / process id.

[0073] S203: Create a dependent thread / process linked list according to the thread / process dependency relationship and the thread / process identifier.

[0074] In an embodiment of the present application, a dependent thread / process linked list is created based on thread / process dependencies and thread / process identifiers.

[0075] For example, the thread / process dependency relationship is that thread / process A depends on thread / process B, thread / process A is the dependent thread / process, thread / process B is the dependent thread / process, the dependent id of thread / process A is id1, and the dependent id of thread / process B is id2. A dependent thread / process linked list is created based on thread / process A's dependency on thread / process B and thread / process ids (id1, id2).

[0076] S204, creating a node in the thread / process dependency graph, and storing a dependent thread / process identifier and a dependent thread / process linked list in the node.

[0077] In an embodiment of the present application, a node is created in a thread / process dependency graph, and a dependent thread / process identifier and a dependent thread / process linked list are stored in the node.

[0078] For example, dependent thread / process identifier A corresponds to dependent thread / process linked list A, and dependent thread / process identifier B corresponds to dependent thread / process linked list B. Two nodes (node ​​1, node 2) are created in the thread / process dependency graph. Node 1 stores dependent thread / process identifier A and dependent thread / process linked list A, and node 2 stores dependent thread / process identifier B and dependent thread / process linked list B.

[0079] In addition, a hash cache structure is designed to facilitate the search for dependencies, which can specifically include the following steps:

[0080] Get the dependent thread / process ID and dependent thread / process linked list stored in the node.

[0081] Specifically, node information (dependent thread / process identifier and dependent thread / process linked list) in a thread / process dependency graph is obtained, where each node in the thread / process dependency graph includes a dependent thread / process identifier and a dependent thread / process linked list.

[0082] For example, in the thread / process dependency graph, one node is (depending on thread / process identifier id1, depending on thread / process linked list 1), and another node is (depending on thread / process identifier id2, depending on thread / process linked list 2).

[0083] The dependent thread / process ID is hashed to obtain a hash value, and the hash value is used as a key and the dependent thread / process linked list is used as a value to store in a hash cache structure.

[0084] Specifically, the dependent thread / process identifiers in the obtained thread / process dependency graph are hashed, the dependent thread / process identifiers can be converted into hash values ​​through the Jenkins Hash algorithm, the hash value is used as the key of the hash cache structure, and the dependent thread / process linked list corresponding to the dependent thread / process identifier is stored as the value in the hash cache structure. In addition, a hash linked list can be set to handle hash conflicts, which is not limited to this example in the present application.

[0085] For example, the dependent threads / processes in the thread / process dependency graph are identified as id1 and id2, which correspond to linked lists 1 and linked lists 2 of the dependent thread / process linked lists respectively. Hash processing is performed on id1 and id2 to obtain hash values ​​1 and hash value 2. Hash values ​​1 and hash value 2 are used as keys, and linked lists 1 and linked lists 2 are stored as values ​​in the hash cache structure.

[0086] S205, when the target thread / process is awakened, searching for the target dependent thread / process of the target thread / process according to the thread / process dependency relationship in the thread / process dependency graph.

[0087] In an embodiment of the present application, the target thread / process is awakened, and the target dependent thread / process of the target thread / process is searched according to the thread / process dependency relationship of the thread / process dependency graph.

[0088] For example, wake up the target thread / process A, and find the target dependent thread / process B of the target thread / process A according to the thread / process dependency relationship in the thread / process dependency graph.

[0089] Specifically, when the target thread / process is awakened, the target dependent thread / process of the target thread / process is found according to the thread / process dependency relationship of the thread / process dependency graph, such as Figure 3 As shown, it is a schematic diagram of an implementation flow of searching for a target dependent thread / process of a target thread / process provided by an embodiment of the present application, which may specifically include the following steps:

[0090] S301, obtaining a dependent thread / process identifier of a target thread / process, performing hash processing on the dependent thread / process identifier of the target thread / process, and obtaining a target hash value.

[0091] In an embodiment of the present application, a dependent thread / process identifier of a target thread / process is obtained, and a hash process is performed on the dependent thread / process identifier of the target thread / process to obtain a target hash value.

[0092] For example, the dependent thread / process identifier id1 of the target thread / process A is obtained, and the dependent thread / process identifier of the target thread / process is hashed, that is, id1 is hashed to obtain a target hash value 1.

[0093] S302, searching for a hash value matching the target hash value in the hash cache structure, and searching for a dependent thread / process linked list corresponding to the matching hash value.

[0094] In the embodiment of the present application, in the hash cache structure, the hash value corresponds to the dependent thread / process linked list. Therefore, by finding a hash value that matches the target hash value, the corresponding dependent thread / process linked list can be determined.

[0095] For example, a hash value 2 matching the target hash value 1 is searched in the hash cache structure, and dependent thread / process linked list 2 is found according to hash value 2.

[0096] S303, searching for the target dependent thread / process of the target thread / process according to the dependent thread / process linked list corresponding to the matching hash value.

[0097] In an embodiment of the present application, the target dependent thread / process of the target thread / process is searched according to the dependent thread / process linked list corresponding to the matching hash value.

[0098] For example, the matching hash value 1 corresponds to the dependent thread / process linked list 1, and the target dependent thread / process B is searched according to the dependent thread / process linked list 1.

[0099] S206, raising the thread / process priority of the target dependent thread / process to complete scheduler optimization.

[0100] In the embodiment of the present application, the thread / process priority of the target dependent thread / process is increased to complete the scheduler optimization.

[0101] For example, if the target dependent thread / process is B, the priority of B is increased to complete the scheduler optimization.

[0102] Specifically, the thread / process priority of the target dependent thread / process is increased to complete the scheduler optimization, such as Figure 4 As shown, it is a schematic diagram of an implementation process of improving the thread / process priority of the target dependent thread / process to complete scheduler optimization provided by an embodiment of the present application, which may specifically include the following steps:

[0103] S401, when the battery power of the device is higher than a preset threshold and / or the device is not in energy-saving mode, increase the thread / process priority of the dependent thread / process so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing scheduler optimization.

[0104] In an embodiment of the present application, when the battery power of the device is higher than a preset threshold and / or the device is not in energy-saving mode, the priority adjustment operation can be reduced or suspended to avoid excessive battery consumption due to frequent priority adjustments.

[0105] For example, when the battery power of the device is higher than a preset threshold and / or the device is not in energy-saving mode, the dependent threads / processes A, B, and C need to have their priorities adjusted. However, in order to solve the problem of rapid battery consumption due to frequent priority adjustments, the priority adjustments can be reduced. You can choose to adjust only the priority of dependent thread / process A, or not adjust the priorities of dependent thread / process A, dependent thread / process B, and dependent thread / process C.

[0106] Specifically, the thread / process priority of the dependent thread / process is improved so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, and the scheduler optimization is completed. The priority improvement can be completed by modifying the first level value of the target dependent thread / process.

[0107] Among them, the first level value can be a nice value, which is not limited in this application example.

[0108] By modifying the nice value of the target dependent thread / process, the scheduler is scheduled according to the nice value to complete scheduler optimization. For example, if the nice value of the dependent thread / process is 10 and the nice value of the target thread / process is 1, the nice value of the dependent thread / process is modified to 1, so that the priority of the dependent thread / process matches the priority of the target thread / process, the priority is increased, and the scheduler optimization is completed.

[0109] In addition, after the scheduler optimization is completed, the priority of the target dependent thread / process is restored to the original state.

[0110] Specifically, the first level value of the target dependent thread / process (the first level value of the target dependent thread / process that has been modified through priority enhancement) is modified to the initial level value (the first level value of the dependent thread / process that has not been modified through priority enhancement), so that the priority of the target dependent thread / process is restored to its original state.

[0111] For example, if the first level value of the target dependent thread / process is 10 (initial level value), when performing scheduler optimization, the first level value of the target dependent thread / process is modified to 1. After completing the scheduler optimization, the first level value of the target dependent thread / process is modified to the initial level value, that is, the first level value of the target dependent thread / process is modified from 1 to 10, so that the priority of the target dependent thread / process is restored to its original state.

[0112] S402, when the application corresponding to the target dependent thread / process is a specific application, the thread / process priority of the target dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing the scheduler optimization.

[0113] In the embodiment of the present application, the specific application can be a program that shares resources or communicates between threads or processes in a thread pool. When the application corresponding to the target dependent thread / process is a specific application, the thread / process priority of the target dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing the scheduler optimization.

[0114] For example, there is resource sharing or communication between threads or processes between program 1 and program 2, but there is no resource sharing or communication between threads or processes between program 3. Then the dependent threads / processes corresponding to program 1 and program 2 can be given priority improvement strategy, while the dependent threads / processes of program 3 are not given priority improvement strategy.

[0115] Specifically, the thread / process priority of the dependent thread / process is improved so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, and the scheduler optimization is completed. The priority improvement can be completed by modifying the first level value of the target dependent thread / process.

[0116] Among them, the first level value can be a nice value, which is not limited in this application example.

[0117] By modifying the nice value of the target dependent thread / process, the scheduler is scheduled according to the nice value to complete scheduler optimization. For example, if the nice value of the dependent thread / process is 10 and the nice value of the target thread / process is 1, the nice value of the dependent thread / process is modified to 1, so that the priority of the dependent thread / process matches the priority of the target thread / process, the priority is increased, and the scheduler optimization is completed.

[0118] In addition, after the scheduler optimization is completed, the priority of the target dependent thread / process is restored to the original state.

[0119] Specifically, the first level value of the target dependent thread / process (the first level value of the target dependent thread / process that has been modified through priority enhancement) is modified to the initial level value (the first level value of the dependent thread / process that has not been modified through priority enhancement), so that the priority of the target dependent thread / process is restored to its original state.

[0120] For example, if the first level value of the target dependent thread / process is 10 (initial level value), when performing scheduler optimization, the first level value of the target dependent thread / process is modified to 1. After completing the scheduler optimization, the first level value of the target dependent thread / process is modified to the initial level value, that is, the first level value of the target dependent thread / process is modified from 1 to 10, so that the priority of the target dependent thread / process is restored to its original state.

[0121] Corresponding to the above method embodiment, the present application embodiment also provides a process scheduling device of the Linux kernel, such as Figure 5 As shown, the apparatus may include a table group capturing module 501 , a creating module 502 , a searching module 503 , and a promoting module 504 .

[0122] The capturing module 501 determines the dependent thread / process and the dependent thread / process when capturing the thread / process wake-up event, and records the thread / process dependency relationship between the dependent thread / process and the dependent thread / process;

[0123] A creation module 502 is used to create a thread / process dependency graph according to the thread / process dependency relationship, where the thread / process dependency graph is used to record the thread / process dependency relationship;

[0124] A search module 503 searches for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship of the thread / process dependency graph when the target thread / process is awakened;

[0125] The promotion module 504 promotes the thread / process priority of the target dependent thread / process to complete the scheduler optimization.

[0126] The embodiment of the present invention further provides an electronic device, such as Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.

[0127] Memory 603, used for storing computer programs;

[0128] In one embodiment of the present invention, the processor 601, when used to execute the program stored in the memory 603, implements the following steps:

[0129] When a thread / process wake-up event is captured, the dependent thread / process and the dependent thread / process are determined, and the thread / process dependency between the dependent thread / process and the dependent thread / process is recorded. Based on the thread / process dependency, a thread / process dependency graph is created. The thread / process dependency graph is used to record the thread / process dependency. When the target thread / process is awakened, the target dependent thread / process of the target thread / process is found based on the thread / process dependency of the thread / process dependency graph, and the thread / process priority of the target dependent thread / process is increased to complete the scheduler optimization.

[0130] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0131] The communication interface is used for communication between the above electronic device and other devices.

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

[0133] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0134] In another embodiment of the present invention, a storage medium is provided, in which instructions are stored. When the storage medium is run on a computer, the computer executes the process scheduling method of the Linux kernel described in any of the above embodiments.

[0135] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the process scheduling method of the Linux kernel described in any one of the above embodiments.

[0136] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium, or transmitted from one storage medium to another storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0137] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0138] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0139] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A process scheduling method for a Linux kernel, characterized in that: The method comprises: When a thread / process wake-up event is captured, determining a dependent thread / process and a dependent thread / process, and recording a thread / process dependency relationship between the dependent thread / process and the dependent thread / process; Creating a thread / process dependency graph based on the thread / process dependency relationship, wherein the thread / process dependency graph is used to record the thread / process dependency relationship; When the target thread / process is awakened, searching for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship of the thread / process dependency graph; The thread / process priority of the target dependent thread / process is increased to complete scheduler optimization.

2. The method according to claim 1, characterized in that: The step of creating a thread / process dependency graph according to the thread / process dependency relationship includes: Obtaining a thread / process identifier, wherein the thread / process identifier includes a dependent thread / process identifier and a dependent thread / process identifier; Creating a dependent thread / process linked list according to the thread / process dependency and the thread / process identifier; A node is created in the thread / process dependency graph, and the dependent thread / process identifier and the dependent thread / process linked list are stored in the node.

3. The method according to claim 2, characterized in that The method further comprises: Obtaining the dependent thread / process identifier and the dependent thread / process linked list stored in the node; The dependent thread / process identifier is hashed to obtain a hash value, and the hash value is used as a key and the dependent thread / process linked list is stored as a value in a hash cache structure.

4. The method according to claim 3, characterized in that The step of searching, according to the thread / process dependency relationship in the thread / process dependency graph, a target dependent thread / process of the target thread / process comprises: Obtaining a dependent thread / process identifier of the target thread / process, performing hash processing on the dependent thread / process identifier of the target thread / process to obtain a target hash value; Searching for a hash value matching the target hash value in a hash cache structure, and searching for a dependent thread / process linked list corresponding to the matching hash value; According to the dependent thread / process linked list corresponding to the matching hash value, the target dependent thread / process of the target thread / process is searched.

5. The method according to claim 1, characterized in that The step of improving the thread / process priority of the target dependent thread / process and completing scheduler optimization includes: When the battery power of the device is higher than a preset threshold and / or the device is not in energy-saving mode, the thread / process priority of the dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing scheduler optimization; In the case where the application corresponding to the target dependent thread / process is a specific application, the thread / process priority of the target dependent thread / process is increased so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process, thereby completing scheduler optimization.

6. The method according to claim 5, characterized in that The step of increasing the thread / process priority of the target dependent thread / process so that the thread / process priority of the target dependent thread / process matches the priority of the target thread / process includes: The first level value of the target dependent thread / process is modified to improve the priority.

7. The method according to claim 5, characterized in that The method further comprises: After the scheduler optimization is completed, the priority of the target dependent thread / process is restored to its original state.

8. The method according to claim 7, characterized in that The step of restoring the priority of the target dependent thread / process to an original state includes: The first level value of the target dependent thread / process is modified to an initial level value, so that the priority of the target dependent thread / process is restored to its original state.

9. A process scheduling device for a Linux kernel, characterized in that: include: A capture module, when capturing a thread / process wake-up event, determines a dependent thread / process and a dependent thread / process, and records a thread / process dependency relationship between the dependent thread / process and the dependent thread / process; A creation module is used to create a thread / process dependency graph according to the thread / process dependency relationship, wherein the thread / process dependency graph is used to record the thread / process dependency relationship; A search module, when a target thread / process is awakened, searches for a target dependent thread / process of the target thread / process according to the thread / process dependency relationship of the thread / process dependency graph; The promotion module promotes the thread / process priority of the target dependent thread / process to complete the scheduler optimization.

10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 8 when executing a program stored in a memory.