Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


update_process_timesis used to manage process-specific time elements and is invoked from the
local tick.

As the code flow diagram in Figure 15-23 shows, four things need to be done:


  1. account_process_tickuses eitheraccount_user_timeoraccount_sys_timeto update the
    values for user or system CPU time consumed in the task structure (utimeorstime,respec-
    tively). TheSIGXCPUsignal is also sent at intervals of 1 second if the process has exceeded its
    CPU limits specified by Rlimit.

  2. run_local_timersactivates and expires low-resolution timers. Recall that this was dis-
    cussed in detail in Section 15.2.

  3. scheduler_tickis a helper for the CPU scheduler as discussed in Chapter 2.

  4. run_posix_cpu_timersinitiates that the currently registered POSIX timers are run. This
    includes running the abovementioned interval timers since their implementation is based on
    POSIX CPU timers. Since these timers are otherwise not very interesting, their implementa-
    tion is not covered in detail.


run_posix_cpu_timers

update_process_times

account_process_tick

run_local_timers

scheduler_tick

Figure 15-23: Code flow diagram for
update_process_times.

15.9 Summary
The kernel needs to keep track of time for various purposes, and there are also a good many aspects that
must be considered to solve the problem. In this chapter, first you were introduced to the general concept
of timekeeping and the difference between timers and time-outs. You have seen that the implementation
of timers and time-outs is based on hardware that can manage the time. Typically, each system contains
more than one component for this purpose, and you were introduced to the data structures that allow
for representing these components and sorting them by quality. Traditionally, the kernel relied on low-
resolution timers, but recent hardware progress and a rework of the timing subsystem have allowed the
introduction of a new class ofhigh-resolution timers.

After a discussion of the implementation of high- and low-resolution timers, you were introduced to
the concept ofdynamic ticks. Traditionally, a periodic timer tick was issued withHZfrequency, but this is
suboptimal for machines where power is scarce: When a system is idle and has nothing to do, the tick
is superfluous and can be temporarily disabled to allow components to enter deeper sleep states without
being woken up at periodic intervals. The dynamic tick mode allows for achieving exactly this.

Time is also relevant for userspace processes, and thus I finally discussed various system calls that are
available in this area.
Free download pdf