Call stack sampling

By designing processing circuits, call stack storage devices, stack pointer storage devices and Inspur mark pointer storage devices in the data processing device, non-destructive sampling of the call stack is achieved, and the problems of sampling destructiveness and fixed size limitations in the prior art are solved, and the efficiency and accuracy of program performance analysis are improved.

CN113508366BActive Publication Date: 2025-06-24ARM LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202080018068.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2019-03-05
Filing Date
2020-03-04
Publication Date
2025-06-24
Estimated Expiration
2040-03-04

AI Technical Summary

Technical Problem

In the prior art, call stack sampling in the data processing device has destructive and fixed size limitations, making it difficult to effectively perform program performance analysis.

Method used

A device is designed, including a processing circuit, a call stack storage device, a stack pointer storage device and a Inspur mark pointer storage device. By triggering the call stack sampling program in response to the call stack sampling, the call stack is accessed and marked with the stack pointer and Inspur mark pointer, non-destructive sampling and effective storage of the call stack are realized.

Benefits of technology

It realizes efficient and non-destructive sampling of the call stack of the data processing device, supports program performance analysis, avoids fixed size limitations, and improves sampling flexibility and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113508366B_ABST
    Figure CN113508366B_ABST
Patent Text Reader

Abstract

The present invention discloses an apparatus and a method of operating the same. A call stack is maintained that includes subroutine information associated with subroutines that have been called during a data processing operation and have not yet returned. A stack pointer indicates an end of the call stack associated with the most recently called subroutine that has been called during the data processing operation and has not yet returned. The call stack sampling can be performed with reference to the stack pointer. A wave flag pointer is maintained that indicates a value that the stack pointer had when the processing circuitry last completed the call stack sampling procedure. The call stack sampling procedure includes retrieving subroutine information indicated between a value of the wave flag pointer and a current value of the stack pointer from the call stack. Thereby, more efficient call stack sampling is supported because only modifications to the call stack need to be sampled.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to data processing. Specifically, the present disclosure relates to sampling a call stack in a data processing device.

[0002] Related Description

[0003] Program performance analysis can be performed by sampling a call stack maintained by a data processing device while the data processing device is performing its data processing operations. The sampling can be performed, for example, periodically or in response to a specific event. When a software calls a subroutine, a corresponding frame is added to the call stack, and when the subroutine returns, the frame is removed. Thus, the current content of the call stack provides information related to the currently active function. Software can be arranged to provide information related to the content of the call stack, but this is disruptive because the software being executed must be interrupted in order for the stack to be "traversed", for example, using a frame pointer chain or frame unwind metadata. It can also be disruptive to the data cache content. A data processing device can be provided with a hardware call stack buffer, which is a small fixed-size buffer of call stack records updated by call and return instructions. The call stack buffer can be sampled separately, but has a fixed size, which can be disadvantageous. Summary of the Invention

[0004] In an exemplary embodiment described herein, there is an apparatus including: a processing circuit for performing data processing operations, where the data processing operations include subroutines; a call stack storage device for storing a call stack including subroutine information related to subroutines that have been called and not yet returned during the data processing operations; a stack pointer storage device for storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called and not yet returned during the data processing operations, where the processing circuit executes a call stack sampling program in response to a call stack sampling trigger, the call stack sampling program including accessing the call stack with reference to the stack pointer, and a wave mark pointer storage device for storing a wave mark pointer, where the value of the wave mark pointer indicates the previous value that the stack pointer had when the processing circuit last completed the call stack sampling program, where the processing circuit is arranged to execute the call stack sampling program, the call stack sampling program including retrieving subroutine information indicated between the value of the wave mark pointer and the current value of the stack pointer, where the wave mark pointer storage device modifies the wave mark pointer to match the current value of the stack pointer in response to the execution of the call stack sampling program, and where the wave mark pointer storage device modifies the wave mark pointer in response to the removal of subroutine information from the call stack to match the current value of the stack pointer resulting from the removal of subroutine information from the call stack.

[0005] In an exemplary embodiment described herein, there is a method of data processing including: performing data processing operations, where the data processing operations include subroutines; storing a call stack including subroutine information related to subroutines that have been called and not yet returned during the data processing operations; storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called and not yet returned during the data processing operations; executing a call stack sampling program in response to a call stack sampling trigger, the call stack sampling program including accessing the call stack with reference to the stack pointer; storing a wave mark pointer, where the value of the wave mark pointer indicates the previous value that the stack pointer had when the call stack sampling program last completed; modifying the wave mark pointer to match the modified value of the stack pointer in response to the execution of the call stack sampling program; and modifying the wave mark pointer to match the current value of the stack pointer resulting from the removal of subroutine information from the call stack, where executing the call stack sampling program includes retrieving subroutine information indicated between the value of the wave mark pointer and the current value of the stack pointer.

[0006] In one exemplary embodiment described herein, there is a device comprising: means for performing data processing operations, where the data processing operations include subroutines; means for storing a call stack including subroutine information related to the subroutines that have been called and not yet returned during the data processing operations; means for storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called and not yet returned during the data processing operations; means for executing a call stack sampling program in response to a call stack sampling trigger, the call stack sampling program including accessing the call stack with reference to the stack pointer; means for storing a wavemark pointer, where the value of the wavemark pointer indicates the previous value that the stack pointer had when the call stack sampling program last completed; means for modifying the wavemark pointer to match the modified value of the stack pointer in response to executing the call stack sampling program; and means for modifying the wavemark pointer to match the current value of the stack pointer resulting from removing subroutine information from the call stack, where executing the call stack sampling program includes retrieving subroutine information indicated between the value of the wavemark pointer and the current value of the stack pointer. BRIEF DESCRIPTION OF THE DRAWINGS

