Computer, control method, and control program
Context switching and state recovery are performed through the stack frame indicated by the stack pointer value, which solves the problem of task scheduling mismatch in a multi-tasking environment and ensures the stable operation of the computer when additional programs exceed the limit.
Patent Information
- Application Number
- CN202280089541.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-26
- Publication Date
- 2024-08-30
AI Technical Summary
In a multi-tasking environment, using the setjmp and longjmp functions for context switching may cause task scheduling mismatch and priority reversal, causing the computer to lose control.
The stack frame indicated by the stack pointer value is used for context switching, and the execution state is restored after task interruption by building and restoring the stack frame to ensure the matching of task scheduling.
Even if the additional program exceeds the limit, the computer's actions can be continued, preventing the computer from running out of control and achieving matching recovery of task scheduling and execution status.
Smart Images

Figure CN118575167A
Abstract
Description
Technical Field
[0001] The present invention relates to context switching performed by a computer. Background Art
[0002] In computers that implement embedded systems such as industrial equipment, it is necessary to implement control that corresponds to the characteristics of the application target. In order to quickly respond to various diverse needs, it is conceivable to install basic programs that provide common functions and additional programs that provide extended functions in the computer.
[0003] When an additional program developed by a developer different from the basic program is installed on a computer, the execution of the additional program may exceed the predetermined upper limit of the execution time due to a malfunction, etc. (hereinafter, such an event is referred to as an "overrun"). If an overrun occurs, control may not return to the basic program, and the computer may lose control.
[0004] As part of the processing of existing tasks, when an additional program is executed by function call, if the task is forcibly terminated when an overtime occurs, the basic program that should be executed after the additional program will not be executed. Therefore, when the task is forcibly terminated, the computer may also go out of control.
[0005] Therefore, it is necessary for an interrupt handler or other task that detects the overrun of the additional program to restore the execution state of the basic program at the execution point just before the function call of the additional program, invalidate the additional program, and perform subsequent processing of the basic program based on the restored execution state.
[0006] As a technology related to such control, there is a technology described in Non-Patent Document 1.
[0007] As described in Non-Patent Document 1, a setjmp function and a longjmp function are provided in the standard library of the C language.
[0008] By executing the setjmp function, the execution state of an arbitrary execution point can be saved. In addition, by executing the longjmp function, the saved execution state can be restored and the processing at the execution point and thereafter can be executed.
[0009] Non-patent document 1: ISO / IEC 9899:2011 Information technology - Programming languages - C Summary of the invention
[0010] The technology described in non-patent document 1 has the following problem: in a multi-task environment, when a longjmp function is executed from an execution context (interrupt handler or task) different from the task that executed the setjmp function, the operation of the computer cannot be continued. If the longjmp function is executed, the execution state is immediately restored. Therefore, a mismatch with the context switching process or task scheduling occurs, and the operation of the computer cannot be continued.
[0011] Specifically, there is a mismatch in the task management data used for context switching processing. In addition, since a context switch is performed in a different framework from that of task scheduling, priority reversal between tasks may occur depending on the execution status of the tasks. That is, even if another program with a higher priority than the basic program is scheduled for execution, the execution status of the basic program is immediately restored due to the execution of the longjmp function, resulting in a mismatch with task scheduling.
[0012] One of the main objects of the present invention is to solve the above-mentioned problems. Specifically, the main object of the present invention is to enable the computer to continue to operate even when a program executed by a function call exceeds the limit.
[0013] The computer involved in the present invention has:
[0014] a context switch processing unit that performs context switching using the stack frame indicated by the stack pointer value;
[0015] a stack frame construction unit that, when a first program calls a second program through a function call and the first program interrupts execution, and the execution of the second program exceeds a predetermined time, constructs a stack frame for restoring the execution state of the first program before the execution of the first program was interrupted, that is, a first program stack frame, in a stack area for the first program in accordance with the structure of the stack frame used by the context switching processing unit; and
[0016] A stack pointer value setting unit sets a start address value of the first program stack frame as the stack pointer value.
[0017] Effects of the Invention
[0018] According to the present invention, even when the second program executed by the function call exceeds the limit, the operation of the computer can be continued. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 This is a diagram showing an example of the hardware configuration of a computer according to the first embodiment.
[0020] Figure 2This is a diagram showing an example of a functional configuration of a computer according to the first embodiment.
[0021] Figure 3 This is a diagram showing an overview of the operation of the computer according to the first embodiment.
[0022] Figure 4 This is a flowchart showing the details of the execution state saving process involved in the first embodiment.
[0023] Figure 5 This is a flowchart showing the details of the execution state recovery preparation process involved in the first embodiment. DETAILED DESCRIPTION
[0024] The following describes the embodiments using the drawings. In the following description of the embodiments and the drawings, parts denoted by the same reference numerals represent the same parts or corresponding parts.
[0025] Implementation Method 1
[0026] ***Description of the structure***
[0027] Figure 1 A hardware configuration example of the computer 100 according to the present embodiment is shown.
[0028] The processing flow of the computer 100 corresponds to the control method. The program for realizing the processing of the computer 100 corresponds to the control program.
[0029] like Figure 1 As shown, the computer 100 has a CPU 200 , an FPU 300 , a memory 400 , and a timer 500 .
[0030] Hereinafter, the CPU 200 , the FPU 300 , the memory 400 , and the timer 500 will be described respectively.
[0031] The CPU 200 is a Central Processing Unit and is an example of a processor.
[0032] The CPU 200 calls the program stored in the memory 400 and executes the program. Specifically, the CPU 200 executes the basic program and the additional program described above. As described above, the basic program is a program that provides common functions. In addition, the additional program is a program that provides extended functions.
[0033] In the drawings, a basic program may be abbreviated as “basic”. Similarly, an additional program may be abbreviated as “additional”.
[0034] In addition, the CPU 200 executes a high priority program described later.
[0035] In addition, the CPU 200 executes a program for realizing the functional components of the computer 100 described later. More specifically, the CPU 200 executes a program for realizing Figure 2 Among the elements shown, the program of the element ending with "section" such as the task N processing unit 101.
[0036] In addition, the CPU 200 may cause the FPU 300 to perform floating-point operations.
[0037] In addition, the CPU 200 controls the timer 500 to perform time management.
[0038] The CPU 200 includes a PC 201 , an SP 202 , a control / status register 203 , and a general register 204 .
[0039] PC 201 is a program counter. PC 201 stores the address location of the executed command.
[0040] SP 202 is a stack pointer. SP 202 indicates the start address of the stack area.
[0041] The control / status register 203 stores settings and status during execution of a program on the CPU 200. The control / status register 203 may be separated into a control register and a status register.
[0042] The general register 204 stores information such as calculation results and reference addresses during program execution.
[0043] The FPU 300 is a Floating Point Unit and performs floating point operations.
[0044] The FPU 300 has a control / status register 301 and a general register 302 .
[0045] The control / status register 301 stores settings and statuses in floating-point operations on the FPU 300. The control / status register 301 may be separated into a control register and a status register.
[0046] The general register 302 stores the calculation results of floating-point operations and the like.
[0047] The memory 400 includes a main storage device and an auxiliary storage device.
[0048] The memory 400 stores program codes and data. As described above, the memory 400 stores the functional components ( Figure 2 In addition, the memory 400 also stores basic programs, additional programs, and high-priority programs.
[0049] In addition, after the memory 400 exists, there is an execution state save area 105 described below. Figure 2
[0050] In addition, there is a stack area in the memory 400. In the stack area, there are a stack area of task M, a stack area of task N, and a stack area of a timer interrupt handler described below.
[0051] The timer 500 has a function of measuring time.
[0052] In addition, the timer 500 has a function of generating an interrupt for the CPU 200 at an arbitrary time period.
[0053] Here, the tasks and interrupt handler structure according to this embodiment will be described.
[0054] In this embodiment, the CPU 200 executes programs in task M, task N, and the timer interrupt handler.
[0055] The CPU 200 executes timer interrupt handler processing, overrun detection processing, execution state restoration preparation processing, context switching processing, task scheduling processing, etc. in the timer interrupt handler. That is, the CPU 200 executes a program for implementing the functional structural elements of the computer 100 ( Figure 2 elements whose names end with "unit") in the timer interrupt handler.
[0056] The CPU 200 may also execute a program other than the program for implementing the functional structural elements of the computer 100 ( Figure 2 elements whose names end with "unit") in the timer interrupt handler. However, as described below, the CPU 200 executes a basic program and an additional program in task N.
[0057] The CPU 200 executes a basic program and an additional program in task N.
[0058] In addition, the CPU 200 sometimes executes a high-priority program with a higher priority than the basic program and the additional program in task M.
[0059] In this embodiment, the basic program calls the additional program through a function call. In addition, the execution of the additional program sometimes exceeds a predetermined time (an overrun sometimes occurs).
[0060] In addition, the basic program corresponds to the first program. The additional program corresponds to the second program. In addition, the high-priority program corresponds to the third program.
[0061] The main purpose of this embodiment is to restore the execution state of the basic program so as not to stop the operation of the computer 100 when the additional program exceeds the limit.
[0062] Therefore, the following description will focus on the operation of restoring the execution state of the basic program when an additional program exceeds the limit.
[0063] Therefore, the following description of executing a program in a timer interrupt handler, executing a program other than a basic program and an additional program in task N, and executing a high-priority program in task M is made within the scope of the recovery process of the execution state of the basic program when an additional program exceeds the limit. In addition, the same is true for the recovery of the execution state of the basic program when an additional program does not exceed the limit.
[0064] Figure 2 A functional configuration example of the computer 100 according to the present embodiment is shown.
[0065] exist Figure 2 , functional structural elements for restoring the execution state of the basic program when an additional program exceeds the limit are shown.
[0066] The computer 100 further includes a functional structural element for controlling the execution of a program in a timer interrupt handler and the execution of a program in a task M, but in Figure 2 Illustration omitted.
[0067] The task N processing unit 101 performs control of task N.
[0068] When the execution of the basic program is interrupted due to a function call of the additional program, the task N processing unit 101 calls the execution state storage unit 104 described later.
[0069] The task N stack area 102 is a stack area used by the task N in the memory 400. The task N stack area 102 is used when constructing a stack frame for restoring the execution state of the basic program.
[0070] The additional processing unit 103 controls the execution of the additional program.
[0071] When called by the task N processing unit 101 , the execution status storage unit 104 stores the execution status of the basic program before the execution is interrupted in the execution status storage area 105 .
[0072] The execution state stored in the execution state storage area 105 by the execution state storage unit 104 includes the value of the control / status register 203 and the value of the general register 204 of the CPU 200. In addition, the execution state stored in the execution state storage area 105 by the execution state storage unit 104 may also include the value of the control / status register 301 and the value of the general register 302 of the FPU 300.
[0073] The execution status saving area 105 is an area in the memory 400 for saving the execution status before the execution of the basic program is interrupted.
[0074] The execution status storage area 105 is an area that is statically reserved (the location of which can be determined).
[0075] The execution status saving area 105 is an area different from the task N stack area 102 .
[0076] The timer interrupt handler processing unit 106 is an interrupt handler activated by a timer interrupt. The timer interrupt handler processing unit 106 calls the overrun detection unit 107 when the additional program is being executed.
[0077] The overrun detection unit 107 measures the execution time of the additional program and compares the execution time of the additional program with the executable upper limit time 108 to determine the occurrence of the overrun.
[0078] The executable upper limit time 108 is the upper limit of the execution time of the additional program. When the execution time of the additional program exceeds the executable upper limit time 108, the overrun detection unit 107 determines that the overrun has occurred.
[0079] When an additional program exceeds the limit, the execution state restoration preparation unit 109 constructs a stack frame for restoring the execution state of the basic program before the execution was interrupted.
[0080] In addition, hereinafter, the stack frame for restoring the execution state of the basic program before the execution interruption is referred to as the basic program stack frame. The basic program stack frame corresponds to the first program stack frame.
[0081] The execution state restoration preparation unit 109 constructs a basic program stack frame in the task N stack area 102 using the execution state of the basic program before execution interruption saved in the execution state saving area 105 by the execution state saving unit 104 .
[0082] The execution state restoration preparation unit 109 constructs a basic program stack frame in accordance with the structure of a stack frame used by the context switch processing unit 112 described later.
[0083] Furthermore, the execution state restoration preparation unit 109 sets the starting address value of the basic program stack frame as the stack pointer value that the context switch processing unit 112 refers to when restarting task N. The stack pointer value that the context switch processing unit 112 refers to when restarting task N is already described in the task N management data 110. Therefore, the execution state restoration preparation unit 109 overwrites the stack pointer value of the task N management data 110 with the starting address value of the basic program stack frame.
[0084] The execution state restoration preparation unit 109 corresponds to a stack frame construction unit and a stack pointer value setting unit. The processing performed by the execution state restoration preparation unit 109 corresponds to a stack frame construction process and a stack pointer value setting process.
[0085] The task N management data 110 describes a stack pointer value that the context switch processing unit 112 refers to when restarting task N. In addition, the task N management data 110 may also describe the execution state and priority of task N.
[0086] The task scheduling processing unit 111 selects a task to be executed next by the CPU 200 based on the execution status and priority of the task.
[0087] The task scheduling processing unit 111 is executed when a system call is called from a task or when an interrupt handler ends.
[0088] The context switch processing unit 112 performs context switch processing using the stack frame indicated by the stack pointer value.
[0089] When the additional program exceeds the limit, the context switch processing unit 112 refers to the stack pointer value recorded in the task N management data 110 when task N is scheduled. Then, the context switch processing unit 112 uses the stack frame constructed in the task N stack area 102 based on the stack pointer value to restore the execution state of the basic program.
[0090] ***Description of the action***
[0091] First, refer to Figure 3 An overview of the operation of the computer 100 according to the present embodiment will be described.
[0092] Figure 3 (a) shows the processing performed in the timer interrupt handler and task N in chronological order. Figure 3 In (a), time flows from left to right.
[0093] exist Figure 3 (b) shows that after just executing Figure 3The stack structure of the task N stack area 102 at the time point after the execution state recovery preparation processing (S307) of (a). At the time point just after the execution state recovery preparation processing (S307) is executed, the task N stack area 102 contains "execution state information saved due to interruption", "area used by additional programs" and "basic program stack frame".
[0094] The “area used by the additional program” is a part of the task N stack area 102 used for executing the additional program.
[0095] The “execution status information saved due to the occurrence of an interruption” is the execution status information of task N saved to the task N stack area 102 when the timer interrupt handler is activated due to the occurrence of a timer interrupt. In addition, when the “execution status information saved due to the occurrence of an interruption” is saved in the task N stack area 102, the stack pointer value of the task N management data 110 is updated with the starting address value of the “execution status information saved due to the occurrence of an interruption”.
[0096] exist Figure 3 In (a), in task N, the basic program is executed by the task N processing unit 101 (S301).
[0097] Next, in task N, immediately before the basic program calls the additional program by function call (S303), the task N processing unit 101 calls the execution state storage unit 104. Then, the execution state storage unit 104 stores the execution state of the basic program in the execution state storage area 105 (S302).
[0098] The execution status storage unit 104 stores, for example, the value of the control / status register 203 , the value of the general register 204 , the value of the control / status register 301 , the value of the general register 302 , etc. as the execution status in the execution status storage area 105 .
[0099] In addition, the execution status storage unit 104 stores the stack pointer in the execution status storage area 105 (S302). The stack pointer stored in the execution status storage area 105 indicates the start address value of the task N stack area 102 at the current time point.
[0100] When the basic program calls the additional program by a function call ( S303 ), the task N processing unit 101 interrupts the execution of the basic program and calls the additional processing unit 103 .
[0101] The additional processing unit 103 executes the additional program ( S304 ).
[0102] Furthermore, the task N processing unit 101 notifies the timer interrupt handler processing unit 106 that the execution of the additional program has started. The timer interrupt handler processing unit 106 calls the overrun detection unit 107 .
[0103] If the additional program exceeds the limit due to a failure or the like ( S305 ), the limit exceeding detection unit 107 detects the limit exceeding of the additional program in the timer interrupt handler ( S306 ). The limit exceeding detection unit 107 calls the execution state restoration preparation unit 109 .
[0104] Next, in the timer interrupt handler, the execution state recovery preparation unit 109 prepares for recovery of the execution state (S307). Figure 3 As shown in (b), the execution state recovery preparation unit 109 refers to the stack pointer stored in the execution state storage area 105 to determine the starting address value of the task N stack area 102 immediately before the additional program is executed. Furthermore, the execution state recovery preparation unit 109 obtains the execution state of the basic program from the execution state storage area 105. Then, the execution state recovery preparation unit 109 constructs a basic program stack frame with the execution state obtained from the execution state storage area 105 as the content in the task N stack area 102 above the determined starting address (stack extension direction).
[0105] In addition, the execution state recovery preparation unit 109 uses the starting address value of the basic program stack frame to overwrite the stack pointer of the task N management data 110. In addition, the stack pointer of the task N management data 110 before overwriting points to the starting address of the execution state information of the task N that is executing the additional program that has exceeded the limit and has been interrupted by the activation of the timer interrupt handle.
[0106] At the time point of S307, preparations are made until the execution state of the basic program is restored, and the execution state is not restored.
[0107] Then, in the timer interrupt handler, the context switch processing unit 112 performs the context switch processing at the timing of the task schedule (S308). That is, at the time point when the task schedule processing unit 111 schedules the resumption of the execution of the basic program in task N, the context switch processing unit 112 performs the context switch processing for the basic program.
[0108] In addition, when the execution of a high-priority program in task M having a higher priority than the basic program in task N is first scheduled, after the execution of the high-priority program in task M is completed, context switching processing for the basic program is performed at the time when the execution of the basic program is scheduled to be restarted.
[0109] In the context switch process for the basic program, the context switch processing unit 112 refers to the stack pointer value described in the task N management data 110. Then, the context switch processing unit 112 restores the execution state of the basic program using the stack frame constructed in the task N stack area 102 based on the stack pointer value.
[0110] Next, explain Figure 3 Details of the execution status saving process (S302) and the execution status recovery preparation process (S307).
[0111] Figure 4 This is a flowchart showing the details of the execution state saving process (S302).
[0112] Figure 5 This is a flowchart showing the details of the execution state restoration preparation process (S307).
[0113] First, refer to Figure 4 The details of the execution state saving process (S302) will be described.
[0114] In step S401 , the task N processing unit 101 determines whether a call of an additional program by a function call occurs during the execution of the basic program.
[0115] When a call of an additional program by a function call occurs (YES in step S401 ), the task N processing unit 101 calls the execution status storage unit 104 , and the process proceeds to step S402 .
[0116] In step S402, the execution state storage unit 104 stores the execution state and stack pointer of the basic program before the interruption in the execution state storage area 105. As described above, the execution state stored in the execution state storage area 105 by the execution state storage unit 104 includes, for example, the value of the control / status register 203, the value of the general register 204, the value of the control / status register 301 of the FPU 300, and the value of the general register 302.
[0117] In addition, the stack pointer indicates the start address value of the task N stack area 102 at the current time point.
[0118] Next, in step S403 , the task N processing unit 101 interrupts the execution of the basic program.
[0119] Then, in step S404 , the task N processing unit 101 calls the additional processing unit 103 , and the additional processing unit 103 starts executing the additional program.
[0120] Next, refer to Figure 5 The details of the execution state restoration preparation process (S307) will be described.
[0121] When the limit-exceeding detecting unit 107 determines that the additional program has exceeded the limit (YES in step S501 ), the limit-exceeding detecting unit 107 calls the execution state restoration preparing unit 109 .
[0122] Then, in step S502 , the execution state restoration preparation unit 109 refers to the stack pointer stored in the execution state storage area 105 to identify the start address value of the task N stack area 102 immediately before the additional program is executed.
[0123] Next, in step S503 , the execution state restoration preparation unit 109 obtains the execution state of the basic program before the interruption from the execution state storage area 105 .
[0124] Next, in step S504 , the execution state restoration preparation unit 109 constructs a basic program stack frame having the execution state acquired in step S503 as content in the task N stack area 102 above the start address determined in step S502 (in the stack extension direction).
[0125] Next, in step S505 , the execution state restoration preparation unit 109 overwrites the stack pointer of the task N management data 110 with the start address value of the basic program stack frame constructed in step S504 .
[0126] ***Explanation of the effects of the implementation method***
[0127] In this embodiment, when a timeout occurs, the execution state is not immediately restored, but preparation for restoring the execution state (building a stack frame) is stopped. In addition, in this embodiment, the execution state of the basic program is restored at the timing of task scheduling.
[0128] Therefore, according to the present embodiment, it is possible to achieve compatibility between the execution state recovery process, the context switch process, and the task scheduling, and to continue the operation of the computer.
[0129] In addition, the processing flow described in this embodiment is just an example.
[0130] Therefore, only a part of the processing flow described in this embodiment may be implemented.
[0131] Furthermore, at least a part of the processing flow described in this embodiment may be implemented in combination with a processing flow not described in this embodiment.
[0132] In addition, the configuration and processing flow described in this embodiment may be changed as necessary.
[0133] ***Supplementary description of hardware structure***
[0134] Finally, a supplementary description of the hardware structure of the computer 100 is given.
[0135] The CPU 200 and the FPU 300 are ICs (Integrated Circuits) that execute processing.
[0136] The memory 400 is a RAM (Random Access Memory), a ROM (Read Only Memory), a flash memory, a HDD (Hard Disk Drive), or the like.
[0137] In addition, the memory 400 also stores an OS (Operating System).
[0138] Also, at least a part of the OS is executed by the CPU 200 .
[0139] While executing at least a part of the OS, the CPU 200 executes a program that implements the functions of the task N processing unit 101, the additional processing unit 103, the execution status saving unit 104, the timer interrupt handle processing unit 106, the overlimit detection unit 107, the execution status recovery preparation unit 109, the task scheduling processing unit 111 and the context switching processing unit 112.
[0140] The CPU 200 executes the OS to perform task management, memory management, file management, communication control, and the like.
[0141] In addition, at least any one of the information, data, signal values and variable values representing the results of processing by the task N processing unit 101, the additional processing unit 103, the execution status saving unit 104, the timer interrupt handle processing unit 106, the over-limit detection unit 107, the execution status recovery preparation unit 109, the task scheduling processing unit 111 and the context switching processing unit 112 is stored in the memory 400, the control / status register 203, the general register 204, the control / status register 301 and the general register 302.
[0142] In addition, the program that realizes the functions of the task N processing unit 101, the additional processing unit 103, the execution state storage unit 104, the timer interrupt handle processing unit 106, the over-limit detection unit 107, the execution state recovery preparation unit 109, the task scheduling processing unit 111, and the context switching processing unit 112 can also be stored in a removable recording medium such as a magnetic disk, a floppy disk, an optical disk, a compressed disk, a Blu-ray (registered trademark) disk, a DVD, etc. In addition, a removable recording medium storing the program that realizes the functions of the task N processing unit 101, the additional processing unit 103, the execution state storage unit 104, the timer interrupt handle processing unit 106, the over-limit detection unit 107, the execution state recovery preparation unit 109, the task scheduling processing unit 111, and the context switching processing unit 112 can also be circulated.
[0143] In addition, the word "unit" of at least any one of the task N processing unit 101, the additional processing unit 103, the execution status saving unit 104, the timer interrupt handle processing unit 106, the over-limit detection unit 107, the execution status recovery preparation unit 109, the task scheduling processing unit 111 and the context switching processing unit 112 may be replaced by "circuit", "process", "flow", "processing" or "circuit system".
[0144] In addition, at least any one of the task N processing unit 101, the additional processing unit 103, the execution state storage unit 104, the timer interrupt handle processing unit 106, the over-limit detection unit 107, the execution state recovery preparation unit 109, the task scheduling processing unit 111, and the context switching processing unit 112 can also be implemented by a processing circuit. The processing circuit is, for example, a logic IC (Integrated Circuit), a GA (Gate Array), an ASIC (Application Specific Integrated Circuit), or an FPGA (Field-Programmable Gate Array).
[0145] In addition, in this specification, the general concept of a processor and a processing circuit is referred to as a "processing circuit system".
[0146] That is, the processor and the processing circuit are each a specific example of a "processing circuit system".
[0147] Description of the label
[0148] 100 computer, 101 task N processing unit, 102 task N stack area, 103 additional processing unit, 104 execution status saving unit, 105 execution status saving area, 106 timer interrupt handle processing unit, 107 overlimit detection unit, 108 executable upper limit time, 109 execution status recovery preparation unit, 110 task N management data, 111 task scheduling processing unit, 112 context switching processing unit, 200 CPU, 201 PC, 202 SP, 203 control / status register, 204 general register, 300 FPU, 301 control / status register, 302 general register, 400 memory, 500 timer.
Claims
1. A computer having: a context switch processing unit that performs context switching using the stack frame indicated by the stack pointer value; a stack frame construction unit that, when a first program calls a second program through a function call and the first program interrupts execution, and the execution of the second program exceeds a predetermined time, constructs a stack frame for restoring the execution state of the first program before the execution of the first program was interrupted, that is, a first program stack frame, in a stack area for the first program in accordance with the structure of the stack frame used by the context switching processing unit; and A stack pointer value setting unit sets a start address value of the first program stack frame as the stack pointer value.
2. The computer according to claim 1, in, The context switching processing unit refers to the stack pointer value at a time point when the execution of the first program is scheduled to be restarted, and uses the first program stack frame to restore the execution state of the first program before the execution was interrupted based on the start address value of the first program stack frame set as the stack pointer value.
3. The computer according to claim 2, in, When the context switching processing unit schedules the execution of a third program having a higher priority than the first program before resuming the execution of the first program, after completing the execution of the third program, the execution state of the first program before the execution was interrupted is restored at the time when the execution of the first program is scheduled to be resumed.
4. The computer according to claim 1, in, The computer further includes an execution state storage unit that stores an execution state of the first program before the execution of the first program is interrupted in a storage area other than a stack area of the first program. The stack frame construction unit constructs the first program stack frame in the stack area for the first program using the execution state before the execution of the first program is interrupted, which is saved in the storage area by the execution state saving unit.
5. The computer according to claim 4, in, The execution status saving unit saves at least any one of the value of the control register included in the computer before the execution of the first program is interrupted, the value of the status register included in the computer before the execution of the first program is interrupted, and the value of the general register included in the computer before the execution of the first program is interrupted in the storage area as at least a part of the execution status before the execution of the first program is interrupted.
6. A control method, in, A processor included in a computer that performs context switching processing using a stack frame indicated by a stack pointer value, when a first program calls a second program through a function call, and the first program interrupts execution, and when the execution of the second program exceeds a predetermined time, a stack frame for restoring the execution state of the first program before the execution of the first program was interrupted is constructed in a stack area for the first program in accordance with the structure of the stack frame used for the context switching processing, i.e., a first program stack frame, The processor sets a start address value of the first program stack frame as the stack pointer value.
7. A control program that causes a computer to execute the following processing: Context switch processing, using the stack frame indicated by the stack pointer value to perform context switch; a stack frame construction process, in which, when a first program calls a second program through a function call and the first program interrupts execution, and the execution of the second program exceeds a predetermined time, a stack frame for restoring the execution state of the first program before the execution of the first program was interrupted is constructed in a stack area for the first program in accordance with the structure of the stack frame used by the context switching process, i.e., a first program stack frame; and The stack pointer value setting process sets the start address value of the first program stack frame as the stack pointer value.
