Apparatus and method for collecting tracking data

CN116018587BActive Publication Date: 2026-10-16ARM LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202180054540.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2020-08-03
Filing Date
2021-08-02
Publication Date
2026-10-16
Estimated Expiration
2041-08-02

AI Technical Summary

Technical Problem

因此,不可能重建完整的调用返回堆栈

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116018587B_ABST
    Figure CN116018587B_ABST
Patent Text Reader

Abstract

Data processing apparatus and methods for processing data are disclosed. The data processing apparatus comprises processing circuitry to process instructions; and a trace circuit comprising: a trace buffer; write pointer storage to store a write pointer to indicate a current position in the trace buffer; and a call depth counter to indicate a number of events, wherein the trace circuit is configured to generate trace data indicative of processing activity of the processing circuitry, and in response to a first event: modify the call depth counter in a first direction, store first trace data indicative of the first event at the current position in the trace buffer, and modify the write pointer to point to a next position in the trace buffer; in response to a second event, when the call depth counter is not equal to a threshold call depth: modify the call depth counter in a second direction, and modify the write pointer to point to a previous position in the trace buffer; and in response to the second event, when the call depth counter is equal to the threshold call depth, store second trace data indicative of the second event at the current position in the trace buffer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the generation of tracking data for instructing processing activities. Background Technology

[0002] Trace data comprises a series of data items indicating the processing activities of the data processing device. Typically, trace data is collected in a trace buffer, which can be a dedicated memory for storing trace data or a mapped area of ​​system memory. The trace buffer is used in a circular buffer model, where trace data is continuously written to a position within the circular buffer determined by a write pointer that advances through the buffer as trace data is written. When the write pointer reaches the end of the buffer, it loops back to the beginning. In this way, trace data is continuously recorded. It is also common for the system to stop collecting trace data upon triggering an event. This stop can occur: immediately upon triggering, allowing retrieval of trace data prior to the trigger; when the write pointer loops back to the trigger point, allowing collection of trace data after the trigger; or somewhere in between, allowing collection of trace data surrounding the trigger.

[0003] It is generally desirable to store trace data associated with each branch employed by the data processing unit. In this way, the call return stack can be reconstructed, and using this information, the sequence of instructions executed before, around, or after the trigger can be reconstructed. However, when the data associated with multiple branches becomes larger than the buffer size, only the top of the call return stack is stored. Therefore, it is impossible to reconstruct the complete call return stack. Summary of the Invention

[0004] At least one embodiment of this disclosure provides a data processing apparatus comprising: a processing circuit for processing instructions; and a tracking circuit comprising: a tracking buffer; a write pointer storage device for storing a write pointer to indicate a current position in the tracking buffer; and a call depth counter for indicating the number of events, wherein the tracking circuit is configured to generate tracking data indicating processing activities of the processing circuit, and in response to a first event: modifying the call depth counter along a first direction, storing first tracking data indicating the first event at the current position in the tracking buffer, and modifying the write pointer to point to the next position in the tracking buffer; and in response to a second event, when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction and modifying the write pointer to point to the previous position in the tracking buffer, and wherein the tracking circuit responds to a triggering event to reset the difference between the call depth counter and the threshold call depth.

[0005] At least one embodiment of this disclosure provides a method for storing trace data in a trace buffer, the method comprising: processing instructions; generating the trace data indicating the processing; in response to a first event: modifying a call depth counter along a first direction; storing the first trace data indicating the first event at a current position in the trace buffer defined by a write pointer; modifying the write pointer to point to the next position in the trace buffer; and in response to a second event and when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction; and modifying the write pointer to point to the previous position in the trace buffer, and in response to a triggering event, resetting the difference between the call depth counter and the threshold call depth.

[0006] At least one embodiment of this disclosure provides a data processing apparatus comprising: a component for storing tracking data; a component for processing instructions; a component for generating tracking data indicating processing activities of the component for processing; a component for performing the following operations in response to a first event: modifying a call depth counter along a first direction; storing first tracking data indicating the first event at a current position defined by a write pointer in the component for storing the tracking data; and modifying the write pointer to point to the next position in the component for storing the tracking data; and a component for performing the following operations in response to a second event and when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction; and modifying the write pointer to point to the previous position in the component for storing the tracking data; and a component for resetting the difference between the call depth counter and the threshold call depth in response to a triggering event. Attached Figure Description

[0007] The present invention will be further described by way of example only, with reference to embodiments shown in the accompanying drawings, wherein: Figure 1 The data processing apparatus is illustrated schematically with various examples that may embody the present technology; Figure 2 The details of the operation of a tracking circuit, which can embody various examples of this technology, are illustrated schematically. Figure 3 The following sequence of steps is shown, performed by some examples of this technique; Figure 4 The data processing apparatus is illustrated schematically with various examples that may embody the present technology; Figure 5 The data processing apparatus is illustrated schematically with various examples that may embody the present technology; Figure 6 The following sequence of steps is shown, performed by some examples of this technique; Figure 7The illustration schematically shows tracking data that can be stored in various exemplary examples of this technology; Figure 8 The trace buffer is schematically illustrated with various examples that can embody this technique; and Figure 9 The layout of a tracking buffer is schematically shown, illustrating various examples of this technique. Detailed Implementation

[0008] At least some embodiments provide a data processing apparatus comprising: a processing circuit for processing instructions; and a tracking circuit comprising: a tracking buffer; a write pointer storage device for storing a write pointer to indicate a current position in the tracking buffer; and a call depth counter for indicating the number of events, wherein the tracking circuit is configured to generate tracking data indicating processing activities of the processing circuit, and in response to a first event: modifying the call depth counter in a first direction, storing first tracking data indicating the first event at the current position in the tracking buffer, and modifying the write pointer to point to the next position in the tracking buffer; and in response to a second event, when the call depth counter is not equal to a threshold call depth: modifying the call depth counter in a second direction and modifying the write pointer to point to the previous position in the tracking buffer, and wherein the tracking circuit responds to a triggering event to reset the difference between the call depth counter and the threshold call depth.

[0009] The tracking circuit is configured to generate and store tracking data at a current position. The tracking data indicates multiple different events and is based on multiple different conditions. The tracking circuit includes a write pointer storage device for storing a write pointer indicating the current position in the write buffer where data indicating processing activity should be written. In response to a first event, the tracking circuit is configured to generate first tracking data indicating the first event and store the first tracking data in the tracking buffer at the current position defined by the write pointer. The tracking circuit is further configured to modify the write pointer to point to the next position in the tracking buffer. In this way, repeated occurrences of the first event will result in the generation of a sequence of first tracking data items and their storage at a position sequence in the tracking buffer. Additionally, the tracking circuit responds to a second event by modifying the write pointer to point to the previous position in the tracking buffer. In this way, the occurrence of the second event serves to rewind the tracking buffer, such that subsequent occurrences of the first event can overwrite previous occurrences of the first event.

[0010] The tracing circuitry also includes a call depth counter that indicates the relative number of occurrences of the first and second events. In response to the first event, the tracing circuitry is configured to modify the call depth counter along a first direction; and in response to the second event, the tracing circuitry is configured to modify the call depth counter along a second direction. In some embodiments, the tracing circuitry is configured to maintain the current value of the write pointer when the call depth counter equals a threshold call depth. In this way, the total amount of trace buffer that can be rolled back is limited by the threshold call depth, which can be used to effectively repair trace entries held in the trace buffer, regardless of the number of occurrences of the second event. This mechanism provides a means of calculating how many more times the first event has occurred than the second event. As an example, the tracing circuitry can be configured to increment the call depth counter in response to the first event and decrement the call depth counter in response to the second event, while additionally, the threshold call depth can be set to zero. In this way, the call depth counter provides an indication of how many times the first event has occurred in the absence of a corresponding second event.

[0011] The device also responds to trigger events to reset the difference between the call depth counter and the threshold call depth. This mechanism means that after a trigger event, the difference between the call depth counter and the threshold call depth can be used to determine the number of first events in cases where there has been no corresponding second event since the last trigger event. As an example event sequence, consider a trigger event, followed by a first event sequence, followed by a subsequent second event sequence. When a trigger event occurs, the difference between the call depth counter and the threshold call depth is reset. The first event sequence is then stored in a trace buffer, where at each first event, the write pointer is modified to point to the next position, and in response to each first event in the first event, the call depth counter is modified along a first direction. Subsequent second event sequences cause the write pointer to rewind through the trace buffer and cause the call depth counter to be modified along a second direction, where in some embodiments, the second direction is the opposite of the first direction. If there are more first events in the first event sequence than second events in the subsequent second event sequence, the call depth counter remains different from the threshold call depth, and multiple first events are retained in the trace buffer. On the other hand, if the number of second events in the subsequent second event sequence is greater than the number of first events in the first event sequence, all first events are removed from the trace buffer. However, when the number of first events stored in the trace buffer reaches zero, the call depth counter also reaches the threshold call depth. Therefore, the call depth counter does not roll back further, and any previously stored events in the trace buffer remain in the trace buffer. If a second triggering event occurs after the first event sequence and the subsequent second event sequence, the difference between the threshold call depth and the call depth counter is reset, and any remaining first events stored in the trace buffer at the time of the reset are maintained in the trace buffer.