[0007] Embodiments of the present invention will be further described by way of example only with reference to the accompanying drawings, in which:

[0008] Figure 1 A device in an exemplary embodiment is schematically shown;

[0009] Figure 2A and Figure 2B shows the evolution of the call stack sampled according to the corresponding exemplary embodiment;

[0010] Figure 3 is a flowchart showing a sequence of steps taken by a method according to an embodiment when maintaining a call stack and sampling the call stack;

[0011] Figure 4A A data processing device in an exemplary embodiment is schematically shown, where software multithreading occurs and the context of the current thread can be replaced by a different context to switch to a new thread;

[0012] Figure 4B A device in an exemplary embodiment is schematically shown, where the call stack sampling program can be triggered by an interrupt generated by a timer or by an interrupt generated by comparing the stack pointer and the wavemark pointer;

[0013] Figure 5An apparatus in an exemplary embodiment is schematically illustrated, where the processing circuit is hardware multithreaded, and the apparatus is arranged to maintain a stack pointer and a wavemark pointer for each call stack it maintains for each thread;

[0014] Figure 6A An apparatus in an exemplary embodiment including a call stack buffer is schematically illustrated;

[0015] Figure 6B The content of a call stack buffer in an exemplary embodiment is schematically illustrated;

[0016] Figure 7 is a flowchart showing a sequence of steps taken by a method according to an exemplary embodiment when performing a call stack sampling procedure; and

[0017] Figure 8 is a flowchart showing a sequence of steps performed by a method according to an exemplary embodiment when maintaining a call stack buffer. DETAILED DESCRIPTION

[0018] Before discussing embodiments with reference to the accompanying drawings, the following description of the embodiments is provided.

[0019] According to an exemplary configuration, there is provided an apparatus including: a processing circuit for performing data processing operations, where the data processing operations include subroutines; a call stack storage device for storing a call stack including subroutine information related to subroutines that have been called and not yet returned during the data processing operations; a stack pointer storage device for storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called and not yet returned during the data processing operations, where the processing circuit executes a call stack sampling procedure in response to a call stack sampling trigger, which includes accessing the call stack with reference to the stack pointer, and a wavemark pointer storage device for storing a wavemark pointer, where the value of the wavemark pointer indicates the previous value that the stack pointer had when the processing circuit last completed the call stack sampling procedure, where the processing circuit is arranged to execute the call stack sampling procedure, which includes retrieving subroutine information indicated between the value of the wavemark pointer and the current value of the stack pointer, where the wavemark pointer storage device modifies the wavemark pointer to match the current value of the stack pointer in response to the execution of the call stack sampling procedure, and where the wavemark pointer storage device modifies the wavemark pointer in response to the removal of subroutine information from the call stack to match the current value of the stack pointer resulting from the removal of subroutine information from the call stack.

[0020] Providing a wavemark pointer storage device that stores a wavemark pointer (where the value of the wavemark pointer indicates the value that the stack pointer had when the call stack was last sampled) means that when performing call stack sampling, the call stack only needs to be sampled to a certain "depth" because it is known that the call stack records beyond that point have not changed. In fact, in the case where the wavemark pointer and the call stack pointer have the same value, call stack sampling is not required. This can be useful, for example, in the case of repeated sampling during a very long-running function such as the multiplication of a very large matrix. Once the first sampling of the call stack has been performed (and the wavemark pointer is set accordingly), then when call stack sampling is triggered while the same function is still running, the same value of the wavemark pointer will be seen. The same value of the wavemark not only indicates that the sampling is for the same function with the same call stack, but also indicates that this is the same instance of the function (i.e., the function has not returned and is being called again simultaneously).

[0021] The device can be configured differently to hold the wavemark pointer value in the wavemark pointer storage device, but in some embodiments, the wavemark pointer storage device modifies the wavemark pointer to match the current value of the stack pointer in response to the execution of a subroutine return instruction, the subroutine return instruction causing the current value of the stack pointer to correspond to a subroutine that is not the most recently called subroutine compared to the subroutine indicated by the value of the wavemark pointer. Similarly, in some embodiments, the wavemark pointer storage device modifies the wavemark pointer to match the current value of the stack pointer resulting from a write to the stack pointer, the write causing the current value of the stack pointer to correspond to a subroutine that is not the most recently called subroutine compared to the subroutine indicated by the value of the wavemark pointer. Thus, this enables updating the wavemark pointer not only for "pop" style instructions but also for returns and / or direct writes relative to the stack pointer, the returns and / or direct writes covering the normal return and unwind of the call stack (as part of calling the sampling routine).

[0022] Call stack sampling triggering can take various forms, but in some embodiments, the call stack sampling triggering is receiving a predetermined call stack sampling interrupt.

