Subversion Repositories HelenOS-doc

Rev

Rev 127 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 127 Rev 131
Line 1... Line 1...
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<chapter id="time">
2
<chapter id="time">
3
  <?dbhtml filename="time.html"?>
3
  <?dbhtml filename="time.html"?>
4
 
4
 
5
  <title>Time management</title>
5
  <title>Time Management</title>
6
 
6
 
7
  <para>Time is one of the dimensions in which kernel, as well as the whole
7
  <para>Time is one of the dimensions in which kernel, as well as the whole
8
  system, operates. It is of special importance to many kernel subsytems.
8
  system, operates. It is of special importance to many kernel subsytems.
9
  Knowledge of time makes it possible for the scheduler to preemptively plan
9
  Knowledge of time makes it possible for the scheduler to preemptively plan
10
  threads for execution. Different parts of the kernel can request execution
10
  threads for execution. Different parts of the kernel can request execution
11
  of their callback function with some specified delay. A good example of such
11
  of their callback function with some specified delay. A good example of such
12
  kernel code is the synchronization subsystem which uses this functionality
12
  kernel code is the synchronization subsystem which uses this functionality
13
  to implement timeouting versions of synchronization primitives.</para>
13
  to implement timeouting versions of synchronization primitives.</para>
14
 
14
 
15
  <section>
15
  <section>
16
    <title>System clock</title>
16
    <title>System Clock</title>
17
 
17
 
18
    <para>Every hardware architecture supported by HelenOS must support some
18
    <para>Every hardware architecture supported by HelenOS must support some
19
    kind of a device that can be programmed to yield periodic time signals
19
    kind of a device that can be programmed to yield periodic time signals
20
    (i.e. clock interrupts). Some architectures have external clock that is
20
    (i.e. clock interrupts). Some architectures have external clock that is
21
    merely programmed by the kernel to interrupt the processor multiple times
21
    merely programmed by the kernel to interrupt the processor multiple times
Line 82... Line 82...
82
    <title>Timeouts</title>
82
    <title>Timeouts</title>
83
 
83
 
84
    <para>Kernel subsystems can register a callback function to be executed
84
    <para>Kernel subsystems can register a callback function to be executed
85
    with a specified delay. Such a registration is represented by a kernel
85
    with a specified delay. Such a registration is represented by a kernel
86
    structure called <classname>timeout</classname>. Timeouts are registered
86
    structure called <classname>timeout</classname>. Timeouts are registered
87
    via <code>timeout_register()</code> function. This function takes a pointer
87
    via <code>timeout_register</code> function. This function takes a pointer
88
    to a timeout structure, a callback function, a parameter of the callback
88
    to a timeout structure, a callback function, a parameter of the callback
89
    function and a delay in microseconds as parameters. After the structure is
89
    function and a delay in microseconds as parameters. After the structure is
90
    initialized with all these values, it is sorted into the processor's list
90
    initialized with all these values, it is sorted into the processor's list
91
    of active timeouts, according to the number of clock interrupts remaining
91
    of active timeouts, according to the number of clock interrupts remaining
92
    to their expiration and relatively to already listed timeouts.</para>
92
    to their expiration and relatively to already listed timeouts.</para>
93
 
93
 
94
    <para>Timeouts can be unregistered via <code>timeout_unregister()</code>.
94
    <para>Timeouts can be unregistered via <code>timeout_unregister</code>.
95
    This function can, as opposed to <code>timeout_register()</code>, fail when
95
    This function can, as opposed to <code>timeout_register</code>, fail when
96
    it is too late to remove the timeout from the list of active
96
    it is too late to remove the timeout from the list of active
97
    timeouts.</para>
97
    timeouts.</para>
98
 
98
 
99
    <para>Timeouts are nearing their expiration in the list of active timeouts
99
    <para>Timeouts are nearing their expiration in the list of active timeouts
100
    which exists on every processor in the system. The expiration counters are
100
    which exists on every processor in the system. The expiration counters are
Line 105... Line 105...
105
    the list and their callback function is called with respective
105
    the list and their callback function is called with respective
106
    parameter.</para>
106
    parameter.</para>
107
  </section>
107
  </section>
108
 
108
 
109
  <section>
109
  <section>
110
    <title>Generic clock interrupt handler</title>
110
    <title>Generic Clock Interrupt Handler</title>
111
 
111
 
112
    <para>On each clock interrupt, the architecture specific part of the clock
112
    <para>On each clock interrupt, the architecture specific part of the clock
113
    interrupt handler makes a call to the generic clock interrupt handler
113
    interrupt handler makes a call to the generic clock interrupt handler
114
    implemented by the <code>clock()</code> function. The generic handler takes
114
    implemented by the <code>clock</code> function. The generic handler takes
115
    care of several mission critical goals:</para>
115
    care of several mission critical goals:</para>
116
 
116
 
117
    <itemizedlist>
117
    <itemizedlist>
118
      <listitem>
118
      <listitem>
119
        <para>expiration of timeouts,</para>
119
        <para>expiration of timeouts,</para>
Line 126... Line 126...
126
      <listitem>
126
      <listitem>
127
        <para>preemption of threads.</para>
127
        <para>preemption of threads.</para>
128
      </listitem>
128
      </listitem>
129
    </itemizedlist>
129
    </itemizedlist>
130
 
130
 
131
    <para>The <code>clock()</code> function checks for expired timeouts and
131
    <para>The <code>clock</code> function checks for expired timeouts and
132
    decrements unexpired timeout expiration counters exactly one more times
132
    decrements unexpired timeout expiration counters exactly one more times
133
    than is the number of missed clock signals (i.e. at least once and
133
    than is the number of missed clock signals (i.e. at least once and
134
    possibly more times, depending on the missed clock signals counter). The
134
    possibly more times, depending on the missed clock signals counter). The
135
    time of the day counters are also updated one more times than is the
135
    time of the day counters are also updated one more times than is the
136
    number of missed clock signals. And finally, the remaining timeslice of
136
    number of missed clock signals. And finally, the remaining timeslice of
Line 139... Line 139...
139
    lost due to an occasional excessive time drift described in previous
139
    lost due to an occasional excessive time drift described in previous
140
    paragraphs.</para>
140
    paragraphs.</para>
141
  </section>
141
  </section>
142
 
142
 
143
  <section>
143
  <section>
144
    <title>Time source for userspace</title>
144
    <title>Time Source for Userspace</title>
145
 
145
 
146
    <para>In HelenOS, userspace tasks don't communicate with the kernel in
146
    <para>In HelenOS, userspace tasks don't communicate with the kernel in
147
    order to read the system time. Instead, a mechanism that shares kernel
147
    order to read the system time. Instead, a mechanism that shares kernel
148
    time of the the day counters with userspace address spaces is deployed. On
148
    time of the the day counters with userspace address spaces is deployed. On
149
    the kernel side, during system initialization, HelenOS allocates a frame
149
    the kernel side, during system initialization, HelenOS allocates a frame