Task processing method and device, electronic equipment and readable storage medium
By dividing the processor into lightweight kernels and basic kernels in cloud platform systems and supercomputing systems, task allocation is optimized, and performance issues caused by task scheduling and processor interrupts are resolved, resulting in more efficient task processing and performance improvement.
Patent Information
- Application Number
- CN202411177243.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2026-03-03
AI Technical Summary
In existing cloud platform systems and supercomputing systems, frequent task scheduling and processor interruptions lead to computing power loss and overall performance degradation of computing nodes.
By dividing the processor into lightweight cores and basic cores, configuring them to handle different types of tasks respectively, and allocating tasks to the high-priority third processor or the low-priority fourth processor according to priority and quantity, the number of task scheduling and processor interrupts is reduced.
It reduces processor computing power loss, improves task processing efficiency and overall performance, reduces the number of devices required, and lowers procurement and operation and maintenance costs.
Smart Images

Figure CN121597386A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a task processing method, apparatus, electronic device, and readable storage medium. Background Technology
[0002] With the continuous development of technology, the computing power provided by a single server system can no longer meet the needs of some big data operation scenarios, such as star simulation, weather forecasting, and resource partitioning. To solve this problem, computer systems have evolved from the original single server system to cloud platform systems and supercomputing (supercomputing) systems.
[0003] Currently, these cloud platform systems and supercomputing systems utilize existing parallel software technologies (such as Slurm) to break down massive tasks into multiple smaller tasks, which run on each computing node. This not only meets the resource requirements of the tasks but also accelerates their completion time.
[0004] Then, in real-world applications, the operating system of the computing node (e.g., Linux parallel system) often has frequent task scheduling. Furthermore, when there are related tasks, processor interrupts are required for execution. The state checks and changes during each task scheduling process, the time spent on processor interrupts (Inter-Processor Interrupt, IPI) during processor interrupt execution, and the synchronization of resource status updates all cause a loss of computing power in the computing node, resulting in a decrease in the overall performance of the computing node. Summary of the Invention
[0005] This application provides a task processing method, apparatus, electronic device, and readable storage medium, which can solve the problems of processor power loss and significant reduction in overall computing node performance caused by frequent task scheduling and processor interrupt execution in related technologies.
[0006] To address the aforementioned problems, this application discloses a task processing method applied to an electronic device, the electronic device including a lightweight kernel, a basic kernel, a first processor, and a second processor; the method includes:
[0007] The first processor and the second processor are initialized and configured so that the first processor is configured to process the tasks of the lightweight kernel and the second processor is configured to process the tasks of the basic kernel.
[0008] From the n first processors, determine (n-1) third processors and 1 fourth processor; n is an integer greater than 1; the allocation priority of the third processors is higher than that of the fourth processor.
[0009] When the target application corresponding to the lightweight kernel is launched, the task corresponding to the target application is assigned to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0.
[0010] The third and fourth processors are run to execute the tasks corresponding to the target application.
[0011] On the other hand, embodiments of this application disclose a task processing device applied to an electronic device, the electronic device including a lightweight kernel, a basic kernel, a first processor, and a second processor; the device includes:
[0012] A configuration module is used to initialize and configure the first processor and the second processor, so as to configure the first processor to process the task of the lightweight kernel and the second processor to process the task of the basic kernel;
[0013] The first determining module is used to determine (n-1) third processors and 1 fourth processor from n first processors; n is an integer greater than 1; the allocation priority of the third processors is higher than the allocation priority of the fourth processor;
[0014] The first allocation module is configured to, when the target application corresponding to the lightweight kernel is started, allocate the task corresponding to the target application to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0.
[0015] An execution module is used to run the third processor and the fourth processor to execute the tasks corresponding to the target application.
[0016] In another aspect, embodiments of this application also disclose an electronic device, which includes a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface communicate with each other through the communication bus. The memory is used to store executable instructions, which cause the processor to execute the aforementioned task processing method.
[0017] This application also discloses a readable storage medium, which, when the instructions in the readable storage medium are executed by the processor of an electronic device, enables the electronic device to perform the aforementioned task processing method.
[0018] The embodiments of this application have the following advantages:
[0019] This application provides a task processing method. During task processing, an electronic device determines (n-1) third processors and 1 fourth processor from n first processors configured to process tasks with lightweight kernels. When assigning tasks corresponding to the target application to the third or fourth processor, each third processor is bound to one task, and the number of tasks bound to the fourth processor is greater than or equal to 0. During the execution of tasks bound to the third processor by the third processor, no task scheduling is required. The execution time of the tasks bound to the third processor is infinitely close to the total execution time of the task, reducing the number of task scheduling operations and thus reducing the processor's computing power loss caused by frequent task scheduling. Furthermore, during the operation of the third and fourth processors, the tasks bound to each third processor are executed in parallel. When tasks corresponding to the target application are interconnected, only the fourth processor needs to interrupt and execute tasks associated with the tasks executed by the third processor, without involving interrupt execution operations of the third processor. This reduces the number of processor interrupts, thereby reducing the processor's computing power loss caused by processor interrupt execution in the electronic device and improving the task processing efficiency and overall performance of the electronic device. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating the steps of an embodiment of a task processing method according to this application;
[0022] Figure 2 This is a structural block diagram of an electronic device according to this application;
[0023] Figure 3 This is a flowchart illustrating the steps of another embodiment of the task processing method of this application;
[0024] Figure 4 This is a flowchart illustrating the steps of another embodiment of the task processing method of this application;
[0025] Figure 5 This is a structural block diagram of a task processing device according to this application;
[0026] Figure 6 This is a structural block diagram of an electronic device for task processing according to this application. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0028] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and are not limited in number; for example, a first object can be one or more. Furthermore, the term "and / or" in the specification and claims is used to describe the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. In the embodiments of this application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0029] Method Implementation Examples
[0030] Reference Figure 1 The diagram illustrates a flowchart of an embodiment of a task processing method according to this application. The method may specifically include steps 101 to 104:
[0031] Step 101: Initialize the configuration of the first processor and the second processor, so that the first processor is configured to handle tasks of the lightweight kernel and the second processor is configured to handle tasks of the basic kernel.
[0032] Step 102: Determine (n-1) third processors and 1 fourth processor from n first processors; the allocation priority of the third processors is higher than that of the fourth processors.
[0033] Where n is an integer greater than 1.
[0034] Step 103: When the target application corresponding to the lightweight kernel is started, the task corresponding to the target application is assigned to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0.
[0035] Step 104: Run the third and fourth processors to execute the tasks corresponding to the target application.
[0036] The task processing method provided in this application can be applied to electronic devices, see below. Figure 2 The diagram illustrates a structural block diagram of an electronic device according to this application. The electronic device is equipped with an operating system, which includes a user mode and a kernel mode. The kernel mode includes a Lightweight Kernel (LWK) and a Fullweight Kernel (FWK). The electronic device includes a first processor and a second processor. In step 101, the electronic device initializes and configures the first processor and the second processor respectively, so that the first processor processes the tasks of the Lightweight Kernel and the second processor processes the tasks of the Fullweight Kernel. Further, in step 102, the electronic device determines a third processor and a fourth processor from the first processor, and in step 103, assigns the tasks corresponding to the target application to the third processor or the fourth processor. In step 104, the third processor and the fourth processor are run to execute the tasks corresponding to the target application.
[0037] The first processor, configured to handle tasks of the lightweight kernel, can run within the lightweight kernel, while the second processor, configured to handle tasks of the basic kernel, can run within the basic kernel. The lightweight kernel is used by the first processor to handle tasks corresponding to the target application running in user space; the basic kernel is used by the second processor to handle basic system services and tasks corresponding to other applications running in user space besides the target application.
[0038] It is understood that the first processor and the second processor are central processing units (CPUs) in electronic devices that provide computing and processing capabilities for the operating system kernel. The number of first processors is greater than 1, and the number of second processors is at least 1.
[0039] Specifically, the task corresponding to the target application has a preset flag. The electronic device can assign the task corresponding to the target application to the first processor running in the lightweight kernel for processing according to the preset flag, and assign the task without the preset flag to the second processor for processing.
[0040] In this application embodiment, the electronic device may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, cellular phones, cordless phones, personal digital assistants (PDAs), handheld devices, computing devices, in-vehicle devices, and wearable devices, as well as fixed terminals such as digital TVs and desktop computers. The operating system running on the electronic device may include, but is not limited to, Windows, Mac, Linux, Chrome OS, and UNIX operating systems.
[0041] Specifically, in step 101, the electronic device first initializes the first processor in the electronic device and loads various configurations related to the processor through the first processor; then, it initializes various kernel subsystems in the electronic device, such as the memory subsystem and device subsystem, etc. After the initialization of each kernel subsystem is completed, it enters the working state and initializes other processors in the electronic device besides the first processor; during the initialization of the processors in the electronic device, thread 0 (initial thread) and thread 2 (kernel parent thread) are started in the processor; finally, process 1 (init process) is started in the processor. Process 1 serves as the parent process of the user-mode application. At this point, the initialization configuration of the first and second processors is completed, and the device switches to user mode to enter the working state.
[0042] Initializing the processor may include, but is not limited to, initializing the configuration of the processor's task queue (e.g., rq queue), root domain, task groups, etc. The processor in the electronic device includes a first processor and a second processor. The first processor in the electronic device is the processor with the smallest processor number in the electronic device, for example, CPU0.
[0043] In this embodiment of the application, after the electronic device completes the initialization configuration of the first processor and the second processor through step 101, it can further determine the third processor and the fourth processor from the first processor; wherein, the number of the first processors in the electronic device is n, and in step 102, (n-1) first processors are determined as the third processor, and the 1 first processor other than the third processor is determined as the fourth processor.
[0044] For example, the number of first processors is 6, and the first processors are numbered CPU5 to CPU10. The electronic device can identify CPU5 to CPU9 as the third processor and CPU10 as the fourth processor through step 102.
[0045] It should be noted that the allocation priority of the third processor is higher than that of the fourth processor; where the allocation priority refers to the allocation priority of the task corresponding to the target application.
[0046] Specifically, when the allocation priority of the third processor is higher than that of the fourth processor, in step 103, the electronic device prioritizes allocating the task corresponding to the target application to the third processor, so that one task is bound to one third processor; when each third processor is bound to one task, the subsequently created tasks are then allocated to the fourth processor.
[0047] In this embodiment, when the target application corresponding to the lightweight kernel is launched, the electronic device allocates the tasks corresponding to the target application to the third or fourth processor according to the allocation priority and the number of third processors: First, since the allocation priority of the third processor is higher than that of the fourth processor, the tasks corresponding to the target application are preferentially allocated to the third processor, so that the task queue of the third processor contains only one task. During the operation of the third processor, the third processor executes the tasks in the task queue until the task is completed, without the need for task scheduling. The execution time of the task bound to the third processor is infinitely close to the total running time of the task, reducing the number of task scheduling and reducing the processor computing power loss caused by frequent task scheduling. Then, if the number of tasks corresponding to the target application is greater than the number of third processors (n-1), the electronic device allocates all the tasks corresponding to the target application created subsequently to the fourth processor. During the operation of the fourth processor, the fourth processor can poll and execute each task in the task queue of the fourth processor.
[0048] The polling method for tasks in the task queue by the fourth processor may include, but is not limited to: simple polling (Round Robin, RR), weighted round polling (WRR), least connections polling, smart polling, time-slice polling, etc. In practical application scenarios, the polling method for tasks in the task queue by the fourth processor can be selected as needed, and this application embodiment does not limit it.
[0049] Understandably, when the number of tasks corresponding to the target application is less than or equal to the number of third processors, the tasks corresponding to the target application can be assigned to each third processor, and one task is bound to one third processor. In this scenario, the number of tasks bound to the fourth processor is 0. When the number of tasks corresponding to the target application is greater than the number of third processors, the tasks corresponding to the target application are assigned to (n-1) third processors according to the rule of one task bound to one third processor. Then, all tasks corresponding to the target application created subsequently can be assigned to the fourth processor. In this scenario, the number of tasks bound to the fourth processor is greater than 0.
[0050] It is understandable that assigning the task corresponding to the target application to the third or fourth processor means writing the task corresponding to the target application into the task queue of the third or fourth processor, thereby binding the task to the third or fourth processor.
[0051] As an optional implementation, the lightweight kernel includes the lwk tool, which allows electronic devices to use to launch a target application, create a task corresponding to the target application, and assign the task to a third or fourth processor.
[0052] The lwk tool, set up in kernel mode, is used to update the lightweight kernel data in the " / sys / " directory. The tasks corresponding to the target application can include, but are not limited to: the target application's main process, child processes created by the main process, the first thread created by the main process, and the second thread created by the child process.
[0053] In this embodiment of the application, when the electronic device assigns a task to a third processor or a fourth processor in step 103, it can execute step 104 to run the third processor and the fourth processor to execute the task corresponding to the target application.
[0054] It should be noted that during the operation of the target application, the tasks corresponding to the target application are created sequentially according to the actual operation needs. The electronic device can assign the task to the third processor or the fourth processor in step 103 when any task is created. After the task is assigned, the processor (third processor or fourth processor) bound to the task is run to execute the task.
[0055] When both the third and fourth processors are bound to tasks, they run in parallel. When the tasks corresponding to the target application are interconnected, only the fourth processor needs to interrupt and execute the tasks associated with the tasks executed by the third processor. This does not involve interrupting the execution of the third processor, reducing the number of processor interrupts, reducing the loss of processor computing power caused by processor interrupt execution in electronic devices, and improving the task processing efficiency and overall performance of electronic devices.
[0056] In related technologies, cloud platform systems and supercomputing systems generally suffer from "system noise" that causes an overall performance degradation of the server due to additional losses generated during server operation. In Linux parallel systems, "system noise" mainly comes from the frequent scheduling of tasks in the system and the execution of processor interrupts, which leads to a significant reduction in the computing power and overall performance of the processor in the server.
[0057] The mOS kernel project is a relatively feasible supercomputing system kernel. The mOS kernel consists of LWK and FWK. FWK runs basic system services and applications, while LWK runs specified applications through the yod tool. In the mOS kernel, LWK is an isolated partition of the mOS kernel. It schedules specified applications through the mOS scheduler class and uses a lightweight processor and specified memory region to process the tasks of the specified applications. Specifically, in the mOS kernel scheduling architecture, the mOS kernel categorizes tasks into ordinary tasks and lightweight tasks using a classification technique. When enqueuing a task, it checks whether the current task has the MOS flag. Tasks with the MOS flag are lightweight tasks, and are enqueued into the lightweight processor corresponding to LWK after initializing relevant configuration parameters. Tasks without the MOS flag continue the traditional Linux task scheduling and are enqueued into the ordinary processor corresponding to FWK. During the execution of the application specified by LWK, the main task of the application (the first process of the application started by yod) has the MOS flag, and the threads created by the main task inherit this flag. However, the child processes created by the main task and the threads created by the child processes do not inherit the MOS flag, so the child processes and the threads created by the child processes are ordinary tasks.
[0058] While this method can reduce performance loss caused by "system noise" to some extent, the mOS kernel still has the following problems:
[0059] (1) LWK not used properly: In the mOS kernel, the child processes and threads created by the main process of the application run in the normal processor queue of FWK, and there is a situation where the lightweight processors of LWK are not fully utilized. For example, the number of lightweight processors is 12, the main process of the application and the threads created by the main process have a total of 6, and the child processes and the threads created by the main process have 6. When the child processes and the threads created by the child processes run in the normal processor queue of FWK, only 6 lightweight processors can be used, resulting in a waste of resources.
[0060] (2) Long test waiting time: For example, for HPL-related testing tools, such as mpirun, when the number of tasks is close to or exceeds the number of lightweight processors, the testing tool needs to synchronize the state between each child process and the threads created by the child process. However, the polling time slice of each task in the mOS kernel is 200ms. When the number of lightweight tasks is close to or exceeds the number of lightweight processors, it will take a long time to poll all the tasks. For HPL-related testing tools, it generally takes nearly 30 minutes to start the test.
[0061] (3) Memory resource waste: The mOS kernel pre-specifies a fixed size of partition memory for LWK partitions. In most application scenarios, the utilization rate of this partition memory is less than 50%, and this partition memory cannot be used for the processing of FWK tasks, resulting in memory resource waste.
[0062] The task processing method provided in this application reduces the number of task scheduling and processor interrupts, thereby reducing the loss of processor computing power caused by frequent task scheduling and processor interrupts, and improving the task processing efficiency and overall performance of electronic devices. At the same time, all tasks corresponding to the target application are allocated to the first processor that processes tasks of the lightweight kernel, thus making full use of the first processor used to process tasks of the lightweight kernel. Moreover, this application reduces the number of task scheduling and processor interrupts, shortens the processing time of the first processor for tasks corresponding to the target application, and improves the efficiency of task processing. Furthermore, this application does not pre-allocate the memory of the electronic device and uses a general memory management subsystem to manage the memory space according to the specific tasks executed by the first and second processors, thus avoiding waste of memory resources.
[0063] Furthermore, by adopting the task processing method provided in the embodiments of this application, the overall performance of electronic devices is improved. Under the same workload, the number of devices required for task processing can be reduced, thereby reducing equipment procurement costs, operation and maintenance costs and energy consumption.
[0064] In an optional embodiment of this application, step 103, which involves allocating the task corresponding to the target application to a third or fourth processor based on the allocation priority and the number of third processors when the target application corresponding to the lightweight kernel is started, includes steps 1031 to 1033:
[0065] Step 1031: When the target application corresponding to the lightweight kernel is started, determine the task corresponding to the target application.
[0066] Step 1032: If the number of tasks is less than or equal to (n-1), assign each task to a different third processor.
[0067] Step 1033: If the number of tasks is greater than (n-1), the first (n-1) tasks are assigned to different third processors according to the order in which the tasks are created, and the tasks created afterward are assigned to the fourth processor.
[0068] In this embodiment of the application, when the target application corresponding to the lightweight kernel is started, the electronic device creates at least one task corresponding to the target application through the lightweight kernel according to the running needs of the target application, thereby realizing the determination of the task corresponding to the target application.
[0069] It is understandable that the tasks corresponding to the target application are created sequentially according to actual operational needs. Once the electronic device determines the task corresponding to the target application through step 1031, it can execute step 1032 or step 1033. If other tasks corresponding to the target application are determined, step 1032 or step 1033 is repeated until the target application completes its operation and exits.
[0070] Specifically, when the electronic device determines the tasks corresponding to the target application in step 1031 each time, it can first determine the number of tasks corresponding to the target application, and then execute step 1032 or step 1033 based on the number of target applications. It should be noted that the number of tasks corresponding to the target application is the total number of tasks corresponding to the target application determined by the electronic device through step 1031 from the moment the target application starts.
[0071] If the number of tasks corresponding to the target application is less than or equal to (n-1), the tasks will be assigned to the third processor because the allocation priority of the third processor is higher than that of the fourth processor. If the number of tasks corresponding to the target application is greater than (n-1), the allocation priority of the third processor is higher than that of the fourth processor. Based on the order in which the tasks are created, the first (n-1) tasks will be assigned to different third processors, and the tasks created subsequently will be assigned to the fourth processor.
[0072] As another optional implementation, after step 1031, the electronic device may further: first, determine whether there is a third processor in the electronic device that is in an idle state; then, if there is a third processor in the electronic device that is in an idle state, assign the task determined in step 1031 to the third processor in the idle state; if there is no third processor in the electronic device that is in an idle state, assign the task determined in step 1031 to a fourth processor.
[0073] Among them, an idle third processor refers to a third processor that is not bound to any tasks and has 0 tasks in its task queue.
[0074] The task processing method provided in this application prioritizes assigning tasks to the third processor according to the creation order of tasks corresponding to the target application. When all third processors are under load, subsequently created tasks are then assigned to the fourth processor. This reduces the number of task scheduling and processor interrupts, thereby minimizing processor power loss caused by frequent task scheduling and processor interrupts. Furthermore, when the number of tasks corresponding to the target application exceeds the number of third processors, tasks exceeding the number of third processors can be assigned to the fourth processor. This solves the problem of overloading the third processor due to a larger number of tasks, ensuring that the lightweight kernel runs all tasks corresponding to the target application with high performance, thus improving the task processing efficiency and overall performance of the electronic device.
[0075] In an optional embodiment of this application, step 103, which involves allocating the task corresponding to the target application to a third or fourth processor based on the allocation priority and the number of third processors when the target application corresponding to the lightweight kernel is started, includes steps 1034 to 1036:
[0076] Step 1034: When the target application corresponding to the lightweight kernel is started, create the main process corresponding to the target application and bind the main process to any third processor.
[0077] Step 1035: Based on the allocation priority and the number of third processors, bind the first thread created by the main process and / or the child process created by the main process to the third and fourth processors that are in an idle state.
[0078] Step 1036: Based on the allocation priority and the number of third processors, bind the second thread created by the child process to the third and fourth processors that are in an idle state.
[0079] In this embodiment, the task corresponding to the target application includes a main process, a first thread created by the main process, a child process created by the main process, and a second thread created by the child process. The main process is the first process created by the lightweight kernel.
[0080] Specifically, the lightweight kernel can create the main process corresponding to the target application using execve-related functions. It is understandable that, since the main process is the first process corresponding to the target application, all third processors in the electronic device are currently idle. In step 1034, after creating the main process corresponding to the target application, the electronic device can bind the main process to any third processor.
[0081] After binding the main process to any third processor, the electronic device can perform step 104 to run the third processor to execute the main process.
[0082] During the execution of the main process, the main process creates a first thread and / or a child process. When the main process creates a first thread and / or a child process, the electronic device can bind the first thread and / or the child process created by the main process to the idle third and fourth processors according to the allocation priority of the third and fourth processors and the number of third processors.
[0083] Specifically, when the main process creates the first thread or child process, the electronic device can first determine whether there is an idle third processor in the electronic device; if there is an idle third processor in the electronic device, the first thread or child process is bound to the idle third processor; if there is no idle third processor in the electronic device, the first thread or child process is bound to the fourth processor.
[0084] When the main process creates the first thread and child process, the electronic device can first determine whether there is an idle third processor in the electronic device. If there is an idle third processor in the electronic device, and the number of idle third processors is greater than or equal to 2, the first thread is bound to the idle third processor, and the child process is bound to another idle third processor. If there is an idle third processor in the electronic device, and the number of idle third processors is 1, according to the creation order of the first thread and child process, the first thread or child process created earlier is bound to an idle third processor, and the child process or first thread created later is bound to a fourth processor (for example, if the first thread is created first and the child process is created later, then the first thread created earlier is bound to an idle third processor, and the child process created later is bound to a fourth processor). If there is no idle third processor in the electronic device, the first thread is bound to a fourth processor, and the child process is bound to a fourth processor.
[0085] In this embodiment of the application, after binding the first thread created by the main process and / or the child process created by the main process to the third and fourth processors which are in an idle state, the electronic device can perform step 104 to run the third and fourth processors to execute the first thread and the child process.
[0086] During the execution of a child process, the child process creates a second thread. When a child process creates a second thread, the electronic device can bind the second thread to an idle third or fourth processor based on the allocation priority of the third and fourth processors and the number of third processors.
[0087] Specifically, when a child process creates a second thread, the electronic device can first determine whether there is an idle third processor in the electronic device; if there is an idle third processor in the electronic device, the second thread is bound to the idle third processor; if there is no idle third processor in the electronic device, the second thread is bound to a fourth processor.
[0088] As an example, the default flag of the main process corresponding to the target application is IS_LWK_PROCESS; the first thread created by the main process inherits the default flag of the main process, and the default flag of the first thread is also IS_LWK_PROCESS; the default flag of the child process created by the main process is IS_LWK_CLONE_PROCESS, and the default flag of the second thread created by the child process inherits the default flag of the child process, and the default flag of the second thread is also IS_LWK_CLONE_PROCESS.
[0089] The task processing method provided in this application embodiment, when the task corresponding to the target application includes a main process, a first thread, a child process, and a second thread, binds the third processor and the fourth processor sequentially according to the allocation priority of the third processor and the fourth processor, the number of third processors, and the creation order of the main process, the first thread, the child process, and the second thread. This improves the task processing efficiency and overall performance of the electronic device while ensuring that the task executed by the third processor is not preempted, thus improving the feasibility of this application embodiment.
[0090] In one optional embodiment of this application, step 104, which involves running the third and fourth processors to execute the task corresponding to the target application, includes steps 1041 to 1042:
[0091] Step 1041: Determine the execution priority and running weight of the task bound to the fourth processor.
[0092] Step 1042: Run the fourth processor and, based on the execution priority and execution weight, poll and execute the tasks bound to the fourth processor.
[0093] In this embodiment of the application, if the number of tasks in the task queue of the fourth processor is greater than 1, it is necessary to poll and execute each task in the task queue of the fourth processor.
[0094] When an electronic device runs a fourth processor to execute tasks corresponding to the target application bound to the fourth processor, it can first determine the execution priority and running weight of the tasks bound to the fourth processor; then run the fourth processor and, based on the execution priority and running weight, poll and execute the tasks bound to the fourth processor; in this scenario, the task queue of the fourth processor can be a queue in the form of a red-black tree (binary tree).
[0095] Specifically, in step 103, during the process of allocating the task corresponding to the target application to the fourth processor, the task can be inserted into the corresponding red-black tree node according to the execution priority. The red-black tree queue supports a maximum of 80,000 tasks. Each time a task is switched, the scheduling entity is taken out from the leftmost node of the red-black tree and returned as a task_struct task structure. When a task is completed, the running weight of the task is recalculated and the task is inserted after the unexecuted tasks.
[0096] The task processing method provided in this application embodiment, during the operation of the fourth processor, polls and executes the tasks bound to the fourth processor according to their execution priority and execution weight, ensuring that tasks with higher execution priority and higher execution weight can be processed in a timely manner. The execution time of each task in the task queue of the fourth processor is between 1ms and 5ms, which can execute all tasks in the task queue in a very short time, shortening the processing time of the fourth processor for the tasks corresponding to the target application, enabling faster response to the execution process of the target application, and improving the task execution performance of the fourth processor.
[0097] In one optional embodiment of this application, the task processing method provided in this application further includes step A11:
[0098] Step A11: In the case that there is at least one third processor in an idle state in the electronic device, at least one first task is determined from the tasks to be executed by the fourth processor, and the first task is assigned to the third processor in the idle state.
[0099] In this embodiment of the application, after the third processor completes the execution of the bound task, it can execute an idle thread; wherein, an idle thread refers to a thread that is scheduled by the operating system to be executed by the processor when there is no task to be executed in the operating system. When the processor executes an idle thread, it means that the processor is in an idle state and does not occupy too much processor resources.
[0100] Specifically, the electronic device can monitor the operating status of each third processor in real time. When a third processor is executing an idle thread, it indicates that the task bound to that third processor has been completed and is in an idle state. In this scenario, the electronic device can determine at least one first task from the tasks to be executed by the fourth processor and assign the first task to the idle third processor. This improves the execution efficiency of the task corresponding to the target application while also improving the load balancing of the third processor.
[0101] In this context, the tasks to be executed by the fourth processor refer to all tasks bound to the fourth processor other than the task currently being executed by the fourth processor; that is, all tasks in the fourth processor's task queue other than the currently executing task. It can be understood that the number of first tasks is less than or equal to the number of third processors currently in an idle state, ensuring that after the electronic device assigns the first tasks to idle third processors, one task is bound to one third processor.
[0102] It is understandable that when the number of tasks to be executed is 0, the electronic device does not need to perform step A11 to determine the first task and assign the first task to the third processor which is in an idle state.
[0103] In this embodiment of the application, assigning the first task to the third processor in an idle state is as follows: the first task is bound to the third processor in an idle state according to the principle of binding one task to one third processor; specifically, the electronic device can write the first task from the task queue of the fourth processor to the task queue of the third processor in an idle state.
[0104] In the embodiments of this application, the task bound to the third processor can be regarded as a real-time task (SCHED_RR), and the task bound to the fourth processor can be regarded as a normal task (SCHED_NORMAL). Assigning the first task of the fourth processor to the third processor in an idle state can be regarded as promoting the normal task in the fourth processor to a real-time task and binding it to the third processor in an idle state for execution.
[0105] During the execution of the target application, the lightweight kernel can continuously process the tasks corresponding to the target application according to the task processing method described above until all tasks corresponding to the target application are completed, at which point the target application exits, and the electronic device can launch other target applications corresponding to the lightweight kernel through the lwk tool.
[0106] Optionally, during the initialization configuration of the first processor and the second processor, the electronic device may also initialize each first processor mask to perform usage statistics of the first processor during the operation of the target application and initialize the number of tasks in the task queue of the first processor. At this point, the first processor enters a usable state.
[0107] It should be noted that in this embodiment of the application, the lightweight kernel processes only one target application at a time. When the target application starts running, the electronic device can obtain the number of tasks in the task queue of each first processor in real time. When the number of tasks in the task queue of each first processor is 0, it is determined that the target application has finished running and exits. The electronic device can then start other target applications corresponding to the lightweight kernel through the lwk tool.
[0108] Optionally, if the target application's tasks include a main process, a first thread, a child process, and a second thread, during the initialization configuration of the first and second processors, the electronic device can also initialize each first processor mask. This mask is used to perform usage statistics of the first processor during the target application's execution and to initialize process variables and task counts in the task queue corresponding to the first processor. At this point, the first processor enters a usable state. The process variables are used for process counting.
[0109] Specifically, during the execution of a process by the processor, after the process completes its execution, it exits, and when the process exits, the threads created by that process will also necessarily exit. When the target application starts running, the electronic device can obtain the total number of processes in the task queues of each first processor in real time. When the total number of processes in the task queues of each first processor is 0, it is determined that the target application has completed running and exited. The electronic device can then use the lwk tool to launch other target applications corresponding to the lightweight kernel. Here, processes include main processes and child processes, and threads include first threads and second threads.
[0110] The task processing method provided in this application embodiment facilitates the management of the launch and exit timing of target applications by electronic devices.
[0111] In one optional embodiment of this application, step 101, which initializes and configures the first processor and the second processor to process tasks of a lightweight kernel and the second processor to process tasks of a basic kernel, includes steps 1011 to 1012:
[0112] Step 1011: Set the preset flag bit in the first processor to the first flag bit; the first flag bit is used to indicate that the first processor is used to process the lightweight kernel task.
[0113] Step 1012: Set the preset flag bit in the second processor to the second flag bit; the second flag bit is used to indicate that the second processor is used to process the basic kernel's tasks.
[0114] In this embodiment, the task queues of the first processor and the second processor further include a preset flag bit, which is used to indicate the type of task the processor is used to process; wherein, the task type includes tasks of the lightweight kernel and tasks of the basic kernel.
[0115] Specifically, the preset flags include a first flag and a second flag. The first flag indicates that the task category processed by the processor is a lightweight kernel task, and the second flag indicates that the task category processed by the processor is a basic kernel task. For example, the first flag can be "1" and the second flag can be "0".
[0116] In this embodiment of the application, during the initialization configuration of the first processor and the second processor, the electronic device can set a preset flag bit in the first processor to a first flag bit and set a preset flag bit in the second processor to a second flag bit. This allows the electronic device to determine, based on the preset flag bits in the first processor and the second processor, that the first processor is used to process tasks of the lightweight kernel and the second processor is used to process tasks of the basic kernel, thereby improving the accuracy of task scheduling by the electronic device.
[0117] In an optional embodiment of this application, before initializing and configuring the first processor and the second processor in step 101 to configure the first processor to process tasks of a lightweight kernel and the second processor to process tasks of a basic kernel, the method further includes steps A21 to A23:
[0118] Step A21: Obtain processor boot parameters; processor boot parameters include the first processor identifier.
[0119] Step A22: Identify the processor in the electronic device that matches the identifier of the first processor as the first processor.
[0120] Step A23: Identify the processors in the electronic device other than the first processor as the second processor.
[0121] In this embodiment of the application, before step 101, the electronic device may further divide the processor in the electronic device into a first processor and a second processor through steps A21 to A23.
[0122] Specifically, when the operating system kernel in the electronic device starts, the electronic device can load the processor boot parameters from the operating system's configuration file, and divide the processor in the electronic device into a first processor and a second processor according to the first processor identifier in the processor boot parameters through steps A22 and A23.
[0123] The first processor identifier is the processor number corresponding to the first processor specified in the boot parameters. As an example, the processors in the electronic device include CPU0 to CPU15, and the first processor identifier in the boot parameters can be represented as lwkcpus = 4-15. After the electronic device obtains the processor boot parameters through step A21, it can determine the processors with processor numbers 4 to 15 (CPU4 to CPU15) in the electronic device as the first processor based on the first processor identifier (lwkcpus = 4-15) in the processor boot parameters, and determine the other processors (CPU0 to CPU3) other than the first processor (CPU4 to CPU15) as the second processor.
[0124] In this embodiment, the processor boot parameters can be GRUB (GRand Unified Bootloader) boot parameters. The electronic device can load the GRUB boot parameters from the GRUB configuration file to obtain the processor boot parameters. In Linux systems, the GRUB configuration file is usually located in the / boot / grub / grub.cfg directory.
[0125] As an example, refer to Figure 3 The diagram illustrates a flowchart of another task processing method embodiment provided in this application, which specifically includes steps 201 to 206:
[0126] Step 201: Lightweight kernel startup.
[0127] Specifically, when an electronic device starts up, it first executes the Basic Input Output System (BIOS) and the Unified Extensible Firmware Interface (UEFI), initializes the hardware of the electronic device through the BIOS and UEFI, checks the hardware boot order, and loads the operating system kernel of the electronic device into memory.
[0128] Step 202: Obtain processor boot parameters.
[0129] For example, the processor in the electronic device includes CPU0 to CPU15, and the electronic device loads processor boot parameters from the operating system's configuration file, wherein the first processor in the boot parameters is identified as lwkcpus=4-15.
[0130] Step 203: Initialize the processor and each kernel subsystem.
[0131] Specifically, the electronic device first initializes the first processor (CPU0) in the electronic device and loads various configurations through the first processor; then, each kernel subsystem is initialized, such as the memory subsystem and the device subsystem, so that the subsystems can enter the working state; then, the other processors in the electronic device other than CPU0 are initialized; during the initialization of the processors in the electronic device, thread 0 and thread 2 are started in the processor.
[0132] Step 204: Initialize the first processor according to the first processor identifier in the processor boot parameters.
[0133] Specifically, the electronic device first identifies the processors numbered 4 to 15 (CPU4 to CPU15) in the electronic device as the first processor based on the first processor identifier (lwkcpus=4-15) in the processor boot parameters, and sets the preset flag bit in the first processor to the first flag bit (1); then, it identifies the other processors (CPU0 to CPU3) besides the first processor (CPU4 to CPU15) as the second processor, and sets the preset flag bit in the second processor to the second flag bit (0).
[0134] Step 205: Start the init process, and the lightweight kernel enters the working state.
[0135] Specifically, the electronic device starts the init process, which acts as the parent process of user-mode applications. This completes the initialization and configuration of the first processor, and the lightweight kernel enters the working state.
[0136] Step 206: Lightweight kernel exits.
[0137] Specifically, the lightweight kernel exits when the electronic device is turned off or restarted.
[0138] As an example, refer to Figure 4 The diagram illustrates a flowchart of another task processing method embodiment provided in this application, which specifically includes steps 301 to 309:
[0139] Step 301: Use the lwk tool to launch the target application.
[0140] Specifically, after completing the initialization configuration of the first and second processors, the electronic device can use the lwk tool to launch the target application corresponding to the lightweight kernel.
[0141] During the startup of the target application, the lwk tool first sets the number of first processors to be used in the lightweight kernel (by default, all first processors are used); then, it initializes the masks of each first processor to perform statistics on the usage of the first processors during the execution of the target application, and initializes the process variables and task counts of the task queue of the first processors, at which point the first processors enter a usable state.
[0142] It should be noted that when the first processor is CPU4 to CPU15, the electronic device can identify CPU4 to CPU14 as the third processor and CPU15 as the fourth processor.
[0143] Step 302: Create the main process.
[0144] Specifically, the lwk tool can create the main process corresponding to the target application through execve-related functions; the main process inherits the startup environment of the lwk tool, and the default flag of the main process is IS_LWK_PROCESS.
[0145] Step 303: Create a child process.
[0146] Specifically, the default flag for child processes created by the main process is IS_LWK_CLONE_PROCESS; in addition, to ensure that the child process has the ability to run on the first processor, the electronic device also needs to create an lwk_process structure object for the child process, thus enabling the child process to run on the first processor.
[0147] The lwk_process structure object records information related to the first processor. This information may include, but is not limited to, the range mask of the first processor and the processor number of the last first processor. By creating an lwk_process structure object for a child process, the child process can be enabled to run on the first processor.
[0148] Step 304: Create the first thread.
[0149] Specifically, the first thread created by the main process inherits the main process's default flag (IS_LWK_PROCESS).
[0150] Step 305: Create a second thread.
[0151] Specifically, the second thread created by the child process inherits the child process's default flag (IS_LWK_CLONE_PROCESS), and the second thread shares the lwk_process structure object with the child process.
[0152] Step 306: Allocate processor.
[0153] Specifically, when the electronic device creates the main process using the lwk tool in step 302, it binds the main process to any third processor.
[0154] In the case where the main process creates a child process in step 303 and / or the main process creates a first thread in step 304, the electronic device binds the child process and / or the first thread created by the main process to the third and fourth processors that are in an idle state, according to the allocation priority of the third and fourth processors and the number of third processors.
[0155] In step 305, if the subprocess creates a second thread, the electronic device binds the second thread created by the subprocess to the third and fourth processors that are in an idle state, according to the allocation priority of the third and fourth processors and the number of third processors.
[0156] Step 307: Execute the logic code.
[0157] Specifically, when the main process, first thread, child process, and second thread are bound to a third or fourth processor, the electronic device can run the third or fourth processor, execute the logic code of the process or thread bound to the third processor, and the logic code of the process and / or thread bound to the fourth processor, and process the main process, first thread, child process, and second thread corresponding to the target application.
[0158] Step 308: Code execution complete.
[0159] Specifically, when the logical code of a process or thread has finished executing, it indicates that the process or thread has completed execution and has exited.
[0160] When a process or thread bound to a third processor exits, the third processor is in an idle state. In this embodiment, when at least one third processor in an idle state exists in the electronic device, the electronic device can determine at least one first task from the tasks to be executed by the fourth processor and assign the first task to the idle third processor.
[0161] Step 309: The target application exits.
[0162] Specifically, during the startup and operation of the target application, the electronic device can obtain the total number of processes in the task queue of each first processor in real time. When the total number of processes in the task queue of each first processor is 0, it is determined that the target application has finished running and the target application exits.
[0163] When the target application exits, the electronic device can clear each first processor mask and, if it needs to run other target applications corresponding to the lightweight kernel, launch a new target application again using the lwk tool.
[0164] In summary, this application provides a task processing method. During task processing, the electronic device determines (n-1) third processors and 1 fourth processor from n first processors configured to process tasks with lightweight kernels. When assigning tasks corresponding to the target application to the third or fourth processor, each third processor is bound to one task, and the number of tasks bound to the fourth processor is greater than or equal to 0. During the execution of tasks bound to the third processor by the third processor, no task scheduling is required. The execution time of the tasks bound to the third processor is infinitely close to the total execution time of the task, reducing the number of task scheduling operations and thus reducing the processor's computing power loss caused by frequent task scheduling. Furthermore, during the operation of the third and fourth processors, the tasks bound to each third processor are executed in parallel. When tasks corresponding to the target application are interconnected, only the fourth processor needs to interrupt and execute tasks associated with the tasks executed by the third processor, without involving interrupt execution operations of the third processor. This reduces the number of processor interrupts, thereby reducing the processor's computing power loss caused by processor interrupt execution in the electronic device and improving the task processing efficiency and overall performance of the electronic device.
[0165] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this application.
[0166] Device Examples
[0167] Reference Figure 5 This diagram illustrates a structural block diagram of a task processing device according to this application, applied to an electronic device. The electronic device includes a lightweight kernel, a basic kernel, a first processor, and a second processor. Specifically, the device may include:
[0168] Configuration module 501 is used to initialize and configure the first processor and the second processor, so as to configure the first processor to process the task of the lightweight kernel and the second processor to process the task of the basic kernel;
[0169] The first determining module 502 is used to determine (n-1) third processors and 1 fourth processor from n first processors; n is an integer greater than 1; the allocation priority of the third processors is higher than the allocation priority of the fourth processor;
[0170] The first allocation module 503 is configured to, when the target application corresponding to the lightweight kernel is started, allocate the task corresponding to the target application to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0.
[0171] The execution module 504 is used to run the third processor and the fourth processor to execute the tasks corresponding to the target application.
[0172] Optionally, the first allocation module includes:
[0173] The first determining submodule is used to determine the task corresponding to the target application when the target application corresponding to the lightweight kernel is started.
[0174] The first allocation submodule is used to allocate each task to a different third processor when the number of tasks is less than or equal to (n-1);
[0175] The second allocation submodule is used to allocate the first (n-1) tasks to different third processors according to the creation order of the tasks when the number of tasks is greater than (n-1), and to allocate the subsequently created tasks to the fourth processor.
[0176] Optionally, the task includes a main process, a first thread, a child process, and a second thread; the first allocation module includes:
[0177] The first binding submodule is used to create the main process corresponding to the target application when the target application corresponding to the lightweight kernel is started, and bind the main process to any of the third processors.
[0178] The second binding submodule is used to bind the first thread created by the main process and / or the child process created by the main process to the third processor and the fourth processor that are in an idle state, according to the allocation priority and the number of third processors.
[0179] The third binding submodule is used to bind the second thread created by the subprocess to the idle third processor and the fourth processor according to the allocation priority and the number of third processors.
[0180] Optionally, the execution module includes:
[0181] The second determining submodule is used to determine the execution priority and running weight of the task bound to the fourth processor;
[0182] The first execution submodule is used to run the fourth processor and, according to the execution priority and the execution weight, to execute the tasks bound to the fourth processor in a round-robin fashion.
[0183] Optionally, the device further includes:
[0184] The second allocation module is configured to, when there is at least one third processor in the electronic device that is in an idle state, determine at least one first task from the tasks to be executed by the fourth processor and allocate the first task to the third processor that is in an idle state.
[0185] Optionally, the configuration module includes:
[0186] A first setting submodule is used to set a preset flag bit in the first processor to a first flag bit; the first flag bit is used to indicate that the first processor is used to process the task of the lightweight kernel;
[0187] The second setting submodule is used to set a preset flag bit in the second processor to a second flag bit; the second flag bit is used to indicate that the second processor is used to process the tasks of the basic kernel.
[0188] Optionally, the device further includes:
[0189] The acquisition module is used to acquire processor boot parameters; the processor boot parameters include a first processor identifier;
[0190] The second determining module is used to determine the processor in the electronic device that matches the first processor identifier as the first processor;
[0191] The third determining module is used to determine other processors in the electronic device besides the first processor as the second processor.
[0192] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0193] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0194] Regarding the processor in the above embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, and will not be elaborated here.
[0195] Reference Figure 6 This is a structural block diagram of an electronic device for task processing provided in an embodiment of this application. Figure 6 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface communicate with each other through the communication bus. The memory is used to store executable instructions, which cause the processor to execute the task processing method of the aforementioned embodiment.
[0196] The processor can be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), a FPGA (Field Programmable Gate Array), or other programmable devices, transistor logic devices, hardware components, or any combination thereof. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, or a combination of a DSP and a microprocessor.
[0197] The communication bus may include a path for transmitting information between the memory and the communication interface. The communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.
[0198] The memory may be ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it may be EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disk Read Only), magnetic tape, floppy disk, and optical data storage devices, etc.
[0199] This application also provides a readable storage medium that, when the instructions in the storage medium are executed by the processor of an electronic device (server or terminal), enables the processor to perform... Figure 1 The task processing method shown.
[0200] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0201] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0202] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0203] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0204] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0205] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0206] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0207] The above provides a detailed description of a task processing method, apparatus, electronic device, and readable storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A task processing method, characterized in that, Applied to an electronic device, the electronic device including a lightweight kernel, a basic kernel, a first processor, and a second processor; the method includes: The first processor and the second processor are initialized and configured so that the first processor is configured to process the tasks of the lightweight kernel and the second processor is configured to process the tasks of the basic kernel. From the n first processors, determine (n-1) third processors and 1 fourth processor; n is an integer greater than 1; the allocation priority of the third processors is higher than that of the fourth processor. When the target application corresponding to the lightweight kernel is launched, the task corresponding to the target application is assigned to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0. The third and fourth processors are run to execute the tasks corresponding to the target application.
2. The method according to claim 1, characterized in that, When the target application corresponding to the lightweight kernel is launched, the task corresponding to the target application is allocated to the third processor or the fourth processor according to the allocation priority and the number of third processors, including: When the target application corresponding to the lightweight kernel is launched, the task corresponding to the target application is determined; If the number of tasks is less than or equal to (n-1), each task is assigned to a different third processor; If the number of tasks is greater than (n-1), the first (n-1) tasks are assigned to different third processors according to the order in which the tasks are created, and the tasks created subsequently are assigned to the fourth processor.
3. The method according to claim 1, characterized in that, The task includes a main process, a first thread, a child process, and a second thread; When the target application corresponding to the lightweight kernel is launched, the task corresponding to the target application is allocated to the third processor or the fourth processor according to the allocation priority and the number of third processors, including: When the target application corresponding to the lightweight kernel is started, a main process corresponding to the target application is created, and the main process is bound to any of the third processors. Based on the allocation priority and the number of third processors, the first thread created by the main process and / or the child process created by the main process are bound to the third processor and the fourth processor that are in an idle state; Based on the allocation priority and the number of third processors, the second thread created by the child process is bound to the third and fourth processors that are in an idle state.
4. The method according to claim 1, characterized in that, The step of running the third and fourth processors to execute the tasks corresponding to the target application includes: Determine the execution priority and running weight of the task bound to the fourth processor; The fourth processor is run, and the tasks bound to the fourth processor are executed in a round-robin manner according to the execution priority and the execution weight.
5. The method according to claim 1, characterized in that, The method further includes: In the case that at least one of the third processors in the electronic device is in an idle state, at least one first task is determined from the tasks to be executed by the fourth processor, and the first task is assigned to the third processor in the idle state.
6. The method according to claim 1, characterized in that, The initialization configuration of the first processor and the second processor, configuring the first processor to process the tasks of the lightweight kernel and the second processor to process the tasks of the base kernel, includes: Set a preset flag bit in the first processor to a first flag bit; the first flag bit is used to indicate that the first processor is used to process the task of the lightweight kernel; Set the preset flag bit in the second processor to the second flag bit; the second flag bit is used to indicate that the second processor is used to process the tasks of the basic kernel.
7. The method according to claim 1, characterized in that, Before initializing and configuring the first processor and the second processor, the method further includes: Obtain processor boot parameters; the processor boot parameters include a first processor identifier; The processor in the electronic device that matches the first processor identifier is identified as the first processor; The processors in the electronic device other than the first processor are designated as the second processor.
8. A task processing device, characterized in that, Applied to an electronic device, the electronic device including a lightweight kernel, a base kernel, a first processor, and a second processor; the device includes: A configuration module is used to initialize and configure the first processor and the second processor, so as to configure the first processor to process the task of the lightweight kernel and the second processor to process the task of the basic kernel; The first determining module is used to determine (n-1) third processors and 1 fourth processor from n first processors; n is an integer greater than 1; the allocation priority of the third processors is higher than the allocation priority of the fourth processor; The first allocation module is configured to, when the target application corresponding to the lightweight kernel is started, allocate the task corresponding to the target application to the third processor or the fourth processor according to the allocation priority and the number of third processors; wherein, one task is bound to one third processor, and the number of tasks bound to the fourth processor is greater than or equal to 0. An execution module is used to run the third processor and the fourth processor to execute the tasks corresponding to the target application.
9. An electronic device, characterized in that, The electronic device includes a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface communicate with each other through the communication bus. The memory is used to store executable instructions, which cause the processor to perform the task processing method as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that, When the instructions in the readable storage medium are executed by the processor of the electronic device, the processor is able to perform the task processing method as described in any one of claims 1 to 7.