[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs

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

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

PowerPC 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. This 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 PowerPC 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.
time_base_to_time Converts the results of read_real_time to seconds and nanoseconds.

read_real_time reads either the time base register or the real-time clock register and stores the result. This routine 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 | Contents | Glossary | Home | Search ]