A task switching method, device, equipment and storage medium

By only backing up and restoring the required register data in the CPU, using special register identification and address generation units, the storage resource and time occupancy problems during task switching are solved, and CPU performance is improved.

CN114741237BActive Publication Date: 2024-11-01GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210417383.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-20
Publication Date
2024-11-01
Estimated Expiration
2042-04-20

AI Technical Summary

Technical Problem

Existing CPUs need to go through five-level pipelines when switching tasks, resulting in excessive storage resources and processing time consuming and reducing CPU performance.

Method used

Provides a task switching method, by only backing up and restoring the required register data in the register file, and using special register identification and address generation units to realize selective backup and restore, reducing storage resources and time overhead.

Benefits of technology

Save storage resources and time overhead, reduce performance losses caused by backup and restore, and improve CPU processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114741237B_ABST
    Figure CN114741237B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a task switching method, device, equipment and storage medium, the method comprising: executing a first task; when triggering a task switch, backing up the first task data stored in the first register in the register file to the first storage unit; executing the second task; determining that the execution of the second task is finished, restoring the first task data in the first storage unit to the first register in the register file; reading the first task data from the register file, and continuing to execute the first task. In this way, when switching from the first task to the second task, there is no need to add backup and restore instructions in the code, and the first register for the second task to perform a write operation is determined in the instruction decoding stage, and only the first task data in the first register is backed up, so as to realize a selective backup of the register data. Similarly, when restoring, only the data of the first register is restored, which saves the use of storage resources. It also saves the time overhead of executing instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to computer technology, and in particular to a task switching method, device, equipment and storage medium. Background Art

[0002] At present, the central processing unit (CPU) is a typical von Neumann structure, which uses pipelines to improve the resource utilization of the CPU, such as Figure 1 As shown, ideally the CPU uses a five-stage pipeline to perform five tasks, namely, instruction fetch (IF) - instruction decode (ID) - instruction execute (IE) - memory read and write (MEM) - write back.

[0003] In terms of multi-threaded scheduling, the thread switching process needs to go through five levels of pipelines for data backup, that is, all the data of the current thread is backed up to other storage units, then jump to the thread to be processed, run the thread, and restore the previously backed up data after the thread is finished. This method will take up too much storage resources and processing time, not only increasing the chip area, but also reducing CPU performance. Summary of the invention

[0004] In order to solve the above technical problems, the embodiments of the present application hope to provide a task switching method, device, equipment and storage medium.

[0005] The technical solution of this application is implemented as follows:

[0006] In a first aspect, a task switching method is provided, comprising:

[0007] Execute the first task;

[0008] When a task switch is triggered, the first task data stored in the first register in the register file is backed up to the first storage unit; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up;

[0009] Perform the second task;

[0010] Determining that the execution of the second task is completed, restoring the first task data in the first storage unit to the first register in the register file;

[0011] The first task data is read from the register file, and the first task is continued to be executed.

[0012] In a second aspect, a task switching device is provided, which is applied to a processor of an electronic device to implement task switching. The task switching device can implement the functions of multiple units through software, hardware, or a combination of software and hardware, so that the device can execute the task switching method provided in any one of the first aspects above. The effects of each technical solution in the second aspect can refer to the corresponding technical solution in the first aspect, and this application will not repeat them one by one.

[0013] The device comprises:

[0014] An execution unit, configured to execute a first task;

[0015] A backup unit, used for backing up the first task data stored in the first register in the register file to the first storage unit when triggering task switching; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up;

[0016] The execution unit is further used to execute a second task;

[0017] a restoring unit, configured to determine that the execution of the second task is finished, and restore the first task data in the first storage unit to the first register in the register file;

[0018] The execution unit is further configured to read the first task data from the register file and continue to execute the first task.

[0019] In a third aspect, an electronic device is provided, the electronic device comprising: a processor and a memory configured to store a computer program that can be run on the processor, and a register file including a plurality of registers, the memory including a plurality of storage units for backing up register data;

[0020] Wherein, the processor is configured to execute the steps of the aforementioned method when running the computer program.

[0021] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, wherein the computer program implements the steps of the aforementioned method when executed by a processor.