[0012] Resetting the call depth counter to a threshold call depth can take several different forms. In at least some embodiments, when resetting the difference between the call depth counter and the threshold call depth, the tracing circuitry is adapted to perform one of the following operations: resetting the call depth counter to the threshold call depth; and setting the threshold call depth to the call depth counter. By resetting the call depth counter to the threshold call depth, the threshold call depth can be implemented as a fixed value, and the call depth counter maintains a value representing the current number of first events that have not yet had a corresponding second event and have occurred since the last triggered event. Alternatively, by setting the threshold call depth to the call depth counter, two values ​​need to be stored, one for the threshold call depth and the other for the call depth counter. Using this mechanism, the call depth counter provides a value representing the total number of entries in the tracing buffer. The difference between the call depth counter and the threshold call depth can be used to determine a value representing the current number of first events that have not yet had a corresponding second event and have occurred since the last triggered event. It will be apparent to those skilled in the art that in some embodiments, resetting the call depth counter to the threshold call depth can be achieved by resetting either the call depth counter or the threshold call depth such that there is a known offset between the call depth counter and the threshold call depth. In such implementations, the corresponding step of determining whether the call depth counter is equal to the threshold call depth will correspond to determining whether the difference between the call depth counter and the threshold call depth is equal to the known offset.

[0013] In at least some implementations, the tracing circuitry responds to a trigger event by storing third tracing data indicating the trigger event in a tracing buffer and modifying the write pointer to point to the next position in the tracing buffer. The third tracing data stored in the tracing buffer allows for the reconstruction of the sequence of the first and second events at subsequent points. The third tracing data may include data related to the state of the call depth counter or detailed information related to the execution context of the processing circuitry at the time the trigger event occurred. Additionally, the third tracing data may include a timestamp and / or data related to the current state of the processing device. In addition to writing tracing data, the write pointer is also advanced to the next position. It should be noted that advancing the write pointer in response to a trigger event does not include incrementing the call depth counter. In this way, the third tracing data is maintained in the buffer when a subsequent second event sequence follows the trigger event; otherwise, the third tracing data is used to rewind the tracing buffer by sequentially modifying the write pointer to the previous value.

[0014] In at least some embodiments, the tracking circuitry responds to a trigger event to generate and store additional information indicative of processing activity of the processing circuitry. In this way, further information relating to events surrounding the trigger event can be stored. Such events are unrestricted and can generally correspond to any data related to the activity of the processing device, and may relate to the processing circuitry, the tracking circuitry, or any other component of the processing device.

[0015] In at least some embodiments, the data processing apparatus further includes a statistical profiling circuit for sampling processing information related to the current instruction, wherein additional information indicative of the processing activity of the processing circuitry is generated based on the processing information sampled by the statistical profiling circuit. Statistical profiling is a code profiling technique. When using statistical profiling, the statistical profiling circuit samples the instruction and records the operation of the instruction, then writes this record to a buffer in memory. The buffer used to record the statistical profiling data is not necessarily the same as the trace buffer, but may, for example, record a timestamp to allow the statistical profiling record to be associated with the trace buffer at a later stage. However, in some embodiments, statistical profiling data is interleaved with trace data. Specifically, statistical profiling records may be written between buffers or merged into the trace as separate trace data items.

[0016] In at least some implementations, when the call depth counter equals a threshold call depth, the tracing circuitry responds to a second event by modifying the write pointer to point to the next location in the tracing buffer. In this way, the information contained in the tracing buffer determines the record of a first event that has occurred after a triggering event, before another triggering time, and not followed by a subsequent second event; and the tracing buffer maintains a record of second events that were not previously associated with the first event. As an example, consider the following sequence of events: Triggering event – ​​This is used to reset the difference between the call depth counter and the threshold call depth. It should be understood that this can be achieved by modifying the call depth counter or the threshold call depth relative to each other. In some implementations, third trace data may also be written to the trace buffer, indicating the triggering event and possibly indicating the current value of the call depth counter and / or information related to the number of second events that do not have a corresponding first event.

[0017] The second event – ​​when the call depth counter equals the threshold call depth – does not involve backtracking the trace buffer. Instead, the write pointer is modified to point to the next location in the trace buffer.

[0018] The second event – ​​when the call depth counter is still equal to the threshold call depth – does not involve backtracking the trace buffer. As in the case of the previous second event, the write pointer is modified to point to the next location in the trace buffer. Therefore, the trace buffer contains an indication that two second events have occurred since the triggering event.

[0019] The first event-tracing circuitry is configured to generate first tracing data indicating the first event in response to a first event and store the first tracing data in a tracing buffer. The call depth counter is modified along a first direction, and the write pointer is modified to point to the next location in the tracing buffer. At this point, the tracing buffer contains: optional third data indicating the triggering event; an indication that two second events have occurred since the triggering event; and the first tracing data indicating the first event.

[0020] The first event is followed by a further sequence of the same number of second events—this sequence causes the first trace data to be written, the write pointer to be modified to point to the next position, and the depth counter to be modified along the first direction with each occurrence of the first trace data. With each second event, the write pointer is reversed to point to the previous position, and the depth counter is modified along the second direction. Since there are the same number of first and second events, and the second events follow the first events, the end result is that the write pointer has been reversed to point to a position before a further sequence of the same number of second events as the first event. The first trace data items that have been written remain in the trace buffer but may be overwritten in response to further first events.

[0021] A further trigger event occurs – this causes the difference between the call depth counter and the threshold call depth to be reset. This action results in the maintenance in the trace buffer of first trace data indicating the first event and an indication that two second events have occurred since the first trigger, regardless of the number of subsequent second events. In some implementations, third trace data may also be written to the trace buffer, indicating the trigger event and possibly indicating the current value of the call depth counter and / or information related to the number of second events that do not have a corresponding first event.

[0022] In this way, the sequence of the first and second events can be determined from the trace buffer. As an example, if the first event is a subroutine call and the second event is a subroutine return, the subroutine call stack can be built at the instance between the first and second triggering events. Additionally, by rebuilding the subroutine call / return stack between all triggering events, a complete function call return stack can be built at any triggering event point. Note that the second event (in this example, a subroutine return) causes the write pointer to rewind and effectively allows overwriting the first event (in this example, a subroutine call). Therefore, any subroutine call sequence that has ended at the point of the second triggering event (due to the occurrence of the corresponding subroutine return sequence) is not actually stored in the trace buffer (because it may be overwritten by subsequent events). However, if the triggering event occurred during the subroutine call sequence before the corresponding subroutine return occurred, the trace buffer will contain trace data indicating the subroutine call stack at the point of the triggering event and thus capture this subroutine call sequence.

[0023] In at least some embodiments, in response to a second event, when the call depth counter equals a threshold call depth, second trace data indicating the second event is stored at its current position in the trace buffer. The second trace data may include multiple distinct data items. For example, any data item indicating the second event may be incorporated into the second trace data. Additionally, in some embodiments, the second trace data may include information indicating that the call depth counter equals the threshold call depth. In other embodiments, the second trace data may be written to overwrite existing first trace data, which may already exist at the position indicated by the write pointer, as a result of the mechanism described above. This provides a method for calculating how many more times the first event occurred than the second event, or alternatively, how many more times the second event occurred than the first event.

[0024] In at least some implementations, the trace buffer also includes an underflow counter, and the trace circuitry responds to a second event by modifying the underflow counter when the call depth counter equals a threshold call depth. This provides an alternative way to capture the number of times a second event has occurred, where the second event does not follow a previous first event. Specifically, when the underflow counter equals a threshold underflow and the call depth counter equals a threshold call depth, the trace circuitry is configured to modify the underflow counter as a means of tracking how many second events, which were not previously corresponding to the first event, have occurred since the last event when the call depth counter was reset.

[0025] In at least some implementations, when the call depth counter equals a threshold call depth and the underflow counter equals a threshold underflow, the tracing circuit responds to a second event by: storing second tracing data indicating the current value of the underflow counter; and modifying the write pointer to point to the next position in the tracing buffer, and wherein when the call depth counter equals a threshold call depth and the underflow counter does not equal a threshold underflow, the tracing circuit responds to the second event by: modifying the write pointer to point to the previous position in the tracing buffer; storing second tracing data indicating the current value of the underflow counter; and modifying the write pointer to point to the next position in the tracing buffer.

[0026] This provides an alternative way to capture the number of times a second event has occurred. Specifically, when the underflow counter equals a threshold underflow and the call depth counter equals a threshold call depth, the tracing circuitry is configured to store second tracing data indicating the second event, and the value of the underflow counter is indicated in the second tracing data. The tracing circuitry is further configured to modify the write pointer to point to the next location in the tracing buffer. Therefore, a subsequent first event will not cause the second tracing data indicating the second event to be overwritten, and a record of the underflow (i.e., a record of the number of times the second event has occurred in the absence of a previous first event) is maintained in the tracing buffer. To prevent a separate second trace data set indicating a second event from being written every time a second event that is not previously a first event occurs, the trace circuitry is configured to: when the call depth counter equals the call depth and the underflow counter does not equal the threshold underflow (i.e., second trace data indicating the second event already exists, which contains an underflow indication to be written to the trace buffer): modify the underflow counter; modify the write pointer to point to the previous position (which is the position of the previously written second trace data indicating the second event containing the underflow indication); then write the second trace data indicating the second event, which contains the modified underflow indication; and then modify the write pointer to point to the next position. In this way, the underflow record is maintained. An exemplary event sequence and the corresponding data stored in the trace buffer are shown below. In this example, it can be assumed that the call depth counter and the underflow counter are initialized to zero, and that modifying the call depth counter along the first and second directions corresponds to incrementing and decrementing the call depth counter, respectively. Additionally, in this example, it can be assumed that modifying the underflow counter corresponds to incrementing the underflow counter.