[0023] According to a specific implementation of the present technology, the call stack sampling interrupt can be generated in various ways and by various sources. However, in some embodiments, the wave marker pointer storage device and the stack pointer storage device are arranged to cooperate to generate the predetermined call stack sampling interrupt when the current value of the stack pointer indicates a stack pointer position in the call stack corresponding to a subroutine that is more recently called compared to the wave marker position in the call stack indicated by the value of the wave marker pointer. Thus, this condition (indicating the current value of the stack pointer of a subroutine that is more recently called compared to the subroutine indicated by the current wave marker position) can be used as a trigger and / or filter for the generation of the call stack sampling interrupt. On the one hand, call stack sampling can thus be initiated when a new function is called, and on the other hand, call stack sampling can be prevented from occurring unless this is the case. In this way, an effective method for call stack sampling is supported, where it only occurs when needed.

[0024] In some embodiments, the sampling of the call stack can be periodic, and thus the call stack sampling trigger is after a predetermined time period. In an exemplary embodiment where the processing circuit is software multithreaded, the wave marker pointer value forms part of the thread context. Thus, when a thread switch occurs, the wave marker pointer value must be appropriately updated for the new thread context or must be invalidated. Therefore, in some embodiments, the processing circuit is software multithreaded and, when performing a thread switch from a first thread to a second thread, is arranged to export the thread context of the first thread including the first thread value of the wave marker pointer and import the thread context of the second thread including the second thread value of the wave marker pointer for the second thread. Alternatively, in some embodiments, the processing circuit is software multithreaded and, when performing a thread switch from a first thread to a second thread, is arranged to invalidate the first thread value of the wave marker pointer and set a default value for the second thread value of the wave marker pointer for the second thread. In some exemplary embodiments, the processing circuit is hardware multithreaded, where the call stack storage device is capable of storing a set of per-thread call stacks, where the stack pointer storage device is capable of storing a set of per-thread stack pointers, and where the wave marker pointer storage device is capable of storing a set of per-thread wave marker pointers.

[0025] In some embodiments, the apparatus further includes: a call stack buffer for storing records, each record including: a source address and a target address of a subroutine that has been called and not yet returned during the data processing operation; and a recorded value of the stack pointer at the time point when the record was created; a trace buffer for storing trace data for export from the apparatus; and a call stack buffer sampling circuit that, in response to a call stack buffer sampling trigger, performs a record copying process that includes copying the stored records in the call stack buffer to the trace buffer. The call stack buffer sampling trigger can take various forms, but can be, for example, a call stack sampling trigger. Thus, when a call stack sampling procedure is performed, the contents of the call stack buffer (i.e., the records including the source address, target address, and stack pointer value) are copied to the trace buffer. This can be performed, for example, as a first step in response to a call stack sampling trigger, since in some cases the call stack buffer contents will be sufficient in terms of sampling the call stack.

[0026] In some exemplary embodiments, when performing the record copying process, the call stack buffer sampling circuit ends the record copying process in response to reaching a record in which the recorded value of the stack pointer indicates a stack pointer position in the call stack corresponding to a subroutine that is not the most recently called compared to the wave marker position in the call stack indicated by the value of the wave marker pointer, and updates the wave marker pointer to indicate the most recently called subroutine in the call stack buffer. Thus, such embodiments recognize that it may not be necessary to copy all of the contents of the call stack buffer, where a previous call stack sampling process has sampled the call stack to a certain extent, meaning that this is not required. This is recognized with reference to the wave marker position, and thus when the stack pointer value of a record is within the region that has been copied, the copying process can be stopped. Additionally, the wave marker pointer itself can then also be updated to the most recently called record in the call stack buffer, since this forms part of the set of copied records.

[0027] In some embodiments, when performing the record copying process, the call stack buffer sampling circuit, in response to reaching the oldest record in the call stack buffer corresponding to the least recently called subroutine having a record in the call stack buffer, causes the processing circuit to execute the call stack sampling program when the record value of the oldest record indicates a stack pointer position in the call stack corresponding to a subroutine that is more recently called compared to the stack pointer position in the call stack indicated by the value of the wave marker pointer. Thus, if the oldest record in the call stack buffer has a stack pointer value that is more recent compared to the wave marker position indicated by the wave marker pointer, this means there is a gap between the content of the call stack buffer and the previously taken call stack sample. In such a case, it is necessary to unwind the call stack in software. Once this is done, an accurate record of the call stack is obtained from the most recently called subroutine in the call stack buffer. The wave marker can then be set to the current stack pointer value. In some embodiments, the call stack buffer sampling circuit is arranged to cause the processing circuit to execute the call stack sampling program by issuing a call stack sampling interrupt.

[0028] In some embodiments, the call stack buffer discards a record in which the record value of the stack pointer indicates a stack pointer position in the call stack corresponding to a subroutine that is more recently called compared to the stack pointer position in the call stack indicated by the modified value of the stack pointer, in response to modifying the value of the stack pointer. Thus, when the stack pointer is updated (e.g., during software exception unwind of multiple calls), the call stack buffer records that have become obsolete due to the modification of the stack pointer value are discarded.

[0029] In some embodiments, the call stack buffer sampling circuit, in response to a new subroutine call, performs the record copying process and updates the value of the wave marker pointer to the current value of the stack pointer when creating a new record for the new subroutine call will cause the new record to have a record value of the stack pointer indicating a stack pointer position in the call stack corresponding to a subroutine that is more recently called compared to the wave marker position in the call stack indicated by the value of the wave marker pointer. Thus, this allows the content of the call stack buffer to be pre-emptively captured into the trace buffer when a new call is pushed onto the call stack buffer, which otherwise would result in the stack pointer of the latest entry being more updated than the wave marker pointer value. Thus, the content of the trace buffer is already up-to-date, and when a subsequent trigger for call stack sampling occurs, the trace buffer already has the required content and no software intent to unwind the call stack is needed.