[0022] By adopting the above technical solution, when switching from the first task to the second task, there is no need to add backup and restore instructions in the code. In the instruction decoding stage, the first register for the second task to perform the write operation is determined, and only the first task data in the first register is backed up, so as to achieve selective backup of the register data. Similarly, when restoring, only the data of the first register is restored, which saves the storage resource usage. It also saves the time cost of executing instructions. Overall, it reduces the storage resource usage and time cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 This is a schematic diagram of the workflow of a typical CPU five-stage pipeline;

[0024] Figure 2 This is a schematic diagram of a first process flow of a task switching method in an embodiment of the present application;

[0025] Figure 3 This is a schematic diagram of the data structure of the first special register in the embodiment of the present application;

[0026] Figure 4 This is a schematic diagram of the data structure of the second special register in the embodiment of the present application;

[0027] Figure 5 Schematic diagram of the hardware structure of the task switching method in the embodiment of the present application;

[0028] Figure 6 This is a second flow chart of the task switching method in an embodiment of the present application;

[0029] Figure 7 This is a schematic diagram of the composition structure of the task switching device in the embodiment of the present application;

[0030] Figure 8 It is a schematic diagram of the composition structure of the electronic device in the embodiment of the present application. DETAILED DESCRIPTION

[0031] In order to enable a more detailed understanding of the features and technical contents of the embodiments of the present application, the implementation of the embodiments of the present application is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present application.

[0032] The present application embodiment provides a task switching method. Figure 2 FIG. 1 is a first flow chart of the task switching method in the embodiment of the present application. Figure 2 As shown, the method may specifically include:

[0033] Step 201: Execute the first task;

[0034] Here, the first task can be understood as the task currently being executed by the processor. The processor reads the first task data from the register in the register file and executes the first task.

[0035] For example, a task can be a thread, a process or an interrupt program. A thread is the basic unit of task switching and execution in the operating system. A thread is the smallest unit for executing operations in a process. It is an entity in a process and a basic unit that is independently scheduled and dispatched by the system. A thread itself does not own system resources, but only has a few resources that are essential for operation. However, it can share all the resources owned by the process with other threads belonging to the same process.

[0036] That is to say, the task switching method provided in the embodiment of the present application can realize switching between threads, switching between processes, switching between threads and interrupt programs, or switching between processes and interrupt programs.

[0037] Step 202: when a task switch is triggered, backing up first task data stored in a first register in a register file to a first storage unit; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up;

[0038] Here, when the first task is currently being executed, the processor schedules the execution of the second task to trigger switching, stops executing the first task, and switches to executing the second task, where the second task may be an interrupt program or another thread.

[0039] The first register may also be a register for the second task to perform write operations. Specifically, the method further includes: when triggering task switching, determining the register for the second task to perform write operations in the instruction decoding stage; and determining the first register according to the register for the second task to perform write operations.

[0040] It is understandable that after the task switch is triggered, in the instruction decoding stage, it is determined which registers in the register file the second task performs a write operation on, and these registers are defined as first registers. Before performing a write operation on the first register, the first task data in the first register is backed up first, and then the write operation is performed on the first register to avoid the loss of the first task data when the second task is executed. It is understandable that in the embodiment of the present application, the priority of the backup operation on the first register is higher than the priority of the write operation on the first register. Here, the backup operation can be understood as a read operation. If the current instruction is a write operation, then the backup operation is performed first, and then the write operation is performed.

[0041] The register file includes multiple registers for storing task data. When the processor performs task switching, it selectively backs up the register data in the register file. In some cases, only some registers need to be backed up, and not all registers. Similarly, when restoring, only some registers are restored, saving storage resources.

[0042] Exemplarily, in some embodiments, determining the first register based on the register on which the second task performs a write operation includes: determining that the register on which the second task performs a write operation has not been backed up, and backing up data of the register on which the second task performs a write operation as the first register.

[0043] That is to say, when executing the second task, after determining the register for the write operation of the second task, it is also necessary to determine whether the register has been backed up. If not, back it up again; otherwise, no backup is required.

[0044] Exemplarily, in some embodiments, the method further comprises: setting a backup flag of the first register in a first special register, wherein the first special register comprises the backup flags of the plurality of registers in the register file. That is, whether the register data has been backed up can be identified by setting the first special register.

