LINUX TIPS AND TRICKS --- February 02, 2001

Published by ITworld.com -- changing the way you view IT
http://www.itworld.com/Newsletters
________________________________________________________________________________

System Clocks
By Danny Kalev

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 
sources.

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 
active).

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 
time.

About the author(s)
----------------
Danny Kalev is a system analyst and software engineer with more than 10 
years of experience, specializing in C++ and object-oriented analysis 
and design on various platforms including VMS, DOS, Windows, Unix, and 
Linux. His technical interests involve code optimization, networking, 
and distributed computing. He is also a member of the ANSI C++ 
standardization committee and the author of ANSI/ISO C++ Professional 
Programmer's Handbook (Que, 1999). Contact him at linuxnl@excite.com.

________________________________________________________________________________

ADDITIONAL RESOURCES

The Solaris process model, Part 7: Managing thread execution and wait 
times in the system clock handler. A look at the dispatcher-related 
functions driven by the clock handler in Solaris

http://www.unixinsider.com/jsw/lintps_nl/swol-03-1999/swol-03-insidesolaris.html

Time bombs 
Setting, adjusting, and maintaining synchronized clocks on a network 

http://www.unixinsider.com/jsw/lintps_nl/swol-04-1996/swol-04-sysadmin.html

Keeping time 
How the clock and time function in Solaris

http://www.unixinsider.com/jsw/lintps_nl/swol-11-1999/swol-11-insidesolaris.html

________________________________________________________________________________

COMMUNITY DISCUSSIONS

Linux Software Development
Hone your Linux development skills, share your expertise, and put out 
the occasional call for help in this discussion for programmers of all 
levels. Moderated by Danny Kalev.

http://www.itworld.com/jump/lintps_nl/forums.itworld.com/
webx?14@@.ee6b652/227!skip=154

Ask the Geek
Got a question about Linux setup, tuning, security, or maintenance? 
Hackers, newbies, and all the geeks in between knock heads and devise 
solutions in this discussion moderated by LinuxWorld.com's resident 
geek.

http://www.itworld.com/jump/lintps_nl/forums.itworld.com/
webx?14@@.ee6c981/318!skip=268

________________________________________________________________________________

CONTACTS

* For editorial comments, write Andrew Santosusso, Associate Editor, 
  Newsletters at: andrew_santosusso@itworld.com

* For advertising information, write Dan Chupka, Account Executive at:
  dan_chupka@itworld.com

* For recruitment advertising information, write Jamie Swartz, Eastern
  Regional Sales Manager at: jamie_swartz@itworld.com or Paul Duthie,
  Western Regional Sales Manager at: paul_duthie@itworld.com

* For all other inquiries, write Jodie Naze, Product Manager, 
  Newsletters at: jodie_naze@itworld.com
________________________________________________________________________________

PRIVACY POLICY
http://www2.itworld.com/CDA/ITW_Privacy_Policy

Copyright 2001 ITworld.com, Inc., All Rights Reserved.

http://www.itworld.com