[0027] Table 1 In Table 1, the call depth counter and underflow counter values ​​indicate the values ​​of the call depth counter and underflow counter after the tracing circuit has completed executing the modified sequence described above. Table 1 illustrates how the tracing circuit responds to the event sequence. Initially (sequence number 0), the call depth counter and underflow counter are set to zero. This could be, for example, the result of a previously triggered event or the system being initialized. Those skilled in the art will recognize that this is purely illustrative, and the mechanisms described in these embodiments will apply to any initial values ​​of the call depth counter, underflow counter, and tracing buffer.

[0028] At sequence number 1, a second event occurs. The tracing circuitry responds to the second event by generating second tracing data indicating the second event. Additionally, the tracing circuitry is configured to, in response to a call depth counter equal to a threshold call depth and an underflow counter equal to a threshold underflow, indicate the underflow value (UC=1) in the second tracing data and modify the write pointer to point to the next location in the tracing buffer. At sequence number 2, another second event occurs. The tracing circuitry responds to a call depth counter equal to zero and an underflow counter not equal to zero (i.e., equal to 1 in this example) by first modifying the write pointer to point to the previous location, then writing second tracing data indicating the second event, where the second tracing data includes the underflow value (UC=2), and finally modifying the write pointer to point to the next location.

[0029] At serial numbers 3 and 4, the first event occurs. Therefore, the tracing circuit generates tracing data indicating the first event and stores the tracing data in the tracing buffer, supplementing the modification of the call depth counter along the first direction and the modification of the write pointer to point to the next position. At serial numbers 5 and 6, the second event occurs. The tracing circuit modifies the call depth counter along the second direction in response to the call depth counter not being equal to the threshold call depth. At this point, the number of modifications to the call depth counter in the second direction is the same as the number of modifications along the first direction. Therefore, once the tracing circuit has completed storing data and modifying the counter as a result of serial number 6, the call depth counter is again equal to the threshold call depth.

[0030] At sequence number 7, a second event occurs. Therefore, the tracing circuit generates tracing data indicating the second event, and in response to the call depth counter equaling the threshold call depth and the underflow counter not equaling the threshold underflow, the tracing circuit first modifies the write pointer to point to the previous position, then modifies the underflow counter, and then writes the second tracing data indicating the second event into the tracing buffer. This second tracing data also includes an underflow indication (UC=3). The tracing circuit then modifies the write pointer to point to the next position. In this way, the tracing circuit can maintain a record of multiple second events that have occurred without a preceding first event.

[0031] In at least some implementations, the trace circuitry responds to a trigger event to indicate the current value of the underflow counter in the third trace data. The current underflow counter can be stored in a register, and when the trigger event occurs, the underflow counter can be written out as part of the third trace data. In this way, the current underflow counter is stored in a register, and past underflow counters are stored in the trace buffer as part of the third trace data.

[0032] In at least some implementations, the tracing circuitry responds to a triggering event to reset the underflow counter to a threshold underflow. Combined with the above mechanism, the tracing circuitry can maintain tracing data indicating the stack of a first event that has occurred since the previous triggering event, and maintain an indication of a second event that has occurred since the previous triggering event, for which no corresponding first event has occurred since the triggering event. For example, the first event could be a subroutine call, and the second event could be a subroutine return. If the first triggering event occurs after multiple subroutine calls, making the current subroutine call return stack quite large, then there can be subsequent subroutine returns corresponding to subroutine calls that occurred before the triggering event. By combining the stored value of the underflow counter with the tracing data stored before the first triggering event, the state of the subroutine call return stack in subsequent triggering events can be reconstructed without the stored tracing data containing a complete list of every subroutine call and every subroutine return. In this way, a compact tracing dataset indicating the state of the subroutine call return stack in multiple triggering events can be stored.

[0033] In at least some implementations, the threshold underflow is zero. In this way, a binary counter can be used to indicate the current value of the underflow. This counter can be implemented, for example, using a 4-bit binary counter, an 8-bit binary counter, or a 16-bit binary counter, although it will be apparent to those skilled in the art that a counter of any size can be used.

[0034] In at least some implementations, the underflow counter is initialized to a threshold underflow. Therefore, the trace data collected between initialization and the first trigger event will indicate any underflow that occurs after initialization but before the first trigger event.

[0035] In at least some embodiments, the tracking data is stored as tracking data packets of a predetermined size. Therefore, the write pointer can be modified to point to the previous or next position by adding or subtracting a value from a write pointer corresponding to the predetermined size. However, it will be apparent to those skilled in the art that any method can be used to modify the write pointer to point to the previous or next position. For example, if the predetermined size is N bytes of data, the modification to point to the next position may include adding an N-byte value to the write pointer or subtracting N bytes from the write pointer. Alternatively, for example, the modification to point to the previous position may include adding an N-byte value to the write pointer or subtracting N bytes from the write pointer. This mechanism means that it is not necessary to store additional data along with the tracking data to indicate the positions of the next and previous positions.

[0036] In at least some alternative embodiments, the trace data is stored as trace data packets, and the size of the trace data packets is indicated within the trace data. The size of the trace data packets can be indicated in various ways. For example, the trace data may include a base pointer and a limit pointer to determine the start address and end address of the trace data. Alternatively, the trace data may specify data indicating the size of the trace data packets. It will be apparent to those skilled in the art that any method of storing data indicating the location where the trace data is stored in the trace buffer can be used to determine the size of the trace data. Additionally, the trace data may include data indicating the previous and next positions. The next position may correspond to an address adjacent to the current position. Alternatively, the next position may be stored at an address not adjacent to the current position. In this way, the trace buffer can be distributed across system memory rather than stored in a dedicated trace buffer.

[0037] In at least some implementations, the trace buffer is divided into multiple blocks, and each block has a block size defined by a block base address and a block limit, wherein the block size is an integer multiple of a predetermined size. In this way, the trace buffer can be divided into multiple regions corresponding to each of the multiple blocks to generate trace data constructed based on a sequence of first and second events. For example, trace data indicating processor activity occurring at the same level in the first / second event stack can be maintained in each of the multiple blocks. In this way, further historical details related to the processing activity of the processing circuitry can be maintained.

[0038] In at least some embodiments, the current position is the position in the current block of a plurality of blocks, and the tracking circuitry responds to the storage of tracking data in the current block by incrementing the position in the current block by a predetermined size. In this way, in addition to storing previous items of tracking data in one of the plurality of blocks, subsequent tracking data items stored in that block can also be stored, rather than overwriting this data.

[0039] In at least some embodiments, the data processing device responds to a position in the current block being greater than or equal to the block limit by resetting the position in the current block to the current block base address. Each of the multiple blocks serves as a separate circular buffer. When a block is full, such that the next position would point to a position not included within the limits defined by the block base address and the block limit, the current position is reset to point to the current block base address. In this way, each block maintains multiple trace data items associated with the first and second events. This provides further historical information about the first and second events that can be reconstructed after the trace data is collected. In at least some alternative embodiments, the data processing device responds to a position in the current block being greater than the block limit by resetting the position in the current block to the current block base address. In this way, both an inclusion limit (where the limit is the last position within the current block) and an exclusivity limit (where the limit is the first position outside the current block) can be defined. It will be apparent to those skilled in the art that trace data can be stored in the opposite direction by decrementing positions, and that any test used to determine whether a position is included in the current block or falls outside the current block can be used.

[0040] In some implementations, the next position is the position in the next block of multiple blocks, and the previous position is the position in the previous block of multiple blocks. In this way, the tracking circuitry responds to a first / second event, causing the write pointer to point to the position in the next / previous block. When the position in each block is incremented by a predetermined size, this means that in response to the first event, tracking data will be written to the position in the current block. The position in the current block will be incremented by a predetermined size such that the next time tracking data is written to the current block, the tracking data will not overwrite the most recently written tracking data. Additionally, the write pointer is modified to point to the position following the position in the next block of multiple blocks. When the sequence of the first and second events causes the write pointer (at a future point) to be modified to point back to the current block, the next data to be written will not overwrite the already written data, but will be written to the current position in the current block. In this way, each of the multiple blocks maintains a history of the most recent M tracking datasets written to that block, where M is an integer multiple of a predetermined size defining the block size.

[0041] In at least some embodiments, each of the multiple blocks is divided into multiple sub-blocks, and each sub-block has a sub-block size that is defined as an integer multiple of a predetermined size. In this way, a deeper nesting of first tracking data indicating a first event and second tracking data indicating a second event is maintained in the tracking buffer. In at least some embodiments, the sub-block size is a predetermined size. In this way, each data sub-block includes a single tracking dataset corresponding to one of the first event, the second event, and the triggering event.