[0045] Exemplarily, in some embodiments, the setting of the backup identifier of the first register in the first special register includes: determining the first storage position of the backup identifier of the first register in the first special register according to a preset first mapping relationship; and setting the backup identifier of the first register in the first special register to a backed-up state according to the first storage position. Here, the first mapping relationship includes a mapping relationship between a register identifier and a backup identifier storage position.

[0046] For example, Figure 3 As shown, a first special register ① is defined to mark the backup status of each register in the register file (Register File, RF). This backup status indicates whether the current register has been backed up. For example, assuming that there are 32 32-bit registers in the Register File, REG0 to REG31, and the maximum number of threads currently supported is 2, then a first special register ① can be defined with a bit width of 32 bits, where each bit is used to represent the status of each 32-bit register in the register file. If register 0 (REG0) has been backed up, the 0th bit corresponding to REG0 in the 32-bit first special register ① is 1, otherwise it is 0.

[0047] When the maximum number of threads currently supported is greater than 2, multiple first special registers ① can be defined for switching between different threads, or one first special register ①, but multiple bits of one first special register ① need to be grouped and used to distinguish different threads through a mapping table. Assuming that there are 32 32-bit registers in the Register File, REG0 to REG31, and the maximum number of threads currently supported is 3, three first special registers ① can be defined, one first special register ① has a bit width of 32 bits, or one first special register ① has a bit width of 96 bits.

[0048] Exemplarily, in some embodiments, a logical operation is performed based on the backup base address and the identifier of the first register to generate the address of the first storage unit. Here, the backup base address can be understood as the base address of the memory space used to store the backup data. The processor can configure a portion of storage resources in the memory space for backing up the previous task data.

[0049] Specifically, a logical operation is performed on the backup base address and the identifier of the first register to obtain the address of the first storage unit. Exemplarily, the logical operation can be concatenation, addition, subtraction, or other operations. Exemplarily, the identifier of the first register can be 0, 1, 2, ..., N, and the identifier of the first register can be regarded as an address offset. The backup base address and the address offset are added to obtain the address of the first storage unit corresponding to the first register.

[0050] Exemplarily, the backup base address may be a fixed base address or may be flexibly configured by the processor. Exemplarily, the backup base address is configured in a third special register. That is, a third special register may be defined to configure the base address. Exemplarily, the third special register ③ records a backup base address, or multiple backup base addresses, and different threads correspond to a backup base address. Alternatively, multiple third special registers ③ are set to respectively record a backup base address corresponding to a thread.

[0051] Exemplarily, the method further includes: when triggering task switching, setting a state flag in a second special register for indicating switching from the first task to the second task, determining that the second task is finished executing, and determining to restore the second task to the first task based on the state flag in the second special register for indicating switching from the first task to the second task. That is, the second special register includes a state flag for indicating switching from a source task to a target task.

[0052] Exemplarily, the method further includes: after determining to restore the second task to the first task, restoring the state flag in the second special register for indicating switching from the first task to the second task.

[0053] Here, a second special register ② is defined, and the status flag of the second special register is used to indicate whether the currently executed first task has been switched to the second task. Exemplarily, the maximum number of threads currently supported is 2, and the second special register ② contains 1 bit. When the bit is high, it indicates that the currently executed first task has switched to the second task. When the maximum number of threads currently supported is greater than 2, a second special register ② can be defined, and a mapping table can be used to distinguish different threads, or the high bit of the second special register ② can be used to indicate the currently executed first task, and the high bit of the second special register ② can be used to indicate switching to the second task. When the maximum number of threads currently supported is greater than 2, multiple second special registers ② can be defined for switching between different threads.

[0054] For example, Figure 4 As shown, assuming that the maximum number of threads currently supported is 4, four second special registers ② are set, each thread corresponds to a second special register ②, and the bit width of each second special register ② is 2. Taking the second special register ② corresponding to thread 1 as an example, 00 indicates no switching, 01 indicates switching from thread 1 to thread 2, 10 indicates switching from thread 1 to thread 3, and 11 indicates switching from thread 1 to thread 4.

[0055] Step 203: Execute the second task;

[0056] Exemplarily, in some embodiments, after backing up the first task data stored in the first register in the register file to the first storage unit, the method further includes: writing the second task data into the first register, reading the second task data from the first register, and executing the second task.

