• Aucun résultat trouvé

Time Base

Dans le document PowerPC Architecture First Edition (Page 150-154)

The Time Base (TB) is a 64-bit register (see Figure 37) containing a 64-bit unsigned integer which is incremented periodically. Each increment adds 1 to the .Iow-order bit (bit 63). The frequency at which the counter is updated is implementation-dependent.

o Field TBU TBl

TBU TBl

32

Description

Upper 32 bits of Time Base lower 32 bits of Time Base Figure 37. Time Base

63

The Time Base increments until its value becomes OxFFFF _FFFF _FFFF _FFFF (264 - 1). At the next incre-ment, its value becomes OxOOOO_OOOO_OOOO_OOOO.

There is no explicit indication (such as an interrupt:

see Part 3, "PowerPC Operating Environment Architecture" on page 141) that this has occurred.

The period of the Time Base depends on the driving frequency. As an order of magnitude example, suppose that the CPU clock is 1 00 MHz and that the Time Base is driven by this frequency divided by 32.

Then the period of the Time Base would be 264

x

32 12

TTS

=

100 MHz = 5.90 x 10 seconds which is approximately 187,000 years.

The PowerPC Architecture does not specify a relation-ship between the frequency at which the Time Base is updated and other frequencies, such as the CPU clock or bus clock, in a Power PC system. The Time Base update frequency is not required to be constant.

What is required, so that system software can keep time of day and operate interval timers, is that either:

• The system provides an (implementation-dependent) interrupt to software whenever the update frequency of the Time Base changes, and

also a means to determine what the current update frequency is;

or

• The update frequency of the Time Base is under the control of the system software.

Programming Note ---~

If the operating system initializes the Time Base on power-on to some reasonable value and the update frequency of the Time Base is constant, the Time Base can be used as a source of values which increase at a constant rate, such as for time stamps in trace entries.

Even if the update frequency is not constant, values read from the Time Base are monotonically increasing (except when the Time Base wraps from 264_1 to 0). If a trace entry is recorded each time the update frequency changes, the sequence of Time Base values can be post-processed to become actual time values.

8.1 Time Base Instructions

Extended mnemonics

A pair of extended mnemonics is provided for the mftb instruction so that it can be coded with the TBR name as part of the mnemonic rather than as a numeric operand. See the Assembler Extended Mne-monics appendix in Part 3, "PowerPC Operating Envi-ronment Architecture" on page 141.

Move From Time Base XFX-form

mftb RT,TBR

31

16

RT

I"

tbr

12,

371

1:,1

Chapter 8. Time Base 137

n

+-

tbrS:9 II tbro:4 if n = 268 then

if (64-bit implementation) then

RT +- TB

else

RT +- TB32:63

else if n = 269 then

if (64-bit implementation) then

RT +- 328

II

TBo:31 of the TBR number is reversed.

Figure 38. TBR encodings for mftb

Extended mnemonics for Move From Time Base:

Extended: extended form. Another way of saying this is that if mftb is coded with one operand, then that operand is assumed to be RT, and TBR defaults to the value corresponding to TB.

Compiler and Assembler Note - - - . contents of the Time Base into register Rx, execute:

mftb Rx

Reading the Time Base has no effect on the value it contains or the periodic incrementing of that value.

8.3 Reading the Time Base on

extended mnemonic moves from the upper half (TBU) to a GPR.

Because of the possibility of a carry from TBl to TBU occurring between reads of TBl and TBU, a sequence such as the following is necessary to read the Time Base on 32-bit impl~mentations.

loop: that a consistent pair of values has been obtained.

8.4 Computing Time of Day from the Time Base

Since the update frequency of the Time Base is implementation-dependent, the algorithm for con-verting the current value in the Time Base to time of day is also implementation-dependent.

As an example, assume that the Time Base is incre-mented at a constant rate of once for every 32 cycles of a 100 MHZ CPU instruction clock. What is wanted

standard clock1: the ·number of whole seconds which simple 64-bit subtraction will make it so).

• Integer constant ticksyer _sec contains the value 100 MHz

32 3,125,000

which is the number of times the Time Base is updated each second.

• Integer constant ns_adj contains the value 1,000,000,000

=

320 code given above for 64-bit machines is awkward, due mainly to the difficulty of doing 64-bit division.2 Such division can be avoided entirely if a time of day clock in POSIX format is updated at least once each second.

Assume that:

• The operating system maintains the following var-iables: (see Part 3, "PowerPC Operating Environment Architecture" on page 141) to occur at least once sequence such as this:

loop: delta value does not exceed one second.

Non-constant update frequency

In a system in which the update frequency of the Ti me Base may change over time, it is not possible to system software is notified of the change via an inter-rupt (see Part 3, "PowerPC Operating Environment

1 Described in POSIX Draft Standard P1003.4/D12, Draft Standard for Information Technology - Portable Operating System Interlace (POS/X) --Part 1: System Application Program Interlace (API) - Amendment 1: Realtime Extension [C Language]. Institute of Electrical and Electronics Engineers, Inc., Feb. 1992.

2 See D. E. Knuth, The Art of Computer Programming, Volume 2, Seminumerical Algorithms, section 4.3.1, Algorithm D. Addison-Wesley, 1981.

Chapter 8. Time Base 139

Architecture" on page 141), or else the change was instigated by the system software itself. At each such change, the system software must compute the current time of day using the old update frequency, compute a new value of ticks_per_second for the new frequency, and save the time of day, Time Base value, and tick rate.· Subsequent calls to compute time of day use the current Time Base value and the saved data.

Programming Note - - - , A generalized service to compute time of day could take the following as input.

1. Time of day at beginning of current epoch 2. Time Base value at beginning of current

epoch

3. Time Base update frequency

4. Time Base value for which time of day is desired

For a Power PC system in which the Time Base update frequency does not vary, the first three inputs would be constant.

Dans le document PowerPC Architecture First Edition (Page 150-154)