[0030] In some embodiments, the call stack buffer sampling circuit is arranged to further perform the record copying process depending on a predefined call stack buffer copy timing interval. Thus, this prevents excessive copying that may otherwise occur during frequent function calls (e.g., in heavily nested program code).

[0031] In some embodiments, the trace buffer causes the value of the wavemark pointer to be set to a stack pointer position corresponding to the oldest position in the call stack in response to a trace buffer rewrite, where the trace buffer rewrite causes unexported trace data to be rewritten. Thus, in the case where previously copied call stack information in the trace buffer is lost, modifying the wavemark pointer to the oldest position in the call stack means that the mechanisms discussed above will subsequently cause a full stack unwind. Similarly, in some exemplary embodiments, the trace buffer invalidates the wavemark pointer in response to a trace buffer rewrite, where the trace buffer rewrite causes unexported trace data to be rewritten. This has the same effect that the next call stack sampling trigger will cause a full call stack unwind to be performed.

[0032] According to an exemplary configuration, a method of data processing is provided, including: performing a data processing operation, where the data processing operation includes a subroutine; storing a call stack including subroutine information related to the subroutine, the subroutine having been called and not yet returned during the data processing operation; storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine, the subroutine having been called and not yet returned during the data processing operation; performing a call stack sampling program in response to a call stack sampling trigger, which includes accessing the call stack with reference to the stack pointer; storing a wavemark pointer, where the value of the wavemark pointer indicates the previous value that the stack pointer had when the call stack sampling program last completed; modifying the wavemark pointer to match the modified value of the stack pointer in response to performing the call stack sampling program; and modifying the wavemark pointer to match the current value of the stack pointer resulting from removing subroutine information from the call stack, where performing the call stack sampling program includes retrieving subroutine information indicated between the value of the wavemark pointer and the current value of the stack pointer.

[0033] According to an exemplary configuration, a device is provided that includes: means for performing a data processing operation, where the data processing operation includes a subroutine; means for storing a call stack that includes subroutine information related to the subroutine that has been called and has not yet returned during the data processing operation; means for storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called and has not yet returned during the data processing operation; means for executing a call stack sampling program in response to a call stack sampling trigger, where the call stack sampling program includes accessing the call stack with reference to the stack pointer; means for storing a wavemark pointer, where the value of the wavemark pointer indicates the previous value that the stack pointer had when the call stack sampling program last completed; means for modifying the wavemark pointer to match the modified value of the stack pointer in response to executing the call stack sampling program; and means for modifying the wavemark pointer to match the current value of the stack pointer resulting from removing subroutine information from the call stack, where executing the call stack sampling program includes retrieving the subroutine information indicated between the value of the wavemark pointer and the current value of the stack pointer.

[0034] Specific embodiments will now be described with reference to the accompanying drawings.

[0035] Figure 1 A data processing device 10 in an exemplary embodiment is schematically illustrated. The device includes a processing circuit 12 that performs data processing operations. When performing these data processing operations, particularly when executing program instructions, a call stack 14 is maintained. The call stack 14 is schematically illustrated as being stored in a (data) storage device 16. As is known to those of ordinary skill in the art, a call stack is a data structure to which return functions corresponding to active functions in the software executed by the processing circuit 12 are added. Thus, when a function or subroutine is called within the software, a return instruction is pushed onto the call stack 14, and when the function or subroutine ends, the return address is popped from the call stack 14 so that the processing circuit can return to the correct point in the program instructions to continue its execution. The processing circuit maintains a stack pointer value 13, for example, in a locally accessible register, where the value of the stack pointer indicates the "top" of the stack (in the sense of a growing, ascending stack). The device 10 also includes a call stack control 18 that also maintains a copy of the stack pointer value 19 and further maintains a wavemark pointer 20. The data processing operations of the processing circuit 12 can be temporarily interrupted to cause it to execute a call stack sampling program, where the call stack 14 is sampled and its contents can be, for example, exported for inspection by a programmer. Such sampling of the call stack, which is performed periodically or in response to a specific event, can be used for program performance analysis. For example, the top level of the stack shows the current active function, while deeper levels can indicate which subsystems are active, such as phases and modules.

[0036] When the call stack sampling program is executed, the processing circuitry references the stack pointer to identify the most recently added portion of the call stack and also references the wave marker pointer maintained by the call stack control 18 to determine the limit of the call stack sampling it performs. In other words, the call stack sampling program retrieves the information pushed onto the call stack 14 that will be found between the values of the stack pointer and the wave marker pointer. The manner of maintaining the value of the wave marker pointer will be described in more detail below with reference to the following drawings.