[0057] Step 204: Determine that the execution of the second task is completed, and restore the first task data in the first storage unit to the first register in the register file;

[0058] Exemplarily, in some embodiments, when the last instruction of the second task is executed, it is determined that the execution of the second task is finished. Exemplarily, the last instruction is a return instruction ret instruction.

[0059] Exemplarily, when a first special register is set to identify the backup status of each register in a register file, the step of determining that the second task is finished and restoring the first task data in the first storage unit to the first register in the register file includes: determining that the second task is finished and determining the first register according to the backup identifier in the first special register; and restoring the first task data in the first storage unit to the first register in the register file. Figure 3As shown, the backed-up register is determined according to each bit of the first special register ① of 32 bits in width.

[0060] When performing the restore operation, in the embodiment of the present application, the restore operation on the first register has a higher priority than the read operation on the first register. Here, the restore operation can be understood as a write operation. If the current instruction is a read operation, the restore operation is performed first, and then the read operation is performed.

[0061] Exemplarily, in some embodiments, the method further includes: after restoring the first task data in the first storage unit to the first register in the register file, restoring the backup identifier of the first register in the first special register.

[0062] That is to say, after the data of the first register is restored, the backup flag of the first register in the first special register needs to be restored from the backed-up state to the unbacked-up state. Figure 3 As shown, the bit in the first special register ① is restored from 1 to 0.

[0063] Exemplarily, in some embodiments, restoring the first task data in the first storage unit to the first register in the register file includes: performing a logical operation based on a backup base address and an identifier of the first register to generate an address of the first storage unit; and based on the address of the first storage unit, reading the first task data from the first storage unit and writing it back to the first register.

[0064] Specifically, a logical operation is performed on the backup base address and the identifier of the first register to obtain the address of the first storage unit. Exemplarily, the logical operation can be concatenation, addition, subtraction, or other operations. Exemplarily, the identifier of the first register can be a register identifier such as 0, 1, 2, ..., N, or a register address. The identifier of the first register can be an address offset, and the backup base address and the address offset are added to obtain the address of the first storage unit corresponding to the first register.

[0065] Step 205: Read the first task data from the register file and continue to execute the first task.

[0066] Here, when the data of the first register is completely restored, the first task data is read from the first register and other registers in the register file, and the first task is continued to be executed. The other registers are registers in the register file that have not been backed up.

[0067] By adopting the above technical solution, when switching from the first task to the second task, there is no need to add backup and restore instructions in the code. In the instruction decoding stage, the first register for the second task to perform the write operation is determined, and only the first task data in the first register is backed up, so as to achieve selective backup of the register data. Similarly, when restoring, only the data of the first register is restored, which saves the storage resources. There is no need to add new backup and restore instructions to the code segment for on-site maintenance, and the backup operation is compatible with the original five-stage pipeline, and only three stages of pipeline (i.e., execution, memory access and write back) need to be executed to successfully complete the backup and restore operations, which greatly reduces the performance loss caused by backup and restore, and saves the time overhead of executing instructions.

[0068] Figure 5 FIG. 1 is a schematic diagram of the hardware structure of the task switching method in the embodiment of the present application. Figure 5 As shown, three special registers and an address generation unit are added to the existing processor five-stage pipeline architecture.

[0069] 1. The first special register ① is used to mark the status of each register in the Register File. This status indicates whether the current register has been backed up. Figure 2 As shown, assuming that there are 32 32-bit registers in the Register File and the maximum number of threads currently supported is 2, we can define a special register with a bit width of 32 bits, where each bit is used to represent the status of each 32-bit register in the register file. If the current register has been backed up, the corresponding bit of the 32-bit special register is 1, otherwise it is 0.

[0070] 2. The second special register ② is used to record the thread running status, wherein the status flag is used to indicate whether the currently executing first task has been switched to the second task.

[0071] 3. The third special register ③ is used for the backup base address. This address is used to back up certain register data when the thread is switched or the interruption site is maintained. It can be configured through the control register (Control and Status Register, CSR).

