Browse Prior Art Database

# Clock Compensation Algorithm for Instruction Level Tracing Tools

IP.com Disclosure Number: IPCOM000118655D
Original Publication Date: 1997-May-01
Included in the Prior Art Database: 2005-Apr-01
Document File: 4 page(s) / 106K

IBM

## Related People

Smolders, LR: AUTHOR [+1]

## Abstract

Disclosed is an algorithm used to "compensate", i.e., slow down the clock in instruction level software tracing tools. It provides a simple and flexible mechanism to slow down the clock proportionally to the density of the trace.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 44% of the total text.

Clock Compensation Algorithm for Instruction Level Tracing Tools

Disclosed is an algorithm used to "compensate", i.e., slow down
the clock in instruction level software tracing tools.  It provides a
simple and flexible mechanism to slow down the clock proportionally
to the density of the trace.

Software tracing tools divert the flow of execution from the
regular code to their own code to take the trace.  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 interruption handling code.  To solve this problem, an
algorithm is proposed here to slow down the clock, therefore,
limiting the number and the distortion introduced by clock
interruptions.

The term "clock" is usually implemented with two counters.  One
is continuously being incremented and serves as the time reference
and the other one is decremented until it reaches zero, at which
point a clock interrupt is generated and the clock interrupt handling
code is called to reload the counter.  One variety of the first
counter is called  Real Time Clock.  It represents the number of
ticks since a fixed known  time.  Knowing that start time and the
value of a tick, gives you the current time.  Another type of counter
just counts the number of ticks  since it was last reloaded with
zero.  This is called a Time Based Clock.  Knowing when the counter
was started and the value of the tick  is all that is necessary to
calculate the current time.  In both cases,  the second counter
represents ticks until the next clock interrupt will  be sent to the
processor.  This counter is also usually called the decrementer.

The algorithm proposed here works with both types of
clocks.  It is executed each time the code used to take the trace is
executed.  Here follows its pseudo-code:
< code to take trace >
if (previous_clock > current_clock) then
goto end   # clock rolled over since last compensation
# see note 1
if ((current clock value - previous clock value) > Maxdelta)
goto end   # code not being traced ran since last compensation
# see note 2
if (decrementer < Nearzero) then
goto end   # decrementer too close to zero to compensate
# see note 3
if (clock > Nearoverflow) then
goto end   # clock too close to overflow to compensate
# see note 4
if (count_since_trigger < trigger) then
count_since_trigger++
goto end
# clock compensation
# see note 5
target_clock_value = previous_clock + Step
new_clock_value  ...