The Linux Programming Interface

(nextflipdebug5) #1

206 Chapter 10


with greater accuracy and time measurements can be made with greater precision.
However, it isn’t desirable to set the clock rate to arbitrarily high values, because
each clock interrupt consumes a small amount of CPU time, which is time that the
CPU can’t spend executing processes.
Debate among kernel developers eventually resulted in the software clock
rate becoming a configurable kernel option (under Processor type and features,
Timer frequency). Since kernel 2.6.13, the clock rate can be set to 100, 250 (the
default), or 1000 hertz, giving jiffy values of 10, 4, and 1 milliseconds, respec-
tively. Since kernel 2.6.20, a further frequency is available: 300 hertz, a number
that divides evenly for two common video frame rates: 25 frames per second
(PAL) and 30 frames per second (NTSC).

10.7 Process Time.............................................................................................................


Process time is the amount of CPU time used by a process since it was created. For
recording purposes, the kernel separates CPU time into the following two
components:

z User CPU time is the amount of time spent executing in user mode. Sometimes
referred to as virtual time, this is the time that it appears to the program that it
has access to the CPU.
z System CPU time is amount of time spent executing in kernel mode. This is the
time that the kernel spends executing system calls or performing other tasks
on behalf of the program (e.g., servicing page faults).

Sometimes, we refer to process time as the total CPU time consumed by the process.
When we run a program from the shell, we can use the time(1) command to
obtain both process time values, as well as the real time required to run the program:

$ time ./myprog
real 0m4.84s
user 0m1.030s
sys 0m3.43s

The times() system call retrieves process time information, returning it in the struc-
ture pointed to by buf.

This tms structure pointed to by buf has the following form:

struct tms {
clock_t tms_utime; /* User CPU time used by caller */
clock_t tms_stime; /* System CPU time used by caller */

#include <sys/times.h>

clock_t times(struct tms *buf);
Returns number of clock ticks (sysconf(_SC_CLK_TCK)) since
“arbitrary” time in past on success, or (clock_t) –1 on error
Free download pdf