[0072] 4. Define the hardware components. The hardware is divided into two parts. One part is used for backup operation, which is equivalent to the store instruction, but does not need to go through the five-stage pipeline unit, because the base address is defined in the third special register ③. It only needs to use the address generation unit to generate the destination address in the MEM stage to perform the backup operation without affecting the original pipeline execution mode. The other part is the on-site restoration unit, which is equivalent to the load instruction. It is also the same as the backup operation process. It only needs to use the address generation unit to generate the destination address in the MEM stage to perform the restoration operation. However, if the previously backed-up data is used in the ID stage, it is necessary to wait until the load operation is completed before continuing to the next step (or through the optimization of the pipeline stack, start the load operation in advance to prevent the pipeline stack from being stalled).

[0073] like Figure 5 As shown, special registers are added in the instruction decoding stage (ID stage), including the first special register ①, the second special register ② and the third special register ③, which are used to store the backup identification, the running status and the base address. An address generation unit is added in the execution stage (EX stage) to generate the target address of the storage unit during backup and restoration. When the current instruction determines to perform a write operation on the target register RD, it is determined to perform a backup operation on the target register RD according to the backup identification of the first special register ①, and the backup operation is performed first, and then the write operation is performed. When the current instruction determines to perform a read operation on the two registers RS1 and RS2, it is determined according to the backup identification of the first special register ① whether to perform a restore operation on the two registers RS1 and RS2. If yes, the restore operation is performed first, and then the read operation is performed.

[0074] The following takes the CPU executing an interrupt program as an example to further illustrate the task switching method provided in the embodiment of the present application. Figure 6 FIG. 2 is a second flow chart of the task switching method in the embodiment of the present application. Figure 6 As shown,

[0075] S1 configures the vector interrupt address and backup base address when powered on;

[0076] The S2 processor executes the current program;

[0077] S3 interrupt is triggered, if no, continue to execute S2, if yes, execute S4;

[0078] S4 determines the interrupt ID;

[0079] S5 searches for the corresponding interrupt entry program in the vector according to the interrupt ID;

[0080] S6 executes the interrupt program and updates SR2;

[0081] Taking interrupt processing as an example, power is turned on, interrupts are configured through CSR, and the third special register (SR3) is configured to store the backup base address. After the interrupt occurs, jump to the interrupt entry program. The above process is the same as the steps of a general processor. Then, the second special register (SR2) is used to record the processor running status, indicating that the next program to be run is the interrupt program.

[0082] S7 interrupt is completed and SR2 is high; if not, execute S8, if yes, execute S12;

[0083] S8 determines whether the interrupt program writes to RF; if not, execute S6; if yes, execute S9;

[0084] The interrupt program only contains interrupt functions for normal processing and no instructions for field maintenance. Therefore, during normal execution, if a write operation is found to be performed on the first register in RF during the instruction decoding stage, the backup operation is started.

[0085] S9 needs to back up the data of the first register in RF and update SR1;

[0086] The backup operation first reads the corresponding data in RF according to the address of the first register, corresponding to Figure 5 The dotted part of the instruction decoding stage (ID stage) is shown in FIG. 1 ; at the same time, the corresponding bit in the first special register (SR1) is updated, indicating that the current register has been backed up.

[0087] S10 generates an address;

[0088] Then in the execution stage (EX stage), a logical operation (or concatenation, addition, subtraction, or other operations) is performed based on the backup base address stored in SR3 and the address of the current first register to generate the destination address of the storage unit, corresponding to Figure 5 The address generation unit in .

[0089] S11 backup operation;

[0090] Then in the memory access stage (MEM stage), the memory is accessed for backup operations. The priority of the backup operation is higher than the priority of the currently executing instruction. For example, if the currently executing instruction is also a register load / store instruction, then the storage backup operation is performed first, and then the currently executing load / store instruction continues to be executed.

[0091] After the backup operation is completed, execute S6 to continue executing the interrupt program. When the interrupt program is completed and it is necessary to jump back to the originally executed program, the specific execution process is as follows:

[0092] If the last instruction of the interrupt program is the ret instruction, first check the second special register SR2 to determine the processor running status;

[0093] If SR2 is high, it means that the previous instruction belongs to the interrupt program. Then we need to check the backup flag in SR1 to determine which register in RF has been backed up.

[0094] If a bit in SR1 is high, it indicates that the register corresponding to the bit has been backed up, so the register corresponding to the bit needs to be restored. If a bit in SR1 is low, it indicates that the register corresponding to the bit has not been backed up, and no restoration operation is required. For example, if the bit storing the program counter PC value is high, it indicates that the PC value has been backed up, and a restoration operation needs to be performed to update the PC value.

