Data stack method, device, chip and storage medium
By optimizing the data push method in the MCU and skipping or adjusting the push order of context data, the problem of the processor waiting for incomplete instruction updates is solved, and the real-time performance of interrupt response is improved.
Patent Information
- Application Number
- CN202111080668.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-15
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-09-15
AI Technical Summary
In an MCU, when the processor responds to an exception signal or an external interrupt, it needs to wait for the unfinished instructions to update the context data, which prolongs the interrupt response time, especially when executing floating-point instructions.
By skipping context data that has not been updated when a push operation occurs, and then pushing the context data that has not been updated onto the stack only after all or part of the other context data has been pushed onto the stack, or by optimizing the push order of context data through data range partitioning and round-robin methods, we can ensure that data pushing and data updating are performed in parallel.
Reduce or eliminate the time spent waiting for data updates, improve the real-time performance of interrupt responses, and significantly improve the interrupt response speed of the MCU, especially when pushing data onto the floating-point context stack.
Smart Images

Figure CN113986348B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a data stack method, device, chip and storage medium. BACKGROUND
[0002] In MCU (micro control unit), the processor (CPU core) needs to respond to abnormal signals or external interrupt control signals frequently, and switch from the current user program instruction stream to the exception handling program. In this process, the state of the current program execution needs to be protected, and the context data of the current program is pushed into the stack for protection; when the exception handling program exits, the saved context data is popped from the stack for the user program instruction stream to continue execution.
[0003] When the context data is pushed into the stack, it is necessary to ensure that the data pushed into the stack is fresh data of the program, that is, when the stack action occurs, if there is an instruction that has not been executed and the instruction will update the context data to be pushed into the stack, the instruction needs to be executed before the context data is pushed into the stack, and if the execution of the instruction needs to consume a large number of clock cycles, the response time of the exception or interrupt will be significantly increased, thereby reducing the real-time performance of the interrupt response. SUMMARY
[0004] The present application aims to at least solve one of the problems in the related art. To this end, the first object of the present application is to provide a data stack method, which can make the data stack and data update parallel, reduce or eliminate the waiting time for data update, and thereby improve the real-time performance of the interrupt response.
[0005] The second object of the present application is to provide a data stack device.
[0006] The third object of the present application is to provide a chip.
[0007] The fourth object of the present application is to provide a computer readable storage medium.
[0008] To achieve the above object, the first aspect of the present application provides a data stack method, which comprises: when the stack action occurs, if there is context data that has not been updated, skipping the context data that has not been updated, and pushing the context data that has not been updated into the stack after all or part of the other context data is pushed into the stack; if there is no context data that has not been updated, pushing all context data into the stack in sequence.
[0009] According to the data stack method of the embodiment of the present application, when the stack action occurs, if there is context data which is not updated, the context data which is not updated is skipped, and after all or part of the other context data is stacked, the context data which is not updated is stacked; if there is no context data which is not updated, all the context data is stacked in sequence. Thus, when there is context data which is not updated, the data stack and the data update can be parallel, the time of waiting for the data update is reduced or eliminated, and the real-time of the interrupt response is improved.
[0010] According to an embodiment of the present application, the skipping of the context data which is not updated and the stacking of the context data which is not updated after all or part of the other context data is stacked, comprises: first, stacking all the context data in sequence, and when the context data which is not updated is stacked, if it is determined that the context data which is not updated is still not updated, the context data which is not updated is skipped and the subsequent context data is stacked until the subsequent context data is stacked and then the context data which is not updated is stacked.
[0011] According to an embodiment of the present application, the skipping of the context data which is not updated and the stacking of the context data which is not updated after all or part of the other context data is stacked, further comprises: when the context data which is not updated is stacked, if it is determined that the context data which is not updated is updated, all the context data is continued to be stacked in sequence.
[0012] According to another embodiment of the present application, the skipping of the context data which is not updated and the stacking of the context data which is not updated after all or part of the other context data is stacked, comprises: first, stacking the context data which is sorted after the context data which is not updated in sequence, then stacking the context data which is sorted before the context data which is not updated in sequence, and finally stacking the context data which is not updated.
[0013] According to still another embodiment of the present application, the skipping of the context data which is not updated and the stacking of the context data which is not updated after all or part of the other context data is stacked, comprises: dividing all the context data into multiple data intervals; after determining the data interval in which the context data which is not updated is located, the context data corresponding to the other data intervals is stacked first, and then the context data corresponding to the data interval in which the context data which is not updated is located is stacked.
[0014] According to one embodiment of the present application, the plurality of data intervals include a first data interval and a second data interval with the same data length, and the data update time length of the context data which has not been updated is less than the data stack time length of the first data interval and the second data interval respectively, further, the context data corresponding to other data intervals is stacked first, and then the context data corresponding to the data interval in which the context data which has not been updated is stacked, including: when the context data which has not been updated is in the first data interval, the context data corresponding to the second data interval is stacked first, and then the context data corresponding to the first data interval is stacked; when the context data which has not been updated is in the second data interval, the context data corresponding to the first data interval is stacked first, and then the context data corresponding to the second data interval is stacked.
[0015] According to another embodiment of the present application, the plurality of data intervals include a third data interval, a fourth data interval and a fifth data interval, the third data interval and the fourth data interval have the same data length, the context data which has not been updated is in the third data interval or the fourth data interval, and the data update time length of the context data which has not been updated is less than the data stack time length of the third data interval and the fourth data interval respectively, further, the context data corresponding to other data intervals is stacked first, and then the context data corresponding to the data interval in which the context data which has not been updated is stacked, including: when the context data which has not been updated is in the third data interval, the context data corresponding to the fourth data interval is stacked first, and then the context data corresponding to the third data interval is stacked, and finally the context data corresponding to the fifth data interval is stacked; when the context data which has not been updated is in the fourth data interval, the context data corresponding to the third data interval is stacked first, and then the context data corresponding to the fourth data interval is stacked, and finally the context data corresponding to the fifth data interval is stacked.
[0016] According to one embodiment of the present application, the context data includes one or more of program status register data, fixed point register data, floating point register data and interrupt return address.
[0017] According to one embodiment of the present application, the context data which has not been updated is stacked, including: if it is determined that the context data which has not been updated has been updated, the context data after being updated is stacked; if it is determined that the context data which has not been updated has not been updated, the context data after being updated is stacked after being updated.
[0018] To achieve the above object, the second aspect of the present application provides a data stack device, comprising: a determining module, configured to determine whether there is context data which is not updated when a stack action occurs; and a stack module, configured to: when the stack module determines that there is context data which is not updated, skip the context data which is not updated, and stack the context data which is not updated after all or part of other context data is stacked; and when the stack module determines that there is no context data which is not updated, stack all context data in sequence.
[0019] The data stack device according to the embodiment of the present application, by the determining module, determines whether there is context data which is not updated when a stack action occurs, and by the stack module, when there is context data which is not updated, skips the context data which is not updated, and stacks the context data which is not updated after all or part of other context data is stacked, and when there is no context data which is not updated, stacks all context data in sequence. Thus, when there is context data which is not updated, the data stack and the data update can be parallel, the time of waiting for the data update can be reduced or eliminated, and the real-time performance of the interrupt response is improved.
[0020] According to an embodiment of the present application, the stack module is specifically configured to: stack all context data in sequence first, and when the context data which is not updated is stacked, if it is determined that the context data which is not updated is still not updated, skip the context data which is not updated and stack subsequent context data, until the context data which is not updated is stacked after the subsequent context data is stacked.
[0021] According to an embodiment of the present application, the stack module is specifically configured to: stack context data which is sorted after the context data which is not updated in sequence first, stack context data which is sorted before the context data which is not updated in sequence, and finally stack the context data which is not updated.
[0022] According to an embodiment of the present application, the stack module is specifically configured to: divide all context data into a plurality of data intervals, and after determining a data interval in which the context data which is not updated is located, stack context data corresponding to other data intervals first, and then stack context data corresponding to the data interval in which the context data which is not updated is located.
[0023] To achieve the above object, the third aspect of the present application provides a chip, comprising a memory and a processor, the memory stores a computer program, and the processor implements the steps of the data stack method when executing the computer program.
[0024] According to the data stack method, when there is context data to be updated, the data stack and the data update can be performed in parallel, the time for waiting for the data update is reduced or eliminated, and the real-time performance of interrupt response is improved.
[0025] To achieve the above object, the fourth aspect of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the data stack method.
[0026] According to the computer readable storage medium, when there is context data to be updated, the data stack and the data update can be performed in parallel, the time for waiting for the data update is reduced or eliminated, and the real-time performance of interrupt response is improved.
[0027] Additional aspects and advantages of the present application will be given in part in the following description, become apparent from the following description, or be learned by practice of the present application. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 a flowchart of the data stack method according to an embodiment of the present application;
[0029] Figure 2 a flowchart of the data stack method according to another embodiment of the present application;
[0030] Figure 3 a flowchart of the data stack method according to an embodiment of the present application in a skip mode;
[0031] Figure 4 a flowchart of the data stack method according to an embodiment of the present application in a round-robin mode;
[0032] Figure 5 a flowchart of the data stack method according to an embodiment of the present application in a region division mode;
[0033] Figure 6 a flowchart of the data stack method according to another embodiment of the present application in a region division mode;
[0034] Figure 7 a flowchart of the data stack method when executing a floating point division instruction according to an embodiment of the present application;
[0035] Figure 8 a flowchart of the data stack method when executing a floating point division instruction according to another embodiment of the present application;
[0036] Figure 9 A structure diagram of a data stack device according to an embodiment of the present application. DETAILED DESCRIPTION
[0037] Embodiments of the present application are described in detail below with reference to the attached drawings, which show by way of example, embodiments in which the same or similar elements have the same or similar reference numbers and in which:
[0038] Generally, when performing the stack of context data, it is necessary to ensure that the data stacked into the stack is fresh data of the program, that is, when the stack action occurs, if there is an instruction that has not been executed and the instruction will update the context data to be stacked, the instruction needs to be executed before the context data is stacked, and if the execution of the instruction needs to consume a large number of clock cycles, the response time of the exception or interruption will be significantly increased, thereby reducing the real-time performance of the interruption response, which is particularly obvious when performing the stack of floating point context, especially when the instruction being executed is a floating point division instruction. For example, assuming that a floating point division is being executed and will update the floating point register, 16 clock cycles are needed to complete the execution, 8 clock cycles are needed for the fixed point context stack, and then the processor needs to wait for another 8 clock cycles after completing the fixed point context stack to ensure that the data of the floating point register is fresh data after the floating point division operation is completed, which significantly increases the response time of the MCU to the interruption. Based on this, the present application provides a data stack optimization method, which can reduce the time for waiting for the completion of the instruction execution by overlapping the stack time and the instruction execution time, thereby improving the real-time performance of the MCU for the interruption response.
[0039] Figure 1 A flow chart of a data stack method according to an embodiment of the present application, as shown in Figure 1 The data stack method can include the following steps:
[0040] In step S100, when the stack action occurs, if there is context data that has not been updated, the context data that has not been updated is skipped, and the context data that has not been updated is stacked after all or part of the other context data is stacked.
[0041] That is, when the push stack operation occurs, the context data which has not been updated is not pushed into the stack first, but the context data which has not been updated is pushed into the stack after all or part of the other context data is pushed into the stack, during which the instruction is in the execution state and the context data which has not been updated is updated, so that the context data which has not been updated is pushed into the stack after all or part of the other context data is pushed into the stack, which can reduce or eliminate the time for waiting for the instruction execution, i.e. the time for waiting for the data update, thereby improving the interrupt response time.
[0042] For example, if the time for executing the instruction is slightly less than the time for pushing all of the other context data into the stack, the context data which has not been updated can be pushed into the stack after all of the other context data is pushed into the stack, because the context data which has not been updated has been updated after all of the other context data is pushed into the stack, so that the context data which has been updated is directly pushed into the stack, thereby eliminating the time for waiting for the data update; if the time for executing the instruction is much less than the time for pushing all of the other context data into the stack, the context data which has not been updated can be pushed into the stack after part of the other context data is pushed into the stack, because the context data which has not been updated has been updated after part of the other context data is pushed into the stack, so that the context data which has been updated is directly pushed into the stack, thereby eliminating the time for waiting for the data update. If the time for executing the instruction is greater than the time for pushing all of the other context data into the stack, the context data which has not been updated can be pushed into the stack after all of the other context data is pushed into the stack, because the context data which has not been updated has been partially updated after all of the other context data is pushed into the stack, so that although the time for waiting for the data update cannot be eliminated, the time for waiting for the data update can be reduced.
[0043] In some embodiments, the pushing of the context data which has not been updated into the stack comprises: when all of the other context data except the context data which has not been updated is pushed into the stack, if it is determined that the context data which has not been updated has been updated, the context data which has been updated is pushed into the stack; if it is determined that the context data which has not been updated has not been updated, the context data which has been updated is pushed into the stack after the update is completed. That is, when all of the other context data except the context data which has not been updated is pushed into the stack, it is determined whether the context data which has not been updated has been updated before the context data which has not been updated is pushed into the stack, if the context data which has not been updated has been updated, the context data which has been updated is pushed into the stack; otherwise, the pushing is waited until the context data which has not been updated is updated.
[0044] Step S200, if there is no context data to be updated, then stack all context data in order.
[0045] That is, if all context data has been updated when the stacking action occurs, then stack all context data in order directly, which can be implemented by using the prior art, and thus is not described here.
[0046] Optionally, the context data can include one or more of program status register data, fixed point register data, floating point register data and interrupt return address.
[0047] Further, as a specific example, as shown in Figure 2 the data stacking method can include the following steps:
[0048] Step S101, respond to the interrupt request.
[0049] Step S102, determine whether there is context register (e.g., program status register, fixed point register, floating point register) to be updated. If yes, execute step S103; otherwise, execute step S107.
[0050] Step S103, record the context register to be updated, and stack other context data (e.g., context data that has been updated or does not need to be updated) first.
[0051] It should be noted that the instructions that are not completed are executed in parallel while stacking the other context data.
[0052] Step S104, after the stacking of the other context data is completed, determine whether the context register to be updated has been updated. If yes, execute step S105; otherwise, execute step S106.
[0053] Step S105, stack the context register data to be updated until the stacking is completed.
[0054] Step S106, wait for the context register to be updated, and after the updating is completed, execute step S105.
[0055] Step S107, stack the context data in order until the stacking is completed.
[0056] Thus, if there is context data to be updated during the stacking process, it is skipped first, and the context data that has been updated or does not need to be updated is stacked preferentially, so that the stacking operation and the operation of updating the context data to be updated are performed in parallel, i.e., the instruction execution time and the stacking time are overlapped, thereby reducing or eliminating the waiting time for the completion of the instruction execution.
[0057] The following is an example of three specific implementations of the data stack method described above.
[0058] As a first example, the context data that has not been updated is skipped and is stacked after the other context data is completely or partially stacked, including: all context data is stacked in order, and when the context data that has not been updated is stacked, if it is determined that the context data that has not been updated has not been updated, the context data that has not been updated is skipped and the subsequent context data is stacked until the context data that has not been updated is stacked after the subsequent context data is completely stacked.
[0059] That is, when the stacking action occurs, if there is context data that has not been updated, all context data is stacked in order, and when the context data that has not been updated is stacked, it is determined whether the context data that has not been updated has been updated, if the context data that has not been updated has not been updated, the context data that has not been updated is skipped and the context data behind is continuously stacked, and the context data that has not been updated before is stacked after the context data behind is completely stacked. Further, when the context data that has not been updated is stacked, if the context data that has not been updated has been updated, all context data is continuously stacked in order.
[0060] As a specific example, as shown in Figure 3 the entire data stacking process can include the following steps:
[0061] Step S201, responding to an interrupt request.
[0062] Step S202, determining whether there is context register (such as program status register, fixed point register, floating point register) that has not been updated. If yes, step S203 is executed; otherwise, step S209 is executed.
[0063] Step S203, recording the context register to be updated, and stacking all context data in order.
[0064] Step S204, when the context register to be updated is stacked, it is determined whether the register has been updated. If yes, step S209 is executed; otherwise, step S205 is executed.
[0065] Step S205, skipping the context register to be updated, and stacking the context data behind.
[0066] Step S206, after the context data behind is completely stacked, it is determined whether the context register to be updated has been updated. If yes, step S207 is executed; otherwise, step S208 is executed.
[0067] Step S207, stack the context registers to be updated until the stacking is completed.
[0068] Step S208, wait for the completion of the updating of the context registers to be updated, and after the updating is completed, execute step S207.
[0069] Step S209, stack the context data in order until the stacking is completed.
[0070] Thus, when stacking the data, the context data is stacked in order first, when the stacking reaches the context data to be updated, the context data to be updated is skipped first, and the stacking of the subsequent context data is performed, and finally the context data to be updated is stacked, so that the stacking time and the time of executing the instruction can be overlapped, the time of waiting for executing the instruction can be reduced or eliminated, and the interrupt response time is improved.
[0071] As a second example, the context data to be updated is skipped, and the context data to be updated is stacked after the stacking of the other context data is completed, including: stacking the context data after the context data to be updated in order first, stacking the context data before the context data to be updated in order, and finally stacking the context data to be updated.
[0072] That is, the data stacking can be performed in a round-robin manner, that is, the context data to be updated is determined at the beginning of the data stacking, and then the data after the context data to be updated is stacked first, the data before the context data to be updated is stacked, and finally the context data to be updated is stacked.
[0073] As a specific example, as shown in FIG. 3, the data stacking process can include the following steps: Figure 4
[0074] Step S301, responding to the interrupt request.
[0075] Step S302, determining whether there is context register (such as program status register, fixed point register, floating point register) to be updated. If yes, execute step S303; otherwise, execute step S308.
[0076] Step S303, recording the index T of the context register to be updated, and stacking from the index position T+1 in order to the end of the stack. Then, execute step S209, stacking from the position at the beginning of the stack to the index T-1 of the register.
[0077] Step S304, stacking from the position at the beginning of the stack to the index T-1 of the register.
[0078] Step S305, determine whether T is completed updating. If yes, execute step S306; otherwise, execute step S307.
[0079] Step S306, stack the data corresponding to the register index T until the stacking is completed.
[0080] Step S307, wait for the data corresponding to the register index T to be updated, and after the updating is completed, execute step S306.
[0081] Step S308, stack the context data in sequence until the stacking is completed.
[0082] Thus, when stacking the data, if it is confirmed that there is context data which is not completed updating, the subsequent context data is stacked first until the bottom of the stack, then the context data is stacked from the top of the stack until the context data which is not completed updating is stacked, and finally the context data which is not completed updating is stacked, so that the stacking time and the time of executing the instruction can be overlapped, the time of waiting for executing the instruction can be reduced or eliminated, and the interruption response time is improved.
[0083] As a third example, the context data which is not completed updating is skipped, and the context data which is not completed updating is stacked after all or part of the other context data is stacked, including: dividing all the context data into multiple data intervals; after determining the data interval in which the context data which is not completed updating is located, stacking the context data corresponding to the other data intervals first, and then stacking the context data corresponding to the data interval in which the context data which is not completed updating is located.
[0084] That is, the regions of the stack can be divided, and the stacking order of each region is adjusted, the region in which there is no context data which is not completed updating is stacked first, and then the region in which the context data which is not completed updating is stacked.
[0085] In some embodiments, the multiple data intervals include a first data interval and a second data interval with the same data length, and the data updating time length of the context data which is not completed updating is respectively less than the data stacking time length of the first data interval and the second data interval, and further, the context data corresponding to the other data intervals is stacked first, and then the context data corresponding to the data interval in which the context data which is not completed updating is located is stacked, including: when the context data which is not completed updating is in the first data interval, the context data corresponding to the second data interval is stacked first, and then the context data corresponding to the first data interval is stacked; when the context data which is not completed updating is in the second data interval, the context data corresponding to the first data interval is stacked first, and then the context data corresponding to the second data interval is stacked.
[0086] As a specific example, as shown in FIG. 3, the context data is divided into three data intervals, and the data intervals are respectively denoted as interval 1, interval 2 and interval 3. Figure 5As shown, the data stack process can include the following steps:
[0087] Step S401, in response to the interrupt request.
[0088] Step S402, determine whether there is an unfinished update context register. If yes, execute step S403; otherwise, execute step S409.
[0089] Step S403, record the context register to be updated, and divide all context data into two intervals: [0, a) and [a, b]. It should be noted that the update duration of the context register to be updated, i.e. the duration of the corresponding instruction execution, is less than the data stack duration corresponding to the interval [0, a) and less than the data stack duration corresponding to the interval [a, b], so that after the data stack corresponding to an interval is completed, the context register to be updated is also updated, thereby eliminating the waiting time for data update, i.e. the duration of instruction execution.
[0090] Step S404, determine whether the context register to be updated is in the interval [0, a). If yes, execute step S405; otherwise, execute step S407.
[0091] Step S405, stack the data in the interval [a, b].
[0092] Step S406, after the data stack in the interval [a, b] is completed, stack the data in the interval [0, a) until the stacking is completed.
[0093] Step S407, stack the data in the interval [0, a).
[0094] Step S408, after the data stack in the interval [0, a) is completed, stack the data in the interval [a, b] until the stacking is completed.
[0095] Step S409, stack all context data in sequence until the stacking is completed.
[0096] Thus, when the execution time of the unfinished instruction is less than one half of the total stacking time, the stack content can be divided into two equal regions [0, a) and [a, b], and the waiting time caused by data correlation can be eliminated by adjusting the stacking order of the two regions, thereby improving the interrupt response time.
[0097] In other embodiments, the multiple data intervals include a third data interval, a fourth data interval, and a fifth data interval. The third data interval and the fourth data interval have the same data length. The context data that has not been updated is located in the third data interval or the fourth data interval, and the data update time of the context data that has not been updated is less than the data push time of the third data interval and the fourth data interval, respectively. Further, the context data corresponding to other data intervals is pushed onto the stack first, and then the context data corresponding to the data interval where the context data that has not been updated is located is pushed onto the stack. This includes: when the context data that has not been updated is located in the third data interval, the context data corresponding to the fourth data interval is pushed onto the stack first, then the context data corresponding to the third data interval is pushed onto the stack, and finally the context data corresponding to the fifth data interval is pushed onto the stack; when the context data that has not been updated is located in the fourth data interval, the context data corresponding to the third data interval is pushed onto the stack first, then the context data corresponding to the fourth data interval is pushed onto the stack, and finally the context data corresponding to the fifth data interval is pushed onto the stack.
[0098] In other words, the data interval can include two or three. Specifically, when the execution time of the incomplete instruction is less than or close to half of the total push time, the data interval can include two, such as the first data interval and the second data interval, with the data push process described above. Conversely, when the execution time of the incomplete instruction is much less than the total push time, the data interval can include three, such as the third, fourth, and fifth data intervals. Two data intervals have the same data length (i.e., the same push time), and the incompletely updated context data is located in one of these two data intervals, with its update time being less than the push time of each of the two data intervals. In other words, the interval can be divided into three based on the instruction execution time and the location of the incompletely updated context data. Two intervals have the same data length, and their corresponding push time is slightly greater than the instruction execution time. This ensures that when data is pushed onto the stack in one interval, the instruction can be completed, meaning the incompletely updated context data is updated. Then, data is pushed onto the stack based on the three divided data intervals. For details, please refer to [reference needed]. Figure 6 Example shown.
[0099] As a concrete example, see reference Figure 6 As shown, the data push-to-stack process may include the following steps:
[0100] Step S501: Respond to the interrupt request.
[0101] Step S502: Determine if there are any unupdated context registers. If yes, proceed to step S503; otherwise, proceed to step S510.
[0102] Step S503: Record the context register to be updated and divide all context data into three intervals: [0, a), [a, b), and [b, c]. It should be noted that the update duration of the context register to be updated, i.e., the execution duration of the corresponding instruction, is less than the data push duration corresponding to interval [0, a) and less than the data push duration corresponding to interval [a, b). Furthermore, the context register to be updated is located in either interval [0, a) or interval [a, b). This ensures that the context register to be updated is completed after the data corresponding to one of these intervals is pushed onto the stack, thus eliminating the waiting time for data updates, i.e., the instruction execution duration.
[0103] Step S504: Determine whether the context register to be updated is in the range [0, a). If yes, proceed to step S505; otherwise, proceed to step S507.
[0104] Step S505: Push the data in the interval [a, b) onto the stack.
[0105] Step S506: After pushing the data in the interval [a, b) onto the stack, push the data in the interval [0, a) onto the stack until the stack push is complete.
[0106] Step S507: Push the data in the interval [0, a) onto the stack.
[0107] Step S508: After pushing the data in the interval [0, a) onto the stack, push the data in the interval [a, b) onto the stack until the pushing is complete.
[0108] Step S509: Push the data in the interval [b, c] onto the stack until the push is complete.
[0109] Step S510: Push all context data onto the stack in sequence until the stack push is complete.
[0110] Therefore, the stack content can be divided into multiple segments for processing. As shown above, the stack content is divided into three intervals: [0, a), [a, b), and [b, c]. The [0, a) interval is the same size as the [a, b) interval. At the same time, the execution time of the instruction is less than the time to push the corresponding data in [0, a) or [a, b) onto the stack, and the data to be updated is located in any interval of these two intervals. This ensures that the instruction completes the update of the context data during the push process, and the push process does not introduce waiting time.
[0111] Furthermore, in order to enable those skilled in the art to understand more clearly Figure 6 The corresponding data push-on process will be explained with a more specific example below.
[0112] For example, taking the Arm-M instruction set architecture commonly used in embedded processors as an example, when the floating-point division instruction is not completed and the current program execution encounters an interrupt request, the fixed-point context can be stacked first, and the floating-point division and the stacking process are executed in parallel, and then when the floating-point context is stacked, it is first judged whether the target register index of the floating-point division falls within the interval of S0 to S7. If yes, it indicates that there is data in the S0 to S7 floating-point registers that has not been updated, at this time, the data stacking process of S0 to S7 is skipped, and the stacking of the data of S8 to S15 floating-point registers is started, thereby avoiding the time delay caused by waiting for the floating-point division target register to be updated. After completing the data stacking of the S8 to S15 floating-point registers, the fixed-point context and the floating-point context consume 16 clock cycles (the fixed-point context consumes 8 clock cycles), and if the number of division operation periods is less than or equal to 16, the data of S0 to S7 has been updated to obtain the operation result of the floating-point division, so that the data of S0 to S7 can be stacked into the stack, and the time of waiting for the floating-point register to be updated is eliminated. Similarly, if the floating-point division target register is not in the interval of S0 to S7 floating-point registers, the S0 to S7 floating-point register context is first stacked into the stack, and after completing the context stacking of S0 to S7, the fixed-point context and the floating-point context consume 16 clock cycles, and in the case that the number of division operation periods is less than or equal to 16, the result of the division is also updated to the target register, so that the subsequent floating-point context stacking operation can be continued, and the time of waiting for the division to update the target register is eliminated. The specific data stacking process is shown in Figure 7 may include the following steps:
[0113] Step S601, responding to an interrupt request.
[0114] Step S602, stacking the data of the fixed-point register.
[0115] Step S603, judging whether the floating-point division target register is in S0 to S7. If yes, step S604 is executed; otherwise, step S606 is executed.
[0116] Step S604, stacking the data of floating-point registers S8 to S15.
[0117] Step S605, after the data stacking of floating-point registers S8 to S15 is completed, the data of floating-point registers S0 to S7 is stacked.
[0118] Step S606, stacking the data of floating-point registers S0 to S7.
[0119] Step S607, after the data stacking of floating-point registers S0 to S7 is completed, the data of floating-point registers S8 to S15 is stacked.
[0120] Step S608, stack the data of the floating point registers S16 to S31.
[0121] Step S609, stack the data of the floating point status registers until the stack is completed.
[0122] Further, the above stack method can be extended to adapt to longer division operation clock cycles, so that the above stack method has universality.
[0123] Specifically, assuming that the floating point operation period is m and the stack fixed point context clock period is n, the floating point context index can be selected as t = m - n, and the floating point registers are divided into three intervals: S(0) to S(t-1), S(t) to S(2t-1), and S(2t) to S31. When the index of the floating point division target register is in the interval S0 to S(t-1), the data of the floating point registers S(t) to S(2t-1) is stacked first, and then the data of the floating point registers S0 to S(t-1) is stacked. When the index of the floating point division target register is not in the interval S(0) to S(t-1), the data of the floating point registers S(0) to S(t-1) is stacked first, and then the subsequent floating point stack is performed. The specific data stack process is as shown in Figure 8 The method can include the following steps:
[0124] Step S701, respond to an interrupt request.
[0125] Step S702, stack the data of the fixed point registers.
[0126] Step S703, determine whether the floating point division target register is in S(0) to S(t-1). If yes, execute step S704; otherwise, execute step S706.
[0127] Step S704, stack the data of the floating point registers S(t) to S(2t-1).
[0128] Step S705, after the data of the floating point registers S(t) to S(2t-1) is stacked, stack the data of the floating point registers S(0) to S(t-1).
[0129] Step S706, stack the data of the floating point registers S(0) to S(t-1).
[0130] Step S707, after the data of the floating point registers S(0) to S(t-1) is stacked, stack the data of the floating point registers S(t) to S(2t-1).
[0131] Step S708, stack the data of the floating point registers S(2t) to S31.
[0132] Step S709, push the floating point state register data to the stack until the pushing is completed.
[0133] It should be noted that the above three implementation manners have respective advantages in applicability and practicability, and can be flexibly selected according to actual instruction execution time and the number of context data, and the specific implementation is not limited here; and the data pushing method of the present application is not only applicable to the pushing of fixed point data, but also applicable to the pushing of floating point data, such as floating point division, floating point multiplication and other multi-cycle floating point or fixed point instructions, wherein, since the floating point division instruction usually has a longer execution time, the data pushing method of the present application can more obviously improve the real-time performance of interrupt response. In addition, the idea of the data pushing method of the present application is to adjust the context pushing sequence according to the context data to be updated, so as to hide the updating time of the data to be updated in the context data pushing process, thereby reducing or eliminating the waiting time for data updating. The division mode of the context register in the above examples is only exemplary, and other division modes or by adjusting the pushing sequence of the context data should be considered as consistent with the method principle of the present application.
[0134] In summary, according to the data pushing method of the embodiment of the present application, when the pushing action occurs, if there is context data to be updated, the context data to be updated is skipped, and after all or part of the other context data is pushed to the stack, the context data to be updated is pushed to the stack again; if there is no context data to be updated, all context data is sequentially pushed to the stack. Thus, when there is context data to be updated, the data pushing and data updating can be parallel, the waiting time for data updating can be reduced or eliminated, and the real-time performance of interrupt response can be improved.
[0135] Figure 9 For the structure of the data pushing device according to an embodiment of the present application, reference is made to Figure 9 It is shown that the data pushing device 50 can include a determination module 51 and a pushing module 52.
[0136] The determination module 51 is used to determine the context data to be updated when the pushing action occurs. The pushing module 52 is used to skip the context data to be updated when the determination module determines that there is context data to be updated, and push the context data to be updated to the stack after all or part of the other context data is pushed to the stack, and sequentially push all context data to the stack when the determination module determines that there is no context data to be updated.
[0137] As a first embodiment, the pushing module 52 is specifically configured to: first push all the context data in sequence, and when pushing the context data that is not updated, if it is determined that the context data that is not updated is still not updated, then the context data that is not updated is skipped and the subsequent context data is pushed until the subsequent context data is pushed completely, and then the context data that is not updated is pushed.
[0138] Further, in some embodiments, the pushing module 52 is further configured to: when pushing the context data that is not updated, if it is determined that the context data that is not updated has been updated, then all the context data is pushed in sequence.
[0139] As a second embodiment, the pushing module 52 is specifically configured to: first push the context data that is sorted after the context data that is not updated in sequence, then push the context data that is sorted before the context data that is not updated in sequence, and finally push the context data that is not updated.
[0140] As a third embodiment, the pushing module 52 is specifically configured to: divide all the context data into multiple data intervals; after determining the data interval in which the context data that is not updated is located, first push the context data corresponding to other data intervals, and then push the context data corresponding to the data interval in which the context data that is not updated is located.
[0141] Further, in some embodiments, the multiple data intervals include a first data interval and a second data interval with the same data length, and the data update duration of the context data that is not updated is respectively less than the data pushing duration of the first data interval and the second data interval, and the pushing module 52 is further configured to: when the context data that is not updated is in the first data interval, first push the context data corresponding to the second data interval, and then push the context data corresponding to the first data interval; when the context data that is not updated is in the second data interval, first push the context data corresponding to the first data interval, and then push the context data corresponding to the second data interval.
[0142] Further, in some embodiments, the plurality of data sections comprises a third data section, a fourth data section and a fifth data section, the third data section and the fourth data section have the same data length, the context data to be updated is in the third data section or the fourth data section, and the data update time length of the context data to be updated is respectively less than the data stack time length of the third data section and the fourth data section, and the stack module 52 is further configured to: when the context data to be updated is in the third data section, stack the context data corresponding to the fourth data section first, then stack the context data corresponding to the third data section, and finally stack the context data corresponding to the fifth data section; when the context data to be updated is in the fourth data section, stack the context data corresponding to the third data section first, then stack the context data corresponding to the fourth data section, and finally stack the context data corresponding to the fifth data section.
[0143] In some embodiments, the context data comprises one or more of program status register data, fixed point register data, floating point register data and interrupt return address.
[0144] In some embodiments, the stack module 52 is further configured to: if it is determined that the context data to be updated has been updated, stack the context data after the update; and if it is determined that the context data to be updated has not been updated, stack the context data after the update.
[0145] It should be noted that the description of the data stack device in the present application can refer to the description of the data stack method in the present application, which will not be repeated here.
[0146] According to the data stack device, when the stack action occurs, the determining module determines the context data to be updated, when there is context data to be updated, the stack module skips the context data to be updated, and stacks the context data to be updated after all or part of the other context data is stacked, and when there is no context data to be updated, stacks all the context data in sequence. Thus, when there is context data to be updated, the data stack and the data update can be parallel, the waiting time for the data update can be reduced or eliminated, and the real-time performance of the interrupt response can be improved.
[0147] In some embodiments, the embodiments of the present application also provide a chip comprising a memory and a processor, the memory stores a computer program, and the processor implements the steps of the data stack method as described above when executing the computer program.
[0148] According to the chip of the embodiment of the present application, by using the data stack method, when there is context data to be updated, the data stack and the data update can be performed in parallel, the time for waiting for the data update can be reduced or eliminated, and the real-time performance of the interrupt response can be improved.
[0149] In some embodiments, the embodiment of the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the data stack method.
[0150] According to the computer readable storage medium of the embodiment of the present application, by using the data stack method, when there is context data to be updated, the data stack and the data update can be performed in parallel, the time for waiting for the data update can be reduced or eliminated, and the real-time performance of the interrupt response can be improved.
[0151] It should be noted that the logic and / or steps represented in the flowcharts and / or otherwise described herein, for example, can be considered as a list of executable instructions for implementing logic functions, and can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus or device, such as a computer-based system, processor- based system, or other system that can fetch the instructions from the instruction execution system, apparatus or device and execute the instructions, or in conjunction with which the instructions can be executed. For the purposes of this specification, a "computer-readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus or device. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection having one or more wires (electrical apparatus), a portable computer diskette (magnetic apparatus), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber (optical apparatus), and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium can even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, for example, by optically scanning the paper or other suitable medium, then electronically converted into a form that can be further processed by the computer. Therefore, the computer-readable medium can be paper or another suitable medium that can be treated as a computer-readable medium to store data for execution by the computer.
[0152] It should be understood that portions of the present application can be realized with a hardware, software, firmware or a combination thereof. In the above-described embodiments, a plurality of steps or methods can be realized with software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if realized with hardware, and as in another embodiment, it can be realized with any one or a combination of the following technologies known in the art: discrete logic circuit having logic gates for implementing logic functions on data signals, application specific integrated circuits having appropriate combinational logic gates, programmable gate arrays (PGA), field programmable gate arrays (FPGA), etc.
[0153] In the description of the present specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Also, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.
[0154] In addition, the terms "first", "second", "third", etc. are used only for the purpose of description and should not be construed as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present application, the meaning of "a plurality of" is at least two, for example, two, three, etc., unless otherwise explicitly specified and limited.
[0155] In the present application, unless otherwise explicitly specified and limited, the terms "mounting", "connection", "connecting", "fixing" and the like should be understood broadly, for example, can be fixed connection, can be detachable connection, or integral; can be mechanical connection, can be electrical connection; can be directly connected, can be indirectly connected through an intermediate medium, can be internal communication of two elements or interaction relationship between two elements, unless otherwise explicitly limited. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0156] Although the embodiments of the present application have been shown and described above, it should be understood that the above-described embodiments are exemplary and should not be construed as limiting the present application, and those skilled in the art can make changes, modifications, replacements and variations to the above-described embodiments within the scope of the present application.
Claims
1. A data push stack method, characterized in that, include: When a push operation occurs, if there is incompletely updated context data, the incompletely updated context data is skipped, and the incompletely updated context data is pushed onto the stack only after all or part of the other context data has been pushed onto the stack. This includes: first, pushing all context data onto the stack in sequence; and when pushing the incompletely updated context data onto the stack, if it is determined that the incompletely updated context data is still not updated, then skipping the incompletely updated context data and pushing subsequent context data onto the stack, until the subsequent context data is pushed onto the stack, then pushing the incompletely updated context data onto the stack; if it is determined that the incompletely updated context data has been updated, then continuing to push all context data onto the stack in sequence. Pushing the incompletely updated context data onto the stack includes: if it is determined that the incompletely updated context data has been updated, then pushing the updated context data onto the stack; if it is determined that the incompletely updated context data has not been updated, then pushing the updated context data onto the stack only after the update is completed. If no context data has been updated, then all context data are pushed onto the stack in sequence.
2. The data pushing method according to claim 1, characterized in that, The step of skipping the incompletely updated context data and pushing the incompletely updated context data onto the stack only after all or part of the other context data has been pushed onto the stack also includes: First, push the context data after the context data that has not been updated onto the stack in order. Then, push the context data before the context data that has not been updated onto the stack in order. Finally, push the context data that has not been updated onto the stack.
3. The data pushing method according to claim 1, characterized in that, The step of skipping the incompletely updated context data and pushing the incompletely updated context data onto the stack only after all or part of the other context data has been pushed onto the stack also includes: Divide all context data into multiple data ranges; After determining the data range where the incompletely updated context data is located, first push the context data corresponding to other data ranges onto the stack, and then push the context data corresponding to the data range where the incompletely updated context data is located onto the stack.
4. The data pushing method according to claim 3, characterized in that, The plurality of data intervals includes a first data interval and a second data interval with the same data length, and the data update time of the context data that has not been updated is less than the data push time of the first data interval and the second data interval, respectively. The step of first pushing the context data corresponding to other data intervals onto the stack, and then pushing the context data corresponding to the data interval where the context data that has not been updated is located onto the stack, includes: When the context data that has not been updated is in the first data interval, push the context data corresponding to the second data interval onto the stack first, and then push the context data corresponding to the first data interval onto the stack. When the context data that has not been updated is in the second data range, push the context data corresponding to the first data range onto the stack first, and then push the context data corresponding to the second data range onto the stack.
5. The data pushing method according to claim 3, characterized in that, The plurality of data intervals include a third data interval, a fourth data interval, and a fifth data interval. The third data interval and the fourth data interval have the same data length. The context data that has not been updated is located in the third data interval or the fourth data interval, and the data update time of the context data that has not been updated is less than the data push time of the third data interval and the fourth data interval, respectively.
6. The data pushing method according to claim 5, characterized in that, The step of first pushing context data corresponding to other data ranges onto the stack, and then pushing context data corresponding to the data range containing the incompletely updated context data onto the stack, includes: When the context data that has not been updated is in the third data interval, first push the context data corresponding to the fourth data interval onto the stack, then push the context data corresponding to the third data interval onto the stack, and finally push the context data corresponding to the fifth data interval onto the stack. When the context data that has not been updated is in the fourth data interval, the context data corresponding to the third data interval is pushed onto the stack first, then the context data corresponding to the fourth data interval is pushed onto the stack, and finally the context data corresponding to the fifth data interval is pushed onto the stack.
7. The data pushing method according to claim 1, characterized in that, The context data includes one or more of the following: program status register data, fixed-point register data, floating-point register data, and interrupt return address.
8. A data stacking device, characterized in that, include: The determination module is used to determine the context data that has not been updated when a push operation occurs; The stack pushing module is used to: when the determining module determines that there is incompletely updated context data, skip the incompletely updated context data and push the incompletely updated context data onto the stack only after all or part of the other context data has been pushed onto the stack; and when the determining module determines that there is no incompletely updated context data, push all context data onto the stack in sequence, including: first, push all context data onto the stack in sequence, and when pushing the incompletely updated context data onto the stack, if it is determined that the incompletely updated context data is still not updated, skip the incompletely updated context data and push subsequent context data onto the stack until the subsequent context data is pushed onto the stack, then push the incompletely updated context data onto the stack; if it is determined that the incompletely updated context data has been updated, continue pushing all context data onto the stack in sequence, wherein pushing the incompletely updated context data onto the stack includes: if it is determined that the incompletely updated context data has been updated, push the updated context data onto the stack; if it is determined that the incompletely updated context data has not been updated, push the updated context data onto the stack only after the update is completed.
9. The data stacking device according to claim 8, characterized in that, The stacking module is specifically used to: first, push the context data after the context data that has not been updated in order onto the stack; then, push the context data before the context data that has not been updated in order onto the stack; and finally, push the context data that has not been updated onto the stack.
10. The data stacking device according to claim 8, characterized in that, The stacking module is specifically used to: divide all context data into multiple data intervals, and after determining the data interval where the context data that has not been updated is located, first push the context data corresponding to other data intervals onto the stack, and then push the context data corresponding to the data interval where the context data that has not been updated is located onto the stack.
11. A chip comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the data push stack method according to any one of claims 1 to 7.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the data push stack method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Data backup method, data backup system and terminal
CN106294003A
Device which supports multiple SPI interface standard sets based on SoC
CN107015927A