[0042] In at least some implementations, the tracking data includes multiple tracking entries sequentially written to the current sub-block of the current block, wherein the current position is defined based on the position and offset of the current sub-block, and wherein the tracking circuitry responds to a current sub-block offset being greater than or equal to the sub-block size by resetting the current sub-block offset to zero. In this way, the sub-block acts as a circular buffer for the tracking data. While collecting tracking data, the tracking circuitry can continuously write tracking data to the current sub-block in the tracking buffer. When the current sub-block is full, the current sub-block offset is reset and the tracking data wraps around. Therefore, when a first event / second event occurs, tracking data indicating the first event / second event has been written to the tracking buffer. Thus, the resulting tracking buffer can be configured as one buffer in a circular buffer (multiple blocks), where each of the multiple blocks includes further multiple circular buffers (multiple sub-blocks). This allows the reconstruction of the current first event / second event stack after multiple triggering events and provides a history of the occurrence of multiple first and second events, which are not necessary for the generation of the first event / second event stack but can provide further information related to the operation of the data processing circuitry.

[0043] In at least some embodiments, the tracing circuitry responds to a first event by performing one of the following operations: storing multiple trace entries in the current sub-block; storing multiple further trace entries in the current sub-block before modifying the write pointer, wherein the multiple further trace entries correspond to a portion of a predetermined size; and storing multiple further trace entries in the current sub-block before modifying the write pointer, wherein the multiple further trace entries correspond to a predetermined size. These options correspond to storing tracing data indicating events occurring before, around, and after the first event, respectively, in sub-blocks of the tracing buffer.

[0044] In at least some implementations, when the call depth counter is not equal to a threshold call depth, the tracing circuitry responds to a second event by performing one of the following operations: storing multiple trace entries in the current sub-block; storing multiple further trace entries in the current sub-block before modifying the write pointer, wherein the multiple further trace entries correspond to a portion of a predetermined size; and storing multiple further trace entries in the current sub-block before modifying the write pointer, wherein the multiple further trace entries correspond to a predetermined size. These options correspond to storing tracing data indicating events occurring before, around, and after the second event, respectively, in sub-blocks of the tracing buffer.

[0045] In at least some implementations, the trace buffer has a trace buffer size defined by a global base pointer and a global limit pointer, and wherein the trace circuitry responds to a current position defined by a write pointer falling outside the trace buffer by setting the write pointer to the global base pointer. A trace buffer configured in this way behaves as a circular buffer. The result is that the trace buffer behaves as a circular buffer comprising multiple circular buffers (blocks), which in turn comprise multiple circular buffers (sub-blocks). This allows for a more limited trace buffer size that stores only data indicating a first and second event occurring near the top of the stack, while allowing the trace buffer to maintain data indicating multiple triggering events, maintain the historical occurrence of the first and second events within each block of the block, and store trace data indicating events occurring before, around, or after the first and second events.

[0046] In some implementations, the first event is a subroutine call, and the second event is a subroutine return. In this way, the trace buffer includes trace data that can be used to reconstruct the subroutine call return stack at multiple different trigger points without storing trace data indicating each subroutine call and each subroutine return.

[0047] In some implementations, the first event is an anomalous event, and the second event is an anomalous return event. In this way, the trace buffer includes trace data that can be used to reconstruct information related to the sequence of anomalous events and anomalous return events, without storing data indicating each anomalous event and each anomalous return.

[0048] In some implementations, the first event is one of a plurality of first events including at least one of a subroutine call and an exception event, and the second event is one of a plurality of second events including at least one of a subroutine return and an exception return event. In this way, the tracing circuitry is configured to generate tracing data indicating a plurality of different possible events. Different counters can be used to maintain tracing for each type of event among the plurality of first events and the plurality of second events. For example, a first underflow counter can be used to track underflows corresponding to a first type of first event and a corresponding first type of second event. Additionally, a second underflow counter can be used to track underflows corresponding to a second type of first event and a second type of second event. Similarly, a first call depth counter can be used to track the call depth associated with a first type of first event and a corresponding first type of second event. Additionally, a second call depth counter can be used to track the call depth associated with a second type of first event and a second type of second event. The plurality of first events and second events can include any event for which tracing data can be generated and for which a stack can be maintained. Specifically, in addition to responding to third type first events and second events, the tracing circuitry can also use this mechanism to respond to both subroutine call / return and exception event / return. In this way, first event / second event stacks can be generated for multiple different types of events.

[0049] In at least some implementations, the trace data indicates at least one of the following: branch source address; branch destination address; timestamp; and the current value of the program counter. By recording data indicating the location in the program or the time when the trace data was generated, the corresponding trace data can be associated with additional profiling data (e.g., statistical profiling data) that can be stored in a separate buffer.

[0050] In at least some implementations, the threshold call depth is zero. In this way, a binary counter can be used to indicate the current value of the call depth. This counter can be implemented, for example, using a 4-bit binary counter, an 8-bit binary counter, or a 16-bit binary counter, although it will be apparent to those skilled in the art that a counter of any size can be used.

[0051] In at least some implementations, the call depth counter is initialized to a threshold call depth. Therefore, the trace data collected between initialization and the first triggering event will indicate any underflows that occur after initialization but before the first triggering event.

[0052] At least some embodiments provide a method for storing trace data in a trace buffer, the method comprising: processing instructions; generating the trace data indicating the processing; in response to a first event: modifying a call depth counter along a first direction; storing the first trace data indicating the first event at a current position in the trace buffer defined by a write pointer; modifying the write pointer to point to the next position in the trace buffer; and in response to a second event and when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction; and modifying the write pointer to point to the previous position in the trace buffer, and in response to a triggering event, resetting the difference between the call depth counter and the threshold call depth.

[0053] At least some embodiments provide a data processing apparatus comprising: a component for storing tracking data; a component for processing instructions; a component for generating tracking data indicating processing activities of the component for processing; a component for performing the following operations in response to a first event: modifying a call depth counter along a first direction; storing first tracking data indicating the first event at a current position defined by a write pointer in the component for storing the tracking data; and modifying the write pointer to point to the next position in the component for storing the tracking data; and a component for performing the following operations in response to a second event and when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction; and modifying the write pointer to point to the previous position in the component for storing the tracking data; and a component for resetting the difference between the call depth counter and the threshold call depth in response to a triggering event.

[0054] At least some implementations provide a trace buffer configured to operate in an mode in which the total trace buffer is divided into multiple blocks that are used sequentially. Upon a trigger event, the trace buffer saves the state of the current block and moves to a new block. Each block serves as an independent circular buffer. In some implementations, the trace buffer may be defined by a global base address and a global limit pointer, which in some implementations may be software-programmable and define the absolute start and end of the total trace buffer. For embedded trace buffers or trace buffers mapped to system memory, the global base address and global limit pointer may be implicit rather than programmable. Additionally, a block size is defined. The block size is smaller than the total trace buffer and, in some implementations, much smaller. In some implementations, for simplicity, the block size is a power of two. In some implementations, the block size is programmable. However, in other implementations, the block size is fixed.

[0055] In some implementations, the current block base address defines the current block within the total trace buffer. The current block limit is the current block base address plus the block size. In some implementations, the current block base address is a multiple of the block size. This allows the current block base address and block limit to be derived from the current value of the write pointer. In some implementations, the current base address and current limit pointers are used to define the current trace buffer as part of the total trace buffer. The current base address is a known offset above the current block base address, and the current limit is a known offset below the current block limit. In some implementations, these offsets are fixed by the implementation and are used to create a small current block storage. In other implementations, these limits can be programmable. In some exemplary implementations, the current base address can be the current block base address + 16 bytes, and the current limit can be the current block limit. This gives a 16-byte region at the beginning of the block, which is defined as the current block storage.

[0056] In some implementations, the current block base address is initially set to the global base address. Between trigger events, the trace buffer operates to store trace data before, around, or after the trigger event, where traces are collected into the current trace buffer. In other words, the current trace buffer operates as a circular buffer. Upon triggering an event, a trigger counter operates to count the number of trigger events. In some implementations, the trace buffer may write a timestamp to a known offset within the current block storage. However, when the trigger counter reaches a threshold, instead of flushing the trace buffer or stopping the collection of traces, it flushes the trace buffer and writes the final trace write pointer value to a known offset within the current block storage. Additionally, the trace buffer sets a new current block base address as the current block limit. This has the effect of setting a new current block limit. If the new current block limit is above the global limit, the trace buffer is configured to stop collecting trace data.

[0057] In some implementations, pointers stored in block storage can be used to locate the end of the circular buffer for each block when the software begins decoding the trace. Timestamps in or from the block storage can be used to correlate trace blocks with other traces, such as traces from statistical profiling circuitry.

[0058] In some implementations, the trace buffer is configured to set the new current block base address as the global base address when the final buffer is filled, thus providing a circular buffer within a circular buffer. In some implementations, the trace buffer is configured to move to a randomly selected next current block. Therefore, the global buffer is eventually filled with a random selection of traces, where older traces are unlikely to be retained. In some implementations, statistical profiling records may be written between buffers, or written to block storage, or merged into the trace (as a separate trace ID). In some implementations, this scheme may be implemented recursively, where a series of triggers causes the trace buffer to advance by different amounts, blocks within blocks, etc.