[0095] If SR2 is low, it indicates that the previous instruction does not belong to the interrupt program, the interrupt program is not executed, and the next thread continues to execute.

[0096] S12 continues to execute the program before the interruption;

[0097] Is S13 finished? If not, execute S14, if yes, finish;

[0098] S14 checks SR1 to determine whether RF is backed up; if yes, execute S15; if no, continue to execute S12 without restoration;

[0099] S15 needs to restore the data of the first register in RF and update SR1;

[0100] First, in the instruction decoding stage (ID stage), the SR3 storage backup base address and the current address of the first register, or the address of the first register and the identification mapping relationship table are obtained;

[0101] S16 generates an address;

[0102] Then in the execution stage (EX stage), a logical operation (or concatenation, addition, subtraction, or other operations) is performed based on the backup base address stored in SR3 and the address of the current first register to generate the destination address of the storage unit, corresponding to Figure 5 The address generation unit in .

[0103] S17 restore operation;

[0104] Then in the memory access stage (MEM stage), the memory is accessed for restoration operation, and the priority of the restoration operation is higher than the priority of the currently executing instruction.

[0105] S18 write back operation.

[0106] Finally, in the write-back phase (WB phase), the data from the memory is updated to the first register corresponding to RF to complete the restoration of the scene.

[0107] The backup and restore operation provided in the embodiment of the present application does not require adding new backup and restore instructions to the code segment for on-site maintenance, and the backup operation is compatible with the original five-stage pipeline, and only needs to execute three stages of the pipeline (i.e., execution, memory access, and write-back stages) to successfully complete the backup and restore operation, which greatly reduces the performance loss caused by backup and restore, saves the time overhead of executing instructions, and reduces the performance loss caused by backup and restore.

[0108] The backup and restore operation provided by the embodiment of the present application greatly saves code space resources compared to traditional backup and restore instruction schemes. Even if the currently executed operation is an Arithmetic Logical Unit (alu) operation or other memory access operation without memory, there will be no pipeline stack stall, which will not affect the performance of the processor, thereby ensuring the CPU processing efficiency during task switching.

[0109] In the above task switching process, the operation of restoring RF->ADDRESS->LOAD->WB can actually jump out of the interruption to execute the original program before the interruption. In this intermediate stage, the data of all registers in the restored register file can be determined according to the bit in SR1, and then the original program before the interruption can be executed.

[0110] Among them, the multi-thread switching field maintenance process is the same as the above-mentioned interrupt switching process. The only difference is that it is necessary to define multiple groups of special registers for switching different threads according to the maximum number of threads supported, or use a group of special registers but need to define a group of linear mapping tables to distinguish different threads.

[0111] The adoption of the above technical solution improves the flexibility of task switching processing. On the one hand, the software part does not need to pay attention to the underlying backup or restore process and can be executed as a general processor program. On the other hand, compared with traditional on-site maintenance, new batch backup and restore instructions are added to the code, and then the original performance required for the function can be met after passing through five or more levels of pipeline units. The technical solution provided in the embodiment of the present application does not need to add new batch backup and restore instructions to the code, and there will be no situation in which performance is reduced due to the occupation of this pipeline station. At the same time, in terms of hardware resources, by selectively backing up register data, data storage space is greatly successfully saved. At the same time, it can be flexibly expanded according to different usage scenarios, and has better compatibility with those large number of thread systems.

[0112] Compared with traditional processor programs, the technical solution provided by the embodiment of the present application retains the original program execution solution, so that the original program does not need to be transplanted or modified, can be effectively compatible with the previous operating system, will not cause conflicts, and has good versatility.

[0113] To implement the method of the embodiment of the present application, based on the same inventive concept, the embodiment of the present application also provides a task switching device, such as Figure 7 As shown, the device 70 includes:

[0114] An execution unit 701, configured to execute a first task;

[0115] A backup unit 702 is used to back up the first task data stored in the first register in the register file to the first storage unit when triggering task switching; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up;

[0116] The execution unit 701 is further configured to execute a second task;

[0117] A restoring unit 703, configured to determine that the execution of the second task is completed, and restore the first task data in the first storage unit to the first register in the register file;

