[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

General Programming Concepts: Writing and Debugging Programs


Chapter 29. High-Resolution Time Measurements Using POWER-based Time Base or POWER family Real-Time Clock

The POWER family and PowerPC 601 RISC Microprocessor have real-time clock registers that can be used to make high-resolution time measurements. These registers provide seconds and nanoseconds.

POWER-based processors other than PowerPC 601 RISC Microprocessor do not have real time clock registers. Instead these processors have a time base register, which is a free-running 64-bit register that increments at a constant rate. The time base register can also be used to make high resolution elapsed-time measurements, but requires calculations to convert the value in the time base register to seconds and nanoseconds.

If an application tries to read the real-time clock registers on a POWER-based processor that does not implement them, the processor generates a trap that causes the instruction to be emulated. The answer is correct, but the emulation requires a much larger number of cycles than just reading the register. If the application uses this for high-resolution timing, the time associated with the emulation is included.

If an application tries to read the time base registers on any processor that does not implement them, including the PowerPC 601 RISC Microprocessor, this will not be emulated and will result in the application being killed.

Beginning with AIX Version 4, the operating system provides the following library services to support writing processor-independent code to perform high resolution time measurements:

read_real_time Reads either the real-time clock registers or the time base register and stores the result
time_base_to_time Converts the results of read_real_time to seconds and nanoseconds

read_real_time does no conversions and runs quickly. time_base_to_time does whatever conversions are needed, based on whether the processor has a real-time clock register or a time base register, to convert the results to seconds and nanoseconds.

Since there are separate routines to read the registers and do the conversions, an application can move the conversion out of time-critical code paths.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]