The present invention relates to a computer system, and specifically to a technology of handling a timer device.
Patent Literature 1 discloses that a DMA engine is instructed to transmit data stored in a plurality of memory areas, the DMA engine transmits the specified data sequentially, and the DMA engine receives the transmit instruction again after completing the transmit, thereby repeating the same processing.
Patent Literature 1: U.S. Pat. No. 6,111,592 A
In general, when a central processing unit (CPU) performs reading and/or writing on various storage devices, a difference between an operation clock of the CPU and an operation clock of the storage device or a property of the storage device causes a “wait” of the CPU. The “wait” is more prominent, compared to the case of the primary storage device, in reading from and writing to a register of an input/output device accessed in a way similar to the primary storage device being read/written by the CPU.
As a means for reducing the “wait”, there is a method of transferring a content using a DMA device out of synchronization with the CPU, as described in Patent Literature 1. Patent Literature 1 describes the method of repeating the transfer of the content by the DMA device, which is intended to transmit the data between the primary storage devices but not for an access to the input/output device. The input/output device may not necessarily be accessible by the DMA device, but its value may need some kind of conversion when being used by software. In addition, since an interrupt occurs to the CPU upon completion of the transmission by the DMA device, there is a problem that frequent transmissions may increase the processing load on the CPU due to an interrupt handler.
The present invention aims to address the issue of the “wait” caused by an access to the register of the input/output device while minimizing the increase of the processing load due to the interrupt.
In the present invention, a CPU core or a DMA device other than the CPU core performing a processing that needs to access the register (hereinafter, referred to as a processing core or a processing unit) is used to constantly transfer the latest value from the device register to the primary storage device. The processing core is not limited to performing the processing of the interrupt handler but it can also avoid the wait that occurs when directly reading the device register by reading the transferred value on the primary storage device instead of accessing the register. Since the value transfer is performed out of synchronization with the processing core, the processing core has neither to wait for completion of the transfer nor to process the interrupt or notification from another CPU core or the DMA device.
According to one aspect of the present invention, it is possible to reduce delay of the register of the input/output device caused by a read access when there are too many read accesses, and thereby improving a use efficiency of the processing core.
This example achieves, as described below, a trace log function of recording a log of an operation of an operating system on a computer system. The trace log needs to record a timestamp at which an event to be recorded occurred along with the event for use in a later analysis.
The present invention is beneficial to obtain timestamp information so as not to influence the process of the CPU that records the event.
The CPU 110 may be a general-purpose processor, which reads out software such as an application 121 and an operating system 122 from the non-volatile storage device 125 or the like, and deploys and executes the software on the primary storage device 120 as needed. Although
The primary storage device 120 is a readable/writable non-volatile storage area, on which command is executed by the CPU 110, or which is readable and writable by a command including a load command and a store command. Arranged on the primary storage device 120 are software program and data including the application 121 and the operating system 122. As described later, however, there may be arranged the program and data that are not rewritten upon execution on the non-volatile storage device 125, and in such a case, the program and data on the non-volatile storage device 125 may not be present on the primary storage device 120. The primary storage device 120 is constituted by, for example, a DRAM or the like.
The non-volatile storage device 125 is a readable non-volatile storage area, on which a command is executed by the CPU 110, or which is readable by a load command. By arranging the program and data that does not cause rewrite of the software, it is also possible for the CPU 110 to directly execute or read them. Hereinafter, the explanation is given assuming that all the software program and data are present on the primary storage device 120, and the same applies to a case in which a part of the software program and data is located on the non-volatile storage device 125.
The application 121 is software for achieving a function provided by the computer system 100. The application 121 consists of a single or a plurality of tasks. The computer system 100 may include only one application 121 or a plurality of applications 121. The operating system 122 is capable of multi-task processing, which can execute a plurality of applications 121 and tasks thereof in parallel. The operating system 122 switches operations between tasks, copes with an interrupt from an input/output device, and the like. The computer system 100 may also take an OS-less configuration used for an embedded device, in which case there is no distinction between the application 121 and the operating system 122 and a single task provides the functions of the application 121 and the operating system 122. Hereinafter, the explanation is given assuming that the application 121 is distinguished from the operating system 122, and the same applies to the case of the OS-less configuration.
The operating system 122 includes a timestamp transfer buffer 131, a timestamp counter 132, and a trace buffer 140 as its data structure, for example. Naturally, the operating system 122 may also include other data structures to provide functions required for the operating system. The timestamp transfer buffer 131 is an area that stores therein a value indicative of information of a timestamp transferred from a register of a device that stores therein the information. The timestamp counter 132 is incremented by 1 every time the timestamp transfer buffer 131 is read out. The trace buffer 140 is an area to record a certain event that occurred in the operating system 122 and to store a trace log 141 no smaller than 0. Each trace log 141 corresponds to an occurrence of a single or a plurality of events. The event to be recorded may be for example, an interrupt that occurred or switching of tasks executed in the operating system 122, and the event to be recorded may be altered depending on its application or may be dynamically altered depending on the state of execution.
The trace log 141 includes a log timestamp 145 and a log content 146 as an internal structure. The log timestamp 145 indicates a timestamp at which an event corresponding to the trace log 141 occurred. The log content 146 indicates the content of the event. The log content 146 may include, for example, a type of the event, information about an object of the event such as a number indicative of the type of the interrupt in the case of the interrupt, and the like.
The timer device 150 is a device that measures actual time. For example, it may be a device that includes a counter which counts up based on a clock at a constant period and it may not necessarily indicate an absolute timestamp. The counter of the timer device 150 can gain the value by accessing the timestamp register 151 from the CPU 110. A method of accessing the timestamp register 151 by the CPU 110 may use a dedicated I/O port command or a load command to a specific address. It should be noted that, however, the “wait” time caused to the reading of the value is longer than that caused to the reading of a value by the primary storage device 120.
The DMA device 160 is a device that performs memory transmission independently of the CPU 110. The DMA device 160 transfers a specified size of the content from a specified source address to a specified destination address according to an instruction from the CPU 110. In this example, when performing the transfer by the CPU core 110B, the DMA device 160 is not always required; on the other hand, the DMA device 160 can also be used for the transfer from the register as an alternative for the CPU core 110B. The processing in the case of using the DMA device 160 as an alternative will be described at the end of description of this example.
Although
In this example, the CPU core 110B in charge of transfer reads out a value from the timestamp register 151, which is used as a timestamp value 211. The timestamp value 211 may be the same value as the read value or may be another value appropriately converted therefrom. The timestamp value 211 is written to the timestamp transfer buffer 131 asynchronously at a timing different from the processing by the CPU core 110A. This enables the transfer from the timestamp register 151 to the timestamp transfer buffer 131. The CPU core 110A requiring the timestamp information calculates a timestamp record value 212 from values of the timestamp transfer buffer 131 and the timestamp counter 132. This may be a value simply connecting the timestamp transfer buffer 131 and the timestamp counter 132 or a value appropriately converted therefrom. One example of the timestamp information would be the log timestamp 145 of the trace log 141, and the CPU core 110A stores the timestamp record value 212 in the log timestamp 145.
Description is now given with reference to
In other words, because the “wait” caused by reading from the primary storage device 120 is sufficiently shorter than the “wait” caused by the direct reading from the timestamp register 151, it is possible to reduce the delay caused when the CPU core 110A directly accesses the timestamp register 151.
It should be noted that other processing than in the operation flow of transfer described above may be performed as the processing of the CPU core 110B. In such a case, it is also possible to put the lowest priority to the operation flow of transfer so that, if there is any other task to be executed, it is executed.
In
Next, the CPU core 110B writes the timestamp value 211 to the timestamp transfer buffer 131 (Step 412A). This changes the value of the timestamp transfer buffer 131 to 10 (Step 131a). The CPU core 110A starts processing thereafter to read values from the timestamp transfer buffer 131 and the timestamp counter 132 (Step 311A). These values are 10 and 5, respectively (Steps 131b, 132a). By adding 1 to the timestamp counter 132 (Step 312A), the value of the timestamp counter 132 becomes 6 (Step 132b). As a result, the timestamp record value 212 obtained by the CPU core 110A in the form of (timestamp transfer buffer 131, timestamp counter 132) is (10, 5).
Now, consider that the CPU core 110B performs the transfer processing again. The processing includes, as in the case described previously, read-out from the timestamp register 151 (Step 411B) and write to the timestamp transfer buffer 131 (Step 412B). The value of the timestamp register 151 at this time is assumed to be 20 (Step 151b).
Now, consider the case in which the recording of the next log by the CPU core 110A is performed in parallel and the read-out from the timestamp transfer buffer 131 and the timestamp counter 132 (Step 311B) is performed earlier than
Step 411B. In this case, the values read by the CPU core 110A are 10 and 6 (Steps 131c, 132c), and the timestamp record value 212 obtained by the CPU core 110A is (10, 6). The write by the CPU core 110B (Step 412B) then changes the timestamp transfer buffer 131 to 20 (Step 131d), then the timestamp counter 132 indicates 7 (Step 132d) by addition by the CPU 110A (Step 312B).
By the processing described above, the CPU core 110A obtains the values of (10, 5) and (10, 6) from the two calculations of the timestamp record value 212. If there is no timestamp counter 132, only the timestamp transfer buffer 131 can be used to calculate the timestamp record value 212, which makes the two timestamp record values 212 both 10. As a result, the first and second timestamp record values 212 cannot be distinguished from each other, which makes it difficult to determine the order of the two trace logs 141 by their log timestamps 145 although there is actually the order. According to this example, however, the different values of (10, 5) and (10, 6) can be obtained, and their order can be apparently determined by the values of the timestamp counters 132.
In other words, since the processing of the CPU 110A is not linked to the processing of the CPU 110B, it is possible to avoid that the CPU 110A receives the same timestamp despite the lapse of time.
It should be noted that, depending on the usage of the obtained trace log 141, when there is no need of distinguishing between the two timestamp record values 212 described with reference to
In contrast, it is also conceivable to use only the timestamp counter 132 and use it as the timestamp value 211. In this case, however, since the value of the timestamp register 151 indicative of the actual time is not reflected at all, the accuracy is low as the timestamp information and only the order can be obtained. Using the timestamp transfer buffer 131 makes it possible to obtain information of the actual time, though not a real-time value.
When the DMA device 160 can access the timestamp register 151 in the same manner as loading the primary storage device 120 and the value of the timestamp transfer buffer 131 is stored in the same manner as the timestamp register 151, it is also possible to use the DMA device 160 instead of the CPU core 110B. In this case, a given core of the CPU 110 can perform the transfer by the DMA device 160 setting the timestamp register 151 as the source address, the timestamp transfer buffer 131 as the destination address, and the size of the timestamp register 151 as the transmission size. Furthermore, if the DMA device 160 can notify the CPU 110 of completion of the transfer in the form of interrupt, the CPU 110 is by the notification the DMA device 160 to perform the transfer again. Moreover, if the DMA device 160 can be set to repeat the transfer, the CPU 110 may set the transfer only once when initializing the operating system 122. In this case, the DMA device 160 does not need to interrupt the CPU 110 due to completion of the transfer and thus the CPU 110 does not need to process the interrupt. In this manner, the DMA device 160 can replace the transfer function performed by the CPU core 110B in the above description.
Example 2 is related to a function of monitoring whether execution time of each task exceeds a prespecified timestamp on an operating system, specifically on a real-time operating system
In order to monitor whether the prespecified timestamp is exceeded, it is necessary to notify the timer device of the timestamp used as a reference for determination and, if the timestamp is exceeded, to notify the CPU by causing only a timer interrupt to the timer device.
However, there is a problem of requiring many operation clocks to set an interrupt timestamp to the timer device as in Example 1. To address this problem, delay of an application can be prevented by causing the CPU core that is not executing the application to set the interrupt timestamp to the timer device instead of causing the CPU core that is executing the application to set the interrupt timestamp. The specific processing thereof is described below.
A task 521 constitutes the application 121. Although there is a plurality of tasks 521 in
A task management unit 540 manages information of the task 521, and includes, for example, a task management table 541. The task management table 541 is a table that contains information about each task 521 in one row for management of the task 521. Details thereof will be described with reference to
The timer device 150 includes a function of interrupting the CPU 110 when the value of the timestamp register 151 reaches a set value, in addition to the functions described with reference to Example 1. The timer device 150 includes an interrupt setting register 552, which sets whether to validate occurrence of an interrupt, a value of the timestamp register 151 that causes the interrupt, and the like.
The operating system 122 includes an interrupt setting buffer 533 and a task management unit 540. The interrupt setting buffer 533 stores therein a value to be set to the interrupt setting register 552 of the timer device 150 to be described later, and the like. The interrupt setting buffer 533 includes, for example, an interrupt validity flag 535 and an interrupt timestamp 536. The interrupt validity flag 535 is a value indicating that, for example, the interrupt validity flag 535 indicates, if it stores therein a value to be “valid”, that the CPU 110 is interrupted when the value in the timestamp register 151 reaches the interrupt timestamp 536 and if it stores therein a value to be “invalid”, it indicates that no interrupt can occur even when the value in the timestamp register 151 reaches the interrupt timestamp 536. However, because it is naturally present on the primary storage device 120, the behavior of the timer device 150 cannot actually be changed unless it is transferred to the interrupt setting register 552 that achieves these functions of the timer device 150.
Although the task is managed based on the time limit in this example, it may be managed based on the timestamp instead of the time limit. For example, although the start time is set to 100 and the time limit is set to 200 in an example of task 3, the interrupt timestamp may be set to 300 instead of the time limit for management.
First, the flow when starting the execution of the task 521 in the application is described with reference to
After obtaining the timestamp record value 212 at Step 813, the timestamp record value 212 is stored in the start time 623 in the row of the task management table 541 corresponding to the task 521 to be executed, and the task state 622 is changed to “in execution” (814). After 814, the timestamp at which the task 521 must be terminated, namely a deadline, is calculated from the start time 623 and the time limit 624 (Step 815).
This calculation is, for example, a simple sum of the start time 623 and the time limit 624. The deadline is then set to the interrupt timestamp 536 of the interrupt setting buffer 533, and the interrupt validity flag 535 is set to a value to be “valid” (Step 816). Then the execution of the task 521 is started (Step 817). This makes it possible to record the start time when each task 521 starts its execution.
Next, the flow when terminating the execution of the task 521 is described with reference to
The time lapsed from the start to the end of the operation of the task, namely the execution time, is calculated from the timestamp record value 212 generated at Step 915 and the start time 623 (Step 916). This processing is performed by, for example, simple subtraction between two values.
The obtained execution time is then compared with the time limit 624 (Step 917). If the execution time exceeds the time limit 624 (Step 917: Yes), it is determined that the task 521 is executed beyond the specified execution time, which means an abnormal condition. Accordingly, a processing to be performed under such an abnormal condition is performed on the task 521 (Step 918).
This processing can be, for example, preventing the task from being activated again, or reactivating the whole computer system 100. In contrast, if the execution time does not exceed the time limit 624 (Step 917: No), the normal processing of terminating the execution is continued (Step 919).
Finally, a case in which an interrupt from the timer device 150 occurs is described with reference to
Next, if the task 521 is operating when the interrupt occurs, the execution state of the task 521 is determined by the task state 622 in the corresponding row of the task management table 541 (Step 1014). If the task state 622 is “in execution” (Step 1014: Yes), Steps 913, 914, and 915 are performed (1013), and if the obtained execution time exceeds the time limit 624 (Step 1012: Yes), processing is performed for the abnormality of the task 521 (Step 1015).
If the task is not executed (Step 1014: No) and the execution time is not exceeded (Step 1012: No), the process returns to the processing before the interrupt (Step 1016).
To do so, the interrupt setting value 613 corresponding to the contents of the interrupt validity flag 535 and the interrupt timestamp 536 are calculated first (Step 1115). The calculated interrupt setting value 613 is then set in the interrupt setting register 552 (Step 1116). This is the end of the transfer. After completion of setup in the interrupt setting register 552 or when the setup in the interrupt setting register 552 is not required (Step 1114: No), the CPU core 110B returns to Step 1111. As described with reference to
While two examples have been described above, when values on the same primary storage device 120 are accessed by a plurality of cores, a procedure necessary for the software to retain the consistency may be performed when loading or storing the values on the primary storage device 120 in each example, if any. For example, it may be a special command on the CPU 110 or a method using an exclusive control on the software, such as a typical lock.
While the case of obtaining the timestamp from the timer device is taken as an example in both example, the present invention is not limited to the timestamp information obtained from the timer device but can be applied to any information having a total or local monotonicity as the nature of the value. The timestamp is one example having a nature of monotonically increasing its value.
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/JP2015/051753 | 1/23/2015 | WO | 00 |