[0118] The execution unit 701 is further configured to read the first task data from the register file and continue to execute the first task.

[0119] Exemplarily, in some embodiments, the device further includes: a first special register ( Figure 7 not shown),

[0120] The backup unit 702 is used to set a backup identifier of the first register in the first special register, wherein the first special register includes the backup identifiers of the multiple registers in the register file.

[0121] Exemplarily, in some embodiments, the restoration unit 703 is used to determine the end of execution of the second task, determine the first register according to the backup identifier in the first special register; and restore the first task data in the first storage unit to the first register in the register file.

[0122] Exemplarily, in some embodiments, the restoration unit 703 is configured to restore the backup identifier of the first register in the first special register after restoring the first task data in the first storage unit to the first register in the register file.

[0123] Exemplarily, in some embodiments, the backup unit 702 is used to determine the first storage position of the backup identifier of the first register in the first special register according to a preset first mapping relationship; and set the backup identifier of the first register in the first special register to a backed-up state according to the first storage position.

[0124] Exemplarily, in some embodiments, the device further includes: a second special register ( Figure 7 The execution unit 701 is used to set a status flag in a second special register for indicating a switch from the first task to the second task when triggering a task switch; determine that the execution of the second task is completed, and based on the status flag in the second special register for indicating a switch from the first task to the second task, determine to restore the second task to the first task.

[0125] Exemplarily, in some embodiments, the execution unit 701 is used to restore the state flag in the second special register for indicating switching from the first task to the second task after determining to restore the second task to the first task.

[0126] Exemplarily, in some embodiments, the device further includes: an address generating unit ( Figure 7 ), which is used to perform a logical operation based on the backup base address and the identifier of the first register to generate the address of the first storage unit.

[0127] Exemplarily, in some embodiments, the device further includes: a third special register ( Figure 7 (not shown), the execution unit 701 is used to configure the backup base address in the third special register.

[0128] Exemplarily, in some embodiments, the backup unit 702 is used to determine the register on which the second task performs a write operation during the instruction decoding stage when triggering task switching; and determine the first register based on the register on which the second task performs a write operation.

[0129] Based on the hardware implementation of each unit in the above task switching device, the embodiment of the present application also provides an electronic device, such as Figure 8 As shown, the electronic device 80 includes: a processor 801 and a memory 802 configured to store a computer program that can be run on the processor, and a register file 803 including a plurality of registers, wherein the memory includes a plurality of storage units for backing up register data;

[0130] The processor 801 is configured to execute the method steps in the aforementioned embodiment when running a computer program.

[0131] Of course, in practical applications, Figure 8 As shown, the various components in the electronic device are coupled together through a bus system 804. It can be understood that the bus system 804 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 804 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, various buses are marked as bus system 804 in the figure.

[0132] In practical applications, the processor may be at least one of an application-specific integrated circuit (ASIC), a digital signal processing device (DSPD), a programmable logic device (PLD), a field-programmable gate array (FPGA), a controller, a microcontroller, and a microprocessor. It is understandable that for different devices, the electronic device used to implement the functions of the processor may also be other, and the embodiments of the present application do not specifically limit this.

[0133] The above-mentioned memory can be a volatile memory (volatile memory), such as a random access memory (RAM); or a non-volatile memory (non-volatile memory), such as a read-only memory (ROM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD); or a combination of the above-mentioned types of memory, and provide instructions and data to the processor.

[0134] In practical applications, the above device can be an electronic device or a chip applied to an electronic device. In the present application, the device can realize the functions of multiple units by means of software, hardware, or a combination of software and hardware, so that the device can execute the task switching method provided in any of the above embodiments. The technical effects of each technical solution of the device can refer to the technical effects of the corresponding technical solution in the task switching method, and the present application will not elaborate on this one by one.

[0135] In an exemplary embodiment, the embodiment of the present application further provides a computer-readable storage medium, such as a memory including a computer program, and the computer program can be executed by a processor of an electronic device to complete the steps of the aforementioned method.

[0136] An embodiment of the present application also provides a computer program product, including computer program instructions.

[0137] Optionally, the computer program product can be applied to the electronic device in the embodiments of the present application, and the computer program instructions enable the computer to execute the corresponding processes implemented by the electronic device in the various methods of the embodiments of the present application. For the sake of brevity, they are not repeated here.

[0138] The embodiment of the present application also provides a computer program.

[0139] Optionally, the computer program can be applied to the electronic device in the embodiments of the present application. When the computer program runs on a computer, the computer executes the corresponding processes implemented by the electronic device in the various methods of the embodiments of the present application. For the sake of brevity, they are not described here.

[0140] It should be understood that the terms used in the present application are only for the purpose of describing specific embodiments, but are not intended to limit the present application. The singular forms of "a", "said" and "the" used in the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items. The expressions "having", "may have", "include" and "include", or "may include" and "may include" in this application can be used to indicate the presence of corresponding features (e.g., elements such as numerical values, functions, operations or components), but the presence of additional features is not excluded.

[0141] It should be understood that although the terms first, second, third, etc. may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other and are not necessarily used to describe a specific order or sequence. For example, without departing from the scope of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information.

[0142] The technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.

[0143] In the several embodiments provided in the present application, it should be understood that the disclosed methods, devices and equipment can be implemented in other ways. The embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0144] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0145] In addition, all functional units in the embodiments of the present application may be integrated into one execution unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0146] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.

