Context-Switching Method and Apparatus
20200285472 ยท 2020-09-10
Inventors
Cpc classification
G06F9/485
PHYSICS
International classification
Abstract
A semiconductor apparatus for reducing context-switch time includes at least one CPU, at least one memory and a logic circuit. The central processor unit includes a control unit, a process unit and registers. The memory includes at least one region for storing information of multiple tasks. The information of each of the tasks includes an identification, priority, status and context. The logic circuit uses direct memory access to read and write the registers of the CPU and move data between the CPU registers and the memory. The logic circuit is operable to instruct the control unit to stop and resume the execution of CPU instruction.
Claims
1. A semiconductor apparatus for reducing context-switch time comprising: at least one CPU (10) comprising a control unit (12), a process unit (14) and registers (16, 18, 19); and a logic circuit (20) that uses direct memory access to read and write the registers of the CPU (10) and move data between the registers of the CPU (10) and at least one memory (30) for storing information of multiple tasks, wherein the information of each of the tasks comprises an identification, priority, status and context, wherein the logic circuit (20) is operable to instruct the control unit (12) to stop and resume execution of a command of the CPU (10).
2. The semiconductor apparatus according to claim 1, comprising multiple CPUs (10), wherein the logic circuit (20) is operable to control the multiple CPUs (10).
3. The semiconductor apparatus according to claim 1, wherein the logic circuit (20) comprises a mask swap register (21) operable to determine whether the contexts of the tasks should be switched, wherein the mask swap register (21) is controlled by software.
4. The semiconductor apparatus according to claim 1, wherein the logic circuit (20) further comprises a timer circuit (25) operable to the task running time before context switches.
5. The semiconductor apparatus according to claim 1, wherein the memory (30) is selected from the group consisting of a dynamic random access memory or a static random access memory.
6. The semiconductor apparatus according to claim 1, wherein the registers comprise at least one general purpose register file (16), at least one control and status register (18) and at least one program counter register (19).
7. A semiconductor apparatus for reducing context-switch time comprising: at least one CPU (10) comprising a control unit (12), a process unit (14) and registers (16, 18, 19); at least one memory (30) for storing information of multiple tasks, wherein the information of each of the tasks comprises an identification, priority, status and context; and a logic circuit (20) that uses direct memory access to read and write the registers of the CPU (10) and move data between the registers of the CPU (10) and the memory (30), wherein the logic circuit (20) is operable to instruct the control unit (12) to stop and resume the execution of instruction in the CPU (10).
8. A method for operating the semiconductor apparatus set forth in claim 1 to reduce context-switch time comprising the steps of: using the logic circuit (20) to temporarily stop the execution of instruction in the CPU (10) (S101); using the logic circuit (20) to read the context of a current task executed in the CPU (10) (S102); using the logic circuit (20) to move the context of the current task to a designated address of the memory (30) from the registers of the CPU (10) and change the priority of the current task (S103); using the logic circuit (20) to obtain the context of a next task from the memory (30) (S104); using the logic circuit (20) to write the context of the next task in some of the registers of the central processor unit (10) (S105); and using the logic circuit (20) to instruct the CPU (10) to resume the execution of instruction (S106).
9. The method according to claim 8, wherein the logic circuit (20) comprises a mask swap register (21) operable to determine whether the contexts of the tasks should be switched.
10. The method according to claim 8, wherein the logic circuit (20) further comprises a timer circuit (25) operable to set the task-running time before context switches.
Description
BRIEF DESCRIPTION OF DRAWINGS
[0013] The present invention will be described via detailed illustration of the preferred embodiment versus the prior art referring to the drawings wherein:
[0014]
[0015]
[0016]
[0017]
[0018]
DETAILED DESCRIPTION OF PREFERRED EMBODIMENT
[0019] Referring to
[0020] Each CPU 10 includes a control unit 12, a process unit 14 and multiple registers. The registers include at least one general purpose register file 16, at least one control and status register (CSR) 18 and at least one program counter register (PC) 19. The control unit 12 is used to control the other elements of the CPU 10 and receive and send commands. The process unit 14 executes the CPU instruction dependent on the control unit's signals. The general purpose register file 16 is used to store the information and status of the current execution task. The general purpose register file 16 is a group of high-speed registers with a limited capacity, used to temporarily store data, addresses and/or other information about calculation. Moreover, the control and status register 18 and the program counter register 19 are used to store information of the control unit 12.
[0021] The logic circuit 20 is provided in the semiconductor apparatus. The logic circuit 20 can synchronously operate more than one CPU 10. Moreover, the logic circuit 20 can use memory direct memory access (DMA). The logic circuit 20 uses direct memory access to move data between the memory 30 and the registers of each CPU 10. The logic circuit 20 can amend the control unit 12 of each CPU 10 so that the logic circuit 20 can temporarily stop the CPU execution through the control unit 12. The logic circuit 20 can amend the access to the general purpose register file 16, the program counter register 19 and the control and status register 18 of the CPU 10 so that the logic circuit 20 can read and write all of the registers of the CPU 10.
[0022] In some embodiments, the logic circuit 20 includes a mask swap register 21 so that the logic circuit 20 can determine whether to switch contexts corresponding to tasks based on the context of the mask swap register 21. The mask swap register 21 value is cleared by software. After determining to switch contexts, the logic circuit 20 will temporarily stop the switching of contexts if the logic circuit 20 finds that the mask swap register 21 is set. The logic circuit 20 will resume the switching of contexts immediately after the mask swap register 21 is cleared.
[0023] In some embodiments, the logic circuit 20 can further include a timer circuit 25 operable for context-switch cycle time.
[0024] The memory 30 can be a dynamic random access memory (DRAM) or a static random access memory (SRAM). The memory 30 is connected to the CPU 10 via a bus 35. A region in the memory 30 is selected to store information about multiple tasks. The information about each task includes the identification (ID), priority, status and context of the task.
[0025] As discussed above, a semiconductor apparatus for reducing context-switch time is provided. The semiconductors apparatus can reduce time spent on a multi-task operation and hence improve the efficiency of the multi-task operation.
[0026] When the semiconductor apparatus is in a multi-task operation, the logic circuit 20 switches the contexts of tasks between the CPU 10 and the memory 30. Referring to
[0027] Referring to
[0028] Then, at S102, the logic circuit 20 reads the context of a task (the current task) executed in the CPU 10. The logic circuit 20 uses the DMA to read the context of a temporarily stopped task (the current task).
[0029] Then, at S103, the logic circuit 20 moves the context of the current task to a designated address of the memory 30. The logic circuit 20 uses the DMA to move the context of the current task to the designated address of the memory 30 from the registers of the CPU 10, and update the current task's ID, priority and status for the next time of execution. As mentioned above, in some embodiments, the logic circuit 20 determines whether to switch contexts according to the context of the mask swap register 21. Moreover, in some embodiments, the logic circuit 20 switches contexts according to timeout value in the timer circuit 25.
[0030] Then, at S104, the logic circuit 20 reads the context of the next task from the memory 30. The logic circuit 20 reads the context of the task that is top priority in the memory 30 according to the ID, priority and status.
[0031] Then, at S105, the logic circuit 20 writes the context of the next task to the CPU 10. The logic circuit 20 uses the DMA to write the context of the next task to the registers of the CPU 10.
[0032] Then, at S106, the logic circuit 20 instructs the CPU 10 to resume the execution of instruction. The logic circuit 20 instructs the control unit 12 of the CPU 10 to resume the execution of instruction after writing the context of the next task to the CPU 10 registers.
[0033] As discussed above, the logic circuit 20 uses the DMA to move the context of the current task to the memory 30 from the CPU 10 registers and move the context of the next task to the CPU 10 registers from the memory 30. The steps represented by S101 to S106 are repeated to complete a multi-task operation. The data moving time by DMA of the logic circuit is much smaller than the data moving time by software. Hence, the efficiency of the switching of contexts according to the present invention is higher than that of the prior art.
[0034] The present invention has been described via the illustration of the preferred embodiment. Those skilled in the art can derive variations from the preferred embodiment without departing from the scope of the present invention. Therefore, the preferred embodiment shall not limit the scope of the present invention defined in the claims.