[0037] Figure 2A and Figure 2B shows the evolution of the contents of the call stack in a corresponding example where the function is called by software, resulting in the corresponding return address being pushed onto the call stack. The return address is typically part of the "stack frame" corresponding to the function (subroutine) that has been called but not yet terminated by a return. The frame may include additional information related to the call of the function or subroutine, but this is not important for this discussion. Figure 2A Starting at 20, where the call stack includes stack frame A, indicating that subroutine A has been called but not yet returned. Thus, the value of the stack pointer SP indicates the top of the frame. Note that a convention is adopted throughout the description of the upward-growing call stack, but this is also an arbitrary choice of representation. At this point, the wave marker pointer TM is at its default or "zero level" value (or may actually currently be only invalid), indicating that no call stack sampling has been performed. Next, at 21, another subroutine B has been called, causing stack frame B to be pushed onto the top of the call stack. SP has been updated to indicate the new top of the call stack and TM remains at the zero level. Similarly, at 22, another subroutine C has been called, causing another stack frame C to be pushed onto the call stack. SP indicates the top of the stack and TM indicates the bottom. However, in this state, the software is interrupted to sample the call stack, and thus stack frames C, B, and A (travelling down through the stack) are sampled for export and separate analysis. Once the call stack sampling is complete, the wave marker pointer TM is updated to match the current value of the stack pointer, and thus as Figure 2A shown at 23, both SP and TM now point to the top of the call stack. Subsequently, another subroutine D is called, and thus, as shown at 24, another stack frame D is pushed onto the call stack. SP continues to indicate the top of the stack, but note that the wave marker pointer TM remains at the level it was set to after sampling. Another subroutine E is called, and at 25, it is shown that the corresponding stack frame E has been pushed onto the call stack. At this point, the software is interrupted again to perform call stack sampling, and now the sampling only includes copying the stack frames D and E, i.e., the call stack contents between the SP and TM pointers, because the position of the TM pointer indicates that further sampling below this point in the call stack is unnecessary since that portion has not changed since the last call stack sampling was performed.

[0038] Figure 2B shows Figure 2A the evolved variant shown. In fact, the evolution from 30 to 33 is the same as the evolution from 20 to 23 and will not be described here. Between Figure 2B 33 and 34 in, the subroutine C returns, causing the stack frame C to be popped from the call stack. Associated with this pop, both the stack pointer SP and the wave marker pointer TM are updated to correspond to the new state of the call stack. Subsequently, the new subroutine D is called, and at 35, this is shown by the stack frame D that has been pushed onto the call stack, and after that another subroutine E is called, as shown at 36, where the stack frame E is pushed onto the call stack. Thus, in the case where the call stack has the Figure 2B state shown at 36 in, when the software is interrupted to execute the call stack sampling program, the sampling only copies the contents of the call stack between SP and TM (i.e., frames E and D).

[0039] Figure 3 is a flowchart showing the steps taken by a method according to one exemplary embodiment. The process can be considered to start at step 50, where it is determined whether a function (subroutine) has been called or has returned. If this is the case, the process proceeds to step 51, where it is determined whether this is a function (subroutine) call. If so, the process proceeds to step 52, where a new stack frame corresponding to this new function call is pushed onto the call stack. It should be understood that this causes the stack pointer SP to now indicate this newly added stack frame. Then, the process returns to step 50. Returning to the consideration at step 51, if this is not a function call, then it is a return and the process proceeds to step 53, where the returned function frame is popped from the top of the call stack. It should be understood that this pop of the frame from the call stack also causes the stack pointer to be reset to indicate the new top of the remaining call stack. Then at step 54, if necessary, the wave marker pointer is also updated because it is set to the minimum of its current value and the updated stack pointer value. Then, the process returns to step 50. When it is determined at step 50 that neither a function call nor a function return occurs, the process proceeds to step 55, where it is determined whether to perform a sampling of the call stack. If this is not the case, the process simply returns to step 50. However, when a call stack sampling is to be performed, the process proceeds to step 56, where it is first determined whether the wave marker pointer value matches the value of the stack pointer. If it matches, this indicates that the call stack has not changed since its last sampling, and since no further call stack sampling is required, the process simply returns to step 50. However, if this is not the case, the process proceeds to step 57, where the call stack is sampled between the levels indicated by the stack pointer and the wave marker pointer. Then at step 58, the wave marker pointer is set to the current value of the stack pointer. Then, the process returns to step 50.

[0040] Figure 4AAn apparatus 17 in an exemplary embodiment is schematically illustrated. The processing circuit 71 is software multi-threaded and can thus switch between multiple software threads. Each software thread has an associated context (defining various aspects of the state of the data processing apparatus), and as Figure 4A shown, the current context 73 of the currently executing software thread can be considered to include a stack pointer value 74 and a wavemark pointer value 75. Thus, when the processing circuit 71 switches software threads, the current context 73 is saved and exported for storage in the storage device 72, while the stored context 76 (stored values including the stack pointer value 76 and the wavemark pointer value 78) saved in the storage device 72 is imported for the software thread to which the processing circuit is switching. If the current value of the wavemark pointer is simply invalidated or reset (see Figure 2A and Figure 2B , set to the zero level), then an alternative method is employed when switching to a different software thread. This invalidation or reset does not functionally affect the data processing operations performed by the processing circuit, but when the call stack is sampled next, the entire call stack will need to be sampled. When the wavemark pointer value is maintained as part of the context of a thread, it can also be transferred in and out of the processing circuit according to any context switching mechanism (e.g., save registers or lazy loading of context from memory).