Claims

1. A task switching method, characterized in that: The method comprises: Execute the first task; When a task switch is triggered, the first task data stored in the first register in the register file is backed up to the first storage unit; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up; When a task switch is triggered, the register for the second task to perform a write operation is determined in the instruction decoding stage; Determine the register on which the second task performs a write operation as the first register; Perform the second task; Determining that the execution of the second task is completed, restoring the first task data in the first storage unit to the first register in the register file; The first task data is read from the register file, and the first task is continued to be executed.

2. The method according to claim 1, characterized in that The method further comprises: A backup identifier of the first register in a first special register is set, wherein the first special register includes the backup identifiers of the multiple registers in the register file.

3. The method according to claim 2, characterized in that The step of determining that the execution of the second task is completed and restoring the first task data in the first storage unit to the first register in the register file includes: Determining that the execution of the second task is completed, and determining the first register according to the backup identifier in the first special register; The first task data in the first storage unit is restored to the first register in the register file.

4. The method according to claim 3, characterized in that The method further comprises: After restoring the first task data in the first storage unit to the first register in the register file, restoring the backup identifier of the first register in the first special register.

5. The method according to claim 2, characterized in that: The step of setting a backup flag of the first register in the first special register includes: Determine, according to a preset first mapping relationship, a first storage position of the backup identifier of the first register in the first special register; According to the first storage location, a backup flag of the first register in the first special register is set to a backed-up state.

6. The method according to claim 1, characterized in that The method further comprises: When triggering task switching, setting a state flag in a second special register for indicating switching from the first task to the second task; It is determined that the execution of the second task is completed, and based on a state flag in the second special register indicating switching from the first task to the second task, it is determined that the second task is restored to the first task.

7. The method according to claim 6, characterized in that The method further comprises: After determining to restore the second task to the first task, restore the state flag in the second special register for indicating switching from the first task to the second task.

8. The method according to claim 1, characterized in that The method further comprises: A logical operation is performed based on the backup base address and the identifier of the first register to generate the address of the first storage unit.

9. The method according to claim 8, characterized in that The method further comprises: The backup base address is configured in a third special register.

10. A task switching device, characterized in that: The device comprises: An execution unit, configured to execute a first task; A backup unit, used to back up the first task data stored in the first register in the register file to the first storage unit when triggering task switching; wherein the register file includes a plurality of registers, and the first register is one or more registers in the register file that need to be backed up; The backup unit is further used to determine the register for the second task to perform the write operation in the instruction decoding stage when triggering the task switching; and determine the register for the second task to perform the write operation as the first register; The execution unit is further used to execute a second task; a restoring unit, configured to determine that the execution of the second task is finished, and restore the first task data in the first storage unit to the first register in the register file; The execution unit is further configured to read the first task data from the register file and continue to execute the first task.

11. An electronic device, characterized in that: The electronic device comprises: a processor and a memory configured to store a computer program capable of running on the processor, and a register file comprising a plurality of registers, wherein the memory comprises a plurality of storage units for backing up register data; Wherein, the processor is configured to execute the steps of the method according to any one of claims 1 to 9 when running the computer program.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.