[0059] In some implementations, the buffer, segmented into multiple blocks, can be expanded to provide enhanced stack history tracing. In some implementations, the tracing circuitry and tracing buffer operate as usual. Upon function call, the tracing circuitry generates a trigger event that functions as described above. This causes the tracing buffer to advance to a new current tracing buffer on top of the current one. Upon function return, the tracing macrocell generates a reverse trigger event that functions as described above, except that the tracing buffer is reversed, so that the new tracing buffer is now the tracing buffer below the current one. Additionally, the tracing buffer reads a write pointer from the data store and resumes the stored tracing from where it left off. In some implementations, a counter mechanism or a global base pointer can be used to prevent buffer underflow. This has the effect of generating a sequence of tracing buffers, each containing the tracing of a single function on the call stack.

[0060] Some specific implementation schemes will now be described with reference to the accompanying drawings.

[0061] Figure 1A data processing apparatus 10, illustrating various examples of the present technology, is schematically shown. The data processing apparatus 10 includes: a processing circuit 12 for processing instructions; and a tracking circuit 14. The tracking circuit 14 includes: a tracking buffer 16 for storing tracking data indicating the processing activities of the processing circuit 12; and a write pointer 18 for pointing to the current position in the tracking buffer 16. The tracking circuit 14 also includes: a call depth counter 20 for indicating the number of events; and a threshold call depth 22. In response to a first event, the tracking circuit 14 performs the following operations: generating first tracking data indicating the first event, storing the first tracking data in the tracking buffer 16 at the current position pointed to by the write pointer 18, modifying the call depth counter 20 along a first direction, and modifying the write pointer 18 to point to the next position in the tracking buffer 16. When the call depth counter 20 is not equal to the threshold call depth 22, the tracing circuit 14 also responds to a second event by modifying the call depth counter 20 along a second direction and resetting the write pointer 18 to point to the previous position in the tracing buffer 16. When the call depth counter 20 is equal to the threshold call depth 22, the tracing circuit 14 also responds to a second event by optionally generating second tracing data indicating the second event and storing the second tracing data in the tracing buffer 16 at the current position indicated by the write pointer 18. In response to the second event, when the call depth counter 20 is equal to the threshold call depth 22, the write pointer is kept pointing to the current position and is not modified to point to the next or previous position. Further details of the tracing circuit 14 and the tracing buffer 16 will be described below.

[0062] Figure 2 Details of a tracking circuit, illustrating various examples of this technology, are schematically shown. Figure 2Processing activity 24 is illustrated, which includes an activity sequence AJ for which tracking data is to be generated. The tracking data is stored in a circular buffer 30, which forms part of the tracking buffer and can be defined in various ways. For example, the circular buffer can be defined by any two of a base pointer, a limit pointer, and a circular buffer size. Additionally, the current position in the circular buffer is defined by a current position pointer 28. As processing circuitry 12 executes processing activity 24, tracking circuitry 14 generates a tracking data item aj corresponding to the activity sequence AJ. As the tracking data item is written to the circular buffer 30, the current position pointer 28 is advanced through the circular buffer, and when the buffer is full (indicated by the current position pointer 28 pointing to a position falling outside the circular buffer), the current position pointer 28 wraps back to point to a first position to be written into the circular buffer 30. Note that in various embodiments of the invention, the current position pointer 28 may correspond to a write pointer 18. Tracking circuitry 14 responds to multiple events that cause the current tracking data in the circular buffer 30 to be stored in the tracking buffer 26. These events may correspond to a first event, a second event, or a trigger event. Storing the circular buffer 30 into the tracking buffer 26 may require physical movement of the data, or alternatively, the circular buffer 30 may include a portion of the tracking buffer 26, and storing data into the tracking buffer may include advancing the current position pointer 28 to correspond to a different portion of the tracking buffer 26.

[0063] The response to the trigger can be configured in various ways. In some embodiments, the tracing circuit 14 may stop writing to the circular buffer 30 when the trigger occurs, such that the tracing data stored in the circular buffer 30 corresponds to tracing data corresponding to the processing activity prior to the trigger. In other alternative embodiments, the tracing circuit may stop writing to the circular buffer 30 once the current position pointer 28 has cycled to the position where the trigger was received. In this way, the circular buffer 30 stores data corresponding to the processing activity that occurred after the trigger. In other alternative embodiments, the tracing circuit 14 may be configured to stop writing to the circular buffer 30 at a point between two previous examples, such that multiple additional tracing data items are stored in the circular buffer 30, but the circular buffer 30 still contains tracing data indicating the processing activity prior to the trigger event. In these embodiments, the circular buffer 30 contains tracing data indicating tracing events that occurred around the trigger.

[0064] Figure 3 The sequence of steps performed by some embodiments of this technology is shown. Figure 3The steps performed in this process correspond to those performed by the data processing device 10. The process can be considered to begin at step S31, where the processing circuit 12 receives the next instruction in the instruction sequence. At step S32, the tracking circuit 14 determines whether the instruction corresponds to a first event. If so, the process proceeds to step S38, where the tracking circuit 14 modifies the call depth counter 20 along a first direction, and then proceeds to step S39. At step S39, the tracking circuit 14 generates first tracking data indicating the first event and stores the first tracking data in the tracking buffer 16 at the current position indicated by the write pointer 16, and then proceeds to step S40. At step S40, the tracking circuit 14 modifies the write pointer 18 to point to the next position in the tracking buffer 16, and then the process returns to step S31. Returning to step S32, if it is determined that the instruction does not correspond to the first event, the process proceeds to step S33. At step S33, the tracking circuit 14 determines whether the instruction corresponds to a second event. If not, the process returns to step S31. On the other hand, if the tracking circuit 14 determines that the instruction corresponds to the second event, the process proceeds to step S34. At step S34, it is determined whether the call depth counter 20 is equal to the threshold call depth 22. If so, the process proceeds to step S35, where the tracking circuit 14 optionally generates second tracking data indicating the second event and stores the second tracking data in the tracking buffer 16, and then the process returns to step S31. In some embodiments, at step S35, the tracking circuit maintains the current value of the write pointer (the write pointer is not modified to point to the next or previous position, but continues to point to the current position). However, if it is determined at step S34 that the call depth counter 20 is not equal to the threshold call depth 22, the process proceeds to step S36. At step S36, the call depth counter 20 is modified along the second direction, and then the process proceeds to step S37, where the write pointer is modified to point to the previous position. Finally, the process proceeds from step S37 to step S31 to prepare for the next instruction.

[0065] Figure 4A data processing apparatus, illustrative of various examples embodying the present technology, is shown schematically. The data processing apparatus 40 includes: a processing circuit 42 for processing instructions; a tracking circuit 44 for generating tracking data indicative of the processing activities of the processing circuit; and a statistical profiling circuit 54 for generating additional information indicative of the processing activities of the processing circuit based on statistical profiling techniques. The tracking circuit 44 includes a tracking buffer 46 for storing the tracking data generated by the tracking circuit and additional information indicative of the processing activities based on the statistical profiling techniques generated by the statistical profiling circuit 54. The tracking circuit 44 also includes: a write pointer 48 for pointing to the current position in the tracking buffer 46; a call depth counter 50 for indicating the number of events; and a threshold call depth 52. In response to a trigger event, the statistical profiling circuit 54 is configured to generate additional data indicative of the processing activities of the processing circuit 42 and pass the additional data to the tracking circuit 44. The tracking circuit 44 is configured to store the additional data generated by the statistical profiling circuit 54 in the tracking buffer 46, such that the tracking data generated by the tracking circuit 44 is interleaved with the additional data generated by the statistical profiling circuit 54. In this way, a detailed view of the state of the processing circuit 42 can be obtained based on a detailed snapshot of the processing circuit generated by the statistical profiling circuit 54 over a short time window and a less detailed view of the state of the processing circuit 42 generated by the tracking circuit 44 over a much longer time window.

[0066] Figure 5 A data processing apparatus, illustrative of various examples embodying the present technology, is shown schematically. Data processing apparatus 56 includes: a processing circuit 62 for performing processing activities; and a tracking circuit 64 for generating tracking data indicative of the processing activities of the processing circuit. The processing circuit includes: a clock 82 for generating a timestamp indicating the time of instruction execution; and a program counter 84 for indicating the position of the instruction in the instruction stream. As discussed, the processing circuit 62 performs processing activities associated with an instruction sequence 86. The instruction sequence 86 may include instructions that do not trigger the tracking circuit 64 to generate tracking data, as well as instructions that also cause the tracking circuit 64 to generate tracking data.

[0067] The tracing circuit 64 includes a tracing buffer 66 for storing tracing data generated by the tracing circuit 64. Further details of the tracing buffer 66 will be provided below. The tracing circuit 64 also includes: a global limit pointer 80 for determining the limit address of the tracing buffer; and a global base pointer 78 for determining the first address of the tracing buffer. Those skilled in the art will understand that this is merely one way of defining the tracing buffer, and alternatives, such as defining any two of the global limit pointer 80, the global base pointer 78, and the buffer size, are equivalent. The tracing circuit 64 also includes: a write pointer 68 for indicating the current position in the tracing buffer 66 to which tracing data is to be written; a call depth counter 70 for indicating the number of events; a threshold call depth 72; an underflow counter 74 for indicating the underflow of the first event / second event stack; and a threshold underflow 76.