[0041] Figure 4B An apparatus 80 in an exemplary embodiment is schematically illustrated. Specifically, Figure 4B two exemplary mechanisms by which a processing circuit can be caused to execute a call stack sampling program are schematically illustrated. As Figure 4B shown, the apparatus 80 includes a processing circuit 81 and a timer 82. The timer 82 can be set to a suitable interval for the call stack sampling to be performed and generate interrupts at an appropriate frequency. When an interrupt IRQ1 is received from the timer 82, the processing circuit 81 can execute a call stack sampling program. Figure 4B A call stack monitoring circuit 83 including a comparison circuit 84 is also shown (although it should be noted that both mechanisms can be present, or only one of them can be present). The comparison circuit 84 receives the value of the stack pointer 85 and the value of the wavemark pointer 86. Based on the comparison of these values, the comparison circuit 84 can generate an interrupt IRQ2 for the processing circuit 81 to cause it to perform a call stack sampling program. The configuration of the comparison circuit 84 can be set, for example, such that when the stack pointer value 85 exceeds the wavemark pointer value 86 (see, for example, Figure 2A and Figure 2B ), then the sampling of the call stack is triggered. It should also be noted that the call stack monitoring circuit 83 can also receive an input from a timer 87 such that the comparison between the SP and the TM is not performed continuously, but rather the two are compared at a predetermined interval.

[0042] Figure 5An apparatus 100 in an exemplary embodiment is schematically illustrated. Here, the processing circuitry 101 is hardware multithreaded and thus includes separate hardware controls for multiple threads. This is represented by thread A control 102 and thread B control 103 in Figure 5 . For simplicity of illustration, only two hardware threads are shown. Correspondingly, two call stacks 104 and 105 are maintained in the storage device 106, and the call stack control circuitry 107 maintains stack pointer values 108 and wavemark pointer values 109 corresponding to the respective call stacks, as well as stack pointer values 110 and wavemark pointer values 111.

