Updating System Statistics

The kernel, among the other time-related duties, must periodically collect several data used to:

  • Checking the CPU resource limit of the running processes

  • Computing the average system load

  • Profiling the kernel code

Checking the Current Process CPU Resource Limit

The update_process_times( ) function (invoked by either the PIT’s timer interrupt handler on uniprocessor systems or the local timer interrupt handler in multiprocessor systems) updates some kernel statistics stored in the kstat variable of type kernel_stat; it then invokes update_one_process( ) to update some fields storing statistics that can be exported to user programs through the times( ) system call. In particular, a distinction is made between CPU time spent in User Mode and in Kernel Mode. The function performs the following actions:

  1. Updates the per_cpu_utime field of current’s process descriptor, which stores the number of ticks during which the process has been running in User Mode.

  2. Updates the per_cpu_stime field of current’s process descriptor, which stores the number of ticks during which the process has been running in Kernel Mode.

  3. Invokes do_process_times( ), which checks whether the total CPU time limit has been reached; if so, it sends SIGXCPU and SIGKILL signals to current. Section 3.2.5 describes how the limit is controlled by the rlim[RLIMIT_CPU].rlim_cur field of each process descriptor.

Two additional fields called times.tms_cutime and times.tms_cstime are provided in the process ...

Get Understanding the Linux Kernel, Second Edition 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.