[0068] Tracing circuit 64 can respond to any number of events (including a first event and a second event). The first and second events may include function calls and function returns, subroutine calls and subroutine returns, exception events and exception returns, or any other events for which trace data may be desired to be generated. In response to a first event encountered by processing circuit 62 in instruction sequence 86, tracing circuit 64 is configured to generate first trace data indicating the first event of processing circuit 62. Tracing circuit 64 is further configured to store the first trace data in trace buffer 66 at the current location indicated by write pointer 68. Additionally, tracing circuit 64 is configured to modify write pointer 68 to point to the next location in trace buffer 66 and modify call depth counter 70 along a first direction. The first trace data may include information indicating details about the first event, a timestamp generated by clock 82, and the current value of program counter 84. For example, in the case of a function call or subroutine call, the first trace data may indicate the branch source address and branch destination address.

[0069] The tracing circuit 64 also responds to a second event encountered by the processing circuit 62 in the instruction sequence 86. In response to the second event, when the call depth counter 70 is not equal to the threshold call depth 72, the tracing circuit is configured to modify the call depth counter 70 along a first direction and modify the write pointer 68 to point to the previous position in the tracing buffer 66. In response to the second event, when the call depth counter 70 is equal to the threshold call depth 72, the tracing circuit 64 is configured to modify the underflow counter 74 and optionally generate second tracing data indicating the second event and store the second tracing data in the tracing buffer 66. In some embodiments, the tracing circuit 64 is further configured to modify the write pointer 68 to point to the next position when the call depth counter 70 is equal to the threshold call depth 72. In some embodiments, the tracing circuit 64 is further configured to: modify the underflow counter 74, indicate the current value of the underflow counter 74 in the second tracing data, and modify the write pointer 68 to point to the next position in the tracing buffer 66 when the call depth counter 70 is equal to the threshold call depth 72 and the underflow counter 74 is equal to the threshold underflow 76. Additionally, the tracing circuit 64 is configured to: modify the underflow counter 74 when the call depth counter 70 equals the threshold call depth 72 and the underflow counter 74 does not equal the threshold underflow 76; modify the write pointer 68 to point to the previous position in the tracing buffer 66; indicate the current value of the underflow counter 74 in the second tracing data; and modify the write pointer 68 to point to the next position in the tracing buffer 66. In embodiments where the second tracing data is generated, the second tracing data may include information indicating details about the second event, a timestamp generated by the clock 82, and the current value of the program counter 84. For example, in the case of a function return or subroutine return, the second tracing data may indicate the branch source address and the branch destination address.

[0070] In some implementations, the trace buffer 66 may be divided into multiple blocks 88, 90, 92, each of which includes block stores 98, 100, 102 to define metadata associated with the blocks 88, 90, 92. The block stores may include: base pointers 104, 190, 116 and limit pointers 106, 112, 118, used to define the size of blocks 88, 90, 92; and block offsets 108, 114, 120, used to determine the current write position within blocks 88, 90, 92. It will be apparent to those skilled in the art that block offsets 108, 114, 120 may be replaced with data indicating the position within the current block, and base pointers 104, 110, 116 and limit pointers 106, 112, 118 may be replaced with any two of the base pointers 104, 110, 116, limit pointers 106, 112, 118, and the block size. Figure 5In the example shown, there are N blocks. "Block 1" 88 includes block storage 98, which includes a base pointer 104, a limit pointer 106, and a block offset 108. "Block 2" 90 includes block storage 100, a base pointer 110, a limit pointer 112, and a block offset 114. "Block N" 92 includes block storage 102, a base pointer 116, a limit pointer 118, and a block offset 120.

[0071] In some implementations, blocks 88, 90, and 92 are configured to behave as circular buffers. In some implementations, the trace circuit 64 may be configured to modify the write pointer 68 to point to the next / previous block when the write pointer 68 is modified to point to the next / previous location. In the illustrated example, the write pointer 68 is pointing to "block 2" 90, where the address pointed to by the write pointer is determined by the current block offset 114 stored in block storage 100. This can be implemented in several ways. The write pointer 68 may be defined based on block offsets 108, 114, and 120. Alternatively, the write pointer 68 may indicate the number of most significant bits of the address corresponding to the address range of blocks 88, 90, and 92, and the block offsets 108, 114, and 120 may provide the number of least significant bits of the address. Thus, the current location can be defined by appending block offsets 88, 90, and 92 to the write pointer 68. Regardless of how it is defined, in the illustrated implementation, the write pointer 68 points to the current location in "block 2" 90 of the trace buffer 66. When the tracking circuit 64 determines that tracking data needs to be generated and written to the tracking buffer 66, the block offset is increased by a predetermined size and the write pointer is modified to point to the next / previous block in the tracking buffer. For example, in the illustrated embodiment, the write pointer may be modified to point to a position in "block 1" 88 of the tracking buffer 66, where the next / previous position in "block 1" 88 of the tracking buffer 66 is determined based on the block offset 108 stored in the block memory 98.

[0072] Additionally, the tracking circuit 66 can respond to trigger events to reset the call depth counter 70 and the underflow counter 72. As discussed, this enables the tracking circuit 64 to maintain a tracking buffer 66 containing tracking data indicating the number of first events and the number of second events that have occurred between the first and second trigger events.

[0073] Figure 6 The sequence of steps performed by some embodiments of this technology is shown. Figure 3The steps performed in this process correspond to the steps performed by the data processing device 10. The process can be considered to begin at step S60, where the data processing device waits for the next instruction. The process then proceeds to step S61, where the tracking circuit 64 determines whether the instruction indicates a first event. If not, the process proceeds to step S62, where the tracking circuit 64 determines whether the instruction indicates a second event. If not, the process proceeds to step S63 to determine whether a triggering event has occurred. If no triggering event has occurred, the process returns to step S60 to wait for the next instruction. If it is determined at step S63 that a triggering event has occurred, the process proceeds to step S64, where the difference between the call depth counter 70 and the threshold call depth 72 is reset, and then the process proceeds to step S65. At step S65, the underflow counter 74 is reset to the threshold underflow 76, and then the process returns to step S60. If it is determined at step S62 that the instruction corresponds to the second event, the process proceeds to step S66, where it is determined whether the call depth counter 70 is equal to the threshold call depth 72. If so, the process proceeds to step S67. At step S67, the tracking circuit 64 modifies the underflow counter 74 and then proceeds to optional step S68, where the tracking circuit 64 generates second tracking data indicating the second event and stores the second tracking data in the tracking buffer 66 at the current position indicated by the write pointer 68. At steps S67 and S68, the current value of the write pointer can be maintained at its current value. Alternatively, at steps S67 and S68, the write pointer can be modified according to any of the above schemes. The process then returns to step S60 to await the next instruction. If it is determined at step S66 that the call depth counter 70 is not equal to the threshold call depth 72, the process proceeds to step S69. At step S69, the call depth counter 70 is modified along the second direction, and the process proceeds to step S70, where the tracking circuit 64 modifies the write pointer 68 to point to the previous position in the tracking buffer 66. The process then returns to step S60 to await the next instruction. If the tracking circuit 64 determines at step S61 that the instruction corresponds to the first event, the process proceeds to step S71. At step S71, the call depth counter 70 is modified along the first direction, and then the process proceeds to step S72. At step S72, the tracking circuit 64 generates first tracking data indicating the first event and stores the first tracking data in the tracking buffer 64 at the location determined by the write pointer 68. The process then proceeds to step S73, where the write pointer 68 is modified to point to the next location in the tracking buffer 64. The process then returns to step S60 to await the next instruction.

[0074] Figure 7 The illustration schematically depicts tracking data that can be stored in various exemplary embodiments of the present technology. Table 122 shows exemplary sequences of events that may occur according to various exemplary embodiments of the present technology, wherein... Figure 6 The flowchart shown illustrates the behavior of the tracing circuit. In these exemplary embodiments, the first event is a function call, and the second event is a function return. In these exemplary embodiments, the tracing circuit is configured to generate first tracing data indicating the first event in response to the first event, and to generate second tracing data indicating the second event in response to the second event. When the call depth counter equals a threshold call depth and the underflow counter equals a threshold underflow, the tracing circuit further responds to the second event by: storing the second tracing data indicating the current value of the underflow counter; and modifying the write pointer to point to the next position in the tracing buffer, and wherein when the call depth counter equals a threshold call depth and the underflow counter does not equal a threshold underflow, the tracing circuit responds to the second event by: modifying the write pointer to point to the previous position in the tracing buffer; storing the second tracing data indicating the current value of the underflow counter; and modifying the write pointer to point to the next position in the tracing buffer. It can be further assumed that modification of the call depth counter along the first direction corresponds to incrementing the call depth counter, and modification of the call depth counter along the second direction corresponds to decrementing the call depth counter. Furthermore, it can be assumed that modification of the underflow counter corresponds to incrementing the underflow counter. Finally, in these exemplary embodiments, it can be assumed that the threshold call depth and threshold underflow are each equal to zero. However, it should be noted that these assumptions are purely for illustrative purposes, and the described techniques are applicable to any form of modification and any first and second events as set forth in the above description.

[0075] Table 122 shows the call depth counter and underflow counter generated by events. Events marked with an asterisk (*) are events retained in the trace buffer 124.

