X-Simulator | |
Create: 17 September 2007; Last review: 18 September 2007 |
Clock module | |||||||||||||
Introduction | The clock model used in the X-Simulator
is based on the Unix clock model, as reported also in the
RFC-1305. Before introducing this model, we briefly explain the general
model for a clock. A clock is a very simple device, obtained by an oscillator and a counter. The oscillator can be any physical device, such as a pendulum or a quartz crystal or it can be an electromagnetic signal. For instance an atomic clock uses an oscillation associates with a quantum transition between two energy level in an atom. The counter keeps track of the number of oscillations that have occured. After being set initially, the clock can then provide its estimate of the correct time by adding up the number of oscillations, also called clock cycles. In principle, if a clock was set perfectly and if its frequency (the frequency of the oscillator) remained perfect, it would keep the correct time indefinitely. However, this is not the case for different reasons. The quality of a clock depends on how well it is set, how accurate and stable its frequency is, and the degree of immunity the clock has to environmental changes. With the variable t, called the epoch, it is indicated the reference time scale. It corresponds to the reading of a counter that runs at the standard unit of frequency and began counting at some initial epoch t0. The standard unit of frequency corresponds to the inverse of the standard unit of time interval u, where the time interval is defined by the International Standard (SI) in terms of the standard second. A standard second corresponds to the duration of 9,192,631,770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the cesium-133 atom. For the purpose of our work instead, the reference time scale, representing with the variable t, corresponds to the reading of a reference clock, which is a simply better clock, that usually does not correspond to an atomic clock! In the following the reference clock is the master clock. Now, we indicate with the variable C(t) the time displayed by our clock (which corresponds to a slave clock) at the time t relative to the master timescale. The relationship between these two timescales are: C(t) = 1/2*D(t0)*[t-t0]2 + R(t0)*[t-t0] + C(t0) + w(t) .
This holds to the following, simplified, relationship: C(t) = R*[t-t0] + C(t0) + w(t) . If the clock is perfectly synchronized with the reference time clock, its frequency is unitary, that is R=1. In the other cases, the clock frequency is different from the unitary value and the frequency can be represented by a model that takes into account the deviation from the unit: R = 1 + DRIFT Finally, we can obtain the model used in the simulator: C(t) = (1 + DRIFT)*(t-t0) + C(t0) + w(t) . |
||||||||||||
Unix clock model |
The Unix 4.3bsd clock model is based on two system calls, setimeofday
and adjtime, and on two kernel variables, tick and
tickadj. The settimeoday call resets the kernel clock to the value given. Let value be the value passed with this system call. The effect of this system call is to initialize the variable C(t0)=value and the variable t0 to the time instant during which the system call was invoked. The adjtime call instead, slews the kernel clock. The clock usually run at a rate that corresponds to the intrinsic frequency of the particular oscillator used as the clock source, representing by the tick value. The rate of the clock can be varied, such as the clock can actually run at three different rates, one correpsonding to tick, one to tick+tickadj and the last to tick-tickadj. These last two rates are used when the adjtime system call is invoked. The interval during which one or the other of the two rates are used is calculated by: T = value * tick / tickadj , where value is the parameter passed by the adjtime system call. The effect is to slew the clock to a new value at a small, constant rate, rather than incorporate the adjustment all at once, which could cause the clock to be set backward. One of the assumptions made in the Unix clock model is that the period T of adjustment computed in the adjtime call must be completed before the next call is made. If not, this results in an error message to the system log. |
||||||||||||
Implementation | In the X-Simulator, the system clock
is implementing by the clock module. This simple module include
both the clock model and the system calls. It is a module of the coumpound
slave module and furthermore, this module only exchanges messages with
the node module. The messages that the node module can send to the clock one are:
|