5.2. The Timer Interrupt Handler

Each occurrence of a timer interrupt triggers the following major activities:

  • Updates the time elapsed since system startup.

  • Updates the time and date.

  • Determines how long the current process has been running on the CPU and preempts it if it has exceeded the time allocated to it. The allocation of time slots (also called quanta) is discussed in Chapter 10.

  • Updates resource usage statistics.

  • Checks whether the interval of time associated with each software timer (see Section 5.4.4) has elapsed; if so, invokes the proper function.

The first activity is considered urgent, so it is performed by the timer interrupt handler itself. The remaining four activities are less urgent; they are performed by the functions invoked by the TIMER_BH and TQUEUE_BH bottom halves (see Section 4.6.6 in Chapter 4).

The kernel uses two basic timekeeping functions: one to keep the current time up to date and another to count the number of microseconds that have elapsed within the current second. There are two different ways to maintain such values: a more precise method that is available if the chip has a Time Stamp Counter (TSC) and a less precise method used in other cases. So the kernel creates two variables to store the functions it uses, pointing the variables to the functions using the TSC if it exists:

  • The current time is calculated by do_gettimeofday( ) if the CPU has the TSC register and by do_normal_gettime( ) otherwise. A pointer to the proper function is stored ...

Get Understanding the Linux Kernel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.