Subversion Repositories HelenOS-doc

Rev

Rev 52 | Rev 55 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <chapter id="time"><?dbhtml filename="time.html"?>
  4.     <title>Time management</title>
  5.    
  6.     <para>
  7.     Time is one of the dimensions in which kernel, as well as the whole system, operates.
  8.     It is of special importance to many kernel subsytems. Knowledge of time makes it possible
  9.     for the scheduler to preemptively plan threads for execution. Different parts of the kernel
  10.     can request execution of their callback function with some specified delay. A good example
  11.     of such kernel code is the synchronization subsystem which uses this functionality to implement
  12.     timeouting versions of synchronization primitives.
  13.     </para>
  14.  
  15.     <section>
  16.     <title>System clock</title>
  17.     <para>
  18.     Every hardware architecture supported by HelenOS must support some kind of a device that can be
  19.     programmed to yield periodic time signals (i.e. clock interrupts). Some architectures have
  20.     external clock that is merely programmed by the kernel to interrupt the processor multiple
  21.     times in a second. This is the case of ia32 and amd64 architectures<footnote><para>When
  22.     running in uniprocessor mode.</para></footnote>, which use i8254 or a compatible chip to
  23.     achieve the goal.
  24.     </para>
  25.     <para>
  26.     Other architectures' processors typically contain two registers. The first
  27.    register is usually called a compare or a match register and can be set to an arbitrary value
  28.    by the operating system. The contents of the compare register then stays unaltered until it is
  29.    written by the kernel again. The second register, often called a counter register, can be also
  30.    written by the kernel, but the processor automatically increments it after every executed
  31.    instruction or in some fixed relation to processor speed. The point is that a clock interrupt is
  32.    generated whenever the values of the counter and the compare registers match. Sometimes, the scheme of
  33.    two registers is modified so that only one register is needed. Such a register, called a decrementer,
  34.    then counts towards zero and an interrupt is generated when zero is reached.
  35.    </para>
  36.    <para>
  37.    In any case, the initial value of the decrementer or the initial difference between the counter and
  38.    the compare registers, respectively, must be set accordingly to a known relation between the real time
  39.    and the speed of the decrementer or the counter register, respectively.
  40.    </para>
  41.    
  42.    </section>
  43.  
  44. </chapter>