In fact, the process might not even have been the only process running in the last tick! This granular process accounting is classic Unix, and without much more complex accounting, this is the best the kernel can provide. In reality, the process might have entered and exited kernel mode many times during the last tick. You might realize that this implies that the kernel credits a process for running the entire previous tick in whatever mode the processor was in when the timer interrupt occurred. The appropriate value is increased by one and the other value remains the same.
SUSPEND ITIMER WHILE IN HANDLER UPDATE
* update by one jiffy the appropriate time counter Therefore, updates_one_process() can simply add each value to the corresponding counter without a branch: It is rather elaborate, but note how one of either the user_tick or the system value is equal to one and the other is zero, because of the exclusive-or (XOR). The update_one_process() function does the actual updating of the process's times. Update_one_process(p, user_tick, system, cpu) This enables update_process_times() to attribute the previous tick to the proper mode, either user or system: The user_mode() macro looks at the state of the processor registers, regs, and returns one if the timer interrupt occurred in user-space and zero if the interrupt occurred in kernel mode. The actual routine is very simple because other functions handle most of the previously discussed work: Update the wall time, which is stored in xtime Run any dynamic timers that have expired (discussed in the following section)Įxecute scheduler_tick(), as discussed in Chapter 4, "Process Scheduling" Update resource usages, such as consumed system and user time, for the currently running process Increment the jiffies_64 count by one (this is safe, even on 32-bit architectures, because the xtime_lock lock was previously obtained) The architecture-independent routine, do_timer(), performs much more work: Periodically save the updated wall time to the real time clockĬall the architecture-independent timer routine, do_timer()
Obtain the xtime_lock lock, which protects access to jiffies_64 and the wall time value, xtimeĪcknowledge or reset the system timer as required Its exact job depends on the given architecture, of course, but most handlers perform at least the following work: The architecture-dependent routine is registered as the interrupt handler for the system timer and, thus, runs when the timer interrupt hits. The timer interrupt is broken into two pieces: an architecture-dependent and an architecture-independent routine. MessageBoxButtons.YesNo) = DialogResult.Now that we have an understanding of HZ, jiffies, and what the system timer's role is, let's look at the actual implementation of the timer interrupt handler. If(MessageBox.Show("Continue running?", "Count is: " + alarmCounter, Private static void TimerEventProcessor(Object myObject, Processes all the events in the queue. MyTimer->Tick += gcnew EventHandler( TimerEventProcessor ) * Adds the event and the event handler for the method that will Restarts the timer and increments the counter. If ( MessageBox::Show( "Continue running?", String::Format( "Count is: ", alarmCounter ), MessageBoxButtons::YesNo ) = DialogResult::Yes ) Displays a message box asking whether to continue running the timer. Static void TimerEventProcessor( Object^ /*myObject*/, EventArgs^ /*myEventArgs*/ ) This is the method to run when the timer is raised.
Static System::Windows::Forms::Timer^ myTimer = gcnew System::Windows::Forms::Timer When the alarm occurs, a MessageBox displays a count of the number of times the alarm has started and prompts the user whether the timer should continue to run.
SUSPEND ITIMER WHILE IN HANDLER CODE
The following code example implements a simple interval timer, which sets off an alarm every five seconds. public:Įvent EventHandler ^ Tick public event EventHandler Tick member this.Tick : EventHandler Public Custom Event Tick As EventHandler Event Type EventHandler Examples
Occurs when the specified timer interval has elapsed and the timer is enabled.