Multi-task switching method, device, embedded system and medium
By introducing multiple sets of first general-purpose registers into the embedded operating system and directly obtaining the context of the target task according to the task allocation strategy, the problem of long context switching time during the task switching process is solved, and task scheduling efficiency and system performance are improved.
Patent Information
- Application Number
- CN202410846854.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-06-27
AI Technical Summary
Context switching during the task switching process in embedded operating systems takes up a lot of processing time, affecting real-time performance and efficiency. Existing technology cannot effectively improve task scheduling efficiency.
N groups of first general-purpose registers are introduced into the processor, and each group of registers is assigned to a task. By judging the register type assigned to the target task, the context of the target task is directly obtained and executed, avoiding context relocation operations and improving task switching efficiency.
It reduces the time spent on task switching, improves the efficiency of task scheduling and the running speed of system software, and improves overall system performance.
Smart Images

Figure CN118394489B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded operating systems, and in particular to a multi-task switching method, device, embedded system and medium. Background Art
[0002] Embedded systems generally refer to small computing systems used to control and perform specific tasks, and have been widely used in various fields. General embedded systems pay more attention to the requirements of practicality and reliability, but due to the constraints of volume, energy consumption, cost, and the limitations of processor technology development, the computing and processing performance of embedded systems is relatively weak, and the memory capacity is generally small. Therefore, the embedded operating system used in embedded systems needs to adopt a streamlined and high-real-time task scheduling strategy to ensure the stability and efficiency of the system.
[0003] The core of the embedded operating system is the task scheduler, which is responsible for arranging and allocating multiple tasks in the system so that different tasks can work reasonably and effectively in the system and ultimately complete the various functions of the system. Context switching is an important and necessary link in multi-task switching. In an embedded operating system, context refers to the environmental conditions required for a task to run, including the execution status, load address, stack address, etc. of each task. This information is generally stored in the general registers of the processor. Each task has its own independent context data, and they share the general registers of the processor hardware through dynamic switching during runtime. For example Figure 1 and Figure 2 As shown, Figure 1 A schematic diagram of the hardware architecture of multi-task context switching in the related art is shown. Figure 2 The following is a schematic diagram of the process flow of context switching in the related art. When the task scheduler performs task scheduling, the operating system will perform the following three steps in sequence:
[0004] (1) The operating system will save the context of the current task (represented by the current general register contents of the processor) to the task's private storage area;
[0005] (2) Take the context of the next task from its corresponding storage area (i.e., the corresponding private storage area of the next task) and write it into the general register of the current processor;
[0006] (3) Move the processor execution pointer to the next task and jump to the next task to start execution.
[0007] After the above three steps, the embedded operating system completes the switch from the current task to the next task.
[0008] In the related art, in order to improve the efficiency of task scheduling of embedded operating systems, different task scheduling strategies are provided. However, no matter which task scheduling strategy is adopted, during the task switching process, the context switch needs to go through the above three steps, so that the task switching takes up more processing time, which has a greater impact on the real-time performance of the embedded system and cannot effectively improve the efficiency of task scheduling. Summary of the invention
[0009] Based on this, it is necessary to provide a multi-task switching method, device, embedded system and medium that can reduce the context switching time cost in response to the above technical problems.
[0010] A multi-task switching method is applied to a processor, wherein the processor is configured with N groups of first general registers, each group of the first general registers is used to be assigned to a task, wherein N is an integer greater than 1, and the method comprises:
[0011] Upon receiving a task switching request, determining a target task of the task switching request;
[0012] The general register of the processor is switched to the first general register allocated to the target task, the context of the target task stored in the first general register allocated to the target task is acquired, and the target task is executed.
[0013] In the above solution, the processor is further configured with a set of second general registers, and the method further includes:
[0014] Determining the general register allocated to the target task;
[0015] If the general register allocated to the target task is the first general register, performing the step of obtaining the context of the target task stored in the first general register allocated to the target task;
[0016] If the general register assigned to the target task is the second general register, the context of the target task is written from the private storage area of the target task to the second general register, the general register of the processor is switched to the second general register assigned to the target task, the context of the target task is obtained from the second general register, and the target task is executed.
[0017] In the above scheme, the method further includes:
[0018] Determine the general register assigned to the currently executed task;
[0019] If the general register allocated to the currently executing task is the second general register, the context of the currently executing task is written from the second general register to the private storage area of the currently executing task.
[0020] In the above scheme, the method further includes:
[0021] Get the number of tasks to be assigned;
[0022] If the number is greater than N, the first general registers corresponding to the N different tasks to be assigned are assigned, and the second general registers are assigned to the remaining tasks to be assigned;
[0023] If the number is less than or equal to N, the first general register corresponding to each task to be assigned is allocated.
[0024] In the above solution, allocating the first general register corresponding to the task to be allocated includes:
[0025] According to the number of the task to be assigned, the first general register of the task to be assigned is allocated; the number of the task is the same as the register group number of the assigned first general register.
[0026] In the above solution, the determining the general register allocated to the target task includes:
[0027] According to the relationship between the number of the target task and N, the general register allocated to the target task is determined.
[0028] In the above solution, the processor is further configured with a setting register, and the method further includes:
[0029] The register group number corresponding to the general register allocated to the target task is written into the setting register.
[0030] A multi-task switching device is applied to a processor, wherein the processor is configured with N groups of first general registers, each group of the first general registers is used to be assigned to a task, wherein N is an integer greater than 1, and the device comprises:
[0031] A processing module, configured to, upon receiving a task switching request, store the context of a currently executing task in a first general register allocated to the currently executing task, and determine a target task of the task switching request;
[0032] An execution module is used to obtain the context of the target task stored in the first general register allocated to the target task, and execute the target task.
[0033] An embedded system includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps of the multi-task switching method are implemented.
[0034] A computer-readable storage medium stores a computer program, which implements the steps of the multi-task switching method when executed by a processor.
[0035] The above-mentioned multi-task switching method, device, embedded system and medium propose an architecture of multiple groups of first general registers on the processor hardware, and assign each group of first general registers to a task, so that the first general register is occupied by a task alone. Therefore, when a task switching request is received, the context of the currently executing task can be stored in the first general register assigned to the currently executing task, and there is no need to additionally store the context of the currently executing task. Therefore, the general register of the processor can be directly switched to the first general register assigned to the target task, and the context of the target task can be obtained from the first general register assigned to the target task. No context migration operation is required during the entire task switching process, thereby improving the scheduling efficiency of task switching and the running speed of the system software. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 A schematic diagram of a hardware architecture for multi-task context switching in the related art;
[0037] Figure 2 A schematic diagram of a process flow of context switching in the related art;
[0038] Figure 3 A schematic diagram of a hardware architecture in an embodiment;
[0039] Figure 4 is a flowchart of a multi-task switching method in an embodiment;
[0040] Figure 5 is a schematic diagram of a first multi-task switching method in an embodiment;
[0041] Figure 6 A schematic diagram of a context processing flow for obtaining a target task in one embodiment;
[0042] Figure 7 A schematic diagram of a context storage process of a currently executed task in one embodiment;
[0043] Figure 8 is a schematic diagram of a second multi-task switching method in an embodiment;
[0044] Fig. 9 is a schematic diagram of a third task switching method in an embodiment;
[0045] Fig.10 FIG. 4 is a structural block diagram of a multi-task switching device in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0047] The implementation details of the technical solution of the embodiment of the present invention are described in detail below.
[0048] Figure 3 FIG. 1 shows a schematic diagram of the hardware architecture of this embodiment. N groups of first general registers are introduced into the processor hardware, wherein each group of first general registers is used to be assigned to a task, so that each group of first general registers corresponds to a different task. Figure 3 As shown, the first general register group 1 is allocated to task 1, and the first general register group 2 is allocated to task 2. In this way, each group of first general registers can be allocated to a task, and the first general registers allocated to a task do not need to be shared with other tasks, and the context of the task can be directly saved.
[0049] Considering that due to the limitation of hardware resources, it is impossible to provide an unlimited number of first general registers. If the number of tasks applied by the system exceeds N, it is impossible to allocate a corresponding first general register to each task. Based on this, a set of special second general registers is also configured in the processor hardware. The second general registers can be considered as a backup of the conventional processor general registers. The second general registers here are used to allocate to multiple tasks for common use and are used as data transfer stations. Figure 3 As shown, task X (X is greater than N) and task Y (Y>N) use the second general register in common.
[0050] exist Figure 3 The processor is configured with both N groups of first general registers and one group of second general registers, so that when hardware resources are limited, general registers for processing contexts can be provided for each task, which is suitable for all application scenarios of multi-task switching.
[0051] In addition, Figure 3 The processor in is also configured with a setting register, which is used to save the group number of the general register currently being used by the processor, which can help the processor identify the general register group currently being used, so that the processor can identify and quickly access the corresponding general register.
[0052] exist Figure 3 Based on the hardware architecture shown in FIG. , a multi-task switching method applied to a processor is provided, such as Figure 4 As shown, Figure 4 A schematic flow chart of a multi-task switching method is shown, and the method may include the following steps:
[0053] Step S401, when a task switching request is received, determining a target task of the task switching request.
[0054] The task switching request may be triggered by an interrupt, a timer event, a system call, etc. When a task switching request is received, the context of the currently executing task needs to be saved first to prevent the context of the currently executing task from being lost.
[0055] It should be noted that the first general register allocated to the currently executing task is dedicated to the currently executing task, and other tasks cannot use the first general register allocated to the currently executing task, so that the first general register can isolate the context of the currently executing task from the context of other tasks, and the context stored in the first general register will not be affected by the running of other tasks, so that the currently executing task has an independent first general register for context storage of the currently executing task. Therefore, when a task switching request is received, the context of the currently executing task has been stored in the first general register allocated to the currently executing task without the need for additional storage operations, because in the process of executing the currently executing task, the general register of the processor is the first general register allocated to the executing task, and the context has been written into the first general register allocated to the currently executing task during the execution of the current task.
[0056] Based on this, when a task switching request is received, the processor can directly determine the next target task to be executed according to the task scheduling algorithm and strategy. This target task can be the task with the highest priority, the task with the longest waiting time, the task with the rotation time slice, etc.
[0057] Step S402: switch the general register of the processor to the first general register allocated to the target task, obtain the context of the target task stored in the first general register allocated to the target task, and execute the target task.
[0058] After determining the target task, it is necessary to read the context of the target task to restore the execution state of the target task so that the target task can continue to execute from where it was last interrupted without losing any important information.
[0059] The target task is also assigned a set of first general registers, which are dedicated to the target task and used to save the context of the target task. Based on this, by switching the general registers of the processor to the first general registers assigned to the target task, the context of the target task can be directly obtained from the first general registers assigned to the target task, and the execution environment of the target task can be restored according to the context of the target task, so that the target task can be executed from the interrupted place.
[0060] The following takes the switching process between task 1 and task 2 as an example to illustrate. Figure 5 As shown, Figure 5 A schematic diagram of the first multi-task switching mode is shown, wherein task 1 corresponds to the currently executed task mentioned above, and task 2 corresponds to the target task mentioned above.
[0061] During the execution of Task 1 , the processor is currently using the first general register 1 , and the context 1 of Task 1 is directly stored in the first general register 1 .
[0062] When receiving the notification that task 2 needs to be executed, context 1 of task 1 has been stored in first general register 1, and no additional saving operation is required. The first general register 1 currently being used by the processor can be directly switched to the first general register 2, so that context 2 of task 2 can be read from the first general register 2.
[0063] exist Figure 5 In the example, the group number of the first general register corresponding to task 2 is written into the setting register, and the current valid group number in the setting register is modified to 2, thereby switching the general register currently being used by the processor.
[0064] After reading the context of Task 2, the processor starts execution of Task 2.
[0065] Based on this, in the process of switching from task 1 to task 2, the context switch of the task is only achieved by switching the general register currently being used by the processor.
[0066] In the above multi-task switching process, since both the currently executed task and the target task have a set of dedicated first general registers for storing their own context data, when switching tasks, no excessive context data movement processing is required, which greatly improves the task execution efficiency.
[0067] In one embodiment, reference Figure 3 ,The processor is also configured with a set of second general purpose registers, such as Figure 6 As shown, Figure 6 A schematic diagram of the context processing flow for obtaining a target task is shown.
[0068] Step S601, determining the general register allocated to the target task.
[0069] Step S602: if the general register allocated to the target task is the first general register, then obtaining the context of the target task stored in the first general register allocated to the target task, and executing the target task.
[0070] Step S603, if the general register allocated to the target task is the second general register, write the context of the target task from the private storage area of the target task to the second general register, switch the general register of the processor to the second general register allocated to the target task, obtain the context of the target task from the second general register, and execute the target task.
[0071] In practical applications, hardware resources are limited and cannot provide enough first general registers to allocate to each task. In this case, some tasks are allocated task-specific first general registers, and some tasks are allocated second general registers shared by multiple tasks.
[0072] It can be understood that the first general register is dedicated to one task, while the second general register is commonly used by multiple tasks. Due to the different usage properties of the first general register and the second general register, the way to obtain the context of the target task also changes.
[0073] Based on this, it is necessary to determine the general registers allocated to the target task. The general registers allocated to the target task can be determined in a variety of ways. For example, in one implementation, a general register allocation table is maintained, and the general registers allocated to each task are recorded in the table, so that the general registers allocated to the target task can be determined by searching the general register allocation table.
[0074] Based on the general registers allocated to the target task, there are two results:
[0075] (1) The general register allocated to the target task is the first general register.
[0076] In this case, the first general register is only used by the target task, and the first general register also holds the context of the target task. Based on this, the general register of the processor can be switched to the first general register assigned to the target task, thereby directly performing a read operation on the first general register assigned to the target task. The context of the target task can be directly read from the first general register, and the target task can be executed.
[0077] (2) The general register allocated to the target task is the second general register.
[0078] In this case, the second general register cannot save the context of the target task, that is, the context of the target task is stored in other locations instead of the second general register, so the context of the target task cannot be directly read from the second general register.
[0079] In actual applications, the context of the target task is stored in the private storage area of the target task. It is necessary to write the context of the target task from the private storage area of the target task to the second general register by means of data migration, and then switch the general register of the processor to the second general register allocated to the target task, so that the context of the target task can be obtained from the second general register. In this process, the second general register plays a role of data transfer. By moving the context to the second general register, the processor can read the context of the target task from the second general register, thereby restoring the execution environment of the target task and starting the execution of the target task.
[0080] In one embodiment, Figure 7 As shown, Figure 7 A schematic diagram of the context storage process of the currently executed task is shown.
[0081] Step S701, determining the general register allocated to the currently executed task.
[0082] Step S702: If the general register allocated to the currently executing task is the second general register, the context of the currently executing task is written from the second general register to the private storage area of the currently executing task.
[0083] In this embodiment, due to the different usage properties of the first general register and the second general register, the way to store the context of the currently executed task will also change accordingly.
[0084] Based on this, it is necessary to judge the general register allocated to the currently executed task to determine whether the currently executed task is allocated to the first general register or the second general register.
[0085] Based on the general registers assigned to the currently executed task, there are two results:
[0086] (1) The general register assigned to the currently executed task is the first general register.
[0087] In this case, the first general register is used solely for the currently executing task and can be used to save the context of the currently executing task. Based on this, when the general register allocated to the currently executing task is the first general register, the first general register has already stored the context of the currently executing task, and there is no need to perform additional storage operations on the context of the currently executing task.
[0088] (2) The general register allocated to the currently executed task is the second general register.
[0089] In this case, the second general register is used by the currently executing task and other tasks, and the second general register temporarily stores the context of the currently executing task. If the context of the currently executing task is directly retained in the second general register, it will be overwritten by the context of other tasks using the second general register, resulting in the loss of the context of the currently executing task and the inability to restore the execution environment of the currently executing task.
[0090] Based on this, in this case, the context of the currently executing task is written from the second general register to the private storage area of the currently executing task, wherein the private storage area refers to a memory area used independently by the target task.
[0091] The following describes the context switching method in hybrid multi-tasking scheduling through two specific application scenarios.
[0092] Take Task 1 and Task X as an example. Figure 8 As shown, Figure 8 A schematic diagram of a second multi-task switching method is shown, wherein task 1 corresponds to the currently executed task mentioned above, and task X corresponds to the target task mentioned above.
[0093] During the execution of Task 1, the group number in the register is set to 1, indicating that the processor is currently using the first general register 1, and the context 1 associated with Task 1 is directly stored in the first general register 1. Based on this, when receiving a notification that Task X needs to be executed, there is no need to perform an additional storage operation on the context 1 associated with Task 1.
[0094] Among them, the general register allocated to task X is the second general register 0. In order to enable the processor to read the context X of task X, it is first necessary to write the context X of task X from the private storage area of task X into the second general register 0. At this time, the group number in the setting register is modified to 0, and the general register of the processor is switched from the first general register 1 to the second general register 0, that is, the current effective general register group number is 0, and the processor can access the second general register 0, and read the context X of task X in the second general register 0, and start the execution of task X.
[0095] Based on this, in the process of switching from task 1 to task X, the task context switch only needs to load the context of task X into the second general register 0, without requiring excessive context data movement processing, thereby greatly improving the task execution efficiency.
[0096] like Fig. 9 As shown, Fig. 9 A schematic diagram of a third multi-task switching method is shown, wherein task X corresponds to the currently executed task mentioned above, and task 1 corresponds to the target task mentioned above.
[0097] During the execution of task X, the group number in the register is set to 0, indicating that the processor is currently using the second general register 0, and the context X related to task X is temporarily stored in the second general register 0.
[0098] When a notification that task 1 needs to be executed is received, the context X of task X is written from the second general register 0 to the private storage area of task X, so as to store the context X of task X.
[0099] Then, task 1 is started to be executed. At this time, the group number in the register is set to 1. The processor is currently using the first general register 1, so that the context 1 of task 1 in the first general register 1 can be read.
[0100] Based on this, in the process of switching from task X to task 1, the context switch of the task only needs to save the context of task X, and does not require excessive context data movement processing, which greatly improves the task execution efficiency.
[0101] In practical applications, corresponding general registers are allocated to tasks in advance. In one embodiment, the allocation method used is to allocate general registers according to the number of tasks to be allocated. This allocation method is described in detail below.
[0102] In the process of allocating corresponding general registers to the tasks to be assigned, it is necessary to consider the size relationship between the number of tasks to be assigned and N. If the number of tasks to be assigned is greater than N, it means that the number of first general registers configured by the processor is insufficient, and it is impossible to allocate corresponding first general registers to each task to be assigned. In this case, N of the tasks to be assigned are allocated corresponding first general registers, and the remaining tasks to be assigned use the second general registers together.
[0103] If the number of tasks to be assigned is less than or equal to N, it indicates that the number of first general registers configured for the processor is sufficient, and a corresponding first general register can be assigned to each task to be assigned.
[0104] In one embodiment, in the process of allocating the first general register, the first general register can be allocated in sequence according to the number of the task to be allocated, so that the encoding of the task to be allocated is the same as the grouping number of the first general register allocated to the task to be allocated, that is, the first general register 1 is allocated to task 1, the second general register 2 is allocated to task 2, and so on.
[0105] In another allocation method, the corresponding general registers may be allocated according to the priority of the task to be allocated, wherein the first general register is allocated to the task to be allocated with a high priority, and the second general register is allocated to the task to be allocated with a low priority.
[0106] In one embodiment, if the first general register is allocated according to the number of the task to be allocated, when judging the general register allocated to the target task, the general register allocated to the target task can be directly determined according to the number of the target task, wherein if the number of the target task is less than or equal to N, the first general register is allocated to the target task, and if the number of the target task is greater than N, the second general register is allocated to the target task.
[0107] Similarly, when determining the general register assigned to the currently executing task, the assigned general register can also be determined based on the number of the currently executing task. If the code of the currently executing task is less than or equal to N, then the currently executing task is assigned the first general register; if the number of the currently executing task is greater than N, then the currently executing task is assigned the second general register.
[0108] In one embodiment, Figure 3 The processor in is also configured with a setting register, which is used to save the general register group number currently used by the processor, that is, the effective general register group number, which can help the processor hardware identify the general register currently in use.
[0109] Based on this, when obtaining the context of the target task, the group number corresponding to the general register assigned to the target task is written into the setting register, so that the processor can identify and quickly access the corresponding general register through the group number recorded in the setting register, and read the context of the target task from the general register.
[0110] For example, assuming that the general register assigned to the target task is the first general register 1, after saving the context of the currently executed task, the group number corresponding to the first general register 1 assigned to the target task is written into the setting register, that is, the current valid general register group number is modified to 1. The processor can access the first general register 1 according to the group number recorded in the setting register, and obtain the context of the target task stored in the first general register 1.
[0111] Similarly, assuming that the general register assigned to the target task is the second general register 0, after saving the context of the currently executed task, the context of the target task is written from the private storage area of the target task to the second general register 0, and the group number corresponding to the second general register 0 is written to the setting register, that is, the current effective general register group number is modified to 0. The processor can access the second general register 0 according to the group number recorded in the setting register, and obtain the context of the target task in the second general register 0.
[0112] It should be noted that before the group number in the setting register is modified, the group number in the setting register is the group number corresponding to the general register allocated to the task being executed.
[0113] In the above embodiment, by adding general register grouping to the processor, a first general register for dedicated context storage is provided for each task, so that during the task switching process, the context of the currently executing task can be directly saved to the corresponding first general register, and at the same time, the context of the target task can be obtained from the first general register allocated to the target task, thereby shortening the software data movement execution time during task switching, optimizing the context switching time, and improving the efficiency of task scheduling, thereby improving the execution efficiency of the entire system task.
[0114] In one embodiment, a multi-task switching device is provided, referring to Fig.10 As shown, the multi-task switching device 1000 is applied to a processor, and the processor is configured with N groups of first general registers, each group of first general registers is used to be assigned to a task, where N is an integer greater than 1. The multi-task switching device 1000 may include: a processing module 1001, an execution module 1002 and an allocation module 1003.
[0115] The processing module 1001 is used to determine the target task of the task switching request when receiving the task switching request;
[0116] The execution module 1002 is used to switch the general register of the processor to the first general register allocated to the target task, obtain the context of the target task stored in the first general register allocated to the target task, and execute the target task.
[0117] In one embodiment, the processor is further configured with a set of second general registers, and the execution module 1002 is further used to determine the general registers allocated to the target task;
[0118] If the general register allocated to the target task is the first general register, executing the step of acquiring the context of the target task stored in the first general register allocated to the target task;
[0119] If the general register assigned to the target task is the second general register, the context of the target task is written from the private storage area of the target task to the second general register, the general register of the processor is switched to the second general register assigned to the target task, the context of the target task is obtained from the second general register, and the target task is executed.
[0120] In one embodiment, the processing module 1001 is further used to determine the general register allocated to the currently executed task;
[0121] If the general register allocated to the currently executing task is the second general register, the context of the currently executing task is written from the second general register to the private storage area of the currently executing task.
[0122] In one embodiment, the multi-task switching device 1000 further includes an allocation module 1003 for obtaining the number of tasks to be allocated;
[0123] If the number is greater than N, corresponding first general registers are allocated to N different tasks to be allocated, and second general registers are allocated to the remaining tasks to be allocated;
[0124] If the number is less than or equal to N, a corresponding first general register is allocated to each task to be allocated.
[0125] In one embodiment, the allocation module 1003 is specifically used to allocate the first general register to the task to be allocated according to the number of the task to be allocated; the task number is the same as the register group number of the allocated first general register.
[0126] In one embodiment, the execution module 1001 is specifically configured to determine the general register allocated to the target task according to the relationship between the number of the target task and N.
[0127] In one embodiment, the processor is further configured with a setting register, and the execution module 1001 is further configured to write the register group number corresponding to the general register allocated to the target task into the setting register.
[0128] For the specific definition of the multi-task switching device 1000, please refer to the definition of the multi-task switching method above, which will not be repeated here. Each module in the above-mentioned multi-task switching device 1000 can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0129] In one embodiment, an embedded system is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements a multi-task switching method when executing the computer program.
[0130] In one embodiment, a computer storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, a multi-task switching method is implemented.
[0131] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A multi-task switching method, It is characterized in that Applied to a processor, the processor is configured with N groups of first general registers, each group of the first general registers is used to be assigned to a task to automatically save the context data of the task when the task is switched, and is dedicated to the assigned task, wherein N is an integer greater than 1, and the method includes: Upon receiving a task switching request, determining a target task of the task switching request; Switching the general register of the processor to the first general register assigned to the target task, acquiring the context of the target task stored in the first general register assigned to the target task, and executing the target task; wherein, The processor is further configured with a set of second general registers, and the method further comprises: Determining the general register allocated to the target task; If the general register allocated to the target task is the first general register, performing the step of obtaining the context of the target task stored in the first general register allocated to the target task; If the general register assigned to the target task is the second general register, the context of the target task is written from the private storage area of the target task to the second general register, the general register of the processor is switched to the second general register assigned to the target task, the context of the target task is obtained from the second general register, and the target task is executed.
2. The multi-task switching method according to claim 1, It is characterized in that The method further comprises: Determine the general register assigned to the currently executed task; If the general register allocated to the currently executing task is the second general register, the context of the currently executing task is written from the second general register to the private storage area of the currently executing task.
3. The multi-task switching method according to claim 1, It is characterized in that The method further comprises: Get the number of tasks to be assigned; If the number is greater than N, the first general registers corresponding to the N different tasks to be assigned are assigned, and the second general registers are assigned to the remaining tasks to be assigned; If the number is less than or equal to N, the first general register corresponding to each task to be assigned is allocated.
4. The multi-task switching method according to claim 3, It is characterized in that Allocating the first general register corresponding to the task to be assigned includes: According to the number of the task to be assigned, the first general register of the task to be assigned is allocated; the number of the task is the same as the register group number of the assigned first general register.
5. The multi-task switching method according to claim 3, It is characterized in that The determining of the general register allocated to the target task includes: According to the relationship between the number of the target task and N, the general register allocated to the target task is determined.
6. The multi-task switching method according to claim 1, It is characterized in that The processor is also configured with a setting register, and the method further includes: The register group number corresponding to the general register allocated to the target task is written into the setting register.
7. A multi-task switching device, It is characterized in that Applied to a processor, the processor is configured with N groups of first general registers, each group of the first general registers is used to be assigned to a task to automatically save the context data of the task when the task is switched, and is dedicated to the assigned task, wherein N is an integer greater than 1, and the device comprises: A processing module, configured to determine a target task of the task switching request upon receiving the task switching request; an execution module, configured to switch a general register of a processor to a first general register assigned to the target task, obtain a context of the target task stored in the first general register assigned to the target task, and execute the target task; wherein, The processor is further configured with a set of second general registers, and the execution module is further configured to: Determining the general register allocated to the target task; If the general register allocated to the target task is the first general register, performing the step of obtaining the context of the target task stored in the first general register allocated to the target task; If the general register assigned to the target task is the second general register, the context of the target task is written from the private storage area of the target task to the second general register, the general register of the processor is switched to the second general register assigned to the target task, the context of the target task is obtained from the second general register, and the target task is executed.
8. An embedded system comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the multi-task switching method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the multi-task switching method according to any one of claims 1 to 6 are implemented.
