Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


provide both are considered.^9 Actually most widespread architectures have been updated to
support both options, even if some (for instance SuperH) do this only for certain time models.
❑ CONFIG_TICK_ONESHOTbuilds support for the one-shot mode of clock event devices. This is auto-
matically selected if high-resolution timers or dynamic ticks are enabled.

❑ GENERIC_CLOCKEVENTS_BROADCASTmust be defined if the architecture suffers from problems that
require broadcasting. Currently only IA-32, AMD64, and MIPS are affected.

15.3.3 Time Representation


The generic time framework uses the data typektime_tto represent time values. Irregardless of the
underlying architecture, the type always resolves toa 64-bit quantity. This makes the structure conve-
nient to work with on 64-bit architectures as only simple integer operations are required for time-related
operations.

To reduce the effort on 32-bit machines, the definition ensures that the two 32-bit values are ordered
such that they can be directly interpreted as a 64-bit quantity without further ado — clearly this requires
sorting the fields differently depending on the processor’s endianness:

<ktime.h>
typedef union {
s64 tv64;
#if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)
struct {
# ifdef __BIG_ENDIAN
s32 sec, nsec;
# else
s32 nsec, sec;
# endif
} tv;
#endif
} ktime_t;

If a 32-bit architecture provides functions that handle 64-bit quantities efficiently, it can set the config-
uration optionKTIME_SCALAR— IA-32 is the only architecture that makes use of this possibility at the
moment. A separation into two 32-bit values is not performed in this case, but the representation of
kernel times as direct 64-bit quantities is used.

Several auxiliary functions to handlektime_tobjects are defined by the kernel. Among them are the
following:

❑ ktime_subandktime_addare used to subtract and addktime_ts, respectively.
❑ ktime_add_nsadds a given number of nanoseconds to aktime_t.ktime_add_usis another vari-
ant for microseconds.ktime_sub_nsandktime_sub_usare also available.
❑ ktime_setproduces aktime_tfrom a given number of seconds and nanoseconds.
❑ Various functions of the typex_to_yconvert between representationxandy,wherethetypes
ktime_t,timeval,clock_t,andtimespecare possible.

(^9) Architectures that are currently migrating to the generic clock event framework can setGENERIC_CLOCKEVENTS_MIGR. This will
build the code, but not use it at run time.

Free download pdf