System Clocks

This week, we'll explore the notion of time measurement and processing

under Linux. We will start with a quick overview of the low-level

hardware clocks and their interrupts, and then we will discuss

associated device drivers and synchronization with external time


Real-Time Clocks

All modern PCs possess an internal real-time clock (RTC), typically

built into the machine's chipset; however, some machines have an on-

board Motorola MC146818 clock (or a compatible chip). Real-time clocks

can send periodical signals in frequencies ranging between 2hz to

8192hz and functions as an alarm, raising IRQ (interrupt request) 8

when a timer countdown completes. Linux's /dev/rtc driver, a read-only

character device type, controls the system's RTC and reports the

current value as an unsigned long whose low-order byte contains the

interrupt type. The interrupt type can be update-done, alarm-rang, or

periodic. The remaining three bytes hold the number of interrupts since

the last read. You can access status information of the /dev/rtc driver

via the pseudo-file proc/driver/rtc. (if the /proc filesystem is


Time-related Interrupt Requests

On a congested system, the IRQ load can affect the system's

performance. Thus, several interrupts may pile up, causing an "IRQ

jam". Users must check the number of interrupts accumulated since the

last read, as it may be higher than one. Modern hardware architectures

can handle clock signals at a rate of up to 2048hz. Higher frequencies,

however, might cause IRQ jams. By design, a non-privileged process may

enable interrupts and signals at a rate of 64hz or lower. For higher

frequencies, the process must have a root privilege.

Synchronization with External Time Sources

Certain systems are synchronized with an external time-measuring

device. Using an external time source is common practice in hard-core,

real-time processing, embedded systems and clusters. Synchronizing the

kernel with the Network Time Protocol (NTP) enables Linux to keep-up

with very accurate atomic clocks around the world via the Internet. In

such systems, the kernel writes time to the CMOS every 11 minutes. When

doing so, the kernel disables the RTC periodic interrupts for a short


Now Read This IT Resume Makeover: Our top 11 tips
You Might Like