Patent Publication Number: US-6336191-B1

Title: Method and system for clock compensation in instruction level tracing in a symmetrical multi-processing system

Description:
BACKGROUND OF THE INVENTION 
     1. Technical Field 
     The present invention relates in general to a method and system for data processing and in particular to an improved method and system for clock compensation in a symmetrical multi-processing system. Still more particularly, the present invention relates to a method and system for clock compensation in a symmetrical multi-processing environment when using instruction level tracing tools. 
     2. Description of the Related Art 
     Conventionally, detailed code debugging or analysis in a symmetrical multi-processing system or information handling system can be accomplished by using software-tracing tools. These software tracing tools divert the flow of execution from the regular code to their own code to take the trace. Typically, this usually adds many instructions to the regular path of execution and slows it down considerably, depending on the granularity of the trace. 
     With the machine executing many more instructions than in regular mode, and the hardware, including the clock, going at regular speed, huge distortions in the trace can be observed, essentially because of the clock interrupt handling code. Therefore, clock “compensation” is necessary in software instruction level tracing tools because they divert the flow of execution from the regular code to their own code to take the trace. Prior art solutions to solve this problem have the clock “compensated” or slowed down while the software-tracing tool is active. However, these solutions do not work very effectively in a symmetrical multi-processor SMP environment where there is no mechanism to force the processor clocks to stay in sync. Another weakness of prior art compensation techniques is the lack of machine speed or workload type related adjustment of the compensation amount that is typically a static value. 
     Consequently, it would be desirable to provide an improved method and system that compensates all the processor clocks in an SMP environment when using software-instruction level tracing. The subject invention herein solves all of these problems in a new and unique manner that has not been part of the art previously. 
     SUMMARY OF THE INVENTION 
     It is therefore one object of the present invention to provide an improved method and system for clock compensation during instruction level tracing. 
     It is another object of the present invention to provide an improved method and system for clock compensation when using instruction level tracing in a symmetrical multi-processing SMP environment. 
     It is yet another object of the present invention to provide an improved method and system for linking the machine speed and the type of workload to be traced to the clock compensation amount. 
     The foregoing objects are achieved as is now described. A method and system within a symmetrical multi-processing system or information handling system are disclosed for compensating all the processor clocks when performing instruction level tracing. The method provides a simple and flexible mechanism to slow down the clock proportionally to the density of the trace. According to the present invention, the method determines two parameters; a trigger and a compensation step. The trigger is defined as the number of instructions in the traced code between clock increments and the compensation step is the number of ticks to add to a clock. When the trigger is equal to one, the clock is incremented at each tracing step by an amount equal to the compensation step multiplied by the number of instructions in the current basic block. When the trigger is greater than one, the compensation step is equal to one and the clock is incremented by one every time the number of instructions since the last compensation is bigger than the trigger. The method and system of the present invention links the trigger and compensation step to the processor speed and the workload to trace thereby allowing accurate clock compensation. 
     The above as well as additional objects, features, and advantages of the present invention will become apparent in the following detailed written description. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself however, as well as a preferred mode of use, further objects and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein: 
     FIG. 1 depicts a high-level block diagram of a symmetrical multi-processing system, which may use the clock compensation method of the present invention; 
     FIG. 2 is a flow diagram depicting the calculation of parameters used in association with the clock compensation method in accordance with the present invention; 
     FIG. 3 is a flow diagram depicting the clock compensation method in accordance with the present invention; 
     FIG. 4 is a detailed flow diagram depicting the step for determining if clock compensation is safe to perform in FIG. 3; 
     FIG. 5 is a detailed flow diagram depicting the step when clock compensation is not performed in FIG. 3; 
     FIG. 6 is a detailed flow diagram depicting the step of calculating the compensation increment in FIG. 3; and 
     FIG. 7 is a detailed flow diagram depicting the step of compensating the clock and try to compensate the decrementer in FIG.  3 . 
    
    
     DETAILED DESCRIPTION OF ILLUSTRATIVE EMBODIMENT 
     With reference now to the figures and in particular with reference to FIG. 1, there is illustrated a preferred embodiment of a symmetrical multi-processing SMP system  10  that may be used with the method and system of the present invention. The SMP system comprises multiple integrated circuit pipelined superscalar microprocessors, shown in one example as  12   a  and  12   b  in FIG.  1 . Accordingly, the multiprocessors each include processing cores  28  and  38 , instruction caches  24  and  42 , and data caches  26  and  44 , respectively. The processor cores,  28  and  38 , preferably comprise one of the PowerPC™ line of microprocessors available from IBM Microelectronics (e.g., the PowerPC™604), which operate according to reduced instruction set computing (RISC) techniques. Details concerning the architecture and operation of the PowerPC™604 processor may be found in the  PowerPC™ 604  RISC Microprocessor User&#39;s Manual , which is incorporated herein by reference. 
     Referring once again to FIG. 1, the processing cores  28  and  38 , are connected via a single system bus  20  to I/O devices  14  and memory  16  through processor clocks  30  and  32  and decrementers  34  and  36  for use with the present invention, as will be more fully described below. The processor clocks and decrementers may be implemented utilizing first and second hardware counters. The first counter or processor clock is continuously being incremented and serves as the time reference, and the second counter or decrementer is decremented continuously at the same frequency until it reaches zero, at which point a clock interrupt is generated and the clock interrupt handling code is called to reload this counter. Therefore, the second counter or decrementer represents ticks until the next clock interrupt will be sent to the processor. 
     In accordance with the method and system of the present invention, two parameters are initially calculated for use in clock compensation, more specifically, a trigger and a compensation step. The method provides a simple mechanism to slow down the clock proportionally to the density of the trace. The trigger is defined as the number of instructions in the traced code between clock increments and the compensation step is the number of ticks to add to a processor clock and to delete from a decrementer. The following parameters must first be determined in order to calculate the compensation amount and are set values used in accordance with the preferred embodiment of the present invention: 
     P=Processor Speed (in Cycles/Second); 
     T=Clock Speed (in Ticks/Seconds); 
     C=CPI (in Cycles/Instructions); and 
     by making the appropriate substitutions; 
     
       
         Compensation Amount=( C×T )/ P  (in Ticks/Instructions). 
       
     
     Referring now to FIG. 2, there is shown a flowchart for the calculation of the compensation step and the trigger that should be used given the above calculated compensation amount. More specifically, the compensation amount is a fractional number that is broken into a combination of the trigger and compensation step, as will be more fully described below. As shown in block  101 , if the compensation amount is less than one, the compensation step is set equal to one and the trigger is one over the compensation amount, as shown in block  103 . If however, the compensation amount is greater than 1, the trigger than equals one and the compensation step equals the compensation amount, as shown in block  105   
     Referring now to FIG. 3, there is shown a flow diagram depicting the clock compensation method in accordance with the present invention. The method begins at step  100  wherein a current processor clock value is read, either processor clock  30  or  32  of processing units  12   a  or  12   b  for the processing unit which is using instruction level tracing. By way of example, the tracing tool will be used for processing unit  12   a  utilizing processor clock  30  and decrementer  34 . Therefore, reading current clock value at step  100  corresponds to reading the current value of processor clock  30 . At this point, the current clock value becomes a fixed value in software designated as the current clock value within the flowcharts of FIGS. 4 and 5. In accordance with the preferred embodiment of the present invention, a second assigned fixed value in software is used for compensating all the processor clocks and is referred to as the master clock value. A master clock value is always a copy of the current clock value of the processor designated as the master, as will be more fully described below. Only one processor fully compensates both its processor clock and associated decrementer independently from the other processors, while all the other processors compensate only their decrementer independently and simply follow the master processor. 
     Turning once again to FIG. 3, once the tracing code has been executed in step  102 , the method of the present invention determines if a master processor has already been assigned after a first execution of the tracing code for the data processing system, as shown in step  104 . If there is no master processor or if the processing unit being traced has been designated as the master processor, as shown in step  106 , the process proceeds to step  108  to determine if it is safe to compensate the clock  30 . A more detailed flow diagram depicting step  108  is shown in FIG.  4 . 
     Referring now to FIG. 4, the flow diagram shown determines when it is not safe to compensate a processor clock and starts by comparing a previous clock value (which would be a value of zero in the case of a first trace interrupt) taken at a previous trace interrupt to see if it is greater than the current clock value, as shown in step  46 . The case of when the previous clock value is greater than the current clock value represents a processor clock overflow condition. When a processor clock overflow condition occurs it is not safe to compensate, as shown in step  56 , but this occurs very infrequently relative to the frequency of a trace. If the previous clock value is less then than the current clock value a delta value is calculated by subtracting the previous clock value from the current clock value, as shown in step  48 . The typical time between executions of the tracing code is well known in the prior art and is less then a max-delta value wherein max-delta is defined as the maximum delta clock ticks allowed between calls of the tracing code. Therefore, as shown in step  52 , when the delta value is greater than the max-delta value, a large difference between trace events has occurred. This large difference is assumed to be due to an interval of untraced code. In this case the clock once again is not safe to compensate, as shown in step  56 . 
     Referring once again to FIG. 4, if the delta value is equal or less than the max-delta value, the current clock value is checked in step  54  to see if it is greater than a near overflow value. The near overflow value is defined as the maximum clock value to be compensated. Therefore, if the clock is too close to overflowing it is not safe to compensate, as shown in step  56  because it may overflow before the compensation is applied. If the above three conditions in FIG. 4 result in the clock not being safe to compensate then the process in step  108  of FIG. 3 proceeds to step  110  wherein the clock is not compensated. 
     Referring once again to FIG. 3, if it is determined in step  106  that another processor (in this example,  12   b ) has been designated as the master processor, the process proceeds to step  116  to calculate the compensation increment. Additionally, as shown in FIG. 3, if the processing unit  12   a  has been designated as the master processor in step  108  and in accordance with the logic described above in FIG. 4 it is safe to compensate, the process also proceeds to step  116  to calculate the compensation increment. A more detailed flow diagram depicting step  116  is shown in FIG.  6 . 
     Referring now to FIG. 6, there is shown a detailed flow diagram depicting the step of calculating the clock compensation increment in step  116  of FIG.  3 . The method of the present invention links the machine speed and the type of workload to be traced to the clock compensation amount. This compensation scheme is based on the assumption that when tracing is activated each instruction or basic block is being traced. Therefore the real time between calls is very nearly just the time spent in the tracing code. In accordance with the present invention and as mentioned before, two parameters are used; the trigger and the compensation step. As described before, the trigger is the number of instructions between clock increments before compensation and the compensation step is the number of ticks to add to the clock and represent in combination the fractional value for the compensation amount. Referring to FIG. 6, if in step  62  the trigger value is equal to one, the increment amount, in step  64  equals the compensation step times the number of instructions in a current block and the process returns to FIG.  3 . 
     However, if the trigger value is greater than one, a value for the instructions since compensation (ISC) is determined in step  66 , which equals the number of instructions since the last time the trigger value was reached and the clock was compensated. This ISC value is then checked to see if it is less than the trigger value in step  68 . If the ISC value is less than the trigger value the new value for ISC equals its value plus the number of instructions in the current block and the increment is set equal to zero, as shown in steps  70  and  74 . If the ISC value is greater or equal than the trigger value, the new ISC and increment amount value are respectively the integer remainder of the ISC value divided by the trigger value and the result of the integer division, as shown in steps  72  and  50 . For example, 9/2=4 (9 equaling the number of instructions and 2 equaling the predetermined trigger value) with an integer remainder of 1, the value of the increment equals 4 and the ISC equals 1. The process after completing either step  74  or  50  now has an increment value for compensation and returns to FIG.  3 . Good values for the trigger and the compensation step are critical for accurate clock compensation and depend on the machine speed and the workload to be traced. As described above the compensation step and trigger are linked to these two parameters thereby allowing accurate clock compensation. 
     Turning once again to FIG. 3, the processing unit  12   a  is once again checked to see if it is the master processor in step  118 . If the processing unit  12   a  is the master processor, then the new clock value equals the previous clock value plus the increment determined in step  116  from FIG. 6, as shown in step  124 . The previous clock and master clock values are now set equal to this new clock value and the decrementer and clock are compensated for use next time the tracing code is called, as shown in steps  126 ,  128  and  130 . If the processing unit in step  118  is not designated as the master processor, the process proceeds to step  120  wherein a determination is made if there is already a master processor. If there is no master processor yet, then the case of the first time through the tracing code has occurred for the data processing system and processor  12   a  is designated as such in step  122  and the process proceeds to step  124 , as described above. If there is a master processor and it is not the processing unit  12   a , the new clock value is set equal to the master clock value and the previous clock value is set equal to the new clock value, as shown in steps  132  and  128 , and the decrementer and clock are compensated in step  130 . A more detailed flow diagram depicting step  130  of FIG. 3 is shown in FIG.  7 . 
     Referring now to FIG. 7, there is shown a detailed flow diagram depicting the step of compensating the clock and compensating the decrementer when necessary in step  130  of FIG.  3 . Referring to FIG. 7, the current decrementer value is read from the decrementer  34  in step  152  and a determination is made if it is a negative value in step  154 . The decrementer continues to decline regardless of the clock value. A negative decrementer indicates that a clock interrupt has already been posted and there is no need to compensate the decrementer until it has been reloaded with a positive value by the operating system&#39;s clock interrupt handling code. If the decrementer is negative, the negative decrementer value is set equal to one, and the new clock value calculated in FIG. 3 is now written to the processor clock  30  of processing unit  12   a , as shown in steps  160  and  166 . The previous decrementer value is then set equal to the current decrementer value for use the next time the tracing code is being executed, as shown in step  162 . At this point in the process, compensation has been completed for this execution of the tracing code and the method therefore finishes and ends at step  112  in FIG. 3 until the next time the tracing code is being executed. If, in step  154 , the current decrementer is not negative, the negative decrementer value is checked in step  158  to see if it is equal to one. If the negative decrementer value is equal to one, its value is set equal to zero in step  170  and the process continues to step  162 . If the negative decrementer value is not equal to one in step  158 , then a new decrementer value is set equal to the previous decrementer value minus the increment calculated in FIG.  6 . This new decrementer value is now written to the decrementer  34  in processing unit  12   a , as shown in step  164 . The previous decrementer value is now set to the new decrementer value and the new clock value calculated in FIG. 3 is now written to the processor clock  30  of processing unit  12   a . Compensation has again been completed for this execution of the tracing code and the method therefore finishes and ends at step  112  in FIG. 3 until the next execution of the tracing code. 
     Referring now to FIG. 5, there is shown a detailed flow diagram depicting step  110  in FIG. 3 when clock compensation is not performed after the execution of the tracing code. Referring to FIG. 5, the ISC value is set to the number of instructions in the current basic block in step  138 . The current clock and current decrementer values are read respectively from the processor clock  30  and the decrementer  34  in steps  142  and  144 . The processing unit  12   a  is then checked in step  146  to see if it is designated as being the master processor. If processing unit  12   a  is the master processor, then the value assigned to the master clock value in software is set equal to the current clock value of step  142  and the process proceeds to step  159 . If the processing unit  12   a  has not been designated as the master processor, then the process proceeds directly to step  159 . As shown in FIG. 5, in step  159  the previous decrementer value is set to the current decrementer value and the previous clock value is set to the current clock value. Therefore, the next time the tracing code is being called, the current values for the clock and decrementer become stored as the previous clock and decrementer values for use with the method of the present invention. At this point in the process no compensation was necessary after the execution of the tracing code and the method therefore finishes and ends at step  112  in FIG. 3 until the next time the tracing code is being called. These calculations cover the cases for which no clock compensation is used. The relative infrequency of these cases means that they have negligible effect on clock compensation. The previous clock value is simply reset to the current value of the clock. 
     It therefore should be appreciated that the advantage of using the present invention versus prior art compensation techniques is in that all the processor clocks in a symmetrical multi-processing system may be compensated. The method described allows one processor to fully compensate its clock and decrementer independently while all the other processor&#39;s to compensate only their decrementers independently and simply follow a defined “Master” processor clock value. The method and system of the present invention provides a simple and flexible mechanism which is performed each time the code used to take the trace is executed by slowing down the clock proportionally to the density of the trace. 
     It is also important to note that although the present invention has been described in the context of a fully functional clock compensation technique for symmetrical multi-processing systems when performing instruction level tracing, those skilled in the art will appreciate that the mechanisms of the present invention are capable of being distributed as a program product in a variety of forms to any type of information handling system, and that the present invention applies equally regardless of the particular type of signal bearing media utilized to actually carry out the distribution. Examples of signal bearing media include, without limitation, recordable type media such as floppy disk or CD ROMs and transmission type media such as analog or digital communications links. 
     While the invention has been particularly shown and described with reference to a preferred embodiment, it will be understood by those skilled in the art that various changes in form and detail may be made therein without departing from the spirit and scope of the invention.