[0043] Figure 6A An apparatus 120 in an exemplary embodiment is schematically illustrated. The apparatus includes processing circuitry 121 that performs data processing operations and utilizes a call stack 130 data structure stored in the storage device 140 when performing its data processing operations. The processing circuitry maintains a stack pointer 122 with reference to the call stack 130. The apparatus 120 also includes a call stack buffer 124 in which a fixed number of records 125 can be stored, each record including a source address, a target address, and a stack pointer value, as Figure 6B shown. The call stack buffer 124 is updated by call and return instructions. Further, updating the stack pointer (e.g., on a software exception unwind of multiple calls) causes any call stack buffer records with a newer (higher) stack pointer value to be discarded. The apparatus 120 also includes a call stack buffer sampler 128 that is arranged to control the copying process of contents from the call stack buffer 128 to a trace buffer 150. The contents of the trace buffer 150 are periodically exported or exported in response to a specific signal. The call stack buffer sampler 128 maintains a wavemark pointer value 131 and a stack pointer value 132 (which is a copy of the stack pointer 122 maintained by the processing circuitry 121). The call stack buffer sampler 128 also includes a timer 133 that triggers the call stack buffer sampler to copy the contents of the call stack buffer 124 to the trace buffer 150 at a predetermined interval. When performing the copy from the call stack buffer 124 to the trace buffer 150, the call stack buffer sampler compares the recorded stack pointer value with the wavemark pointer value 131 it maintains, and it is configured to stop the copying process when the next record it checks in the call stack buffer 124 corresponds to a subroutine older than the subroutine indicated by the wavemark value 131. In terms of the Figure 2A and Figure 2B illustrated call stack, this would correspond to a stack pointer level lower than the level currently indicated by the wavemark pointer value 131. However, if the copying process ends and the oldest record in the call stack buffer 124 (i.e., having Figure 2A and Figure 2Bthe record of the lowest stack pointer value in the representation) has a stack pointer value higher than the WaveMark pointer value 131, this indicates that there is a gap between the content available in the call stack buffer 124 and the portion of the call stack 130 for which sampling has previously been performed. In this case, the software needs to unwind the call stack and the call stack buffer sampler generates an interrupt IRQ to cause the processing circuitry 121 to be interrupted to do so. Once this is done, an accurate record of the call stack has been made down from the latest record in the call stack buffer, and after that the WaveMark pointer value 131 is set to the current stack pointer value SP. The apparatus 120 also includes a trace buffer rewrite monitor 151 that monitors the use of the trace buffer 150 and specifically identifies when the non-exported content of the trace buffer is rewritten. In this case, it signals the call stack buffer sampler 128 and the WaveMark pointer 131 is reset (i.e., zeroed in the representation of Figure 2A and Figure 2B so that a full call stack unwind will be performed at the next sampling point to recapture this information.

[0044] Figure 7 is a flowchart showing the sequence of steps performed in the method of an exemplary embodiment, for example, can be performed within the apparatus 120 of Figure 6A . The process can be considered to start at step 200, where it is determined whether call stack sampling is required. The process does not wait at this point. When call stack sampling is to be performed, the process proceeds to step 201, where a copy process for copying the content of the call stack buffer to the trace buffer is initiated. Next, at step 202, it is determined whether the first record encountered has a stack pointer value greater than the current WaveMark pointer value. If it does, the process proceeds to step 203 and stops the copy process, and at step 204 the WaveMark pointer value is updated to match the most recent call record stored in the call stack buffer. Then, the process returns to step 200. Returning to the consideration of step 202, if this condition is not true, then at step 205, the record is copied from the call stack buffer to the trace buffer. Then at step 206, it is determined whether the oldest record in the call stack buffer has been reached. If not, the process returns to step 202. However, if the oldest record in the call stack buffer has been reached, then at step 207, it is determined whether this oldest record has a stack pointer value greater than the current WaveMark pointer value. If this is not the case, the process returns to step 200. Otherwise, if this is true at step 207, the process proceeds to step 208, where the software is caused to unwind the full call stack (to cover the gap) and then at step 209 the WaveMark pointer is set to the current value of the stack pointer. Then, the process returns to step 200.

[0045] Figure 8is a flowchart showing a sequence of steps taken by a method according to an embodiment, the sequence of steps being executable, for example, by the apparatus 120 in Figure 6A . The process may be considered to start at step 250, where it is determined whether there is a new function call to be pushed onto the call stack buffer. The process waits at this point until this is the case. When this is true, the process proceeds to step 251, where it is determined whether creating the new record in the call stack buffer would result in the new record having a stack pointer value greater than the current value of the wavemark pointer. If this is not the case, the process proceeds to step 252 and creates a new call stack buffer record, and the process returns to step 250. However, if this condition is true, the process proceeds to step 253, where the contents of the call stack buffer are caused to be copied to the trace buffer, and the wavemark pointer is updated to the current stack pointer value at step 254. This method and manner means that subsequently when a call stack sampling trigger occurs and call stack sampling is required, the trace buffer already has the call stack contents captured up to that point and there is no need to interrupt the software to unwind the stack. Note that a delay may be introduced into the Figure 8 process steps to avoid heavily nested code (i.e., code that repeatedly executes a large number of calls followed by a large number of returns) that would cause more preemptive tracing than desired.

[0046] In short, an apparatus and method of operation are disclosed. A call stack is maintained that includes subroutine information related to subroutines that have been called during a data processing operation and have not yet returned. A stack pointer indicates the end of the call stack associated with the most recently called subroutine that has been called during the data processing operation and has not yet returned. Call stack sampling may be performed with reference to the stack pointer. A wavemark pointer is maintained that indicates the value that the stack pointer had when the processing circuitry last completed the call stack sampling procedure. The call stack sampling procedure includes retrieving subroutine information indicated between the value of the wavemark pointer and the current value of the stack pointer from the call stack. This enables more efficient call stack sampling because only modifications to the call stack need to be sampled.

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

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

Claims

1. A data processing apparatus, comprising: a processing circuit configured to perform data processing operations, wherein the data processing operations include subroutines; a call stack storage device configured to store a call stack including subroutine information related to subroutines that have been called and not yet returned during the data processing operations; a stack pointer storage device configured to store a stack pointer, wherein a current value of the stack pointer indicates an end of the call stack associated with the most recently called subroutine that has been called and not yet returned during the data processing operations, wherein the processing circuit executes a call stack sampling program in response to a call stack sampling trigger, the call stack sampling program including accessing the call stack with reference to the stack pointer, and a wave flag pointer storage device configured to store a wave flag pointer, wherein a value of the wave flag pointer indicates a previous value that the stack pointer had when the processing circuit last completed the call stack sampling program, wherein the processing circuit is arranged to execute the call stack sampling program, the call stack sampling program including retrieving subroutine information indicated between the value of the wave flag pointer and the current value of the stack pointer, wherein the wave flag pointer storage device modifies the wave flag pointer to match the current value of the stack pointer in response to execution of the call stack sampling program, and wherein the wave flag pointer storage device modifies the wave flag pointer in response to removal of subroutine information from the call stack to match the current value of the stack pointer resulting from the removal of subroutine information from the call stack.

2. The apparatus according to claim 1, wherein the wave flag pointer storage device modifies the wave flag pointer to match the current value of the stack pointer in response to execution of a subroutine return instruction that causes the current value of the stack pointer to correspond to a subroutine that is less recently called compared to the subroutine indicated by the value of the wave flag pointer.

3. The apparatus according to claim 1 or claim 2, wherein the wave flag pointer storage device modifies the wave flag pointer to match the current value of the stack pointer resulting from a write to the stack pointer, the write causing the current value of the stack pointer to correspond to a subroutine that is less recently called compared to the subroutine indicated by the value of the wave flag pointer.

4. The apparatus according to claim 1 or claim 2, wherein the call stack sampling trigger is receipt of a predetermined call stack sampling interrupt.

5. The apparatus according to claim 4, wherein the wave flag pointer storage device and the stack pointer storage device are arranged to cooperate to generate the predetermined call stack sampling interrupt when the current value of the stack pointer indicates a stack pointer position corresponding to a subroutine that is more recently called compared to a subroutine corresponding to a wave flag position in the call stack indicated by the value of the wave flag pointer.

6. The apparatus according to claim 1 or claim 2, wherein the call stack sampling trigger is after a predetermined time period.

7. The apparatus according to claim 1 or claim 2, wherein the processing circuit is software multi-threaded and, when performing a thread switch from a first thread to a second thread, is arranged to export the thread context of the first thread including a first value of the wavemark pointer for the first thread and is arranged to import the thread context of the second thread including a second value of the wavemark pointer for the second thread.

8. The apparatus according to claim 1 or claim 2, wherein the processing circuit is software multi-threaded and, when performing a thread switch from a first thread to a second thread, is arranged to invalidate a first value of the wavemark pointer for the first thread and is arranged to set a default value as a second value of the wavemark pointer for the second thread.

9. The apparatus according to claim 1 or claim 2, wherein the processing circuit is hardware multi-threaded, wherein the call stack storage device is capable of storing a set of per-thread call stacks, wherein the stack pointer storage device is capable of storing a set of per-thread stack pointers, and wherein the wavemark pointer storage device is capable of storing a set of per-thread wavemark pointers.

10. The apparatus according to claim 1, further comprising: a call stack buffer for storing records, each record including: the source address and the target address of a subroutine that has been called and has not yet returned during the data processing operation; and the recorded value of the stack pointer at the time point when the record is created; a trace buffer for storing trace data for export from the apparatus; and a call stack buffer sampling circuit that, in response to a call stack buffer sampling trigger, performs a record copying process that includes copying the stored records in the call stack buffer to the trace buffer.

11. The apparatus according to claim 10, wherein when performing the record copying process, the call stack buffer sampling circuit ends the record copying process in response to reaching a record where the recorded value of the stack pointer indicates a stack pointer position in the call stack corresponding to a subroutine that is not the most recently called subroutine compared to the subroutine corresponding to the wavemark position in the call stack indicated by the value of the wavemark pointer, and updates the wavemark pointer to indicate the most recently called subroutine indicated in the call stack buffer.

12. The apparatus according to claim 10 or claim 11, wherein when performing the record copying process, the call stack buffer sampling circuit responds to reaching the oldest record in the call stack buffer corresponding to the least recently called subroutine having a record in the call stack buffer, and when the record value of the oldest record indicates a stack pointer position of a subroutine in the call stack that is more recently called compared to the subroutine corresponding to the wave marker position in the call stack indicated by the value of the wave marker pointer, causes the processing circuit to execute the call stack sampling program.

13. The apparatus according to claim 10 or claim 11, wherein the call stack buffer sampling circuit is arranged to cause the processing circuit to execute the call stack sampling program by issuing a call stack sampling interrupt.

14. The apparatus according to claim 10 or claim 11, wherein the call stack buffer discards a record whose record value of the stack pointer indicates a stack pointer position of a subroutine in the call stack that is more recently called compared to the subroutine corresponding to the stack pointer position in the call stack indicated by the modified value of the stack pointer in response to modifying the value of the stack pointer.

15. The apparatus according to claim 10 or claim 11, wherein the call stack buffer sampling circuit responds to a new subroutine call and, when creating a new record of the new subroutine call will cause the new record to have a record value of the stack pointer indicating a stack pointer position of a subroutine in the call stack that is more recently called compared to the subroutine corresponding to the wave marker position in the call stack indicated by the value of the wave marker pointer, performs the record copying process and updates the value of the wave marker pointer to the current value of the stack pointer.

16. The apparatus according to claim 15, wherein the call stack buffer sampling circuit is arranged to further perform the record copying process depending on a predefined call stack buffer copy timing interval.

17. The apparatus according to claim 10 or claim 11, wherein the trace buffer causes the value of the wave marker pointer to be set to a stack pointer position corresponding to indicating the oldest position in the call stack in response to a trace buffer rewrite, wherein the trace buffer rewrite causes unexported trace data to be rewritten.

18. The apparatus according to claim 10 or claim 11, wherein the trace buffer causes the wave marker pointer to become invalid in response to a trace buffer rewrite, wherein the trace buffer rewrite causes unexported trace data to be rewritten.

19. A method of data processing, comprising: performing a data processing operation, wherein the data processing operation includes subroutines; storing a call stack including subroutine information related to subroutines that have been called and have not yet returned during the data processing operation; Store a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine, and the most recently called subroutine has been called and has not returned during the data processing operation; Execute a call stack sampling program in response to a call stack sampling trigger, where the call stack sampling program includes accessing the call stack with reference to the stack pointer; Store a wave mark pointer, where the value of the wave mark pointer indicates the previous value that the stack pointer had when the call stack sampling program was last completed; Modify the wave mark pointer to match the modified value of the stack pointer in response to executing the call stack sampling program; and Modify the wave mark pointer to match the current value of the stack pointer resulting from removing subroutine information from the call stack, where executing the call stack sampling program includes retrieving subroutine information indicated between the value of the wave mark pointer and the current value of the stack pointer.

20. A data processing apparatus, comprising: Means for performing a data processing operation, where the data processing operation includes subroutines; Means for storing a call stack including subroutine information related to subroutines, where the subroutines have been called and have not returned during the data processing operation; Means for storing a stack pointer, where the current value of the stack pointer indicates the end of the call stack associated with the most recently called subroutine, and the most recently called subroutine has been called and has not returned during the data processing operation; Means for executing a call stack sampling program in response to a call stack sampling trigger, where the call stack sampling program includes accessing the call stack with reference to the stack pointer; Means for storing a wave mark pointer, where the value of the wave mark pointer indicates the previous value that the stack pointer had when the call stack sampling program was last completed; Means for modifying the wave mark pointer to match the modified value of the stack pointer in response to executing the call stack sampling program; And Means for modifying the wave mark pointer to match the current value of the stack pointer resulting from removing subroutine information from the call stack, where executing the call stack sampling program includes retrieving subroutine information indicated between the value of the wave mark pointer and the current value of the stack pointer.

Citation Information

Patent Citations

  • Interrupt-based hardware support for profiling system performance

    CA2152110A1

  • Operation system performance analysis method and device

    CN102004678A