[0076] At time T0, function func_1() calls function func_2(), causing the call depth counter to increment from 0 to 1. Since this is the first event, the underflow counter is not modified. This event causes the generation of the first trace data and its storage at position L0 in trace buffer 124, where the first trace data indicates the function call from function func_1() to function func_2(). Additionally, the write pointer is modified to point to the next position L1 in trace buffer 124.

[0077] At time T1, function func_2() calls function func_3(), causing the call depth counter to increment from 1 to 2. Since this is the first event, the underflow counter is not modified. This event causes the generation of the first trace data and its storage at position L1 in trace buffer 124, where the first trace data indicates the function call from function func_2() to function func_3(). Additionally, the write pointer is modified to point to the next position L2 in trace buffer 124.

[0078] At time T2, a trigger event occurs. This causes the call depth counter to be reset, and the underflow counter (which was already at the threshold underflow) to be reset as well. The tracing circuit 64 further responds to the trigger event by storing the third tracing data indicating the trigger event at position L2 in the tracing buffer 124. Therefore, the first tracing data items generated at T0 and T1, and the third tracing data generated at T2, are stored at positions L0, L1, and L2 in the final tracing buffer 124, respectively. Additionally, the tracing circuit 64 modifies the write pointer to point to the next position L3 in the tracing buffer.

[0079] At time T3, function func_3() calls function func_4(), causing the call depth counter to increment from 0 to 1. Since this is the first event, the underflow counter is not modified. This event causes the generation of the first trace data and its storage at position L3 in trace buffer 124, where the first trace data indicates the function call from function func_3() to function func_4(). Additionally, the write pointer is modified to point to the next position L4 in trace buffer 124.

[0080] At time T4, a function return occurs from function func_4() to func_3(), causing the call depth counter to decrement. Since the call depth counter is not equal to zero when the function return occurs, the underflow counter remains zero. The tracing circuit 64 is further configured to modify the write pointer to point to the previous position L3 in the tracing buffer 124.

[0081] At time T5, a function return occurs from function func_3() to function func_2(). Since the call depth counter is already zero, it does not decrement further. Instead, the underflow counter increments from 0 to 1, and the underflow indication is generated by tracing circuit 64 and stored as part of the second tracing data at position L3 in tracing buffer 124. Additionally, the write pointer is modified to point to the next position L4 in the tracing buffer.

[0082] At time T6, function func_2() calls function func_5(), causing the call depth counter to increment from 0 to 1. Since this is the first event, the underflow counter is not modified and remains set to 1. This event causes the generation of the first trace data and its storage at position L4 in trace buffer 124, where the first trace data indicates the function call from function func_2() to function func_5(). Additionally, the write pointer is modified to point to the next position L5 in trace buffer 124.

[0083] At time T7, a function return occurs from function func_5() to function func_2(), causing the call depth counter to decrement. Since the call depth counter is not equal to zero when the function return occurs, the underflow counter remains at 1. Additionally, the tracing circuitry is configured to modify the write pointer to point to the previous position L4 in the tracing buffer 124.

[0084] At time T8, a function return occurs from func_2() to func_1(). Since the call depth counter is already zero, it does not decrement further. Instead, the underflow counter increments from 1 to 2. When the underflow counter is not zero, the write pointer is modified to point to the previous position L3 in the trace buffer 124, and an underflow indication is generated by the trace circuit 64 and stored as part of the second trace data at position L3 in the trace buffer 124. Once complete, the write pointer is modified to point to the next position L4 in the trace buffer.

[0085] At time T9, a function call occurs from function func_1() to function func_5(), causing the call depth counter to increment from 0 to 1. Since this is the first event, the underflow counter is not modified. This event causes the generation of the first trace data and its storage at position L4 in trace buffer 124, where the first trace data indicates the function call from function func_1() to function func_5(). Additionally, the write pointer is modified to point to the next position L5 in trace buffer 124.

[0086] At time T10, a trigger event occurs. This causes the call depth counter and the underflow counter to be reset. The tracing circuit 64 further responds to the trigger event by storing a third tracing data indicating the trigger event at position L5 in the tracing buffer 124. Therefore, the underflow count generated in response to the function return at T8, the first tracing data item generated at T9, and the third tracing data generated at T10 are stored at positions L3, L4, and L5 in the final tracing buffer 124, respectively. Additionally, the tracing circuit 64 modifies the write pointer to point to the next position L6 in the tracing buffer.

[0087] At time T11, a function return occurs from function func_5() to function func_1(). Since the call depth counter is already zero, it does not decrement further. Instead, the underflow counter increments from 0 to 1, and the underflow indication is generated by tracing circuit 64 and stored at position L6 in tracing buffer 124 as part of the second tracing data. Once complete, the write pointer is modified to point to the next position L7 in the tracing buffer.

[0088] At time T12, a function call occurs from function func_1() to function func_2(), causing the call depth counter to increment from 0 to 1. Since this is the first event, the underflow counter is not modified. This event causes the generation of the first trace data and its storage at position L7 in trace buffer 124, where the first trace data indicates the function call from function func_1() to function func_2(). Additionally, the write pointer is modified to point to the next position L8 in trace buffer 124.

[0089] At time T13, a function call occurs from function func_2() to function func_3(), causing the call depth counter to increment from 1 to 2. Since this is the first event, the underflow counter is not modified and remains set to 1. This event causes the generation of the first trace data and its storage at position L8 in trace buffer 124, where the first trace data indicates the function call from function func_2() to function func_3(). Additionally, the write pointer is modified to point to the next position L9 in trace buffer 124.

[0090] At time T14, a function call occurs from function func_3() to function func_4(), causing the call depth counter to increment from 2 to 3. Since this is the first event, the underflow counter is not modified and remains set to 1. This event causes the generation of the first trace data and its storage at position L9 in trace buffer 124, where the first trace data indicates the function call from function func_3() to function func_4(). Additionally, the write pointer is modified to point to the next position L10 in trace buffer 124.

[0091] Based on the resulting trace buffer 124, the function call return stack 128 can be recreated from the entries held in the trace buffer 124. At time T2, the trace buffer 128 indicates that function func_1() has called func_2() and function func_2() has called function func_3(). Therefore, the call return stack at this time includes the stacks of func_1(), func_2(), and func_3(). At time T8, the trace buffer indicates an underflow of 2. This indicates that the call return stack at T10 is the same as the call return stack at T2, but the top two entries have been removed. Additionally, at T9, the call return stack indicates that function func_1() has called function func_5(). This indicates that the call return stack at T10 has further entries for func_5(). At the current time T14, trace buffer 124 indicates that an underflow of 1 occurred at T11, and that function calls from func_1() to func_2(), from func_2() to func_3(), and from func_3() to func_4() occurred at times T12, T13, and T14. This indicates that the call return stack for T14 is the same as the call return stack for T10, but the top entries have been removed and replaced with func_1(), func_2(), and func_3(). In this way, call return stack 128 can be constructed from trace buffer 124.

[0092] Figure 8 A trace buffer, illustrating various examples of the present technology, is schematically shown. The trace circuitry 64 includes a trace buffer 130. In some embodiments, the trace buffer 130 may include multiple blocks 130(1), 130(2), ..., 130(N). Each block 130(i) (where i is any integer from 1 to N) may also include multiple sub-blocks 132(0), 132(1), 132(M). Each sub-block 132(j) (where j is any integer from 1 to M) may correspond to one of first trace data, second trace data, or third trace data. Each of the first, second, and third trace data items may also include multiple data items 134(1), 134(2), ..., 134(P), which correspond to data indicating data processing activity prior to, surrounding, or following a corresponding event. Each data item 134(k) (where k is any integer from 1 to P) may include a timestamp, a branch source address, a branch destination address, a program counter, and any further data items. The tracking buffer 130, block 130(i) and sub-block 132(j) can be configured to behave as circular buffers as described in the above implementation scheme.

[0093] In summary, a data processing apparatus and method for processing data are disclosed. The data processing apparatus includes: a processing circuit for processing instructions; and a tracking circuit including: a tracking buffer; a write pointer storage device for storing a write pointer to indicate the current position in the tracking buffer; and a call depth counter for indicating the number of events, wherein the tracking circuit is configured to generate tracking data indicating the processing activities of the processing circuit, and in response to a first event: modifying the call depth counter along a first direction, storing a first tracking data indicating the first event at the current position in the tracking buffer, and modifying the write pointer to point to the next position in the tracking buffer; in response to a second event, when the call depth counter is not equal to a threshold call depth: modifying the call depth counter along a second direction, and modifying the write pointer to point to the previous position in the tracking buffer; and in response to the second event, when the call depth counter is equal to the threshold call depth, storing a second tracking data indicating the second event at the current position in the tracking buffer.

[0094] Figure 9 The layout of a trace buffer, illustrating various examples of the present technology, is schematically shown. The trace buffer 200 is divided into multiple blocks 140, 142, and 144. In this example, the trace buffer 200 is divided into three blocks, each 1024 bytes in size. Each block 140, 142, and 144 includes block storage 146, 148, and 150 for storing the current block. The current base address is a known offset from the current block base address. In this example, the current base address is 16 bytes higher than the current block base address. The current block 142 is defined by at least two of the current block base address, the current block limit, and the block size.

