]> git.ipfire.org Git - thirdparty/util-linux.git/blob - hwclock/hwclock.8
Imported from util-linux-2.10m tarball.
[thirdparty/util-linux.git] / hwclock / hwclock.8
1 .TH HWCLOCK 8 "02 March 1998"
2 .SH NAME
3 hwclock \- query and set the hardware clock (RTC)
4 .SH SYNOPSIS
5 .BR "hwclock \-r" " or " "hwclock \-\-show"
6 .br
7 .BR "hwclock \-w" " or " "hwclock \-\-systohc"
8 .br
9 .BR "hwclock \-s" " or " "hwclock \-\-hctosys"
10 .br
11 .BR "hwclock \-a" " or " "hwclock \-\-adjust"
12 .br
13 .BR "hwclock \-v" " or " "hwclock \-\-version"
14 .br
15 .B "hwclock \-\-set \-\-date=newdate"
16 .br
17 .B "hwclock \-\-getepoch"
18 .br
19 .B "hwclock \-\-setepoch \-\-epoch=year"
20 .PP
21 other options:
22 .PP
23 .B "[\-u|\-\-utc] \-\-localtime \-\-directisa \-\-test \-\-debug"
24 .PP
25 and arcane options for DEC Alpha:
26 .PP
27 .B "[\-A|\-\-arc] [\-J|\-\-jensen] [\-S|\-\-srm] [\-F|\-\-funky-toy]"
28 .PP
29 Minimum unique abbreviations of all options are acceptable.
30 .PP
31 Also, equivalent options \-r, \-w, \-s, \-a, \-v, \-u,
32 \-D, \-A, \-J, \-S, and \-F are accepted for compatibility
33 with the program "clock", while \-h asks for a help message.
34
35 .SH DESCRIPTION
36 .B hwclock
37 is a tool for accessing the Hardware Clock. You can display the
38 current time, set the Hardware Clock to a specified time, set the
39 Hardware Clock to the System Time, and set the System Time from the
40 Hardware Clock.
41 .PP
42 You can also run
43 .B hwclock
44 periodically to insert or remove time from the Hardware Clock to
45 compensate for systematic drift (where the clock consistently gains or
46 loses time at a certain rate if left to run).
47
48 .SH OPTIONS
49 You need exactly one of the following options to tell
50 .B hwclock
51 what function to perform:
52 .PP
53 .TP
54 .B \-\-show
55 Read the Hardware Clock and print the time on Standard Output.
56 The time is always in local time, even if you keep your Hardware Clock
57 in Coordinated Universal Time. See the
58 .B \-\-utc
59 option.
60
61 .TP
62 .B \-\-set
63 Set the Hardware Clock to the time given by the
64 .B \-\-date
65 option.
66 .TP
67 .B \-\-hctosys
68 Set the System Time from the Hardware Clock.
69
70 Also set the kernel's timezone value to the local timezone
71 as indicated by the TZ environment variable and/or
72 .IR /usr/lib/zoneinfo ,
73 as
74 .BR tzset (3)
75 would interpret them.
76 The obsolete tz_dsttime field of the kernel's timezone value is set
77 to DST_NONE. (For details on what this field used to mean, see
78 .BR settimeofday (2).)
79
80 This is a good option to use in one of the system startup scripts.
81 .TP
82 .B \-\-systohc
83 Set the Hardware Clock to the current System Time.
84 .TP
85 .B \-\-adjust
86 Add or subtract time from the Hardware Clock to account for systematic
87 drift since the last time the clock was set or adjusted. See discussion
88 below.
89 .TP
90 .B \-\-getepoch
91 Print out standard output the kernel's Hardware Clock epoch value.
92 This is the number of years into AD to which a zero year value in the
93 Hardware Clock refers. For example, if you are using the convention
94 that the year counter in your Hardware Clock contains the number of
95 full years since 1952, then the kernel's Hardware Counter epoch value
96 must be 1952.
97
98 This epoch value is used whenever hwclock reads or sets the Hardware Clock.
99 .TP
100 .B \-\-setepoch
101 Set the kernel's Hardware Clock epoch value to the value specified by the
102 .B \-\-epoch
103 option. See the
104 .B \-\-getepoch
105 option for details.
106 .TP
107 .B \-\-version
108 Print the version of
109 .B hwclock
110 on Standard Output.
111 .br
112 You need the following option if you specify
113 .B \-\-set
114 option. Otherwise, it is ignored.
115 .TP
116 .B \-\-date=date_string
117 Specifies the time to which to set the Hardware Clock. The value of this
118 option is an argument to the
119 .BR date (1)
120 program. For example,
121 .sp
122 .I hwclock --set --date="9/22/96 16:45:05"
123 .sp
124 The argument is in local time, even if you keep your Hardware Clock in
125 Coordinated Universal time. See the
126 .B \-\-utc
127 option.
128
129 .TP
130 .B \-\-epoch=year
131 Specifies the year which is the beginning of the Hardware Clock's
132 epoch. I.e. the number of years into AD to which a zero value in the
133 Hardware Clock's year counter refers.
134
135 For example,
136 .sp
137 .I hwclock --setepoch --epoch=1952
138
139 .PP
140 The following options apply to most functions.
141 .TP
142 .B \-\-utc
143 .TP
144 .B \-\-localtime
145 Indicates that the Hardware Clock is kept in Coordinated Universal
146 Time or local time, respectively. It is your choice whether to keep
147 your clock in UTC or local time, but nothing in the clock tells which
148 you've chosen. So this option is how you give that information to
149 .BR hwclock .
150
151 If you specify the wrong one of these options (or specify neither and
152 take a wrong default), both setting and querying of the Hardware Clock
153 will be messed up.
154
155 If you specify neither
156 .B \-\-utc
157 nor
158 .B \-\-localtime
159 , the default is whichever was specified the last time
160 .B hwclock
161 was used to set the clock (i.e. hwclock was successfully run with the
162 .B \-\-set
163 ,
164 .B \-\-systohc
165 ,
166 or
167 .B \-\-adjust
168 options), as recorded in the adjtime file. If the adjtime file doesn't
169 exist, the default is local time.
170
171 .TP
172 .B \-\-directisa
173 is meaningful only on an ISA machine or an Alpha (which implements enough
174 of ISA to be, roughly speaking, an ISA machine for
175 .BR hwclock 's
176 purposes). For other machines, it has no effect. This option tells
177 .B hwclock
178 to use explicit I/O instructions to access the Hardware Clock.
179 Without this option,
180 .B hwclock
181 will try to use the /dev/rtc device (which it assumes to be driven by the
182 rtc device driver). If it is unable to open the device (for read), it will
183 use the explicit I/O instructions anyway.
184
185 The rtc device driver was new in Linux Release 2.
186 .TP
187 .B \-\-badyear
188 Indicates that the Hardware Clock is incapable of storing years outside
189 the range 1994-1999. There is a problem in some BIOSes (almost all
190 Award BIOSes made between 4/26/94 and 5/31/95) wherein they are unable
191 to deal with years after 1999. If one attempts to set the year-of-century
192 value to something less than 94 (or 95 in some cases), the value that
193 actually gets set is 94 (or 95). Thus, if you have one of these machines,
194 .B hwclock
195 cannot set the year after 1999 and cannot use the value of the clock as
196 the true time in the normal way.
197
198 To compensate for this (without your getting a BIOS update, which would
199 definitely be preferable), always use
200 .B \-\-badyear
201 if you have one of these machines. When
202 .B hwclock
203 knows it's working with a brain-damaged clock, it ignores the year part of
204 the Hardware Clock value and instead tries to guess the year based on the
205 last calibrated date in the adjtime file, by assuming that that date is
206 within the past year. For this to work, you had better do a
207 .I hwclock \-\-set
208 or
209 .I hwclock \-\-systohc
210 at least once a year!
211
212 Though
213 .B hwclock
214 ignores the year value when it reads the Hardware Clock, it sets the
215 year value when it sets the clock. It sets it to 1995, 1996, 1997, or
216 1998, whichever one has the same position in the leap year cycle as
217 the true year. That way, the Hardware Clock inserts leap days where
218 they belong. Again, if you let the Hardware Clock run for more than a
219 year without setting it, this scheme could be defeated and you could
220 end up losing a day.
221
222 .B hwclock
223 warns you that you probably need
224 .B \-\-badyear
225 whenever it finds your Hardware Clock set to 1994 or 1995.
226
227 .TP
228 .B \-\-srm
229 .TP
230 .B \-\-arc
231 .TP
232 .B \-\-jensen
233 .TP
234 .B \-\-funky\-toy
235 These options all tell
236 .B hwclock
237 what kind of Alpha machine you have. They
238 are invalid if you don't have an Alpha and shouldn't be necessary if you
239 do, because
240 .B hwclock
241 should be able to determine by itself what it's
242 running on, at least when
243 .I /proc
244 is mounted. These options make it possible for
245 .B hwclock
246 to work even when
247 its environment does not conform to its expectations and thus it cannot
248 accurately determine what sort of system it is running on. If you think
249 hwclock is incorrectly determining the system's characteristics, try
250 running with the
251 .B \-\-debug
252 option to see what conclusions the program is
253 reaching and how. If you find you need one of these options to make
254 .B hwclock
255 work, contact the
256 .B hwclock
257 maintainer to see if the program can be improved to detect your system
258 automatically.
259
260 .B \-\-jensen
261 means you are running on a Jensen model.
262
263 .B \-\-arc
264 means your machine uses epoch 1980 in its hardware clock, as is commonly
265 the case for machines on ARC console (but Ruffians have epoch 1900).
266
267 .B \-\-srm
268 means your machine uses epoch 1900 in its hardware clock, as is commonly
269 the case for machines on SRM console.
270
271 .B \-\-funky\-toy
272 means that on your machine, one has to use the UF bit instead
273 of the UIP bit in the Hardware Clock to detect a time transition. "Toy"
274 in the option name refers to the Time Of Year facility of the machine.
275
276
277 .TP
278 .B \-\-test
279 Do everything except actually updating the Hardware Clock or anything
280 else. This is useful, especially in conjunction with
281 .B \-\-debug,
282 in learning about
283 .B hwclock.
284 .TP
285 .B \-\-debug
286 Display a lot of information about what
287 .B hwclock
288 is doing internally. Some of its function is complex and this output
289 can help you understand how the program works.
290
291
292 .SH NOTES
293
294
295 .SH Clocks in a Linux System
296 .PP
297 There are two main clocks in a Linux system:
298 .PP
299 .B The Hardware Clock:
300 This is a clock that runs independently of any control program running
301 in the CPU and even when the machine is powered off.
302
303 On an ISA system, this clock is specified as part of the ISA standard.
304 The control program can read or set this clock to a whole second, but
305 the control program can also detect the edges of the 1 second clock
306 ticks, so the clock actually has virtually infinite precision.
307 .PP
308 This clock is commonly called the hardware clock, the real time clock,
309 the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its
310 capitalized form, was coined for use by
311 .B hwclock
312 because all of the other names are inappropriate to the point of being
313 misleading.
314 .PP
315 .B The System Time:
316 This is the time kept by a clock inside the Linux kernel and driven by
317 a timer interrupt. (On an ISA machine, the timer interrupt is part of
318 the ISA standard). It has meaning only while Linux is running on the
319 machine. The System Time is the number of seconds since 00:00:00
320 January 1, 1970 UTC (or more succinctly, the number of seconds since
321 1969). The System Time is not an integer, though. It has virtually
322 infinite precision.
323 .PP
324 The System Time is the time that matters. The Hardware Clock's basic
325 purpose in a Linux system is to keep time when Linux is not running. You
326 initialize the System Time to the time from the Hardware Clock when Linux
327 starts up, and then never use the Hardware Clock again. Note that in DOS,
328 for which ISA was designed, the Hardware Clock is the only real time clock.
329 .PP
330 It is important that the System Time not have any discontinuities such as
331 would happen if you used the
332 .BR date (1L)
333 program to set it while the system is running. You can, however, do whatever
334 you want to the Hardware Clock while the system is running, and the next
335 time Linux starts up, it will do so with the adjusted time from the Hardware
336 Clock. You can also use the program
337 .BR adjtimex (8)
338 to smoothly adjust the System Time while the system runs.
339 .PP
340 A Linux kernel maintains a concept of a local timezone for the system.
341 But don't be misled -- almost nobody cares what timezone the kernel
342 thinks it is in. Instead, programs that care about the timezone
343 (perhaps because they want to display a local time for you) almost
344 always use a more traditional method of determining the timezone: They
345 use the TZ environment variable and/or the /usr/local/timezone
346 directory, as explained in the man page for tzset(3). However, some
347 programs and fringe parts of the Linux kernel such as filesystems use
348 the kernel timezone value. An example is the vfat filesystem. If the
349 kernel timezone value is wrong, the vfat filesystem will report and
350 set the wrong timestamps on files.
351 .PP
352 .B hwclock
353 sets the kernel timezone to the value indicated by TZ and/or
354 /usr/local/timezone when you set the System Time using the
355 .B \-\-hctosys
356 option.
357 .PP
358 The timezone value actually consists of two parts: 1) a field
359 tz_minuteswest indicating how many minutes local time (not adjusted
360 for DST) lags behind UTC, and 2) a field tz_dsttime indicating
361 the type of Daylight Savings Time (DST) convention that is in effect
362 in the locality at the present time.
363 This second field is not used under Linux and is always zero.
364 (See also
365 .BR settimeofday (2).)
366
367 .SH How hwclock Accesses the Hardware Clock
368 .PP
369 .B hwclock
370 Uses many different ways to get and set Hardware Clock values.
371 The most normal way is to do I/O to the device special file /dev/rtc,
372 which is presumed to be driven by the rtc device driver. However,
373 this method is not always available. For one thing, the rtc driver is
374 a relatively recent addition to Linux. Older systems don't have it.
375 Also, though there are versions of the rtc driver that work on DEC
376 Alphas, there appear to be plenty of Alphas on which the rtc driver
377 does not work (a common symptom is hwclock hanging).
378 .PP
379 On older systems, the method of accessing the Hardware Clock depends on
380 the system hardware.
381 .PP
382 On an ISA system,
383 .B hwclock
384 can directly access the "CMOS memory" registers that
385 constitute the clock, by doing I/O to Ports 0x70 and 0x71. It does
386 this with actual I/O instructions and consequently can only do it if
387 running with superuser effective userid. (In the case of a Jensen
388 Alpha, there is no way for
389 .B hwclock
390 to execute those I/O instructions, and so it uses instead the
391 /dev/port device special file, which provides almost as low-level an
392 interface to the I/O subsystem).
393
394 This is a really poor method of accessing the clock, for all the
395 reasons that user space programs are generally not supposed to do
396 direct I/O and disable interrupts. Hwclock provides it because it is
397 the only method available on ISA and Alpha systems which don't have
398 working rtc device drivers available.
399
400 .PP
401 On an m68k system,
402 .B hwclock
403 can access the clock via the console driver, via the device special
404 file /dev/tty1.
405 .PP
406 .B hwclock
407 tries to use /dev/rtc. If it is compiled for a kernel that doesn't have
408 that function or it is unable to open /dev/rtc,
409 .B hwclock
410 will fall back to another method, if available. On an ISA or Alpha
411 machine, you can force
412 .B hwclock
413 to use the direct manipulation of the CMOS registers without even trying
414 .I /dev/rtc
415 by specifying the \-\-directisa option.
416
417
418 .SH The Adjust Function
419 .PP
420 The Hardware Clock is usually not very accurate. However, much of its
421 inaccuracy is completely predictable - it gains or loses the same amount
422 of time every day. This is called systematic drift.
423 .BR hwclock 's
424 "adjust" function lets you make systematic corrections to correct the
425 systematic drift.
426 .PP
427 It works like this:
428 .B hwclock
429 keeps a file,
430 .I /etc/adjtime,
431 that keeps some historical information. This is called the adjtime file.
432 .PP
433 Suppose you start with no adjtime file. You issue a
434 .I hwclock \-\-set
435 command to set the Hardware Clock to the true current time.
436 .B Hwclock
437 creates the adjtime file and records in it the current time as the
438 last time the clock was calibrated.
439 5 days later, the clock has gained 10 seconds, so you issue another
440 .I hwclock \-\-set
441 command to set it back 10 seconds.
442 .B Hwclock
443 updates the adjtime file to show the current time as the last time the
444 clock was calibrated, and records 2 seconds per day as the systematic
445 drift rate. 24 hours go by, and then you issue a
446 .I hwclock \-\-adjust
447 command.
448 .B Hwclock
449 consults the adjtime file and sees that the clock gains 2 seconds per
450 day when left alone and that it has been left alone for exactly one
451 day. So it subtracts 2 seconds from the Hardware Clock. It then
452 records the current time as the last time the clock was adjusted.
453 Another 24 hours goes by and you issue another
454 .I hwclock \-\-adjust.
455 .B Hwclock
456 does the same thing: subtracts 2 seconds and updates the adjtime file
457 with the current time as the last time the clock was adjusted.
458 .PP
459 Every time you calibrate (set) the clock (using
460 .I \-\-set
461 or
462 .I \-\-systohc
463 ),
464 .B hwclock
465 recalculates the systematic drift rate based on how long it has been
466 since the last calibration, how long it has been since the last
467 adjustment, what drift rate was assumed in any intervening
468 adjustments, and the amount by which the clock is presently off.
469 .PP
470 A small amount of error creeps in any time
471 .B hwclock
472 sets the clock, so it refrains from making an adjustment that would be
473 less than 1 second. Later on, when you request an adjustment again,
474 the accumulated drift will be more than a second and
475 .B hwclock
476 will do the adjustment then.
477 .PP
478 It is good to do a
479 .I hwclock \-\-adjust
480 just before the
481 .I hwclock \-\-hctosys
482 at system startup time, and maybe periodically while the system is
483 running via cron.
484 .PP
485 The adjtime file, while named for its historical purpose of controlling
486 adjustments only, actually contains other information for use by hwclock
487 in remembering information from one invocation to the next.
488 .PP
489 The format of the adjtime file is, in ASCII:
490 .PP
491 Line 1: 3 numbers, separated by blanks: 1) systematic drift rate in
492 seconds per day, floating point decimal; 2) Resulting number of
493 seconds since 1969 UTC of most recent adjustment or calibration,
494 decimal integer; 3) zero (for compatibility with
495 .BR clock (8))
496 as a decimal integer.
497 .PP
498 Line 2: 1 number: Resulting number of seconds since 1969 UTC of most
499 recent calibration. Zero if there has been no calibration yet or it
500 is known that any previous calibration is moot (for example, because
501 the Hardware Clock has been found, since that calibration, not to
502 contain a valid time). This is a decimal integer.
503 .PP
504 Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
505 Coordinated Universal Time or local time. You can always override this
506 value with options on the
507 .B hwclock
508 command line.
509 .PP
510 You can use an adjtime file that was previously used with the
511 .BR clock (8)
512 program with
513 .B hwclock.
514
515
516 .SH "Automatic Hardware Clock Synchronization By the Kernel"
517
518 You should be aware of another way that the Hardware Clock is kept
519 synchronized in some systems. The Linux kernel has a mode wherein it
520 copies the System Time to the Hardware Clock every 11 minutes.
521 This is a good mode to use when you are using something sophisticated
522 like ntp to keep your System Time synchronized. (ntp is a way to keep
523 your System Time synchronized either to a time server somewhere on the
524 network or to a radio clock hooked up to your system. See RFC 1305).
525
526 This mode (we'll call it "11 minute mode") is off until something
527 turns it on. The ntp daemon xntpd is one thing that turns it on. You
528 can turn it off by running anything, including
529 .IR "hwclock \-\-hctosys" ,
530 that sets the System Time the old fashioned way.
531
532 To see if it is on or
533 off, use the command
534 .I adjtimex \-\-print
535 and look at the value of "status". If the "64" bit of this number
536 (expressed in binary) equal to 0, 11 minute mode is on. Otherwise, it
537 is off.
538
539 If your system runs with 11 minute mode on, don't use
540 .I hwclock \-\-adjust
541 or
542 .IR "hwclock \-\-hctosys" .
543 You'll just make a mess. It is acceptable to use a
544 .I hwclock \-\-hctosys
545 at startup time to get a reasonable System Time until your system is
546 able to set the System Time from the external source and start 11
547 minute mode.
548
549
550 .SH ISA Hardware Clock Century value
551
552 There is some sort of standard that defines CMOS memory Byte 50 on an ISA
553 machine as an indicator of what century it is.
554 .B hwclock
555 does not use or set that byte because there are some machines that
556 don't define the byte that way, and it really isn't necessary anyway,
557 since the year-of-century does a good job of implying which century it
558 is.
559
560 If you have a bona fide use for a CMOS century byte, contact the
561 .B hwclock
562 maintainer; an option may be appropriate.
563
564 Note that this section is only relevant when you are using the "direct
565 ISA" method of accessing the Hardware Clock.
566
567
568
569 .SH "ENVIRONMENT VARIABLES"
570 .I TZ
571
572 .SH FILES
573 .I /etc/adjtime
574 .I /usr/lib/zoneinfo/
575 .I /dev/rtc
576 .I /dev/port
577 .I /dev/tty1
578 .I /proc/cpuinfo
579
580 .SH "SEE ALSO"
581 .BR adjtimex (8),
582 .BR date (1),
583 .BR gettimeofday (2),
584 .BR settimeofday (2),
585 .BR crontab (1),
586 .BR tzset (3)
587
588 .SH AUTHORS
589 Written By Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
590 based on work done on the
591 .I clock
592 program by Charles Hedrick, Rob Hooft, and Harald Koenig.
593 See the source code for complete history and credits.
594
595