The timers cause Unix signals (see Chapter 10) to be sent periodically to the process. It is also possible to activate an interval timer so that it sends just one signal after a specified delay. Each interval timer is therefore characterized by:
• The frequency at which the signals must be emitted, or a null value if just one signal has to be generated
• The time remaining until the next signal is to be generated
The earlier warning about accuracy applies to these timers. They are guaranteed to execute after the requested time has elapsed, but it is impossible to predict exactly when they will be delivered.
Interval timers are activated by means of the POSIX setitimer( ) system call. The first parameter specifies which of the following policies should be adopted:
The actual elapsed time; the process receives sigalrm signals. ITIMER_VIRTUAL
The time spent by the process in User Mode; the process receives sigvtalrm signals.
The time spent by the process both in User and in Kernel Mode; the process receives sigprof signals.
To implement an interval timer for each of the preceding policies, the process descriptor includes three pairs of fields:
• it real incr and it real value
• it virt incr and it virt value
• it prof incr and it prof value
The first field of each pair stores the interval in ticks between two signals; the other field stores the current value of the timer.
The itimer_real interval timer is implemented by using dynamic timers because the kernel must send signals to the process even when it is not running on the CPU. Therefore, each process descriptor includes a dynamic timer object called real_timer. The setitimer( ) system call initializes the real_timer fields and then invokes add_timer( ) to insert the dynamic timer in the proper list. When the timer expires, the kernel executes the it_real_fn( ) timer function. In turn, the it_real_fn( ) function sends a sigalrm signal to the process; if it_real_incr is not null, it sets the expires field again, reactivating the timer.
The itimer_virtual and itimer_prof interval timers do not require dynamic timers, since they can be updated while the process is running. The do_it_virt( ) and do_it_prof( ) functions are invoked by update_one_ process( ), which is called either by the PIT's timer interrupt handler (UP) or by the local timer interrupt handlers (SMP). Therefore, the two interval timers are updated once every tick, and if they are expired, the proper signal is sent to the current process.
The alarm( ) system call sends a sigalrm signal to the calling process when a specified time interval has elapsed. It is very similar to setitimer( ) when invoked with the itimer_real parameter, since it uses the real_timer dynamic timer included in the process descriptor. Therefore, alarm( ) and setitimer( ) with parameter itimer_real cannot be used at the same time.
I [email protected] RuBoard
Was this article helpful?