[0095] In this application, the phrase "configured as..." is used to mean that the elements of the device have a configuration capable of performing the defined operation. In this context, "configuration" means the arrangement or manner of interconnection of hardware or software. For example, the device may have dedicated hardware that provides the defined operation, or a processor or other processing device may be programmed to perform the function. "Configured as" does not mean that the elements of the device need to be changed in any way to provide the defined operation.

[0096] While exemplary embodiments have been described in detail herein with reference to the accompanying drawings, it should be understood that the invention is not limited to those precise embodiments, and various changes, additions, and modifications can be made therein by those skilled in the art without departing from the scope of the invention as defined by the appended claims. For example, features of dependent claims may be combined with features of independent claims in various ways without departing from the scope of the invention.

Claims

1. A data processing apparatus, the data processing apparatus comprising: A processing circuit, the processing circuit being used to process instructions; and The tracking circuit includes: Tracking buffer; A write pointer storage device, wherein the write pointer storage device is used to store a write pointer to indicate the current position in the tracking buffer; and The depth counter is invoked to indicate the number of events. The tracking circuit is configured to generate tracking data indicating the processing activities of the processing circuit, and In response to a first event: modify the call depth counter along a first direction, store the first trace data indicating the first event at the current position in the trace buffer, and modify the write pointer to point to the next position in the trace buffer; and In response to the second event, when the call depth counter is not equal to the threshold call depth: modify the call depth counter along the second direction, and modify the write pointer to point to the previous position in the trace buffer; The tracking circuitry responds to a trigger event to reset the difference between the call depth counter and the threshold call depth; and In response to the second event, when the call depth counter equals the threshold call depth, the second tracking data of the second event is stored at the current position in the tracking buffer.

2. The data processing apparatus of claim 1, wherein when the difference between the call depth counter and the threshold call depth is reset to zero, the tracking circuit is adapted to perform one of the following operations: Reset the call depth counter to the threshold call depth; and Set the threshold call depth to the call depth counter.

3. The data processing apparatus of claim 1, wherein the tracking circuit responds to the trigger event by storing a third tracking data indicating the trigger event in the tracking buffer and modifying the write pointer to point to the next position in the tracking buffer.

4. The data processing apparatus of claim 1, wherein the tracking circuit responds to the triggering event to generate and store additional information indicating the processing activity of the processing circuit.

5. The data processing apparatus according to claim 4, further comprising a statistical analysis circuit, the statistical analysis circuit being used to sample processing information related to the current instruction. The additional information indicating the processing activity of the processing circuit is generated based on the processing information sampled by the statistical profiling circuit.

6. The data processing apparatus of claim 1, wherein when the call depth counter is equal to the threshold call depth, the tracking circuit responds to the second event to modify the write pointer to point to the next position in the tracking buffer.

7. The data processing apparatus of claim 1, wherein the tracking buffer further comprises an underflow counter, and When the call depth counter equals the threshold call depth, the tracing circuit responds to the second event to modify the underflow counter.

8. The data processing apparatus of claim 7, wherein when the call depth counter is equal to the threshold call depth and the underflow counter is equal to the threshold underflow, the tracking circuit responds to the second event to perform the following operations: Store second tracking data indicating the current value of the underflow counter; as well as Modify the write pointer to point to the next position in the tracking buffer, and When the call depth counter equals the threshold call depth and the underflow counter does not equal the threshold underflow, the tracing circuit responds to the second event by performing the following operations: Modify the write pointer to point to the previous position in the tracking buffer; Store second tracking data indicating the current value of the underflow counter; as well as Modify the write pointer to point to the next position in the trace buffer.

9. The data processing apparatus according to claim 7, wherein the tracking circuit responds to the trigger event to store third tracking data indicating the trigger event in the tracking buffer and modifies the write pointer to point to the next position in the tracking buffer; and The tracking circuit responds to the trigger event to indicate the current value of the underflow counter in the third tracking data.

10. The data processing apparatus according to any one of claims 8 to 9, wherein the tracking circuit responds to the triggering event to reset the underflow counter to the threshold underflow.

11. The data processing apparatus according to any one of claims 8 to 9, wherein the threshold underflow is zero.

12. The data processing apparatus according to any one of claims 8 to 9, wherein the underflow counter is initialized to the threshold underflow.

13. The data processing apparatus of claim 1, wherein the tracking data is stored as tracking data packets of a predetermined size.

14. The data processing apparatus of claim 1, wherein the tracking data is stored as tracking data packets, and the size of the tracking data packets is indicated in the tracking data.

15. The data processing apparatus of claim 13, wherein the tracking buffer is divided into a plurality of blocks, and each of the plurality of blocks has a block size defined by a block base address and a block limit, and The block size is an integer multiple of the predetermined size.

16. The data processing apparatus of claim 15, wherein the current position is the position in the current block of the plurality of blocks, and The tracking circuit responds to the storage of tracking data in the current block by incrementing the position in the current block by the predetermined size.

17. The data processing apparatus of claim 16, wherein the data processing apparatus responds to a position in the current block being greater than or equal to the block limit to reset the position in the current block to the current block base address.

18. The data processing apparatus of claim 17, wherein the next position is a position in the next block of the plurality of blocks, and the previous position is a position in the previous block of the plurality of blocks.

19. The data processing apparatus according to any one of claims 15 to 18, wherein each of the plurality of blocks is divided into a plurality of sub-blocks, and Each of the sub-blocks has a sub-block size defined as an integer multiple of the predetermined size.

20. The data processing apparatus of claim 19, wherein the sub-block size is the predetermined size.

21. The data processing apparatus of claim 20, wherein the tracking data comprises a plurality of tracking items sequentially written into the current sub-block of the current block. The current position is defined based on the position and offset of the current sub-block, and The tracking circuit responds to the current sub-block offset being greater than or equal to the sub-block size by resetting the current sub-block offset to zero.

22. The data processing apparatus of claim 21, wherein the tracking circuit responds to the first event to perform one of the following operations: Store the plurality of tracking items in the current sub-block; Before modifying the write pointer, store multiple further trace entries into the current sub-block, wherein the multiple further trace entries correspond to a portion of the predetermined size; and The plurality of further trace entries are stored in the current sub-block before the write pointer is modified, wherein the plurality of further trace entries correspond to the predetermined size.

23. The data processing apparatus of claim 21, wherein when the call depth counter is not equal to the threshold call depth, the tracking circuit responds to the second event to perform one of the following operations: Store the plurality of tracking items in the current sub-block; Before modifying the write pointer, multiple further trace entries are stored in the current sub-block, wherein the multiple further trace entries correspond to a portion of the predetermined size; as well as The plurality of further trace entries are stored in the current sub-block before the write pointer is modified, wherein the plurality of further trace entries correspond to the predetermined size.

24. The data processing apparatus of claim 1, wherein the trace buffer has a trace buffer size defined by a global base pointer and a global limit pointer, and The tracing circuitry responds to the current position defined by the write pointer falling outside the tracing buffer by setting the write pointer to the global base address pointer.

25. The data processing apparatus of claim 1, wherein the first event is a subroutine call and the second event is a subroutine return.

26. The data processing apparatus of claim 1, wherein the first event is an abnormal event and the second event is an abnormal return event.

27. The data processing apparatus of claim 1, wherein the first event is one of a plurality of first events including at least one of subroutine calls and exception events, and The second event is one of a plurality of second events, including at least one of a subroutine return event and an exception return event.

28. The data processing apparatus of claim 1, wherein the tracking data indicates at least one of the following: Branch source address; Branch target address; Timestamp; and The current value of the program counter.

29. The data processing apparatus according to claim 1, wherein the threshold call depth is zero.

30. The data processing apparatus of claim 1, wherein the call depth counter is initialized to the threshold call depth.

31. A method for storing tracking data in a tracking buffer, the method comprising: Processing instructions; Generate the tracking data that indicates the processing; Response to the first event: Modify the call depth counter along the first direction; The first trace data indicating the first event is stored in the trace buffer at the current position defined by the write pointer; and Modify the write pointer to point to the next position in the tracking buffer; as well as In response to the second event and when the call depth counter is not equal to the threshold call depth: Modify the call depth counter along the second direction; as well as Modify the write pointer to point to the previous position in the trace buffer; In response to the triggering event, reset the difference between the call depth counter and the threshold call depth; as well as In response to the second event, when the call depth counter equals the threshold call depth, the second tracking data of the second event is stored at the current position in the tracking buffer.

32. A data processing apparatus, the data processing apparatus comprising: Components used to store tracking data; Components used for processing instructions; A component used to generate tracking data indicating the processing activities of the component being processed; Components used to perform the following operations in response to the first event: Modify the call depth counter along the first direction; The first tracking data indicating the first event is stored in the component used to store the tracking data at the current position defined by the write pointer; as well as Modify the write pointer to point to the next position in the component used to store the tracking data; as well as A component for responding to a second event and performing the following operations when the call depth counter is not equal to a threshold call depth: Modify the call depth counter along the second direction; as well as Modify the write pointer to point to the previous position in the component used to store tracking data; A component for resetting the difference between the call depth counter and the threshold call depth in response to a triggering event; and In response to the second event, when the call depth counter equals the threshold call depth, a second tracking data indicating the second event is stored in the component at the current location in the component for storing tracking data.

Citation Information

Patent Citations

  • Method And Apparatus For Obtaining A Call Stack To An Event Of Interest And Analyzing The Same

    US20120311307A1