Detailed Description
In order to clearly describe the technical solution of the embodiments of the present application, the following description is made with reference to the accompanying drawings.
In embodiments of the present application, the words "first," "second," and the like are used to distinguish between identical or similar items that have substantially the same function and effect. For example, the first instruction and the second instruction are for distinguishing different user instructions, and the sequence of the instructions is not limited. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
In the present application, the words "exemplary" or "such as" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "for example" should not be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete fashion.
"At least one" means one or more, and "a plurality" means two or more. "and/or" describes an association of associated objects, meaning that there may be three relationships, e.g., A and/or B, and that there may be A alone, while A and B are present, and B alone, where A, B may be singular or plural. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s).
Before describing the technical scheme in the embodiment of the application, an electronic device related to executing the application is first described.
The electronic device in embodiments of the present application may be one or more Virtual Machines (VMs) (e.g., hypervisors, virtual servers), network nodes (e.g., switches, virtual networks, routers, virtual routers), a single computing device (e.g., client terminals), a set of computing devices arranged in parallel, a server (including a network server, web server, storage server, local server, remote server), a client terminal, a mobile device, a fixed device, a public information machine, a smart phone, a laptop computer, a wearable computing device, a glasses computing device, a watch computing device, a desktop computer, and so forth.
The terminal device (also referred to as User Equipment (UE)) is a device with a wireless transceiving function, and may be deployed on land, including indoor or outdoor, handheld or vehicle-mounted, on water surface (such as a ship, etc.), or in air (such as an airplane, a balloon, a satellite, etc.). The terminal may be a mobile phone, a tablet (pad), a computer with wireless transceiving function, a Virtual Reality (VR) terminal, an augmented reality (augmented reality, AR) terminal, a wireless terminal in industrial control (industrial control), a wireless terminal in unmanned (SELF DRIVING), a wireless terminal in remote medical (remote medical), a wireless terminal in smart grid (SMART GRID), a wireless terminal in transportation security (transportation safety), a wireless terminal in smart city (SMART CITY), a wireless terminal in smart home (smart home), etc.
Referring to fig. 1, a schematic structural diagram of an example of an electronic device 100 according to an embodiment of the present application is shown. As shown in fig. 1, the electronic device 100 may include at least one processor 110 for implementing or for supporting the electronic device 100 to implement the task scheduling method provided by the embodiment of the present application.
The electronic device 100 may include at least one memory 120 for storing program instructions and/or data. Memory 120 is coupled to processor 110. The coupling in the embodiments of the present application is an indirect coupling or communication connection between devices, units, or modules, which may be in electrical, mechanical, or other forms for information interaction between the devices, units, or modules. The processor 110 may operate in conjunction with the memory 120. Processor 110 may execute program instructions stored in memory 120.
At least one of the at least one memory 120 may be included in the processor 110. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, the instruction or data can be directly called from the memory, repeated access is avoided, and the waiting time of the processor 110 is reduced, so that the processing efficiency of the processor 110 can be improved.
The electronic device 100 may also include a communication interface 130 for communicating with other devices over a transmission medium so that apparatus for use in the electronic device 100 may communicate with other devices. The processor 110 may transmit and receive data using the communication interface 130. As an example, the communication interface 130 may be a transceiver in particular.
The specific connection medium between the communication interface 130, the processor 110, and the memory 120 is not limited in the embodiment of the present application. In fig. 1, the memory 120, the processor 110, and the communication interface 130 are connected by a bus 140, which is indicated by a thick line in fig. 1, and the connection between other components is merely schematically illustrated, and is not limited thereto. The buses may be classified as address buses, data buses, control buses, etc. For ease of illustration, only one thick line is shown in fig. 1, but not only one bus or one type of bus.
The processor 110 may be a general purpose processor, a digital signal processor, an application specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and may implement or perform the methods, steps and logic blocks disclosed in embodiments of the application. The general purpose processor may be a microprocessor or any conventional processor or the like. The steps of a method disclosed in connection with the embodiments of the present application may be embodied directly in a hardware processor for execution, or in a combination of hardware and software modules in the processor for execution.
The memory 120 may be a nonvolatile memory such as a hard disk (HARD DISK DRIVE, HDD) or a solid state disk (solidstate drive, SSD), and may also be a volatile memory (RAM) such as a random-access memory (RAM). The memory is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory in embodiments of the present application may also be circuitry or any other device capable of performing memory functions for storing program instructions and/or data.
The communication interface 130 may include an integrated circuit (INTERINTEGRATED CIRCUIT, I2C) interface, an integrated circuit built-in audio (inter-INTEGRATED CIRCUITSOUND, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purposeinput/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
It should be understood that the interfaces illustrated in this embodiment are illustrative only and are not limiting on the structure of the electronic device 100. In addition, the interfacing manners of the different interfaces may be different, and in other embodiments, the electronic device 100 may use the interfacing manners of the different interfaces in the above embodiments, or a combination of the interfacing manners.
It is to be understood that the structure illustrated in the present embodiment does not constitute a specific limitation on the electronic apparatus 100. In other embodiments, electronic device 100 may include more or fewer components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
In one possible implementation, the processor 110 in the electronic device 100 as shown in fig. 1 may be understood as a physical processor chip, and the electronic device 100 may include at least one processor chip, where the processor 110 is taken as an example in fig. 1. A processor may comprise at least one processor core or at least one logical CPU, wherein a processor core may also be referred to as a physical CPU, and when the number of processors 110 in the electronic device 100 shown in fig. 1 is one, the processor 110 may be understood as comprising a plurality of physical CPUs or a plurality of logical CPUs.
Referring to FIG. 2, an exemplary architecture of a processor 110 is shown. As shown in fig. 2, the processor 110 includes two physical CPUs, or may be understood as two logical CPUs, which are labeled as CPU0 and CPU1 in fig. 2, respectively, and CPU0 and CPU1 may schedule individual processes or threads in parallel.
While the electronic device 100 according to the embodiment of the present application has been described above from a hardware perspective, in order to implement the task scheduling method according to the embodiment of the present application, cooperation of a software system is also required, and a software architecture of the electronic device according to the present application will be described below.
Referring to fig. 3, a schematic structural diagram of an example of a software architecture of the electronic device 100 according to an embodiment of the present application is shown. As shown in fig. 3, the electronic device 100 is logically divided into an application layer 310, a system layer 320, a kernel layer 330, and a hardware layer 340, which communicate with each other through a software interface.
The application layer 310 includes one or more application programs, which may be, for example, applications such as task management clients. As an example, a user may input a command line through a task management client to bind the tasks of two applications to run on the same processing unit, where the processing unit may refer to a processor, a physical CPU, or a logical CPU.
It should be noted that various applications may be system applications of the electronic device 100 or third party non-system applications, which are not limited herein. Among other things, a system application may be understood as an application that is developed and designed by the manufacturer of electronic device 100. Third party non-system applications may be understood as applications developed by other vendors and that may run in the system, such as gaming, fitness, learning, or social applications.
The system layer 320 is a computer program for managing and controlling hardware and software resources, including, for example, a runtime module that provides the executable with the required library files and execution environments at runtime. The runtime module includes a virtual machine that is responsible for scheduling and management of the system, a virtual machine or instance of a virtual machine that can convert the bytecode of an application into machine code, which can provide a separate operating environment for each application in the application layer 310.
Kernel layer 330 is used to provide underlying system components and services, such as memory management, process management, hardware drivers, etc., and is the layer between hardware and software. The hardware driver may include a display driver, a storage driver, a CPU driver, and the like.
Hardware layer 340 is the portion of the physical components of electronic device 100 that are responsible for performing computing, storage, communication, and input-output tasks, which may include processor 110, memory 120, and communication interface 130, as shown in fig. 1.
It should be noted that, as shown in fig. 3, the software architecture is described taking the operating system of the electronic device 100 as the Linux operating system as an example, however, other operating systems, such as an android (android) system, a honest operating system, or an IOS operating system, may be used for the electronic device 100, and in different operating systems, the software architecture may be changed, but as long as the functions implemented by the functional modules are similar to those of the functional modules in the embodiments of the present application, the task scheduling method provided by the embodiments of the present application may also be implemented, and therefore, the software architecture shown in the embodiments of the present application is only an example and should not be construed as limiting the software architecture.
As can be seen from the schematic structural diagram of the software architecture of the electronic device 100 shown in fig. 3, the process management module is an important functional module of the kernel layer 330 of the electronic device 100, and the process management module is described below.
In an operating system, a process is a basic unit of resource allocation and scheduling, and because an electronic device may include a plurality of processes, but because resources are limited, for example, computing resources of a CPU, storage resources of a memory, and the like, when the number of processes that can be run in the electronic device exceeds the maximum value of the number of processes that can be processed by the CPU, at a certain moment, some processes in the plurality of processes cannot be executed. In this case, the process management module may coordinate efficient and rational allocation of the resources of the electronic device among the processes, thereby maximizing the resource utilization of the electronic device.
In some examples, the process management module may be managed by a scheduler, which may be a real-time scheduler (RTS), a full-fair scheduler (completely fair scheduler, CFS), or an idle scheduler (idle scheduler), to name but a few.
Since the resources of the electronic device need to be allocated among multiple processes, there may be a case where two processes associated with each other are allocated different CPU resources, i.e., scheduled to run on different CPUs. As an example, the process a and the process B are two processes in a wake-up relationship, the process B is woken up after the process a is finished running, and the process a is scheduled on the CPU0 shown in fig. 2, and the process B is scheduled on the CPU1 shown in fig. 2.
Then, when the process a is completed and the process B is ready to be executed, since each CPU has its own cache, when switching to a new CPU, that is, CPU1, the cache data previously cached in the old CPU, that is, CPU0, may fail, resulting in a cache miss, so that CPU1 needs to access the memory to obtain the required data, and accessing the memory is slower than accessing the cache, it is seen that there is a large scheduling overhead when the processes that wake up each other are scheduled to be run by different CPUs.
In the related art, in order to solve the problem of high scheduling overhead caused by process switching, it is proposed to bind at least two processes with an association relationship (e.g., a wake-up relationship) to run in the same processing unit by means of manual identification.
However, the above manual identification method is relatively complex to operate, so how to provide a scheduling method with low operation complexity and capable of reducing the process switching overhead is a problem to be solved at present.
The embodiment of the application provides a task scheduling method, which comprises the steps of firstly determining whether a task to be selected and a current task which is running are in a mutual awakening relation or not, and whether awakening frequencies between the task to be selected and the current task meet a threshold value or not, and then determining a processing unit which runs the current task as a processing unit for scheduling the task to be selected under the condition that the task to be selected and the current task are in the mutual awakening relation and the awakening frequency meets the threshold value, wherein the task types of the task to be selected and the current task are processes or threads.
According to the technical scheme, whether the task to be selected is scheduled to run on the processing unit of the current task or not is determined by determining whether the task to be selected and the current task are in a mutual wakeup relationship and whether the wakeup frequency between the task to be selected and the current task meets a threshold value or not, that is, no operation is required by a user, and the electronic equipment can automatically determine whether the two tasks are bound to run on the same processing unit or not according to the scheme, so that the operation complexity can be reduced under the condition of reducing the task switching overhead.
The task scheduling method provided by the embodiment of the application is described below with reference to the accompanying drawings.
For easy understanding, an execution body of the task scheduling method according to the embodiment of the present application will be described.
In the embodiment of the present application, the execution body of the task scheduling method may be the electronic device shown in fig. 1, or may be a part of the apparatus in the electronic device shown in fig. 1, for example, may be the processor 110 in the electronic device, or may be a physical CPU or a logical CPU shown in fig. 2, or may be a process management module of the kernel layer 330 in the electronic device 100 shown in fig. 3, which is not limited herein.
In the following description, an execution subject of the task scheduling method will be described as an example of a process management module in the kernel layer 330. It should be noted that, the process management module may implement process management by invoking any of the schedulers described above, which is not limited herein.
Referring to fig. 4, a flowchart of an example of a task scheduling method according to an embodiment of the present application is shown. As shown in fig. 4, the flow includes the steps of:
S401, determining whether a task to be selected and a current task which is running are in a mutual awakening relation, and whether awakening frequencies between the task to be selected and the current task meet a threshold value.
In the embodiment of the present application, the task may be a process as described above, or may be a thread (thread), which is not limited herein.
The step S401 includes two conditions, namely, a first condition that whether the task to be selected and the current task being operated are in a wake relationship with each other, and a second condition that whether the wake frequency between the task to be selected and the current task meets a threshold. The following describes the determination modes of these two conditions, respectively.
In the embodiment of the present application, the execution order of the first condition and the second condition is not limited, and the first condition may be executed first, the second condition may be executed first, the first condition may be executed, or the first condition and the second condition may be executed simultaneously. For convenience of explanation, hereinafter, the first condition is performed before the second condition is performed.
For the first condition, whether the task to be selected and the current task running are in a mutual wake-up relationship.
In the embodiment of the present application, the first condition may be determined by, but not limited to, the following determination methods:
the first determination mode is as follows:
And determining whether the current task and the task to be selected are in a mutual awakening relation according to whether the current task and the task to be selected have an affinity relation, first task information of the task awakened by the current task and second task information of the task awakened by the task to be selected.
For example, when the current task and the task to be selected have the affinity relationship, and the first task information includes information of the task to be selected, and the second task information includes information of the current task, determining that the current task and the task to be selected are in the inter-wake relationship, and if the current task and the task to be selected do not have the affinity relationship, or the first task information does not include information of the task to be selected, or the second task information does not include information of the current task, determining that the current task and the task to be selected do not have the inter-wake relationship.
As an example, the affinity relationship between the current task and the task to be selected may be determined according to a value of a target parameter in a kernel selection function, where the target parameter is used to indicate affinity between the current task and the task to be selected, and the current task and the task to be selected are determined to have the affinity relationship if the target parameter is not a preset value.
Specifically, the target parameter may be a want_affine variable in the kernel selection function, and the process management module calls the want_affine variable, and when the return value of the want_affine variable is a preset value, for example, 0, it indicates that the current task and the task to be selected have no affinity, and when the return value of the want_affine variable is not the preset value, it indicates that the current task and the task to be selected have an affinity. Whether the kernel function has an affinity relation is judged by selecting variables in the kernel function, the implementation mode is simple, and the complexity of the scheme can be reduced.
As another example, the affinity between the current task and the task of the core to be selected may also be determined based on the wake_width variable of the function of the core to be selected and the function cpumask _test_cpu (). The wake_wide variable is used for indicating the wake-up turnover times of the kernel function to be selected. If the return value of the function wake_wide is 0, the number of wake-up turnups of the task to be selected is smaller than or equal to the preset number, and if the return value of the function wake_wide is 1, the number of wake-up turnups of the task to be selected is larger than the preset number. The number of wake-up flips indicates how often a task wakes up other tasks when it is a waker, or may indicate how often a task wakes up by other tasks when it is a waker. If a task wakes up frequently or is waken up by other tasks, this means that the task may migrate between different CPUs, and function cpumask _test_cpu () is used to determine if the task to be selected is allowed to run on the current CPU. If the function returns a non-0, it may indicate that the task to be selected is allowed to execute on the current CPU, and if the function returns a 0, it may indicate that the task to be selected is not allowed to execute on the current CPU line.
If the return value of the wake_wide variable is 0 and the return value of the function cpumask _test_cpu () is not 0, it is determined that there is an affinity relationship between the current task and the task to be selected, and if the return value of the wake_wide variable is not 0 or the return value of the function cpumask _test_cpu () is 0, it is determined that there is no affinity relationship between the current task and the task to be selected.
The above examples of determining affinity relationships are for illustration only, and one skilled in the art may determine whether the current task and the task to be selected have affinity relationships in other ways, which are not limited herein.
After determining whether any of the current tasks and the task to be selected have an affinity relationship, the first task information of the task awakened by the current task and the second task information of the task awakened by the task to be selected can be obtained.
As a first example, the tasks included in the first task information and the second task information may be all the tasks that have been awakened, and may include a plurality of tasks, that is, the first task information includes information of a task to be selected, it may be understood that information of one of the plurality of tasks included in the first task information is information of a task to be selected, and information of one of the plurality of tasks included in the second task information is information of a current task.
As a second example, the tasks included in the first task information and the second task information may be the last-wake task, and the first task information and the second task information may each include only one task information, where the first task information includes information of a task to be selected, which may be understood as task information included in the first task information, that is, information of the task to be selected, and the second task information includes information of a current task, which may be understood as task information included in the second task information, that is, information of the current task.
In the technical scheme, only the information of the task awakened by each task is needed to be acquired, so that the acquired information is simpler, the operation complexity is low, and the task scheduling rate can be improved.
When the current task and the task to be selected have the affinity relationship, and the first task information comprises the information of the task to be selected, and the second task information comprises the information of the current task, the current task and the task to be selected can be determined to be in a mutual awakening relationship. If the current task and the task to be selected do not have an affinity relationship, or the first task does not include information of the task to be selected, or the second task does not include information of the current task, it can be determined that any current task and the task to be selected are not in a wake relationship with each other.
The first task information and the second task information may include an identifier of the awakened task, for example, a name of the task or an ID of the task.
In addition, in the above example, the description is given by taking the case that the affinity relationship between the current task and the task to be selected is acquired first, and then the first task information and the second task information are acquired, and in the actual use process, the affinity relationship between the current task and the task to be selected and the sequence of acquiring the first task information and the second task information are not limited, and the affinity relationship, the first task information and the second task information can be acquired at the same time, or the first task information and the second task information can be acquired, and then the affinity relationship is acquired.
If the affinity relationship, the first task information and the second task information are sequentially acquired according to the sequence, when the acquired first information does not meet the condition, other information can be acquired without further acquisition. For example, when the acquired first information is an affinity relationship, if the affinity relationship is that the current task and the task to be selected do not have an affinity relationship, the first task information and the second task information may not be acquired any more, which is not described herein.
The above is the first determination for the first condition.
The following describes a second way of determining for the first condition:
In the embodiment of the present application, before a task is executed, a core selection process needs to be started to determine a processing unit for scheduling the task for the task, where a core selection process can be understood as a function, such as a schedule () function, in the kernel layer 330 or a process management module, and when the schedule () function is called, the core selection process is started, and when the core selection process is executed, the processing unit for scheduling the task can be determined. The processing unit that scheduled the task is determined, which is also understood to be the processing unit that runs the task.
It should be noted that, as an example, the processing unit that schedules the task may be the aforementioned processor 110. For example, the electronic device 100 includes a plurality of processors 110, each including a physical CPU or a logical CPU, and the initiation of the core selection process may determine the processor from the plurality of processors that schedules the task.
As another example, the processing unit that schedules the task may also be a physical CPU. For example, processor 110 may include one or more physical CPUs, and the launch kernel flow may determine the physical CPU from among the plurality of physical CPUs that scheduled the task.
As another example, the processing unit that schedules the task may also be a logical CPU. For example, the processor 110 may include a plurality of logical CPUs, and the launch kernel selection process may determine a logical CPU from the plurality of logical CPUs that schedules the task.
In the embodiment of the application, the opportunity for starting the nuclear selection process is not limited. For example, the kernel selection process may be initiated when a process is awakened, or may be initiated when a new process is created by a fork function, or may be initiated when an executable file (execve) is executed, or may be initiated when load balancing is performed. Of course, the starting time of the core selection process may also include other cases, which are not illustrated herein.
In one example, the task to be selected may be determined by the process management module from an un-run task according to a preset scheduling policy before starting the selection process. For example, the process management module may use a real-time task that is not running as a task to be selected through the real-time scheduler, or select a task with the highest static priority as a task to be selected according to the static priority of each task in the non-running tasks. For another example, the process management module may select, by the full-fair scheduler, a task with a highest dynamic priority as a task to be selected according to the dynamic priority of each task in the tasks that are not running.
In another example, if the core selection process is started by some task preempting the CPU, the task preempting the CPU is the core task to be selected.
In another example, if the kernel selection process is started because the running task wakes up a task, the waken task is the task to be kernel selected.
It should be noted that, although the core selection process is started because the processing unit for scheduling the task needs to be determined for the core selection task, the manner of determining the core selection process may be varied, which is not limited herein.
After the core selection process is started, the first condition of step S401 is executed, and whether the task to be selected and the current task being run are in a wake-up relationship with each other is determined.
Referring to fig. 5, a flow chart of a second determination method of the first condition is shown. As shown in fig. 5, the second determination method includes the following steps:
s501, judging whether the kernel selecting flow is located in the context of the current task running by the CPU.
First, the context to which the present application relates will be explained.
Context is understood to be a collection of environments and states at the execution of a task, which may include various variables and data at the execution of the task, such as all register variables the task includes, the files the task opens, and stack and memory information at the execution of the task.
Taking a task as an example of a process, the context may include a process context. The process context can be understood as the value in all registers of the CPU, the state of the process and the content on the stack when one process is running, and when the process needs to be switched to another process, the kernel needs to save all the current states of the process, that is, save the process context of the current process, so that when the process is executed again, the state during switching can be recovered, and the execution can be continued.
It should be noted that, when the task is a thread, the thread context may also include a thread context, and the content included in the thread context is similar to that included in the thread context, which is not described herein again.
It can be understood that whether the core selection process is located in the context of the current task can be understood that the core selection process is executed when the current task is executed to the corresponding position of the context, that is to say, the core selection process is awakened, so that judging that the context of the current task is located can determine whether the current task can awaken the core selection task, and therefore, the task that the current task and the core selection task possibly belong to a mutual awakening relation is described to a certain extent.
The following describes how to determine the inclusion relationship between the initiated kernel selection flow and the context of the current task that the CPU is running.
From the foregoing, it will be appreciated that one or more CPUs may be included in electronic device 100, where the CPUs may be physical or logical. In the case where multiple CPUs are included in the electronic device 100, each CPU may have a current task running therein, the process management module may determine whether the kernel flow is in the context of the current task running in any of the multiple CPUs.
For example, the electronic device 100 includes a CPU0 and a CPU1, where the current task being executed in the CPU0 is a task a, the current task being executed in the CPU1 is a task B, and after the kernel selecting process is started, the process management module determines whether the kernel selecting process is in the context of the task a or whether the kernel selecting process is in the context of the task B, so as to determine whether the kernel selecting process is in the context of an executed task.
In an embodiment of the present application, the manner of determining the inclusion relationship between the kernel selection process and the context of the running current task may include, but is not limited to, the following two ways:
In the first containing relation judging mode, the containing relation between the kernel selecting flow and the context of the running current task is judged through the kernel function in_task ().
Taking the current task as a process and the context of the current task as a process context as an example, the process management module can judge whether the started kernel selection process is executed in the process context of the current process or whether the started kernel selection process is executed in the process context of the current process by calling the kernel function in_task (). For example, the kernel function in_task () is run, and if the return value of the kernel function in_task () is a preset value, for example, 1, the kernel selection flow can be considered to be in the process context of the current process.
And in a second inclusion relation judging mode, judging the inclusion relation between the kernel selecting flow and the context of the running current task through a kernel function in_irq ().
As an example, the process management module may determine whether the initiated kernel flow is executed in the process context of the current process or whether the initiated kernel flow is in the process context of the current process by calling the kernel function in_irq (). The kernel function in_irq () is a function in the kernel for detecting whether the current code is in the interrupt context. Interrupt context, it is understood that when a CPU receives an interrupt signal, which causes a process to interrupt operation, the parameters included in the interrupt signal and the set of circumstances and states when the process is interrupted.
If the return value of the kernel function in_irq () is a preset value, for example, false, then the kernel selection flow can be considered to be in the process context of the current process.
Of course, the process management module may determine whether the kernel selection process is located in the context of the running current task in other ways, which are not illustrated herein.
In the case that the core selection procedure is in the context of the current task, step S502 is executed.
S502, judging whether an affinity relationship exists between the current task and the task to be selected.
In step S502, the content of the affinity relationship between the current task and the task to be selected is similar to that of the first determination method, and will not be described herein.
In the case where it is determined that there is an affinity between the current task and the task to be selected, step S503 is performed.
S503, judging whether first task information of a task awakened by a current task comprises information of a task to be selected and whether second task information of the task awakened by the task to be selected comprises information of the current task.
In step S502, the content of the first task information and the second task information are similar to those of the first determination method, and are not described herein.
Step S504 is executed when the first task information includes information of the task to be selected and the second task information includes information of the current task, and step S505 is executed when the first task information does not include information of the task to be selected or the second task information includes information of the current task.
S504, determining the current task and the task to be selected as a mutual awakening relation.
S505, determining that the current task and the task to be selected are not in a mutual awakening relationship.
The above are examples of two methods for determining whether the current task and the task to be selected have a mutual wake-up relationship according to the embodiments of the present application, however, those skilled in the art may also determine whether the current task and the task to be selected have a mutual wake-up relationship by using other methods, which are not illustrated herein.
The first task information and the second task information may be acquired according to a structure of the corresponding task. Whether a thread or a process, it is an entity that is scheduled by the process management module, and an abstraction of the resources required by the entity is required, and in the kernel layer 330, the task structure task_struct may be used to describe the content. The task_struct includes a target member, where the target member is used to record information of a task that is awakened, or the target member is used to record information of a task that is awakened last time, and is labeled as last_ wakee, so that the first task information is determined according to information of the target member in a structure body of a current task, and the second task information is determined according to information of the target member in a structure body of a task to be selected.
For example, the identifier of the current task is A, the identifier of the task to be selected is B, the value of last_ wakee in task_struct of task A is obtained, whether the value is B is determined, if B is the last time the current task wakes up is task B, the value of last_ wakee in task_struct of task B is obtained, whether the value is A is determined, if A is the last time the current task wakes up is task A, and therefore the task A and the task B are determined to be in a mutual wake-up relationship. The last awakening task of each task is determined through the information in the structural body of each task, and the realization mode is simple and accurate.
The above description was made with respect to two determination modes of the first condition. The manner of determining the second condition is described below.
And aiming at a second condition, whether the wake-up frequency between the task to be selected and the current task meets a threshold value.
In the embodiment of the present application, the second condition may include, but is not limited to, the following three judgment modes:
According to the first judgment mode, whether the wake-up frequency between the current task and the task to be selected meets a threshold value is determined according to whether the wake-up frequency of one party in the current task and the task to be selected wakes up the other party in a history manner is larger than or equal to a first threshold value.
The wake-up times of one of the current task and the task to be selected for waking up the other party in a history manner can comprise wake-up times of the current task for waking up the task to be selected in a history manner and wake-up times of the task to be selected for waking up the current task in a history manner.
In this case, when it is determined that the number of times the history of the task to be selected wakes up the current task is greater than or equal to a first threshold, or when it is determined that the number of times the history of the task to be selected wakes up the task to be selected is greater than or equal to a first threshold, it is determined that a wake-up frequency between the task to be selected and the current task satisfies a threshold.
In the embodiment of the present application, the first threshold may be set by a technician according to an actual use process, which is not limited herein.
As an example, the number of wakeups may be obtained by taking statistics of the values of the target members in the task structure task_struct for recording the information of the wakened tasks.
For example, the identifier of the current task is A, the identifier of the task to be selected is B, the value of the target member in the task_struct of the task A is B, C, B, D, B, so that the wake-up times of the current task, in which the task to be selected is awakened in a history manner, can be obtained to be 3 times, and if the first threshold is 2, it can be determined that the wake-up frequency between the current task and the task to be selected meets the threshold.
As another example, a new member may be added to the task structure task_struct, and the awakened task and the awakening times of the awakened tasks may be recorded by the new member, in which case, the awakening times may be obtained directly through the value of the new member.
For example, the identifier of the current task is A, the identifier of the task to be selected is B, the values of the new members in the task_struct of the task A are obtained to be B,3, C,1, D,1, so that the wake-up times of the current task, in which the task to be selected is awakened in a history manner, can be obtained to be 3 times, and if the first threshold is 2, the wake-up frequency between the current task and the task to be selected can be determined to meet the threshold.
The above is similar to the foregoing in the manner of determining whether the number of wake-up times of the current task history to wake up the task to be selected is greater than or equal to the first threshold, and details are not repeated herein.
And determining that the wake-up frequency between the current task and the task to be selected meets a threshold according to the wake-up times of one task and the other task in the current task and the task to be selected.
In this case, in the case where it is determined that the number of times the task history of the core to be selected wakes up the current task is greater than or equal to the number of times the current task is waken up by other task histories, or in the case where it is determined that the number of times the task history of the current task wakes up the task to be selected is greater than or equal to the number of times the task history of the core to be selected wakes up by other task histories, it is determined that the wake-up frequency between the task to be selected and the current task satisfies a threshold.
In the embodiment of the present application, the number of wake-up times of the current task when the current task is awakened by other task history may be obtained by obtaining a target member for recording information of the awakened task in the task structure task_struct of the other task, or may be obtained by obtaining a new member for recording the awakened task and the number of wake-up times of each awakened task in the task structure task_struct of the other task, where the specific process is similar to the corresponding content in the first case, and will not be repeated herein.
As an example, the other tasks may be understood as all tasks that run during a historical period of time, which may be a period of time prior to the current time, or may be a fixed period of time, without limitation in embodiments of the present application. In this case, the process management module needs to acquire information of each task that is awakened in the history of all tasks running in the history period, and determine whether the information of the other tasks that are awakened in the history of the tasks includes information of the current task or information of the task to be selected.
For example, if the process management module determines that 10 other tasks are running in the history period, the process management module obtains the wake-up times of the current task or the task to be selected through task structures task_struct of the 10 other tasks respectively.
According to the above example, under the condition that whether the wake-up times of the to-be-selected core task historic wake-up current task is larger than or equal to the wake-up times of the current task by other task historic wake-up is determined, the wake-up times of the to-be-selected core task historic wake-up current task are respectively compared with the wake-up times of the 10 other task historic wake-up current tasks, and if the wake-up times of the to-be-selected core task historic wake-up current task are larger than or equal to the wake-up times of each other task historic wake-up current task, the wake-up times of the to-be-selected core task historic wake-up current task are larger than or equal to the wake-up times of the current task by other task historic wake-up times are determined.
Of course, for convenience of comparison, the maximum value of the wake-up times of the current task of the 10 other task histories can be obtained first, the wake-up times of the current task of the task history to be selected is compared with the maximum value, and if the wake-up times of the current task of the task history to be selected is greater than or equal to the maximum value, the wake-up times of the current task of the task history to be selected is greater than or equal to the wake-up times of the current task to be selected by other task histories.
The manner of determining whether the wake-up times of the current task history to wake up the task to be selected is greater than or equal to the wake-up times of the task to be selected to wake up by other task histories is similar to the above, and will not be described herein.
In addition, it should be noted that, since other tasks in the history period are not all awakened by the current task or the task to be selected, if the process of determining the awakening times of the other tasks in the history period after the current task or the task to be selected is performed for each other task, more computing resources are occupied, therefore, after the other tasks in the history period are acquired, the affinity relationship between each other task and the current task or the task to be selected can be determined first, and if the two tasks do not have the affinity relationship, the two tasks may not be awakened by each other.
As an example, taking the above example as an edge, in the case of determining whether the number of times the to-be-selected-core task historic wakes up the current task is greater than or equal to the number of times the current task is waken up by other task historic wakens, the process management module determines that 10 other tasks are running in the history time period, first determines whether there is an affinity relationship between the 10 other tasks and the current task, for example, 5 of the 10 other tasks have affinity relationships with the current task, then the process management module obtains the number of times the 5 other tasks historic wakens up the current task, and compares the number of times the to-be-selected-core task historic wakens up the current task with the number of times the 5 other tasks historic wakens up the current task, respectively, and if the number of times the to-be-selected-core task historic wakens up the current task is greater than or equal to the number of times the each other tasks waken up the current task historic wakens up the current task, then determines that the number of times the to-be-selected-core task historic waken up the current task is greater than or equal to the number of times the current task is waken up by other historic wakens.
In addition, it should be noted that, in the foregoing determination process, when it is determined that the number of times the task history to wake up the current task is greater than or equal to the number of times the current task is wake up by other task histories, or when it is determined that the number of times the task history to wake up the task is greater than or equal to the number of times the task history to wake up the task, it is determined that the wake up frequency between the task history and the current task meets the threshold, that is, only one of the two conditions needs to be met to determine that the wake up frequency between the task history and the current task meets the threshold.
In other embodiments, it may be determined that the wake frequency between the task to be selected and the current task meets a threshold, that is, when it is determined that the wake frequency of the task to be selected for waking up the current task is greater than or equal to the wake frequency of the current task for waking up by other task histories, and when it is determined that the wake frequency of the task to be selected for waking up the current task history is greater than or equal to the wake frequency of the task to be selected for waking up by other task histories, it is determined that the wake frequency between the task to be selected for waking up and the current task meets a threshold, so that accuracy of determining whether different tasks are inter-wake relationships can be further improved.
According to the third judging mode, determining that the awakening frequency between the current task and the task to be selected meets a threshold value according to whether the awakening frequency of one of the current task and the task to be selected in the other mode is larger than or equal to a first threshold value.
It may be understood that, when it is determined that the number of times the task history to wake up the current task is greater than or equal to the first threshold, and the number of times the task history to wake up the current task is greater than or equal to the number of times the current task is wake up by other task histories, it is determined that the wake-up frequency between the current task and the task history to wake up meets the threshold.
Or determining that the wake-up frequency between the task to be selected and the current task meets a threshold value under the condition that the wake-up frequency of the task to be selected, which is obtained by the current task history, is greater than or equal to a first threshold value, and the wake-up frequency of the task to be selected, which is obtained by the current task history, is greater than or equal to the wake-up frequency of the task to be selected, which is obtained by the other task histories.
It can be understood that the third judgment mode is a combination of the first judgment mode and the second judgment mode, and the specific implementation mode can refer to the corresponding content in the two judgment modes, which is not described herein.
The above description is made with respect to three judgment modes of the second condition.
S402, determining a processing unit running the current task as a processing unit for scheduling the task to be selected under the condition that the task to be selected and the current task are in the mutual wakeup relationship and the wakeup frequency meets the threshold value.
After the judgment results of the two conditions in step S401 are obtained, a processing unit for scheduling the task to be selected is determined according to the judgment result of each condition.
And under the condition that the task to be selected and the current task are in the mutual awakening relation and the awakening frequency meets the threshold value, determining a processing unit running the current task as a processing unit for scheduling the task to be selected.
And determining other processing units in the plurality of processing units as processing units for scheduling the task to be selected, wherein the other processing units are processing units except the current processing unit in the plurality of processing units under the condition that the task to be selected and the current task are not in the mutual wakeup relation or the wakeup frequency does not meet the threshold value. In fig. 4, the task to be selected and the current task are taken as the mutual wake relationship, and the wake frequency satisfies the threshold value as an example.
According to the technical scheme, whether the task to be selected is scheduled to run on the processing unit of the current task or not is determined by determining whether the task to be selected and the current task are in a mutual wakeup relationship and whether the wakeup frequency between the task to be selected and the current task meets a threshold value or not, that is, no operation is required by a user, and the electronic equipment can automatically determine whether the two tasks are bound to run on the same processing unit or not according to the scheme, so that the operation complexity can be reduced under the condition of reducing the task switching overhead.
Further, whether the task to be selected and the current task are in a mutual awakening relation or not and whether the awakening frequency between the task to be selected and the current task meets a threshold value or not are determined as conditions for determining whether the two tasks are bound to the same processing unit to run or not, so that the accuracy of the binding operation for binding different tasks to the same processing unit to run can be improved.
It should be noted that, as shown in the foregoing description of the task, the task types of the current task and the task to be checked may be threads or processes, so in this embodiment of the present application, the task types of the current task and the task to be checked may be the same, that is, if the current task is a process, the task to be checked is also a process, if the current task is a thread, the task types of the current task and the task to be checked are also threads, and may be different, for example, the current task is a process, the task to be checked may be a thread, for example, a process may include only one thread, and if the task to be checked is a process including only one thread, it may also be understood that the task to be checked is a thread, or if the current task is a process, the task to be checked may be a process, which is not limited herein.
In the embodiment shown in fig. 4, a flow of how to determine the processing unit to schedule the task to be selected is described. To further improve the efficiency of task execution, another example of a task scheduling method is provided below.
Referring to fig. 6, a flowchart of another example of a task scheduling method according to an embodiment of the present application is shown. As shown in fig. 6, the method includes the steps of:
S601, determining whether a task to be selected and a current task which is running are in a mutual awakening relation, and whether awakening frequencies between the task to be selected and the current task meet a threshold value.
Step S601 is similar to step S401, and will not be described again.
S602, judging whether the length of a running queue of a processing unit running the current task is smaller than or equal to a length threshold value under the condition that the task to be selected and the current task are in the mutual wake-up relation and the wake-up frequency meets the threshold value.
As an example, if the relationship between the current task and the task to be selected is the inter-wake relationship, the length of the running queue of the processing unit running the current task may be obtained, and the processing unit for scheduling the task to be selected may be determined according to the size relationship between the length of the running queue of the processing unit running the current task and the length threshold. By increasing the condition of judging the length of the running queue of the processing unit running the current task, the efficiency of task execution can be improved.
The length threshold can be set according to actual use requirements, for example, can be set to be 1, so that the current task and the task to be processed can monopolize the current processing unit, the processing efficiency of the current task and the task to be selected can be improved, data to be transmitted between the two tasks can be processed faster, and the communication performance of the current task and the task to be selected can be improved.
Of course, the length threshold may be set to other values, for example, may be 2 or 3, or may be a maximum value of the tasks that can be supported by the processing unit running the current task, which is not limited herein.
If the length of the running queue of the processing unit running the current task is less than or equal to the length threshold, that is, if the determination result of step S602 is yes, step S603 is executed, and if the length of the running queue of the processing unit running the current task is greater than the length threshold, that is, if the determination result of step S602 is no, step S604 is executed.
S603, determining a processing unit running the current task as a processing unit for scheduling the task to be selected.
And if the length of the running queue of the processing unit running the current task is smaller than or equal to the length threshold value, determining the processing unit running the current task as the processing unit for scheduling the task to be checked, so that the task to be checked is added into the running queue of the processing unit running the current task.
S604, determining the processing unit of which the history is scheduled to be the processing unit for scheduling the task to be selected.
If the length of the running queue of the processing unit running the current task is greater than the length threshold, the processing unit for scheduling the task to be selected can be determined from the processing units of which the task to be selected is scheduled historically. Therefore, if the number of the tasks running on the processing unit running the current task is large, the processing unit with the task to be selected can be used for running the task to be selected through historical dispatching, and the waiting time of the task to be selected can be reduced.
As an example, a processing unit that scheduled a task to be selected last time may be determined as a processing unit for scheduling the task to be selected. Of course, if the processing unit that scheduled the task to be selected last time is the current processing unit, the current processing unit is still determined to be the processing unit that scheduled the task to be selected.
As another example, the length of the run queue of the processing unit that schedules the task to be selected last time may be obtained, and if the length of the run queue of the processing unit that schedules the task to be selected last time is less than or equal to the length threshold, the processing unit that schedules the task to be selected last time is determined to be the processing unit for scheduling the task to be selected. The length threshold value for determining the length of the running queue of the processing unit running the current task and the length threshold value for determining the length of the running queue of the processing unit last scheduling the task to be selected may be the same or different, and are not limited herein. The processing efficiency of the task to be selected can be improved by selecting the processing unit with the length of the running queue smaller than the length threshold value from the processing units with the task to be selected which are historically scheduled.
As another example, if the processing units for which the core task to be selected is historically scheduled include a plurality of processing units, the scheduler may select a processing unit whose run queue length is less than or equal to a length threshold as the processing unit for which the core task to be selected is scheduled, or the scheduler may randomly select any one of the processing units for which the core task to be selected is scheduled, or may determine, according to the number of times that each processing unit has scheduled the core task to be selected, the processing unit with the largest number of times as the processing unit for which the core task to be selected is scheduled, or may determine the affinity between the core task to be selected and each processing unit, and determine the processing unit with the highest affinity as the processing unit for which the core task to be selected is scheduled.
As another example, if the number of wake times that the task to be selected is awakened by the other task history is determined in step S601, the processing unit that schedules the task to be selected may be determined according to the number of wake times that the task to be selected is awakened by the other task history. For example, in the case where the number of wake-ups of the task to be selected by other task histories is greater than the preset number, it may be determined that the processing unit running the current task is the processing unit that schedules the task to be selected.
Of course, it can also be determined in other ways, which are not examples here.
In the above technical solution, the processing unit for scheduling the task to be selected may be further determined by combining the length of the running queue of the processing unit, and if the number of the tasks running on the current processing unit is greater, the processing unit for scheduling the task to be selected may be used to run the task to be selected through history, so that the waiting time of the task to be selected may be reduced.
For further explanation, the effects achieved by the task scheduling method according to the embodiment of the present application are explained below with reference to fig. 7. For ease of illustration, a task is illustrated in FIG. 7 as a pipeline process. It should be noted that, the process in the embodiment of the present application is not limited to a pipeline process, but may be a socket process or other processes, which are not illustrated herein.
Referring to fig. 7, fig. 7 (a) is a process timing diagram of each CPU when scheduling processes that wake up each other on different CPUs in the related art. Taking a process A and a process B which are mutually awakened and the awakening frequency meets a threshold value as an example, the process A and the process B are communicated through a pipeline pipe1 and a pipeline pipe2, the process A is executed on a CPU0, then the process A writes a message to the process B through the pipeline pipe1 so as to awaken the process B, the process A enters dormancy, the CPU1 reads the message through the pipeline pipe1 and wakes the process B, the process B is executed on the CPU1, and then the message is written through the pipeline pipe2 so as to awaken the process A, and meanwhile the process B enters dormancy. Thus, the process is repeated in a cycle over a period of time.
Fig. 7 (b) is a process timing diagram of a CPU after a task scheduling method provided by an embodiment of the present application schedules processes that wake up each other and the wake-up frequency satisfies a threshold. Taking a process A and a process B which are mutually awakened and the awakening frequency meets a threshold value as an example, by adopting the task scheduling method in the embodiment of the application, the process A and the process B are scheduled to run on the same processing unit in the process of running the process A by the CPU0, when the process A is executed, a message is written to the process B through a pipeline pipe1 to awaken the process B, the CPU0 reads the message from the pipeline pipe1 to awaken the process B, and after the process B is executed, the message is written to wake the process A through the pipeline pipe2, so that the process is repeatedly performed.
After the task scheduling method provided by the embodiment of the application is adopted, processes which are mutually awakened and the awakening frequency meets the threshold value are scheduled to run in the same processing unit, so that the cross-core scheduling overhead is avoided, and the cache hit rate is higher. In the related art, when the CPU0 and the CPU1 are on different processing unit nodes, the cross-core scheduling overhead which can be reduced by adopting the task scheduling method provided by the application is more obvious.
The scheme provided by the embodiment of the application is mainly described from the perspective of the electronic equipment. It will be appreciated that in order to achieve the above-described functionality, the electronic device may comprise corresponding hardware structures and/or software modules that perform the respective functionality. Those of skill in the art will readily appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is implemented as hardware or computer software driven hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The functional modules in the embodiments of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module. The integrated modules may be implemented in hardware or in software functional modules.
The integrated modules, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the embodiments of the present application may be essentially or a part contributing to the prior art or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in the embodiments of the present application. The storage medium may be a variety of media such as a memory that can store program codes.
The embodiment of the application further provides a computer readable storage medium, wherein the computer readable storage medium stores computer instructions, and when the computer instructions run on electronic equipment, the electronic equipment is caused to execute the task scheduling method.
Any combination of one or more computer readable media may be utilized as the above-described computer readable storage media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read Only Memory (ROM), an erasable programmable read only memory (erasable programmable read only memory, EPROM) or flash memory, an optical fiber, a portable compact disc read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, radio Frequency (RF), etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for the present specification may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a local area network (local area network, LAN) or a wide area network (wide area network, WAN), or may be connected to an external computer (e.g., through the internet using an internet service provider).
Embodiments of the present application also provide a computer program product which, when run on a computer, causes the computer to perform some or all of the steps of the method embodiments described above.
The embodiment of the application provides a chip system, which comprises a processor and can also comprise a memory, wherein the memory is used for realizing the functions of the electronic equipment in the method. The chip system may be formed of a chip or may include a chip and other discrete devices.
It will be appreciated by those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional modules is illustrated, and in practical application, the above-described functional allocation may be performed by different functional modules according to needs, i.e. the internal structure of the apparatus is divided into different functional modules to perform all or part of the functions described above.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of modules or units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another apparatus, or some features may be omitted or not performed. Alternatively, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and the parts shown as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed in a plurality of different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application. Therefore, the protection scope of the application is subject to the protection scope of the claims.